Eclipse SUMO - Simulation of Urban MObility
GNERoute.cpp
Go to the documentation of this file.
1 /****************************************************************************/
2 // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo
3 // Copyright (C) 2001-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 class for visualizing routes in Netedit
19 /****************************************************************************/
20 
21 #include <netedit/GNENet.h>
22 #include <netedit/GNEUndoList.h>
23 #include <netedit/GNEViewNet.h>
24 #include <netedit/GNEViewParent.h>
28 #include <utils/gui/div/GLHelper.h>
32 
33 #include "GNERoute.h"
34 #include "GNEVehicle.h"
35 
36 // ===========================================================================
37 // FOX callback mapping
38 // ===========================================================================
39 FXDEFMAP(GNERoute::GNERoutePopupMenu) GNERoutePopupMenuMap[] = {
41 };
42 
43 // Object implementation
44 FXIMPLEMENT(GNERoute::GNERoutePopupMenu, GUIGLObjectPopupMenu, GNERoutePopupMenuMap, ARRAYNUMBER(GNERoutePopupMenuMap))
45 
46 // ===========================================================================
47 // GNERoute::GNERoutePopupMenu - methods
48 // ===========================================================================
49 
51  GUIGLObjectPopupMenu(app, parent, o) {
52 }
53 
54 
56 
57 
58 long
59 GNERoute::GNERoutePopupMenu::onCmdApplyDistance(FXObject*, FXSelector, void*) {
60  GNERoute* route = static_cast<GNERoute*>(myObject);
61  GNEUndoList* undoList = route->myNet->getViewNet()->getUndoList();
62  undoList->begin(route, "apply distance along route");
63  double dist = (route->getParentEdges().size() > 0) ? route->getParentEdges().front()->getNBEdge()->getDistance() : 0;
64  for (GNEEdge* edge : route->getParentEdges()) {
65  GNEChange_Attribute::changeAttribute(edge, SUMO_ATTR_DISTANCE, toString(dist), edge->getAttribute(SUMO_ATTR_DISTANCE), undoList);
66  dist += edge->getNBEdge()->getFinalLength();
67  }
68  undoList->end();
69  return 1;
70 }
71 
72 // ===========================================================================
73 // GNERoute - methods
74 // ===========================================================================
75 
77  GNEDemandElement("", net, GLO_ROUTE, tag, GUIIconSubSys::getIcon(GUIIcon::ROUTE),
79 {}, {}, {}, {}, {}, {}),
81 myColor(RGBColor::YELLOW),
82 myRepeat(0),
83 myCycleTime(0),
84 myVClass(SVC_PASSENGER) {
85  // reset default values
86  resetDefaultValues();
87 }
88 
89 
91  GNEDemandElement(net->getAttributeCarriers()->generateDemandElementID(SUMO_TAG_ROUTE), net, GLO_ROUTE, SUMO_TAG_ROUTE,
92  GUIIconSubSys::getIcon(GUIIcon::ROUTE),
93  GNEPathManager::PathElement::Options::DEMAND_ELEMENT | GNEPathManager::PathElement::Options::ROUTE,
94 {}, {}, {}, {}, {}, {}),
96 myColor(RGBColor::YELLOW),
97 myRepeat(0),
98 myCycleTime(0),
99 myVClass(SVC_PASSENGER) {
100  // reset default values
101  resetDefaultValues();
102 }
103 
104 
105 GNERoute::GNERoute(GNENet* net, const std::string& id, const GNEDemandElement* originalRoute) :
107  GNEPathManager::PathElement::Options::DEMAND_ELEMENT | GNEPathManager::PathElement::Options::ROUTE,
108 {}, originalRoute->getParentEdges(), {}, {}, {}, {}),
109 Parameterised(originalRoute->getACParametersMap()),
110 myRepeat(parse<int>(originalRoute->getAttribute(SUMO_ATTR_REPEAT))),
111 myCycleTime(string2time(originalRoute->getAttribute(SUMO_ATTR_REPEAT))),
112 myVClass(originalRoute->getVClass()) {
113  setAttribute(SUMO_ATTR_COLOR, originalRoute->getAttribute(SUMO_ATTR_COLOR));
114 }
115 
116 
117 GNERoute::GNERoute(GNENet* net, GNEVehicle* vehicleParent, const GNEDemandElement* originalRoute) :
119  GNEPathManager::PathElement::Options::DEMAND_ELEMENT | GNEPathManager::PathElement::Options::ROUTE,
120 {}, originalRoute->getParentEdges(), {}, {}, {vehicleParent}, {}),
121 Parameterised(originalRoute->getACParametersMap()),
122 myRepeat(parse<int>(originalRoute->getAttribute(SUMO_ATTR_REPEAT))),
123 myCycleTime(string2time(originalRoute->getAttribute(SUMO_ATTR_REPEAT))),
124 myVClass(originalRoute->getVClass()) {
125  setAttribute(SUMO_ATTR_COLOR, originalRoute->getAttribute(SUMO_ATTR_COLOR));
126 }
127 
128 
129 GNERoute::GNERoute(GNENet* net, const std::string& id, SUMOVehicleClass vClass, const std::vector<GNEEdge*>& edges,
130  const RGBColor& color, const int repeat, const SUMOTime cycleTime, const Parameterised::Map& parameters) :
132  GNEPathManager::PathElement::Options::DEMAND_ELEMENT | GNEPathManager::PathElement::Options::ROUTE,
133 {}, edges, {}, {}, {}, {}),
134 Parameterised(parameters),
135 myColor(color),
136 myRepeat(repeat),
137 myCycleTime(cycleTime),
138 myVClass(vClass) {
139 }
140 
141 
142 GNERoute::GNERoute(GNENet* net, GNEDemandElement* vehicleParent, const std::vector<GNEEdge*>& edges,
143  const RGBColor& color, const int repeat, const SUMOTime cycleTime, const Parameterised::Map& parameters) :
145  GNEPathManager::PathElement::Options::DEMAND_ELEMENT | GNEPathManager::PathElement::Options::ROUTE,
146 {}, edges, {}, {}, {vehicleParent}, {}),
147 Parameterised(parameters),
148 myColor(color),
149 myRepeat(repeat),
150 myCycleTime(cycleTime),
151 myVClass(vehicleParent->getVClass()) {
152 }
153 
154 
156 
157 
160  return nullptr;
161 }
162 
163 
166  GUIGLObjectPopupMenu* ret = new GNERoutePopupMenu(app, parent, *this);
167  // build header
168  buildPopupHeader(ret, app);
169  // build menu command for center button and copy cursor position to clipboard
171  buildPositionCopyEntry(ret, app);
172  // build menu commands for names
173  GUIDesigns::buildFXMenuCommand(ret, "Copy " + getTagStr() + " name to clipboard", nullptr, ret, MID_COPY_NAME);
174  GUIDesigns::buildFXMenuCommand(ret, "Copy " + getTagStr() + " typed name to clipboard", nullptr, ret, MID_COPY_TYPED_NAME);
175  new FXMenuSeparator(ret);
176  // build selection and show parameters menu
179  // show option to open demand element dialog
180  if (myTagProperty.hasDialog()) {
181  GUIDesigns::buildFXMenuCommand(ret, "Open " + getTagStr() + " Dialog", getACIcon(), &parent, MID_OPEN_ADDITIONAL_DIALOG);
182  new FXMenuSeparator(ret);
183  }
184  GUIDesigns::buildFXMenuCommand(ret, "Cursor position in view: " + toString(getPositionInView().x()) + "," + toString(getPositionInView().y()), nullptr, nullptr, 0);
185  new FXMenuSeparator(ret);
186  GUIDesigns::buildFXMenuCommand(ret, "Apply distance along route", nullptr, ret, MID_GNE_ROUTE_APPLY_DISTANCE);
187  // route length
190  // add reverse
191  buildMenuAddReverse(ret);
192  }
193  return ret;
194 }
195 
196 
197 void
199  device.openTag(SUMO_TAG_ROUTE);
200  // write id only for non-embedded routes
202  device.writeAttr(SUMO_ATTR_ID, getID());
203  }
205  if (myColor != RGBColor::INVISIBLE) {
207  }
208  if (myRepeat != 0) {
210  }
211  if (myCycleTime != 0) {
213  }
214  // write sorted stops
216  // write stops
217  for (const auto& demandElement : getChildDemandElements()) {
218  if (demandElement->getTagProperty().isVehicleStop()) {
219  demandElement->writeDemandElement(device);
220  }
221  }
222  }
223  // write parameters
224  writeParams(device);
225  // close tag
226  device.closeTag();
227 }
228 
229 
232  // get sorted stops and check number
233  std::vector<GNEDemandElement*> stops;
234  for (const auto& routeChild : getChildDemandElements()) {
235  if (routeChild->getTagProperty().isVehicleStop()) {
236  stops.push_back(routeChild);
237  }
238  }
239  // check stops
240  if (getInvalidStops().size() > 0) {
242  }
243  // check repeating
244  if (myRepeat > 0) {
245  // avoid repeat in routes with only one edge
246  if (getParentEdges().size() == 1) {
248  }
249  // check if front and last routes are connected
250  if (isRouteValid({getParentEdges().back(), getParentEdges().front()}).size() > 0) {
252  }
253  }
254  // check that exist a connection between every edge
255  if (isRouteValid(getParentEdges()).size() > 0) {
256  return Problem::INVALID_PATH;
257  } else {
258  return Problem::OK;
259  }
261 }
262 
263 
264 std::string
266  // get sorted stops and check number
267  std::vector<GNEDemandElement*> stops;
268  for (const auto& routeChild : getChildDemandElements()) {
269  if (routeChild->getTagProperty().isVehicleStop()) {
270  stops.push_back(routeChild);
271  }
272  }
273  const auto invalidStops = getInvalidStops();
274  if (invalidStops.size() > 0) {
275  return toString(invalidStops.size()) + " stops are outside of route (downstream)";
276  }
277  // check repeating
278  if (myRepeat > 0) {
279  // avoid repeat in routes with only one edge
280  if (getParentEdges().size() == 1) {
281  return TL("Cannot repeat in routes with only one edge");
282  }
283  // check if front and last routes is connected
284  if (isRouteValid({getParentEdges().back(), getParentEdges().front()}).size() > 0) {
285  return TL("Cannot repeat route; front and last edge aren't connected");
286  }
287  }
288  // return string with the problem obtained from isRouteValid
289  return isRouteValid(getParentEdges());
290 }
291 
292 
293 void
295  // currently the only solution is removing Route
296 }
297 
298 
301  return myVClass;
302 }
303 
304 
305 const RGBColor&
307  if (myColor != RGBColor::INVISIBLE) {
308  return myColor;
309  } else if ((getParentDemandElements().size() > 0) && (getParentDemandElements().front()->getColor() != RGBColor::INVISIBLE)) {
310  return getParentDemandElements().front()->getColor();
311  } else if ((getChildDemandElements().size() > 0) && (getChildDemandElements().front()->getColor() != RGBColor::INVISIBLE)) {
312  return getChildDemandElements().front()->getColor();
313  } else {
314  return RGBColor::YELLOW;
315  }
316 }
317 
318 
319 void
321  // compute geometry
323  // update child demand elements
324  for (const auto& demandElement : getChildDemandElements()) {
325  if (!demandElement->getTagProperty().isVehicleStop()) {
326  demandElement->updateGeometry();
327  }
328  }
329 }
330 
331 
332 Position
335 }
336 
337 
338 std::string
340  return getParentEdges().front()->getID();
341 }
342 
343 
344 double
346  return s.vehicleSize.getExaggeration(s, this);
347 }
348 
349 
350 Boundary
352  Boundary routeBoundary;
353  // return the combination of all parent edges's boundaries
354  for (const auto& i : getParentEdges()) {
355  routeBoundary.add(i->getCenteringBoundary());
356  }
357  // check if is valid
358  if (routeBoundary.isInitialised()) {
359  return routeBoundary;
360  } else {
361  return Boundary(-0.1, -0.1, 0.1, 0.1);
362  }
363 }
364 
365 
366 void
367 GNERoute::splitEdgeGeometry(const double /*splitPosition*/, const GNENetworkElement* originalElement, const GNENetworkElement* newElement, GNEUndoList* undoList) {
368  // obtain new list of route edges
369  std::string newRouteEdges = getNewListOfParents(originalElement, newElement);
370  // update route edges
371  if (newRouteEdges.size() > 0) {
372  setAttribute(SUMO_ATTR_EDGES, newRouteEdges, undoList);
373  }
374 }
375 
376 
377 void
379  // Routes are drawn in drawJunctionPartialGL
380 }
381 
382 
383 void
386  // get parent vehicle
387  const GNEDemandElement* parentVehicle = getParentDemandElements().at(0);
388  // declare lane vector
389  std::vector<GNELane*> lanes;
390  // get first and last path lane
391  GNELane* firstLane = parentVehicle->getFirstPathLane();
392  GNELane* lastLane = parentVehicle->getLastPathLane();
393  // insert first vehicle lane
394  if (firstLane) {
395  lanes.push_back(firstLane);
396  }
397  // add middle lanes
398  for (int i = 1; i < ((int)getParentEdges().size() - 1); i++) {
399  lanes.push_back(getParentEdges().at(i)->getLaneByAllowedVClass(getVClass()));
400  }
401  // insert last vehicle lane
402  if (lastLane) {
403  lanes.push_back(lastLane);
404  }
405  // calculate consecutive path using vClass of vehicle parent
407  } else {
408  // calculate path using SVC_PASSENGER
410  // if path is empty, then calculate path again using SVC_IGNORING
411  if (!myNet->getPathManager()->isPathValid(this)) {
413  }
414  }
415 }
416 
417 
418 void
419 GNERoute::drawLanePartialGL(const GUIVisualizationSettings& s, const GNEPathManager::Segment* segment, const double offsetFront) const {
420  // check conditions
424  // get exaggeration
425  const double exaggeration = getExaggeration(s);
426  // get detail level
427  const auto d = s.getDetailLevel(exaggeration);
428  // get embedded route flag
429  const bool embedded = (myTagProperty.getTag() == GNE_TAG_ROUTE_EMBEDDED);
430  // get route width
431  const double routeWidth = embedded ? s.widthSettings.embeddedRouteWidth : s.widthSettings.routeWidth;
432  // calculate startPos
433  const double geometryDepartPos = embedded ? (getParentDemandElements().at(0)->getAttributeDouble(SUMO_ATTR_DEPARTPOS) + getParentDemandElements().at(0)->getParentDemandElements().at(0)->getAttributeDouble(SUMO_ATTR_LENGTH)) : -1;
434  // get endPos
435  const double geometryEndPos = embedded ? getParentDemandElements().at(0)->getAttributeDouble(SUMO_ATTR_ARRIVALPOS) : -1;
436  // declare path geometry
437  GUIGeometry routeGeometry;
438  // update pathGeometry depending of first and last segment
439  if (segment->isFirstSegment() && segment->isLastSegment()) {
440  routeGeometry.updateGeometry(segment->getLane()->getLaneGeometry().getShape(),
441  geometryDepartPos,
443  geometryEndPos,
445  } else if (segment->isFirstSegment()) {
446  routeGeometry.updateGeometry(segment->getLane()->getLaneGeometry().getShape(),
447  geometryDepartPos,
449  -1,
451  } else if (segment->isLastSegment()) {
452  routeGeometry.updateGeometry(segment->getLane()->getLaneGeometry().getShape(),
453  -1,
455  geometryEndPos,
457  } else {
458  routeGeometry = segment->getLane()->getLaneGeometry();
459  }
460  // draw geometry only if we'rent in drawForObjectUnderCursor mode
461  if (!s.drawForViewObjectsHandler) {
462  // draw route partial lane
463  drawRoutePartialLane(s, d, segment, offsetFront, routeGeometry, exaggeration);
464  // draw name
465  drawName(getCenteringBoundary().getCenter(), s.scale, s.addName);
466  // draw dotted contour
467  segment->getContour()->drawDottedContours(s, d, this, s.dottedContourSettings.segmentWidth, true);
468  }
469  // calculate contour
470  segment->getContour()->calculateContourExtrudedShape(s, d, this, routeGeometry.getShape(), routeWidth, exaggeration,
471  segment->isFirstSegment(), segment->isLastSegment(), 0);
472  }
473 }
474 
475 
476 void
477 GNERoute::drawJunctionPartialGL(const GUIVisualizationSettings& s, const GNEPathManager::Segment* segment, const double offsetFront) const {
478  // check conditions
482  // Obtain exaggeration of the draw
483  const double routeExaggeration = getExaggeration(s);
484  // get detail level
485  const auto d = s.getDetailLevel(routeExaggeration);
486  // get route width
488  // check if connection to next lane exist
489  const bool connectionExist = segment->getPreviousLane()->getLane2laneConnections().exist(segment->getNextLane());
490  // get geometry
491  const GUIGeometry& routeGeometry = connectionExist ? segment->getPreviousLane()->getLane2laneConnections().getLane2laneGeometry(segment->getNextLane()) :
492  GUIGeometry({segment->getPreviousLane()->getLaneShape().back(), segment->getNextLane()->getLaneShape().front()});
493  // draw geometry only if we'rent in drawForObjectUnderCursor mode
494  if (!s.drawForViewObjectsHandler) {
495  // draw route partial
496  drawRoutePartialJunction(s, d, offsetFront, routeGeometry, routeExaggeration);
497  // draw dotted contour
498  segment->getContour()->drawDottedContours(s, d, this, s.dottedContourSettings.segmentWidth, true);
499  }
500  // calculate contour
501  segment->getContour()->calculateContourExtrudedShape(s, d, this, routeGeometry.getShape(), routeWidth, routeExaggeration, false, false, 0);
502  }
503 }
504 
505 
506 GNELane*
509  return getParentEdges().front()->getLaneByAllowedVClass(SVC_PASSENGER);
510  } else {
511  return getParentDemandElements().at(0)->getFirstPathLane();
512  }
513 }
514 
515 
516 GNELane*
519  return getParentEdges().back()->getLaneByAllowedVClass(SVC_PASSENGER);
520  } else {
521  return getParentDemandElements().at(0)->getLastPathLane();
522  }
523 }
524 
525 
526 std::string
528  switch (key) {
529  case SUMO_ATTR_ID:
530  return getMicrosimID();
531  case SUMO_ATTR_EDGES:
532  return parseIDs(getParentEdges());
533  case SUMO_ATTR_COLOR:
534  if (myColor != RGBColor::INVISIBLE) {
535  return toString(myColor);
536  } else {
537  return "";
538  }
539  case SUMO_ATTR_REPEAT:
540  return toString(myRepeat);
541  case SUMO_ATTR_CYCLETIME:
542  return time2string(myCycleTime);
543 
544  case GNE_ATTR_SELECTED:
546  case GNE_ATTR_PARAMETERS:
547  return getParametersStr();
549  return getDistributionParents();
550  default:
551  throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
552  }
553 }
554 
555 
556 double
558  switch (key) {
559  case SUMO_ATTR_DEPARTPOS:
560  return 0;
562  return getParentEdges().back()->getLanes().front()->getLaneShape().length2D();
563  default:
564  throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
565  }
566 }
567 
568 
569 Position
571  switch (key) {
572  case SUMO_ATTR_DEPARTPOS:
573  return getParentEdges().front()->getLanes().front()->getLaneShape().front();
575  return getParentEdges().back()->getLanes().front()->getLaneShape().back();
576  default:
577  throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
578  }
579 }
580 
581 
582 bool
584  switch (key) {
586  return false;
587  default:
588  return true;
589  }
590 }
591 
592 
593 void
594 GNERoute::setAttribute(SumoXMLAttr key, const std::string& value, GNEUndoList* undoList) {
595  if (value == getAttribute(key)) {
596  return; //avoid needless changes, later logic relies on the fact that attributes have changed
597  }
598  switch (key) {
599  case SUMO_ATTR_ID:
600  case SUMO_ATTR_COLOR:
601  case SUMO_ATTR_REPEAT:
602  case SUMO_ATTR_CYCLETIME:
603  case GNE_ATTR_SELECTED:
604  case GNE_ATTR_PARAMETERS:
605  GNEChange_Attribute::changeAttribute(this, key, value, undoList);
606  break;
607  // special case due depart and arrival edge vehicles
608  case SUMO_ATTR_EDGES: {
609  // extract all vehicle childrens
610  std::vector<GNEDemandElement*> vehicles;
611  for (const auto& childDemandElement : getChildDemandElements()) {
612  if (childDemandElement->getTagProperty().isVehicle()) {
613  vehicles.push_back(childDemandElement);
614  }
615  }
616  // check vehicles
617  if (vehicles.size() > 0) {
618  undoList->begin(this, "reset start and end edges");
619  for (const auto& vehicle : vehicles) {
622  }
623  GNEChange_Attribute::changeAttribute(this, key, value, undoList);
624  undoList->end();
625  } else if (myTagProperty.getTag() == GNE_TAG_ROUTE_EMBEDDED) {
626  undoList->begin(this, "reset start and end edges");
629  GNEChange_Attribute::changeAttribute(this, key, value, undoList);
630  undoList->end();
631  } else {
632  // just change edges
633  GNEChange_Attribute::changeAttribute(this, key, value, undoList);
634  }
635  break;
636  }
637  default:
638  throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
639  }
640 }
641 
642 
643 bool
644 GNERoute::isValid(SumoXMLAttr key, const std::string& value) {
645  switch (key) {
646  case SUMO_ATTR_ID:
647  return isValidDemandElementID(value);
648  case SUMO_ATTR_EDGES:
649  if (canParse<std::vector<GNEEdge*> >(myNet, value, false)) {
650  // all edges exist, then check if compounds a valid route
651  return isRouteValid(parse<std::vector<GNEEdge*> >(myNet, value)).empty();
652  } else {
653  return false;
654  }
655  case SUMO_ATTR_COLOR:
656  if (value.empty()) {
657  return true;
658  } else {
659  return canParse<RGBColor>(value);
660  }
661  case SUMO_ATTR_REPEAT:
662  return canParse<int>(value);
663  case SUMO_ATTR_CYCLETIME:
664  if (canParse<SUMOTime>(value)) {
665  return (parse<SUMOTime>(value) >= 0);
666  } else {
667  return false;
668  }
669  case GNE_ATTR_SELECTED:
670  return canParse<bool>(value);
671  case GNE_ATTR_PARAMETERS:
672  return Parameterised::areParametersValid(value);
673  default:
674  throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
675  }
676 }
677 
678 
679 std::string
681  return getTagStr();
682 }
683 
684 
685 std::string
687  return getTagStr() + ": " + getAttribute(SUMO_ATTR_ID) ;
688 }
689 
690 
691 const Parameterised::Map&
693  return getParametersMap();
694 }
695 
696 
697 std::string
698 GNERoute::isRouteValid(const std::vector<GNEEdge*>& edges) {
699  if (edges.size() == 0) {
700  // routes cannot be empty
701  return ("list of route edges cannot be empty");
702  } else if (edges.size() == 1) {
703  // routes with a single edge are valid, then return an empty string
704  return ("");
705  } else {
706  // iterate over edges to check that compounds a chain
707  auto it = edges.begin();
708  while (it != edges.end() - 1) {
709  const GNEEdge* currentEdge = *it;
710  const GNEEdge* nextEdge = *(it + 1);
711  // same consecutive edges aren't allowed
712  if (currentEdge->getID() == nextEdge->getID()) {
713  return ("consecutive duplicated edges (" + currentEdge->getID() + ") aren't allowed in a route");
714  }
715  // obtain outgoing edges of currentEdge
716  const std::vector<GNEEdge*>& outgoingEdges = currentEdge->getToJunction()->getGNEOutgoingEdges();
717  // check if nextEdge is in outgoingEdges
718  if (std::find(outgoingEdges.begin(), outgoingEdges.end(), nextEdge) == outgoingEdges.end()) {
719  return ("Edges '" + currentEdge->getID() + "' and '" + nextEdge->getID() + "' aren't consecutives");
720  }
721  it++;
722  }
723  // all edges consecutives, then return an empty string
724  return ("");
725  }
726 }
727 
729 GNERoute::copyRoute(const GNERoute* originalRoute) {
730  // get net and undoList
731  const auto net = originalRoute->getNet();
732  auto undoList = net->getViewNet()->getUndoList();
733  // generate new route ID
734  const std::string newRouteID = net->getAttributeCarriers()->generateDemandElementID(SUMO_TAG_ROUTE);
735  // create new route
736  GNERoute* newRoute = new GNERoute(net, newRouteID, originalRoute);
737  // add new route using undo-list
738  undoList->begin(originalRoute, TLF("copy % '%'", originalRoute->getTagStr(), newRouteID));
739  net->getViewNet()->getUndoList()->add(new GNEChange_DemandElement(newRoute, true), true);
740  undoList->end();
741  // return new route
742  return newRoute;
743 }
744 
745 // ===========================================================================
746 // private
747 // ===========================================================================
748 
749 void
751  const GNEPathManager::Segment* segment, const double offsetFront,
752  const GUIGeometry& geometry, const double exaggeration) const {
753  // get route width
755  // push layer matrix
757  // Start with the drawing of the area traslating matrix to origin
758  glTranslated(0, 0, getType() + offsetFront);
759  // Set color
760  if (drawUsingSelectColor()) {
762  } else {
764  }
765  // draw geometry
766  GUIGeometry::drawGeometry(d, geometry, routeWidth * exaggeration);
767  // check if we have to draw a red line to the next segment
768  if (segment->getNextLane()) {
769  // push draw matrix
771  // Set red color
773  // get firstPosition (last position of current lane shape)
774  const Position firstPosition = segment->getLane()->getLaneShape().back();
775  // get lastPosition (first position of next lane shape)
776  const Position arrivalPos = segment->getNextLane()->getLaneShape().front();
777  // draw box line
778  GLHelper::drawBoxLine(arrivalPos,
779  RAD2DEG(firstPosition.angleTo2D(arrivalPos)) - 90,
780  firstPosition.distanceTo2D(arrivalPos), .05);
781  // pop draw matrix
783  }
784  // Pop layer matrix
786 }
787 
788 
789 void
791  const double offsetFront, const GUIGeometry& geometry, const double exaggeration) const {
792  const bool invalid = geometry.getShape().length() == 2;
793  // get route width
795  // Add a draw matrix
797  // Start with the drawing of the area traslating matrix to origin
798  glTranslated(0, 0, getType() + offsetFront);
799  // Set color of the base
800  if (drawUsingSelectColor()) {
802  } else if (invalid) {
804  } else {
806  }
807  // draw geometry
808  GUIGeometry::drawGeometry(d, geometry, routeWidth * exaggeration);
809  // Pop last matrix
811 }
812 
813 
814 void
815 GNERoute::setAttribute(SumoXMLAttr key, const std::string& value) {
816  switch (key) {
817  case SUMO_ATTR_ID:
818  // update microsimID
819  setDemandElementID(value);
820  break;
821  case SUMO_ATTR_EDGES:
823  // compute route
825  // update all parent and child demand elements
826  for (const auto& element : getParentDemandElements()) {
827  element->updateGeometry();
828  }
829  for (const auto& element : getChildDemandElements()) {
830  element->updateGeometry();
831  }
832  break;
833  case SUMO_ATTR_COLOR:
834  if (value.empty()) {
836  } else {
837  myColor = parse<RGBColor>(value);
838  }
839  break;
840  case SUMO_ATTR_REPEAT:
841  myRepeat = parse<int>(value);
842  break;
843  case SUMO_ATTR_CYCLETIME:
844  myCycleTime = string2time(value);
845  break;
846  case GNE_ATTR_SELECTED:
847  if (parse<bool>(value)) {
849  } else {
851  }
852  break;
853  case GNE_ATTR_PARAMETERS:
854  setParametersStr(value);
855  break;
856  default:
857  throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
858  }
859 }
860 
861 
862 void
863 GNERoute::setMoveShape(const GNEMoveResult& /*moveResult*/) {
864  // routes cannot be moved
865 }
866 
867 
868 void
869 GNERoute::commitMoveShape(const GNEMoveResult& /*moveResult*/, GNEUndoList* /*undoList*/) {
870  // routes cannot be moved
871 }
872 
873 /****************************************************************************/
FXDEFMAP(GNERoute::GNERoutePopupMenu) GNERoutePopupMenuMap[]
long long int SUMOTime
Definition: GUI.h:35
@ MID_COPY_TYPED_NAME
Copy typed object name - popup entry.
Definition: GUIAppEnum.h:453
@ 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
@ MID_GNE_ROUTE_APPLY_DISTANCE
apply distance
Definition: GUIAppEnum.h:1358
@ GLO_ROUTE
a route
GUIIcon
An enumeration of icons used by the gui applications.
Definition: GUIIcons.h:33
#define RAD2DEG(x)
Definition: GeomHelper.h:36
#define TL(string)
Definition: MsgHandler.h:315
#define TLF(string,...)
Definition: MsgHandler.h:317
SUMOTime string2time(const std::string &r)
convert string to SUMOTime
Definition: SUMOTime.cpp:46
std::string time2string(SUMOTime t, bool humanReadable)
convert SUMOTime to string (independently of global format setting)
Definition: SUMOTime.cpp:69
SUMOVehicleClass
Definition of vehicle classes to differ between different lane usage and authority types.
@ SVC_IGNORING
vehicles ignoring classes
@ SVC_PASSENGER
vehicle is a passenger car (a "normal" car)
SumoXMLTag
Numbers representing SUMO-XML - element names.
@ SUMO_TAG_ROUTE
begin/end of the description of a route
@ GNE_TAG_ROUTE_EMBEDDED
embedded route
SumoXMLAttr
Numbers representing SUMO-XML - attributes.
@ SUMO_ATTR_DEPARTEDGE
@ SUMO_ATTR_ARRIVALEDGE
@ SUMO_ATTR_ARRIVALPOS
@ GNE_ATTR_SELECTED
element is selected
@ SUMO_ATTR_EDGES
the edges of a route
@ GNE_ATTR_PARAMETERS
parameters "key1=value1|key2=value2|...|keyN=valueN"
@ SUMO_ATTR_DEPARTPOS
@ SUMO_ATTR_DISTANCE
@ SUMO_ATTR_LENGTH
@ SUMO_ATTR_COLOR
A color information.
@ SUMO_ATTR_ID
@ GNE_ATTR_ROUTE_DISTRIBUTION
route distribution
@ SUMO_ATTR_REPEAT
@ SUMO_ATTR_CYCLETIME
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
Definition: ToString.h:46
A class that stores a 2D geometrical boundary.
Definition: Boundary.h:39
void add(double x, double y, double z=0)
Makes the boundary include the given coordinate.
Definition: Boundary.cpp:78
bool isInitialised() const
check if Boundary is Initialised
Definition: Boundary.cpp:235
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
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
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
void unselectAttributeCarrier(const bool changeFlag=true)
unselect attribute carrier using GUIGlobalSelection
bool drawUsingSelectColor() const
check if attribute carrier must be drawn using selecting color.
static bool canParse(const std::string &string)
true if a value of type T can be parsed from string
GNENet * myNet
pointer to net
GNENet * getNet() const
get pointer to net
static std::string parseIDs(const std::vector< T > &ACs)
parses a list of specific Attribute Carriers into a string of IDs
void selectAttributeCarrier(const bool changeFlag=true)
select attribute carrier using GUIGlobalSelection
const GNETagProperties & myTagProperty
reference to tagProperty associated with this attribute carrier
static void changeAttribute(GNEAttributeCarrier *AC, SumoXMLAttr key, const std::string &value, GNEUndoList *undoList, const bool force=false)
change attribute
void calculateContourExtrudedShape(const GUIVisualizationSettings &s, const GUIVisualizationSettings::Detail d, const GUIGlObject *glObject, const PositionVector &shape, const double extrusionWidth, const double scale, const bool closeFirstExtrem, const bool closeLastExtrem, const double offset) const
calculate contour extruded (used in elements formed by a central shape)
Definition: GNEContour.cpp:88
void drawDottedContours(const GUIVisualizationSettings &s, const GUIVisualizationSettings::Detail d, const GNEAttributeCarrier *AC, const double lineWidth, const bool addOffset) const
drawing contour functions
Definition: GNEContour.cpp:265
void buildMenuCommandRouteLength(GUIGLObjectPopupMenu *ret) const
build menu command route length
void replaceDemandParentEdges(const std::string &value)
replace demand parent edges
std::vector< GNEDemandElement * > getInvalidStops() const
get invalid stops
std::string getDistributionParents() const
get distribution in which the given element is part
virtual GNELane * getLastPathLane() const =0
get last path lane
bool isValidDemandElementID(const std::string &value) const
check if a new demand element ID is valid
void setDemandElementID(const std::string &newID)
set demand element id
void buildMenuAddReverse(GUIGLObjectPopupMenu *ret) const
build menu command route length
virtual GNELane * getFirstPathLane() const =0
get first path lane
Problem
enum class for demandElement problems
A road/street connecting two junctions (netedit-version)
Definition: GNEEdge.h:53
GNEJunction * getToJunction() const
get from Junction (only used to increase readability)
Definition: GNEEdge.h:82
const std::vector< GNEDemandElement * > & getChildDemandElements() const
return child demand elements
const std::vector< GNEDemandElement * > & getParentDemandElements() const
get parent demand elements
const std::vector< GNEEdge * > & getParentEdges() const
get parent edges
std::string getNewListOfParents(const GNENetworkElement *currentElement, const GNENetworkElement *newNextElement) const
if use edge/parent lanes as a list of consecutive elements, obtain a list of IDs of elements after in...
const std::vector< GNEEdge * > & getGNEOutgoingEdges() const
Returns incoming GNEEdges.
bool exist(const GNELane *toLane) const
check if exist a lane2lane geometry for the given toLane
const GUIGeometry & getLane2laneGeometry(const GNELane *toLane) const
get lane2lane geometry
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
const GNELane2laneConnection & getLane2laneConnections() const
get Lane2laneConnection struct
Definition: GNELane.cpp:684
Position getPositionInView() const
Returns position of hierarchical element in view.
Definition: GNELane.cpp:319
const GUIGeometry & getLaneGeometry() const
get lane geometry
Definition: GNELane.cpp:208
move operation
move result
A NBNetBuilder extended by visualisation and editing capabilities.
Definition: GNENet.h:42
GNEPathManager * getPathManager()
get path manager
Definition: GNENet.cpp:134
GNEViewNet * getViewNet() const
get view net
Definition: GNENet.cpp:2055
bool checkDrawPathGeometry(const GUIVisualizationSettings &s, const GNELane *lane, SumoXMLTag tag)
check if path element geometry must be drawn in the given lane
PathElement()=delete
invalidate default constructor
const GNELane * getPreviousLane() const
get previous lane
GNEContour * getContour() const
getcontour associated with segment
const GNELane * getNextLane() const
get next lane
const GNELane * getLane() const
get lane associated with this segment
bool isLastSegment() const
check if segment is the last path's segment
bool isFirstSegment() const
check if segment is the first path's segment
PathDraw * getPathDraw()
obtain instance of PathDraw
void calculateConsecutivePathEdges(PathElement *pathElement, SUMOVehicleClass vClass, const std::vector< GNEEdge * > edges)
calculate consecutive path edges
bool isPathValid(const PathElement *pathElement) const
check if path element is valid
void calculateConsecutivePathLanes(PathElement *pathElement, const std::vector< GNELane * > lanes)
calculate consecutive path lanes
class used in GUIGLObjectPopupMenu for routes
Definition: GNERoute.h:45
~GNERoutePopupMenu()
Destructor.
Definition: GNERoute.cpp:55
long onCmdApplyDistance(FXObject *, FXSelector, void *)
Called to modify edge distance values along the route.
Definition: GNERoute.cpp:59
std::string getHierarchyName() const
get Hierarchy Name (Used in AC Hierarchy)
Definition: GNERoute.cpp:686
void fixDemandElementProblem()
fix demand element problem (by default throw an exception, has to be reimplemented in children)
Definition: GNERoute.cpp:294
double getExaggeration(const GUIVisualizationSettings &s) const
return exaggeration associated with this GLObject
Definition: GNERoute.cpp:345
GNELane * getLastPathLane() const
get last path lane
Definition: GNERoute.cpp:517
Position getPositionInView() const
Returns position of additional in view.
Definition: GNERoute.cpp:333
SUMOVehicleClass myVClass
SUMOVehicleClass (Only used for drawing)
Definition: GNERoute.h:279
std::string getParentName() const
Returns the name of the parent object.
Definition: GNERoute.cpp:339
SUMOTime myCycleTime
cycleTime
Definition: GNERoute.h:276
std::string getPopUpID() const
get PopPup ID (Used in AC Hierarchy)
Definition: GNERoute.cpp:680
std::string getAttribute(SumoXMLAttr key) const
inherited from GNEAttributeCarrier
Definition: GNERoute.cpp:527
Position getAttributePosition(SumoXMLAttr key) const
Definition: GNERoute.cpp:570
void updateGeometry()
update pre-computed geometry information
Definition: GNERoute.cpp:320
GUIGLObjectPopupMenu * getPopUpMenu(GUIMainWindow &app, GUISUMOAbstractView &parent)
Returns an own popup-menu.
Definition: GNERoute.cpp:165
void drawLanePartialGL(const GUIVisualizationSettings &s, const GNEPathManager::Segment *segment, const double offsetFront) const
Draws partial object over lane.
Definition: GNERoute.cpp:419
void drawRoutePartialJunction(const GUIVisualizationSettings &s, const GUIVisualizationSettings::Detail d, const double offsetFront, const GUIGeometry &geometry, const double exaggeration) const
draw route partial junction
Definition: GNERoute.cpp:790
void splitEdgeGeometry(const double splitPosition, const GNENetworkElement *originalElement, const GNENetworkElement *newElement, GNEUndoList *undoList)
split geometry
Definition: GNERoute.cpp:367
void setMoveShape(const GNEMoveResult &moveResult)
set move shape
Definition: GNERoute.cpp:863
const Parameterised::Map & getACParametersMap() const
get parameters map
Definition: GNERoute.cpp:692
static GNEDemandElement * copyRoute(const GNERoute *originalRoute)
create a copy of the given route
Definition: GNERoute.cpp:729
GNELane * getFirstPathLane() const
get first path lane
Definition: GNERoute.cpp:507
void drawRoutePartialLane(const GUIVisualizationSettings &s, const GUIVisualizationSettings::Detail d, const GNEPathManager::Segment *segment, const double offsetFront, const GUIGeometry &geometry, const double exaggeration) const
draw route partial lane
Definition: GNERoute.cpp:750
double getAttributeDouble(SumoXMLAttr key) const
Definition: GNERoute.cpp:557
GNEMoveOperation * getMoveOperation()
get move operation
Definition: GNERoute.cpp:159
void commitMoveShape(const GNEMoveResult &moveResult, GNEUndoList *undoList)
commit move shape
Definition: GNERoute.cpp:869
SUMOVehicleClass getVClass() const
obtain VClass related with this demand element
Definition: GNERoute.cpp:300
GNERoute(SumoXMLTag tag, GNENet *net)
default constructor
Definition: GNERoute.cpp:76
Boundary getCenteringBoundary() const
Returns the boundary to which the view shall be centered in order to show the object.
Definition: GNERoute.cpp:351
bool isValid(SumoXMLAttr key, const std::string &value)
method for checking if the key and their conrrespond attribute are valids
Definition: GNERoute.cpp:644
void drawGL(const GUIVisualizationSettings &s) const
Draws the object.
Definition: GNERoute.cpp:378
static std::string isRouteValid(const std::vector< GNEEdge * > &edges)
check if a route is valid
Definition: GNERoute.cpp:698
void setAttribute(SumoXMLAttr key, const std::string &value, GNEUndoList *undoList)
method for setting the attribute and letting the object perform demand element changes
Definition: GNERoute.cpp:594
int myRepeat
repeat
Definition: GNERoute.h:273
void computePathElement()
compute pathElement
Definition: GNERoute.cpp:384
std::string getDemandElementProblem() const
return a string with the current demand element problem (by default empty, can be reimplemented in ch...
Definition: GNERoute.cpp:265
RGBColor myColor
route color
Definition: GNERoute.h:270
void writeDemandElement(OutputDevice &device) const
write demand element element into a xml file
Definition: GNERoute.cpp:198
~GNERoute()
destructor
Definition: GNERoute.cpp:155
bool isAttributeEnabled(SumoXMLAttr key) const
Definition: GNERoute.cpp:583
const RGBColor & getColor() const
get color
Definition: GNERoute.cpp:306
void drawJunctionPartialGL(const GUIVisualizationSettings &s, const GNEPathManager::Segment *segment, const double offsetFront) const
Draws partial object over junction.
Definition: GNERoute.cpp:477
Problem isDemandElementValid() const
check if current demand element is valid to be written into XML (by default true, can be reimplemente...
Definition: GNERoute.cpp:231
SumoXMLTag getTag() const
get Tag vinculated with this attribute Property
bool hasDialog() const
return true if tag correspond to an element that can be edited using a dialog
void end()
End undo command sub-group. If the sub-group is still empty, it will be deleted; otherwise,...
void begin(GUIIcon icon, const std::string &description)
Begin undo command sub-group with current supermode. This begins a new group of commands that are tre...
const GNEViewNetHelper::DataViewOptions & getDataViewOptions() const
get data view options
Definition: GNEViewNet.cpp:727
const GNEViewNetHelper::EditModes & getEditModes() const
get edit modes
Definition: GNEViewNet.cpp:703
const GNEViewNetHelper::NetworkViewOptions & getNetworkViewOptions() const
get network view options
Definition: GNEViewNet.cpp:715
GNEUndoList * getUndoList() const
get the undoList object
void buildSelectionACPopupEntry(GUIGLObjectPopupMenu *ret, GNEAttributeCarrier *AC)
Builds an entry which allows to (de)select the object.
Definition: GNEViewNet.cpp:538
const GNEViewNetHelper::DemandViewOptions & getDemandViewOptions() const
get demand view options
Definition: GNEViewNet.cpp:721
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.
static void drawGeometry(const GUIVisualizationSettings::Detail d, const GUIGeometry &geometry, const double width, double offset=0)
draw geometry
const PositionVector & getShape() const
The shape of the additional element.
void updateGeometry(const PositionVector &shape)
update entire geometry
Definition: GUIGeometry.cpp:59
void buildShowParamsPopupEntry(GUIGLObjectPopupMenu *ret, bool addSeparator=true)
Builds an entry which allows to open the parameter window.
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
const std::string & getMicrosimID() const
Returns the id of the object as known to microsim.
Definition: GUIGlObject.h:143
void buildPositionCopyEntry(GUIGLObjectPopupMenu *ret, const GUIMainWindow &app) const
Builds an entry which allows to copy the cursor position if geo projection is used,...
void drawName(const Position &pos, const double scale, const GUIVisualizationTextSettings &settings, const double angle=0, bool forceShow=false) const
draw name of item
Stores the information about how to visualize structures.
GUIVisualizationTextSettings addName
GUIVisualizationSizeSettings vehicleSize
GUIVisualizationWidthSettings widthSettings
width settings
Detail getDetailLevel(const double exaggeration) const
return the detail level
GUIVisualizationColorSettings colorSettings
color settings
GUIVisualizationDottedContourSettings dottedContourSettings
dotted contour settings
double scale
information about a lane's width (temporary, used for a single view)
bool drawForViewObjectsHandler
whether drawing is performed for the purpose of selecting objects in view using ViewObjectsHandler
Static storage of an output device and its base (abstract) implementation.
Definition: OutputDevice.h:61
OutputDevice & openTag(const std::string &xmlElement)
Opens an XML tag.
OutputDevice & writeAttr(const SumoXMLAttr attr, const T &val)
writes a named attribute
Definition: OutputDevice.h:254
bool closeTag(const std::string &comment="")
Closes the most recently opened tag and optionally adds a comment.
An upper class for objects with additional parameters.
Definition: Parameterised.h:41
static bool areParametersValid(const std::string &value, bool report=false, const std::string kvsep="=", const std::string sep="|")
check if given string can be parsed to a parameters map "key1=value1|key2=value2|....
std::map< std::string, std::string > Map
parameters map
Definition: Parameterised.h:45
void setParametersStr(const std::string &paramsString, const std::string kvsep="=", const std::string sep="|")
set the inner key/value map in string format "key1=value1|key2=value2|...|keyN=valueN"
const Parameterised::Map & getParametersMap() const
Returns the inner key/value map.
void writeParams(OutputDevice &device) const
write Params in the given outputdevice
std::string getParametersStr(const std::string kvsep="=", const std::string sep="|") const
Returns the inner key/value map in string format "key1=value1|key2=value2|...|keyN=valueN".
A point in 2D or 3D with translation and scaling methods.
Definition: Position.h:37
static const Position INVALID
used to indicate that a position is valid
Definition: Position.h:317
double distanceTo2D(const Position &p2) const
returns the euclidean distance in the x-y-plane
Definition: Position.h:271
double angleTo2D(const Position &other) const
returns the angle in the plane of the vector pointing from here to the other position (in radians bet...
Definition: Position.h:281
double length() const
Returns the length.
static const RGBColor YELLOW
Definition: RGBColor.h:188
static const RGBColor INVISIBLE
Definition: RGBColor.h:195
static const RGBColor RED
named colors
Definition: RGBColor.h:185
bool showDemandElements() const
check if show demand elements checkbox is enabled
bool showNonInspectedDemandElements(const GNEDemandElement *demandElement) const
check if non inspected element has to be hidden
bool isCurrentSupermodeDemand() const
@check if current supermode is Demand
bool showDemandElements() const
check if show demand elements checkbox is enabled
RGBColor selectedRouteColor
route selection color (used for routes and vehicle stops)
RGBColor selectedAdditionalColor
additional selection color (busStops, Detectors...)
static const double segmentWidth
width of dotted contour segments
double getExaggeration(const GUIVisualizationSettings &s, const GUIGlObject *o, double factor=20) const
return the drawing size including exaggeration and constantSize values
static const double embeddedRouteWidth
width for embeddedroutes
static const double routeWidth
width for routes