Eclipse SUMO - Simulation of Urban MObility
GNEStop.cpp
Go to the documentation of this file.
1 /****************************************************************************/
2 // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.org/sumo
3 // Copyright (C) 2001-2020 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 // Representation of Stops in NETEDIT
19 /****************************************************************************/
20 #include <cmath>
21 #include <netedit/GNENet.h>
22 #include <netedit/GNEUndoList.h>
23 #include <netedit/GNEViewNet.h>
26 #include <utils/gui/div/GLHelper.h>
29 
30 #include "GNEStop.h"
31 
32 // ===========================================================================
33 // member method definitions
34 // ===========================================================================
35 
36 GNEStop::GNEStop(SumoXMLTag tag, GNENet* net, const SUMOVehicleParameter::Stop& stopParameter, GNEAdditional* stoppingPlace, GNEDemandElement* stopParent) :
37  GNEDemandElement(stopParent, net, GLO_STOP, tag,
38 {}, {}, {}, {stoppingPlace}, {}, {}, {stopParent}, {}),
39 SUMOVehicleParameter::Stop(stopParameter) {
40 }
41 
42 
43 GNEStop::GNEStop(GNENet* net, const SUMOVehicleParameter::Stop& stopParameter, GNELane* lane, GNEDemandElement* stopParent) :
45 {}, {}, {lane}, {}, {}, {}, {stopParent}, {}),
46 SUMOVehicleParameter::Stop(stopParameter) {
47 }
48 
49 
51 
52 
53 std::string
55  return "";
56 }
57 
58 
59 void
61  write(device);
62 }
63 
64 
65 bool
67  // only Stops placed over lanes can be invalid
69  return true;
70  } else if (friendlyPos) {
71  // with friendly position enabled position are "always fixed"
72  return true;
73  } else {
74  // obtain lane length
75  double laneLength = getParentLanes().front()->getParentEdge()->getNBEdge()->getFinalLength() * getParentLanes().front()->getLengthGeometryFactor();
76  // declare a copy of start and end positions
77  double startPosCopy = startPos;
78  double endPosCopy = endPos;
79  // check if position has to be fixed
80  if (startPosCopy < 0) {
81  startPosCopy += laneLength;
82  }
83  if (endPosCopy < 0) {
84  endPosCopy += laneLength;
85  }
86  // check values
88  return true;
89  } else if (!(parametersSet & STOP_START_SET)) {
90  return (endPosCopy <= getParentLanes().front()->getParentEdge()->getNBEdge()->getFinalLength());
91  } else if (!(parametersSet & STOP_END_SET)) {
92  return (startPosCopy >= 0);
93  } else {
94  return ((startPosCopy >= 0) && (endPosCopy <= getParentLanes().front()->getParentEdge()->getNBEdge()->getFinalLength()) && ((endPosCopy - startPosCopy) >= POSITION_EPS));
95  }
96  }
97 }
98 
99 
100 std::string
102  // declare a copy of start and end positions
103  double startPosCopy = startPos;
104  double endPosCopy = endPos;
105  // obtain lane length
106  double laneLength = getParentLanes().front()->getParentEdge()->getNBEdge()->getFinalLength();
107  // check if position has to be fixed
108  if (startPosCopy < 0) {
109  startPosCopy += laneLength;
110  }
111  if (endPosCopy < 0) {
112  endPosCopy += laneLength;
113  }
114  // declare variables
115  std::string errorStart, separator, errorEnd;
116  // check positions over lane
117  if (startPosCopy < 0) {
118  errorStart = (toString(SUMO_ATTR_STARTPOS) + " < 0");
119  } else if (startPosCopy > getParentLanes().front()->getParentEdge()->getNBEdge()->getFinalLength()) {
120  errorStart = (toString(SUMO_ATTR_STARTPOS) + " > lanes's length");
121  }
122  if (endPosCopy < 0) {
123  errorEnd = (toString(SUMO_ATTR_ENDPOS) + " < 0");
124  } else if (endPosCopy > getParentLanes().front()->getParentEdge()->getNBEdge()->getFinalLength()) {
125  errorEnd = (toString(SUMO_ATTR_ENDPOS) + " > lanes's length");
126  }
127  // check separator
128  if ((errorStart.size() > 0) && (errorEnd.size() > 0)) {
129  separator = " and ";
130  }
131  return errorStart + separator + errorEnd;
132 }
133 
134 
135 void
137  //
138 }
139 
140 
143  return getParentDemandElements().front()->getVClass();
144 }
145 
146 
147 const RGBColor&
150 }
151 
152 
153 void
155  // only start geometry moving if stop is placed over a lane
156  if (getParentLanes().size() > 0) {
157  // always save original position over view
159  // save start and end position
162  // save current centering boundary
164  }
165 }
166 
167 
168 void
170  // check that stop is placed over a lane and endGeometryMoving was called only once
172  // reset myMovingGeometryBoundary
174  }
175 }
176 
177 
178 void
180  // only move if at leats start or end positions is defined
181  if ((getParentLanes().size() > 0) && ((parametersSet & STOP_START_SET) || (parametersSet & STOP_END_SET))) {
182  // Calculate new position using old position
184  newPosition.add(offset);
185  // filtern position using snap to active grid
186  newPosition = myNet->getViewNet()->snapToActiveGrid(newPosition);
187  double offsetLane = getParentLanes().front()->getLaneShape().nearest_offset_to_point2D(newPosition, false) - getParentLanes().front()->getLaneShape().nearest_offset_to_point2D(myStopMove.originalViewPosition, false);
188  // check if both position has to be moved
190  // calculate stoppingPlace length and lane length (After apply geometry factor)
191  double stoppingPlaceLength = fabs(parse<double>(myStopMove.secondOriginalPosition) - parse<double>(myStopMove.firstOriginalLanePosition));
192  double laneLengt = getParentLanes().front()->getParentEdge()->getNBEdge()->getFinalLength() * getParentLanes().front()->getLengthGeometryFactor();
193  // avoid changing stopping place's length
194  if ((parse<double>(myStopMove.firstOriginalLanePosition) + offsetLane) < 0) {
195  startPos = 0;
196  endPos = stoppingPlaceLength;
197  } else if ((parse<double>(myStopMove.secondOriginalPosition) + offsetLane) > laneLengt) {
198  startPos = laneLengt - stoppingPlaceLength;
199  endPos = laneLengt;
200  } else {
201  startPos = parse<double>(myStopMove.firstOriginalLanePosition) + offsetLane;
202  endPos = parse<double>(myStopMove.secondOriginalPosition) + offsetLane;
203  }
204  } else {
205  // check if start position must be moved
206  if ((parametersSet & STOP_START_SET)) {
207  startPos = parse<double>(myStopMove.firstOriginalLanePosition) + offsetLane;
208  }
209  // check if start position must be moved
210  if ((parametersSet & STOP_END_SET)) {
211  endPos = parse<double>(myStopMove.secondOriginalPosition) + offsetLane;
212  }
213  }
214  // update geometry
215  updateGeometry();
216  }
217 }
218 
219 
220 void
222  // only commit geometry moving if at leats start or end positions is defined
223  if ((getParentLanes().size() > 0) && ((parametersSet & STOP_START_SET) || (parametersSet & STOP_END_SET))) {
224  undoList->p_begin("position of " + getTagStr());
227  }
228  if (parametersSet & STOP_END_SET) {
230  }
231  undoList->p_end();
232  }
233 }
234 
235 
236 void
238  //only update Stops over lanes, because other uses the geometry of stopping place parent
239  if (getParentLanes().size() > 0) {
240  // Cut shape using as delimitators fixed start position and fixed end position
242  } else if (getParentAdditionals().size() > 0) {
243  // use geometry of additional (busStop)
245  }
246  // recompute geometry of all Demand elements related with this this stop
247  if (getParentDemandElements().front()->getTagProperty().isRoute()) {
248  getParentDemandElements().front()->updateGeometry();
249  }
250 }
251 
252 
253 void
255  // nothing to compute
256 }
257 
258 
259 void
261  // nothing to invalidate
262 }
263 
264 
265 Position
267  if (getParentLanes().size() > 0) {
268  // calculate start and end positions as absolute values
269  double start = fabs(parametersSet & STOP_START_SET ? startPos : 0);
270  double end = fabs(parametersSet & STOP_END_SET ? endPos : getParentLanes().front()->getParentEdge()->getNBEdge()->getFinalLength());
271  // obtain position in view depending if both positions are defined
273  return getParentLanes().front()->getLaneShape().positionAtOffset(getParentLanes().front()->getLaneShape().length() / 2);
274  } else if (!(parametersSet & STOP_START_SET)) {
275  return getParentLanes().front()->getLaneShape().positionAtOffset(end);
276  } else if (!(parametersSet & STOP_END_SET)) {
277  return getParentLanes().front()->getLaneShape().positionAtOffset(start);
278  } else {
279  return getParentLanes().front()->getLaneShape().positionAtOffset((start + end) / 2.0);
280  }
281  } else if (getParentDemandElements().size() > 0) {
282  return getParentDemandElements().front()->getPositionInView();
283  } else {
284  throw ProcessError("Invalid Stop parent");
285  }
286 }
287 
288 
289 std::string
291  if (getParentDemandElements().size() > 0) {
292  return getParentDemandElements().front()->getID();
293  } else if (getParentAdditionals().size() > 0) {
294  return getParentAdditionals().front()->getID();
295  } else if (getParentLanes().size() > 0) {
296  return getParentLanes().front()->getID();
297  } else {
298  throw ProcessError("Invalid parent");
299  }
300 }
301 
302 
303 Boundary
305  // Return Boundary depending if myMovingGeometryBoundary is initialised (important for move geometry)
306  if (getParentAdditionals().size() > 0) {
307  return getParentAdditionals().at(0)->getCenteringBoundary();
310  } else if (myDemandElementGeometry.getShape().size() > 0) {
312  b.grow(20);
313  return b;
314  } else {
315  return Boundary(-0.1, -0.1, 0.1, 0.1);
316  }
317 }
318 
319 
320 void
321 GNEStop::splitEdgeGeometry(const double /*splitPosition*/, const GNENetworkElement* /*originalElement*/, const GNENetworkElement* /*newElement*/, GNEUndoList* /*undoList*/) {
322  // geometry of this element cannot be splitted
323 }
324 
325 
326 void
328  // declare flag to enable or disable draw person plan
329  bool drawPersonPlan = false;
330  if (myTagProperty.isStop()) {
333  drawPersonPlan = true;
334  }
336  drawPersonPlan = true;
338  drawPersonPlan = true;
340  drawPersonPlan = true;
341  } else if (!myNet->getViewNet()->getInspectedAttributeCarriers().empty() &&
343  drawPersonPlan = true;
344  }
345  // check if stop can be drawn
346  if (drawPersonPlan) {
347  // Obtain exaggeration of the draw
348  const double exaggeration = s.addSize.getExaggeration(s, this);
349  // declare value to save stop color
350  RGBColor stopColor;
351  // Set color
352  if (drawUsingSelectColor()) {
353  stopColor = s.colorSettings.selectedRouteColor;
354  } else {
355  stopColor = s.colorSettings.stops;
356  }
357  // Start drawing adding an gl identificator
358  glPushName(getGlID());
359  // Add a draw matrix
360  glPushMatrix();
361  // set Color
362  GLHelper::setColor(stopColor);
363  // Start with the drawing of the area traslating matrix to origin
365  // draw depending of details
366  if (s.drawDetail(s.detailSettings.stopsDetails, exaggeration) && getParentLanes().size() > 0) {
367  // Draw the area using shape, shapeRotations, shapeLengths and value of exaggeration
369  getParentLanes().front()->getParentEdge()->getNBEdge()->getLaneWidth(getParentLanes().front()->getIndex()) * 0.5);
371  getParentLanes().front()->getParentEdge()->getNBEdge()->getLaneWidth(getParentLanes().front()->getIndex()) * -0.5);
372  // pop draw matrix
373  glPopMatrix();
374  // Add a draw matrix
375  glPushMatrix();
376  // move to geometry front
377  glTranslated(myDemandElementGeometry.getShape().back().x(), myDemandElementGeometry.getShape().back().y(), getType());
378  glRotated(myDemandElementGeometry.getShapeRotations().back(), 0, 0, 1);
379  // draw front of Stop depending if it's placed over a lane or over a stoppingPlace
380  if (getParentLanes().size() > 0) {
381  // draw front of Stop
382  GLHelper::drawBoxLine(Position(0, 0), 0, exaggeration * 0.5,
383  getParentLanes().front()->getParentEdge()->getNBEdge()->getLaneWidth(getParentLanes().front()->getIndex()) * 0.5);
384  } else {
385  // draw front of Stop
386  GLHelper::drawBoxLine(Position(0, 0), 0, exaggeration * 0.5, exaggeration);
387  }
388  // move to "S" position
389  glTranslated(0, 1, 0);
390  // only draw text if isn't being drawn for selecting
392  GLHelper::setColor(stopColor);
393  GLHelper::drawBoxLine(Position(0, 1), 0, 2, 1);
394  } else if (s.drawDetail(s.detailSettings.stopsText, exaggeration)) {
395  // draw "S" symbol
396  GLHelper::drawText("S", Position(), .1, 2.8, stopColor);
397  // move to subtitle positin
398  glTranslated(0, 1.4, 0);
399  // draw subtitle depending of tag
400  GLHelper::drawText("lane", Position(), .1, 1, stopColor, 180);
401  }
402  // pop draw matrix
403  glPopMatrix();
404  // Draw name if isn't being drawn for selecting
405  drawName(getCenteringBoundary().getCenter(), s.scale, s.addName);
406  // check if dotted contour has to be drawn
408  // draw dooted contour depending if it's placed over a lane or over a stoppingPlace
409  if (getParentLanes().size() > 0) {
410  // GLHelper::drawShapeDottedContourAroundShape(s, getType(), myDemandElementGeometry.getShape(),
411  // getParentLanes().front()->getParentEdge()->getNBEdge()->getLaneWidth(getParentLanes().front()->getIndex()) * 0.5);
412  } else {
413  // GLHelper::drawShapeDottedContourAroundShape(s, getType(), myDemandElementGeometry.getShape(), exaggeration);
414  }
415  }
416  } else {
417  // Draw the area using shape, shapeRotations, shapeLengths and value of exaggeration
419  // pop draw matrix
420  glPopMatrix();
421  }
422  // Pop name
423  glPopName();
424  // draw person parent if this stop if their first person plan child
425  if ((getParentDemandElements().size() == 1) && getParentDemandElements().front()->getChildDemandElements().front() == this) {
426  getParentDemandElements().front()->drawGL(s);
427  }
428  }
429 }
430 
431 
432 void
433 GNEStop::drawPartialGL(const GUIVisualizationSettings& /*s*/, const GNELane* /*lane*/, const double /*offsetFront*/) const {
434  // Stops don't use drawPartialGL
435 }
436 
437 
438 void
439 GNEStop::drawPartialGL(const GUIVisualizationSettings& /*s*/, const GNELane* /* fromLane */, const GNELane* /* toLane */, const double /*offsetFront*/) const {
440  // Stops don't use drawPartialGL
441 }
442 
443 
444 std::string
446  switch (key) {
447  case SUMO_ATTR_DURATION:
449  return time2string(duration);
450  } else {
451  return "";
452  }
453  case SUMO_ATTR_UNTIL:
455  return time2string(until);
456  } else {
457  return "";
458  }
459  case SUMO_ATTR_EXTENSION:
461  return time2string(extension);
462  } else {
463  return "";
464  }
465  case SUMO_ATTR_TRIGGERED:
466  // this is an special case
468  return "1";
469  } else {
470  return "0";
471  }
473  // this is an special case
475  return "1";
476  } else {
477  return "0";
478  }
479  case SUMO_ATTR_EXPECTED:
481  return toString(awaitedPersons);
482  } else {
483  return "";
484  }
487  return toString(awaitedContainers);
488  } else {
489  return "";
490  }
491  case SUMO_ATTR_PARKING:
492  return toString(parking);
493  case SUMO_ATTR_ACTTYPE:
494  return actType;
495  case SUMO_ATTR_TRIP_ID:
497  return tripId;
498  } else {
499  return "";
500  }
501  // specific of Stops over stoppingPlaces
502  case SUMO_ATTR_BUS_STOP:
506  return getParentAdditionals().front()->getID();
507  // specific of stops over lanes
508  case SUMO_ATTR_LANE:
509  return getParentLanes().front()->getID();
510  case SUMO_ATTR_STARTPOS:
512  return toString(startPos);
513  } else {
514  return "";
515  }
516  case SUMO_ATTR_ENDPOS:
517  if (parametersSet & STOP_END_SET) {
518  return toString(endPos);
519  } else {
520  return "";
521  }
523  return toString(friendlyPos);
524  //
525  case GNE_ATTR_SELECTED:
527  case GNE_ATTR_PARENT:
528  return getParentDemandElements().front()->getID();
529  default:
530  throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
531  }
532 }
533 
534 
535 double
537  switch (key) {
538  case SUMO_ATTR_STARTPOS:
540  return startPos;
541  } else {
542  return 0;
543  }
544  case SUMO_ATTR_ENDPOS:
545  if (parametersSet & STOP_END_SET) {
546  return endPos;
547  } else {
548  return getParentLanes().front()->getParentEdge()->getNBEdge()->getFinalLength();
549  }
550  default:
551  throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
552  }
553 }
554 
555 
556 void
557 GNEStop::setAttribute(SumoXMLAttr key, const std::string& value, GNEUndoList* undoList) {
558  if (value == getAttribute(key)) {
559  return; //avoid needless changes, later logic relies on the fact that attributes have changed
560  }
561  switch (key) {
562  case SUMO_ATTR_DURATION:
563  case SUMO_ATTR_UNTIL:
564  case SUMO_ATTR_EXTENSION:
565  case SUMO_ATTR_TRIGGERED:
567  case SUMO_ATTR_EXPECTED:
569  case SUMO_ATTR_PARKING:
570  case SUMO_ATTR_ACTTYPE:
571  case SUMO_ATTR_TRIP_ID:
572  // specific of Stops over stoppingPlaces
573  case SUMO_ATTR_BUS_STOP:
577  // specific of stops over lanes
578  case SUMO_ATTR_LANE:
579  case SUMO_ATTR_STARTPOS:
580  case SUMO_ATTR_ENDPOS:
582  //
583  case GNE_ATTR_SELECTED:
584  undoList->p_add(new GNEChange_Attribute(this, key, value));
585  break;
586  default:
587  throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
588  }
589 }
590 
591 
592 bool
593 GNEStop::isValid(SumoXMLAttr key, const std::string& value) {
594  // declare string error
595  std::string error;
596  switch (key) {
597  case SUMO_ATTR_DURATION:
598  case SUMO_ATTR_UNTIL:
599  case SUMO_ATTR_EXTENSION:
600  if (canParse<SUMOTime>(value)) {
601  return parse<SUMOTime>(value) >= 0;
602  } else {
603  return false;
604  }
605  case SUMO_ATTR_TRIGGERED:
606  return canParse<bool>(value);
608  return canParse<bool>(value);
609  case SUMO_ATTR_EXPECTED:
611  if (value.empty()) {
612  return true;
613  } else {
614  std::vector<std::string> IDs = parse<std::vector<std::string>>(value);
615  for (const auto& i : IDs) {
616  if (SUMOXMLDefinitions::isValidVehicleID(i) == false) {
617  return false;
618  }
619  }
620  return true;
621  }
622  case SUMO_ATTR_PARKING:
623  return canParse<bool>(value);
624  case SUMO_ATTR_ACTTYPE:
625  return true;
626  case SUMO_ATTR_TRIP_ID:
628  // specific of Stops over stoppingPlaces
629  case SUMO_ATTR_BUS_STOP:
630  return (myNet->retrieveAdditional(SUMO_TAG_BUS_STOP, value, false) != nullptr);
632  return (myNet->retrieveAdditional(SUMO_TAG_CONTAINER_STOP, value, false) != nullptr);
634  return (myNet->retrieveAdditional(SUMO_TAG_CHARGING_STATION, value, false) != nullptr);
636  return (myNet->retrieveAdditional(SUMO_TAG_PARKING_AREA, value, false) != nullptr);
637  // specific of stops over lanes
638  case SUMO_ATTR_LANE:
639  if (myNet->retrieveLane(value, false) != nullptr) {
640  return true;
641  } else {
642  return false;
643  }
644  case SUMO_ATTR_STARTPOS:
645  if (value.empty()) {
646  return true;
647  } else if (canParse<double>(value)) {
648  return SUMORouteHandler::isStopPosValid(parse<double>(value), endPos, getParentLanes().front()->getParentEdge()->getNBEdge()->getFinalLength(), POSITION_EPS, friendlyPos);
649  } else {
650  return false;
651  }
652  case SUMO_ATTR_ENDPOS:
653  if (value.empty()) {
654  return true;
655  } else if (canParse<double>(value)) {
656  return SUMORouteHandler::isStopPosValid(startPos, parse<double>(value), getParentLanes().front()->getParentEdge()->getNBEdge()->getFinalLength(), POSITION_EPS, friendlyPos);
657  } else {
658  return false;
659  }
661  return canParse<bool>(value);
662  //
663  case GNE_ATTR_SELECTED:
664  return canParse<bool>(value);
665  default:
666  throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
667  }
668 }
669 
670 
671 void
673  // obtain a copy of parameter sets
674  int newParametersSet = parametersSet;
675  // modify parametersSetCopy depending of attr
676  switch (key) {
677  case SUMO_ATTR_STARTPOS:
678  newParametersSet |= STOP_START_SET;
679  break;
680  case SUMO_ATTR_ENDPOS:
681  newParametersSet |= STOP_END_SET;
682  break;
683  case SUMO_ATTR_DURATION:
684  newParametersSet |= STOP_DURATION_SET;
685  break;
686  case SUMO_ATTR_UNTIL:
687  newParametersSet |= STOP_UNTIL_SET;
688  break;
689  case SUMO_ATTR_EXTENSION:
690  newParametersSet |= STOP_EXTENSION_SET;
691  break;
692  case SUMO_ATTR_EXPECTED:
693  newParametersSet |= STOP_TRIGGER_SET;
694  break;
696  newParametersSet |= STOP_CONTAINER_TRIGGER_SET;
697  break;
698  case SUMO_ATTR_PARKING:
699  newParametersSet |= STOP_PARKING_SET;
700  break;
701  default:
702  break;
703  }
704  // add GNEChange_EnableAttribute
705  undoList->add(new GNEChange_EnableAttribute(this, parametersSet, newParametersSet), true);
706  // modify parametersSetCopy depending of attr
707  switch (key) {
708  case SUMO_ATTR_STARTPOS:
709  if (parametersSet & STOP_END_SET) {
710  undoList->p_add(new GNEChange_Attribute(this, key, toString(endPos - MIN_STOP_LENGTH)));
711  } else {
712  undoList->p_add(new GNEChange_Attribute(this, key, toString(getParentLanes().front()->getParentEdge()->getNBEdge()->getFinalLength() - MIN_STOP_LENGTH)));
713  }
714  break;
715  case SUMO_ATTR_ENDPOS:
716  undoList->p_add(new GNEChange_Attribute(this, key, toString(getParentLanes().front()->getParentEdge()->getNBEdge()->getFinalLength())));
717  break;
718  case SUMO_ATTR_DURATION:
720  break;
721  case SUMO_ATTR_UNTIL:
722  case SUMO_ATTR_EXTENSION:
724  break;
725  default:
726  break;
727  }
728 }
729 
730 
731 void
733  // obtain a copy of parameter sets
734  int newParametersSet = parametersSet;
735  // modify parametersSetCopy depending of attr
736  switch (key) {
737  case SUMO_ATTR_STARTPOS:
738  newParametersSet &= ~STOP_START_SET;
739  break;
740  case SUMO_ATTR_ENDPOS:
741  newParametersSet &= ~STOP_END_SET;
742  break;
743  case SUMO_ATTR_DURATION:
744  newParametersSet &= ~STOP_DURATION_SET;
745  break;
746  case SUMO_ATTR_UNTIL:
747  newParametersSet &= ~STOP_UNTIL_SET;
748  break;
749  case SUMO_ATTR_EXTENSION:
750  newParametersSet &= ~STOP_EXTENSION_SET;
751  break;
752  case SUMO_ATTR_EXPECTED:
753  newParametersSet &= ~STOP_TRIGGER_SET;
754  break;
756  newParametersSet &= ~STOP_CONTAINER_TRIGGER_SET;
757  break;
758  case SUMO_ATTR_PARKING:
759  newParametersSet &= ~STOP_PARKING_SET;
760  break;
761  default:
762  break;
763  }
764  // add GNEChange_EnableAttribute
765  undoList->add(new GNEChange_EnableAttribute(this, parametersSet, newParametersSet), true);
766 }
767 
768 
769 bool
771  switch (key) {
772  // Currently stops parents cannot be edited
773  case SUMO_ATTR_BUS_STOP:
777  return false;
778  case SUMO_ATTR_STARTPOS:
779  return (parametersSet & STOP_START_SET) != 0;
780  case SUMO_ATTR_ENDPOS:
781  return (parametersSet & STOP_END_SET) != 0;
782  case SUMO_ATTR_DURATION:
783  return (parametersSet & STOP_DURATION_SET) != 0;
784  case SUMO_ATTR_UNTIL:
785  return (parametersSet & STOP_UNTIL_SET) != 0;
786  case SUMO_ATTR_EXTENSION:
787  return (parametersSet & STOP_EXTENSION_SET) != 0;
788  case SUMO_ATTR_EXPECTED:
789  return (parametersSet & STOP_TRIGGER_SET) != 0;
792  case SUMO_ATTR_PARKING:
793  return (parametersSet & STOP_PARKING_SET) != 0;
794  default:
795  return true;
796  }
797 }
798 
799 
800 std::string
802  return getTagStr();
803 }
804 
805 
806 std::string
808  if (getParentAdditionals().size() > 0) {
809  return "vehicle stop: " + getParentAdditionals().front()->getTagStr();
810  } else {
811  return "vehicle stop: lane";
812  }
813 }
814 
815 
816 const std::map<std::string, std::string>&
818  return getParametersMap();
819 }
820 
821 double
823  double fixedPos = 0;
825  fixedPos = startPos;
826  } else if (parametersSet & STOP_END_SET) {
827  fixedPos = endPos - MIN_STOP_LENGTH;
828  } else {
829  fixedPos = getParentLanes().front()->getParentEdge()->getNBEdge()->getFinalLength() - MIN_STOP_LENGTH;
830  }
831  const double len = getParentLanes().front()->getParentEdge()->getNBEdge()->getFinalLength();
832  if (fixedPos < 0) {
833  fixedPos += len;
834  }
835  return fixedPos * getParentLanes().front()->getLengthGeometryFactor();
836 }
837 
838 
839 double
841  double fixedPos = 0;
842  if (parametersSet & STOP_END_SET) {
843  fixedPos = endPos;
844  } else {
845  fixedPos = getParentLanes().front()->getParentEdge()->getNBEdge()->getFinalLength();
846  }
847  const double len = getParentLanes().front()->getParentEdge()->getNBEdge()->getFinalLength();
848  if (fixedPos < 0) {
849  fixedPos += len;
850  }
851  return fixedPos * getParentLanes().front()->getLengthGeometryFactor();
852 }
853 
854 // ===========================================================================
855 // private
856 // ===========================================================================
857 
858 void
859 GNEStop::setAttribute(SumoXMLAttr key, const std::string& value) {
860  switch (key) {
861  case SUMO_ATTR_DURATION:
862  if (value.empty()) {
864  } else {
865  duration = string2time(value);
867  }
868  break;
869  case SUMO_ATTR_UNTIL:
870  if (value.empty()) {
872  } else {
873  until = string2time(value);
875  }
876  break;
877  case SUMO_ATTR_EXTENSION:
878  if (value.empty()) {
880  } else {
881  extension = string2time(value);
883  }
884  break;
885  case SUMO_ATTR_TRIGGERED:
886  triggered = parse<bool>(value);
887  // this is an special case: only if SUMO_ATTR_TRIGGERED is true, it will be written in XML
888  if (triggered) {
890  } else {
892  }
893  break;
895  containerTriggered = parse<bool>(value);
896  // this is an special case: only if SUMO_ATTR_CONTAINER_TRIGGERED is true, it will be written in XML
897  if (containerTriggered) {
899  } else {
901  }
902  break;
903  case SUMO_ATTR_EXPECTED:
904  if (value.empty()) {
906  } else {
907  awaitedPersons = parse<std::set<std::string> >(value);
909  }
910  break;
912  if (value.empty()) {
914  } else {
915  awaitedContainers = parse<std::set<std::string> >(value);
917  }
918  break;
919  case SUMO_ATTR_PARKING:
920  parking = parse<bool>(value);
921  break;
922  case SUMO_ATTR_ACTTYPE:
923  actType = value;
924  break;
925  case SUMO_ATTR_TRIP_ID:
926  if (value.empty()) {
928  } else {
929  tripId = value;
931  }
932  break;
933  // specific of Stops over stoppingPlaces
934  case SUMO_ATTR_BUS_STOP:
936  updateGeometry();
937  break;
940  updateGeometry();
941  break;
944  updateGeometry();
945  break;
948  updateGeometry();
949  break;
950  // specific of Stops over lanes
951  case SUMO_ATTR_LANE:
953  updateGeometry();
954  break;
955  case SUMO_ATTR_STARTPOS:
956  if (value.empty()) {
958  } else {
959  startPos = parse<double>(value);
961  }
962  updateGeometry();
963  break;
964  case SUMO_ATTR_ENDPOS:
965  if (value.empty()) {
967  } else {
968  endPos = parse<double>(value);
970  }
971  updateGeometry();
972  break;
974  friendlyPos = parse<bool>(value);
975  break;
976  //
977  case GNE_ATTR_SELECTED:
978  if (parse<bool>(value)) {
980  } else {
982  }
983  break;
984  default:
985  throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
986  }
987 }
988 
989 
990 void
991 GNEStop::setEnabledAttribute(const int enabledAttributes) {
992  parametersSet = enabledAttributes;
993 }
994 
995 
996 /****************************************************************************/
@ GLO_STOP
a stop
std::string time2string(SUMOTime t)
convert SUMOTime to string
Definition: SUMOTime.cpp:68
SUMOTime string2time(const std::string &r)
convert string to SUMOTime
Definition: SUMOTime.cpp:45
SUMOVehicleClass
Definition of vehicle classes to differ between different lane usage and authority types.
const int STOP_DURATION_SET
const int STOP_EXPECTED_SET
const int STOP_UNTIL_SET
const int STOP_PARKING_SET
const int STOP_TRIP_ID_SET
const int STOP_START_SET
const int STOP_CONTAINER_TRIGGER_SET
const int STOP_EXTENSION_SET
const int STOP_TRIGGER_SET
const int STOP_END_SET
const double MIN_STOP_LENGTH
const int STOP_EXPECTED_CONTAINERS_SET
SumoXMLTag
Numbers representing SUMO-XML - element names.
@ SUMO_TAG_CHARGING_STATION
A Charging Station.
@ SUMO_TAG_CONTAINER_STOP
A container stop.
@ SUMO_TAG_STOP_LANE
stop placed over a lane (used in netedit)
@ SUMO_TAG_BUS_STOP
A bus stop.
@ SUMO_TAG_PARKING_AREA
A parking area.
SumoXMLAttr
Numbers representing SUMO-XML - attributes.
@ SUMO_ATTR_CONTAINER_TRIGGERED
@ SUMO_ATTR_STARTPOS
@ SUMO_ATTR_PARKING
@ SUMO_ATTR_EXTENSION
@ SUMO_ATTR_LANE
@ SUMO_ATTR_CONTAINER_STOP
@ SUMO_ATTR_PARKING_AREA
@ SUMO_ATTR_BUS_STOP
@ SUMO_ATTR_ENDPOS
@ GNE_ATTR_PARENT
parent of an additional element
@ SUMO_ATTR_ACTTYPE
@ GNE_ATTR_SELECTED
element is selected
@ SUMO_ATTR_EXPECTED
@ SUMO_ATTR_CHARGING_STATION
@ SUMO_ATTR_TRIP_ID
@ SUMO_ATTR_FRIENDLY_POS
@ SUMO_ATTR_EXPECTED_CONTAINERS
@ SUMO_ATTR_UNTIL
@ SUMO_ATTR_TRIGGERED
@ SUMO_ATTR_DURATION
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
Definition: ToString.h:44
A class that stores a 2D geometrical boundary.
Definition: Boundary.h:39
bool isInitialised() const
check if Boundary is Initialised
Definition: Boundary.cpp:215
void reset()
Resets the boundary.
Definition: Boundary.cpp:65
Boundary & grow(double by)
extends the boundary by the given amount
Definition: Boundary.cpp:299
static void setColor(const RGBColor &c)
Sets the gl-color to this value.
Definition: GLHelper.cpp:446
static void drawBoxLines(const PositionVector &geom, const std::vector< double > &rots, const std::vector< double > &lengths, double width, int cornerDetail=0, double offset=0)
Draws thick lines.
Definition: GLHelper.cpp:181
static void drawBoxLine(const Position &beg, double rot, double visLength, double width, double offset=0)
Draws a thick line.
Definition: GLHelper.cpp:135
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:498
An Element which don't belongs to GNENet but has influency in the simulation.
Definition: GNEAdditional.h:47
bool isAttributeCarrierSelected() const
check if attribute carrier is selected
friend class GNEChange_EnableAttribute
friend class GNEChange_Attribute
declare friend class
const std::string & getTagStr() const
get tag assigned to this object in string format
const GNETagProperties & getTagProperty() const
get Tag Property assigned to this object
void unselectAttributeCarrier(const bool changeFlag=true)
unselect attribute carrier using GUIGlobalSelection
bool drawUsingSelectColor() const
check if attribute carrier must be drawn using selecting color.
GNENet * myNet
pointer to net
void selectAttributeCarrier(const bool changeFlag=true)
select attribute carrier using GUIGlobalSelection
const GNETagProperties & myTagProperty
the xml tag to which this attribute carrier corresponds
const std::string & getDefaultValue() const
get default value
An Element which don't belongs to GNENet but has influency in the simulation.
void replaceDemandParentLanes(const std::string &value)
replace demand parent lanes
GNEGeometry::Geometry myDemandElementGeometry
demand element geometry (also called "stacked geometry")
void replaceAdditionalParent(SumoXMLTag tag, const std::string &value, const int parentIndex)
replace additional parent
const std::vector< double > & getShapeRotations() const
The rotations of the single shape parts.
const PositionVector & getShape() const
The shape of the additional element.
void updateGeometry(const PositionVector &shape, double startPos=-1, double endPos=-1, const Position &extraFirstPosition=Position::INVALID, const Position &extraLastPosition=Position::INVALID)
update geometry shape
Definition: GNEGeometry.cpp:81
const std::vector< double > & getShapeLengths() const
The lengths of the single shape parts.
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< GNELane * > & getParentLanes() const
get parent lanes
This lane is powered by an underlying GNEEdge and basically knows how to draw itself.
Definition: GNELane.h:45
A NBNetBuilder extended by visualisation and editing capabilities.
Definition: GNENet.h:40
GNELane * retrieveLane(const std::string &id, bool failHard=true, bool checkVolatileChange=false)
get lane by id
Definition: GNENet.cpp:1337
GNEAdditional * retrieveAdditional(SumoXMLTag type, const std::string &id, bool hardFail=true) const
Returns the named additional.
Definition: GNENet.cpp:2316
GNEViewNet * getViewNet() const
get view net
Definition: GNENet.cpp:2245
const RGBColor & getColor() const
get color
Definition: GNEStop.cpp:148
bool isValid(SumoXMLAttr key, const std::string &value)
method for checking if the key and their conrrespond attribute are valids
Definition: GNEStop.cpp:593
std::string getBegin() const
get begin time of demand element
Definition: GNEStop.cpp:54
SUMOVehicleClass getVClass() const
Definition: GNEStop.cpp:142
void disableAttribute(SumoXMLAttr key, GNEUndoList *undoList)
Definition: GNEStop.cpp:732
~GNEStop()
destructor
Definition: GNEStop.cpp:50
std::string getPopUpID() const
get PopPup ID (Used in AC Hierarchy)
Definition: GNEStop.cpp:801
Position getPositionInView() const
Returns position of demand element in view.
Definition: GNEStop.cpp:266
void splitEdgeGeometry(const double splitPosition, const GNENetworkElement *originalElement, const GNENetworkElement *newElement, GNEUndoList *undoList)
split geometry
Definition: GNEStop.cpp:321
bool isAttributeEnabled(SumoXMLAttr key) const
Definition: GNEStop.cpp:770
void moveGeometry(const Position &offset)
change the position of the element geometry without saving in undoList
Definition: GNEStop.cpp:179
bool isDemandElementValid() const
check if current demand element is valid to be writed into XML (by default true, can be reimplemented...
Definition: GNEStop.cpp:66
void writeDemandElement(OutputDevice &device) const
writte demand element element into a xml file
Definition: GNEStop.cpp:60
std::string getHierarchyName() const
get Hierarchy Name (Used in AC Hierarchy)
Definition: GNEStop.cpp:807
std::string getParentName() const
Returns the name of the parent object.
Definition: GNEStop.cpp:290
void enableAttribute(SumoXMLAttr key, GNEUndoList *undoList)
Definition: GNEStop.cpp:672
double getAttributeDouble(SumoXMLAttr key) const
Definition: GNEStop.cpp:536
std::string getAttribute(SumoXMLAttr key) const
inherited from GNEAttributeCarrier
Definition: GNEStop.cpp:445
void computePath()
compute path
Definition: GNEStop.cpp:254
Boundary getCenteringBoundary() const
Returns the boundary to which the view shall be centered in order to show the object.
Definition: GNEStop.cpp:304
void drawGL(const GUIVisualizationSettings &s) const
Draws the object.
Definition: GNEStop.cpp:327
void setAttribute(SumoXMLAttr key, const std::string &value, GNEUndoList *undoList)
method for setting the attribute and letting the object perform demand element changes
Definition: GNEStop.cpp:557
void commitGeometryMoving(GNEUndoList *undoList)
commit geometry changes in the attributes of an element after use of moveGeometry(....
Definition: GNEStop.cpp:221
void endGeometryMoving()
end movement
Definition: GNEStop.cpp:169
void fixDemandElementProblem()
fix demand element problem (by default throw an exception, has to be reimplemented in children)
Definition: GNEStop.cpp:136
GNEStop(SumoXMLTag tag, GNENet *net, const SUMOVehicleParameter::Stop &stopParameter, GNEAdditional *stoppingPlace, GNEDemandElement *stopParent)
constructor used for stops over stoppingPlaces
Definition: GNEStop.cpp:36
void invalidatePath()
invalidate path
Definition: GNEStop.cpp:260
double getStartGeometryPositionOverLane() const
get start position over lane that is applicable to the shape
Definition: GNEStop.cpp:822
void drawPartialGL(const GUIVisualizationSettings &s, const GNELane *lane, const double offsetFront) const
Draws partial object.
Definition: GNEStop.cpp:433
DemandElementMove myStopMove
variable demand element move
Definition: GNEStop.h:207
const std::map< std::string, std::string > & getACParametersMap() const
get parameters map
Definition: GNEStop.cpp:817
void setEnabledAttribute(const int enabledAttributes)
method for enabling the attribute and nothing else (used in GNEChange_EnableAttribute)
Definition: GNEStop.cpp:991
void updateGeometry()
update pre-computed geometry information
Definition: GNEStop.cpp:237
double getEndGeometryPositionOverLane() const
get end position over lane that is applicable to the shape
Definition: GNEStop.cpp:840
void startGeometryMoving()
Definition: GNEStop.cpp:154
std::string getDemandElementProblem() const
return a string with the current demand element problem (by default empty, can be reimplemented in ch...
Definition: GNEStop.cpp:101
const GNEAttributeProperties & getAttributeProperties(SumoXMLAttr attr) const
get attribute (throw error if doesn't exist)
bool isStop() const
return true if tag correspond to a stop element
SumoXMLTag getTag() const
get Tag vinculated with this attribute Property
void p_add(GNEChange_Attribute *cmd)
special method, avoid empty changes, always execute
void p_begin(const std::string &description)
Begin undo command sub-group. This begins a new group of commands that are treated as a single comman...
Definition: GNEUndoList.cpp:71
void p_end()
End undo command sub-group. If the sub-group is still empty, it will be deleted; otherwise,...
Definition: GNEUndoList.cpp:78
const GNEViewNetHelper::DataViewOptions & getDataViewOptions() const
get data view options
Definition: GNEViewNet.cpp:491
const GNEViewNetHelper::NetworkViewOptions & getNetworkViewOptions() const
get network view options
Definition: GNEViewNet.cpp:479
const std::vector< GNEAttributeCarrier * > & getInspectedAttributeCarriers() const
get inspected attribute carriers
bool isAttributeCarrierInspected(const GNEAttributeCarrier *AC) const
check if attribute carrier is being inspected
void drawTranslateFrontAttributeCarrier(const GNEAttributeCarrier *AC, GUIGlObjectType objectType, const double extraOffset=0)
draw front attributeCarrier
const GNEViewNetHelper::DemandViewOptions & getDemandViewOptions() const
get demand view options
Definition: GNEViewNet.cpp:485
GUIGlObjectType getType() const
Returns the type of the object as coded in GUIGlObjectType.
GUIGlID getGlID() const
Returns the numerical id of the object.
void drawName(const Position &pos, const double scale, const GUIVisualizationTextSettings &settings, const double angle=0) const
draw name of item
Position snapToActiveGrid(const Position &pos, bool snapXY=true) const
Returns a position that is mapped to the closest grid point if the grid is active.
GUIVisualizationSettings & getVisualisationSettings() const
get visualization settings
Stores the information about how to visualize structures.
GUIVisualizationTextSettings addName
bool drawForRectangleSelection
whether drawing is performed for the purpose of selecting objects using a rectangle
GUIVisualizationDetailSettings detailSettings
detail settings
GUIVisualizationSizeSettings addSize
bool drawDottedContour() const
check if dotted contour can be drawn
GUIVisualizationColorSettings colorSettings
color settings
double scale
information about a lane's width (temporary, used for a single view)
bool drawDetail(const double detail, const double exaggeration) const
check if details can be drawn for the given GUIVisualizationDetailSettings and current scale and exxa...
Static storage of an output device and its base (abstract) implementation.
Definition: OutputDevice.h:60
const std::map< std::string, std::string > & getParametersMap() const
Returns the inner key/value map.
A point in 2D or 3D with translation and scaling methods.
Definition: Position.h:36
void add(const Position &pos)
Adds the given position to this one.
Definition: Position.h:124
Boundary getBoxBoundary() const
Returns a boundary enclosing this list of lines.
static bool isStopPosValid(const double startPos, const double endPos, const double laneLength, const double minLength, const bool friendlyPos)
check if start and end position of a stop is valid
Definition of vehicle stop (position and duration)
void write(OutputDevice &dev, bool close=true) const
Writes the stop as XML.
SUMOTime extension
The maximum time extension for boarding / loading.
bool friendlyPos
enable or disable friendly position (used by NETEDIT)
double startPos
The stopping position start.
int parametersSet
Information for the output which parameter were set.
SUMOTime until
The time at which the vehicle may continue its journey.
std::string actType
act Type (only used by Persons) (used by NETEDIT)
bool triggered
whether an arriving person lets the vehicle continue
double endPos
The stopping position end.
bool parking
whether the vehicle is removed from the net while stopping
std::set< std::string > awaitedPersons
IDs of persons the vehicle has to wait for until departing.
std::set< std::string > awaitedContainers
IDs of containers the vehicle has to wait for until departing.
std::string tripId
id of the trip within a cyclical public transport route
bool containerTriggered
whether an arriving container lets the vehicle continue
SUMOTime duration
The stopping duration.
static bool isValidVehicleID(const std::string &value)
whether the given string is a valid id for a vehicle or flow
Position originalViewPosition
value for saving first original position over lane before moving
std::string secondOriginalPosition
value for saving second original position over lane before moving
std::string firstOriginalLanePosition
value for saving first original position over lane before moving
Boundary movingGeometryBoundary
boundary used during moving of elements (to avoid insertion in RTREE)
static void drawGeometry(const GNEViewNet *viewNet, const Geometry &geometry, const double width)
draw geometry
bool showDemandElements() const
check if show demand elements checkbox is enabled
bool showAllPersonPlans() const
check all person plans has to be show
const GNEDemandElement * getLockedPerson() const
get locked person
bool showNonInspectedDemandElements(const GNEDemandElement *demandElement) const
check if non inspected element has to be hidden
bool showDemandElements() const
check if show demand elements checkbox is enabled
RGBColor selectedRouteColor
route selection color (used for routes and vehicle stops)
static const RGBColor stops
color for Stops
static const double stopsText
details for stop texts
static const double stopsDetails
details for stops
double getExaggeration(const GUIVisualizationSettings &s, const GUIGlObject *o, double factor=20) const
return the drawing size including exaggeration and constantSize values