Eclipse 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-2019 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>
36 #include <guisim/GUILane.h>
37 
38 #include "GUIMEVehicle.h"
39 
40 
41 // ===========================================================================
42 // method definitions
43 // ===========================================================================
44 #ifdef _MSC_VER
45 #pragma warning(push)
46 #pragma warning(disable: 4355)
47 #endif
49  MSVehicleType* type, const double speedFactor) :
50  MEVehicle(pars, route, type, speedFactor),
51  GUIBaseVehicle((MSBaseVehicle&) * this) {
52 }
53 #ifdef _MSC_VER
54 #pragma warning(pop)
55 #endif
56 
57 
59 
60 
65  new GUIParameterTableWindow(app, *this, 21 + (int)getParameter().getParametersMap().size());
66  // add items
67  ret->mkItem("edge [id]", true, new FunctionBindingString<GUIMEVehicle>(this, &GUIMEVehicle::getEdgeID));
68  ret->mkItem("segment [#]", true, new FunctionBinding<GUIMEVehicle, int>(this, &GUIMEVehicle::getSegmentIndex));
69  ret->mkItem("position [m]", true, new FunctionBinding<GUIMEVehicle, double>(this, &MEVehicle::getPositionOnLane));
70  ret->mkItem("speed [m/s]", true, new FunctionBinding<GUIMEVehicle, double>(this, &MEVehicle::getSpeed));
71  ret->mkItem("angle [degree]", true, new FunctionBinding<GUIMEVehicle, double>(this, &GUIBaseVehicle::getNaviDegree));
72  ret->mkItem("waiting time [s]", true,
74  ret->mkItem("speed factor", false, getChosenSpeedFactor());
75  //ret->mkItem("time gap [s]", true,
76  // new FunctionBinding<GUIMEVehicle, double>(this, &MSVehicle::getTimeGap));
77  //ret->mkItem("waiting time [s]", true,
78  // new FunctionBinding<GUIMEVehicle, double>(this, &MSVehicle::getWaitingSeconds));
79  //ret->mkItem("impatience", true,
80  // new FunctionBinding<GUIMEVehicle, double>(this, &MSVehicle::getImpatience));
81  //ret->mkItem("last lane change [s]", true,
82  // new FunctionBinding<GUIMEVehicle, double>(this, &GUIMEVehicle::getLastLaneChangeOffset));
83  ret->mkItem("desired depart [s]", false, time2string(getParameter().depart));
84  ret->mkItem("depart delay [s]", false, time2string(getDepartDelay()));
85  if (getParameter().repetitionNumber < std::numeric_limits<int>::max()) {
86  ret->mkItem("remaining [#]", false, (int) getParameter().repetitionNumber - getParameter().repetitionsDone);
87  }
88  if (getParameter().repetitionOffset > 0) {
89  ret->mkItem("insertion period [s]", false, time2string(getParameter().repetitionOffset));
90  }
91  if (getParameter().repetitionProbability > 0) {
92  ret->mkItem("insertion probability", false, getParameter().repetitionProbability);
93  }
94  //ret->mkItem("stop info", false, getStopInfo());
95  ret->mkItem("line", false, myParameter->line);
96  //ret->mkItem("CO2 [mg/s]", true,
97  // new FunctionBinding<GUIMEVehicle, double>(this, &GUIMEVehicle::getCO2Emissions));
98  //ret->mkItem("CO [mg/s]", true,
99  // new FunctionBinding<GUIMEVehicle, double>(this, &GUIMEVehicle::getCOEmissions));
100  //ret->mkItem("HC [mg/s]", true,
101  // new FunctionBinding<GUIMEVehicle, double>(this, &GUIMEVehicle::getHCEmissions));
102  //ret->mkItem("NOx [mg/s]", true,
103  // new FunctionBinding<GUIMEVehicle, double>(this, &GUIMEVehicle::getNOxEmissions));
104  //ret->mkItem("PMx [mg/s]", true,
105  // new FunctionBinding<GUIMEVehicle, double>(this, &GUIMEVehicle::getPMxEmissions));
106  //ret->mkItem("fuel [ml/s]", true,
107  // new FunctionBinding<GUIMEVehicle, double>(this, &GUIMEVehicle::getFuelConsumption));
108  //ret->mkItem("noise (Harmonoise) [dB]", true,
109  // new FunctionBinding<GUIMEVehicle, double>(this, &GUIMEVehicle::getHarmonoise_NoiseEmissions));
110  ret->mkItem("devices", false, toString(myDevices));
111  //ret->mkItem("persons", true,
112  // new FunctionBinding<GUIMEVehicle, int>(this, &GUIMEVehicle::getPersonNumber));
113  //ret->mkItem("containers", true,
114  // new FunctionBinding<GUIMEVehicle, int>(this, &GUIMEVehicle::getContainerNumber));
115  // meso specific values
116  ret->mkItem("event time [s]", true, new FunctionBinding<GUIMEVehicle, double>(this, &MEVehicle::getEventTimeSeconds));
117  ret->mkItem("entry time [s]", true, new FunctionBinding<GUIMEVehicle, double>(this, &MEVehicle::getLastEntryTimeSeconds));
118  ret->mkItem("block time [s]", true, new FunctionBinding<GUIMEVehicle, double>(this, &MEVehicle::getBlockTimeSeconds));
121  // close building
122  ret->closeBuilding(&getParameter());
123  return ret;
124 }
125 
126 
131  new GUIParameterTableWindow(app, *this, 9 + (int)myType->getParameter().getParametersMap().size());
132  // add items
133  ret->mkItem("Type Information:", false, "");
134  ret->mkItem("type [id]", false, myType->getID());
135  ret->mkItem("length", false, myType->getLength());
136  ret->mkItem("minGap", false, myType->getMinGap());
137  ret->mkItem("vehicle class", false, SumoVehicleClassStrings.getString(myType->getVehicleClass()));
138  ret->mkItem("emission class", false, PollutantsInterface::getName(myType->getEmissionClass()));
139  ret->mkItem("maximum speed [m/s]", false, getMaxSpeed());
140  //ret->mkItem("maximum acceleration [m/s^2]", false, getCarFollowModel().getMaxAccel());
141  //ret->mkItem("maximum deceleration [m/s^2]", false, getCarFollowModel().getMaxDecel());
142  //ret->mkItem("imperfection (sigma)", false, getCarFollowModel().getImperfection());
143  //ret->mkItem("desired headway (tau)", false, getCarFollowModel().getHeadwayTime());
144  ret->mkItem("person capacity", false, myType->getPersonCapacity());
145  ret->mkItem("container capacity", false, myType->getContainerCapacity());
146  // close building
147  ret->closeBuilding(&(myType->getParameter()));
148  return ret;
149 }
150 
151 
152 void
153 GUIMEVehicle::drawAction_drawCarriageClass(const GUIVisualizationSettings& /* s */, bool /* asImage */) const {
155 }
156 
157 
158 double
159 GUIMEVehicle::getColorValue(const GUIVisualizationSettings& /* s */, int activeScheme) const {
160  switch (activeScheme) {
161  case 8:
162  return getSpeed();
163  case 9:
164  return 0; // by actionStep
165  case 10:
166  return getWaitingSeconds();
167  case 11:
168  return 0; // getAccumulatedWaitingSeconds
169  case 12:
170  return 0; // invalid getLastLaneChangeOffset();
171  case 13:
172  return getSegment()->getEdge().getVehicleMaxSpeed(this);
173  case 14:
174  return 0; // invalid getCO2Emissions();
175  case 15:
176  return 0; // invalid getCOEmissions();
177  case 16:
178  return 0; // invalid getPMxEmissions();
179  case 17:
180  return 0; // invalid getNOxEmissions();
181  case 18:
182  return 0; // invalid getHCEmissions();
183  case 19:
184  return 0; // invalid getFuelConsumption();
185  case 20:
186  return 0; // invalid getHarmonoise_NoiseEmissions();
187  case 21: // reroute number
188  if (getNumberReroutes() == 0) {
189  return -1;
190  }
191  return getNumberReroutes();
192  case 22:
194  case 23:
195  return 0; // invalid getBestLaneOffset();
196  case 24:
197  return 0; // invalid getAcceleration();
198  case 25:
199  return 0; // invalid getTimeGapOnLane();
200  case 26:
201  return STEPS2TIME(getDepartDelay());
202  case 27:
203  return 0; // electricityConsumption
204  case 28:
205  return 0; // timeLossSeconds
206  case 29:
207  return 0; // getSpeedLat
208  }
209  return 0;
210 }
211 
212 
213 
214 void
215 GUIMEVehicle::drawRouteHelper(const GUIVisualizationSettings& s, const MSRoute& r, bool future) const {
216  const double exaggeration = s.vehicleSize.getExaggeration(s, this);
217  MSRouteIterator i = future ? myCurrEdge : r.begin();
218  for (; i != r.end(); ++i) {
219  const GUILane* lane = static_cast<GUILane*>((*i)->getLanes()[0]);
220  GLHelper::drawBoxLines(lane->getShape(), lane->getShapeRotations(), lane->getShapeLengths(), 1.0);
221  GLHelper::drawBoxLines(lane->getShape(), lane->getShapeRotations(), lane->getShapeLengths(), exaggeration);
222  }
223 }
224 
225 
226 double
228  // @todo possibly we could compute something reasonable here
229  return 0;
230 }
231 
232 
233 std::string
235  std::string result = "";
236  if (isParking()) {
237  result += "parking";
238  } else if (isStopped()) {
239  result += "stopped";
240  } else {
241  return "";
242  }
243  return result;
244 }
245 
246 std::string
248  return getEdge()->getID();
249 }
250 
251 int
253  return getSegment()->getIndex();
254 }
255 
256 
257 void
259  // @todo possibly we could compute something reasonable here
260 }
261 /****************************************************************************/
262 
double getBlockTimeSeconds() const
Returns the time at which the vehicle was blocked on the current segment.
Definition: MEVehicle.h:323
std::vector< MSVehicleDevice * > myDevices
The devices this vehicle has.
double getLength() const
Returns the vehicle&#39;s length.
void closeBuilding(const Parameterised *p=0)
Closes the building of the table.
std::string getEdgeID() const
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:182
double getVehicleMaxSpeed(const SUMOTrafficObject *const veh) const
Returns the maximum speed the vehicle may use on this edge.
Definition: MSEdge.cpp:928
static void drawAction_drawVehicleAsBoxPlus(const double width, const double length)
draw vehicle as a Box
const MSVehicleType & getVType() const
A shortcut to myVehicle.myType.
Stores the information about how to visualize structures.
int getIndex() const
Returns the running index of the segment in the edge (0 is the most upstream).
Definition: MESegment.h:144
const SUMOVehicleParameter & getParameter() const
Returns the vehicle&#39;s parameter (including departure definition)
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.
void drawAction_drawCarriageClass(const GUIVisualizationSettings &s, bool asImage) const
draws the given guiShape with distinct carriages/modules
const SUMOVehicleParameter * myParameter
This vehicle&#39;s parameter.
const std::string & getID() const
Returns the id.
Definition: Named.h:77
int getSegmentIndex() const
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:313
const std::vector< double > & getShapeRotations() const
Definition: GUILane.cpp:905
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:62
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:276
GUIParameterTableWindow * getParameterWindow(GUIMainWindow &app, GUISUMOAbstractView &parent)
Returns an own parameter window.
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
Definition: ToString.h:48
double getColorValue(const GUIVisualizationSettings &s, int activeScheme) const
gets the color value according to the current scheme index
MESegment * getSegment() const
Returns the current segment the vehicle is on.
Definition: MEVehicle.h:244
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:242
#define STEPS2TIME(x)
Definition: SUMOTime.h:57
void selectBlockingFoes() const
adds the blocking foes to the current selection
A MSVehicle extended by some values for usage within the gui.
const PositionVector & getShape() const
Definition: GUILane.cpp:899
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)
Structure representing possible vehicle parameter.
double getLastEntryTimeSeconds() const
Returns the entry time for the current segment.
Definition: MEVehicle.h:318
MSVehicleType * myType
This vehicle&#39;s type.
const std::vector< double > & getShapeLengths() const
Definition: GUILane.cpp:911
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.
void drawRouteHelper(const GUIVisualizationSettings &s, const MSRoute &r, bool future) const
Draws the route.
double getPositionOnLane() const
Get the vehicle&#39;s position along the lane.
Definition: MEVehicle.cpp:78
GUIVisualizationSizeSettings vehicleSize
MSRouteIterator myCurrEdge
Iterator to current route-edge.
double getCurrentLinkPenaltySeconds() const
Returns the delay that is accrued due to option –meso-tls-penalty or –meso-minor-penalty.
Definition: MEVehicle.cpp:369
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.
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 getWidth() const
Returns the vehicle&#39;s width.
double getWaitingSeconds() const
Returns the number of seconds waited (speed was lesser than 0.1m/s)
Definition: MEVehicle.h:307