Eclipse SUMO - Simulation of Urban MObility
GNERide.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 rides in Netedit
19 /****************************************************************************/
20 
23 #include <netedit/GNENet.h>
24 #include <netedit/GNEUndoList.h>
25 #include <netedit/GNEViewNet.h>
27 
28 #include "GNERide.h"
29 
30 // ===========================================================================
31 // method definitions
32 // ===========================================================================
33 
34 GNERide::GNERide(GNENet* net, SumoXMLTag tag, GUIIcon icon, GNEDemandElement* personParent, const GNEPlanParents& planParameters,
35  const double arrivalPosition, const std::vector<std::string>& lines, const std::string& group) :
36  GNEDemandElement(personParent, net, GLO_PERSONTRIP, tag, GUIIconSubSys::getIcon(icon),
37  GNEPathManager::PathElement::Options::DEMAND_ELEMENT,
38  planParameters.getJunctions(), planParameters.getEdges(), {},
39 planParameters.getAdditionalElements(), planParameters.getDemandElements(personParent), {}),
40  GNEDemandElementPlan(this, -1, arrivalPosition),
41  myLines(lines),
42 myGroup(group) {
43 }
44 
45 
47  GNEDemandElement("", net, GLO_RIDE, tag, GUIIconSubSys::getIcon(GUIIcon::RIDE_EDGE),
48  GNEPathManager::PathElement::Options::DEMAND_ELEMENT, {}, {}, {}, {}, {}, {}),
49 GNEDemandElementPlan(this, -1, -1) {
50  // reset default values
52 }
53 
54 
56 
57 
60  return getPlanMoveOperation();
61 }
62 
63 
66  return getPlanPopUpMenu(app, parent);
67 }
68 
69 
70 void
72  // first write origin stop (if this element starts in a stoppingPlace)
73  writeOriginStop(device);
74  // write rest of attributes
75  device.openTag(SUMO_TAG_RIDE);
77  // lines
78  if (myLines.size() > 0) {
80  }
81  // group
82  if (myGroup.size() > 0) {
84  }
85  device.closeTag();
86 }
87 
88 
91  return isPlanPersonValid();
92 }
93 
94 
95 std::string
97  return getPersonPlanProblem();
98 }
99 
100 
101 void
103  // currently the only solution is removing Ride
104 }
105 
106 
109  return SVC_PEDESTRIAN;
110 }
111 
112 
113 const RGBColor&
116 }
117 
118 
119 void
122 }
123 
124 
125 Position
127  return getPlanPositionInView();
128 }
129 
130 
131 std::string
133  return getParentDemandElements().front()->getID();
134 }
135 
136 
137 Boundary
139  return getPlanCenteringBoundary();
140 }
141 
142 
143 void
144 GNERide::splitEdgeGeometry(const double /*splitPosition*/, const GNENetworkElement* /*originalElement*/, const GNENetworkElement* /*newElement*/, GNEUndoList* /*undoList*/) {
145  // geometry of this element cannot be splitted
146 }
147 
148 
149 void
152 }
153 
154 
155 void
157  // get first and last path lanes
158  const auto firstPathLane = getFirstPathLane();
159  const auto lastPathLane = getLastPathLane();
160  // continue depending of pathLane
161  if (firstPathLane && lastPathLane) {
162  // calculate path
163  myNet->getPathManager()->calculatePath(this, SVC_PASSENGER, firstPathLane, lastPathLane);
164  // check if calculate ignoring path
165  if (!myNet->getPathManager()->isPathValid(this)) {
166  myNet->getPathManager()->calculatePath(this, SVC_IGNORING, firstPathLane, lastPathLane);
167  }
168  } else {
169  // reset path
170  myNet->getPathManager()->removePath(this);
171  }
172  // update geometry
173  updateGeometry();
174 }
175 
176 
177 void
178 GNERide::drawLanePartialGL(const GUIVisualizationSettings& s, const GNEPathManager::Segment* segment, const double offsetFront) const {
180 }
181 
182 
183 void
184 GNERide::drawJunctionPartialGL(const GUIVisualizationSettings& s, const GNEPathManager::Segment* segment, const double offsetFront) const {
186 }
187 
188 
189 GNELane*
191  return getFirstPlanPathLane();
192 }
193 
194 
195 GNELane*
197  return getLastPlanPathLane();
198 }
199 
200 
201 std::string
203  switch (key) {
204  case SUMO_ATTR_LINES:
205  return joinToString(myLines, " ");
206  case SUMO_ATTR_GROUP:
207  return myGroup;
208  default:
209  return getPlanAttribute(key);
210  }
211 }
212 
213 
214 double
216  return getPlanAttributeDouble(key);
217 }
218 
219 
220 Position
222  return getPlanAttributePosition(key);
223 }
224 
225 
226 void
227 GNERide::setAttribute(SumoXMLAttr key, const std::string& value, GNEUndoList* undoList) {
228  switch (key) {
229  case SUMO_ATTR_LINES:
230  case SUMO_ATTR_GROUP:
231  GNEChange_Attribute::changeAttribute(this, key, value, undoList);
232  break;
233  default:
234  setPlanAttribute(key, value, undoList);
235  break;
236  }
237 }
238 
239 
240 bool
241 GNERide::isValid(SumoXMLAttr key, const std::string& value) {
242  switch (key) {
243  case SUMO_ATTR_LINES:
244  return canParse<std::vector<std::string> >(value);
245  case SUMO_ATTR_GROUP:
246  return true;
247  default:
248  return isPlanValid(key, value);
249  }
250 }
251 
252 
253 bool
255  return isPlanAttributeEnabled(key);
256 }
257 
258 
259 std::string
261  return getTagStr();
262 }
263 
264 
265 std::string
267  return getPlanHierarchyName();
268 }
269 
270 
271 const Parameterised::Map&
273  return getParametersMap();
274 }
275 
276 // ===========================================================================
277 // private
278 // ===========================================================================
279 
280 void
281 GNERide::setAttribute(SumoXMLAttr key, const std::string& value) {
282  switch (key) {
283  case SUMO_ATTR_LINES:
284  myLines = GNEAttributeCarrier::parse<std::vector<std::string> >(value);
285  break;
286  case SUMO_ATTR_GROUP:
287  myGroup = value;
288  break;
289  default:
290  setPlanAttribute(key, value);
291  break;
292  }
293 }
294 
295 
296 void
298  // change both position
299  myArrivalPosition = moveResult.newSecondPos;
300  // update geometry
301  updateGeometry();
302 }
303 
304 
305 void
306 GNERide::commitMoveShape(const GNEMoveResult& moveResult, GNEUndoList* undoList) {
307  undoList->begin(this, "arrivalPos of " + getTagStr());
308  // now adjust start position
309  setAttribute(SUMO_ATTR_ARRIVALPOS, toString(moveResult.newFirstPos), undoList);
310  undoList->end();
311 }
312 
313 /****************************************************************************/
@ GLO_RIDE
a ride
@ GLO_PERSONTRIP
a person trip
GUIIcon
An enumeration of icons used by the gui applications.
Definition: GUIIcons.h:33
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)
@ SVC_PEDESTRIAN
pedestrian
SumoXMLTag
Numbers representing SUMO-XML - element names.
@ SUMO_TAG_RIDE
SumoXMLAttr
Numbers representing SUMO-XML - attributes.
@ SUMO_ATTR_LINES
@ SUMO_ATTR_ARRIVALPOS
@ SUMO_ATTR_GROUP
std::string joinToString(const std::vector< T > &v, const T_BETWEEN &between, std::streamsize accuracy=gPrecision)
Definition: ToString.h:283
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
const std::string & getTagStr() const
get tag assigned to this object in string format
void resetDefaultValues()
reset attribute carrier to their default values
GNENet * myNet
pointer to net
static void changeAttribute(GNEAttributeCarrier *AC, SumoXMLAttr key, const std::string &value, GNEUndoList *undoList, const bool force=false)
change attribute
Problem
enum class for demandElement problems
bool isPlanValid(SumoXMLAttr key, const std::string &value)
check if plan attribute is valid
Boundary getPlanCenteringBoundary() const
get plan centering boundary
Position getPlanPositionInView() const
Returns position of additional in view.
std::string getPersonPlanProblem() const
get plan problem
Position getPlanAttributePosition(SumoXMLAttr key) const
get plan attribute position
GNEDemandElement::Problem isPlanPersonValid() const
check if plan is valid
void drawPlanLanePartial(const bool drawPlan, const GUIVisualizationSettings &s, const GNEPathManager::Segment *segment, const double offsetFront, const double planWidth, const RGBColor &planColor, const RGBColor &planSelectedColor) const
draw plan partial lane
GUIGLObjectPopupMenu * getPlanPopUpMenu(GUIMainWindow &app, GUISUMOAbstractView &parent)
Returns an own popup-menu.
void drawPlanJunctionPartial(const bool drawPlan, const GUIVisualizationSettings &s, const GNEPathManager::Segment *segment, const double offsetFront, const double planWidth, const RGBColor &planColor, const RGBColor &planSelectedColor) const
draw plan partial junction
std::string getPlanHierarchyName() const
get plan Hierarchy Name (Used in AC Hierarchy)
void writeLocationAttributes(OutputDevice &device) const
write plan element common attributes
bool checkDrawPersonPlan() const
check if person plan can be drawn
GNEMoveOperation * getPlanMoveOperation()
get move operation
double getPlanAttributeDouble(SumoXMLAttr key) const
get plan attribute double
void setPlanAttribute(SumoXMLAttr key, const std::string &value, GNEUndoList *undoList)
set plan attribute
double myArrivalPosition
arrival position (used in all plans over edges)
std::string getPlanAttribute(SumoXMLAttr key) const
get plan attribute string
bool isPlanAttributeEnabled(SumoXMLAttr key) const
check if plan attribute is enabled
GNELane * getLastPlanPathLane() const
get last plan path lane
void drawPlanGL(const bool drawPlan, const GUIVisualizationSettings &s, const RGBColor &planColor, const RGBColor &planSelectedColor) const
draw plan
void updatePlanGeometry()
update pre-computed geometry information
GNELane * getFirstPlanPathLane() const
get first plan path lane
void writeOriginStop(OutputDevice &device) const
write initial stop stage if plan starts at a stopping place
const std::vector< GNEDemandElement * > & getParentDemandElements() const
get parent demand elements
This lane is powered by an underlying GNEEdge and basically knows how to draw itself.
Definition: GNELane.h:46
move operation
move result
double newFirstPos
new first position
double newSecondPos
new second position
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
void removePath(PathElement *pathElement)
remove path
bool isPathValid(const PathElement *pathElement) const
check if path element is valid
void calculatePath(PathElement *pathElement, SUMOVehicleClass vClass, GNELane *fromLane, GNELane *toLane)
calculate path between from-to edges (using dijkstra, require path calculator updated)
GNEPlanParents (used for group all plan parents)
std::vector< GNEAdditional * > getAdditionalElements() const
get additionalElements (used in plan constructors)
std::string myGroup
group
Definition: GNERide.h:213
double getAttributeDouble(SumoXMLAttr key) const
Definition: GNERide.cpp:215
Position getPositionInView() const
Returns position of additional in view.
Definition: GNERide.cpp:126
void fixDemandElementProblem()
fix demand element problem (by default throw an exception, has to be reimplemented in children)
Definition: GNERide.cpp:102
void splitEdgeGeometry(const double splitPosition, const GNENetworkElement *originalElement, const GNENetworkElement *newElement, GNEUndoList *undoList)
split geometry
Definition: GNERide.cpp:144
SUMOVehicleClass getVClass() const
obtain VClass related with this demand element
Definition: GNERide.cpp:108
std::string getDemandElementProblem() const
return a string with the current demand element problem (by default empty, can be reimplemented in ch...
Definition: GNERide.cpp:96
GNERide(SumoXMLTag tag, GNENet *net)
default constructor
Definition: GNERide.cpp:46
std::string getPopUpID() const
get PopPup ID (Used in AC Hierarchy)
Definition: GNERide.cpp:260
Boundary getCenteringBoundary() const
Returns the boundary to which the view shall be centered in order to show the object.
Definition: GNERide.cpp:138
void commitMoveShape(const GNEMoveResult &moveResult, GNEUndoList *undoList)
commit move shape
Definition: GNERide.cpp:306
void drawGL(const GUIVisualizationSettings &s) const
Draws the object.
Definition: GNERide.cpp:150
std::string getParentName() const
Returns the name of the parent object.
Definition: GNERide.cpp:132
~GNERide()
destructor
Definition: GNERide.cpp:55
GNEMoveOperation * getMoveOperation()
get move operation
Definition: GNERide.cpp:59
void updateGeometry()
update pre-computed geometry information
Definition: GNERide.cpp:120
Problem isDemandElementValid() const
check if current demand element is valid to be written into XML (by default true, can be reimplemente...
Definition: GNERide.cpp:90
GUIGLObjectPopupMenu * getPopUpMenu(GUIMainWindow &app, GUISUMOAbstractView &parent)
Returns an own popup-menu.
Definition: GNERide.cpp:65
bool isValid(SumoXMLAttr key, const std::string &value)
method for checking if the key and their conrrespond attribute are valids
Definition: GNERide.cpp:241
const RGBColor & getColor() const
get color
Definition: GNERide.cpp:114
Position getAttributePosition(SumoXMLAttr key) const
Definition: GNERide.cpp:221
const Parameterised::Map & getACParametersMap() const
get parameters map
Definition: GNERide.cpp:272
void drawJunctionPartialGL(const GUIVisualizationSettings &s, const GNEPathManager::Segment *segment, const double offsetFront) const
Draws partial object over junction.
Definition: GNERide.cpp:184
std::vector< std::string > myLines
valid line or vehicle ids or ANY
Definition: GNERide.h:210
GNELane * getLastPathLane() const
get last path lane
Definition: GNERide.cpp:196
bool isAttributeEnabled(SumoXMLAttr key) const
Definition: GNERide.cpp:254
void computePathElement()
compute pathElement
Definition: GNERide.cpp:156
void setAttribute(SumoXMLAttr key, const std::string &value, GNEUndoList *undoList)
method for setting the attribute and letting the object perform demand element changes
Definition: GNERide.cpp:227
std::string getAttribute(SumoXMLAttr key) const
inherited from GNEAttributeCarrier
Definition: GNERide.cpp:202
void setMoveShape(const GNEMoveResult &moveResult)
set move shape
Definition: GNERide.cpp:297
GNELane * getFirstPathLane() const
get first path lane
Definition: GNERide.cpp:190
std::string getHierarchyName() const
get Hierarchy Name (Used in AC Hierarchy)
Definition: GNERide.cpp:266
void writeDemandElement(OutputDevice &device) const
write demand element element into a xml file
Definition: GNERide.cpp:71
void drawLanePartialGL(const GUIVisualizationSettings &s, const GNEPathManager::Segment *segment, const double offsetFront) const
Draws partial object over lane.
Definition: GNERide.cpp:178
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...
The popup menu of a globject.
const GUIVisualizationSettings & getVisualisationSettings() const
get visualization settings (read only)
Stores the information about how to visualize structures.
GUIVisualizationWidthSettings widthSettings
width settings
GUIVisualizationColorSettings colorSettings
color settings
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.
std::map< std::string, std::string > Map
parameters map
Definition: Parameterised.h:45
const Parameterised::Map & getParametersMap() const
Returns the inner key/value map.
A point in 2D or 3D with translation and scaling methods.
Definition: Position.h:37
RGBColor selectedPersonPlanColor
person plan selection color (Rides, Walks, stopPersons...)