Eclipse SUMO - Simulation of Urban MObility
Loading...
Searching...
No Matches
GNEVTypeRef.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 vType references
19/****************************************************************************/
20
21#include <netedit/GNENet.h>
24
25#include "GNEVTypeRef.h"
26#include "GNEVehicle.h"
27
28// ===========================================================================
29// GNEVTypeRef - methods
30// ===========================================================================
31
35
36
38 GNEDemandElement(distributionParent, GNE_TAG_VTYPEREF, GNEPathElement::Options::DEMAND_ELEMENT) {
39 // set parents
40 setParents<GNEDemandElement*>({distributionParent, vTypeParent});
41}
42
43
44GNEVTypeRef::GNEVTypeRef(GNEDemandElement* distributionParent, GNEDemandElement* vTypeParent, const double probability) :
45 GNEDemandElement(distributionParent, GNE_TAG_VTYPEREF, GNEPathElement::Options::DEMAND_ELEMENT),
46 myProbability(probability) {
47 // set parents
48 setParents<GNEDemandElement*>({distributionParent, vTypeParent});
49}
50
51
53
54
57 return nullptr;
58}
59
60
63 return nullptr;
64}
65
66
67const Parameterised*
69 return nullptr;
70}
71
72
75 // create popup
76 GUIGLObjectPopupMenu* ret = new GUIGLObjectPopupMenu(app, parent, this);
77 // build common options
78 buildPopUpMenuCommonOptions(ret, app, myNet->getViewNet(), myTagProperty->getTag(), mySelected);
79 return ret;
80}
81
82
83void
93
94
99
100
101std::string
103 return "";
104}
105
106
107void
109 // currently the only solution is removing VType
110}
111
112
115 return getParentDemandElements().back()->getVClass();
116}
117
118
119const RGBColor&
123
124
125void
127 // nothing to update
128}
129
130
133 return getParentDemandElements().front()->getPositionInView();
134}
135
136
137std::string
139 return getParentDemandElements().front()->getID();
140}
141
142
143double
145 return 1;
146}
147
148
151 return getParentDemandElements().front()->getCenteringBoundary();
152}
153
154
155void
156GNEVTypeRef::splitEdgeGeometry(const double /*splitPosition*/, const GNENetworkElement* /*originalElement*/,
157 const GNENetworkElement* /*newElement*/, GNEUndoList* /*undoList*/) {
158 // nothing to do
159}
160
161
162void
164 // nothing to draw
165}
166
167
168void
170 // nothing to do
171}
172
173
174void
175GNEVTypeRef::drawLanePartialGL(const GUIVisualizationSettings& /*s*/, const GNESegment* /*segment*/, const double /*offsetFront*/) const {
176 // nothing to draw
177}
178
179
180void
181GNEVTypeRef::drawJunctionPartialGL(const GUIVisualizationSettings& /*s*/, const GNESegment* /*segment*/, const double /*offsetFront*/) const {
182 // nothing to draw
183}
184
185
186GNELane*
188 return getParentDemandElements().back()->getFirstPathLane();
189}
190
191
192GNELane*
194 return getParentDemandElements().back()->getLastPathLane();
195}
196
197
198std::string
200 switch (key) {
201 case SUMO_ATTR_ID:
202 return getMicrosimID();
203 case SUMO_ATTR_REFID:
204 return getParentDemandElements().back()->getID();
205 case SUMO_ATTR_PROB:
207 return getParentDemandElements().at(1)->getAttribute(key);
208 } else {
209 return toString(myProbability);
210 }
213 default:
214 return getCommonAttribute(key);
215 }
216}
217
218
219double
221 switch (key) {
222 case SUMO_ATTR_PROB:
224 return getParentDemandElements().at(1)->getAttributeDouble(key);
225 } else {
226 return myProbability;
227 }
228 default:
229 return getCommonAttributeDouble(key);
230 }
231}
232
233
238
239
240bool
242 switch (key) {
243 case SUMO_ATTR_REFID:
244 return false;
245 default:
246 return true;
247 }
248}
249
250
251void
252GNEVTypeRef::setAttribute(SumoXMLAttr key, const std::string& value, GNEUndoList* undoList) {
253 if (value == getAttribute(key)) {
254 return; //avoid needless changes, later logic relies on the fact that attributes have changed
255 }
256 switch (key) {
257 case SUMO_ATTR_PROB:
258 GNEChange_Attribute::changeAttribute(this, key, value, undoList);
259 break;
260 default:
261 setCommonAttribute(key, value, undoList);
262 break;
263 }
264}
265
266
267bool
268GNEVTypeRef::isValid(SumoXMLAttr key, const std::string& value) {
269 switch (key) {
270 case SUMO_ATTR_PROB:
271 if (value.empty()) {
272 return true;
273 } else {
274 return canParse<double>(value) && (parse<double>(value) >= 0);
275 }
276 default:
277 return isCommonAttributeValid(key, value);
278 }
279}
280
281
282bool
284 switch (key) {
285 case SUMO_ATTR_PROB:
287 default:
288 return false;
289 }
290}
291
292
293std::string
295 return getTagStr();
296}
297
298
299std::string
301 return TLF("%: %, %", myTagProperty->getTagStr(), getParentDemandElements().back()->getID(), getAttribute(SUMO_ATTR_PROB));
302}
303
304// ===========================================================================
305// private
306// ===========================================================================
307
308void
310 switch (key) {
311 case SUMO_ATTR_PROB:
312 if (value.empty()) {
314 } else {
316 }
317 break;
318 default:
320 break;
321 }
322}
323
324/****************************************************************************/
#define TLF(string,...)
Definition MsgHandler.h:306
const std::string invalid_return< std::string >::value
SUMOVehicleClass
Definition of vehicle classes to differ between different lane usage and authority types.
@ GNE_TAG_VTYPEREF
reference to a vType (used in VType distributions)
@ SUMO_TAG_VTYPE
description of a vehicle/person/container type
SumoXMLAttr
Numbers representing SUMO-XML - attributes.
@ SUMO_ATTR_REFID
@ SUMO_ATTR_PROB
@ GNE_ATTR_DEFAULT_PROBABILITY
Flag to check if we're using a default probability.
@ SUMO_ATTR_ID
const double INVALID_DOUBLE
invalid double
Definition StdDefs.h:68
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
double getCommonAttributeDouble(SumoXMLAttr key) const
bool mySelected
boolean to check if this AC is selected (more quickly as checking GUIGlObjectStorage)
static const std::string FALSE_STR
true value in string format(used for comparing boolean values in getAttribute(...))
static const std::string TRUE_STR
true value in string format (used for comparing boolean values in getAttribute(......
const std::string getID() const override
get ID (all Attribute Carriers have one)
static T parse(const std::string &string)
parses a value of type T from string (used for basic types: int, double, bool, etc....
void setCommonAttribute(SumoXMLAttr key, const std::string &value, GNEUndoList *undoList)
const std::string & getTagStr() const
get tag assigned to this object in string format
Position getCommonAttributePosition(SumoXMLAttr key) const
static bool canParse(const std::string &string)
true if a value of type T can be parsed from string
GNENet * myNet
pointer to net
bool isCommonAttributeValid(SumoXMLAttr key, const std::string &value) const
std::string getCommonAttribute(SumoXMLAttr key) const
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
GNEDemandElement(const std::string &id, GNENet *net, const std::string &filename, SumoXMLTag tag, const GNEPathElement::Options pathOptions)
Constructor.
Problem
enum class for demandElement problems
const GNEHierarchicalContainerParents< GNEDemandElement * > & getParentDemandElements() const
get parent demand elements
void setParents(const GNEHierarchicalContainerParents< ParentType > &parents)
set multiple parent element (ONLY use in constructors)
A NBNetBuilder extended by visualisation and editing capabilities.
Definition GNENet.h:42
GNEPathElement(const GNEPathElement::Options options)
constructor
double myProbability
probability
Problem isDemandElementValid() const override
check if current demand element is valid to be written into XML (by default true, can be reimplemente...
void fixDemandElementProblem() override
fix demand element problem (by default throw an exception, has to be reimplemented in children)
void writeDemandElement(OutputDevice &device) const override
write demand element element into a xml file
void drawJunctionPartialGL(const GUIVisualizationSettings &s, const GNESegment *segment, const double offsetFront) const override
Draws partial object over junction.
bool isAttributeComputed(SumoXMLAttr key) const override
GNELane * getLastPathLane() const override
get last path lane
GUIGLObjectPopupMenu * getPopUpMenu(GUIMainWindow &app, GUISUMOAbstractView &parent) override
Returns an own popup-menu.
Position getPositionInView() const override
Returns position of additional in view.
void drawLanePartialGL(const GUIVisualizationSettings &s, const GNESegment *segment, const double offsetFront) const override
Draws partial object over lane.
void splitEdgeGeometry(const double splitPosition, const GNENetworkElement *originalElement, const GNENetworkElement *newElement, GNEUndoList *undoList) override
split geometry
bool isValid(SumoXMLAttr key, const std::string &value) override
std::string getParentName() const override
Returns the name of the parent object.
SUMOVehicleClass getVClass() const override
obtain VClass related with this demand element
std::string getPopUpID() const override
get PopPup ID (Used in AC Hierarchy)
GNEMoveElement * getMoveElement() const override
methods to retrieve the elements linked to this vTypeRef
std::string getHierarchyName() const override
get Hierarchy Name (Used in AC Hierarchy)
Parameterised * getParameters() override
get parameters associated with this vTypeRef
const RGBColor & getColor() const override
get color
void setAttribute(SumoXMLAttr key, const std::string &value, GNEUndoList *undoList) override
double getAttributeDouble(SumoXMLAttr key) const override
Boundary getCenteringBoundary() const override
Returns the boundary to which the view shall be centered in order to show the object.
void computePathElement() override
compute pathElement
void drawGL(const GUIVisualizationSettings &s) const override
Draws the object.
GNEVTypeRef(GNENet *net)
default constructor
GNELane * getFirstPathLane() const override
get first path lane
double getExaggeration(const GUIVisualizationSettings &s) const override
return exaggeration associated with this GLObject
std::string getDemandElementProblem() const override
return a string with the current demand element problem (by default empty, can be reimplemented in ch...
std::string getAttribute(SumoXMLAttr key) const override
inherited from GNEAttributeCarrier
void updateGeometry() override
update pre-computed geometry information
bool isAttributeEnabled(SumoXMLAttr key) const override
Position getAttributePosition(SumoXMLAttr key) const override
~GNEVTypeRef()
destructor
The popup menu of a globject.
const std::string & getMicrosimID() const
Returns the id of the object as known to microsim.
void buildPopUpMenuCommonOptions(GUIGLObjectPopupMenu *ret, GUIMainWindow &app, GUISUMOAbstractView *parent, const SumoXMLTag tag, const bool selected, bool addSeparator=true)
Stores the information about how to visualize structures.
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
static const RGBColor INVISIBLE
Definition RGBColor.h:198