SUMO - Simulation of Urban MObility
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules 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.dlr.de/
12 // Copyright (C) 2001-2016 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 "GUICalibrator.h"
46 #include <gui/GUIGlobals.h>
53 #include <guisim/GUICalibrator.h>
55 
56 #ifdef CHECK_MEMORY_LEAKS
57 #include <foreign/nvwa/debug_new.h>
58 #endif // CHECK_MEMORY_LEAKS
59 
60 
61 // ===========================================================================
62 // FOX callback mapping
63 // ===========================================================================
64 /* -------------------------------------------------------------------------
65  * GUICalibrator::GUICalibratorPopupMenu - mapping
66  * ----------------------------------------------------------------------- */
70 
71 };
72 
73 // Object implementation
75 
76 
77 /* -------------------------------------------------------------------------
78  * GUICalibrator::GUIManip_Calibrator - mapping
79  * ----------------------------------------------------------------------- */
80 FXDEFMAP(GUICalibrator::GUIManip_Calibrator) GUIManip_CalibratorMap[] = {
87 };
88 
89 FXIMPLEMENT(GUICalibrator::GUIManip_Calibrator, GUIManipulator, GUIManip_CalibratorMap, ARRAYNUMBER(GUIManip_CalibratorMap))
90 
91 
92 // ===========================================================================
93 // method definitions
94 // ===========================================================================
95 /* -------------------------------------------------------------------------
96  * GUICalibrator::GUIManip_Calibrator - methods
97  * ----------------------------------------------------------------------- */
99  GUIMainWindow& app,
100  const std::string& name, GUICalibrator& o,
101  int /*xpos*/, int /*ypos*/) :
102  GUIManipulator(app, name, 0, 0),
103  myParent(&app),
104  myChosenValue(0),
105  myChosenTarget(myChosenValue, NULL, MID_OPTION),
106  //mySpeed(o.getDefaultSpeed()),
107  mySpeed(0),
108  mySpeedTarget(mySpeed),
109  myObject(&o) {
110  myChosenTarget.setTarget(this);
111  FXVerticalFrame* f1 =
112  new FXVerticalFrame(this, LAYOUT_FILL_X | LAYOUT_FILL_Y, 0, 0, 0, 0, 0, 0, 0, 0);
113 
114  FXGroupBox* gp = new FXGroupBox(f1, "Change Speed",
115  GROUPBOX_TITLE_LEFT | FRAME_RIDGE,
116  0, 0, 0, 0, 4, 4, 1, 1, 2, 0);
117  {
118  // default
119  FXHorizontalFrame* gf1 =
120  new FXHorizontalFrame(gp, LAYOUT_TOP | LAYOUT_LEFT, 0, 0, 0, 0, 10, 10, 5, 5);
121  new FXRadioButton(gf1, "Default", &myChosenTarget, FXDataTarget::ID_OPTION + 0,
122  ICON_BEFORE_TEXT | LAYOUT_SIDE_TOP,
123  0, 0, 0, 0, 2, 2, 0, 0);
124  }
125  {
126  // loaded
127  FXHorizontalFrame* gf0 =
128  new FXHorizontalFrame(gp, LAYOUT_TOP | LAYOUT_LEFT, 0, 0, 0, 0, 10, 10, 5, 5);
129  new FXRadioButton(gf0, "Loaded", &myChosenTarget, FXDataTarget::ID_OPTION + 1,
130  ICON_BEFORE_TEXT | LAYOUT_SIDE_TOP,
131  0, 0, 0, 0, 2, 2, 0, 0);
132  }
133  {
134  // predefined
135  FXHorizontalFrame* gf2 =
136  new FXHorizontalFrame(gp, LAYOUT_TOP | LAYOUT_LEFT, 0, 0, 0, 0, 10, 10, 5, 5);
137  new FXRadioButton(gf2, "Predefined: ", &myChosenTarget, FXDataTarget::ID_OPTION + 2,
138  ICON_BEFORE_TEXT | LAYOUT_SIDE_TOP | LAYOUT_CENTER_Y,
139  0, 0, 0, 0, 2, 2, 0, 0);
140  myPredefinedValues =
141  new FXComboBox(gf2, 10, this, MID_PRE_DEF,
142  ICON_BEFORE_TEXT | LAYOUT_SIDE_TOP | LAYOUT_CENTER_Y | COMBOBOX_STATIC);
143  myPredefinedValues->appendItem("20 km/h");
144  myPredefinedValues->appendItem("40 km/h");
145  myPredefinedValues->appendItem("60 km/h");
146  myPredefinedValues->appendItem("80 km/h");
147  myPredefinedValues->appendItem("100 km/h");
148  myPredefinedValues->appendItem("120 km/h");
149  myPredefinedValues->appendItem("140 km/h");
150  myPredefinedValues->appendItem("160 km/h");
151  myPredefinedValues->appendItem("180 km/h");
152  myPredefinedValues->appendItem("200 km/h");
153  myPredefinedValues->setNumVisible(5);
154  }
155  {
156  // free
157  FXHorizontalFrame* gf12 =
158  new FXHorizontalFrame(gp, LAYOUT_TOP | LAYOUT_LEFT, 0, 0, 0, 0, 10, 10, 5, 5);
159  new FXRadioButton(gf12, "Free Entry: ", &myChosenTarget, FXDataTarget::ID_OPTION + 3,
160  ICON_BEFORE_TEXT | LAYOUT_SIDE_TOP | LAYOUT_CENTER_Y,
161  0, 0, 0, 0, 2, 2, 0, 0);
162  myUserDefinedSpeed =
163  new FXRealSpinDial(gf12, 10, this, MID_USER_DEF,
164  LAYOUT_TOP | FRAME_SUNKEN | FRAME_THICK);
165  myUserDefinedSpeed->setFormatString("%.0f km/h");
166  myUserDefinedSpeed->setIncrements(1, 10, 10);
167  myUserDefinedSpeed->setRange(0, 300);
168  myUserDefinedSpeed->setValue(0);
169  //static_cast<GUICalibrator*>(myObject)->getDefaultSpeed() * 3.6);
170  }
171  new FXButton(f1, "Close", NULL, this, MID_CLOSE,
172  BUTTON_INITIAL | BUTTON_DEFAULT | FRAME_RAISED | FRAME_THICK | LAYOUT_TOP | LAYOUT_LEFT | LAYOUT_CENTER_X, 0, 0, 0, 0, 30, 30, 4, 4);
173  //static_cast<GUICalibrator*>(myObject)->setOverriding(true);
174 }
175 
176 
178 
179 
180 long
181 GUICalibrator::GUIManip_Calibrator::onCmdClose(FXObject*, FXSelector, void*) {
182  destroy();
183  return 1;
184 }
185 
186 
187 long
189  //mySpeed = (SUMOReal)(myUserDefinedSpeed->getValue() / 3.6);
190  //static_cast<GUICalibrator*>(myObject)->setOverridingValue(mySpeed);
191  //myParent->updateChildren();
192  return 1;
193 }
194 
195 
196 long
197 GUICalibrator::GUIManip_Calibrator::onUpdUserDef(FXObject* sender, FXSelector, void* ptr) {
198  sender->handle(this,
199  myChosenValue != 3 ? FXSEL(SEL_COMMAND, ID_DISABLE) : FXSEL(SEL_COMMAND, ID_ENABLE),
200  ptr);
201  myParent->updateChildren();
202  return 1;
203 }
204 
205 
206 long
207 GUICalibrator::GUIManip_Calibrator::onCmdPreDef(FXObject*, FXSelector, void*) {
208  //mySpeed = (SUMOReal)(SUMOReal)((myPredefinedValues->getCurrentItem() * 20 + 20) / 3.6);
209  //static_cast<GUICalibrator*>(myObject)->setOverridingValue(mySpeed);
210  //myParent->updateChildren();
211  return 1;
212 }
213 
214 
215 long
216 GUICalibrator::GUIManip_Calibrator::onUpdPreDef(FXObject* sender, FXSelector, void* ptr) {
217  sender->handle(this,
218  myChosenValue != 2 ? FXSEL(SEL_COMMAND, ID_DISABLE) : FXSEL(SEL_COMMAND, ID_ENABLE),
219  ptr);
220  myParent->updateChildren();
221  return 1;
222 }
223 
224 
225 long
227  //static_cast<GUICalibrator*>(myObject)->setOverriding(true);
228  //switch (myChosenValue) {
229  // case 0:
230  // mySpeed = (SUMOReal) static_cast<GUICalibrator*>(myObject)->getDefaultSpeed();
231  // break;
232  // case 1:
233  // mySpeed = (SUMOReal) static_cast<GUICalibrator*>(myObject)->getLoadedSpeed();
234  // break;
235  // case 2:
236  // mySpeed = (SUMOReal)((myPredefinedValues->getCurrentItem() * 20 + 20) / 3.6);
237  // break;
238  // case 3:
239  // mySpeed = (SUMOReal)(myUserDefinedSpeed->getValue() / 3.6);
240  // break;
241  // default:
242  // // hmmm, should not happen
243  // break;
244  //}
245  //static_cast<GUICalibrator*>(myObject)->setOverridingValue(mySpeed);
246  //myParent->updateChildren();
247  //if (myChosenValue == 1) {
248  // // !!! lock in between
249  // static_cast<GUICalibrator*>(myObject)->setOverriding(false);
250  //}
251  return 1;
252 }
253 
254 
255 
256 /* -------------------------------------------------------------------------
257  * GUICalibrator::GUICalibratorPopupMenu - methods
258  * ----------------------------------------------------------------------- */
260  GUIMainWindow& app, GUISUMOAbstractView& parent,
261  GUIGlObject& o)
262  : GUIGLObjectPopupMenu(app, parent, o) {}
263 
264 
266 
267 
268 long
270  FXSelector,
271  void*) {
272  static_cast<GUICalibrator*>(myObject)->openManipulator(
273  *myApplication, *myParent);
274  return 1;
275 }
276 
277 
278 /* -------------------------------------------------------------------------
279  * GUICalibrator - methods
280  * ----------------------------------------------------------------------- */
281 GUICalibrator::GUICalibrator(const std::string& id,
282  MSEdge* edge, SUMOReal pos,
283  const std::string& aXMLFilename,
284  const std::string& outputFilename,
285  const SUMOTime freq,
286  const MSRouteProbe* probe) :
287  MSCalibrator(id, edge, pos, aXMLFilename, outputFilename, freq, edge->getLength(), probe),
288  GUIGlObject_AbstractAdd("calibrator", GLO_TRIGGER, id),
289  myShowAsKMH(true) {
290  const std::vector<MSLane*>& destLanes = edge->getLanes();
291  myFGPositions.reserve(destLanes.size());
292  myFGRotations.reserve(destLanes.size());
293  for (std::vector<MSLane*>::const_iterator i = destLanes.begin(); i != destLanes.end(); ++i) {
294  const PositionVector& v = (*i)->getShape();
295  myFGPositions.push_back(v.positionAtOffset(pos));
297  myFGRotations.push_back(-v.rotationDegreeAtOffset(pos));
298  }
299 }
300 
301 
303 
304 
307  GUISUMOAbstractView& parent) {
308  GUIGLObjectPopupMenu* ret = new GUICalibratorPopupMenu(app, parent, *this);
309  buildPopupHeader(ret, app);
311  //buildShowManipulatorPopupEntry(ret);
315  buildPositionCopyEntry(ret, false);
316  return ret;
317 }
318 
319 
324  if (isActive()) {
325  ret = new GUIParameterTableWindow(app, *this, 10);
326  // add items
327  ret->mkItem("interval start", false, STEPS2TIME(myCurrentStateInterval->begin));
328  ret->mkItem("interval end", false, STEPS2TIME(myCurrentStateInterval->end));
329  ret->mkItem("aspired flow [veh/h]", false, myCurrentStateInterval->q);
330  ret->mkItem("aspired speed", false, myCurrentStateInterval->v);
331  ret->mkItem("default speed", false, myDefaultSpeed);
332  ret->mkItem("required vehicles", true, new FunctionBinding<GUICalibrator, int>(this, &GUICalibrator::totalWished));
333  ret->mkItem("passed vehicles", true, new FunctionBinding<GUICalibrator, int>(this, &GUICalibrator::passed));
334  ret->mkItem("inserted vehicles", true, new FunctionBinding<GUICalibrator, int>(this, &GUICalibrator::inserted));
335  ret->mkItem("removed vehicles", true, new FunctionBinding<GUICalibrator, int>(this, &GUICalibrator::removed));
336  ret->mkItem("cleared in jam", true, new FunctionBinding<GUICalibrator, int>(this, &GUICalibrator::clearedInJam));
337  } else {
338  ret = new GUIParameterTableWindow(app, *this, 1);
339  const std::string nextStart =
342  "simulation end");
343  ret->mkItem("inactive until", false, nextStart);
344  }
345  // close building
346  ret->closeBuilding();
347  return ret;
348 }
349 
350 
351 void
353  glPushName(getGlID());
354  std::string flow = "-";
355  std::string speed = "-";
356  if (isActive()) {
357  if (myCurrentStateInterval->v >= 0) {
358  speed = toString(myCurrentStateInterval->v) + "m/s";
359  }
360  if (myCurrentStateInterval->q >= 0) {
361  flow = toString((int)myCurrentStateInterval->q) + "v/h";
362  }
363  }
364  const SUMOReal exaggeration = s.addSize.getExaggeration(s);
365  for (int i = 0; i < (int)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(exaggeration, exaggeration, 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 * exaggeration >= 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 
SUMOReal getExaggeration(const GUIVisualizationSettings &s, SUMOReal factor=20) const
return the drawing size including exaggeration and constantSize values
int pfDrawString(const char *c)
Definition: polyfonts.c:1074
a lane speed trigger,
long long int SUMOTime
Definition: SUMOTime.h:43
Changes the speed allowed on a set of lanes (gui version)
Definition: GUICalibrator.h:53
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's lanes.
Definition: MSEdge.h:192
const std::string & getFullName() const
GUIManipulator * openManipulator(GUIMainWindow &app, GUISUMOAbstractView &parent)
int inserted() const
Definition: MSCalibrator.h:176
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:179
std::string time2string(SUMOTime t)
Definition: SUMOTime.cpp:59
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:480
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.
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.
A class that stores a 2D geometrical boundary.
Definition: Boundary.h:48
long onCmdOpenManip(FXObject *, FXSelector, void *)
Called if the object's manipulator shall be shown.
FXDEFMAP(GUICalibrator::GUIManip_Calibrator) GUIManip_CalibratorMap[]
SUMOReal scale
information about a lane'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:80
GUICalibratorPopupMenuMap[]
GUIVisualizationSizeSettings addSize
GUIGlObjectType getType() const
Returns the type of the object as coded in GUIGlObjectType.
virtual ~GUIManip_Calibrator()
Destructor.
std::vector< AspiredState >::const_iterator myCurrentStateInterval
Iterator pointing to the current interval.
Definition: MSCalibrator.h:223
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
Position positionAtOffset(SUMOReal pos, SUMOReal lateralOffset=0) const
Returns the position at the given length.
Boundary getCenteringBoundary() const
Returns the boundary to which the view shall be centered in order to show the object.
Open the object's manipulator.
Definition: GUIAppEnum.h:255
RotCont myFGRotations
The rotations in full-geometry mode.
std::vector< AspiredState > myIntervals
List of adaptation intervals.
Definition: MSCalibrator.h:221
void drawName(const Position &pos, const SUMOReal scale, const GUIVisualizationTextSettings &settings, const SUMOReal angle=0) const
draw name of item
std::string toString(const T &t, std::streamsize accuracy=OUTPUT_ACCURACY)
Definition: ToString.h:55
long onCmdClose(FXObject *, FXSelector, void *)
SUMOReal rotationDegreeAtOffset(SUMOReal pos) const
Returns the rotation at the given length.
Boundary & grow(SUMOReal by)
extends the boundary by the given amount
Definition: Boundary.cpp:232
void add(SUMOReal x, SUMOReal y, SUMOReal z=0)
Makes the boundary include the given coordinate.
Definition: Boundary.cpp:90
void pfSetScale(SUMOReal s)
Definition: polyfonts.c:465
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:1113
virtual int passed() const
Definition: MSCalibrator.h:159
Calibrates the flow on a segment to a specified one.
Definition: MSCalibrator.h:57
long onCmdUserDef(FXObject *, FXSelector, void *)
long onUpdUserDef(FXObject *, FXSelector, void *)
#define SUMOReal
Definition: config.h:214
Close simulation - ID.
Definition: GUIAppEnum.h:85
int totalWished() const
number of vehicles expected to pass this interval
Spinner control.
bool isActive() const
Definition: MSCalibrator.h:136
int clearedInJam() const
Definition: MSCalibrator.h:182
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's parameter.
SUMOReal myDefaultSpeed
The default (maximum) speed on the segment.
Definition: MSCalibrator.h:251
void buildPopupHeader(GUIGLObjectPopupMenu *ret, GUIMainWindow &app, bool addSeparator=true)
Builds the header.
GUIGLObjectPopupMenu * getPopUpMenu(GUIMainWindow &app, GUISUMOAbstractView &parent)
Returns an own popup-menu.