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 /****************************************************************************/
16 // A MSVehicle extended by some values for usage within the gui
17 /****************************************************************************/
18 
19 
20 // ===========================================================================
21 // included modules
22 // ===========================================================================
23 #include <config.h>
24 
26 #include <utils/gui/div/GLHelper.h>
35 #include <guisim/GUILane.h>
36 
37 #include "GUIMEVehicle.h"
38 
39 
40 // ===========================================================================
41 // method definitions
42 // ===========================================================================
43 #ifdef _MSC_VER
44 #pragma warning(push)
45 #pragma warning(disable: 4355)
46 #endif
48  MSVehicleType* type, const double speedFactor) :
49  MEVehicle(pars, route, type, speedFactor),
50  GUIBaseVehicle((MSBaseVehicle&) * this) {
51 }
52 #ifdef _MSC_VER
53 #pragma warning(pop)
54 #endif
55 
56 
58 
59 
64  new GUIParameterTableWindow(app, *this, 21 + (int)getParameter().getParametersMap().size());
65  // add items
66  ret->mkItem("edge [id]", true, new FunctionBindingString<GUIMEVehicle>(this, &GUIMEVehicle::getEdgeID));
67  ret->mkItem("segment [#]", true, new FunctionBinding<GUIMEVehicle, int>(this, &GUIMEVehicle::getSegmentIndex));
68  ret->mkItem("position [m]", true, new FunctionBinding<GUIMEVehicle, double>(this, &MEVehicle::getPositionOnLane));
69  ret->mkItem("speed [m/s]", true, new FunctionBinding<GUIMEVehicle, double>(this, &MEVehicle::getSpeed));
70  ret->mkItem("angle [degree]", true, new FunctionBinding<GUIMEVehicle, double>(this, &GUIBaseVehicle::getNaviDegree));
71  ret->mkItem("waiting time [s]", true,
73  ret->mkItem("speed factor", false, getChosenSpeedFactor());
74  //ret->mkItem("time gap [s]", true,
75  // new FunctionBinding<GUIMEVehicle, double>(this, &MSVehicle::getTimeGap));
76  //ret->mkItem("waiting time [s]", true,
77  // new FunctionBinding<GUIMEVehicle, double>(this, &MSVehicle::getWaitingSeconds));
78  //ret->mkItem("impatience", true,
79  // new FunctionBinding<GUIMEVehicle, double>(this, &MSVehicle::getImpatience));
80  //ret->mkItem("last lane change [s]", true,
81  // new FunctionBinding<GUIMEVehicle, double>(this, &GUIMEVehicle::getLastLaneChangeOffset));
82  ret->mkItem("desired depart [s]", false, time2string(getParameter().depart));
83  ret->mkItem("depart delay [s]", false, time2string(getDepartDelay()));
84  if (getParameter().repetitionNumber < std::numeric_limits<int>::max()) {
85  ret->mkItem("remaining [#]", false, (int) getParameter().repetitionNumber - getParameter().repetitionsDone);
86  }
87  if (getParameter().repetitionOffset > 0) {
88  ret->mkItem("insertion period [s]", false, time2string(getParameter().repetitionOffset));
89  }
90  if (getParameter().repetitionProbability > 0) {
91  ret->mkItem("insertion probability", false, getParameter().repetitionProbability);
92  }
93  //ret->mkItem("stop info", false, getStopInfo());
94  ret->mkItem("line", false, myParameter->line);
95  //ret->mkItem("CO2 [mg/s]", true,
96  // new FunctionBinding<GUIMEVehicle, double>(this, &GUIMEVehicle::getCO2Emissions));
97  //ret->mkItem("CO [mg/s]", true,
98  // new FunctionBinding<GUIMEVehicle, double>(this, &GUIMEVehicle::getCOEmissions));
99  //ret->mkItem("HC [mg/s]", true,
100  // new FunctionBinding<GUIMEVehicle, double>(this, &GUIMEVehicle::getHCEmissions));
101  //ret->mkItem("NOx [mg/s]", true,
102  // new FunctionBinding<GUIMEVehicle, double>(this, &GUIMEVehicle::getNOxEmissions));
103  //ret->mkItem("PMx [mg/s]", true,
104  // new FunctionBinding<GUIMEVehicle, double>(this, &GUIMEVehicle::getPMxEmissions));
105  //ret->mkItem("fuel [ml/s]", true,
106  // new FunctionBinding<GUIMEVehicle, double>(this, &GUIMEVehicle::getFuelConsumption));
107  //ret->mkItem("noise (Harmonoise) [dB]", true,
108  // new FunctionBinding<GUIMEVehicle, double>(this, &GUIMEVehicle::getHarmonoise_NoiseEmissions));
109  ret->mkItem("devices", false, toString(myDevices));
110  //ret->mkItem("persons", true,
111  // new FunctionBinding<GUIMEVehicle, int>(this, &GUIMEVehicle::getPersonNumber));
112  //ret->mkItem("containers", true,
113  // new FunctionBinding<GUIMEVehicle, int>(this, &GUIMEVehicle::getContainerNumber));
114  // meso specific values
115  ret->mkItem("event time [s]", true, new FunctionBinding<GUIMEVehicle, double>(this, &MEVehicle::getEventTimeSeconds));
116  ret->mkItem("entry time [s]", true, new FunctionBinding<GUIMEVehicle, double>(this, &MEVehicle::getLastEntryTimeSeconds));
117  ret->mkItem("block time [s]", true, new FunctionBinding<GUIMEVehicle, double>(this, &MEVehicle::getBlockTimeSeconds));
120  // close building
121  ret->closeBuilding(&getParameter());
122  return ret;
123 }
124 
125 
130  new GUIParameterTableWindow(app, *this, 9 + (int)myType->getParameter().getParametersMap().size());
131  // add items
132  ret->mkItem("Type Information:", false, "");
133  ret->mkItem("type [id]", false, myType->getID());
134  ret->mkItem("length", false, myType->getLength());
135  ret->mkItem("minGap", false, myType->getMinGap());
136  ret->mkItem("vehicle class", false, SumoVehicleClassStrings.getString(myType->getVehicleClass()));
137  ret->mkItem("emission class", false, PollutantsInterface::getName(myType->getEmissionClass()));
138  ret->mkItem("maximum speed [m/s]", false, getMaxSpeed());
139  //ret->mkItem("maximum acceleration [m/s^2]", false, getCarFollowModel().getMaxAccel());
140  //ret->mkItem("maximum deceleration [m/s^2]", false, getCarFollowModel().getMaxDecel());
141  //ret->mkItem("imperfection (sigma)", false, getCarFollowModel().getImperfection());
142  //ret->mkItem("desired headway (tau)", false, getCarFollowModel().getHeadwayTime());
143  ret->mkItem("person capacity", false, myType->getPersonCapacity());
144  ret->mkItem("container capacity", false, myType->getContainerCapacity());
145  // close building
146  ret->closeBuilding(&(myType->getParameter()));
147  return ret;
148 }
149 
150 
151 void
152 GUIMEVehicle::drawAction_drawCarriageClass(const GUIVisualizationSettings& /* s */, bool /* asImage */) const {
154 }
155 
156 
157 double
158 GUIMEVehicle::getColorValue(const GUIVisualizationSettings& /* s */, int activeScheme) const {
159  switch (activeScheme) {
160  case 8:
161  return getSpeed();
162  case 9:
163  return 0; // by actionStep
164  case 10:
165  return getWaitingSeconds();
166  case 11:
167  return 0; // getAccumulatedWaitingSeconds
168  case 12:
169  return 0; // invalid getLastLaneChangeOffset();
170  case 13:
171  return getSegment()->getEdge().getVehicleMaxSpeed(this);
172  case 14:
173  return 0; // invalid getCO2Emissions();
174  case 15:
175  return 0; // invalid getCOEmissions();
176  case 16:
177  return 0; // invalid getPMxEmissions();
178  case 17:
179  return 0; // invalid getNOxEmissions();
180  case 18:
181  return 0; // invalid getHCEmissions();
182  case 19:
183  return 0; // invalid getFuelConsumption();
184  case 20:
185  return 0; // invalid getHarmonoise_NoiseEmissions();
186  case 21: // reroute number
187  if (getNumberReroutes() == 0) {
188  return -1;
189  }
190  return getNumberReroutes();
191  case 22:
193  case 23:
194  return 0; // invalid getBestLaneOffset();
195  case 24:
196  return 0; // invalid getAcceleration();
197  case 25:
198  return 0; // invalid getTimeGapOnLane();
199  case 26:
200  return STEPS2TIME(getDepartDelay());
201  case 27:
202  return 0; // electricityConsumption
203  case 28:
204  return 0; // timeLossSeconds
205  case 29:
206  return 0; // getSpeedLat
207  }
208  return 0;
209 }
210 
211 
212 
213 void
214 GUIMEVehicle::drawRouteHelper(const GUIVisualizationSettings& s, const MSRoute& r, bool future, const RGBColor& /*col*/) const {
215  const double exaggeration = s.vehicleSize.getExaggeration(s, this);
216  MSRouteIterator i = future ? myCurrEdge : r.begin();
217  for (; i != r.end(); ++i) {
218  const GUILane* lane = static_cast<GUILane*>((*i)->getLanes()[0]);
219  GLHelper::drawBoxLines(lane->getShape(), lane->getShapeRotations(), lane->getShapeLengths(), 1.0);
220  GLHelper::drawBoxLines(lane->getShape(), lane->getShapeRotations(), lane->getShapeLengths(), exaggeration);
221  }
222 }
223 
224 
225 double
227  // @todo possibly we could compute something reasonable here
228  return 0;
229 }
230 
231 
232 std::string
234  std::string result = "";
235  if (isParking()) {
236  result += "parking";
237  } else if (isStopped()) {
238  result += "stopped";
239  } else {
240  return "";
241  }
242  return result;
243 }
244 
245 std::string
247  return getEdge()->getID();
248 }
249 
250 int
252  return getSegment()->getIndex();
253 }
254 
255 
256 void
258  // @todo possibly we could compute something reasonable here
259 }
260 /****************************************************************************/
261 
GUIMEVehicle.h
MSVehicleType
The car-following model and parameter.
Definition: MSVehicleType.h:65
MEVehicle
A vehicle from the mesoscopic point of view.
Definition: MEVehicle.h:44
MSVehicleType::getEmissionClass
SUMOEmissionClass getEmissionClass() const
Get this vehicle type's emission class.
Definition: MSVehicleType.h:193
MSBaseVehicle::getParameter
const SUMOVehicleParameter & getParameter() const
Returns the vehicle's parameter (including departure definition)
Definition: MSBaseVehicle.cpp:144
MSVehicleType::getID
const std::string & getID() const
Returns the name of the vehicle type.
Definition: MSVehicleType.h:93
GUIParameterTableWindow
A window containing a gl-object's parameter.
Definition: GUIParameterTableWindow.h:62
GUIBaseVehicle
A MSVehicle extended by some values for usage within the gui.
Definition: GUIBaseVehicle.h:61
GUIMEVehicle::getSegmentIndex
int getSegmentIndex() const
Definition: GUIMEVehicle.cpp:251
GUISUMOAbstractView
Definition: GUISUMOAbstractView.h:72
MEVehicle::getEventTimeSeconds
double getEventTimeSeconds() const
Returns the earliest leave time for the current segment.
Definition: MEVehicle.h:316
MSEdge::getVehicleMaxSpeed
double getVehicleMaxSpeed(const SUMOTrafficObject *const veh) const
Returns the maximum speed the vehicle may use on this edge.
Definition: MSEdge.cpp:889
GUIParameterTableWindow.h
MSVehicleDevice.h
MSRoute::end
MSRouteIterator end() const
Returns the end of the list of edges to pass.
Definition: MSRoute.cpp:75
MSRouteIterator
ConstMSEdgeVector::const_iterator MSRouteIterator
Definition: MSRoute.h:57
GUIMEVehicle::selectBlockingFoes
void selectBlockingFoes() const
adds the blocking foes to the current selection
Definition: GUIMEVehicle.cpp:257
GLHelper::drawBoxLines
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
MSBaseVehicle::myDevices
std::vector< MSVehicleDevice * > myDevices
The devices this vehicle has.
Definition: MSBaseVehicle.h:542
MESegment::getEdge
const MSEdge & getEdge() const
Returns the edge this segment belongs to.
Definition: MESegment.h:265
MSBaseVehicle::getNumberReroutes
int getNumberReroutes() const
Returns the number of new routes this vehicle got.
Definition: MSBaseVehicle.h:315
GUIMEVehicle::~GUIMEVehicle
~GUIMEVehicle()
destructor
Definition: GUIMEVehicle.cpp:57
GUIGlobalSelection.h
MSBaseVehicle::getLength
double getLength() const
Returns the vehicle's length.
Definition: MSBaseVehicle.h:410
MSBaseVehicle::getDepartDelay
SUMOTime getDepartDelay() const
Returns the depart delay.
Definition: MSBaseVehicle.h:266
MEVehicle::getPositionOnLane
double getPositionOnLane() const
Get the vehicle's position along the lane.
Definition: MEVehicle.cpp:77
GUIMEVehicle::drawRouteHelper
void drawRouteHelper(const GUIVisualizationSettings &s, const MSRoute &r, bool future, const RGBColor &col) const
Draws the route.
Definition: GUIMEVehicle.cpp:214
MEVehicle::getCurrentStoppingTimeSeconds
double getCurrentStoppingTimeSeconds() const
Returns the delay that is accrued due to option –meso-tls-penalty or –meso-minor-penalty.
Definition: MEVehicle.cpp:275
GUIVisualizationSettings.h
GUIBaseVehicle::getVType
const MSVehicleType & getVType() const
A shortcut to myVehicle.myType.
Definition: GUIBaseVehicle.h:329
SUMOVehicleParameter
Structure representing possible vehicle parameter.
Definition: SUMOVehicleParameter.h:297
GLO_VEHICLE
@ GLO_VEHICLE
Definition: GUIGlObjectTypes.h:141
GLHelper.h
GUIVisualizationSettings::vehicleSize
GUIVisualizationSizeSettings vehicleSize
Definition: GUIVisualizationSettings.h:520
PollutantsInterface::getName
static std::string getName(const SUMOEmissionClass c)
Checks whether the string describes a known vehicle class.
Definition: PollutantsInterface.cpp:99
MSVehicleType::getPersonCapacity
int getPersonCapacity() const
Get this vehicle type's person capacity.
Definition: MSVehicleType.h:284
MSRoute
Definition: MSRoute.h:66
FunctionBindingString
Definition: FunctionBinding.h:82
GUIParameterTableWindow::closeBuilding
void closeBuilding(const Parameterised *p=0)
Closes the building of the table.
Definition: GUIParameterTableWindow.cpp:219
MSBaseVehicle::getMaxSpeed
double getMaxSpeed() const
Returns the maximum speed.
Definition: MSBaseVehicle.cpp:165
SumoVehicleClassStrings
StringBijection< SUMOVehicleClass > SumoVehicleClassStrings(sumoVehicleClassStringInitializer, SVC_CUSTOM2, false)
MSBaseVehicle::getChosenSpeedFactor
double getChosenSpeedFactor() const
Returns the precomputed factor by which the driver wants to be faster than the speed limit.
Definition: MSBaseVehicle.h:426
MSBaseVehicle::myParameter
const SUMOVehicleParameter * myParameter
This vehicle's parameter.
Definition: MSBaseVehicle.h:512
MSBaseVehicle::getEdge
const MSEdge * getEdge() const
Returns the edge the vehicle is currently at.
Definition: MSBaseVehicle.cpp:181
SUMOVehicleParameter::line
std::string line
The vehicle's line (mainly for public transport)
Definition: SUMOVehicleParameter.h:561
MEVehicle::getWaitingSeconds
double getWaitingSeconds() const
Returns the number of seconds waited (speed was lesser than 0.1m/s)
Definition: MEVehicle.h:310
RGBColor
Definition: RGBColor.h:39
Parameterised::getParametersMap
const std::map< std::string, std::string > & getParametersMap() const
Returns the inner key/value map.
Definition: Parameterised.cpp:106
MEVehicle::isStopped
bool isStopped() const
Returns whether the vehicle is at a stop.
Definition: MEVehicle.cpp:241
GUILane::getShape
const PositionVector & getShape() const
Definition: GUILane.cpp:907
PollutantsInterface.h
GUIMEVehicle::getEdgeID
std::string getEdgeID() const
Definition: GUIMEVehicle.cpp:246
GUILane.h
GUIParameterTableWindow::mkItem
void mkItem(const char *name, bool dynamic, ValueSource< T > *src)
Adds a row which obtains its value from a ValueSource.
Definition: GUIParameterTableWindow.h:108
GUILane::getShapeRotations
const std::vector< double > & getShapeRotations() const
Definition: GUILane.cpp:913
STEPS2TIME
#define STEPS2TIME(x)
Definition: SUMOTime.h:56
GUIGlObject::getGlID
GUIGlID getGlID() const
Returns the numerical id of the object.
Definition: GUIGlObject.cpp:149
MEVehicle::getBlockTimeSeconds
double getBlockTimeSeconds() const
Returns the time at which the vehicle was blocked on the current segment.
Definition: MEVehicle.h:326
GUILane::getShapeLengths
const std::vector< double > & getShapeLengths() const
Definition: GUILane.cpp:919
CastingFunctionBinding.h
GUIMEVehicle::drawAction_drawCarriageClass
void drawAction_drawCarriageClass(const GUIVisualizationSettings &s, bool asImage) const
draws the given guiShape with distinct carriages/modules
Definition: GUIMEVehicle.cpp:152
time2string
std::string time2string(SUMOTime t)
Definition: SUMOTime.cpp:67
MSVehicleType::getMinGap
double getMinGap() const
Get the free space in front of vehicles of this class.
Definition: MSVehicleType.h:125
GUIBaseVehicleHelper.h
GUIBaseVehicleHelper::drawAction_drawVehicleAsBoxPlus
static void drawAction_drawVehicleAsBoxPlus(const double width, const double length)
draw vehicle as a Box
Definition: GUIBaseVehicleHelper.cpp:111
GUIBaseVehicle::getNaviDegree
double getNaviDegree() const
return the current angle in navigational degrees
Definition: GUIBaseVehicle.h:85
GUIMEVehicle::getTypeParameterWindow
GUIParameterTableWindow * getTypeParameterWindow(GUIMainWindow &app, GUISUMOAbstractView &parent)
Returns an own type parameter window.
Definition: GUIMEVehicle.cpp:127
GLIncludes.h
toString
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
Definition: ToString.h:47
GUILane
Representation of a lane in the micro simulation (gui-version)
Definition: GUILane.h:61
MEVehicle::getCurrentLinkPenaltySeconds
double getCurrentLinkPenaltySeconds() const
Returns the delay that is accrued due to option –meso-tls-penalty or –meso-minor-penalty.
Definition: MEVehicle.cpp:368
MEVehicle::getSegment
MESegment * getSegment() const
Returns the current segment the vehicle is on.
Definition: MEVehicle.h:247
FunctionBinding.h
GUIMainWindow
Definition: GUIMainWindow.h:46
MSBaseVehicle::myCurrEdge
MSRouteIterator myCurrEdge
Iterator to current route-edge.
Definition: MSBaseVehicle.h:521
MEVehicle::isParking
bool isParking() const
Returns whether the vehicle is parking.
Definition: MEVehicle.cpp:171
MEVehicle::getSpeed
double getSpeed() const
Returns the vehicle's estimated speed assuming no delays.
Definition: MEVehicle.cpp:106
MSVehicleType::getLength
double getLength() const
Get vehicle's length [m].
Definition: MSVehicleType.h:109
GUIMEVehicle::getLastLaneChangeOffset
double getLastLaneChangeOffset() const
Returns the time since the last lane change in seconds.
Definition: GUIMEVehicle.cpp:226
MSVehicleType::getParameter
const SUMOVTypeParameter & getParameter() const
Definition: MSVehicleType.h:560
gSelected
GUISelectedStorage gSelected
A global holder of selected objects.
Definition: GUIGlobalSelection.cpp:33
MSBaseVehicle
The base class for microscopic and mesoscopic vehicles.
Definition: MSBaseVehicle.h:51
GUIMEVehicle::getParameterWindow
GUIParameterTableWindow * getParameterWindow(GUIMainWindow &app, GUISUMOAbstractView &parent)
Returns an own parameter window.
Definition: GUIMEVehicle.cpp:61
MSRoute::begin
MSRouteIterator begin() const
Returns the begin of the list of edges to pass.
Definition: MSRoute.cpp:69
MSBaseVehicle::getWidth
double getWidth() const
Returns the vehicle's width.
Definition: MSBaseVehicle.h:418
config.h
GUIMEVehicle::getStopInfo
std::string getStopInfo() const
retrieve information about the current stop state
Definition: GUIMEVehicle.cpp:233
MSVehicleType::getContainerCapacity
int getContainerCapacity() const
Get this vehicle type's container capacity.
Definition: MSVehicleType.h:292
GUIVisualizationSettings
Stores the information about how to visualize structures.
Definition: GUIVisualizationSettings.h:345
GUIMEVehicle::getColorValue
double getColorValue(const GUIVisualizationSettings &s, int activeScheme) const
gets the color value according to the current scheme index
Definition: GUIMEVehicle.cpp:158
FunctionBinding
Definition: FunctionBinding.h:40
MSBaseVehicle::myType
MSVehicleType * myType
This vehicle's type.
Definition: MSBaseVehicle.h:518
MSVehicleType::getVehicleClass
SUMOVehicleClass getVehicleClass() const
Get this vehicle type's vehicle class.
Definition: MSVehicleType.h:184
MESegment::getIndex
int getIndex() const
Returns the running index of the segment in the edge (0 is the most upstream).
Definition: MESegment.h:143
Named::getID
const std::string & getID() const
Returns the id.
Definition: Named.h:76
GUIMEVehicle::GUIMEVehicle
GUIMEVehicle(SUMOVehicleParameter *pars, const MSRoute *route, MSVehicleType *type, const double speedFactor)
Constructor.
Definition: GUIMEVehicle.cpp:47
GUIVisualizationSizeSettings::getExaggeration
double getExaggeration(const GUIVisualizationSettings &s, const GUIGlObject *o, double factor=20) const
return the drawing size including exaggeration and constantSize values
Definition: GUIVisualizationSettings.cpp:212
MEVehicle::getLastEntryTimeSeconds
double getLastEntryTimeSeconds() const
Returns the entry time for the current segment.
Definition: MEVehicle.h:321
GUISelectedStorage::isSelected
bool isSelected(GUIGlObjectType type, GUIGlID id)
Returns the information whether the object with the given type and id is selected.
Definition: GUISelectedStorage.cpp:94