Eclipse SUMO - Simulation of Urban MObility
Loading...
Searching...
No Matches
GNEPathCreator.cpp
Go to the documentation of this file.
1/****************************************************************************/
2// Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo
3// Copyright (C) 2001-2023 German Aerospace Center (DLR) and others.
4// This program and the accompanying materials are made available under the
5// terms of the Eclipse Public License 2.0 which is available at
6// https://www.eclipse.org/legal/epl-2.0/
7// This Source Code may also be made available under the following Secondary
8// Licenses when the conditions for such availability set forth in the Eclipse
9// Public License 2.0 are satisfied: GNU General Public License, version 2
10// or later which is available at
11// https://www.gnu.org/licenses/old-licenses/gpl-2.0-standalone.html
12// SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-or-later
13/****************************************************************************/
18// Frame for create paths
19/****************************************************************************/
20#include <config.h>
21
23#include <netedit/GNENet.h>
24#include <netedit/GNEViewNet.h>
31
32#include "GNEPathCreator.h"
33
34
35// ===========================================================================
36// FOX callback mapping
37// ===========================================================================
38
47
48// Object implementation
49FXIMPLEMENT(GNEPathCreator, MFXGroupBoxModule, PathCreatorMap, ARRAYNUMBER(PathCreatorMap))
50
51
52// ===========================================================================
53// method definitions
54// ===========================================================================
55
57 mySubPath({edge}),
58 myFromBusStop(nullptr),
59 myToBusStop(nullptr),
60 myConflictVClass(false),
61myConflictDisconnected(false) {
62 // check if we have to change vClass flag
63 if (edge->getNBEdge()->getNumLanesThatAllow(vClass) == 0) {
64 myConflictVClass = true;
65 }
66}
67
68
69GNEPathCreator::Path::Path(GNEViewNet* viewNet, const SUMOVehicleClass vClass, GNEEdge* edgeFrom, GNEEdge* edgeTo) :
70 myFromBusStop(nullptr),
71 myToBusStop(nullptr),
72 myConflictVClass(false),
73 myConflictDisconnected(false) {
74 // calculate subpath
75 mySubPath = viewNet->getNet()->getPathManager()->getPathCalculator()->calculateDijkstraPath(vClass, {edgeFrom, edgeTo});
76 // if subPath is empty, try it with pedestrian (i.e. ignoring vCass)
77 if (mySubPath.empty()) {
79 if (mySubPath.empty()) {
80 mySubPath = { edgeFrom, edgeTo };
82 } else {
83 myConflictVClass = true;
84 }
85 }
86}
87
88
89GNEPathCreator::Path::Path(GNEViewNet* viewNet, const SUMOVehicleClass vClass, GNEJunction* junctionFrom, GNEJunction* junctionTo) :
90 myFromBusStop(nullptr),
91 myToBusStop(nullptr),
92 myConflictVClass(false),
93 myConflictDisconnected(false) {
94 // calculate subpath
95 mySubPath = viewNet->getNet()->getPathManager()->getPathCalculator()->calculateDijkstraPath(vClass, junctionFrom, junctionTo);
96 // if subPath is empty, try it with pedestrian (i.e. ignoring vCass)
97 if (mySubPath.empty()) {
98 mySubPath = viewNet->getNet()->getPathManager()->getPathCalculator()->calculateDijkstraPath(SVC_PEDESTRIAN, junctionFrom, junctionTo);
99 if (mySubPath.empty()) {
101 } else {
102 myConflictVClass = true;
103 }
104 }
105}
106
107
108const std::vector<GNEEdge*>&
110 return mySubPath;
111}
112
113
115 return myFromBusStop;
116}
117
118
120 return myToBusStop;
121}
122
123
124bool
126 return myConflictVClass;
127}
128
129
130bool
132 return myConflictDisconnected;
133}
134
135
137 myFromBusStop(nullptr),
138 myToBusStop(nullptr),
139 myConflictVClass(false),
140 myConflictDisconnected(false) {
141}
142
143
145 MFXGroupBoxModule(frameParent, TL("Route creator")),
146 myFrameParent(frameParent),
149 myToStoppingPlace(nullptr),
150 myRoute(nullptr) {
151 // create label for route info
152 myInfoRouteLabel = new FXLabel(getCollapsableFrame(), TL("No edges selected"), 0, GUIDesignLabelFrameInformation);
153 // create button for use last route
155 myUseLastRoute->disable();
156 // create button for finish route creation
157 myFinishCreationButton = new FXButton(getCollapsableFrame(), TL("Finish route creation"), nullptr, this, MID_GNE_PATHCREATOR_FINISH, GUIDesignButton);
158 myFinishCreationButton->disable();
159 // create button for abort route creation
160 myAbortCreationButton = new FXButton(getCollapsableFrame(), TL("Abort route creation"), nullptr, this, MID_GNE_PATHCREATOR_ABORT, GUIDesignButton);
161 myAbortCreationButton->disable();
162 // create button for remove last inserted edge
163 myRemoveLastInsertedElement = new FXButton(getCollapsableFrame(), TL("Remove last edge"), nullptr, this, MID_GNE_PATHCREATOR_REMOVELAST, GUIDesignButton);
165 // create check button
166 myShowCandidateEdges = new FXCheckButton(getCollapsableFrame(), TL("Show candidate edges"), this, MID_GNE_PATHCREATOR_SHOWCANDIDATES, GUIDesignCheckButton);
167 myShowCandidateEdges->setCheck(TRUE);
168 // create shift label
169 myShiftLabel = new FXLabel(this,
170 "SHIFT-click: ignore vClass",
172 // create control label
173 myControlLabel = new FXLabel(this,
174 "CTRL-click: force add",
176 // create backspace label (always shown)
177 myBackSpaceLabel = new FXLabel(this,
178 "BACKSPACE: undo click",
180}
181
182
184
185
186void
187GNEPathCreator::showPathCreatorModule(SumoXMLTag element, const bool firstElement, const bool consecutives) {
188 // declare flag
189 bool showPathCreator = true;
190 // first abort creation
192 // hide use last inserted route
193 myUseLastRoute->hide();
194 // disable buttons
195 myFinishCreationButton->disable();
196 myAbortCreationButton->disable();
198 // show info label
199 myInfoRouteLabel->show();
200 myShowCandidateEdges->show();
201 myShiftLabel->show();
202 myControlLabel->show();
203 myBackSpaceLabel->show();
204 // reset creation mode
205 myCreationMode = 0;
206 // set first element
207 if (firstElement) {
209 }
210 // set consecutive or non consecuives
211 if (consecutives) {
213 } else {
215 }
216 // set specific mode depending of tag
217 switch (element) {
218 // routes
219 case SUMO_TAG_ROUTE:
224 break;
225 // vehicles
226 case SUMO_TAG_VEHICLE:
230 // show use last inserted route
231 myUseLastRoute->show();
232 // disable other elements
234 myAbortCreationButton->hide();
236 myInfoRouteLabel->hide();
237 myShowCandidateEdges->hide();
238 myShiftLabel->hide();
239 myControlLabel->hide();
240 myBackSpaceLabel->hide();
241 break;
242 case SUMO_TAG_TRIP:
243 case SUMO_TAG_FLOW:
249 break;
256 break;
262 break;
263 // edges
269 break;
270 // edge->edge
280 break;
281 // edge->busStop
289 break;
290 // edge->trainStop
298 break;
299 // edge->containerStop
306 break;
307 // junction->junction
314 break;
315 // stops (person and containers)
319 break;
323 break;
327 break;
332 break;
333 // generic datas
334 case SUMO_TAG_EDGEREL:
338 break;
339 default:
340 showPathCreator = false;
341 break;
342 }
343 // update colors
346 // check if show path creator
347 if (showPathCreator) {
348 // recalc before show (to avoid graphic problems)
349 recalc();
350 // show modul
351 show();
352 } else {
353 // hide modul
354 hide();
355 }
356}
357
358
359void
361 // clear path
362 clearPath();
363 // hide modul
364 hide();
365}
366
367
370 return myVClass;
371}
372
373
374void
376 myVClass = vClass;
377 // update edge colors
379}
380
381
382bool
384 // check if junctions are allowed
385 if (((myCreationMode & START_JUNCTION) == 0) && ((myCreationMode & END_JUNCTION) == 0)) {
386 return false;
387 }
388 // continue depending of number of selected edge
389 if (mySelectedJunctions.size() > 0) {
390 // check double junctions
391 if (mySelectedJunctions.back() == junction) {
392 // Write warning
393 WRITE_WARNING(TL("Double junctions aren't allowed"));
394 // abort add junction
395 return false;
396 }
397 }
398 // check number of junctions
400 // Write warning
401 WRITE_WARNING(TL("Only two junctions are allowed"));
402 // abort add junction
403 return false;
404 }
405 // All checks ok, then add it in selected elements
406 mySelectedJunctions.push_back(junction);
407 // enable abort route button
408 myAbortCreationButton->enable();
409 // enable finish button
410 myFinishCreationButton->enable();
411 // disable undo/redo
413 // enable or disable remove last junction button
414 if (mySelectedJunctions.size() > 1) {
416 } else {
418 }
419 // recalculate path
421 // update info route label
423 // update junction colors
425 return true;
426}
427
428
429bool
431 // check if TAZs are allowed
432 if (((myCreationMode & START_TAZ) == 0) && ((myCreationMode & END_TAZ) == 0)) {
433 return false;
434 }
435 // continue depending of number of selected edge
436 if (mySelectedTAZs.size() > 0) {
437 // check double TAZs
438 if (mySelectedTAZs.back() == TAZ) {
439 // Write warning
440 WRITE_WARNING(TL("Double TAZs aren't allowed"));
441 // abort add TAZ
442 return false;
443 }
444 }
445 // check number of TAZs
446 if (mySelectedTAZs.size() == 2 && (myCreationMode & Mode::ONLY_FROMTO)) {
447 // Write warning
448 WRITE_WARNING(TL("Only two TAZs are allowed"));
449 // abort add TAZ
450 return false;
451 }
452 // All checks ok, then add it in selected elements
453 mySelectedTAZs.push_back(TAZ);
454 // enable abort route button
455 myAbortCreationButton->enable();
456 // enable finish button
457 myFinishCreationButton->enable();
458 // disable undo/redo
460 // enable or disable remove last TAZ button
461 if (mySelectedTAZs.size() > 1) {
463 } else {
465 }
466 // update info route label
468 return true;
469}
470
471
472bool
473GNEPathCreator::addEdge(GNEEdge* edge, const bool shiftKeyPressed, const bool controlKeyPressed) {
474 // check if edges are allowed
475 if (((myCreationMode & START_EDGE) == 0) && ((myCreationMode & END_EDGE) == 0)) {
476 return false;
477 }
478 // continue depending of number of selected eges
479 if (mySelectedEdges.size() > 0) {
480 // check double edges
481 if (mySelectedEdges.back() == edge) {
482 // Write warning
483 WRITE_WARNING(TL("Double edges aren't allowed"));
484 // abort add edge
485 return false;
486 }
487 // check consecutive edges
489 // check that new edge is consecutive
490 const auto& outgoingEdges = mySelectedEdges.back()->getToJunction()->getGNEOutgoingEdges();
491 if (std::find(outgoingEdges.begin(), outgoingEdges.end(), edge) == outgoingEdges.end()) {
492 // Write warning
493 WRITE_WARNING(TL("Only consecutives edges are allowed"));
494 // abort add edge
495 return false;
496 }
497 }
498 }
499 // check number of edges
500 if (mySelectedEdges.size() == 2 && (myCreationMode & Mode::ONLY_FROMTO)) {
501 // Write warning
502 WRITE_WARNING(TL("Only two edges are allowed"));
503 // abort add edge
504 return false;
505 }
506 // check candidate edge
507 if ((myShowCandidateEdges->getCheck() == TRUE) && !edge->isPossibleCandidate()) {
508 if (edge->isSpecialCandidate()) {
509 if (!shiftKeyPressed) {
510 // Write warning
511 WRITE_WARNING(TL("Invalid edge (SHIFT + click to add an invalid vClass edge)"));
512 // abort add edge
513 return false;
514 }
515 } else if (edge->isConflictedCandidate()) {
516 if (!controlKeyPressed) {
517 // Write warning
518 WRITE_WARNING(TL("Invalid edge (CONTROL + click to add a disconnected edge)"));
519 // abort add edge
520 return false;
521 }
522 }
523 }
524 // All checks ok, then add it in selected elements
525 mySelectedEdges.push_back(edge);
526 // enable abort route button
527 myAbortCreationButton->enable();
528 // enable finish button
529 myFinishCreationButton->enable();
530 // disable undo/redo
532 // enable or disable remove last edge button
533 if (mySelectedEdges.size() > 1) {
535 } else {
537 }
538 // recalculate path
540 // update info route label
542 // update edge colors
544 // if is a stop, create inmediately
545 if (myCreationMode & STOP) {
546 if (createPath(false)) {
547 return true;
548 } else {
549 mySelectedEdges.pop_back();
550 // recalculate path again
552 // update info route label
554 // update edge colors
556 return false;
557 }
558 } else {
559 return true;
560 }
561}
562
563
564const std::vector<GNEEdge*>&
568
569
570const std::vector<GNEJunction*>&
574
575
576const std::vector<GNETAZ*>&
580
581
582bool
583GNEPathCreator::addStoppingPlace(GNEAdditional* stoppingPlace, const bool /*shiftKeyPressed*/, const bool /*controlKeyPressed*/) {
584 if (stoppingPlace == nullptr) {
585 return false;
586 }
587 // check if stoppingPlaces are allowed
588 if (((myCreationMode & END_BUSSTOP) == 0) && ((myCreationMode & END_TRAINSTOP) == 0) && ((myCreationMode & END_CONTAINERSTOP) == 0)) {
589 return false;
590 }
591 if (((myCreationMode & END_BUSSTOP) != 0) && (stoppingPlace->getTagProperty().getTag() != SUMO_TAG_BUS_STOP)) {
592 return false;
593 }
594 if (((myCreationMode & END_TRAINSTOP) != 0) && (stoppingPlace->getTagProperty().getTag() != SUMO_TAG_TRAIN_STOP)) {
595 return false;
596 }
597 if (((myCreationMode & END_CONTAINERSTOP) != 0) && (stoppingPlace->getTagProperty().getTag() != SUMO_TAG_CONTAINER_STOP)) {
598 return false;
599 }
600 // avoid select first an stopping place
601 if (((myCreationMode & START_EDGE) != 0) && mySelectedEdges.empty()) {
602 WRITE_WARNING(TL("first select an edge"));
603 return false;
604 }
605 // check if previously stopping place from was set
606 if (myToStoppingPlace) {
607 return false;
608 } else {
609 myToStoppingPlace = stoppingPlace;
610 }
611 // enable abort route button
612 myAbortCreationButton->enable();
613 // enable finish button
614 myFinishCreationButton->enable();
615 // disable undo/redo
617 // enable or disable remove last stoppingPlace button
618 if (myToStoppingPlace) {
620 } else {
622 }
623 // recalculate path
625 // update info route label
627 // update stoppingPlace colors
629 // if is a stop, create inmediately
630 if (myCreationMode & STOP) {
631 if (createPath(false)) {
632 return true;
633 } else {
634 myToStoppingPlace = nullptr;
635 // recalculate path again
637 // update info route label
639 // update stoppingPlace colors
641 return false;
642 }
643 } else {
644 return true;
645 }
646}
647
648
651 if (myToStoppingPlace && (myToStoppingPlace->getTagProperty().getTag() == expectedTag)) {
652 return myToStoppingPlace;
653 } else {
654 return nullptr;
655 }
656}
657
658
659bool
660GNEPathCreator::addRoute(GNEDemandElement* route, const bool /*shiftKeyPressed*/, const bool /*controlKeyPressed*/) {
661 // check if routes aren allowed
662 if ((myCreationMode & ROUTE) == 0) {
663 return false;
664 }
665 // check if previously a route was added
666 if (myRoute) {
667 return false;
668 }
669 // set route and create path
670 myRoute = route;
671 createPath(false);
672 myRoute = nullptr;
673 // recalculate path
677 return true;
678}
679
680
683 return myRoute;
684}
685
686
687const std::vector<GNEPathCreator::Path>&
689 return myPath;
690}
691
692
693bool
695 return (myShowCandidateEdges->getCheck() == TRUE);
696}
697
698
699void
701 // clear junction colors
703 // check if show possible candidates
705 // set candidate flags
706 for (const auto& junction : myFrameParent->getViewNet()->getNet()->getAttributeCarriers()->getJunctions()) {
707 junction.second->resetCandidateFlags();
708 junction.second->setPossibleCandidate(true);
709 }
710 }
711 // set selected junctions
712 if (mySelectedJunctions.size() > 0) {
713 // mark selected eges
714 for (const auto& junction : mySelectedJunctions) {
715 junction->resetCandidateFlags();
716 junction->setSourceCandidate(true);
717 }
718 // finally mark last selected element as target
719 mySelectedJunctions.back()->resetCandidateFlags();
720 mySelectedJunctions.back()->setTargetCandidate(true);
721 }
722 // update view net
724}
725
726
727void
729 // clear edge colors
731 // first check if show candidate edges
732 if (myShowCandidateEdges->getCheck() == TRUE && (myCreationMode & SHOW_CANDIDATE_EDGES)) {
733 // mark all edges that have at least one lane that allow given vClass
734 for (const auto& edge : myFrameParent->getViewNet()->getNet()->getAttributeCarriers()->getEdges()) {
735 if (edge.second->getNBEdge()->getNumLanesThatAllow(myVClass) > 0) {
736 edge.second->setPossibleCandidate(true);
737 } else {
738 edge.second->setSpecialCandidate(true);
739 }
740 }
741 }
742 // set reachability
743 if (mySelectedEdges.size() > 0) {
744 // only coloring edges if checkbox "show candidate edges" is enabled
745 if ((myShowCandidateEdges->getCheck() == TRUE) && (myCreationMode & SHOW_CANDIDATE_EDGES)) {
746 // mark all edges as conflicted (to mark special candidates)
747 for (const auto& edge : myFrameParent->getViewNet()->getNet()->getAttributeCarriers()->getEdges()) {
748 edge.second->resetCandidateFlags();
749 edge.second->setConflictedCandidate(true);
750 }
751 // set special candidates (Edges that are connected but aren't compatibles with current vClass
753 // mark again all edges as conflicted (to mark possible candidates)
754 for (const auto& edge : myFrameParent->getViewNet()->getNet()->getAttributeCarriers()->getEdges()) {
755 edge.second->setConflictedCandidate(true);
756 }
757 // set possible candidates (Edges that are connected AND are compatibles with current vClass
759 }
760 // now mark selected eges
761 for (const auto& edge : mySelectedEdges) {
762 edge->resetCandidateFlags();
763 edge->setSourceCandidate(true);
764 }
765 // finally mark last selected element as target
766 mySelectedEdges.back()->resetCandidateFlags();
767 mySelectedEdges.back()->setTargetCandidate(true);
768 }
769 // update view net
771}
772
773
774void
776 // reset all junction flags
777 for (const auto& junction : myFrameParent->getViewNet()->getNet()->getAttributeCarriers()->getJunctions()) {
778 junction.second->resetCandidateFlags();
779 }
780}
781
782
783void
785 // reset all junction flags
786 for (const auto& edge : myFrameParent->getViewNet()->getNet()->getAttributeCarriers()->getEdges()) {
787 edge.second->resetCandidateFlags();
788 }
789}
790
791
792void
794 const double lineWidth = 0.35;
795 const double lineWidthin = 0.25;
796 // Add a draw matrix
798 // Start with the drawing of the area traslating matrix to origin
799 glTranslated(0, 0, GLO_MAX - 0.1);
800 // check if draw bewteen junction or edges
801 if (myPath.size() > 0) {
802 // set first color
804 // iterate over path
805 for (int i = 0; i < (int)myPath.size(); i++) {
806 // get path
807 const GNEPathCreator::Path& path = myPath.at(i);
808 // draw line over
809 for (int j = 0; j < (int)path.getSubPath().size(); j++) {
810 const GNELane* lane = path.getSubPath().at(j)->getLanes().back();
811 if (((i == 0) && (j == 0)) || (j > 0)) {
812 GLHelper::drawBoxLines(lane->getLaneShape(), lineWidth);
813 }
814 // draw connection between lanes
815 if ((j + 1) < (int)path.getSubPath().size()) {
816 const GNELane* nextLane = path.getSubPath().at(j + 1)->getLanes().back();
817 if (lane->getLane2laneConnections().exist(nextLane)) {
819 } else {
820 GLHelper::drawBoxLines({lane->getLaneShape().back(), nextLane->getLaneShape().front()}, lineWidth);
821 }
822 }
823 }
824 }
825 glTranslated(0, 0, 0.1);
826 // iterate over path again
827 for (int i = 0; i < (int)myPath.size(); i++) {
828 // get path
829 const GNEPathCreator::Path& path = myPath.at(i);
830 // set path color color
833 } else if (path.isConflictDisconnected()) {
835 } else if (path.isConflictVClass()) {
837 } else {
839 }
840 // draw line over
841 for (int j = 0; j < (int)path.getSubPath().size(); j++) {
842 const GNELane* lane = path.getSubPath().at(j)->getLanes().back();
843 if (((i == 0) && (j == 0)) || (j > 0)) {
844 GLHelper::drawBoxLines(lane->getLaneShape(), lineWidthin);
845 }
846 // draw connection between lanes
847 if ((j + 1) < (int)path.getSubPath().size()) {
848 const GNELane* nextLane = path.getSubPath().at(j + 1)->getLanes().back();
849 if (lane->getLane2laneConnections().exist(nextLane)) {
851 } else {
852 GLHelper::drawBoxLines({ lane->getLaneShape().back(), nextLane->getLaneShape().front() }, lineWidthin);
853 }
854 }
855 }
856 }
857 } else if (mySelectedJunctions.size() > 0) {
858 // set color
860 // draw line between junctions
861 for (int i = 0; i < (int)mySelectedJunctions.size() - 1; i++) {
862 // get two points
863 const Position posA = mySelectedJunctions.at(i)->getPositionInView();
864 const Position posB = mySelectedJunctions.at(i + 1)->getPositionInView();
865 const double rot = ((double)atan2((posB.x() - posA.x()), (posA.y() - posB.y())) * (double) 180.0 / (double)M_PI);
866 const double len = posA.distanceTo2D(posB);
867 // draw line
868 GLHelper::drawBoxLine(posA, rot, len, 0.25);
869 }
870 } else if (mySelectedTAZs.size() > 0) {
871 // set color
873 // draw line between TAZs
874 for (int i = 0; i < (int)mySelectedTAZs.size() - 1; i++) {
875 // get two points
876 const Position posA = mySelectedTAZs.at(i)->getPositionInView();
877 const Position posB = mySelectedTAZs.at(i + 1)->getPositionInView();
878 const double rot = ((double)atan2((posB.x() - posA.x()), (posA.y() - posB.y())) * (double) 180.0 / (double)M_PI);
879 const double len = posA.distanceTo2D(posB);
880 // draw line
881 GLHelper::drawBoxLine(posA, rot, len, 0.25);
882 }
883 }
884 // Pop last matrix
886}
887
888
889bool
890GNEPathCreator::createPath(const bool useLastRoute) {
891 // call create path implemented in frame parent
892 return myFrameParent->createPath(useLastRoute);
893}
894
895
896void
898 // first check that there is elements
899 if ((mySelectedJunctions.size() > 0) || (mySelectedTAZs.size() > 0) || (mySelectedEdges.size() > 0) || myToStoppingPlace || myRoute) {
900 // unblock undo/redo
902 // clear edges
903 clearPath();
904 // disable buttons
905 myFinishCreationButton->disable();
906 myAbortCreationButton->disable();
908 // update info route label
910 // update junction colors
912 // update edge colors
914 // update view (to see the new route)
916 }
917}
918
919
920void
922 if (mySelectedEdges.size() > 1) {
923 // remove special color of last selected edge
924 mySelectedEdges.back()->resetCandidateFlags();
925 // remove last edge
926 mySelectedEdges.pop_back();
927 // change last edge flag
928 if ((mySelectedEdges.size() > 0) && mySelectedEdges.back()->isSourceCandidate()) {
929 mySelectedEdges.back()->setSourceCandidate(false);
930 mySelectedEdges.back()->setTargetCandidate(true);
931 }
932 // enable or disable remove last edge button
933 if (mySelectedEdges.size() > 1) {
935 } else {
937 }
938 // recalculate path
940 // update info route label
942 // update junction colors
944 // update edge colors
946 // update view
948 }
949}
950
951
952long
953GNEPathCreator::onCmdCreatePath(FXObject*, FXSelector, void*) {
954 // call create path
955 return createPath(false);
956}
957
958
959long
960GNEPathCreator::onCmdUseLastRoute(FXObject*, FXSelector, void*) {
961 // call create path with useLastRoute = true
962 return createPath(true);
963}
964
965long
966GNEPathCreator::onUpdUseLastRoute(FXObject* sender, FXSelector, void*) {
968 return sender->handle(this, FXSEL(SEL_COMMAND, ID_ENABLE), nullptr);
969 } else {
970 return sender->handle(this, FXSEL(SEL_COMMAND, ID_DISABLE), nullptr);
971 }
972}
973
974long
975GNEPathCreator::onCmdAbortPathCreation(FXObject*, FXSelector, void*) {
976 // just call abort path creation
978 return 1;
979}
980
981
982long
983GNEPathCreator::onCmdRemoveLastElement(FXObject*, FXSelector, void*) {
984 // just call remove last element
986 return 1;
987}
988
989
990long
991GNEPathCreator::onCmdShowCandidateEdges(FXObject*, FXSelector, void*) {
992 // update labels
993 if (myShowCandidateEdges->getCheck() == TRUE) {
994 myShiftLabel->show();
995 myControlLabel->show();
996 } else {
997 myShiftLabel->hide();
998 myControlLabel->hide();
999 }
1000 // recalc frame
1001 recalc();
1002 // update edge colors (view will be updated within function)
1004 return 1;
1005}
1006
1007
1008void
1010 if (myPath.size() > 0) {
1011 // declare variables for route info
1012 double length = 0;
1013 double speed = 0;
1014 int pathSize = 0;
1015 for (const auto& path : myPath) {
1016 for (const auto& edge : path.getSubPath()) {
1017 length += edge->getNBEdge()->getLength();
1018 speed += edge->getNBEdge()->getSpeed();
1019 }
1020 pathSize += (int)path.getSubPath().size();
1021 }
1022 // declare ostringstream for label and fill it
1023 std::ostringstream information;
1024 information
1025 << TL("- Selected edges: ") << toString(mySelectedEdges.size()) << "\n"
1026 << TL("- Path edges: ") << toString(pathSize) << "\n"
1027 << TL("- Length: ") << toString(length) << "\n"
1028 << TL("- Average speed: ") << toString(speed / pathSize);
1029 // set new label
1030 myInfoRouteLabel->setText(information.str().c_str());
1031 } else {
1032 myInfoRouteLabel->setText(TL("No edges selected"));
1033 }
1034}
1035
1036
1037void
1042 // clear junction, TAZs, edges, additionals and route
1043 mySelectedJunctions.clear();
1044 mySelectedTAZs.clear();
1045 mySelectedEdges.clear();
1046 myToStoppingPlace = nullptr;
1047 myRoute = nullptr;
1048 // clear path
1049 myPath.clear();
1050 // update info route label
1052}
1053
1054
1055void
1057 // first clear path
1058 myPath.clear();
1059 // set edges
1060 std::vector<GNEEdge*> edges;
1061 // add route edges
1062 if (myRoute) {
1063 edges = myRoute->getParentEdges();
1064 } else {
1065 // add selected edges
1066 for (const auto& edge : mySelectedEdges) {
1067 edges.push_back(edge);
1068 }
1069 // add to stopping place edge
1070 if (myToStoppingPlace) {
1071 edges.push_back(myToStoppingPlace->getParentLanes().front()->getParentEdge());
1072 }
1073 }
1074 // fill paths
1075 if (edges.size() == 1) {
1076 myPath.push_back(Path(myVClass, edges.front()));
1077 } else if (mySelectedJunctions.size() == 2) {
1078 // add path between two junctions
1080 } else {
1081 // add every segment
1082 for (int i = 1; i < (int)edges.size(); i++) {
1083 myPath.push_back(Path(myFrameParent->getViewNet(), myVClass, edges.at(i - 1), edges.at(i)));
1084 }
1085 }
1086}
1087
1088
1089void
1091 // first calculate reachability for pedestrians (we use it, because pedestran can walk in almost all edges)
1093 // change flags
1094 for (const auto& edge : myFrameParent->getViewNet()->getNet()->getAttributeCarriers()->getEdges()) {
1095 for (const auto& lane : edge.second->getLanes()) {
1096 if (lane->getReachability() > 0) {
1097 lane->getParentEdge()->resetCandidateFlags();
1098 lane->getParentEdge()->setSpecialCandidate(true);
1099 }
1100 }
1101 }
1102}
1103
1104void
1106 // first calculate reachability for pedestrians
1108 // change flags
1109 for (const auto& edge : myFrameParent->getViewNet()->getNet()->getAttributeCarriers()->getEdges()) {
1110 for (const auto& lane : edge.second->getLanes()) {
1111 if (lane->getReachability() > 0) {
1112 lane->getParentEdge()->resetCandidateFlags();
1113 lane->getParentEdge()->setPossibleCandidate(true);
1114 }
1115 }
1116 }
1117}
1118
1119/****************************************************************************/
FXDEFMAP(GNEPathCreator) PathCreatorMap[]
@ MID_GNE_PATHCREATOR_FINISH
finish edge path creation
Definition GUIAppEnum.h:953
@ MID_GNE_PATHCREATOR_REMOVELAST
remove last inserted element in path
Definition GUIAppEnum.h:957
@ MID_GNE_PATHCREATOR_USELASTROUTE
use last inserted route
Definition GUIAppEnum.h:955
@ MID_GNE_PATHCREATOR_ABORT
abort edge path creation
Definition GUIAppEnum.h:951
@ MID_GNE_PATHCREATOR_SHOWCANDIDATES
enable or disable show path candidates
Definition GUIAppEnum.h:959
#define GUIDesignButton
Definition GUIDesigns.h:74
#define GUIDesignCheckButton
checkButton placed in left position
Definition GUIDesigns.h:187
#define GUIDesignLabelFrameInformation
label extended over frame without thick and with text justify to left, used to show information in fr...
Definition GUIDesigns.h:274
@ GLO_MAX
empty max
#define WRITE_WARNING(msg)
Definition MsgHandler.h:270
#define TL(string)
Definition MsgHandler.h:287
SUMOVehicleClass
Definition of vehicle classes to differ between different lane usage and authority types.
@ SVC_PASSENGER
vehicle is a passenger car (a "normal" car)
@ SVC_PEDESTRIAN
pedestrian
SumoXMLTag
Numbers representing SUMO-XML - element names.
@ GNE_TAG_TRIP_JUNCTIONS
a trip between junctions
@ GNE_TAG_TRIP_TAZS
a single trip definition that uses TAZs
@ GNE_TAG_PERSONTRIP_JUNCTIONS
@ SUMO_TAG_EDGEREL
a relation between two edges
@ GNE_TAG_TRANSPORT_CONTAINERSTOP
@ GNE_TAG_PERSONTRIP_BUSSTOP
@ GNE_TAG_WALK_EDGES
@ SUMO_TAG_CONTAINER_STOP
A container stop.
@ GNE_TAG_STOPCONTAINER_EDGE
@ SUMO_TAG_BUS_STOP
A bus stop.
@ GNE_TAG_STOPPERSON_BUSSTOP
@ SUMO_TAG_VEHICLE
description of a vehicle
@ GNE_TAG_FLOW_ROUTE
a flow definition using a route instead of a from-to edges route
@ GNE_TAG_FLOW_JUNCTIONS
a flow between junctions
@ GNE_TAG_TRANSHIP_EDGES
@ GNE_TAG_STOPCONTAINER_CONTAINERSTOP
@ GNE_TAG_FLOW_WITHROUTE
description of a vehicle with an embedded route
@ SUMO_TAG_FLOW
a flow definition using from and to edges or a route
@ GNE_TAG_PERSONTRIP_TRAINSTOP
@ GNE_TAG_FLOW_TAZS
a flow between TAZs
@ GNE_TAG_WALK_BUSSTOP
@ SUMO_TAG_ROUTE
begin/end of the description of a route
@ SUMO_TAG_TRAIN_STOP
A train stop (alias for bus stop)
@ GNE_TAG_RIDE_EDGE
@ GNE_TAG_TRANSHIP_EDGE
@ GNE_TAG_WALK_JUNCTIONS
@ GNE_TAG_VEHICLE_WITHROUTE
description of a vehicle with an embedded route
@ GNE_TAG_WALK_TRAINSTOP
@ GNE_TAG_STOPPERSON_TRAINSTOP
@ GNE_TAG_RIDE_TRAINSTOP
@ GNE_TAG_WALK_EDGE
@ GNE_TAG_PERSONTRIP_EDGE
@ GNE_TAG_ROUTE_EMBEDDED
embedded route
@ GNE_TAG_RIDE_BUSSTOP
@ GNE_TAG_STOPPERSON_EDGE
@ GNE_TAG_WALK_ROUTE
@ SUMO_TAG_TRIP
a single trip definition (used by router)
@ GNE_TAG_TRANSHIP_CONTAINERSTOP
@ GNE_TAG_TRANSPORT_EDGE
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
Definition ToString.h:46
static void setColor(const RGBColor &c)
Sets the gl-color to this value.
Definition GLHelper.cpp:583
static void popMatrix()
pop matrix
Definition GLHelper.cpp:130
static void drawBoxLines(const PositionVector &geom, const std::vector< double > &rots, const std::vector< double > &lengths, double width, int cornerDetail=0, double offset=0)
Draws thick lines.
Definition GLHelper.cpp:329
static void drawBoxLine(const Position &beg, double rot, double visLength, double width, double offset=0)
Draws a thick line.
Definition GLHelper.cpp:277
static void pushMatrix()
push matrix
Definition GLHelper.cpp:117
An Element which don't belong to GNENet but has influence in the simulation.
void disableUndoRedo(const std::string &reason)
disable undo-redo giving a string with the reason
void enableUndoRedo()
disable undo-redo
const GNETagProperties & getTagProperty() const
get tagProperty associated with this Attribute Carrier
bool isSpecialCandidate() const
check if this element is a special candidate
bool isPossibleCandidate() const
check if this element is a possible candidate
bool isConflictedCandidate() const
check if this element is a conflicted candidate
An Element which don't belong to GNENet but has influence in the simulation.
A road/street connecting two junctions (netedit-version)
Definition GNEEdge.h:53
GNEViewNet * getViewNet() const
get view net
Definition GNEFrame.cpp:150
virtual bool createPath(const bool useLastRoute)
create path between two elements
Definition GNEFrame.cpp:304
const std::vector< GNEEdge * > & getParentEdges() const
get parent edges
const std::vector< GNELane * > & getParentLanes() const
get parent lanes
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
This lane is powered by an underlying GNEEdge and basically knows how to draw itself.
Definition GNELane.h:46
const PositionVector & getLaneShape() const
get elements shape
Definition GNELane.cpp:136
const GNELane2laneConnection & getLane2laneConnections() const
get Lane2laneConnection struct
Definition GNELane.cpp:829
const std::map< std::string, GNEEdge * > & getEdges() const
map with the ID and pointer to edges of net
const std::map< std::string, GNEJunction * > & getJunctions() const
get junctions
GNENetHelper::AttributeCarriers * getAttributeCarriers() const
get all attribute carriers used in this net
Definition GNENet.cpp:120
GNEPathManager * getPathManager()
get path manager
Definition GNENet.cpp:132
FOX-declaration.
bool isConflictVClass() const
check if current path is conflict due vClass
bool myConflictDisconnected
flag to mark this path as disconnected
bool myConflictVClass
flag to mark this path as conflicted
bool isConflictDisconnected() const
check if current path is conflict due is disconnected
GNEAdditional * getToBusStop() const
to additional
std::vector< GNEEdge * > mySubPath
sub path
Path()
default constructor
const std::vector< GNEEdge * > & getSubPath() const
get sub path
GNEAdditional * getFromBusStop() const
get from additional
long onCmdCreatePath(FXObject *, FXSelector, void *)
GNEAdditional * getToStoppingPlace(SumoXMLTag expectedTag) const
get to stoppingPlace
std::vector< Path > myPath
vector with current path
FXButton * myAbortCreationButton
button for abort route creation
bool addStoppingPlace(GNEAdditional *stoppingPlace, const bool shiftKeyPressed, const bool controlKeyPressed)
add stoppingPlace
void updateEdgeColors()
update edge colors
long onCmdAbortPathCreation(FXObject *, FXSelector, void *)
Called when the user click over button "Abort route creation".
bool addRoute(GNEDemandElement *route, const bool shiftKeyPressed, const bool controlKeyPressed)
add route
GNEAdditional * myToStoppingPlace
to additional (usually a busStop)
FXLabel * myControlLabel
label for control information
GNEFrame * myFrameParent
current frame parent
std::vector< GNEEdge * > mySelectedEdges
vector with selected edges
std::vector< GNETAZ * > mySelectedTAZs
vector with selected TAZs
GNEDemandElement * myRoute
route (usually a busStop)
const std::vector< GNETAZ * > & getSelectedTAZs() const
get current selected TAZs
void abortPathCreation()
abort path creation
void updateInfoRouteLabel()
update InfoRouteLabel
bool addTAZ(GNETAZ *taz)
add TAZ
FXCheckButton * myShowCandidateEdges
CheckBox for show candidate edges.
long onCmdShowCandidateEdges(FXObject *, FXSelector, void *)
Called when the user click over check button "show candidate edges".
~GNEPathCreator()
destructor
const std::vector< GNEJunction * > & getSelectedJunctions() const
get current selected junctions
void clearPath()
clear edges (and restore colors)
SUMOVehicleClass myVClass
current vClass
const std::vector< GNEEdge * > & getSelectedEdges() const
get current selected edges
void setPossibleCandidates(GNEEdge *originEdge, const SUMOVehicleClass vClass)
set edgereachability (This function will be called recursively)
long onCmdUseLastRoute(FXObject *, FXSelector, void *)
Called when the user click over button "Use last route".
void clearEdgeColors()
clear edge colors
bool addEdge(GNEEdge *edge, const bool shiftKeyPressed, const bool controlKeyPressed)
add edge
GNEDemandElement * getRoute() const
get route
void removeLastElement()
remove path element
bool addJunction(GNEJunction *junction)
add junction
bool createPath(const bool useLastRoute)
create path
void setVClass(SUMOVehicleClass vClass)
set vClass
void updateJunctionColors()
update junction colors
void drawTemporalRoute(const GUIVisualizationSettings &s) const
draw temporal route
SUMOVehicleClass getVClass() const
get vClass
FXButton * myRemoveLastInsertedElement
button for removing last inserted element
long onCmdRemoveLastElement(FXObject *, FXSelector, void *)
Called when the user click over button "Remove las inserted edge".
int myCreationMode
current creation mode
FXLabel * myInfoRouteLabel
label with route info
FXLabel * myBackSpaceLabel
label for backSpace information
bool drawCandidateEdgesWithSpecialColor() const
draw candidate edges with special color (Only for candidates, special and conflicted)
void setSpecialCandidates(GNEEdge *originEdge)
set special candidates (This function will be called recursively)
FXButton * myFinishCreationButton
button for finish route creation
long onUpdUseLastRoute(FXObject *, FXSelector, void *)
Called when update button "Use last route".
FXLabel * myShiftLabel
label for shift information
void recalculatePath()
recalculate path
GNEPathCreator(GNEFrame *frameParent)
default constructor
const std::vector< Path > & getPath() const
get path route
void clearJunctionColors()
clear junction colors
void hidePathCreatorModule()
show GNEPathCreator
void showPathCreatorModule(SumoXMLTag element, const bool firstElement, const bool consecutives)
show GNEPathCreator for the given tag
FXButton * myUseLastRoute
button for use last inserted route
std::vector< GNEJunction * > mySelectedJunctions
vector with selected junctions
void calculateReachability(const SUMOVehicleClass vClass, GNEEdge *originEdge)
calculate reachability for given edge
std::vector< GNEEdge * > calculateDijkstraPath(const SUMOVehicleClass vClass, const std::vector< GNEEdge * > &partialEdges) const
calculate Dijkstra path between a list of partial edges
PathCalculator * getPathCalculator()
obtain instance of PathCalculator
SumoXMLTag getTag() const
get Tag vinculated with this attribute Property
GNENet * getNet() const
get the net object
GNEDemandElement * getLastCreatedRoute() const
get last created route
GNEViewParent * getViewParent() const
get the net object
void updateViewNet() const
Mark the entire GNEViewNet to be repainted later.
GNEApplicationWindow * getGNEAppWindows() const
get GNE Application Windows
const PositionVector & getShape() const
The shape of the additional element.
static FXIcon * getIcon(const GUIIcon which)
returns a icon previously defined in the enum GUIIcon
Stores the information about how to visualize structures.
GUIVisualizationCandidateColorSettings candidateColorSettings
candidate color settings
MFXGroupBoxModule (based on FXGroupBox)
FXVerticalFrame * getCollapsableFrame()
get collapsable frame (used by all elements that will be collapsed if button is toggled)
A point in 2D or 3D with translation and scaling methods.
Definition Position.h:37
double distanceTo2D(const Position &p2) const
returns the euclidean distance in the x-y-plane
Definition Position.h:254
double x() const
Returns the x-position.
Definition Position.h:55
double y() const
Returns the y-position.
Definition Position.h:60
static const RGBColor GREY
Definition RGBColor.h:194
static const RGBColor ORANGE
Definition RGBColor.h:191
#define M_PI
Definition odrSpiral.cpp:45
static const RGBColor special
color for selected special candidate element (Usually selected using shift+click)
static const RGBColor conflict
color for selected conflict candidate element (Usually selected using ctrl+click)