SUMO - Simulation of Urban MObility
GUILaneSpeedTrigger.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 // Changes the speed allowed on a set of lanes (gui version)
20 /****************************************************************************/
21 // ===========================================================================
22 // included modules
23 // ===========================================================================
24 #ifdef _MSC_VER
25 #include <windows_config.h>
26 #else
27 #include <config.h>
28 #endif
29 
30 #include <string>
33 #include <utils/geom/Boundary.h>
34 #include <utils/gui/div/GLHelper.h>
35 #include <utils/common/ToString.h>
36 #include <utils/common/Command.h>
37 #include <microsim/MSNet.h>
38 #include <microsim/MSLane.h>
39 #include <microsim/MSEdge.h>
40 #include <guisim/GUINet.h>
41 #include <guisim/GUIEdge.h>
42 #include "GUILaneSpeedTrigger.h"
45 #include <gui/GUIGlobals.h>
53 
54 
55 // ===========================================================================
56 // FOX callback mapping
57 // ===========================================================================
58 /* -------------------------------------------------------------------------
59  * GUILaneSpeedTrigger::GUILaneSpeedTriggerPopupMenu - mapping
60  * ----------------------------------------------------------------------- */
64 
65 };
66 
67 // Object implementation
69 
70 
71 /* -------------------------------------------------------------------------
72  * GUILaneSpeedTrigger::GUIManip_LaneSpeedTrigger - mapping
73  * ----------------------------------------------------------------------- */
74 FXDEFMAP(GUILaneSpeedTrigger::GUIManip_LaneSpeedTrigger) GUIManip_LaneSpeedTriggerMap[] = {
81 };
82 
83 FXIMPLEMENT(GUILaneSpeedTrigger::GUIManip_LaneSpeedTrigger, GUIManipulator, GUIManip_LaneSpeedTriggerMap, ARRAYNUMBER(GUIManip_LaneSpeedTriggerMap))
84 
85 
86 // ===========================================================================
87 // method definitions
88 // ===========================================================================
89 /* -------------------------------------------------------------------------
90  * GUILaneSpeedTrigger::GUIManip_LaneSpeedTrigger - methods
91  * ----------------------------------------------------------------------- */
93  GUIMainWindow& app,
94  const std::string& name, GUILaneSpeedTrigger& o,
95  int /*xpos*/, int /*ypos*/)
96  : GUIManipulator(app, name, 0, 0),
97  myParent(&app), myChosenValue(0), myChosenTarget(myChosenValue, NULL, MID_OPTION),
98  mySpeed(o.getDefaultSpeed()), mySpeedTarget(mySpeed),
99  myObject(&o) {
100  myChosenTarget.setTarget(this);
101  FXVerticalFrame* f1 =
102  new FXVerticalFrame(this, LAYOUT_FILL_X | LAYOUT_FILL_Y, 0, 0, 0, 0, 0, 0, 0, 0);
103 
104  FXGroupBox* gp = new FXGroupBox(f1, "Change Speed",
105  GROUPBOX_TITLE_LEFT | FRAME_RIDGE,
106  0, 0, 0, 0, 4, 4, 1, 1, 2, 0);
107  {
108  // default
109  FXHorizontalFrame* gf1 =
110  new FXHorizontalFrame(gp, LAYOUT_TOP | LAYOUT_LEFT, 0, 0, 0, 0, 10, 10, 5, 5);
111  new FXRadioButton(gf1, "Default", &myChosenTarget, FXDataTarget::ID_OPTION + 0,
112  ICON_BEFORE_TEXT | LAYOUT_SIDE_TOP,
113  0, 0, 0, 0, 2, 2, 0, 0);
114  }
115  {
116  // loaded
117  FXHorizontalFrame* gf0 =
118  new FXHorizontalFrame(gp, LAYOUT_TOP | LAYOUT_LEFT, 0, 0, 0, 0, 10, 10, 5, 5);
119  new FXRadioButton(gf0, "Loaded", &myChosenTarget, FXDataTarget::ID_OPTION + 1,
120  ICON_BEFORE_TEXT | LAYOUT_SIDE_TOP,
121  0, 0, 0, 0, 2, 2, 0, 0);
122  }
123  {
124  // predefined
125  FXHorizontalFrame* gf2 =
126  new FXHorizontalFrame(gp, LAYOUT_TOP | LAYOUT_LEFT, 0, 0, 0, 0, 10, 10, 5, 5);
127  new FXRadioButton(gf2, "Predefined: ", &myChosenTarget, FXDataTarget::ID_OPTION + 2,
128  ICON_BEFORE_TEXT | LAYOUT_SIDE_TOP | LAYOUT_CENTER_Y,
129  0, 0, 0, 0, 2, 2, 0, 0);
130  myPredefinedValues =
131  new FXComboBox(gf2, 10, this, MID_PRE_DEF,
132  ICON_BEFORE_TEXT | LAYOUT_SIDE_TOP | LAYOUT_CENTER_Y | COMBOBOX_STATIC);
133  myPredefinedValues->appendItem("20 km/h");
134  myPredefinedValues->appendItem("40 km/h");
135  myPredefinedValues->appendItem("60 km/h");
136  myPredefinedValues->appendItem("80 km/h");
137  myPredefinedValues->appendItem("100 km/h");
138  myPredefinedValues->appendItem("120 km/h");
139  myPredefinedValues->appendItem("140 km/h");
140  myPredefinedValues->appendItem("160 km/h");
141  myPredefinedValues->appendItem("180 km/h");
142  myPredefinedValues->appendItem("200 km/h");
143  myPredefinedValues->setNumVisible(5);
144  }
145  {
146  // free
147  FXHorizontalFrame* gf12 =
148  new FXHorizontalFrame(gp, LAYOUT_TOP | LAYOUT_LEFT, 0, 0, 0, 0, 10, 10, 5, 5);
149  new FXRadioButton(gf12, "Free Entry: ", &myChosenTarget, FXDataTarget::ID_OPTION + 3,
150  ICON_BEFORE_TEXT | LAYOUT_SIDE_TOP | LAYOUT_CENTER_Y,
151  0, 0, 0, 0, 2, 2, 0, 0);
152  myUserDefinedSpeed =
153  new FXRealSpinDial(gf12, 10, this, MID_USER_DEF,
154  LAYOUT_TOP | FRAME_SUNKEN | FRAME_THICK);
155  myUserDefinedSpeed->setFormatString("%.0f km/h");
156  myUserDefinedSpeed->setIncrements(1, 10, 10);
157  myUserDefinedSpeed->setRange(0, 300);
158  myUserDefinedSpeed->setValue(
159  static_cast<GUILaneSpeedTrigger*>(myObject)->getDefaultSpeed() * 3.6);
160  }
161  new FXButton(f1, "Close", NULL, this, MID_CLOSE,
162  BUTTON_INITIAL | BUTTON_DEFAULT | FRAME_RAISED | FRAME_THICK | LAYOUT_TOP | LAYOUT_LEFT | LAYOUT_CENTER_X, 0, 0, 0, 0, 30, 30, 4, 4);
163  static_cast<GUILaneSpeedTrigger*>(myObject)->setOverriding(true);
164 }
165 
166 
168 
169 
170 long
172  destroy();
173  return 1;
174 }
175 
176 
177 long
179  mySpeed = (double)(myUserDefinedSpeed->getValue() / 3.6);
182  return 1;
183 }
184 
185 
186 long
187 GUILaneSpeedTrigger::GUIManip_LaneSpeedTrigger::onUpdUserDef(FXObject* sender, FXSelector, void* ptr) {
188  sender->handle(this,
189  myChosenValue != 3 ? FXSEL(SEL_COMMAND, ID_DISABLE) : FXSEL(SEL_COMMAND, ID_ENABLE),
190  ptr);
192  return 1;
193 }
194 
195 
196 long
198  mySpeed = (double)(double)((myPredefinedValues->getCurrentItem() * 20 + 20) / 3.6);
201  return 1;
202 }
203 
204 
205 long
206 GUILaneSpeedTrigger::GUIManip_LaneSpeedTrigger::onUpdPreDef(FXObject* sender, FXSelector, void* ptr) {
207  sender->handle(this,
208  myChosenValue != 2 ? FXSEL(SEL_COMMAND, ID_DISABLE) : FXSEL(SEL_COMMAND, ID_ENABLE),
209  ptr);
211  return 1;
212 }
213 
214 
215 long
217  static_cast<GUILaneSpeedTrigger*>(myObject)->setOverriding(true);
218  switch (myChosenValue) {
219  case 0:
220  mySpeed = (double) static_cast<GUILaneSpeedTrigger*>(myObject)->getDefaultSpeed();
221  break;
222  case 1:
223  mySpeed = (double) static_cast<GUILaneSpeedTrigger*>(myObject)->getLoadedSpeed();
224  break;
225  case 2:
226  mySpeed = (double)((myPredefinedValues->getCurrentItem() * 20 + 20) / 3.6);
227  break;
228  case 3:
229  mySpeed = (double)(myUserDefinedSpeed->getValue() / 3.6);
230  break;
231  default:
232  // hmmm, should not happen
233  break;
234  }
237  if (myChosenValue == 1) {
238  // !!! lock in between
239  static_cast<GUILaneSpeedTrigger*>(myObject)->setOverriding(false);
240  }
241  return 1;
242 }
243 
244 
245 
246 /* -------------------------------------------------------------------------
247  * GUILaneSpeedTrigger::GUILaneSpeedTriggerPopupMenu - methods
248  * ----------------------------------------------------------------------- */
250  GUIMainWindow& app, GUISUMOAbstractView& parent,
251  GUIGlObject& o)
252  : GUIGLObjectPopupMenu(app, parent, o) {}
253 
254 
256 
257 
258 long
260  FXSelector,
261  void*) {
264  return 1;
265 }
266 
267 
268 /* -------------------------------------------------------------------------
269  * GUILaneSpeedTrigger - methods
270  * ----------------------------------------------------------------------- */
272  const std::string& id, const std::vector<MSLane*>& destLanes,
273  const std::string& aXMLFilename) :
274  MSLaneSpeedTrigger(id, destLanes, aXMLFilename),
275  GUIGlObject_AbstractAdd("speedtrigger", GLO_TRIGGER, id),
276  myShowAsKMH(true), myLastValue(-1) {
277  myFGPositions.reserve(destLanes.size());
278  myFGRotations.reserve(destLanes.size());
279  std::vector<MSLane*>::const_iterator i;
280  for (i = destLanes.begin(); i != destLanes.end(); ++i) {
281  const PositionVector& v = (*i)->getShape();
282  myFGPositions.push_back(v.positionAtOffset(0));
284  myFGRotations.push_back(-v.rotationDegreeAtOffset(0));
285  }
286 }
287 
288 
290 
291 
294  GUISUMOAbstractView& parent) {
295  GUIGLObjectPopupMenu* ret = new GUILaneSpeedTriggerPopupMenu(app, parent, *this);
296  buildPopupHeader(ret, app);
302  buildPositionCopyEntry(ret, false);
303  return ret;
304 }
305 
306 
311  new GUIParameterTableWindow(app, *this, 1);
312  // add items
313  ret->mkItem("speed [m/s]", true,
315  // close building
316  ret->closeBuilding();
317  return ret;
318 }
319 
320 
321 void
323  glPushName(getGlID());
324  glPushMatrix();
325  glTranslated(0, 0, getType());
326  const double exaggeration = s.addSize.getExaggeration(s);
327  for (int i = 0; i < (int)myFGPositions.size(); ++i) {
328  const Position& pos = myFGPositions[i];
329  double rot = myFGRotations[i];
330  glPushMatrix();
331  glScaled(exaggeration, exaggeration, 1);
332  glTranslated(pos.x(), pos.y(), 0);
333  glRotated(rot, 0, 0, 1);
334  glTranslated(0, -1.5, 0);
335 
336  int noPoints = 9;
337  if (s.scale > 25) {
338  noPoints = (int)(9.0 + s.scale / 10.0);
339  if (noPoints > 36) {
340  noPoints = 36;
341  }
342  }
343  glColor3d(1, 0, 0);
344  GLHelper::drawFilledCircle((double) 1.3, noPoints);
345  if (s.scale >= 5) {
346  glTranslated(0, 0, .1);
347  glColor3d(0, 0, 0);
348  GLHelper::drawFilledCircle((double) 1.1, noPoints);
349  // draw the speed string
350  // not if scale to low
351  // compute
352  double value = (double) getCurrentSpeed();
353  if (myShowAsKMH) {
354  value *= 3.6f;
355  if (((int) value + 1) % 10 == 0) {
356  value = (double)(((int) value + 1) / 10 * 10);
357  }
358  }
359  if (value != myLastValue) {
360  myLastValue = value;
361  myLastValueString = toString<double>(myLastValue);
362  std::string::size_type idx = myLastValueString.find('.');
363  if (idx != std::string::npos) {
364  if (idx > myLastValueString.length()) {
365  idx = myLastValueString.length();
366  }
367  myLastValueString = myLastValueString.substr(0, idx);
368  }
369  }
370  //draw
371  glColor3d(1, 1, 0);
372  glTranslated(0, 0, .1);
373  glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
374 
375  // draw last value string
376  GLHelper::drawText(myLastValueString.c_str(), Position(0, 0), .1, 1.2, RGBColor(255, 255, 0), 180);
377  }
378  glPopMatrix();
379  }
380  glPopMatrix();
381  drawName(getCenteringBoundary().getCenter(), s.scale, s.addName);
382  glPopName();
383 }
384 
385 
386 Boundary
388  Boundary b(myBoundary);
389  b.grow(20);
390  return b;
391 }
392 
393 
398  new GUIManip_LaneSpeedTrigger(app, getFullName(), *this, 0, 0);
399  gui->create();
400  gui->show();
401  return gui;
402 }
403 
404 
405 
406 /****************************************************************************/
407 
double rotationDegreeAtOffset(double pos) const
Returns the rotation at the given length.
long onCmdClose(FXObject *, FXSelector, void *)
a lane speed trigger,
double scale
information about a lane&#39;s width (temporary, used for a single view)
void closeBuilding(const Parameterised *p=0)
Closes the building of the table.
long onCmdUserDef(FXObject *, FXSelector, void *)
GUIVisualizationTextSettings addName
void buildNameCopyPopupEntry(GUIGLObjectPopupMenu *ret, bool addSeparator=true)
Builds entries which allow to copy the name / typed name into the clipboard.
PosCont myFGPositions
The positions in full-geometry mode.
double getCurrentSpeed() const
Returns the current speed.
long onCmdOpenManip(FXObject *, FXSelector, void *)
Called if the object&#39;s manipulator shall be shown.
Stores the information about how to visualize structures.
long onCmdChangeOption(FXObject *, FXSelector, void *)
double y() const
Returns the y-position.
Definition: Position.h:67
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
long onUpdPreDef(FXObject *, FXSelector, void *)
GUISUMOAbstractView * myParent
The parent window.
GUIGLObjectPopupMenu * getPopUpMenu(GUIMainWindow &app, GUISUMOAbstractView &parent)
Returns an own popup-menu.
double myLastValue
Storage for last value to avoid string recomputation.
void buildShowParamsPopupEntry(GUIGLObjectPopupMenu *ret, bool addSeparator=true)
Builds an entry which allows to open the parameter window.
static void drawFilledCircle(double width, int steps=8)
Draws a filled circle around (0,0)
Definition: GLHelper.cpp:350
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.
A class that stores a 2D geometrical boundary.
Definition: Boundary.h:47
Changes the speed allowed on a set of lanes.
long onUpdUserDef(FXObject *, FXSelector, void *)
GUILaneSpeedTrigger(const std::string &id, const std::vector< MSLane *> &destLanes, const std::string &file)
Constructor.
Boundary myBoundary
The boundary of this rerouter.
GUIVisualizationSizeSettings addSize
GUIGlObjectType getType() const
Returns the type of the object as coded in GUIGlObjectType.
A point in 2D or 3D with translation and scaling methods.
Definition: Position.h:45
A list of positions.
void drawGL(const GUIVisualizationSettings &s) const
Draws the object.
void drawName(const Position &pos, const double scale, const GUIVisualizationTextSettings &settings, const double angle=0) const
draw name of item
GUILaneSpeedTriggerPopupMenuMap[]
Boundary getCenteringBoundary() const
Returns the boundary to which the view shall be centered in order to show the object.
Boundary & grow(double by)
extends the boundary by the given amount
Definition: Boundary.cpp:301
void setOverriding(bool val)
long onCmdPreDef(FXObject *, FXSelector, void *)
std::string myLastValueString
Storage for speed string to avoid recomputation.
void buildShowManipulatorPopupEntry(GUIGLObjectPopupMenu *ret, bool addSeparator=true)
Builds an entry which allows to open the manipulator window.
GUIParameterTableWindow * getParameterWindow(GUIMainWindow &app, GUISUMOAbstractView &parent)
Returns an own parameter window.
Open the object&#39;s manipulator.
Definition: GUIAppEnum.h:254
RotCont myFGRotations
The rotations in full-geometry mode.
bool myShowAsKMH
The information whether the speed shall be shown in m/s or km/h.
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
GUIManipulator * openManipulator(GUIMainWindow &app, GUISUMOAbstractView &parent)
FXDEFMAP(GUILaneSpeedTrigger::GUIManip_LaneSpeedTrigger) GUIManip_LaneSpeedTriggerMap[]
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
GUIMainWindow * myApplication
The main application.
const std::string & getFullName() const
Changes the speed allowed on a set of lanes (gui version)
void add(double x, double y, double z=0)
Makes the boundary include the given coordinate.
Definition: Boundary.cpp:85
GUIGlObject * myObject
The object that belongs to this popup-menu.
Spinner control.
void mkItem(const char *name, bool dynamic, ValueSource< unsigned > *src)
Adds a row which obtains its value from an unsigned-ValueSource.
Position positionAtOffset(double pos, double lateralOffset=0) const
Returns the position at the given length.
A window containing a gl-object&#39;s parameter.
void buildPopupHeader(GUIGLObjectPopupMenu *ret, GUIMainWindow &app, bool addSeparator=true)
Builds the header.
void setOverridingValue(double val)