SUMO - Simulation of Urban MObility
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
GUICalibrator.cpp
Go to the documentation of this file.
1 /****************************************************************************/
9 // Changes flow and speed 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 "GUICalibrator.h"
47 #include <gui/GUIGlobals.h>
54 #include <guisim/GUICalibrator.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  * GUICalibrator::GUICalibratorPopupMenu - mapping
67  * ----------------------------------------------------------------------- */
71 
72 };
73 
74 // Object implementation
76 
77 
78 /* -------------------------------------------------------------------------
79  * GUICalibrator::GUIManip_Calibrator - mapping
80  * ----------------------------------------------------------------------- */
81 FXDEFMAP(GUICalibrator::GUIManip_Calibrator) GUIManip_CalibratorMap[] = {
88 };
89 
90 FXIMPLEMENT(GUICalibrator::GUIManip_Calibrator, GUIManipulator, GUIManip_CalibratorMap, ARRAYNUMBER(GUIManip_CalibratorMap))
91 
92 
93 // ===========================================================================
94 // method definitions
95 // ===========================================================================
96 /* -------------------------------------------------------------------------
97  * GUICalibrator::GUIManip_Calibrator - methods
98  * ----------------------------------------------------------------------- */
100  GUIMainWindow& app,
101  const std::string& name, GUICalibrator& o,
102  int /*xpos*/, int /*ypos*/) :
103  GUIManipulator(app, name, 0, 0),
104  myParent(&app),
105  myChosenValue(0),
106  myChosenTarget(myChosenValue, NULL, MID_OPTION),
107  //mySpeed(o.getDefaultSpeed()),
108  mySpeed(0),
109  mySpeedTarget(mySpeed),
110  myObject(&o) {
111  myChosenTarget.setTarget(this);
112  FXVerticalFrame* f1 =
113  new FXVerticalFrame(this, LAYOUT_FILL_X | LAYOUT_FILL_Y, 0, 0, 0, 0, 0, 0, 0, 0);
114 
115  FXGroupBox* gp = new FXGroupBox(f1, "Change Speed",
116  GROUPBOX_TITLE_LEFT | FRAME_RIDGE,
117  0, 0, 0, 0, 4, 4, 1, 1, 2, 0);
118  {
119  // default
120  FXHorizontalFrame* gf1 =
121  new FXHorizontalFrame(gp, LAYOUT_TOP | LAYOUT_LEFT, 0, 0, 0, 0, 10, 10, 5, 5);
122  new FXRadioButton(gf1, "Default", &myChosenTarget, FXDataTarget::ID_OPTION + 0,
123  ICON_BEFORE_TEXT | LAYOUT_SIDE_TOP,
124  0, 0, 0, 0, 2, 2, 0, 0);
125  }
126  {
127  // loaded
128  FXHorizontalFrame* gf0 =
129  new FXHorizontalFrame(gp, LAYOUT_TOP | LAYOUT_LEFT, 0, 0, 0, 0, 10, 10, 5, 5);
130  new FXRadioButton(gf0, "Loaded", &myChosenTarget, FXDataTarget::ID_OPTION + 1,
131  ICON_BEFORE_TEXT | LAYOUT_SIDE_TOP,
132  0, 0, 0, 0, 2, 2, 0, 0);
133  }
134  {
135  // predefined
136  FXHorizontalFrame* gf2 =
137  new FXHorizontalFrame(gp, LAYOUT_TOP | LAYOUT_LEFT, 0, 0, 0, 0, 10, 10, 5, 5);
138  new FXRadioButton(gf2, "Predefined: ", &myChosenTarget, FXDataTarget::ID_OPTION + 2,
139  ICON_BEFORE_TEXT | LAYOUT_SIDE_TOP | LAYOUT_CENTER_Y,
140  0, 0, 0, 0, 2, 2, 0, 0);
141  myPredefinedValues =
142  new FXComboBox(gf2, 10, this, MID_PRE_DEF,
143  ICON_BEFORE_TEXT | LAYOUT_SIDE_TOP | LAYOUT_CENTER_Y | COMBOBOX_STATIC);
144  myPredefinedValues->appendItem("20 km/h");
145  myPredefinedValues->appendItem("40 km/h");
146  myPredefinedValues->appendItem("60 km/h");
147  myPredefinedValues->appendItem("80 km/h");
148  myPredefinedValues->appendItem("100 km/h");
149  myPredefinedValues->appendItem("120 km/h");
150  myPredefinedValues->appendItem("140 km/h");
151  myPredefinedValues->appendItem("160 km/h");
152  myPredefinedValues->appendItem("180 km/h");
153  myPredefinedValues->appendItem("200 km/h");
154  myPredefinedValues->setNumVisible(5);
155  }
156  {
157  // free
158  FXHorizontalFrame* gf12 =
159  new FXHorizontalFrame(gp, LAYOUT_TOP | LAYOUT_LEFT, 0, 0, 0, 0, 10, 10, 5, 5);
160  new FXRadioButton(gf12, "Free Entry: ", &myChosenTarget, FXDataTarget::ID_OPTION + 3,
161  ICON_BEFORE_TEXT | LAYOUT_SIDE_TOP | LAYOUT_CENTER_Y,
162  0, 0, 0, 0, 2, 2, 0, 0);
163  myUserDefinedSpeed =
164  new FXRealSpinDial(gf12, 10, this, MID_USER_DEF,
165  LAYOUT_TOP | FRAME_SUNKEN | FRAME_THICK);
166  myUserDefinedSpeed->setFormatString("%.0f km/h");
167  myUserDefinedSpeed->setIncrements(1, 10, 10);
168  myUserDefinedSpeed->setRange(0, 300);
169  myUserDefinedSpeed->setValue(0);
170  //static_cast<GUICalibrator*>(myObject)->getDefaultSpeed() * 3.6);
171  }
172  new FXButton(f1, "Close", NULL, this, MID_CLOSE,
173  BUTTON_INITIAL | BUTTON_DEFAULT | FRAME_RAISED | FRAME_THICK | LAYOUT_TOP | LAYOUT_LEFT | LAYOUT_CENTER_X, 0, 0, 0, 0, 30, 30, 4, 4);
174  //static_cast<GUICalibrator*>(myObject)->setOverriding(true);
175 }
176 
177 
179 
180 
181 long
183  destroy();
184  return 1;
185 }
186 
187 
188 long
190  //mySpeed = (SUMOReal)(myUserDefinedSpeed->getValue() / 3.6);
191  //static_cast<GUICalibrator*>(myObject)->setOverridingValue(mySpeed);
192  //myParent->updateChildren();
193  return 1;
194 }
195 
196 
197 long
199  sender->handle(this,
200  myChosenValue != 3 ? FXSEL(SEL_COMMAND, ID_DISABLE) : FXSEL(SEL_COMMAND, ID_ENABLE),
201  ptr);
202  myParent->updateChildren();
203  return 1;
204 }
205 
206 
207 long
209  //mySpeed = (SUMOReal)(SUMOReal)((myPredefinedValues->getCurrentItem() * 20 + 20) / 3.6);
210  //static_cast<GUICalibrator*>(myObject)->setOverridingValue(mySpeed);
211  //myParent->updateChildren();
212  return 1;
213 }
214 
215 
216 long
218  sender->handle(this,
219  myChosenValue != 2 ? FXSEL(SEL_COMMAND, ID_DISABLE) : FXSEL(SEL_COMMAND, ID_ENABLE),
220  ptr);
221  myParent->updateChildren();
222  return 1;
223 }
224 
225 
226 long
228  //static_cast<GUICalibrator*>(myObject)->setOverriding(true);
229  //switch (myChosenValue) {
230  // case 0:
231  // mySpeed = (SUMOReal) static_cast<GUICalibrator*>(myObject)->getDefaultSpeed();
232  // break;
233  // case 1:
234  // mySpeed = (SUMOReal) static_cast<GUICalibrator*>(myObject)->getLoadedSpeed();
235  // break;
236  // case 2:
237  // mySpeed = (SUMOReal)((myPredefinedValues->getCurrentItem() * 20 + 20) / 3.6);
238  // break;
239  // case 3:
240  // mySpeed = (SUMOReal)(myUserDefinedSpeed->getValue() / 3.6);
241  // break;
242  // default:
243  // // hmmm, should not happen
244  // break;
245  //}
246  //static_cast<GUICalibrator*>(myObject)->setOverridingValue(mySpeed);
247  //myParent->updateChildren();
248  //if (myChosenValue == 1) {
249  // // !!! lock in between
250  // static_cast<GUICalibrator*>(myObject)->setOverriding(false);
251  //}
252  return 1;
253 }
254 
255 
256 
257 /* -------------------------------------------------------------------------
258  * GUICalibrator::GUICalibratorPopupMenu - methods
259  * ----------------------------------------------------------------------- */
261  GUIMainWindow& app, GUISUMOAbstractView& parent,
262  GUIGlObject& o)
263  : GUIGLObjectPopupMenu(app, parent, o) {}
264 
265 
267 
268 
269 long
271  FXSelector,
272  void*) {
273  static_cast<GUICalibrator*>(myObject)->openManipulator(
274  *myApplication, *myParent);
275  return 1;
276 }
277 
278 
279 /* -------------------------------------------------------------------------
280  * GUICalibrator - methods
281  * ----------------------------------------------------------------------- */
282 GUICalibrator::GUICalibrator(const std::string& id,
283  MSEdge* edge, SUMOReal pos,
284  const std::string& aXMLFilename,
285  const std::string& outputFilename,
286  const SUMOTime freq,
287  const MSRouteProbe* probe) :
288  MSCalibrator(id, edge, pos, aXMLFilename, outputFilename, freq, edge->getLength(), probe),
289  GUIGlObject_AbstractAdd("calibrator", GLO_TRIGGER, id),
290  myShowAsKMH(true) {
291  const std::vector<MSLane*>& destLanes = edge->getLanes();
292  myFGPositions.reserve(destLanes.size());
293  myFGRotations.reserve(destLanes.size());
294  for (std::vector<MSLane*>::const_iterator i = destLanes.begin(); i != destLanes.end(); ++i) {
295  const PositionVector& v = (*i)->getShape();
296  myFGPositions.push_back(v.positionAtOffset(pos));
298  myFGRotations.push_back(-v.rotationDegreeAtOffset(pos));
299  }
300 }
301 
302 
304 
305 
308  GUISUMOAbstractView& parent) {
309  GUIGLObjectPopupMenu* ret = new GUICalibratorPopupMenu(app, parent, *this);
310  buildPopupHeader(ret, app);
312  //buildShowManipulatorPopupEntry(ret);
316  buildPositionCopyEntry(ret, false);
317  return ret;
318 }
319 
320 
325  if (isActive()) {
326  ret = new GUIParameterTableWindow(app, *this, 10);
327  // add items
328  ret->mkItem("interval start", false, STEPS2TIME(myCurrentStateInterval->begin));
329  ret->mkItem("interval end", false, STEPS2TIME(myCurrentStateInterval->end));
330  ret->mkItem("aspired flow [veh/h]", false, myCurrentStateInterval->q);
331  ret->mkItem("aspired speed", false, myCurrentStateInterval->v);
332  ret->mkItem("default speed", false, myDefaultSpeed);
333  ret->mkItem("required vehicles", true, new FunctionBinding<GUICalibrator, int>(this, &GUICalibrator::totalWished));
334  ret->mkItem("passed vehicles", true, new FunctionBinding<GUICalibrator, int>(this, &GUICalibrator::passed));
335  ret->mkItem("inserted vehicles", true, new FunctionBinding<GUICalibrator, int>(this, &GUICalibrator::inserted));
336  ret->mkItem("removed vehicles", true, new FunctionBinding<GUICalibrator, int>(this, &GUICalibrator::removed));
337  ret->mkItem("cleared in jam", true, new FunctionBinding<GUICalibrator, int>(this, &GUICalibrator::clearedInJam));
338  } else {
339  ret = new GUIParameterTableWindow(app, *this, 1);
340  const std::string nextStart =
343  "simulation end");
344  ret->mkItem("inactive until", false, nextStart);
345  }
346  // close building
347  ret->closeBuilding();
348  return ret;
349 }
350 
351 
352 void
354  glPushName(getGlID());
355  std::string flow = "-";
356  std::string speed = "-";
357  if (isActive()) {
358  if (myCurrentStateInterval->v >= 0) {
359  speed = toString(myCurrentStateInterval->v) + "m/s";
360  }
361  if (myCurrentStateInterval->q >= 0) {
362  flow = toString((int)myCurrentStateInterval->q) + "v/h";
363  }
364  }
365  for (size_t i = 0; i < myFGPositions.size(); ++i) {
366  const Position& pos = myFGPositions[i];
367  SUMOReal rot = myFGRotations[i];
368  glPushMatrix();
369  glTranslated(pos.x(), pos.y(), getType());
370  glRotated(rot, 0, 0, 1);
371  glTranslated(0, 0, getType());
372  glScaled(s.addExaggeration, s.addExaggeration, 1);
373  glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
374 
375  glBegin(GL_TRIANGLES);
376  glColor3d(1, .8f, 0);
377  // base
378  glVertex2d(0 - 1.4, 0);
379  glVertex2d(0 - 1.4, 6);
380  glVertex2d(0 + 1.4, 6);
381  glVertex2d(0 + 1.4, 0);
382  glVertex2d(0 - 1.4, 0);
383  glVertex2d(0 + 1.4, 6);
384  glEnd();
385 
386  // draw text
387  if (s.scale * s.addExaggeration >= 1.) {
388  glTranslated(0, 0, .1);
389  glColor3d(0, 0, 0);
390  pfSetPosition(0, 0);
391  pfSetScale(3.f);
392  SUMOReal w = pfdkGetStringWidth("C");
393  glRotated(180, 0, 1, 0);
394  glTranslated(-w / 2., 2, 0);
395  pfDrawString("C");
396  glTranslated(w / 2., -2, 0);
397 
398 
399  pfSetPosition(0, 0);
400  pfSetScale(.7f);
401  w = pfdkGetStringWidth(flow.c_str());
402  glTranslated(-w / 2., 4, 0);
403  pfDrawString(flow.c_str());
404  glTranslated(w / 2., -4, 0);
405 
406  pfSetPosition(0, 0);
407  pfSetScale(.7f);
408  w = pfdkGetStringWidth(speed.c_str());
409  glTranslated(-w / 2., 5, 0);
410  pfDrawString(speed.c_str());
411  glTranslated(-w / 2., -5, 0);
412  }
413  glPopMatrix();
414  }
415  drawName(getCenteringBoundary().getCenter(), s.scale, s.addName);
416  glPopName();
417 }
418 
419 
420 Boundary
422  Boundary b(myBoundary);
423  b.grow(20);
424  return b;
425 }
426 
427 
431  GUIManip_Calibrator* gui =
432  new GUIManip_Calibrator(app, getFullName(), *this, 0, 0);
433  gui->create();
434  gui->show();
435  return gui;
436 }
437 
438 
439 
440 /****************************************************************************/
441 
int pfDrawString(const char *c)
Definition: polyfonts.c:1070
a lane speed trigger,
Changes the speed allowed on a set of lanes (gui version)
Definition: GUICalibrator.h:53
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.
const std::vector< MSLane * > & getLanes() const
Returns this edge&#39;s lanes.
Definition: MSEdge.h:168
GUIManipulator * openManipulator(GUIMainWindow &app, GUISUMOAbstractView &parent)
int inserted() const
Definition: MSCalibrator.h:175
Writes routes of vehicles passing a certain edge.
Definition: MSRouteProbe.h:68
Stores the information about how to visualize structures.
int removed() const
Definition: MSCalibrator.h:178
std::string time2string(SUMOTime t)
Definition: SUMOTime.cpp:61
GUICalibrator(const std::string &id, MSEdge *edge, SUMOReal pos, const std::string &aXMLFilename, const std::string &outputFilename, const SUMOTime freq, const MSRouteProbe *probe)
Constructor.
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.
void buildShowParamsPopupEntry(GUIGLObjectPopupMenu *ret, bool addSeparator=true)
Builds an entry which allows to open the parameter window.
Close simulation - ID.
Definition: GUIAppEnum.h:81
long onCmdChangeOption(FXObject *, FXSelector, void *)
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.
long onUpdPreDef(FXObject *, FXSelector, void *)
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[]
long onCmdOpenManip(FXObject *, FXSelector, void *)
Called if the object&#39;s manipulator shall be shown.
SUMOReal scale
information about a lane&#39;s width (temporary, used for a single view)
GUIParameterTableWindow * getParameterWindow(GUIMainWindow &app, GUISUMOAbstractView &parent)
Returns an own parameter window.
A road/street connecting two junctions.
Definition: MSEdge.h:73
GUICalibratorPopupMenuMap[]
GUIGlObjectType getType() const
Returns the type of the object as coded in GUIGlObjectType.
Definition: GUIGlObject.h:159
virtual ~GUIManip_Calibrator()
Destructor.
float addExaggeration
The additional structures exaggeration (upscale)
std::vector< AspiredState >::const_iterator myCurrentStateInterval
Iterator pointing to the current interval.
Definition: MSCalibrator.h:222
Boundary myBoundary
The boundary of this rerouter.
A point in 2D or 3D with translation and scaling methods.
Definition: Position.h:46
void drawGL(const GUIVisualizationSettings &s) const
Draws the object.
A list of positions.
long onCmdPreDef(FXObject *, FXSelector, void *)
#define STEPS2TIME(x)
Definition: SUMOTime.h:65
Boundary getCenteringBoundary() const
Returns the boundary to which the view shall be centered in order to show the object.
RotCont myFGRotations
The rotations in full-geometry mode.
std::vector< AspiredState > myIntervals
List of adaptation intervals.
Definition: MSCalibrator.h:220
void drawName(const Position &pos, const SUMOReal scale, const GUIVisualizationTextSettings &settings, const SUMOReal angle=0) const
std::string toString(const T &t, std::streamsize accuracy=OUTPUT_ACCURACY)
Definition: ToString.h:51
long onCmdClose(FXObject *, FXSelector, void *)
SUMOReal rotationDegreeAtOffset(SUMOReal pos) const
Returns the rotation at the given length.
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
void pfSetScale(SUMOReal s)
Definition: polyfonts.c:461
bool myShowAsKMH
The information whether the speed shall be shown in m/s or km/h.
PosCont myFGPositions
The positions in full-geometry mode.
SUMOReal y() const
Returns the y-position.
Definition: Position.h:68
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
virtual int passed() const
Definition: MSCalibrator.h:158
Calibrates the flow on a segment to a specified one.
Definition: MSCalibrator.h:56
long onCmdUserDef(FXObject *, FXSelector, void *)
long onUpdUserDef(FXObject *, FXSelector, void *)
#define SUMOReal
Definition: config.h:215
int totalWished() const
number of vehicles expected to pass this interval
Spinner control.
bool isActive() const
Definition: MSCalibrator.h:135
int clearedInJam() const
Definition: MSCalibrator.h:181
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.
SUMOReal myDefaultSpeed
The default (maximum) speed on the segment.
Definition: MSCalibrator.h:250
void buildPopupHeader(GUIGLObjectPopupMenu *ret, GUIMainWindow &app, bool addSeparator=true)
Builds the header.
GUIGLObjectPopupMenu * getPopUpMenu(GUIMainWindow &app, GUISUMOAbstractView &parent)
Returns an own popup-menu.
Open the object&#39;s manipulator.
Definition: GUIAppEnum.h:231