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-2026 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 myFullScreenTextNode = new osg::Geode();
217 myFullScreenText = new osgText::Text;
218 myFullScreenText->setCharacterSizeMode(osgText::Text::SCREEN_COORDS);
219 myFullScreenText->setShaderTechnique(osgText::NO_TEXT_SHADER);
220 if (font != nullptr) {
221 myFullScreenText->setFont(font);
222 }
223 myFullScreenText->setCharacterSize(16.f);
224 myFullScreenText->setAlignment(osgText::TextBase::AlignmentType::RIGHT_BOTTOM);
225 myFullScreenText->setDrawMode(osgText::TextBase::DrawModeMask::FILLEDBOUNDINGBOX | osgText::TextBase::DrawModeMask::TEXT);
226 myFullScreenText->setBoundingBoxColor(osg::Vec4(0.0f, 0.0f, 0.0f, 0.6f));
227 myFullScreenText->setBoundingBoxMargin(6.0f);
228 myFullScreenText->setText(getFullScreenHintText(), osgText::String::ENCODING_UTF8);
229 myFullScreenTextNode->addDrawable(myFullScreenText);
230 myFullScreenTextNode->setNodeMask(0);
231
232 myHUD = new osg::Camera;
233 myHUD->setProjectionMatrixAsOrtho2D(0, 800, 0, 800); // default size will be overwritten
234 myHUD->setReferenceFrame(osg::Transform::ABSOLUTE_RF);
235 myHUD->setViewMatrix(osg::Matrix::identity());
236 myHUD->setClearMask(GL_DEPTH_BUFFER_BIT);
237 myHUD->setRenderOrder(osg::Camera::POST_RENDER);
238 myHUD->setAllowEventFocus(false);
239 myHUD->setGraphicsContext(myAdapter);
240 myHUD->addChild(myTextNode);
241 myHUD->addChild(myFullScreenTextNode);
242 myHUD->setViewport(0, 0, w, h);
243 myViewer->addSlave(myHUD, false);
244 myCameraManipulator->updateHUDText();
245
246 // adjust the main light
247 adoptViewSettings();
248 osgUtil::Optimizer optimizer;
249 optimizer.optimize(myRoot);
250}
251
252
253GUIOSGView::~GUIOSGView() {
254 getApp()->removeChore(this, MID_CHORE);
255 myViewer->setDone(true);
256 myViewer = 0;
257 myRoot = 0;
258 myAdapter = 0;
259 myCameraManipulator = 0;
260 myHUD = 0;
261 myText = 0;
262 myTextNode = 0;
263 myFullScreenText = 0;
264 myFullScreenTextNode = 0;
265 myGreenLight = 0;
266 myYellowLight = 0;
267 myRedLight = 0;
268 myRedYellowLight = 0;
269 myPoleBase = 0;
270}
271
272
273void
274GUIOSGView::adoptViewSettings() {
275 // lighting
276 osg::Light* globalLight = myViewer->getLight();
277 globalLight->setAmbient(toOSGColorVector(myVisualizationSettings->ambient3DLight));
278 globalLight->setDiffuse(toOSGColorVector(myVisualizationSettings->diffuse3DLight));
279 myViewer->getCamera()->setClearColor(toOSGColorVector(myVisualizationSettings->skyColor));
280
281 // ground color
282 osg::Geode* planeGeode = dynamic_cast<osg::Geode*>(myPlane->getChild(0));
283 osg::Geometry* planeGeom = dynamic_cast<osg::Geometry*>(planeGeode->getChild(0));
284 osg::Vec4ubArray* colors = dynamic_cast<osg::Vec4ubArray*>(planeGeom->getColorArray());
285 (*colors)[0].set(myVisualizationSettings->backgroundColor.red(),
286 myVisualizationSettings->backgroundColor.green(),
287 myVisualizationSettings->backgroundColor.blue(),
288 myVisualizationSettings->backgroundColor.alpha());
289 planeGeom->setColorArray(colors);
290
291 // show/hide OSG nodes
292 unsigned int cullMask = 0xFFFFFFFF;
293 if (!myVisualizationSettings->show3DTLSDomes) {
294 cullMask &= ~(unsigned int)NODESET_TLSDOMES;
295 }
296 if (!myVisualizationSettings->show3DTLSLinkMarkers) {
297 cullMask &= ~(unsigned int)NODESET_TLSLINKMARKERS;
298 }
299 if (!myVisualizationSettings->generate3DTLSModels) {
300 cullMask &= ~(unsigned int)NODESET_TLSMODELS;
301 }
302 myViewer->getCamera()->setCullMask(cullMask);
303 const unsigned int hudNodeMask = (myVisualizationSettings->show3DHeadUpDisplay) ? 0xFFFFFFFF : 0;
304 myTextNode->setNodeMask(hudNodeMask);
305}
306
307
309GUIOSGView::getPositionInformation() const {
310 Position pos;
311 getPositionAtCursor(myOSGNormalizedCursorX, myOSGNormalizedCursorY, pos);
312 return pos;
313}
314
315
316bool
317GUIOSGView::is3DView() const {
318 return true;
319}
320
321
322void
323GUIOSGView::buildViewToolBars(GUIGlChildWindow* v) {
324 // build coloring tools
325 {
326 const std::vector<std::string>& names = gSchemeStorage.getNames();
327 for (std::vector<std::string>::const_iterator i = names.begin(); i != names.end(); ++i) {
328 v->getColoringSchemesCombo()->appendIconItem(i->c_str());
329 if ((*i) == myVisualizationSettings->name) {
331 }
332 }
333 }
334 // for junctions
336 "Locate Junction", "Locate a junction within the network.", "",
339 // for edges
341 "Locate Street", "Locate a street within the network.", "",
344 // for vehicles
346 "Locate Vehicle", "Locate a vehicle within the network.", "",
349 // for persons
351 "Locate Person", "Locate a person within the network.", "",
354 // for containers
356 "Locate Container", "Locate a container within the network.", "",
359 // for tls
361 "Locate TLS", "Locate a tls within the network.", "",
364 // for additional stuff
366 "Locate Additional", "Locate an additional structure within the network.", "",
369 // for pois
371 "Locate POI", "Locate a POI within the network.", "",
374 // for polygons
376 "Locate Polygon", "Locate a Polygon within the network.", "",
379}
380
381
382void
383GUIOSGView::resize(int w, int h) {
384 GUISUMOAbstractView::resize(w, h);
385 updateHUDPosition(w, h);
386}
387
388
389void
390GUIOSGView::position(int x, int y, int w, int h) {
391 GUISUMOAbstractView::position(x, y, w, h);
392 updateHUDPosition(w, h);
393}
394
395
396void
397GUIOSGView::updateHUDPosition(int w, int h) {
398 // keep the HUD text in the left top corner
399 myHUD->setProjectionMatrixAsOrtho2D(0, w, 0, h);
400 myText->setPosition(osg::Vec3d(0., static_cast<double>(height), 0.));
401 // keep the full screen hint in the bottom right corner
402 myFullScreenText->setPosition(osg::Vec3d(static_cast<double>(w) - 12., 12., 0.));
403}
404
405
406void
407GUIOSGView::updateHUDText(const std::string text) {
408 myText->setText(text, osgText::String::ENCODING_UTF8);
409}
410
411
412void
413GUIOSGView::recenterView() {
414 stopTrack();
415 Position center = myGrid->getCenter();
416 double radius = std::max(myGrid->xmax() - myGrid->xmin(), myGrid->ymax() - myGrid->ymin());
417 myChanger->centerTo(center, radius);
418}
419
420
421bool
422GUIOSGView::setColorScheme(const std::string& name) {
423 if (!gSchemeStorage.contains(name)) {
424 return false;
425 }
426 if (myGUIDialogViewSettings != 0) {
427 if (myGUIDialogViewSettings->getCurrentScheme() != name) {
428 myGUIDialogViewSettings->setCurrentScheme(name);
429 }
430 }
431 myVisualizationSettings = &gSchemeStorage.get(name.c_str());
432 myVisualizationSettings->gaming = myApp->isGaming();
433 adoptViewSettings();
434 update();
435 return true;
436}
437
438
439long
440GUIOSGView::onPaint(FXObject*, FXSelector, void*) {
441 if (!isEnabled()) {
442 return 1;
443 }
444 myDecalsLockMutex.lock();
445 for (GUISUMOAbstractView::Decal& d : myDecals) {
446 if (!d.initialised && d.filename.length() > 0) {
447 if (d.filename.length() == 6 && d.filename.substr(0, 5) == "light") {
448 GUIOSGBuilder::buildLight(d, *myRoot);
449 } else if (d.filename.length() > 3 && d.filename.substr(0, 3) == "tl:") {
450 const int linkStringIdx = (int)d.filename.find(':', 3);
451 GUINet* net = (GUINet*) MSNet::getInstance();
452 try {
453 const std::string tlLogic = d.filename.substr(3, linkStringIdx - 3);
455 const int linkIdx = StringUtils::toInt(d.filename.substr(linkStringIdx + 1));
456 if (linkIdx < 0 || linkIdx >= static_cast<int>(vars.getActive()->getLinks().size())) {
457 throw NumberFormatException("");
458 }
459 const MSLink* const link = vars.getActive()->getLinksAt(linkIdx)[0];
460 osg::Group* tlNode = GUIOSGBuilder::getTrafficLight(d, vars, link, myGreenLight, myYellowLight, myRedLight, myRedYellowLight, myPoleBase, true, 0.5);
461 tlNode->setName("tlLogic:" + tlLogic);
462 myRoot->addChild(tlNode);
463 } catch (NumberFormatException&) {
464 WRITE_ERRORF(TL("Invalid link index in '%'."), d.filename);
465 } catch (InvalidArgument&) {
466 WRITE_ERRORF(TL("Unknown traffic light in '%'."), d.filename);
467 }
468 } else {
469 GUIOSGBuilder::buildDecal(d, *myRoot);
470 }
471 d.initialised = true;
472 }
473 }
474 myDecalsLockMutex.unlock();
475
476 // reset active flag
477 for (auto& item : myVehicles) {
478 item.second.active = false;
479 }
480
481 GUINet* net = static_cast<GUINet*>(MSNet::getInstance());
482 // build edges
483 for (const MSEdge* e : net->getEdgeControl().getEdges()) {
484 for (const MSLane* l : e->getLanes()) {
485 const MSLane::VehCont& vehicles = l->getVehiclesSecure();
486 for (MSVehicle* msVeh : vehicles) {
487 GUIVehicle* veh = static_cast<GUIVehicle*>(msVeh);
488 if (!(veh->isOnRoad() || veh->isParking() || veh->wasRemoteControlled())) {
489 continue;
490 }
491 auto itVeh = myVehicles.find(veh);
492 if (itVeh == myVehicles.end()) {
493 myVehicles[veh] = GUIOSGBuilder::buildMovable(veh->getVehicleType());
494 myRoot->addChild(myVehicles[veh].pos);
495 myVehicles[veh].pos->setName("vehicle:" + veh->getID());
496 veh->setNode(myVehicles[veh].pos);
497 } else {
498 itVeh->second.active = true;
499 }
500 osg::PositionAttitudeTransform* n = myVehicles[veh].pos;
501 n->setPosition(osg::Vec3d(veh->getPosition().x(), veh->getPosition().y(), veh->getPosition().z()));
502 const double dir = veh->getAngle() + M_PI / 2.;
503 const double slope = -veh->getSlope();
504 n->setAttitude(osg::Quat(osg::DegreesToRadians(slope), osg::Vec3(1, 0, 0),
505 0, osg::Vec3(0, 1, 0),
506 dir, osg::Vec3(0, 0, 1)));
507 /*
508 osg::ref_ptr<osg::AnimationPath> path = new osg::AnimationPath;
509 // path->setLoopMode( osg::AnimationPath::NO_LOOPING );
510 osg::AnimationPath::ControlPoint pointA(n->getPosition(), n->getAttitude());
511 osg::AnimationPath::ControlPoint pointB(osg::Vec3(veh->getPosition().x(), veh->getPosition().y(), veh->getPosition().z()),
512 osg::Quat(dir, osg::Vec3(0, 0, 1)) *
513 osg::Quat(osg::DegreesToRadians(slope), osg::Vec3(0, 1, 0)));
514 path->insert(0.0f, pointA);
515 path->insert(0.5f, pointB);
516 n->setUpdateCallback(new osg::AnimationPathCallback(path));
517 */
518
519 if (myVisualizationSettings->ignoreColorSchemeFor3DVehicles) {
520 myVehicles[veh].activateMaterial(false);
521 } else {
522 myVehicles[veh].activateMaterial(true);
523 RGBColor col;
524 if (!GUIBaseVehicle::setFunctionalColor(myVisualizationSettings->vehicleColorer.getActive(), veh, col)) {
525 col = myVisualizationSettings->vehicleColorer.getScheme().getColor(veh->getColorValue(*myVisualizationSettings, myVisualizationSettings->vehicleColorer.getActive()));
526 }
527 myVehicles[veh].mat->setDiffuse(osg::Material::FRONT_AND_BACK, osg::Vec4d(col.red() / 255., col.green() / 255., col.blue() / 255., col.alpha() / 255.));
528 }
531 myVehicles[veh].lights->setValue(2, veh->signalSet(MSVehicle::VEH_SIGNAL_BRAKELIGHT));
532 }
533 l->releaseVehicles();
534 }
535 }
536 // remove inactive
537 for (auto veh = myVehicles.begin(); veh != myVehicles.end();) {
538 if (!veh->second.active) {
539 removeVeh((veh++)->first);
540 } else {
541 ++veh;
542 }
543 }
544
546 if (now != myLastUpdate || (myGUIDialogViewSettings != 0 && myGUIDialogViewSettings->shown())) {
547 GUINet::getGUIInstance()->updateColor(*myVisualizationSettings);
548 }
549 if (now != myLastUpdate && myTracked != 0) {
550 osg::Vec3d lookFrom, lookAt, up;
551 lookAt[0] = myTracked->getPosition().x();
552 lookAt[1] = myTracked->getPosition().y();
553 lookAt[2] = myTracked->getPosition().z();
554 const double angle = myTracked->getAngle();
555 lookFrom[0] = lookAt[0] + 50. * cos(angle);
556 lookFrom[1] = lookAt[1] + 50. * sin(angle);
557 lookFrom[2] = lookAt[2] + 10.;
558 osg::Matrix m;
559 m.makeLookAt(lookFrom, lookAt, osg::Z_AXIS);
560 myViewer->getCameraManipulator()->setByInverseMatrix(m);
561 }
562
563 // reset active flag
564 for (auto& item : myPersons) {
565 item.second.active = false;
566 }
567
568 for (const MSEdge* e : net->getEdgeControl().getEdges()) {
569 const GUIEdge* ge = static_cast<const GUIEdge*>(e);
570 const std::set<MSTransportable*, ComparatorNumericalIdLess>& persons = ge->getPersonsSecure();
571 for (auto person : persons) {
572 if (person->hasArrived() || !person->hasDeparted()) {
573 //std::cout << SIMTIME << " person " << person->getID() << " is loaded but arrived\n";
574 continue;
575 }
576 auto itPers = myPersons.find(person);
577 if (itPers == myPersons.end()) {
578 myPersons[person] = GUIOSGBuilder::buildMovable(person->getVehicleType());
579 myRoot->addChild(myPersons[person].pos);
580 } else {
581 itPers->second.active = true;
582 }
583 osg::PositionAttitudeTransform* n = myPersons[person].pos;
584 const Position pos = person->getPosition();
585 n->setPosition(osg::Vec3d(pos.x(), pos.y(), pos.z()));
586 const double dir = person->getAngle() + M_PI / 2.;
587 n->setAttitude(osg::Quat(dir, osg::Vec3d(0, 0, 1)));
588
589 RGBColor col;
590 GUIPerson* actualPerson = dynamic_cast<GUIPerson*>(person);
591 if (!GUIPerson::setFunctionalColor(myVisualizationSettings->personColorer.getActive(), actualPerson, col)) {
592 col = myVisualizationSettings->personColorer.getScheme().getColor(actualPerson->getColorValue(*myVisualizationSettings, myVisualizationSettings->vehicleColorer.getActive()));
593 }
594 myPersons[person].mat->setDiffuse(osg::Material::FRONT_AND_BACK, osg::Vec4d(col.red() / 255., col.green() / 255., col.blue() / 255., col.alpha() / 255.));
595 }
596 ge->releasePersons();
597 }
598
599 // remove inactive
600 for (auto person = myPersons.begin(); person != myPersons.end();) {
601 if (!person->second.active) {
602 removeTransportable((person++)->first);
603 } else {
604 ++person;
605 }
606 }
607
608 if (myAdapter->makeCurrent()) {
609 myFullScreenTextNode->setNodeMask(myApp->isFullScreen() ? 0xFFFFFFFF : 0);
610 myViewer->frame();
611 makeNonCurrent();
612 }
613 myLastUpdate = now;
614 return 1;
615}
616
617
618void
619GUIOSGView::removeVeh(MSVehicle* veh) {
620 if (myTracked == veh) {
621 stopTrack();
622 }
623 std::map<MSVehicle*, OSGMovable>::iterator i = myVehicles.find(veh);
624 if (i != myVehicles.end()) {
625 myRoot->removeChild(i->second.pos);
626 myVehicles.erase(i);
627 }
628}
629
630
631void
632GUIOSGView::removeTransportable(MSTransportable* t) {
633 std::map<MSTransportable*, OSGMovable>::iterator i = myPersons.find(t);
634 if (i != myPersons.end()) {
635 myRoot->removeChild(i->second.pos);
636 myPersons.erase(i);
637 }
638}
639
640
641void GUIOSGView::updateViewportValues() {
642 osg::Vec3d lookFrom, lookAt, up;
643 myViewer->getCameraManipulator()->getInverseMatrix().getLookAt(lookFrom, lookAt, up);
644 myGUIDialogEditViewport->setValues(Position(lookFrom[0], lookFrom[1], lookFrom[2]),
645 Position(lookAt[0], lookAt[1], lookAt[2]), calculateRotation(lookFrom, lookAt, up));
646}
647
648
649void
650GUIOSGView::showViewportEditor() {
651 getViewportEditor(); // make sure it exists;
652 osg::Vec3d lookFrom, lookAt, up;
653 myViewer->getCameraManipulator()->getInverseMatrix().getLookAt(lookFrom, lookAt, up);
654 Position from(lookFrom[0], lookFrom[1], lookFrom[2]), at(lookAt[0], lookAt[1], lookAt[2]);
655 myGUIDialogEditViewport->setOldValues(from, at, calculateRotation(lookFrom, lookAt, up));
656 myGUIDialogEditViewport->setZoomValue(100);
657 myGUIDialogEditViewport->show();
658}
659
660
661void
662GUIOSGView::setViewportFromToRot(const Position& lookFrom, const Position& lookAt, double rotation) {
663 osg::Vec3d lookFromOSG, lookAtOSG, up;
664 lookFromOSG[0] = lookFrom.x();
665 lookFromOSG[1] = lookFrom.y();
666 lookFromOSG[2] = lookFrom.z();
667 lookAtOSG[0] = lookAt.x();
668 lookAtOSG[1] = lookAt.y();
669 lookAtOSG[2] = lookAt.z();
670
671 osg::Vec3d viewAxis, viewUp, orthogonal, normal;
672 viewAxis = lookFromOSG - lookAtOSG;
673 viewAxis.normalize();
674 viewUp = (viewAxis[0] + viewAxis[1] == 0.) ? osg::Vec3d(0., 1., 0.) : osg::Vec3d(0., 0., 1.); // check for parallel vectors
675 orthogonal = viewUp ^ viewAxis;
676 orthogonal.normalize();
677 normal = viewAxis ^ orthogonal;
678
679 rotation = std::fmod(rotation, 360.);
680 if (rotation < 0) {
681 rotation += 360.;
682 }
683 myChanger->setRotation(rotation);
684 double angle = DEG2RAD(rotation);
685 up = normal * cos(angle) - orthogonal * sin(angle);
686 up.normalize();
687
688 double zoom = (myGUIDialogEditViewport != nullptr) ? myGUIDialogEditViewport->getZoomValue() : 100.;
689 lookFromOSG = lookFromOSG + viewAxis * (100. - zoom);
690 lookAtOSG = lookFromOSG - viewAxis;
691 myViewer->getCameraManipulator()->setHomePosition(lookFromOSG, lookAtOSG, up);
692 myViewer->home();
693}
694
695
696void
697GUIOSGView::copyViewportTo(GUISUMOAbstractView* view) {
698 osg::Vec3d lookFrom, lookAt, up;
699 myViewer->getCameraManipulator()->getHomePosition(lookFrom, lookAt, up);
700 view->setViewportFromToRot(Position(lookFrom[0], lookFrom[1], lookFrom[2]),
701 Position(lookAt[0], lookAt[1], lookAt[2]), 0);
702}
703
704
705void
706GUIOSGView::startTrack(int id) {
707 if (myTracked == 0 || (int)myTracked->getGlID() != id) {
708 myTracked = 0;
710 for (; it != MSNet::getInstance()->getVehicleControl().loadedVehEnd(); it++) {
711 GUIVehicle* veh = (GUIVehicle*)(*it).second;
712 if ((int)veh->getGlID() == id) {
713 if (!veh->isOnRoad() || myVehicles.find(veh) == myVehicles.end()) {
714 return;
715 }
716 myTracked = veh;
717 break;
718 }
719 }
720 if (myTracked != 0) {
721 osg::Vec3d lookFrom, lookAt, up;
722 lookAt[0] = myTracked->getPosition().x();
723 lookAt[1] = myTracked->getPosition().y();
724 lookAt[2] = myTracked->getPosition().z();
725 lookFrom[0] = lookAt[0] + 50.;
726 lookFrom[1] = lookAt[1] + 50.;
727 lookFrom[2] = lookAt[2] + 10.;
728 osg::Matrix m;
729 m.makeLookAt(lookFrom, lookAt, osg::Z_AXIS);
730 myViewer->getCameraManipulator()->setByInverseMatrix(m);
731 }
732 }
733}
734
735
736void
737GUIOSGView::stopTrack() {
738 myTracked = 0;
739}
740
741
743GUIOSGView::getTrackedID() const {
744 return myTracked == 0 ? GUIGlObject::INVALID_ID : myTracked->getGlID();
745}
746
747
748void
749GUIOSGView::onGamingClick(Position pos) {
751 const MSTrafficLightLogic* minTll = nullptr;
752 double minDist = std::numeric_limits<double>::infinity();
753 for (const MSTrafficLightLogic* const tll : tlsControl.getAllLogics()) {
754 if (tlsControl.isActive(tll)) {
755 // get the links
756 const MSTrafficLightLogic::LaneVector& lanes = tll->getLanesAt(0);
757 if (lanes.size() > 0) {
758 const Position& endPos = lanes[0]->getShape().back();
759 if (endPos.distanceTo(pos) < minDist) {
760 minDist = endPos.distanceTo(pos);
761 minTll = tll;
762 }
763 }
764 }
765 }
766 if (minTll != 0) {
767 const MSTLLogicControl::TLSLogicVariants& vars = tlsControl.get(minTll->getID());
768 const std::vector<MSTrafficLightLogic*> logics = vars.getAllLogics();
769 if (logics.size() > 1) {
771 for (int i = 0; i < (int)logics.size() - 1; i++) {
772 if (minTll->getProgramID() == logics[i]->getProgramID()) {
773 l = (MSSimpleTrafficLightLogic*) logics[i + 1];
774 tlsControl.switchTo(minTll->getID(), l->getProgramID());
775 }
776 }
777 if (l == logics[0]) {
778 tlsControl.switchTo(minTll->getID(), l->getProgramID());
779 }
781 update();
782 }
783 }
784}
785
786
788GUIOSGView::getCurrentTimeStep() const {
790}
791
792
793long GUIOSGView::onConfigure(FXObject* sender, FXSelector sel, void* ptr) {
794 // update the window dimensions, in case the window has been resized.
795 const int w = getWidth();
796 const int h = getHeight();
797 if (w > 0 && h > 0) {
798 myAdapter->getEventQueue()->windowResize(0, 0, w, h);
799 myAdapter->resized(0, 0, w, h);
800 updateHUDPosition(w, h);
801 }
802 return FXGLCanvas::onConfigure(sender, sel, ptr);
803}
804
805
806long GUIOSGView::onKeyPress(FXObject* sender, FXSelector sel, void* ptr) {
807 const FXEvent* e = (FXEvent*)ptr;
808 const int key = e->code;
809 if (key == FX::KEY_f) {
810 if ((e->state & (CONTROLMASK | ALTMASK)) != 0) {
811 // do not switch the camera mode but leave shortcuts such as Ctrl+F (fullscreen) to the application
812 myCameraModeKeyPressed = false;
813 return FXGLCanvas::onKeyPress(sender, sel, ptr);
814 }
815 myCameraModeKeyPressed = true;
816 }
817 myAdapter->getEventQueue()->keyPress(key);
818 // leave key handling for some cases to OSG
819 if (key == FX::KEY_f || key == FX::KEY_Left || key == FX::KEY_Right || key == FX::KEY_Up || key == FX::KEY_Down) {
820 return 1;
821 }
822 return FXGLCanvas::onKeyPress(sender, sel, ptr);
823}
824
825
826long GUIOSGView::onKeyRelease(FXObject* sender, FXSelector sel, void* ptr) {
827 const int key = ((FXEvent*)ptr)->code;
828 if (key == FX::KEY_f) {
829 if (!myCameraModeKeyPressed) {
830 // the matching key press was a shortcut (i.e. Ctrl+F), OSG must not switch the camera mode
831 return FXGLCanvas::onKeyRelease(sender, sel, ptr);
832 }
833 myCameraModeKeyPressed = false;
834 }
835 myAdapter->getEventQueue()->keyRelease(key);
836 // leave key handling for some cases to OSG
837 if (key == FX::KEY_f || key == FX::KEY_Left || key == FX::KEY_Right || key == FX::KEY_Up || key == FX::KEY_Down) {
838 return 1;
839 }
840 return FXGLCanvas::onKeyRelease(sender, sel, ptr);
841}
842
843
844long GUIOSGView::onLeftBtnPress(FXObject* sender, FXSelector sel, void* ptr) {
845 handle(this, FXSEL(SEL_FOCUS_SELF, 0), ptr);
846
847 FXEvent* event = (FXEvent*)ptr;
848 myAdapter->getEventQueue()->mouseButtonPress((float)event->click_x, (float)event->click_y, 1);
849 if (myApp->isGaming()) {
850 onGamingClick(getPositionInformation());
851 }
852
853 return FXGLCanvas::onLeftBtnPress(sender, sel, ptr);
854}
855
856
857long GUIOSGView::onLeftBtnRelease(FXObject* sender, FXSelector sel, void* ptr) {
858 FXEvent* event = (FXEvent*)ptr;
859 myAdapter->getEventQueue()->mouseButtonRelease((float)event->click_x, (float)event->click_y, 1);
860 myChanger->onLeftBtnRelease(ptr);
861 return FXGLCanvas::onLeftBtnRelease(sender, sel, ptr);
862}
863
864
865long GUIOSGView::onMiddleBtnPress(FXObject* sender, FXSelector sel, void* ptr) {
866 handle(this, FXSEL(SEL_FOCUS_SELF, 0), ptr);
867
868 FXEvent* event = (FXEvent*)ptr;
869 myAdapter->getEventQueue()->mouseButtonPress((float)event->click_x, (float)event->click_y, 2);
870
871 return FXGLCanvas::onMiddleBtnPress(sender, sel, ptr);
872}
873
874
875long GUIOSGView::onMiddleBtnRelease(FXObject* sender, FXSelector sel, void* ptr) {
876 FXEvent* event = (FXEvent*)ptr;
877 myAdapter->getEventQueue()->mouseButtonRelease((float)event->click_x, (float)event->click_y, 2);
878 myChanger->onMiddleBtnRelease(ptr);
879 return FXGLCanvas::onMiddleBtnRelease(sender, sel, ptr);
880}
881
882
883long GUIOSGView::onRightBtnPress(FXObject* sender, FXSelector sel, void* ptr) {
884 handle(this, FXSEL(SEL_FOCUS_SELF, 0), ptr);
885
886 FXEvent* event = (FXEvent*)ptr;
887 myAdapter->getEventQueue()->mouseButtonPress((float)event->click_x, (float)event->click_y, 3);
888
889 return FXGLCanvas::onRightBtnPress(sender, sel, ptr);
890}
891
892
893long GUIOSGView::onRightBtnRelease(FXObject* sender, FXSelector sel, void* ptr) {
894 FXEvent* event = (FXEvent*)ptr;
895 myAdapter->getEventQueue()->mouseButtonRelease((float)event->click_x, (float)event->click_y, 3);
896 myChanger->onRightBtnRelease(ptr);
897 return FXGLCanvas::onRightBtnRelease(sender, sel, ptr);
898}
899
900
901long
902GUIOSGView::onMouseMove(FXObject* sender, FXSelector sel, void* ptr) {
903 // if popup exist but isn't shown, destroy it first
904 if (myPopup && !myPopup->shown()) {
905 destroyPopup();
906 }
907
908 FXEvent* event = (FXEvent*)ptr;
909 osgGA::GUIEventAdapter* ea = myAdapter->getEventQueue()->mouseMotion((float)event->win_x, (float)event->win_y);
910 setWindowCursorPosition(ea->getXnormalized(), ea->getYnormalized());
911 if (myGUIDialogEditViewport != nullptr && myGUIDialogEditViewport->shown()) {
912 updateViewportValues();
913 }
914 updatePositionInformation();
915 return FXGLCanvas::onMotion(sender, sel, ptr);
916}
917
918
919long
920GUIOSGView::onIdle(FXObject* /* sender */, FXSelector /* sel */, void*) {
921 forceRefresh();
922 update();
923 getApp()->addChore(this, MID_CHORE);
924 return 1;
925}
926
927
928long
929GUIOSGView::onCmdCloseLane(FXObject*, FXSelector, void*) {
930 GUILane* lane = getLaneUnderCursor();
931 if (lane != nullptr) {
932 lane->closeTraffic();
934 GUINet::getGUIInstance()->updateColor(*myVisualizationSettings);
935 update();
936 }
937 return 1;
938}
939
940
941long
942GUIOSGView::onCmdCloseEdge(FXObject*, FXSelector, void*) {
943 GUILane* lane = getLaneUnderCursor();
944 if (lane != nullptr) {
945 dynamic_cast<GUIEdge*>(&lane->getEdge())->closeTraffic(lane);
947 GUINet::getGUIInstance()->updateColor(*myVisualizationSettings);
948 update();
949 }
950 return 1;
951}
952
953
954long
955GUIOSGView::onCmdAddRerouter(FXObject*, FXSelector, void*) {
956 GUILane* lane = getLaneUnderCursor();
957 if (lane != nullptr) {
958 dynamic_cast<GUIEdge*>(&lane->getEdge())->addRerouter();
960 update();
961 }
962 return 1;
963}
964
965
966long
967GUIOSGView::onCmdShowReachability(FXObject* menu, FXSelector selector, void*) {
968 GUILane* lane = getLaneUnderCursor();
969 if (lane != nullptr) {
970 // reset
971 GUIViewTraffic::showLaneReachability(lane, menu, selector);
972 // switch to 'color by selection' unless coloring 'by reachability'
973 if (myVisualizationSettings->laneColorer.getActive() != 36) {
974 myVisualizationSettings->laneColorer.setActive(1);
975 GUINet::getGUIInstance()->updateColor(*myVisualizationSettings);
976 }
977 update();
978 }
979 return 1;
980}
981
982
983long
984GUIOSGView::onVisualizationChange(FXObject*, FXSelector, void*) {
985 adoptViewSettings();
986 return 1;
987}
988
989
990void
991GUIOSGView::setWindowCursorPosition(float x, float y) {
992 myOSGNormalizedCursorX = x;
993 myOSGNormalizedCursorY = y;
994}
995
996
997double
998GUIOSGView::calculateRotation(const osg::Vec3d& lookFrom, const osg::Vec3d& lookAt, const osg::Vec3d& up) {
999 osg::Vec3d viewAxis, viewUp, orthogonal, normal;
1000 viewAxis = lookFrom - lookAt;
1001 viewAxis.normalize();
1002 viewUp = (abs(viewAxis[0]) + abs(viewAxis[1]) == 0.) ? osg::Y_AXIS : osg::Z_AXIS; // check for parallel vectors
1003 orthogonal = viewUp ^ viewAxis;
1004 orthogonal.normalize();
1005 normal = viewAxis ^ orthogonal;
1006 double angle = atan2((normal ^ up).length() / (normal.length() * up.length()), (normal * up) / (normal.length() * up.length()));
1007 if (angle < 0) {
1008 angle += M_PI;
1009 }
1010 return RAD2DEG(angle);
1011}
1012
1013
1014void
1015GUIOSGView::updatePositionInformation() const {
1016 Position pos;
1017 if (getPositionAtCursor(myOSGNormalizedCursorX, myOSGNormalizedCursorY, pos)) {
1018 if (!myApp->getCartesianLabel()->hasFocus()) {
1019 myApp->getCartesianLabel()->setText(("x:" + toString(pos.x()) + ", y:" + toString(pos.y())).c_str());
1020 }
1021 // set geo position
1022 if (!myApp->getGeoLabel()->hasFocus()) {
1024 if (GeoConvHelper::getFinal().usingGeoProjection()) {
1025 if (!myApp->getGeoLabel()->isEnabled()) {
1026 myApp->getGeoLabel()->enable();
1027 myApp->getGeoLabel()->setEditable(true);
1028 }
1029 myApp->getGeoLabel()->setText(("lat:" + toString(pos.y(), gPrecisionGeo) + ", lon:" + toString(pos.x(), gPrecisionGeo)).c_str());
1030 } else {
1031 myApp->getGeoLabel()->setText(TL("(No projection defined)"));
1032 if (myApp->getGeoLabel()->isEnabled()) {
1033 myApp->getGeoLabel()->disable();
1034 myApp->getGeoLabel()->setEditable(false);
1035 }
1036 }
1037 }
1038 } else {
1039 // set placeholder
1040 if (!myApp->getCartesianLabel()->hasFocus()) {
1041 myApp->getCartesianLabel()->setText(TL("N/A"));
1042 }
1043 if (!myApp->getGeoLabel()->hasFocus()) {
1044 if (GeoConvHelper::getFinal().usingGeoProjection()) {
1045 myApp->getGeoLabel()->setText(TL("N/A"));
1046 } else {
1047 myApp->getGeoLabel()->setText(TL("(No projection defined)"));
1048 if (myApp->getGeoLabel()->isEnabled()) {
1049 myApp->getGeoLabel()->disable();
1050 myApp->getGeoLabel()->setEditable(false);
1051 }
1052 }
1053 }
1054 }
1055}
1056
1057
1058bool
1059GUIOSGView::getPositionAtCursor(float xNorm, float yNorm, Position& pos) const {
1060 // only reasonable if view axis points to the ground (not parallel to the ground or in the sky)
1061 osg::Vec3d lookFrom, lookAt, up, viewAxis;
1062 myViewer->getCameraManipulator()->getInverseMatrix().getLookAt(lookFrom, lookAt, up);
1063 if ((lookAt - lookFrom).z() >= 0.) {
1064 // looking to the sky makes position at ground pointless
1065 return false;
1066 }
1067 // solve linear equation of ray crossing the ground plane
1068 osg::Matrixd iVP = osg::Matrixd::inverse(myViewer->getCamera()->getViewMatrix() * myViewer->getCamera()->getProjectionMatrix());
1069 osg::Vec3 nearPoint = osg::Vec3(xNorm, yNorm, 0.0f) * iVP;
1070 osg::Vec3 farPoint = osg::Vec3(xNorm, yNorm, 1.0f) * iVP;
1071 osg::Vec3 ray = farPoint - nearPoint;
1072 osg::Vec3 groundPos = nearPoint - ray * nearPoint.z() / ray.z();
1073 pos.setx(groundPos.x());
1074 pos.sety(groundPos.y());
1075 pos.setz(0.);
1076 return true;
1077}
1078
1079
1080std::vector<GUIGlObject*>
1081GUIOSGView::getGUIGlObjectsUnderCursor() {
1082 std::vector<GUIGlObject*> result;
1083 osgUtil::LineSegmentIntersector::Intersections intersections;
1084 if (myViewer->computeIntersections(myViewer->getCamera(), osgUtil::Intersector::CoordinateFrame::PROJECTION, myOSGNormalizedCursorX, myOSGNormalizedCursorY, intersections)) {
1085 for (auto intersection : intersections) {
1086 if (!intersection.nodePath.empty()) {
1087 // the object is identified by the ID stored in OSG
1088 for (osg::Node* currentNode : intersection.nodePath) {
1089 if (currentNode->getName().length() > 0 && currentNode->getName().find(":") != std::string::npos) {
1090 const std::string objID = currentNode->getName();
1092 // check that GUIGlObject exist
1093 if (o == nullptr) {
1094 continue;
1095 }
1096 // check that GUIGlObject isn't the network
1097 if (o->getGlID() == 0) {
1098 continue;
1099 }
1100 result.push_back(o);
1101 // unblock object
1103 }
1104 }
1105 }
1106 }
1107 }
1108 return result;
1109}
1110
1111
1112GUILane*
1113GUIOSGView::getLaneUnderCursor() {
1114 std::vector<GUIGlObject*> objects = getGUIGlObjectsUnderCursor();
1115 if (objects.size() > 0) {
1116 return dynamic_cast<GUILane*>(objects[0]);
1117 }
1118 return nullptr;
1119}
1120
1121
1122void
1123GUIOSGView::zoom2Pos(Position& camera, Position& lookAt, double zoom) {
1124 osg::Vec3d lookFromOSG, lookAtOSG, viewAxis, up;
1125 myViewer->getCameraManipulator()->getInverseMatrix().getLookAt(lookFromOSG, lookAtOSG, up);
1126 lookFromOSG[0] = camera.x();
1127 lookFromOSG[1] = camera.y();
1128 lookFromOSG[2] = camera.z();
1129 lookAtOSG[0] = lookAt.x();
1130 lookAtOSG[1] = lookAt.y();
1131 lookAtOSG[2] = lookAt.z();
1132 viewAxis = lookAtOSG - lookFromOSG;
1133 viewAxis.normalize();
1134
1135 // compute new camera and lookAt pos
1136 osg::Vec3d cameraUpdate = lookFromOSG + viewAxis * (zoom - 100.);
1137 osg::Vec3d lookAtUpdate = cameraUpdate + viewAxis;
1138
1139 myViewer->getCameraManipulator()->setHomePosition(cameraUpdate, lookAtUpdate, up);
1140 myViewer->home();
1141}
1142
1143
1144osg::Vec4d
1145GUIOSGView::toOSGColorVector(RGBColor c, bool useAlpha) {
1146 return osg::Vec4d(c.red() / 255., c.green() / 255., c.blue() / 255., (useAlpha) ? c.alpha() / 255. : 1.);
1147}
1148
1149
1150GUIOSGView::FXOSGAdapter::FXOSGAdapter(GUISUMOAbstractView* parent, FXCursor* cursor)
1151 : myParent(parent), myOldCursor(cursor) {
1152 _traits = new GraphicsContext::Traits();
1153 _traits->x = 0;
1154 _traits->y = 0;
1155 _traits->width = parent->getWidth();
1156 _traits->height = parent->getHeight();
1157 _traits->windowDecoration = false;
1158 _traits->doubleBuffer = true;
1159 _traits->sharedContext = 0;
1160 if (valid()) {
1161 setState(new osg::State());
1162 getState()->setGraphicsContext(this);
1163#ifdef DEBUG_GLERRORS
1164 getState()->setCheckForGLErrors(osg::State::ONCE_PER_ATTRIBUTE);
1165 std::cout << "OSG getCheckForGLErrors " << getState()->getCheckForGLErrors() << std::endl;
1166#endif
1167 if (_traits.valid() && _traits->sharedContext != 0) {
1168 getState()->setContextID(_traits->sharedContext->getState()->getContextID());
1169 incrementContextIDUsageCount(getState()->getContextID());
1170 } else {
1171 getState()->setContextID(createNewContextID());
1172 }
1173 }
1174}
1175
1176
1177GUIOSGView::FXOSGAdapter::~FXOSGAdapter() {
1178 delete myOldCursor;
1179}
1180
1181
1182void
1183GUIOSGView::FXOSGAdapter::grabFocus() {
1184 // focus this window
1185 myParent->setFocus();
1186}
1187
1188
1189void
1190GUIOSGView::FXOSGAdapter::useCursor(bool cursorOn) {
1191 if (cursorOn) {
1192 myParent->setDefaultCursor(myOldCursor);
1193 } else {
1194 myParent->setDefaultCursor(NULL);
1195 }
1196}
1197
1198
1199bool
1200GUIOSGView::FXOSGAdapter::makeCurrentImplementation() {
1201 myParent->makeCurrent();
1202 return true;
1203}
1204
1205
1206bool
1207GUIOSGView::FXOSGAdapter::releaseContext() {
1208 myParent->makeNonCurrent();
1209 return true;
1210}
1211
1212
1213void
1214GUIOSGView::FXOSGAdapter::swapBuffersImplementation() {
1215 myParent->swapBuffers();
1216}
1217
1218
1219bool
1220GUIOSGView::PickHandler::handle(const osgGA::GUIEventAdapter& ea, osgGA::GUIActionAdapter& /* aa */) {
1221 if (ea.getEventType() == osgGA::GUIEventAdapter::DRAG) {
1222 myDrag = true;
1223 } else if (ea.getEventType() == osgGA::GUIEventAdapter::RELEASE && ea.getButton() == osgGA::GUIEventAdapter::RIGHT_MOUSE_BUTTON) {
1224 if (!myDrag) {
1225 if (myParent->makeCurrent()) {
1226 std::vector<GUIGlObject*> objects = myParent->getGUIGlObjectsUnderCursor();
1227 if (objects.size() > 0) {
1228 myParent->openObjectDialog(objects);
1229 }
1230 myParent->makeNonCurrent();
1231 }
1232 }
1233 myDrag = false;
1234 }
1235 return false;
1236}
1237
1238
1239#endif
1240
1241/****************************************************************************/
long long int SUMOTime
Definition GUI.h:36
@ MID_CHORE
chore
Definition GUIAppEnum.h:421
@ 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:308
#define WRITE_ERROR(msg)
Definition MsgHandler.h:307
#define TL(string)
Definition MsgHandler.h:316
@ 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:29
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
Definition ToString.h:57
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:174
const std::set< MSTransportable *, ComparatorNumericalIdLess > & getPersonsSecure() const
Returns this edge's persons set; locks it for microsimulation.
Definition GUIEdge.h:165
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:1606
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:581
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:52
double getAngle() const override
Return current angle.
Definition GUIVehicle.h:82
Position getPosition(const double offset=0) const override
Return current position (x/y, cartesian)
Definition GUIVehicle.h:72
double getColorValue(const GUIVisualizationSettings &s, int activeScheme) const override
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:78
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:790
static MSNet * getInstance()
Returns the pointer to the unique instance of MSNet (singleton).
Definition MSNet.cpp:201
MSTLLogicControl & getTLSControl()
Returns the tls logics control.
Definition MSNet.h:476
SUMOTime getCurrentTimeStep() const
Returns the current simulation step.
Definition MSNet.h:335
MSVehicleControl & getVehicleControl()
Returns the vehicle control.
Definition MSNet.h:403
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:1194
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:1116
@ VEH_SIGNAL_BRAKELIGHT
The brake lights are on.
Definition MSVehicle.h:1122
@ VEH_SIGNAL_BLINKER_LEFT
Left blinker lights are switched on.
Definition MSVehicle.h:1118
@ VEH_SIGNAL_BLINKER_EMERGENCY
Blinker lights on both sides are switched on.
Definition MSVehicle.h:1120
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:73
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:78
unsigned char alpha() const
Returns the alpha-amount of the color.
Definition RGBColor.cpp:96
unsigned char green() const
Returns the green-amount of the color.
Definition RGBColor.cpp:84
unsigned char blue() const
Returns the blue-amount of the color.
Definition RGBColor.cpp:90
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.