Line data Source code
1 : /****************************************************************************/
2 : // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo
3 : // Copyright (C) 2001-2025 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 : /****************************************************************************/
14 : /// @file GUILane.cpp
15 : /// @author Daniel Krajzewicz
16 : /// @author Jakob Erdmann
17 : /// @author Michael Behrisch
18 : /// @date Sept 2002
19 : ///
20 : // Representation of a lane in the micro simulation (gui-version)
21 : /****************************************************************************/
22 : #include <config.h>
23 :
24 : #include <string>
25 : #include <utility>
26 : #include <utils/foxtools/fxheader.h>
27 : #include <utils/geom/GeomHelper.h>
28 : #include <utils/geom/Position.h>
29 : #include <microsim/logging/FunctionBinding.h>
30 : #include <utils/options/OptionsCont.h>
31 : #include <utils/common/MsgHandler.h>
32 : #include <utils/common/StdDefs.h>
33 : #include <utils/geom/GeomHelper.h>
34 : #include <utils/gui/div/GLHelper.h>
35 : #include <utils/gui/div/GUIParameterTableWindow.h>
36 : #include <utils/gui/div/GUIGlobalSelection.h>
37 : #include <utils/gui/globjects/GLIncludes.h>
38 : #include <utils/gui/globjects/GUIPolygon.h>
39 : #include <utils/gui/images/VClassIcons.h>
40 : #include <utils/gui/windows/GUISUMOAbstractView.h>
41 : #include <utils/gui/windows/GUIAppEnum.h>
42 : #include <gui/GUIGlobals.h>
43 : #include <microsim/MSGlobals.h>
44 : #include <microsim/MSLane.h>
45 : #include <microsim/MSLink.h>
46 : #include <microsim/MSVehicleControl.h>
47 : #include <microsim/MSInsertionControl.h>
48 : #include <microsim/MSVehicleTransfer.h>
49 : #include <microsim/MSNet.h>
50 : #include <microsim/MSEdgeWeightsStorage.h>
51 : #include <microsim/MSParkingArea.h>
52 : #include <microsim/devices/MSDevice_Routing.h>
53 : #include <microsim/traffic_lights/MSRailSignal.h>
54 : #include <microsim/traffic_lights/MSDriveWay.h>
55 : #include <mesosim/MELoop.h>
56 : #include <mesosim/MESegment.h>
57 : #include "GUILane.h"
58 : #include "GUIEdge.h"
59 : #include "GUIVehicle.h"
60 : #include "GUINet.h"
61 : #include <utils/gui/div/GUIDesigns.h>
62 :
63 : #include <osgview/GUIOSGHeader.h>
64 :
65 : #define RENDERING_BUFFER 10
66 :
67 : //#define GUILane_DEBUG_DRAW_FOE_INTERSECTIONS
68 : //#define GUILane_DEBUG_DRAW_CROSSING_OUTLINE
69 :
70 : // ===========================================================================
71 : // static member declaration
72 : // ===========================================================================
73 : const RGBColor GUILane::MESO_USE_LANE_COLOR(0, 0, 0, 0);
74 : GUIVisualizationSettings* GUILane::myCachedGUISettings(nullptr);
75 :
76 :
77 : // ===========================================================================
78 : // method definitions
79 : // ===========================================================================
80 391698 : GUILane::GUILane(const std::string& id, double maxSpeed, double friction, double length,
81 : MSEdge* const edge, int numericalID,
82 : const PositionVector& shape, double width,
83 : SVCPermissions permissions,
84 : SVCPermissions changeLeft, SVCPermissions changeRight,
85 : int index, bool isRampAccel,
86 : const std::string& type,
87 391698 : const PositionVector& outlineShape) :
88 : MSLane(id, maxSpeed, friction, length, edge, numericalID, shape, width, permissions, changeLeft, changeRight, index, isRampAccel, type, outlineShape),
89 : GUIGlObject(GLO_LANE, id, GUIIconSubSys::getIcon(GUIIcon::LANE)),
90 391698 : myParkingAreas(nullptr),
91 391698 : myTesselation(nullptr),
92 : #ifdef HAVE_OSG
93 391698 : myGeom(0),
94 : #endif
95 391698 : myAmClosed(false),
96 391698 : myLengthGeometryFactor2(myLengthGeometryFactor),
97 391698 : myLock(true) {
98 391698 : if (MSGlobals::gUseMesoSim) {
99 274252 : myShape = splitAtSegments(shape);
100 : assert(fabs(myShape.length() - shape.length()) < POSITION_EPS);
101 : assert(myShapeSegments.size() == myShape.size());
102 : }
103 391698 : initRotations(myShape, myShapeRotations, myShapeLengths, myShapeColors);
104 : //
105 391698 : myHalfLaneWidth = myWidth / 2.;
106 391698 : myQuarterLaneWidth = myWidth / 4.;
107 391698 : }
108 :
109 :
110 781048 : GUILane::~GUILane() {
111 : // just to quit cleanly on a failure
112 390524 : if (myLock.locked()) {
113 0 : myLock.unlock();
114 : }
115 390524 : delete myParkingAreas;
116 390524 : delete myTesselation;
117 781048 : }
118 :
119 :
120 : void
121 391698 : GUILane::initRotations(const PositionVector& shape,
122 : std::vector<double>& rotations,
123 : std::vector<double>& lengths,
124 : std::vector<RGBColor>& colors) {
125 : rotations.clear();
126 : lengths.clear();
127 : colors.clear();
128 391698 : rotations.reserve(shape.size() - 1);
129 391698 : lengths.reserve(shape.size() - 1);
130 391698 : colors.reserve(shape.size() - 1);
131 391698 : int e = (int) shape.size() - 1;
132 1325693 : for (int i = 0; i < e; ++i) {
133 933995 : const Position& f = shape[i];
134 933995 : const Position& s = shape[i + 1];
135 933995 : lengths.push_back(f.distanceTo2D(s));
136 933995 : rotations.push_back(RAD2DEG(atan2(s.x() - f.x(), f.y() - s.y())));
137 : }
138 391698 : }
139 :
140 :
141 : void
142 0 : GUILane::addSecondaryShape(const PositionVector& shape) {
143 : myShape2 = shape;
144 0 : initRotations(myShape2, myShapeRotations2, myShapeLengths2, myShapeColors2);
145 0 : myLengthGeometryFactor2 = MAX2(POSITION_EPS, myShape2.length()) / myLength;
146 0 : }
147 :
148 :
149 : // ------ Vehicle insertion ------
150 : void
151 378458 : GUILane::incorporateVehicle(MSVehicle* veh, double pos, double speed, double posLat,
152 : const MSLane::VehCont::iterator& at,
153 : MSMoveReminder::Notification notification) {
154 378458 : FXMutexLock locker(myLock);
155 378458 : MSLane::incorporateVehicle(veh, pos, speed, posLat, at, notification);
156 378458 : }
157 :
158 :
159 : // ------ Access to vehicles ------
160 : const MSLane::VehCont&
161 116318590 : GUILane::getVehiclesSecure() const {
162 116318590 : myLock.lock();
163 116318590 : return myVehicles;
164 : }
165 :
166 :
167 : void
168 116318590 : GUILane::releaseVehicles() const {
169 116318590 : myLock.unlock();
170 116318590 : }
171 :
172 :
173 : void
174 13150909 : GUILane::planMovements(const SUMOTime t) {
175 13150909 : FXMutexLock locker(myLock);
176 13150909 : MSLane::planMovements(t);
177 13150909 : }
178 :
179 : void
180 13150909 : GUILane::setJunctionApproaches() const {
181 13150909 : FXMutexLock locker(myLock);
182 13150909 : MSLane::setJunctionApproaches();
183 13150909 : }
184 :
185 :
186 : void
187 13150909 : GUILane::executeMovements(const SUMOTime t) {
188 13150909 : FXMutexLock locker(myLock);
189 13150909 : MSLane::executeMovements(t);
190 13150908 : }
191 :
192 :
193 : MSVehicle*
194 6113 : GUILane::removeVehicle(MSVehicle* remVehicle, MSMoveReminder::Notification notification, bool notify) {
195 6113 : FXMutexLock locker(myLock);
196 12226 : return MSLane::removeVehicle(remVehicle, notification, notify);
197 : }
198 :
199 :
200 : void
201 2543 : GUILane::removeParking(MSBaseVehicle* remVehicle) {
202 2543 : FXMutexLock locker(myLock);
203 5086 : return MSLane::removeParking(remVehicle);
204 : }
205 :
206 :
207 : void
208 9762042 : GUILane::swapAfterLaneChange(SUMOTime t) {
209 9762042 : FXMutexLock locker(myLock);
210 9762042 : MSLane::swapAfterLaneChange(t);
211 9762042 : }
212 :
213 :
214 : void
215 3751284 : GUILane::integrateNewVehicles() {
216 3751284 : FXMutexLock locker(myLock);
217 3751284 : MSLane::integrateNewVehicles();
218 3751284 : }
219 :
220 :
221 : void
222 14372326 : GUILane::detectCollisions(SUMOTime timestep, const std::string& stage) {
223 14372326 : FXMutexLock locker(myLock);
224 14372326 : MSLane::detectCollisions(timestep, stage);
225 14372326 : }
226 :
227 :
228 : double
229 2521205 : GUILane::setPartialOccupation(MSVehicle* v) {
230 2521205 : FXMutexLock locker(myLock);
231 5042410 : return MSLane::setPartialOccupation(v);
232 : }
233 :
234 :
235 : void
236 2521216 : GUILane::resetPartialOccupation(MSVehicle* v) {
237 2521216 : FXMutexLock locker(myLock);
238 2521216 : MSLane::resetPartialOccupation(v);
239 2521216 : }
240 :
241 :
242 : // ------ Drawing methods ------
243 : void
244 0 : GUILane::drawLinkNo(const GUIVisualizationSettings& s) const {
245 0 : int noLinks = (int)myLinks.size();
246 0 : if (noLinks == 0) {
247 : return;
248 : }
249 : // draw all links
250 0 : if (isCrossing()) {
251 : // draw indices at the start and end of the crossing
252 0 : const MSLink* const link = getLogicalPredecessorLane()->getLinkTo(this);
253 0 : PositionVector shape = getShape(s.secondaryShape);
254 0 : shape.extrapolate(0.5); // draw on top of the walking area
255 0 : GLHelper::drawTextAtEnd(toString(link->getIndex()), shape, 0, s.drawLinkJunctionIndex, s.scale);
256 0 : GLHelper::drawTextAtEnd(toString(link->getIndex()), shape.reverse(), 0, s.drawLinkJunctionIndex, s.scale);
257 : return;
258 0 : }
259 : // draw all links
260 0 : double w = myWidth / (double) noLinks;
261 0 : double x1 = myHalfLaneWidth;
262 0 : for (int i = noLinks; --i >= 0;) {
263 0 : double x2 = x1 - (double)(w / 2.);
264 0 : GLHelper::drawTextAtEnd(toString(myLinks[MSGlobals::gLefthand ? noLinks - 1 - i : i]->getIndex()), getShape(s.secondaryShape), x2, s.drawLinkJunctionIndex, s.scale);
265 0 : x1 -= w;
266 : }
267 : }
268 :
269 :
270 : void
271 0 : GUILane::drawTLSLinkNo(const GUIVisualizationSettings& s, const GUINet& net) const {
272 0 : int noLinks = (int)myLinks.size();
273 0 : if (noLinks == 0) {
274 : return;
275 : }
276 0 : if (isCrossing()) {
277 : // draw indices at the start and end of the crossing
278 0 : const MSLink* const link = getLogicalPredecessorLane()->getLinkTo(this);
279 0 : int linkNo = net.getLinkTLIndex(link);
280 : // maybe the reverse link is controlled separately
281 0 : int linkNo2 = net.getLinkTLIndex(myLinks.front());
282 : // otherwise, use the same index as the forward link
283 0 : if (linkNo2 < 0) {
284 0 : linkNo2 = linkNo;
285 : }
286 0 : if (linkNo >= 0) {
287 0 : PositionVector shape = getShape(s.secondaryShape);
288 0 : shape.extrapolate(0.5); // draw on top of the walking area
289 0 : GLHelper::drawTextAtEnd(toString(linkNo2), shape, 0, s.drawLinkTLIndex, s.scale);
290 0 : GLHelper::drawTextAtEnd(toString(linkNo), shape.reverse(), 0, s.drawLinkTLIndex, s.scale);
291 0 : }
292 : return;
293 : }
294 : // draw all links
295 0 : double w = myWidth / (double) noLinks;
296 0 : double x1 = myHalfLaneWidth;
297 0 : for (int i = noLinks; --i >= 0;) {
298 0 : double x2 = x1 - (double)(w / 2.);
299 0 : int linkNo = net.getLinkTLIndex(myLinks[MSGlobals::gLefthand ? noLinks - 1 - i : i]);
300 0 : if (linkNo < 0) {
301 0 : continue;
302 : }
303 0 : GLHelper::drawTextAtEnd(toString(linkNo), getShape(s.secondaryShape), x2, s.drawLinkTLIndex, s.scale);
304 0 : x1 -= w;
305 : }
306 : }
307 :
308 :
309 : void
310 427036 : GUILane::drawLinkRules(const GUIVisualizationSettings& s, const GUINet& net) const {
311 427036 : int noLinks = (int)myLinks.size();
312 427036 : const PositionVector& shape = getShape(s.secondaryShape);
313 427036 : if (noLinks == 0) {
314 166612 : drawLinkRule(s, net, nullptr, shape, 0, 0);
315 166612 : return;
316 : }
317 260424 : if (isCrossing()) {
318 : // draw rules at the start and end of the crossing
319 9766 : const MSLink* const link = getLogicalPredecessorLane()->getLinkTo(this);
320 9766 : const MSLink* link2 = myLinks.front();
321 9766 : if (link2->getTLLogic() == nullptr) {
322 : link2 = link;
323 : }
324 : PositionVector tmp = shape;
325 9766 : tmp.extrapolate(0.5); // draw on top of the walking area
326 9766 : drawLinkRule(s, net, link2, tmp, 0, myWidth);
327 9766 : drawLinkRule(s, net, link, tmp.reverse(), 0, myWidth);
328 : return;
329 9766 : }
330 : // draw all links
331 250658 : const double isRailSignal = myEdge->getToJunction()->getType() == SumoXMLNodeType::RAIL_SIGNAL;
332 250658 : double w = myWidth / (double) noLinks;
333 250658 : if (isRailSignal && noLinks > 1 && myLinks.back()->isTurnaround() && s.showRails) {
334 1134 : w = myWidth / (double)(noLinks - 1);
335 : }
336 250658 : double x1 = isRailSignal ? -myWidth * 0.5 : 0;
337 564324 : for (int i = 0; i < noLinks; ++i) {
338 313666 : double x2 = x1 + w;
339 313666 : drawLinkRule(s, net, myLinks[MSGlobals::gLefthand ? noLinks - 1 - i : i], shape, x1, x2);
340 : x1 = x2;
341 : }
342 : // draw stopOffset for passenger cars
343 250658 : if (myLaneStopOffset.isDefined() && (myLaneStopOffset.getPermissions() & SVC_PASSENGER) != 0) {
344 345 : const double stopOffsetPassenger = myLaneStopOffset.getOffset();
345 : const Position& end = shape.back();
346 345 : const Position& f = shape[-2];
347 345 : const double rot = RAD2DEG(atan2((end.x() - f.x()), (f.y() - end.y())));
348 345 : GLHelper::setColor(s.getLinkColor(LINKSTATE_MAJOR));
349 345 : GLHelper::pushMatrix();
350 345 : glTranslated(end.x(), end.y(), 0);
351 345 : glRotated(rot, 0, 0, 1);
352 345 : glTranslated(0, stopOffsetPassenger, 0);
353 345 : glBegin(GL_QUADS);
354 345 : glVertex2d(-myHalfLaneWidth, 0.0);
355 345 : glVertex2d(-myHalfLaneWidth, 0.2);
356 345 : glVertex2d(myHalfLaneWidth, 0.2);
357 345 : glVertex2d(myHalfLaneWidth, 0.0);
358 345 : glEnd();
359 345 : GLHelper::popMatrix();
360 : }
361 : }
362 :
363 :
364 : void
365 499810 : GUILane::drawLinkRule(const GUIVisualizationSettings& s, const GUINet& net, const MSLink* link, const PositionVector& shape, double x1, double x2) const {
366 : const Position& end = shape.back();
367 499810 : const Position& f = shape[-2];
368 499810 : const double rot = RAD2DEG(atan2((end.x() - f.x()), (f.y() - end.y())));
369 499810 : if (link == nullptr) {
370 166612 : if (static_cast<GUIEdge*>(myEdge)->showDeadEnd()) {
371 88 : GLHelper::setColor(GUIVisualizationColorSettings::SUMO_color_DEADEND_SHOW);
372 : } else {
373 166524 : GLHelper::setColor(GUIVisualizationSettings::getLinkColor(LINKSTATE_DEADEND));
374 : }
375 166612 : GLHelper::pushMatrix();
376 166612 : glTranslated(end.x(), end.y(), 0);
377 166612 : glRotated(rot, 0, 0, 1);
378 166612 : glBegin(GL_QUADS);
379 166612 : glVertex2d(-myHalfLaneWidth, 0.0);
380 166612 : glVertex2d(-myHalfLaneWidth, 0.5);
381 166612 : glVertex2d(myHalfLaneWidth, 0.5);
382 166612 : glVertex2d(myHalfLaneWidth, 0.0);
383 166612 : glEnd();
384 166612 : GLHelper::popMatrix();
385 : } else {
386 333198 : GLHelper::pushMatrix();
387 333198 : glTranslated(end.x(), end.y(), 0);
388 333198 : glRotated(rot, 0, 0, 1);
389 : // select glID
390 :
391 333198 : switch (link->getState()) {
392 18 : case LINKSTATE_ALLWAY_STOP:
393 : case LINKSTATE_STOP: {
394 : // might be a traffic light link
395 18 : int tlID = net.getLinkTLID(link);
396 36 : GLHelper::pushName(tlID != 0 ? tlID : getGlID());
397 18 : break;
398 : }
399 84858 : case LINKSTATE_TL_GREEN_MAJOR:
400 : case LINKSTATE_TL_GREEN_MINOR:
401 : case LINKSTATE_TL_RED:
402 : case LINKSTATE_TL_REDYELLOW:
403 : case LINKSTATE_TL_YELLOW_MAJOR:
404 : case LINKSTATE_TL_YELLOW_MINOR:
405 : case LINKSTATE_TL_OFF_BLINKING:
406 : case LINKSTATE_TL_OFF_NOSIGNAL:
407 84858 : GLHelper::pushName(net.getLinkTLID(link));
408 84858 : break;
409 248322 : case LINKSTATE_MAJOR:
410 : case LINKSTATE_MINOR:
411 : case LINKSTATE_EQUAL:
412 : default:
413 248322 : GLHelper::pushName(getGlID());
414 248322 : break;
415 : }
416 333198 : GLHelper::setColor(GUIVisualizationSettings::getLinkColor(link->getState(), s.realisticLinkRules));
417 333198 : if (!(drawAsRailway(s) || drawAsWaterway(s)) || link->getState() != LINKSTATE_MAJOR) {
418 : // the white bar should be the default for most railway
419 : // links and looks ugly so we do not draw it
420 329980 : double scale = isInternal() ? 0.5 : 1;
421 329980 : if (myEdge->getToJunction()->getType() == SumoXMLNodeType::RAIL_SIGNAL) {
422 8542 : scale *= MAX2(s.laneWidthExaggeration, s.junctionSize.getExaggeration(s, this, 10));
423 : }
424 329980 : glScaled(scale, scale, 1);
425 329980 : glBegin(GL_QUADS);
426 329980 : glVertex2d(x1 - myHalfLaneWidth, 0.0);
427 329980 : glVertex2d(x1 - myHalfLaneWidth, 0.5);
428 329980 : glVertex2d(x2 - myHalfLaneWidth, 0.5);
429 329980 : glVertex2d(x2 - myHalfLaneWidth, 0.0);
430 329980 : glEnd();
431 329980 : if (s.gaming && link->haveGreen()) {
432 : const MSLane* lane = link->getLane();
433 : // exaggerate green signals for railway game
434 0 : if (isRailway(lane->getPermissions())) {
435 0 : GLHelper::drawFilledCircle(lane->getWidth() / 2., 8, 90, 270);
436 : }
437 : }
438 : }
439 333198 : GLHelper::popName();
440 333198 : GLHelper::popMatrix();
441 : }
442 499810 : }
443 :
444 : void
445 368269 : GUILane::drawArrows(bool secondaryShape) const {
446 368269 : if (myLinks.size() == 0) {
447 : return;
448 : }
449 : // draw all links
450 205857 : const Position& end = getShape(secondaryShape).back();
451 205857 : const Position& f = getShape(secondaryShape)[-2];
452 205857 : const double rot = RAD2DEG(atan2((end.x() - f.x()), (f.y() - end.y())));
453 205857 : GLHelper::pushMatrix();
454 205857 : glColor3d(1, 1, 1);
455 205857 : glTranslated(end.x(), end.y(), 0);
456 205857 : glRotated(rot, 0, 0, 1);
457 205857 : if (myWidth < SUMO_const_laneWidth) {
458 3248 : glScaled(myWidth / SUMO_const_laneWidth, 1, 1);
459 : }
460 473114 : for (const MSLink* const link : myLinks) {
461 : LinkDirection dir = link->getDirection();
462 : LinkState state = link->getState();
463 267257 : if (state == LINKSTATE_DEADEND || dir == LinkDirection::NODIR) {
464 0 : continue;
465 : }
466 267257 : switch (dir) {
467 : case LinkDirection::STRAIGHT:
468 185720 : GLHelper::drawBoxLine(Position(0, 4), 0, 2, .05);
469 185720 : GLHelper::drawTriangleAtEnd(Position(0, 4), Position(0, 1), (double) 1, (double) .25);
470 185720 : break;
471 : case LinkDirection::TURN:
472 10463 : GLHelper::drawBoxLine(Position(0, 4), 0, 1.5, .05);
473 10463 : GLHelper::drawBoxLine(Position(0, 2.5), 90, .5, .05);
474 10463 : GLHelper::drawBoxLine(Position(0.5, 2.5), 180, 1, .05);
475 10463 : GLHelper::drawTriangleAtEnd(Position(0.5, 2.5), Position(0.5, 4), (double) 1, (double) .25);
476 10463 : break;
477 : case LinkDirection::TURN_LEFTHAND:
478 0 : GLHelper::drawBoxLine(Position(0, 4), 0, 1.5, .05);
479 0 : GLHelper::drawBoxLine(Position(0, 2.5), -90, .5, .05);
480 0 : GLHelper::drawBoxLine(Position(-0.5, 2.5), -180, 1, .05);
481 0 : GLHelper::drawTriangleAtEnd(Position(-0.5, 2.5), Position(-0.5, 4), (double) 1, (double) .25);
482 0 : break;
483 : case LinkDirection::LEFT:
484 23494 : GLHelper::drawBoxLine(Position(0, 4), 0, 1.5, .05);
485 23494 : GLHelper::drawBoxLine(Position(0, 2.5), 90, 1, .05);
486 23494 : GLHelper::drawTriangleAtEnd(Position(0, 2.5), Position(1.5, 2.5), (double) 1, (double) .25);
487 23494 : break;
488 : case LinkDirection::RIGHT:
489 29583 : GLHelper::drawBoxLine(Position(0, 4), 0, 1.5, .05);
490 29583 : GLHelper::drawBoxLine(Position(0, 2.5), -90, 1, .05);
491 29583 : GLHelper::drawTriangleAtEnd(Position(0, 2.5), Position(-1.5, 2.5), (double) 1, (double) .25);
492 29583 : break;
493 : case LinkDirection::PARTLEFT:
494 187 : GLHelper::drawBoxLine(Position(0, 4), 0, 1.5, .05);
495 187 : GLHelper::drawBoxLine(Position(0, 2.5), 45, .7, .05);
496 187 : GLHelper::drawTriangleAtEnd(Position(0, 2.5), Position(1.2, 1.3), (double) 1, (double) .25);
497 187 : break;
498 : case LinkDirection::PARTRIGHT:
499 17810 : GLHelper::drawBoxLine(Position(0, 4), 0, 1.5, .05);
500 17810 : GLHelper::drawBoxLine(Position(0, 2.5), -45, .7, .05);
501 17810 : GLHelper::drawTriangleAtEnd(Position(0, 2.5), Position(-1.2, 1.3), (double) 1, (double) .25);
502 17810 : break;
503 : default:
504 : break;
505 : }
506 : }
507 205857 : GLHelper::popMatrix();
508 : }
509 :
510 :
511 : void
512 0 : GUILane::drawLane2LaneConnections(double exaggeration, bool s2) const {
513 : Position centroid;
514 0 : if (exaggeration > 1) {
515 0 : centroid = myEdge->getToJunction()->getShape().getCentroid();
516 : }
517 0 : for (const MSLink* const link : myLinks) {
518 0 : const GUILane* connected = dynamic_cast<GUILane*>(link->getLane());
519 0 : if (connected == nullptr) {
520 0 : continue;
521 : }
522 0 : GLHelper::setColor(GUIVisualizationSettings::getLinkColor(link->getState()));
523 0 : glBegin(GL_LINES);
524 0 : Position p1 = myEdge->isWalkingArea() ? getShape(s2).getCentroid() : getShape(s2)[-1];
525 0 : Position p2 = connected->isWalkingArea() ? connected->getShape(s2).getCentroid() : connected->getShape(s2)[0];
526 0 : if (exaggeration > 1) {
527 0 : p1 = centroid + ((p1 - centroid) * exaggeration);
528 0 : p2 = centroid + ((p2 - centroid) * exaggeration);
529 : }
530 0 : glVertex2d(p1.x(), p1.y());
531 0 : glVertex2d(p2.x(), p2.y());
532 0 : glEnd();
533 0 : GLHelper::drawTriangleAtEnd(p1, p2, (double) .4, (double) .2);
534 : }
535 0 : }
536 :
537 :
538 : void
539 41192295 : GUILane::drawGL(const GUIVisualizationSettings& s) const {
540 41192295 : GLHelper::pushMatrix();
541 41192295 : GLHelper::pushName(getGlID());
542 41192295 : const bool s2 = s.secondaryShape;
543 41192295 : double exaggeration = s.laneWidthExaggeration;
544 41192295 : if (MSGlobals::gUseMesoSim) {
545 4376471 : GUIEdge* myGUIEdge = dynamic_cast<GUIEdge*>(myEdge);
546 4376471 : exaggeration *= s.edgeScaler.getScheme().getColor(myGUIEdge->getScaleValue(s, s.edgeScaler.getActive()));
547 : } else {
548 36815824 : exaggeration *= s.laneScaler.getScheme().getColor(getScaleValue(s, s.laneScaler.getActive(), s2));
549 : }
550 : // set lane color
551 41192295 : const RGBColor color = setColor(s);
552 : // recognize full transparency and simply don't draw
553 41192295 : if (color.alpha() != 0 && s.scale * exaggeration > s.laneMinSize) {
554 :
555 41106575 : const bool isCrossing = myEdge->isCrossing();
556 : const bool isWalkingArea = myEdge->isWalkingArea();
557 41106575 : const bool isInternal = isCrossing || isWalkingArea || myEdge->isInternal();
558 41106575 : const PositionVector& baseShape = getShape(s2);
559 41106575 : const bool hasRailSignal = myEdge->getToJunction()->getType() == SumoXMLNodeType::RAIL_SIGNAL;
560 41106575 : if (s.trueZ) {
561 132 : glTranslated(0, 0, baseShape.getMinZ());
562 : } else {
563 41106443 : if (isCrossing) {
564 : // draw internal lanes on top of junctions
565 155033 : glTranslated(0, 0, GLO_JUNCTION + 0.1);
566 40951410 : } else if (isWalkingArea) {
567 : // draw internal lanes on top of junctions
568 348160 : glTranslated(0, 0, GLO_JUNCTION + 0.3);
569 40603250 : } else if (isWaterway(myPermissions)) {
570 : // draw waterways below normal roads
571 461 : glTranslated(0, 0, getType() - 0.2);
572 40602789 : } else if (myPermissions == SVC_SUBWAY) {
573 : // draw subways further below
574 0 : glTranslated(0, 0, getType() - 0.4);
575 : } else {
576 40602789 : glTranslated(0, 0, getType());
577 : }
578 : }
579 41106575 : auto& shapeColors = getShapeColors(s2);
580 41106575 : if (MSGlobals::gUseMesoSim) {
581 : shapeColors.clear();
582 4374293 : const std::vector<RGBColor>& segmentColors = static_cast<const GUIEdge*>(myEdge)->getSegmentColors();
583 4374293 : if (segmentColors.size() > 0) {
584 : // apply segment specific shape colors
585 : //std::cout << getID() << " shape=" << myShape << " shapeSegs=" << toString(myShapeSegments) << "\n";
586 0 : for (int ii = 0; ii < (int)baseShape.size() - 1; ++ii) {
587 0 : shapeColors.push_back(segmentColors[myShapeSegments[ii]]);
588 : }
589 : }
590 : }
591 :
592 : // scale tls-controlled lane2lane-arrows along with their junction shapes
593 : double junctionExaggeration = 1;
594 : if (!isInternal
595 17314651 : && myEdge->getToJunction()->getType() <= SumoXMLNodeType::RAIL_CROSSING
596 45607557 : && (s.junctionSize.constantSize || s.junctionSize.exaggeration > 1)) {
597 0 : junctionExaggeration = MAX2(1.001, s.junctionSize.getExaggeration(s, this, 4));
598 : }
599 : // draw lane
600 : // check whether it is not too small
601 41106575 : if (s.scale * exaggeration < 1. && junctionExaggeration == 1 && s.junctionSize.minSize != 0) {
602 31248226 : if (!isInternal || hasRailSignal) {
603 13053849 : if (shapeColors.size() > 0) {
604 0 : GLHelper::drawLine(baseShape, shapeColors);
605 : } else {
606 13053849 : GLHelper::drawLine(baseShape);
607 : }
608 : }
609 31248226 : GLHelper::popMatrix();
610 :
611 : } else {
612 :
613 9858349 : GUINet* net = (GUINet*) MSNet::getInstance();
614 : bool mustDrawMarkings = false;
615 9858349 : bool hiddenBidi = getBidiLane() != nullptr && myEdge->getNumericalID() > myEdge->getBidiEdge()->getNumericalID();
616 9858349 : const bool detailZoom = s.scale * exaggeration > 5;
617 9858349 : const bool drawDetails = (detailZoom || s.junctionSize.minSize == 0 || hasRailSignal);
618 9858349 : const bool drawRails = drawAsRailway(s);
619 9858349 : const bool spreadSuperposed = s.spreadSuperposed && myBidiLane != nullptr;
620 9858349 : if (hiddenBidi && !spreadSuperposed) {
621 : // do not draw shape
622 34901 : mustDrawMarkings = !isInternal && myPermissions != 0 && myPermissions != SVC_PEDESTRIAN && exaggeration == 1.0 && !isWaterway(myPermissions) && neighLaneNotBidi();
623 9823448 : } else if (drawRails) {
624 : // draw as railway: assume standard gauge of 1435mm when lane width is not set
625 : // draw foot width 150mm, assume that distance between rail feet inner sides is reduced on both sides by 39mm with regard to the gauge
626 : // assume crosstie length of 181% gauge (2600mm for standard gauge)
627 : PositionVector shape = baseShape;
628 38660 : const double width = myWidth;
629 38660 : double halfGauge = 0.5 * (width == SUMO_const_laneWidth ? 1.4350 : width) * exaggeration;
630 38660 : if (spreadSuperposed) {
631 : try {
632 0 : shape.move2side(halfGauge * 0.8);
633 0 : } catch (InvalidArgument&) {}
634 0 : halfGauge *= 0.4;
635 : }
636 38660 : const double halfInnerFeetWidth = halfGauge - 0.039 * exaggeration;
637 38660 : const double halfRailWidth = detailZoom ? (halfInnerFeetWidth + 0.15 * exaggeration) : SUMO_const_halfLaneWidth * exaggeration;
638 38660 : const double halfCrossTieWidth = halfGauge * 1.81;
639 38660 : if (shapeColors.size() > 0) {
640 0 : GLHelper::drawBoxLines(shape, getShapeRotations(s2), getShapeLengths(s2), getShapeColors(s2), halfRailWidth);
641 : } else {
642 38660 : GLHelper::drawBoxLines(shape, getShapeRotations(s2), getShapeLengths(s2), halfRailWidth);
643 : }
644 : // Draw white on top with reduced width (the area between the two tracks)
645 38660 : if (detailZoom) {
646 1821 : glColor3d(1, 1, 1);
647 1821 : glTranslated(0, 0, .1);
648 1821 : GLHelper::drawBoxLines(shape, getShapeRotations(s2), getShapeLengths(s2), halfInnerFeetWidth);
649 1821 : setColor(s);
650 1821 : GLHelper::drawCrossTies(shape, getShapeRotations(s2), getShapeLengths(s2), 0.26 * exaggeration, 0.6 * exaggeration,
651 1821 : halfCrossTieWidth, 0, s.forceDrawForRectangleSelection);
652 : }
653 9823448 : } else if (isCrossing) {
654 152797 : if (s.drawCrossingsAndWalkingareas && (s.scale > 3.0 || s.junctionSize.minSize == 0)) {
655 46670 : glTranslated(0, 0, .2);
656 46670 : GLHelper::drawCrossTies(baseShape, getShapeRotations(s2), getShapeLengths(s2), 0.5, 1.0, getWidth() * 0.5,
657 46670 : 0, s.drawForRectangleSelection);
658 : #ifdef GUILane_DEBUG_DRAW_CROSSING_OUTLINE
659 : if (myOutlineShape != nullptr) {
660 : GLHelper::setColor(RGBColor::BLUE);
661 : glTranslated(0, 0, 0.4);
662 : GLHelper::drawBoxLines(*myOutlineShape, 0.1);
663 : glTranslated(0, 0, -0.4);
664 : if (s.geometryIndices.show(this)) {
665 : GLHelper::debugVertices(*myOutlineShape, s.geometryIndices, s.scale);
666 : }
667 : }
668 : #endif
669 46670 : glTranslated(0, 0, -.2);
670 : }
671 9631991 : } else if (isWalkingArea) {
672 335124 : if (s.drawCrossingsAndWalkingareas && (s.scale > 3.0 || s.junctionSize.minSize == 0)) {
673 129628 : glTranslated(0, 0, .2);
674 129628 : if (myTesselation == nullptr) {
675 4546 : myTesselation = new TesselatedPolygon(getID(), "", RGBColor::MAGENTA, PositionVector(), false, true, 0);
676 : }
677 129628 : myTesselation->drawTesselation(baseShape);
678 129628 : glTranslated(0, 0, -.2);
679 129628 : if (s.geometryIndices.show(this)) {
680 0 : GLHelper::debugVertices(baseShape, s.geometryIndices, s.scale);
681 : }
682 : }
683 : } else {
684 : // we draw the lanes with reduced width so that the lane markings below are visible
685 : // (this avoids artifacts at geometry corners without having to
686 : // compute lane-marking intersection points)
687 9296867 : double halfWidth = isInternal ? myQuarterLaneWidth : (myHalfLaneWidth - SUMO_const_laneMarkWidth / 2);
688 9296867 : mustDrawMarkings = !isInternal && myPermissions != 0 && myPermissions != SVC_PEDESTRIAN && exaggeration == 1.0 && !isWaterway(myPermissions) && !isAirway(myPermissions);
689 9296867 : const int cornerDetail = drawDetails && !isInternal ? (s.drawForRectangleSelection ? 4 : MIN2(32, (int)(s.scale * exaggeration))) : 0;
690 18593734 : double offset = halfWidth * MAX2(0., (exaggeration - 1)) * (MSGlobals::gLefthand ? -1 : 1);
691 9296867 : if (spreadSuperposed) {
692 76888 : offset += halfWidth * 0.5 * (MSGlobals::gLefthand ? -1 : 1);
693 76888 : halfWidth *= 0.4; // create visible gap
694 : }
695 9296867 : if (shapeColors.size() > 0) {
696 0 : GLHelper::drawBoxLines(baseShape, getShapeRotations(s2), getShapeLengths(s2), shapeColors, halfWidth * exaggeration, cornerDetail, offset);
697 : } else {
698 9296867 : GLHelper::drawBoxLines(baseShape, getShapeRotations(s2), getShapeLengths(s2), halfWidth * exaggeration, cornerDetail, offset);
699 : }
700 : }
701 9858349 : GLHelper::popMatrix();
702 : #ifdef GUILane_DEBUG_DRAW_FOE_INTERSECTIONS
703 : if (myEdge->isInternal() && gSelected.isSelected(getType(), getGlID())) {
704 : debugDrawFoeIntersections();
705 : }
706 : #endif
707 9858349 : if (s.geometryIndices.show(this)) {
708 0 : GLHelper::debugVertices(baseShape, s.geometryIndices, s.scale);
709 : }
710 : // draw details
711 9858349 : if ((!isInternal || isCrossing || !s.drawJunctionShape) && (drawDetails || junctionExaggeration > 1)) {
712 427036 : GLHelper::pushMatrix();
713 427036 : glTranslated(0, 0, GLO_JUNCTION); // must draw on top of junction shape
714 427036 : glTranslated(0, 0, .5);
715 427036 : if (drawDetails) {
716 427036 : if (s.showLaneDirection) {
717 0 : if (drawRails) {
718 : // improve visibility of superposed rail edges
719 0 : GLHelper::setColor(setColor(s).changedBrightness(100));
720 : } else {
721 0 : glColor3d(0.3, 0.3, 0.3);
722 : }
723 0 : if (!isCrossing || s.drawCrossingsAndWalkingareas) {
724 0 : drawDirectionIndicators(exaggeration, spreadSuperposed, s.secondaryShape);
725 : }
726 : }
727 : if (!isInternal || isCrossing
728 : // controlled internal junction
729 427036 : || (getLinkCont().size() != 0 && getLinkCont()[0]->isInternalJunctionLink() && getLinkCont()[0]->getTLLogic() != nullptr)) {
730 427036 : if (MSGlobals::gLateralResolution > 0 && s.showSublanes && !hiddenBidi && (myPermissions & ~(SVC_PEDESTRIAN | SVC_RAIL_CLASSES)) != 0) {
731 : // draw sublane-borders
732 107710 : const double offsetSign = MSGlobals::gLefthand ? -1 : 1;
733 107710 : GLHelper::setColor(color.changedBrightness(51));
734 617934 : for (double offset = -myHalfLaneWidth; offset < myHalfLaneWidth; offset += MSGlobals::gLateralResolution) {
735 510224 : GLHelper::drawBoxLines(baseShape, getShapeRotations(s2), getShapeLengths(s2), 0.01, 0, -offset * offsetSign);
736 : }
737 : }
738 427036 : if (MSGlobals::gUseMesoSim && mySegmentStartIndex.size() > 0 && (myPermissions & ~SVC_PEDESTRIAN) != 0) {
739 : // draw segment borders
740 32889 : GLHelper::setColor(color.changedBrightness(51));
741 66821 : for (int i : mySegmentStartIndex) {
742 33932 : if (shapeColors.size() > 0) {
743 0 : GLHelper::setColor(shapeColors[i].changedBrightness(51));
744 : }
745 33932 : GLHelper::drawBoxLine(baseShape[i], getShapeRotations(s2)[i] + 90, myWidth / 3, 0.2, 0);
746 33932 : GLHelper::drawBoxLine(baseShape[i], getShapeRotations(s2)[i] - 90, myWidth / 3, 0.2, 0);
747 : }
748 : }
749 427036 : if (s.showLinkDecals && !drawRails && !drawAsWaterway(s) && myPermissions != SVC_PEDESTRIAN) {
750 368269 : drawArrows(s.secondaryShape);
751 : }
752 427036 : glTranslated(0, 0, 1000);
753 427036 : if (s.drawLinkJunctionIndex.show(nullptr)) {
754 0 : drawLinkNo(s);
755 : }
756 427036 : if (s.drawLinkTLIndex.show(nullptr)) {
757 0 : drawTLSLinkNo(s, *net);
758 : }
759 427036 : glTranslated(0, 0, -1000);
760 : }
761 427036 : glTranslated(0, 0, .1);
762 : }
763 427036 : if ((drawDetails || junctionExaggeration > 1) && s.showLane2Lane) {
764 : // draw from end of first to the begin of second but respect junction scaling
765 0 : drawLane2LaneConnections(junctionExaggeration, s.secondaryShape);
766 : }
767 427036 : GLHelper::popMatrix();
768 : // make sure link rules are drawn so tls can be selected via right-click
769 427036 : if (s.showLinkRules && drawDetails && !isWalkingArea &&
770 427036 : (!myEdge->isInternal() || (getLinkCont().size() > 0 && getLinkCont()[0]->isInternalJunctionLink()))) {
771 427036 : GLHelper::pushMatrix();
772 427036 : glTranslated(0, 0, GLO_SHAPE); // must draw on top of junction shape and additionals
773 427036 : drawLinkRules(s, *net);
774 427036 : GLHelper::popMatrix();
775 : }
776 : }
777 9858349 : if (mustDrawMarkings && drawDetails && s.laneShowBorders) { // needs matrix reset
778 358620 : drawMarkings(s, exaggeration);
779 : }
780 345088 : if (drawDetails && isInternal && s.showBikeMarkings && myPermissions == SVC_BICYCLE && exaggeration == 1.0 && s.showLinkDecals && s.laneShowBorders && !hiddenBidi
781 2831 : && MSGlobals::gUsingInternalLanes
782 9861001 : && getNormalSuccessorLane()->getPermissions() == SVC_BICYCLE && getNormalPredecessorLane()->getPermissions() == SVC_BICYCLE) {
783 783 : drawBikeMarkings();
784 : }
785 345088 : if (drawDetails && isInternal && exaggeration == 1.0 && s.showLinkDecals && s.laneShowBorders && !hiddenBidi && myIndex > 0
786 9912975 : && !(myEdge->getLanes()[myIndex - 1]->allowsChangingLeft(SVC_PASSENGER) && allowsChangingRight(SVC_PASSENGER))) {
787 : // draw lane changing prohibitions on junction
788 14 : drawJunctionChangeProhibitions();
789 : }
790 : }
791 : } else {
792 85720 : GLHelper::popMatrix();
793 : }
794 : // draw vehicles
795 41192295 : if (s.scale * s.vehicleSize.getExaggeration(s, nullptr) > s.vehicleSize.minSize) {
796 : // retrieve vehicles from lane; disallow simulation
797 9944053 : const MSLane::VehCont& vehicles = getVehiclesSecure();
798 21841701 : for (MSLane::VehCont::const_iterator v = vehicles.begin(); v != vehicles.end(); ++v) {
799 11897648 : if ((*v)->getLane() == this) {
800 11897648 : static_cast<const GUIVehicle*>(*v)->drawGL(s);
801 : } // else: this is the shadow during a continuous lane change
802 : }
803 : // draw long partial vehicles (#14342)
804 10690880 : for (const MSVehicle* veh : myPartialVehicles) {
805 746827 : if (veh->getLength() > RENDERING_BUFFER) {
806 : // potential double rendering taken into account
807 16735 : static_cast<const GUIVehicle*>(veh)->drawGL(s);
808 : }
809 : }
810 : // draw parking vehicles
811 9977575 : for (const MSBaseVehicle* const v : myParkingVehicles) {
812 33522 : dynamic_cast<const GUIBaseVehicle*>(v)->drawGL(s);
813 : }
814 : // allow lane simulation
815 9944053 : releaseVehicles();
816 : }
817 41192295 : GLHelper::popName();
818 41192295 : }
819 :
820 : bool
821 20013 : GUILane::neighLaneNotBidi() const {
822 20013 : const MSLane* right = getParallelLane(-1, false);
823 20013 : if (right && right->getBidiLane() == nullptr) {
824 : return true;
825 : }
826 9762 : const MSLane* left = getParallelLane(1, false);
827 9762 : if (left && left->getBidiLane() == nullptr) {
828 : return true;
829 : }
830 : return false;
831 : }
832 :
833 : void
834 358620 : GUILane::drawMarkings(const GUIVisualizationSettings& s, double scale) const {
835 358620 : GLHelper::pushMatrix();
836 358620 : glTranslated(0, 0, GLO_EDGE);
837 358620 : setColor(s);
838 : // optionally draw inverse markings
839 358620 : const bool s2 = s.secondaryShape;
840 358620 : if (myIndex > 0 && (myEdge->getLanes()[myIndex - 1]->getPermissions() & myPermissions) != 0) {
841 : const bool cl = myEdge->getLanes()[myIndex - 1]->allowsChangingLeft(SVC_PASSENGER);
842 : const bool cr = allowsChangingRight(SVC_PASSENGER);
843 105645 : GLHelper::drawInverseMarkings(getShape(s2), getShapeRotations(s2), getShapeLengths(s2), 3, 6, myHalfLaneWidth, cl, cr, MSGlobals::gLefthand, scale);
844 : }
845 : // draw white boundings and white markings
846 358620 : glColor3d(1, 1, 1);
847 717240 : GLHelper::drawBoxLines(
848 358620 : getShape(s2),
849 : getShapeRotations(s2),
850 : getShapeLengths(s2),
851 358620 : (myHalfLaneWidth + SUMO_const_laneMarkWidth) * scale);
852 358620 : GLHelper::popMatrix();
853 358620 : }
854 :
855 :
856 : void
857 783 : GUILane::drawBikeMarkings() const {
858 : // draw bike lane markings onto the intersection
859 783 : glColor3d(1, 1, 1);
860 : /// fixme
861 : const bool s2 = false;
862 783 : const int e = (int) getShape(s2).size() - 1;
863 : const double markWidth = 0.1;
864 783 : const double mw = myHalfLaneWidth;
865 2466 : for (int i = 0; i < e; ++i) {
866 1683 : GLHelper::pushMatrix();
867 1683 : glTranslated(getShape(s2)[i].x(), getShape(s2)[i].y(), GLO_JUNCTION + 0.4);
868 1683 : glRotated(getShapeRotations(s2)[i], 0, 0, 1);
869 13941 : for (double t = 0; t < getShapeLengths(s2)[i]; t += 0.5) {
870 : // left and right marking
871 36774 : for (int side = -1; side <= 1; side += 2) {
872 24516 : glBegin(GL_QUADS);
873 24516 : glVertex2d(side * mw, -t);
874 24516 : glVertex2d(side * mw, -t - 0.35);
875 24516 : glVertex2d(side * (mw + markWidth), -t - 0.35);
876 24516 : glVertex2d(side * (mw + markWidth), -t);
877 24516 : glEnd();
878 : }
879 : }
880 1683 : GLHelper::popMatrix();
881 : }
882 783 : }
883 :
884 :
885 : void
886 14 : GUILane::drawJunctionChangeProhibitions() const {
887 : // fixme
888 : const bool s2 = false;
889 : // draw white markings
890 14 : if (myIndex > 0 && (myEdge->getLanes()[myIndex - 1]->getPermissions() & myPermissions) != 0) {
891 14 : glColor3d(1, 1, 1);
892 14 : const bool cl = myEdge->getLanes()[myIndex - 1]->allowsChangingLeft(SVC_PASSENGER);
893 : const bool cr = allowsChangingRight(SVC_PASSENGER);
894 : // solid line marking
895 : double mw, mw2;
896 : // optional broken line marking
897 : double mw3, mw4;
898 14 : if (!cl && !cr) {
899 : // draw a single solid line
900 6 : mw = myHalfLaneWidth + SUMO_const_laneMarkWidth * 0.4;
901 6 : mw2 = myHalfLaneWidth - SUMO_const_laneMarkWidth * 0.4;
902 : mw3 = myHalfLaneWidth;
903 : mw4 = myHalfLaneWidth;
904 : } else {
905 : // draw one solid and one broken line
906 8 : if (cl) {
907 4 : mw = myHalfLaneWidth - SUMO_const_laneMarkWidth * 0.2;
908 4 : mw2 = myHalfLaneWidth - SUMO_const_laneMarkWidth * 0.6;
909 4 : mw3 = myHalfLaneWidth + SUMO_const_laneMarkWidth * 0.2;
910 4 : mw4 = myHalfLaneWidth + SUMO_const_laneMarkWidth * 0.6;
911 : } else {
912 4 : mw = myHalfLaneWidth + SUMO_const_laneMarkWidth * 0.2;
913 4 : mw2 = myHalfLaneWidth + SUMO_const_laneMarkWidth * 0.6;
914 4 : mw3 = myHalfLaneWidth - SUMO_const_laneMarkWidth * 0.2;
915 4 : mw4 = myHalfLaneWidth - SUMO_const_laneMarkWidth * 0.6;
916 : }
917 : }
918 14 : if (MSGlobals::gLefthand) {
919 0 : mw *= -1;
920 0 : mw2 *= -1;
921 : }
922 14 : int e = (int) getShape(s2).size() - 1;
923 28 : for (int i = 0; i < e; ++i) {
924 14 : GLHelper::pushMatrix();
925 14 : glTranslated(getShape(s2)[i].x(), getShape(s2)[i].y(), GLO_JUNCTION + 0.4);
926 14 : glRotated(getShapeRotations(s2)[i], 0, 0, 1);
927 294 : for (double t = 0; t < getShapeLengths(s2)[i]; t += 6) {
928 280 : const double lengthSolid = MIN2(6.0, getShapeLengths(s2)[i] - t);
929 280 : glBegin(GL_QUADS);
930 280 : glVertex2d(-mw, -t);
931 280 : glVertex2d(-mw, -t - lengthSolid);
932 280 : glVertex2d(-mw2, -t - lengthSolid);
933 280 : glVertex2d(-mw2, -t);
934 280 : glEnd();
935 280 : if (cl || cr) {
936 160 : const double lengthBroken = MIN2(3.0, getShapeLengths(s2)[i] - t);
937 160 : glBegin(GL_QUADS);
938 160 : glVertex2d(-mw3, -t);
939 160 : glVertex2d(-mw3, -t - lengthBroken);
940 160 : glVertex2d(-mw4, -t - lengthBroken);
941 160 : glVertex2d(-mw4, -t);
942 160 : glEnd();
943 : }
944 : }
945 14 : GLHelper::popMatrix();
946 : }
947 : }
948 14 : }
949 :
950 : void
951 0 : GUILane::drawDirectionIndicators(double exaggeration, bool spreadSuperposed, bool s2) const {
952 0 : GLHelper::pushMatrix();
953 0 : glTranslated(0, 0, GLO_EDGE);
954 0 : int e = (int) getShape(s2).size() - 1;
955 0 : const double widthFactor = spreadSuperposed ? 0.4 : 1;
956 0 : const double w = MAX2(POSITION_EPS, myWidth * widthFactor);
957 0 : const double w2 = MAX2(POSITION_EPS, myHalfLaneWidth * widthFactor);
958 0 : const double w4 = MAX2(POSITION_EPS, myQuarterLaneWidth * widthFactor);
959 0 : const double sideOffset = spreadSuperposed ? w * -0.5 : 0;
960 0 : for (int i = 0; i < e; ++i) {
961 0 : GLHelper::pushMatrix();
962 0 : glTranslated(getShape(s2)[i].x(), getShape(s2)[i].y(), 0.1);
963 0 : glRotated(getShapeRotations(s2)[i], 0, 0, 1);
964 0 : for (double t = 0; t < getShapeLengths(s2)[i]; t += w) {
965 0 : const double length = MIN2(w2, getShapeLengths(s2)[i] - t) * exaggeration;
966 0 : glBegin(GL_TRIANGLES);
967 0 : glVertex2d(sideOffset, -t - length);
968 0 : glVertex2d(sideOffset - w4 * exaggeration, -t);
969 0 : glVertex2d(sideOffset + w4 * exaggeration, -t);
970 0 : glEnd();
971 : }
972 0 : GLHelper::popMatrix();
973 : }
974 0 : GLHelper::popMatrix();
975 0 : }
976 :
977 :
978 : void
979 0 : GUILane::debugDrawFoeIntersections() const {
980 0 : GLHelper::pushMatrix();
981 0 : glTranslated(0, 0, 5);
982 0 : glColor3d(1.0, 0.3, 0.3);
983 : const double orthoLength = 0.5;
984 0 : const MSLink* link = getLinkCont().front();
985 : const std::vector<const MSLane*>& foeLanes = link->getFoeLanes();
986 : const auto& conflicts = link->getConflicts();
987 0 : if (foeLanes.size() == conflicts.size()) {
988 0 : for (int i = 0; i < (int)foeLanes.size(); ++i) {
989 0 : const MSLane* l = foeLanes[i];
990 0 : Position pos = l->geometryPositionAtOffset(l->getLength() - conflicts[i].lengthBehindCrossing);
991 0 : PositionVector ortho = l->getShape().getOrthogonal(pos, 10, true, orthoLength);
992 0 : if (ortho.length() < orthoLength) {
993 0 : ortho.extrapolate(orthoLength - ortho.length(), false, true);
994 : }
995 0 : GLHelper::drawLine(ortho);
996 : //std::cout << "foe=" << l->getID() << " lanePos=" << l->getLength() - conflicts[i].lengthBehindCrossing << " pos=" << pos << "\n";
997 0 : }
998 : }
999 0 : GLHelper::popMatrix();
1000 0 : }
1001 :
1002 :
1003 : // ------ inherited from GUIGlObject
1004 : GUIGLObjectPopupMenu*
1005 0 : GUILane::getPopUpMenu(GUIMainWindow& app, GUISUMOAbstractView& parent) {
1006 0 : GUIGLObjectPopupMenu* ret = new GUIGLObjectPopupMenu(app, parent, this);
1007 0 : buildPopupHeader(ret, app);
1008 0 : buildCenterPopupEntry(ret);
1009 : //
1010 0 : GUIDesigns::buildFXMenuCommand(ret, TL("Copy edge name to clipboard"), nullptr, ret, MID_COPY_EDGE_NAME);
1011 0 : buildNameCopyPopupEntry(ret);
1012 0 : buildSelectionPopupEntry(ret);
1013 : //
1014 0 : buildShowParamsPopupEntry(ret, false);
1015 0 : const PositionVector& baseShape = getShape(parent.getVisualisationSettings().secondaryShape);
1016 0 : const double pos = interpolateGeometryPosToLanePos(baseShape.nearest_offset_to_point25D(parent.getPositionInformation()));
1017 0 : const double height = baseShape.positionAtOffset(pos).z();
1018 0 : GUIDesigns::buildFXMenuCommand(ret, (TL("pos: ") + toString(pos) + " " + TL("height: ") + toString(height)).c_str(), nullptr, nullptr, 0);
1019 0 : if (getEdge().hasDistance()) {
1020 0 : GUIDesigns::buildFXMenuCommand(ret, ("distance: " + toString(getEdge().getDistanceAt(pos))).c_str(), nullptr, nullptr, 0);
1021 : }
1022 0 : new FXMenuSeparator(ret);
1023 0 : buildPositionCopyEntry(ret, app);
1024 0 : new FXMenuSeparator(ret);
1025 0 : if (myAmClosed) {
1026 0 : if (myPermissionChanges.empty()) {
1027 0 : GUIDesigns::buildFXMenuCommand(ret, TL("Reopen lane"), nullptr, &parent, MID_CLOSE_LANE);
1028 0 : GUIDesigns::buildFXMenuCommand(ret, TL("Reopen edge"), nullptr, &parent, MID_CLOSE_EDGE);
1029 : } else {
1030 0 : GUIDesigns::buildFXMenuCommand(ret, TL("Reopen lane (override rerouter)"), nullptr, &parent, MID_CLOSE_LANE);
1031 0 : GUIDesigns::buildFXMenuCommand(ret, TL("Reopen edge (override rerouter)"), nullptr, &parent, MID_CLOSE_EDGE);
1032 : }
1033 : } else {
1034 0 : GUIDesigns::buildFXMenuCommand(ret, TL("Close lane"), nullptr, &parent, MID_CLOSE_LANE);
1035 0 : GUIDesigns::buildFXMenuCommand(ret, TL("Close edge"), nullptr, &parent, MID_CLOSE_EDGE);
1036 : }
1037 0 : GUIDesigns::buildFXMenuCommand(ret, TL("Add rerouter"), nullptr, &parent, MID_ADD_REROUTER);
1038 0 : new FXMenuSeparator(ret);
1039 : // reachability menu
1040 0 : FXMenuPane* reachableByClass = new FXMenuPane(ret);
1041 0 : ret->insertMenuPaneChild(reachableByClass);
1042 0 : new FXMenuCascade(ret, TL("Select reachable"), GUIIconSubSys::getIcon(GUIIcon::FLAG), reachableByClass);
1043 0 : for (auto i : SumoVehicleClassStrings.getStrings()) {
1044 0 : GUIDesigns::buildFXMenuCommand(reachableByClass, i.c_str(), VClassIcons::getVClassIcon(SumoVehicleClassStrings.get(i)), &parent, MID_REACHABILITY);
1045 0 : }
1046 0 : return ret;
1047 : }
1048 :
1049 :
1050 : GUIParameterTableWindow*
1051 0 : GUILane::getParameterWindow(GUIMainWindow& app, GUISUMOAbstractView& view) {
1052 0 : myCachedGUISettings = view.editVisualisationSettings();
1053 0 : GUIParameterTableWindow* ret = new GUIParameterTableWindow(app, *this);
1054 : // add items
1055 0 : ret->mkItem(TL("allowed speed [m/s]"), false, getSpeedLimit());
1056 0 : const std::map<SUMOVehicleClass, double>* restrictions = MSNet::getInstance()->getRestrictions(myEdge->getEdgeType());
1057 0 : if (restrictions != nullptr) {
1058 0 : for (const auto& elem : *restrictions) {
1059 0 : ret->mkItem((std::string(" ") + TL("allowed speed [m/s]") + std::string(": ") + toString(elem.first)).c_str(), false, elem.second);
1060 : }
1061 : }
1062 0 : ret->mkItem(TL("length [m]"), false, myLength);
1063 0 : ret->mkItem(TL("width [m]"), false, myWidth);
1064 0 : ret->mkItem(TL("street name"), false, myEdge->getStreetName());
1065 0 : ret->mkItem(TL("stored travel time [s]"), true, new FunctionBinding<GUILane, double>(this, &GUILane::getStoredEdgeTravelTime));
1066 0 : ret->mkItem(TL("loaded weight"), true, new FunctionBinding<GUILane, double>(this, &GUILane::getLoadedEdgeWeight));
1067 0 : ret->mkItem(TL("routing speed [m/s]"), true, new FunctionBinding<MSEdge, double>(myEdge, &MSEdge::getRoutingSpeed));
1068 0 : ret->mkItem(TL("lane friction coefficient [%]"), true, new FunctionBinding<GUILane, double>(this, &GUILane::getFrictionCoefficient));
1069 0 : ret->mkItem(TL("time penalty [s]"), true, new FunctionBinding<MSEdge, double>(myEdge, &MSEdge::getTimePenalty));
1070 0 : ret->mkItem(TL("brutto occupancy [%]"), true, new FunctionBinding<GUILane, double>(this, &GUILane::getBruttoOccupancy, 100.));
1071 0 : ret->mkItem(TL("netto occupancy [%]"), true, new FunctionBinding<GUILane, double>(this, &GUILane::getNettoOccupancy, 100.));
1072 0 : ret->mkItem(TL("pending insertions [#]"), true, new FunctionBinding<GUILane, double>(this, &GUILane::getPendingEmits));
1073 0 : ret->mkItem(TL("edge type"), false, myEdge->getEdgeType());
1074 0 : ret->mkItem(TL("routing type"), false, myEdge->getRoutingType());
1075 0 : ret->mkItem(TL("type"), false, myLaneType);
1076 0 : ret->mkItem(TL("priority"), false, myEdge->getPriority());
1077 0 : ret->mkItem(TL("distance [km]"), false, myEdge->getDistance() / 1000);
1078 0 : ret->mkItem(TL("allowed vehicle class"), false, StringUtils::wrapText(getVehicleClassNames(myPermissions), 60));
1079 0 : ret->mkItem(TL("disallowed vehicle class"), false, StringUtils::wrapText(getVehicleClassNames(~myPermissions), 60));
1080 0 : ret->mkItem(TL("permission code"), false, myPermissions);
1081 0 : ret->mkItem(TL("color value"), true, new FunctionBinding<GUILane, double>(this, &GUILane::getColorValueForTracker));
1082 0 : if (myBidiLane != nullptr) {
1083 0 : ret->mkItem(TL("bidi-lane"), false, myBidiLane->getID());
1084 : }
1085 : // info for blocked departDriveWay
1086 0 : for (auto item : getParametersMap()) {
1087 0 : if (StringUtils::startsWith(item.first, "insertionBlocked:")) {
1088 0 : const MSDriveWay* dw = MSDriveWay::retrieveDepartDriveWay(myEdge, item.second);
1089 0 : if (dw != nullptr) {
1090 0 : ret->mkItem(("blocking " + dw->getID()).c_str(), false, toString(MSRailSignal::getBlockingVehicles(dw)));
1091 0 : ret->mkItem(("driveWays blocking " + dw->getID()).c_str(), false, toString(MSRailSignal::getBlockingDriveWays(dw)));
1092 : }
1093 : }
1094 : }
1095 :
1096 0 : for (const auto& kv : myEdge->getParametersMap()) {
1097 0 : ret->mkItem(("edgeParam:" + kv.first).c_str(), false, kv.second);
1098 : }
1099 0 : ret->checkFont(myEdge->getStreetName());
1100 0 : ret->closeBuilding();
1101 0 : return ret;
1102 : }
1103 :
1104 :
1105 : Boundary
1106 0 : GUILane::getCenteringBoundary() const {
1107 0 : const PositionVector& shape = GUIGlobals::gSecondaryShape && myShape2.size() > 0 ? myShape2 : myShape;
1108 0 : Boundary b;
1109 0 : b.add(shape[0]);
1110 0 : b.add(shape[-1]);
1111 0 : b.grow(RENDERING_BUFFER);
1112 : // ensure that vehicles and persons on the side are drawn even if the edge
1113 : // is outside the view
1114 0 : return b;
1115 : }
1116 :
1117 :
1118 : const PositionVector&
1119 85356201 : GUILane::getShape(bool secondary) const {
1120 85356201 : return secondary && myShape2.size() > 0 ? myShape2 : myShape;
1121 : }
1122 :
1123 :
1124 : const std::vector<double>&
1125 10429889 : GUILane::getShapeRotations(bool secondary) const {
1126 10429889 : return secondary && myShapeRotations2.size() > 0 ? myShapeRotations2 : myShapeRotations;
1127 : }
1128 :
1129 :
1130 : const std::vector<double>&
1131 10375003 : GUILane::getShapeLengths(bool secondary) const {
1132 10375003 : return secondary && myShapeLengths2.size() > 0 ? myShapeLengths2 : myShapeLengths;
1133 : }
1134 :
1135 :
1136 : std::vector<RGBColor>&
1137 82734434 : GUILane::getShapeColors(bool secondary) const {
1138 82734434 : return secondary && myShapeColors2.size() > 0 ? myShapeColors2 : myShapeColors;
1139 : }
1140 :
1141 :
1142 : double
1143 0 : GUILane::firstWaitingTime() const {
1144 0 : return myVehicles.size() == 0 ? 0 : myVehicles.back()->getWaitingSeconds();
1145 : }
1146 :
1147 :
1148 : double
1149 0 : GUILane::getEdgeLaneNumber() const {
1150 0 : return (double) myEdge->getLanes().size();
1151 : }
1152 :
1153 :
1154 : double
1155 0 : GUILane::getStoredEdgeTravelTime() const {
1156 0 : MSEdgeWeightsStorage& ews = MSNet::getInstance()->getWeightsStorage();
1157 0 : if (!ews.knowsTravelTime(myEdge)) {
1158 : return -1;
1159 : } else {
1160 0 : double value(0);
1161 0 : ews.retrieveExistingTravelTime(myEdge, STEPS2TIME(MSNet::getInstance()->getCurrentTimeStep()), value);
1162 0 : return value;
1163 : }
1164 : }
1165 :
1166 :
1167 : double
1168 0 : GUILane::getLoadedEdgeWeight() const {
1169 0 : MSEdgeWeightsStorage& ews = MSNet::getInstance()->getWeightsStorage();
1170 0 : if (!ews.knowsEffort(myEdge)) {
1171 : return -1;
1172 : } else {
1173 0 : double value(-1);
1174 0 : ews.retrieveExistingEffort(myEdge, STEPS2TIME(MSNet::getInstance()->getCurrentTimeStep()), value);
1175 0 : return value;
1176 : }
1177 : }
1178 :
1179 :
1180 : double
1181 0 : GUILane::getColorValueWithFunctional(const GUIVisualizationSettings& s, int activeScheme) const {
1182 0 : switch (activeScheme) {
1183 0 : case 18: {
1184 0 : return GeomHelper::naviDegree(getShape(s.secondaryShape).beginEndAngle()); // [0-360]
1185 : }
1186 0 : default:
1187 0 : return getColorValue(s, activeScheme);
1188 : }
1189 :
1190 : }
1191 :
1192 :
1193 : RGBColor
1194 41783096 : GUILane::setColor(const GUIVisualizationSettings& s) const {
1195 : // setting and retrieving the color does not work in OSGView so we return it explicitliy
1196 41783096 : RGBColor col;
1197 41783096 : if (MSGlobals::gUseMesoSim && static_cast<const GUIEdge*>(myEdge)->getMesoColor() != MESO_USE_LANE_COLOR) {
1198 0 : col = static_cast<const GUIEdge*>(myEdge)->getMesoColor();
1199 : } else {
1200 41783096 : const GUIColorer& c = s.laneColorer;
1201 41783096 : if (!setFunctionalColor(c, col) && !setMultiColor(s, c, col)) {
1202 41627859 : col = c.getScheme().getColor(getColorValue(s, c.getActive()));
1203 : }
1204 : }
1205 41783096 : GLHelper::setColor(col);
1206 41783096 : return col;
1207 : }
1208 :
1209 :
1210 : bool
1211 45169080 : GUILane::setFunctionalColor(const GUIColorer& c, RGBColor& col, int activeScheme) const {
1212 45169080 : if (activeScheme < 0) {
1213 : activeScheme = c.getActive();
1214 : }
1215 45169080 : switch (activeScheme) {
1216 45159664 : case 0:
1217 45159664 : if (myEdge->isCrossing()) {
1218 : // determine priority to decide color
1219 155237 : const MSLink* const link = getLogicalPredecessorLane()->getLinkTo(this);
1220 155237 : if (link->havePriority() || link->getTLLogic() != nullptr) {
1221 71261 : col = RGBColor(230, 230, 230);
1222 : } else {
1223 83976 : col = RGBColor(26, 26, 26);
1224 : }
1225 155237 : GLHelper::setColor(col);
1226 155237 : return true;
1227 : } else {
1228 : return false;
1229 : }
1230 0 : case 18: {
1231 0 : double hue = GeomHelper::naviDegree(myShape.beginEndAngle()); // [0-360]
1232 0 : col = RGBColor::fromHSV(hue, 1., 1.);
1233 0 : GLHelper::setColor(col);
1234 0 : return true;
1235 : }
1236 : case 30: { // taz color
1237 0 : col = c.getScheme().getColor(0);
1238 : std::vector<RGBColor> tazColors;
1239 0 : for (MSEdge* e : myEdge->getPredecessors()) {
1240 0 : if (e->isTazConnector() && e->hasParameter("tazColor")) {
1241 0 : tazColors.push_back(RGBColor::parseColor(e->getParameter("tazColor")));
1242 : }
1243 : }
1244 0 : for (MSEdge* e : myEdge->getSuccessors()) {
1245 0 : if (e->isTazConnector() && e->hasParameter("tazColor")) {
1246 0 : tazColors.push_back(RGBColor::parseColor(e->getParameter("tazColor")));
1247 : }
1248 : }
1249 0 : if (tazColors.size() > 0) {
1250 0 : int randColor = RandHelper::rand((int)tazColors.size(), RGBColor::getColorRNG());
1251 0 : col = tazColors[randColor];
1252 : }
1253 0 : GLHelper::setColor(col);
1254 : return true;
1255 0 : }
1256 : default:
1257 : return false;
1258 : }
1259 : }
1260 :
1261 :
1262 : bool
1263 41627859 : GUILane::setMultiColor(const GUIVisualizationSettings& s, const GUIColorer& c, RGBColor& col) const {
1264 : const int activeScheme = c.getActive();
1265 41627859 : auto& shapeColors = getShapeColors(s.secondaryShape);
1266 41627859 : const PositionVector& shape = getShape(s.secondaryShape);
1267 : shapeColors.clear();
1268 41627859 : switch (activeScheme) {
1269 0 : case 22: // color by height at segment start
1270 0 : for (PositionVector::const_iterator ii = shape.begin(); ii != shape.end() - 1; ++ii) {
1271 0 : shapeColors.push_back(c.getScheme().getColor(ii->z()));
1272 : }
1273 : // osg fallback (edge height at start)
1274 0 : col = c.getScheme().getColor(getColorValue(s, 21));
1275 0 : return true;
1276 : case 24: // color by inclination at segment start
1277 0 : for (int ii = 1; ii < (int)shape.size(); ++ii) {
1278 0 : const double inc = (shape[ii].z() - shape[ii - 1].z()) / MAX2(POSITION_EPS, shape[ii].distanceTo2D(shape[ii - 1]));
1279 0 : shapeColors.push_back(c.getScheme().getColor(inc));
1280 : }
1281 0 : col = c.getScheme().getColor(getColorValue(s, 23));
1282 0 : return true;
1283 : default:
1284 : return false;
1285 : }
1286 : }
1287 :
1288 : double
1289 0 : GUILane::getColorValueForTracker() const {
1290 0 : if (myCachedGUISettings != nullptr) {
1291 : const GUIVisualizationSettings& s = *myCachedGUISettings;
1292 : const GUIColorer& c = s.laneColorer;
1293 0 : double val = getColorValueWithFunctional(s, c.getActive());
1294 0 : if (val == GUIVisualizationSettings::MISSING_DATA) {
1295 : // blowing up the dialog or plot isn't helpful. At least 0 may be understood as neutral
1296 : return 0;
1297 : } else {
1298 : return val;
1299 : }
1300 : } else {
1301 : return 0;
1302 : }
1303 : }
1304 :
1305 :
1306 : double
1307 41627859 : GUILane::getColorValue(const GUIVisualizationSettings& s, int activeScheme) const {
1308 41627859 : switch (activeScheme) {
1309 41618443 : case 0:
1310 41618443 : switch (myPermissions) {
1311 : case SVC_PEDESTRIAN:
1312 : return 1;
1313 : case SVC_BICYCLE:
1314 : return 2;
1315 88651 : case 0:
1316 : // forbidden road or green verge
1317 88651 : return myEdge->getPermissions() == 0 ? 10 : 3;
1318 608 : case SVC_SHIP:
1319 608 : return 4;
1320 2842 : case SVC_AUTHORITY:
1321 2842 : return 8;
1322 0 : case SVC_AIRCRAFT:
1323 : case SVC_DRONE:
1324 0 : return 11;
1325 : default:
1326 : break;
1327 : }
1328 40528254 : if (myEdge->isTazConnector()) {
1329 : return 9;
1330 40528254 : } else if (isRailway(myPermissions)) {
1331 : return 5;
1332 40201488 : } else if ((myPermissions & SVC_PASSENGER) != 0) {
1333 40092442 : if ((myPermissions & (SVC_RAIL_CLASSES & ~SVC_RAIL_FAST)) != 0 && (myPermissions & SVC_SHIP) == 0) {
1334 : return 6;
1335 : } else {
1336 : return 0;
1337 : }
1338 : } else {
1339 109046 : if ((myPermissions & SVC_RAIL_CLASSES) != 0 && (myPermissions & SVC_SHIP) == 0) {
1340 : return 6;
1341 : } else {
1342 108785 : return 7;
1343 : }
1344 : }
1345 9416 : case 1:
1346 9416 : return isLaneOrEdgeSelected();
1347 0 : case 2:
1348 0 : return (double)myPermissions;
1349 0 : case 3:
1350 0 : return getSpeedLimit();
1351 0 : case 4:
1352 0 : return getBruttoOccupancy();
1353 0 : case 5:
1354 0 : return getNettoOccupancy();
1355 0 : case 6:
1356 0 : return firstWaitingTime();
1357 0 : case 7:
1358 0 : return getEdgeLaneNumber();
1359 0 : case 8:
1360 0 : return getEmissions<PollutantsInterface::CO2>() / myLength;
1361 0 : case 9:
1362 0 : return getEmissions<PollutantsInterface::CO>() / myLength;
1363 0 : case 10:
1364 0 : return getEmissions<PollutantsInterface::PM_X>() / myLength;
1365 0 : case 11:
1366 0 : return getEmissions<PollutantsInterface::NO_X>() / myLength;
1367 0 : case 12:
1368 0 : return getEmissions<PollutantsInterface::HC>() / myLength;
1369 0 : case 13:
1370 0 : return getEmissions<PollutantsInterface::FUEL>() / myLength;
1371 0 : case 14:
1372 0 : return getHarmonoise_NoiseEmissions();
1373 0 : case 15: {
1374 0 : return getStoredEdgeTravelTime();
1375 : }
1376 0 : case 16: {
1377 0 : MSEdgeWeightsStorage& ews = MSNet::getInstance()->getWeightsStorage();
1378 0 : if (!ews.knowsTravelTime(myEdge)) {
1379 : return -1;
1380 : } else {
1381 0 : double value(0);
1382 0 : ews.retrieveExistingTravelTime(myEdge, 0, value);
1383 0 : return 100 * myLength / value / getSpeedLimit();
1384 : }
1385 : }
1386 0 : case 17: {
1387 : // geometrical length has no meaning for walkingAreas since it describes the outer boundary
1388 0 : return myEdge->isWalkingArea() ? 1 : 1 / getLengthGeometryFactor(s.secondaryShape);
1389 : }
1390 0 : case 19: {
1391 0 : return getLoadedEdgeWeight();
1392 : }
1393 0 : case 20: {
1394 0 : return myEdge->getPriority();
1395 : }
1396 0 : case 21: {
1397 : // color by z of first shape point
1398 0 : return getShape(s.secondaryShape)[0].z();
1399 : }
1400 0 : case 23: {
1401 : // color by incline
1402 0 : return (getShape(s.secondaryShape)[-1].z() - getShape(s.secondaryShape)[0].z()) / getLength();
1403 : }
1404 0 : case 25: {
1405 : // color by average speed
1406 0 : return getMeanSpeed();
1407 : }
1408 0 : case 26: {
1409 : // color by average relative speed
1410 0 : return getMeanSpeed() / myMaxSpeed;
1411 : }
1412 0 : case 27: {
1413 : // color by routing device assumed speed
1414 0 : return myEdge->getRoutingSpeed();
1415 : }
1416 0 : case 28:
1417 0 : return getEmissions<PollutantsInterface::ELEC>() / myLength;
1418 0 : case 29:
1419 0 : return getPendingEmits();
1420 0 : case 31: {
1421 : // by numerical edge param value
1422 0 : if (myEdge->hasParameter(s.edgeParam)) {
1423 : try {
1424 0 : return StringUtils::toDouble(myEdge->getParameter(s.edgeParam, "0"));
1425 0 : } catch (NumberFormatException&) {
1426 : try {
1427 0 : return StringUtils::toBool(myEdge->getParameter(s.edgeParam, "0"));
1428 0 : } catch (BoolFormatException&) {
1429 0 : return GUIVisualizationSettings::MISSING_DATA;
1430 0 : }
1431 0 : }
1432 : } else {
1433 0 : return GUIVisualizationSettings::MISSING_DATA;
1434 : }
1435 : }
1436 0 : case 32: {
1437 : // by numerical lane param value
1438 0 : if (hasParameter(s.laneParam)) {
1439 : try {
1440 0 : return StringUtils::toDouble(getParameter(s.laneParam, "0"));
1441 0 : } catch (NumberFormatException&) {
1442 : try {
1443 0 : return StringUtils::toBool(getParameter(s.laneParam, "0"));
1444 0 : } catch (BoolFormatException&) {
1445 0 : return GUIVisualizationSettings::MISSING_DATA;
1446 0 : }
1447 0 : }
1448 : } else {
1449 0 : return GUIVisualizationSettings::MISSING_DATA;
1450 : }
1451 : }
1452 0 : case 33: {
1453 : // by edge data value
1454 0 : return GUINet::getGUIInstance()->getEdgeData(myEdge, s.edgeData);
1455 : }
1456 0 : case 34: {
1457 0 : return myEdge->getDistance();
1458 : }
1459 0 : case 35: {
1460 0 : return fabs(myEdge->getDistance());
1461 : }
1462 0 : case 36: {
1463 0 : return myReachability;
1464 : }
1465 0 : case 37: {
1466 0 : return myRNGIndex % MSGlobals::gNumSimThreads;
1467 : }
1468 0 : case 38: {
1469 0 : if (myParkingAreas == nullptr) {
1470 : // init
1471 0 : myParkingAreas = new std::vector<MSParkingArea*>();
1472 0 : for (auto& item : MSNet::getInstance()->getStoppingPlaces(SUMO_TAG_PARKING_AREA)) {
1473 0 : if (&item.second->getLane().getEdge() == myEdge) {
1474 0 : myParkingAreas->push_back(dynamic_cast<MSParkingArea*>(item.second));
1475 : }
1476 : }
1477 : }
1478 : int capacity = 0;
1479 0 : for (MSParkingArea* pa : *myParkingAreas) {
1480 0 : capacity += pa->getCapacity() - pa->getOccupancy();
1481 : }
1482 0 : return capacity;
1483 : }
1484 0 : case 39: {
1485 : // by live edge data value
1486 0 : return GUINet::getGUIInstance()->getMeanData(this, s.edgeDataID, s.edgeData);
1487 : }
1488 : }
1489 : return 0;
1490 : }
1491 :
1492 :
1493 : double
1494 36815824 : GUILane::getScaleValue(const GUIVisualizationSettings& s, int activeScheme, bool s2) const {
1495 36815824 : switch (activeScheme) {
1496 : case 0:
1497 : return 0;
1498 0 : case 1:
1499 0 : return isLaneOrEdgeSelected();
1500 0 : case 2:
1501 0 : return getSpeedLimit();
1502 0 : case 3:
1503 0 : return getBruttoOccupancy();
1504 0 : case 4:
1505 0 : return getNettoOccupancy();
1506 0 : case 5:
1507 0 : return firstWaitingTime();
1508 0 : case 6:
1509 0 : return getEdgeLaneNumber();
1510 0 : case 7:
1511 0 : return getEmissions<PollutantsInterface::CO2>() / myLength;
1512 0 : case 8:
1513 0 : return getEmissions<PollutantsInterface::CO>() / myLength;
1514 0 : case 9:
1515 0 : return getEmissions<PollutantsInterface::PM_X>() / myLength;
1516 0 : case 10:
1517 0 : return getEmissions<PollutantsInterface::NO_X>() / myLength;
1518 0 : case 11:
1519 0 : return getEmissions<PollutantsInterface::HC>() / myLength;
1520 0 : case 12:
1521 0 : return getEmissions<PollutantsInterface::FUEL>() / myLength;
1522 0 : case 13:
1523 0 : return getHarmonoise_NoiseEmissions();
1524 0 : case 14: {
1525 0 : return getStoredEdgeTravelTime();
1526 : }
1527 0 : case 15: {
1528 0 : MSEdgeWeightsStorage& ews = MSNet::getInstance()->getWeightsStorage();
1529 0 : if (!ews.knowsTravelTime(myEdge)) {
1530 : return -1;
1531 : } else {
1532 0 : double value(0);
1533 0 : ews.retrieveExistingTravelTime(myEdge, 0, value);
1534 0 : return 100 * myLength / value / getSpeedLimit();
1535 : }
1536 : }
1537 0 : case 16: {
1538 0 : return 1 / getLengthGeometryFactor(s2);
1539 : }
1540 0 : case 17: {
1541 0 : return getLoadedEdgeWeight();
1542 : }
1543 0 : case 18: {
1544 0 : return myEdge->getPriority();
1545 : }
1546 0 : case 19: {
1547 : // scale by average speed
1548 0 : return getMeanSpeed();
1549 : }
1550 0 : case 20: {
1551 : // scale by average relative speed
1552 0 : return getMeanSpeed() / myMaxSpeed;
1553 : }
1554 0 : case 21:
1555 0 : return getEmissions<PollutantsInterface::ELEC>() / myLength;
1556 0 : case 22:
1557 0 : return MSNet::getInstance()->getInsertionControl().getPendingEmits(this);
1558 0 : case 23:
1559 : // by edge data value
1560 0 : return GUINet::getGUIInstance()->getEdgeData(myEdge, s.edgeDataScaling);
1561 : }
1562 : return 0;
1563 : }
1564 :
1565 :
1566 : bool
1567 10191547 : GUILane::drawAsRailway(const GUIVisualizationSettings& s) const {
1568 10191547 : return isRailway(myPermissions) && ((myPermissions & SVC_BUS) == 0) && s.showRails;
1569 : }
1570 :
1571 :
1572 : bool
1573 746425 : GUILane::drawAsWaterway(const GUIVisualizationSettings& s) const {
1574 746425 : return isWaterway(myPermissions) && s.showRails; // reusing the showRails setting
1575 : }
1576 :
1577 :
1578 : #ifdef HAVE_OSG
1579 : void
1580 230360 : GUILane::updateColor(const GUIVisualizationSettings& s) {
1581 230360 : if (myGeom == 0) {
1582 : // not drawn
1583 0 : return;
1584 : }
1585 230360 : const RGBColor col = setColor(s);
1586 230360 : osg::Vec4ubArray* colors = dynamic_cast<osg::Vec4ubArray*>(myGeom->getColorArray());
1587 230360 : (*colors)[0].set(col.red(), col.green(), col.blue(), col.alpha());
1588 230360 : myGeom->setColorArray(colors);
1589 : }
1590 : #endif
1591 :
1592 :
1593 : void
1594 0 : GUILane::closeTraffic(bool rebuildAllowed) {
1595 0 : MSGlobals::gCheckRoutes = false;
1596 0 : if (myAmClosed) {
1597 : myPermissionChanges.clear(); // reset rerouters
1598 0 : resetPermissions(CHANGE_PERMISSIONS_GUI);
1599 : } else {
1600 0 : setPermissions(SVC_AUTHORITY, CHANGE_PERMISSIONS_GUI);
1601 : }
1602 0 : myAmClosed = !myAmClosed;
1603 0 : if (rebuildAllowed) {
1604 0 : getEdge().rebuildAllowedLanes();
1605 : }
1606 0 : }
1607 :
1608 :
1609 : PositionVector
1610 137126 : GUILane::splitAtSegments(const PositionVector& shape) {
1611 : assert(MSGlobals::gUseMesoSim);
1612 137126 : int no = MELoop::numSegmentsFor(myLength, OptionsCont::getOptions().getFloat("meso-edgelength"));
1613 137126 : const double slength = myLength / no;
1614 : PositionVector result = shape;
1615 : double offset = 0;
1616 435196 : for (int i = 0; i < no; ++i) {
1617 298070 : offset += slength;
1618 298070 : Position pos = shape.positionAtOffset(offset);
1619 298070 : int index = result.indexOfClosest(pos);
1620 298070 : if (pos.distanceTo(result[index]) > POSITION_EPS) {
1621 161513 : index = result.insertAtClosest(pos, false);
1622 : }
1623 298070 : if (i != no - 1) {
1624 160944 : mySegmentStartIndex.push_back(index);
1625 : }
1626 711773 : while ((int)myShapeSegments.size() < index) {
1627 413703 : myShapeSegments.push_back(i);
1628 : }
1629 : //std::cout << "splitAtSegments " << getID() << " no=" << no << " i=" << i << " offset=" << offset << " index=" << index << " segs=" << toString(myShapeSegments) << " resultSize=" << result.size() << " result=" << toString(result) << "\n";
1630 : }
1631 278348 : while (myShapeSegments.size() < result.size()) {
1632 141222 : myShapeSegments.push_back(no - 1);
1633 : }
1634 137126 : return result;
1635 0 : }
1636 :
1637 : bool
1638 300670 : GUILane::isSelected() const {
1639 300670 : return gSelected.isSelected(GLO_LANE, getGlID());
1640 : }
1641 :
1642 : bool
1643 9416 : GUILane::isLaneOrEdgeSelected() const {
1644 9416 : return isSelected() || gSelected.isSelected(GLO_EDGE, dynamic_cast<GUIEdge*>(myEdge)->getGlID());
1645 : }
1646 :
1647 : double
1648 0 : GUILane::getPendingEmits() const {
1649 0 : return MSNet::getInstance()->getInsertionControl().getPendingEmits(this);
1650 : }
1651 :
1652 : double
1653 0 : GUILane::getClickPriority() const {
1654 0 : if (MSGlobals::gUseMesoSim) {
1655 : // do not select lanes in meso mode
1656 0 : return INVALID_PRIORITY;
1657 : }
1658 0 : if (myEdge->isCrossing()) {
1659 0 : return GLO_CROSSING;
1660 : }
1661 : return GLO_LANE;
1662 : }
1663 :
1664 :
1665 : /****************************************************************************/
|