SUMO - Simulation of Urban MObility
GUIOSGView.cpp
Go to the documentation of this file.
1 /****************************************************************************/
8 // An OSG-based 3D view on the simulation
9 /****************************************************************************/
10 // SUMO, Simulation of Urban MObility; see http://sumo.dlr.de/
11 // Copyright (C) 2001-2016 DLR (http://www.dlr.de/) and contributors
12 /****************************************************************************/
13 //
14 // This file is part of SUMO.
15 // SUMO is free software: you can redistribute it and/or modify
16 // it under the terms of the GNU General Public License as published by
17 // the Free Software Foundation, either version 3 of the License, or
18 // (at your option) any later version.
19 //
20 /****************************************************************************/
21 
22 
23 // ===========================================================================
24 // included modules
25 // ===========================================================================
26 #ifdef _MSC_VER
27 #include <windows_config.h>
28 #else
29 #include <config.h>
30 #endif
31 
32 #ifdef HAVE_OSG
33 
34 #include <iostream>
35 #include <utility>
36 #include <cmath>
37 #include <limits>
38 // osg may include windows.h somewhere so we need to guard against macro pollution
39 #ifdef WIN32
40 #define NOMINMAX
41 #endif
42 #include <osgViewer/Viewer>
43 #include <osgViewer/ViewerEventHandlers>
44 #include <osgGA/NodeTrackerManipulator>
45 #include <osgDB/ReadFile>
46 #include <osg/PositionAttitudeTransform>
47 #include <osg/Vec4>
48 #include <osg/ShapeDrawable>
49 #ifdef WIN32
50 #undef NOMINMAX
51 #endif
66 #include <utils/gui/div/GLHelper.h>
67 #include <guisim/GUINet.h>
69 #include <guisim/GUIEdge.h>
70 #include <guisim/GUILane.h>
71 #include <guisim/GUIVehicle.h>
72 #include <microsim/MSEdge.h>
73 #include <microsim/MSEdgeControl.h>
74 #include <microsim/MSLane.h>
79 #include <utils/common/RGBColor.h>
83 #include <utils/shapes/Polygon.h>
84 #include <gui/GUISUMOViewParent.h>
86 #include "GUIOSGBuilder.h"
87 #include "GUIOSGView.h"
88 
89 #ifdef CHECK_MEMORY_LEAKS
90 #include <foreign/nvwa/debug_new.h>
91 #endif // CHECK_MEMORY_LEAKS
92 
93 
94 FXDEFMAP(GUIOSGView) GUIOSGView_Map[] = {
95  //________Message_Type_________ ___ID___ ________Message_Handler________
96  FXMAPFUNC(SEL_CHORE, MID_CHORE, GUIOSGView::OnIdle)
97 };
98 FXIMPLEMENT(GUIOSGView, GUISUMOAbstractView, GUIOSGView_Map, ARRAYNUMBER(GUIOSGView_Map))
99 
100 
101 std::ostream&
102 operator<<(std::ostream& os, const osg::Vec3d& v) {
103  return os << v.x() << "," << v.y() << "," << v.z();
104 }
105 
106 
107 // ===========================================================================
108 // GUIOSGView::Command_TLSChange member method definitions
109 // ===========================================================================
110 GUIOSGView::Command_TLSChange::Command_TLSChange(const MSLink* const link, osg::Switch* switchNode)
111  : myLink(link), mySwitch(switchNode), myLastState(LINKSTATE_TL_OFF_NOSIGNAL) {
112  execute();
113 }
114 
115 
116 GUIOSGView::Command_TLSChange::~Command_TLSChange() {}
117 
118 
119 void
120 GUIOSGView::Command_TLSChange::execute() {
121  switch (myLink->getState()) {
124  mySwitch->setSingleChildOn(0);
125  break;
128  mySwitch->setSingleChildOn(1);
129  break;
130  case LINKSTATE_TL_RED:
131  mySwitch->setSingleChildOn(2);
132  break;
134  mySwitch->setSingleChildOn(3);
135  break;
136  default:
137  mySwitch->setAllChildrenOff();
138  }
139  myLastState = myLink->getState();
140 }
141 
142 
143 
144 // ===========================================================================
145 // GUIOSGView member method definitions
146 // ===========================================================================
147 GUIOSGView::GUIOSGView(
148  FXComposite* p,
149  GUIMainWindow& app,
150  GUISUMOViewParent* parent,
151  GUINet& net, FXGLVisual* glVis,
152  FXGLCanvas* share) :
153  GUISUMOAbstractView(p, app, parent, net.getVisualisationSpeedUp(), glVis, share),
154  myTracked(0), myCameraManipulator(new SUMOTerrainManipulator()), myLastUpdate(-1) {
155 
156  //FXGLVisual* glVisual=new FXGLVisual(getApp(),VISUAL_DOUBLEBUFFER|VISUAL_STEREO);
157 
158  //m_gwFox = new GraphicsWindowFOX(this, glVisual, NULL, NULL, LAYOUT_FILL_X|LAYOUT_FILL_Y, x, y, w, h );
159 
160  int w = getWidth();
161  int h = getHeight();
162  myAdapter = new FXOSGAdapter(this, new FXCursor(parent->getApp(), CURSOR_CROSS));
163 
164  myViewer = new osgViewer::Viewer();
165  myViewer->getCamera()->setGraphicsContext(myAdapter);
166  myViewer->getCamera()->setViewport(0, 0, w, h);
167  myViewer->setThreadingModel(osgViewer::Viewer::SingleThreaded);
168 
169  const char* sumoPath = getenv("SUMO_HOME");
170  if (sumoPath != 0) {
171  std::string newPath = std::string(sumoPath) + "/data/3D";
172  if (FileHelpers::isReadable(newPath)) {
173  osgDB::FilePathList path = osgDB::Registry::instance()->getDataFilePathList();
174  path.push_back(newPath);
175  osgDB::Registry::instance()->setDataFilePathList(path);
176  }
177  }
178 
179  myGreenLight = osgDB::readNodeFile("tlg.obj");
180  myYellowLight = osgDB::readNodeFile("tly.obj");
181  myRedLight = osgDB::readNodeFile("tlr.obj");
182  myRedYellowLight = osgDB::readNodeFile("tlu.obj");
183  if (myGreenLight == 0 || myYellowLight == 0 || myRedLight == 0 || myRedYellowLight == 0) {
184  WRITE_ERROR("Could not load traffic light files.");
185  }
186  myRoot = GUIOSGBuilder::buildOSGScene(myGreenLight, myYellowLight, myRedLight, myRedYellowLight);
187  // add the stats handler
188  myViewer->addEventHandler(new osgViewer::StatsHandler());
189  myViewer->setSceneData(myRoot);
190  myViewer->setCameraManipulator(myCameraManipulator);
191  osg::Vec3d lookFrom, lookAt, up;
192  myCameraManipulator->getHomePosition(lookFrom, lookAt, up);
193  double z = lookFrom[2];
194  lookFrom[2] = -lookFrom.y();
195  lookFrom[1] = z;
196  myCameraManipulator->setHomePosition(lookFrom, lookAt, up);
197  myViewer->home();
198  getApp()->addChore(this, MID_CHORE);
199 }
200 
201 
202 GUIOSGView::~GUIOSGView() {
203  getApp()->removeChore(this, MID_CHORE);
204  myViewer->setDone(true);
205  myViewer = 0;
206  myRoot = 0;
207  myAdapter = 0;
208 }
209 
210 
211 void
212 GUIOSGView::buildViewToolBars(GUIGlChildWindow& v) {
213  // build coloring tools
214  {
215  const std::vector<std::string>& names = gSchemeStorage.getNames();
216  for (std::vector<std::string>::const_iterator i = names.begin(); i != names.end(); ++i) {
217  v.getColoringSchemesCombo().appendItem((*i).c_str());
218  if ((*i) == myVisualizationSettings->name) {
219  v.getColoringSchemesCombo().setCurrentItem(v.getColoringSchemesCombo().getNumItems() - 1);
220  }
221  }
222  v.getColoringSchemesCombo().setNumVisible(5);
223  }
224  // for junctions
225  new FXButton(v.getLocatorPopup(),
226  "\tLocate Junction\tLocate a junction within the network.",
228  ICON_ABOVE_TEXT | FRAME_THICK | FRAME_RAISED);
229  // for edges
230  new FXButton(v.getLocatorPopup(),
231  "\tLocate Street\tLocate a street within the network.",
233  ICON_ABOVE_TEXT | FRAME_THICK | FRAME_RAISED);
234  // for vehicles
235  new FXButton(v.getLocatorPopup(),
236  "\tLocate Vehicle\tLocate a vehicle within the network.",
238  ICON_ABOVE_TEXT | FRAME_THICK | FRAME_RAISED);
239  // for persons
240  new FXButton(v.getLocatorPopup(),
241  "\tLocate Vehicle\tLocate a person within the network.",
243  ICON_ABOVE_TEXT | FRAME_THICK | FRAME_RAISED);
244  // for tls
245  new FXButton(v.getLocatorPopup(),
246  "\tLocate TLS\tLocate a tls within the network.",
248  ICON_ABOVE_TEXT | FRAME_THICK | FRAME_RAISED);
249  // for additional stuff
250  new FXButton(v.getLocatorPopup(),
251  "\tLocate Additional\tLocate an additional structure within the network.",
253  ICON_ABOVE_TEXT | FRAME_THICK | FRAME_RAISED);
254  // for pois
255  new FXButton(v.getLocatorPopup(),
256  "\tLocate POI\tLocate a POI within the network.",
258  ICON_ABOVE_TEXT | FRAME_THICK | FRAME_RAISED);
259  // for polygons
260  new FXButton(v.getLocatorPopup(),
261  "\tLocate Polygon\tLocate a Polygon within the network.",
263  ICON_ABOVE_TEXT | FRAME_THICK | FRAME_RAISED);
264 }
265 
266 
267 void
268 GUIOSGView::recenterView() {
269  stopTrack();
270  myViewer->home();
271 }
272 
273 
274 void
275 GUIOSGView::centerTo(GUIGlID id, bool /* applyZoom */, SUMOReal /* zoomDist */) {
276  startTrack(id);
277 }
278 
279 
280 bool
281 GUIOSGView::setColorScheme(const std::string& name) {
282  if (!gSchemeStorage.contains(name)) {
283  return false;
284  }
285  if (myVisualizationChanger != 0) {
286  if (myVisualizationChanger->getCurrentScheme() != name) {
287  myVisualizationChanger->setCurrentScheme(name);
288  }
289  }
290  myVisualizationSettings = &gSchemeStorage.get(name.c_str());
291  myVisualizationSettings->gaming = myApp->isGaming();
292  update();
293  return true;
294 }
295 
296 
297 long
298 GUIOSGView::onPaint(FXObject*, FXSelector, void*) {
299  if (!isEnabled()) {
300  return 1;
301  }
302  myDecalsLock.lock();
303  for (std::vector<GUISUMOAbstractView::Decal>::iterator l = myDecals.begin(); l != myDecals.end(); ++l) {
305  if (!d.initialised) {
306  if (d.filename.length() == 6 && d.filename.substr(0, 5) == "light") {
307  GUIOSGBuilder::buildLight(d, *myRoot);
308  } else if (d.filename.length() > 3 && d.filename.substr(0, 3) == "tl:") {
309  const int linkStringIdx = d.filename.find(':', 3);
310  GUINet* net = (GUINet*) MSNet::getInstance();
311  try {
312  MSTLLogicControl::TLSLogicVariants& vars = net->getTLSControl().get(d.filename.substr(3, linkStringIdx - 3));
313  const int linkIdx = TplConvert::_2int(d.filename.substr(linkStringIdx + 1).c_str());
314  if (linkIdx < 0 || linkIdx >= static_cast<int>(vars.getActive()->getLinks().size())) {
315  throw NumberFormatException();
316  }
317  const MSLink* const l = vars.getActive()->getLinksAt(linkIdx)[0];
318  osg::Switch* switchNode = new osg::Switch();
319  switchNode->addChild(GUIOSGBuilder::getTrafficLight(d, d.layer < 0 ? 0 : myGreenLight, osg::Vec4(0., 1., 0., .3)), false);
320  switchNode->addChild(GUIOSGBuilder::getTrafficLight(d, d.layer < 0 ? 0 : myYellowLight, osg::Vec4(1., 1., 0., .3)), false);
321  switchNode->addChild(GUIOSGBuilder::getTrafficLight(d, d.layer < 0 ? 0 : myRedLight, osg::Vec4(1., 0., 0., .3)), false);
322  switchNode->addChild(GUIOSGBuilder::getTrafficLight(d, d.layer < 0 ? 0 : myRedYellowLight, osg::Vec4(1., .5, 0., .3)), false);
323  myRoot->addChild(switchNode);
324  vars.addSwitchCommand(new Command_TLSChange(l, switchNode));
325  } catch (NumberFormatException&) {
326  WRITE_ERROR("Invalid link index in '" + d.filename + "'.");
327  } catch (InvalidArgument&) {
328  WRITE_ERROR("Unknown traffic light in '" + d.filename + "'.");
329  }
330  } else {
331  GUIOSGBuilder::buildDecal(d, *myRoot);
332  }
333  d.initialised = true;
334  }
335  }
336  myDecalsLock.unlock();
338  for (; it != MSNet::getInstance()->getVehicleControl().loadedVehEnd(); it++) {
339  GUIVehicle* veh = static_cast<GUIVehicle*>(it->second);
340  if (!veh->isOnRoad()) {
341  continue;
342  }
343  if (myVehicles.find(veh) == myVehicles.end()) {
344  myVehicles[veh] = GUIOSGBuilder::buildMovable(veh->getVehicleType());
345  myRoot->addChild(myVehicles[veh].pos);
346  }
347  osg::PositionAttitudeTransform* n = myVehicles[veh].pos;
348  n->setPosition(osg::Vec3(veh->getPosition().x(), veh->getPosition().y(), veh->getPosition().z()));
349  const SUMOReal dir = veh->getAngle() + PI / 2.;
350  const SUMOReal slope = veh->getSlope();
351  n->setAttitude(osg::Quat(dir, osg::Vec3(0, 0, 1)) *
352  osg::Quat(osg::DegreesToRadians(slope), osg::Vec3(0, 1, 0)));
353  /*
354  osg::ref_ptr<osg::AnimationPath> path = new osg::AnimationPath;
355  // path->setLoopMode( osg::AnimationPath::NO_LOOPING );
356  osg::AnimationPath::ControlPoint pointA(n->getPosition(), n->getAttitude());
357  osg::AnimationPath::ControlPoint pointB(osg::Vec3(veh->getPosition().x(), veh->getPosition().y(), veh->getPosition().z()),
358  osg::Quat(dir, osg::Vec3(0, 0, 1)) *
359  osg::Quat(osg::DegreesToRadians(slope), osg::Vec3(0, 1, 0)));
360  path->insert(0.0f, pointA);
361  path->insert(0.5f, pointB);
362  n->setUpdateCallback(new osg::AnimationPathCallback(path));
363  */
364  const RGBColor& col = myVisualizationSettings->vehicleColorer.getScheme().getColor(veh->getColorValue(myVisualizationSettings->vehicleColorer.getActive()));
365  myVehicles[veh].geom->setColor(osg::Vec4(col.red() / 255., col.green() / 255., col.blue() / 255., col.alpha() / 255.));
367  myVehicles[veh].lights->setValue(1, veh->signalSet(MSVehicle::VEH_SIGNAL_BLINKER_LEFT | MSVehicle::VEH_SIGNAL_BLINKER_EMERGENCY));
368  myVehicles[veh].lights->setValue(2, veh->signalSet(MSVehicle::VEH_SIGNAL_BRAKELIGHT));
369  }
370 
372  if (now != myLastUpdate || (myVisualizationChanger != 0 && myVisualizationChanger->shown())) {
373  GUINet::getGUIInstance()->updateColor(*myVisualizationSettings);
374  }
375  if (now != myLastUpdate && myTracked != 0) {
376  osg::Vec3d lookFrom, lookAt, up;
377  lookAt[0] = myTracked->getPosition().x();
378  lookAt[1] = myTracked->getPosition().y();
379  lookAt[2] = myTracked->getPosition().z();
380  const SUMOReal angle = myTracked->getAngle();
381  lookFrom[0] = lookAt[0] + 50. * cos(angle);
382  lookFrom[1] = lookAt[1] + 50. * sin(angle);
383  lookFrom[2] = lookAt[2] + 10.;
384  osg::Matrix m;
385  m.makeLookAt(lookFrom, lookAt, osg::Z_AXIS);
386  myCameraManipulator->setByInverseMatrix(m);
387  }
388 
389  for (std::map<std::string, MSTransportable*>::const_iterator it = MSNet::getInstance()->getPersonControl().loadedBegin(); it != MSNet::getInstance()->getPersonControl().loadedEnd(); ++it) {
390  MSTransportable* person = (*it).second;
391  // XXX if not departed: continue
392  if (myPersons.find(person) == myPersons.end()) {
393  myPersons[person] = GUIOSGBuilder::buildMovable(person->getVehicleType());
394  myRoot->addChild(myPersons[person].pos);
395  }
396  osg::PositionAttitudeTransform* n = myPersons[person].pos;
397  const Position pos = person->getPosition();
398  n->setPosition(osg::Vec3(pos.x(), pos.y(), pos.z()));
399  const SUMOReal dir = person->getAngle() + PI / 2.;
400  n->setAttitude(osg::Quat(dir, osg::Vec3(0, 0, 1)));
401  }
402  if (myAdapter->makeCurrent()) {
403  myViewer->frame();
404  makeNonCurrent();
405  }
406  myLastUpdate = now;
407  return 1;
408 }
409 
410 
411 void
412 GUIOSGView::remove(GUIVehicle* veh) {
413  if (myTracked == veh) {
414  stopTrack();
415  }
416  std::map<MSVehicle*, OSGMovable>::iterator i = myVehicles.find(veh);
417  if (i != myVehicles.end()) {
418  myRoot->removeChild(i->second.pos);
419  myVehicles.erase(i);
420  }
421 }
422 
423 
424 void
425 GUIOSGView::showViewportEditor() {
426  getViewportEditor(); // make sure it exists;
427  osg::Vec3d lookFromOSG, lookAtOSG, up;
428  myViewer->getCameraManipulator()->getInverseMatrix().getLookAt(lookFromOSG, lookAtOSG, up);
429  Position from(lookFromOSG[0], lookFromOSG[1], lookFromOSG[2]), at(lookAtOSG[0], lookAtOSG[1], lookAtOSG[2]);
430  myViewportChooser->setOldValues(from, at);
431  myViewportChooser->show();
432 }
433 
434 
435 void
436 GUIOSGView::setViewport(const Position& lookFrom, const Position& lookAt) {
437  osg::Vec3d lookFromOSG, lookAtOSG, up;
438  myViewer->getCameraManipulator()->getHomePosition(lookFromOSG, lookAtOSG, up);
439  lookFromOSG[0] = lookFrom.x();
440  lookFromOSG[1] = lookFrom.y();
441  lookFromOSG[2] = lookFrom.z();
442  lookAtOSG[0] = lookAt.x();
443  lookAtOSG[1] = lookAt.y();
444  lookAtOSG[2] = lookAt.z();
445  myViewer->getCameraManipulator()->setHomePosition(lookFromOSG, lookAtOSG, up);
446  myViewer->home();
447 }
448 
449 
450 void
451 GUIOSGView::startTrack(int id) {
452  if (myTracked == 0 || (int)myTracked->getGlID() != id) {
453  myTracked = 0;
455  for (; it != MSNet::getInstance()->getVehicleControl().loadedVehEnd(); it++) {
456  GUIVehicle* veh = (GUIVehicle*)(*it).second;
457  if ((int)veh->getGlID() == id) {
458  if (!veh->isOnRoad() || myVehicles.find(veh) == myVehicles.end()) {
459  return;
460  }
461  myTracked = veh;
462  break;
463  }
464  }
465  if (myTracked != 0) {
466  osg::Vec3d lookFrom, lookAt, up;
467  lookAt[0] = myTracked->getPosition().x();
468  lookAt[1] = myTracked->getPosition().y();
469  lookAt[2] = myTracked->getPosition().z();
470  lookFrom[0] = lookAt[0] + 50.;
471  lookFrom[1] = lookAt[1] + 50.;
472  lookFrom[2] = lookAt[2] + 10.;
473  osg::Matrix m;
474  m.makeLookAt(lookFrom, lookAt, osg::Z_AXIS);
475  myCameraManipulator->setByInverseMatrix(m);
476  }
477  }
478 }
479 
480 
481 void
482 GUIOSGView::stopTrack() {
483  myTracked = 0;
484 }
485 
486 
487 int
488 GUIOSGView::getTrackedID() const {
489  return myTracked == 0 ? -1 : myTracked->getGlID();
490 }
491 
492 
493 void
494 GUIOSGView::onGamingClick(Position pos) {
496  const std::vector<MSTrafficLightLogic*>& logics = tlsControl.getAllLogics();
497  MSTrafficLightLogic* minTll = 0;
498  SUMOReal minDist = std::numeric_limits<SUMOReal>::infinity();
499  for (std::vector<MSTrafficLightLogic*>::const_iterator i = logics.begin(); i != logics.end(); ++i) {
500  // get the logic
501  MSTrafficLightLogic* tll = (*i);
502  if (tlsControl.isActive(tll)) {
503  // get the links
504  const MSTrafficLightLogic::LaneVector& lanes = tll->getLanesAt(0);
505  if (lanes.size() > 0) {
506  const Position& endPos = lanes[0]->getShape().back();
507  if (endPos.distanceTo(pos) < minDist) {
508  minDist = endPos.distanceTo(pos);
509  minTll = tll;
510  }
511  }
512  }
513  }
514  if (minTll != 0) {
515  const MSTLLogicControl::TLSLogicVariants& vars = tlsControl.get(minTll->getID());
516  const std::vector<MSTrafficLightLogic*> logics = vars.getAllLogics();
517  if (logics.size() > 1) {
519  for (unsigned int i = 0; i < logics.size() - 1; i++) {
520  if (minTll->getProgramID() == logics[i]->getProgramID()) {
521  l = (MSSimpleTrafficLightLogic*) logics[i + 1];
522  tlsControl.switchTo(minTll->getID(), l->getProgramID());
523  }
524  }
525  if (l == logics[0]) {
526  tlsControl.switchTo(minTll->getID(), l->getProgramID());
527  }
529  update();
530  }
531  }
532 }
533 
534 
535 SUMOTime
536 GUIOSGView::getCurrentTimeStep() const {
538 }
539 
540 
541 long GUIOSGView::onConfigure(FXObject* sender, FXSelector sel, void* ptr) {
542  // update the window dimensions, in case the window has been resized.
543  myAdapter->getEventQueue()->windowResize(0, 0, getWidth(), getHeight());
544  myAdapter->resized(0, 0, getWidth(), getHeight());
545 
546  return FXGLCanvas::onConfigure(sender, sel, ptr);
547 }
548 
549 long GUIOSGView::onKeyPress(FXObject* sender, FXSelector sel, void* ptr) {
550  int key = ((FXEvent*)ptr)->code;
551  myAdapter->getEventQueue()->keyPress(key);
552 
553  return FXGLCanvas::onKeyPress(sender, sel, ptr);
554 }
555 
556 long GUIOSGView::onKeyRelease(FXObject* sender, FXSelector sel, void* ptr) {
557  int key = ((FXEvent*)ptr)->code;
558  myAdapter->getEventQueue()->keyRelease(key);
559 
560  return FXGLCanvas::onKeyRelease(sender, sel, ptr);
561 }
562 
563 long GUIOSGView::onLeftBtnPress(FXObject* sender, FXSelector sel, void* ptr) {
564  handle(this, FXSEL(SEL_FOCUS_SELF, 0), ptr);
565 
566  FXEvent* event = (FXEvent*)ptr;
567  myAdapter->getEventQueue()->mouseButtonPress(event->click_x, event->click_y, 1);
568  if (myApp->isGaming()) {
569  onGamingClick(getPositionInformation());
570  }
571 
572  return FXGLCanvas::onLeftBtnPress(sender, sel, ptr);
573 }
574 
575 long GUIOSGView::onLeftBtnRelease(FXObject* sender, FXSelector sel, void* ptr) {
576  FXEvent* event = (FXEvent*)ptr;
577  myAdapter->getEventQueue()->mouseButtonRelease(event->click_x, event->click_y, 1);
578 
579  return FXGLCanvas::onLeftBtnRelease(sender, sel, ptr);
580 }
581 
582 long GUIOSGView::onMiddleBtnPress(FXObject* sender, FXSelector sel, void* ptr) {
583  handle(this, FXSEL(SEL_FOCUS_SELF, 0), ptr);
584 
585  FXEvent* event = (FXEvent*)ptr;
586  myAdapter->getEventQueue()->mouseButtonPress(event->click_x, event->click_y, 2);
587 
588  return FXGLCanvas::onMiddleBtnPress(sender, sel, ptr);
589 }
590 
591 long GUIOSGView::onMiddleBtnRelease(FXObject* sender, FXSelector sel, void* ptr) {
592  FXEvent* event = (FXEvent*)ptr;
593  myAdapter->getEventQueue()->mouseButtonRelease(event->click_x, event->click_y, 2);
594 
595  return FXGLCanvas::onMiddleBtnRelease(sender, sel, ptr);
596 }
597 
598 long GUIOSGView::onRightBtnPress(FXObject* sender, FXSelector sel, void* ptr) {
599  handle(this, FXSEL(SEL_FOCUS_SELF, 0), ptr);
600 
601  FXEvent* event = (FXEvent*)ptr;
602  myAdapter->getEventQueue()->mouseButtonPress(event->click_x, event->click_y, 3);
603 
604  return FXGLCanvas::onRightBtnPress(sender, sel, ptr);
605 }
606 
607 long GUIOSGView::onRightBtnRelease(FXObject* sender, FXSelector sel, void* ptr) {
608  FXEvent* event = (FXEvent*)ptr;
609  myAdapter->getEventQueue()->mouseButtonRelease(event->click_x, event->click_y, 3);
610 
611  return FXGLCanvas::onRightBtnRelease(sender, sel, ptr);
612 }
613 
614 long
615 GUIOSGView::onMouseMove(FXObject* sender, FXSelector sel, void* ptr) {
616  FXEvent* event = (FXEvent*)ptr;
617  myAdapter->getEventQueue()->mouseMotion(event->win_x, event->win_y);
618 
619  return FXGLCanvas::onMotion(sender, sel, ptr);
620 }
621 
622 long
623 GUIOSGView::OnIdle(FXObject* /* sender */, FXSelector /* sel */, void*) {
624  forceRefresh();
625  update();
626  getApp()->addChore(this, MID_CHORE);
627  return 1;
628 }
629 
630 
631 
632 GUIOSGView::FXOSGAdapter::FXOSGAdapter(GUISUMOAbstractView* parent, FXCursor* cursor)
633  : myParent(parent), myOldCursor(cursor) {
634  _traits = new GraphicsContext::Traits();
635  _traits->x = 0;
636  _traits->y = 0;
637  _traits->width = parent->getWidth();
638  _traits->height = parent->getHeight();
639  _traits->windowDecoration = false;
640  _traits->doubleBuffer = true;
641  _traits->sharedContext = 0;
642  if (valid()) {
643  setState(new osg::State());
644  getState()->setGraphicsContext(this);
645  if (_traits.valid() && _traits->sharedContext != 0) {
646  getState()->setContextID(_traits->sharedContext->getState()->getContextID());
647  incrementContextIDUsageCount(getState()->getContextID());
648  } else {
649  getState()->setContextID(createNewContextID());
650  }
651  }
652 }
653 
654 
655 GUIOSGView::FXOSGAdapter::~FXOSGAdapter() {
656  delete myOldCursor;
657 }
658 
659 
660 void GUIOSGView::FXOSGAdapter::grabFocus() {
661  // focus this window
662  myParent->setFocus();
663 }
664 
665 void GUIOSGView::FXOSGAdapter::useCursor(bool cursorOn) {
666  if (cursorOn) {
667  myParent->setDefaultCursor(myOldCursor);
668  } else {
669  myParent->setDefaultCursor(NULL);
670  }
671 }
672 
673 bool GUIOSGView::FXOSGAdapter::makeCurrentImplementation() {
674  myParent->makeCurrent();
675  return true;
676 }
677 
678 bool GUIOSGView::FXOSGAdapter::releaseContext() {
679  myParent->makeNonCurrent();
680  return true;
681 }
682 
683 void GUIOSGView::FXOSGAdapter::swapBuffersImplementation() {
684  myParent->swapBuffers();
685 }
686 
687 
688 #endif
689 
690 /****************************************************************************/
bool signalSet(int which) const
Returns whether the given signal is on.
Definition: MSVehicle.h:1020
A decal (an image) that can be shown.
void changeStepAndDuration(MSTLLogicControl &tlcontrol, SUMOTime simStep, unsigned int step, SUMOTime stepDuration)
Changes the current phase and her duration.
The link has green light, may pass.
bool isActive(const MSTrafficLightLogic *tl) const
Returns whether the given tls program is the currently active for his tls.
SUMOReal getColorValue(size_t activeScheme) const
gets the color value according to the current scheme index
Definition: GUIVehicle.cpp:377
GUICompleteSchemeStorage gSchemeStorage
long long int SUMOTime
Definition: SUMOTime.h:43
Locate poi - button.
Definition: GUIAppEnum.h:187
Storage for all programs of a single tls.
static bool isReadable(std::string path)
Checks whether the given file is readable.
Definition: FileHelpers.cpp:58
void switchTo(const std::string &id, const std::string &programID)
Switches the named (id) tls to the named (programID) program.
constVehIt loadedVehBegin() const
Returns the begin of the internal vehicle map.
bool gaming
whether the application is in gaming mode or not
Locate vehicle - button.
Definition: GUIAppEnum.h:175
The link has green light, has to brake.
Locate person - button.
Definition: GUIAppEnum.h:177
Locate TLS - button.
Definition: GUIAppEnum.h:179
static MSNet * getInstance()
Returns the pointer to the unique instance of MSNet (singleton).
Definition: MSNet.cpp:159
const MSPhaseDefinition & getPhase(int givenstep) const
Returns the definition of the phase from the given position within the plan.
SUMOReal distanceTo(const Position &p2) const
returns the euclidean distance in 3 dimension
Definition: Position.h:221
The link is controlled by a tls which is off, not blinking, may pass.
virtual SUMOReal getAngle() const
return the current angle of the transportable
SUMOTime getCurrentTimeStep() const
Returns the current simulation step.
Definition: MSNet.h:253
SUMORTree & getVisualisationSpeedUp()
Returns the RTree used for visualisation speed-up.
Definition: GUINet.h:277
Locate junction - button.
Definition: GUIAppEnum.h:171
SUMOReal x() const
Returns the x-position.
Definition: Position.h:63
GUIGlID getGlID() const
Returns the numerical id of the object.
FXDEFMAP(GUIDialog_AppSettings) GUIDialog_AppSettingsMap[]
A fixed traffic light logic.
Right blinker lights are switched on.
Definition: MSVehicle.h:942
unsigned char blue() const
Returns the blue-amount of the color.
Definition: RGBColor.h:91
A class that stores and controls tls and switching of their programs.
std::vector< MSTrafficLightLogic * > getAllLogics() const
#define new
Definition: debug_new.h:121
const std::string & getID() const
Returns the id.
Definition: Named.h:66
SUMOTime duration
The duration of the phase.
const std::vector< std::string > & getNames() const
Returns a list of stored settings names.
const MSVehicleType & getVehicleType() const
void addSwitchCommand(OnSwitchAction *c)
Left blinker lights are switched on.
Definition: MSVehicle.h:944
#define PI
Definition: polyfonts.c:61
MSTrafficLightLogic * getActive() const
Locate polygons - button.
Definition: GUIAppEnum.h:189
static GUINet * getGUIInstance()
Returns the pointer to the unique instance of GUINet (singleton).
Definition: GUINet.cpp:502
virtual MSTransportableControl & getPersonControl()
Returns the person control.
Definition: MSNet.cpp:693
A point in 2D or 3D with translation and scaling methods.
Definition: Position.h:46
MSTLLogicControl & getTLSControl()
Returns the tls logics control.
Definition: MSNet.h:379
FXComboBox & getColoringSchemesCombo()
const LaneVector & getLanesAt(unsigned int i) const
Returns the list of lanes that are controlled by the signals at the given position.
MSVehicleControl & getVehicleControl()
Returns the vehicle control.
Definition: MSNet.h:306
unsigned char alpha() const
Returns the alpha-amount of the color.
Definition: RGBColor.h:99
bool contains(const std::string &name) const
Returns the information whether a setting with the given name is stored.
const LinkVector & getLinksAt(unsigned int i) const
Returns the list of links that are controlled by the signals at the given position.
const LinkVectorVector & getLinks() const
Returns the list of lists of all affected links.
SUMOReal z() const
Returns the z-position.
Definition: Position.h:73
GUIVisualizationSettings & get(const std::string &name)
Returns the named scheme.
Blinker lights on both sides are switched on.
Definition: MSVehicle.h:946
bool initialised
Whether this image was initialised (inserted as a texture)
The brake lights are on.
Definition: MSVehicle.h:948
std::string filename
The path to the file the image is located at.
MSTransportableControl & getPersonControl()
Returns the person control.
Definition: GUINet.cpp:124
A single child window which contains a view of the simulation area.
#define WRITE_ERROR(msg)
Definition: MsgHandler.h:206
unsigned int GUIGlID
Definition: GUIGlObject.h:50
constVehIt loadedEnd() const
Returns the end of the internal transportables map.
static int _2int(const E *const data)
converts a char-type array into the integer value described by it
Definition: TplConvert.h:149
std::vector< MSLane * > LaneVector
Definition of the list of links that participate in this tl-light.
chore
Definition: GUIAppEnum.h:213
Locate addtional structure - button.
Definition: GUIAppEnum.h:185
A MSNet extended by some values for usage within the gui.
Definition: GUINet.h:89
SUMOReal getSlope() const
Returns the slope of the road at vehicle&#39;s position.
Definition: MSVehicle.cpp:750
The link has yellow light, may pass.
SUMOReal y() const
Returns the y-position.
Definition: Position.h:68
The link has red light (must brake)
const MSVehicleType & getVehicleType() const
Returns the vehicle&#39;s type definition.
Definition: MSBaseVehicle.h:97
std::map< std::string, SUMOVehicle * >::const_iterator constVehIt
Definition of the internal vehicles map iterator.
virtual Position getPosition() const
Return the Network coordinate of the transportable.
TLSLogicVariants & get(const std::string &id) const
Returns the variants of a named tls.
Position getPosition(const SUMOReal offset=0) const
Return current position (x/y, cartesian)
Definition: GUIVehicle.h:81
SUMOReal layer
The layer of the image.
The parent class for traffic light logics.
unsigned char green() const
Returns the green-amount of the color.
Definition: RGBColor.h:83
#define SUMOReal
Definition: config.h:214
const std::string & getProgramID() const
Returns this tl-logic&#39;s id.
constVehIt loadedVehEnd() const
Returns the end of the internal vehicle map.
Locate edge - button.
Definition: GUIAppEnum.h:173
std::vector< MSTrafficLightLogic * > getAllLogics() const
Returns a vector which contains all logics.
The link has yellow light, has to brake anyway.
bool isOnRoad() const
Returns the information whether the vehicle is on a road (is simulated)
Definition: MSVehicle.h:455
unsigned char red() const
Returns the red-amount of the color.
Definition: RGBColor.h:75
SUMOReal getAngle() const
Return current angle.
Definition: GUIVehicle.h:89
static FXIcon * getIcon(GUIIcon which)
returns a icon previously defined in the enum GUIIcon
The link has red light (must brake) but indicates upcoming green.
FXPopup * getLocatorPopup()
A MSVehicle extended by some values for usage within the gui.
Definition: GUIVehicle.h:61