Eclipse SUMO - Simulation of Urban MObility
Loading...
Searching...
No Matches
GUIOSGView.cpp
Go to the documentation of this file.
1/****************************************************************************/
2// Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo
3// Copyright (C) 2001-2025 German Aerospace Center (DLR) and others.
4// This program and the accompanying materials are made available under the
5// terms of the Eclipse Public License 2.0 which is available at
6// https://www.eclipse.org/legal/epl-2.0/
7// This Source Code may also be made available under the following Secondary
8// Licenses when the conditions for such availability set forth in the Eclipse
9// Public License 2.0 are satisfied: GNU General Public License, version 2
10// or later which is available at
11// https://www.gnu.org/licenses/old-licenses/gpl-2.0-standalone.html
12// SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-or-later
13/****************************************************************************/
20// An OSG-based 3D view on the simulation
21/****************************************************************************/
22#include <config.h>
23
24#ifdef HAVE_OSG
25
26#include <cmath>
27#include <fxkeys.h>
28#include <iostream>
29#include <limits>
30#include <utility>
34#include <gui/GUIViewTraffic.h>
35#include <guisim/GUIEdge.h>
37#include <guisim/GUILane.h>
38#include <guisim/GUINet.h>
39#include <guisim/GUIPerson.h>
40#include <guisim/GUIVehicle.h>
41#include <microsim/MSEdge.h>
43#include <microsim/MSLane.h>
44#include <microsim/MSNet.h>
70
71#include "GUIOSGBuilder.h"
73#include "GUIOSGView.h"
74
75//#define DEBUG_GLERRORS
76
77FXDEFMAP(GUIOSGView) GUIOSGView_Map[] = {
78 //________Message_Type_________ ___ID___ ________Message_Handler________
79 FXMAPFUNC(SEL_CHORE, MID_CHORE, GUIOSGView::onIdle),
80};
81FXIMPLEMENT(GUIOSGView, GUISUMOAbstractView, GUIOSGView_Map, ARRAYNUMBER(GUIOSGView_Map))
82
83
84std::ostream&
85operator<<(std::ostream& os, const osg::Vec3d& v) {
86 return os << v.x() << "," << v.y() << "," << v.z();
87}
88
89// ===========================================================================
90// GUIOSGView::Command_TLSChange member method definitions
91// ===========================================================================
92
93GUIOSGView::Command_TLSChange::Command_TLSChange(const MSLink* const link, osg::Switch* switchNode)
94 : myLink(link), mySwitch(switchNode), myLastState(LINKSTATE_TL_OFF_NOSIGNAL) {
95 execute();
96}
97
98
99GUIOSGView::Command_TLSChange::~Command_TLSChange() {}
100
101
102void
103GUIOSGView::Command_TLSChange::execute() {
104 switch (myLink->getState()) {
107 mySwitch->setSingleChildOn(0);
108 break;
111 mySwitch->setSingleChildOn(1);
112 break;
113 case LINKSTATE_TL_RED:
114 case LINKSTATE_STOP:
115 mySwitch->setSingleChildOn(2);
116 break;
118 mySwitch->setSingleChildOn(3);
119 break;
122 mySwitch->setSingleChildOn(3);
123 break;
124 default:
125 mySwitch->setAllChildrenOff();
126 }
127 myLastState = myLink->getState();
128}
129
130// ===========================================================================
131// GUIOSGView member method definitions
132// ===========================================================================
133
134GUIOSGView::GUIOSGView(
135 FXComposite* p,
136 GUIMainWindow& app,
137 GUISUMOViewParent* parent,
138 GUINet& net, FXGLVisual* glVis,
139 FXGLCanvas* share) :
140 GUISUMOAbstractView(p, app, parent, net.getVisualisationSpeedUp(), glVis, share),
141 myTracked(0), myLastUpdate(-1),
142 myOSGNormalizedCursorX(0.), myOSGNormalizedCursorY(0.) {
143 if (myChanger != nullptr) {
144 delete (myChanger);
145 }
146 int w = getWidth();
147 int h = getHeight();
148 myAdapter = new FXOSGAdapter(this, new FXCursor(parent->getApp(), CURSOR_CROSS));
149 myViewer = new osgViewer::Viewer();
150 myCameraManipulator = new GUIOSGManipulator(this);
151 myChanger = new GUIOSGPerspectiveChanger(*this, *myGrid);
152 const char* sumoPath = getenv("SUMO_HOME");
153 if (sumoPath != 0) {
154 std::string newPath = std::string(sumoPath) + "/data/3D";
155 if (FileHelpers::isReadable(newPath)) {
156 osgDB::FilePathList path = osgDB::Registry::instance()->getDataFilePathList();
157 path.push_back(newPath);
158 osgDB::Registry::instance()->setDataFilePathList(path);
159 }
160 }
161
162 myGreenLight = osgDB::readNodeFile("tlg.obj");
163 myYellowLight = osgDB::readNodeFile("tly.obj");
164 myRedLight = osgDB::readNodeFile("tlr.obj");
165 myRedYellowLight = osgDB::readNodeFile("tlu.obj");
166 myPoleBase = osgDB::readNodeFile("poleBase.obj");
167 if (myGreenLight == 0 || myYellowLight == 0 || myRedLight == 0 || myRedYellowLight == 0 || myPoleBase == 0) {
168 WRITE_ERROR(TL("Could not load traffic light files."));
169 }
170 // calculate camera frustum to scale the ground plane all across
171 double left, right, bottom, top, zNear, zFar;
172 myViewer->getCamera()->getProjectionMatrixAsFrustum(left, right, bottom, top, zNear, zFar);
173 myRoot = GUIOSGBuilder::buildOSGScene(myGreenLight, myYellowLight, myRedLight, myRedYellowLight, myPoleBase);
174 myPlane = new osg::MatrixTransform();
175 myPlane->setCullCallback(new ExcludeFromNearFarComputationCallback());
176 myPlane->addChild(GUIOSGBuilder::buildPlane((float)(zFar - zNear)));
177 myPlane->addUpdateCallback(new PlaneMoverCallback(myViewer->getCamera()));
178 myRoot->addChild(myPlane);
179 // add the stats handler
180 osgViewer::StatsHandler* statsHandler = new osgViewer::StatsHandler();
181 statsHandler->setKeyEventTogglesOnScreenStats(osgGA::GUIEventAdapter::KEY_I);
182 myViewer->addEventHandler(statsHandler);
183 myViewer->setSceneData(myRoot);
184 myViewer->setCameraManipulator(myCameraManipulator);
185
186 myViewer->setKeyEventSetsDone(0);
187 myViewer->getCamera()->setGraphicsContext(myAdapter);
188 myViewer->getCamera()->setViewport(0, 0, w, h);
189 myViewer->getCamera()->setNearFarRatio(0.005); // does not work together with setUpDepthPartitionForCamera
190 myViewer->setThreadingModel(osgViewer::Viewer::SingleThreaded);
191 myViewer->addEventHandler(new PickHandler(this));
192 osg::Vec3d lookFrom, lookAt, up;
193 myCameraManipulator->getHomePosition(lookFrom, lookAt, up);
194 lookFrom = lookAt + osg::Z_AXIS;
195 up = osg::Y_AXIS;
196 myCameraManipulator->setHomePosition(lookFrom, lookAt, up);
197 myViewer->home();
198 recenterView();
199 myViewer->home();
200 getApp()->addChore(this, MID_CHORE);
201 myTextNode = new osg::Geode();
202 myText = new osgText::Text;
203 myText->setCharacterSizeMode(osgText::Text::SCREEN_COORDS);
204 myText->setShaderTechnique(osgText::NO_TEXT_SHADER);
205 osgText::Font* font = osgText::readFontFile("arial.ttf");
206 if (font != nullptr) {
207 myText->setFont(font);
208 }
209 myText->setCharacterSize(16.f);
210 myTextNode->addDrawable(myText);
211 myText->setAlignment(osgText::TextBase::AlignmentType::LEFT_TOP);
212 myText->setDrawMode(osgText::TextBase::DrawModeMask::FILLEDBOUNDINGBOX | osgText::TextBase::DrawModeMask::TEXT);
213 myText->setBoundingBoxColor(osg::Vec4(0.0f, 0.0f, 0.2f, 0.5f));
214 myText->setBoundingBoxMargin(2.0f);
215
216 myHUD = new osg::Camera;
217 myHUD->setProjectionMatrixAsOrtho2D(0, 800, 0, 800); // default size will be overwritten
218 myHUD->setReferenceFrame(osg::Transform::ABSOLUTE_RF);
219 myHUD->setViewMatrix(osg::Matrix::identity());
220 myHUD->setClearMask(GL_DEPTH_BUFFER_BIT);
221 myHUD->setRenderOrder(osg::Camera::POST_RENDER);
222 myHUD->setAllowEventFocus(false);
223 myHUD->setGraphicsContext(myAdapter);
224 myHUD->addChild(myTextNode);
225 myHUD->setViewport(0, 0, w, h);
226 myViewer->addSlave(myHUD, false);
227 myCameraManipulator->updateHUDText();
228
229 // adjust the main light
230 adoptViewSettings();
231 osgUtil::Optimizer optimizer;
232 optimizer.optimize(myRoot);
233}
234
235
236GUIOSGView::~GUIOSGView() {
237 getApp()->removeChore(this, MID_CHORE);
238 myViewer->setDone(true);
239 myViewer = 0;
240 myRoot = 0;
241 myAdapter = 0;
242 myCameraManipulator = 0;
243 myHUD = 0;
244 myText = 0;
245 myTextNode = 0;
246 myGreenLight = 0;
247 myYellowLight = 0;
248 myRedLight = 0;
249 myRedYellowLight = 0;
250 myPoleBase = 0;
251}
252
253
254void
255GUIOSGView::adoptViewSettings() {
256 // lighting
257 osg::Light* globalLight = myViewer->getLight();
258 globalLight->setAmbient(toOSGColorVector(myVisualizationSettings->ambient3DLight));
259 globalLight->setDiffuse(toOSGColorVector(myVisualizationSettings->diffuse3DLight));
260 myViewer->getCamera()->setClearColor(toOSGColorVector(myVisualizationSettings->skyColor));
261
262 // ground color
263 osg::Geode* planeGeode = dynamic_cast<osg::Geode*>(myPlane->getChild(0));
264 osg::Geometry* planeGeom = dynamic_cast<osg::Geometry*>(planeGeode->getChild(0));
265 osg::Vec4ubArray* colors = dynamic_cast<osg::Vec4ubArray*>(planeGeom->getColorArray());
266 (*colors)[0].set(myVisualizationSettings->backgroundColor.red(),
267 myVisualizationSettings->backgroundColor.green(),
268 myVisualizationSettings->backgroundColor.blue(),
269 myVisualizationSettings->backgroundColor.alpha());
270 planeGeom->setColorArray(colors);
271
272 // show/hide OSG nodes
273 unsigned int cullMask = 0xFFFFFFFF;
274 if (!myVisualizationSettings->show3DTLSDomes) {
275 cullMask &= ~(unsigned int)NODESET_TLSDOMES;
276 }
277 if (!myVisualizationSettings->show3DTLSLinkMarkers) {
278 cullMask &= ~(unsigned int)NODESET_TLSLINKMARKERS;
279 }
280 if (!myVisualizationSettings->generate3DTLSModels) {
281 cullMask &= ~(unsigned int)NODESET_TLSMODELS;
282 }
283 myViewer->getCamera()->setCullMask(cullMask);
284 unsigned int hudCullMask = (myVisualizationSettings->show3DHeadUpDisplay) ? 0xFFFFFFFF : 0;
285 myHUD->setCullMask(hudCullMask);
286}
287
288
290GUIOSGView::getPositionInformation() const {
291 Position pos;
292 getPositionAtCursor(myOSGNormalizedCursorX, myOSGNormalizedCursorY, pos);
293 return pos;
294}
295
296
297bool
298GUIOSGView::is3DView() const {
299 return true;
300}
301
302
303void
304GUIOSGView::buildViewToolBars(GUIGlChildWindow* v) {
305 // build coloring tools
306 {
307 const std::vector<std::string>& names = gSchemeStorage.getNames();
308 for (std::vector<std::string>::const_iterator i = names.begin(); i != names.end(); ++i) {
309 v->getColoringSchemesCombo()->appendIconItem(i->c_str());
310 if ((*i) == myVisualizationSettings->name) {
312 }
313 }
314 }
315 // for junctions
317 "Locate Junction", "Locate a junction within the network.", "",
320 // for edges
322 "Locate Street", "Locate a street within the network.", "",
325 // for vehicles
327 "Locate Vehicle", "Locate a vehicle within the network.", "",
330 // for persons
332 "Locate Person", "Locate a person within the network.", "",
335 // for containers
337 "Locate Container", "Locate a container within the network.", "",
340 // for tls
342 "Locate TLS", "Locate a tls within the network.", "",
345 // for additional stuff
347 "Locate Additional", "Locate an additional structure within the network.", "",
350 // for pois
352 "Locate POI", "Locate a POI within the network.", "",
355 // for polygons
357 "Locate Polygon", "Locate a Polygon within the network.", "",
360}
361
362
363void
364GUIOSGView::resize(int w, int h) {
365 GUISUMOAbstractView::resize(w, h);
366 updateHUDPosition(w, h);
367}
368
369
370void
371GUIOSGView::position(int x, int y, int w, int h) {
372 GUISUMOAbstractView::position(x, y, w, h);
373 updateHUDPosition(w, h);
374}
375
376
377void
378GUIOSGView::updateHUDPosition(int w, int h) {
379 // keep the HUD text in the left top corner
380 myHUD->setProjectionMatrixAsOrtho2D(0, w, 0, h);
381 myText->setPosition(osg::Vec3d(0., static_cast<double>(height), 0.));
382}
383
384
385void
386GUIOSGView::updateHUDText(const std::string text) {
387 myText->setText(text, osgText::String::ENCODING_UTF8);
388}
389
390
391void
392GUIOSGView::recenterView() {
393 stopTrack();
394 Position center = myGrid->getCenter();
395 double radius = std::max(myGrid->xmax() - myGrid->xmin(), myGrid->ymax() - myGrid->ymin());
396 myChanger->centerTo(center, radius);
397}
398
399
400bool
401GUIOSGView::setColorScheme(const std::string& name) {
402 if (!gSchemeStorage.contains(name)) {
403 return false;
404 }
405 if (myGUIDialogViewSettings != 0) {
406 if (myGUIDialogViewSettings->getCurrentScheme() != name) {
407 myGUIDialogViewSettings->setCurrentScheme(name);
408 }
409 }
410 myVisualizationSettings = &gSchemeStorage.get(name.c_str());
411 myVisualizationSettings->gaming = myApp->isGaming();
412 adoptViewSettings();
413 update();
414 return true;
415}
416
417
418long
419GUIOSGView::onPaint(FXObject*, FXSelector, void*) {
420 if (!isEnabled()) {
421 return 1;
422 }
423 myDecalsLockMutex.lock();
424 for (GUISUMOAbstractView::Decal& d : myDecals) {
425 if (!d.initialised && d.filename.length() > 0) {
426 if (d.filename.length() == 6 && d.filename.substr(0, 5) == "light") {
427 GUIOSGBuilder::buildLight(d, *myRoot);
428 } else if (d.filename.length() > 3 && d.filename.substr(0, 3) == "tl:") {
429 const int linkStringIdx = (int)d.filename.find(':', 3);
430 GUINet* net = (GUINet*) MSNet::getInstance();
431 try {
432 const std::string tlLogic = d.filename.substr(3, linkStringIdx - 3);
434 const int linkIdx = StringUtils::toInt(d.filename.substr(linkStringIdx + 1));
435 if (linkIdx < 0 || linkIdx >= static_cast<int>(vars.getActive()->getLinks().size())) {
436 throw NumberFormatException("");
437 }
438 const MSLink* const link = vars.getActive()->getLinksAt(linkIdx)[0];
439 osg::Group* tlNode = GUIOSGBuilder::getTrafficLight(d, vars, link, myGreenLight, myYellowLight, myRedLight, myRedYellowLight, myPoleBase, true, 0.5);
440 tlNode->setName("tlLogic:" + tlLogic);
441 myRoot->addChild(tlNode);
442 } catch (NumberFormatException&) {
443 WRITE_ERRORF(TL("Invalid link index in '%'."), d.filename);
444 } catch (InvalidArgument&) {
445 WRITE_ERRORF(TL("Unknown traffic light in '%'."), d.filename);
446 }
447 } else {
448 GUIOSGBuilder::buildDecal(d, *myRoot);
449 }
450 d.initialised = true;
451 }
452 }
453 myDecalsLockMutex.unlock();
454
455 // reset active flag
456 for (auto& item : myVehicles) {
457 item.second.active = false;
458 }
459
460 GUINet* net = static_cast<GUINet*>(MSNet::getInstance());
461 // build edges
462 for (const MSEdge* e : net->getEdgeControl().getEdges()) {
463 for (const MSLane* l : e->getLanes()) {
464 const MSLane::VehCont& vehicles = l->getVehiclesSecure();
465 for (MSVehicle* msVeh : vehicles) {
466 GUIVehicle* veh = static_cast<GUIVehicle*>(msVeh);
467 if (!(veh->isOnRoad() || veh->isParking() || veh->wasRemoteControlled())) {
468 continue;
469 }
470 auto itVeh = myVehicles.find(veh);
471 if (itVeh == myVehicles.end()) {
472 myVehicles[veh] = GUIOSGBuilder::buildMovable(veh->getVehicleType());
473 myRoot->addChild(myVehicles[veh].pos);
474 myVehicles[veh].pos->setName("vehicle:" + veh->getID());
475 veh->setNode(myVehicles[veh].pos);
476 } else {
477 itVeh->second.active = true;
478 }
479 osg::PositionAttitudeTransform* n = myVehicles[veh].pos;
480 n->setPosition(osg::Vec3d(veh->getPosition().x(), veh->getPosition().y(), veh->getPosition().z()));
481 const double dir = veh->getAngle() + M_PI / 2.;
482 const double slope = -veh->getSlope();
483 n->setAttitude(osg::Quat(osg::DegreesToRadians(slope), osg::Vec3(1, 0, 0),
484 0, osg::Vec3(0, 1, 0),
485 dir, osg::Vec3(0, 0, 1)));
486 /*
487 osg::ref_ptr<osg::AnimationPath> path = new osg::AnimationPath;
488 // path->setLoopMode( osg::AnimationPath::NO_LOOPING );
489 osg::AnimationPath::ControlPoint pointA(n->getPosition(), n->getAttitude());
490 osg::AnimationPath::ControlPoint pointB(osg::Vec3(veh->getPosition().x(), veh->getPosition().y(), veh->getPosition().z()),
491 osg::Quat(dir, osg::Vec3(0, 0, 1)) *
492 osg::Quat(osg::DegreesToRadians(slope), osg::Vec3(0, 1, 0)));
493 path->insert(0.0f, pointA);
494 path->insert(0.5f, pointB);
495 n->setUpdateCallback(new osg::AnimationPathCallback(path));
496 */
497
498 if (myVisualizationSettings->ignoreColorSchemeFor3DVehicles) {
499 myVehicles[veh].activateMaterial(false);
500 } else {
501 myVehicles[veh].activateMaterial(true);
502 RGBColor col;
503 if (!GUIBaseVehicle::setFunctionalColor(myVisualizationSettings->vehicleColorer.getActive(), veh, col)) {
504 col = myVisualizationSettings->vehicleColorer.getScheme().getColor(veh->getColorValue(*myVisualizationSettings, myVisualizationSettings->vehicleColorer.getActive()));
505 }
506 myVehicles[veh].mat->setDiffuse(osg::Material::FRONT_AND_BACK, osg::Vec4d(col.red() / 255., col.green() / 255., col.blue() / 255., col.alpha() / 255.));
507 }
510 myVehicles[veh].lights->setValue(2, veh->signalSet(MSVehicle::VEH_SIGNAL_BRAKELIGHT));
511 }
512 l->releaseVehicles();
513 }
514 }
515 // remove inactive
516 for (auto veh = myVehicles.begin(); veh != myVehicles.end();) {
517 if (!veh->second.active) {
518 removeVeh((veh++)->first);
519 } else {
520 ++veh;
521 }
522 }
523
525 if (now != myLastUpdate || (myGUIDialogViewSettings != 0 && myGUIDialogViewSettings->shown())) {
526 GUINet::getGUIInstance()->updateColor(*myVisualizationSettings);
527 }
528 if (now != myLastUpdate && myTracked != 0) {
529 osg::Vec3d lookFrom, lookAt, up;
530 lookAt[0] = myTracked->getPosition().x();
531 lookAt[1] = myTracked->getPosition().y();
532 lookAt[2] = myTracked->getPosition().z();
533 const double angle = myTracked->getAngle();
534 lookFrom[0] = lookAt[0] + 50. * cos(angle);
535 lookFrom[1] = lookAt[1] + 50. * sin(angle);
536 lookFrom[2] = lookAt[2] + 10.;
537 osg::Matrix m;
538 m.makeLookAt(lookFrom, lookAt, osg::Z_AXIS);
539 myViewer->getCameraManipulator()->setByInverseMatrix(m);
540 }
541
542 // reset active flag
543 for (auto& item : myPersons) {
544 item.second.active = false;
545 }
546
547 for (const MSEdge* e : net->getEdgeControl().getEdges()) {
548 const GUIEdge* ge = static_cast<const GUIEdge*>(e);
549 const std::set<MSTransportable*, ComparatorNumericalIdLess>& persons = ge->getPersonsSecure();
550 for (auto person : persons) {
551 if (person->hasArrived() || !person->hasDeparted()) {
552 //std::cout << SIMTIME << " person " << person->getID() << " is loaded but arrived\n";
553 continue;
554 }
555 auto itPers = myPersons.find(person);
556 if (itPers == myPersons.end()) {
557 myPersons[person] = GUIOSGBuilder::buildMovable(person->getVehicleType());
558 myRoot->addChild(myPersons[person].pos);
559 } else {
560 itPers->second.active = true;
561 }
562 osg::PositionAttitudeTransform* n = myPersons[person].pos;
563 const Position pos = person->getPosition();
564 n->setPosition(osg::Vec3d(pos.x(), pos.y(), pos.z()));
565 const double dir = person->getAngle() + M_PI / 2.;
566 n->setAttitude(osg::Quat(dir, osg::Vec3d(0, 0, 1)));
567
568 RGBColor col;
569 GUIPerson* actualPerson = dynamic_cast<GUIPerson*>(person);
570 if (!GUIPerson::setFunctionalColor(myVisualizationSettings->personColorer.getActive(), actualPerson, col)) {
571 col = myVisualizationSettings->personColorer.getScheme().getColor(actualPerson->getColorValue(*myVisualizationSettings, myVisualizationSettings->vehicleColorer.getActive()));
572 }
573 myPersons[person].mat->setDiffuse(osg::Material::FRONT_AND_BACK, osg::Vec4d(col.red() / 255., col.green() / 255., col.blue() / 255., col.alpha() / 255.));
574 }
575 ge->releasePersons();
576 }
577
578 // remove inactive
579 for (auto person = myPersons.begin(); person != myPersons.end();) {
580 if (!person->second.active) {
581 removeTransportable((person++)->first);
582 } else {
583 ++person;
584 }
585 }
586
587 if (myAdapter->makeCurrent()) {
588 myViewer->frame();
589 makeNonCurrent();
590 }
591 myLastUpdate = now;
592 return 1;
593}
594
595
596void
597GUIOSGView::removeVeh(MSVehicle* veh) {
598 if (myTracked == veh) {
599 stopTrack();
600 }
601 std::map<MSVehicle*, OSGMovable>::iterator i = myVehicles.find(veh);
602 if (i != myVehicles.end()) {
603 myRoot->removeChild(i->second.pos);
604 myVehicles.erase(i);
605 }
606}
607
608
609void
610GUIOSGView::removeTransportable(MSTransportable* t) {
611 std::map<MSTransportable*, OSGMovable>::iterator i = myPersons.find(t);
612 if (i != myPersons.end()) {
613 myRoot->removeChild(i->second.pos);
614 myPersons.erase(i);
615 }
616}
617
618
619void GUIOSGView::updateViewportValues() {
620 osg::Vec3d lookFrom, lookAt, up;
621 myViewer->getCameraManipulator()->getInverseMatrix().getLookAt(lookFrom, lookAt, up);
622 myGUIDialogEditViewport->setValues(Position(lookFrom[0], lookFrom[1], lookFrom[2]),
623 Position(lookAt[0], lookAt[1], lookAt[2]), calculateRotation(lookFrom, lookAt, up));
624}
625
626
627void
628GUIOSGView::showViewportEditor() {
629 getViewportEditor(); // make sure it exists;
630 osg::Vec3d lookFrom, lookAt, up;
631 myViewer->getCameraManipulator()->getInverseMatrix().getLookAt(lookFrom, lookAt, up);
632 Position from(lookFrom[0], lookFrom[1], lookFrom[2]), at(lookAt[0], lookAt[1], lookAt[2]);
633 myGUIDialogEditViewport->setOldValues(from, at, calculateRotation(lookFrom, lookAt, up));
634 myGUIDialogEditViewport->setZoomValue(100);
635 myGUIDialogEditViewport->show();
636}
637
638
639void
640GUIOSGView::setViewportFromToRot(const Position& lookFrom, const Position& lookAt, double rotation) {
641 osg::Vec3d lookFromOSG, lookAtOSG, up;
642 lookFromOSG[0] = lookFrom.x();
643 lookFromOSG[1] = lookFrom.y();
644 lookFromOSG[2] = lookFrom.z();
645 lookAtOSG[0] = lookAt.x();
646 lookAtOSG[1] = lookAt.y();
647 lookAtOSG[2] = lookAt.z();
648
649 osg::Vec3d viewAxis, viewUp, orthogonal, normal;
650 viewAxis = lookFromOSG - lookAtOSG;
651 viewAxis.normalize();
652 viewUp = (viewAxis[0] + viewAxis[1] == 0.) ? osg::Vec3d(0., 1., 0.) : osg::Vec3d(0., 0., 1.); // check for parallel vectors
653 orthogonal = viewUp ^ viewAxis;
654 orthogonal.normalize();
655 normal = viewAxis ^ orthogonal;
656
657 rotation = std::fmod(rotation, 360.);
658 if (rotation < 0) {
659 rotation += 360.;
660 }
661 myChanger->setRotation(rotation);
662 double angle = DEG2RAD(rotation);
663 up = normal * cos(angle) - orthogonal * sin(angle);
664 up.normalize();
665
666 double zoom = (myGUIDialogEditViewport != nullptr) ? myGUIDialogEditViewport->getZoomValue() : 100.;
667 lookFromOSG = lookFromOSG + viewAxis * (100. - zoom);
668 lookAtOSG = lookFromOSG - viewAxis;
669 myViewer->getCameraManipulator()->setHomePosition(lookFromOSG, lookAtOSG, up);
670 myViewer->home();
671}
672
673
674void
675GUIOSGView::copyViewportTo(GUISUMOAbstractView* view) {
676 osg::Vec3d lookFrom, lookAt, up;
677 myViewer->getCameraManipulator()->getHomePosition(lookFrom, lookAt, up);
678 view->setViewportFromToRot(Position(lookFrom[0], lookFrom[1], lookFrom[2]),
679 Position(lookAt[0], lookAt[1], lookAt[2]), 0);
680}
681
682
683void
684GUIOSGView::startTrack(int id) {
685 if (myTracked == 0 || (int)myTracked->getGlID() != id) {
686 myTracked = 0;
688 for (; it != MSNet::getInstance()->getVehicleControl().loadedVehEnd(); it++) {
689 GUIVehicle* veh = (GUIVehicle*)(*it).second;
690 if ((int)veh->getGlID() == id) {
691 if (!veh->isOnRoad() || myVehicles.find(veh) == myVehicles.end()) {
692 return;
693 }
694 myTracked = veh;
695 break;
696 }
697 }
698 if (myTracked != 0) {
699 osg::Vec3d lookFrom, lookAt, up;
700 lookAt[0] = myTracked->getPosition().x();
701 lookAt[1] = myTracked->getPosition().y();
702 lookAt[2] = myTracked->getPosition().z();
703 lookFrom[0] = lookAt[0] + 50.;
704 lookFrom[1] = lookAt[1] + 50.;
705 lookFrom[2] = lookAt[2] + 10.;
706 osg::Matrix m;
707 m.makeLookAt(lookFrom, lookAt, osg::Z_AXIS);
708 myViewer->getCameraManipulator()->setByInverseMatrix(m);
709 }
710 }
711}
712
713
714void
715GUIOSGView::stopTrack() {
716 myTracked = 0;
717}
718
719
721GUIOSGView::getTrackedID() const {
722 return myTracked == 0 ? GUIGlObject::INVALID_ID : myTracked->getGlID();
723}
724
725
726void
727GUIOSGView::onGamingClick(Position pos) {
729 const MSTrafficLightLogic* minTll = nullptr;
730 double minDist = std::numeric_limits<double>::infinity();
731 for (const MSTrafficLightLogic* const tll : tlsControl.getAllLogics()) {
732 if (tlsControl.isActive(tll)) {
733 // get the links
734 const MSTrafficLightLogic::LaneVector& lanes = tll->getLanesAt(0);
735 if (lanes.size() > 0) {
736 const Position& endPos = lanes[0]->getShape().back();
737 if (endPos.distanceTo(pos) < minDist) {
738 minDist = endPos.distanceTo(pos);
739 minTll = tll;
740 }
741 }
742 }
743 }
744 if (minTll != 0) {
745 const MSTLLogicControl::TLSLogicVariants& vars = tlsControl.get(minTll->getID());
746 const std::vector<MSTrafficLightLogic*> logics = vars.getAllLogics();
747 if (logics.size() > 1) {
749 for (int i = 0; i < (int)logics.size() - 1; i++) {
750 if (minTll->getProgramID() == logics[i]->getProgramID()) {
751 l = (MSSimpleTrafficLightLogic*) logics[i + 1];
752 tlsControl.switchTo(minTll->getID(), l->getProgramID());
753 }
754 }
755 if (l == logics[0]) {
756 tlsControl.switchTo(minTll->getID(), l->getProgramID());
757 }
759 update();
760 }
761 }
762}
763
764
766GUIOSGView::getCurrentTimeStep() const {
768}
769
770
771long GUIOSGView::onConfigure(FXObject* sender, FXSelector sel, void* ptr) {
772 // update the window dimensions, in case the window has been resized.
773 const int w = getWidth();
774 const int h = getHeight();
775 if (w > 0 && h > 0) {
776 myAdapter->getEventQueue()->windowResize(0, 0, w, h);
777 myAdapter->resized(0, 0, w, h);
778 updateHUDPosition(w, h);
779 }
780 return FXGLCanvas::onConfigure(sender, sel, ptr);
781}
782
783
784long GUIOSGView::onKeyPress(FXObject* sender, FXSelector sel, void* ptr) {
785 int key = ((FXEvent*)ptr)->code;
786 myAdapter->getEventQueue()->keyPress(key);
787 // leave key handling for some cases to OSG
788 if (key == FX::KEY_f || key == FX::KEY_Left || key == FX::KEY_Right || key == FX::KEY_Up || key == FX::KEY_Down) {
789 return 1;
790 }
791 return FXGLCanvas::onKeyPress(sender, sel, ptr);
792}
793
794
795long GUIOSGView::onKeyRelease(FXObject* sender, FXSelector sel, void* ptr) {
796 int key = ((FXEvent*)ptr)->code;
797 myAdapter->getEventQueue()->keyRelease(key);
798 // leave key handling for some cases to OSG
799 if (key == FX::KEY_f || key == FX::KEY_Left || key == FX::KEY_Right || key == FX::KEY_Up || key == FX::KEY_Down) {
800 return 1;
801 }
802 return FXGLCanvas::onKeyRelease(sender, sel, ptr);
803}
804
805
806long GUIOSGView::onLeftBtnPress(FXObject* sender, FXSelector sel, void* ptr) {
807 handle(this, FXSEL(SEL_FOCUS_SELF, 0), ptr);
808
809 FXEvent* event = (FXEvent*)ptr;
810 myAdapter->getEventQueue()->mouseButtonPress((float)event->click_x, (float)event->click_y, 1);
811 if (myApp->isGaming()) {
812 onGamingClick(getPositionInformation());
813 }
814
815 return FXGLCanvas::onLeftBtnPress(sender, sel, ptr);
816}
817
818
819long GUIOSGView::onLeftBtnRelease(FXObject* sender, FXSelector sel, void* ptr) {
820 FXEvent* event = (FXEvent*)ptr;
821 myAdapter->getEventQueue()->mouseButtonRelease((float)event->click_x, (float)event->click_y, 1);
822 myChanger->onLeftBtnRelease(ptr);
823 return FXGLCanvas::onLeftBtnRelease(sender, sel, ptr);
824}
825
826
827long GUIOSGView::onMiddleBtnPress(FXObject* sender, FXSelector sel, void* ptr) {
828 handle(this, FXSEL(SEL_FOCUS_SELF, 0), ptr);
829
830 FXEvent* event = (FXEvent*)ptr;
831 myAdapter->getEventQueue()->mouseButtonPress((float)event->click_x, (float)event->click_y, 2);
832
833 return FXGLCanvas::onMiddleBtnPress(sender, sel, ptr);
834}
835
836
837long GUIOSGView::onMiddleBtnRelease(FXObject* sender, FXSelector sel, void* ptr) {
838 FXEvent* event = (FXEvent*)ptr;
839 myAdapter->getEventQueue()->mouseButtonRelease((float)event->click_x, (float)event->click_y, 2);
840 myChanger->onMiddleBtnRelease(ptr);
841 return FXGLCanvas::onMiddleBtnRelease(sender, sel, ptr);
842}
843
844
845long GUIOSGView::onRightBtnPress(FXObject* sender, FXSelector sel, void* ptr) {
846 handle(this, FXSEL(SEL_FOCUS_SELF, 0), ptr);
847
848 FXEvent* event = (FXEvent*)ptr;
849 myAdapter->getEventQueue()->mouseButtonPress((float)event->click_x, (float)event->click_y, 3);
850
851 return FXGLCanvas::onRightBtnPress(sender, sel, ptr);
852}
853
854
855long GUIOSGView::onRightBtnRelease(FXObject* sender, FXSelector sel, void* ptr) {
856 FXEvent* event = (FXEvent*)ptr;
857 myAdapter->getEventQueue()->mouseButtonRelease((float)event->click_x, (float)event->click_y, 3);
858 myChanger->onRightBtnRelease(ptr);
859 return FXGLCanvas::onRightBtnRelease(sender, sel, ptr);
860}
861
862
863long
864GUIOSGView::onMouseMove(FXObject* sender, FXSelector sel, void* ptr) {
865 // if popup exist but isn't shown, destroy it first
866 if (myPopup && !myPopup->shown()) {
867 destroyPopup();
868 }
869
870 FXEvent* event = (FXEvent*)ptr;
871 osgGA::GUIEventAdapter* ea = myAdapter->getEventQueue()->mouseMotion((float)event->win_x, (float)event->win_y);
872 setWindowCursorPosition(ea->getXnormalized(), ea->getYnormalized());
873 if (myGUIDialogEditViewport != nullptr && myGUIDialogEditViewport->shown()) {
874 updateViewportValues();
875 }
876 updatePositionInformation();
877 return FXGLCanvas::onMotion(sender, sel, ptr);
878}
879
880
881long
882GUIOSGView::onIdle(FXObject* /* sender */, FXSelector /* sel */, void*) {
883 forceRefresh();
884 update();
885 getApp()->addChore(this, MID_CHORE);
886 return 1;
887}
888
889
890long
891GUIOSGView::onCmdCloseLane(FXObject*, FXSelector, void*) {
892 GUILane* lane = getLaneUnderCursor();
893 if (lane != nullptr) {
894 lane->closeTraffic();
896 GUINet::getGUIInstance()->updateColor(*myVisualizationSettings);
897 update();
898 }
899 return 1;
900}
901
902
903long
904GUIOSGView::onCmdCloseEdge(FXObject*, FXSelector, void*) {
905 GUILane* lane = getLaneUnderCursor();
906 if (lane != nullptr) {
907 dynamic_cast<GUIEdge*>(&lane->getEdge())->closeTraffic(lane);
909 GUINet::getGUIInstance()->updateColor(*myVisualizationSettings);
910 update();
911 }
912 return 1;
913}
914
915
916long
917GUIOSGView::onCmdAddRerouter(FXObject*, FXSelector, void*) {
918 GUILane* lane = getLaneUnderCursor();
919 if (lane != nullptr) {
920 dynamic_cast<GUIEdge*>(&lane->getEdge())->addRerouter();
922 update();
923 }
924 return 1;
925}
926
927
928long
929GUIOSGView::onCmdShowReachability(FXObject* menu, FXSelector selector, void*) {
930 GUILane* lane = getLaneUnderCursor();
931 if (lane != nullptr) {
932 // reset
933 GUIViewTraffic::showLaneReachability(lane, menu, selector);
934 // switch to 'color by selection' unless coloring 'by reachability'
935 if (myVisualizationSettings->laneColorer.getActive() != 36) {
936 myVisualizationSettings->laneColorer.setActive(1);
937 GUINet::getGUIInstance()->updateColor(*myVisualizationSettings);
938 }
939 update();
940 }
941 return 1;
942}
943
944
945long
946GUIOSGView::onVisualizationChange(FXObject*, FXSelector, void*) {
947 adoptViewSettings();
948 return 1;
949}
950
951
952void
953GUIOSGView::setWindowCursorPosition(float x, float y) {
954 myOSGNormalizedCursorX = x;
955 myOSGNormalizedCursorY = y;
956}
957
958
959double
960GUIOSGView::calculateRotation(const osg::Vec3d& lookFrom, const osg::Vec3d& lookAt, const osg::Vec3d& up) {
961 osg::Vec3d viewAxis, viewUp, orthogonal, normal;
962 viewAxis = lookFrom - lookAt;
963 viewAxis.normalize();
964 viewUp = (abs(viewAxis[0]) + abs(viewAxis[1]) == 0.) ? osg::Y_AXIS : osg::Z_AXIS; // check for parallel vectors
965 orthogonal = viewUp ^ viewAxis;
966 orthogonal.normalize();
967 normal = viewAxis ^ orthogonal;
968 double angle = atan2((normal ^ up).length() / (normal.length() * up.length()), (normal * up) / (normal.length() * up.length()));
969 if (angle < 0) {
970 angle += M_PI;
971 }
972 return RAD2DEG(angle);
973}
974
975
976void
977GUIOSGView::updatePositionInformation() const {
978 Position pos;
979 if (getPositionAtCursor(myOSGNormalizedCursorX, myOSGNormalizedCursorY, pos)) {
980 myApp->getCartesianLabel()->setText(("x:" + toString(pos.x()) + ", y:" + toString(pos.y())).c_str());
981 // set geo position
983 if (GeoConvHelper::getFinal().usingGeoProjection()) {
984 myApp->getGeoLabel()->setText(("lat:" + toString(pos.y(), gPrecisionGeo) + ", lon:" + toString(pos.x(), gPrecisionGeo)).c_str());
985 } else {
986 myApp->getGeoLabel()->setText(TL("(No projection defined)"));
987 }
988 } else {
989 // set placeholder
990 myApp->getCartesianLabel()->setText(TL("N/A"));
991 myApp->getGeoLabel()->setText(TL("N/A"));
992 }
993}
994
995
996bool
997GUIOSGView::getPositionAtCursor(float xNorm, float yNorm, Position& pos) const {
998 // only reasonable if view axis points to the ground (not parallel to the ground or in the sky)
999 osg::Vec3d lookFrom, lookAt, up, viewAxis;
1000 myViewer->getCameraManipulator()->getInverseMatrix().getLookAt(lookFrom, lookAt, up);
1001 if ((lookAt - lookFrom).z() >= 0.) {
1002 // looking to the sky makes position at ground pointless
1003 return false;
1004 }
1005 // solve linear equation of ray crossing the ground plane
1006 osg::Matrixd iVP = osg::Matrixd::inverse(myViewer->getCamera()->getViewMatrix() * myViewer->getCamera()->getProjectionMatrix());
1007 osg::Vec3 nearPoint = osg::Vec3(xNorm, yNorm, 0.0f) * iVP;
1008 osg::Vec3 farPoint = osg::Vec3(xNorm, yNorm, 1.0f) * iVP;
1009 osg::Vec3 ray = farPoint - nearPoint;
1010 osg::Vec3 groundPos = nearPoint - ray * nearPoint.z() / ray.z();
1011 pos.setx(groundPos.x());
1012 pos.sety(groundPos.y());
1013 pos.setz(0.);
1014 return true;
1015}
1016
1017
1018std::vector<GUIGlObject*>
1019GUIOSGView::getGUIGlObjectsUnderCursor() {
1020 std::vector<GUIGlObject*> result;
1021 osgUtil::LineSegmentIntersector::Intersections intersections;
1022 if (myViewer->computeIntersections(myViewer->getCamera(), osgUtil::Intersector::CoordinateFrame::PROJECTION, myOSGNormalizedCursorX, myOSGNormalizedCursorY, intersections)) {
1023 for (auto intersection : intersections) {
1024 if (!intersection.nodePath.empty()) {
1025 // the object is identified by the ID stored in OSG
1026 for (osg::Node* currentNode : intersection.nodePath) {
1027 if (currentNode->getName().length() > 0 && currentNode->getName().find(":") != std::string::npos) {
1028 const std::string objID = currentNode->getName();
1030 // check that GUIGlObject exist
1031 if (o == nullptr) {
1032 continue;
1033 }
1034 // check that GUIGlObject isn't the network
1035 if (o->getGlID() == 0) {
1036 continue;
1037 }
1038 result.push_back(o);
1039 // unblock object
1041 }
1042 }
1043 }
1044 }
1045 }
1046 return result;
1047}
1048
1049
1050GUILane*
1051GUIOSGView::getLaneUnderCursor() {
1052 std::vector<GUIGlObject*> objects = getGUIGlObjectsUnderCursor();
1053 if (objects.size() > 0) {
1054 return dynamic_cast<GUILane*>(objects[0]);
1055 }
1056 return nullptr;
1057}
1058
1059
1060void
1061GUIOSGView::zoom2Pos(Position& camera, Position& lookAt, double zoom) {
1062 osg::Vec3d lookFromOSG, lookAtOSG, viewAxis, up;
1063 myViewer->getCameraManipulator()->getInverseMatrix().getLookAt(lookFromOSG, lookAtOSG, up);
1064 lookFromOSG[0] = camera.x();
1065 lookFromOSG[1] = camera.y();
1066 lookFromOSG[2] = camera.z();
1067 lookAtOSG[0] = lookAt.x();
1068 lookAtOSG[1] = lookAt.y();
1069 lookAtOSG[2] = lookAt.z();
1070 viewAxis = lookAtOSG - lookFromOSG;
1071 viewAxis.normalize();
1072
1073 // compute new camera and lookAt pos
1074 osg::Vec3d cameraUpdate = lookFromOSG + viewAxis * (zoom - 100.);
1075 osg::Vec3d lookAtUpdate = cameraUpdate + viewAxis;
1076
1077 myViewer->getCameraManipulator()->setHomePosition(cameraUpdate, lookAtUpdate, up);
1078 myViewer->home();
1079}
1080
1081
1082osg::Vec4d
1083GUIOSGView::toOSGColorVector(RGBColor c, bool useAlpha) {
1084 return osg::Vec4d(c.red() / 255., c.green() / 255., c.blue() / 255., (useAlpha) ? c.alpha() / 255. : 1.);
1085}
1086
1087
1088GUIOSGView::FXOSGAdapter::FXOSGAdapter(GUISUMOAbstractView* parent, FXCursor* cursor)
1089 : myParent(parent), myOldCursor(cursor) {
1090 _traits = new GraphicsContext::Traits();
1091 _traits->x = 0;
1092 _traits->y = 0;
1093 _traits->width = parent->getWidth();
1094 _traits->height = parent->getHeight();
1095 _traits->windowDecoration = false;
1096 _traits->doubleBuffer = true;
1097 _traits->sharedContext = 0;
1098 if (valid()) {
1099 setState(new osg::State());
1100 getState()->setGraphicsContext(this);
1101#ifdef DEBUG_GLERRORS
1102 getState()->setCheckForGLErrors(osg::State::ONCE_PER_ATTRIBUTE);
1103 std::cout << "OSG getCheckForGLErrors " << getState()->getCheckForGLErrors() << std::endl;
1104#endif
1105 if (_traits.valid() && _traits->sharedContext != 0) {
1106 getState()->setContextID(_traits->sharedContext->getState()->getContextID());
1107 incrementContextIDUsageCount(getState()->getContextID());
1108 } else {
1109 getState()->setContextID(createNewContextID());
1110 }
1111 }
1112}
1113
1114
1115GUIOSGView::FXOSGAdapter::~FXOSGAdapter() {
1116 delete myOldCursor;
1117}
1118
1119
1120void
1121GUIOSGView::FXOSGAdapter::grabFocus() {
1122 // focus this window
1123 myParent->setFocus();
1124}
1125
1126
1127void
1128GUIOSGView::FXOSGAdapter::useCursor(bool cursorOn) {
1129 if (cursorOn) {
1130 myParent->setDefaultCursor(myOldCursor);
1131 } else {
1132 myParent->setDefaultCursor(NULL);
1133 }
1134}
1135
1136
1137bool
1138GUIOSGView::FXOSGAdapter::makeCurrentImplementation() {
1139 myParent->makeCurrent();
1140 return true;
1141}
1142
1143
1144bool
1145GUIOSGView::FXOSGAdapter::releaseContext() {
1146 myParent->makeNonCurrent();
1147 return true;
1148}
1149
1150
1151void
1152GUIOSGView::FXOSGAdapter::swapBuffersImplementation() {
1153 myParent->swapBuffers();
1154}
1155
1156
1157bool
1158GUIOSGView::PickHandler::handle(const osgGA::GUIEventAdapter& ea, osgGA::GUIActionAdapter& /* aa */) {
1159 if (ea.getEventType() == osgGA::GUIEventAdapter::DRAG) {
1160 myDrag = true;
1161 } else if (ea.getEventType() == osgGA::GUIEventAdapter::RELEASE && ea.getButton() == osgGA::GUIEventAdapter::RIGHT_MOUSE_BUTTON) {
1162 if (!myDrag) {
1163 if (myParent->makeCurrent()) {
1164 std::vector<GUIGlObject*> objects = myParent->getGUIGlObjectsUnderCursor();
1165 if (objects.size() > 0) {
1166 myParent->openObjectDialog(objects);
1167 }
1168 myParent->makeNonCurrent();
1169 }
1170 }
1171 myDrag = false;
1172 }
1173 return false;
1174}
1175
1176
1177#endif
1178
1179/****************************************************************************/
long long int SUMOTime
Definition GUI.h:36
@ MID_CHORE
chore
Definition GUIAppEnum.h:413
@ MID_HOTKEY_SHIFT_O_LOCATEPOI
Locate poi - button.
Definition GUIAppEnum.h:182
@ MID_HOTKEY_SHIFT_A_LOCATEADDITIONAL
Locate additional structure - button.
Definition GUIAppEnum.h:172
@ MID_HOTKEY_SHIFT_C_LOCATECONTAINER
Locate container - button.
Definition GUIAppEnum.h:174
@ MID_HOTKEY_SHIFT_V_LOCATEVEHICLE
Locate vehicle - button.
Definition GUIAppEnum.h:192
@ MID_HOTKEY_SHIFT_L_LOCATEPOLY
Locate polygons - button.
Definition GUIAppEnum.h:180
@ MID_HOTKEY_SHIFT_E_LOCATEEDGE
Locate edge - button.
Definition GUIAppEnum.h:176
@ MID_HOTKEY_SHIFT_P_LOCATEPERSON
Locate person - button.
Definition GUIAppEnum.h:184
@ MID_HOTKEY_SHIFT_J_LOCATEJUNCTION
Locate junction - button.
Definition GUIAppEnum.h:178
@ MID_HOTKEY_SHIFT_T_LOCATETLS
Locate TLS - button.
Definition GUIAppEnum.h:190
GUICompleteSchemeStorage gSchemeStorage
#define GUIDesignButtonPopup
checkable button placed in popup (for example, locate buttons)
Definition GUIDesigns.h:130
FXDEFMAP(GUIDialog_AppSettings) GUIDialog_AppSettingsMap[]
unsigned int GUIGlID
Definition GUIGlObject.h:44
@ LOCATEVEHICLE
@ LOCATEPERSON
@ LOCATECONTAINER
@ LOCATEJUNCTION
#define DEG2RAD(x)
Definition GeomHelper.h:35
#define RAD2DEG(x)
Definition GeomHelper.h:36
std::ostream & operator<<(std::ostream &out, MSDevice_SSM::EncounterType type)
Nicer output for EncounterType enum.
#define WRITE_ERRORF(...)
Definition MsgHandler.h:297
#define WRITE_ERROR(msg)
Definition MsgHandler.h:296
#define TL(string)
Definition MsgHandler.h:305
@ LINKSTATE_TL_REDYELLOW
The link has red light (must brake) but indicates upcoming green.
@ LINKSTATE_STOP
This is an uncontrolled, minor link, has to stop.
@ LINKSTATE_TL_YELLOW_MAJOR
The link has yellow light, may pass.
@ LINKSTATE_TL_GREEN_MAJOR
The link has green light, may pass.
@ LINKSTATE_TL_OFF_BLINKING
The link is controlled by a tls which is off and blinks, has to brake.
@ LINKSTATE_TL_YELLOW_MINOR
The link has yellow light, has to brake anyway.
@ LINKSTATE_TL_RED
The link has red light (must brake)
@ LINKSTATE_TL_GREEN_MINOR
The link has green light, has to brake.
@ LINKSTATE_TL_OFF_NOSIGNAL
The link is controlled by a tls which is off, not blinking, may pass.
int gPrecisionGeo
Definition StdDefs.cpp:28
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
Definition ToString.h:46
static bool isReadable(std::string path)
Checks whether the given file is readable.
static bool setFunctionalColor(int activeScheme, const MSBaseVehicle *veh, RGBColor &col)
sets the color according to the current scheme index and some vehicle function
bool contains(const std::string &name) const
Returns the information whether a setting with the given name is stored.
GUIVisualizationSettings & get(const std::string &name)
Returns the named scheme.
const std::vector< std::string > & getNames() const
Returns a list of stored settings names.
static FXButton * buildFXButton(FXComposite *p, const std::string &text, const std::string &tip, const std::string &help, FXIcon *ic, FXObject *tgt, FXSelector sel, FXuint opts=BUTTON_NORMAL, FXint x=0, FXint y=0, FXint w=0, FXint h=0, FXint pl=DEFAULT_PAD, FXint pr=DEFAULT_PAD, FXint pt=DEFAULT_PAD, FXint pb=DEFAULT_PAD)
build button
A road/street connecting two junctions (gui-version)
Definition GUIEdge.h:51
void releasePersons() const
Allows to use the container for microsimulation again.
Definition GUIEdge.h:173
const std::set< MSTransportable *, ComparatorNumericalIdLess > & getPersonsSecure() const
Returns this edge's persons set; locks it for microsimulation.
Definition GUIEdge.h:164
MFXComboBoxIcon * getColoringSchemesCombo()
return combobox with the current coloring schemes (standard, fastest standard, real world....
FXPopup * getLocatorPopup()
@ brief return a pointer to locator popup
static const GUIGlID INVALID_ID
Definition GUIGlObject.h:73
GUIGlID getGlID() const
Returns the numerical id of the object.
void unblockObject(GUIGlID id)
Marks an object as unblocked.
GUIGlObject * getObjectBlocking(GUIGlID id) const
Returns the object from the container locking it.
static GUIGlObjectStorage gIDStorage
A single static instance of this class.
static FXIcon * getIcon(const GUIIcon which)
returns a icon previously defined in the enum GUIIcon
Representation of a lane in the micro simulation (gui-version)
Definition GUILane.h:60
void closeTraffic(bool rebuildAllowed=true)
close this lane for traffic
Definition GUILane.cpp:1593
A MSNet extended by some values for usage within the gui.
Definition GUINet.h:82
static GUINet * getGUIInstance()
Returns the pointer to the unique instance of GUINet (singleton).
Definition GUINet.cpp:572
double getColorValue(const GUIVisualizationSettings &s, int activeScheme) const override
gets the color value according to the current scheme index
static bool setFunctionalColor(int activeScheme, const MSPerson *person, RGBColor &col)
sets the color according to the current scheme index and some vehicle function
virtual void setViewportFromToRot(const Position &lookFrom, const Position &lookAt, double rotation)
applies the given viewport settings
A single child window which contains a view of the simulation area.
A MSVehicle extended by some values for usage within the gui.
Definition GUIVehicle.h:51
double getAngle() const
Return current angle.
Definition GUIVehicle.h:81
Position getPosition(const double offset=0) const
Return current position (x/y, cartesian)
Definition GUIVehicle.h:71
double getColorValue(const GUIVisualizationSettings &s, int activeScheme) const
gets the color value according to the current scheme index
static long showLaneReachability(GUILane *lane, FXObject *, FXSelector)
bool gaming
whether the application is in gaming mode or not
static const GeoConvHelper & getFinal()
the coordinate transformation for writing the location element and for tracking the original coordina...
void cartesian2geo(Position &cartesian) const
Converts the given cartesian (shifted) position to its geo (lat/long) representation.
long setCurrentItem(const FXint index, FXbool notify=FALSE)
Set the current item (index is zero-based)
FXint getNumItems() const
Return the number of items in the list.
FXint appendIconItem(const FXString &text, FXIcon *icon=nullptr, FXColor bgColor=FXRGB(255, 255, 255), void *ptr=nullptr)
append icon item in the last position
bool isParking() const
Returns whether the vehicle is parking.
const MSVehicleType & getVehicleType() const
Returns the vehicle's type definition.
A road/street connecting two junctions.
Definition MSEdge.h:77
Representation of a lane in the micro simulation.
Definition MSLane.h:84
std::vector< MSVehicle * > VehCont
Container for vehicles.
Definition MSLane.h:119
MSEdge & getEdge() const
Returns the lane's edge.
Definition MSLane.h:769
static MSNet * getInstance()
Returns the pointer to the unique instance of MSNet (singleton).
Definition MSNet.cpp:186
MSTLLogicControl & getTLSControl()
Returns the tls logics control.
Definition MSNet.h:457
SUMOTime getCurrentTimeStep() const
Returns the current simulation step.
Definition MSNet.h:326
MSVehicleControl & getVehicleControl()
Returns the vehicle control.
Definition MSNet.h:384
SUMOTime duration
The duration of the phase.
A fixed traffic light logic.
virtual void changeStepAndDuration(MSTLLogicControl &tlcontrol, SUMOTime simStep, int step, SUMOTime stepDuration) override
Changes the current phase and her duration.
const MSPhaseDefinition & getPhase(int givenstep) const override
Returns the definition of the phase from the given position within the plan.
Storage for all programs of a single tls.
std::vector< MSTrafficLightLogic * > getAllLogics() const
MSTrafficLightLogic * getActive() const
A class that stores and controls tls and switching of their programs.
void switchTo(const std::string &id, const std::string &programID)
Switches the named (id) tls to the named (programID) program.
TLSLogicVariants & get(const std::string &id) const
Returns the variants of a named tls.
bool isActive(const MSTrafficLightLogic *tl) const
Returns whether the given tls program is the currently active for his tls.
The parent class for traffic light logics.
const LinkVectorVector & getLinks() const
Returns the list of lists of all affected links.
std::vector< MSLane * > LaneVector
Definition of the list of arrival lanes subjected to this tls.
const std::string & getProgramID() const
Returns this tl-logic's id.
const LinkVector & getLinksAt(int i) const
Returns the list of links that are controlled by the signals at the given position.
std::map< std::string, SUMOVehicle * >::const_iterator constVehIt
Definition of the internal vehicles map iterator.
constVehIt loadedVehBegin() const
Returns the begin of the internal vehicle map.
constVehIt loadedVehEnd() const
Returns the end of the internal vehicle map.
Representation of a vehicle in the micro simulation.
Definition MSVehicle.h:77
bool wasRemoteControlled(SUMOTime lookBack=DELTA_T) const
Returns the information whether the vehicle is fully controlled via TraCI within the lookBack time.
bool isOnRoad() const
Returns the information whether the vehicle is on a road (is simulated)
Definition MSVehicle.h:605
bool signalSet(int which) const
Returns whether the given signal is on.
Definition MSVehicle.h:1187
Position getPosition(const double offset=0) const
Return current position (x/y, cartesian)
@ VEH_SIGNAL_BLINKER_RIGHT
Right blinker lights are switched on.
Definition MSVehicle.h:1109
@ VEH_SIGNAL_BRAKELIGHT
The brake lights are on.
Definition MSVehicle.h:1115
@ VEH_SIGNAL_BLINKER_LEFT
Left blinker lights are switched on.
Definition MSVehicle.h:1111
@ VEH_SIGNAL_BLINKER_EMERGENCY
Blinker lights on both sides are switched on.
Definition MSVehicle.h:1113
double getSlope() const
Returns the slope of the road at vehicle's position in degrees.
const std::string & getID() const
Returns the id.
Definition Named.h:74
A point in 2D or 3D with translation and scaling methods.
Definition Position.h:37
void setx(double x)
set position x
Definition Position.h:67
double distanceTo(const Position &p2) const
returns the euclidean distance in 3 dimensions
Definition Position.h:263
double x() const
Returns the x-position.
Definition Position.h:52
void setz(double z)
set position z
Definition Position.h:77
double z() const
Returns the z-position.
Definition Position.h:62
void sety(double y)
set position y
Definition Position.h:72
double y() const
Returns the y-position.
Definition Position.h:57
unsigned char red() const
Returns the red-amount of the color.
Definition RGBColor.cpp:74
unsigned char alpha() const
Returns the alpha-amount of the color.
Definition RGBColor.cpp:92
unsigned char green() const
Returns the green-amount of the color.
Definition RGBColor.cpp:80
unsigned char blue() const
Returns the blue-amount of the color.
Definition RGBColor.cpp:86
static int toInt(const std::string &sData)
converts a string into the integer value described by it by calling the char-type converter,...
@ key
the parser read a key of a value in an object
#define M_PI
Definition odrSpiral.cpp:45
A decal (an image) that can be shown.