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 }
59 #ifdef _MSC_VER
60 #pragma warning(default: 4355)
61 #endif
62 
63 
65 
66 
71  new GUIParameterTableWindow(app, *this, 21);
72  // add items
73  ret->mkItem("edge [id]", false, getEdge()->getID());
74  ret->mkItem("segment [#]", false, getSegment()->getIndex());
75  ret->mkItem("position [m]", true, new FunctionBinding<GUIMEVehicle, SUMOReal>(this, &MEVehicle::getPositionOnLane));
76  ret->mkItem("speed [m/s]", true, new FunctionBinding<GUIMEVehicle, SUMOReal>(this, &MEVehicle::getSpeed));
77  ret->mkItem("angle [degree]", true, new FunctionBinding<GUIMEVehicle, SUMOReal>(this, &GUIBaseVehicle::getNaviDegree));
78  ret->mkItem("waiting time [s]", true,
80  if (getChosenSpeedFactor() != 1) {
81  ret->mkItem("speed factor", false, getChosenSpeedFactor());
82  }
83  //ret->mkItem("time gap [s]", true,
84  // new FunctionBinding<GUIMEVehicle, SUMOReal>(this, &MSVehicle::getTimeGap));
85  //ret->mkItem("waiting time [s]", true,
86  // new FunctionBinding<GUIMEVehicle, SUMOReal>(this, &MSVehicle::getWaitingSeconds));
87  //ret->mkItem("impatience", true,
88  // new FunctionBinding<GUIMEVehicle, SUMOReal>(this, &MSVehicle::getImpatience));
89  //ret->mkItem("last lane change [s]", true,
90  // new FunctionBinding<GUIMEVehicle, SUMOReal>(this, &GUIMEVehicle::getLastLaneChangeOffset));
91  ret->mkItem("desired depart [s]", false, time2string(getParameter().depart));
92  ret->mkItem("depart delay [s]", false, time2string(getDepartDelay()));
93  if (getParameter().repetitionNumber < INT_MAX) {
94  ret->mkItem("remaining [#]", false, (int) getParameter().repetitionNumber - getParameter().repetitionsDone);
95  }
96  if (getParameter().repetitionOffset > 0) {
97  ret->mkItem("insertion period [s]", false, time2string(getParameter().repetitionOffset));
98  }
99  if (getParameter().repetitionProbability > 0) {
100  ret->mkItem("insertion probability", false, getParameter().repetitionProbability);
101  }
102  //ret->mkItem("stop info", false, getStopInfo());
103  ret->mkItem("line", false, myParameter->line);
104  //ret->mkItem("CO2 [mg/s]", true,
105  // new FunctionBinding<GUIMEVehicle, SUMOReal>(this, &GUIMEVehicle::getCO2Emissions));
106  //ret->mkItem("CO [mg/s]", true,
107  // new FunctionBinding<GUIMEVehicle, SUMOReal>(this, &GUIMEVehicle::getCOEmissions));
108  //ret->mkItem("HC [mg/s]", true,
109  // new FunctionBinding<GUIMEVehicle, SUMOReal>(this, &GUIMEVehicle::getHCEmissions));
110  //ret->mkItem("NOx [mg/s]", true,
111  // new FunctionBinding<GUIMEVehicle, SUMOReal>(this, &GUIMEVehicle::getNOxEmissions));
112  //ret->mkItem("PMx [mg/s]", true,
113  // new FunctionBinding<GUIMEVehicle, SUMOReal>(this, &GUIMEVehicle::getPMxEmissions));
114  //ret->mkItem("fuel [ml/s]", true,
115  // new FunctionBinding<GUIMEVehicle, SUMOReal>(this, &GUIMEVehicle::getFuelConsumption));
116  //ret->mkItem("noise (Harmonoise) [dB]", true,
117  // new FunctionBinding<GUIMEVehicle, SUMOReal>(this, &GUIMEVehicle::getHarmonoise_NoiseEmissions));
118  std::ostringstream str;
119  for (std::vector<MSDevice*>::const_iterator i = myDevices.begin(); i != myDevices.end(); ++i) {
120  if (i != myDevices.begin()) {
121  str << ' ';
122  }
123  str << (*i)->getID().substr(0, (*i)->getID().find(getID()));
124  }
125  ret->mkItem("devices", false, str.str());
126  //ret->mkItem("persons", true,
127  // new FunctionBinding<GUIMEVehicle, int>(this, &GUIMEVehicle::getPersonNumber));
128  //ret->mkItem("containers", true,
129  // new FunctionBinding<GUIMEVehicle, int>(this, &GUIMEVehicle::getContainerNumber));
130  ret->mkItem("parameters [key:val]", false, toString(getParameter().getMap()));
131 
132  // meso specific values
133  ret->mkItem("event time [s]", true, new FunctionBinding<GUIMEVehicle, SUMOReal>(this, &MEVehicle::getEventTimeSeconds));
135  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 bool
171 GUIMEVehicle::drawAction_drawCarriageClass(const GUIVisualizationSettings& /* s */, SUMOVehicleShape /* guiShape */, bool /* asImage */) const {
173  return true;
174 }
175 
176 
177 SUMOReal
178 GUIMEVehicle::getColorValue(int activeScheme) const {
179  switch (activeScheme) {
180  case 8:
181  return getSpeed();
182  case 9:
183  return getWaitingSeconds();
184  case 11:
185  return 0; // invalid getLastLaneChangeOffset();
186  case 12:
187  return getSegment()->getEdge().getVehicleMaxSpeed(this);
188  case 13:
189  return 0; // invalid getCO2Emissions();
190  case 14:
191  return 0; // invalid getCOEmissions();
192  case 15:
193  return 0; // invalid getPMxEmissions();
194  case 16:
195  return 0; // invalid getNOxEmissions();
196  case 17:
197  return 0; // invalid getHCEmissions();
198  case 18:
199  return 0; // invalid getFuelConsumption();
200  case 19:
201  return 0; // invalid getHarmonoise_NoiseEmissions();
202  case 20: // !!! unused!?
203  if (getNumberReroutes() == 0) {
204  return -1;
205  }
206  return getNumberReroutes();
207  case 21:
209  case 22:
210  return 0; // invalid getBestLaneOffset();
211  case 23:
212  return 0; // invalid getAcceleration();
213  case 24:
214  return 0; // invalid getTimeGap();
215  case 25:
216  return STEPS2TIME(getDepartDelay());
217  }
218  return 0;
219 }
220 
221 
222 
223 void
224 GUIMEVehicle::drawRouteHelper(const MSRoute& r, SUMOReal exaggeration) const {
225  MSRouteIterator i = r.begin();
226  for (; i != r.end(); ++i) {
227  const GUILane* lane = static_cast<GUILane*>((*i)->getLanes()[0]);
228  GLHelper::drawBoxLines(lane->getShape(), lane->getShapeRotations(), lane->getShapeLengths(), 1.0);
229  GLHelper::drawBoxLines(lane->getShape(), lane->getShapeRotations(), lane->getShapeLengths(), exaggeration);
230  }
231 }
232 
233 
234 SUMOReal
236  // @todo possibly we could compute something reasonable here
237  return 0;
238 }
239 
240 
241 std::string
243  std::string result = "";
244  if (isParking()) {
245  result += "parking";
246  } else if (isStopped()) {
247  result += "stopped";
248  } else {
249  return "";
250  }
251  return result;
252 }
253 
254 
255 void
257  // @todo possibly we could compute something reasonable here
258 }
259 /****************************************************************************/
260 
void drawAction_drawVehicleAsBoxPlus() const
const MSVehicleType * myType
This Vehicle&#39;s type.
const std::vector< SUMOReal > & getShapeRotations() const
Definition: GUILane.cpp:806
bool isParking() const
Returns whether the vehicle is parking.
Definition: MEVehicle.cpp:174
SUMOVehicleClass getVehicleClass() const
Get this vehicle type&#39;s vehicle class.
A vehicle from the mesoscopic point of view.
Definition: MEVehicle.h:52
a vehicles
SUMOReal getMaxSpeed() const
Returns the maximum speed.
Stores the information about how to visualize structures.
void drawRouteHelper(const MSRoute &r, SUMOReal exaggeration) const
Draws the route.
SUMOReal getNaviDegree() const
return the current angle in navigational degrees
SUMOReal getCurrentTLSPenaltySeconds() const
Returns the delay that is accrued due to option –meso-tls-penalty.
Definition: MEVehicle.cpp:267
SUMOReal getSpeed() const
Returns the vehicle&#39;s estimated speed assuming no delays.
Definition: MEVehicle.cpp:113
std::string time2string(SUMOTime t)
Definition: SUMOTime.cpp:59
SUMOReal getLength() const
Get vehicle&#39;s length [m].
int getNumberReroutes() const
Returns the number of new routes this vehicle got.
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:812
const SUMOVehicleParameter * myParameter
This Vehicle&#39;s parameter.
The base class for microscopic and mesoscopic vehicles.
Definition: MSBaseVehicle.h:56
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:277
GUIGlID getGlID() const
Returns the numerical id of the object.
The car-following model and parameter.
Definition: MSVehicleType.h:74
int getPersonCapacity() const
Get this vehicle type&#39;s person capacity.
SUMOReal getBlockTimeSeconds() const
Returns the time at which the vehicle was blocked on the current segment.
Definition: MEVehicle.h:287
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:230
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.
SUMOReal getLastEntryTimeSeconds() const
Returns the entry time for the current segment.
Definition: MEVehicle.h:282
~GUIMEVehicle()
destructor
ConstMSEdgeVector::const_iterator MSRouteIterator
Definition: MSRoute.h:65
#define STEPS2TIME(x)
Definition: SUMOTime.h:65
SUMOReal getColorValue(int activeScheme) const
gets the color value according to the current scheme index
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:55
std::string line
The vehicle&#39;s line (mainly for public transport)
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:271
void selectBlockingFoes() const
adds the blocking foes to the current selection
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:84
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)
#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:769
int getContainerCapacity() const
Get this vehicle type&#39;s container capacity.
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:213
MSRouteIterator begin() const
Returns the begin of the list of edges to pass.
Definition: MSRoute.cpp:78
const std::string & getID() const
Returns the name of the vehicle.
const PositionVector & getShape() const
Definition: GUILane.cpp:800