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