SUMO - Simulation of Urban MObility
GUITriggeredRerouter.cpp
Go to the documentation of this file.
1 /****************************************************************************/
2 // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.org/sumo
3 // Copyright (C) 2001-2017 German Aerospace Center (DLR) and others.
4 /****************************************************************************/
5 //
6 // This program and the accompanying materials
7 // are made available under the terms of the Eclipse Public License v2.0
8 // which accompanies this distribution, and is available at
9 // http://www.eclipse.org/legal/epl-v20.html
10 //
11 /****************************************************************************/
19 // Reroutes vehicles passing an edge (gui version)
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 #include <string>
35 #include <utils/geom/Boundary.h>
36 #include <utils/gui/div/GLHelper.h>
37 #include <utils/common/ToString.h>
38 #include <utils/common/Command.h>
39 #include <microsim/MSNet.h>
40 #include <microsim/MSLane.h>
41 #include <microsim/MSEdge.h>
42 #include <guisim/GUINet.h>
43 #include <guisim/GUIEdge.h>
44 #include "GUITriggeredRerouter.h"
47 #include <gui/GUIGlobals.h>
53 
54 
55 // ===========================================================================
56 // FOX callback mapping
57 // ===========================================================================
58 /* -------------------------------------------------------------------------
59  * GUITriggeredRerouter::GUITriggeredRerouterPopupMenu - mapping
60  * ----------------------------------------------------------------------- */
64 
65 };
66 
67 // Object implementation
69 
70 
71 /* -------------------------------------------------------------------------
72  * GUITriggeredRerouter::GUIManip_TriggeredRerouter - mapping
73  * ----------------------------------------------------------------------- */
74 FXDEFMAP(GUITriggeredRerouter::GUIManip_TriggeredRerouter) GUIManip_TriggeredRerouterMap[] = {
79 };
80 
81 FXIMPLEMENT(GUITriggeredRerouter::GUIManip_TriggeredRerouter, GUIManipulator, GUIManip_TriggeredRerouterMap, ARRAYNUMBER(GUIManip_TriggeredRerouterMap))
82 
83 
84 // ===========================================================================
85 // method definitions
86 // ===========================================================================
87 /* -------------------------------------------------------------------------
88  * GUITriggeredRerouter::GUIManip_TriggeredRerouter - methods
89  * ----------------------------------------------------------------------- */
91  GUIMainWindow& app,
92  const std::string& name, GUITriggeredRerouter& o,
93  int /*xpos*/, int /*ypos*/)
94  : GUIManipulator(app, name, 0, 0), myParent(&app),
95  myChosenValue(0), myChosenTarget(myChosenValue, NULL, MID_OPTION),
96  myUsageProbability(o.getProbability()), myUsageProbabilityTarget(myUsageProbability),
97  myObject(&o) {
98  myChosenTarget.setTarget(this);
99  FXVerticalFrame* f1 =
100  new FXVerticalFrame(this, LAYOUT_FILL_X | LAYOUT_FILL_Y, 0, 0, 0, 0, 0, 0, 0, 0);
101 
102  FXGroupBox* gp = new FXGroupBox(f1, "Change Probability",
103  GROUPBOX_TITLE_LEFT | FRAME_SUNKEN | FRAME_RIDGE,
104  0, 0, 0, 0, 4, 4, 1, 1, 2, 0);
105  {
106  // default
107  FXHorizontalFrame* gf1 =
108  new FXHorizontalFrame(gp, LAYOUT_TOP | LAYOUT_LEFT, 0, 0, 0, 0, 10, 10, 5, 5);
109  new FXRadioButton(gf1, "Default", &myChosenTarget, FXDataTarget::ID_OPTION + 0,
110  ICON_BEFORE_TEXT | LAYOUT_SIDE_TOP,
111  0, 0, 0, 0, 2, 2, 0, 0);
112  }
113  {
114  // free
115  FXHorizontalFrame* gf12 =
116  new FXHorizontalFrame(gp, LAYOUT_TOP | LAYOUT_LEFT, 0, 0, 0, 0, 10, 10, 5, 5);
117  new FXRadioButton(gf12, "User Given: ", &myChosenTarget, FXDataTarget::ID_OPTION + 1,
118  ICON_BEFORE_TEXT | LAYOUT_SIDE_TOP | LAYOUT_CENTER_Y,
119  0, 0, 0, 0, 2, 2, 0, 0);
120  myUsageProbabilityDial =
121  new FXRealSpinDial(gf12, 10, this, MID_USER_DEF,
122  LAYOUT_TOP | FRAME_SUNKEN | FRAME_THICK);
123  myUsageProbabilityDial->setFormatString("%.2f");
124  myUsageProbabilityDial->setIncrements(.1, .1, .1);
125  myUsageProbabilityDial->setRange(0, 1);
126  myUsageProbabilityDial->setValue(myObject->getUserProbability());
127  }
128  {
129  // off
130  FXHorizontalFrame* gf13 =
131  new FXHorizontalFrame(gp, LAYOUT_TOP | LAYOUT_LEFT, 0, 0, 0, 0, 10, 10, 5, 5);
132  new FXRadioButton(gf13, "Off", &myChosenTarget, FXDataTarget::ID_OPTION + 2,
133  ICON_BEFORE_TEXT | LAYOUT_SIDE_TOP,
134  0, 0, 0, 0, 2, 2, 0, 0);
135  }
136  myChosenValue = myObject->inUserMode()
137  ? myObject->getUserProbability() > 0
138  ? 1 : 2
139  : 0;
140  new FXButton(f1, "Close", NULL, this, MID_CLOSE,
141  BUTTON_INITIAL | BUTTON_DEFAULT | FRAME_RAISED | FRAME_THICK | LAYOUT_TOP | LAYOUT_LEFT | LAYOUT_CENTER_X, 0, 0, 0, 0, 30, 30, 4, 4);
142 }
143 
144 
146 
147 
148 long
150  destroy();
151  return 1;
152 }
153 
154 
155 long
159  static_cast<GUITriggeredRerouter*>(myObject)->setUserMode(true);
161  return 1;
162 }
163 
164 
165 long
166 GUITriggeredRerouter::GUIManip_TriggeredRerouter::onUpdUserDef(FXObject* sender, FXSelector, void* ptr) {
167  sender->handle(this,
168  myChosenValue != 1 ? FXSEL(SEL_COMMAND, ID_DISABLE) : FXSEL(SEL_COMMAND, ID_ENABLE),
169  ptr);
171  return 1;
172 }
173 
174 
175 long
178  switch (myChosenValue) {
179  case 0:
180  static_cast<GUITriggeredRerouter*>(myObject)->setUserMode(false);
181  break;
182  case 1:
183  static_cast<GUITriggeredRerouter*>(myObject)->setUserMode(true);
184  break;
185  case 2:
187  static_cast<GUITriggeredRerouter*>(myObject)->setUserMode(true);
188  break;
189  default:
190  throw 1;
191  }
193  return 1;
194 }
195 
196 
197 /* -------------------------------------------------------------------------
198  * GUITriggeredRerouter::GUITriggeredRerouterPopupMenu - methods
199  * ----------------------------------------------------------------------- */
201  GUIMainWindow& app, GUISUMOAbstractView& parent,
202  GUIGlObject& o)
203  : GUIGLObjectPopupMenu(app, parent, o) {}
204 
205 
207 
208 
209 long
211  FXSelector,
212  void*) {
215  return 1;
216 }
217 
218 
219 /* -------------------------------------------------------------------------
220  * GUITriggeredRerouter - methods
221  * ----------------------------------------------------------------------- */
223  const std::string& id,
224  const MSEdgeVector& edges,
225  double prob, const std::string& aXMLFilename, bool off,
226  SUMOTime timeThreshold,
227  SUMORTree& rtree) :
228  MSTriggeredRerouter(id, edges, prob, aXMLFilename, off, timeThreshold),
229  GUIGlObject_AbstractAdd("rerouter", GLO_TRIGGER, id) {
230  // add visualisation objects for edges which trigger the rerouter
231  for (MSEdgeVector::const_iterator it = edges.begin(); it != edges.end(); ++it) {
232  myEdgeVisualizations.push_back(new GUITriggeredRerouterEdge(dynamic_cast<GUIEdge*>(*it), this, false));
234  myBoundary.add(myEdgeVisualizations.back()->getCenteringBoundary());
235  }
236 }
237 
238 
240  for (std::vector<GUITriggeredRerouterEdge*>::iterator it = myEdgeVisualizations.begin(); it != myEdgeVisualizations.end(); ++it) {
241  delete *it;
242  }
243  myEdgeVisualizations.clear();
244 }
245 
246 
247 void
250  if (element == SUMO_TAG_INTERVAL) {
251  // add visualisation objects for closed edges
252  const RerouteInterval& ri = myIntervals.back();
253  for (MSEdgeVector::const_iterator it = ri.closed.begin(); it != ri.closed.end(); ++it) {
254  myEdgeVisualizations.push_back(new GUITriggeredRerouterEdge(dynamic_cast<GUIEdge*>(*it), this, true));
255  dynamic_cast<GUINet*>(GUINet::getInstance())->getVisualisationSpeedUp().addAdditionalGLObject(myEdgeVisualizations.back());
256  myBoundary.add(myEdgeVisualizations.back()->getCenteringBoundary());
257  }
258  }
259 }
260 
261 
264  GUISUMOAbstractView& parent) {
265  GUIGLObjectPopupMenu* ret = new GUITriggeredRerouterPopupMenu(app, parent, *this);
266  buildPopupHeader(ret, app);
268  buildShowManipulatorPopupEntry(ret, false);
271  buildPositionCopyEntry(ret, false);
272  return ret;
273 }
274 
275 
279  return 0;
280 }
281 
282 
283 void
285  UNUSED_PARAMETER(s);
286 }
287 
288 
289 Boundary
291  Boundary b(myBoundary);
292  b.grow(20);
293  return b;
294 }
295 
296 
297 
302  new GUIManip_TriggeredRerouter(app, getFullName(), *this, 0, 0);
303  gui->create();
304  gui->show();
305  return gui;
306 }
307 
308 
309 /* -------------------------------------------------------------------------
310  * GUITriggeredRerouterEdge - methods
311  * ----------------------------------------------------------------------- */
313  GUIGlObject("rerouter_edge", GLO_TRIGGER, parent->getID() + ":" + edge->getID()),
314  myParent(parent),
315  myEdge(edge),
316  myAmClosedEdge(closed) {
317  const std::vector<MSLane*>& lanes = edge->getLanes();
318  myFGPositions.reserve(lanes.size());
319  myFGRotations.reserve(lanes.size());
320  for (std::vector<MSLane*>::const_iterator i = lanes.begin(); i != lanes.end(); ++i) {
321  const PositionVector& v = (*i)->getShape();
322  const double pos = closed ? 3 : v.length() - (double) 6.;
323  myFGPositions.push_back((*i)->geometryPositionAtOffset(pos));
324  myFGRotations.push_back(-v.rotationDegreeAtOffset(pos));
325  myBoundary.add(myFGPositions.back());
326  }
327 }
328 
329 
331 
332 
335  GUISUMOAbstractView& parent) {
336  return myParent->getPopUpMenu(app, parent);
337 }
338 
339 
343  return 0;
344 }
345 
346 
347 void
349  const double exaggeration = s.addSize.getExaggeration(s);
350  if (s.scale * exaggeration >= 3) {
351  glPushName(getGlID());
352  const double prob = myParent->getProbability();
353  if (myAmClosedEdge) {
354  // draw closing symbol onto all lanes
355  const RerouteInterval* const ri =
356  myParent->getCurrentReroute(MSNet::getInstance()->getCurrentTimeStep());
357  if (ri != 0 && prob > 0) {
358  // draw only if the edge is closed at this time
359  if (std::find(ri->closed.begin(), ri->closed.end(), myEdge) != ri->closed.end()) {
360  const int noLanes = (int)myFGPositions.size();
361  for (int j = 0; j < noLanes; ++j) {
362  Position pos = myFGPositions[j];
363  double rot = myFGRotations[j];
364  glPushMatrix();
365  glTranslated(pos.x(), pos.y(), 0);
366  glRotated(rot, 0, 0, 1);
367  glTranslated(0, -1.5, 0);
368  int noPoints = 9;
369  if (s.scale > 25) {
370  noPoints = (int)(9.0 + s.scale / 10.0);
371  if (noPoints > 36) {
372  noPoints = 36;
373  }
374  }
375  glTranslated(0, 0, getType());
376  //glScaled(exaggeration, exaggeration, 1);
377  glColor3d(0.7, 0, 0);
378  GLHelper::drawFilledCircle((double) 1.3, noPoints);
379  glTranslated(0, 0, .1);
380  glColor3d(1, 0, 0);
381  GLHelper::drawFilledCircle((double) 1.3, noPoints, 0, prob * 360);
382  glTranslated(0, 0, .1);
383  glColor3d(1, 1, 1);
384  glRotated(-90, 0, 0, 1);
385  glBegin(GL_TRIANGLES);
386  glVertex2d(0 - .3, -1.);
387  glVertex2d(0 - .3, 1.);
388  glVertex2d(0 + .3, 1.);
389  glVertex2d(0 + .3, -1.);
390  glVertex2d(0 - .3, -1.);
391  glVertex2d(0 + .3, 1.);
392  glEnd();
393  glPopMatrix();
394  }
395  }
396  }
397 
398  } else {
399  // draw rerouter symbol onto all lanes
400  for (int i = 0; i < (int)myFGPositions.size(); ++i) {
401  const Position& pos = myFGPositions[i];
402  double rot = myFGRotations[i];
403  glPushMatrix();
404  glTranslated(pos.x(), pos.y(), 0);
405  glRotated(rot, 0, 0, 1);
406  glTranslated(0, 0, getType());
407  glScaled(exaggeration, exaggeration, 1);
408  glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
409 
410  glBegin(GL_TRIANGLES);
411  glColor3d(1, .8f, 0);
412  // base
413  glVertex2d(0 - 1.4, 0);
414  glVertex2d(0 - 1.4, 6);
415  glVertex2d(0 + 1.4, 6);
416  glVertex2d(0 + 1.4, 0);
417  glVertex2d(0 - 1.4, 0);
418  glVertex2d(0 + 1.4, 6);
419  glEnd();
420 
421  // draw "U"
422  GLHelper::drawText("U", Position(0, 2), .1, 3, RGBColor::BLACK, 180);
423 
424  // draw Probability
425  GLHelper::drawText((toString((int)(prob * 100)) + "%").c_str(), Position(0, 4), .1, 0.7, RGBColor::BLACK, 180);
426 
427  glPopMatrix();
428  }
429  }
430  glPopName();
431  }
432 }
433 
434 
435 Boundary
437  Boundary b(myBoundary);
438  b.grow(20);
439  return b;
440 }
441 
442 
443 /****************************************************************************/
444 
void drawGL(const GUIVisualizationSettings &s) const
Draws the object.
double getProbability() const
Returns the rerouting probability.
double rotationDegreeAtOffset(double pos) const
Returns the rotation at the given length.
long onCmdClose(FXObject *, FXSelector, void *)
MSEdgeVector closed
The list of closed edges.
a lane speed trigger,
const RerouteInterval * getCurrentReroute(SUMOTime time, SUMOVehicle &veh) const
Returns the rerouting definition valid for the given time and vehicle, 0 if none. ...
GUITriggeredRerouterEdge(GUIEdge *edge, GUITriggeredRerouter *parent, bool closed)
double scale
information about a lane&#39;s width (temporary, used for a single view)
Reroutes vehicles passing an edge One rerouter can be active on multiple edges. To reduce drawing loa...
void buildNameCopyPopupEntry(GUIGLObjectPopupMenu *ret, bool addSeparator=true)
Builds entries which allow to copy the name / typed name into the clipboard.
std::vector< GUITriggeredRerouterEdge * > myEdgeVisualizations
FXDEFMAP(GUITriggeredRerouter::GUIManip_TriggeredRerouter) GUIManip_TriggeredRerouterMap[]
GUIManipulator * openManipulator(GUIMainWindow &app, GUISUMOAbstractView &parent)
Stores the information about how to visualize structures.
double y() const
Returns the y-position.
Definition: Position.h:67
Boundary getCenteringBoundary() const
Returns the boundary to which the view shall be centered in order to show the object.
double x() const
Returns the x-position.
Definition: Position.h:62
void buildCenterPopupEntry(GUIGLObjectPopupMenu *ret, bool addSeparator=true)
Builds an entry which allows to center to the object.
static void drawText(const std::string &text, const Position &pos, const double layer, const double size, const RGBColor &col=RGBColor::BLACK, const double angle=0, int align=0, double width=-1)
Definition: GLHelper.cpp:487
const std::vector< MSLane * > & getLanes() const
Returns this edge&#39;s lanes.
Definition: MSEdge.h:167
static MSNet * getInstance()
Returns the pointer to the unique instance of MSNet (singleton).
Definition: MSNet.cpp:167
GUITriggeredRerouter * myParent
The parent rerouter to which this edge instance belongs.
GUISUMOAbstractView * myParent
The parent window.
void setUserUsageProbability(double prob)
Sets the probability with which a vehicle is rerouted given by the user.
static const RGBColor BLACK
Definition: RGBColor.h:186
const std::string & getID() const
Returns the id.
Definition: Named.h:65
void setUserMode(bool val)
Sets whether the process is currently steered by the user.
GUITriggeredRerouterPopupMenuMap[]
MSEdge * myEdge
The edge for which this visualization applies.
static void drawFilledCircle(double width, int steps=8)
Draws a filled circle around (0,0)
Definition: GLHelper.cpp:350
A RT-tree for efficient storing of SUMO&#39;s GL-objects.
Definition: SUMORTree.h:73
void drawGL(const GUIVisualizationSettings &s) const
Draws the object.
void buildPositionCopyEntry(GUIGLObjectPopupMenu *ret, bool addSeparator=true)
Builds an entry which allows to copy the cursor position if geo projection is used, also builds an entry for copying the geo-position.
#define UNUSED_PARAMETER(x)
Definition: StdDefs.h:39
A class that stores a 2D geometrical boundary.
Definition: Boundary.h:47
GUIGLObjectPopupMenu * getPopUpMenu(GUIMainWindow &app, GUISUMOAbstractView &parent)
Returns an own popup-menu.
A road/street connecting two junctions (gui-version)
Definition: GUIEdge.h:59
virtual void myEndElement(int element)
Called when a closing tag occurs.
GUIVisualizationSizeSettings addSize
GUIParameterTableWindow * getParameterWindow(GUIMainWindow &app, GUISUMOAbstractView &parent)
Returns an own parameter window.
GUIGlObjectType getType() const
Returns the type of the object as coded in GUIGlObjectType.
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
Definition: ToString.h:55
GUITriggeredRerouter(const std::string &id, const MSEdgeVector &edges, double prob, const std::string &aXMLFilename, bool off, SUMOTime timeThreshold, SUMORTree &rtree)
Constructor.
A point in 2D or 3D with translation and scaling methods.
Definition: Position.h:45
A list of positions.
GUIGLObjectPopupMenu * getPopUpMenu(GUIMainWindow &app, GUISUMOAbstractView &parent)
Returns an own popup-menu.
Boundary getCenteringBoundary() const
Returns the boundary to which the view shall be centered in order to show the object.
const bool myAmClosedEdge
whether this edge instance visualizes a closed edge
Boundary & grow(double by)
extends the boundary by the given amount
Definition: Boundary.cpp:301
long onCmdUserDef(FXObject *, FXSelector, void *)
Boundary myBoundary
The boundary of this rerouter.
long onCmdOpenManip(FXObject *, FXSelector, void *)
Called if the object&#39;s manipulator shall be shown.
long onUpdUserDef(FXObject *, FXSelector, void *)
GUIParameterTableWindow * getParameterWindow(GUIMainWindow &app, GUISUMOAbstractView &parent)
Returns an own parameter window.
long onCmdChangeOption(FXObject *, FXSelector, void *)
RotCont myFGRotations
The rotations in full-geometry mode.
void buildShowManipulatorPopupEntry(GUIGLObjectPopupMenu *ret, bool addSeparator=true)
Builds an entry which allows to open the manipulator window.
Reroutes vehicles passing an edge.
double length() const
Returns the length.
A MSNet extended by some values for usage within the gui.
Definition: GUINet.h:88
Open the object&#39;s manipulator.
Definition: GUIAppEnum.h:254
void addAdditionalGLObject(GUIGlObject *o)
Adds an additional object (detector/shape/trigger) for visualisation.
Definition: SUMORTree.h:128
std::vector< RerouteInterval > myIntervals
List of rerouting definition intervals.
The popup menu of a globject.
FXdouble getValue() const
Return current value.
void buildSelectionPopupEntry(GUIGLObjectPopupMenu *ret, bool addSeparator=true)
Builds an entry which allows to (de)select the object.
Close simulation - ID.
Definition: GUIAppEnum.h:84
GUIGlID getGlID() const
Returns the numerical id of the object.
double getExaggeration(const GUIVisualizationSettings &s, double factor=20) const
return the drawing size including exaggeration and constantSize values
an aggreagated-output interval
GUIMainWindow * myApplication
The main application.
long long int SUMOTime
Definition: TraCIDefs.h:51
std::vector< MSEdge * > MSEdgeVector
Definition: MSEdge.h:77
const std::string & getFullName() const
void add(double x, double y, double z=0)
Makes the boundary include the given coordinate.
Definition: Boundary.cpp:85
void myEndElement(int element)
Called when a closing tag occurs.
GUIGlObject * myObject
The object that belongs to this popup-menu.
Spinner control.
Boundary myBoundary
The boundary of this rerouter.
A window containing a gl-object&#39;s parameter.
PosCont myFGPositions
The positions in full-geometry mode.
void buildPopupHeader(GUIGLObjectPopupMenu *ret, GUIMainWindow &app, bool addSeparator=true)
Builds the header.