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 
GUIMEVehicle.h
MSVehicleType
The car-following model and parameter.
Definition: MSVehicleType.h:66
MEVehicle
A vehicle from the mesoscopic point of view.
Definition: MEVehicle.h:45
MSVehicleType::getEmissionClass
SUMOEmissionClass getEmissionClass() const
Get this vehicle type's emission class.
Definition: MSVehicleType.h:194
MSBaseVehicle::getParameter
const SUMOVehicleParameter & getParameter() const
Returns the vehicle's parameter (including departure definition)
Definition: MSBaseVehicle.cpp:143
MSVehicleType::getID
const std::string & getID() const
Returns the name of the vehicle type.
Definition: MSVehicleType.h:94
GUIParameterTableWindow
A window containing a gl-object's parameter.
Definition: GUIParameterTableWindow.h:63
GUIBaseVehicle
A MSVehicle extended by some values for usage within the gui.
Definition: GUIBaseVehicle.h:62
GUIMEVehicle::getSegmentIndex
int getSegmentIndex() const
Definition: GUIMEVehicle.cpp:252
GUISUMOAbstractView
Definition: GUISUMOAbstractView.h:73
MEVehicle::getEventTimeSeconds
double getEventTimeSeconds() const
Returns the earliest leave time for the current segment.
Definition: MEVehicle.h:313
MSEdge::getVehicleMaxSpeed
double getVehicleMaxSpeed(const SUMOTrafficObject *const veh) const
Returns the maximum speed the vehicle may use on this edge.
Definition: MSEdge.cpp:928
GUIParameterTableWindow.h
MSVehicleDevice.h
MSRoute::end
MSRouteIterator end() const
Returns the end of the list of edges to pass.
Definition: MSRoute.cpp:76
MSRouteIterator
ConstMSEdgeVector::const_iterator MSRouteIterator
Definition: MSRoute.h:58
GUIMEVehicle::selectBlockingFoes
void selectBlockingFoes() const
adds the blocking foes to the current selection
Definition: GUIMEVehicle.cpp:258
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:523
MESegment::getEdge
const MSEdge & getEdge() const
Returns the edge this segment belongs to.
Definition: MESegment.h:266
MSBaseVehicle::getNumberReroutes
int getNumberReroutes() const
Returns the number of new routes this vehicle got.
Definition: MSBaseVehicle.h:299
GUIMEVehicle::~GUIMEVehicle
~GUIMEVehicle()
destructor
Definition: GUIMEVehicle.cpp:58
GUIGlobalSelection.h
MSBaseVehicle::getLength
double getLength() const
Returns the vehicle's length.
Definition: MSBaseVehicle.h:394
MSBaseVehicle::getDepartDelay
SUMOTime getDepartDelay() const
Returns the depart delay.
Definition: MSBaseVehicle.h:261
MEVehicle::getPositionOnLane
double getPositionOnLane() const
Get the vehicle's position along the lane.
Definition: MEVehicle.cpp:78
MEVehicle::getCurrentStoppingTimeSeconds
double getCurrentStoppingTimeSeconds() const
Returns the delay that is accrued due to option –meso-tls-penalty or –meso-minor-penalty.
Definition: MEVehicle.cpp:276
GUIVisualizationSettings.h
GUIBaseVehicle::getVType
const MSVehicleType & getVType() const
A shortcut to myVehicle.myType.
Definition: GUIBaseVehicle.h:337
SUMOVehicleParameter
Structure representing possible vehicle parameter.
Definition: SUMOVehicleParameter.h:291
GLO_VEHICLE
Definition: GUIGlObjectTypes.h:142
GLHelper.h
GUIVisualizationSettings::vehicleSize
GUIVisualizationSizeSettings vehicleSize
Definition: GUIVisualizationSettings.h:511
PollutantsInterface::getName
static std::string getName(const SUMOEmissionClass c)
Checks whether the string describes a known vehicle class.
Definition: PollutantsInterface.cpp:100
MSVehicleType::getPersonCapacity
int getPersonCapacity() const
Get this vehicle type's person capacity.
Definition: MSVehicleType.h:285
MSRoute
Definition: MSRoute.h:67
FunctionBindingString
Definition: FunctionBinding.h:83
GUIParameterTableWindow::closeBuilding
void closeBuilding(const Parameterised *p=0)
Closes the building of the table.
Definition: GUIParameterTableWindow.cpp:220
MSBaseVehicle::getMaxSpeed
double getMaxSpeed() const
Returns the maximum speed.
Definition: MSBaseVehicle.cpp:154
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:410
MSBaseVehicle::myParameter
const SUMOVehicleParameter * myParameter
This vehicle's parameter.
Definition: MSBaseVehicle.h:493
MSBaseVehicle::getEdge
const MSEdge * getEdge() const
Returns the edge the vehicle is currently at.
Definition: MSBaseVehicle.cpp:170
SUMOVehicleParameter::line
std::string line
The vehicle's line (mainly for public transport)
Definition: SUMOVehicleParameter.h:555
MEVehicle::getWaitingSeconds
double getWaitingSeconds() const
Returns the number of seconds waited (speed was lesser than 0.1m/s)
Definition: MEVehicle.h:307
Parameterised::getParametersMap
const std::map< std::string, std::string > & getParametersMap() const
Returns the inner key/value map.
Definition: Parameterised.cpp:105
MEVehicle::isStopped
bool isStopped() const
Returns whether the vehicle is at a stop.
Definition: MEVehicle.cpp:242
GUILane::getShape
const PositionVector & getShape() const
Definition: GUILane.cpp:899
PollutantsInterface.h
GUIMEVehicle::getEdgeID
std::string getEdgeID() const
Definition: GUIMEVehicle.cpp:247
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:109
GUILane::getShapeRotations
const std::vector< double > & getShapeRotations() const
Definition: GUILane.cpp:905
STEPS2TIME
#define STEPS2TIME(x)
Definition: SUMOTime.h:57
GUIGlObject::getGlID
GUIGlID getGlID() const
Returns the numerical id of the object.
Definition: GUIGlObject.cpp:150
MEVehicle::getBlockTimeSeconds
double getBlockTimeSeconds() const
Returns the time at which the vehicle was blocked on the current segment.
Definition: MEVehicle.h:323
GUILane::getShapeLengths
const std::vector< double > & getShapeLengths() const
Definition: GUILane.cpp:911
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:153
time2string
std::string time2string(SUMOTime t)
Definition: SUMOTime.cpp:65
MSVehicleType::getMinGap
double getMinGap() const
Get the free space in front of vehicles of this class.
Definition: MSVehicleType.h:126
GUIBaseVehicleHelper.h
GUIBaseVehicleHelper::drawAction_drawVehicleAsBoxPlus
static void drawAction_drawVehicleAsBoxPlus(const double width, const double length)
draw vehicle as a Box
Definition: GUIBaseVehicleHelper.cpp:112
GUIBaseVehicle::getNaviDegree
double getNaviDegree() const
return the current angle in navigational degrees
Definition: GUIBaseVehicle.h:86
GUIMEVehicle::getTypeParameterWindow
GUIParameterTableWindow * getTypeParameterWindow(GUIMainWindow &app, GUISUMOAbstractView &parent)
Returns an own type parameter window.
Definition: GUIMEVehicle.cpp:128
GLIncludes.h
toString
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
Definition: ToString.h:48
GUILane
Representation of a lane in the micro simulation (gui-version)
Definition: GUILane.h:62
MEVehicle::getCurrentLinkPenaltySeconds
double getCurrentLinkPenaltySeconds() const
Returns the delay that is accrued due to option –meso-tls-penalty or –meso-minor-penalty.
Definition: MEVehicle.cpp:369
MEVehicle::getSegment
MESegment * getSegment() const
Returns the current segment the vehicle is on.
Definition: MEVehicle.h:244
FunctionBinding.h
GUIMainWindow
Definition: GUIMainWindow.h:47
MSBaseVehicle::myCurrEdge
MSRouteIterator myCurrEdge
Iterator to current route-edge.
Definition: MSBaseVehicle.h:502
MEVehicle::isParking
bool isParking() const
Returns whether the vehicle is parking.
Definition: MEVehicle.cpp:172
MEVehicle::getSpeed
double getSpeed() const
Returns the vehicle's estimated speed assuming no delays.
Definition: MEVehicle.cpp:107
MSVehicleType::getLength
double getLength() const
Get vehicle's length [m].
Definition: MSVehicleType.h:110
GUIMEVehicle::getLastLaneChangeOffset
double getLastLaneChangeOffset() const
Returns the time since the last lane change in seconds.
Definition: GUIMEVehicle.cpp:227
MSVehicleType::getParameter
const SUMOVTypeParameter & getParameter() const
Definition: MSVehicleType.h:556
gSelected
GUISelectedStorage gSelected
A global holder of selected objects.
Definition: GUIGlobalSelection.cpp:34
MSBaseVehicle
The base class for microscopic and mesoscopic vehicles.
Definition: MSBaseVehicle.h:52
GUIMEVehicle::getParameterWindow
GUIParameterTableWindow * getParameterWindow(GUIMainWindow &app, GUISUMOAbstractView &parent)
Returns an own parameter window.
Definition: GUIMEVehicle.cpp:62
MSRoute::begin
MSRouteIterator begin() const
Returns the begin of the list of edges to pass.
Definition: MSRoute.cpp:70
MSBaseVehicle::getWidth
double getWidth() const
Returns the vehicle's width.
Definition: MSBaseVehicle.h:402
config.h
GUIMEVehicle::getStopInfo
std::string getStopInfo() const
retrieve information about the current stop state
Definition: GUIMEVehicle.cpp:234
MSVehicleType::getContainerCapacity
int getContainerCapacity() const
Get this vehicle type's container capacity.
Definition: MSVehicleType.h:293
GUIVisualizationSettings
Stores the information about how to visualize structures.
Definition: GUIVisualizationSettings.h:346
GUIMEVehicle::getColorValue
double getColorValue(const GUIVisualizationSettings &s, int activeScheme) const
gets the color value according to the current scheme index
Definition: GUIMEVehicle.cpp:159
FunctionBinding
Definition: FunctionBinding.h:41
MSBaseVehicle::myType
MSVehicleType * myType
This vehicle's type.
Definition: MSBaseVehicle.h:499
MSVehicleType::getVehicleClass
SUMOVehicleClass getVehicleClass() const
Get this vehicle type's vehicle class.
Definition: MSVehicleType.h:185
MESegment::getIndex
int getIndex() const
Returns the running index of the segment in the edge (0 is the most upstream).
Definition: MESegment.h:144
Named::getID
const std::string & getID() const
Returns the id.
Definition: Named.h:77
GUIMEVehicle::GUIMEVehicle
GUIMEVehicle(SUMOVehicleParameter *pars, const MSRoute *route, MSVehicleType *type, const double speedFactor)
Constructor.
Definition: GUIMEVehicle.cpp:48
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:318
GUIMEVehicle::drawRouteHelper
void drawRouteHelper(const GUIVisualizationSettings &s, const MSRoute &r, bool future) const
Draws the route.
Definition: GUIMEVehicle.cpp:215
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:95