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