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