Eclipse SUMO - Simulation of Urban MObility
GNEPersonTrip.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 person trips in Netedit
19 /****************************************************************************/
20 
23 #include <netedit/GNENet.h>
24 #include <netedit/GNEUndoList.h>
25 #include <netedit/GNEViewNet.h>
27 
28 #include "GNEPersonTrip.h"
29 
30 // ===========================================================================
31 // method definitions
32 // ===========================================================================
33 
36  GNEEdge* fromEdge, GNEAdditional* fromTAZ, GNEJunction* fromJunction, GNEAdditional* fromBusStop, GNEAdditional* fromTrainStop,
37  GNEEdge* toEdge, GNEAdditional* toTAZ, GNEJunction* toJunction, GNEAdditional* toBusStop, GNEAdditional* toTrainStop,
38  double arrivalPosition, const std::vector<std::string>& types, const std::vector<std::string>& modes,
39  const std::vector<std::string>& lines) {
40  // declare icon an tag
41  const auto iconTag = getPersonTripTagIcon(fromEdge, toEdge, fromTAZ, toTAZ, fromJunction, toJunction,
42  fromBusStop, toBusStop, fromTrainStop, toTrainStop);
43  // declare containers
44  std::vector<GNEJunction*> junctions;
45  std::vector<GNEEdge*> edges;
46  std::vector<GNEAdditional*> additionals;
47  // continue depending of input parameters
48  if (fromEdge) {
49  edges.push_back(fromEdge);
50  } else if (fromTAZ) {
51  additionals.push_back(fromTAZ);
52  } else if (fromJunction) {
53  junctions.push_back(fromJunction);
54  } else if (fromBusStop) {
55  additionals.push_back(fromBusStop);
56  } else if (fromTrainStop) {
57  additionals.push_back(fromTrainStop);
58  }
59  if (toEdge) {
60  edges.push_back(toEdge);
61  } else if (toTAZ) {
62  additionals.push_back(toTAZ);
63  } else if (toJunction) {
64  junctions.push_back(toJunction);
65  } else if (toBusStop) {
66  additionals.push_back(toBusStop);
67  } else if (toTrainStop) {
68  additionals.push_back(toTrainStop);
69  }
70  return new GNEPersonTrip(net, iconTag.first, iconTag.second, personParent, junctions, edges, additionals, arrivalPosition, types, modes, lines);
71 }
72 
73 
76  GNEPathManager::PathElement::Options::DEMAND_ELEMENT, {}, {}, {}, {}, {}, {}),
77 GNEDemandElementPlan(this, -1, -1) {
78  // reset default values
80 }
81 
82 
84 
85 
88  return getPlanMoveOperation();
89 }
90 
91 
94  return getPlanPopUpMenu(app, parent);
95 }
96 
97 
98 void
100  writeOriginStop(device);
102  writeLocationAttributes(device);
103  if (myModes.size() > 0) {
105  }
106  if (myLines.size() > 0 && (myLines.size() != 1 || myLines.front() != "ANY")) {
108  }
109  if (myVTypes.size() > 0) {
111  }
112  device.closeTag();
113 }
114 
115 
118  return isPlanPersonValid();
119 }
120 
121 
122 std::string
124  return getPersonPlanProblem();
125 }
126 
127 
128 void
130  // currently the only solution is removing PersonTrip
131 }
132 
133 
136  return SVC_PEDESTRIAN;
137 }
138 
139 
140 const RGBColor&
143 }
144 
145 
146 void
149 }
150 
151 
152 Position
154  return getPlanPositionInView();
155 }
156 
157 
158 std::string
160  return getParentDemandElements().front()->getID();
161 }
162 
163 
164 Boundary
166  return getPlanCenteringBoundary();
167 }
168 
169 
170 void
171 GNEPersonTrip::splitEdgeGeometry(const double /*splitPosition*/, const GNENetworkElement* /*originalElement*/, const GNENetworkElement* /*newElement*/, GNEUndoList* /*undoList*/) {
172  // geometry of this element cannot be splitted
173 }
174 
175 
176 void
179 }
180 
181 
182 void
185 }
186 
187 
188 void
189 GNEPersonTrip::drawLanePartialGL(const GUIVisualizationSettings& s, const GNEPathManager::Segment* segment, const double offsetFront) const {
191 }
192 
193 
194 void
195 GNEPersonTrip::drawJunctionPartialGL(const GUIVisualizationSettings& s, const GNEPathManager::Segment* segment, const double offsetFront) const {
197 }
198 
199 
200 GNELane*
202  return getFirstPlanPathLane();
203 }
204 
205 
206 GNELane*
208  return getLastPlanPathLane();
209 }
210 
211 
212 std::string
214  switch (key) {
215  // specific person plan attributes
216  case SUMO_ATTR_MODES:
217  return joinToString(myModes, " ");
218  case SUMO_ATTR_VTYPES:
219  return joinToString(myVTypes, " ");
220  case SUMO_ATTR_LINES:
221  return joinToString(myLines, " ");
222  default:
223  return getPlanAttribute(key);
224  }
225 }
226 
227 
228 double
230  return getPlanAttributeDouble(key);
231 }
232 
233 
234 Position
236  return getPlanAttributePosition(key);
237 }
238 
239 
240 void
241 GNEPersonTrip::setAttribute(SumoXMLAttr key, const std::string& value, GNEUndoList* undoList) {
242  switch (key) {
243  case SUMO_ATTR_MODES:
244  case SUMO_ATTR_VTYPES:
245  case SUMO_ATTR_LINES:
246  GNEChange_Attribute::changeAttribute(this, key, value, undoList);
247  break;
248  default:
249  setPlanAttribute(key, value, undoList);
250  break;
251  }
252 }
253 
254 
255 bool
256 GNEPersonTrip::isValid(SumoXMLAttr key, const std::string& value) {
257  switch (key) {
258  // specific person plan attributes
259  case SUMO_ATTR_MODES: {
260  SVCPermissions dummyModeSet;
261  std::string dummyError;
262  return SUMOVehicleParameter::parsePersonModes(value, myTagProperty.getTagStr(), "", dummyModeSet, dummyError);
263  }
264  case SUMO_ATTR_VTYPES:
265  return canParse<std::vector<std::string> >(value);
266  case SUMO_ATTR_LINES:
267  return canParse<std::vector<std::string> >(value);
268  default:
269  return isPlanValid(key, value);
270  }
271 }
272 
273 
274 bool
276  return isPlanAttributeEnabled(key);
277 }
278 
279 
280 std::string
282  return getTagStr();
283 }
284 
285 
286 std::string
288  return getPlanHierarchyName();
289 }
290 
291 
292 const Parameterised::Map&
294  return getParametersMap();
295 }
296 
297 // ===========================================================================
298 // private
299 // ===========================================================================
300 
301 void
302 GNEPersonTrip::setAttribute(SumoXMLAttr key, const std::string& value) {
303  switch (key) {
304  // specific person plan attributes
305  case SUMO_ATTR_MODES:
306  myModes = GNEAttributeCarrier::parse<std::vector<std::string> >(value);
307  break;
308  case SUMO_ATTR_VTYPES:
309  myVTypes = GNEAttributeCarrier::parse<std::vector<std::string> >(value);
310  break;
311  case SUMO_ATTR_LINES:
312  myLines = GNEAttributeCarrier::parse<std::vector<std::string> >(value);
313  break;
314  default:
315  setPlanAttribute(key, value);
316  break;
317  }
318 }
319 
320 
321 void
323  // change both position
324  myArrivalPosition = moveResult.newFirstPos;
325  // update geometry
326  updateGeometry();
327 }
328 
329 
330 void
332  undoList->begin(this, "arrivalPos of " + getTagStr());
333  // now adjust start position
334  setAttribute(SUMO_ATTR_ARRIVALPOS, toString(moveResult.newFirstPos), undoList);
335  undoList->end();
336 }
337 
338 
339 GNEPersonTrip::GNEPersonTrip(GNENet* net, SumoXMLTag tag, GUIIcon icon, GNEDemandElement* personParent, const std::vector<GNEJunction*>& junctions,
340  const std::vector<GNEEdge*>& edges, const std::vector<GNEAdditional*>& additionals, double arrivalPosition,
341  const std::vector<std::string>& types, const std::vector<std::string>& modes, const std::vector<std::string>& lines) :
342  GNEDemandElement(personParent, net, GLO_PERSONTRIP, tag, GUIIconSubSys::getIcon(icon),
343  GNEPathManager::PathElement::Options::DEMAND_ELEMENT, junctions, edges, {}, additionals, {personParent}, {}),
344 GNEDemandElementPlan(this, -1, arrivalPosition),
345 myVTypes(types),
346 myModes(modes),
347 myLines(lines) {
348 }
349 
350 /****************************************************************************/
@ GLO_PERSONTRIP
a person trip
GUIIcon
An enumeration of icons used by the gui applications.
Definition: GUIIcons.h:33
@ PERSONTRIP_EDGE
long long int SVCPermissions
bitset where each bit declares whether a certain SVC may use this edge/lane
SUMOVehicleClass
Definition of vehicle classes to differ between different lane usage and authority types.
@ SVC_PEDESTRIAN
pedestrian
SumoXMLTag
Numbers representing SUMO-XML - element names.
@ SUMO_TAG_PERSONTRIP
SumoXMLAttr
Numbers representing SUMO-XML - attributes.
@ SUMO_ATTR_LINES
@ SUMO_ATTR_ARRIVALPOS
@ SUMO_ATTR_MODES
@ SUMO_ATTR_VTYPES
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
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
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
void computePlanPathElement()
compute plan pathElement
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
static std::pair< SumoXMLTag, GUIIcon > getPersonTripTagIcon(const GNEEdge *fromEdge, const GNEEdge *toEdge, const GNEAdditional *fromTAZ, const GNEAdditional *toTAZ, const GNEJunction *fromJunction, const GNEJunction *toJunction, const GNEAdditional *fromBusStop, const GNEAdditional *toBusStop, const GNEAdditional *fromTrainStop, const GNEAdditional *toTrainStop)
get the personTrip tag and icon for the combination
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
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
A NBNetBuilder extended by visualisation and editing capabilities.
Definition: GNENet.h:42
GNEViewNet * getViewNet() const
get view net
Definition: GNENet.cpp:2055
void writeDemandElement(OutputDevice &device) const
write demand element element into a xml file
void splitEdgeGeometry(const double splitPosition, const GNENetworkElement *originalElement, const GNENetworkElement *newElement, GNEUndoList *undoList)
split geometry
void drawJunctionPartialGL(const GUIVisualizationSettings &s, const GNEPathManager::Segment *segment, const double offsetFront) const
Draws partial object over junction.
GNELane * getLastPathLane() const
get last path lane
GNEMoveOperation * getMoveOperation()
get move operation
void setAttribute(SumoXMLAttr key, const std::string &value, GNEUndoList *undoList)
method for setting the attribute and letting the object perform demand element changes
Position getPositionInView() const
Returns position of additional in view.
GUIGLObjectPopupMenu * getPopUpMenu(GUIMainWindow &app, GUISUMOAbstractView &parent)
Returns an own popup-menu.
bool isAttributeEnabled(SumoXMLAttr key) const
void updateGeometry()
update pre-computed geometry information
std::vector< std::string > myModes
valid line or modes
Boundary getCenteringBoundary() const
Returns the boundary to which the view shall be centered in order to show the object.
void drawLanePartialGL(const GUIVisualizationSettings &s, const GNEPathManager::Segment *segment, const double offsetFront) const
Draws partial object over lane.
static GNEPersonTrip * buildPersonTrip(GNENet *net, GNEDemandElement *personParent, GNEEdge *fromEdge, GNEAdditional *fromTAZ, GNEJunction *fromJunction, GNEAdditional *fromBusStop, GNEAdditional *fromTrainStop, GNEEdge *toEdge, GNEAdditional *toTAZ, GNEJunction *toJunction, GNEAdditional *toBusStop, GNEAdditional *toTrainStop, double arrivalPosition, const std::vector< std::string > &types, const std::vector< std::string > &modes, const std::vector< std::string > &lines)
general constructor for personTrip
void drawGL(const GUIVisualizationSettings &s) const
Draws the object.
std::string getPopUpID() const
get PopPup ID (Used in AC Hierarchy)
Position getAttributePosition(SumoXMLAttr key) const
std::string getHierarchyName() const
get Hierarchy Name (Used in AC Hierarchy)
bool isValid(SumoXMLAttr key, const std::string &value)
method for checking if the key and their conrrespond attribute are valids
std::string getAttribute(SumoXMLAttr key) const
inherited from GNEAttributeCarrier
const RGBColor & getColor() const
get color
std::vector< std::string > myVTypes
valid line or vehicle types
std::string getParentName() const
Returns the name of the parent object.
double getAttributeDouble(SumoXMLAttr key) const
void commitMoveShape(const GNEMoveResult &moveResult, GNEUndoList *undoList)
commit move shape
~GNEPersonTrip()
destructor
void fixDemandElementProblem()
fix demand element problem (by default throw an exception, has to be reimplemented in children)
Problem isDemandElementValid() const
check if current demand element is valid to be written into XML (by default true, can be reimplemente...
SUMOVehicleClass getVClass() const
obtain VClass related with this demand element
const Parameterised::Map & getACParametersMap() const
get parameters map
GNEPersonTrip(SumoXMLTag tag, GNENet *net)
default constructor
std::string getDemandElementProblem() const
return a string with the current demand element problem (by default empty, can be reimplemented in ch...
void setMoveShape(const GNEMoveResult &moveResult)
set move shape
std::vector< std::string > myLines
valid line or vehicle ids or ANY
void computePathElement()
compute pathElement
GNELane * getFirstPathLane() const
get first path lane
const std::string & getTagStr() const
get Tag vinculated with this attribute Property in String Format (used to avoid multiple calls to toS...
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
static bool parsePersonModes(const std::string &modes, const std::string &element, const std::string &id, SVCPermissions &modeSet, std::string &error)
Validates a given person modes value.
RGBColor selectedPersonPlanColor
person plan selection color (Rides, Walks, stopPersons...)
RGBColor personTripColor
color for stopPersons
double personTripWidth
width for person trips