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-2017 German Aerospace Center (DLR) and others.
4 /****************************************************************************/
5 //
6 // This program and the accompanying materials
7 // are made available under the terms of the Eclipse Public License v2.0
8 // which accompanies this distribution, and is available at
9 // http://www.eclipse.org/legal/epl-v20.html
10 //
11 /****************************************************************************/
19 // A MSVehicle extended by some values for usage within the gui
20 /****************************************************************************/
21 
22 
23 // ===========================================================================
24 // included modules
25 // ===========================================================================
26 #ifdef _MSC_VER
27 #include <windows_config.h>
28 #else
29 #include <config.h>
30 #endif
31 
32 #include <utils/gui/div/GLHelper.h>
40 #include <guisim/GUILane.h>
41 #include "GUIMEVehicle.h"
42 
43 
44 // ===========================================================================
45 // method definitions
46 // ===========================================================================
47 #ifdef _MSC_VER
48 #pragma warning(push)
49 #pragma warning(disable: 4355)
50 #endif
52  MSVehicleType* type, const double speedFactor) :
53  MEVehicle(pars, route, type, speedFactor),
54  GUIBaseVehicle((MSBaseVehicle&) * this) {
55 }
56 #ifdef _MSC_VER
57 #pragma warning(pop)
58 #endif
59 
60 
62 
63 
68  new GUIParameterTableWindow(app, *this, 20 + (int)getParameter().getMap().size());
69  // add items
70  ret->mkItem("edge [id]", false, getEdge()->getID());
71  ret->mkItem("segment [#]", false, getSegment()->getIndex());
72  ret->mkItem("position [m]", true, new FunctionBinding<GUIMEVehicle, double>(this, &MEVehicle::getPositionOnLane));
73  ret->mkItem("speed [m/s]", true, new FunctionBinding<GUIMEVehicle, double>(this, &MEVehicle::getSpeed));
74  ret->mkItem("angle [degree]", true, new FunctionBinding<GUIMEVehicle, double>(this, &GUIBaseVehicle::getNaviDegree));
75  ret->mkItem("waiting time [s]", true,
77  ret->mkItem("speed factor", false, getChosenSpeedFactor());
78  //ret->mkItem("time gap [s]", true,
79  // new FunctionBinding<GUIMEVehicle, double>(this, &MSVehicle::getTimeGap));
80  //ret->mkItem("waiting time [s]", true,
81  // new FunctionBinding<GUIMEVehicle, double>(this, &MSVehicle::getWaitingSeconds));
82  //ret->mkItem("impatience", true,
83  // new FunctionBinding<GUIMEVehicle, double>(this, &MSVehicle::getImpatience));
84  //ret->mkItem("last lane change [s]", true,
85  // new FunctionBinding<GUIMEVehicle, double>(this, &GUIMEVehicle::getLastLaneChangeOffset));
86  ret->mkItem("desired depart [s]", false, time2string(getParameter().depart));
87  ret->mkItem("depart delay [s]", false, time2string(getDepartDelay()));
88  if (getParameter().repetitionNumber < std::numeric_limits<int>::max()) {
89  ret->mkItem("remaining [#]", false, (int) getParameter().repetitionNumber - getParameter().repetitionsDone);
90  }
91  if (getParameter().repetitionOffset > 0) {
92  ret->mkItem("insertion period [s]", false, time2string(getParameter().repetitionOffset));
93  }
94  if (getParameter().repetitionProbability > 0) {
95  ret->mkItem("insertion probability", false, getParameter().repetitionProbability);
96  }
97  //ret->mkItem("stop info", false, getStopInfo());
98  ret->mkItem("line", false, myParameter->line);
99  //ret->mkItem("CO2 [mg/s]", true,
100  // new FunctionBinding<GUIMEVehicle, double>(this, &GUIMEVehicle::getCO2Emissions));
101  //ret->mkItem("CO [mg/s]", true,
102  // new FunctionBinding<GUIMEVehicle, double>(this, &GUIMEVehicle::getCOEmissions));
103  //ret->mkItem("HC [mg/s]", true,
104  // new FunctionBinding<GUIMEVehicle, double>(this, &GUIMEVehicle::getHCEmissions));
105  //ret->mkItem("NOx [mg/s]", true,
106  // new FunctionBinding<GUIMEVehicle, double>(this, &GUIMEVehicle::getNOxEmissions));
107  //ret->mkItem("PMx [mg/s]", true,
108  // new FunctionBinding<GUIMEVehicle, double>(this, &GUIMEVehicle::getPMxEmissions));
109  //ret->mkItem("fuel [ml/s]", true,
110  // new FunctionBinding<GUIMEVehicle, double>(this, &GUIMEVehicle::getFuelConsumption));
111  //ret->mkItem("noise (Harmonoise) [dB]", true,
112  // new FunctionBinding<GUIMEVehicle, double>(this, &GUIMEVehicle::getHarmonoise_NoiseEmissions));
113  std::ostringstream str;
114  for (std::vector<MSDevice*>::const_iterator i = myDevices.begin(); i != myDevices.end(); ++i) {
115  if (i != myDevices.begin()) {
116  str << ' ';
117  }
118  str << (*i)->getID().substr(0, (*i)->getID().find(getID()));
119  }
120  ret->mkItem("devices", false, str.str());
121  //ret->mkItem("persons", true,
122  // new FunctionBinding<GUIMEVehicle, int>(this, &GUIMEVehicle::getPersonNumber));
123  //ret->mkItem("containers", true,
124  // new FunctionBinding<GUIMEVehicle, int>(this, &GUIMEVehicle::getContainerNumber));
125  // meso specific values
126  ret->mkItem("event time [s]", true, new FunctionBinding<GUIMEVehicle, double>(this, &MEVehicle::getEventTimeSeconds));
127  ret->mkItem("entry time [s]", true, new FunctionBinding<GUIMEVehicle, double>(this, &MEVehicle::getLastEntryTimeSeconds));
128  ret->mkItem("block time [s]", true, new FunctionBinding<GUIMEVehicle, double>(this, &MEVehicle::getBlockTimeSeconds));
130  // close building
131  ret->closeBuilding(&getParameter());
132  return ret;
133 }
134 
135 
140  new GUIParameterTableWindow(app, *this, 9 + (int)myType->getParameter().getMap().size());
141  // add items
142  ret->mkItem("Type Information:", false, "");
143  ret->mkItem("type [id]", false, myType->getID());
144  ret->mkItem("length", false, myType->getLength());
145  ret->mkItem("minGap", false, myType->getMinGap());
146  ret->mkItem("vehicle class", false, SumoVehicleClassStrings.getString(myType->getVehicleClass()));
147  ret->mkItem("emission class", false, PollutantsInterface::getName(myType->getEmissionClass()));
148  ret->mkItem("maximum speed [m/s]", false, getMaxSpeed());
149  //ret->mkItem("maximum acceleration [m/s^2]", false, getCarFollowModel().getMaxAccel());
150  //ret->mkItem("maximum deceleration [m/s^2]", false, getCarFollowModel().getMaxDecel());
151  //ret->mkItem("imperfection (sigma)", false, getCarFollowModel().getImperfection());
152  //ret->mkItem("desired headway (tau)", false, getCarFollowModel().getHeadwayTime());
153  ret->mkItem("person capacity", false, myType->getPersonCapacity());
154  ret->mkItem("container capacity", false, myType->getContainerCapacity());
155  // close building
156  ret->closeBuilding(&(myType->getParameter()));
157  return ret;
158 }
159 
160 
161 bool
162 GUIMEVehicle::drawAction_drawCarriageClass(const GUIVisualizationSettings& /* s */, SUMOVehicleShape /* guiShape */, bool /* asImage */) const {
164  return true;
165 }
166 
167 
168 double
169 GUIMEVehicle::getColorValue(int activeScheme) const {
170  switch (activeScheme) {
171  case 8:
172  return getSpeed();
173  case 9:
174  return getWaitingSeconds();
175  case 11:
176  return 0; // invalid getLastLaneChangeOffset();
177  case 12:
178  return getSegment()->getEdge().getVehicleMaxSpeed(this);
179  case 13:
180  return 0; // invalid getCO2Emissions();
181  case 14:
182  return 0; // invalid getCOEmissions();
183  case 15:
184  return 0; // invalid getPMxEmissions();
185  case 16:
186  return 0; // invalid getNOxEmissions();
187  case 17:
188  return 0; // invalid getHCEmissions();
189  case 18:
190  return 0; // invalid getFuelConsumption();
191  case 19:
192  return 0; // invalid getHarmonoise_NoiseEmissions();
193  case 20: // !!! unused!?
194  if (getNumberReroutes() == 0) {
195  return -1;
196  }
197  return getNumberReroutes();
198  case 21:
200  case 22:
201  return 0; // invalid getBestLaneOffset();
202  case 23:
203  return 0; // invalid getAcceleration();
204  case 24:
205  return 0; // invalid getTimeGapOnLane();
206  case 25:
207  return STEPS2TIME(getDepartDelay());
208  }
209  return 0;
210 }
211 
212 
213 
214 void
216  const double exaggeration = s.vehicleSize.getExaggeration(s);
217  MSRouteIterator i = 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 
247 void
249  // @todo possibly we could compute something reasonable here
250 }
251 /****************************************************************************/
252 
void drawAction_drawVehicleAsBoxPlus() const
const std::vector< double > & getShapeRotations() const
Definition: GUILane.cpp:830
double getMinGap() const
Get the free space in front of vehicles of this class.
bool isParking() const
Returns whether the vehicle is parking.
Definition: MEVehicle.cpp:174
SUMOVehicleClass getVehicleClass() const
Get this vehicle type&#39;s vehicle class.
void closeBuilding(const Parameterised *p=0)
Closes the building of the table.
A vehicle from the mesoscopic point of view.
Definition: MEVehicle.h:51
void drawRouteHelper(const GUIVisualizationSettings &s, const MSRoute &r) const
Draws the route.
double getMaxSpeed() const
Returns the maximum speed.
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:183
a vehicles
Stores the information about how to visualize structures.
double getChosenSpeedFactor() const
Returns the precomputed factor by which the driver wants to be faster than the speed limit...
double getNaviDegree() const
return the current angle in navigational degrees
std::string time2string(SUMOTime t)
Definition: SUMOTime.cpp:59
int getNumberReroutes() const
Returns the number of new routes this vehicle got.
double getColorValue(int activeScheme) const
gets the color value according to the current scheme index
GUIParameterTableWindow * getTypeParameterWindow(GUIMainWindow &app, GUISUMOAbstractView &parent)
Returns an own type parameter window.
double getPositionOnLane() const
Get the vehicle&#39;s position along the lane.
Definition: MEVehicle.cpp:80
bool isSelected(GUIGlObjectType type, GUIGlID id)
Returns the information whether the object with the given type and id is selected.
const std::map< std::string, std::string > & getMap() const
Returns the inner key/value map.
double getSpeed() const
Returns the vehicle&#39;s estimated speed assuming no delays.
Definition: MEVehicle.cpp:109
const SUMOVehicleParameter * myParameter
This vehicle&#39;s parameter.
The base class for microscopic and mesoscopic vehicles.
Definition: MSBaseVehicle.h:55
double getLastEntryTimeSeconds() const
Returns the entry time for the current segment.
Definition: MEVehicle.h:303
const MSEdge & getEdge() const
Returns the edge this segment belongs to.
Definition: MESegment.h:270
double getWaitingSeconds() const
Returns the number of seconds waited (speed was lesser than 0.1m/s)
Definition: MEVehicle.h:292
GUIGlID getGlID() const
Returns the numerical id of the object.
The car-following model and parameter.
Definition: MSVehicleType.h:72
int getPersonCapacity() const
Get this vehicle type&#39;s person capacity.
const std::vector< double > & getShapeLengths() const
Definition: GUILane.cpp:836
Representation of a lane in the micro simulation (gui-version)
Definition: GUILane.h:69
double getBlockTimeSeconds() const
Returns the time at which the vehicle was blocked on the current segment.
Definition: MEVehicle.h:308
GUIParameterTableWindow * getParameterWindow(GUIMainWindow &app, GUISUMOAbstractView &parent)
Returns an own parameter window.
double getVehicleMaxSpeed(const SUMOVehicle *const veh) const
Returns the maximum speed the vehicle may use on this edge.
Definition: MSEdge.cpp:858
bool isStopped() const
Returns whether the vehicle is at a stop.
Definition: MEVehicle.cpp:234
double getExaggeration(const GUIVisualizationSettings &s, double factor=20) const
return the drawing size including exaggeration and constantSize values
const SUMOVTypeParameter & getParameter() const
double getLastLaneChangeOffset() const
Returns the time since the last lane change in seconds.
SUMOTime getDepartDelay() const
Returns the depart delay.
~GUIMEVehicle()
destructor
ConstMSEdgeVector::const_iterator MSRouteIterator
Definition: MSRoute.h:64
#define STEPS2TIME(x)
Definition: SUMOTime.h:64
A MSVehicle extended by some values for usage within the gui.
static std::string getName(const SUMOEmissionClass c)
Checks whether the string describes a known vehicle class.
StringBijection< SUMOVehicleClass > SumoVehicleClassStrings(sumoVehicleClassStringInitializer, SVC_CUSTOM2, false)
std::string line
The vehicle&#39;s line (mainly for public transport)
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 ...
std::string getStopInfo() const
retrieve information about the current stop state
double getLength() const
Get vehicle&#39;s length [m].
double getEventTimeSeconds() const
Returns the earliest leave time for the current segment.
Definition: MEVehicle.h:298
Structure representing possible vehicle parameter.
MSRouteIterator end() const
Returns the end of the list of edges to pass.
Definition: MSRoute.cpp:79
SUMOVehicleShape
Definition of vehicle classes to differ between different appearences.
void selectBlockingFoes() const
adds the blocking foes to the current selection
MSVehicleType * myType
This vehicle&#39;s type.
const std::string & getID() const
Returns the name of the vehicle type.
const SUMOVehicleParameter & getParameter() const
Returns the vehicle&#39;s parameter (including departure definition)
GUIVisualizationSizeSettings vehicleSize
double getCurrentLinkPenaltySeconds() const
Returns the delay that is accrued due to option –meso-tls-penalty or –meso-minor-penalty.
Definition: MEVehicle.cpp:278
int getContainerCapacity() const
Get this vehicle type&#39;s container capacity.
const MSEdge * getEdge() const
Returns the edge the vehicle is currently at.
SUMOEmissionClass getEmissionClass() const
Get this vehicle type&#39;s emission class.
GUIMEVehicle(SUMOVehicleParameter *pars, const MSRoute *route, MSVehicleType *type, const double speedFactor)
Constructor.
void mkItem(const char *name, bool dynamic, ValueSource< unsigned > *src)
Adds a row which obtains its value from an unsigned-ValueSource.
GUISelectedStorage gSelected
A global holder of selected objects.
std::vector< MSDevice * > myDevices
The devices this vehicle has.
A window containing a gl-object&#39;s parameter.
MESegment * getSegment() const
Returns the current segment the vehicle is on.
Definition: MEVehicle.h:229
MSRouteIterator begin() const
Returns the begin of the list of edges to pass.
Definition: MSRoute.cpp:73
const std::string & getID() const
Returns the name of the vehicle.
const PositionVector & getShape() const
Definition: GUILane.cpp:824