SUMO - Simulation of Urban MObility
GUIMEVehicle.cpp
Go to the documentation of this file.
1 /****************************************************************************/
9 // A MSVehicle extended by some values for usage within the gui
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 
24 // ===========================================================================
25 // included modules
26 // ===========================================================================
27 #ifdef _MSC_VER
28 #include <windows_config.h>
29 #else
30 #include <config.h>
31 #endif
32 
33 #include <utils/gui/div/GLHelper.h>
40 #include <guisim/GUILane.h>
41 #include "GUIMEVehicle.h"
42 
43 #ifdef CHECK_MEMORY_LEAKS
44 #include <foreign/nvwa/debug_new.h>
45 #endif // CHECK_MEMORY_LEAKS
46 
47 
48 // ===========================================================================
49 // method definitions
50 // ===========================================================================
51 #ifdef _MSC_VER
52 #pragma warning(disable: 4355)
53 #endif
55  const MSVehicleType* type, const SUMOReal speedFactor) :
56  MEVehicle(pars, route, type, speedFactor),
57  GUIBaseVehicle((MSBaseVehicle&) * this),
58  myPos(Position::INVALID) {
59 }
60 #ifdef _MSC_VER
61 #pragma warning(default: 4355)
62 #endif
63 
64 
66 
67 
72  new GUIParameterTableWindow(app, *this, 20);
73  // add items
74  ret->mkItem("edge [id]", false, getEdge()->getID());
75  ret->mkItem("segment [#]", false, getSegment()->getIndex());
76  ret->mkItem("position [m]", true, new FunctionBinding<GUIMEVehicle, SUMOReal>(this, &MEVehicle::getPositionOnLane));
77  ret->mkItem("speed [m/s]", true, new FunctionBinding<GUIMEVehicle, SUMOReal>(this, &MEVehicle::getSpeed));
78  ret->mkItem("angle [degree]", true, new FunctionBinding<GUIMEVehicle, SUMOReal>(this, &MEVehicle::getAngle));
79  ret->mkItem("waiting time [s]", true,
81  if (getChosenSpeedFactor() != 1) {
82  ret->mkItem("speed factor", false, getChosenSpeedFactor());
83  }
84  //ret->mkItem("time gap [s]", true,
85  // new FunctionBinding<GUIMEVehicle, SUMOReal>(this, &MSVehicle::getTimeGap));
86  //ret->mkItem("waiting time [s]", true,
87  // new FunctionBinding<GUIMEVehicle, SUMOReal>(this, &MSVehicle::getWaitingSeconds));
88  //ret->mkItem("impatience", true,
89  // new FunctionBinding<GUIMEVehicle, SUMOReal>(this, &MSVehicle::getImpatience));
90  //ret->mkItem("last lane change [s]", true,
91  // new FunctionBinding<GUIMEVehicle, SUMOReal>(this, &GUIMEVehicle::getLastLaneChangeOffset));
92  ret->mkItem("desired depart [s]", false, time2string(getParameter().depart));
93  ret->mkItem("depart delay [s]", false, time2string(getDepartDelay()));
94  if (getParameter().repetitionNumber < INT_MAX) {
95  ret->mkItem("remaining [#]", false, (unsigned int) getParameter().repetitionNumber - getParameter().repetitionsDone);
96  }
97  if (getParameter().repetitionOffset > 0) {
98  ret->mkItem("insertion period [s]", false, time2string(getParameter().repetitionOffset));
99  }
100  if (getParameter().repetitionProbability > 0) {
101  ret->mkItem("insertion probability", false, getParameter().repetitionProbability);
102  }
103  //ret->mkItem("stop info", false, getStopInfo());
104  ret->mkItem("line", false, myParameter->line);
105  //ret->mkItem("CO2 [mg/s]", true,
106  // new FunctionBinding<GUIMEVehicle, SUMOReal>(this, &GUIMEVehicle::getCO2Emissions));
107  //ret->mkItem("CO [mg/s]", true,
108  // new FunctionBinding<GUIMEVehicle, SUMOReal>(this, &GUIMEVehicle::getCOEmissions));
109  //ret->mkItem("HC [mg/s]", true,
110  // new FunctionBinding<GUIMEVehicle, SUMOReal>(this, &GUIMEVehicle::getHCEmissions));
111  //ret->mkItem("NOx [mg/s]", true,
112  // new FunctionBinding<GUIMEVehicle, SUMOReal>(this, &GUIMEVehicle::getNOxEmissions));
113  //ret->mkItem("PMx [mg/s]", true,
114  // new FunctionBinding<GUIMEVehicle, SUMOReal>(this, &GUIMEVehicle::getPMxEmissions));
115  //ret->mkItem("fuel [ml/s]", true,
116  // new FunctionBinding<GUIMEVehicle, SUMOReal>(this, &GUIMEVehicle::getFuelConsumption));
117  //ret->mkItem("noise (Harmonoise) [dB]", true,
118  // new FunctionBinding<GUIMEVehicle, SUMOReal>(this, &GUIMEVehicle::getHarmonoise_NoiseEmissions));
119  std::ostringstream str;
120  for (std::vector<MSDevice*>::const_iterator i = myDevices.begin(); i != myDevices.end(); ++i) {
121  if (i != myDevices.begin()) {
122  str << ' ';
123  }
124  str << (*i)->getID().substr(0, (*i)->getID().find(getID()));
125  }
126  ret->mkItem("devices", false, str.str());
127  //ret->mkItem("persons", true,
128  // new FunctionBinding<GUIMEVehicle, unsigned int>(this, &GUIMEVehicle::getPersonNumber));
129  //ret->mkItem("containers", true,
130  // new FunctionBinding<GUIMEVehicle, unsigned int>(this, &GUIMEVehicle::getContainerNumber));
131  ret->mkItem("parameters [key:val]", false, toString(getParameter().getMap()));
132 
133  // meso specific values
134  ret->mkItem("event time [s]", true, new FunctionBinding<GUIMEVehicle, SUMOReal>(this, &MEVehicle::getEventTimeSeconds));
136  ret->mkItem("block time [s]", true, new FunctionBinding<GUIMEVehicle, SUMOReal>(this, &MEVehicle::getBlockTimeSeconds));
137  // close building
138  ret->closeBuilding();
139  return ret;
140 }
141 
142 
147  new GUIParameterTableWindow(app, *this, 10);
148  // add items
149  ret->mkItem("Type Information:", false, "");
150  ret->mkItem("type [id]", false, myType->getID());
151  ret->mkItem("length", false, myType->getLength());
152  ret->mkItem("minGap", false, myType->getMinGap());
153  ret->mkItem("vehicle class", false, SumoVehicleClassStrings.getString(myType->getVehicleClass()));
154  ret->mkItem("emission class", false, PollutantsInterface::getName(myType->getEmissionClass()));
155  ret->mkItem("maximum speed [m/s]", false, getMaxSpeed());
156  //ret->mkItem("maximum acceleration [m/s^2]", false, getCarFollowModel().getMaxAccel());
157  //ret->mkItem("maximum deceleration [m/s^2]", false, getCarFollowModel().getMaxDecel());
158  //ret->mkItem("imperfection (sigma)", false, getCarFollowModel().getImperfection());
159  //ret->mkItem("reaction time (tau)", false, getCarFollowModel().getHeadwayTime());
160  ret->mkItem("person capacity", false, myType->getPersonCapacity());
161  ret->mkItem("container capacity", false, myType->getContainerCapacity());
162 
163  ret->mkItem("type parameters [key:val]", false, toString(myType->getParameter().getMap()));
164  // close building
165  ret->closeBuilding();
166  return ret;
167 }
168 
169 
170 Position
171 GUIMEVehicle::getPosition(const SUMOReal /* offset */) const {
172  if (myPos == Position::INVALID && mySegment != 0) {
173  // best guess before the actual position is set in GUIEdge::drawMesoVehicles
174  return mySegment->getEdge().getLanes().front()->geometryPositionAtOffset(getPositionOnLane() + mySegment->getLength());
175  } else {
176  return myPos;
177  }
178 }
179 
180 
181 SUMOReal
183  return myAngle;
184 }
185 
186 
187 bool
188 GUIMEVehicle::drawAction_drawCarriageClass(const GUIVisualizationSettings& /* s */, SUMOVehicleShape /* guiShape */, bool /* asImage */) const {
190  return true;
191 }
192 
193 
194 SUMOReal
195 GUIMEVehicle::getColorValue(size_t activeScheme) const {
196  switch (activeScheme) {
197  case 8:
198  return getSpeed();
199  case 9:
200  return getWaitingSeconds();
201  case 11:
202  return 0; // invalid getLastLaneChangeOffset();
203  case 12:
204  return getSegment()->getEdge().getVehicleMaxSpeed(this);
205  case 13:
206  return 0; // invalid getCO2Emissions();
207  case 14:
208  return 0; // invalid getCOEmissions();
209  case 15:
210  return 0; // invalid getPMxEmissions();
211  case 16:
212  return 0; // invalid getNOxEmissions();
213  case 17:
214  return 0; // invalid getHCEmissions();
215  case 18:
216  return 0; // invalid getFuelConsumption();
217  case 19:
218  return 0; // invalid getHarmonoise_NoiseEmissions();
219  case 20: // !!! unused!?
220  if (getNumberReroutes() == 0) {
221  return -1;
222  }
223  return getNumberReroutes();
224  case 21:
226  case 22:
227  return 0; // invalid getBestLaneOffset();
228  case 23:
229  return 0; // invalid getAcceleration();
230  case 24:
231  return 0; // invalid getTimeGap();
232  case 25:
233  return STEPS2TIME(getDepartDelay());
234  }
235  return 0;
236 }
237 
238 
239 
240 void
241 GUIMEVehicle::drawRouteHelper(const MSRoute& r, SUMOReal exaggeration) const {
242  MSRouteIterator i = r.begin();
243  for (; i != r.end(); ++i) {
244  const GUILane* lane = static_cast<GUILane*>((*i)->getLanes()[0]);
245  GLHelper::drawBoxLines(lane->getShape(), lane->getShapeRotations(), lane->getShapeLengths(), 1.0);
246  GLHelper::drawBoxLines(lane->getShape(), lane->getShapeRotations(), lane->getShapeLengths(), exaggeration);
247  }
248 }
249 
250 
251 SUMOReal
253  // @todo possibly we could compute something reasonable here
254  return 0;
255 }
256 
257 
258 std::string
260  std::string result = "";
261  if (isParking()) {
262  result += "parking";
263  } else if (isStopped()) {
264  result += "stopped";
265  } else {
266  return "";
267  }
268  return result;
269 }
270 
271 
272 void
274  // @todo possibly we could compute something reasonable here
275 }
276 /****************************************************************************/
277 
void drawAction_drawVehicleAsBoxPlus() const
const MSVehicleType * myType
This Vehicle&#39;s type.
const std::vector< SUMOReal > & getShapeRotations() const
Definition: GUILane.cpp:731
bool isParking() const
Returns whether the vehicle is parking.
Definition: MEVehicle.cpp:168
unsigned int getNumberReroutes() const
Returns the number of new routes this vehicle got.
SUMOVehicleClass getVehicleClass() const
Get this vehicle type&#39;s vehicle class.
A vehicle from the mesoscopic point of view.
Definition: MEVehicle.h:52
Position getPosition(const SUMOReal offset=0) const
Return current position (x/y, cartesian)
a vehicles
SUMOReal getMaxSpeed() const
Returns the maximum speed.
const std::vector< MSLane * > & getLanes() const
Returns this edge&#39;s lanes.
Definition: MSEdge.h:185
Position myPos
the position for drawing
Definition: GUIMEVehicle.h:147
Stores the information about how to visualize structures.
void drawRouteHelper(const MSRoute &r, SUMOReal exaggeration) const
Draws the route.
SUMOReal getSpeed() const
Returns the vehicle&#39;s estimated speed assuming no delays.
Definition: MEVehicle.cpp:107
std::string time2string(SUMOTime t)
Definition: SUMOTime.cpp:59
SUMOReal getLength() const
Get vehicle&#39;s length [m].
static void drawBoxLines(const PositionVector &geom, const std::vector< SUMOReal > &rots, const std::vector< SUMOReal > &lengths, SUMOReal width, int cornerDetail=0, SUMOReal offset=0)
Draws thick lines.
Definition: GLHelper.cpp:176
GUIParameterTableWindow * getTypeParameterWindow(GUIMainWindow &app, GUISUMOAbstractView &parent)
Returns an own type parameter window.
bool isSelected(GUIGlObjectType type, GUIGlID id)
Returns the information whether the object with the given type and id is selected.
const std::map< std::string, std::string > & getMap() const
Returns the inner key/value map.
const std::vector< SUMOReal > & getShapeLengths() const
Definition: GUILane.cpp:737
const SUMOVehicleParameter * myParameter
This Vehicle&#39;s parameter.
The base class for microscopic and mesoscopic vehicles.
Definition: MSBaseVehicle.h:52
const MSEdge & getEdge() const
Returns the edge this segment belongs to.
Definition: MESegment.h:272
SUMOReal getEventTimeSeconds() const
Returns the earliest leave time for the current segment.
Definition: MEVehicle.h:271
GUIGlID getGlID() const
Returns the numerical id of the object.
Definition: GUIGlObject.h:123
The car-following model and parameter.
Definition: MSVehicleType.h:74
SUMOReal getBlockTimeSeconds() const
Returns the time at which the vehicle was blocked on the current segment.
Definition: MEVehicle.h:281
Representation of a lane in the micro simulation (gui-version)
Definition: GUILane.h:70
GUIParameterTableWindow * getParameterWindow(GUIMainWindow &app, GUISUMOAbstractView &parent)
Returns an own parameter window.
bool isStopped() const
Returns whether the vehicle is at a stop.
Definition: MEVehicle.cpp:224
const SUMOVTypeParameter & getParameter() const
SUMOReal getMinGap() const
Get the free space in front of vehicles of this class.
SUMOTime getDepartDelay() const
Returns the depart delay.
A point in 2D or 3D with translation and scaling methods.
Definition: Position.h:46
SUMOReal getLastEntryTimeSeconds() const
Returns the entry time for the current segment.
Definition: MEVehicle.h:276
~GUIMEVehicle()
destructor
SUMOReal getLength() const
Returns the length of the segment in meters.
Definition: MESegment.h:166
ConstMSEdgeVector::const_iterator MSRouteIterator
Definition: MSRoute.h:65
#define STEPS2TIME(x)
Definition: SUMOTime.h:65
SUMOReal myAngle
the angle for drawing
Definition: GUIMEVehicle.h:150
A MSVehicle extended by some values for usage within the gui.
static std::string getName(const SUMOEmissionClass c)
Checks whether the string describes a known vehicle class.
StringBijection< SUMOVehicleClass > SumoVehicleClassStrings(sumoVehicleClassStringInitializer, SVC_CUSTOM2, false)
std::string toString(const T &t, std::streamsize accuracy=OUTPUT_ACCURACY)
Definition: ToString.h:54
unsigned int getPersonCapacity() const
Get this vehicle type&#39;s person capacity.
SUMOReal getAngle() const
Returns the vehicle&#39;s direction in degrees.
std::string line
The vehicle&#39;s line (mainly for public transport)
MESegment * mySegment
The segment the vehicle is at.
Definition: MEVehicle.h:317
bool drawAction_drawCarriageClass(const GUIVisualizationSettings &s, SUMOVehicleShape guiShape, bool asImage) const
draws the given guiShape if it has distinc carriages/modules and eturns true if so ...
std::string getStopInfo() const
retrieve information about the current stop state
SUMOReal getLastLaneChangeOffset() const
Returns the time since the last lane change in seconds.
Structure representing possible vehicle parameter.
MSRouteIterator end() const
Returns the end of the list of edges to pass.
Definition: MSRoute.cpp:84
SUMOVehicleShape
Definition of vehicle classes to differ between different appearences.
SUMOReal getWaitingSeconds() const
Returns the number of seconds waited (speed was lesser than 0.1m/s)
Definition: MEVehicle.h:265
void selectBlockingFoes() const
adds the blocking foes to the current selection
SUMOReal getColorValue(size_t activeScheme) const
gets the color value according to the current scheme index
SUMOReal getChosenSpeedFactor() const
Returns the precomputed factor by which the driver wants to be faster than the speed limit...
SUMOReal getPositionOnLane() const
Get the vehicle&#39;s position along the lane.
Definition: MEVehicle.cpp:78
const std::string & getID() const
Returns the name of the vehicle type.
const SUMOVehicleParameter & getParameter() const
Returns the vehicle&#39;s parameter (including departure definition)
unsigned int getContainerCapacity() const
Get this vehicle type&#39;s container capacity.
#define SUMOReal
Definition: config.h:213
SUMOReal getVehicleMaxSpeed(const SUMOVehicle *const veh) const
Returns the maximum speed the vehicle may use on this edge.
Definition: MSEdge.cpp:681
const MSEdge * getEdge() const
Returns the edge the vehicle is currently at.
SUMOEmissionClass getEmissionClass() const
Get this vehicle type&#39;s emission class.
GUIMEVehicle(SUMOVehicleParameter *pars, const MSRoute *route, const MSVehicleType *type, const SUMOReal speedFactor)
Constructor.
void mkItem(const char *name, bool dynamic, ValueSource< unsigned > *src)
Adds a row which obtains its value from an unsigned-ValueSource.
GUISelectedStorage gSelected
A global holder of selected objects.
void closeBuilding()
Closes the building of the table.
std::vector< MSDevice * > myDevices
The devices this vehicle has.
A window containing a gl-object&#39;s parameter.
MESegment * getSegment() const
Returns the current segment the vehicle is on.
Definition: MEVehicle.h:207
SUMOReal getAngle() const
Returns the vehicle&#39;s direction in degrees.
Definition: MEVehicle.cpp:86
MSRouteIterator begin() const
Returns the begin of the list of edges to pass.
Definition: MSRoute.cpp:78
static const Position INVALID
Definition: Position.h:261
const std::string & getID() const
Returns the name of the vehicle.
const PositionVector & getShape() const
Definition: GUILane.cpp:725