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>
26
27#include "GNEVTypeRef.h"
28#include "GNEVehicle.h"
29
30// ===========================================================================
31// GNEVTypeRef - methods
32// ===========================================================================
33
37
38
39GNEVTypeRef::GNEVTypeRef(GNEDemandElement* distributionParent, GNEDemandElement* vTypeParent, const double probability) :
40 GNEDemandElement(distributionParent, GNE_TAG_VTYPEREF, GNEPathElement::Options::DEMAND_ELEMENT),
41 myProbability(probability) {
42 // set parents
43 setParents<GNEDemandElement*>({distributionParent, vTypeParent});
44}
45
46
48
49
52 return nullptr;
53}
54
55
58 // create popup
59 GUIGLObjectPopupMenu* ret = new GUIGLObjectPopupMenu(app, parent, this);
60 // build common options
62 return ret;
63}
64
65
66void
68 device.openTag(SUMO_TAG_VTYPE);
71 // write parameters
72 writeParams(device);
73 // close tag
74 device.closeTag();
75}
76
77
82
83
84std::string
86 return "";
87}
88
89
90void
92 // currently the only solution is removing VType
93}
94
95
98 return getParentDemandElements().back()->getVClass();
99}
100
101
102const RGBColor&
104 return getParentDemandElements().back()->getColor();
105}
106
107
108void
110 // nothing to update
111}
112
113
116 return getParentDemandElements().front()->getPositionInView();
117}
118
119
120std::string
122 return getParentDemandElements().front()->getID();
123}
124
125
126double
128 return 1;
129}
130
131
134 return getParentDemandElements().front()->getCenteringBoundary();
135}
136
137
138void
139GNEVTypeRef::splitEdgeGeometry(const double /*splitPosition*/, const GNENetworkElement* /*originalElement*/,
140 const GNENetworkElement* /*newElement*/, GNEUndoList* /*undoList*/) {
141 // nothing to do
142}
143
144
145void
147 // nothing to draw
148}
149
150
151void
153 // nothing to do
154}
155
156
157void
158GNEVTypeRef::drawLanePartialGL(const GUIVisualizationSettings& /*s*/, const GNESegment* /*segment*/, const double /*offsetFront*/) const {
159 // nothing to draw
160}
161
162
163void
164GNEVTypeRef::drawJunctionPartialGL(const GUIVisualizationSettings& /*s*/, const GNESegment* /*segment*/, const double /*offsetFront*/) const {
165 // nothing to draw
166}
167
168
169GNELane*
171 return getParentDemandElements().back()->getFirstPathLane();
172}
173
174
175GNELane*
177 return getParentDemandElements().back()->getLastPathLane();
178}
179
180
181std::string
183 switch (key) {
184 case SUMO_ATTR_ID:
185 return getMicrosimID();
187 return getParentDemandElements().front()->getID();
188 case SUMO_ATTR_REFID:
189 return getParentDemandElements().back()->getID();
190 case SUMO_ATTR_PROB:
191 return toString(myProbability);
192 default:
193 return getCommonAttribute(this, key);
194 }
195}
196
197
198double
200 switch (key) {
201 case SUMO_ATTR_PROB:
202 return myProbability;
203 default:
204 throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
205 }
206}
207
208
211 throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
212}
213
214
215bool
217 switch (key) {
219 case SUMO_ATTR_REFID:
220 return false;
221 default:
222 return true;
223 }
224}
225
226
227void
228GNEVTypeRef::setAttribute(SumoXMLAttr key, const std::string& value, GNEUndoList* undoList) {
229 if (value == getAttribute(key)) {
230 return; //avoid needless changes, later logic relies on the fact that attributes have changed
231 }
232 switch (key) {
233 case SUMO_ATTR_PROB:
234 GNEChange_Attribute::changeAttribute(this, key, value, undoList);
235 break;
236 default:
237 setCommonAttribute(key, value, undoList);
238 break;
239 }
240}
241
242
243bool
244GNEVTypeRef::isValid(SumoXMLAttr key, const std::string& value) {
245 switch (key) {
246 case SUMO_ATTR_PROB:
247 if (value.empty()) {
248 return true;
249 } else {
250 return canParse<double>(value) && (parse<double>(value) >= 0);
251 }
252 default:
253 return isCommonValid(key, value);
254 }
255}
256
257
258std::string
260 return getTagStr();
261}
262
263
264std::string
268
269
274
275// ===========================================================================
276// private
277// ===========================================================================
278
279void
280GNEVTypeRef::setAttribute(SumoXMLAttr key, const std::string& value) {
281 switch (key) {
282 case SUMO_ATTR_PROB:
283 if (value.empty()) {
285 } else {
286 myProbability = parse<double>(value);
287 }
288 break;
289 default:
290 setCommonAttribute(this, key, value);
291 break;
292 }
293}
294
295
296void
298 // vTypesRefs cannot be moved
299}
300
301
302void
303GNEVTypeRef::commitMoveShape(const GNEMoveResult& /*moveResult*/, GNEUndoList* /*undoList*/) {
304 // vTypesRefs cannot be moved
305}
306
307/****************************************************************************/
#define TLF(string,...)
Definition MsgHandler.h:307
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
@ GNE_ATTR_VTYPE_DISTRIBUTION
vehicle type distribution
@ SUMO_ATTR_PROB
@ SUMO_ATTR_ID
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
bool mySelected
boolean to check if this AC is selected (more quickly as checking GUIGlObjectStorage)
std::string getCommonAttribute(const Parameterised *parameterised, SumoXMLAttr key) const
void setCommonAttribute(SumoXMLAttr key, const std::string &value, GNEUndoList *undoList)
const std::string & getTagStr() const
get tag assigned to this object in string format
GNENet * myNet
pointer to net
bool isCommonValid(SumoXMLAttr key, const std::string &value) 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
Problem
enum class for demandElement problems
const GNEHierarchicalContainerParents< 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
A NBNetBuilder extended by visualisation and editing capabilities.
Definition GNENet.h:42
GNEViewNet * getViewNet() const
get view net
Definition GNENet.cpp:2195
const std::string & getTagStr() const
get Tag vinculated with this attribute Property in String Format (used to avoid multiple calls to toS...
double getDefaultDoubleValue(SumoXMLAttr attr) const
get default double value
SumoXMLTag getTag() const
get Tag vinculated with this attribute Property
double getAttributeDouble(SumoXMLAttr key) const
double myProbability
probability
Position getAttributePosition(SumoXMLAttr key) const
void computePathElement()
compute pathElement
std::string getParentName() const
Returns the name of the parent object.
double getExaggeration(const GUIVisualizationSettings &s) const
return exaggeration associated with this GLObject
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
Position getPositionInView() const
Returns position of additional in view.
void drawJunctionPartialGL(const GUIVisualizationSettings &s, const GNESegment *segment, const double offsetFront) const
Draws partial object over junction.
std::string getPopUpID() const
get PopPup ID (Used in AC Hierarchy)
void drawLanePartialGL(const GUIVisualizationSettings &s, const GNESegment *segment, const double offsetFront) const
Draws partial object over lane.
const RGBColor & getColor() const
get color
void commitMoveShape(const GNEMoveResult &moveResult, GNEUndoList *undoList)
commit move shape
void drawGL(const GUIVisualizationSettings &s) const
Draws the object.
void updateGeometry()
update pre-computed geometry information
SUMOVehicleClass getVClass() const
obtain VClass related with this demand element
void fixDemandElementProblem()
fix demand element problem (by default throw an exception, has to be reimplemented in children)
GNELane * getFirstPathLane() const
get first path lane
void splitEdgeGeometry(const double splitPosition, const GNENetworkElement *originalElement, const GNENetworkElement *newElement, GNEUndoList *undoList)
split geometry
GNEMoveOperation * getMoveOperation()
get move operation
GNELane * getLastPathLane() const
get last path lane
void setMoveShape(const GNEMoveResult &moveResult)
set move shape
std::string getHierarchyName() const
get Hierarchy Name (Used in AC Hierarchy)
std::string getAttribute(SumoXMLAttr key) const
inherited from GNEAttributeCarrier
GUIGLObjectPopupMenu * getPopUpMenu(GUIMainWindow &app, GUISUMOAbstractView &parent)
Returns an own popup-menu.
std::string getDemandElementProblem() const
return a string with the current demand element problem (by default empty, can be reimplemented in ch...
Problem isDemandElementValid() const
check if current demand element is valid to be written into XML (by default true, can be reimplemente...
Boundary getCenteringBoundary() const
Returns the boundary to which the view shall be centered in order to show the object.
GNEVTypeRef(GNENet *net)
default constructor
const Parameterised::Map & getACParametersMap() const
get parameters map
bool isValid(SumoXMLAttr key, const std::string &value)
method for checking if the key and their conrrespond attribute are valids
void writeDemandElement(OutputDevice &device) const
write demand element element into a xml file
~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.
std::map< std::string, std::string > Map
parameters map
const Parameterised::Map & getParametersMap() const
Returns the inner key/value map.
void writeParams(OutputDevice &device) const
write Params in the given outputdevice
A point in 2D or 3D with translation and scaling methods.
Definition Position.h:37