Eclipse SUMO - Simulation of Urban MObility
Loading...
Searching...
No Matches
GNEDemandElement.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-2024 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 abstract class for demand elements
19/****************************************************************************/
20
21#include <netedit/GNENet.h>
22#include <netedit/GNESegment.h>
23#include <netedit/GNEViewNet.h>
36
37#include "GNEDemandElement.h"
38#include "GNERouteHandler.h"
39
40// ===========================================================================
41// member method definitions
42// ===========================================================================
43
44GNEDemandElement::GNEDemandElement(const std::string& id, GNENet* net, GUIGlObjectType type, SumoXMLTag tag, FXIcon* icon, const int options,
45 const std::vector<GNEJunction*>& junctionParents,
46 const std::vector<GNEEdge*>& edgeParents,
47 const std::vector<GNELane*>& laneParents,
48 const std::vector<GNEAdditional*>& additionalParents,
49 const std::vector<GNEDemandElement*>& demandElementParents,
50 const std::vector<GNEGenericData*>& genericDataParents) :
51 GNEPathElement(type, id, icon, options),
52 GNEHierarchicalElement(net, tag, junctionParents, edgeParents, laneParents, additionalParents, demandElementParents, genericDataParents),
54 myStackedLabelNumber(0) {
55 // check if is template
56 myIsTemplate = id.empty();
57}
58
59
60GNEDemandElement::GNEDemandElement(GNEDemandElement* demandElementParent, GNENet* net, GUIGlObjectType type, SumoXMLTag tag, FXIcon* icon, const int options,
61 const std::vector<GNEJunction*>& junctionParents,
62 const std::vector<GNEEdge*>& edgeParents,
63 const std::vector<GNELane*>& laneParents,
64 const std::vector<GNEAdditional*>& additionalParents,
65 const std::vector<GNEDemandElement*>& demandElementParents,
66 const std::vector<GNEGenericData*>& genericDataParents) :
67 GNEPathElement(type, demandElementParent->getID(), icon, options),
68 GNEHierarchicalElement(net, tag, junctionParents, edgeParents, laneParents, additionalParents, demandElementParents, genericDataParents),
70 myStackedLabelNumber(0) {
71}
72
73
75
76
77void
78GNEDemandElement::removeGeometryPoint(const Position /*clickedPosition*/, GNEUndoList* /*undoList*/) {
79 // currently there isn't demand elements with removable geometry points
80}
81
82
85 return this;
86}
87
88
89const GUIGlObject*
91 return this;
92}
93
94
95const GUIGeometry&
99
100
103 // first check if there are demand elements
104 if (getChildDemandElements().empty()) {
105 return nullptr;
106 } else {
107 // find child demand element
108 auto it = std::find(getChildDemandElements().begin(), getChildDemandElements().end(), demandElement);
109 // return element or null depending of iterator
110 if (it == getChildDemandElements().end()) {
111 // in this case, we assume that the last child is the previos child
112 return getChildDemandElements().back();
113 } else if (it == getChildDemandElements().begin()) {
114 return nullptr;
115 } else {
116 return *(it - 1);
117 }
118 }
119}
120
121
124 // find child demand element
125 auto it = std::find(getChildDemandElements().begin(), getChildDemandElements().end(), demandElement);
126 // return element or null depending of iterator
127 if (it == getChildDemandElements().end()) {
128 return nullptr;
129 } else if (it == (getChildDemandElements().end() - 1)) {
130 return nullptr;
131 } else {
132 return *(it + 1);
133 }
134}
135
136
137void
141
142
143void
147
148
149void
153
154
155const GUIGeometry&
159
160
161bool
163 return false;
164}
165
166
167bool
169 return false;
170}
171
172
173bool
175 return false;
176}
177
178
179bool
181 // get modes
182 const auto& modes = myNet->getViewNet()->getEditModes();
183 // get frames
184 const auto& personFramePlanSelector = myNet->getViewNet()->getViewParent()->getPersonFrame()->getPlanSelector();
185 const auto& personPlanFramePlanSelector = myNet->getViewNet()->getViewParent()->getPersonPlanFrame()->getPlanSelector();
186 const auto& containerFramePlanSelector = myNet->getViewNet()->getViewParent()->getContainerFrame()->getPlanSelector();
187 const auto& containerPlanFramePlanSelector = myNet->getViewNet()->getViewParent()->getContainerPlanFrame()->getPlanSelector();
188 // special case for Route
190 // get vehicle frame
191 const auto& vehicleFrame = myNet->getViewNet()->getViewParent()->getVehicleFrame();
192 // check if we're in vehicle mode
193 if (vehicleFrame->shown()) {
194 // get current vehicle template
195 const auto& vehicleTemplate = vehicleFrame->getVehicleTagSelector()->getCurrentTemplateAC();
196 // check if vehicle can be placed over route
197 if (vehicleTemplate && vehicleTemplate->getTagProperty().vehicleRoute()) {
199 }
200 } else if (modes.isCurrentSupermodeDemand()) {
201 // check if we're in person or personPlan modes
202 if (((modes.demandEditMode == DemandEditMode::DEMAND_PERSON) && personFramePlanSelector->markRoutes()) ||
203 ((modes.demandEditMode == DemandEditMode::DEMAND_PERSONPLAN) && personPlanFramePlanSelector->markRoutes()) ||
204 ((modes.demandEditMode == DemandEditMode::DEMAND_CONTAINER) && containerFramePlanSelector->markRoutes()) ||
205 ((modes.demandEditMode == DemandEditMode::DEMAND_CONTAINERPLAN) && containerPlanFramePlanSelector->markRoutes())) {
207 }
208 }
209 }
210 return false;
211}
212
213
214bool
216 // get edit modes
217 const auto& editModes = myNet->getViewNet()->getEditModes();
218 // check if we're in delete mode
219 if (editModes.isCurrentSupermodeDemand() && (editModes.demandEditMode == DemandEditMode::DEMAND_DELETE)) {
221 } else {
222 return false;
223 }
224}
225
226
227bool
229 // get edit modes
230 const auto& editModes = myNet->getViewNet()->getEditModes();
231 // check if we're in select mode
232 if (editModes.isCurrentSupermodeDemand() && (editModes.demandEditMode == DemandEditMode::DEMAND_SELECT)) {
234 } else {
235 return false;
236 }
237}
238
239
240bool
242 // get edit modes
243 const auto& editModes = myNet->getViewNet()->getEditModes();
244 // check first set of conditions
245 if (!myNet->getViewNet()->isCurrentlyMovingElements() && // another elements are not currently moved
246 editModes.isCurrentSupermodeDemand() && // supermode demand
247 (editModes.demandEditMode == DemandEditMode::DEMAND_MOVE) && // move mode
248 myNet->getViewNet()->checkOverLockedElement(this, mySelected) && // no locked
249 myNet->getViewNet()->getViewObjectsSelector().getGUIGlObjectFront() == this) { // first element
250 // continue depending of subtype
251 if (myTagProperty.isVehicle()) {
252 // only vehicles over edges can be moved
254 return true;
255 } else {
256 return false;
257 }
258 } else if ((myTagProperty.isPerson() || myTagProperty.isContainer()) && (getChildDemandElements().size() > 0)) {
259 // only persons/containers with their first plan over edge can be moved
260 return getChildDemandElements().front()->getTagProperty().planFromEdge();
261 } else {
262 return false;
263 }
264 } else {
265 return false;
266 }
267}
268
269
270void
272 throw InvalidArgument(getTagStr() + " doesn't have a demand element dialog");
273}
274
275
278 GUIGLObjectPopupMenu* ret = new GUIGLObjectPopupMenu(app, parent, *this);
279 // build header
280 buildPopupHeader(ret, app);
281 // build menu command for center button and copy cursor position to clipboard
283 buildPositionCopyEntry(ret, app);
284 // build menu commands for names
285 GUIDesigns::buildFXMenuCommand(ret, "Copy " + getTagStr() + " name to clipboard", nullptr, ret, MID_COPY_NAME);
286 GUIDesigns::buildFXMenuCommand(ret, "Copy " + getTagStr() + " typed name to clipboard", nullptr, ret, MID_COPY_TYPED_NAME);
287 new FXMenuSeparator(ret);
288 // build selection and show parameters menu
291 // show option to open demand element dialog
292 if (myTagProperty.hasDialog()) {
293 GUIDesigns::buildFXMenuCommand(ret, ("Open " + getTagStr() + " Dialog").c_str(), getACIcon(), &parent, MID_OPEN_ADDITIONAL_DIALOG);
294 new FXMenuSeparator(ret);
295 }
296 GUIDesigns::buildFXMenuCommand(ret, "Cursor position in view: " + toString(getPositionInView().x()) + "," + toString(getPositionInView().y()), nullptr, nullptr, 0);
297 return ret;
298}
299
300
303 // Create table
305 // Iterate over attributes
306 for (const auto& i : myTagProperty) {
307 // Add attribute and set it dynamic if aren't unique
308 if (i.isUnique()) {
309 ret->mkItem(i.getAttrStr().c_str(), false, getAttribute(i.getAttr()));
310 } else {
311 ret->mkItem(i.getAttrStr().c_str(), true, getAttribute(i.getAttr()));
312 }
313 }
314 // close building
315 ret->closeBuilding();
316 return ret;
317}
318
319
320bool
328
329
330void
334
335
336void
338 // we need an special checks due hierarchies
339 if (myTagProperty.isPlan()) {
340 // get person/container plarent
341 GNEDemandElement* planParent = getParentDemandElements().front();
342 // if this is the last person/container plan element, remove parent instead plan
343 if (planParent->getChildDemandElements().size() == 1) {
344 planParent->deleteGLObject();
345 } else {
347 }
349 // remove parent demand element
350 getParentDemandElements().front()->deleteGLObject();
351 } else {
353 }
354}
355
356
357void
367
368
369void
373
374
375bool
379
380// ---------------------------------------------------------------------------
381// GNEDemandElement - protected methods
382// ---------------------------------------------------------------------------
383
384bool
385GNEDemandElement::isValidDemandElementID(const std::string& value) const {
386 if (!isTemplate() && (value == getID())) {
387 return true;
388 } else if (SUMOXMLDefinitions::isValidVehicleID(value)) {
389 return (myNet->getAttributeCarriers()->retrieveDemandElement(myTagProperty.getTag(), value, false) == nullptr);
390 } else {
391 return false;
392 }
393}
394
395
396bool
397GNEDemandElement::isValidDemandElementID(const std::vector<SumoXMLTag>& tags, const std::string& value) const {
398 if (value == getID()) {
399 return true;
400 } else if (SUMOXMLDefinitions::isValidVehicleID(value)) {
401 return (myNet->getAttributeCarriers()->retrieveDemandElements(tags, value, false) == nullptr);
402 } else {
403 return false;
404 }
405}
406
407
408void
409GNEDemandElement::setDemandElementID(const std::string& newID) {
410 // update ID
412 setMicrosimID(newID);
413 } else {
415 }
416 // check if update ids of child elements
418 // Change IDs of all person plans children (stops, embedded routes...)
419 for (const auto& childDemandElement : getChildDemandElements()) {
420 childDemandElement->setDemandElementID(getID());
421 }
422 }
423}
424
425
428 if (getParentDemandElements().size() < 1) {
429 throw InvalidArgument("This demand element doesn't have a type parent");
430 } else if (!getParentDemandElements().at(0)->getTagProperty().isType()
431 && !getParentDemandElements().at(0)->getTagProperty().isTypeDist()) {
432 throw InvalidArgument("The first parent isn't a type");
433 } else if (getParentDemandElements().at(0)->getTagProperty().getTag() == SUMO_TAG_VTYPE) {
434 return getParentDemandElements().at(0);
435 } else {
436 // get typeDistribution ID
437 const auto typeDistributionID = getParentDemandElements().at(0)->getID();
438 // obtain all types with the given typeDistribution sorted by ID
439 std::map<std::string, GNEDemandElement*> sortedTypes;
440 for (const auto& type : myNet->getAttributeCarriers()->getDemandElements().at(SUMO_TAG_VTYPE)) {
441 if (type.second->getAttribute(GNE_ATTR_VTYPE_DISTRIBUTION) == typeDistributionID) {
442 sortedTypes[type.second->getID()] = type.second;
443 }
444 }
445 // return first type, or default vType
446 if (sortedTypes.size() > 0) {
447 return sortedTypes.begin()->second;
448 } else if (myNet->getAttributeCarriers()->getDemandElements().size() > 0) {
449 return myNet->getAttributeCarriers()->getDemandElements().at(SUMO_TAG_VTYPE).begin()->second;
450 } else {
451 throw InvalidArgument("no vTypes");
452 }
453 }
454}
455
456
459 if (getParentDemandElements().size() < 2) {
460 throw InvalidArgument("This demand element doesn't have two parent");
461 } else if (getParentDemandElements().at(1)->getTagProperty().getTag() != SUMO_TAG_ROUTE) {
462 throw InvalidArgument("This demand element doesn't have a route parent");
463 } else {
464 return getParentDemandElements().at(1);
465 }
466}
467
468
469std::vector<GNEDemandElement*>
472 // get stops
473 std::vector<GNEDemandElement*> invalidStops;
474 // get edge stop index
475 const auto edgeStopIndex = getEdgeStopIndex();
476 // take all stops/waypoints with index = -1
477 for (const auto& edgeStop : edgeStopIndex) {
478 if (edgeStop.stopIndex == -1) {
479 for (const auto& stop : edgeStop.stops) {
480 invalidStops.push_back(stop);
481 }
482 }
483 }
484 return invalidStops;
485 } else {
486 return {};
487 }
488}
489
490
491void
493 // get two points
494 const Position posA = element->getParentJunctions().front()->getPositionInView();
495 const Position posB = element->getParentJunctions().back()->getPositionInView();
496 const double rot = ((double)atan2((posB.x() - posA.x()), (posA.y() - posB.y())) * (double) 180.0 / (double)M_PI);
497 const double len = posA.distanceTo2D(posB);
498 // push draw matrix
500 // Start with the drawing of the area traslating matrix to origin
502 // set trip color
504 // draw line
505 GLHelper::drawBoxLine(posA, rot, len, 0.25);
506 // pop draw matrix
508}
509
510
511void
512GNEDemandElement::drawStackLabel(const int number, const std::string& element, const Position& position, const double rotation, const double width, const double length, const double exaggeration) const {
513 // declare contour width
514 const double contourWidth = (0.05 * exaggeration);
515 // Push matrix
517 // Traslate to top
518 glTranslated(position.x(), position.y(), GLO_ROUTE + getType() + 0.1 + GLO_PERSONFLOW);
519 glRotated(rotation, 0, 0, -1);
520 glTranslated((width * exaggeration * 0.5) + (0.35 * exaggeration), 0, 0);
521 // draw external box
523 GLHelper::drawBoxLine(Position(), 0, (length * exaggeration), 0.3 * exaggeration);
524 // draw internal box
525 glTranslated(0, 0, 0.1);
526 GLHelper::setColor(RGBColor(0, 128, 0));
527 GLHelper::drawBoxLine(Position(0, -contourWidth), Position(0, -contourWidth), 0, (length * exaggeration) - (contourWidth * 2), (0.3 * exaggeration) - contourWidth);
528 // draw stack label
529 GLHelper::drawText(element + "s stacked: " + toString(number), Position(0, length * exaggeration * -0.5), (.1 * exaggeration), (0.6 * exaggeration), RGBColor::WHITE, 90, 0, -1);
530 // pop draw matrix
532}
533
534
535void
537 replaceParentElements(this, parse<std::vector<GNEEdge*> >(getNet(), value));
538}
539
540
541void
543 replaceParentElements(this, parse<std::vector<GNELane*> >(getNet(), value));
544}
545
546
547void
549 std::vector<GNEJunction*> parentJunctions = getParentJunctions();
550 parentJunctions[0] = myNet->getAttributeCarriers()->retrieveJunction(value);
551 // replace parent junctions
552 replaceParentElements(this, parentJunctions);
553}
554
555
556void
558 std::vector<GNEJunction*> parentJunctions = getParentJunctions();
559 parentJunctions[(int)parentJunctions.size() - 1] = myNet->getAttributeCarriers()->retrieveJunction(value);
560 // replace parent junctions
561 replaceParentElements(this, parentJunctions);
562}
563
564
565void
567 std::vector<GNEEdge*> parentEdges = getParentEdges();
568 parentEdges[0] = myNet->getAttributeCarriers()->retrieveEdge(value);
569 // replace parent edges
570 replaceParentElements(this, parentEdges);
571}
572
573
574void
576 std::vector<GNEEdge*> parentEdges = getParentEdges();
577 parentEdges[(int)parentEdges.size() - 1] = myNet->getAttributeCarriers()->retrieveEdge(value);
578 // replace parent edges
579 replaceParentElements(this, parentEdges);
580}
581
582
583void
585 std::vector<GNEAdditional*> parentAdditionals = getParentAdditionals();
586 parentAdditionals[0] = myNet->getAttributeCarriers()->retrieveAdditional(tag, value);
587 // replace parent additionals
588 replaceParentElements(this, parentAdditionals);
589}
590
591
592void
594 std::vector<GNEAdditional*> parentAdditionals = getParentAdditionals();
595 parentAdditionals[(int)parentAdditionals.size() - 1] = myNet->getAttributeCarriers()->retrieveAdditional(tag, value);
596 // replace parent additionals
597 replaceParentElements(this, parentAdditionals);
598}
599
600
601void
602GNEDemandElement::replaceDemandElementParent(SumoXMLTag tag, const std::string& value, const int parentIndex) {
603 std::vector<GNEDemandElement*> parentDemandElements = getParentDemandElements();
604 parentDemandElements[parentIndex] = myNet->getAttributeCarriers()->retrieveDemandElement(tag, value);
605 // replace parent demand elements
606 replaceParentElements(this, parentDemandElements);
607}
608
609
610void
612 std::vector<GNEDemandElement*> parents;
613 if (value.size() > 0) {
615 }
616 replaceParentElements(this, parents);
617}
618
619
620bool
622 // throw exception because this function mus be implemented in child (see GNEE3Detector)
623 throw ProcessError(StringUtils::format("Calling non-implemented function checkChildDemandElementRestriction during saving of %. It muss be reimplemented in child class", getTagStr()));
624}
625
626
627std::vector<GNEDemandElement::EdgeStopIndex>
629 std::vector<GNEDemandElement::EdgeStopIndex> edgeStopIndex;
630 // first check that this stop has parent
631 if (getParentDemandElements().size() > 0) {
632 // get path edges depending of parent
633 std::vector<GNEEdge*> pathEdges;
634 // get parent demand element
635 const auto parent = getParentDemandElements().front();
636 // continue depending of parent
637 if (parent->getTagProperty().hasAttribute(SUMO_ATTR_EDGES)) {
638 pathEdges = parent->getParentEdges();
639 } else if (parent->getTagProperty().vehicleRoute()) {
640 // get route edges
641 if (parent->getParentDemandElements().size() > 1) {
642 pathEdges = parent->getParentDemandElements().at(1)->getParentEdges();
643 }
644 } else if (parent->getTagProperty().vehicleRouteEmbedded()) {
645 // get embedded route edges
646 pathEdges = parent->getChildDemandElements().front()->getParentEdges();
647 } else {
648 // get last parent edge
649 const auto lastEdge = parent->getParentEdges().back();
650 bool stop = false;
651 const auto& pathElementSegments = myNet->getDemandPathManager()->getPathElementSegments(parent);
652 // extract all edges from pathElement parent
653 for (auto it = pathElementSegments.begin(); (it != pathElementSegments.end()) && !stop; it++) {
654 if ((*it)->getLane()) {
655 pathEdges.push_back((*it)->getLane()->getParentEdge());
656 // stop if path correspond to last edge
657 if (pathEdges.back() == lastEdge) {
658 stop = true;
659 }
660 }
661 }
662 }
663 // get all parent's stops and waypoints sorted by position
664 for (const auto& demandElement : parent->getChildDemandElements()) {
665 if (demandElement->getTagProperty().isVehicleStop()) {
666 // get stop/waypoint edge
667 GNEEdge* edge = nullptr;
668 if (demandElement->getParentAdditionals().size() > 0) {
669 edge = demandElement->getParentAdditionals().front()->getParentLanes().front()->getParentEdge();
670 } else {
671 edge = demandElement->getParentLanes().front()->getParentEdge();
672 }
673 // check if add a new edgeStopIndex or update last
674 if ((edgeStopIndex.size() > 0) && (edgeStopIndex.back().edge == edge)) {
675 edgeStopIndex.back().stops.push_back(demandElement);
676 } else {
677 edgeStopIndex.push_back(EdgeStopIndex(edge, demandElement));
678 }
679 }
680 }
681 // declare index for current stop
682 int currentEdgeStopIndex = 0;
683 for (int i = 0; (i < (int)pathEdges.size()) && (currentEdgeStopIndex < (int)edgeStopIndex.size()); i++) {
684 // check if current edge stop index is in the path
685 if (edgeStopIndex[currentEdgeStopIndex].edge == pathEdges.at(i)) {
686 edgeStopIndex[currentEdgeStopIndex].stopIndex = i;
687 currentEdgeStopIndex++;
688 } else {
689 // check if edge exist in the rest of the path
690 bool next = false;
691 for (int j = (i + 1); j < (int)pathEdges.size(); j++) {
692 if (edgeStopIndex[currentEdgeStopIndex].edge == pathEdges.at(j)) {
693 next = true;
694 }
695 }
696 if (!next) {
697 // ignore current stops (because is out of path)
698 currentEdgeStopIndex++;
699 }
700 }
701 }
702 }
703 // sort stops by position
704 for (auto& edgeStop : edgeStopIndex) {
705 if (edgeStop.stops.size() > 1) {
706 // copy all stops to a map to sort it by endPos
707 std::map<double, std::vector<GNEDemandElement*> > sortedStops;
708 for (const auto& stop : edgeStop.stops) {
709 if (sortedStops.count(stop->getAttributeDouble(SUMO_ATTR_ENDPOS)) == 0) {
710 sortedStops[stop->getAttributeDouble(SUMO_ATTR_ENDPOS)] = {stop};
711 } else {
712 sortedStops[stop->getAttributeDouble(SUMO_ATTR_ENDPOS)].push_back(stop);
713 }
714 }
715 // update stops with sorted stops
716 edgeStop.stops.clear();
717 for (const auto& sortedStop : sortedStops) {
718 edgeStop.stops.insert(edgeStop.stops.end(), sortedStop.second.begin(), sortedStop.second.end());
719 }
720 }
721 }
722 return edgeStopIndex;
723}
724
725
728 // set color depending of color active
729 switch (c.getActive()) {
730 case 0: {
731 // test for emergency vehicle
732 if (getTypeParent()->getAttribute(SUMO_ATTR_GUISHAPE) == "emergency") {
733 return RGBColor::WHITE;
734 }
735 // test for firebrigade
736 if (getTypeParent()->getAttribute(SUMO_ATTR_GUISHAPE) == "firebrigade") {
737 return RGBColor::RED;
738 }
739 // test for police car
740 if (getTypeParent()->getAttribute(SUMO_ATTR_GUISHAPE) == "police") {
741 return RGBColor::BLUE;
742 }
743 if (getTypeParent()->getAttribute(SUMO_ATTR_GUISHAPE) == "scooter") {
744 return RGBColor::WHITE;
745 }
746 // check if color was set
747 if (parameters->wasSet(VEHPARS_COLOR_SET)) {
748 return parameters->color;
749 } else {
750 // take their parent's color)
751 return getTypeParent()->getColor();
752 }
753 }
754 case 2: {
755 if (parameters->wasSet(VEHPARS_COLOR_SET)) {
756 return parameters->color;
757 } else {
758 return c.getScheme().getColor(0);
759 }
760 }
761 case 3: {
763 return getTypeParent()->getColor();
764 } else {
765 return c.getScheme().getColor(0);
766 }
767 break;
768 }
769 case 4: {
771 return getRouteParent()->getColor();
772 } else {
773 return c.getScheme().getColor(0);
774 }
775 }
776 case 5: {
777 Position p = getRouteParent()->getParentEdges().at(0)->getLanes().at(0)->getLaneShape()[0];
778 const Boundary& b = myNet->getBoundary();
779 Position center = b.getCenter();
780 double hue = 180. + atan2(center.x() - p.x(), center.y() - p.y()) * 180. / M_PI;
781 double sat = p.distanceTo(center) / center.distanceTo(Position(b.xmin(), b.ymin()));
782 return RGBColor::fromHSV(hue, sat, 1.);
783 }
784 case 6: {
785 Position p = getRouteParent()->getParentEdges().back()->getLanes().at(0)->getLaneShape()[-1];
786 const Boundary& b = myNet->getBoundary();
787 Position center = b.getCenter();
788 double hue = 180. + atan2(center.x() - p.x(), center.y() - p.y()) * 180. / M_PI;
789 double sat = p.distanceTo(center) / center.distanceTo(Position(b.xmin(), b.ymin()));
790 return RGBColor::fromHSV(hue, sat, 1.);
791 }
792 case 7: {
793 Position pb = getRouteParent()->getParentEdges().at(0)->getLanes().at(0)->getLaneShape()[0];
794 Position pe = getRouteParent()->getParentEdges().back()->getLanes().at(0)->getLaneShape()[-1];
795 const Boundary& b = myNet->getBoundary();
796 double hue = 180. + atan2(pb.x() - pe.x(), pb.y() - pe.y()) * 180. / M_PI;
797 Position minp(b.xmin(), b.ymin());
798 Position maxp(b.xmax(), b.ymax());
799 double sat = pb.distanceTo(pe) / minp.distanceTo(maxp);
800 return RGBColor::fromHSV(hue, sat, 1.);
801 }
802 case 35: { // color randomly (by pointer hash)
803 std::hash<const GNEDemandElement*> ptr_hash;
804 const double hue = (double)(ptr_hash(this) % 360); // [0-360]
805 const double sat = (double)((ptr_hash(this) / 360) % 67) / 100. + 0.33; // [0.33-1]
806 return RGBColor::fromHSV(hue, sat, 1.);
807 }
808 default: {
809 return c.getScheme().getColor(0);
810 }
811 }
812}
813
814
815std::string
817 SumoXMLTag tagDistribution = SUMO_TAG_NOTHING;
819 tagDistribution = SUMO_TAG_VTYPE_DISTRIBUTION;
820 } else if (myTagProperty.getTag() == SUMO_TAG_ROUTE) {
821 tagDistribution = SUMO_TAG_ROUTE_DISTRIBUTION;
822 } else {
823 return "";
824 }
825 // check if the current element is in the distributions
826 std::vector<std::string> distributionParents;
827 for (const auto& distribution : myNet->getAttributeCarriers()->getDemandElements().at(tagDistribution)) {
828 if (distribution.second->keyExists(this)) {
829 distributionParents.push_back(distribution.second->getID());
830 }
831 }
832 return toString(distributionParents);
833}
834
835
836void
838 std::vector<GNEEdge*> edges;
839 if (myTagProperty.isRoute()) {
840 edges = getParentEdges();
841 } else if (myTagProperty.vehicleRoute()) {
842 edges = getParentDemandElements().at(1)->getParentEdges();
843 } else if (myTagProperty.vehicleRouteEmbedded()) {
844 edges = getChildDemandElements().front()->getParentEdges();
845 } else if (myTagProperty.vehicleEdges()) {
846 edges = getParentEdges();
847 }
848 // calculate path
850 // check path size
851 if (path.size() > 0) {
852 double length = 0;
853 for (const auto& edge : path) {
854 length += edge->getNBEdge()->getFinalLength();
855 }
856 for (int i = 0; i < ((int)path.size() - 1); i++) {
857 length += path.at(i)->getLanes().front()->getLane2laneConnections().getLane2laneGeometry(path.at(i + 1)->getLanes().front()).getShape().length();
858 }
859 GUIDesigns::buildFXMenuCommand(ret, TL("Route length: ") + toString(length), nullptr, ret, MID_COPY_NAME);
860 }
861}
862
863
864void
866 // create menu pane for transform operations
867 FXMenuPane* transformOperation = new FXMenuPane(ret);
868 ret->insertMenuPaneChild(transformOperation);
869 auto reverseMenuCascade = new FXMenuCascade(ret, TL("reverse"), nullptr, transformOperation);
870 // build menu commands
871 GUIDesigns::buildFXMenuCommand(transformOperation, TLF("reverse current %", myTagProperty.getTagStr()), nullptr, myNet->getViewNet(), MID_GNE_REVERSE);
872 GUIDesigns::buildFXMenuCommand(transformOperation, TLF("Add reverse %", myTagProperty.getTagStr()), nullptr, myNet->getViewNet(), MID_GNE_ADDREVERSE);
873 // check if reverse can be added
874 if (GNERouteHandler::canReverse(this)) {
875 reverseMenuCascade->enable();
876 } else {
877 reverseMenuCascade->disable();
878 }
879}
880
881/****************************************************************************/
@ DEMAND_PERSONPLAN
Mode for editing person plan.
@ DEMAND_CONTAINER
Mode for editing container.
@ DEMAND_DELETE
mode for deleting demand elements
@ DEMAND_PERSON
Mode for editing person.
@ DEMAND_SELECT
mode for selecting demand elements
@ DEMAND_MOVE
mode for moving demand elements
@ DEMAND_CONTAINERPLAN
Mode for editing container plan.
@ MID_GNE_ADDREVERSE
add reverse element
@ MID_COPY_TYPED_NAME
Copy typed object name - popup entry.
Definition GUIAppEnum.h:455
@ MID_GNE_REVERSE
reverse current element
@ MID_OPEN_ADDITIONAL_DIALOG
open additional dialog (used in netedit)
Definition GUIAppEnum.h:469
@ MID_COPY_NAME
Copy object name - popup entry.
Definition GUIAppEnum.h:453
GUIGlObjectType
@ GLO_ROUTE
a route
@ GLO_PERSONFLOW
a person flow
#define TL(string)
Definition MsgHandler.h:315
#define TLF(string,...)
Definition MsgHandler.h:317
const long long int VEHPARS_COLOR_SET
SumoXMLTag
Numbers representing SUMO-XML - element names.
@ SUMO_TAG_VTYPE
description of a vehicle/person/container type
@ SUMO_TAG_NOTHING
invalid tag, must be the last one
@ SUMO_TAG_ROUTE_DISTRIBUTION
distribution of a route
@ SUMO_TAG_ROUTE
begin/end of the description of a route
@ SUMO_TAG_VTYPE_DISTRIBUTION
distribution of a vehicle type
@ GNE_TAG_ROUTE_EMBEDDED
embedded route
@ SUMO_ATTR_ENDPOS
@ GNE_ATTR_VTYPE_DISTRIBUTION
vehicle type distribution
@ SUMO_ATTR_EDGES
the edges of a route
@ SUMO_ATTR_GUISHAPE
@ SUMO_ATTR_COLOR
A color information.
@ SUMO_ATTR_ID
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
Position getCenter() const
Returns the center of the boundary.
Definition Boundary.cpp:112
double ymin() const
Returns minimum y-coordinate.
Definition Boundary.cpp:130
double xmin() const
Returns minimum x-coordinate.
Definition Boundary.cpp:118
double ymax() const
Returns maximum y-coordinate.
Definition Boundary.cpp:136
double xmax() const
Returns maximum x-coordinate.
Definition Boundary.cpp:124
static void setColor(const RGBColor &c)
Sets the gl-color to this value.
Definition GLHelper.cpp:654
static void popMatrix()
pop matrix
Definition GLHelper.cpp:130
static void drawBoxLine(const Position &beg, double rot, double visLength, double width, double offset=0)
Draws a thick line.
Definition GLHelper.cpp:295
static void pushMatrix()
push matrix
Definition GLHelper.cpp:117
static void drawText(const std::string &text, const Position &pos, const double layer, const double size, const RGBColor &col=RGBColor::BLACK, const double angle=0, const int align=0, double width=-1)
Definition GLHelper.cpp:756
const std::string getID() const
get ID (all Attribute Carriers have one)
bool isAttributeCarrierSelected() const
check if attribute carrier is selected
FXIcon * getACIcon() const
get FXIcon associated to this AC
bool mySelected
boolean to check if this AC is selected (instead of GUIGlObjectStorage)
bool myIsTemplate
whether the current object is a template object (not drawn in the view)
static T parse(const std::string &string)
parses a value of type T from string (used for basic types: int, double, bool, etc....
virtual bool isAttributeEnabled(SumoXMLAttr key) const
const std::string & getTagStr() const
get tag assigned to this object in string format
const GNETagProperties & getTagProperty() const
get tagProperty associated with this Attribute Carrier
bool isTemplate() const
check if this AC is template
void unselectAttributeCarrier(const bool changeFlag=true)
unselect attribute carrier using GUIGlobalSelection
GNENet * myNet
pointer to net
GNENet * getNet() const
get pointer to net
void selectAttributeCarrier(const bool changeFlag=true)
select attribute carrier using GUIGlobalSelection
const GNETagProperties & myTagProperty
reference to tagProperty associated with this attribute carrier
GNEPlanSelector * getPlanSelector() const
get containerPlan selector
GNEPlanSelector * getPlanSelector() const
get containerPlan selector
void buildMenuCommandRouteLength(GUIGLObjectPopupMenu *ret) const
build menu command route length
void replaceDemandParentEdges(const std::string &value)
replace demand parent edges
virtual void updateGeometry()=0
update pre-computed geometry information
std::vector< GNEDemandElement * > getInvalidStops() const
get invalid stops
virtual SUMOVehicleClass getVClass() const =0
obtain VClass related with this demand element
void updateDemandElementGeometry(const GNELane *lane, const double posOverLane)
update element stacked geometry (stacked)
void replaceDemandElementParent(SumoXMLTag tag, const std::string &value, const int parentIndex)
replace demand element parent
void drawStackLabel(const int number, const std::string &element, const Position &position, const double rotation, const double width, const double length, const double exaggeration) const
draw stack label
bool checkDrawOverContour() const
check if draw over contour (orange)
std::string getDistributionParents() const
get distribution in which the given element is part
GUIGeometry myDemandElementGeometry
demand element geometry (also called "stacked geometry")
bool isValidDemandElementID(const std::string &value) const
check if a new demand element ID is valid
GNEDemandElement * getNextChildDemandElement(const GNEDemandElement *demandElement) const
get next child demand element to the given demand element
void updateDemandElementStackLabel(const int stack)
update stack label
void replaceLastParentEdge(const std::string &value)
replace the last parent edge
void drawJunctionLine(const GNEDemandElement *element) const
draw line between junctions
virtual std::string getAttribute(SumoXMLAttr key) const =0
virtual const RGBColor & getColor() const =0
get color
GUIGlObject * getGUIGlObject()
get GUIGlObject associated with this AttributeCarrier
bool isPathElementSelected() const
check if path element is selected
bool checkDrawToContour() const
check if draw from contour (magenta)
void replaceFirstParentAdditional(SumoXMLTag tag, const std::string &value)
replace the first parent additional
GNEDemandElement * getRouteParent() const
get route parent (always the second parent demand element)
void selectGLObject()
select element
bool checkDrawMoveContour() const
check if draw move contour (red)
bool checkDrawDeleteContour() const
check if draw delete contour (pink/white)
void setDemandElementID(const std::string &newID)
set demand element id
GUIGeometry mySpreadGeometry
demand element spread geometry (Only used by vehicles and pedestrians)
void buildMenuAddReverse(GUIGLObjectPopupMenu *ret) const
build menu command route length
void replaceFirstParentJunction(const std::string &value)
replace the first parent junction
std::vector< EdgeStopIndex > getEdgeStopIndex() const
get edgeStopIndex
bool checkDrawRelatedContour() const
check if draw related contour (cyan)
void setVTypeDistributionParent(const std::string &value)
set VTypeDistribution parent
void updateGLObject()
update GLObject (geometry, ID, etc.)
GNEDemandElement * getTypeParent() const
get type parent (needed because first parent can be either type or typeDistribution)
bool checkDrawSelectContour() const
check if draw select contour (blue)
void replaceDemandParentLanes(const std::string &value)
replace demand parent lanes
void replaceFirstParentEdge(const std::string &value)
replace the first parent edge
int myStackedLabelNumber
stacked label number
GUIParameterTableWindow * getParameterWindow(GUIMainWindow &app, GUISUMOAbstractView &parent)
Returns an own parameter window.
void updateDemandElementSpreadGeometry(const GNELane *lane, const double posOverLane)
update element spread geometry
virtual Position getPositionInView() const =0
Returns position of demand element in view.
RGBColor getColorByScheme(const GUIColorer &c, const SUMOVehicleParameter *parameters) const
get color by scheme (used by vehicles, persons and containers)
const GUIGeometry & getDemandElementGeometry()
get demand element geometry (stacked)
virtual GUIGLObjectPopupMenu * getPopUpMenu(GUIMainWindow &app, GUISUMOAbstractView &parent)
Returns an own popup-menu.
virtual bool checkChildDemandElementRestriction() const
check restriction with the number of children
void removeGeometryPoint(const Position clickedPosition, GNEUndoList *undoList)
remove geometry point in the clicked position (Currently unused in shapes)
GNEDemandElement * getPreviousChildDemandElement(const GNEDemandElement *demandElement) const
get previous child demand element to the given demand element
bool isGLObjectLocked() const
check if element is locked
void markAsFrontElement()
mark element as front element
void replaceLastParentAdditional(SumoXMLTag tag, const std::string &value)
replace the last parent additional
virtual ~GNEDemandElement()
Destructor.
virtual void openDemandElementDialog()
open DemandElement Dialog
void deleteGLObject()
delete element
void replaceLastParentJunction(const std::string &value)
replace the last parent junction
bool checkDrawFromContour() const
check if draw from contour (green)
A road/street connecting two junctions (netedit-version)
Definition GNEEdge.h:53
const std::vector< GNEJunction * > & getParentJunctions() const
get parent junctions
const std::vector< GNEDemandElement * > & getChildDemandElements() const
return child demand elements
const std::vector< GNEDemandElement * > & getParentDemandElements() const
get parent demand elements
const std::vector< GNEAdditional * > & getParentAdditionals() const
get parent additionals
const std::vector< GNEEdge * > & getParentEdges() const
get parent edges
const std::vector< GNELane * > & getParentLanes() const
get parent lanes
void replaceParentElements(T *elementChild, const U &newParents)
replace parent elements
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:214
double myMoveElementLateralOffset
move element lateral offset (used by elements placed over lanes
const std::unordered_map< SumoXMLTag, std::unordered_map< const GUIGlObject *, GNEDemandElement * > > & getDemandElements() const
get demand elements
GNEAdditional * retrieveAdditional(SumoXMLTag type, const std::string &id, bool hardFail=true) const
Returns the named additional.
GNEJunction * retrieveJunction(const std::string &id, bool hardFail=true) const
get junction by id
GNEDemandElement * retrieveDemandElements(const std::vector< SumoXMLTag > types, const std::string &id, bool hardFail=true) const
Returns the named demand element.
void updateDemandElementID(GNEDemandElement *demandElement, const std::string &newID)
update demand element ID in container
GNEEdge * retrieveEdge(const std::string &id, bool hardFail=true) const
get edge by id
GNEDemandElement * retrieveDemandElement(SumoXMLTag type, const std::string &id, bool hardFail=true) const
Returns the named demand element.
A NBNetBuilder extended by visualisation and editing capabilities.
Definition GNENet.h:42
void deleteDemandElement(GNEDemandElement *demandElement, GNEUndoList *undoList)
remove demand element
Definition GNENet.cpp:697
const Boundary & getBoundary() const
returns the bounder of the network
Definition GNENet.cpp:157
GNEPathManager * getDemandPathManager()
get demand path manager
Definition GNENet.cpp:145
GNENetHelper::AttributeCarriers * getAttributeCarriers() const
get all attribute carriers used in this net
Definition GNENet.cpp:127
GNEViewNet * getViewNet() const
get view net
Definition GNENet.cpp:2155
std::vector< GNEEdge * > calculateDijkstraPath(const SUMOVehicleClass vClass, const std::vector< GNEEdge * > &edges) const
calculate Dijkstra path between a list of edges (for example, from-via-to edges)
PathCalculator * getPathCalculator()
obtain instance of PathCalculator
const std::vector< GNESegment * > & getPathElementSegments(GNEPathElement *pathElement) const
get path segments
GNEPlanSelector * getPlanSelector() const
get personPlan selector
GNEPlanSelector * getPlanSelector() const
get personPlan selector
static bool canReverse(const GNEDemandElement *element)
reverse functions
void updateInformationLabel()
update information label
SelectionInformation * getSelectionInformation() const
get modul for selection information
bool isContainer() const
return true if tag correspond to a container element
bool isPlan() const
plans
const std::string & getTagStr() const
get Tag vinculated with this attribute Property in String Format (used to avoid multiple calls to toS...
bool isRoute() const
return true if tag correspond to a route element
bool isVehicle() const
return true if tag correspond to a vehicle element
SumoXMLTag getTag() const
get Tag vinculated with this attribute Property
bool vehicleRouteEmbedded() const
return true if tag correspond to a vehicle placed over an embedded route
bool hasDialog() const
return true if tag correspond to an element that can be edited using a dialog
bool vehicleEdges() const
return true if tag correspond to a vehicle placed over from-to edges
bool hasAttribute(SumoXMLAttr attr) const
check if current TagProperties owns the attribute "attr"
bool isVehicleStop() const
return true if tag correspond to a vehicle stop element
bool isPerson() const
return true if tag correspond to a person element
bool vehicleRoute() const
plan parents
GNEAttributeCarrier * getCurrentTemplateAC() const
get current templateAC
GNETagSelector * getVehicleTagSelector() const
get vehicle tag selector (needed for transform vehicles)
bool isObjectLocked(GUIGlObjectType objectType, const bool selected) const
check if given GLObject is locked for inspect, select, delete and move
const GUIGlObject * getGUIGlObjectFront() const
get front GUIGLObject or a pointer to nullptr
bool isCurrentlyMovingElements() const
check if an element is being moved
const GNEViewNetHelper::EditModes & getEditModes() const
get edit modes
void setFrontAttributeCarrier(GNEAttributeCarrier *AC)
set front attributeCarrier
void drawTranslateFrontAttributeCarrier(const GNEAttributeCarrier *AC, double typeOrLayer, const double extraOffset=0)
draw front attributeCarrier
GNEViewParent * getViewParent() const
get the net object
bool checkOverLockedElement(const GUIGlObject *GLObject, const bool isSelected) const
check if given element is locked (used for drawing select and delete contour)
GNEUndoList * getUndoList() const
get the undoList object
const GNEViewNetHelper::ViewObjectsSelector & getViewObjectsSelector() const
get objects under cursor
GNEViewNetHelper::LockManager & getLockManager()
get lock manager
void buildSelectionACPopupEntry(GUIGLObjectPopupMenu *ret, GNEAttributeCarrier *AC)
Builds an entry which allows to (de)select the object.
GNEPersonPlanFrame * getPersonPlanFrame() const
get frame for DEMAND_PERSONFRAME
GNESelectorFrame * getSelectorFrame() const
get frame for select elements
GNEContainerPlanFrame * getContainerPlanFrame() const
get frame for DEMAND_CONTAINERFRAME
GNEVehicleFrame * getVehicleFrame() const
get frame for DEMAND_VEHICLE
GNEContainerFrame * getContainerFrame() const
get frame for DEMAND_CONTAINER
GNEPersonFrame * getPersonFrame() const
get frame for DEMAND_PERSON
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.
void insertMenuPaneChild(FXMenuPane *child)
Insert a sub-menu pane in this GUIGLObjectPopupMenu.
void updateGeometry(const PositionVector &shape)
update entire geometry
void buildShowParamsPopupEntry(GUIGLObjectPopupMenu *ret, bool addSeparator=true)
Builds an entry which allows to open the parameter window.
virtual void setMicrosimID(const std::string &newID)
Changes the microsimID of the object.
void buildCenterPopupEntry(GUIGLObjectPopupMenu *ret, bool addSeparator=true)
Builds an entry which allows to center to the object.
void buildPopupHeader(GUIGLObjectPopupMenu *ret, GUIMainWindow &app, bool addSeparator=true)
Builds the header.
GUIGlObjectType getType() const
Returns the type of the object as coded in GUIGlObjectType.
void buildPositionCopyEntry(GUIGLObjectPopupMenu *ret, const GUIMainWindow &app) const
Builds an entry which allows to copy the cursor position if geo projection is used,...
A window containing a gl-object's parameter.
void mkItem(const char *name, bool dynamic, ValueSource< T > *src)
Adds a row which obtains its value from a ValueSource.
void closeBuilding(const Parameterised *p=0)
Closes the building of the table.
T getColor(const double value) const
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:276
double distanceTo(const Position &p2) const
returns the euclidean distance in 3 dimensions
Definition Position.h:266
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 WHITE
Definition RGBColor.h:192
static const RGBColor BLUE
Definition RGBColor.h:187
static const RGBColor GREY
Definition RGBColor.h:194
static RGBColor fromHSV(double h, double s, double v)
Converts the given hsv-triplet to rgb, inspired by http://alvyray.com/Papers/CG/hsv2rgb....
Definition RGBColor.cpp:371
static const RGBColor DEFAULT_COLOR
The default color (for vehicle types and vehicles)
Definition RGBColor.h:199
static const RGBColor RED
named colors
Definition RGBColor.h:185
Structure representing possible vehicle parameter.
bool wasSet(long long int what) const
Returns whether the given parameter was set.
RGBColor color
The vehicle's color, TraCI may change this.
static bool isValidVehicleID(const std::string &value)
whether the given string is a valid id for a vehicle or flow
static const std::string format(const std::string &format, T value, Targs... Fargs)
adds a new formatted message
#define M_PI
Definition odrSpiral.cpp:45
auxiliar struct used for calculate pathStopIndex
bool isCurrentSupermodeDemand() const
@check if current supermode is Demand