SUMO - Simulation of Urban MObility
GUILaneSpeedTrigger.cpp
Go to the documentation of this file.
1 /****************************************************************************/
9 // Changes the speed allowed on a set of lanes (gui version)
10 /****************************************************************************/
11 // SUMO, Simulation of Urban MObility; see http://sumo.dlr.de/
12 // Copyright (C) 2001-2017 DLR (http://www.dlr.de/) and contributors
13 /****************************************************************************/
14 //
15 // This file is part of SUMO.
16 // SUMO is free software: you can redistribute it and/or modify
17 // it under the terms of the GNU General Public License as published by
18 // the Free Software Foundation, either version 3 of the License, or
19 // (at your option) any later version.
20 //
21 /****************************************************************************/
22 // ===========================================================================
23 // included modules
24 // ===========================================================================
25 #ifdef _MSC_VER
26 #include <windows_config.h>
27 #else
28 #include <config.h>
29 #endif
30 
31 #include <string>
34 #include <utils/geom/Boundary.h>
35 #include <utils/gui/div/GLHelper.h>
36 #include <utils/common/ToString.h>
37 #include <utils/common/Command.h>
38 #include <microsim/MSNet.h>
39 #include <microsim/MSLane.h>
40 #include <microsim/MSEdge.h>
41 #include <guisim/GUINet.h>
42 #include <guisim/GUIEdge.h>
43 #include "GUILaneSpeedTrigger.h"
46 #include <gui/GUIGlobals.h>
55 
56 
57 // ===========================================================================
58 // FOX callback mapping
59 // ===========================================================================
60 /* -------------------------------------------------------------------------
61  * GUILaneSpeedTrigger::GUILaneSpeedTriggerPopupMenu - mapping
62  * ----------------------------------------------------------------------- */
66 
67 };
68 
69 // Object implementation
71 
72 
73 /* -------------------------------------------------------------------------
74  * GUILaneSpeedTrigger::GUIManip_LaneSpeedTrigger - mapping
75  * ----------------------------------------------------------------------- */
76 FXDEFMAP(GUILaneSpeedTrigger::GUIManip_LaneSpeedTrigger) GUIManip_LaneSpeedTriggerMap[] = {
83 };
84 
85 FXIMPLEMENT(GUILaneSpeedTrigger::GUIManip_LaneSpeedTrigger, GUIManipulator, GUIManip_LaneSpeedTriggerMap, ARRAYNUMBER(GUIManip_LaneSpeedTriggerMap))
86 
87 
88 // ===========================================================================
89 // method definitions
90 // ===========================================================================
91 /* -------------------------------------------------------------------------
92  * GUILaneSpeedTrigger::GUIManip_LaneSpeedTrigger - methods
93  * ----------------------------------------------------------------------- */
95  GUIMainWindow& app,
96  const std::string& name, GUILaneSpeedTrigger& o,
97  int /*xpos*/, int /*ypos*/)
98  : GUIManipulator(app, name, 0, 0),
99  myParent(&app), myChosenValue(0), myChosenTarget(myChosenValue, NULL, MID_OPTION),
100  mySpeed(o.getDefaultSpeed()), mySpeedTarget(mySpeed),
101  myObject(&o) {
102  myChosenTarget.setTarget(this);
103  FXVerticalFrame* f1 =
104  new FXVerticalFrame(this, LAYOUT_FILL_X | LAYOUT_FILL_Y, 0, 0, 0, 0, 0, 0, 0, 0);
105 
106  FXGroupBox* gp = new FXGroupBox(f1, "Change Speed",
107  GROUPBOX_TITLE_LEFT | FRAME_RIDGE,
108  0, 0, 0, 0, 4, 4, 1, 1, 2, 0);
109  {
110  // default
111  FXHorizontalFrame* gf1 =
112  new FXHorizontalFrame(gp, LAYOUT_TOP | LAYOUT_LEFT, 0, 0, 0, 0, 10, 10, 5, 5);
113  new FXRadioButton(gf1, "Default", &myChosenTarget, FXDataTarget::ID_OPTION + 0,
114  ICON_BEFORE_TEXT | LAYOUT_SIDE_TOP,
115  0, 0, 0, 0, 2, 2, 0, 0);
116  }
117  {
118  // loaded
119  FXHorizontalFrame* gf0 =
120  new FXHorizontalFrame(gp, LAYOUT_TOP | LAYOUT_LEFT, 0, 0, 0, 0, 10, 10, 5, 5);
121  new FXRadioButton(gf0, "Loaded", &myChosenTarget, FXDataTarget::ID_OPTION + 1,
122  ICON_BEFORE_TEXT | LAYOUT_SIDE_TOP,
123  0, 0, 0, 0, 2, 2, 0, 0);
124  }
125  {
126  // predefined
127  FXHorizontalFrame* gf2 =
128  new FXHorizontalFrame(gp, LAYOUT_TOP | LAYOUT_LEFT, 0, 0, 0, 0, 10, 10, 5, 5);
129  new FXRadioButton(gf2, "Predefined: ", &myChosenTarget, FXDataTarget::ID_OPTION + 2,
130  ICON_BEFORE_TEXT | LAYOUT_SIDE_TOP | LAYOUT_CENTER_Y,
131  0, 0, 0, 0, 2, 2, 0, 0);
132  myPredefinedValues =
133  new FXComboBox(gf2, 10, this, MID_PRE_DEF,
134  ICON_BEFORE_TEXT | LAYOUT_SIDE_TOP | LAYOUT_CENTER_Y | COMBOBOX_STATIC);
135  myPredefinedValues->appendItem("20 km/h");
136  myPredefinedValues->appendItem("40 km/h");
137  myPredefinedValues->appendItem("60 km/h");
138  myPredefinedValues->appendItem("80 km/h");
139  myPredefinedValues->appendItem("100 km/h");
140  myPredefinedValues->appendItem("120 km/h");
141  myPredefinedValues->appendItem("140 km/h");
142  myPredefinedValues->appendItem("160 km/h");
143  myPredefinedValues->appendItem("180 km/h");
144  myPredefinedValues->appendItem("200 km/h");
145  myPredefinedValues->setNumVisible(5);
146  }
147  {
148  // free
149  FXHorizontalFrame* gf12 =
150  new FXHorizontalFrame(gp, LAYOUT_TOP | LAYOUT_LEFT, 0, 0, 0, 0, 10, 10, 5, 5);
151  new FXRadioButton(gf12, "Free Entry: ", &myChosenTarget, FXDataTarget::ID_OPTION + 3,
152  ICON_BEFORE_TEXT | LAYOUT_SIDE_TOP | LAYOUT_CENTER_Y,
153  0, 0, 0, 0, 2, 2, 0, 0);
154  myUserDefinedSpeed =
155  new FXRealSpinDial(gf12, 10, this, MID_USER_DEF,
156  LAYOUT_TOP | FRAME_SUNKEN | FRAME_THICK);
157  myUserDefinedSpeed->setFormatString("%.0f km/h");
158  myUserDefinedSpeed->setIncrements(1, 10, 10);
159  myUserDefinedSpeed->setRange(0, 300);
160  myUserDefinedSpeed->setValue(
161  static_cast<GUILaneSpeedTrigger*>(myObject)->getDefaultSpeed() * 3.6);
162  }
163  new FXButton(f1, "Close", NULL, this, MID_CLOSE,
164  BUTTON_INITIAL | BUTTON_DEFAULT | FRAME_RAISED | FRAME_THICK | LAYOUT_TOP | LAYOUT_LEFT | LAYOUT_CENTER_X, 0, 0, 0, 0, 30, 30, 4, 4);
165  static_cast<GUILaneSpeedTrigger*>(myObject)->setOverriding(true);
166 }
167 
168 
170 
171 
172 long
174  destroy();
175  return 1;
176 }
177 
178 
179 long
181  mySpeed = (double)(myUserDefinedSpeed->getValue() / 3.6);
184  return 1;
185 }
186 
187 
188 long
189 GUILaneSpeedTrigger::GUIManip_LaneSpeedTrigger::onUpdUserDef(FXObject* sender, FXSelector, void* ptr) {
190  sender->handle(this,
191  myChosenValue != 3 ? FXSEL(SEL_COMMAND, ID_DISABLE) : FXSEL(SEL_COMMAND, ID_ENABLE),
192  ptr);
194  return 1;
195 }
196 
197 
198 long
200  mySpeed = (double)(double)((myPredefinedValues->getCurrentItem() * 20 + 20) / 3.6);
203  return 1;
204 }
205 
206 
207 long
208 GUILaneSpeedTrigger::GUIManip_LaneSpeedTrigger::onUpdPreDef(FXObject* sender, FXSelector, void* ptr) {
209  sender->handle(this,
210  myChosenValue != 2 ? FXSEL(SEL_COMMAND, ID_DISABLE) : FXSEL(SEL_COMMAND, ID_ENABLE),
211  ptr);
213  return 1;
214 }
215 
216 
217 long
219  static_cast<GUILaneSpeedTrigger*>(myObject)->setOverriding(true);
220  switch (myChosenValue) {
221  case 0:
222  mySpeed = (double) static_cast<GUILaneSpeedTrigger*>(myObject)->getDefaultSpeed();
223  break;
224  case 1:
225  mySpeed = (double) static_cast<GUILaneSpeedTrigger*>(myObject)->getLoadedSpeed();
226  break;
227  case 2:
228  mySpeed = (double)((myPredefinedValues->getCurrentItem() * 20 + 20) / 3.6);
229  break;
230  case 3:
231  mySpeed = (double)(myUserDefinedSpeed->getValue() / 3.6);
232  break;
233  default:
234  // hmmm, should not happen
235  break;
236  }
239  if (myChosenValue == 1) {
240  // !!! lock in between
241  static_cast<GUILaneSpeedTrigger*>(myObject)->setOverriding(false);
242  }
243  return 1;
244 }
245 
246 
247 
248 /* -------------------------------------------------------------------------
249  * GUILaneSpeedTrigger::GUILaneSpeedTriggerPopupMenu - methods
250  * ----------------------------------------------------------------------- */
252  GUIMainWindow& app, GUISUMOAbstractView& parent,
253  GUIGlObject& o)
254  : GUIGLObjectPopupMenu(app, parent, o) {}
255 
256 
258 
259 
260 long
262  FXSelector,
263  void*) {
266  return 1;
267 }
268 
269 
270 /* -------------------------------------------------------------------------
271  * GUILaneSpeedTrigger - methods
272  * ----------------------------------------------------------------------- */
274  const std::string& id, const std::vector<MSLane*>& destLanes,
275  const std::string& aXMLFilename) :
276  MSLaneSpeedTrigger(id, destLanes, aXMLFilename),
277  GUIGlObject_AbstractAdd("speedtrigger", GLO_TRIGGER, id),
278  myShowAsKMH(true), myLastValue(-1) {
279  myFGPositions.reserve(destLanes.size());
280  myFGRotations.reserve(destLanes.size());
281  std::vector<MSLane*>::const_iterator i;
282  for (i = destLanes.begin(); i != destLanes.end(); ++i) {
283  const PositionVector& v = (*i)->getShape();
284  myFGPositions.push_back(v.positionAtOffset(0));
286  myFGRotations.push_back(-v.rotationDegreeAtOffset(0));
287  }
288 }
289 
290 
292 
293 
296  GUISUMOAbstractView& parent) {
297  GUIGLObjectPopupMenu* ret = new GUILaneSpeedTriggerPopupMenu(app, parent, *this);
298  buildPopupHeader(ret, app);
304  buildPositionCopyEntry(ret, false);
305  return ret;
306 }
307 
308 
313  new GUIParameterTableWindow(app, *this, 1);
314  // add items
315  ret->mkItem("speed [m/s]", true,
317  // close building
318  ret->closeBuilding();
319  return ret;
320 }
321 
322 
323 void
325  glPushName(getGlID());
326  glPushMatrix();
327  glTranslated(0, 0, getType());
328  const double exaggeration = s.addSize.getExaggeration(s);
329  for (int i = 0; i < (int)myFGPositions.size(); ++i) {
330  const Position& pos = myFGPositions[i];
331  double rot = myFGRotations[i];
332  glPushMatrix();
333  glScaled(exaggeration, exaggeration, 1);
334  glTranslated(pos.x(), pos.y(), 0);
335  glRotated(rot, 0, 0, 1);
336  glTranslated(0, -1.5, 0);
337 
338  int noPoints = 9;
339  if (s.scale > 25) {
340  noPoints = (int)(9.0 + s.scale / 10.0);
341  if (noPoints > 36) {
342  noPoints = 36;
343  }
344  }
345  glColor3d(1, 0, 0);
346  GLHelper::drawFilledCircle((double) 1.3, noPoints);
347  if (s.scale >= 5) {
348  glTranslated(0, 0, .1);
349  glColor3d(0, 0, 0);
350  GLHelper::drawFilledCircle((double) 1.1, noPoints);
351  // draw the speed string
352  // not if scale to low
353  // compute
354  double value = (double) getCurrentSpeed();
355  if (myShowAsKMH) {
356  value *= 3.6f;
357  if (((int) value + 1) % 10 == 0) {
358  value = (double)(((int) value + 1) / 10 * 10);
359  }
360  }
361  if (value != myLastValue) {
362  myLastValue = value;
363  myLastValueString = toString<double>(myLastValue);
364  std::string::size_type idx = myLastValueString.find('.');
365  if (idx != std::string::npos) {
366  if (idx > myLastValueString.length()) {
367  idx = myLastValueString.length();
368  }
369  myLastValueString = myLastValueString.substr(0, idx);
370  }
371  }
372  //draw
373  glColor3d(1, 1, 0);
374  glTranslated(0, 0, .1);
375  glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
376  pfSetPosition(0, 0);
377  pfSetScale(1.2f);
378  double w = pfdkGetStringWidth(myLastValueString.c_str());
379  glRotated(180, 0, 1, 0);
380  glTranslated(-w / 2., 0.3, 0);
382  }
383  glPopMatrix();
384  }
385  glPopMatrix();
386  drawName(getCenteringBoundary().getCenter(), s.scale, s.addName);
387  glPopName();
388 }
389 
390 
391 Boundary
393  Boundary b(myBoundary);
394  b.grow(20);
395  return b;
396 }
397 
398 
403  new GUIManip_LaneSpeedTrigger(app, getFullName(), *this, 0, 0);
404  gui->create();
405  gui->show();
406  return gui;
407 }
408 
409 
410 
411 /****************************************************************************/
412 
int pfDrawString(const char *c)
Definition: polyfonts.c:1074
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)
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.
void pfSetScale(double s)
Definition: polyfonts.c:465
PosCont myFGPositions
The positions in full-geometry mode.
Open the object&#39;s manipulator.
Definition: GUIAppEnum.h:257
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:68
double x() const
Returns the x-position.
Definition: Position.h:63
Close simulation - ID.
Definition: GUIAppEnum.h:85
void buildCenterPopupEntry(GUIGLObjectPopupMenu *ret, bool addSeparator=true)
Builds an entry which allows to center to the object.
long onUpdPreDef(FXObject *, FXSelector, void *)
GUISUMOAbstractView * myParent
The parent window.
void pfSetPosition(double x, double y)
Definition: polyfonts.c:480
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:340
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:48
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:46
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:234
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.
double pfdkGetStringWidth(const char *c)
Definition: polyfonts.c:1113
GUIParameterTableWindow * getParameterWindow(GUIMainWindow &app, GUISUMOAbstractView &parent)
Returns an own parameter window.
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.
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:86
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.
void closeBuilding()
Closes the building of the table.
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)