Eclipse SUMO - Simulation of Urban MObility
Loading...
Searching...
No Matches
GNETranship.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-2025 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 tranships in Netedit
19/****************************************************************************/
20
22#include <netedit/GNENet.h>
23
24#include "GNETranship.h"
25
26
27// ===========================================================================
28// method definitions
29// ===========================================================================
30#ifdef _MSC_VER
31#pragma warning(push)
32#pragma warning(disable: 4355) // mask warning about "this" in initializers
33#endif
35 GNEDemandElement("", net, "", tag, GNEPathElement::Options::DEMAND_ELEMENT),
36 GNEDemandElementPlan(this, -1, -1) {
37}
38
39
40GNETranship::GNETranship(SumoXMLTag tag, GNEDemandElement* containerParent, const GNEPlanParents& planParameters,
41 const double departPosition, const double arrivalPosition, const double speed, const SUMOTime duration) :
42 GNEDemandElement(containerParent, tag, GNEPathElement::Options::DEMAND_ELEMENT),
43 GNEDemandElementPlan(this, departPosition, arrivalPosition),
44 mySpeed(speed),
45 myDuration(duration) {
46 // set parents
47 setParents<GNEJunction*>(planParameters.getJunctions());
48 setParents<GNEEdge*>(planParameters.getEdges());
49 setParents<GNEAdditional*>(planParameters.getAdditionalElements());
50 setParents<GNEDemandElement*>(planParameters.getDemandElements(containerParent));
51 // update centering boundary without updating grid
53}
54#ifdef _MSC_VER
55#pragma warning(pop)
56#endif
57
59
60
65
66
69 return nullptr;
70}
71
72
73const Parameterised*
75 return nullptr;
76}
77
78
83
84
85void
87 // first write origin stop (if this element starts in a stoppingPlace)
88 writeOriginStop(device);
89 // write rest of attributes
92 // speed
95 }
96 // duration
99 }
100 device.closeTag();
101}
102
103
108
109
110std::string
114
115
116void
118 // currently the only solution is removing Tranship
119}
120
121
124 return SVC_IGNORING;
125}
126
127
128const RGBColor&
132
133
134void
138
139
144
145
146std::string
148 return getParentDemandElements().front()->getID();
149}
150
151
156
157
158void
159GNETranship::splitEdgeGeometry(const double /*splitPosition*/, const GNENetworkElement* originalElement, const GNENetworkElement* newElement, GNEUndoList* undoList) {
160 // only split geometry of TranshipEdges
162 // obtain new list of tranship edges
163 std::string newTranshipEdges = getNewListOfParents(originalElement, newElement);
164 // update tranship edges
165 if (newTranshipEdges.size() > 0) {
166 setAttribute(SUMO_ATTR_EDGES, newTranshipEdges, undoList);
167 }
168 }
169}
170
171
172void
176
177
178void
182
183
184void
188
189
190void
194
195
196GNELane*
200
201
202GNELane*
206
207
208std::string
210 switch (key) {
211 case SUMO_ATTR_SPEED:
213 return "";
214 } else {
215 return toString(mySpeed);
216 }
219 return "";
220 } else {
221 return time2string(myDuration);
222 }
223 default:
224 return getPlanAttribute(key);
225 }
226}
227
228
229double
231 switch (key) {
232 case SUMO_ATTR_SPEED:
233 return mySpeed;
234 default:
235 return getPlanAttributeDouble(key);
236 }
237}
238
239
244
245
246void
247GNETranship::setAttribute(SumoXMLAttr key, const std::string& value, GNEUndoList* undoList) {
248 switch (key) {
249 case SUMO_ATTR_SPEED:
251 GNEChange_Attribute::changeAttribute(this, key, value, undoList);
252 break;
253 default:
254 setPlanAttribute(key, value, undoList);
255 break;
256 }
257}
258
259
260bool
261GNETranship::isValid(SumoXMLAttr key, const std::string& value) {
262 switch (key) {
263 case SUMO_ATTR_SPEED:
264 return canParse<double>(value) && (parse<double>(value) >= 0);
266 return canParse<SUMOTime>(value) && (parse<SUMOTime>(value) >= 0);
267 default:
268 return isPlanValid(key, value);
269 }
270}
271
272
273bool
277
278
279std::string
281 return getTagStr();
282}
283
284
285std::string
289
290// ===========================================================================
291// private
292// ===========================================================================
293
294void
295GNETranship::setAttribute(SumoXMLAttr key, const std::string& value) {
296 switch (key) {
297 case SUMO_ATTR_SPEED:
298 if (value.empty()) {
300 } else {
301 mySpeed = GNEAttributeCarrier::parse<double>(value);
302 }
303 break;
305 if (value.empty()) {
307 } else {
308 myDuration = GNEAttributeCarrier::parse<SUMOTime>(value);
309 }
310 break;
311 default:
312 setPlanAttribute(key, value);
313 break;
314 }
315}
316
317/****************************************************************************/
long long int SUMOTime
Definition GUI.h:36
std::string time2string(SUMOTime t, bool humanReadable)
convert SUMOTime to string (independently of global format setting)
Definition SUMOTime.cpp:91
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_TRANSHIP
@ GNE_TAG_TRANSHIP_EDGES
SumoXMLAttr
Numbers representing SUMO-XML - attributes.
@ SUMO_ATTR_SPEED
@ SUMO_ATTR_EDGES
the edges of a route
@ SUMO_ATTR_DURATION
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
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 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
GUIGLObjectPopupMenu * getPlanPopUpMenu(GUIMainWindow &app, GUISUMOAbstractView &parent)
Returns an own popup-menu.
GNEMoveElementPlan * myMoveElementPlan
move element plan
std::string getPlanHierarchyName() const
get plan Hierarchy Name (Used in AC Hierarchy)
void writeLocationAttributes(OutputDevice &device) const
write plan element common attributes
double getPlanAttributeDouble(SumoXMLAttr key) const
get plan attribute double
void setPlanAttribute(SumoXMLAttr key, const std::string &value, GNEUndoList *undoList)
set plan attribute
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 updatePlanCenteringBoundary(const bool updateGrid)
update plan centering boundary
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 drawPlanLanePartial(const bool drawPlan, const GUIVisualizationSettings &s, const GNESegment *segment, const double offsetFront, const double planWidth, const RGBColor &planColor, const RGBColor &planSelectedColor) const
draw plan partial lane
void drawPlanJunctionPartial(const bool drawPlan, const GUIVisualizationSettings &s, const GNESegment *segment, const double offsetFront, const double planWidth, const RGBColor &planColor, const RGBColor &planSelectedColor) const
draw plan partial junction
void writeOriginStop(OutputDevice &device) const
write initial stop stage if plan starts at a stopping place
const GNEHierarchicalContainerParents< GNEDemandElement * > & getParentDemandElements() const
get parent demand elements
std::string getNewListOfParents(const GNENetworkElement *currentElement, const GNENetworkElement *newNextElement) const
if use edge/parent lanes as a list of consecutive elements, obtain a list of IDs of elements after in...
A NBNetBuilder extended by visualisation and editing capabilities.
Definition GNENet.h:42
GNEViewNet * getViewNet() const
get view net
Definition GNENet.cpp:2193
GNEPlanParents (used for group all plan parents)
std::vector< GNEDemandElement * > getDemandElements(GNEDemandElement *parent) const
get demand elements (used in plan constructors)
std::vector< GNEAdditional * > getAdditionalElements() const
get additionalElements (used in plan constructors)
std::vector< GNEEdge * > getEdges() const
get edges (used in plan constructors)
std::vector< GNEJunction * > getJunctions() const
get junctions (used in plan constructors)
double getDefaultDoubleValue(SumoXMLAttr attr) const
get default double value
SUMOTime getDefaultTimeValue(SumoXMLAttr attr) const
get default time value
SumoXMLTag getTag() const
get Tag vinculated with this attribute Property
std::string getAttribute(SumoXMLAttr key) const override
inherited from GNEAttributeCarrier
bool isValid(SumoXMLAttr key, const std::string &value) override
double getAttributeDouble(SumoXMLAttr key) const override
void drawGL(const GUIVisualizationSettings &s) const
Draws the object.
~GNETranship()
destructor
SUMOVehicleClass getVClass() const
obtain VClass related with this demand element
void setAttribute(SumoXMLAttr key, const std::string &value, GNEUndoList *undoList) override
double mySpeed
speed
void drawLanePartialGL(const GUIVisualizationSettings &s, const GNESegment *segment, const double offsetFront) const
Draws partial object over lane.
void drawJunctionPartialGL(const GUIVisualizationSettings &s, const GNESegment *segment, const double offsetFront) const
Draws partial object over junction.
GNELane * getFirstPathLane() const
get first path lane
GNETranship(SumoXMLTag tag, GNENet *net)
default constructor
bool isAttributeEnabled(SumoXMLAttr key) const
GNEMoveElement * getMoveElement() const override
methods to retrieve the elements linked to this tranship
std::string getHierarchyName() const override
get Hierarchy Name (Used in AC Hierarchy)
Boundary getCenteringBoundary() const
Returns the boundary to which the view shall be centered in order to show the object.
void splitEdgeGeometry(const double splitPosition, const GNENetworkElement *originalElement, const GNENetworkElement *newElement, GNEUndoList *undoList)
split geometry
Parameterised * getParameters() override
get parameters associated with this tranship
Position getPositionInView() const
Returns position of additional in view.
GUIGLObjectPopupMenu * getPopUpMenu(GUIMainWindow &app, GUISUMOAbstractView &parent)
Returns an own popup-menu.
SUMOTime myDuration
duration
void computePathElement()
compute pathElement
Problem isDemandElementValid() const
check if current demand element is valid to be written into XML (by default true, can be reimplemente...
Position getAttributePosition(SumoXMLAttr key) const override
void writeDemandElement(OutputDevice &device) const
write demand element element into a xml file
void fixDemandElementProblem()
fix demand element problem (by default throw an exception, has to be reimplemented in children)
std::string getParentName() const
Returns the name of the parent object.
GNELane * getLastPathLane() const
get last path lane
const RGBColor & getColor() const
get color
void updateGeometry() override
update pre-computed geometry information
std::string getPopUpID() const override
get PopPup ID (Used in AC Hierarchy)
std::string getDemandElementProblem() const
return a string with the current demand element problem (by default empty, can be reimplemented in ch...
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.
OutputDevice & writeAttr(const SumoXMLAttr attr, const T &val)
writes a named attribute
OutputDevice & openTag(const std::string &xmlElement)
Opens an XML tag.
bool closeTag(const std::string &comment="")
Closes the most recently opened tag and optionally adds a comment.
An upper class for objects with additional parameters.
A point in 2D or 3D with translation and scaling methods.
Definition Position.h:37
RGBColor transhipColor
color for tranships
RGBColor selectedContainerPlanColor
container plan selection color (Rides, Walks, containerStops...)