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  Position center = myGrid->getCenter();
271  osg::Vec3d lookFromOSG, lookAtOSG, up;
272  myViewer->getCameraManipulator()->getHomePosition(lookFromOSG, lookAtOSG, up);
273  lookFromOSG[0] = center.x();
274  lookFromOSG[1] = center.y();
275  lookFromOSG[2] = myChanger->zoom2ZPos(100);
276  lookAtOSG[0] = center.x();
277  lookAtOSG[1] = center.y();
278  lookAtOSG[2] = 0;
279  myViewer->getCameraManipulator()->setHomePosition(lookFromOSG, lookAtOSG, up);
280  myViewer->home();
281 }
282 
283 
284 void
285 GUIOSGView::centerTo(GUIGlID id, bool /* applyZoom */, SUMOReal /* zoomDist */) {
286  startTrack(id);
287 }
288 
289 
290 bool
291 GUIOSGView::setColorScheme(const std::string& name) {
292  if (!gSchemeStorage.contains(name)) {
293  return false;
294  }
295  if (myVisualizationChanger != 0) {
296  if (myVisualizationChanger->getCurrentScheme() != name) {
297  myVisualizationChanger->setCurrentScheme(name);
298  }
299  }
300  myVisualizationSettings = &gSchemeStorage.get(name.c_str());
301  myVisualizationSettings->gaming = myApp->isGaming();
302  update();
303  return true;
304 }
305 
306 
307 long
308 GUIOSGView::onPaint(FXObject*, FXSelector, void*) {
309  if (!isEnabled()) {
310  return 1;
311  }
312  myDecalsLock.lock();
313  for (std::vector<GUISUMOAbstractView::Decal>::iterator l = myDecals.begin(); l != myDecals.end(); ++l) {
315  if (!d.initialised) {
316  if (d.filename.length() == 6 && d.filename.substr(0, 5) == "light") {
317  GUIOSGBuilder::buildLight(d, *myRoot);
318  } else if (d.filename.length() > 3 && d.filename.substr(0, 3) == "tl:") {
319  const int linkStringIdx = d.filename.find(':', 3);
320  GUINet* net = (GUINet*) MSNet::getInstance();
321  try {
322  MSTLLogicControl::TLSLogicVariants& vars = net->getTLSControl().get(d.filename.substr(3, linkStringIdx - 3));
323  const int linkIdx = TplConvert::_2int(d.filename.substr(linkStringIdx + 1).c_str());
324  if (linkIdx < 0 || linkIdx >= static_cast<int>(vars.getActive()->getLinks().size())) {
325  throw NumberFormatException();
326  }
327  const MSLink* const l = vars.getActive()->getLinksAt(linkIdx)[0];
328  osg::Switch* switchNode = new osg::Switch();
329  switchNode->addChild(GUIOSGBuilder::getTrafficLight(d, d.layer < 0 ? 0 : myGreenLight, osg::Vec4(0., 1., 0., .3)), false);
330  switchNode->addChild(GUIOSGBuilder::getTrafficLight(d, d.layer < 0 ? 0 : myYellowLight, osg::Vec4(1., 1., 0., .3)), false);
331  switchNode->addChild(GUIOSGBuilder::getTrafficLight(d, d.layer < 0 ? 0 : myRedLight, osg::Vec4(1., 0., 0., .3)), false);
332  switchNode->addChild(GUIOSGBuilder::getTrafficLight(d, d.layer < 0 ? 0 : myRedYellowLight, osg::Vec4(1., .5, 0., .3)), false);
333  myRoot->addChild(switchNode);
334  vars.addSwitchCommand(new Command_TLSChange(l, switchNode));
335  } catch (NumberFormatException&) {
336  WRITE_ERROR("Invalid link index in '" + d.filename + "'.");
337  } catch (InvalidArgument&) {
338  WRITE_ERROR("Unknown traffic light in '" + d.filename + "'.");
339  }
340  } else {
341  GUIOSGBuilder::buildDecal(d, *myRoot);
342  }
343  d.initialised = true;
344  }
345  }
346  myDecalsLock.unlock();
348  for (; it != MSNet::getInstance()->getVehicleControl().loadedVehEnd(); it++) {
349  GUIVehicle* veh = static_cast<GUIVehicle*>(it->second);
350  if (!veh->isOnRoad()) {
351  continue;
352  }
353  if (myVehicles.find(veh) == myVehicles.end()) {
354  myVehicles[veh] = GUIOSGBuilder::buildMovable(veh->getVehicleType());
355  myRoot->addChild(myVehicles[veh].pos);
356  }
357  osg::PositionAttitudeTransform* n = myVehicles[veh].pos;
358  n->setPosition(osg::Vec3(veh->getPosition().x(), veh->getPosition().y(), veh->getPosition().z()));
359  const SUMOReal dir = veh->getAngle() + PI / 2.;
360  const SUMOReal slope = veh->getSlope();
361  n->setAttitude(osg::Quat(dir, osg::Vec3(0, 0, 1)) *
362  osg::Quat(osg::DegreesToRadians(slope), osg::Vec3(0, 1, 0)));
363  /*
364  osg::ref_ptr<osg::AnimationPath> path = new osg::AnimationPath;
365  // path->setLoopMode( osg::AnimationPath::NO_LOOPING );
366  osg::AnimationPath::ControlPoint pointA(n->getPosition(), n->getAttitude());
367  osg::AnimationPath::ControlPoint pointB(osg::Vec3(veh->getPosition().x(), veh->getPosition().y(), veh->getPosition().z()),
368  osg::Quat(dir, osg::Vec3(0, 0, 1)) *
369  osg::Quat(osg::DegreesToRadians(slope), osg::Vec3(0, 1, 0)));
370  path->insert(0.0f, pointA);
371  path->insert(0.5f, pointB);
372  n->setUpdateCallback(new osg::AnimationPathCallback(path));
373  */
374  const RGBColor& col = myVisualizationSettings->vehicleColorer.getScheme().getColor(veh->getColorValue(myVisualizationSettings->vehicleColorer.getActive()));
375  myVehicles[veh].geom->setColor(osg::Vec4(col.red() / 255., col.green() / 255., col.blue() / 255., col.alpha() / 255.));
377  myVehicles[veh].lights->setValue(1, veh->signalSet(MSVehicle::VEH_SIGNAL_BLINKER_LEFT | MSVehicle::VEH_SIGNAL_BLINKER_EMERGENCY));
378  myVehicles[veh].lights->setValue(2, veh->signalSet(MSVehicle::VEH_SIGNAL_BRAKELIGHT));
379  }
380 
382  if (now != myLastUpdate || (myVisualizationChanger != 0 && myVisualizationChanger->shown())) {
383  GUINet::getGUIInstance()->updateColor(*myVisualizationSettings);
384  }
385  if (now != myLastUpdate && myTracked != 0) {
386  osg::Vec3d lookFrom, lookAt, up;
387  lookAt[0] = myTracked->getPosition().x();
388  lookAt[1] = myTracked->getPosition().y();
389  lookAt[2] = myTracked->getPosition().z();
390  const SUMOReal angle = myTracked->getAngle();
391  lookFrom[0] = lookAt[0] + 50. * cos(angle);
392  lookFrom[1] = lookAt[1] + 50. * sin(angle);
393  lookFrom[2] = lookAt[2] + 10.;
394  osg::Matrix m;
395  m.makeLookAt(lookFrom, lookAt, osg::Z_AXIS);
396  myCameraManipulator->setByInverseMatrix(m);
397  }
398 
399  for (std::map<std::string, MSTransportable*>::const_iterator it = MSNet::getInstance()->getPersonControl().loadedBegin(); it != MSNet::getInstance()->getPersonControl().loadedEnd(); ++it) {
400  MSTransportable* person = (*it).second;
401  // XXX if not departed: continue
402  if (myPersons.find(person) == myPersons.end()) {
403  myPersons[person] = GUIOSGBuilder::buildMovable(person->getVehicleType());
404  myRoot->addChild(myPersons[person].pos);
405  }
406  osg::PositionAttitudeTransform* n = myPersons[person].pos;
407  const Position pos = person->getPosition();
408  n->setPosition(osg::Vec3(pos.x(), pos.y(), pos.z()));
409  const SUMOReal dir = person->getAngle() + PI / 2.;
410  n->setAttitude(osg::Quat(dir, osg::Vec3(0, 0, 1)));
411  }
412  if (myAdapter->makeCurrent()) {
413  myViewer->frame();
414  makeNonCurrent();
415  }
416  myLastUpdate = now;
417  return 1;
418 }
419 
420 
421 void
422 GUIOSGView::remove(GUIVehicle* veh) {
423  if (myTracked == veh) {
424  stopTrack();
425  }
426  std::map<MSVehicle*, OSGMovable>::iterator i = myVehicles.find(veh);
427  if (i != myVehicles.end()) {
428  myRoot->removeChild(i->second.pos);
429  myVehicles.erase(i);
430  }
431 }
432 
433 
434 void
435 GUIOSGView::showViewportEditor() {
436  getViewportEditor(); // make sure it exists;
437  osg::Vec3d lookFromOSG, lookAtOSG, up;
438  myViewer->getCameraManipulator()->getInverseMatrix().getLookAt(lookFromOSG, lookAtOSG, up);
439  Position from(lookFromOSG[0], lookFromOSG[1], lookFromOSG[2]), at(lookAtOSG[0], lookAtOSG[1], lookAtOSG[2]);
440  myViewportChooser->setOldValues(from, at);
441  myViewportChooser->show();
442 }
443 
444 
445 void
446 GUIOSGView::setViewportFromTo(const Position& lookFrom, const Position& lookAt) {
447  osg::Vec3d lookFromOSG, lookAtOSG, up;
448  myViewer->getCameraManipulator()->getHomePosition(lookFromOSG, lookAtOSG, up);
449  lookFromOSG[0] = lookFrom.x();
450  lookFromOSG[1] = lookFrom.y();
451  lookFromOSG[2] = lookFrom.z();
452  lookAtOSG[0] = lookAt.x();
453  lookAtOSG[1] = lookAt.y();
454  lookAtOSG[2] = lookAt.z();
455  myViewer->getCameraManipulator()->setHomePosition(lookFromOSG, lookAtOSG, up);
456  myViewer->home();
457 }
458 
459 
460 
461 void
462 GUIOSGView::copyViewportTo(GUISUMOAbstractView* view) {
463  osg::Vec3d lookFrom, lookAt, up;
464  myCameraManipulator->getHomePosition(lookFrom, lookAt, up);
465  view->setViewportFromTo(Position(lookFrom[0], lookFrom[1], lookFrom[2]),
466  Position(lookAt[0], lookAt[1], lookAt[2]));
467 }
468 
469 
470 
471 void
472 GUIOSGView::startTrack(int id) {
473  if (myTracked == 0 || (int)myTracked->getGlID() != id) {
474  myTracked = 0;
476  for (; it != MSNet::getInstance()->getVehicleControl().loadedVehEnd(); it++) {
477  GUIVehicle* veh = (GUIVehicle*)(*it).second;
478  if ((int)veh->getGlID() == id) {
479  if (!veh->isOnRoad() || myVehicles.find(veh) == myVehicles.end()) {
480  return;
481  }
482  myTracked = veh;
483  break;
484  }
485  }
486  if (myTracked != 0) {
487  osg::Vec3d lookFrom, lookAt, up;
488  lookAt[0] = myTracked->getPosition().x();
489  lookAt[1] = myTracked->getPosition().y();
490  lookAt[2] = myTracked->getPosition().z();
491  lookFrom[0] = lookAt[0] + 50.;
492  lookFrom[1] = lookAt[1] + 50.;
493  lookFrom[2] = lookAt[2] + 10.;
494  osg::Matrix m;
495  m.makeLookAt(lookFrom, lookAt, osg::Z_AXIS);
496  myCameraManipulator->setByInverseMatrix(m);
497  }
498  }
499 }
500 
501 
502 void
503 GUIOSGView::stopTrack() {
504  myTracked = 0;
505 }
506 
507 
508 GUIGlID
509 GUIOSGView::getTrackedID() const {
510  return myTracked == 0 ? GUIGlObject::INVALID_ID : myTracked->getGlID();
511 }
512 
513 
514 void
515 GUIOSGView::onGamingClick(Position pos) {
517  const std::vector<MSTrafficLightLogic*>& logics = tlsControl.getAllLogics();
518  MSTrafficLightLogic* minTll = 0;
519  SUMOReal minDist = std::numeric_limits<SUMOReal>::infinity();
520  for (std::vector<MSTrafficLightLogic*>::const_iterator i = logics.begin(); i != logics.end(); ++i) {
521  // get the logic
522  MSTrafficLightLogic* tll = (*i);
523  if (tlsControl.isActive(tll)) {
524  // get the links
525  const MSTrafficLightLogic::LaneVector& lanes = tll->getLanesAt(0);
526  if (lanes.size() > 0) {
527  const Position& endPos = lanes[0]->getShape().back();
528  if (endPos.distanceTo(pos) < minDist) {
529  minDist = endPos.distanceTo(pos);
530  minTll = tll;
531  }
532  }
533  }
534  }
535  if (minTll != 0) {
536  const MSTLLogicControl::TLSLogicVariants& vars = tlsControl.get(minTll->getID());
537  const std::vector<MSTrafficLightLogic*> logics = vars.getAllLogics();
538  if (logics.size() > 1) {
540  for (int i = 0; i < (int)logics.size() - 1; i++) {
541  if (minTll->getProgramID() == logics[i]->getProgramID()) {
542  l = (MSSimpleTrafficLightLogic*) logics[i + 1];
543  tlsControl.switchTo(minTll->getID(), l->getProgramID());
544  }
545  }
546  if (l == logics[0]) {
547  tlsControl.switchTo(minTll->getID(), l->getProgramID());
548  }
550  update();
551  }
552  }
553 }
554 
555 
556 SUMOTime
557 GUIOSGView::getCurrentTimeStep() const {
559 }
560 
561 
562 long GUIOSGView::onConfigure(FXObject* sender, FXSelector sel, void* ptr) {
563  // update the window dimensions, in case the window has been resized.
564  myAdapter->getEventQueue()->windowResize(0, 0, getWidth(), getHeight());
565  myAdapter->resized(0, 0, getWidth(), getHeight());
566 
567  return FXGLCanvas::onConfigure(sender, sel, ptr);
568 }
569 
570 long GUIOSGView::onKeyPress(FXObject* sender, FXSelector sel, void* ptr) {
571  int key = ((FXEvent*)ptr)->code;
572  myAdapter->getEventQueue()->keyPress(key);
573 
574  return FXGLCanvas::onKeyPress(sender, sel, ptr);
575 }
576 
577 long GUIOSGView::onKeyRelease(FXObject* sender, FXSelector sel, void* ptr) {
578  int key = ((FXEvent*)ptr)->code;
579  myAdapter->getEventQueue()->keyRelease(key);
580 
581  return FXGLCanvas::onKeyRelease(sender, sel, ptr);
582 }
583 
584 long GUIOSGView::onLeftBtnPress(FXObject* sender, FXSelector sel, void* ptr) {
585  handle(this, FXSEL(SEL_FOCUS_SELF, 0), ptr);
586 
587  FXEvent* event = (FXEvent*)ptr;
588  myAdapter->getEventQueue()->mouseButtonPress(event->click_x, event->click_y, 1);
589  if (myApp->isGaming()) {
590  onGamingClick(getPositionInformation());
591  }
592 
593  return FXGLCanvas::onLeftBtnPress(sender, sel, ptr);
594 }
595 
596 long GUIOSGView::onLeftBtnRelease(FXObject* sender, FXSelector sel, void* ptr) {
597  FXEvent* event = (FXEvent*)ptr;
598  myAdapter->getEventQueue()->mouseButtonRelease(event->click_x, event->click_y, 1);
599 
600  return FXGLCanvas::onLeftBtnRelease(sender, sel, ptr);
601 }
602 
603 long GUIOSGView::onMiddleBtnPress(FXObject* sender, FXSelector sel, void* ptr) {
604  handle(this, FXSEL(SEL_FOCUS_SELF, 0), ptr);
605 
606  FXEvent* event = (FXEvent*)ptr;
607  myAdapter->getEventQueue()->mouseButtonPress(event->click_x, event->click_y, 2);
608 
609  return FXGLCanvas::onMiddleBtnPress(sender, sel, ptr);
610 }
611 
612 long GUIOSGView::onMiddleBtnRelease(FXObject* sender, FXSelector sel, void* ptr) {
613  FXEvent* event = (FXEvent*)ptr;
614  myAdapter->getEventQueue()->mouseButtonRelease(event->click_x, event->click_y, 2);
615 
616  return FXGLCanvas::onMiddleBtnRelease(sender, sel, ptr);
617 }
618 
619 long GUIOSGView::onRightBtnPress(FXObject* sender, FXSelector sel, void* ptr) {
620  handle(this, FXSEL(SEL_FOCUS_SELF, 0), ptr);
621 
622  FXEvent* event = (FXEvent*)ptr;
623  myAdapter->getEventQueue()->mouseButtonPress(event->click_x, event->click_y, 3);
624 
625  return FXGLCanvas::onRightBtnPress(sender, sel, ptr);
626 }
627 
628 long GUIOSGView::onRightBtnRelease(FXObject* sender, FXSelector sel, void* ptr) {
629  FXEvent* event = (FXEvent*)ptr;
630  myAdapter->getEventQueue()->mouseButtonRelease(event->click_x, event->click_y, 3);
631 
632  return FXGLCanvas::onRightBtnRelease(sender, sel, ptr);
633 }
634 
635 long
636 GUIOSGView::onMouseMove(FXObject* sender, FXSelector sel, void* ptr) {
637  FXEvent* event = (FXEvent*)ptr;
638  myAdapter->getEventQueue()->mouseMotion(event->win_x, event->win_y);
639 
640  return FXGLCanvas::onMotion(sender, sel, ptr);
641 }
642 
643 long
644 GUIOSGView::OnIdle(FXObject* /* sender */, FXSelector /* sel */, void*) {
645  forceRefresh();
646  update();
647  getApp()->addChore(this, MID_CHORE);
648  return 1;
649 }
650 
651 
652 
653 GUIOSGView::FXOSGAdapter::FXOSGAdapter(GUISUMOAbstractView* parent, FXCursor* cursor)
654  : myParent(parent), myOldCursor(cursor) {
655  _traits = new GraphicsContext::Traits();
656  _traits->x = 0;
657  _traits->y = 0;
658  _traits->width = parent->getWidth();
659  _traits->height = parent->getHeight();
660  _traits->windowDecoration = false;
661  _traits->doubleBuffer = true;
662  _traits->sharedContext = 0;
663  if (valid()) {
664  setState(new osg::State());
665  getState()->setGraphicsContext(this);
666  if (_traits.valid() && _traits->sharedContext != 0) {
667  getState()->setContextID(_traits->sharedContext->getState()->getContextID());
668  incrementContextIDUsageCount(getState()->getContextID());
669  } else {
670  getState()->setContextID(createNewContextID());
671  }
672  }
673 }
674 
675 
676 GUIOSGView::FXOSGAdapter::~FXOSGAdapter() {
677  delete myOldCursor;
678 }
679 
680 
681 void GUIOSGView::FXOSGAdapter::grabFocus() {
682  // focus this window
683  myParent->setFocus();
684 }
685 
686 void GUIOSGView::FXOSGAdapter::useCursor(bool cursorOn) {
687  if (cursorOn) {
688  myParent->setDefaultCursor(myOldCursor);
689  } else {
690  myParent->setDefaultCursor(NULL);
691  }
692 }
693 
694 bool GUIOSGView::FXOSGAdapter::makeCurrentImplementation() {
695  myParent->makeCurrent();
696  return true;
697 }
698 
699 bool GUIOSGView::FXOSGAdapter::releaseContext() {
700  myParent->makeNonCurrent();
701  return true;
702 }
703 
704 void GUIOSGView::FXOSGAdapter::swapBuffersImplementation() {
705  myParent->swapBuffers();
706 }
707 
708 
709 #endif
710 
711 /****************************************************************************/
A decal (an image) that can be shown.
The link has green light, may pass.
Locate vehicle - button.
Definition: GUIAppEnum.h:175
GUICompleteSchemeStorage gSchemeStorage
long long int SUMOTime
Definition: SUMOTime.h:43
Locate person - button.
Definition: GUIAppEnum.h:177
constVehIt loadedVehBegin() const
Returns the begin of the internal vehicle map.
Storage for all programs of a single tls.
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:58
void switchTo(const std::string &id, const std::string &programID)
Switches the named (id) tls to the named (programID) program.
SUMOReal distanceTo(const Position &p2) const
returns the euclidean distance in 3 dimension
Definition: Position.h:221
Locate TLS - button.
Definition: GUIAppEnum.h:179
const std::vector< std::string > & getNames() const
Returns a list of stored settings names.
chore
Definition: GUIAppEnum.h:213
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:99
The link has green light, has to brake.
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:331
Locate poi - button.
Definition: GUIAppEnum.h:187
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:159
unsigned char blue() const
Returns the blue-amount of the color.
Definition: RGBColor.h:91
const std::string & getID() const
Returns the id.
Definition: Named.h:66
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:277
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.
SUMOReal getColorValue(int activeScheme) const
gets the color value according to the current scheme index
Definition: GUIVehicle.cpp:377
const LaneVector & getLanesAt(int i) const
Returns the list of lanes that are controlled by the signals at the given position.
Right blinker lights are switched on.
Definition: MSVehicle.h:1000
A class that stores and controls tls and switching of their programs.
virtual SUMOReal getAngle() const
return the current angle of the transportable
bool signalSet(int which) const
Returns whether the given signal is on.
Definition: MSVehicle.h:1078
#define new
Definition: debug_new.h:121
Locate addtional structure - button.
Definition: GUIAppEnum.h:185
bool isOnRoad() const
Returns the information whether the vehicle is on a road (is simulated)
Definition: MSVehicle.h:509
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:1002
#define PI
Definition: polyfonts.c:61
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:494
SUMOReal z() const
Returns the z-position.
Definition: Position.h:73
virtual MSTransportableControl & getPersonControl()
Returns the person control.
Definition: MSNet.cpp:699
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:380
Locate edge - button.
Definition: GUIAppEnum.h:173
FXComboBox & getColoringSchemesCombo()
MSVehicleControl & getVehicleControl()
Returns the vehicle control.
Definition: MSNet.h:307
GUIVisualizationSettings & get(const std::string &name)
Returns the named scheme.
Blinker lights on both sides are switched on.
Definition: MSVehicle.h:1004
SUMOTime getCurrentTimeStep() const
Returns the current simulation step.
Definition: MSNet.h:254
bool initialised
Whether this image was initialised (inserted as a texture)
SUMOReal x() const
Returns the x-position.
Definition: Position.h:63
The brake lights are on.
Definition: MSVehicle.h:1006
Locate junction - button.
Definition: GUIAppEnum.h:171
std::string filename
The path to the file the image is located at.
SUMOReal getSlope() const
Returns the slope of the road at vehicle&#39;s position.
Definition: MSVehicle.cpp:765
MSTransportableControl & getPersonControl()
Returns the person control.
Definition: GUINet.cpp:124
A single child window which contains a view of the simulation area.
unsigned int GUIGlID
Definition: GUIGlObject.h:50
#define WRITE_ERROR(msg)
Definition: MsgHandler.h:206
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.
SUMOReal getAngle() const
Return current angle.
Definition: GUIVehicle.h:89
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:89
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:83
The link has red light (must brake)
Locate polygons - button.
Definition: GUIAppEnum.h:189
static const GUIGlID INVALID_ID
Definition: GUIGlObject.h:77
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.
Position getPosition(const SUMOReal offset=0) const
Return current position (x/y, cartesian)
Definition: GUIVehicle.h:81
SUMOReal layer
The layer of the image.
GUIGlID getGlID() const
Returns the numerical id of the object.
Position getCenter() const
Returns the center of the boundary.
Definition: Boundary.cpp:124
unsigned char red() const
Returns the red-amount of the color.
Definition: RGBColor.h:75
const MSVehicleType & getVehicleType() const
The parent class for traffic light logics.
#define SUMOReal
Definition: config.h:213
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
SUMOReal y() const
Returns the y-position.
Definition: Position.h:68
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.
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:61