SUMO - Simulation of Urban MObility
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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-sim.org/
12 // Copyright (C) 2001-2013 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/Line.h>
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 "GUILaneSpeedTrigger.h"
47 #include <gui/GUIGlobals.h>
56 
57 #ifdef CHECK_MEMORY_LEAKS
58 #include <foreign/nvwa/debug_new.h>
59 #endif // CHECK_MEMORY_LEAKS
60 
61 
62 // ===========================================================================
63 // FOX callback mapping
64 // ===========================================================================
65 /* -------------------------------------------------------------------------
66  * GUILaneSpeedTrigger::GUILaneSpeedTriggerPopupMenu - mapping
67  * ----------------------------------------------------------------------- */
71 
72 };
73 
74 // Object implementation
76 
77 
78 /* -------------------------------------------------------------------------
79  * GUILaneSpeedTrigger::GUIManip_LaneSpeedTrigger - mapping
80  * ----------------------------------------------------------------------- */
81 FXDEFMAP(GUILaneSpeedTrigger::GUIManip_LaneSpeedTrigger) GUIManip_LaneSpeedTriggerMap[] = {
88 };
89 
90 FXIMPLEMENT(GUILaneSpeedTrigger::GUIManip_LaneSpeedTrigger, GUIManipulator, GUIManip_LaneSpeedTriggerMap, ARRAYNUMBER(GUIManip_LaneSpeedTriggerMap))
91 
92 
93 // ===========================================================================
94 // method definitions
95 // ===========================================================================
96 /* -------------------------------------------------------------------------
97  * GUILaneSpeedTrigger::GUIManip_LaneSpeedTrigger - methods
98  * ----------------------------------------------------------------------- */
100  GUIMainWindow& app,
101  const std::string& name, GUILaneSpeedTrigger& o,
102  int /*xpos*/, int /*ypos*/)
103  : GUIManipulator(app, name, 0, 0),
104  myParent(&app), myChosenValue(0), myChosenTarget(myChosenValue, NULL, MID_OPTION),
105  mySpeed(o.getDefaultSpeed()), mySpeedTarget(mySpeed),
106  myObject(&o) {
107  myChosenTarget.setTarget(this);
108  FXVerticalFrame* f1 =
109  new FXVerticalFrame(this, LAYOUT_FILL_X | LAYOUT_FILL_Y, 0, 0, 0, 0, 0, 0, 0, 0);
110 
111  FXGroupBox* gp = new FXGroupBox(f1, "Change Speed",
112  GROUPBOX_TITLE_LEFT | FRAME_RIDGE,
113  0, 0, 0, 0, 4, 4, 1, 1, 2, 0);
114  {
115  // default
116  FXHorizontalFrame* gf1 =
117  new FXHorizontalFrame(gp, LAYOUT_TOP | LAYOUT_LEFT, 0, 0, 0, 0, 10, 10, 5, 5);
118  new FXRadioButton(gf1, "Default", &myChosenTarget, FXDataTarget::ID_OPTION + 0,
119  ICON_BEFORE_TEXT | LAYOUT_SIDE_TOP,
120  0, 0, 0, 0, 2, 2, 0, 0);
121  }
122  {
123  // loaded
124  FXHorizontalFrame* gf0 =
125  new FXHorizontalFrame(gp, LAYOUT_TOP | LAYOUT_LEFT, 0, 0, 0, 0, 10, 10, 5, 5);
126  new FXRadioButton(gf0, "Loaded", &myChosenTarget, FXDataTarget::ID_OPTION + 1,
127  ICON_BEFORE_TEXT | LAYOUT_SIDE_TOP,
128  0, 0, 0, 0, 2, 2, 0, 0);
129  }
130  {
131  // predefined
132  FXHorizontalFrame* gf2 =
133  new FXHorizontalFrame(gp, LAYOUT_TOP | LAYOUT_LEFT, 0, 0, 0, 0, 10, 10, 5, 5);
134  new FXRadioButton(gf2, "Predefined: ", &myChosenTarget, FXDataTarget::ID_OPTION + 2,
135  ICON_BEFORE_TEXT | LAYOUT_SIDE_TOP | LAYOUT_CENTER_Y,
136  0, 0, 0, 0, 2, 2, 0, 0);
137  myPredefinedValues =
138  new FXComboBox(gf2, 10, this, MID_PRE_DEF,
139  ICON_BEFORE_TEXT | LAYOUT_SIDE_TOP | LAYOUT_CENTER_Y | COMBOBOX_STATIC);
140  myPredefinedValues->appendItem("20 km/h");
141  myPredefinedValues->appendItem("40 km/h");
142  myPredefinedValues->appendItem("60 km/h");
143  myPredefinedValues->appendItem("80 km/h");
144  myPredefinedValues->appendItem("100 km/h");
145  myPredefinedValues->appendItem("120 km/h");
146  myPredefinedValues->appendItem("140 km/h");
147  myPredefinedValues->appendItem("160 km/h");
148  myPredefinedValues->appendItem("180 km/h");
149  myPredefinedValues->appendItem("200 km/h");
150  myPredefinedValues->setNumVisible(5);
151  }
152  {
153  // free
154  FXHorizontalFrame* gf12 =
155  new FXHorizontalFrame(gp, LAYOUT_TOP | LAYOUT_LEFT, 0, 0, 0, 0, 10, 10, 5, 5);
156  new FXRadioButton(gf12, "Free Entry: ", &myChosenTarget, FXDataTarget::ID_OPTION + 3,
157  ICON_BEFORE_TEXT | LAYOUT_SIDE_TOP | LAYOUT_CENTER_Y,
158  0, 0, 0, 0, 2, 2, 0, 0);
159  myUserDefinedSpeed =
160  new FXRealSpinDial(gf12, 10, this, MID_USER_DEF,
161  LAYOUT_TOP | FRAME_SUNKEN | FRAME_THICK);
162  myUserDefinedSpeed->setFormatString("%.0f km/h");
163  myUserDefinedSpeed->setIncrements(1, 10, 10);
164  myUserDefinedSpeed->setRange(0, 300);
165  myUserDefinedSpeed->setValue(
166  static_cast<GUILaneSpeedTrigger*>(myObject)->getDefaultSpeed() * 3.6);
167  }
168  new FXButton(f1, "Close", NULL, this, MID_CLOSE,
169  BUTTON_INITIAL | BUTTON_DEFAULT | FRAME_RAISED | FRAME_THICK | LAYOUT_TOP | LAYOUT_LEFT | LAYOUT_CENTER_X, 0, 0, 0, 0, 30, 30, 4, 4);
170  static_cast<GUILaneSpeedTrigger*>(myObject)->setOverriding(true);
171 }
172 
173 
175 
176 
177 long
179  destroy();
180  return 1;
181 }
182 
183 
184 long
186  mySpeed = (SUMOReal)(myUserDefinedSpeed->getValue() / 3.6);
187  static_cast<GUILaneSpeedTrigger*>(myObject)->setOverridingValue(mySpeed);
188  myParent->updateChildren();
189  return 1;
190 }
191 
192 
193 long
195  sender->handle(this,
196  myChosenValue != 3 ? FXSEL(SEL_COMMAND, ID_DISABLE) : FXSEL(SEL_COMMAND, ID_ENABLE),
197  ptr);
198  myParent->updateChildren();
199  return 1;
200 }
201 
202 
203 long
205  mySpeed = (SUMOReal)(SUMOReal)((myPredefinedValues->getCurrentItem() * 20 + 20) / 3.6);
206  static_cast<GUILaneSpeedTrigger*>(myObject)->setOverridingValue(mySpeed);
207  myParent->updateChildren();
208  return 1;
209 }
210 
211 
212 long
214  sender->handle(this,
215  myChosenValue != 2 ? FXSEL(SEL_COMMAND, ID_DISABLE) : FXSEL(SEL_COMMAND, ID_ENABLE),
216  ptr);
217  myParent->updateChildren();
218  return 1;
219 }
220 
221 
222 long
224  static_cast<GUILaneSpeedTrigger*>(myObject)->setOverriding(true);
225  switch (myChosenValue) {
226  case 0:
227  mySpeed = (SUMOReal) static_cast<GUILaneSpeedTrigger*>(myObject)->getDefaultSpeed();
228  break;
229  case 1:
230  mySpeed = (SUMOReal) static_cast<GUILaneSpeedTrigger*>(myObject)->getLoadedSpeed();
231  break;
232  case 2:
233  mySpeed = (SUMOReal)((myPredefinedValues->getCurrentItem() * 20 + 20) / 3.6);
234  break;
235  case 3:
236  mySpeed = (SUMOReal)(myUserDefinedSpeed->getValue() / 3.6);
237  break;
238  default:
239  // hmmm, should not happen
240  break;
241  }
242  static_cast<GUILaneSpeedTrigger*>(myObject)->setOverridingValue(mySpeed);
243  myParent->updateChildren();
244  if (myChosenValue == 1) {
245  // !!! lock in between
246  static_cast<GUILaneSpeedTrigger*>(myObject)->setOverriding(false);
247  }
248  return 1;
249 }
250 
251 
252 
253 /* -------------------------------------------------------------------------
254  * GUILaneSpeedTrigger::GUILaneSpeedTriggerPopupMenu - methods
255  * ----------------------------------------------------------------------- */
257  GUIMainWindow& app, GUISUMOAbstractView& parent,
258  GUIGlObject& o)
259  : GUIGLObjectPopupMenu(app, parent, o) {}
260 
261 
263 
264 
265 long
267  FXSelector,
268  void*) {
269  static_cast<GUILaneSpeedTrigger*>(myObject)->openManipulator(
270  *myApplication, *myParent);
271  return 1;
272 }
273 
274 
275 /* -------------------------------------------------------------------------
276  * GUILaneSpeedTrigger - methods
277  * ----------------------------------------------------------------------- */
279  const std::string& id, const std::vector<MSLane*>& destLanes,
280  const std::string& aXMLFilename) :
281  MSLaneSpeedTrigger(id, destLanes, aXMLFilename),
282  GUIGlObject_AbstractAdd("speedtrigger", GLO_TRIGGER, id),
283  myShowAsKMH(true), myLastValue(-1) {
284  myFGPositions.reserve(destLanes.size());
285  myFGRotations.reserve(destLanes.size());
286  std::vector<MSLane*>::const_iterator i;
287  for (i = destLanes.begin(); i != destLanes.end(); ++i) {
288  const PositionVector& v = (*i)->getShape();
289  myFGPositions.push_back(v.positionAtOffset(0));
291  myFGRotations.push_back(-v.rotationDegreeAtOffset(0));
292  }
293 }
294 
295 
297 
298 
301  GUISUMOAbstractView& parent) {
302  GUIGLObjectPopupMenu* ret = new GUILaneSpeedTriggerPopupMenu(app, parent, *this);
303  buildPopupHeader(ret, app);
309  buildPositionCopyEntry(ret, false);
310  return ret;
311 }
312 
313 
318  new GUIParameterTableWindow(app, *this, 1);
319  // add items
320  ret->mkItem("speed [m/s]", true,
322  // close building
323  ret->closeBuilding();
324  return ret;
325 }
326 
327 
328 void
330  glPushName(getGlID());
331  glPushMatrix();
332  glTranslated(0, 0, getType());
333  for (size_t i = 0; i < myFGPositions.size(); ++i) {
334  const Position& pos = myFGPositions[i];
335  SUMOReal rot = myFGRotations[i];
336  glPushMatrix();
337  glScaled(s.addExaggeration, s.addExaggeration, 1);
338  glTranslated(pos.x(), pos.y(), 0);
339  glRotated(rot, 0, 0, 1);
340  glTranslated(0, -1.5, 0);
341 
342  int noPoints = 9;
343  if (s.scale > 25) {
344  noPoints = (int)(9.0 + s.scale / 10.0);
345  if (noPoints > 36) {
346  noPoints = 36;
347  }
348  }
349  glColor3d(1, 0, 0);
350  GLHelper::drawFilledCircle((SUMOReal) 1.3, noPoints);
351  if (s.scale >= 5) {
352  glTranslated(0, 0, .1);
353  glColor3d(0, 0, 0);
354  GLHelper::drawFilledCircle((SUMOReal) 1.1, noPoints);
355  // draw the speed string
356  // not if scale to low
357  // compute
358  SUMOReal value = (SUMOReal) getCurrentSpeed();
359  if (myShowAsKMH) {
360  value *= 3.6f;
361  if (((int) value + 1) % 10 == 0) {
362  value = (SUMOReal)(((int) value + 1) / 10 * 10);
363  }
364  }
365  if (value != myLastValue) {
366  myLastValue = value;
367  myLastValueString = toString<SUMOReal>(myLastValue);
368  size_t idx = myLastValueString.find('.');
369  if (idx != std::string::npos) {
370  if (idx > myLastValueString.length()) {
371  idx = myLastValueString.length();
372  }
373  myLastValueString = myLastValueString.substr(0, idx);
374  }
375  }
376  //draw
377  glColor3d(1, 1, 0);
378  glTranslated(0, 0, .1);
379  glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
380  pfSetPosition(0, 0);
381  pfSetScale(1.2f);
383  glRotated(180, 0, 1, 0);
384  glTranslated(-w / 2., 0.3, 0);
386  }
387  glPopMatrix();
388  }
389  glPopMatrix();
390  drawName(getCenteringBoundary().getCenter(), s.scale, s.addName);
391  glPopName();
392 }
393 
394 
395 Boundary
397  Boundary b(myBoundary);
398  b.grow(20);
399  return b;
400 }
401 
402 
407  new GUIManip_LaneSpeedTrigger(app, getFullName(), *this, 0, 0);
408  gui->create();
409  gui->show();
410  return gui;
411 }
412 
413 
414 
415 /****************************************************************************/
416 
void setOverridingValue(SUMOReal val)
int pfDrawString(const char *c)
Definition: polyfonts.c:1070
long onCmdClose(FXObject *, FXSelector, void *)
a lane speed trigger,
long onCmdUserDef(FXObject *, FXSelector, void *)
Position positionAtOffset(SUMOReal pos) const
Returns the position at the given length.
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.
void drawGL(const GUIVisualizationSettings &s) const
Draws the object.
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 *)
void pfSetPosition(SUMOReal x, SUMOReal y)
Definition: polyfonts.c:476
void buildCenterPopupEntry(GUIGLObjectPopupMenu *ret, bool addSeparator=true)
Builds an entry which allows to center to the object.
long onUpdPreDef(FXObject *, FXSelector, void *)
Boundary getCenteringBoundary() const
Returns the boundary to which the view shall be centered in order to show the object.
GUIGLObjectPopupMenu * getPopUpMenu(GUIMainWindow &app, GUISUMOAbstractView &parent)
Returns an own popup-menu.
void buildShowParamsPopupEntry(GUIGLObjectPopupMenu *ret, bool addSeparator=true)
Builds an entry which allows to open the parameter window.
Close simulation - ID.
Definition: GUIAppEnum.h:81
SUMOReal x() const
Returns the x-position.
Definition: Position.h:63
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.
GUIGlID getGlID() const
Returns the numerical id of the object.
Definition: GUIGlObject.h:115
A class that stores a 2D geometrical boundary.
Definition: Boundary.h:48
FXDEFMAP(GUIDialog_AppSettings) GUIDialog_AppSettingsMap[]
SUMOReal scale
information about a lane&#39;s width (temporary, used for a single view)
Changes the speed allowed on a set of lanes.
long onUpdUserDef(FXObject *, FXSelector, void *)
SUMOReal getCurrentSpeed() const
Returns the current speed.
static void drawFilledCircle(SUMOReal width, int steps=8)
Draws a filled circle around (0,0)
Definition: GLHelper.cpp:196
Boundary myBoundary
The boundary of this rerouter.
GUIGlObjectType getType() const
Returns the type of the object as coded in GUIGlObjectType.
Definition: GUIGlObject.h:159
float addExaggeration
The additional structures exaggeration (upscale)
A point in 2D or 3D with translation and scaling methods.
Definition: Position.h:46
A list of positions.
GUILaneSpeedTriggerPopupMenuMap[]
void drawName(const Position &pos, const SUMOReal scale, const GUIVisualizationTextSettings &settings, const SUMOReal angle=0) const
void setOverriding(bool val)
long onCmdPreDef(FXObject *, FXSelector, void *)
std::string myLastValueString
Storage for speed string to avoid recomputation.
GUILaneSpeedTrigger(const std::string &id, const std::vector< MSLane * > &destLanes, const std::string &file)
Constructor.
SUMOReal rotationDegreeAtOffset(SUMOReal pos) const
Returns the rotation at the given length.
void buildShowManipulatorPopupEntry(GUIGLObjectPopupMenu *ret, bool addSeparator=true)
Builds an entry which allows to open the manipulator window.
void add(SUMOReal x, SUMOReal y)
Makes the boundary include the given coordinate.
Definition: Boundary.cpp:76
Boundary & grow(SUMOReal by)
extends the boundary by the given amount
Definition: Boundary.cpp:200
GUIParameterTableWindow * getParameterWindow(GUIMainWindow &app, GUISUMOAbstractView &parent)
Returns an own parameter window.
void pfSetScale(SUMOReal s)
Definition: polyfonts.c:461
RotCont myFGRotations
The rotations in full-geometry mode.
SUMOReal y() const
Returns the y-position.
Definition: Position.h:68
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.
SUMOReal pfdkGetStringWidth(const char *c)
Definition: polyfonts.c:1109
GUIManipulator * openManipulator(GUIMainWindow &app, GUISUMOAbstractView &parent)
#define SUMOReal
Definition: config.h:215
Changes the speed allowed on a set of lanes (gui version)
Spinner control.
const std::string & getFullName() const
Returns the full name appearing in the tool tip.
Definition: GUIGlObject.h:107
void mkItem(const char *name, bool dynamic, ValueSource< unsigned > *src)
Adds a row which obtains its value from an unsigned-ValueSource.
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.
Open the object&#39;s manipulator.
Definition: GUIAppEnum.h:231
SUMOReal myLastValue
Storage for last value to avoid string recomputation.