Eclipse SUMO - Simulation of Urban MObility
Loading...
Searching...
No Matches
GUIMEVehicle.cpp
Go to the documentation of this file.
1/****************************************************************************/
2// Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo
3// Copyright (C) 2001-2024 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
44 MSVehicleType* type, const double speedFactor) :
45 MEVehicle(pars, route, type, speedFactor),
46 GUIBaseVehicle((MSBaseVehicle&) * this) {
47}
48
49
51
52
57 // add items
58 ret->mkItem("edge [id]", true, new FunctionBindingString<GUIMEVehicle>(this, &GUIMEVehicle::getEdgeID));
59 ret->mkItem("segment [#]", true, new FunctionBinding<GUIMEVehicle, int>(this, &GUIMEVehicle::getSegmentIndex));
60 ret->mkItem("queue [#]", true, new FunctionBinding<GUIMEVehicle, int>(this, &GUIMEVehicle::getQueIndex));
62 ret->mkItem("speed [m/s]", true, new FunctionBinding<GUIMEVehicle, double>(this, &MEVehicle::getSpeed));
63 ret->mkItem("angle [degree]", true, new FunctionBinding<GUIMEVehicle, double>(this, &GUIBaseVehicle::getNaviDegree));
64 ret->mkItem("waiting time [s]", true,
66 ret->mkItem("speed factor", false, getChosenSpeedFactor());
67 //ret->mkItem("time gap [s]", true,
68 // new FunctionBinding<GUIMEVehicle, double>(this, &MSVehicle::getTimeGap));
69 //ret->mkItem("waiting time [s]", true,
70 // new FunctionBinding<GUIMEVehicle, double>(this, &MSVehicle::getWaitingSeconds));
71 //ret->mkItem("impatience", true,
72 // new FunctionBinding<GUIMEVehicle, double>(this, &MSVehicle::getImpatience));
73 //ret->mkItem("last lane change [s]", true,
74 // new FunctionBinding<GUIMEVehicle, double>(this, &GUIMEVehicle::getLastLaneChangeOffset));
75 ret->mkItem("desired depart [s]", false, time2string(getParameter().depart));
76 ret->mkItem("depart delay [s]", false, time2string(getDepartDelay()));
77 ret->mkItem("odometer [m]", true,
79 if (getParameter().repetitionNumber < std::numeric_limits<int>::max()) {
80 ret->mkItem("remaining [#]", false, (int) getParameter().repetitionNumber - getParameter().repetitionsDone);
81 }
82 if (getParameter().repetitionOffset > 0) {
83 ret->mkItem("insertion period [s]", false, time2string(getParameter().repetitionOffset));
84 }
85 if (getParameter().repetitionProbability > 0) {
86 ret->mkItem("insertion probability", false, getParameter().repetitionProbability);
87 }
88 if (getParameter().poissonRate > 0) {
89 ret->mkItem(TL("poisson rate"), false, getParameter().poissonRate);
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 ret->mkItem("devices", false, getDeviceDescription());
108 //ret->mkItem("persons", true,
109 // new FunctionBinding<GUIMEVehicle, int>(this, &GUIMEVehicle::getPersonNumber));
110 //ret->mkItem("containers", true,
111 // new FunctionBinding<GUIMEVehicle, int>(this, &GUIMEVehicle::getContainerNumber));
112 // meso specific values
113 ret->mkItem("event time [s]", true, new FunctionBinding<GUIMEVehicle, double>(this, &MEVehicle::getEventTimeSeconds));
115 ret->mkItem("block time [s]", true, new FunctionBinding<GUIMEVehicle, double>(this, &MEVehicle::getBlockTimeSeconds));
118 // close building
120 return ret;
121}
122
123
126 GUIParameterTableWindow* ret = new GUIParameterTableWindow(app, *this, "vType:" + myType->getID());
127 ret->mkItem("length [m]", false, myType->getLength());
128 ret->mkItem("width [m]", false, myType->getWidth());
129 ret->mkItem("height [m]", false, myType->getHeight());
130 ret->mkItem("minGap [m]", false, myType->getMinGap());
131 ret->mkItem("vehicle class", false, SumoVehicleClassStrings.getString(myType->getVehicleClass()));
132 ret->mkItem("emission class", false, PollutantsInterface::getName(myType->getEmissionClass()));
133 ret->mkItem("mass [kg]", false, myType->getMass());
134 ret->mkItem("guiShape", false, getVehicleShapeName(myType->getGuiShape()));
135 ret->mkItem("maximum speed [m/s]", false, getMaxSpeed());
136 ret->mkItem("speedFactor", false, myType->getParameter().speedFactor.toStr(gPrecision));
137 ret->mkItem("person capacity", false, myType->getPersonCapacity());
138 ret->mkItem("container capacity", false, myType->getContainerCapacity());
140 return ret;
141}
142
143
144void
148
149
150double
151GUIMEVehicle::getColorValue(const GUIVisualizationSettings& /* s */, int activeScheme) const {
152 switch (activeScheme) {
153 case 8:
154 return getSpeed();
155 case 9:
156 return 0; // by actionStep
157 case 10:
158 return getWaitingSeconds();
159 case 11:
160 return 0; // getAccumulatedWaitingSeconds
161 case 12:
162 return 0; // invalid getLastLaneChangeOffset();
163 case 13:
164 return getSegment()->getEdge().getVehicleMaxSpeed(this);
165 case 14:
166 return 0; // invalid getEmissions<PollutantsInterface::CO2>();
167 case 15:
168 return 0; // invalid getEmissions<PollutantsInterface::CO>();
169 case 16:
170 return 0; // invalid getEmissions<PollutantsInterface::PM_X>();
171 case 17:
172 return 0; // invalid getEmissions<PollutantsInterface::NO_X>();
173 case 18:
174 return 0; // invalid getEmissions<PollutantsInterface::HC>();
175 case 19:
176 return 0; // invalid getEmissions<PollutantsInterface::FUEL>();
177 case 20:
178 return 0; // invalid getHarmonoise_NoiseEmissions();
179 case 21: // reroute number
180 if (getNumberReroutes() == 0) {
181 return -1;
182 }
183 return getNumberReroutes();
184 case 22:
186 case 23:
187 return 0; // invalid getBestLaneOffset();
188 case 24:
189 return 0; // invalid getAcceleration();
190 case 25:
191 return 0; // invalid getTimeGapOnLane();
192 case 26:
193 return STEPS2TIME(getDepartDelay());
194 case 27:
195 return 0; // electricityConsumption
196 case 28:
197 return 0; // timeLossSeconds
198 case 29:
199 return 0; // getSpeedLat
200 }
201 return 0;
202}
203
204
205
206void
207GUIMEVehicle::drawRouteHelper(const GUIVisualizationSettings& s, ConstMSRoutePtr r, bool future, bool noLoop, const RGBColor& col) const {
208 const double exaggeration = getExaggeration(s);
209 MSRouteIterator start = future ? myCurrEdge : r->begin();
210 MSRouteIterator i = start;
211 std::map<const MSLane*, int> repeatLane; // count repeated occurrences of the same edge
212 const double textSize = s.vehicleName.size / s.scale;
213 const int indexDigits = (int)toString(r->size()).size();
214 const bool s2 = s.secondaryShape;
215 for (; i != r->end(); ++i) {
216 const GUILane* lane = static_cast<GUILane*>((*i)->getLanes()[0]);
217 GLHelper::drawBoxLines(lane->getShape(s2), lane->getShapeRotations(s2), lane->getShapeLengths(s2), exaggeration);
218 if (s.showRouteIndex) {
219 std::string label = toString((int)(i - myCurrEdge));
220 const double laneAngle = lane->getShape(s2).angleAt2D(0);
221 Position pos = lane->getShape(s2).front() - Position(0, textSize * repeatLane[lane]) + Position(
222 (laneAngle >= -0.25 * M_PI && laneAngle < 0.75 * M_PI ? 1 : -1) * 0.4 * indexDigits * textSize, 0);
223 //GLHelper::drawText(label, pos, 1.0, textSize, s.vehicleName.color);
224 GLHelper::drawTextSettings(s.vehicleName, label, pos, s.scale, s.angle, 1.0);
225 }
226 if (noLoop && i != start && (*i) == (*start)) {
227 break;
228 }
229 repeatLane[lane]++;
230 }
231 drawStopLabels(s, noLoop, col);
233}
234
235
236double
238 // @todo possibly we could compute something reasonable here
239 return 0;
240}
241
242
243std::string
245 std::string result = "";
246 if (isParking()) {
247 result += "parking";
248 } else if (isStopped()) {
249 result += "stopped";
250 } else {
251 return "";
252 }
253 return result;
254}
255
256std::string
258 return getEdge()->getID();
259}
260
261
262void
264 // @todo possibly we could compute something reasonable here
265}
266
267
268double
272
273
276 // getPosition returns the start of the first lane, so we do not use it here
277 getEdge()->lock();
278 const double curTime = SIMTIME;
279 double vehiclePosition = 0.;
280 const MESegment* const segment = getSegment();
281 const int queIdx = getQueIndex();
282 if (segment != nullptr && queIdx != MESegment::PARKING_QUEUE) {
283 vehiclePosition = segment->getLength();
284 const std::vector<MEVehicle*>& queue = segment->getQueue(queIdx);
285 for (auto it = queue.rbegin(); it != queue.rend(); ++it) {
286 const MEVehicle* const v = *it;
287 const double intendedLeave = MIN2(v->getEventTimeSeconds(), v->getBlockTimeSeconds());
288 const double entry = v->getLastEntryTimeSeconds();
289 const double offset = segment->getLength() * (curTime - entry) / (intendedLeave - entry);
290 if (offset < vehiclePosition) {
291 vehiclePosition = offset;
292 }
293 if (v == this) {
294 break;
295 }
296 vehiclePosition -= v->getVehicleType().getLengthWithGap();
297 }
298 }
299 Boundary b;
300 const MSLane* const lane = getEdge()->getLanes()[queIdx == MESegment::PARKING_QUEUE ? 0 : queIdx];
301 b.add(lane->geometryPositionAtOffset(getPositionOnLane() + vehiclePosition));
303 getEdge()->unlock();
304 return b;
305}
306
307
308/****************************************************************************/
@ GLO_VEHICLE
a vehicle
GUISelectedStorage gSelected
A global holder of selected objects.
ConstMSEdgeVector::const_iterator MSRouteIterator
Definition MSRoute.h:57
#define TL(string)
Definition MsgHandler.h:315
std::shared_ptr< const MSRoute > ConstMSRoutePtr
Definition Route.h:32
std::string time2string(SUMOTime t, bool humanReadable)
convert SUMOTime to string (independently of global format setting)
Definition SUMOTime.cpp:69
#define STEPS2TIME(x)
Definition SUMOTime.h:55
#define SIMTIME
Definition SUMOTime.h:62
std::string getVehicleShapeName(SUMOVehicleShape id)
Returns the class name of the shape class given by its id.
StringBijection< SUMOVehicleClass > SumoVehicleClassStrings(sumoVehicleClassStringInitializer, SVC_CUSTOM2, false)
int gPrecision
the precision for floating point outputs
Definition StdDefs.cpp:26
T MIN2(T a, T b)
Definition StdDefs.h:76
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:343
std::string toStr(std::streamsize accuracy) const
Returns the string representation of this distribution.
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:348
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:782
static void drawAction_drawVehicleAsBoxPlus(const double width, const double length, bool amReversed=false)
draw vehicle as a Box
A MSVehicle extended by some values for usage within the gui.
void drawParkingInfo(const GUIVisualizationSettings &s) 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.
Representation of a lane in the micro simulation (gui-version)
Definition GUILane.h:60
const std::vector< double > & getShapeRotations(bool secondary) const
Definition GUILane.cpp:1115
const PositionVector & getShape(bool secondary) const override
Definition GUILane.cpp:1109
const std::vector< double > & getShapeLengths(bool secondary) const
Definition GUILane.cpp:1121
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, ConstMSRoutePtr route, MSVehicleType *type, const double speedFactor)
Constructor.
~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.
void drawRouteHelper(const GUIVisualizationSettings &s, ConstMSRoutePtr r, bool future, bool noLoop, const RGBColor &col) const
Draws the route.
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
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 secondaryShape
whether secondary lane shape shall be drawn
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:242
const std::vector< MEVehicle * > & getQueue(int index) const
Returns the cars in the queue with the given index for visualization.
Definition MESegment.h:217
const MSEdge & getEdge() const
Returns the edge this segment belongs to.
Definition MESegment.h:359
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:300
double getBlockTimeSeconds() const
Returns the time at which the vehicle was blocked on the current segment.
Definition MEVehicle.h:305
double getCurrentStoppingTimeSeconds() const
Returns the delay that is accrued due to option –meso-tls-penalty or –meso-minor-penalty.
double getPositionOnLane() const
Get the vehicle's position along the lane.
Definition MEVehicle.cpp:72
MESegment * getSegment() const
Returns the current segment the vehicle is on.
Definition MEVehicle.h:224
int getQueIndex() const
Returns the index of the que the vehicle is in.
Definition MEVehicle.h:233
int getSegmentIndex() const
double getCurrentLinkPenaltySeconds() const
Returns the delay that is accrued due to option –meso-tls-penalty or –meso-minor-penalty.
double getSpeed() const
Returns the vehicle's estimated speed assuming no delays.
double getEventTimeSeconds() const
Returns the earliest leave time for the current segment.
Definition MEVehicle.h:295
The base class for microscopic and mesoscopic vehicles.
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:777
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:1170
virtual void lock() const
grant exclusive access to the mesoscopic state
Definition MSEdge.h:774
Representation of a lane in the micro simulation.
Definition MSLane.h:84
const Position geometryPositionAtOffset(double offset, double lateralOffset=0) const
Definition MSLane.h:560
The car-following model and parameter.
double getLengthWithGap() const
Get vehicle's length including the minimum gap [m].
double getWidth() const
Get the width which vehicles of this class shall have when being drawn.
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.
double getMinGap() const
Get the free space in front of vehicles of this class.
double getHeight() const
Get the height which vehicles of this class shall have when being drawn.
SUMOEmissionClass getEmissionClass() const
Get this vehicle type's emission class.
double getLength() const
Get vehicle's length [m].
SUMOVehicleShape getGuiShape() const
Get this vehicle type's shape.
double getMass() const
Get this vehicle type's mass.
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 (in radians between -M_PI and M_PI)
Distribution_Parameterized speedFactor
The factor by which the maximum speed may deviate from the allowed max speed on the street.
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