Eclipse SUMO - Simulation of Urban MObility
GNETransport.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 transports in Netedit
19 /****************************************************************************/
20 
23 #include <netedit/GNENet.h>
24 #include <netedit/GNEUndoList.h>
25 #include <netedit/GNEViewNet.h>
27 
28 #include "GNETransport.h"
29 
30 // ===========================================================================
31 // method definitions
32 // ===========================================================================
33 
36  GNEPathManager::PathElement::Options::DEMAND_ELEMENT, {}, {}, {}, {}, {}, {}),
37 GNEDemandElementPlan(this, -1, -1) {
38  // reset default values
40 }
41 
42 
43 GNETransport::GNETransport(GNENet* net, SumoXMLTag tag, GUIIcon icon, GNEDemandElement* containerParent, const GNEPlanParents& planParameters,
44  const double arrivalPosition, const std::vector<std::string>& lines, const std::string& group) :
45  GNEDemandElement(containerParent, net, GLO_TRANSPORT, tag, GUIIconSubSys::getIcon(icon),
46  GNEPathManager::PathElement::Options::DEMAND_ELEMENT,
47  planParameters.getJunctions(), planParameters.getEdges(), {},
48 planParameters.getAdditionalElements(), planParameters.getDemandElements(containerParent), {}),
49 GNEDemandElementPlan(this, -1, arrivalPosition),
50 myLines(lines),
51 myGroup(group) {
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
77  if (myLines.size() > 0) {
79  }
80  if (myGroup.size() > 0) {
82  }
83  device.closeTag();
84 }
85 
86 
89  return isPlanPersonValid();
90 }
91 
92 
93 std::string
95  return getPersonPlanProblem();
96 }
97 
98 
99 void
101  // currently the only solution is removing Transport
102 }
103 
104 
107  return SVC_IGNORING;
108 }
109 
110 
111 const RGBColor&
114 }
115 
116 
117 void
120 }
121 
122 
123 Position
125  return getPlanPositionInView();
126 }
127 
128 
129 std::string
131  return getParentDemandElements().front()->getID();
132 }
133 
134 
135 Boundary
137  return getPlanCenteringBoundary();
138 }
139 
140 
141 void
142 GNETransport::splitEdgeGeometry(const double /*splitPosition*/, const GNENetworkElement* /*originalElement*/, const GNENetworkElement* /*newElement*/, GNEUndoList* /*undoList*/) {
143  // Nothing to do
144 }
145 
146 
147 void
150 }
151 
152 
153 void
156 }
157 
158 
159 void
160 GNETransport::drawLanePartialGL(const GUIVisualizationSettings& s, const GNEPathManager::Segment* segment, const double offsetFront) const {
162 }
163 
164 
165 void
166 GNETransport::drawJunctionPartialGL(const GUIVisualizationSettings& s, const GNEPathManager::Segment* segment, const double offsetFront) const {
168 }
169 
170 
171 GNELane*
173  return getFirstPlanPathLane();
174 }
175 
176 
177 GNELane*
179  return getLastPlanPathLane();
180 }
181 
182 
183 std::string
185  switch (key) {
186  // specific person plan attributes
187  case SUMO_ATTR_LINES:
188  return joinToString(myLines, " ");
189  case SUMO_ATTR_GROUP:
190  return myGroup;
191  default:
192  return getPlanAttribute(key);
193  }
194 }
195 
196 
197 double
199  return getPlanAttributeDouble(key);
200 }
201 
202 
203 Position
205  return getPlanAttributePosition(key);
206 }
207 
208 
209 void
210 GNETransport::setAttribute(SumoXMLAttr key, const std::string& value, GNEUndoList* undoList) {
211  switch (key) {
212  case SUMO_ATTR_LINES:
213  case SUMO_ATTR_GROUP:
214  GNEChange_Attribute::changeAttribute(this, key, value, undoList);
215  break;
216  default:
217  setPlanAttribute(key, value, undoList);
218  break;
219  }
220 }
221 
222 
223 bool
224 GNETransport::isValid(SumoXMLAttr key, const std::string& value) {
225  switch (key) {
226  // specific person plan attributes
227  case SUMO_ATTR_LINES:
228  return canParse<std::vector<std::string> >(value);
229  case SUMO_ATTR_GROUP:
230  return true;
231  default:
232  return isPlanValid(key, value);
233  }
234 }
235 
236 
237 bool
239  return isPlanAttributeEnabled(key);
240 }
241 
242 
243 std::string
245  return getTagStr();
246 }
247 
248 
249 std::string
251  return getPlanHierarchyName();
252 }
253 
254 
255 const Parameterised::Map&
257  return getParametersMap();
258 }
259 
260 // ===========================================================================
261 // private
262 // ===========================================================================
263 
264 void
265 GNETransport::setAttribute(SumoXMLAttr key, const std::string& value) {
266  switch (key) {
267  // specific person plan attributes
268  case SUMO_ATTR_LINES:
269  myLines = GNEAttributeCarrier::parse<std::vector<std::string> >(value);
270  break;
271  case SUMO_ATTR_GROUP:
272  myGroup = value;
273  break;
274  default:
275  setPlanAttribute(key, value);
276  break;
277  }
278 }
279 
280 
281 void
283  // change both position
284  myArrivalPosition = moveResult.newFirstPos;
285  // update geometry
286  updateGeometry();
287 }
288 
289 
290 void
292  undoList->begin(this, "arrivalPos of " + getTagStr());
293  // now adjust start position
294  setAttribute(SUMO_ATTR_ARRIVALPOS, toString(moveResult.newFirstPos), undoList);
295  undoList->end();
296 }
297 
298 /****************************************************************************/
@ GLO_TRANSPORT
a container transport
GUIIcon
An enumeration of icons used by the gui applications.
Definition: GUIIcons.h:33
@ TRANSHIP_EDGE
SUMOVehicleClass
Definition of vehicle classes to differ between different lane usage and authority types.
@ SVC_IGNORING
vehicles ignoring classes
SumoXMLTag
Numbers representing SUMO-XML - element names.
@ SUMO_TAG_TRANSPORT
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
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
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
bool checkDrawContainerPlan() const
check if container plan can be drawn
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
A NBNetBuilder extended by visualisation and editing capabilities.
Definition: GNENet.h:42
GNEViewNet * getViewNet() const
get view net
Definition: GNENet.cpp:2136
GNEPlanParents (used for group all plan parents)
std::vector< GNEAdditional * > getAdditionalElements() const
get additionalElements (used in plan constructors)
std::string getAttribute(SumoXMLAttr key) const
inherited from GNEAttributeCarrier
Boundary getCenteringBoundary() const
Returns the boundary to which the view shall be centered in order to show the object.
GNELane * getLastPathLane() const
get last path lane
void drawJunctionPartialGL(const GUIVisualizationSettings &s, const GNEPathManager::Segment *segment, const double offsetFront) const
Draws partial object over junction.
GUIGLObjectPopupMenu * getPopUpMenu(GUIMainWindow &app, GUISUMOAbstractView &parent)
Returns an own popup-menu.
void commitMoveShape(const GNEMoveResult &moveResult, GNEUndoList *undoList)
commit move shape
void computePathElement()
compute pathElement
std::string myGroup
group
Definition: GNETransport.h:214
void setMoveShape(const GNEMoveResult &moveResult)
set move shape
Problem isDemandElementValid() const
check if current demand element is valid to be written into XML (by default true, can be reimplemente...
void fixDemandElementProblem()
fix demand element problem (by default throw an exception, has to be reimplemented in children)
GNELane * getFirstPathLane() const
get first path lane
Position getAttributePosition(SumoXMLAttr key) const
void writeDemandElement(OutputDevice &device) const
write demand element element into a xml file
bool isValid(SumoXMLAttr key, const std::string &value)
method for checking if the key and their conrrespond attribute are valids
GNEMoveOperation * getMoveOperation()
get move operation
const RGBColor & getColor() const
get color
void drawGL(const GUIVisualizationSettings &s) const
Draws the object.
GNETransport(SumoXMLTag tag, GNENet *net)
default constructor
void splitEdgeGeometry(const double splitPosition, const GNENetworkElement *originalElement, const GNENetworkElement *newElement, GNEUndoList *undoList)
split geometry
std::string getDemandElementProblem() const
return a string with the current demand element problem (by default empty, can be reimplemented in ch...
std::string getPopUpID() const
get PopPup ID (Used in AC Hierarchy)
const Parameterised::Map & getACParametersMap() const
get parameters map
double getAttributeDouble(SumoXMLAttr key) const
bool isAttributeEnabled(SumoXMLAttr key) const
void setAttribute(SumoXMLAttr key, const std::string &value, GNEUndoList *undoList)
method for setting the attribute and letting the object perform demand element changes
std::vector< std::string > myLines
The list of lines that are assigned to this stop.
Definition: GNETransport.h:211
std::string getParentName() const
Returns the name of the parent object.
~GNETransport()
destructor
SUMOVehicleClass getVClass() const
obtain VClass related with this demand element
std::string getHierarchyName() const
get Hierarchy Name (Used in AC Hierarchy)
Position getPositionInView() const
Returns position of additional in view.
void updateGeometry()
update pre-computed geometry information
void drawLanePartialGL(const GUIVisualizationSettings &s, const GNEPathManager::Segment *segment, const double offsetFront) const
Draws partial object over lane.
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 transportColor
color for transport
RGBColor selectedContainerPlanColor
container plan selection color (Rides, Walks, containerStops...)