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-2018 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 /****************************************************************************/
17 // Changes the speed allowed on a set of lanes (gui version)
18 /****************************************************************************/
19 // ===========================================================================
20 // included modules
21 // ===========================================================================
22 #include <config.h>
23 
24 #include <string>
27 #include <utils/geom/Boundary.h>
28 #include <utils/gui/div/GLHelper.h>
29 #include <utils/common/ToString.h>
30 #include <utils/common/Command.h>
31 #include <microsim/MSNet.h>
32 #include <microsim/MSLane.h>
33 #include <microsim/MSEdge.h>
34 #include <guisim/GUINet.h>
35 #include <guisim/GUIEdge.h>
36 #include "GUILaneSpeedTrigger.h"
39 #include <gui/GUIGlobals.h>
47 
48 
49 // ===========================================================================
50 // FOX callback mapping
51 // ===========================================================================
52 /* -------------------------------------------------------------------------
53  * GUILaneSpeedTrigger::GUILaneSpeedTriggerPopupMenu - mapping
54  * ----------------------------------------------------------------------- */
58 
59 };
60 
61 // Object implementation
63 
64 
65 /* -------------------------------------------------------------------------
66  * GUILaneSpeedTrigger::GUIManip_LaneSpeedTrigger - mapping
67  * ----------------------------------------------------------------------- */
68 FXDEFMAP(GUILaneSpeedTrigger::GUIManip_LaneSpeedTrigger) GUIManip_LaneSpeedTriggerMap[] = {
75 };
76 
77 FXIMPLEMENT(GUILaneSpeedTrigger::GUIManip_LaneSpeedTrigger, GUIManipulator, GUIManip_LaneSpeedTriggerMap, ARRAYNUMBER(GUIManip_LaneSpeedTriggerMap))
78 
79 
80 // ===========================================================================
81 // method definitions
82 // ===========================================================================
83 /* -------------------------------------------------------------------------
84  * GUILaneSpeedTrigger::GUIManip_LaneSpeedTrigger - methods
85  * ----------------------------------------------------------------------- */
87  GUIMainWindow& app,
88  const std::string& name, GUILaneSpeedTrigger& o,
89  int /*xpos*/, int /*ypos*/)
90  : GUIManipulator(app, name, 0, 0),
91  myParent(&app), myChosenValue(0), myChosenTarget(myChosenValue, nullptr, MID_OPTION),
92  mySpeed(o.getDefaultSpeed()), mySpeedTarget(mySpeed),
93  myObject(&o) {
94  myChosenTarget.setTarget(this);
95  FXVerticalFrame* f1 =
96  new FXVerticalFrame(this, LAYOUT_FILL_X | LAYOUT_FILL_Y, 0, 0, 0, 0, 0, 0, 0, 0);
97 
98  FXGroupBox* gp = new FXGroupBox(f1, "Change Speed",
99  GROUPBOX_TITLE_LEFT | FRAME_RIDGE,
100  0, 0, 0, 0, 4, 4, 1, 1, 2, 0);
101  {
102  // default
103  FXHorizontalFrame* gf1 =
104  new FXHorizontalFrame(gp, LAYOUT_TOP | LAYOUT_LEFT, 0, 0, 0, 0, 10, 10, 5, 5);
105  new FXRadioButton(gf1, "Default", &myChosenTarget, FXDataTarget::ID_OPTION + 0,
106  ICON_BEFORE_TEXT | LAYOUT_SIDE_TOP,
107  0, 0, 0, 0, 2, 2, 0, 0);
108  }
109  {
110  // loaded
111  FXHorizontalFrame* gf0 =
112  new FXHorizontalFrame(gp, LAYOUT_TOP | LAYOUT_LEFT, 0, 0, 0, 0, 10, 10, 5, 5);
113  new FXRadioButton(gf0, "Loaded", &myChosenTarget, FXDataTarget::ID_OPTION + 1,
114  ICON_BEFORE_TEXT | LAYOUT_SIDE_TOP,
115  0, 0, 0, 0, 2, 2, 0, 0);
116  }
117  {
118  // predefined
119  FXHorizontalFrame* gf2 =
120  new FXHorizontalFrame(gp, LAYOUT_TOP | LAYOUT_LEFT, 0, 0, 0, 0, 10, 10, 5, 5);
121  new FXRadioButton(gf2, "Predefined: ", &myChosenTarget, FXDataTarget::ID_OPTION + 2,
122  ICON_BEFORE_TEXT | LAYOUT_SIDE_TOP | LAYOUT_CENTER_Y,
123  0, 0, 0, 0, 2, 2, 0, 0);
124  myPredefinedValues =
125  new FXComboBox(gf2, 10, this, MID_PRE_DEF,
126  ICON_BEFORE_TEXT | LAYOUT_SIDE_TOP | LAYOUT_CENTER_Y | COMBOBOX_STATIC);
127  myPredefinedValues->appendItem("20 km/h");
128  myPredefinedValues->appendItem("40 km/h");
129  myPredefinedValues->appendItem("60 km/h");
130  myPredefinedValues->appendItem("80 km/h");
131  myPredefinedValues->appendItem("100 km/h");
132  myPredefinedValues->appendItem("120 km/h");
133  myPredefinedValues->appendItem("140 km/h");
134  myPredefinedValues->appendItem("160 km/h");
135  myPredefinedValues->appendItem("180 km/h");
136  myPredefinedValues->appendItem("200 km/h");
137  myPredefinedValues->setNumVisible(5);
138  }
139  {
140  // free
141  FXHorizontalFrame* gf12 =
142  new FXHorizontalFrame(gp, LAYOUT_TOP | LAYOUT_LEFT, 0, 0, 0, 0, 10, 10, 5, 5);
143  new FXRadioButton(gf12, "Free Entry: ", &myChosenTarget, FXDataTarget::ID_OPTION + 3,
144  ICON_BEFORE_TEXT | LAYOUT_SIDE_TOP | LAYOUT_CENTER_Y,
145  0, 0, 0, 0, 2, 2, 0, 0);
146  myUserDefinedSpeed =
147  new FXRealSpinner(gf12, 10, this, MID_USER_DEF,
148  LAYOUT_TOP | FRAME_SUNKEN | FRAME_THICK);
149  //myUserDefinedSpeed->setFormatString("%.0f km/h");
150  //myUserDefinedSpeed->setIncrements(1, 10, 10);
151  myUserDefinedSpeed->setIncrement(10);
152  myUserDefinedSpeed->setRange(0, 300);
153  myUserDefinedSpeed->setValue(
154  static_cast<GUILaneSpeedTrigger*>(myObject)->getDefaultSpeed() * 3.6);
155  }
156  new FXButton(f1, "Close", nullptr, this, MID_CLOSE,
157  BUTTON_INITIAL | BUTTON_DEFAULT | FRAME_RAISED | FRAME_THICK | LAYOUT_TOP | LAYOUT_LEFT | LAYOUT_CENTER_X, 0, 0, 0, 0, 30, 30, 4, 4);
158  static_cast<GUILaneSpeedTrigger*>(myObject)->setOverriding(true);
159 }
160 
161 
163 
164 
165 long
167  destroy();
168  return 1;
169 }
170 
171 
172 long
174  mySpeed = (double)(myUserDefinedSpeed->getValue() / 3.6);
177  return 1;
178 }
179 
180 
181 long
182 GUILaneSpeedTrigger::GUIManip_LaneSpeedTrigger::onUpdUserDef(FXObject* sender, FXSelector, void* ptr) {
183  sender->handle(this,
184  myChosenValue != 3 ? FXSEL(SEL_COMMAND, ID_DISABLE) : FXSEL(SEL_COMMAND, ID_ENABLE),
185  ptr);
187  return 1;
188 }
189 
190 
191 long
193  mySpeed = (double)(double)((myPredefinedValues->getCurrentItem() * 20 + 20) / 3.6);
196  return 1;
197 }
198 
199 
200 long
201 GUILaneSpeedTrigger::GUIManip_LaneSpeedTrigger::onUpdPreDef(FXObject* sender, FXSelector, void* ptr) {
202  sender->handle(this,
203  myChosenValue != 2 ? FXSEL(SEL_COMMAND, ID_DISABLE) : FXSEL(SEL_COMMAND, ID_ENABLE),
204  ptr);
206  return 1;
207 }
208 
209 
210 long
212  static_cast<GUILaneSpeedTrigger*>(myObject)->setOverriding(true);
213  switch (myChosenValue) {
214  case 0:
215  mySpeed = (double) static_cast<GUILaneSpeedTrigger*>(myObject)->getDefaultSpeed();
216  break;
217  case 1:
218  mySpeed = (double) static_cast<GUILaneSpeedTrigger*>(myObject)->getLoadedSpeed();
219  break;
220  case 2:
221  mySpeed = (double)((myPredefinedValues->getCurrentItem() * 20 + 20) / 3.6);
222  break;
223  case 3:
224  mySpeed = (double)(myUserDefinedSpeed->getValue() / 3.6);
225  break;
226  default:
227  // hmmm, should not happen
228  break;
229  }
232  if (myChosenValue == 1) {
233  // !!! lock in between
234  static_cast<GUILaneSpeedTrigger*>(myObject)->setOverriding(false);
235  }
236  return 1;
237 }
238 
239 
240 
241 /* -------------------------------------------------------------------------
242  * GUILaneSpeedTrigger::GUILaneSpeedTriggerPopupMenu - methods
243  * ----------------------------------------------------------------------- */
245  GUIMainWindow& app, GUISUMOAbstractView& parent,
246  GUIGlObject& o)
247  : GUIGLObjectPopupMenu(app, parent, o) {}
248 
249 
251 
252 
253 long
255  FXSelector,
256  void*) {
259  return 1;
260 }
261 
262 // -------------------------------------------------------------------------
263 // GUILaneSpeedTrigger - methods
264 // -------------------------------------------------------------------------
265 
267  const std::string& id, const std::vector<MSLane*>& destLanes,
268  const std::string& aXMLFilename) :
269  MSLaneSpeedTrigger(id, destLanes, aXMLFilename),
271  myShowAsKMH(true), myLastValue(-1) {
272  myFGPositions.reserve(destLanes.size());
273  myFGRotations.reserve(destLanes.size());
274  std::vector<MSLane*>::const_iterator i;
275  for (i = destLanes.begin(); i != destLanes.end(); ++i) {
276  const PositionVector& v = (*i)->getShape();
277  myFGPositions.push_back(v.positionAtOffset(0));
279  myFGRotations.push_back(-v.rotationDegreeAtOffset(0));
280  }
281 }
282 
283 
285 
286 
289  GUISUMOAbstractView& parent) {
290  GUIGLObjectPopupMenu* ret = new GUILaneSpeedTriggerPopupMenu(app, parent, *this);
291  buildPopupHeader(ret, app);
297  buildPositionCopyEntry(ret, false);
298  return ret;
299 }
300 
301 
306  new GUIParameterTableWindow(app, *this, 1);
307  // add items
308  ret->mkItem("speed [m/s]", true,
310  // close building
311  ret->closeBuilding();
312  return ret;
313 }
314 
315 
316 void
318  glPushName(getGlID());
319  glPushMatrix();
320  glTranslated(0, 0, getType());
321  const double exaggeration = s.addSize.getExaggeration(s, this);
322  for (int i = 0; i < (int)myFGPositions.size(); ++i) {
323  const Position& pos = myFGPositions[i];
324  double rot = myFGRotations[i];
325  glPushMatrix();
326  glScaled(exaggeration, exaggeration, 1);
327  glTranslated(pos.x(), pos.y(), 0);
328  glRotated(rot, 0, 0, 1);
329  glTranslated(0, -1.5, 0);
330 
331  int noPoints = 9;
332  if (s.scale > 25) {
333  noPoints = (int)(9.0 + s.scale / 10.0);
334  if (noPoints > 36) {
335  noPoints = 36;
336  }
337  }
338  glColor3d(1, 0, 0);
339  GLHelper::drawFilledCircle((double) 1.3, noPoints);
340  if (s.scale >= 5) {
341  glTranslated(0, 0, .1);
342  glColor3d(0, 0, 0);
343  GLHelper::drawFilledCircle((double) 1.1, noPoints);
344  // draw the speed string
345  // not if scale to low
346  // compute
347  double value = (double) getCurrentSpeed();
348  if (myShowAsKMH) {
349  value *= 3.6f;
350  if (((int) value + 1) % 10 == 0) {
351  value = (double)(((int) value + 1) / 10 * 10);
352  }
353  }
354  if (value != myLastValue) {
355  myLastValue = value;
356  myLastValueString = toString<double>(myLastValue);
357  std::string::size_type idx = myLastValueString.find('.');
358  if (idx != std::string::npos) {
359  if (idx > myLastValueString.length()) {
360  idx = myLastValueString.length();
361  }
362  myLastValueString = myLastValueString.substr(0, idx);
363  }
364  }
365  //draw
366  glColor3d(1, 1, 0);
367  glTranslated(0, 0, .1);
368  glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
369 
370  // draw last value string
371  GLHelper::drawText(myLastValueString.c_str(), Position(0, 0), .1, 1.2, RGBColor(255, 255, 0), 180);
372  }
373  glPopMatrix();
374  }
375  glPopMatrix();
376  drawName(getCenteringBoundary().getCenter(), s.scale, s.addName);
377  glPopName();
378 }
379 
380 
381 Boundary
383  Boundary b(myBoundary);
384  b.grow(20);
385  return b;
386 }
387 
388 
393  new GUIManip_LaneSpeedTrigger(app, getFullName(), *this, 0, 0);
394  gui->create();
395  gui->show();
396  return gui;
397 }
398 
399 
400 
401 /****************************************************************************/
402 
double rotationDegreeAtOffset(double pos) const
Returns the rotation at the given length.
long onCmdClose(FXObject *, FXSelector, void *)
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.
Open the object&#39;s manipulator.
Definition: GUIAppEnum.h:258
a Variable Speed Sign
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:62
void mkItem(const char *name, bool dynamic, ValueSource< T > *src)
Adds a row which obtains its value from a ValueSource.
double x() const
Returns the x-position.
Definition: Position.h:57
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:611
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:344
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:42
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:39
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.
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.
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.
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:79
GUIGlObject * myObject
The object that belongs to this popup-menu.
double getExaggeration(const GUIVisualizationSettings &s, const GUIGlObject *o, double factor=20) const
return the drawing size including exaggeration and constantSize values
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.
Close simulation - ID.
Definition: GUIAppEnum.h:80
void setOverridingValue(double val)