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
385  const auto vClass = myTagProperty.getTag() == GNE_TAG_ROUTE_EMBEDDED ? getVClass() : SVC_PASSENGER;
386  // calculate path
388  // if path is empty, then calculate path again using SVC_IGNORING
389  if (!myNet->getPathManager()->isPathValid(this)) {
391  }
392 }
393 
394 
395 void
396 GNERoute::drawLanePartialGL(const GUIVisualizationSettings& s, const GNEPathManager::Segment* segment, const double offsetFront) const {
397  // check conditions
401  // get exaggeration
402  const double exaggeration = getExaggeration(s);
403  // get detail level
404  const auto d = s.getDetailLevel(exaggeration);
405  // get embedded route flag
406  const bool embedded = (myTagProperty.getTag() == GNE_TAG_ROUTE_EMBEDDED);
407  // get route width
408  const double routeWidth = embedded ? s.widthSettings.embeddedRouteWidth : s.widthSettings.routeWidth;
409  // calculate startPos
410  const double geometryDepartPos = embedded ? (getParentDemandElements().at(0)->getAttributeDouble(SUMO_ATTR_DEPARTPOS) + getParentDemandElements().at(0)->getParentDemandElements().at(0)->getAttributeDouble(SUMO_ATTR_LENGTH)) : -1;
411  // get endPos
412  const double geometryEndPos = embedded ? getParentDemandElements().at(0)->getAttributeDouble(SUMO_ATTR_ARRIVALPOS) : -1;
413  // declare path geometry
414  GUIGeometry routeGeometry;
415  // update pathGeometry depending of first and last segment
416  if (segment->isFirstSegment() && segment->isLastSegment()) {
417  routeGeometry.updateGeometry(segment->getLane()->getLaneGeometry().getShape(),
418  geometryDepartPos,
420  geometryEndPos,
422  } else if (segment->isFirstSegment()) {
423  routeGeometry.updateGeometry(segment->getLane()->getLaneGeometry().getShape(),
424  geometryDepartPos,
426  -1,
428  } else if (segment->isLastSegment()) {
429  routeGeometry.updateGeometry(segment->getLane()->getLaneGeometry().getShape(),
430  -1,
432  geometryEndPos,
434  } else {
435  routeGeometry = segment->getLane()->getLaneGeometry();
436  }
437  // draw geometry only if we'rent in drawForObjectUnderCursor mode
439  // draw route partial lane
440  drawRoutePartialLane(s, d, segment, offsetFront, routeGeometry, exaggeration);
441  // draw name
442  drawName(getCenteringBoundary().getCenter(), s.scale, s.addName);
443  // draw dotted contour
444  segment->getContour()->drawDottedContours(s, d, this, s.dottedContourSettings.segmentWidth, true);
445  }
446  // calculate contour
447  segment->getContour()->calculateContourExtrudedShape(s, d, this, routeGeometry.getShape(), routeWidth, exaggeration,
448  segment->isFirstSegment(), segment->isLastSegment(), 0);
449  }
450 }
451 
452 
453 void
454 GNERoute::drawJunctionPartialGL(const GUIVisualizationSettings& s, const GNEPathManager::Segment* segment, const double offsetFront) const {
455  // check conditions
459  // Obtain exaggeration of the draw
460  const double routeExaggeration = getExaggeration(s);
461  // get detail level
462  const auto d = s.getDetailLevel(routeExaggeration);
463  // get route width
465  // check if connection to next lane exist
466  const bool connectionExist = segment->getPreviousLane()->getLane2laneConnections().exist(segment->getNextLane());
467  // get geometry
468  const GUIGeometry& routeGeometry = connectionExist ? segment->getPreviousLane()->getLane2laneConnections().getLane2laneGeometry(segment->getNextLane()) :
469  GUIGeometry({segment->getPreviousLane()->getLaneShape().back(), segment->getNextLane()->getLaneShape().front()});
470  // draw geometry only if we'rent in drawForObjectUnderCursor mode
472  // draw route partial
473  drawRoutePartialJunction(s, d, offsetFront, routeGeometry, routeExaggeration);
474  // draw dotted contour
475  segment->getContour()->drawDottedContours(s, d, this, s.dottedContourSettings.segmentWidth, true);
476  }
477  // calculate contour
478  segment->getContour()->calculateContourExtrudedShape(s, d, this, routeGeometry.getShape(), routeWidth, routeExaggeration, false, false, 0);
479  }
480 }
481 
482 
483 GNELane*
486  return getParentEdges().front()->getLaneByAllowedVClass(SVC_PASSENGER);
487  } else {
488  return getParentDemandElements().at(0)->getFirstPathLane();
489  }
490 }
491 
492 
493 GNELane*
496  return getParentEdges().back()->getLaneByAllowedVClass(SVC_PASSENGER);
497  } else {
498  return getParentDemandElements().at(0)->getLastPathLane();
499  }
500 }
501 
502 
503 std::string
505  switch (key) {
506  case SUMO_ATTR_ID:
507  return getMicrosimID();
508  case SUMO_ATTR_EDGES:
509  return parseIDs(getParentEdges());
510  case SUMO_ATTR_COLOR:
511  if (myColor != RGBColor::INVISIBLE) {
512  return toString(myColor);
513  } else {
514  return "";
515  }
516  case SUMO_ATTR_REPEAT:
517  return toString(myRepeat);
518  case SUMO_ATTR_CYCLETIME:
519  return time2string(myCycleTime);
520 
521  case GNE_ATTR_SELECTED:
523  case GNE_ATTR_PARAMETERS:
524  return getParametersStr();
526  return getDistributionParents();
527  default:
528  throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
529  }
530 }
531 
532 
533 double
535  switch (key) {
536  case SUMO_ATTR_DEPARTPOS:
537  return 0;
539  return getParentEdges().back()->getLanes().front()->getLaneShape().length2D();
540  default:
541  throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
542  }
543 }
544 
545 
546 Position
548  switch (key) {
549  case SUMO_ATTR_DEPARTPOS:
550  return getParentEdges().front()->getLanes().front()->getLaneShape().front();
552  return getParentEdges().back()->getLanes().front()->getLaneShape().back();
553  default:
554  throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
555  }
556 }
557 
558 
559 bool
561  switch (key) {
563  return false;
564  default:
565  return true;
566  }
567 }
568 
569 
570 void
571 GNERoute::setAttribute(SumoXMLAttr key, const std::string& value, GNEUndoList* undoList) {
572  if (value == getAttribute(key)) {
573  return; //avoid needless changes, later logic relies on the fact that attributes have changed
574  }
575  switch (key) {
576  case SUMO_ATTR_ID:
577  case SUMO_ATTR_COLOR:
578  case SUMO_ATTR_REPEAT:
579  case SUMO_ATTR_CYCLETIME:
580  case GNE_ATTR_SELECTED:
581  case GNE_ATTR_PARAMETERS:
582  GNEChange_Attribute::changeAttribute(this, key, value, undoList);
583  break;
584  // special case due depart and arrival edge vehicles
585  case SUMO_ATTR_EDGES: {
586  // extract all vehicle childrens
587  std::vector<GNEDemandElement*> vehicles;
588  for (const auto& childDemandElement : getChildDemandElements()) {
589  if (childDemandElement->getTagProperty().isVehicle()) {
590  vehicles.push_back(childDemandElement);
591  }
592  }
593  // check vehicles
594  if (vehicles.size() > 0) {
595  undoList->begin(this, "reset start and end edges");
596  for (const auto& vehicle : vehicles) {
599  }
600  GNEChange_Attribute::changeAttribute(this, key, value, undoList);
601  undoList->end();
602  } else if (myTagProperty.getTag() == GNE_TAG_ROUTE_EMBEDDED) {
603  undoList->begin(this, "reset start and end edges");
606  GNEChange_Attribute::changeAttribute(this, key, value, undoList);
607  undoList->end();
608  } else {
609  // just change edges
610  GNEChange_Attribute::changeAttribute(this, key, value, undoList);
611  }
612  break;
613  }
614  default:
615  throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
616  }
617 }
618 
619 
620 bool
621 GNERoute::isValid(SumoXMLAttr key, const std::string& value) {
622  switch (key) {
623  case SUMO_ATTR_ID:
624  return isValidDemandElementID(value);
625  case SUMO_ATTR_EDGES:
626  if (canParse<std::vector<GNEEdge*> >(myNet, value, false)) {
627  // all edges exist, then check if compounds a valid route
628  return isRouteValid(parse<std::vector<GNEEdge*> >(myNet, value)).empty();
629  } else {
630  return false;
631  }
632  case SUMO_ATTR_COLOR:
633  if (value.empty()) {
634  return true;
635  } else {
636  return canParse<RGBColor>(value);
637  }
638  case SUMO_ATTR_REPEAT:
639  return canParse<int>(value);
640  case SUMO_ATTR_CYCLETIME:
641  if (canParse<SUMOTime>(value)) {
642  return (parse<SUMOTime>(value) >= 0);
643  } else {
644  return false;
645  }
646  case GNE_ATTR_SELECTED:
647  return canParse<bool>(value);
648  case GNE_ATTR_PARAMETERS:
649  return Parameterised::areParametersValid(value);
650  default:
651  throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
652  }
653 }
654 
655 
656 std::string
658  return getTagStr();
659 }
660 
661 
662 std::string
664  return getTagStr() + ": " + getAttribute(SUMO_ATTR_ID) ;
665 }
666 
667 
668 const Parameterised::Map&
670  return getParametersMap();
671 }
672 
673 
674 std::string
675 GNERoute::isRouteValid(const std::vector<GNEEdge*>& edges) {
676  if (edges.size() == 0) {
677  // routes cannot be empty
678  return ("list of route edges cannot be empty");
679  } else if (edges.size() == 1) {
680  // routes with a single edge are valid, then return an empty string
681  return ("");
682  } else {
683  // iterate over edges to check that compounds a chain
684  auto it = edges.begin();
685  while (it != edges.end() - 1) {
686  const GNEEdge* currentEdge = *it;
687  const GNEEdge* nextEdge = *(it + 1);
688  // same consecutive edges aren't allowed
689  if (currentEdge->getID() == nextEdge->getID()) {
690  return ("consecutive duplicated edges (" + currentEdge->getID() + ") aren't allowed in a route");
691  }
692  // obtain outgoing edges of currentEdge
693  const std::vector<GNEEdge*>& outgoingEdges = currentEdge->getToJunction()->getGNEOutgoingEdges();
694  // check if nextEdge is in outgoingEdges
695  if (std::find(outgoingEdges.begin(), outgoingEdges.end(), nextEdge) == outgoingEdges.end()) {
696  return ("Edges '" + currentEdge->getID() + "' and '" + nextEdge->getID() + "' aren't consecutives");
697  }
698  it++;
699  }
700  // all edges consecutives, then return an empty string
701  return ("");
702  }
703 }
704 
706 GNERoute::copyRoute(const GNERoute* originalRoute) {
707  // get net and undoList
708  const auto net = originalRoute->getNet();
709  auto undoList = net->getViewNet()->getUndoList();
710  // generate new route ID
711  const std::string newRouteID = net->getAttributeCarriers()->generateDemandElementID(SUMO_TAG_ROUTE);
712  // create new route
713  GNERoute* newRoute = new GNERoute(net, newRouteID, originalRoute);
714  // add new route using undo-list
715  undoList->begin(originalRoute, TLF("copy % '%'", originalRoute->getTagStr(), newRouteID));
716  net->getViewNet()->getUndoList()->add(new GNEChange_DemandElement(newRoute, true), true);
717  undoList->end();
718  // return new route
719  return newRoute;
720 }
721 
722 // ===========================================================================
723 // private
724 // ===========================================================================
725 
726 void
728  const GNEPathManager::Segment* segment, const double offsetFront,
729  const GUIGeometry& geometry, const double exaggeration) const {
730  // get route width
732  // push layer matrix
734  // Start with the drawing of the area traslating matrix to origin
735  glTranslated(0, 0, getType() + offsetFront);
736  // Set color
737  if (drawUsingSelectColor()) {
739  } else {
741  }
742  // draw geometry
743  GUIGeometry::drawGeometry(d, geometry, routeWidth * exaggeration);
744  // check if we have to draw a red line to the next segment
745  if (segment->getNextLane()) {
746  // push draw matrix
748  // Set red color
750  // get firstPosition (last position of current lane shape)
751  const Position firstPosition = segment->getLane()->getLaneShape().back();
752  // get lastPosition (first position of next lane shape)
753  const Position arrivalPos = segment->getNextLane()->getLaneShape().front();
754  // draw box line
755  GLHelper::drawBoxLine(arrivalPos,
756  RAD2DEG(firstPosition.angleTo2D(arrivalPos)) - 90,
757  firstPosition.distanceTo2D(arrivalPos), .05);
758  // pop draw matrix
760  }
761  // Pop layer matrix
763 }
764 
765 
766 void
768  const double offsetFront, const GUIGeometry& geometry, const double exaggeration) const {
769  const bool invalid = geometry.getShape().length() == 2;
770  // get route width
772  // Add a draw matrix
774  // Start with the drawing of the area traslating matrix to origin
775  glTranslated(0, 0, getType() + offsetFront);
776  // Set color of the base
777  if (drawUsingSelectColor()) {
779  } else if (invalid) {
781  } else {
783  }
784  // draw geometry
785  GUIGeometry::drawGeometry(d, geometry, routeWidth * exaggeration);
786  // Pop last matrix
788 }
789 
790 
791 void
792 GNERoute::setAttribute(SumoXMLAttr key, const std::string& value) {
793  switch (key) {
794  case SUMO_ATTR_ID:
795  // update microsimID
796  setDemandElementID(value);
797  break;
798  case SUMO_ATTR_EDGES:
800  // compute route
802  // update all parent and child demand elements
803  for (const auto& element : getParentDemandElements()) {
804  element->updateGeometry();
805  }
806  for (const auto& element : getChildDemandElements()) {
807  element->updateGeometry();
808  }
809  break;
810  case SUMO_ATTR_COLOR:
811  if (value.empty()) {
813  } else {
814  myColor = parse<RGBColor>(value);
815  }
816  break;
817  case SUMO_ATTR_REPEAT:
818  myRepeat = parse<int>(value);
819  break;
820  case SUMO_ATTR_CYCLETIME:
821  myCycleTime = string2time(value);
822  break;
823  case GNE_ATTR_SELECTED:
824  if (parse<bool>(value)) {
826  } else {
828  }
829  break;
830  case GNE_ATTR_PARAMETERS:
831  setParametersStr(value);
832  break;
833  default:
834  throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
835  }
836 }
837 
838 
839 void
840 GNERoute::setMoveShape(const GNEMoveResult& /*moveResult*/) {
841  // routes cannot be moved
842 }
843 
844 
845 void
846 GNERoute::commitMoveShape(const GNEMoveResult& /*moveResult*/, GNEUndoList* /*undoList*/) {
847  // routes cannot be moved
848 }
849 
850 /****************************************************************************/
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:455
@ 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
@ MID_GNE_ROUTE_APPLY_DISTANCE
apply distance
Definition: GUIAppEnum.h:1384
@ 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
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
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:657
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:135
GNEViewNet * getViewNet() const
get view net
Definition: GNENet.cpp:2136
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
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:663
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:494
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:657
std::string getAttribute(SumoXMLAttr key) const
inherited from GNEAttributeCarrier
Definition: GNERoute.cpp:504
Position getAttributePosition(SumoXMLAttr key) const
Definition: GNERoute.cpp:547
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:396
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:767
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:840
const Parameterised::Map & getACParametersMap() const
get parameters map
Definition: GNERoute.cpp:669
static GNEDemandElement * copyRoute(const GNERoute *originalRoute)
create a copy of the given route
Definition: GNERoute.cpp:706
GNELane * getFirstPathLane() const
get first path lane
Definition: GNERoute.cpp:484
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:727
double getAttributeDouble(SumoXMLAttr key) const
Definition: GNERoute.cpp:534
GNEMoveOperation * getMoveOperation()
get move operation
Definition: GNERoute.cpp:159
void commitMoveShape(const GNEMoveResult &moveResult, GNEUndoList *undoList)
commit move shape
Definition: GNERoute.cpp:846
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:621
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:675
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:571
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:560
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:454
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:747
const GNEViewNetHelper::EditModes & getEditModes() const
get edit modes
Definition: GNEViewNet.cpp:723
const GNEViewNetHelper::NetworkViewOptions & getNetworkViewOptions() const
get network view options
Definition: GNEViewNet.cpp:735
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:553
const GNEViewNetHelper::DemandViewOptions & getDemandViewOptions() const
get demand view options
Definition: GNEViewNet.cpp:741
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
bool checkDrawVehicle(Detail d, const bool selected) const
check if draw vehicle
Detail getDetailLevel(const double exaggeration) const
return the detail level
GUIVisualizationColorSettings colorSettings
color settings
GUIVisualizationDottedContourSettings dottedContourSettings
dotted contour settings
double scale
information about a lane's width (temporary, used for a single view)
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:322
double distanceTo2D(const Position &p2) const
returns the euclidean distance in the x-y-plane
Definition: Position.h:276
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:286
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