Eclipse SUMO - Simulation of Urban MObility
GUIVehicle.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-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
92}
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
211 // add items
212 ret->mkItem("Type Information:", false, "");
213 ret->mkItem("type [id]", false, myType->getID());
214 ret->mkItem("length", false, myType->getLength());
215 ret->mkItem("width", false, myType->getWidth());
216 ret->mkItem("height", false, myType->getHeight());
217 ret->mkItem("minGap", false, myType->getMinGap());
218 ret->mkItem("vehicle class", false, SumoVehicleClassStrings.getString(myType->getVehicleClass()));
219 ret->mkItem("emission class", false, PollutantsInterface::getName(myType->getEmissionClass()));
220 ret->mkItem("carFollowModel", false, SUMOXMLDefinitions::CarFollowModels.getString((SumoXMLTag)getCarFollowModel().getModelID()));
221 ret->mkItem("LaneChangeModel", false, SUMOXMLDefinitions::LaneChangeModels.getString(getLaneChangeModel().getModelID()));
222 ret->mkItem("guiShape", false, getVehicleShapeName(myType->getGuiShape()));
223 ret->mkItem("maximum speed [m/s]", false, getVehicleType().getMaxSpeed());
224 ret->mkItem("desired maximum speed [m/s]", false, getVehicleType().getDesiredMaxSpeed());
225 ret->mkItem("maximum acceleration [m/s^2]", false, getCarFollowModel().getMaxAccel());
226 ret->mkItem("maximum deceleration [m/s^2]", false, getCarFollowModel().getMaxDecel());
227 ret->mkItem("emergency deceleration [m/s^2]", false, getCarFollowModel().getEmergencyDecel());
228 ret->mkItem("apparent deceleration [m/s^2]", false, getCarFollowModel().getApparentDecel());
229 ret->mkItem("imperfection (sigma)", false, getCarFollowModel().getImperfection());
230 ret->mkItem("desired headway (tau)", false, getCarFollowModel().getHeadwayTime());
231 ret->mkItem("speedFactor", false, myType->getParameter().speedFactor.toStr(gPrecision));
233 ret->mkItem("action step length [s]", false, myType->getActionStepLengthSecs());
234 }
235 ret->mkItem("person capacity", false, myType->getPersonCapacity());
236 ret->mkItem("boarding time", false, STEPS2TIME(myType->getLoadingDuration(true)));
237 ret->mkItem("container capacity", false, myType->getContainerCapacity());
238 ret->mkItem("loading time", false, STEPS2TIME(myType->getLoadingDuration(false)));
240 ret->mkItem("minGapLat", false, myType->getMinGapLat());
241 ret->mkItem("maxSpeedLat", false, myType->getMaxSpeedLat());
242 ret->mkItem("latAlignment", true, new FunctionBindingString<GUIVehicle>(this, &GUIVehicle::getDynamicAlignment));
243 } else if (MSGlobals::gLaneChangeDuration > 0) {
244 ret->mkItem("maxSpeedLat", false, myType->getMaxSpeedLat());
245 }
246 for (auto item : myType->getParameter().lcParameter) {
247 ret->mkItem(toString(item.first).c_str(), false, toString(item.second));
248 }
249 for (auto item : myType->getParameter().jmParameter) {
250 ret->mkItem(toString(item.first).c_str(), false, toString(item.second));
251 }
253 ret->mkItem("manoeuver Angle vs Times", false, myType->getParameter().getManoeuverAngleTimesS());
254 }
255
256 // close building
258 return ret;
259}
260
261
262std::string
267 std::string align2 = toString(getLaneChangeModel().getDesiredAlignment());
268 if (align2 != align) {
269 align = align2 + " (default: " + align + ")";
270 }
271 return align;
272}
273
274void
276 glTranslated(0, 0, getType() + .2); // draw on top of cars
277 for (DriveItemVector::const_iterator i = myLFLinkLanes.begin(); i != myLFLinkLanes.end(); ++i) {
278 if ((*i).myLink == nullptr) {
279 continue;
280 }
281 MSLink* link = (*i).myLink;
282 MSLane* via = link->getViaLaneOrLane();
283 if (via != nullptr) {
284 Position p = via->getShape()[0];
285 if ((*i).mySetRequest) {
286 glColor3d(0, .8, 0);
287 } else {
288 glColor3d(.8, 0, 0);
289 }
290 const SUMOTime leaveTime = (*i).myLink->getLeaveTime(
291 (*i).myArrivalTime, (*i).myArrivalSpeed, (*i).getLeaveSpeed(), getVehicleType().getLength());
292 drawLinkItem(p, (*i).myArrivalTime, leaveTime, s.vehicleName.size / s.scale);
293 // the time slot that ego vehicle uses when checking opened may
294 // differ from the one it requests in setApproaching
295 MSLink::ApproachingVehicleInformation avi = (*i).myLink->getApproaching(this);
296 assert(avi.arrivalTime == (*i).myArrivalTime && avi.leavingTime == leaveTime);
297 UNUSED_PARAMETER(avi); // only used for assertion
298 }
299 }
300 glTranslated(0, 0, getType() - .2); // draw on top of cars
301}
302
303
304void
306 const bool s2 = s.secondaryShape;
307 RGBColor current = GLHelper::getColor();
308 RGBColor darker = current.changedBrightness(-51);
309 const double exaggeration = (s.vehicleSize.getExaggeration(s, this)
311 const double totalLength = getVType().getLength();
312 double upscaleLength = exaggeration;
313 if (exaggeration > 1 && totalLength > 5) {
314 // reduce the length/width ratio because this is not useful at high zoom
315 const double widthLengthFactor = totalLength / 5;
316 const double shrinkFactor = MIN2(widthLengthFactor, sqrt(upscaleLength));
317 upscaleLength /= shrinkFactor;
318 }
319 const double locomotiveLength = getVehicleType().getParameter().locomotiveLength * upscaleLength;
320 if (exaggeration == 0) {
321 return;
322 }
323 const double defaultLength = getVehicleType().getParameter().carriageLength * upscaleLength;
324 const double carriageGap = getVehicleType().getParameter().carriageGap * upscaleLength;
325 const double length = totalLength * upscaleLength;
326 const double halfWidth = getVehicleType().getWidth() / 2.0 * exaggeration;
327 GLHelper::popMatrix(); // undo initial translation and rotation
328 const double xCornerCut = 0.3 * exaggeration;
329 const double yCornerCut = 0.4 * exaggeration;
330 // round to closest integer
331 const int numCarriages = MAX2(1, 1 + (int)((length - locomotiveLength) / (defaultLength + carriageGap) + 0.5));
332 assert(numCarriages > 0);
333 double carriageLengthWithGap = length / numCarriages;
334 double carriageLength = carriageLengthWithGap - carriageGap;
335 double firstCarriageLength = carriageLength;
336 if (defaultLength != locomotiveLength && numCarriages > 1) {
337 firstCarriageLength = locomotiveLength;
338 carriageLengthWithGap = (length - locomotiveLength) / (numCarriages - 1);
339 carriageLength = carriageLengthWithGap - carriageGap;
340 }
341 const int firstPassengerCarriage = defaultLength == locomotiveLength || numCarriages == 1 || (getVClass() & SVC_RAIL_CLASSES) == 0 ? 0 : 1;
342 const int noPersonsBackCarriages = (getVehicleType().getGuiShape() == SUMOVehicleShape::TRUCK_SEMITRAILER || getVehicleType().getGuiShape() == SUMOVehicleShape::TRUCK_1TRAILER) && numCarriages > 1 ? 1 : 0;
343 const int firstContainerCarriage = numCarriages == 1 || getVehicleType().getGuiShape() == SUMOVehicleShape::TRUCK_1TRAILER ? 0 : 1;
344 const int seatsPerCarriage = (int)ceil(getVType().getPersonCapacity() / (numCarriages - firstPassengerCarriage - noPersonsBackCarriages));
345 const int containersPerCarriage = (int)ceil(getVType().getContainerCapacity() / (numCarriages - firstContainerCarriage));
346 // lane on which the carriage front is situated
347 MSLane* lane = myLane;
348 int furtherIndex = 0;
349 // lane on which the carriage back is situated
350 MSLane* backLane = myLane;
351 int backFurtherIndex = furtherIndex;
352 // offsets of front and back
353 double carriageOffset = myState.pos();
355 // @note this still produces some artifacts while not fully on the current lane
356 carriageOffset = MIN2(carriageOffset + getLength(), lane->getLength());
357 }
358 double carriageBackOffset = carriageOffset - firstCarriageLength;
359 // handle seats
360 int requiredSeats = getNumPassengers();
361 int requiredPositions = getNumContainers();
362 if (requiredSeats > 0) {
363 mySeatPositions.clear();
364 }
365 if (requiredPositions > 0) {
366 myContainerPositions.clear();
367 }
368 Position front, back;
369 double angle = 0.;
370 // position parking vehicle beside the road or track
371 const double lateralOffset = (isParking() && getNextStopParameter()->posLat == INVALID_DOUBLE
372 ? (getLane()->getWidth() * (MSGlobals::gLefthand ? -1 : 1))
374
375 // draw individual carriages
376 double curCLength = firstCarriageLength;
377 int firstCarriageNo = 0; // default case - we're going forwards
378 const bool reversed = drawReversed(s) || getLaneChangeModel().isOpposite();
379 if (reversed) {
380 firstCarriageNo = numCarriages - 1;
381 if (numCarriages > 1) {
382 carriageBackOffset = carriageOffset - carriageLength;
383 }
384 }
385
386 //std::cout << SIMTIME << " veh=" << getID() << " curCLength=" << curCLength << " loc=" << locomotiveLength << " car=" << carriageLength << " tlen=" << totalLength << " len=" << length << "\n";
387 for (int i = 0; i < numCarriages; ++i) {
388 if (i == firstCarriageNo) {
389 curCLength = firstCarriageLength;
390 if (firstCarriageNo > 0) {
391 // previous loop iteration has adjusted backpos for a normal carriage so have to correct
392 carriageBackOffset += carriageLengthWithGap;
393 carriageBackOffset -= firstCarriageLength + carriageGap;
394 }
395 } else {
396 curCLength = carriageLength;
397 }
398 while (carriageOffset < 0) {
399 MSLane* prev = getPreviousLane(lane, furtherIndex);
400 if (prev != lane) {
401 carriageOffset += prev->getLength();
402 } else {
403 // no lane available for drawing.
404 carriageOffset = 0;
405 }
406 lane = prev;
407 }
408 while (carriageBackOffset < 0) {
409 MSLane* prev = getPreviousLane(backLane, backFurtherIndex);
410 if (prev != backLane) {
411 carriageBackOffset += prev->getLength();
412 } else {
413 // no lane available for drawing.
414 carriageBackOffset = 0;
415 }
416 backLane = prev;
417 }
418 front = lane->getShape(s2).positionAtOffset(carriageOffset * lane->getLengthGeometryFactor(s2), lateralOffset);
419 back = backLane->getShape(s2).positionAtOffset(carriageBackOffset * lane->getLengthGeometryFactor(s2), lateralOffset);
420 if (front == back) {
421 // no place for drawing available
422 continue;
423 }
424 const double drawnCarriageLength = front.distanceTo2D(back);
425 angle = atan2((front.x() - back.x()), (back.y() - front.y())) * (double) 180.0 / (double) M_PI;
426 // if we are in reverse 'first' carriages are drawn last so the >= test doesn't work
427 if (reversed) {
428 if (i <= numCarriages - firstPassengerCarriage) {
429 computeSeats(back, front, SUMO_const_waitingPersonWidth, seatsPerCarriage, exaggeration, requiredSeats, mySeatPositions);
430 }
431 if (i <= numCarriages - firstContainerCarriage) {
432 computeSeats(front, back, SUMO_const_waitingContainerWidth, containersPerCarriage, exaggeration, requiredPositions, myContainerPositions);
433 }
434 } else {
435 if (i >= firstPassengerCarriage) {
436 computeSeats(front, back, SUMO_const_waitingPersonWidth, seatsPerCarriage, exaggeration, requiredSeats, mySeatPositions);
437 }
438 if (i >= firstContainerCarriage) {
439 computeSeats(front, back, SUMO_const_waitingContainerWidth, containersPerCarriage, exaggeration, requiredPositions, myContainerPositions);
440 }
441 }
443 glTranslated(front.x(), front.y(), getType());
444 glRotated(angle, 0, 0, 1);
445 if (!asImage || !GUIBaseVehicleHelper::drawAction_drawVehicleAsImage(s, getVType().getImgFile(), this, getVType().getWidth() * exaggeration, curCLength)) {
446 switch (getVType().getGuiShape()) {
449 if (i == firstCarriageNo) { // at the moment amReversed is only ever set for rail - so has no impact in this call
450 GUIBaseVehicleHelper::drawAction_drawVehicleAsPoly(s, getVType().getGuiShape(), getVType().getWidth() * exaggeration, curCLength, 0, false, reversed);
451 } else {
452 GLHelper::setColor(current);
453 GLHelper::drawBoxLine(Position(0, 0), 180, curCLength, halfWidth);
454 }
455 break;
456 default: {
457 if (i == firstCarriageNo) {
458 GLHelper::setColor(darker);
459 } else {
460 GLHelper::setColor(current);
461 }
462 // generic rail carriage
463 glBegin(GL_TRIANGLE_FAN);
464 glVertex2d(-halfWidth + xCornerCut, 0);
465 glVertex2d(-halfWidth, yCornerCut);
466 glVertex2d(-halfWidth, drawnCarriageLength - yCornerCut);
467 glVertex2d(-halfWidth + xCornerCut, drawnCarriageLength);
468 glVertex2d(halfWidth - xCornerCut, drawnCarriageLength);
469 glVertex2d(halfWidth, drawnCarriageLength - yCornerCut);
470 glVertex2d(halfWidth, yCornerCut);
471 glVertex2d(halfWidth - xCornerCut, 0);
472 glEnd();
473 // indicate front of the head of the train
474 if (i == firstCarriageNo) {
475 glTranslated(0, 0, 0.1);
476 glColor3d(0, 0, 0);
477 glBegin(GL_TRIANGLE_FAN);
478 if (reversed) { // not quite correct as its drawing at the wrong end of the locomotive - however useful as visual indicator of reverse?
479 glVertex2d(-halfWidth + xCornerCut, yCornerCut);
480 glVertex2d(-halfWidth + 2 * xCornerCut, 3 * yCornerCut);
481 glVertex2d(halfWidth - 2 * xCornerCut, 3 * yCornerCut);
482 glVertex2d(halfWidth - xCornerCut, yCornerCut);
483 } else {
484 glVertex2d(-halfWidth + 2 * xCornerCut, yCornerCut);
485 glVertex2d(-halfWidth + xCornerCut, 3 * yCornerCut);
486 glVertex2d(halfWidth - xCornerCut, 3 * yCornerCut);
487 glVertex2d(halfWidth - 2 * xCornerCut, yCornerCut);
488 }
489 glEnd();
490 glTranslated(0, 0, -0.1);
491 }
492 }
493 }
494 }
496 carriageOffset -= (curCLength + carriageGap);
497 carriageBackOffset -= carriageLengthWithGap;
498 }
501 glTranslated(front.x(), front.y(), getType());
502 glRotated(angle, 0, 0, 1);
506 }
507 // restore matrix
509 front = getPosition();
510 glTranslated(front.x(), front.y(), getType());
511 const double degAngle = RAD2DEG(getAngle() + M_PI / 2.);
512 glRotated(degAngle, 0, 0, 1);
513 glScaled(exaggeration, upscaleLength, 1);
514 if (mySeatPositions.size() == 0) {
515 mySeatPositions.push_back(Seat(back, DEG2RAD(angle)));
516 }
517 if (myContainerPositions.size() == 0) {
518 myContainerPositions.push_back(Seat(back, DEG2RAD(angle)));
519 }
520}
521
522#define BLINKER_POS_FRONT .5
523#define BLINKER_POS_BACK .5
524
525inline void
526drawAction_drawBlinker(double dir, double length) {
527 glColor3d(1.f, .8f, 0);
529 glTranslated(dir, BLINKER_POS_FRONT, -0.1);
533 glTranslated(dir, length - BLINKER_POS_BACK, -0.1);
536}
537
538
539void
542 return;
543 }
544 const double offset = MAX2(.5 * getVehicleType().getWidth(), .4);
546 drawAction_drawBlinker(-offset, length);
547 }
549 drawAction_drawBlinker(offset, length);
550 }
552 drawAction_drawBlinker(-offset, length);
553 drawAction_drawBlinker(offset, length);
554 }
555}
556
557
558inline void
559GUIVehicle::drawAction_drawVehicleBrakeLight(double length, bool onlyOne) const {
561 return;
562 }
563 glColor3f(1.f, .2f, 0);
565 if (onlyOne) {
566 glTranslated(0, length, -0.1);
568 } else {
569 glTranslated(-getVehicleType().getWidth() * 0.5, length, -0.1);
573 glTranslated(getVehicleType().getWidth() * 0.5, length, -0.1);
575 }
577}
578
579inline void
583 glTranslated(0, 2.5, .5);
584 glColor3f(0, 0, 1);
587 }
588}
589
590
591double
592GUIVehicle::getColorValue(const GUIVisualizationSettings& s, int activeScheme) const {
593 switch (activeScheme) {
594 case 8:
595 if (isStopped()) {
596 return isParking() ? -2 : -1;
597 }
598 return getSpeed();
599 case 9:
600 // color by action step
601 if (isActionStep(SIMSTEP)) {
602 // Upcoming simstep is actionstep (t was already increased before drawing)
603 return 1.;
604 } else if (isActive()) {
605 // Completed simstep was actionstep
606 return 2.;
607 } else {
608 // not active
609 return 0.;
610 }
611 case 10:
612 return getWaitingSeconds();
613 case 11:
615 case 12:
617 case 13:
618 return getLane()->getVehicleMaxSpeed(this);
619 case 14:
620 return getEmissions<PollutantsInterface::CO2>();
621 case 15:
622 return getEmissions<PollutantsInterface::CO>();
623 case 16:
624 return getEmissions<PollutantsInterface::PM_X>();
625 case 17:
626 return getEmissions<PollutantsInterface::NO_X>();
627 case 18:
628 return getEmissions<PollutantsInterface::HC>();
629 case 19:
630 return getEmissions<PollutantsInterface::FUEL>();
631 case 20:
633 case 21:
634 return getNumberReroutes();
635 case 22:
637 case 23:
638 return getLaneChangeModel().isOpposite() ? -100 : getBestLaneOffset();
639 case 24:
640 return getAcceleration();
641 case 25:
642 return getTimeGapOnLane();
643 case 26:
644 return STEPS2TIME(getDepartDelay());
645 case 27:
646 return getEmissions<PollutantsInterface::ELEC>();
647 case 28:
648 return getTimeLossSeconds();
649 case 29:
650 return getStopDelay();
651 case 30:
652 return getStopArrivalDelay();
653 case 31:
655 case 32: // by numerical param value
656 std::string error;
657 std::string val = getPrefixedParameter(s.vehicleParam, error);
658 try {
659 if (val == "") {
661 } else {
662 return StringUtils::toDouble(val);
663 }
664 } catch (NumberFormatException&) {
665 try {
666 return StringUtils::toBool(val);
667 } catch (BoolFormatException&) {
668 WRITE_WARNINGF(TL("Vehicle parameter '%' key '%' is not a number for vehicle '%'."),
671 }
672 }
673 }
674 return 0;
675}
676
677
678void
680 myLock.lock();
681 std::vector<std::vector<MSVehicle::LaneQ> > bestLanes = myBestLanes;
682 myLock.unlock();
683 for (std::vector<std::vector<MSVehicle::LaneQ> >::iterator j = bestLanes.begin(); j != bestLanes.end(); ++j) {
684 std::vector<MSVehicle::LaneQ>& lanes = *j;
685 double gmax = -1;
686 double rmax = -1;
687 for (std::vector<MSVehicle::LaneQ>::const_iterator i = lanes.begin(); i != lanes.end(); ++i) {
688 gmax = MAX2((*i).length, gmax);
689 rmax = MAX2((*i).occupation, rmax);
690 }
691 for (std::vector<MSVehicle::LaneQ>::const_iterator i = lanes.begin(); i != lanes.end(); ++i) {
692 const PositionVector& shape = (*i).lane->getShape();
693 double g = (*i).length / gmax;
694 double r = (*i).occupation / rmax;
695 glColor3d(r, g, 0);
696 double width = 0.5 / (1 + abs((*i).bestLaneOffset));
697 GLHelper::drawBoxLines(shape, width);
698
699 PositionVector s1 = shape;
700 s1.move2side((double) .1);
701 glColor3d(r, 0, 0);
703 s1.move2side((double) - .2);
704 glColor3d(0, g, 0);
706
707 glColor3d(r, g, 0);
708 }
709 }
710}
711
712
713void
714GUIVehicle::drawRouteHelper(const GUIVisualizationSettings& s, ConstMSRoutePtr r, bool future, bool noLoop, const RGBColor& col) const {
715 const double exaggeration = s.vehicleSize.getExaggeration(s, this) * (s.gaming ? 0.5 : 1);
716 MSRouteIterator start = future ? myCurrEdge : r->begin();
717 MSRouteIterator i = start;
718 const std::vector<MSLane*>& bestLaneConts = getBestLanesContinuation();
719 // draw continuation lanes when drawing the current route where available
720 int bestLaneIndex = (r == myRoute ? 0 : (int)bestLaneConts.size());
721 std::map<const MSLane*, int> repeatLane; // count repeated occurrences of the same edge
722 const double textSize = s.vehicleName.size / s.scale;
723 const GUILane* prevLane = nullptr;
724 int reversalIndex = 0;
725 const int indexDigits = (int)toString(r->size()).size();
726 if (!isOnRoad() && !isParking()) {
727 // simulation time has already advanced so isRemoteControlled is always false
728 const std::string offRoadLabel = hasInfluencer() && getInfluencer()->isRemoteAffected(SIMSTEP) ? "offRoad" : "teleporting";
729 GLHelper::drawTextSettings(s.vehicleValue, offRoadLabel, getPosition(), s.scale, s.angle, 1.0);
730 } else if (myLane->isInternal()) {
731 bestLaneIndex++;
732 }
733 const bool s2 = s.secondaryShape;
734 for (; i != r->end(); ++i) {
735 const GUILane* lane;
736 if (bestLaneIndex < (int)bestLaneConts.size() && bestLaneConts[bestLaneIndex] != 0 && (*i) == &(bestLaneConts[bestLaneIndex]->getEdge())) {
737 lane = static_cast<GUILane*>(bestLaneConts[bestLaneIndex]);
738 ++bestLaneIndex;
739 } else {
740 const std::vector<MSLane*>* allowed = (*i)->allowedLanes(getVClass());
741 if (allowed != nullptr && allowed->size() != 0) {
742 lane = static_cast<GUILane*>((*allowed)[0]);
743 } else {
744 lane = static_cast<GUILane*>((*i)->getLanes()[0]);
745 }
746 }
748 GLHelper::drawBoxLines(lane->getShape(s2), lane->getShapeRotations(s2), lane->getShapeLengths(s2), exaggeration);
749 if (prevLane != nullptr && lane->getBidiLane() == prevLane) {
750 // indicate train reversal
751 std::string label = "reverse:" + toString(reversalIndex++);
752 if (s.showRouteIndex) {
753 label += "@r" + toString((int)(i - myCurrEdge));
754 }
755 Position pos = lane->geometryPositionAtOffset(lane->getLength() / 2) - Position(0, textSize * repeatLane[lane]);
756 GLHelper::drawTextSettings(s.vehicleValue, label, pos, s.scale, s.angle, 1.0);
757 }
758 if (s.showRouteIndex) {
759 std::string label = toString((int)(i - myCurrEdge));
760 const double laneAngle = lane->getShape(s2).angleAt2D(0);
761 Position pos = lane->getShape(s2).front() - Position(0, textSize * repeatLane[lane]) + Position(
762 (laneAngle >= -0.25 * M_PI && laneAngle < 0.75 * M_PI ? 1 : -1) * 0.4 * indexDigits * textSize, 0);
763 //GLHelper::drawText(label, pos, 1.0, textSize, s.vehicleName.color);
764 GLHelper::drawTextSettings(s.vehicleName, label, pos, s.scale, s.angle, 1.0);
765 }
766 repeatLane[lane]++;
767 prevLane = lane;
768 if (noLoop && i != start && (*i) == (*start)) {
769 break;
770 }
771 }
772 drawStopLabels(s, noLoop, col);
773 drawParkingInfo(s, col);
774}
775
776
777MSLane*
778GUIVehicle::getPreviousLane(MSLane* current, int& furtherIndex) const {
779 if (furtherIndex < (int)myFurtherLanes.size()) {
780 return myFurtherLanes[furtherIndex++];
781 } else {
782 // try to use route information
783 int routeIndex = getRoutePosition();
784 bool resultInternal;
785 if (MSGlobals::gUsingInternalLanes && MSNet::getInstance()->hasInternalLinks()) {
786 if (myLane->isInternal()) {
787 if (furtherIndex % 2 == 0) {
788 routeIndex -= (furtherIndex + 0) / 2;
789 resultInternal = false;
790 } else {
791 routeIndex -= (furtherIndex + 1) / 2;
792 resultInternal = false;
793 }
794 } else {
795 if (furtherIndex % 2 != 0) {
796 routeIndex -= (furtherIndex + 1) / 2;
797 resultInternal = false;
798 } else {
799 routeIndex -= (furtherIndex + 2) / 2;
800 resultInternal = true;
801 }
802 }
803 } else {
804 routeIndex -= furtherIndex;
805 resultInternal = false;
806 }
807 furtherIndex++;
808 if (routeIndex >= 0) {
809 if (resultInternal) {
810 const MSEdge* prevNormal = myRoute->getEdges()[routeIndex];
811 for (MSLane* cand : prevNormal->getLanes()) {
812 for (MSLink* link : cand->getLinkCont()) {
813 if (link->getLane() == current) {
814 if (link->getViaLane() != nullptr) {
815 return link->getViaLane();
816 } else {
817 return const_cast<MSLane*>(link->getLaneBefore());
818 }
819 }
820 }
821 }
822 } else {
823 return myRoute->getEdges()[routeIndex]->getLanes()[0];
824 }
825 }
826 }
827 return current;
828}
829
830
831double
834}
835
836
837std::string
839 std::string result = "";
840 if (isParking()) {
841 result += "parking";
842 } else if (isStopped()) {
843 result += "stopped";
844 } else if (hasStops()) {
845 return "next: " + myStops.front().getDescription();
846 } else {
847 return "";
848 }
849 if (myStops.front().pars.triggered) {
850 result += ", triggered";
851 } else if (myStops.front().pars.containerTriggered) {
852 result += ", containerTriggered";
853 } else if (myStops.front().pars.collision) {
854 result += ", collision";
855 } else if (myStops.front().pars.until != -1) {
856 result += ", until=" + time2string(myStops.front().pars.until);
857 } else {
858 result += ", duration=" + time2string(myStops.front().duration);
859 }
860 if (myStops.front().pars.actType != "") {
861 result += ", actType=" + myStops.front().pars.actType;
862 }
863 return result;
864}
865
866
867void
869 double dist = myLane->getLength() - getPositionOnLane();
870#ifdef DEBUG_FOES
871 std::cout << SIMTIME << " selectBlockingFoes veh=" << getID() << " dist=" << dist << " numLinks=" << myLFLinkLanes.size() << "\n";
872#endif
873 for (DriveItemVector::const_iterator i = myLFLinkLanes.begin(); i != myLFLinkLanes.end(); ++i) {
874 const DriveProcessItem& dpi = *i;
875 if (dpi.myLink == nullptr) {
877 continue;
878 }
879 MSLink::BlockingFoes blockingFoes;
880 std::vector<const MSPerson*> blockingPersons;
881#ifdef DEBUG_FOES
882 std::cout << " foeLink=" << dpi.myLink->getViaLaneOrLane()->getID() << "\n";
883 const bool isOpen =
884#endif
886 getImpatience(), getCarFollowModel().getMaxDecel(), getWaitingTime(), getLateralPositionOnLane(), &blockingFoes, false, this);
887#ifdef DEBUG_FOES
888 if (!isOpen) {
889 std::cout << " closed due to:\n";
890 for (const auto& item : blockingFoes) {
891 std::cout << " " << item->getID() << "\n";
892 }
893 }
894#endif
895 if (getLaneChangeModel().getShadowLane() != nullptr) {
896 MSLink* parallelLink = dpi.myLink->getParallelLink(getLaneChangeModel().getShadowDirection());
897 if (parallelLink != nullptr) {
898 const double shadowLatPos = getLateralPositionOnLane() - getLaneChangeModel().getShadowDirection() * 0.5 * (
900#ifdef DEBUG_FOES
901 const bool isShadowOpen =
902#endif
903 parallelLink->opened(dpi.myArrivalTime, dpi.myArrivalSpeed, dpi.getLeaveSpeed(),
906 getWaitingTime(), shadowLatPos, &blockingFoes, false, this);
907#ifdef DEBUG_FOES
908 if (!isShadowOpen) {
909 std::cout << " foes at shadow link=" << parallelLink->getViaLaneOrLane()->getID() << ":\n";
910 for (const auto& item : blockingFoes) {
911 std::cout << " " << item->getID() << "\n";
912 }
913 }
914#endif
915 }
916 }
917 for (const auto& item : blockingFoes) {
918 gSelected.select(static_cast<const GUIVehicle*>(item)->getGlID());
919 }
920#ifdef DEBUG_FOES
921 gDebugFlag1 = true;
922#endif
923 const MSLink::LinkLeaders linkLeaders = (dpi.myLink)->getLeaderInfo(this, dist, &blockingPersons);
924#ifdef DEBUG_FOES
925 gDebugFlag1 = false;
926#endif
927 for (MSLink::LinkLeaders::const_iterator it = linkLeaders.begin(); it != linkLeaders.end(); ++it) {
928 // the vehicle to enter the junction first has priority
929 const GUIVehicle* leader = dynamic_cast<const GUIVehicle*>(it->vehAndGap.first);
930 if (leader != nullptr) {
931 if (isLeader(dpi.myLink, leader, it->vehAndGap.second)) {
932 gSelected.select(leader->getGlID());
933#ifdef DEBUG_FOES
934 std::cout << " linkLeader=" << leader->getID() << "\n";
935#endif
936 }
937 } else {
938 for (std::vector<const MSPerson*>::iterator it_p = blockingPersons.begin(); it_p != blockingPersons.end(); ++it_p) {
939 const GUIPerson* foe = dynamic_cast<const GUIPerson*>(*it_p);
940 if (foe != nullptr) {
941 gSelected.select(foe->getGlID());
942 //std::cout << SIMTIME << " veh=" << getID() << " is blocked on link " << dpi.myLink->getRespondIndex() << " to " << dpi.myLink->getViaLaneOrLane()->getID() << " by pedestrian. dist=" << it->second << "\n";
943 }
944 }
945 }
946 }
947 dist += dpi.myLink->getViaLaneOrLane()->getLength();
948 }
949}
950
951
952void
956 if (view != nullptr) {
957 if (add) {
961 }
962 } else {
964 myAdditionalVisualizations[view] &= ~VO_DRAW_OUTSIDE_NETWORK;
965 }
966 }
967}
968
969bool
972}
973
974int
976 const double rightSide = getRightSideOnEdge();
977 const std::vector<double>& sublaneSides = myLane->getEdge().getSubLaneSides();
978 for (int i = 0; i < (int)sublaneSides.size(); ++i) {
979 if (sublaneSides[i] > rightSide) {
980 return MAX2(i - 1, 0);
981 }
982 }
983 return (int)sublaneSides.size() - 1;
984}
985
986int
988 const double leftSide = getLeftSideOnEdge();
989 const std::vector<double>& sublaneSides = myLane->getEdge().getSubLaneSides();
990 for (int i = (int)sublaneSides.size() - 1; i >= 0; --i) {
991 if (sublaneSides[i] < leftSide) {
992 return i;
993 }
994 }
995 return -1;
996}
997
998
999std::string
1001 return toString((LaneChangeAction)getLaneChangeModel().getSavedState(-1).second);
1002}
1003
1004std::string
1006 return toString((LaneChangeAction)getLaneChangeModel().getSavedState(1).second);
1007}
1008
1009std::string
1011 return toString((LaneChangeAction)getLaneChangeModel().getSavedState(0).second);
1012}
1013
1014std::string
1016 return Named::getIDSecure(myLane, "n/a");
1017}
1018
1019std::string
1021 return toString(myFurtherLanes);
1022}
1023
1024std::string
1026 return Named::getIDSecure(getLaneChangeModel().getShadowLane(), "");
1027}
1028
1029std::string
1031 return Named::getIDSecure(getLaneChangeModel().getTargetLane(), "");
1032}
1033
1034double
1037}
1038
1039std::string
1041 return std::bitset<6>(getInfluencer()->getSpeedMode()).to_string();
1042}
1043
1044std::string
1046 return std::bitset<12>(getInfluencer()->getLaneChangeMode()).to_string();
1047}
1048
1049void
1051 SUMOTime intermediateDuration = TIME2STEPS(20);
1052 SUMOTime finalDuration = SUMOTime_MAX;
1053 if (myParameter->stops.size() >= 2) {
1054 // copy durations from the original stops
1055 intermediateDuration = myParameter->stops.front().duration;
1056 finalDuration = myParameter->stops.back().duration;
1057 }
1058 // if the stop is already in the list of stops, cancel all stops that come
1059 // after it and set the stop duration
1060 std::string line = "";
1061 int destinations = 0;
1062 bool add = true;
1063 for (auto it = myStops.begin(); it != myStops.end(); it++) {
1064 if (!it->reached && destinations < 2 && it->busstop != nullptr) {
1065 line += it->busstop->getID();
1066 destinations++;
1067 }
1068 if (it->busstop == busStop) {
1069 it->duration = finalDuration;
1070 myStops.erase(++it, myStops.end());
1071 add = false;
1072 break;
1073 } else {
1074 it->duration = MIN2(it->duration, intermediateDuration);
1075 }
1076 }
1077 if (destinations < 2) {
1078 line += busStop->getID();
1079 }
1080 if (add) {
1081 // create new stop
1083 stopPar.busstop = busStop->getID();
1084 stopPar.lane = busStop->getLane().getID();
1085 stopPar.startPos = busStop->getBeginLanePosition();
1086 stopPar.endPos = busStop->getEndLanePosition();
1087 stopPar.duration = finalDuration;
1088 stopPar.until = -1;
1089 stopPar.triggered = false;
1090 stopPar.containerTriggered = false;
1091 stopPar.parking = ParkingType::ONROAD;
1092 stopPar.index = STOP_INDEX_FIT;
1094 // clean up prior route to improve visualisation, ensure that the stop can be added immediately
1095 ConstMSEdgeVector edges = myRoute->getEdges();
1096 edges.erase(edges.begin(), edges.begin() + getRoutePosition());
1097 edges.push_back(&busStop->getLane().getEdge());
1098 replaceRouteEdges(edges, -1, 0, "DRT.tmp", false, false, false);
1099 std::string errorMsg;
1100 // add stop
1101 addStop(stopPar, errorMsg);
1102 }
1103 const bool hasReroutingDevice = getDevice(typeid(MSDevice_Routing)) != nullptr;
1104 SUMOAbstractRouter<MSEdge, SUMOVehicle>& router = hasReroutingDevice
1107 // reroute to ensure the new stop is reached
1108 reroute(MSNet::getInstance()->getCurrentTimeStep(), "DRT", router);
1109 myParameter->line = line;
1110 assert(haveValidStopEdges());
1111}
1112
1114GUIVehicle::getVisualPosition(bool s2, const double offset) const {
1115 if (s2) {
1116 // see MSVehicle::getPosition
1117 if (myLane == nullptr) {
1118 return Position::INVALID;
1119 }
1120 if (isParking()) {
1121 if (myStops.begin()->parkingarea != nullptr) {
1122 return myStops.begin()->parkingarea->getVehiclePosition(*this);
1123 } else {
1124 // position beside the road
1125 PositionVector shp = myLane->getEdge().getLanes()[0]->getShape(s2);
1127 return shp.positionAtOffset((getPositionOnLane() + offset) * myLane->getLengthGeometryFactor(s2));
1128 }
1129 }
1130 const PositionVector& shape = myLane->getShape(s2);
1131 const double posLat = (MSGlobals::gLefthand ? 1 : -1) * getLateralPositionOnLane();
1132 return shape.positionAtOffset((getPositionOnLane() + offset) * myLane->getLengthGeometryFactor(s2), posLat);
1133 } else {
1134 return getPosition(offset);
1135 }
1136}
1137
1138
1139double
1141 if (s2) {
1142 // see MSVehicle::computeAngle
1143 const PositionVector& shape = myLane->getShape(s2);
1144 if (isParking()) {
1145 if (myStops.begin()->parkingarea != nullptr) {
1146 return myStops.begin()->parkingarea->getVehicleAngle(*this);
1147 } else {
1149 }
1150 }
1151 // if (myLaneChangeModel->isChangingLanes()) {
1152 const double lefthandSign = (MSGlobals::gLefthand ? -1 : 1);
1153 Position p1 = getVisualPosition(s2);
1154 Position p2 = getVisualPosition(s2, MAX2(0.0, -myType->getLength()));
1155 double result = (p1 != p2 ? p2.angleTo2D(p1) :
1158 result += lefthandSign * DEG2RAD(myLaneChangeModel->getAngleOffset());
1159 }
1160 return result;
1161 } else {
1162 return getAngle();
1163 }
1164}
1165/****************************************************************************/
long long int SUMOTime
Definition: GUI.h:36
@ GLO_VEHICLE
a vehicle
GUISelectedStorage gSelected
A global holder of selected objects.
#define BLINKER_POS_FRONT
Definition: GUIVehicle.cpp:522
#define LANECHANGEMODE_DEFAULT
Definition: GUIVehicle.cpp:69
#define SPEEDMODE_DEFAULT
Definition: GUIVehicle.cpp:68
void drawAction_drawBlinker(double dir, double length)
Definition: GUIVehicle.cpp:526
#define BLINKER_POS_BACK
Definition: GUIVehicle.cpp:523
#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:268
#define TL(string)
Definition: MsgHandler.h:284
std::shared_ptr< const MSRoute > ConstMSRoutePtr
Definition: Route.h:32
std::string time2string(SUMOTime t)
convert SUMOTime to string
Definition: SUMOTime.cpp:68
#define STEPS2TIME(x)
Definition: SUMOTime.h:54
#define SIMSTEP
Definition: SUMOTime.h:60
#define SUMOTime_MAX
Definition: SUMOTime.h:33
#define SIMTIME
Definition: SUMOTime.h:61
#define TIME2STEPS(x)
Definition: SUMOTime.h:56
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
Seats myContainerPositions
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.
Definition: GUIGlObject.h:154
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 std::vector< double > & getShapeRotations(bool secondary) const
Definition: GUILane.cpp:1065
const PositionVector & getShape(bool secondary) const override
Definition: GUILane.cpp:1059
const std::vector< double > & getShapeLengths(bool secondary) const
Definition: GUILane.cpp:1071
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.
const 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
Definition: GUIVehicle.cpp:970
int getLeftSublaneOnEdge() const
Definition: GUIVehicle.cpp:987
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
Definition: GUIVehicle.cpp:592
std::string getDynamicAlignment() const
return the current lateral alignment as string
Definition: GUIVehicle.cpp:263
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
Definition: GUIVehicle.cpp:868
GUIParameterTableWindow * getTypeParameterWindow(GUIMainWindow &app, GUISUMOAbstractView &parent)
Returns an own type parameter window.
Definition: GUIVehicle.cpp:208
void drawBestLanes() const
Draws the vehicle's best lanes.
Definition: GUIVehicle.cpp:679
void drawOutsideNetwork(bool add)
register vehicle for drawing while outside the network
Definition: GUIVehicle.cpp:953
int getRightSublaneOnEdge() const
return the righmost sublane on the edge occupied by the vehicle
Definition: GUIVehicle.cpp:975
void drawRouteHelper(const GUIVisualizationSettings &s, ConstMSRoutePtr r, bool future, bool noLoop, const RGBColor &col) const
Draws the route.
Definition: GUIVehicle.cpp:714
MSLane * getPreviousLane(MSLane *current, int &furtherIndex) const
Definition: GUIVehicle.cpp:778
std::string getStopInfo() const
retrieve information about the current stop state
Definition: GUIVehicle.cpp:838
GUIParameterTableWindow * getParameterWindow(GUIMainWindow &app, GUISUMOAbstractView &parent)
Returns an own parameter window.
Definition: GUIVehicle.cpp:96
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
Definition: GUIVehicle.cpp:305
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.
Definition: GUIVehicle.cpp:84
void drawAction_drawVehicleBlinker(double length) const
Definition: GUIVehicle.cpp:540
void rerouteDRTStop(MSStoppingPlace *busStop)
handle route to accomodate to given stop
std::string getLCStateRight() const
return the lanechange state
void drawAction_drawVehicleBlueLight() const
Definition: GUIVehicle.cpp:580
double getLastLaneChangeOffset() const
Returns the time since the last lane change in seconds.
Definition: GUIVehicle.cpp:832
std::string getLaneID() const
return vehicle lane id
void drawAction_drawLinkItems(const GUIVisualizationSettings &s) const
Definition: GUIVehicle.cpp:275
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
Definition: GUIVehicle.cpp:559
~GUIVehicle()
destructor
Definition: GUIVehicle.cpp:91
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.
Definition: MSBaseVehicle.h:55
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.
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:2365
MSLane * getBidiLane() const
retrieve bidirectional lane or nullptr
Definition: MSLane.cpp:4321
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:1452
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
Definition: MSVehicle.cpp:811
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)
Definition: MSVehicle.cpp:6430
double getTimeGapOnLane() const
Returns the time gap in seconds to the leader of the vehicle on the same lane.
Definition: MSVehicle.cpp:6288
double getStopDelay() const
Returns the public transport stop delay in seconds.
Definition: MSVehicle.cpp:7634
bool isOnRoad() const
Returns the information whether the vehicle is on a road (is simulated)
Definition: MSVehicle.h:606
SUMOTime getWaitingTime() const
Returns the SUMOTime waited (speed was lesser than 0.1m/s)
Definition: MSVehicle.h:670
bool isActive() const
Returns whether the current simulation step is an action point for the vehicle.
Definition: MSVehicle.h:629
double getTimeLossSeconds() const
Returns the time loss in seconds.
Definition: MSVehicle.h:721
double getAccumulatedWaitingSeconds() const
Returns the number of seconds waited (speed was lesser than 0.1m/s) within the last millisecs.
Definition: MSVehicle.h:715
double getTimeSinceStartupSeconds() const
Definition: MSVehicle.h:684
MSAbstractLaneChangeModel & getLaneChangeModel()
Definition: MSVehicle.cpp:5510
bool isActionStep(SUMOTime t) const
Returns whether the next simulation step will be an action point for the vehicle.
Definition: MSVehicle.h:636
MSAbstractLaneChangeModel * myLaneChangeModel
Definition: MSVehicle.h:1885
std::vector< MSLane * > myFurtherLanes
The information into which lanes the vehicle laps into.
Definition: MSVehicle.h:1912
bool signalSet(int which) const
Returns whether the given signal is on.
Definition: MSVehicle.h:1200
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.
Definition: MSVehicle.cpp:6005
int getBestLaneOffset() const
Definition: MSVehicle.cpp:6176
double getStopArrivalDelay() const
Returns the estimated public transport stop arrival delay in seconds.
Definition: MSVehicle.cpp:7655
@ VEH_SIGNAL_BLINKER_RIGHT
Right blinker lights are switched on.
Definition: MSVehicle.h:1122
@ VEH_SIGNAL_BRAKELIGHT
The brake lights are on.
Definition: MSVehicle.h:1128
@ VEH_SIGNAL_EMERGENCY_BLUE
A blue emergency light is on.
Definition: MSVehicle.h:1144
@ VEH_SIGNAL_BLINKER_LEFT
Left blinker lights are switched on.
Definition: MSVehicle.h:1124
@ VEH_SIGNAL_BLINKER_EMERGENCY
Blinker lights on both sides are switched on.
Definition: MSVehicle.h:1126
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
Definition: MSVehicle.cpp:7077
Influencer & getInfluencer()
Definition: MSVehicle.cpp:6939
std::vector< std::vector< LaneQ > > myBestLanes
Definition: MSVehicle.h:1895
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.
Definition: MSVehicle.cpp:1189
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:973
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:1883
bool hasInfluencer() const
whether the vehicle is individually influenced (via TraCI or special parameters)
Definition: MSVehicle.h:1691
State myState
This Vehicles driving state (pos and speed)
Definition: MSVehicle.h:1866
DriveItemVector myLFLinkLanes
container for the planned speeds in the current step
Definition: MSVehicle.h:2007
The car-following model and parameter.
Definition: MSVehicleType.h:63
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.
Definition: MSVehicleType.h:91
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.
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:1951
double getLeaveSpeed() const
Definition: MSVehicle.h:1997