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*
36  GNEEdge* fromEdge, GNEAdditional* fromBusStop, GNEAdditional* fromTrainStop,
37  GNEEdge* toEdge, GNEAdditional* toBusStop, GNEAdditional* toTrainStop,
38  double arrivalPosition, const std::vector<std::string>& lines) {
39  // declare icon an tag
40  const auto iconTag = getRideTagIcon(fromEdge, toEdge, fromBusStop, toBusStop, fromTrainStop, toTrainStop);
41  // declare containers
42  std::vector<GNEJunction*> junctions;
43  std::vector<GNEEdge*> edges;
44  std::vector<GNEAdditional*> additionals;
45  // continue depending of input parameters
46  if (fromEdge) {
47  edges.push_back(fromEdge);
48  } else if (fromBusStop) {
49  additionals.push_back(fromBusStop);
50  } else if (fromTrainStop) {
51  additionals.push_back(fromTrainStop);
52  }
53  if (toEdge) {
54  edges.push_back(toEdge);
55  } else if (toBusStop) {
56  additionals.push_back(toBusStop);
57  } else if (toTrainStop) {
58  additionals.push_back(toTrainStop);
59  }
60  return new GNERide(net, iconTag.first, iconTag.second, personParent, edges, additionals, arrivalPosition, lines);
61 }
62 
63 
65  GNEDemandElement("", net, GLO_RIDE, tag, GUIIconSubSys::getIcon(GUIIcon::RIDE_EDGE),
66  GNEPathManager::PathElement::Options::DEMAND_ELEMENT, {}, {}, {}, {}, {}, {}),
67 GNEDemandElementPlan(this, -1, -1) {
68  // reset default values
70 }
71 
72 
74 
75 
78  return getPlanMoveOperation();
79 }
80 
81 
84  return getPlanPopUpMenu(app, parent);
85 }
86 
87 
88 void
90  writeOriginStop(device);
91  device.openTag(SUMO_TAG_RIDE);
93  if (myLines.empty()) {
94  device.writeAttr(SUMO_ATTR_LINES, "ANY");
95  } else {
97  }
98  device.closeTag();
99 }
100 
101 
104  return isPlanPersonValid();
105 }
106 
107 
108 std::string
110  return getPersonPlanProblem();
111 }
112 
113 
114 void
116  // currently the only solution is removing Ride
117 }
118 
119 
122  return SVC_PEDESTRIAN;
123 }
124 
125 
126 const RGBColor&
129 }
130 
131 
132 void
135 }
136 
137 
138 Position
140  return getPlanPositionInView();
141 }
142 
143 
144 std::string
146  return getParentDemandElements().front()->getID();
147 }
148 
149 
150 Boundary
152  return getPlanCenteringBoundary();
153 }
154 
155 
156 void
157 GNERide::splitEdgeGeometry(const double /*splitPosition*/, const GNENetworkElement* /*originalElement*/, const GNENetworkElement* /*newElement*/, GNEUndoList* /*undoList*/) {
158  // geometry of this element cannot be splitted
159 }
160 
161 
162 void
165 }
166 
167 
168 void
170  // get first and last path lanes
171  const auto firstPathLane = getFirstPathLane();
172  const auto lastPathLane = getLastPathLane();
173  // continue depending of pathLane
174  if (firstPathLane && lastPathLane) {
175  // calculate path
176  myNet->getPathManager()->calculatePath(this, SVC_PASSENGER, firstPathLane, lastPathLane);
177  // check if calculate ignoring path
178  if (!myNet->getPathManager()->isPathValid(this)) {
179  myNet->getPathManager()->calculatePath(this, SVC_IGNORING, firstPathLane, lastPathLane);
180  }
181  } else {
182  // reset path
183  myNet->getPathManager()->removePath(this);
184  }
185  // update geometry
186  updateGeometry();
187 }
188 
189 
190 void
191 GNERide::drawLanePartialGL(const GUIVisualizationSettings& s, const GNEPathManager::Segment* segment, const double offsetFront) const {
193 }
194 
195 
196 void
197 GNERide::drawJunctionPartialGL(const GUIVisualizationSettings& s, const GNEPathManager::Segment* segment, const double offsetFront) const {
199 }
200 
201 
202 GNELane*
204  return getFirstPlanPathLane();
205 }
206 
207 
208 GNELane*
210  return getLastPlanPathLane();
211 }
212 
213 
214 std::string
216  switch (key) {
217  case SUMO_ATTR_LINES:
218  return joinToString(myLines, " ");
219  default:
220  return getPlanAttribute(key);
221  }
222 }
223 
224 
225 double
227  return getPlanAttributeDouble(key);
228 }
229 
230 
231 Position
233  return getPlanAttributePosition(key);
234 }
235 
236 
237 void
238 GNERide::setAttribute(SumoXMLAttr key, const std::string& value, GNEUndoList* undoList) {
239  switch (key) {
240  case SUMO_ATTR_LINES:
241  GNEChange_Attribute::changeAttribute(this, key, value, undoList);
242  break;
243  default:
244  setPlanAttribute(key, value, undoList);
245  break;
246  }
247 }
248 
249 
250 bool
251 GNERide::isValid(SumoXMLAttr key, const std::string& value) {
252  switch (key) {
253  case SUMO_ATTR_LINES:
254  return canParse<std::vector<std::string> >(value);
255  default:
256  return isPlanValid(key, value);
257  }
258 }
259 
260 
261 bool
263  return isPlanAttributeEnabled(key);
264 }
265 
266 
267 std::string
269  return getTagStr();
270 }
271 
272 
273 std::string
275  return getPlanHierarchyName();
276 }
277 
278 
279 const Parameterised::Map&
281  return getParametersMap();
282 }
283 
284 // ===========================================================================
285 // private
286 // ===========================================================================
287 
288 void
289 GNERide::setAttribute(SumoXMLAttr key, const std::string& value) {
290  switch (key) {
291  case SUMO_ATTR_LINES:
292  myLines = GNEAttributeCarrier::parse<std::vector<std::string> >(value);
293  break;
294  default:
295  setPlanAttribute(key, value);
296  break;
297  }
298 }
299 
300 
301 void
303  // change both position
304  myArrivalPosition = moveResult.newSecondPos;
305  // update geometry
306  updateGeometry();
307 }
308 
309 
310 void
311 GNERide::commitMoveShape(const GNEMoveResult& moveResult, GNEUndoList* undoList) {
312  undoList->begin(this, "arrivalPos of " + getTagStr());
313  // now adjust start position
314  setAttribute(SUMO_ATTR_ARRIVALPOS, toString(moveResult.newFirstPos), undoList);
315  undoList->end();
316 }
317 
318 
319 GNERide::GNERide(GNENet* net, SumoXMLTag tag, GUIIcon icon, GNEDemandElement* personParent, const std::vector<GNEEdge*>& edges,
320  const std::vector<GNEAdditional*>& additionals, double arrivalPosition, const std::vector<std::string>& lines) :
321  GNEDemandElement(personParent, net, GLO_PERSONTRIP, tag, GUIIconSubSys::getIcon(icon),
322  GNEPathManager::PathElement::Options::DEMAND_ELEMENT, {}, edges, {}, additionals, {personParent}, {}),
323 GNEDemandElementPlan(this, -1, arrivalPosition),
324 myLines(lines) {
325 }
326 
327 /****************************************************************************/
@ 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
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
An Element which don't belong to GNENet but has influence in the simulation.
Definition: GNEAdditional.h:49
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 centering boundaryt
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)
static std::pair< SumoXMLTag, GUIIcon > getRideTagIcon(const GNEEdge *fromEdge, const GNEEdge *toEdge, const GNEAdditional *fromBusStop, const GNEAdditional *toBusStop, const GNEAdditional *fromTrainStop, const GNEAdditional *toTrainStop)
get the ride tag and icon for the combination
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
A road/street connecting two junctions (netedit-version)
Definition: GNEEdge.h:53
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:133
GNEViewNet * getViewNet() const
get view net
Definition: GNENet.cpp:2022
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)
double getAttributeDouble(SumoXMLAttr key) const
Definition: GNERide.cpp:226
Position getPositionInView() const
Returns position of additional in view.
Definition: GNERide.cpp:139
void fixDemandElementProblem()
fix demand element problem (by default throw an exception, has to be reimplemented in children)
Definition: GNERide.cpp:115
void splitEdgeGeometry(const double splitPosition, const GNENetworkElement *originalElement, const GNENetworkElement *newElement, GNEUndoList *undoList)
split geometry
Definition: GNERide.cpp:157
SUMOVehicleClass getVClass() const
obtain VClass related with this demand element
Definition: GNERide.cpp:121
std::string getDemandElementProblem() const
return a string with the current demand element problem (by default empty, can be reimplemented in ch...
Definition: GNERide.cpp:109
GNERide(SumoXMLTag tag, GNENet *net)
default constructor
Definition: GNERide.cpp:64
std::string getPopUpID() const
get PopPup ID (Used in AC Hierarchy)
Definition: GNERide.cpp:268
Boundary getCenteringBoundary() const
Returns the boundary to which the view shall be centered in order to show the object.
Definition: GNERide.cpp:151
void commitMoveShape(const GNEMoveResult &moveResult, GNEUndoList *undoList)
commit move shape
Definition: GNERide.cpp:311
void drawGL(const GUIVisualizationSettings &s) const
Draws the object.
Definition: GNERide.cpp:163
std::string getParentName() const
Returns the name of the parent object.
Definition: GNERide.cpp:145
~GNERide()
destructor
Definition: GNERide.cpp:73
GNEMoveOperation * getMoveOperation()
get move operation
Definition: GNERide.cpp:77
void updateGeometry()
update pre-computed geometry information
Definition: GNERide.cpp:133
Problem isDemandElementValid() const
check if current demand element is valid to be written into XML (by default true, can be reimplemente...
Definition: GNERide.cpp:103
GUIGLObjectPopupMenu * getPopUpMenu(GUIMainWindow &app, GUISUMOAbstractView &parent)
Returns an own popup-menu.
Definition: GNERide.cpp:83
static GNERide * buildRide(GNENet *net, GNEDemandElement *personParent, GNEEdge *fromEdge, GNEAdditional *fromBusStop, GNEAdditional *fromTrainStop, GNEEdge *toEdge, GNEAdditional *toBusStop, GNEAdditional *toTrainStop, double arrivalPosition, const std::vector< std::string > &lines)
general constructor for rides
Definition: GNERide.cpp:35
bool isValid(SumoXMLAttr key, const std::string &value)
method for checking if the key and their conrrespond attribute are valids
Definition: GNERide.cpp:251
const RGBColor & getColor() const
get color
Definition: GNERide.cpp:127
Position getAttributePosition(SumoXMLAttr key) const
Definition: GNERide.cpp:232
const Parameterised::Map & getACParametersMap() const
get parameters map
Definition: GNERide.cpp:280
void drawJunctionPartialGL(const GUIVisualizationSettings &s, const GNEPathManager::Segment *segment, const double offsetFront) const
Draws partial object over junction.
Definition: GNERide.cpp:197
std::vector< std::string > myLines
valid line or vehicle ids or ANY
Definition: GNERide.h:215
GNELane * getLastPathLane() const
get last path lane
Definition: GNERide.cpp:209
bool isAttributeEnabled(SumoXMLAttr key) const
Definition: GNERide.cpp:262
void computePathElement()
compute pathElement
Definition: GNERide.cpp:169
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:238
std::string getAttribute(SumoXMLAttr key) const
inherited from GNEAttributeCarrier
Definition: GNERide.cpp:215
void setMoveShape(const GNEMoveResult &moveResult)
set move shape
Definition: GNERide.cpp:302
GNELane * getFirstPathLane() const
get first path lane
Definition: GNERide.cpp:203
std::string getHierarchyName() const
get Hierarchy Name (Used in AC Hierarchy)
Definition: GNERide.cpp:274
void writeDemandElement(OutputDevice &device) const
write demand element element into a xml file
Definition: GNERide.cpp:89
void drawLanePartialGL(const GUIVisualizationSettings &s, const GNEPathManager::Segment *segment, const double offsetFront) const
Draws partial object over lane.
Definition: GNERide.cpp:191
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...)