SUMO - Simulation of Urban MObility
GUIMEVehicle.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-2018 German Aerospace Center (DLR) and others.
4 // This program and the accompanying materials
5 // are made available under the terms of the Eclipse Public License v2.0
6 // which accompanies this distribution, and is available at
7 // http://www.eclipse.org/legal/epl-v20.html
8 // SPDX-License-Identifier: EPL-2.0
9 /****************************************************************************/
17 // A MSVehicle extended by some values for usage within the gui
18 /****************************************************************************/
19 
20 
21 // ===========================================================================
22 // included modules
23 // ===========================================================================
24 #include <config.h>
25 
27 #include <utils/gui/div/GLHelper.h>
35 #include <guisim/GUILane.h>
36 #include "GUIMEVehicle.h"
37 
38 
39 // ===========================================================================
40 // method definitions
41 // ===========================================================================
42 #ifdef _MSC_VER
43 #pragma warning(push)
44 #pragma warning(disable: 4355)
45 #endif
47  MSVehicleType* type, const double speedFactor) :
48  MEVehicle(pars, route, type, speedFactor),
49  GUIBaseVehicle((MSBaseVehicle&) * this) {
50 }
51 #ifdef _MSC_VER
52 #pragma warning(pop)
53 #endif
54 
55 
57 
58 
63  new GUIParameterTableWindow(app, *this, 21 + (int)getParameter().getParametersMap().size());
64  // add items
65  ret->mkItem("edge [id]", false, getEdge()->getID());
66  ret->mkItem("segment [#]", false, getSegment()->getIndex());
67  ret->mkItem("position [m]", true, new FunctionBinding<GUIMEVehicle, double>(this, &MEVehicle::getPositionOnLane));
68  ret->mkItem("speed [m/s]", true, new FunctionBinding<GUIMEVehicle, double>(this, &MEVehicle::getSpeed));
69  ret->mkItem("angle [degree]", true, new FunctionBinding<GUIMEVehicle, double>(this, &GUIBaseVehicle::getNaviDegree));
70  ret->mkItem("waiting time [s]", true,
72  ret->mkItem("speed factor", false, getChosenSpeedFactor());
73  //ret->mkItem("time gap [s]", true,
74  // new FunctionBinding<GUIMEVehicle, double>(this, &MSVehicle::getTimeGap));
75  //ret->mkItem("waiting time [s]", true,
76  // new FunctionBinding<GUIMEVehicle, double>(this, &MSVehicle::getWaitingSeconds));
77  //ret->mkItem("impatience", true,
78  // new FunctionBinding<GUIMEVehicle, double>(this, &MSVehicle::getImpatience));
79  //ret->mkItem("last lane change [s]", true,
80  // new FunctionBinding<GUIMEVehicle, double>(this, &GUIMEVehicle::getLastLaneChangeOffset));
81  ret->mkItem("desired depart [s]", false, time2string(getParameter().depart));
82  ret->mkItem("depart delay [s]", false, time2string(getDepartDelay()));
83  if (getParameter().repetitionNumber < std::numeric_limits<int>::max()) {
84  ret->mkItem("remaining [#]", false, (int) getParameter().repetitionNumber - getParameter().repetitionsDone);
85  }
86  if (getParameter().repetitionOffset > 0) {
87  ret->mkItem("insertion period [s]", false, time2string(getParameter().repetitionOffset));
88  }
89  if (getParameter().repetitionProbability > 0) {
90  ret->mkItem("insertion probability", false, getParameter().repetitionProbability);
91  }
92  //ret->mkItem("stop info", false, getStopInfo());
93  ret->mkItem("line", false, myParameter->line);
94  //ret->mkItem("CO2 [mg/s]", true,
95  // new FunctionBinding<GUIMEVehicle, double>(this, &GUIMEVehicle::getCO2Emissions));
96  //ret->mkItem("CO [mg/s]", true,
97  // new FunctionBinding<GUIMEVehicle, double>(this, &GUIMEVehicle::getCOEmissions));
98  //ret->mkItem("HC [mg/s]", true,
99  // new FunctionBinding<GUIMEVehicle, double>(this, &GUIMEVehicle::getHCEmissions));
100  //ret->mkItem("NOx [mg/s]", true,
101  // new FunctionBinding<GUIMEVehicle, double>(this, &GUIMEVehicle::getNOxEmissions));
102  //ret->mkItem("PMx [mg/s]", true,
103  // new FunctionBinding<GUIMEVehicle, double>(this, &GUIMEVehicle::getPMxEmissions));
104  //ret->mkItem("fuel [ml/s]", true,
105  // new FunctionBinding<GUIMEVehicle, double>(this, &GUIMEVehicle::getFuelConsumption));
106  //ret->mkItem("noise (Harmonoise) [dB]", true,
107  // new FunctionBinding<GUIMEVehicle, double>(this, &GUIMEVehicle::getHarmonoise_NoiseEmissions));
108  ret->mkItem("devices", false, toString(myDevices));
109  //ret->mkItem("persons", true,
110  // new FunctionBinding<GUIMEVehicle, int>(this, &GUIMEVehicle::getPersonNumber));
111  //ret->mkItem("containers", true,
112  // new FunctionBinding<GUIMEVehicle, int>(this, &GUIMEVehicle::getContainerNumber));
113  // meso specific values
114  ret->mkItem("event time [s]", true, new FunctionBinding<GUIMEVehicle, double>(this, &MEVehicle::getEventTimeSeconds));
115  ret->mkItem("entry time [s]", true, new FunctionBinding<GUIMEVehicle, double>(this, &MEVehicle::getLastEntryTimeSeconds));
116  ret->mkItem("block time [s]", true, new FunctionBinding<GUIMEVehicle, double>(this, &MEVehicle::getBlockTimeSeconds));
119  // close building
120  ret->closeBuilding(&getParameter());
121  return ret;
122 }
123 
124 
129  new GUIParameterTableWindow(app, *this, 9 + (int)myType->getParameter().getParametersMap().size());
130  // add items
131  ret->mkItem("Type Information:", false, "");
132  ret->mkItem("type [id]", false, myType->getID());
133  ret->mkItem("length", false, myType->getLength());
134  ret->mkItem("minGap", false, myType->getMinGap());
135  ret->mkItem("vehicle class", false, SumoVehicleClassStrings.getString(myType->getVehicleClass()));
136  ret->mkItem("emission class", false, PollutantsInterface::getName(myType->getEmissionClass()));
137  ret->mkItem("maximum speed [m/s]", false, getMaxSpeed());
138  //ret->mkItem("maximum acceleration [m/s^2]", false, getCarFollowModel().getMaxAccel());
139  //ret->mkItem("maximum deceleration [m/s^2]", false, getCarFollowModel().getMaxDecel());
140  //ret->mkItem("imperfection (sigma)", false, getCarFollowModel().getImperfection());
141  //ret->mkItem("desired headway (tau)", false, getCarFollowModel().getHeadwayTime());
142  ret->mkItem("person capacity", false, myType->getPersonCapacity());
143  ret->mkItem("container capacity", false, myType->getContainerCapacity());
144  // close building
145  ret->closeBuilding(&(myType->getParameter()));
146  return ret;
147 }
148 
149 
150 bool
151 GUIMEVehicle::drawAction_drawCarriageClass(const GUIVisualizationSettings& /* s */, SUMOVehicleShape /* guiShape */, bool /* asImage */) const {
152  // undo scaling from GUIBaseVehicle::drawAction_drawVehicleAsPoly
153  glPopMatrix();
155  glPushMatrix();
156  return true;
157 }
158 
159 
160 double
161 GUIMEVehicle::getColorValue(int activeScheme) const {
162  switch (activeScheme) {
163  case 8:
164  return getSpeed();
165  case 9:
166  return getWaitingSeconds();
167  case 11:
168  return 0; // invalid getLastLaneChangeOffset();
169  case 12:
170  return getSegment()->getEdge().getVehicleMaxSpeed(this);
171  case 13:
172  return 0; // invalid getCO2Emissions();
173  case 14:
174  return 0; // invalid getCOEmissions();
175  case 15:
176  return 0; // invalid getPMxEmissions();
177  case 16:
178  return 0; // invalid getNOxEmissions();
179  case 17:
180  return 0; // invalid getHCEmissions();
181  case 18:
182  return 0; // invalid getFuelConsumption();
183  case 19:
184  return 0; // invalid getHarmonoise_NoiseEmissions();
185  case 20: // !!! unused!?
186  if (getNumberReroutes() == 0) {
187  return -1;
188  }
189  return getNumberReroutes();
190  case 21:
192  case 22:
193  return 0; // invalid getBestLaneOffset();
194  case 23:
195  return 0; // invalid getAcceleration();
196  case 24:
197  return 0; // invalid getTimeGapOnLane();
198  case 25:
199  return STEPS2TIME(getDepartDelay());
200  }
201  return 0;
202 }
203 
204 
205 
206 void
208  const double exaggeration = s.vehicleSize.getExaggeration(s, this);
209  MSRouteIterator i = r.begin();
210  for (; i != r.end(); ++i) {
211  const GUILane* lane = static_cast<GUILane*>((*i)->getLanes()[0]);
212  GLHelper::drawBoxLines(lane->getShape(), lane->getShapeRotations(), lane->getShapeLengths(), 1.0);
213  GLHelper::drawBoxLines(lane->getShape(), lane->getShapeRotations(), lane->getShapeLengths(), exaggeration);
214  }
215 }
216 
217 
218 double
220  // @todo possibly we could compute something reasonable here
221  return 0;
222 }
223 
224 
225 std::string
227  std::string result = "";
228  if (isParking()) {
229  result += "parking";
230  } else if (isStopped()) {
231  result += "stopped";
232  } else {
233  return "";
234  }
235  return result;
236 }
237 
238 
239 void
241  // @todo possibly we could compute something reasonable here
242 }
243 /****************************************************************************/
244 
double getBlockTimeSeconds() const
Returns the time at which the vehicle was blocked on the current segment.
Definition: MEVehicle.h:316
std::vector< MSVehicleDevice * > myDevices
The devices this vehicle has.
void closeBuilding(const Parameterised *p=0)
Closes the building of the table.
A vehicle from the mesoscopic point of view.
Definition: MEVehicle.h:45
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:178
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)
void drawRouteHelper(const GUIVisualizationSettings &s, const MSRoute &r) const
Draws the route.
void mkItem(const char *name, bool dynamic, ValueSource< T > *src)
Adds a row which obtains its value from a ValueSource.
std::string time2string(SUMOTime t)
Definition: SUMOTime.cpp:65
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:52
double getEventTimeSeconds() const
Returns the earliest leave time for the current segment.
Definition: MEVehicle.h:306
const std::vector< double > & getShapeRotations() const
Definition: GUILane.cpp:883
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:66
Representation of a lane in the micro simulation (gui-version)
Definition: GUILane.h:63
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.
double getCurrentStoppingTimeSeconds() const
Returns the delay that is accrued due to option –meso-tls-penalty or –meso-minor-penalty.
Definition: MEVehicle.cpp:271
GUIParameterTableWindow * getParameterWindow(GUIMainWindow &app, GUISUMOAbstractView &parent)
Returns an own parameter window.
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
Definition: ToString.h:49
MESegment * getSegment() const
Returns the current segment the vehicle is on.
Definition: MEVehicle.h:237
const MSEdge * getEdge() const
Returns the edge the vehicle is currently at.
~GUIMEVehicle()
destructor
ConstMSEdgeVector::const_iterator MSRouteIterator
Definition: MSRoute.h:58
bool isStopped() const
Returns whether the vehicle is at a stop.
Definition: MEVehicle.cpp:236
#define STEPS2TIME(x)
Definition: SUMOTime.h:58
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:877
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:911
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:311
MSVehicleType * myType
This vehicle&#39;s type.
const std::vector< double > & getShapeLengths() const
Definition: GUILane.cpp:889
const std::string & getID() const
Returns the name of the vehicle type.
Definition: MSVehicleType.h:94
double getLength() const
Get vehicle&#39;s length [m].
bool isParking() const
Returns whether the vehicle is parking.
Definition: MEVehicle.cpp:172
const std::map< std::string, std::string > & getParametersMap() const
Returns the inner key/value map.
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:78
GUIVisualizationSizeSettings vehicleSize
double getCurrentLinkPenaltySeconds() const
Returns the delay that is accrued due to option –meso-tls-penalty or –meso-minor-penalty.
Definition: MEVehicle.cpp:321
MSRouteIterator begin() const
Returns the begin of the list of edges to pass.
Definition: MSRoute.cpp:70
double getSpeed() const
Returns the vehicle&#39;s estimated speed assuming no delays.
Definition: MEVehicle.cpp:107
double getExaggeration(const GUIVisualizationSettings &s, const GUIGlObject *o, double factor=20) const
return the drawing size including exaggeration and constantSize values
GUIMEVehicle(SUMOVehicleParameter *pars, const MSRoute *route, MSVehicleType *type, const double speedFactor)
Constructor.
const std::string & getID() const
Returns the name of the vehicle.
GUISelectedStorage gSelected
A global holder of selected objects.
const MSEdge & getEdge() const
Returns the edge this segment belongs to.
Definition: MESegment.h:266
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:76
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:300