SUMO - Simulation of Urban MObility
GUICalibrator.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-2017 German Aerospace Center (DLR) and others.
4 /****************************************************************************/
5 //
6 // This program and the accompanying materials
7 // are made available under the terms of the Eclipse Public License v2.0
8 // which accompanies this distribution, and is available at
9 // http://www.eclipse.org/legal/epl-v20.html
10 //
11 /****************************************************************************/
19 // Changes flow and speed on a set of lanes (gui version)
20 /****************************************************************************/
21 // ===========================================================================
22 // included modules
23 // ===========================================================================
24 #ifdef _MSC_VER
25 #include <windows_config.h>
26 #else
27 #include <config.h>
28 #endif
29 
30 #include <string>
33 #include <utils/geom/Boundary.h>
34 #include <utils/gui/div/GLHelper.h>
35 #include <utils/common/ToString.h>
36 #include <utils/common/Command.h>
37 #include <microsim/MSNet.h>
38 #include <microsim/MSLane.h>
39 #include <microsim/MSEdge.h>
40 #include <guisim/GUINet.h>
41 #include <guisim/GUIEdge.h>
44 #include <gui/GUIGlobals.h>
50 #include <guisim/GUICalibrator.h>
52 
53 #include "GUICalibrator.h"
54 
55 
56 // ===========================================================================
57 // FOX callback mapping
58 // ===========================================================================
59 /* -------------------------------------------------------------------------
60  * GUICalibrator::GUICalibratorPopupMenu - mapping
61  * ----------------------------------------------------------------------- */
65 
66 };
67 
68 // Object implementation
70 
71 
72 /* -------------------------------------------------------------------------
73  * GUICalibrator::GUIManip_Calibrator - mapping
74  * ----------------------------------------------------------------------- */
75 FXDEFMAP(GUICalibrator::GUIManip_Calibrator) GUIManip_CalibratorMap[] = {
82 };
83 
84 FXIMPLEMENT(GUICalibrator::GUIManip_Calibrator, GUIManipulator, GUIManip_CalibratorMap, ARRAYNUMBER(GUIManip_CalibratorMap))
85 
86 
87 // ===========================================================================
88 // method definitions
89 // ===========================================================================
90 /* -------------------------------------------------------------------------
91  * GUICalibrator::GUIManip_Calibrator - methods
92  * ----------------------------------------------------------------------- */
94  GUIMainWindow& app,
95  const std::string& name, GUICalibrator& o,
96  int /*xpos*/, int /*ypos*/) :
97  GUIManipulator(app, name, 0, 0),
98  myParent(&app),
99  myChosenValue(0),
100  myChosenTarget(myChosenValue, NULL, MID_OPTION),
101  //mySpeed(o.getDefaultSpeed()),
102  mySpeed(0),
103  mySpeedTarget(mySpeed),
104  myObject(&o) {
105  myChosenTarget.setTarget(this);
106  FXVerticalFrame* f1 =
107  new FXVerticalFrame(this, LAYOUT_FILL_X | LAYOUT_FILL_Y, 0, 0, 0, 0, 0, 0, 0, 0);
108 
109  FXGroupBox* gp = new FXGroupBox(f1, "Change Speed",
110  GROUPBOX_TITLE_LEFT | FRAME_RIDGE,
111  0, 0, 0, 0, 4, 4, 1, 1, 2, 0);
112  {
113  // default
114  FXHorizontalFrame* gf1 =
115  new FXHorizontalFrame(gp, LAYOUT_TOP | LAYOUT_LEFT, 0, 0, 0, 0, 10, 10, 5, 5);
116  new FXRadioButton(gf1, "Default", &myChosenTarget, FXDataTarget::ID_OPTION + 0,
117  ICON_BEFORE_TEXT | LAYOUT_SIDE_TOP,
118  0, 0, 0, 0, 2, 2, 0, 0);
119  }
120  {
121  // loaded
122  FXHorizontalFrame* gf0 =
123  new FXHorizontalFrame(gp, LAYOUT_TOP | LAYOUT_LEFT, 0, 0, 0, 0, 10, 10, 5, 5);
124  new FXRadioButton(gf0, "Loaded", &myChosenTarget, FXDataTarget::ID_OPTION + 1,
125  ICON_BEFORE_TEXT | LAYOUT_SIDE_TOP,
126  0, 0, 0, 0, 2, 2, 0, 0);
127  }
128  {
129  // predefined
130  FXHorizontalFrame* gf2 =
131  new FXHorizontalFrame(gp, LAYOUT_TOP | LAYOUT_LEFT, 0, 0, 0, 0, 10, 10, 5, 5);
132  new FXRadioButton(gf2, "Predefined: ", &myChosenTarget, FXDataTarget::ID_OPTION + 2,
133  ICON_BEFORE_TEXT | LAYOUT_SIDE_TOP | LAYOUT_CENTER_Y,
134  0, 0, 0, 0, 2, 2, 0, 0);
135  myPredefinedValues =
136  new FXComboBox(gf2, 10, this, MID_PRE_DEF,
137  ICON_BEFORE_TEXT | LAYOUT_SIDE_TOP | LAYOUT_CENTER_Y | COMBOBOX_STATIC);
138  myPredefinedValues->appendItem("20 km/h");
139  myPredefinedValues->appendItem("40 km/h");
140  myPredefinedValues->appendItem("60 km/h");
141  myPredefinedValues->appendItem("80 km/h");
142  myPredefinedValues->appendItem("100 km/h");
143  myPredefinedValues->appendItem("120 km/h");
144  myPredefinedValues->appendItem("140 km/h");
145  myPredefinedValues->appendItem("160 km/h");
146  myPredefinedValues->appendItem("180 km/h");
147  myPredefinedValues->appendItem("200 km/h");
148  myPredefinedValues->setNumVisible(5);
149  }
150  {
151  // free
152  FXHorizontalFrame* gf12 =
153  new FXHorizontalFrame(gp, LAYOUT_TOP | LAYOUT_LEFT, 0, 0, 0, 0, 10, 10, 5, 5);
154  new FXRadioButton(gf12, "Free Entry: ", &myChosenTarget, FXDataTarget::ID_OPTION + 3,
155  ICON_BEFORE_TEXT | LAYOUT_SIDE_TOP | LAYOUT_CENTER_Y,
156  0, 0, 0, 0, 2, 2, 0, 0);
157  myUserDefinedSpeed =
158  new FXRealSpinDial(gf12, 10, this, MID_USER_DEF,
159  LAYOUT_TOP | FRAME_SUNKEN | FRAME_THICK);
160  myUserDefinedSpeed->setFormatString("%.0f km/h");
161  myUserDefinedSpeed->setIncrements(1, 10, 10);
162  myUserDefinedSpeed->setRange(0, 300);
163  myUserDefinedSpeed->setValue(0);
164  //static_cast<GUICalibrator*>(myObject)->getDefaultSpeed() * 3.6);
165  }
166  new FXButton(f1, "Close", NULL, this, MID_CLOSE,
167  BUTTON_INITIAL | BUTTON_DEFAULT | FRAME_RAISED | FRAME_THICK | LAYOUT_TOP | LAYOUT_LEFT | LAYOUT_CENTER_X, 0, 0, 0, 0, 30, 30, 4, 4);
168  //static_cast<GUICalibrator*>(myObject)->setOverriding(true);
169 }
170 
171 
173 
174 
175 long
176 GUICalibrator::GUIManip_Calibrator::onCmdClose(FXObject*, FXSelector, void*) {
177  destroy();
178  return 1;
179 }
180 
181 
182 long
184  //mySpeed = (double)(myUserDefinedSpeed->getValue() / 3.6);
185  //static_cast<GUICalibrator*>(myObject)->setOverridingValue(mySpeed);
186  //myParent->updateChildren();
187  return 1;
188 }
189 
190 
191 long
192 GUICalibrator::GUIManip_Calibrator::onUpdUserDef(FXObject* sender, FXSelector, void* ptr) {
193  sender->handle(this,
194  myChosenValue != 3 ? FXSEL(SEL_COMMAND, ID_DISABLE) : FXSEL(SEL_COMMAND, ID_ENABLE),
195  ptr);
197  return 1;
198 }
199 
200 
201 long
202 GUICalibrator::GUIManip_Calibrator::onCmdPreDef(FXObject*, FXSelector, void*) {
203  //mySpeed = (double)(double)((myPredefinedValues->getCurrentItem() * 20 + 20) / 3.6);
204  //static_cast<GUICalibrator*>(myObject)->setOverridingValue(mySpeed);
205  //myParent->updateChildren();
206  return 1;
207 }
208 
209 
210 long
211 GUICalibrator::GUIManip_Calibrator::onUpdPreDef(FXObject* sender, FXSelector, void* ptr) {
212  sender->handle(this,
213  myChosenValue != 2 ? FXSEL(SEL_COMMAND, ID_DISABLE) : FXSEL(SEL_COMMAND, ID_ENABLE),
214  ptr);
216  return 1;
217 }
218 
219 
220 long
222  //static_cast<GUICalibrator*>(myObject)->setOverriding(true);
223  //switch (myChosenValue) {
224  // case 0:
225  // mySpeed = (double) static_cast<GUICalibrator*>(myObject)->getDefaultSpeed();
226  // break;
227  // case 1:
228  // mySpeed = (double) static_cast<GUICalibrator*>(myObject)->getLoadedSpeed();
229  // break;
230  // case 2:
231  // mySpeed = (double)((myPredefinedValues->getCurrentItem() * 20 + 20) / 3.6);
232  // break;
233  // case 3:
234  // mySpeed = (double)(myUserDefinedSpeed->getValue() / 3.6);
235  // break;
236  // default:
237  // // hmmm, should not happen
238  // break;
239  //}
240  //static_cast<GUICalibrator*>(myObject)->setOverridingValue(mySpeed);
241  //myParent->updateChildren();
242  //if (myChosenValue == 1) {
243  // // !!! lock in between
244  // static_cast<GUICalibrator*>(myObject)->setOverriding(false);
245  //}
246  return 1;
247 }
248 
249 
250 
251 /* -------------------------------------------------------------------------
252  * GUICalibrator::GUICalibratorPopupMenu - methods
253  * ----------------------------------------------------------------------- */
255  GUIMainWindow& app, GUISUMOAbstractView& parent,
256  GUIGlObject& o)
257  : GUIGLObjectPopupMenu(app, parent, o) {}
258 
259 
261 
262 
263 long
265  FXSelector,
266  void*) {
267  static_cast<GUICalibrator*>(myObject)->openManipulator(
269  return 1;
270 }
271 
272 
273 /* -------------------------------------------------------------------------
274  * GUICalibrator - methods
275  * ----------------------------------------------------------------------- */
276 GUICalibrator::GUICalibrator(const std::string& id,
277  MSEdge* edge,
278  MSLane* lane,
279  double pos,
280  const std::string& aXMLFilename,
281  const std::string& outputFilename,
282  const SUMOTime freq,
283  const MSRouteProbe* probe) :
284  MSCalibrator(id, edge, lane, pos, aXMLFilename, outputFilename, freq, edge->getLength(), probe),
285  GUIGlObject_AbstractAdd("calibrator", GLO_TRIGGER, id),
286  myShowAsKMH(true) {
287  const std::vector<MSLane*>& destLanes = edge->getLanes();
288  for (std::vector<MSLane*>::const_iterator i = destLanes.begin(); i != destLanes.end(); ++i) {
289  if (lane == 0 || (*i) == lane) {
290  const PositionVector& v = (*i)->getShape();
291  myFGPositions.push_back(v.positionAtOffset(pos));
293  myFGRotations.push_back(-v.rotationDegreeAtOffset(pos));
294  }
295  }
296 }
297 
298 
300 
301 
304  GUISUMOAbstractView& parent) {
305  GUIGLObjectPopupMenu* ret = new GUICalibratorPopupMenu(app, parent, *this);
306  buildPopupHeader(ret, app);
308  //buildShowManipulatorPopupEntry(ret);
312  buildPositionCopyEntry(ret, false);
313  return ret;
314 }
315 
316 
321  if (isActive()) {
322  ret = new GUIParameterTableWindow(app, *this, 12);
323  // add items
324  ret->mkItem("interval start", false, STEPS2TIME(myCurrentStateInterval->begin));
325  ret->mkItem("interval end", false, STEPS2TIME(myCurrentStateInterval->end));
326  ret->mkItem("aspired flow [veh/h]", false, myCurrentStateInterval->q);
327  ret->mkItem("aspired speed", false, myCurrentStateInterval->v);
328  ret->mkItem("current flow [veh/h]", true, new FunctionBinding<GUICalibrator, double>(this, &GUICalibrator::currentFlow));
329  ret->mkItem("current speed", true, new FunctionBinding<GUICalibrator, double>(this, &GUICalibrator::currentSpeed));
330  ret->mkItem("default speed", false, myDefaultSpeed);
331  ret->mkItem("required vehicles", true, new FunctionBinding<GUICalibrator, int>(this, &GUICalibrator::totalWished));
332  ret->mkItem("passed vehicles", true, new FunctionBinding<GUICalibrator, int>(this, &GUICalibrator::passed));
333  ret->mkItem("inserted vehicles", true, new FunctionBinding<GUICalibrator, int>(this, &GUICalibrator::inserted));
334  ret->mkItem("removed vehicles", true, new FunctionBinding<GUICalibrator, int>(this, &GUICalibrator::removed));
335  ret->mkItem("cleared in jam", true, new FunctionBinding<GUICalibrator, int>(this, &GUICalibrator::clearedInJam));
336  } else {
337  ret = new GUIParameterTableWindow(app, *this, 1);
338  const std::string nextStart =
341  "simulation end");
342  ret->mkItem("inactive until", false, nextStart);
343  }
344  // close building
345  ret->closeBuilding();
346  return ret;
347 }
348 
349 
350 void
352  glPushName(getGlID());
353  std::string flow = "-";
354  std::string speed = "-";
355  if (isActive()) {
356  if (myCurrentStateInterval->v >= 0) {
357  speed = toString(myCurrentStateInterval->v) + "m/s";
358  }
359  if (myCurrentStateInterval->q >= 0) {
360  flow = toString((int)myCurrentStateInterval->q) + "v/h";
361  }
362  }
363  const double exaggeration = s.addSize.getExaggeration(s);
364  for (int i = 0; i < (int)myFGPositions.size(); ++i) {
365  const Position& pos = myFGPositions[i];
366  double rot = myFGRotations[i];
367  glPushMatrix();
368  glTranslated(pos.x(), pos.y(), getType());
369  glRotated(rot, 0, 0, 1);
370  glTranslated(0, 0, getType());
371  glScaled(exaggeration, exaggeration, 1);
372  glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
373 
374  glBegin(GL_TRIANGLES);
375  glColor3d(1, .8f, 0);
376  // base
377  glVertex2d(0 - 1.4, 0);
378  glVertex2d(0 - 1.4, 6);
379  glVertex2d(0 + 1.4, 6);
380  glVertex2d(0 + 1.4, 0);
381  glVertex2d(0 - 1.4, 0);
382  glVertex2d(0 + 1.4, 6);
383  glEnd();
384 
385  // draw text
386  if (s.scale * exaggeration >= 1.) {
387  glTranslated(0, 0, .1);
388  GLHelper::drawText("C", Position(0, 2), 0.1, 3, RGBColor::BLACK, 180);
389  GLHelper::drawText(flow, Position(0, 4), 0.1, 0.7, RGBColor::BLACK, 180);
390  GLHelper::drawText(speed, Position(0, 5), 0.1, 0.7, RGBColor::BLACK, 180);
391  }
392  glPopMatrix();
393  }
394  drawName(getCenteringBoundary().getCenter(), s.scale, s.addName);
395  glPopName();
396 }
397 
398 
399 Boundary
401  Boundary b(myBoundary);
402  b.grow(20);
403  return b;
404 }
405 
406 
410  GUIManip_Calibrator* gui =
411  new GUIManip_Calibrator(app, getFullName(), *this, 0, 0);
412  gui->create();
413  gui->show();
414  return gui;
415 }
416 
417 
418 
419 /****************************************************************************/
420 
double rotationDegreeAtOffset(double pos) const
Returns the rotation at the given length.
a lane speed trigger,
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.
Changes the speed allowed on a set of lanes (gui version)
Definition: GUICalibrator.h:52
GUIVisualizationTextSettings addName
void buildNameCopyPopupEntry(GUIGLObjectPopupMenu *ret, bool addSeparator=true)
Builds entries which allow to copy the name / typed name into the clipboard.
GUIManipulator * openManipulator(GUIMainWindow &app, GUISUMOAbstractView &parent)
virtual int passed() const
Definition: MSCalibrator.h:175
Writes routes of vehicles passing a certain edge.
Definition: MSRouteProbe.h:67
Stores the information about how to visualize structures.
double y() const
Returns the y-position.
Definition: Position.h:67
std::string time2string(SUMOTime t)
Definition: SUMOTime.cpp:59
double x() const
Returns the x-position.
Definition: Position.h:62
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:487
const std::vector< MSLane * > & getLanes() const
Returns this edge&#39;s lanes.
Definition: MSEdge.h:167
GUISUMOAbstractView * myParent
The parent window.
static const RGBColor BLACK
Definition: RGBColor.h:186
void buildShowParamsPopupEntry(GUIGLObjectPopupMenu *ret, bool addSeparator=true)
Builds an entry which allows to open the parameter window.
long onCmdChangeOption(FXObject *, FXSelector, void *)
double currentSpeed() const
measured speed in the current interval
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 *)
A class that stores a 2D geometrical boundary.
Definition: Boundary.h:47
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.
void drawGL(const GUIVisualizationSettings &s) const
Draws the object.
Boundary getCenteringBoundary() const
Returns the boundary to which the view shall be centered in order to show the object.
int totalWished() const
number of vehicles expected to pass this interval
A road/street connecting two junctions.
Definition: MSEdge.h:80
GUICalibratorPopupMenuMap[]
GUIVisualizationSizeSettings addSize
virtual ~GUIManip_Calibrator()
Destructor.
GUIGlObjectType getType() const
Returns the type of the object as coded in GUIGlObjectType.
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
Definition: ToString.h:55
std::vector< AspiredState >::const_iterator myCurrentStateInterval
Iterator pointing to the current interval.
Definition: MSCalibrator.h:247
Boundary myBoundary
The boundary of this rerouter.
A point in 2D or 3D with translation and scaling methods.
Definition: Position.h:45
A list of positions.
long onCmdPreDef(FXObject *, FXSelector, void *)
#define STEPS2TIME(x)
Definition: SUMOTime.h:64
double myDefaultSpeed
The default (maximum) speed on the segment.
Definition: MSCalibrator.h:275
void drawName(const Position &pos, const double scale, const GUIVisualizationTextSettings &settings, const double angle=0) const
draw name of item
RotCont myFGRotations
The rotations in full-geometry mode.
Boundary & grow(double by)
extends the boundary by the given amount
Definition: Boundary.cpp:301
bool isActive() const
Definition: MSCalibrator.h:152
std::vector< AspiredState > myIntervals
List of adaptation intervals.
Definition: MSCalibrator.h:245
long onCmdClose(FXObject *, FXSelector, void *)
Open the object&#39;s manipulator.
Definition: GUIAppEnum.h:254
bool myShowAsKMH
The information whether the speed shall be shown in m/s or km/h.
PosCont myFGPositions
The positions in full-geometry mode.
GUICalibrator(const std::string &id, MSEdge *edge, MSLane *lane, double pos, const std::string &aXMLFilename, const std::string &outputFilename, const SUMOTime freq, const MSRouteProbe *probe)
Constructor.
The popup menu of a globject.
void buildSelectionPopupEntry(GUIGLObjectPopupMenu *ret, bool addSeparator=true)
Builds an entry which allows to (de)select the object.
int clearedInJam() const
Definition: MSCalibrator.h:204
Close simulation - ID.
Definition: GUIAppEnum.h:84
GUIGlID getGlID() const
Returns the numerical id of the object.
Calibrates the flow on a segment to a specified one.
Definition: MSCalibrator.h:56
double getExaggeration(const GUIVisualizationSettings &s, double factor=20) const
return the drawing size including exaggeration and constantSize values
long onCmdUserDef(FXObject *, FXSelector, void *)
long onUpdUserDef(FXObject *, FXSelector, void *)
GUIMainWindow * myApplication
The main application.
long long int SUMOTime
Definition: TraCIDefs.h:51
const std::string & getFullName() const
void add(double x, double y, double z=0)
Makes the boundary include the given coordinate.
Definition: Boundary.cpp:85
int removed() const
Definition: MSCalibrator.h:201
GUIGlObject * myObject
The object that belongs to this popup-menu.
Spinner control.
void mkItem(const char *name, bool dynamic, ValueSource< unsigned > *src)
Adds a row which obtains its value from an unsigned-ValueSource.
Position positionAtOffset(double pos, double lateralOffset=0) const
Returns the position at the given length.
Representation of a lane in the micro simulation.
Definition: MSLane.h:77
A window containing a gl-object&#39;s parameter.
double currentFlow() const
flow in the current interval in veh/h
void buildPopupHeader(GUIGLObjectPopupMenu *ret, GUIMainWindow &app, bool addSeparator=true)
Builds the header.
GUIGLObjectPopupMenu * getPopUpMenu(GUIMainWindow &app, GUISUMOAbstractView &parent)
Returns an own popup-menu.
int inserted() const
Definition: MSCalibrator.h:198