Eclipse SUMO - Simulation of Urban MObility
Loading...
Searching...
No Matches
GNERoute.cpp
Go to the documentation of this file.
1/****************************************************************************/
2// Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo
3// Copyright (C) 2001-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/****************************************************************************/
18// A class for visualizing routes in Netedit
19/****************************************************************************/
20
25#include <netedit/GNENet.h>
26#include <netedit/GNESegment.h>
28#include <netedit/GNEUndoList.h>
33
34#include "GNERoute.h"
35#include "GNEVehicle.h"
36
37// ===========================================================================
38// FOX callback mapping
39// ===========================================================================
40
44
45// Object implementation
46FXIMPLEMENT(GNERoute::GNERoutePopupMenu, GUIGLObjectPopupMenu, GNERoutePopupMenuMap, ARRAYNUMBER(GNERoutePopupMenuMap))
47
48// ===========================================================================
49// GNERoute::GNERoutePopupMenu - methods
50// ===========================================================================
51
55
56
58
59
60long
62 GNERoute* route = static_cast<GNERoute*>(myObject);
63 GNEUndoList* undoList = route->myNet->getViewNet()->getUndoList();
64 undoList->begin(route, "apply distance along route");
65 double dist = (route->getParentEdges().size() > 0) ? route->getParentEdges().front()->getNBEdge()->getDistance() : 0;
66 for (GNEEdge* edge : route->getParentEdges()) {
68 dist += edge->getNBEdge()->getFinalLength();
69 }
70 undoList->end();
71 return 1;
72}
73
74// ===========================================================================
75// GNERoute - methods
76// ===========================================================================
77
81
82
84 GNEDemandElement(calibrator->getNet()->getAttributeCarriers()->generateDemandElementID(SUMO_TAG_ROUTE), calibrator->getNet(),
85 calibrator->getFilename(), SUMO_TAG_ROUTE, GNEPathElement::Options::DEMAND_ELEMENT | GNEPathElement::Options::ROUTE) {
86 // set parent edge
87 if (calibrator->getParentEdges().size() > 0) {
88 setParents<GNEEdge*>({calibrator->getParentEdges().front()});
89 } else if (calibrator->getParentLanes().size() > 0) {
90 setParents<GNEEdge*>({calibrator->getParentLanes().front()->getParentEdge()});
91 } else {
92 throw InvalidArgument("Calibrator parent requieres at least one edge or one lane");
93 }
94}
95
96
97GNERoute::GNERoute(const std::string& id, const GNEDemandElement* originalRoute) :
98 GNEDemandElement(id, originalRoute->getNet(), originalRoute->getFilename(), originalRoute->getTagProperty()->getTag(),
99 originalRoute->getPathElementOptions()),
100 Parameterised(originalRoute->getParameters()->getParametersMap()),
101 myRepeat(parse<int>(originalRoute->getAttribute(SUMO_ATTR_REPEAT))),
102 myCycleTime(string2time(originalRoute->getAttribute(SUMO_ATTR_REPEAT))),
103 myVClass(originalRoute->getVClass()) {
104 // set parents
105 setParents<GNEEdge*>(originalRoute->getParentEdges());
107}
108
109
110GNERoute::GNERoute(GNEVehicle* vehicleParent, const GNEDemandElement* originalRoute) :
111 GNEDemandElement(vehicleParent, originalRoute->getTagProperty()->getTag(), originalRoute->getPathElementOptions()),
112 Parameterised(originalRoute->getParameters()->getParametersMap()),
113 myRepeat(parse<int>(originalRoute->getAttribute(SUMO_ATTR_REPEAT))),
114 myCycleTime(string2time(originalRoute->getAttribute(SUMO_ATTR_REPEAT))),
115 myVClass(originalRoute->getVClass()) {
116 // set parents
117 setParents<GNEEdge*>(originalRoute->getParentEdges());
118 setParent<GNEDemandElement*>(vehicleParent);
120}
121
122
123GNERoute::GNERoute(const std::string& id, GNENet* net, const std::string& filename, SUMOVehicleClass vClass,
124 const std::vector<GNEEdge*>& edges, const RGBColor& color, const int repeat,
125 const SUMOTime cycleTime, const Parameterised::Map& parameters) :
126 GNEDemandElement(id, net, filename, SUMO_TAG_ROUTE,
127 GNEPathElement::Options::DEMAND_ELEMENT | GNEPathElement::Options::ROUTE),
128 Parameterised(parameters),
129 myColor(color),
130 myRepeat(repeat),
131 myCycleTime(cycleTime),
132 myVClass(vClass) {
133 // set parents
134 setParents<GNEEdge*>(edges);
135}
136
137
138GNERoute::GNERoute(GNEDemandElement* vehicleParent, const std::vector<GNEEdge*>& edges, const RGBColor& color,
139 const int repeat, const SUMOTime cycleTime, const Parameterised::Map& parameters) :
141 GNEPathElement::Options::DEMAND_ELEMENT | GNEPathElement::Options::ROUTE),
142 Parameterised(parameters),
143 myColor(color),
144 myRepeat(repeat),
145 myCycleTime(cycleTime),
146 myVClass(vehicleParent->getVClass()) {
147 // set parents
148 setParents<GNEEdge*>(edges);
149 setParent<GNEDemandElement*>(vehicleParent);
150}
151
152
154
155
157 return nullptr;
158}
159
160
163 return this;
164}
165
166
167const Parameterised*
169 return this;
170}
171
172
175 // create popup
176 GUIGLObjectPopupMenu* ret = new GUIGLObjectPopupMenu(app, parent, this);
177 // build common options
179 // show option to open demand element dialog
180 if (myTagProperty->hasDialog()) {
181 GUIDesigns::buildFXMenuCommand(ret, "Open " + getTagStr() + " Dialog", getACIcon(), &parent, MID_OPEN_ADDITIONAL_DIALOG);
182 new FXMenuSeparator(ret);
183 }
184 GUIDesigns::buildFXMenuCommand(ret, "Cursor position in view: " + toString(getPositionInView().x()) + "," + toString(getPositionInView().y()), nullptr, nullptr, 0);
185 new FXMenuSeparator(ret);
186 GUIDesigns::buildFXMenuCommand(ret, "Apply distance along route", nullptr, ret, MID_GNE_ROUTE_APPLY_DISTANCE);
187 // route length
190 // add reverse
192 }
193 return ret;
194}
195
196
197void
199 device.openTag(SUMO_TAG_ROUTE);
200 // write id only for non-embedded routes
202 device.writeAttr(SUMO_ATTR_ID, getID());
203 }
207 }
210 }
213 }
214 // write probability if we have exactly one routeRef
215 std::vector<GNEDemandElement*> refs;
216 for (const auto& routeChild : getChildDemandElements()) {
217 if (routeChild->getTagProperty()->getTag() == GNE_TAG_ROUTEREF) {
218 refs.push_back(routeChild);
219 }
220 }
221 if (refs.size() == 1) {
222 device.writeAttr(SUMO_ATTR_PROB, refs.front()->getAttribute(SUMO_ATTR_PROB));
223 }
224 // write sorted stops
226 // write stops
227 for (const auto& routeChild : getChildDemandElements()) {
228 if (routeChild->getTagProperty()->isVehicleStop()) {
229 routeChild->writeDemandElement(device);
230 }
231 }
232 }
233 // write parameters
234 writeParams(device);
235 // close tag
236 device.closeTag();
237}
238
239
242 // get sorted stops and check number
243 std::vector<GNEDemandElement*> stops;
244 for (const auto& routeChild : getChildDemandElements()) {
245 if (routeChild->getTagProperty()->isVehicleStop()) {
246 stops.push_back(routeChild);
247 }
248 }
249 // check stops
250 if (getInvalidStops().size() > 0) {
252 }
253 // check repeating
254 if (myRepeat > 0) {
255 // avoid repeat in routes with only one edge
256 if (getParentEdges().size() == 1) {
258 }
259 // check if front and last routes are connected
260 if (isRouteValid({getParentEdges().back(), getParentEdges().front()}).size() > 0) {
262 }
263 }
264 // check that exist a connection between every edge
265 if (isRouteValid(getParentEdges()).size() > 0) {
267 } else {
268 return Problem::OK;
269 }
271}
272
273
274std::string
276 // get sorted stops and check number
277 std::vector<GNEDemandElement*> stops;
278 for (const auto& routeChild : getChildDemandElements()) {
279 if (routeChild->getTagProperty()->isVehicleStop()) {
280 stops.push_back(routeChild);
281 }
282 }
283 const auto invalidStops = getInvalidStops();
284 if (invalidStops.size() > 0) {
285 return toString(invalidStops.size()) + " stops are outside of route (downstream)";
286 }
287 // check repeating
288 if (myRepeat > 0) {
289 // avoid repeat in routes with only one edge
290 if (getParentEdges().size() == 1) {
291 return TL("Cannot repeat in routes with only one edge");
292 }
293 // check if front and last routes is connected
294 if (isRouteValid({getParentEdges().back(), getParentEdges().front()}).size() > 0) {
295 return TL("Cannot repeat route; front and last edge aren't connected");
296 }
297 }
298 // return string with the problem obtained from isRouteValid
300}
301
302
303void
305 // currently the only solution is removing Route
306}
307
308
312 return getParentDemandElements().at(0)->getVClass();
313 } else {
314 return myVClass;
315 }
316}
317
318
319const RGBColor&
322 return myColor;
323 } else if ((getParentDemandElements().size() > 0) && (getParentDemandElements().front()->getColor() != RGBColor::INVISIBLE)) {
324 return getParentDemandElements().front()->getColor();
325 } else if ((getChildDemandElements().size() > 0) && (getChildDemandElements().front()->getColor() != RGBColor::INVISIBLE)) {
326 return getChildDemandElements().front()->getColor();
327 } else {
328 return RGBColor::YELLOW;
329 }
330}
331
332
333void
335 // compute geometry
337 // update child demand elements
338 for (const auto& demandElement : getChildDemandElements()) {
339 if (!demandElement->getTagProperty()->isVehicleStop()) {
340 demandElement->updateGeometry();
341 }
342 }
343}
344
345
350
351
352std::string
354 return getParentEdges().front()->getID();
355}
356
357
358double
362
363
366 Boundary routeBoundary;
367 // return the combination of all parent edges's boundaries
368 for (const auto& i : getParentEdges()) {
369 routeBoundary.add(i->getCenteringBoundary());
370 }
371 // check if is valid
372 if (routeBoundary.isInitialised()) {
373 return routeBoundary;
374 } else {
375 return Boundary(-0.1, -0.1, 0.1, 0.1);
376 }
377}
378
379
380void
381GNERoute::splitEdgeGeometry(const double /*splitPosition*/, const GNENetworkElement* originalElement, const GNENetworkElement* newElement, GNEUndoList* undoList) {
382 // obtain new list of route edges
383 std::string newRouteEdges = getNewListOfParents(originalElement, newElement);
384 // update route edges
385 if (newRouteEdges.size() > 0) {
386 setAttribute(SUMO_ATTR_EDGES, newRouteEdges, undoList);
387 }
388}
389
390
391void
393 // Routes are drawn in drawLanePartialGL and drawJunctionPartialGL
394}
395
396
397void
399 // calculate path depending if is embedded
404 } else {
406 }
407 // if path is empty, then calculate path again using SVC_IGNORING
408 if (!myNet->getDemandPathManager()->isPathValid(this)) {
410 }
411}
412
413
414void
415GNERoute::drawLanePartialGL(const GUIVisualizationSettings& s, const GNESegment* segment, const double offsetFront) const {
416 // check conditions
421 // get exaggeration
422 const double exaggeration = getExaggeration(s);
423 // get detail level
424 const auto d = s.getDetailLevel(exaggeration);
425 // get embedded route flag
426 const bool embedded = (myTagProperty->getTag() == GNE_TAG_ROUTE_EMBEDDED);
427 // get route width
428 const double routeWidth = embedded ? s.widthSettings.embeddedRouteWidth : s.widthSettings.routeWidth;
429 // calculate startPos
430 const double geometryDepartPos = embedded ? (getParentDemandElements().at(0)->getAttributeDouble(SUMO_ATTR_DEPARTPOS) + getParentDemandElements().at(0)->getParentDemandElements().at(0)->getAttributeDouble(SUMO_ATTR_LENGTH)) : -1;
431 // get endPos
432 const double geometryEndPos = embedded ? getParentDemandElements().at(0)->getAttributeDouble(SUMO_ATTR_ARRIVALPOS) : -1;
433 // declare path geometry
434 GUIGeometry routeGeometry;
435 // update pathGeometry depending of first and last segment
436 if (segment->isFirstSegment() && segment->isLastSegment()) {
437 routeGeometry.updateGeometry(segment->getLane()->getLaneGeometry().getShape(),
438 geometryDepartPos,
440 geometryEndPos,
442 } else if (segment->isFirstSegment()) {
443 routeGeometry.updateGeometry(segment->getLane()->getLaneGeometry().getShape(),
444 geometryDepartPos,
446 -1,
448 } else if (segment->isLastSegment()) {
449 routeGeometry.updateGeometry(segment->getLane()->getLaneGeometry().getShape(),
450 -1,
452 geometryEndPos,
454 } else {
455 routeGeometry = segment->getLane()->getLaneGeometry();
456 }
457 // draw geometry only if we'rent in drawForObjectUnderCursor mode
459 // draw route partial lane
460 drawRoutePartialLane(s, d, segment, offsetFront, routeGeometry, exaggeration);
461 // draw name
464 }
465 // draw dotted contour
466 segment->getContour()->drawDottedContours(s, d, this, s.dottedContourSettings.segmentWidth, true);
467 // show index over every edge
470 const double textSize = s.vehicleName.size / s.scale;
471 std::string label = toString(segment->getLaneIndex());
472 Position pos = segment->getLane()->getLaneShape().front() - Position(0, textSize * 1);
473 // use layer above all demand elements
475 }
476 }
477 // calculate contour
478 segment->getContour()->calculateContourExtrudedShape(s, d, this, routeGeometry.getShape(), getType(), routeWidth, exaggeration,
479 segment->isFirstSegment(), segment->isLastSegment(), 0, segment, segment->getLane()->getParentEdge());
480 // check if add this path element to redraw buffer
483 }
484 }
485}
486
487
488void
489GNERoute::drawJunctionPartialGL(const GUIVisualizationSettings& s, const GNESegment* segment, const double offsetFront) const {
490 // check conditions
495 // Obtain exaggeration of the draw
496 const double routeExaggeration = getExaggeration(s);
497 // get detail level
498 const auto d = s.getDetailLevel(routeExaggeration);
499 // get route width
501 // check if connection to next lane exist
502 const bool connectionExist = segment->getPreviousLane()->getLane2laneConnections().exist(segment->getNextLane());
503 // get geometry
504 const GUIGeometry& routeGeometry = connectionExist ? segment->getPreviousLane()->getLane2laneConnections().getLane2laneGeometry(segment->getNextLane()) :
505 GUIGeometry({segment->getPreviousLane()->getLaneShape().back(), segment->getNextLane()->getLaneShape().front()});
506 // draw geometry only if we'rent in drawForObjectUnderCursor mode
508 // draw route partial
509 drawRoutePartialJunction(s, d, offsetFront, routeGeometry, routeExaggeration);
510 // draw dotted contour
511 segment->getContour()->drawDottedContours(s, d, this, s.dottedContourSettings.segmentWidth, true);
512 }
513 // calculate contour
514 segment->getContour()->calculateContourExtrudedShape(s, d, this, routeGeometry.getShape(), getType(), routeWidth, routeExaggeration,
515 false, false, 0, segment, segment->getJunction());
516 // check if add this path element to redraw buffer
519 }
520 }
521}
522
523
524GNELane*
527 return getParentEdges().front()->getLaneByAllowedVClass(SVC_PASSENGER);
528 } else {
529 return getParentDemandElements().at(0)->getFirstPathLane();
530 }
531}
532
533
534GNELane*
537 return getParentEdges().back()->getLaneByAllowedVClass(SVC_PASSENGER);
538 } else {
539 return getParentDemandElements().at(0)->getLastPathLane();
540 }
541}
542
543
544std::string
546 switch (key) {
547 case SUMO_ATTR_ID:
548 return getMicrosimID();
549 case SUMO_ATTR_EDGES:
550 return parseIDs(getParentEdges());
551 case SUMO_ATTR_COLOR:
553 return toString(myColor);
554 } else {
555 return "";
556 }
557 case SUMO_ATTR_REPEAT:
558 return toString(myRepeat);
560 return time2string(myCycleTime);
561 default:
562 return getCommonAttribute(key);
563 }
564}
565
566
567double
569 switch (key) {
571 return 0;
573 return getParentEdges().back()->getChildLanes().front()->getLaneShape().length2D();
574 default:
575 return getCommonAttributeDouble(key);
576 }
577}
578
579
582 switch (key) {
584 return getParentEdges().front()->getChildLanes().front()->getLaneShape().front();
586 return getParentEdges().back()->getChildLanes().front()->getLaneShape().back();
587 default:
588 return getCommonAttributePosition(key);
589 }
590}
591
592
593void
594GNERoute::setAttribute(SumoXMLAttr key, const std::string& value, GNEUndoList* undoList) {
595 if (value == getAttribute(key)) {
596 return; //avoid needless changes, later logic relies on the fact that attributes have changed
597 }
598 switch (key) {
599 case SUMO_ATTR_ID:
600 case SUMO_ATTR_COLOR:
601 case SUMO_ATTR_REPEAT:
603 GNEChange_Attribute::changeAttribute(this, key, value, undoList);
604 break;
605 // special case due depart and arrival edge vehicles
606 case SUMO_ATTR_EDGES: {
607 // extract all vehicle childrens
608 std::vector<GNEDemandElement*> vehicles;
609 for (const auto& childDemandElement : getChildDemandElements()) {
610 if (childDemandElement->getTagProperty()->isVehicle()) {
611 vehicles.push_back(childDemandElement);
612 }
613 }
614 // check vehicles
615 if (vehicles.size() > 0) {
616 undoList->begin(this, "reset start and end edges");
617 for (const auto& vehicle : vehicles) {
620 }
621 GNEChange_Attribute::changeAttribute(this, key, value, undoList);
622 undoList->end();
624 undoList->begin(this, "reset start and end edges");
627 GNEChange_Attribute::changeAttribute(this, key, value, undoList);
628 undoList->end();
629 } else {
630 // just change edges
631 GNEChange_Attribute::changeAttribute(this, key, value, undoList);
632 }
633 break;
634 }
635 default:
636 setCommonAttribute(key, value, undoList);
637 break;
638 }
639}
640
641
642bool
643GNERoute::isValid(SumoXMLAttr key, const std::string& value) {
644 switch (key) {
645 case SUMO_ATTR_ID:
646 return isValidDemandElementID(value);
647 case SUMO_ATTR_EDGES:
648 if (value.empty()) {
649 return false;
650 } else {
651 return canParse<std::vector<GNEEdge*> >(myNet, value, true);
652 }
653 case SUMO_ATTR_COLOR:
654 if (value.empty()) {
655 return true;
656 } else {
657 return canParse<RGBColor>(value);
658 }
659 case SUMO_ATTR_REPEAT:
660 return canParse<int>(value) && (parse<int>(value) >= 0);
662 if (canParse<SUMOTime>(value)) {
663 return (parse<SUMOTime>(value) >= 0);
664 } else {
665 return false;
666 }
667 default:
668 return isCommonAttributeValid(key, value);
669 }
670}
671
672
673std::string
675 return getTagStr();
676}
677
678
679std::string
681 return getTagStr() + ": " + getAttribute(SUMO_ATTR_ID) ;
682}
683
684
685std::string
686GNERoute::isRouteValid(const std::vector<GNEEdge*>& edges) {
687 if (edges.size() == 0) {
688 // routes cannot be empty
689 return ("list of route edges cannot be empty");
690 } else if (edges.size() == 1) {
691 // routes with a single edge are valid, then return an empty string
692 return ("");
693 } else {
694 // iterate over edges to check that compounds a chain
695 auto it = edges.begin();
696 while (it != edges.end() - 1) {
697 const GNEEdge* currentEdge = *it;
698 const GNEEdge* nextEdge = *(it + 1);
699 // same consecutive edges aren't allowed
700 if (currentEdge->getID() == nextEdge->getID()) {
701 return ("consecutive duplicated edges (" + currentEdge->getID() + ") aren't allowed in a route");
702 }
703 // obtain outgoing edges of currentEdge
704 const std::vector<GNEEdge*>& outgoingEdges = currentEdge->getToJunction()->getGNEOutgoingEdges();
705 // check if nextEdge is in outgoingEdges
706 if (std::find(outgoingEdges.begin(), outgoingEdges.end(), nextEdge) == outgoingEdges.end()) {
707 return ("Edges '" + currentEdge->getID() + "' and '" + nextEdge->getID() + "' aren't consecutives");
708 }
709 it++;
710 }
711 // all edges consecutives, then return an empty string
712 return ("");
713 }
714}
715
717GNERoute::copyRoute(const GNERoute* originalRoute) {
718 // get net and undoList
719 const auto net = originalRoute->getNet();
720 auto undoList = net->getViewNet()->getUndoList();
721 // generate new route ID
722 const std::string newRouteID = net->getAttributeCarriers()->generateDemandElementID(SUMO_TAG_ROUTE);
723 // create new route
724 GNERoute* newRoute = new GNERoute(newRouteID, originalRoute);
725 // add new route using undo-list
726 undoList->begin(originalRoute, TLF("copy % '%'", originalRoute->getTagStr(), newRouteID));
727 net->getViewNet()->getUndoList()->add(new GNEChange_DemandElement(newRoute, true), true);
728 undoList->end();
729 // return new route
730 return newRoute;
731}
732
733// ===========================================================================
734// private
735// ===========================================================================
736
737void
739 const GNESegment* segment, const double offsetFront,
740 const GUIGeometry& geometry, const double exaggeration) const {
741 // get route width
743 // push layer matrix
745 // Start with the drawing of the area traslating matrix to origin
746 glTranslated(0, 0, getType() + offsetFront);
747 // Set color
748 if (drawUsingSelectColor()) {
750 } else {
752 }
753 // draw geometry
754 GUIGeometry::drawGeometry(d, geometry, routeWidth * exaggeration);
755 // check if we have to draw a red line to the next segment
756 if (segment->getNextLane()) {
757 // push draw matrix
759 // Set red color
761 // get firstPosition (last position of current lane shape)
762 const Position firstPosition = segment->getLane()->getLaneShape().back();
763 // get lastPosition (first position of next lane shape)
764 const Position arrivalPos = segment->getNextLane()->getLaneShape().front();
765 // draw box line
766 GLHelper::drawBoxLine(arrivalPos,
767 RAD2DEG(firstPosition.angleTo2D(arrivalPos)) - 90,
768 firstPosition.distanceTo2D(arrivalPos), .05);
769 // pop draw matrix
771 }
772 // Pop layer matrix
774}
775
776
777void
779 const double offsetFront, const GUIGeometry& geometry, const double exaggeration) const {
780 const bool invalid = geometry.getShape().length() == 2;
781 // get route width
783 // Add a draw matrix
785 // Start with the drawing of the area traslating matrix to origin
786 glTranslated(0, 0, getType() + offsetFront);
787 // Set color of the base
788 if (drawUsingSelectColor()) {
790 } else if (invalid) {
792 } else {
794 }
795 // draw geometry
796 GUIGeometry::drawGeometry(d, geometry, routeWidth * exaggeration);
797 // Pop last matrix
799}
800
801
802void
803GNERoute::setAttribute(SumoXMLAttr key, const std::string& value) {
804 switch (key) {
805 case SUMO_ATTR_ID:
806 // update microsimID
807 setDemandElementID(value);
808 break;
809 case SUMO_ATTR_EDGES:
810 // replace parents
811 replaceParentEdges(value);
812 // compute route
814 // update all parent and child demand elements
815 for (const auto& element : getParentDemandElements()) {
816 element->updateGeometry();
817 }
818 for (const auto& element : getChildDemandElements()) {
819 element->updateGeometry();
820 }
821 break;
822 case SUMO_ATTR_COLOR:
823 if (value.empty()) {
825 } else {
826 myColor = parse<RGBColor>(value);
827 }
828 break;
829 case SUMO_ATTR_REPEAT:
830 if (value.empty()) {
832 } else {
833 myRepeat = parse<int>(value);
834 }
835 break;
837 if (value.empty()) {
839 } else {
840 myCycleTime = string2time(value);
841 }
842 break;
843 default:
844 setCommonAttribute(key, value);
845 break;
846 }
847}
848
849
850bool
853 // this affect only to embedded routes
854 return true;
856 // only in demand mode
857 return true;
859 // only creating vehicles
860 return true;
861 } else {
862 // get current template AC
864 if (templateAC && templateAC->getTagProperty()->vehicleRoute()) {
865 // we're creating a vehicle over a route, then hidde all embedded routes
866 return false;
867 } else {
868 return true;
869 }
870 }
871}
872
873
874/****************************************************************************/
FXDEFMAP(GNERoute::GNERoutePopupMenu) GNERoutePopupMenuMap[]
@ DEMAND_VEHICLE
Mode for editing vehicles.
long long int SUMOTime
Definition GUI.h:36
@ MID_OPEN_ADDITIONAL_DIALOG
open additional dialog (used in netedit)
Definition GUIAppEnum.h:471
@ MID_GNE_ROUTE_APPLY_DISTANCE
apply distance
@ GLO_VEHICLELABELS
stack and flow labels (used in netedit)
GUIViewObjectsHandler gViewObjectsHandler
#define RAD2DEG(x)
Definition GeomHelper.h:36
#define TL(string)
Definition MsgHandler.h:304
#define TLF(string,...)
Definition MsgHandler.h:306
SUMOTime string2time(const std::string &r)
convert string to SUMOTime
Definition SUMOTime.cpp:46
std::string time2string(SUMOTime t, bool humanReadable)
convert SUMOTime to string (independently of global format setting)
Definition SUMOTime.cpp:91
SUMOVehicleClass
Definition of vehicle classes to differ between different lane usage and authority types.
@ SVC_IGNORING
vehicles ignoring classes
@ SVC_PASSENGER
vehicle is a passenger car (a "normal" car)
SumoXMLTag
Numbers representing SUMO-XML - element names.
@ SUMO_TAG_ROUTE
description of a route
@ GNE_TAG_ROUTEREF
virtual element used to reference routes with distributions
@ GNE_TAG_ROUTE_EMBEDDED
embedded route
SumoXMLAttr
Numbers representing SUMO-XML - attributes.
@ SUMO_ATTR_ARRIVALLANE
@ SUMO_ATTR_DEPARTEDGE
@ SUMO_ATTR_ARRIVALEDGE
@ SUMO_ATTR_ARRIVALPOS
@ SUMO_ATTR_EDGES
the edges of a route
@ SUMO_ATTR_DEPARTPOS
@ SUMO_ATTR_DEPARTLANE
@ SUMO_ATTR_DISTANCE
@ SUMO_ATTR_PROB
@ SUMO_ATTR_LENGTH
@ SUMO_ATTR_COLOR
A color information.
@ SUMO_ATTR_ID
@ SUMO_ATTR_REPEAT
@ SUMO_ATTR_CYCLETIME
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
Definition ToString.h:46
A class that stores a 2D geometrical boundary.
Definition Boundary.h:39
void add(double x, double y, double z=0)
Makes the boundary include the given coordinate.
Definition Boundary.cpp:75
bool isInitialised() const
check if Boundary is Initialised
Definition Boundary.cpp:256
static void setColor(const RGBColor &c)
Sets the gl-color to this value.
Definition GLHelper.cpp:649
static void popMatrix()
pop matrix
Definition GLHelper.cpp:131
static void drawBoxLine(const Position &beg, double rot, double visLength, double width, double offset=0)
Draws a thick line.
Definition GLHelper.cpp:296
static void pushMatrix()
push matrix
Definition GLHelper.cpp:118
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:773
const std::string getID() const
get ID (all Attribute Carriers have one)
bool isAttributeCarrierSelected() const
check if attribute carrier is selected
double getCommonAttributeDouble(SumoXMLAttr key) const
FXIcon * getACIcon() const
get FXIcon associated to this AC
bool mySelected
boolean to check if this AC is selected (more quickly as checking GUIGlObjectStorage)
void setCommonAttribute(SumoXMLAttr key, const std::string &value, GNEUndoList *undoList)
const std::string & getTagStr() const
get tag assigned to this object in string format
bool drawUsingSelectColor() const
check if attribute carrier must be drawn using selecting color.
Position getCommonAttributePosition(SumoXMLAttr key) const
GNENet * myNet
pointer to net
GNENet * getNet() const
get pointer to net
static std::string parseIDs(const std::vector< T > &ACs)
parses a list of specific Attribute Carriers into a string of IDs
bool isCommonAttributeValid(SumoXMLAttr key, const std::string &value) const
virtual std::string getAttribute(SumoXMLAttr key) const =0
std::string getCommonAttribute(SumoXMLAttr key) const
const GNETagProperties * myTagProperty
reference to tagProperty associated with this attribute carrier
static void changeAttribute(GNEAttributeCarrier *AC, SumoXMLAttr key, const std::string &value, GNEUndoList *undoList, const bool force=false)
change attribute
void calculateContourExtrudedShape(const GUIVisualizationSettings &s, const GUIVisualizationSettings::Detail d, const GUIGlObject *glObject, const PositionVector &shape, const double layer, const double extrusionWidth, const double scale, const bool closeFirstExtrem, const bool closeLastExtrem, const double offset, const GNESegment *segment, const GUIGlObject *boundaryParent, const bool addToSelectedObjects=true) const
calculate contour extruded (used in elements formed by a central shape)
bool drawDottedContours(const GUIVisualizationSettings &s, const GUIVisualizationSettings::Detail d, const GNEAttributeCarrier *AC, const double lineWidth, const bool addOffset) const
draw dotted contours (basics, select, delete, inspect...)
bool checkDrawPathContour(const GUIVisualizationSettings &s, const GUIVisualizationSettings::Detail d, const GNEAttributeCarrier *AC) const
drawing contour functions
void buildMenuCommandRouteLength(GUIGLObjectPopupMenu *ret) const
build menu command route length
std::vector< GNEDemandElement * > getInvalidStops() const
get invalid stops
bool isValidDemandElementID(const std::string &value) const
check if a new demand element ID is valid
void setDemandElementID(const std::string &newID)
set demand element id
void buildMenuAddReverse(GUIGLObjectPopupMenu *ret) const
build menu command route length
void replaceParentEdges(const std::string &value)
all edges
Problem
enum class for demandElement problems
GNEJunction * getToJunction() const
get from Junction (only used to increase readability)
Definition GNEEdge.h:92
const GNEHierarchicalContainerParents< GNEDemandElement * > & getParentDemandElements() const
get parent demand elements
const GNEHierarchicalContainerParents< GNEEdge * > & getParentEdges() const
get parent edges
const GNEHierarchicalContainerParents< GNELane * > & getParentLanes() const
get parent lanes
const GNEHierarchicalContainerChildren< GNEDemandElement * > & getChildDemandElements() const
return child demand elements
std::string getNewListOfParents(const GNENetworkElement *currentElement, const GNENetworkElement *newNextElement) const
if use edge/parent lanes as a list of consecutive elements, obtain a list of IDs of elements after in...
const std::vector< GNEEdge * > & getGNEOutgoingEdges() const
Returns incoming GNEEdges.
bool exist(const GNELane *toLane) const
check if exist a lane2lane geometry for the given toLane
const GUIGeometry & getLane2laneGeometry(const GNELane *toLane) const
get lane2lane geometry
const PositionVector & getLaneShape() const
get elements shape
Definition GNELane.cpp:232
const GNELane2laneConnection & getLane2laneConnections() const
get Lane2laneConnection struct
Definition GNELane.cpp:666
Position getPositionInView() const
Returns position of hierarchical element in view.
Definition GNELane.cpp:337
const GUIGeometry & getLaneGeometry() const
get lane geometry
Definition GNELane.cpp:226
GNEEdge * getParentEdge() const
get parent edge
Definition GNELane.cpp:214
A NBNetBuilder extended by visualisation and editing capabilities.
Definition GNENet.h:42
GNEPathManager * getDemandPathManager()
get demand path manager
Definition GNENet.cpp:174
GNEViewNet * getViewNet() const
get view net
Definition GNENet.cpp:2193
bool checkDrawPathGeometry(const GUIVisualizationSettings &s, const GNELane *lane, const SumoXMLTag tag, const bool isPlan)
check if path element geometry must be drawn in the given lane
PathDraw * getPathDraw()
obtain instance of PathDraw
bool isPathValid(const GNEPathElement *pathElement) const
check if path element is valid
void calculateConsecutivePathEdges(GNEPathElement *pathElement, SUMOVehicleClass vClass, const std::vector< GNEEdge * > &edges, const int firstLaneIndex=-1, const int lastLaneIndex=-1)
calculate consecutive path edges
class used in GUIGLObjectPopupMenu for routes
Definition GNERoute.h:42
~GNERoutePopupMenu()
Destructor.
Definition GNERoute.cpp:57
long onCmdApplyDistance(FXObject *, FXSelector, void *)
Called to modify edge distance values along the route.
Definition GNERoute.cpp:61
bool isValid(SumoXMLAttr key, const std::string &value) override
Definition GNERoute.cpp:643
GNEMoveElement * getMoveElement() const override
methods to retrieve the elements linked to this route
Definition GNERoute.cpp:156
void fixDemandElementProblem()
fix demand element problem (by default throw an exception, has to be reimplemented in children)
Definition GNERoute.cpp:304
std::string getAttribute(SumoXMLAttr key) const override
inherited from GNEAttributeCarrier
Definition GNERoute.cpp:545
double getExaggeration(const GUIVisualizationSettings &s) const
return exaggeration associated with this GLObject
Definition GNERoute.cpp:359
GNELane * getLastPathLane() const
get last path lane
Definition GNERoute.cpp:535
Position getPositionInView() const
Returns position of additional in view.
Definition GNERoute.cpp:347
SUMOVehicleClass myVClass
SUMOVehicleClass (Only used for drawing)
Definition GNERoute.h:278
bool checkCreatingVehicleOverRoute() const
check if we're creating a vehicle or flow over route
Definition GNERoute.cpp:851
void drawJunctionPartialGL(const GUIVisualizationSettings &s, const GNESegment *segment, const double offsetFront) const
Draws partial object over junction.
Definition GNERoute.cpp:489
std::string getParentName() const
Returns the name of the parent object.
Definition GNERoute.cpp:353
double getAttributeDouble(SumoXMLAttr key) const override
Definition GNERoute.cpp:568
SUMOTime myCycleTime
cycleTime
Definition GNERoute.h:275
std::string getHierarchyName() const override
get Hierarchy Name (Used in AC Hierarchy)
Definition GNERoute.cpp:680
void updateGeometry() override
update pre-computed geometry information
Definition GNERoute.cpp:334
Parameterised * getParameters() override
get parameters associated with this route
Definition GNERoute.cpp:162
GUIGLObjectPopupMenu * getPopUpMenu(GUIMainWindow &app, GUISUMOAbstractView &parent)
Returns an own popup-menu.
Definition GNERoute.cpp:174
void drawRoutePartialJunction(const GUIVisualizationSettings &s, const GUIVisualizationSettings::Detail d, const double offsetFront, const GUIGeometry &geometry, const double exaggeration) const
draw route partial junction
Definition GNERoute.cpp:778
void splitEdgeGeometry(const double splitPosition, const GNENetworkElement *originalElement, const GNENetworkElement *newElement, GNEUndoList *undoList)
split geometry
Definition GNERoute.cpp:381
static GNEDemandElement * copyRoute(const GNERoute *originalRoute)
create a copy of the given route
Definition GNERoute.cpp:717
GNELane * getFirstPathLane() const
get first path lane
Definition GNERoute.cpp:525
Position getAttributePosition(SumoXMLAttr key) const override
Definition GNERoute.cpp:581
std::string getPopUpID() const override
get PopPup ID (Used in AC Hierarchy)
Definition GNERoute.cpp:674
SUMOVehicleClass getVClass() const
obtain VClass related with this demand element
Definition GNERoute.cpp:310
void drawRoutePartialLane(const GUIVisualizationSettings &s, const GUIVisualizationSettings::Detail d, const GNESegment *segment, const double offsetFront, const GUIGeometry &geometry, const double exaggeration) const
draw route partial lane
Definition GNERoute.cpp:738
GNERoute(SumoXMLTag tag, GNENet *net)
default constructor
Definition GNERoute.cpp:78
Boundary getCenteringBoundary() const
Returns the boundary to which the view shall be centered in order to show the object.
Definition GNERoute.cpp:365
void drawGL(const GUIVisualizationSettings &s) const
Draws the object.
Definition GNERoute.cpp:392
static std::string isRouteValid(const std::vector< GNEEdge * > &edges)
check if a route is valid
Definition GNERoute.cpp:686
int myRepeat
repeat
Definition GNERoute.h:272
void computePathElement()
compute pathElement
Definition GNERoute.cpp:398
void drawLanePartialGL(const GUIVisualizationSettings &s, const GNESegment *segment, const double offsetFront) const
Draws partial object over lane.
Definition GNERoute.cpp:415
std::string getDemandElementProblem() const
return a string with the current demand element problem (by default empty, can be reimplemented in ch...
Definition GNERoute.cpp:275
RGBColor myColor
route color
Definition GNERoute.h:269
void writeDemandElement(OutputDevice &device) const
write demand element element into a xml file
Definition GNERoute.cpp:198
~GNERoute()
destructor
Definition GNERoute.cpp:153
void setAttribute(SumoXMLAttr key, const std::string &value, GNEUndoList *undoList) override
Definition GNERoute.cpp:594
const RGBColor & getColor() const
get color
Definition GNERoute.cpp:320
Problem isDemandElementValid() const
check if current demand element is valid to be written into XML (by default true, can be reimplemente...
Definition GNERoute.cpp:241
const GNELane * getLane() const
get lane associated with this segment
const GNEJunction * getJunction() const
get junction associated with this segment
const GNELane * getNextLane() const
get next lane
const GNELane * getPreviousLane() const
get previous lane
bool isFirstSegment() const
check if segment is the first path's segment
GNEContour * getContour() const
int getLaneIndex() const
get lane index
bool isLastSegment() const
check if segment is the last path's segment
const RGBColor & getDefaultColorValue(SumoXMLAttr attr) const
get default bool value
double getDefaultDoubleValue(SumoXMLAttr attr) const
get default double value
SUMOTime getDefaultTimeValue(SumoXMLAttr attr) const
get default time value
SumoXMLTag getTag() const
get Tag vinculated with this attribute Property
bool hasDialog() const
return true if tag correspond to an element that can be edited using a dialog
int getDefaultIntValue(SumoXMLAttr attr) const
get default int value
GNEAttributeCarrier * getCurrentTemplateAC() const
get current templateAC
void end()
End undo command sub-group. If the sub-group is still empty, it will be deleted; otherwise,...
void begin(GUIIcon icon, const std::string &description)
Begin undo command sub-group with current supermode. This begins a new group of commands that are tre...
GNETagSelector * getVehicleTagSelector() const
get vehicle tag selector (needed for transform vehicles)
bool isACInspected(GNEAttributeCarrier *AC) const
const GNEViewNetHelper::DataViewOptions & getDataViewOptions() const
get data view options
const GNEViewNetHelper::EditModes & getEditModes() const
get edit modes
GNEViewNetHelper::InspectedElements & getInspectedElements()
get inspected elements
const GNEViewNetHelper::NetworkViewOptions & getNetworkViewOptions() const
get network view options
GNEViewParent * getViewParent() const
get the net object
GNEUndoList * getUndoList() const
get the undoList object
const GNEViewNetHelper::DemandViewOptions & getDemandViewOptions() const
get demand view options
GNEVehicleFrame * getVehicleFrame() const
get frame for DEMAND_VEHICLE
static FXMenuCommand * buildFXMenuCommand(FXComposite *p, const std::string &text, FXIcon *icon, FXObject *tgt, FXSelector sel, const bool disable=false)
build menu command
The popup menu of a globject.
static void drawGeometry(const GUIVisualizationSettings::Detail d, const GUIGeometry &geometry, const double width, double offset=0)
draw geometry
const PositionVector & getShape() const
The shape of the additional element.
void updateGeometry(const PositionVector &shape)
update entire geometry
const std::string & getMicrosimID() const
Returns the id of the object as known to microsim.
GUIGlObjectType getType() const
Returns the type of the object as coded in GUIGlObjectType.
void buildPopUpMenuCommonOptions(GUIGLObjectPopupMenu *ret, GUIMainWindow &app, GUISUMOAbstractView *parent, const SumoXMLTag tag, const bool selected, bool addSeparator=true)
virtual Position getCenter() const
void drawName(const Position &pos, const double scale, const GUIVisualizationTextSettings &settings, const double angle=0, bool forceShow=false) const
draw name of item
void addToRedrawPathElements(const GNEPathElement *pathElement)
add path element to redrawing set
bool isPathElementMarkForRedraw(const GNEPathElement *pathElement) const
check if the given path element has to be redraw again
Stores the information about how to visualize structures.
GUIVisualizationTextSettings addName
GUIVisualizationTextSettings vehicleName
GUIVisualizationSizeSettings vehicleSize
GUIVisualizationWidthSettings widthSettings
width settings
bool checkDrawVehicle(Detail d, const bool selected) const
check if draw vehicle
Detail getDetailLevel(const double exaggeration) const
return the detail level
GUIVisualizationColorSettings colorSettings
color settings
GUIVisualizationDottedContourSettings dottedContourSettings
dotted contour settings
double scale
information about a lane's width (temporary, used for a single view)
bool showRouteIndex
Information whether the route index should be shown.
double angle
The current view rotation angle.
Static storage of an output device and its base (abstract) implementation.
OutputDevice & writeAttr(const SumoXMLAttr attr, const T &val)
writes a named attribute
OutputDevice & openTag(const std::string &xmlElement)
Opens an XML tag.
bool closeTag(const std::string &comment="")
Closes the most recently opened tag and optionally adds a comment.
An upper class for objects with additional parameters.
std::map< std::string, std::string > Map
parameters map
void writeParams(OutputDevice &device) const
write Params in the given outputdevice
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:323
double distanceTo2D(const Position &p2) const
returns the euclidean distance in the x-y-plane
Definition Position.h:273
double angleTo2D(const Position &other) const
returns the angle in the plane of the vector pointing from here to the other position (in radians bet...
Definition Position.h:283
double length() const
Returns the length.
static const RGBColor YELLOW
Definition RGBColor.h:191
static const RGBColor INVISIBLE
Definition RGBColor.h:198
static const RGBColor RED
named colors
Definition RGBColor.h:188
bool showDemandElements() const
check if show demand elements checkbox is enabled
bool showNonInspectedDemandElements(const GNEDemandElement *demandElement) const
check if non inspected element has to be hidden
DemandEditMode demandEditMode
the current Demand edit mode
bool isCurrentSupermodeDemand() const
@check if current supermode is Demand
bool showDemandElements() const
check if show demand elements checkbox is enabled
RGBColor selectedRouteColor
route selection color (used for routes and vehicle stops)
RGBColor selectedAdditionalColor
additional selection color (busStops, Detectors...)
static const double segmentWidth
width of dotted contour segments
double getExaggeration(const GUIVisualizationSettings &s, const GUIGlObject *o, double factor=20) const
return the drawing size including exaggeration and constantSize values
static const double embeddedRouteWidth
width for embeddedroutes
static const double routeWidth
width for routes