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-2022 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
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/* Disable warning about using "this" in the constructor */
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 // add items
65 ret->mkItem("edge [id]", true, new FunctionBindingString<GUIMEVehicle>(this, &GUIMEVehicle::getEdgeID));
66 ret->mkItem("segment [#]", true, new FunctionBinding<GUIMEVehicle, int>(this, &GUIMEVehicle::getSegmentIndex));
67 ret->mkItem("queue [#]", true, new FunctionBinding<GUIMEVehicle, int>(this, &GUIMEVehicle::getQueIndex));
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 ret->mkItem("odometer [m]", true,
86 if (getParameter().repetitionNumber < std::numeric_limits<int>::max()) {
87 ret->mkItem("remaining [#]", false, (int) getParameter().repetitionNumber - getParameter().repetitionsDone);
88 }
89 if (getParameter().repetitionOffset > 0) {
90 ret->mkItem("insertion period [s]", false, time2string(getParameter().repetitionOffset));
91 }
92 if (getParameter().repetitionProbability > 0) {
93 ret->mkItem("insertion probability", false, getParameter().repetitionProbability);
94 }
95 //ret->mkItem("stop info", false, getStopInfo());
96 ret->mkItem("line", false, myParameter->line);
97 //ret->mkItem("CO2 [mg/s]", true,
98 // new FunctionBinding<GUIMEVehicle, double>(this, &GUIMEVehicle::getCO2Emissions));
99 //ret->mkItem("CO [mg/s]", true,
100 // new FunctionBinding<GUIMEVehicle, double>(this, &GUIMEVehicle::getCOEmissions));
101 //ret->mkItem("HC [mg/s]", true,
102 // new FunctionBinding<GUIMEVehicle, double>(this, &GUIMEVehicle::getHCEmissions));
103 //ret->mkItem("NOx [mg/s]", true,
104 // new FunctionBinding<GUIMEVehicle, double>(this, &GUIMEVehicle::getNOxEmissions));
105 //ret->mkItem("PMx [mg/s]", true,
106 // new FunctionBinding<GUIMEVehicle, double>(this, &GUIMEVehicle::getPMxEmissions));
107 //ret->mkItem("fuel [ml/s]", true,
108 // new FunctionBinding<GUIMEVehicle, double>(this, &GUIMEVehicle::getFuelConsumption));
109 //ret->mkItem("noise (Harmonoise) [dB]", true,
110 // new FunctionBinding<GUIMEVehicle, double>(this, &GUIMEVehicle::getHarmonoise_NoiseEmissions));
111 ret->mkItem("devices", false, getDeviceDescription());
112 //ret->mkItem("persons", true,
113 // new FunctionBinding<GUIMEVehicle, int>(this, &GUIMEVehicle::getPersonNumber));
114 //ret->mkItem("containers", true,
115 // new FunctionBinding<GUIMEVehicle, int>(this, &GUIMEVehicle::getContainerNumber));
116 // meso specific values
117 ret->mkItem("event time [s]", true, new FunctionBinding<GUIMEVehicle, double>(this, &MEVehicle::getEventTimeSeconds));
119 ret->mkItem("block time [s]", true, new FunctionBinding<GUIMEVehicle, double>(this, &MEVehicle::getBlockTimeSeconds));
122 // close building
124 return ret;
125}
126
127
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
148 return ret;
149}
150
151
152void
155}
156
157
158double
159GUIMEVehicle::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 getEmissions<PollutantsInterface::CO2>();
175 case 15:
176 return 0; // invalid getEmissions<PollutantsInterface::CO>();
177 case 16:
178 return 0; // invalid getEmissions<PollutantsInterface::PM_X>();
179 case 17:
180 return 0; // invalid getEmissions<PollutantsInterface::NO_X>();
181 case 18:
182 return 0; // invalid getEmissions<PollutantsInterface::HC>();
183 case 19:
184 return 0; // invalid getEmissions<PollutantsInterface::FUEL>();
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
214void
215GUIMEVehicle::drawRouteHelper(const GUIVisualizationSettings& s, const MSRoute& r, bool future, bool noLoop, const RGBColor& col) const {
216 const double exaggeration = getExaggeration(s);
217 MSRouteIterator start = future ? myCurrEdge : r.begin();
218 MSRouteIterator i = start;
219 std::map<const MSLane*, int> repeatLane; // count repeated occurrences of the same edge
220 const double textSize = s.vehicleName.size / s.scale;
221 const int indexDigits = (int)toString(r.size()).size();
222 for (; i != r.end(); ++i) {
223 const GUILane* lane = static_cast<GUILane*>((*i)->getLanes()[0]);
224 GLHelper::drawBoxLines(lane->getShape(), lane->getShapeRotations(), lane->getShapeLengths(), exaggeration);
225 if (s.showRouteIndex) {
226 std::string label = toString((int)(i - myCurrEdge));
227 const double laneAngle = lane->getShape().angleAt2D(0);
228 Position pos = lane->getShape().front() - Position(0, textSize * repeatLane[lane]) + Position(
229 (laneAngle >= -0.25 * M_PI && laneAngle < 0.75 * M_PI ? 1 : -1) * 0.4 * indexDigits * textSize, 0);
230 //GLHelper::drawText(label, pos, 1.0, textSize, s.vehicleName.color);
231 GLHelper::drawTextSettings(s.vehicleName, label, pos, s.scale, s.angle, 1.0);
232 }
233 if (noLoop && i != start && (*i) == (*start)) {
234 break;
235 }
236 repeatLane[lane]++;
237 }
238 drawStopLabels(s, noLoop, col);
239 drawParkingInfo(s, col);
240}
241
242
243double
245 // @todo possibly we could compute something reasonable here
246 return 0;
247}
248
249
250std::string
252 std::string result = "";
253 if (isParking()) {
254 result += "parking";
255 } else if (isStopped()) {
256 result += "stopped";
257 } else {
258 return "";
259 }
260 return result;
261}
262
263std::string
265 return getEdge()->getID();
266}
267
268int
270 return getSegment() != nullptr ? getSegment()->getIndex() : -1;
271}
272
273
274void
276 // @todo possibly we could compute something reasonable here
277}
278
279
280double
282 return s.vehicleSize.getExaggeration(s, this);
283}
284
285
288 // getPosition returns the start of the first lane, so we do not use it here
289 getEdge()->lock();
290 const double curTime = SIMTIME;
291 double vehiclePosition = 0.;
292 const MESegment* const segment = getSegment();
293 const int queIdx = getQueIndex();
294 if (segment != nullptr && queIdx != MESegment::PARKING_QUEUE) {
295 vehiclePosition = segment->getLength();
296 const std::vector<MEVehicle*>& queue = segment->getQueue(queIdx);
297 for (auto it = queue.rbegin(); it != queue.rend(); ++it) {
298 const MEVehicle* const v = *it;
299 const double intendedLeave = MIN2(v->getEventTimeSeconds(), v->getBlockTimeSeconds());
300 const double entry = v->getLastEntryTimeSeconds();
301 const double offset = segment->getLength() * (curTime - entry) / (intendedLeave - entry);
302 if (offset < vehiclePosition) {
303 vehiclePosition = offset;
304 }
305 if (v == this) {
306 break;
307 }
308 vehiclePosition -= v->getVehicleType().getLengthWithGap();
309 }
310 }
311 Boundary b;
312 const MSLane* const lane = getEdge()->getLanes()[queIdx == MESegment::PARKING_QUEUE ? 0 : queIdx];
313 b.add(lane->geometryPositionAtOffset(getPositionOnLane() + vehiclePosition));
315 getEdge()->unlock();
316 return b;
317}
318
319
320/****************************************************************************/
@ 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:54
#define SIMTIME
Definition: SUMOTime.h:61
StringBijection< SUMOVehicleClass > SumoVehicleClassStrings(sumoVehicleClassStringInitializer, SVC_CUSTOM2, false)
T MIN2(T a, T b)
Definition: StdDefs.h:71
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
Definition: ToString.h:46
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:78
Boundary & grow(double by)
extends the boundary by the given amount
Definition: Boundary.cpp:300
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:329
static void drawTextSettings(const GUIVisualizationTextSettings &settings, const std::string &text, const Position &pos, const double scale, const double angle=0, const double layer=2048, const int align=0)
Definition: GLHelper.cpp:716
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.
void drawParkingInfo(const GUIVisualizationSettings &s, const RGBColor &col) const
double getNaviDegree() const
return the current angle in navigational degrees
void drawStopLabels(const GUIVisualizationSettings &s, bool noLoop, const RGBColor &col) const
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.
Definition: GUIGlObject.h:102
Representation of a lane in the micro simulation (gui-version)
Definition: GUILane.h:60
const PositionVector & getShape() const
Definition: GUILane.cpp:1009
const std::vector< double > & getShapeLengths() const
Definition: GUILane.cpp:1021
const std::vector< double > & getShapeRotations() const
Definition: GUILane.cpp:1015
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.
double getExaggeration(const GUIVisualizationSettings &s) const
return exaggeration associated with this GLObject
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.
GUIVisualizationTextSettings vehicleName
GUIVisualizationSizeSettings vehicleSize
double scale
information about a lane's width (temporary, used for a single view)
bool showRouteIndex
Information whether the route index should be shown.
double angle
The current view rotation angle.
A single mesoscopic segment (cell)
Definition: MESegment.h:49
static const int PARKING_QUEUE
Definition: MESegment.h:52
double getLength() const
Returns the length of the segment in meters.
Definition: MESegment.h:231
const std::vector< MEVehicle * > & getQueue(int index) const
Returns the cars in the queue with the given index for visualization.
Definition: MESegment.h:206
const MSEdge & getEdge() const
Returns the edge this segment belongs to.
Definition: MESegment.h:348
int getIndex() const
Returns the running index of the segment in the edge (0 is the most upstream).
Definition: MESegment.h:215
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:313
double getBlockTimeSeconds() const
Returns the time at which the vehicle was blocked on the current segment.
Definition: MEVehicle.h:318
double getCurrentStoppingTimeSeconds() const
Returns the delay that is accrued due to option –meso-tls-penalty or –meso-minor-penalty.
Definition: MEVehicle.cpp:296
double getPositionOnLane() const
Get the vehicle's position along the lane.
Definition: MEVehicle.cpp:79
MESegment * getSegment() const
Returns the current segment the vehicle is on.
Definition: MEVehicle.h:239
int getQueIndex() const
Returns the index of the que the vehicle is in.
Definition: MEVehicle.h:247
double getCurrentLinkPenaltySeconds() const
Returns the delay that is accrued due to option –meso-tls-penalty or –meso-minor-penalty.
Definition: MEVehicle.cpp:406
double getSpeed() const
Returns the vehicle's estimated speed assuming no delays.
Definition: MEVehicle.cpp:108
double getEventTimeSeconds() const
Returns the earliest leave time for the current segment.
Definition: MEVehicle.h:308
The base class for microscopic and mesoscopic vehicles.
Definition: MSBaseVehicle.h:55
double getMaxSpeed() const
Returns the maximum speed (the minimum of desired and technical 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.
double getWaitingSeconds() const
Returns the number of seconds waited (speed was lesser than 0.1m/s)
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.
const MSVehicleType & getVehicleType() const
Returns the vehicle's type definition.
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:747
const std::vector< MSLane * > & getLanes() const
Returns this edge's lanes.
Definition: MSEdge.h:168
double getVehicleMaxSpeed(const SUMOTrafficObject *const veh) const
Returns the maximum speed the vehicle may use on this edge.
Definition: MSEdge.cpp:1068
virtual void lock() const
grant exclusive access to the mesoscopic state
Definition: MSEdge.h:744
Representation of a lane in the micro simulation.
Definition: MSLane.h:84
const Position geometryPositionAtOffset(double offset, double lateralOffset=0) const
Definition: MSLane.h:533
int size() const
Returns the number of edges to pass.
Definition: MSRoute.cpp:86
MSRouteIterator end() const
Returns the end of the list of edges to pass.
Definition: MSRoute.cpp:80
MSRouteIterator begin() const
Returns the begin of the list of edges to pass.
Definition: MSRoute.cpp:74
The car-following model and parameter.
Definition: MSVehicleType.h:63
double getLengthWithGap() const
Get vehicle's length including the minimum gap [m].
SUMOVehicleClass getVehicleClass() const
Get this vehicle type's vehicle class.
int getPersonCapacity() const
Get this vehicle type's person capacity.
const std::string & getID() const
Returns the name of the vehicle type.
Definition: MSVehicleType.h:91
double getMinGap() const
Get the free space in front of vehicles of this class.
SUMOEmissionClass getEmissionClass() const
Get this vehicle type's emission class.
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:74
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:37
double angleAt2D(int pos) const
get angle in certain position of position vector
Structure representing possible vehicle parameter.
std::string line
The vehicle's line (mainly for public transport)
#define M_PI
Definition: odrSpiral.cpp:45
double getExaggeration(const GUIVisualizationSettings &s, const GUIGlObject *o, double factor=20) const
return the drawing size including exaggeration and constantSize values