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