Eclipse SUMO - Simulation of Urban MObility
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/GNEViewNet.h>
23 #include <netedit/GNEViewParent.h>
30 #include <utils/gui/div/GLHelper.h>
35 
36 #include "GNEDemandElement.h"
37 #include "GNERouteHandler.h"
38 
39 // ===========================================================================
40 // member method definitions
41 // ===========================================================================
42 
43 GNEDemandElement::GNEDemandElement(const std::string& id, GNENet* net, GUIGlObjectType type, SumoXMLTag tag, FXIcon* icon, const int options,
44  const std::vector<GNEJunction*>& junctionParents,
45  const std::vector<GNEEdge*>& edgeParents,
46  const std::vector<GNELane*>& laneParents,
47  const std::vector<GNEAdditional*>& additionalParents,
48  const std::vector<GNEDemandElement*>& demandElementParents,
49  const std::vector<GNEGenericData*>& genericDataParents) :
50  GNEPathManager::PathElement(type, id, icon, options),
51  GNEHierarchicalElement(net, tag, junctionParents, edgeParents, laneParents, additionalParents, demandElementParents, genericDataParents),
53  myStackedLabelNumber(0) {
54  // check if is template
55  myIsTemplate = id.empty();
56 }
57 
58 
59 GNEDemandElement::GNEDemandElement(GNEDemandElement* demandElementParent, GNENet* net, GUIGlObjectType type, SumoXMLTag tag, FXIcon* icon, const int options,
60  const std::vector<GNEJunction*>& junctionParents,
61  const std::vector<GNEEdge*>& edgeParents,
62  const std::vector<GNELane*>& laneParents,
63  const std::vector<GNEAdditional*>& additionalParents,
64  const std::vector<GNEDemandElement*>& demandElementParents,
65  const std::vector<GNEGenericData*>& genericDataParents) :
66  GNEPathManager::PathElement(type, demandElementParent->getID(), icon, options),
67  GNEHierarchicalElement(net, tag, junctionParents, edgeParents, laneParents, additionalParents, demandElementParents, genericDataParents),
69  myStackedLabelNumber(0) {
70 }
71 
72 
74 
75 
76 void
77 GNEDemandElement::removeGeometryPoint(const Position /*clickedPosition*/, GNEUndoList* /*undoList*/) {
78  // currently there isn't demand elements with removable geometry points
79 }
80 
81 
84  return this;
85 }
86 
87 
88 const GUIGlObject*
90  return this;
91 }
92 
93 
94 const GUIGeometry&
97 }
98 
99 
102  // first check if there are demand elements
103  if (getChildDemandElements().empty()) {
104  return nullptr;
105  } else {
106  // find child demand element
107  auto it = std::find(getChildDemandElements().begin(), getChildDemandElements().end(), demandElement);
108  // return element or null depending of iterator
109  if (it == getChildDemandElements().end()) {
110  // in this case, we assume that the last child is the previos child
111  return getChildDemandElements().back();
112  } else if (it == getChildDemandElements().begin()) {
113  return nullptr;
114  } else {
115  return *(it - 1);
116  }
117  }
118 }
119 
120 
123  // find child demand element
124  auto it = std::find(getChildDemandElements().begin(), getChildDemandElements().end(), demandElement);
125  // return element or null depending of iterator
126  if (it == getChildDemandElements().end()) {
127  return nullptr;
128  } else if (it == (getChildDemandElements().end() - 1)) {
129  return nullptr;
130  } else {
131  return *(it + 1);
132  }
133 }
134 
135 
136 void
137 GNEDemandElement::updateDemandElementGeometry(const GNELane* lane, const double posOverLane) {
139 }
140 
141 
142 void
144  myStackedLabelNumber = stack;
145 }
146 
147 
148 void
149 GNEDemandElement::updateDemandElementSpreadGeometry(const GNELane* lane, const double posOverLane) {
151 }
152 
153 
154 const GUIGeometry&
157 }
158 
159 
160 bool
162  return false;
163 }
164 
165 
166 bool
168  return false;
169 }
170 
171 
172 bool
174  return false;
175 }
176 
177 
178 bool
180  // get modes
181  const auto& modes = myNet->getViewNet()->getEditModes();
182  // get frames
183  const auto& personFramePlanSelector = myNet->getViewNet()->getViewParent()->getPersonFrame()->getPlanSelector();
184  const auto& personPlanFramePlanSelector = myNet->getViewNet()->getViewParent()->getPersonPlanFrame()->getPlanSelector();
185  const auto& containerFramePlanSelector = myNet->getViewNet()->getViewParent()->getContainerFrame()->getPlanSelector();
186  const auto& containerPlanFramePlanSelector = myNet->getViewNet()->getViewParent()->getContainerPlanFrame()->getPlanSelector();
187  // special case for Route
189  // get vehicle frame
190  const auto& vehicleFrame = myNet->getViewNet()->getViewParent()->getVehicleFrame();
191  // check if we're in vehicle mode
192  if (vehicleFrame->shown()) {
193  // get current vehicle template
194  const auto& vehicleTemplate = vehicleFrame->getVehicleTagSelector()->getCurrentTemplateAC();
195  // check if vehicle can be placed over route
196  if (vehicleTemplate && vehicleTemplate->getTagProperty().vehicleRoute()) {
198  }
199  } else if (modes.isCurrentSupermodeDemand()) {
200  // check if we're in person or personPlan modes
201  if (((modes.demandEditMode == DemandEditMode::DEMAND_PERSON) && personFramePlanSelector->markRoutes()) ||
202  ((modes.demandEditMode == DemandEditMode::DEMAND_PERSONPLAN) && personPlanFramePlanSelector->markRoutes()) ||
203  ((modes.demandEditMode == DemandEditMode::DEMAND_CONTAINER) && containerFramePlanSelector->markRoutes()) ||
204  ((modes.demandEditMode == DemandEditMode::DEMAND_CONTAINERPLAN) && containerPlanFramePlanSelector->markRoutes())) {
206  }
207  }
208  }
209  return false;
210 }
211 
212 
213 bool
215  // get edit modes
216  const auto& editModes = myNet->getViewNet()->getEditModes();
217  // check if we're in delete mode
218  if (editModes.isCurrentSupermodeDemand() && (editModes.demandEditMode == DemandEditMode::DEMAND_DELETE)) {
220  } else {
221  return false;
222  }
223 }
224 
225 
226 bool
228  // get edit modes
229  const auto& editModes = myNet->getViewNet()->getEditModes();
230  // check if we're in select mode
231  if (editModes.isCurrentSupermodeDemand() && (editModes.demandEditMode == DemandEditMode::DEMAND_SELECT)) {
233  } else {
234  return false;
235  }
236 }
237 
238 
239 bool
241  // get edit modes
242  const auto& editModes = myNet->getViewNet()->getEditModes();
243  // check if we're in select mode
244  if (!myNet->getViewNet()->isMovingElement() && editModes.isCurrentSupermodeDemand() &&
245  (editModes.demandEditMode == DemandEditMode::DEMAND_MOVE) && myNet->getViewNet()->checkOverLockedElement(this, mySelected)) {
246  // only move the first element
248  } else {
249  return false;
250  }
251 }
252 
253 
254 void
256  throw InvalidArgument(getTagStr() + " doesn't have a demand element dialog");
257 }
258 
259 
262  GUIGLObjectPopupMenu* ret = new GUIGLObjectPopupMenu(app, parent, *this);
263  // build header
264  buildPopupHeader(ret, app);
265  // build menu command for center button and copy cursor position to clipboard
267  buildPositionCopyEntry(ret, app);
268  // build menu commands for names
269  GUIDesigns::buildFXMenuCommand(ret, "Copy " + getTagStr() + " name to clipboard", nullptr, ret, MID_COPY_NAME);
270  GUIDesigns::buildFXMenuCommand(ret, "Copy " + getTagStr() + " typed name to clipboard", nullptr, ret, MID_COPY_TYPED_NAME);
271  new FXMenuSeparator(ret);
272  // build selection and show parameters menu
275  // show option to open demand element dialog
276  if (myTagProperty.hasDialog()) {
277  GUIDesigns::buildFXMenuCommand(ret, ("Open " + getTagStr() + " Dialog").c_str(), getACIcon(), &parent, MID_OPEN_ADDITIONAL_DIALOG);
278  new FXMenuSeparator(ret);
279  }
280  GUIDesigns::buildFXMenuCommand(ret, "Cursor position in view: " + toString(getPositionInView().x()) + "," + toString(getPositionInView().y()), nullptr, nullptr, 0);
281  return ret;
282 }
283 
284 
287  // Create table
288  GUIParameterTableWindow* ret = new GUIParameterTableWindow(app, *this);
289  // Iterate over attributes
290  for (const auto& i : myTagProperty) {
291  // Add attribute and set it dynamic if aren't unique
292  if (i.isUnique()) {
293  ret->mkItem(i.getAttrStr().c_str(), false, getAttribute(i.getAttr()));
294  } else {
295  ret->mkItem(i.getAttrStr().c_str(), true, getAttribute(i.getAttr()));
296  }
297  }
298  // close building
299  ret->closeBuilding();
300  return ret;
301 }
302 
303 
304 bool
308  } else {
309  return true;
310  }
311 }
312 
313 
314 void
317 }
318 
319 
320 void
322  // we need an special checks due hierarchies
323  if (myTagProperty.isPlan()) {
324  // get person/container plarent
325  GNEDemandElement* planParent = getParentDemandElements().front();
326  // if this is the last person/container plan element, remove parent instead plan
327  if (planParent->getChildDemandElements().size() == 1) {
328  planParent->deleteGLObject();
329  } else {
331  }
332  } else if (getTagProperty().getTag() == GNE_TAG_ROUTE_EMBEDDED) {
333  // remove parent demand element
334  getParentDemandElements().front()->deleteGLObject();
335  } else {
337  }
338 }
339 
340 
341 void
345  } else {
347  }
348  // update information label
350 }
351 
352 
353 void
355  updateGeometry();
356 }
357 
358 
359 bool
361  return mySelected;
362 }
363 
364 // ---------------------------------------------------------------------------
365 // GNEDemandElement - protected methods
366 // ---------------------------------------------------------------------------
367 
368 bool
369 GNEDemandElement::isValidDemandElementID(const std::string& value) const {
370  if (value == getID()) {
371  return true;
372  } else if (SUMOXMLDefinitions::isValidVehicleID(value)) {
373  return (myNet->getAttributeCarriers()->retrieveDemandElement(myTagProperty.getTag(), value, false) == nullptr);
374  } else {
375  return false;
376  }
377 }
378 
379 
380 bool
381 GNEDemandElement::isValidDemandElementID(const std::vector<SumoXMLTag>& tags, const std::string& value) const {
382  if (value == getID()) {
383  return true;
384  } else if (SUMOXMLDefinitions::isValidVehicleID(value)) {
385  return (myNet->getAttributeCarriers()->retrieveDemandElements(tags, value, false) == nullptr);
386  } else {
387  return false;
388  }
389 }
390 
391 
392 void
393 GNEDemandElement::setDemandElementID(const std::string& newID) {
394  // set microsim ID
395  setMicrosimID(newID);
396  // check if update ids of child elements
398  // Change IDs of all person plans children (stops, embedded routes...)
399  for (const auto& childDemandElement : getChildDemandElements()) {
400  childDemandElement->setDemandElementID(getID());
401  }
402  }
403 }
404 
405 
408  if (getParentDemandElements().size() < 1) {
409  throw InvalidArgument("This demand element doesn't have a type parent");
410  } else if (!getParentDemandElements().at(0)->getTagProperty().isType()
411  && !getParentDemandElements().at(0)->getTagProperty().isTypeDist()) {
412  throw InvalidArgument("The first parent isn't a type");
413  } else if (getParentDemandElements().at(0)->getTagProperty().getTag() == SUMO_TAG_VTYPE) {
414  return getParentDemandElements().at(0);
415  } else {
416  // get typeDistribution ID
417  const auto typeDistributionID = getParentDemandElements().at(0)->getID();
418  // obtain all types with the given typeDistribution sorted by ID
419  std::map<std::string, GNEDemandElement*> sortedTypes;
420  for (const auto& type : myNet->getAttributeCarriers()->getDemandElements().at(SUMO_TAG_VTYPE)) {
421  if (type.second->getAttribute(GNE_ATTR_VTYPE_DISTRIBUTION) == typeDistributionID) {
422  sortedTypes[type.second->getID()] = type.second;
423  }
424  }
425  // return first type, or default vType
426  if (sortedTypes.size() > 0) {
427  return sortedTypes.begin()->second;
428  } else if (myNet->getAttributeCarriers()->getDemandElements().size() > 0) {
429  return myNet->getAttributeCarriers()->getDemandElements().at(SUMO_TAG_VTYPE).begin()->second;
430  } else {
431  throw InvalidArgument("no vTypes");
432  }
433  }
434 }
435 
436 
439  if (getParentDemandElements().size() < 2) {
440  throw InvalidArgument("This demand element doesn't have two parent");
441  } else if (getParentDemandElements().at(1)->getTagProperty().getTag() != SUMO_TAG_ROUTE) {
442  throw InvalidArgument("This demand element doesn't have a route parent");
443  } else {
444  return getParentDemandElements().at(1);
445  }
446 }
447 
448 
449 std::vector<GNEDemandElement*>
452  // get stops
453  std::vector<GNEDemandElement*> invalidStops;
454  // get edge stop index
455  const auto edgeStopIndex = getEdgeStopIndex();
456  // take all stops/waypoints with index = -1
457  for (const auto& edgeStop : edgeStopIndex) {
458  if (edgeStop.stopIndex == -1) {
459  for (const auto& stop : edgeStop.stops) {
460  invalidStops.push_back(stop);
461  }
462  }
463  }
464  return invalidStops;
465  } else {
466  return {};
467  }
468 }
469 
470 
471 void
473  // get two points
474  const Position posA = element->getParentJunctions().front()->getPositionInView();
475  const Position posB = element->getParentJunctions().back()->getPositionInView();
476  const double rot = ((double)atan2((posB.x() - posA.x()), (posA.y() - posB.y())) * (double) 180.0 / (double)M_PI);
477  const double len = posA.distanceTo2D(posB);
478  // push draw matrix
480  // Start with the drawing of the area traslating matrix to origin
481  myNet->getViewNet()->drawTranslateFrontAttributeCarrier(this, element->getType() + 0.1);
482  // set trip color
484  // draw line
485  GLHelper::drawBoxLine(posA, rot, len, 0.25);
486  // pop draw matrix
488 }
489 
490 
491 void
492 GNEDemandElement::drawStackLabel(const int number, const std::string& element, const Position& position, const double rotation, const double width, const double length, const double exaggeration) const {
493  // declare contour width
494  const double contourWidth = (0.05 * exaggeration);
495  // Push matrix
497  // Traslate to top
498  glTranslated(position.x(), position.y(), GLO_ROUTE + getType() + 0.1 + GLO_PERSONFLOW);
499  glRotated(rotation, 0, 0, -1);
500  glTranslated((width * exaggeration * 0.5) + (0.35 * exaggeration), 0, 0);
501  // draw external box
503  GLHelper::drawBoxLine(Position(), 0, (length * exaggeration), 0.3 * exaggeration);
504  // draw internal box
505  glTranslated(0, 0, 0.1);
506  GLHelper::setColor(RGBColor(0, 128, 0));
507  GLHelper::drawBoxLine(Position(0, -contourWidth), Position(0, -contourWidth), 0, (length * exaggeration) - (contourWidth * 2), (0.3 * exaggeration) - contourWidth);
508  // draw stack label
509  GLHelper::drawText(element + "s stacked: " + toString(number), Position(0, length * exaggeration * -0.5), (.1 * exaggeration), (0.6 * exaggeration), RGBColor::WHITE, 90, 0, -1);
510  // pop draw matrix
512 }
513 
514 
515 void
517  replaceParentElements(this, parse<std::vector<GNEEdge*> >(getNet(), value));
518 }
519 
520 
521 void
523  replaceParentElements(this, parse<std::vector<GNELane*> >(getNet(), value));
524 }
525 
526 
527 void
529  std::vector<GNEJunction*> parentJunctions = getParentJunctions();
530  parentJunctions[0] = myNet->getAttributeCarriers()->retrieveJunction(value);
531  // replace parent junctions
532  replaceParentElements(this, parentJunctions);
533 }
534 
535 
536 void
538  std::vector<GNEJunction*> parentJunctions = getParentJunctions();
539  parentJunctions[(int)parentJunctions.size() - 1] = myNet->getAttributeCarriers()->retrieveJunction(value);
540  // replace parent junctions
541  replaceParentElements(this, parentJunctions);
542 }
543 
544 
545 void
546 GNEDemandElement::replaceFirstParentEdge(const std::string& value) {
547  std::vector<GNEEdge*> parentEdges = getParentEdges();
548  parentEdges[0] = myNet->getAttributeCarriers()->retrieveEdge(value);
549  // replace parent edges
550  replaceParentElements(this, parentEdges);
551 }
552 
553 
554 void
555 GNEDemandElement::replaceLastParentEdge(const std::string& value) {
556  std::vector<GNEEdge*> parentEdges = getParentEdges();
557  parentEdges[(int)parentEdges.size() - 1] = myNet->getAttributeCarriers()->retrieveEdge(value);
558  // replace parent edges
559  replaceParentElements(this, parentEdges);
560 }
561 
562 
563 void
565  std::vector<GNEAdditional*> parentAdditionals = getParentAdditionals();
566  parentAdditionals[0] = myNet->getAttributeCarriers()->retrieveAdditional(tag, value);
567  // replace parent additionals
568  replaceParentElements(this, parentAdditionals);
569 }
570 
571 
572 void
574  std::vector<GNEAdditional*> parentAdditionals = getParentAdditionals();
575  parentAdditionals[(int)parentAdditionals.size() - 1] = myNet->getAttributeCarriers()->retrieveAdditional(tag, value);
576  // replace parent additionals
577  replaceParentElements(this, parentAdditionals);
578 }
579 
580 
581 void
582 GNEDemandElement::replaceDemandElementParent(SumoXMLTag tag, const std::string& value, const int parentIndex) {
583  std::vector<GNEDemandElement*> parentDemandElements = getParentDemandElements();
584  parentDemandElements[parentIndex] = myNet->getAttributeCarriers()->retrieveDemandElement(tag, value);
585  // replace parent demand elements
586  replaceParentElements(this, parentDemandElements);
587 }
588 
589 
590 void
592  std::vector<GNEDemandElement*> parents;
593  if (value.size() > 0) {
595  }
596  replaceParentElements(this, parents);
597 }
598 
599 
600 bool
602  // throw exception because this function mus be implemented in child (see GNEE3Detector)
603  throw ProcessError(StringUtils::format("Calling non-implemented function checkChildDemandElementRestriction during saving of %. It muss be reimplemented in child class", getTagStr()));
604 }
605 
606 
607 std::vector<GNEDemandElement::EdgeStopIndex>
609  std::vector<GNEDemandElement::EdgeStopIndex> edgeStopIndex;
610  // first check that this stop has parent
611  if (getParentDemandElements().size() > 0) {
612  // get path edges depending of parent
613  std::vector<GNEEdge*> pathEdges;
614  // get parent demand element
615  const auto parent = getParentDemandElements().front();
616  // continue depending of parent
617  if (parent->getTagProperty().hasAttribute(SUMO_ATTR_EDGES)) {
618  pathEdges = parent->getParentEdges();
619  } else if (parent->getTagProperty().vehicleRoute()) {
620  // get route edges
621  if (parent->getParentDemandElements().size() > 1) {
622  pathEdges = parent->getParentDemandElements().at(1)->getParentEdges();
623  }
624  } else if (parent->getTagProperty().vehicleRouteEmbedded()) {
625  // get embedded route edges
626  pathEdges = parent->getChildDemandElements().front()->getParentEdges();
627  } else {
628  // get last parent edge
629  const auto lastEdge = parent->getParentEdges().back();
630  bool stop = false;
631  const auto& pathElementSegments = myNet->getPathManager()->getPathElementSegments(parent);
632  // extract all edges from pathElement parent
633  for (auto it = pathElementSegments.begin(); (it != pathElementSegments.end()) && !stop; it++) {
634  if ((*it)->getLane()) {
635  pathEdges.push_back((*it)->getLane()->getParentEdge());
636  // stop if path correspond to last edge
637  if (pathEdges.back() == lastEdge) {
638  stop = true;
639  }
640  }
641  }
642  }
643  // get all parent's stops and waypoints sorted by position
644  for (const auto& demandElement : parent->getChildDemandElements()) {
645  if (demandElement->getTagProperty().isVehicleStop()) {
646  // get stop/waypoint edge
647  GNEEdge* edge = nullptr;
648  if (demandElement->getParentAdditionals().size() > 0) {
649  edge = demandElement->getParentAdditionals().front()->getParentLanes().front()->getParentEdge();
650  } else {
651  edge = demandElement->getParentLanes().front()->getParentEdge();
652  }
653  // check if add a new edgeStopIndex or update last
654  if ((edgeStopIndex.size() > 0) && (edgeStopIndex.back().edge == edge)) {
655  edgeStopIndex.back().stops.push_back(demandElement);
656  } else {
657  edgeStopIndex.push_back(EdgeStopIndex(edge, demandElement));
658  }
659  }
660  }
661  // declare index for current stop
662  int currentEdgeStopIndex = 0;
663  for (int i = 0; (i < (int)pathEdges.size()) && (currentEdgeStopIndex < (int)edgeStopIndex.size()); i++) {
664  // check if current edge stop index is in the path
665  if (edgeStopIndex[currentEdgeStopIndex].edge == pathEdges.at(i)) {
666  edgeStopIndex[currentEdgeStopIndex].stopIndex = i;
667  currentEdgeStopIndex++;
668  } else {
669  // check if edge exist in the rest of the path
670  bool next = false;
671  for (int j = (i + 1); j < (int)pathEdges.size(); j++) {
672  if (edgeStopIndex[currentEdgeStopIndex].edge == pathEdges.at(j)) {
673  next = true;
674  }
675  }
676  if (!next) {
677  // ignore current stops (because is out of path)
678  currentEdgeStopIndex++;
679  }
680  }
681  }
682  }
683  // sort stops by position
684  for (auto& edgeStop : edgeStopIndex) {
685  if (edgeStop.stops.size() > 1) {
686  // copy all stops to a map to sort it by endPos
687  std::map<double, std::vector<GNEDemandElement*> > sortedStops;
688  for (const auto& stop : edgeStop.stops) {
689  if (sortedStops.count(stop->getAttributeDouble(SUMO_ATTR_ENDPOS)) == 0) {
690  sortedStops[stop->getAttributeDouble(SUMO_ATTR_ENDPOS)] = {stop};
691  } else {
692  sortedStops[stop->getAttributeDouble(SUMO_ATTR_ENDPOS)].push_back(stop);
693  }
694  }
695  // update stops with sorted stops
696  edgeStop.stops.clear();
697  for (const auto& sortedStop : sortedStops) {
698  edgeStop.stops.insert(edgeStop.stops.end(), sortedStop.second.begin(), sortedStop.second.end());
699  }
700  }
701  }
702  return edgeStopIndex;
703 }
704 
705 
706 std::string
708  SumoXMLTag tagDistribution = SUMO_TAG_NOTHING;
710  tagDistribution = SUMO_TAG_VTYPE_DISTRIBUTION;
711  } else if (myTagProperty.getTag() == SUMO_TAG_ROUTE) {
712  tagDistribution = SUMO_TAG_ROUTE_DISTRIBUTION;
713  } else {
714  return "";
715  }
716  // check if the current element is in the distributions
717  std::vector<std::string> distributionParents;
718  for (const auto& distribution : myNet->getAttributeCarriers()->getDemandElements().at(tagDistribution)) {
719  if (distribution.second->keyExists(this)) {
720  distributionParents.push_back(distribution.second->getID());
721  }
722  }
723  return toString(distributionParents);
724 }
725 
726 
727 void
729  std::vector<GNEEdge*> edges;
730  if (myTagProperty.isRoute()) {
731  edges = getParentEdges();
732  } else if (myTagProperty.vehicleRoute()) {
733  edges = getParentDemandElements().at(1)->getParentEdges();
734  } else if (myTagProperty.vehicleRouteEmbedded()) {
735  edges = getChildDemandElements().front()->getParentEdges();
736  } else if (myTagProperty.vehicleEdges()) {
737  edges = getParentEdges();
738  }
739  // calculate path
740  const auto path = myNet->getPathManager()->getPathCalculator()->calculateDijkstraPath(getVClass(), edges);
741  // check path size
742  if (path.size() > 0) {
743  double length = 0;
744  for (const auto& edge : path) {
745  length += edge->getNBEdge()->getFinalLength();
746  }
747  for (int i = 0; i < ((int)path.size() - 1); i++) {
748  length += path.at(i)->getLanes().front()->getLane2laneConnections().getLane2laneGeometry(path.at(i + 1)->getLanes().front()).getShape().length();
749  }
750  GUIDesigns::buildFXMenuCommand(ret, TL("Route length: ") + toString(length), nullptr, ret, MID_COPY_NAME);
751  }
752 }
753 
754 
755 void
757  // create menu pane for transform operations
758  FXMenuPane* transformOperation = new FXMenuPane(ret);
759  ret->insertMenuPaneChild(transformOperation);
760  auto reverseMenuCascade = new FXMenuCascade(ret, TL("reverse"), nullptr, transformOperation);
761  // build menu commands
762  GUIDesigns::buildFXMenuCommand(transformOperation, TLF("reverse current %", myTagProperty.getTagStr()), nullptr, myNet->getViewNet(), MID_GNE_REVERSE);
763  GUIDesigns::buildFXMenuCommand(transformOperation, TLF("Add reverse %", myTagProperty.getTagStr()), nullptr, myNet->getViewNet(), MID_GNE_ADDREVERSE);
764  // check if reverse can be added
765  if (GNERouteHandler::canReverse(this)) {
766  reverseMenuCascade->enable();
767  } else {
768  reverseMenuCascade->disable();
769  }
770 }
771 
772 /****************************************************************************/
@ 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
Definition: GUIAppEnum.h:1385
@ MID_COPY_TYPED_NAME
Copy typed object name - popup entry.
Definition: GUIAppEnum.h:453
@ MID_GNE_REVERSE
reverse current element
Definition: GUIAppEnum.h:1383
@ MID_OPEN_ADDITIONAL_DIALOG
open additional dialog (used in netedit)
Definition: GUIAppEnum.h:465
@ MID_COPY_NAME
Copy object name - popup entry.
Definition: GUIAppEnum.h:451
GUIGlObjectType
@ GLO_ROUTE
a route
@ GLO_PERSONFLOW
a person flow
#define TL(string)
Definition: MsgHandler.h:315
#define TLF(string,...)
Definition: MsgHandler.h:317
SumoXMLTag
Numbers representing SUMO-XML - element names.
@ SUMO_TAG_VTYPE
description of a vehicle/person/container type
@ SUMO_TAG_NOTHING
invalid tag
@ 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
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:655
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:757
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....
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
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
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.
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
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.
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.
const std::map< SumoXMLTag, std::map< const GUIGlObject *, GNEDemandElement * > > & getDemandElements() const
get demand elements
A NBNetBuilder extended by visualisation and editing capabilities.
Definition: GNENet.h:42
void deleteDemandElement(GNEDemandElement *demandElement, GNEUndoList *undoList)
remove demand element
Definition: GNENet.cpp:671
GNENetHelper::AttributeCarriers * getAttributeCarriers() const
get all attribute carriers used in this net
Definition: GNENet.cpp:121
GNEPathManager * getPathManager()
get path manager
Definition: GNENet.cpp:133
GNEViewNet * getViewNet() const
get view net
Definition: GNENet.cpp:2056
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< Segment * > & getPathElementSegments(PathElement *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
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 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 attribute carrier or a pointer to nullptr
const GNEViewNetHelper::EditModes & getEditModes() const
get edit modes
Definition: GNEViewNet.cpp:703
void setFrontAttributeCarrier(GNEAttributeCarrier *AC)
set front attributeCarrier
void drawTranslateFrontAttributeCarrier(const GNEAttributeCarrier *AC, double typeOrLayer, const double extraOffset=0)
draw front attributeCarrier
bool isMovingElement() const
check if an element is being moved
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
Definition: GNEViewNet.cpp:468
GNEViewNetHelper::LockManager & getLockManager()
get lock manager
void buildSelectionACPopupEntry(GUIGLObjectPopupMenu *ret, GNEAttributeCarrier *AC)
Builds an entry which allows to (de)select the object.
Definition: GNEViewNet.cpp:538
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
Definition: GUIDesigns.cpp:42
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
Definition: GUIGeometry.cpp:59
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.
Definition: GUIGlObject.h:156
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.
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:271
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 GREY
Definition: RGBColor.h:194
static const RGBColor RED
named colors
Definition: RGBColor.h:185
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
Definition: StringUtils.h:176
#define M_PI
Definition: odrSpiral.cpp:45
auxiliar struct used for calculate pathStopIndex
bool isCurrentSupermodeDemand() const
@check if current supermode is Demand