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-2020 German Aerospace Center (DLR) and others.
4 // This program and the accompanying materials are made available under the
5 // terms of the Eclipse Public License 2.0 which is available at
6 // https://www.eclipse.org/legal/epl-2.0/
7 // This Source Code may also be made available under the following Secondary
8 // Licenses when the conditions for such availability set forth in the Eclipse
9 // Public License 2.0 are satisfied: GNU General Public License, version 2
10 // or later which is available at
11 // https://www.gnu.org/licenses/old-licenses/gpl-2.0-standalone.html
12 // SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-or-later
13 /****************************************************************************/
20 // A MSVehicle extended by some values for usage within the gui
21 /****************************************************************************/
22 #include <config.h>
23 
25 #include <utils/gui/div/GLHelper.h>
34 #include <guisim/GUILane.h>
35 
36 #include "GUIMEVehicle.h"
37 
38 
39 // ===========================================================================
40 // method definitions
41 // ===========================================================================
42 #ifdef _MSC_VER
43 #pragma warning(push)
44 #pragma warning(disable: 4355)
45 #endif
47  MSVehicleType* type, const double speedFactor) :
48  MEVehicle(pars, route, type, speedFactor),
49  GUIBaseVehicle((MSBaseVehicle&) * this) {
50 }
51 #ifdef _MSC_VER
52 #pragma warning(pop)
53 #endif
54 
55 
57 
58 
62  GUIParameterTableWindow* ret = new GUIParameterTableWindow(app, *this);
63  // add items
64  ret->mkItem("edge [id]", true, new FunctionBindingString<GUIMEVehicle>(this, &GUIMEVehicle::getEdgeID));
65  ret->mkItem("segment [#]", true, new FunctionBinding<GUIMEVehicle, int>(this, &GUIMEVehicle::getSegmentIndex));
66  ret->mkItem("queue [#]", true, new FunctionBinding<GUIMEVehicle, int>(this, &GUIMEVehicle::getQueIndex));
67  ret->mkItem("position [m]", true, new FunctionBinding<GUIMEVehicle, double>(this, &MEVehicle::getPositionOnLane));
68  ret->mkItem("speed [m/s]", true, new FunctionBinding<GUIMEVehicle, double>(this, &MEVehicle::getSpeed));
69  ret->mkItem("angle [degree]", true, new FunctionBinding<GUIMEVehicle, double>(this, &GUIBaseVehicle::getNaviDegree));
70  ret->mkItem("waiting time [s]", true,
72  ret->mkItem("speed factor", false, getChosenSpeedFactor());
73  //ret->mkItem("time gap [s]", true,
74  // new FunctionBinding<GUIMEVehicle, double>(this, &MSVehicle::getTimeGap));
75  //ret->mkItem("waiting time [s]", true,
76  // new FunctionBinding<GUIMEVehicle, double>(this, &MSVehicle::getWaitingSeconds));
77  //ret->mkItem("impatience", true,
78  // new FunctionBinding<GUIMEVehicle, double>(this, &MSVehicle::getImpatience));
79  //ret->mkItem("last lane change [s]", true,
80  // new FunctionBinding<GUIMEVehicle, double>(this, &GUIMEVehicle::getLastLaneChangeOffset));
81  ret->mkItem("desired depart [s]", false, time2string(getParameter().depart));
82  ret->mkItem("depart delay [s]", false, time2string(getDepartDelay()));
83  ret->mkItem("odometer [m]", true,
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, getDeviceDescription());
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 
130  GUIParameterTableWindow* ret = new GUIParameterTableWindow(app, *this);
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, bool noLoop, const RGBColor& /*col*/) const {
215  const double exaggeration = s.vehicleSize.getExaggeration(s, this);
216  MSRouteIterator start = future ? myCurrEdge : r.begin();
217  MSRouteIterator i = start;
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  if (noLoop && i != start && (*i) == (*start)) {
223  break;
224  }
225  }
226 }
227 
228 
229 double
231  // @todo possibly we could compute something reasonable here
232  return 0;
233 }
234 
235 
236 std::string
238  std::string result = "";
239  if (isParking()) {
240  result += "parking";
241  } else if (isStopped()) {
242  result += "stopped";
243  } else {
244  return "";
245  }
246  return result;
247 }
248 
249 std::string
251  return getEdge()->getID();
252 }
253 
254 int
256  return getSegment() != nullptr ? getSegment()->getIndex() : -1;
257 }
258 
259 
260 void
262  // @todo possibly we could compute something reasonable here
263 }
264 
265 Boundary
267  // getPosition returns the start of the first laneso we do not use it here
268  getEdge()->lock();
269  const MSLane* const lane = getEdge()->getLanes()[getQueIndex()];
270  double offset = 0;
271  if (getSegment() != nullptr) {
272  offset = getSegment()->getLength();
273  auto queue = getSegment()->getQueue(getQueIndex());
274  for (int i = queue.size() - 1; i >= 0 && queue[i] != this; i--) {
275  offset -= queue[i]->getVehicleType().getLengthWithGap();
276  }
277  }
278  getEdge()->unlock();
279  Position pos = lane->geometryPositionAtOffset(getPositionOnLane() + offset);
280  Boundary b;
281  b.add(pos);
283  return b;
284 }
285 
286 /****************************************************************************/
@ GLO_VEHICLE
a vehicle
GUISelectedStorage gSelected
A global holder of selected objects.
ConstMSEdgeVector::const_iterator MSRouteIterator
Definition: MSRoute.h:54
std::string time2string(SUMOTime t)
convert SUMOTime to string
Definition: SUMOTime.cpp:68
#define STEPS2TIME(x)
Definition: SUMOTime.h:53
StringBijection< SUMOVehicleClass > SumoVehicleClassStrings(sumoVehicleClassStringInitializer, SVC_CUSTOM2, false)
A class that stores a 2D geometrical boundary.
Definition: Boundary.h:39
void add(double x, double y, double z=0)
Makes the boundary include the given coordinate.
Definition: Boundary.cpp:77
Boundary & grow(double by)
extends the boundary by the given amount
Definition: Boundary.cpp:299
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:181
static void drawAction_drawVehicleAsBoxPlus(const double width, const double length)
draw vehicle as a Box
A MSVehicle extended by some values for usage within the gui.
double getNaviDegree() const
return the current angle in navigational degrees
std::string getDeviceDescription()
lists equipped device (types) for the current vehicle
const MSVehicleType & getVType() const
A shortcut to myVehicle.myType.
GUIGlID getGlID() const
Returns the numerical id of the object.
Representation of a lane in the micro simulation (gui-version)
Definition: GUILane.h:59
const PositionVector & getShape() const
Definition: GUILane.cpp:919
const std::vector< double > & getShapeLengths() const
Definition: GUILane.cpp:931
const std::vector< double > & getShapeRotations() const
Definition: GUILane.cpp:925
void drawAction_drawCarriageClass(const GUIVisualizationSettings &s, bool asImage) const
draws the given guiShape with distinct carriages/modules
std::string getStopInfo() const
retrieve information about the current stop state
GUIMEVehicle(SUMOVehicleParameter *pars, const MSRoute *route, MSVehicleType *type, const double speedFactor)
Constructor.
int getSegmentIndex() const
~GUIMEVehicle()
destructor
GUIParameterTableWindow * getParameterWindow(GUIMainWindow &app, GUISUMOAbstractView &parent)
Returns an own parameter window.
virtual Boundary getCenteringBoundary() const
Returns the boundary to which the view shall be centered in order to show the object.
GUIParameterTableWindow * getTypeParameterWindow(GUIMainWindow &app, GUISUMOAbstractView &parent)
Returns an own type parameter window.
double getLastLaneChangeOffset() const
Returns the time since the last lane change in seconds.
void selectBlockingFoes() const
adds the blocking foes to the current selection
double getColorValue(const GUIVisualizationSettings &s, int activeScheme) const
gets the color value according to the current scheme index
std::string getEdgeID() const
void drawRouteHelper(const GUIVisualizationSettings &s, const MSRoute &r, bool future, bool noLoop, const RGBColor &col) const
Draws the route.
A window containing a gl-object's parameter.
void mkItem(const char *name, bool dynamic, ValueSource< T > *src)
Adds a row which obtains its value from a ValueSource.
void closeBuilding(const Parameterised *p=0)
Closes the building of the table.
bool isSelected(GUIGlObjectType type, GUIGlID id)
Returns the information whether the object with the given type and id is selected.
Stores the information about how to visualize structures.
GUIVisualizationSizeSettings vehicleSize
const std::vector< MEVehicle * > & getQueue(int index) const
Returns the cars in the queue with the given index for visualization.
Definition: MESegment.h:191
double getLength() const
Returns the length of the segment in meters.
Definition: MESegment.h:216
const MSEdge & getEdge() const
Returns the edge this segment belongs to.
Definition: MESegment.h:325
int getIndex() const
Returns the running index of the segment in the edge (0 is the most upstream).
Definition: MESegment.h:200
A vehicle from the mesoscopic point of view.
Definition: MEVehicle.h:42
double getLastEntryTimeSeconds() const
Returns the entry time for the current segment.
Definition: MEVehicle.h:316
double getBlockTimeSeconds() const
Returns the time at which the vehicle was blocked on the current segment.
Definition: MEVehicle.h:321
double getCurrentStoppingTimeSeconds() const
Returns the delay that is accrued due to option –meso-tls-penalty or –meso-minor-penalty.
Definition: MEVehicle.cpp:235
double getWaitingSeconds() const
Returns the number of seconds waited (speed was lesser than 0.1m/s)
Definition: MEVehicle.h:305
double getPositionOnLane() const
Get the vehicle's position along the lane.
Definition: MEVehicle.cpp:78
MESegment * getSegment() const
Returns the current segment the vehicle is on.
Definition: MEVehicle.h:237
int getQueIndex() const
Returns the index of the que the vehicle is in.
Definition: MEVehicle.h:245
double getCurrentLinkPenaltySeconds() const
Returns the delay that is accrued due to option –meso-tls-penalty or –meso-minor-penalty.
Definition: MEVehicle.cpp:295
double getSpeed() const
Returns the vehicle's estimated speed assuming no delays.
Definition: MEVehicle.cpp:107
double getEventTimeSeconds() const
Returns the earliest leave time for the current segment.
Definition: MEVehicle.h:311
The base class for microscopic and mesoscopic vehicles.
Definition: MSBaseVehicle.h:51
double getMaxSpeed() const
Returns the maximum speed.
MSVehicleType * myType
This vehicle's type.
const SUMOVehicleParameter & getParameter() const
Returns the vehicle's parameter (including departure definition)
double getChosenSpeedFactor() const
Returns the precomputed factor by which the driver wants to be faster than the speed limit.
double getOdometer() const
Returns the distance that was already driven by this vehicle.
double getLength() const
Returns the vehicle's length.
bool isParking() const
Returns whether the vehicle is parking.
const MSEdge * getEdge() const
Returns the edge the vehicle is currently at.
MSRouteIterator myCurrEdge
Iterator to current route-edge.
double getWidth() const
Returns the vehicle's width.
const MSVehicleType & getVehicleType() const
Returns the vehicle's type definition.
SUMOTime getDepartDelay() const
Returns the depart delay.
const SUMOVehicleParameter * myParameter
This vehicle's parameter.
int getNumberReroutes() const
Returns the number of new routes this vehicle got.
bool isStopped() const
Returns whether the vehicle is at a stop.
virtual void unlock() const
release exclusive access to the mesoscopic state
Definition: MSEdge.h:724
const std::vector< MSLane * > & getLanes() const
Returns this edge's lanes.
Definition: MSEdge.h:166
double getVehicleMaxSpeed(const SUMOTrafficObject *const veh) const
Returns the maximum speed the vehicle may use on this edge.
Definition: MSEdge.cpp:931
virtual void lock() const
grant exclusive access to the mesoscopic state
Definition: MSEdge.h:721
Representation of a lane in the micro simulation.
Definition: MSLane.h:82
const Position geometryPositionAtOffset(double offset, double lateralOffset=0) const
Definition: MSLane.h:503
MSRouteIterator end() const
Returns the end of the list of edges to pass.
Definition: MSRoute.cpp:75
MSRouteIterator begin() const
Returns the begin of the list of edges to pass.
Definition: MSRoute.cpp:69
The car-following model and parameter.
Definition: MSVehicleType.h:62
SUMOVehicleClass getVehicleClass() const
Get this vehicle type's vehicle class.
int getPersonCapacity() const
Get this vehicle type's person capacity.
double getMinGap() const
Get the free space in front of vehicles of this class.
SUMOEmissionClass getEmissionClass() const
Get this vehicle type's emission class.
const std::string & getID() const
Returns the name of the vehicle type.
Definition: MSVehicleType.h:90
double getLength() const
Get vehicle's length [m].
const SUMOVTypeParameter & getParameter() const
int getContainerCapacity() const
Get this vehicle type's container capacity.
const std::string & getID() const
Returns the id.
Definition: Named.h:73
static std::string getName(const SUMOEmissionClass c)
Checks whether the string describes a known vehicle class.
A point in 2D or 3D with translation and scaling methods.
Definition: Position.h:36
Structure representing possible vehicle parameter.
std::string line
The vehicle's line (mainly for public transport)
double getExaggeration(const GUIVisualizationSettings &s, const GUIGlObject *o, double factor=20) const
return the drawing size including exaggeration and constantSize values