Eclipse SUMO - Simulation of Urban MObility
Loading...
Searching...
No Matches
GUIVehicle.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-2023 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
24#include <cmath>
25#include <vector>
26#include <string>
27#include <bitset>
42#include <microsim/MSGlobals.h>
43#include <microsim/MSVehicle.h>
44#include <microsim/MSJunction.h>
45#include <microsim/MSLane.h>
46#include <microsim/MSLink.h>
47#include <microsim/MSStop.h>
59#include <gui/GUIGlobals.h>
60
61#include "GUIVehicle.h"
62#include "GUIPerson.h"
63#include "GUIContainer.h"
64#include "GUINet.h"
65#include "GUIEdge.h"
66#include "GUILane.h"
67
68#define SPEEDMODE_DEFAULT 31
69#define LANECHANGEMODE_DEFAULT 1621
70
71//#define DEBUG_FOES
72
73// ===========================================================================
74// FOX callback mapping
75// ===========================================================================
76
77// Object implementation
78
79
80/* -------------------------------------------------------------------------
81 * GUIVehicle - methods
82 * ----------------------------------------------------------------------- */
83
85 MSVehicleType* type, const double speedFactor) :
86 MSVehicle(pars, route, type, speedFactor),
87 GUIBaseVehicle((MSBaseVehicle&) * this) {
88}
89
90
93
94
98 const bool isElecHybrid = getDevice(typeid(MSDevice_ElecHybrid)) != nullptr ? true : false;
100 // add items
101 ret->mkItem("lane [id]", true, new FunctionBindingString<GUIVehicle>(this, &GUIVehicle::getLaneID));
103 ret->mkItem("shadow lane [id]", true, new FunctionBindingString<GUIVehicle>(this, &GUIVehicle::getShadowLaneID));
104 }
106 ret->mkItem("target lane [id]", true, new FunctionBindingString<GUIVehicle>(this, &GUIVehicle::getTargetLaneID));
107 }
108 if (isSelected()) {
109 ret->mkItem("back lanes [id,..]", true, new FunctionBindingString<GUIVehicle>(this, &GUIVehicle::getBackLaneIDs));
110 }
111 ret->mkItem("position [m]", true,
113 ret->mkItem("lateral offset [m]", true,
115 ret->mkItem("speed [m/s]", true,
117 ret->mkItem("lateral speed [m/s]", true,
119 ret->mkItem("acceleration [m/s^2]", true,
121 ret->mkItem("angle [degree]", true,
123 ret->mkItem("slope [degree]", true,
125 ret->mkItem("speed factor", true,
127 ret->mkItem("time gap on lane [s]", true,
129 ret->mkItem("waiting time [s]", true,
131 ret->mkItem(("waiting time (accumulated, " + time2string(MSGlobals::gWaitingTimeMemory) + "s) [s]").c_str(), true,
133 ret->mkItem("time since startup [s]", true,
135 ret->mkItem("time loss [s]", true,
137 ret->mkItem("impatience", true,
139 ret->mkItem("last lane change [s]", true,
141 ret->mkItem("desired depart [s]", false, time2string(getParameter().depart));
142 ret->mkItem("depart delay [s]", false, time2string(getDepartDelay()));
143 ret->mkItem("odometer [m]", true,
145 if (getParameter().repetitionNumber < std::numeric_limits<int>::max()) {
146 ret->mkItem("remaining [#]", false, (int) getParameter().repetitionNumber - getParameter().repetitionsDone);
147 }
148 if (getParameter().repetitionOffset > 0) {
149 ret->mkItem("insertion period [s]", false, time2string(getParameter().repetitionOffset));
150 }
151 if (getParameter().repetitionProbability > 0) {
152 ret->mkItem("insertion probability", false, getParameter().repetitionProbability);
153 }
154 ret->mkItem("stop info", true, new FunctionBindingString<GUIVehicle>(this, &GUIVehicle::getStopInfo));
155 ret->mkItem("line", false, myParameter->line);
156 ret->mkItem("CO2 [mg/s]", true,
157 new FunctionBinding<GUIVehicle, double>(this, &MSVehicle::getEmissions<PollutantsInterface::CO2>));
158 ret->mkItem("CO [mg/s]", true,
159 new FunctionBinding<GUIVehicle, double>(this, &MSVehicle::getEmissions<PollutantsInterface::CO>));
160 ret->mkItem("HC [mg/s]", true,
161 new FunctionBinding<GUIVehicle, double>(this, &MSVehicle::getEmissions<PollutantsInterface::HC>));
162 ret->mkItem("NOx [mg/s]", true,
163 new FunctionBinding<GUIVehicle, double>(this, &MSVehicle::getEmissions<PollutantsInterface::NO_X>));
164 ret->mkItem("PMx [mg/s]", true,
165 new FunctionBinding<GUIVehicle, double>(this, &MSVehicle::getEmissions<PollutantsInterface::PM_X>));
166 ret->mkItem("fuel [mg/s]", true,
167 new FunctionBinding<GUIVehicle, double>(this, &MSVehicle::getEmissions<PollutantsInterface::FUEL>));
168 ret->mkItem("electricity [Wh/s]", true,
169 new FunctionBinding<GUIVehicle, double>(this, &MSVehicle::getEmissions<PollutantsInterface::ELEC>));
170 ret->mkItem("noise (Harmonoise) [dB]", true,
172 ret->mkItem("devices", false, getDeviceDescription());
173 ret->mkItem("persons", true,
175 ret->mkItem("containers", true,
177 ret->mkItem("lcState right", true, new FunctionBindingString<GUIVehicle>(this, &GUIVehicle::getLCStateRight));
178 ret->mkItem("lcState left", true, new FunctionBindingString<GUIVehicle>(this, &GUIVehicle::getLCStateLeft));
179 // close building
181 ret->mkItem("lcState center", true, new FunctionBindingString<GUIVehicle>(this, &GUIVehicle::getLCStateCenter));
182 ret->mkItem("right side on edge [m]", true, new FunctionBinding<GUIVehicle, double>(this, &GUIVehicle::getRightSideOnEdge2));
183 ret->mkItem("left side on edge [m]", true, new FunctionBinding<GUIVehicle, double>(this, &GUIVehicle::getLeftSideOnEdge));
184 ret->mkItem("rightmost edge sublane [#]", true, new FunctionBinding<GUIVehicle, int>(this, &GUIVehicle::getRightSublaneOnEdge));
185 ret->mkItem("leftmost edge sublane [#]", true, new FunctionBinding<GUIVehicle, int>(this, &GUIVehicle::getLeftSublaneOnEdge));
186 ret->mkItem("lane change maneuver distance [m]", true, new FunctionBinding<GUIVehicle, double>(this, &GUIVehicle::getManeuverDist));
187 }
188 if (isElecHybrid) {
189 ret->mkItem("actual state of charge [Wh]", true,
191 ret->mkItem("actual electric current [A]", true,
193 }
194 if (hasInfluencer()) {
196 ret->mkItem("speed mode", true, new FunctionBindingString<GUIVehicle>(this, &GUIVehicle::getSpeedMode));
197 }
199 ret->mkItem("lane change mode", true, new FunctionBindingString<GUIVehicle>(this, &GUIVehicle::getLaneChangeMode));
200 }
201 }
203 return ret;
204}
205
206
209 GUIParameterTableWindow* ret = new GUIParameterTableWindow(app, *this, "vType:" + myType->getID());
210 ret->mkItem("length [m]", false, myType->getLength());
211 ret->mkItem("width [m]", false, myType->getWidth());
212 ret->mkItem("height [m]", false, myType->getHeight());
213 ret->mkItem("minGap [m]", false, myType->getMinGap());
214 ret->mkItem("vehicle class", false, SumoVehicleClassStrings.getString(myType->getVehicleClass()));
215 ret->mkItem("emission class", false, PollutantsInterface::getName(myType->getEmissionClass()));
216 ret->mkItem("mass [kg]", false, myType->getMass());
217 ret->mkItem("carFollowModel", false, SUMOXMLDefinitions::CarFollowModels.getString((SumoXMLTag)getCarFollowModel().getModelID()));
218 ret->mkItem("laneChangeModel", false, SUMOXMLDefinitions::LaneChangeModels.getString(getLaneChangeModel().getModelID()));
219 ret->mkItem("guiShape", false, getVehicleShapeName(myType->getGuiShape()));
220 ret->mkItem("maximum speed [m/s]", false, getVehicleType().getMaxSpeed());
221 ret->mkItem("desired maximum speed [m/s]", false, getVehicleType().getDesiredMaxSpeed());
222 ret->mkItem("maximum acceleration [m/s^2]", false, getCarFollowModel().getMaxAccel());
223 ret->mkItem("maximum deceleration [m/s^2]", false, getCarFollowModel().getMaxDecel());
224 ret->mkItem("emergency deceleration [m/s^2]", false, getCarFollowModel().getEmergencyDecel());
225 ret->mkItem("apparent deceleration [m/s^2]", false, getCarFollowModel().getApparentDecel());
226 ret->mkItem("imperfection (sigma)", false, getCarFollowModel().getImperfection());
227 ret->mkItem("desired headway (tau) [s]", false, getCarFollowModel().getHeadwayTime());
228 ret->mkItem("speedFactor", false, myType->getParameter().speedFactor.toStr(gPrecision));
230 ret->mkItem("action step length [s]", false, myType->getActionStepLengthSecs());
231 }
232 ret->mkItem("person capacity", false, myType->getPersonCapacity());
233 ret->mkItem("boarding time [s]", false, STEPS2TIME(myType->getLoadingDuration(true)));
234 ret->mkItem("container capacity", false, myType->getContainerCapacity());
235 ret->mkItem("loading time [s]", false, STEPS2TIME(myType->getLoadingDuration(false)));
237 ret->mkItem("minGapLat [m]", false, myType->getMinGapLat());
238 ret->mkItem("maxSpeedLat [m/s]", false, myType->getMaxSpeedLat());
239 ret->mkItem("latAlignment", true, new FunctionBindingString<GUIVehicle>(this, &GUIVehicle::getDynamicAlignment));
240 } else if (MSGlobals::gLaneChangeDuration > 0) {
241 ret->mkItem("maxSpeedLat [m/s]", false, myType->getMaxSpeedLat());
242 }
243 for (auto item : myType->getParameter().lcParameter) {
244 ret->mkItem(toString(item.first).c_str(), false, toString(item.second));
245 }
246 for (auto item : myType->getParameter().jmParameter) {
247 ret->mkItem(toString(item.first).c_str(), false, toString(item.second));
248 }
250 ret->mkItem("manoeuver Angle vs Times", false, myType->getParameter().getManoeuverAngleTimesS());
251 }
253 return ret;
254}
255
256
257std::string
262 std::string align2 = toString(getLaneChangeModel().getDesiredAlignment());
263 if (align2 != align) {
264 align = align2 + " (default: " + align + ")";
265 }
266 return align;
267}
268
269void
271 glTranslated(0, 0, getType() + .2); // draw on top of cars
272 for (DriveItemVector::const_iterator i = myLFLinkLanes.begin(); i != myLFLinkLanes.end(); ++i) {
273 if ((*i).myLink == nullptr) {
274 continue;
275 }
276 MSLink* link = (*i).myLink;
277 MSLane* via = link->getViaLaneOrLane();
278 if (via != nullptr) {
279 Position p = via->getShape()[0];
280 if ((*i).mySetRequest) {
281 glColor3d(0, .8, 0);
282 } else {
283 glColor3d(.8, 0, 0);
284 }
285 const SUMOTime leaveTime = (*i).myLink->getLeaveTime(
286 (*i).myArrivalTime, (*i).myArrivalSpeed, (*i).getLeaveSpeed(), getVehicleType().getLength());
287 drawLinkItem(p, (*i).myArrivalTime, leaveTime, s.vehicleName.size / s.scale);
288 // the time slot that ego vehicle uses when checking opened may
289 // differ from the one it requests in setApproaching
290 MSLink::ApproachingVehicleInformation avi = (*i).myLink->getApproaching(this);
291 assert(avi.arrivalTime == (*i).myArrivalTime && avi.leavingTime == leaveTime);
292 UNUSED_PARAMETER(avi); // only used for assertion
293 }
294 }
295 glTranslated(0, 0, getType() - .2); // draw on top of cars
296}
297
298
299void
301 const bool s2 = s.secondaryShape;
302 RGBColor current = GLHelper::getColor();
303 RGBColor darker = current.changedBrightness(-51);
304 const double exaggeration = (s.vehicleSize.getExaggeration(s, this)
306 const double totalLength = getVType().getLength();
307 double upscaleLength = exaggeration;
308 if (exaggeration > 1 && totalLength > 5) {
309 // reduce the length/width ratio because this is not useful at high zoom
310 const double widthLengthFactor = totalLength / 5;
311 const double shrinkFactor = MIN2(widthLengthFactor, sqrt(upscaleLength));
312 upscaleLength /= shrinkFactor;
313 }
314 const double locomotiveLength = getVehicleType().getParameter().locomotiveLength * upscaleLength;
315 if (exaggeration == 0) {
316 return;
317 }
318 const double defaultLength = getVehicleType().getParameter().carriageLength * upscaleLength;
319 const double carriageGap = getVehicleType().getParameter().carriageGap * upscaleLength;
320 const double length = totalLength * upscaleLength;
321 const double halfWidth = getVehicleType().getWidth() / 2.0 * exaggeration;
322 GLHelper::popMatrix(); // undo initial translation and rotation
323 const double xCornerCut = 0.3 * exaggeration;
324 const double yCornerCut = 0.4 * exaggeration;
325 // round to closest integer
326 const int numCarriages = MAX2(1, 1 + (int)((length - locomotiveLength) / (defaultLength + carriageGap) + 0.5));
327 assert(numCarriages > 0);
328 double carriageLengthWithGap = length / numCarriages;
329 double carriageLength = carriageLengthWithGap - carriageGap;
330 double firstCarriageLength = carriageLength;
331 if (defaultLength != locomotiveLength && numCarriages > 1) {
332 firstCarriageLength = locomotiveLength;
333 carriageLengthWithGap = (length - locomotiveLength) / (numCarriages - 1);
334 carriageLength = carriageLengthWithGap - carriageGap;
335 }
336 const int firstPassengerCarriage = defaultLength == locomotiveLength || numCarriages == 1 || (getVClass() & SVC_RAIL_CLASSES) == 0 ? 0 : 1;
337 const int noPersonsBackCarriages = (getVehicleType().getGuiShape() == SUMOVehicleShape::TRUCK_SEMITRAILER || getVehicleType().getGuiShape() == SUMOVehicleShape::TRUCK_1TRAILER) && numCarriages > 1 ? 1 : 0;
338 const int firstContainerCarriage = numCarriages == 1 || getVehicleType().getGuiShape() == SUMOVehicleShape::TRUCK_1TRAILER ? 0 : 1;
339 const int seatsPerCarriage = (int)ceil(getVType().getPersonCapacity() / (numCarriages - firstPassengerCarriage - noPersonsBackCarriages));
340 const int containersPerCarriage = (int)ceil(getVType().getContainerCapacity() / (numCarriages - firstContainerCarriage));
341 // lane on which the carriage front is situated
342 MSLane* lane = myLane;
343 int furtherIndex = 0;
344 // lane on which the carriage back is situated
345 MSLane* backLane = myLane;
346 int backFurtherIndex = furtherIndex;
347 // offsets of front and back
348 double carriageOffset = myState.pos();
350 // @note this still produces some artifacts while not fully on the current lane
351 carriageOffset = MIN2(carriageOffset + getLength(), lane->getLength());
352 }
353 double carriageBackOffset = carriageOffset - firstCarriageLength;
354 // handle seats
355 int requiredSeats = getNumPassengers();
356 int requiredPositions = getNumContainers();
357 if (requiredSeats > 0) {
358 mySeatPositions.clear();
359 }
360 if (requiredPositions > 0) {
361 myContainerPositions.clear();
362 }
363 Position front, back;
364 double angle = 0.;
365 // position parking vehicle beside the road or track
366 const double lateralOffset = (isParking() && getNextStopParameter()->posLat == INVALID_DOUBLE
367 ? (getLane()->getWidth() * (MSGlobals::gLefthand ? -1 : 1))
369
370 // draw individual carriages
371 double curCLength = firstCarriageLength;
372 int firstCarriageNo = 0; // default case - we're going forwards
373 const bool reversed = drawReversed(s) || getLaneChangeModel().isOpposite();
374 if (reversed) {
375 firstCarriageNo = numCarriages - 1;
376 if (numCarriages > 1) {
377 carriageBackOffset = carriageOffset - carriageLength;
378 }
379 }
380
381 //std::cout << SIMTIME << " veh=" << getID() << " curCLength=" << curCLength << " loc=" << locomotiveLength << " car=" << carriageLength << " tlen=" << totalLength << " len=" << length << "\n";
382 for (int i = 0; i < numCarriages; ++i) {
383 if (i == firstCarriageNo) {
384 curCLength = firstCarriageLength;
385 if (firstCarriageNo > 0) {
386 // previous loop iteration has adjusted backpos for a normal carriage so have to correct
387 carriageBackOffset += carriageLengthWithGap;
388 carriageBackOffset -= firstCarriageLength + carriageGap;
389 }
390 } else {
391 curCLength = carriageLength;
392 }
393 while (carriageOffset < 0) {
394 MSLane* prev = getPreviousLane(lane, furtherIndex);
395 if (prev != lane) {
396 carriageOffset += prev->getLength();
397 } else {
398 // no lane available for drawing.
399 carriageOffset = 0;
400 }
401 lane = prev;
402 }
403 while (carriageBackOffset < 0) {
404 MSLane* prev = getPreviousLane(backLane, backFurtherIndex);
405 if (prev != backLane) {
406 carriageBackOffset += prev->getLength();
407 } else {
408 // no lane available for drawing.
409 carriageBackOffset = 0;
410 }
411 backLane = prev;
412 }
413 front = lane->getShape(s2).positionAtOffset(carriageOffset * lane->getLengthGeometryFactor(s2), lateralOffset);
414 back = backLane->getShape(s2).positionAtOffset(carriageBackOffset * lane->getLengthGeometryFactor(s2), lateralOffset);
415 if (front == back) {
416 // no place for drawing available
417 continue;
418 }
419 const double drawnCarriageLength = front.distanceTo2D(back);
420 angle = atan2((front.x() - back.x()), (back.y() - front.y())) * (double) 180.0 / (double) M_PI;
421 // if we are in reverse 'first' carriages are drawn last so the >= test doesn't work
422 if (reversed) {
423 if (i <= numCarriages - firstPassengerCarriage) {
424 computeSeats(back, front, SUMO_const_waitingPersonWidth, seatsPerCarriage, exaggeration, requiredSeats, mySeatPositions);
425 }
426 if (i <= numCarriages - firstContainerCarriage) {
427 computeSeats(front, back, SUMO_const_waitingContainerWidth, containersPerCarriage, exaggeration, requiredPositions, myContainerPositions);
428 }
429 } else {
430 if (i >= firstPassengerCarriage) {
431 computeSeats(front, back, SUMO_const_waitingPersonWidth, seatsPerCarriage, exaggeration, requiredSeats, mySeatPositions);
432 }
433 if (i >= firstContainerCarriage) {
434 computeSeats(front, back, SUMO_const_waitingContainerWidth, containersPerCarriage, exaggeration, requiredPositions, myContainerPositions);
435 }
436 }
438 glTranslated(front.x(), front.y(), getType());
439 glRotated(angle, 0, 0, 1);
440 if (!asImage || !GUIBaseVehicleHelper::drawAction_drawVehicleAsImage(s, getVType().getImgFile(), this, getVType().getWidth() * exaggeration, curCLength)) {
441 switch (getVType().getGuiShape()) {
444 if (i == firstCarriageNo) { // at the moment amReversed is only ever set for rail - so has no impact in this call
445 GUIBaseVehicleHelper::drawAction_drawVehicleAsPoly(s, getVType().getGuiShape(), getVType().getWidth() * exaggeration, curCLength, 0, false, reversed);
446 } else {
447 GLHelper::setColor(current);
448 GLHelper::drawBoxLine(Position(0, 0), 180, curCLength, halfWidth);
449 }
450 break;
451 default: {
452 if (i == firstCarriageNo) {
453 GLHelper::setColor(darker);
454 } else {
455 GLHelper::setColor(current);
456 }
457 // generic rail carriage
458 glBegin(GL_TRIANGLE_FAN);
459 glVertex2d(-halfWidth + xCornerCut, 0);
460 glVertex2d(-halfWidth, yCornerCut);
461 glVertex2d(-halfWidth, drawnCarriageLength - yCornerCut);
462 glVertex2d(-halfWidth + xCornerCut, drawnCarriageLength);
463 glVertex2d(halfWidth - xCornerCut, drawnCarriageLength);
464 glVertex2d(halfWidth, drawnCarriageLength - yCornerCut);
465 glVertex2d(halfWidth, yCornerCut);
466 glVertex2d(halfWidth - xCornerCut, 0);
467 glEnd();
468 // indicate front of the head of the train
469 if (i == firstCarriageNo) {
470 glTranslated(0, 0, 0.1);
471 glColor3d(0, 0, 0);
472 glBegin(GL_TRIANGLE_FAN);
473 if (reversed) { // not quite correct as its drawing at the wrong end of the locomotive - however useful as visual indicator of reverse?
474 glVertex2d(-halfWidth + xCornerCut, yCornerCut);
475 glVertex2d(-halfWidth + 2 * xCornerCut, 3 * yCornerCut);
476 glVertex2d(halfWidth - 2 * xCornerCut, 3 * yCornerCut);
477 glVertex2d(halfWidth - xCornerCut, yCornerCut);
478 } else {
479 glVertex2d(-halfWidth + 2 * xCornerCut, yCornerCut);
480 glVertex2d(-halfWidth + xCornerCut, 3 * yCornerCut);
481 glVertex2d(halfWidth - xCornerCut, 3 * yCornerCut);
482 glVertex2d(halfWidth - 2 * xCornerCut, yCornerCut);
483 }
484 glEnd();
485 glTranslated(0, 0, -0.1);
486 }
487 }
488 }
489 }
491 carriageOffset -= (curCLength + carriageGap);
492 carriageBackOffset -= carriageLengthWithGap;
493 }
496 glTranslated(front.x(), front.y(), getType());
497 glRotated(angle, 0, 0, 1);
501 }
502 // restore matrix
504 front = getPosition();
505 glTranslated(front.x(), front.y(), getType());
506 const double degAngle = RAD2DEG(getAngle() + M_PI / 2.);
507 glRotated(degAngle, 0, 0, 1);
508 glScaled(exaggeration, upscaleLength, 1);
509 if (mySeatPositions.size() == 0) {
510 mySeatPositions.push_back(Seat(back, DEG2RAD(angle)));
511 }
512 if (myContainerPositions.size() == 0) {
513 myContainerPositions.push_back(Seat(back, DEG2RAD(angle)));
514 }
515}
516
517#define BLINKER_POS_FRONT .5
518#define BLINKER_POS_BACK .5
519
520inline void
521drawAction_drawBlinker(double dir, double length) {
522 glColor3d(1.f, .8f, 0);
524 glTranslated(dir, BLINKER_POS_FRONT, -0.1);
528 glTranslated(dir, length - BLINKER_POS_BACK, -0.1);
531}
532
533
534void
551
552
553inline void
554GUIVehicle::drawAction_drawVehicleBrakeLight(double length, bool onlyOne) const {
556 return;
557 }
558 glColor3f(1.f, .2f, 0);
560 if (onlyOne) {
561 glTranslated(0, length, -0.1);
563 } else {
564 glTranslated(-getVehicleType().getWidth() * 0.5, length, -0.1);
568 glTranslated(getVehicleType().getWidth() * 0.5, length, -0.1);
570 }
572}
573
574inline void
578 glTranslated(0, 2.5, .5);
579 glColor3f(0, 0, 1);
582 }
583}
584
585
586double
587GUIVehicle::getColorValue(const GUIVisualizationSettings& s, int activeScheme) const {
588 switch (activeScheme) {
589 case 8:
590 if (isStopped()) {
591 return isParking() ? -2 : -1;
592 }
593 return getSpeed();
594 case 9:
595 // color by action step
596 if (isActionStep(SIMSTEP)) {
597 // Upcoming simstep is actionstep (t was already increased before drawing)
598 return 1.;
599 } else if (isActive()) {
600 // Completed simstep was actionstep
601 return 2.;
602 } else {
603 // not active
604 return 0.;
605 }
606 case 10:
607 return getWaitingSeconds();
608 case 11:
610 case 12:
612 case 13:
613 return getLane()->getVehicleMaxSpeed(this);
614 case 14:
615 return getEmissions<PollutantsInterface::CO2>();
616 case 15:
617 return getEmissions<PollutantsInterface::CO>();
618 case 16:
619 return getEmissions<PollutantsInterface::PM_X>();
620 case 17:
621 return getEmissions<PollutantsInterface::NO_X>();
622 case 18:
623 return getEmissions<PollutantsInterface::HC>();
624 case 19:
625 return getEmissions<PollutantsInterface::FUEL>();
626 case 20:
628 case 21:
629 return getNumberReroutes();
630 case 22:
632 case 23:
633 return getLaneChangeModel().isOpposite() ? -100 : getBestLaneOffset();
634 case 24:
635 return getAcceleration();
636 case 25:
637 return getTimeGapOnLane();
638 case 26:
639 return STEPS2TIME(getDepartDelay());
640 case 27:
641 return getEmissions<PollutantsInterface::ELEC>();
642 case 28:
643 return getTimeLossSeconds();
644 case 29:
645 return getStopDelay();
646 case 30:
647 return getStopArrivalDelay();
648 case 31:
650 case 32: // by numerical param value
651 std::string error;
652 std::string val = getPrefixedParameter(s.vehicleParam, error);
653 try {
654 if (val == "") {
656 } else {
657 return StringUtils::toDouble(val);
658 }
659 } catch (NumberFormatException&) {
660 try {
661 return StringUtils::toBool(val);
662 } catch (BoolFormatException&) {
663 WRITE_WARNINGF(TL("Vehicle parameter '%' key '%' is not a number for vehicle '%'."),
666 }
667 }
668 }
669 return 0;
670}
671
672
673void
675 myLock.lock();
676 std::vector<std::vector<MSVehicle::LaneQ> > bestLanes = myBestLanes;
677 myLock.unlock();
678 for (std::vector<std::vector<MSVehicle::LaneQ> >::iterator j = bestLanes.begin(); j != bestLanes.end(); ++j) {
679 std::vector<MSVehicle::LaneQ>& lanes = *j;
680 double gmax = -1;
681 double rmax = -1;
682 for (std::vector<MSVehicle::LaneQ>::const_iterator i = lanes.begin(); i != lanes.end(); ++i) {
683 gmax = MAX2((*i).length, gmax);
684 rmax = MAX2((*i).occupation, rmax);
685 }
686 for (std::vector<MSVehicle::LaneQ>::const_iterator i = lanes.begin(); i != lanes.end(); ++i) {
687 const PositionVector& shape = (*i).lane->getShape();
688 double g = (*i).length / gmax;
689 double r = (*i).occupation / rmax;
690 glColor3d(r, g, 0);
691 double width = 0.5 / (1 + abs((*i).bestLaneOffset));
692 GLHelper::drawBoxLines(shape, width);
693
694 PositionVector s1 = shape;
695 s1.move2side((double) .1);
696 glColor3d(r, 0, 0);
698 s1.move2side((double) - .2);
699 glColor3d(0, g, 0);
701
702 glColor3d(r, g, 0);
703 }
704 }
705}
706
707
708void
709GUIVehicle::drawRouteHelper(const GUIVisualizationSettings& s, ConstMSRoutePtr r, bool future, bool noLoop, const RGBColor& col) const {
710 const double exaggeration = s.vehicleSize.getExaggeration(s, this) * (s.gaming ? 0.5 : 1);
711 MSRouteIterator start = future ? myCurrEdge : r->begin();
712 MSRouteIterator i = start;
713 const std::vector<MSLane*>& bestLaneConts = getBestLanesContinuation();
714 // draw continuation lanes when drawing the current route where available
715 int bestLaneIndex = (r == myRoute ? 0 : (int)bestLaneConts.size());
716 std::map<const MSLane*, int> repeatLane; // count repeated occurrences of the same edge
717 const double textSize = s.vehicleName.size / s.scale;
718 const GUILane* prevLane = nullptr;
719 int reversalIndex = 0;
720 const int indexDigits = (int)toString(r->size()).size();
721 if (!isOnRoad() && !isParking()) {
722 // simulation time has already advanced so isRemoteControlled is always false
723 const std::string offRoadLabel = hasInfluencer() && getInfluencer()->isRemoteAffected(SIMSTEP) ? "offRoad" : "teleporting";
724 GLHelper::drawTextSettings(s.vehicleValue, offRoadLabel, getPosition(), s.scale, s.angle, 1.0);
725 } else if (myLane->isInternal()) {
726 bestLaneIndex++;
727 }
728 const bool s2 = s.secondaryShape;
729 for (; i != r->end(); ++i) {
730 const GUILane* lane;
731 if (bestLaneIndex < (int)bestLaneConts.size() && bestLaneConts[bestLaneIndex] != 0 && (*i) == &(bestLaneConts[bestLaneIndex]->getEdge())) {
732 lane = static_cast<GUILane*>(bestLaneConts[bestLaneIndex]);
733 ++bestLaneIndex;
734 } else {
735 const std::vector<MSLane*>* allowed = (*i)->allowedLanes(getVClass());
736 if (allowed != nullptr && allowed->size() != 0) {
737 lane = static_cast<GUILane*>((*allowed)[0]);
738 } else {
739 lane = static_cast<GUILane*>((*i)->getLanes()[0]);
740 }
741 }
743 GLHelper::drawBoxLines(lane->getShape(s2), lane->getShapeRotations(s2), lane->getShapeLengths(s2), exaggeration);
744 if (prevLane != nullptr && lane->getBidiLane() == prevLane) {
745 // indicate train reversal
746 std::string label = "reverse:" + toString(reversalIndex++);
747 if (s.showRouteIndex) {
748 label += "@r" + toString((int)(i - myCurrEdge));
749 }
750 Position pos = lane->geometryPositionAtOffset(lane->getLength() / 2) - Position(0, textSize * repeatLane[lane]);
751 GLHelper::drawTextSettings(s.vehicleValue, label, pos, s.scale, s.angle, 1.0);
752 }
753 if (s.showRouteIndex) {
754 std::string label = toString((int)(i - myCurrEdge));
755 const double laneAngle = lane->getShape(s2).angleAt2D(0);
756 Position pos = lane->getShape(s2).front() - Position(0, textSize * repeatLane[lane]) + Position(
757 (laneAngle >= -0.25 * M_PI && laneAngle < 0.75 * M_PI ? 1 : -1) * 0.4 * indexDigits * textSize, 0);
758 //GLHelper::drawText(label, pos, 1.0, textSize, s.vehicleName.color);
759 GLHelper::drawTextSettings(s.vehicleName, label, pos, s.scale, s.angle, 1.0);
760 }
761 repeatLane[lane]++;
762 prevLane = lane;
763 if (noLoop && i != start && (*i) == (*start)) {
764 break;
765 }
766 }
767 drawStopLabels(s, noLoop, col);
768 drawParkingInfo(s, col);
769}
770
771
772MSLane*
773GUIVehicle::getPreviousLane(MSLane* current, int& furtherIndex) const {
774 if (furtherIndex < (int)myFurtherLanes.size()) {
775 return myFurtherLanes[furtherIndex++];
776 } else {
777 // try to use route information
778 int routeIndex = getRoutePosition();
779 bool resultInternal;
780 if (MSGlobals::gUsingInternalLanes && MSNet::getInstance()->hasInternalLinks()) {
781 if (myLane->isInternal()) {
782 if (furtherIndex % 2 == 0) {
783 routeIndex -= (furtherIndex + 0) / 2;
784 resultInternal = false;
785 } else {
786 routeIndex -= (furtherIndex + 1) / 2;
787 resultInternal = false;
788 }
789 } else {
790 if (furtherIndex % 2 != 0) {
791 routeIndex -= (furtherIndex + 1) / 2;
792 resultInternal = false;
793 } else {
794 routeIndex -= (furtherIndex + 2) / 2;
795 resultInternal = true;
796 }
797 }
798 } else {
799 routeIndex -= furtherIndex;
800 resultInternal = false;
801 }
802 furtherIndex++;
803 if (routeIndex >= 0) {
804 if (resultInternal) {
805 const MSEdge* prevNormal = myRoute->getEdges()[routeIndex];
806 for (MSLane* cand : prevNormal->getLanes()) {
807 for (MSLink* link : cand->getLinkCont()) {
808 if (link->getLane() == current) {
809 if (link->getViaLane() != nullptr) {
810 return link->getViaLane();
811 } else {
812 return const_cast<MSLane*>(link->getLaneBefore());
813 }
814 }
815 }
816 }
817 } else {
818 return myRoute->getEdges()[routeIndex]->getLanes()[0];
819 }
820 }
821 }
822 return current;
823}
824
825
826double
830
831
832std::string
834 std::string result = "";
835 if (isParking()) {
836 result += "parking";
837 } else if (isStopped()) {
838 result += "stopped";
839 } else if (hasStops()) {
840 return "next: " + myStops.front().getDescription();
841 } else {
842 return "";
843 }
844 if (myStops.front().pars.triggered) {
845 result += ", triggered";
846 } else if (myStops.front().pars.containerTriggered) {
847 result += ", containerTriggered";
848 } else if (myStops.front().pars.collision) {
849 result += ", collision";
850 } else if (myStops.front().pars.until != -1) {
851 result += ", until=" + time2string(myStops.front().pars.until);
852 } else {
853 result += ", duration=" + time2string(myStops.front().duration);
854 }
855 if (myStops.front().pars.actType != "") {
856 result += ", actType=" + myStops.front().pars.actType;
857 }
858 return result;
859}
860
861
862void
864 double dist = myLane->getLength() - getPositionOnLane();
865#ifdef DEBUG_FOES
866 std::cout << SIMTIME << " selectBlockingFoes veh=" << getID() << " dist=" << dist << " numLinks=" << myLFLinkLanes.size() << "\n";
867#endif
868 for (DriveItemVector::const_iterator i = myLFLinkLanes.begin(); i != myLFLinkLanes.end(); ++i) {
869 const DriveProcessItem& dpi = *i;
870 if (dpi.myLink == nullptr) {
872 continue;
873 }
874 MSLink::BlockingFoes blockingFoes;
875 std::vector<const MSPerson*> blockingPersons;
876#ifdef DEBUG_FOES
877 std::cout << " foeLink=" << dpi.myLink->getViaLaneOrLane()->getID() << "\n";
878 const bool isOpen =
879#endif
882#ifdef DEBUG_FOES
883 if (!isOpen) {
884 std::cout << " closed due to:\n";
885 for (const auto& item : blockingFoes) {
886 std::cout << " " << item->getID() << "\n";
887 }
888 }
889#endif
890 if (getLaneChangeModel().getShadowLane() != nullptr) {
892 if (parallelLink != nullptr) {
893 const double shadowLatPos = getLateralPositionOnLane() - getLaneChangeModel().getShadowDirection() * 0.5 * (
895#ifdef DEBUG_FOES
896 const bool isShadowOpen =
897#endif
898 parallelLink->opened(dpi.myArrivalTime, dpi.myArrivalSpeed, dpi.getLeaveSpeed(),
901 getWaitingTime(), shadowLatPos, &blockingFoes, false, this);
902#ifdef DEBUG_FOES
903 if (!isShadowOpen) {
904 std::cout << " foes at shadow link=" << parallelLink->getViaLaneOrLane()->getID() << ":\n";
905 for (const auto& item : blockingFoes) {
906 std::cout << " " << item->getID() << "\n";
907 }
908 }
909#endif
910 }
911 }
912 for (const auto& item : blockingFoes) {
913 gSelected.select(static_cast<const GUIVehicle*>(item)->getGlID());
914 }
915#ifdef DEBUG_FOES
916 gDebugFlag1 = true;
917#endif
918 const MSLink::LinkLeaders linkLeaders = (dpi.myLink)->getLeaderInfo(this, dist, &blockingPersons);
919#ifdef DEBUG_FOES
920 gDebugFlag1 = false;
921#endif
922 for (MSLink::LinkLeaders::const_iterator it = linkLeaders.begin(); it != linkLeaders.end(); ++it) {
923 // the vehicle to enter the junction first has priority
924 const GUIVehicle* leader = dynamic_cast<const GUIVehicle*>(it->vehAndGap.first);
925 if (leader != nullptr) {
926 if (isLeader(dpi.myLink, leader, it->vehAndGap.second) || it->inTheWay()) {
927 gSelected.select(leader->getGlID());
928#ifdef DEBUG_FOES
929 std::cout << " linkLeader=" << leader->getID() << "\n";
930#endif
931 }
932 } else {
933 for (std::vector<const MSPerson*>::iterator it_p = blockingPersons.begin(); it_p != blockingPersons.end(); ++it_p) {
934 const GUIPerson* foe = dynamic_cast<const GUIPerson*>(*it_p);
935 if (foe != nullptr) {
936 gSelected.select(foe->getGlID());
937 //std::cout << SIMTIME << " veh=" << getID() << " is blocked on link " << dpi.myLink->getRespondIndex() << " to " << dpi.myLink->getViaLaneOrLane()->getID() << " by pedestrian. dist=" << it->second << "\n";
938 }
939 }
940 }
941 }
942 dist += dpi.myLink->getViaLaneOrLane()->getLength();
943 }
944}
945
946
947void
951 if (view != nullptr) {
952 if (add) {
956 }
957 } else {
959 myAdditionalVisualizations[view] &= ~VO_DRAW_OUTSIDE_NETWORK;
960 }
961 }
962}
963
964bool
968
969int
971 const double rightSide = getRightSideOnEdge();
972 const std::vector<double>& sublaneSides = myLane->getEdge().getSubLaneSides();
973 for (int i = 0; i < (int)sublaneSides.size(); ++i) {
974 if (sublaneSides[i] > rightSide) {
975 return MAX2(i - 1, 0);
976 }
977 }
978 return (int)sublaneSides.size() - 1;
979}
980
981int
983 const double leftSide = getLeftSideOnEdge();
984 const std::vector<double>& sublaneSides = myLane->getEdge().getSubLaneSides();
985 for (int i = (int)sublaneSides.size() - 1; i >= 0; --i) {
986 if (sublaneSides[i] < leftSide) {
987 return i;
988 }
989 }
990 return -1;
991}
992
993
994std::string
996 return toString((LaneChangeAction)getLaneChangeModel().getSavedState(-1).second);
997}
998
999std::string
1001 return toString((LaneChangeAction)getLaneChangeModel().getSavedState(1).second);
1002}
1003
1004std::string
1006 return toString((LaneChangeAction)getLaneChangeModel().getSavedState(0).second);
1007}
1008
1009std::string
1011 return Named::getIDSecure(myLane, "n/a");
1012}
1013
1014std::string
1018
1019std::string
1021 return Named::getIDSecure(getLaneChangeModel().getShadowLane(), "");
1022}
1023
1024std::string
1026 return Named::getIDSecure(getLaneChangeModel().getTargetLane(), "");
1027}
1028
1029double
1033
1034std::string
1036 return std::bitset<6>(getInfluencer()->getSpeedMode()).to_string();
1037}
1038
1039std::string
1041 return std::bitset<12>(getInfluencer()->getLaneChangeMode()).to_string();
1042}
1043
1044void
1046 SUMOTime intermediateDuration = TIME2STEPS(20);
1047 SUMOTime finalDuration = SUMOTime_MAX;
1048 if (myParameter->stops.size() >= 2) {
1049 // copy durations from the original stops
1050 intermediateDuration = myParameter->stops.front().duration;
1051 finalDuration = myParameter->stops.back().duration;
1052 }
1053 // if the stop is already in the list of stops, cancel all stops that come
1054 // after it and set the stop duration
1055 std::string line = "";
1056 int destinations = 0;
1057 bool add = true;
1058 for (auto it = myStops.begin(); it != myStops.end(); it++) {
1059 if (!it->reached && destinations < 2 && it->busstop != nullptr) {
1060 line += it->busstop->getID();
1061 destinations++;
1062 }
1063 if (it->busstop == busStop) {
1064 it->duration = finalDuration;
1065 myStops.erase(++it, myStops.end());
1066 add = false;
1067 break;
1068 } else {
1069 it->duration = MIN2(it->duration, intermediateDuration);
1070 }
1071 }
1072 if (destinations < 2) {
1073 line += busStop->getID();
1074 }
1075 if (add) {
1076 // create new stop
1078 stopPar.busstop = busStop->getID();
1079 stopPar.lane = busStop->getLane().getID();
1080 stopPar.startPos = busStop->getBeginLanePosition();
1081 stopPar.endPos = busStop->getEndLanePosition();
1082 stopPar.duration = finalDuration;
1083 stopPar.until = -1;
1084 stopPar.triggered = false;
1085 stopPar.containerTriggered = false;
1086 stopPar.parking = ParkingType::ONROAD;
1087 stopPar.index = STOP_INDEX_FIT;
1089 // clean up prior route to improve visualisation, ensure that the stop can be added immediately
1090 ConstMSEdgeVector edges = myRoute->getEdges();
1091 edges.erase(edges.begin(), edges.begin() + getRoutePosition());
1092 edges.push_back(&busStop->getLane().getEdge());
1093 replaceRouteEdges(edges, -1, 0, "DRT.tmp", false, false, false);
1094 std::string errorMsg;
1095 // add stop
1096 addStop(stopPar, errorMsg);
1097 }
1098 const bool hasReroutingDevice = getDevice(typeid(MSDevice_Routing)) != nullptr;
1099 SUMOAbstractRouter<MSEdge, SUMOVehicle>& router = hasReroutingDevice
1102 // reroute to ensure the new stop is reached
1103 reroute(MSNet::getInstance()->getCurrentTimeStep(), "DRT", router);
1104 myParameter->line = line;
1105 assert(haveValidStopEdges());
1106}
1107
1109GUIVehicle::getVisualPosition(bool s2, const double offset) const {
1110 if (s2) {
1111 // see MSVehicle::getPosition
1112 if (myLane == nullptr) {
1113 return Position::INVALID;
1114 }
1115 if (isParking()) {
1116 if (myStops.begin()->parkingarea != nullptr) {
1117 return myStops.begin()->parkingarea->getVehiclePosition(*this);
1118 } else {
1119 // position beside the road
1120 PositionVector shp = myLane->getEdge().getLanes()[0]->getShape(s2);
1122 return shp.positionAtOffset((getPositionOnLane() + offset) * myLane->getLengthGeometryFactor(s2));
1123 }
1124 }
1125 const PositionVector& shape = myLane->getShape(s2);
1126 const double posLat = (MSGlobals::gLefthand ? 1 : -1) * getLateralPositionOnLane();
1127 return shape.positionAtOffset((getPositionOnLane() + offset) * myLane->getLengthGeometryFactor(s2), posLat);
1128 } else {
1129 return getPosition(offset);
1130 }
1131}
1132
1133
1134double
1136 if (s2) {
1137 // see MSVehicle::computeAngle
1138 const PositionVector& shape = myLane->getShape(s2);
1139 if (isParking()) {
1140 if (myStops.begin()->parkingarea != nullptr) {
1141 return myStops.begin()->parkingarea->getVehicleAngle(*this);
1142 } else {
1144 }
1145 }
1146 // if (myLaneChangeModel->isChangingLanes()) {
1147 const double lefthandSign = (MSGlobals::gLefthand ? -1 : 1);
1148 Position p1 = getVisualPosition(s2);
1149 Position p2 = getVisualPosition(s2, MAX2(0.0, -myType->getLength()));
1150 double result = (p1 != p2 ? p2.angleTo2D(p1) :
1153 result += lefthandSign * DEG2RAD(myLaneChangeModel->getAngleOffset());
1154 }
1155 return result;
1156 } else {
1157 return getAngle();
1158 }
1159}
1160/****************************************************************************/
long long int SUMOTime
Definition GUI.h:36
@ GLO_VEHICLE
a vehicle
GUISelectedStorage gSelected
A global holder of selected objects.
#define BLINKER_POS_FRONT
#define LANECHANGEMODE_DEFAULT
#define SPEEDMODE_DEFAULT
void drawAction_drawBlinker(double dir, double length)
#define BLINKER_POS_BACK
#define DEG2RAD(x)
Definition GeomHelper.h:35
#define RAD2DEG(x)
Definition GeomHelper.h:36
std::vector< const MSEdge * > ConstMSEdgeVector
Definition MSEdge.h:74
ConstMSEdgeVector::const_iterator MSRouteIterator
Definition MSRoute.h:56
#define WRITE_WARNINGF(...)
Definition MsgHandler.h:271
#define TL(string)
Definition MsgHandler.h:287
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 SIMSTEP
Definition SUMOTime.h:61
#define SUMOTime_MAX
Definition SUMOTime.h:34
#define SIMTIME
Definition SUMOTime.h:62
#define TIME2STEPS(x)
Definition SUMOTime.h:57
const long long int VTYPEPARS_ACTIONSTEPLENGTH_SET
@ GIVEN
The alignment as offset is given.
std::string getVehicleShapeName(SUMOVehicleShape id)
Returns the class name of the shape class given by its id.
StringBijection< SUMOVehicleClass > SumoVehicleClassStrings(sumoVehicleClassStringInitializer, SVC_CUSTOM2, false)
@ SVC_RAIL_CLASSES
classes which drive on tracks
@ RAIL_CAR
render as a (city) rail without locomotive
@ TRUCK_1TRAILER
render as a transport vehicle with one trailer
@ TRUCK_SEMITRAILER
render as a semi-trailer transport vehicle ("Sattelschlepper")
const int STOP_START_SET
const int STOP_INDEX_FIT
const int STOP_END_SET
SumoXMLTag
Numbers representing SUMO-XML - element names.
LaneChangeAction
The state of a vehicle's lane-change behavior.
int gPrecision
the precision for floating point outputs
Definition StdDefs.cpp:26
bool gDebugFlag1
global utility flags for debugging
Definition StdDefs.cpp:35
const double INVALID_DOUBLE
invalid double
Definition StdDefs.h:64
const double SUMO_const_laneWidth
Definition StdDefs.h:48
#define UNUSED_PARAMETER(x)
Definition StdDefs.h:30
T MIN2(T a, T b)
Definition StdDefs.h:76
T MAX2(T a, T b)
Definition StdDefs.h:82
const double SUMO_const_waitingContainerWidth
Definition StdDefs.h:54
const double SUMO_const_waitingPersonWidth
Definition StdDefs.h:52
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
Definition ToString.h:46
std::string toStr(std::streamsize accuracy) const
Returns the string representation of this distribution.
static void drawLine(const Position &beg, double rot, double visLength)
Draws a thin line.
Definition GLHelper.cpp:421
static void setColor(const RGBColor &c)
Sets the gl-color to this value.
Definition GLHelper.cpp:583
static void drawFilledCircle(double width, int steps=8)
Draws a filled circle around (0,0)
Definition GLHelper.cpp:498
static void popMatrix()
pop matrix
Definition GLHelper.cpp:130
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 RGBColor getColor()
gets the gl-color
Definition GLHelper.cpp:589
static void drawBoxLine(const Position &beg, double rot, double visLength, double width, double offset=0)
Draws a thick line.
Definition GLHelper.cpp:277
static void pushMatrix()
push matrix
Definition GLHelper.cpp:117
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 bool drawAction_drawVehicleAsImage(const GUIVisualizationSettings &s, const std::string &file, const GUIGlObject *o, const double width, double length)
try to draw vehicle as raster image and return true if successful
static void drawAction_drawVehicleAsPoly(const GUIVisualizationSettings &s, const SUMOVehicleShape shape, const double width, const double length, int carriageIndex=-1, bool isStopped=false, bool amReversed=false)
draw vehicle as a polygon
A MSVehicle extended by some values for usage within the gui.
void drawParkingInfo(const GUIVisualizationSettings &s, const RGBColor &col) const
int getNumContainers() const
return the number of passengers
static void drawLinkItem(const Position &pos, SUMOTime arrivalTime, SUMOTime leaveTime, double exagerate)
double getScaleValue(const GUIVisualizationSettings &s, int activeScheme) const
gets the size multiplier value according to the current scheme index
void computeSeats(const Position &front, const Position &back, double seatOffset, int maxSeats, double exaggeration, int &requiredSeats, Seats &into) const
add seats to mySeatPositions and update requiredSeats
@ VO_DRAW_OUTSIDE_NETWORK
draw vehicle outside the road network
bool drawReversed(const GUIVisualizationSettings &s) const
whether to reverse trains in their reversed state
FXMutex myLock
The mutex used to avoid concurrent updates of the vehicle buffer.
double getNaviDegree() const
return the current angle in navigational degrees
int getNumPassengers() const
return the number of passengers
std::map< GUISUMOAbstractView *, int > myAdditionalVisualizations
Enabled visualisations, per view.
void drawStopLabels(const GUIVisualizationSettings &s, bool noLoop, const RGBColor &col) const
Seats mySeatPositions
positions of seats in the vehicle (updated at every drawing step)
std::string getDeviceDescription()
lists equipped device (types) for the current vehicle
const MSVehicleType & getVType() const
A shortcut to myVehicle.myType.
GUIGlObjectType getType() const
Returns the type of the object as coded in GUIGlObjectType.
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:1066
const PositionVector & getShape(bool secondary) const override
Definition GUILane.cpp:1060
const std::vector< double > & getShapeLengths(bool secondary) const
Definition GUILane.cpp:1072
GUISUMOAbstractView * getActiveView() const
get the active view or 0
static GUIMainWindow * getInstance()
get instance
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.
T getColor(const double value) const
bool removeAdditionalGLVisualisation(GUIGlObject *const which)
Removes an object from the list of objects that show additional things.
bool addAdditionalGLVisualisation(GUIGlObject *const which)
Adds an object to call its additional visualisation method.
void select(GUIGlID id, bool update=true)
Adds the object with the given id.
bool isSelected(GUIGlObjectType type, GUIGlID id)
Returns the information whether the object with the given type and id is selected.
A MSVehicle extended by some values for usage within the gui.
Definition GUIVehicle.h:51
bool isSelected() const
whether this vehicle is selected in the GUI
int getLeftSublaneOnEdge() const
double getAngle() const
Return current angle.
Definition GUIVehicle.h:81
Position getPosition(const double offset=0) const
Return current position (x/y, cartesian)
Definition GUIVehicle.h:71
double getColorValue(const GUIVisualizationSettings &s, int activeScheme) const
gets the color value according to the current scheme index
std::string getDynamicAlignment() const
return the current lateral alignment as string
double getVisualAngle(bool s2) const
Returns the vehicle's direction in radians taking into account secondary shape.
void selectBlockingFoes() const
adds the blocking foes to the current selection
GUIParameterTableWindow * getTypeParameterWindow(GUIMainWindow &app, GUISUMOAbstractView &parent)
Returns an own type parameter window.
void drawBestLanes() const
Draws the vehicle's best lanes.
void drawOutsideNetwork(bool add)
register vehicle for drawing while outside the network
int getRightSublaneOnEdge() const
return the righmost sublane on the edge occupied by the vehicle
void drawRouteHelper(const GUIVisualizationSettings &s, ConstMSRoutePtr r, bool future, bool noLoop, const RGBColor &col) const
Draws the route.
MSLane * getPreviousLane(MSLane *current, int &furtherIndex) const
std::string getStopInfo() const
retrieve information about the current stop state
GUIParameterTableWindow * getParameterWindow(GUIMainWindow &app, GUISUMOAbstractView &parent)
Returns an own parameter window.
std::string getBackLaneIDs() const
double getLeftSideOnEdge() const
return left vehicle side on current edge
Definition GUIVehicle.h:144
void drawAction_drawCarriageClass(const GUIVisualizationSettings &s, bool asImage) const
draws the given guiShape with distinct carriages/modules
std::string getShadowLaneID() const
double getManeuverDist() const
return the lane-change maneuver distance
double getRightSideOnEdge2() const
return right vehicle side on current edge (without argument)
Definition GUIVehicle.h:140
std::string getSpeedMode() const
return the speed mode as bit string
GUIVehicle(SUMOVehicleParameter *pars, ConstMSRoutePtr route, MSVehicleType *type, const double speedFactor)
Constructor.
void drawAction_drawVehicleBlinker(double length) const
void rerouteDRTStop(MSStoppingPlace *busStop)
handle route to accomodate to given stop
std::string getLCStateRight() const
return the lanechange state
void drawAction_drawVehicleBlueLight() const
double getLastLaneChangeOffset() const
Returns the time since the last lane change in seconds.
std::string getLaneID() const
return vehicle lane id
void drawAction_drawLinkItems(const GUIVisualizationSettings &s) const
std::string getTargetLaneID() const
std::string getLCStateLeft() const
Position getVisualPosition(bool s2, const double offset=0) const
Return current position taking into account secondary shape.
void drawAction_drawVehicleBrakeLight(double length, bool onlyOne=false) const
~GUIVehicle()
destructor
std::string getLCStateCenter() const
std::string getLaneChangeMode() const
return the lane change mode as bit string
Stores the information about how to visualize structures.
GUIVisualizationTextSettings vehicleName
GUIVisualizationSizeSettings vehicleSize
GUIVisualizationTextSettings vehicleValue
bool gaming
whether the application is in gaming mode or not
std::string vehicleParam
key for coloring by vehicle parameter
GUIScaler vehicleScaler
The size scaling settings for vehicles.
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.
double getManeuverDist() const
Returns the remaining unblocked distance for the current maneuver. (only used by sublane model)
MSLane * getShadowLane() const
Returns the lane the vehicle's shadow is on during continuous/sublane lane change.
int getShadowDirection() const
return the direction in which the current shadow lane lies
double getSpeedLat() const
return the lateral speed of the current lane change maneuver
double getAngleOffset() const
return the angle offset resulting from lane change and sigma
bool isChangingLanes() const
return true if the vehicle currently performs a lane change maneuver
The base class for microscopic and mesoscopic vehicles.
double getMaxSpeed() const
Returns the maximum speed (the minimum of desired and technical maximum speed)
MSVehicleDevice * getDevice(const std::type_info &type) const
Returns a device of the given type if it exists, nullptr otherwise.
bool haveValidStopEdges(bool silent=false) const
check whether all stop.edge MSRouteIterators are valid and in order
std::list< MSStop > myStops
The vehicle's list of stops.
double getImpatience() const
Returns this vehicles impatience.
virtual double getLateralPositionOnLane() const
Get the vehicle's lateral position on the lane.
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.
const SUMOVehicleParameter::Stop * getNextStopParameter() const
return parameters for the next stop (SUMOVehicle Interface)
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.
double getHarmonoise_NoiseEmissions() const
Returns noise emissions of the current state.
int getPersonNumber() const
Returns the number of persons.
MSRouteIterator myCurrEdge
Iterator to current route-edge.
ConstMSRoutePtr myRoute
This vehicle's route.
double getWidth() const
Returns the vehicle's width.
double getStateOfCharge() const
Returns actual state of charge of battery (Wh) RICE_CHECK: This may be a misnomer,...
double getWaitingSeconds() const
Returns the number of seconds waited (speed was lesser than 0.1m/s)
bool hasStops() const
Returns whether the vehicle has to stop somewhere.
std::string getPrefixedParameter(const std::string &key, std::string &error) const
retrieve parameters of devices, models and the vehicle itself
SUMOVehicleClass getVClass() const
Returns the vehicle's access class.
bool addStop(const SUMOVehicleParameter::Stop &stopPar, std::string &errorMsg, SUMOTime untilOffset=0, MSRouteIterator *searchStart=nullptr)
Adds a stop.
int getRoutePosition() const
return index of edge within route
SUMOTime getDepartDelay() const
Returns the depart delay.
double getElecHybridCurrent() const
Returns actual current (A) of ElecHybrid device RICE_CHECK: Is this the current consumed from the ove...
const SUMOVehicleParameter * myParameter
This vehicle's parameter.
int getNumberReroutes() const
Returns the number of new routes this vehicle got.
void reroute(SUMOTime t, const std::string &info, SUMOAbstractRouter< MSEdge, SUMOVehicle > &router, const bool onInit=false, const bool withTaz=false, const bool silent=false)
Performs a rerouting using the given router.
int getRNGIndex() const
const MSVehicleType & getVehicleType() const
Returns the vehicle's type definition.
bool isStopped() const
Returns whether the vehicle is at a stop.
int getContainerNumber() const
Returns the number of containers.
bool replaceRouteEdges(ConstMSEdgeVector &edges, double cost, double savings, const std::string &info, bool onInit=false, bool check=false, bool removeStops=true, std::string *msgReturn=nullptr)
Replaces the current route by the given edges.
double getMaxDecel() const
Get the vehicle type's maximal comfortable deceleration [m/s^2].
Definition MSCFModel.h:264
A device which collects info on the vehicle trip (mainly on departure and arrival)
A device that performs vehicle rerouting based on current edge speeds.
A road/street connecting two junctions.
Definition MSEdge.h:77
const std::vector< MSLane * > & getLanes() const
Returns this edge's lanes.
Definition MSEdge.h:168
const std::vector< double > getSubLaneSides() const
Returns the right side offsets of this edge's sublanes.
Definition MSEdge.h:634
static bool gModelParkingManoeuver
whether parking simulation includes manoeuver time and any associated lane blocking
Definition MSGlobals.h:157
static double gLateralResolution
Definition MSGlobals.h:97
static bool gLefthand
Whether lefthand-drive is being simulated.
Definition MSGlobals.h:169
static bool gSublane
whether sublane simulation is enabled (sublane model or continuous lanechanging)
Definition MSGlobals.h:160
static SUMOTime gLaneChangeDuration
Definition MSGlobals.h:94
static SUMOTime gWaitingTimeMemory
length of memory for waiting times (in millisecs)
Definition MSGlobals.h:112
static bool gUsingInternalLanes
Information whether the simulation regards internal lanes.
Definition MSGlobals.h:78
Representation of a lane in the micro simulation.
Definition MSLane.h:84
virtual double getLengthGeometryFactor(bool) const
Definition MSLane.h:289
double getLength() const
Returns the lane's length.
Definition MSLane.h:593
double getVehicleMaxSpeed(const SUMOTrafficObject *const veh) const
Returns the lane's maximum speed, given a vehicle's speed limit adaptation.
Definition MSLane.h:565
bool isInternal() const
Definition MSLane.cpp:2456
MSLane * getBidiLane() const
retrieve bidirectional lane or nullptr
Definition MSLane.cpp:4425
virtual const PositionVector & getShape(bool) const
Definition MSLane.h:293
MSEdge & getEdge() const
Returns the lane's edge.
Definition MSLane.h:745
double getWidth() const
Returns the lane's width.
Definition MSLane.h:622
const Position geometryPositionAtOffset(double offset, double lateralOffset=0) const
Definition MSLane.h:551
static MSNet * getInstance()
Returns the pointer to the unique instance of MSNet (singleton).
Definition MSNet.cpp:183
SUMOAbstractRouter< MSEdge, SUMOVehicle > & getRouterTT(const int rngIndex, const MSEdgeVector &prohibited=MSEdgeVector()) const
Definition MSNet.cpp:1465
static SUMOAbstractRouter< MSEdge, SUMOVehicle > & getRouterTT(const int rngIndex, SUMOVehicleClass svc, const MSEdgeVector &prohibited=MSEdgeVector())
return the router instance
A lane area vehicles can halt at.
double getBeginLanePosition() const
Returns the begin position of this stop.
double getEndLanePosition() const
Returns the end position of this stop.
const MSLane & getLane() const
Returns the lane this stop is located at.
bool isRemoteAffected(SUMOTime t) const
double pos() const
Position of this state.
Definition MSVehicle.h:107
Representation of a vehicle in the micro simulation.
Definition MSVehicle.h:77
double getRightSideOnEdge(const MSLane *lane=0) const
Get the vehicle's lateral position on the edge of the given lane (or its current edge if lane == 0)
double getTimeGapOnLane() const
Returns the time gap in seconds to the leader of the vehicle on the same lane.
double getStopDelay() const
Returns the public transport stop delay in seconds.
bool isOnRoad() const
Returns the information whether the vehicle is on a road (is simulated)
Definition MSVehicle.h:608
SUMOTime getWaitingTime() const
Returns the SUMOTime waited (speed was lesser than 0.1m/s)
Definition MSVehicle.h:672
bool isActive() const
Returns whether the current simulation step is an action point for the vehicle.
Definition MSVehicle.h:631
double getTimeLossSeconds() const
Returns the time loss in seconds.
Definition MSVehicle.h:723
double getAccumulatedWaitingSeconds() const
Returns the number of seconds waited (speed was lesser than 0.1m/s) within the last millisecs.
Definition MSVehicle.h:717
double getTimeSinceStartupSeconds() const
Definition MSVehicle.h:686
MSAbstractLaneChangeModel & getLaneChangeModel()
bool isActionStep(SUMOTime t) const
Returns whether the next simulation step will be an action point for the vehicle.
Definition MSVehicle.h:638
MSAbstractLaneChangeModel * myLaneChangeModel
Definition MSVehicle.h:1884
std::vector< MSLane * > myFurtherLanes
The information into which lanes the vehicle laps into.
Definition MSVehicle.h:1911
bool signalSet(int which) const
Returns whether the given signal is on.
Definition MSVehicle.h:1191
double getAcceleration() const
Returns the vehicle's acceleration in m/s (this is computed as the last step's mean acceleration in c...
Definition MSVehicle.h:517
const std::vector< MSLane * > & getBestLanesContinuation() const
Returns the best sequence of lanes to continue the route starting at myLane.
int getBestLaneOffset() const
double getStopArrivalDelay() const
Returns the estimated public transport stop arrival delay in seconds.
@ VEH_SIGNAL_BLINKER_RIGHT
Right blinker lights are switched on.
Definition MSVehicle.h:1113
@ VEH_SIGNAL_BRAKELIGHT
The brake lights are on.
Definition MSVehicle.h:1119
@ VEH_SIGNAL_EMERGENCY_BLUE
A blue emergency light is on.
Definition MSVehicle.h:1135
@ VEH_SIGNAL_BLINKER_LEFT
Left blinker lights are switched on.
Definition MSVehicle.h:1115
@ VEH_SIGNAL_BLINKER_EMERGENCY
Blinker lights on both sides are switched on.
Definition MSVehicle.h:1117
const MSLane * getLane() const
Returns the lane the vehicle is on.
Definition MSVehicle.h:584
bool isLeader(const MSLink *link, const MSVehicle *veh, const double gap) const
whether the given vehicle must be followed at the given junction
Influencer & getInfluencer()
std::vector< std::vector< LaneQ > > myBestLanes
Definition MSVehicle.h:1894
double getLateralPositionOnLane() const
Get the vehicle's lateral position on the lane.
Definition MSVehicle.h:416
double getSlope() const
Returns the slope of the road at vehicle's position in degrees.
double getSpeed() const
Returns the vehicle's current speed.
Definition MSVehicle.h:493
const MSCFModel & getCarFollowModel() const
Returns the vehicle's car following model definition.
Definition MSVehicle.h:978
double getPositionOnLane() const
Get the vehicle's position along the lane.
Definition MSVehicle.h:377
MSLane * myLane
The lane the vehicle is on.
Definition MSVehicle.h:1882
bool hasInfluencer() const
whether the vehicle is individually influenced (via TraCI or special parameters)
Definition MSVehicle.h:1682
State myState
This Vehicles driving state (pos and speed)
Definition MSVehicle.h:1865
DriveItemVector myLFLinkLanes
container for the planned speeds in the current step
Definition MSVehicle.h:2006
The car-following model and parameter.
double getMinGapLat() const
Get the minimum lateral gap that vehicles of this type maintain.
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.
const LatAlignmentDefinition & getPreferredLateralAlignment() const
Get vehicle's preferred lateral alignment procedure.
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.
SUMOTime getLoadingDuration(const bool isPerson) const
Get this vehicle type's loading duration.
double getHeight() const
Get the height which vehicles of this class shall have when being drawn.
double getActionStepLengthSecs() const
Returns this type's default action step length in seconds.
double getMaxSpeedLat() const
Get vehicle's maximum lateral speed [m/s].
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
double getPreferredLateralAlignmentOffset() const
Get vehicle's preferred lateral alignment offset (in m from center line)
int getContainerCapacity() const
Get this vehicle type's container capacity.
static std::string getIDSecure(const T *obj, const std::string &fallBack="NULL")
get an identifier for Named-like object which may be Null
Definition Named.h:67
const std::string & getID() const
Returns the id.
Definition Named.h:74
virtual const std::string getParameter(const std::string &key, const std::string defaultValue="") const
Returns the value for a given key.
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
static const Position INVALID
used to indicate that a position is valid
Definition Position.h:300
double distanceTo2D(const Position &p2) const
returns the euclidean distance in the x-y-plane
Definition Position.h:254
double x() const
Returns the x-position.
Definition Position.h:55
double angleTo2D(const Position &other) const
returns the angle in the plane of the vector pointing from here to the other position
Definition Position.h:264
double y() const
Returns the y-position.
Definition Position.h:60
A list of positions.
double length() const
Returns the length.
double rotationAtOffset(double pos) const
Returns the rotation at the given length.
Position positionAtOffset(double pos, double lateralOffset=0) const
Returns the position at the given length.
void move2side(double amount, double maxExtension=100)
move position vector to side using certain ammount
double angleAt2D(int pos) const
get angle in certain position of position vector
RGBColor changedBrightness(int change, int toChange=3) const
Returns a new color with altered brightness.
Definition RGBColor.cpp:200
bool wasSet(long long int what) const
Returns whether the given parameter was set.
double carriageLength
the length of train carriages and locomotive
Distribution_Parameterized speedFactor
The factor by which the maximum speed may deviate from the allowed max speed on the street.
SubParams lcParameter
Lane-changing parameter.
SubParams jmParameter
Junction-model parameter.
std::string getManoeuverAngleTimesS() const
Returns myManoeuverAngleTimes as a string for xml output.
Definition of vehicle stop (position and duration)
ParkingType parking
whether the vehicle is removed from the net while stopping
std::string lane
The lane to stop at.
double startPos
The stopping position start.
double posLat
the lateral offset when stopping
int parametersSet
Information for the output which parameter were set.
int index
at which position in the stops list
SUMOTime until
The time at which the vehicle may continue its journey.
bool triggered
whether an arriving person lets the vehicle continue
double endPos
The stopping position end.
std::string busstop
(Optional) bus stop if one is assigned to the stop
bool containerTriggered
whether an arriving container lets the vehicle continue
SUMOTime duration
The stopping duration.
Structure representing possible vehicle parameter.
std::vector< Stop > stops
List of the stops the vehicle will make, TraCI may add entries here.
std::string line
The vehicle's line (mainly for public transport)
static StringBijection< SumoXMLTag > CarFollowModels
car following models
static StringBijection< LaneChangeModel > LaneChangeModels
lane change models
static double toDouble(const std::string &sData)
converts a string into the double value described by it by calling the char-type converter
static bool toBool(const std::string &sData)
converts a string into the bool value described by it by calling the char-type converter
#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
Drive process items represent bounds on the safe velocity corresponding to the upcoming links.
Definition MSVehicle.h:1950
double getLeaveSpeed() const
Definition MSVehicle.h:1996