SUMO - Simulation of Urban MObility
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-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 "GUICalibrator.h"
46 #include <gui/GUIGlobals.h>
53 #include <guisim/GUICalibrator.h>
55 
56 
57 // ===========================================================================
58 // FOX callback mapping
59 // ===========================================================================
60 /* -------------------------------------------------------------------------
61  * GUICalibrator::GUICalibratorPopupMenu - mapping
62  * ----------------------------------------------------------------------- */
66 
67 };
68 
69 // Object implementation
71 
72 
73 /* -------------------------------------------------------------------------
74  * GUICalibrator::GUIManip_Calibrator - mapping
75  * ----------------------------------------------------------------------- */
76 FXDEFMAP(GUICalibrator::GUIManip_Calibrator) GUIManip_CalibratorMap[] = {
83 };
84 
85 FXIMPLEMENT(GUICalibrator::GUIManip_Calibrator, GUIManipulator, GUIManip_CalibratorMap, ARRAYNUMBER(GUIManip_CalibratorMap))
86 
87 
88 // ===========================================================================
89 // method definitions
90 // ===========================================================================
91 /* -------------------------------------------------------------------------
92  * GUICalibrator::GUIManip_Calibrator - methods
93  * ----------------------------------------------------------------------- */
95  GUIMainWindow& app,
96  const std::string& name, GUICalibrator& o,
97  int /*xpos*/, int /*ypos*/) :
98  GUIManipulator(app, name, 0, 0),
99  myParent(&app),
100  myChosenValue(0),
101  myChosenTarget(myChosenValue, NULL, MID_OPTION),
102  //mySpeed(o.getDefaultSpeed()),
103  mySpeed(0),
104  mySpeedTarget(mySpeed),
105  myObject(&o) {
106  myChosenTarget.setTarget(this);
107  FXVerticalFrame* f1 =
108  new FXVerticalFrame(this, LAYOUT_FILL_X | LAYOUT_FILL_Y, 0, 0, 0, 0, 0, 0, 0, 0);
109 
110  FXGroupBox* gp = new FXGroupBox(f1, "Change Speed",
111  GROUPBOX_TITLE_LEFT | FRAME_RIDGE,
112  0, 0, 0, 0, 4, 4, 1, 1, 2, 0);
113  {
114  // default
115  FXHorizontalFrame* gf1 =
116  new FXHorizontalFrame(gp, LAYOUT_TOP | LAYOUT_LEFT, 0, 0, 0, 0, 10, 10, 5, 5);
117  new FXRadioButton(gf1, "Default", &myChosenTarget, FXDataTarget::ID_OPTION + 0,
118  ICON_BEFORE_TEXT | LAYOUT_SIDE_TOP,
119  0, 0, 0, 0, 2, 2, 0, 0);
120  }
121  {
122  // loaded
123  FXHorizontalFrame* gf0 =
124  new FXHorizontalFrame(gp, LAYOUT_TOP | LAYOUT_LEFT, 0, 0, 0, 0, 10, 10, 5, 5);
125  new FXRadioButton(gf0, "Loaded", &myChosenTarget, FXDataTarget::ID_OPTION + 1,
126  ICON_BEFORE_TEXT | LAYOUT_SIDE_TOP,
127  0, 0, 0, 0, 2, 2, 0, 0);
128  }
129  {
130  // predefined
131  FXHorizontalFrame* gf2 =
132  new FXHorizontalFrame(gp, LAYOUT_TOP | LAYOUT_LEFT, 0, 0, 0, 0, 10, 10, 5, 5);
133  new FXRadioButton(gf2, "Predefined: ", &myChosenTarget, FXDataTarget::ID_OPTION + 2,
134  ICON_BEFORE_TEXT | LAYOUT_SIDE_TOP | LAYOUT_CENTER_Y,
135  0, 0, 0, 0, 2, 2, 0, 0);
136  myPredefinedValues =
137  new FXComboBox(gf2, 10, this, MID_PRE_DEF,
138  ICON_BEFORE_TEXT | LAYOUT_SIDE_TOP | LAYOUT_CENTER_Y | COMBOBOX_STATIC);
139  myPredefinedValues->appendItem("20 km/h");
140  myPredefinedValues->appendItem("40 km/h");
141  myPredefinedValues->appendItem("60 km/h");
142  myPredefinedValues->appendItem("80 km/h");
143  myPredefinedValues->appendItem("100 km/h");
144  myPredefinedValues->appendItem("120 km/h");
145  myPredefinedValues->appendItem("140 km/h");
146  myPredefinedValues->appendItem("160 km/h");
147  myPredefinedValues->appendItem("180 km/h");
148  myPredefinedValues->appendItem("200 km/h");
149  myPredefinedValues->setNumVisible(5);
150  }
151  {
152  // free
153  FXHorizontalFrame* gf12 =
154  new FXHorizontalFrame(gp, LAYOUT_TOP | LAYOUT_LEFT, 0, 0, 0, 0, 10, 10, 5, 5);
155  new FXRadioButton(gf12, "Free Entry: ", &myChosenTarget, FXDataTarget::ID_OPTION + 3,
156  ICON_BEFORE_TEXT | LAYOUT_SIDE_TOP | LAYOUT_CENTER_Y,
157  0, 0, 0, 0, 2, 2, 0, 0);
158  myUserDefinedSpeed =
159  new FXRealSpinDial(gf12, 10, this, MID_USER_DEF,
160  LAYOUT_TOP | FRAME_SUNKEN | FRAME_THICK);
161  myUserDefinedSpeed->setFormatString("%.0f km/h");
162  myUserDefinedSpeed->setIncrements(1, 10, 10);
163  myUserDefinedSpeed->setRange(0, 300);
164  myUserDefinedSpeed->setValue(0);
165  //static_cast<GUICalibrator*>(myObject)->getDefaultSpeed() * 3.6);
166  }
167  new FXButton(f1, "Close", NULL, this, MID_CLOSE,
168  BUTTON_INITIAL | BUTTON_DEFAULT | FRAME_RAISED | FRAME_THICK | LAYOUT_TOP | LAYOUT_LEFT | LAYOUT_CENTER_X, 0, 0, 0, 0, 30, 30, 4, 4);
169  //static_cast<GUICalibrator*>(myObject)->setOverriding(true);
170 }
171 
172 
174 
175 
176 long
177 GUICalibrator::GUIManip_Calibrator::onCmdClose(FXObject*, FXSelector, void*) {
178  destroy();
179  return 1;
180 }
181 
182 
183 long
185  //mySpeed = (double)(myUserDefinedSpeed->getValue() / 3.6);
186  //static_cast<GUICalibrator*>(myObject)->setOverridingValue(mySpeed);
187  //myParent->updateChildren();
188  return 1;
189 }
190 
191 
192 long
193 GUICalibrator::GUIManip_Calibrator::onUpdUserDef(FXObject* sender, FXSelector, void* ptr) {
194  sender->handle(this,
195  myChosenValue != 3 ? FXSEL(SEL_COMMAND, ID_DISABLE) : FXSEL(SEL_COMMAND, ID_ENABLE),
196  ptr);
198  return 1;
199 }
200 
201 
202 long
203 GUICalibrator::GUIManip_Calibrator::onCmdPreDef(FXObject*, FXSelector, void*) {
204  //mySpeed = (double)(double)((myPredefinedValues->getCurrentItem() * 20 + 20) / 3.6);
205  //static_cast<GUICalibrator*>(myObject)->setOverridingValue(mySpeed);
206  //myParent->updateChildren();
207  return 1;
208 }
209 
210 
211 long
212 GUICalibrator::GUIManip_Calibrator::onUpdPreDef(FXObject* sender, FXSelector, void* ptr) {
213  sender->handle(this,
214  myChosenValue != 2 ? FXSEL(SEL_COMMAND, ID_DISABLE) : FXSEL(SEL_COMMAND, ID_ENABLE),
215  ptr);
217  return 1;
218 }
219 
220 
221 long
223  //static_cast<GUICalibrator*>(myObject)->setOverriding(true);
224  //switch (myChosenValue) {
225  // case 0:
226  // mySpeed = (double) static_cast<GUICalibrator*>(myObject)->getDefaultSpeed();
227  // break;
228  // case 1:
229  // mySpeed = (double) static_cast<GUICalibrator*>(myObject)->getLoadedSpeed();
230  // break;
231  // case 2:
232  // mySpeed = (double)((myPredefinedValues->getCurrentItem() * 20 + 20) / 3.6);
233  // break;
234  // case 3:
235  // mySpeed = (double)(myUserDefinedSpeed->getValue() / 3.6);
236  // break;
237  // default:
238  // // hmmm, should not happen
239  // break;
240  //}
241  //static_cast<GUICalibrator*>(myObject)->setOverridingValue(mySpeed);
242  //myParent->updateChildren();
243  //if (myChosenValue == 1) {
244  // // !!! lock in between
245  // static_cast<GUICalibrator*>(myObject)->setOverriding(false);
246  //}
247  return 1;
248 }
249 
250 
251 
252 /* -------------------------------------------------------------------------
253  * GUICalibrator::GUICalibratorPopupMenu - methods
254  * ----------------------------------------------------------------------- */
256  GUIMainWindow& app, GUISUMOAbstractView& parent,
257  GUIGlObject& o)
258  : GUIGLObjectPopupMenu(app, parent, o) {}
259 
260 
262 
263 
264 long
266  FXSelector,
267  void*) {
268  static_cast<GUICalibrator*>(myObject)->openManipulator(
270  return 1;
271 }
272 
273 
274 /* -------------------------------------------------------------------------
275  * GUICalibrator - methods
276  * ----------------------------------------------------------------------- */
277 GUICalibrator::GUICalibrator(const std::string& id,
278  MSEdge* edge, double pos,
279  const std::string& aXMLFilename,
280  const std::string& outputFilename,
281  const SUMOTime freq,
282  const MSRouteProbe* probe) :
283  MSCalibrator(id, edge, pos, aXMLFilename, outputFilename, freq, edge->getLength(), probe),
284  GUIGlObject_AbstractAdd("calibrator", GLO_TRIGGER, id),
285  myShowAsKMH(true) {
286  const std::vector<MSLane*>& destLanes = edge->getLanes();
287  myFGPositions.reserve(destLanes.size());
288  myFGRotations.reserve(destLanes.size());
289  for (std::vector<MSLane*>::const_iterator i = destLanes.begin(); i != destLanes.end(); ++i) {
290  const PositionVector& v = (*i)->getShape();
291  myFGPositions.push_back(v.positionAtOffset(pos));
293  myFGRotations.push_back(-v.rotationDegreeAtOffset(pos));
294  }
295 }
296 
297 
299 
300 
303  GUISUMOAbstractView& parent) {
304  GUIGLObjectPopupMenu* ret = new GUICalibratorPopupMenu(app, parent, *this);
305  buildPopupHeader(ret, app);
307  //buildShowManipulatorPopupEntry(ret);
311  buildPositionCopyEntry(ret, false);
312  return ret;
313 }
314 
315 
320  if (isActive()) {
321  ret = new GUIParameterTableWindow(app, *this, 10);
322  // add items
323  ret->mkItem("interval start", false, STEPS2TIME(myCurrentStateInterval->begin));
324  ret->mkItem("interval end", false, STEPS2TIME(myCurrentStateInterval->end));
325  ret->mkItem("aspired flow [veh/h]", false, myCurrentStateInterval->q);
326  ret->mkItem("aspired speed", false, myCurrentStateInterval->v);
327  ret->mkItem("default speed", false, myDefaultSpeed);
328  ret->mkItem("required vehicles", true, new FunctionBinding<GUICalibrator, int>(this, &GUICalibrator::totalWished));
329  ret->mkItem("passed vehicles", true, new FunctionBinding<GUICalibrator, int>(this, &GUICalibrator::passed));
330  ret->mkItem("inserted vehicles", true, new FunctionBinding<GUICalibrator, int>(this, &GUICalibrator::inserted));
331  ret->mkItem("removed vehicles", true, new FunctionBinding<GUICalibrator, int>(this, &GUICalibrator::removed));
332  ret->mkItem("cleared in jam", true, new FunctionBinding<GUICalibrator, int>(this, &GUICalibrator::clearedInJam));
333  } else {
334  ret = new GUIParameterTableWindow(app, *this, 1);
335  const std::string nextStart =
338  "simulation end");
339  ret->mkItem("inactive until", false, nextStart);
340  }
341  // close building
342  ret->closeBuilding();
343  return ret;
344 }
345 
346 
347 void
349  glPushName(getGlID());
350  std::string flow = "-";
351  std::string speed = "-";
352  if (isActive()) {
353  if (myCurrentStateInterval->v >= 0) {
354  speed = toString(myCurrentStateInterval->v) + "m/s";
355  }
356  if (myCurrentStateInterval->q >= 0) {
357  flow = toString((int)myCurrentStateInterval->q) + "v/h";
358  }
359  }
360  const double exaggeration = s.addSize.getExaggeration(s);
361  for (int i = 0; i < (int)myFGPositions.size(); ++i) {
362  const Position& pos = myFGPositions[i];
363  double rot = myFGRotations[i];
364  glPushMatrix();
365  glTranslated(pos.x(), pos.y(), getType());
366  glRotated(rot, 0, 0, 1);
367  glTranslated(0, 0, getType());
368  glScaled(exaggeration, exaggeration, 1);
369  glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
370 
371  glBegin(GL_TRIANGLES);
372  glColor3d(1, .8f, 0);
373  // base
374  glVertex2d(0 - 1.4, 0);
375  glVertex2d(0 - 1.4, 6);
376  glVertex2d(0 + 1.4, 6);
377  glVertex2d(0 + 1.4, 0);
378  glVertex2d(0 - 1.4, 0);
379  glVertex2d(0 + 1.4, 6);
380  glEnd();
381 
382  // draw text
383  if (s.scale * exaggeration >= 1.) {
384  glTranslated(0, 0, .1);
385  glColor3d(0, 0, 0);
386  pfSetPosition(0, 0);
387  pfSetScale(3.f);
388  double w = pfdkGetStringWidth("C");
389  glRotated(180, 0, 1, 0);
390  glTranslated(-w / 2., 2, 0);
391  pfDrawString("C");
392  glTranslated(w / 2., -2, 0);
393 
394 
395  pfSetPosition(0, 0);
396  pfSetScale(.7f);
397  w = pfdkGetStringWidth(flow.c_str());
398  glTranslated(-w / 2., 4, 0);
399  pfDrawString(flow.c_str());
400  glTranslated(w / 2., -4, 0);
401 
402  pfSetPosition(0, 0);
403  pfSetScale(.7f);
404  w = pfdkGetStringWidth(speed.c_str());
405  glTranslated(-w / 2., 5, 0);
406  pfDrawString(speed.c_str());
407  glTranslated(-w / 2., -5, 0);
408  }
409  glPopMatrix();
410  }
411  drawName(getCenteringBoundary().getCenter(), s.scale, s.addName);
412  glPopName();
413 }
414 
415 
416 Boundary
418  Boundary b(myBoundary);
419  b.grow(20);
420  return b;
421 }
422 
423 
427  GUIManip_Calibrator* gui =
428  new GUIManip_Calibrator(app, getFullName(), *this, 0, 0);
429  gui->create();
430  gui->show();
431  return gui;
432 }
433 
434 
435 
436 /****************************************************************************/
437 
int pfDrawString(const char *c)
Definition: polyfonts.c:1074
void drawName(const Position &pos, const double scale, const GUIVisualizationTextSettings &settings, const double angle=0) const
draw name of item
a lane speed trigger,
double scale
information about a lane&#39;s width (temporary, used for a single view)
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.
void pfSetScale(double s)
Definition: polyfonts.c:465
const std::vector< MSLane * > & getLanes() const
Returns this edge&#39;s lanes.
Definition: MSEdge.h:192
const std::string & getFullName() const
GUIManipulator * openManipulator(GUIMainWindow &app, GUISUMOAbstractView &parent)
int inserted() const
Definition: MSCalibrator.h:176
double x() const
Returns the x-position.
Definition: Position.h:63
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:60
void buildCenterPopupEntry(GUIGLObjectPopupMenu *ret, bool addSeparator=true)
Builds an entry which allows to center to the object.
GUISUMOAbstractView * myParent
The parent window.
void pfSetPosition(double x, double y)
Definition: polyfonts.c:480
void buildShowParamsPopupEntry(GUIGLObjectPopupMenu *ret, bool addSeparator=true)
Builds an entry which allows to open the parameter window.
long onCmdChangeOption(FXObject *, FXSelector, void *)
Close simulation - ID.
Definition: GUIAppEnum.h:85
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&#39;s manipulator shall be shown.
FXDEFMAP(GUICalibrator::GUIManip_Calibrator) GUIManip_CalibratorMap[]
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.
double getExaggeration(const GUIVisualizationSettings &s, double factor=20) const
return the drawing size including exaggeration and constantSize values
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
Definition: ToString.h:56
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.
double rotationDegreeAtOffset(double pos) const
Returns the rotation at the given length.
long onCmdPreDef(FXObject *, FXSelector, void *)
double y() const
Returns the y-position.
Definition: Position.h:68
#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.
double myDefaultSpeed
The default (maximum) speed on the segment.
Definition: MSCalibrator.h:251
RotCont myFGRotations
The rotations in full-geometry mode.
Boundary & grow(double by)
extends the boundary by the given amount
Definition: Boundary.cpp:234
std::vector< AspiredState > myIntervals
List of adaptation intervals.
Definition: MSCalibrator.h:221
GUICalibrator(const std::string &id, MSEdge *edge, double pos, const std::string &aXMLFilename, const std::string &outputFilename, const SUMOTime freq, const MSRouteProbe *probe)
Constructor.
long onCmdClose(FXObject *, FXSelector, void *)
double pfdkGetStringWidth(const char *c)
Definition: polyfonts.c:1113
Position positionAtOffset(double pos, double lateralOffset=0) const
Returns the position at the given length.
bool myShowAsKMH
The information whether the speed shall be shown in m/s or km/h.
PosCont myFGPositions
The positions in full-geometry mode.
The popup menu of a globject.
void buildSelectionPopupEntry(GUIGLObjectPopupMenu *ret, bool addSeparator=true)
Builds an entry which allows to (de)select the object.
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 *)
GUIMainWindow * myApplication
The main application.
long long int SUMOTime
Definition: TraCIDefs.h:52
int totalWished() const
number of vehicles expected to pass this interval
Open the object&#39;s manipulator.
Definition: GUIAppEnum.h:257
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.
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&#39;s parameter.
void buildPopupHeader(GUIGLObjectPopupMenu *ret, GUIMainWindow &app, bool addSeparator=true)
Builds the header.
GUIGLObjectPopupMenu * getPopUpMenu(GUIMainWindow &app, GUISUMOAbstractView &parent)
Returns an own popup-menu.