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