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-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 
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 
44 // ===========================================================================
45 // method definitions
46 // ===========================================================================
47 #ifdef _MSC_VER
48 #pragma warning(push)
49 #pragma warning(disable: 4355)
50 #endif
52  const MSVehicleType* type, const double speedFactor) :
53  MEVehicle(pars, route, type, speedFactor),
54  GUIBaseVehicle((MSBaseVehicle&) * this) {
55 }
56 #ifdef _MSC_VER
57 #pragma warning(pop)
58 #endif
59 
60 
62 
63 
68  new GUIParameterTableWindow(app, *this, 21);
69  // add items
70  ret->mkItem("edge [id]", false, getEdge()->getID());
71  ret->mkItem("segment [#]", false, getSegment()->getIndex());
72  ret->mkItem("position [m]", true, new FunctionBinding<GUIMEVehicle, double>(this, &MEVehicle::getPositionOnLane));
73  ret->mkItem("speed [m/s]", true, new FunctionBinding<GUIMEVehicle, double>(this, &MEVehicle::getSpeed));
74  ret->mkItem("angle [degree]", true, new FunctionBinding<GUIMEVehicle, double>(this, &GUIBaseVehicle::getNaviDegree));
75  ret->mkItem("waiting time [s]", true,
77  if (getChosenSpeedFactor() != 1) {
78  ret->mkItem("speed factor", false, getChosenSpeedFactor());
79  }
80  //ret->mkItem("time gap [s]", true,
81  // new FunctionBinding<GUIMEVehicle, double>(this, &MSVehicle::getTimeGap));
82  //ret->mkItem("waiting time [s]", true,
83  // new FunctionBinding<GUIMEVehicle, double>(this, &MSVehicle::getWaitingSeconds));
84  //ret->mkItem("impatience", true,
85  // new FunctionBinding<GUIMEVehicle, double>(this, &MSVehicle::getImpatience));
86  //ret->mkItem("last lane change [s]", true,
87  // new FunctionBinding<GUIMEVehicle, double>(this, &GUIMEVehicle::getLastLaneChangeOffset));
88  ret->mkItem("desired depart [s]", false, time2string(getParameter().depart));
89  ret->mkItem("depart delay [s]", false, time2string(getDepartDelay()));
90  if (getParameter().repetitionNumber < INT_MAX) {
91  ret->mkItem("remaining [#]", false, (int) getParameter().repetitionNumber - getParameter().repetitionsDone);
92  }
93  if (getParameter().repetitionOffset > 0) {
94  ret->mkItem("insertion period [s]", false, time2string(getParameter().repetitionOffset));
95  }
96  if (getParameter().repetitionProbability > 0) {
97  ret->mkItem("insertion probability", false, getParameter().repetitionProbability);
98  }
99  //ret->mkItem("stop info", false, getStopInfo());
100  ret->mkItem("line", false, myParameter->line);
101  //ret->mkItem("CO2 [mg/s]", true,
102  // new FunctionBinding<GUIMEVehicle, double>(this, &GUIMEVehicle::getCO2Emissions));
103  //ret->mkItem("CO [mg/s]", true,
104  // new FunctionBinding<GUIMEVehicle, double>(this, &GUIMEVehicle::getCOEmissions));
105  //ret->mkItem("HC [mg/s]", true,
106  // new FunctionBinding<GUIMEVehicle, double>(this, &GUIMEVehicle::getHCEmissions));
107  //ret->mkItem("NOx [mg/s]", true,
108  // new FunctionBinding<GUIMEVehicle, double>(this, &GUIMEVehicle::getNOxEmissions));
109  //ret->mkItem("PMx [mg/s]", true,
110  // new FunctionBinding<GUIMEVehicle, double>(this, &GUIMEVehicle::getPMxEmissions));
111  //ret->mkItem("fuel [ml/s]", true,
112  // new FunctionBinding<GUIMEVehicle, double>(this, &GUIMEVehicle::getFuelConsumption));
113  //ret->mkItem("noise (Harmonoise) [dB]", true,
114  // new FunctionBinding<GUIMEVehicle, double>(this, &GUIMEVehicle::getHarmonoise_NoiseEmissions));
115  std::ostringstream str;
116  for (std::vector<MSDevice*>::const_iterator i = myDevices.begin(); i != myDevices.end(); ++i) {
117  if (i != myDevices.begin()) {
118  str << ' ';
119  }
120  str << (*i)->getID().substr(0, (*i)->getID().find(getID()));
121  }
122  ret->mkItem("devices", false, str.str());
123  //ret->mkItem("persons", true,
124  // new FunctionBinding<GUIMEVehicle, int>(this, &GUIMEVehicle::getPersonNumber));
125  //ret->mkItem("containers", true,
126  // new FunctionBinding<GUIMEVehicle, int>(this, &GUIMEVehicle::getContainerNumber));
127  ret->mkItem("parameters [key:val]", false, toString(getParameter().getMap()));
128 
129  // meso specific values
130  ret->mkItem("event time [s]", true, new FunctionBinding<GUIMEVehicle, double>(this, &MEVehicle::getEventTimeSeconds));
131  ret->mkItem("entry time [s]", true, new FunctionBinding<GUIMEVehicle, double>(this, &MEVehicle::getLastEntryTimeSeconds));
132  ret->mkItem("block time [s]", true, new FunctionBinding<GUIMEVehicle, double>(this, &MEVehicle::getBlockTimeSeconds));
134  // close building
135  ret->closeBuilding();
136  return ret;
137 }
138 
139 
144  new GUIParameterTableWindow(app, *this, 10);
145  // add items
146  ret->mkItem("Type Information:", false, "");
147  ret->mkItem("type [id]", false, myType->getID());
148  ret->mkItem("length", false, myType->getLength());
149  ret->mkItem("minGap", false, myType->getMinGap());
150  ret->mkItem("vehicle class", false, SumoVehicleClassStrings.getString(myType->getVehicleClass()));
151  ret->mkItem("emission class", false, PollutantsInterface::getName(myType->getEmissionClass()));
152  ret->mkItem("maximum speed [m/s]", false, getMaxSpeed());
153  //ret->mkItem("maximum acceleration [m/s^2]", false, getCarFollowModel().getMaxAccel());
154  //ret->mkItem("maximum deceleration [m/s^2]", false, getCarFollowModel().getMaxDecel());
155  //ret->mkItem("imperfection (sigma)", false, getCarFollowModel().getImperfection());
156  //ret->mkItem("reaction time (tau)", false, getCarFollowModel().getHeadwayTime());
157  ret->mkItem("person capacity", false, myType->getPersonCapacity());
158  ret->mkItem("container capacity", false, myType->getContainerCapacity());
159 
160  ret->mkItem("type parameters [key:val]", false, toString(myType->getParameter().getMap()));
161  // close building
162  ret->closeBuilding();
163  return ret;
164 }
165 
166 
167 bool
168 GUIMEVehicle::drawAction_drawCarriageClass(const GUIVisualizationSettings& /* s */, SUMOVehicleShape /* guiShape */, bool /* asImage */) const {
170  return true;
171 }
172 
173 
174 double
175 GUIMEVehicle::getColorValue(int activeScheme) const {
176  switch (activeScheme) {
177  case 8:
178  return getSpeed();
179  case 9:
180  return getWaitingSeconds();
181  case 11:
182  return 0; // invalid getLastLaneChangeOffset();
183  case 12:
184  return getSegment()->getEdge().getVehicleMaxSpeed(this);
185  case 13:
186  return 0; // invalid getCO2Emissions();
187  case 14:
188  return 0; // invalid getCOEmissions();
189  case 15:
190  return 0; // invalid getPMxEmissions();
191  case 16:
192  return 0; // invalid getNOxEmissions();
193  case 17:
194  return 0; // invalid getHCEmissions();
195  case 18:
196  return 0; // invalid getFuelConsumption();
197  case 19:
198  return 0; // invalid getHarmonoise_NoiseEmissions();
199  case 20: // !!! unused!?
200  if (getNumberReroutes() == 0) {
201  return -1;
202  }
203  return getNumberReroutes();
204  case 21:
206  case 22:
207  return 0; // invalid getBestLaneOffset();
208  case 23:
209  return 0; // invalid getAcceleration();
210  case 24:
211  return 0; // invalid getTimeGapOnLane();
212  case 25:
213  return STEPS2TIME(getDepartDelay());
214  }
215  return 0;
216 }
217 
218 
219 
220 void
221 GUIMEVehicle::drawRouteHelper(const MSRoute& r, double exaggeration) const {
222  MSRouteIterator i = r.begin();
223  for (; i != r.end(); ++i) {
224  const GUILane* lane = static_cast<GUILane*>((*i)->getLanes()[0]);
225  GLHelper::drawBoxLines(lane->getShape(), lane->getShapeRotations(), lane->getShapeLengths(), 1.0);
226  GLHelper::drawBoxLines(lane->getShape(), lane->getShapeRotations(), lane->getShapeLengths(), exaggeration);
227  }
228 }
229 
230 
231 double
233  // @todo possibly we could compute something reasonable here
234  return 0;
235 }
236 
237 
238 std::string
240  std::string result = "";
241  if (isParking()) {
242  result += "parking";
243  } else if (isStopped()) {
244  result += "stopped";
245  } else {
246  return "";
247  }
248  return result;
249 }
250 
251 
252 void
254  // @todo possibly we could compute something reasonable here
255 }
256 /****************************************************************************/
257 
double getBlockTimeSeconds() const
Returns the time at which the vehicle was blocked on the current segment.
Definition: MEVehicle.h:299
const MSVehicleType * myType
This Vehicle&#39;s type.
A vehicle from the mesoscopic point of view.
Definition: MEVehicle.h:52
std::string getStopInfo() const
retrieve information about the current stop state
static void drawBoxLines(const PositionVector &geom, const std::vector< double > &rots, const std::vector< double > &lengths, double width, int cornerDetail=0, double offset=0)
Draws thick lines.
Definition: GLHelper.cpp:172
a vehicles
void drawAction_drawVehicleAsBoxPlus() const
Stores the information about how to visualize structures.
const SUMOVehicleParameter & getParameter() const
Returns the vehicle&#39;s parameter (including departure definition)
std::string time2string(SUMOTime t)
Definition: SUMOTime.cpp:60
GUIParameterTableWindow * getTypeParameterWindow(GUIMainWindow &app, GUISUMOAbstractView &parent)
Returns an own type parameter window.
SUMOTime getDepartDelay() const
Returns the depart delay.
bool isSelected(GUIGlObjectType type, GUIGlID id)
Returns the information whether the object with the given type and id is selected.
const SUMOVehicleParameter * myParameter
This Vehicle&#39;s parameter.
The base class for microscopic and mesoscopic vehicles.
Definition: MSBaseVehicle.h:56
double getEventTimeSeconds() const
Returns the earliest leave time for the current segment.
Definition: MEVehicle.h:289
const std::vector< double > & getShapeRotations() const
Definition: GUILane.cpp:794
int getPersonCapacity() const
Get this vehicle type&#39;s person capacity.
double getNaviDegree() const
return the current angle in navigational degrees
int getNumberReroutes() const
Returns the number of new routes this vehicle got.
int getContainerCapacity() const
Get this vehicle type&#39;s container capacity.
The car-following model and parameter.
Definition: MSVehicleType.h:74
Representation of a lane in the micro simulation (gui-version)
Definition: GUILane.h:70
double getChosenSpeedFactor() const
Returns the precomputed factor by which the driver wants to be faster than the speed limit...
double getMaxSpeed() const
Returns the maximum speed.
GUIParameterTableWindow * getParameterWindow(GUIMainWindow &app, GUISUMOAbstractView &parent)
Returns an own parameter window.
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
Definition: ToString.h:56
GUIMEVehicle(SUMOVehicleParameter *pars, const MSRoute *route, const MSVehicleType *type, const double speedFactor)
Constructor.
MESegment * getSegment() const
Returns the current segment the vehicle is on.
Definition: MEVehicle.h:225
const MSEdge * getEdge() const
Returns the edge the vehicle is currently at.
~GUIMEVehicle()
destructor
ConstMSEdgeVector::const_iterator MSRouteIterator
Definition: MSRoute.h:65
bool isStopped() const
Returns whether the vehicle is at a stop.
Definition: MEVehicle.cpp:228
#define STEPS2TIME(x)
Definition: SUMOTime.h:65
void selectBlockingFoes() const
adds the blocking foes to the current selection
double 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.
const PositionVector & getShape() const
Definition: GUILane.cpp:788
double getMinGap() const
Get the free space in front of vehicles of this class.
static std::string getName(const SUMOEmissionClass c)
Checks whether the string describes a known vehicle class.
StringBijection< SUMOVehicleClass > SumoVehicleClassStrings(sumoVehicleClassStringInitializer, SVC_CUSTOM2, false)
const SUMOVTypeParameter & getParameter() const
std::string line
The vehicle&#39;s line (mainly for public transport)
double getVehicleMaxSpeed(const SUMOVehicle *const veh) const
Returns the maximum speed the vehicle may use on this edge.
Definition: MSEdge.cpp:836
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 ...
Structure representing possible vehicle parameter.
SUMOVehicleShape
Definition of vehicle classes to differ between different appearences.
double getLastEntryTimeSeconds() const
Returns the entry time for the current segment.
Definition: MEVehicle.h:294
const std::map< std::string, std::string > & getMap() const
Returns the inner key/value map.
const std::vector< double > & getShapeLengths() const
Definition: GUILane.cpp:800
const std::string & getID() const
Returns the name of the vehicle type.
double getLength() const
Get vehicle&#39;s length [m].
bool isParking() const
Returns whether the vehicle is parking.
Definition: MEVehicle.cpp:170
GUIGlID getGlID() const
Returns the numerical id of the object.
double getLastLaneChangeOffset() const
Returns the time since the last lane change in seconds.
double getPositionOnLane() const
Get the vehicle&#39;s position along the lane.
Definition: MEVehicle.cpp:80
double getCurrentLinkPenaltySeconds() const
Returns the delay that is accrued due to option –meso-tls-penalty or –meso-minor-penalty.
Definition: MEVehicle.cpp:265
MSRouteIterator begin() const
Returns the begin of the list of edges to pass.
Definition: MSRoute.cpp:74
double getSpeed() const
Returns the vehicle&#39;s estimated speed assuming no delays.
Definition: MEVehicle.cpp:109
const std::string & getID() const
Returns the name of the vehicle.
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.
const MSEdge & getEdge() const
Returns the edge this segment belongs to.
Definition: MESegment.h:271
std::vector< MSDevice * > myDevices
The devices this vehicle has.
A window containing a gl-object&#39;s parameter.
SUMOEmissionClass getEmissionClass() const
Get this vehicle type&#39;s emission class.
MSRouteIterator end() const
Returns the end of the list of edges to pass.
Definition: MSRoute.cpp:80
void drawRouteHelper(const MSRoute &r, double exaggeration) const
Draws the route.
SUMOVehicleClass getVehicleClass() const
Get this vehicle type&#39;s vehicle class.
double getWaitingSeconds() const
Returns the number of seconds waited (speed was lesser than 0.1m/s)
Definition: MEVehicle.h:283