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 
26 #include <utils/gui/div/GLHelper.h>
34 #include <guisim/GUILane.h>
35 #include "GUIMEVehicle.h"
36 
37 
38 // ===========================================================================
39 // method definitions
40 // ===========================================================================
41 #ifdef _MSC_VER
42 #pragma warning(push)
43 #pragma warning(disable: 4355)
44 #endif
46  MSVehicleType* type, const double speedFactor) :
47  MEVehicle(pars, route, type, speedFactor),
48  GUIBaseVehicle((MSBaseVehicle&) * this) {
49 }
50 #ifdef _MSC_VER
51 #pragma warning(pop)
52 #endif
53 
54 
56 
57 
62  new GUIParameterTableWindow(app, *this, 21 + (int)getParameter().getParametersMap().size());
63  // add items
64  ret->mkItem("edge [id]", false, getEdge()->getID());
65  ret->mkItem("segment [#]", false, getSegment()->getIndex());
66  ret->mkItem("position [m]", true, new FunctionBinding<GUIMEVehicle, double>(this, &MEVehicle::getPositionOnLane));
67  ret->mkItem("speed [m/s]", true, new FunctionBinding<GUIMEVehicle, double>(this, &MEVehicle::getSpeed));
68  ret->mkItem("angle [degree]", true, new FunctionBinding<GUIMEVehicle, double>(this, &GUIBaseVehicle::getNaviDegree));
69  ret->mkItem("waiting time [s]", true,
71  ret->mkItem("speed factor", false, getChosenSpeedFactor());
72  //ret->mkItem("time gap [s]", true,
73  // new FunctionBinding<GUIMEVehicle, double>(this, &MSVehicle::getTimeGap));
74  //ret->mkItem("waiting time [s]", true,
75  // new FunctionBinding<GUIMEVehicle, double>(this, &MSVehicle::getWaitingSeconds));
76  //ret->mkItem("impatience", true,
77  // new FunctionBinding<GUIMEVehicle, double>(this, &MSVehicle::getImpatience));
78  //ret->mkItem("last lane change [s]", true,
79  // new FunctionBinding<GUIMEVehicle, double>(this, &GUIMEVehicle::getLastLaneChangeOffset));
80  ret->mkItem("desired depart [s]", false, time2string(getParameter().depart));
81  ret->mkItem("depart delay [s]", false, time2string(getDepartDelay()));
82  if (getParameter().repetitionNumber < std::numeric_limits<int>::max()) {
83  ret->mkItem("remaining [#]", false, (int) getParameter().repetitionNumber - getParameter().repetitionsDone);
84  }
85  if (getParameter().repetitionOffset > 0) {
86  ret->mkItem("insertion period [s]", false, time2string(getParameter().repetitionOffset));
87  }
88  if (getParameter().repetitionProbability > 0) {
89  ret->mkItem("insertion probability", false, getParameter().repetitionProbability);
90  }
91  //ret->mkItem("stop info", false, getStopInfo());
92  ret->mkItem("line", false, myParameter->line);
93  //ret->mkItem("CO2 [mg/s]", true,
94  // new FunctionBinding<GUIMEVehicle, double>(this, &GUIMEVehicle::getCO2Emissions));
95  //ret->mkItem("CO [mg/s]", true,
96  // new FunctionBinding<GUIMEVehicle, double>(this, &GUIMEVehicle::getCOEmissions));
97  //ret->mkItem("HC [mg/s]", true,
98  // new FunctionBinding<GUIMEVehicle, double>(this, &GUIMEVehicle::getHCEmissions));
99  //ret->mkItem("NOx [mg/s]", true,
100  // new FunctionBinding<GUIMEVehicle, double>(this, &GUIMEVehicle::getNOxEmissions));
101  //ret->mkItem("PMx [mg/s]", true,
102  // new FunctionBinding<GUIMEVehicle, double>(this, &GUIMEVehicle::getPMxEmissions));
103  //ret->mkItem("fuel [ml/s]", true,
104  // new FunctionBinding<GUIMEVehicle, double>(this, &GUIMEVehicle::getFuelConsumption));
105  //ret->mkItem("noise (Harmonoise) [dB]", true,
106  // new FunctionBinding<GUIMEVehicle, double>(this, &GUIMEVehicle::getHarmonoise_NoiseEmissions));
107  std::ostringstream str;
108  for (std::vector<MSDevice*>::const_iterator i = myDevices.begin(); i != myDevices.end(); ++i) {
109  if (i != myDevices.begin()) {
110  str << ' ';
111  }
112  str << (*i)->getID().substr(0, (*i)->getID().find(getID()));
113  }
114  ret->mkItem("devices", false, str.str());
115  //ret->mkItem("persons", true,
116  // new FunctionBinding<GUIMEVehicle, int>(this, &GUIMEVehicle::getPersonNumber));
117  //ret->mkItem("containers", true,
118  // new FunctionBinding<GUIMEVehicle, int>(this, &GUIMEVehicle::getContainerNumber));
119  // meso specific values
120  ret->mkItem("event time [s]", true, new FunctionBinding<GUIMEVehicle, double>(this, &MEVehicle::getEventTimeSeconds));
121  ret->mkItem("entry time [s]", true, new FunctionBinding<GUIMEVehicle, double>(this, &MEVehicle::getLastEntryTimeSeconds));
122  ret->mkItem("block time [s]", true, new FunctionBinding<GUIMEVehicle, double>(this, &MEVehicle::getBlockTimeSeconds));
125  // close building
126  ret->closeBuilding(&getParameter());
127  return ret;
128 }
129 
130 
135  new GUIParameterTableWindow(app, *this, 9 + (int)myType->getParameter().getParametersMap().size());
136  // add items
137  ret->mkItem("Type Information:", false, "");
138  ret->mkItem("type [id]", false, myType->getID());
139  ret->mkItem("length", false, myType->getLength());
140  ret->mkItem("minGap", false, myType->getMinGap());
141  ret->mkItem("vehicle class", false, SumoVehicleClassStrings.getString(myType->getVehicleClass()));
142  ret->mkItem("emission class", false, PollutantsInterface::getName(myType->getEmissionClass()));
143  ret->mkItem("maximum speed [m/s]", false, getMaxSpeed());
144  //ret->mkItem("maximum acceleration [m/s^2]", false, getCarFollowModel().getMaxAccel());
145  //ret->mkItem("maximum deceleration [m/s^2]", false, getCarFollowModel().getMaxDecel());
146  //ret->mkItem("imperfection (sigma)", false, getCarFollowModel().getImperfection());
147  //ret->mkItem("desired headway (tau)", false, getCarFollowModel().getHeadwayTime());
148  ret->mkItem("person capacity", false, myType->getPersonCapacity());
149  ret->mkItem("container capacity", false, myType->getContainerCapacity());
150  // close building
151  ret->closeBuilding(&(myType->getParameter()));
152  return ret;
153 }
154 
155 
156 bool
157 GUIMEVehicle::drawAction_drawCarriageClass(const GUIVisualizationSettings& /* s */, SUMOVehicleShape /* guiShape */, bool /* asImage */) const {
159  return true;
160 }
161 
162 
163 double
164 GUIMEVehicle::getColorValue(int activeScheme) const {
165  switch (activeScheme) {
166  case 8:
167  return getSpeed();
168  case 9:
169  return getWaitingSeconds();
170  case 11:
171  return 0; // invalid getLastLaneChangeOffset();
172  case 12:
173  return getSegment()->getEdge().getVehicleMaxSpeed(this);
174  case 13:
175  return 0; // invalid getCO2Emissions();
176  case 14:
177  return 0; // invalid getCOEmissions();
178  case 15:
179  return 0; // invalid getPMxEmissions();
180  case 16:
181  return 0; // invalid getNOxEmissions();
182  case 17:
183  return 0; // invalid getHCEmissions();
184  case 18:
185  return 0; // invalid getFuelConsumption();
186  case 19:
187  return 0; // invalid getHarmonoise_NoiseEmissions();
188  case 20: // !!! unused!?
189  if (getNumberReroutes() == 0) {
190  return -1;
191  }
192  return getNumberReroutes();
193  case 21:
195  case 22:
196  return 0; // invalid getBestLaneOffset();
197  case 23:
198  return 0; // invalid getAcceleration();
199  case 24:
200  return 0; // invalid getTimeGapOnLane();
201  case 25:
202  return STEPS2TIME(getDepartDelay());
203  }
204  return 0;
205 }
206 
207 
208 
209 void
211  const double exaggeration = s.vehicleSize.getExaggeration(s);
212  MSRouteIterator i = r.begin();
213  for (; i != r.end(); ++i) {
214  const GUILane* lane = static_cast<GUILane*>((*i)->getLanes()[0]);
215  GLHelper::drawBoxLines(lane->getShape(), lane->getShapeRotations(), lane->getShapeLengths(), 1.0);
216  GLHelper::drawBoxLines(lane->getShape(), lane->getShapeRotations(), lane->getShapeLengths(), exaggeration);
217  }
218 }
219 
220 
221 double
223  // @todo possibly we could compute something reasonable here
224  return 0;
225 }
226 
227 
228 std::string
230  std::string result = "";
231  if (isParking()) {
232  result += "parking";
233  } else if (isStopped()) {
234  result += "stopped";
235  } else {
236  return "";
237  }
238  return result;
239 }
240 
241 
242 void
244  // @todo possibly we could compute something reasonable here
245 }
246 /****************************************************************************/
247 
double getBlockTimeSeconds() const
Returns the time at which the vehicle was blocked on the current segment.
Definition: MEVehicle.h:310
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:67
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:50
double getEventTimeSeconds() const
Returns the earliest leave time for the current segment.
Definition: MEVehicle.h:300
const std::vector< double > & getShapeRotations() const
Definition: GUILane.cpp:856
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.
MESegment * getSegment() const
Returns the current segment the vehicle is on.
Definition: MEVehicle.h:231
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:850
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:856
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:305
MSVehicleType * myType
This vehicle&#39;s type.
const std::vector< double > & getShapeLengths() const
Definition: GUILane.cpp:862
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 getExaggeration(const GUIVisualizationSettings &s, double factor=20) const
return the drawing size including exaggeration and constantSize values
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:67
double getSpeed() const
Returns the vehicle&#39;s estimated speed assuming no delays.
Definition: MEVehicle.cpp:107
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:264
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:73
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:294