Eclipse SUMO - Simulation of Urban MObility
GNETractionSubstation.cpp
Go to the documentation of this file.
1/****************************************************************************/
2// Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.org/sumo
3// Copyright (C) 2021-2022 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//
19/****************************************************************************/
20#include <netedit/GNENet.h>
21#include <netedit/GNEUndoList.h>
23
25
26
27// ===========================================================================
28// member method definitions
29// ===========================================================================
30
33 GUIIconSubSys::getIcon(GUIIcon::TRACTION_SUBSTATION), "", {}, {}, {}, {}, {}, {}),
34 myVoltage(0),
35myCurrentLimit(0) {
36 // reset default values
37 resetDefaultValues();
38}
39
40
41GNETractionSubstation::GNETractionSubstation(const std::string& id, GNENet* net, const Position& pos, const double voltage,
42 const double currentLimit, const Parameterised::Map& parameters) :
44 GUIIconSubSys::getIcon(GUIIcon::TRACTION_SUBSTATION), "", {}, {}, {}, {}, {}, {}),
45Parameterised(parameters),
46myPosition(pos),
47myVoltage(voltage),
48myCurrentLimit(currentLimit) {
49 // update centering boundary without updating grid
50 updateCenteringBoundary(false);
51}
52
53
55}
56
57
58void
61 device.writeAttr(SUMO_ATTR_ID, getID());
65 }
68 }
69 // write parameters
70 writeParams(device);
71 device.closeTag();
72}
73
74
77 // return move operation for additional placed in view
78 return new GNEMoveOperation(this, myPosition);
79}
80
81
82void
84 // update additional geometry
86}
87
88
91 return myPosition;
92}
93
94
95void
97 // remove additional from grid
98 if (updateGrid) {
100 }
101 // now update geometry
103 // add shape boundary
105 // grow
107 // add additional into RTREE again
108 if (updateGrid) {
110 }
111}
112
113
114void
115GNETractionSubstation::splitEdgeGeometry(const double /*splitPosition*/, const GNENetworkElement* /*originalElement*/, const GNENetworkElement* /*newElement*/, GNEUndoList* /*undoList*/) {
116 // geometry of this element cannot be splitted
117}
118
119
120std::string
122 return myNet->getMicrosimID();
123}
124
125
126void
128 // draw parent and child lines
130 // draw TractionSubstation
132}
133
134
135std::string
137 switch (key) {
138 case SUMO_ATTR_ID:
139 return getMicrosimID();
140 case SUMO_ATTR_EDGES: {
141 std::vector<std::string> edges;
142 for (const auto& tractionSubstationSymbol : getChildAdditionals()) {
143 if (tractionSubstationSymbol->getTagProperty().isSymbol()) {
144 edges.push_back(tractionSubstationSymbol->getAttribute(SUMO_ATTR_EDGE));
145 }
146 }
147 return toString(edges);
148 }
150 return toString(myPosition);
152 return toString(myVoltage);
154 return toString(myCurrentLimit);
158 return getParametersStr();
159 default:
160 throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
161 }
162}
163
164
165double
167 throw InvalidArgument(getTagStr() + " doesn't have a double attribute of type '" + toString(key) + "'");
168}
169
170
171const
173 return PARAMETERS_EMPTY;
174}
175
176
177void
178GNETractionSubstation::setAttribute(SumoXMLAttr key, const std::string& value, GNEUndoList* undoList) {
179 if (value == getAttribute(key)) {
180 return; //avoid needless changes, later logic relies on the fact that attributes have changed
181 }
182 switch (key) {
183 // special case for lanes due tractionSubstation Symbols
184 case SUMO_ATTR_EDGES:
185 case SUMO_ATTR_ID:
191 undoList->changeAttribute(new GNEChange_Attribute(this, key, value));
192 break;
193 default:
194 throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
195 }
196}
197
198
199bool
200GNETractionSubstation::isValid(SumoXMLAttr key, const std::string& value) {
201 switch (key) {
202 case SUMO_ATTR_ID:
203 return isValidAdditionalID(value);
204 case SUMO_ATTR_EDGES:
205 return canParse<std::vector<GNEEdge*> >(myNet, value, false);
207 return canParse<Position>(value);
210 if (canParse<double>(value)) {
211 return (parse<double>(value) >= 0);
212 } else {
213 return false;
214 }
216 return canParse<bool>(value);
218 return areParametersValid(value);
219 default:
220 throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
221 }
222}
223
224
225std::string
227 return getTagStr() + ": " + getID();
228}
229
230
231std::string
233 return getTagStr();
234}
235
236// ===========================================================================
237// private
238// ===========================================================================
239
240void
241GNETractionSubstation::setAttribute(SumoXMLAttr key, const std::string& value) {
242 switch (key) {
243 case SUMO_ATTR_EDGES:
244 throw InvalidArgument(getTagStr() + " cannot be edited");
245 case SUMO_ATTR_ID:
246 // update microsimID
247 setMicrosimID(value);
248 break;
250 myPosition = parse<Position>(value);
251 // update boundary (except for template)
252 if (getID().size() > 0) {
254 }
255 break;
257 myVoltage = parse<double>(value);
258 break;
260 myCurrentLimit = parse<double>(value);
261 break;
263 if (parse<bool>(value)) {
265 } else {
267 }
268 break;
270 setParametersStr(value);
271 break;
272 default:
273 throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
274 }
275}
276
277
278void
280 // update position
281 myPosition = moveResult.shapeToUpdate.front();
282 // update geometry
284}
285
286
287void
289 undoList->begin(GUIIcon::TRACTION_SUBSTATION, "position of " + getTagStr());
290 undoList->changeAttribute(new GNEChange_Attribute(this, SUMO_ATTR_POSITION, toString(moveResult.shapeToUpdate.front())));
291 undoList->end();
292}
293
294/****************************************************************************/
@ GLO_TRACTIONSUBSTATION
a segment of an overhead line
GUIIcon
An enumeration of icons used by the gui applications.
Definition: GUIIcons.h:33
@ TRACTION_SUBSTATION
@ TRACTIONSUBSTATION_SELECTED
@ TRACTIONSUBSTATION
@ SUMO_TAG_TRACTION_SUBSTATION
A traction substation.
SumoXMLAttr
Numbers representing SUMO-XML - attributes.
@ SUMO_ATTR_EDGE
@ SUMO_ATTR_VOLTAGE
voltage of the traction substation [V]
@ GNE_ATTR_SELECTED
element is selected
@ SUMO_ATTR_EDGES
the edges of a route
@ GNE_ATTR_PARAMETERS
parameters "key1=value1|key2=value2|...|keyN=valueN"
@ SUMO_ATTR_CURRENTLIMIT
current limit of the traction substation [A]
@ SUMO_ATTR_ID
@ SUMO_ATTR_POSITION
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
Definition: ToString.h:46
Boundary & grow(double by)
extends the boundary by the given amount
Definition: Boundary.cpp:300
An Element which don't belong to GNENet but has influence in the simulation.
Definition: GNEAdditional.h:48
GUIGeometry myAdditionalGeometry
geometry to be precomputed in updateGeometry(...)
void drawSquaredAdditional(const GUIVisualizationSettings &s, const Position &pos, const double size, GUITexture texture, GUITexture selectedTexture) const
draw squared additional
Boundary myAdditionalBoundary
Additional Boundary.
bool isValidAdditionalID(const std::string &newID) const
check if a new additional ID is valid
void drawParentChildLines(const GUIVisualizationSettings &s, const RGBColor &color, const bool onlySymbols=false) const
draw parent and child lines
const std::string getID() const
get ID (all Attribute Carriers have one)
bool isAttributeCarrierSelected() const
check if attribute carrier is selected
friend class GNEChange_Attribute
declare friend class
const std::string & getTagStr() const
get tag assigned to this object in string format
void unselectAttributeCarrier(const bool changeFlag=true)
unselect attribute carrier using GUIGlobalSelection
static const Parameterised::Map PARAMETERS_EMPTY
empty parameter maps (used by ACs without parameters)
GNENet * myNet
pointer to net
void selectAttributeCarrier(const bool changeFlag=true)
select attribute carrier using GUIGlobalSelection
const GNETagProperties & myTagProperty
reference to tagProperty associated with this attribute carrier
const std::vector< GNEAdditional * > & getChildAdditionals() const
return child additionals
move operation
move result
PositionVector shapeToUpdate
shape to update (edited in moveElement)
A NBNetBuilder extended by visualisation and editing capabilities.
Definition: GNENet.h:42
void addGLObjectIntoGrid(GNEAttributeCarrier *AC)
add GL Object into net
Definition: GNENet.cpp:1245
void removeGLObjectFromGrid(GNEAttributeCarrier *AC)
add GL Object into net
Definition: GNENet.cpp:1257
const std::string & getDefaultValue(SumoXMLAttr attr) const
return the default value of the attribute of an element
std::string getAttribute(SumoXMLAttr key) const
Position getPositionInView() const
Returns position of additional in view.
Position myPosition
position of tractionSubstation in view
void splitEdgeGeometry(const double splitPosition, const GNENetworkElement *originalElement, const GNENetworkElement *newElement, GNEUndoList *undoList)
split geometry
void writeAdditional(OutputDevice &device) const
write additional element into a xml file
void updateGeometry()
update pre-computed geometry information
std::string getParentName() const
Returns the name of the parent object (if any)
void drawGL(const GUIVisualizationSettings &s) const
Draws the object.
double getAttributeDouble(SumoXMLAttr key) const
double myCurrentLimit
current limit
void commitMoveShape(const GNEMoveResult &moveResult, GNEUndoList *undoList)
commit move shape
void setMoveShape(const GNEMoveResult &moveResult)
set move shape
std::string getHierarchyName() const
get Hierarchy Name (Used in AC Hierarchy)
std::string getPopUpID() const
get PopPup ID (Used in AC Hierarchy)
const Parameterised::Map & getACParametersMap() const
get parameters map
void setAttribute(SumoXMLAttr key, const std::string &value, GNEUndoList *undoList)
method for setting the attribute and letting the object perform additional changes
void updateCenteringBoundary(const bool updateGrid)
update centering boundary (implies change in RTREE)
GNETractionSubstation(GNENet *net)
default Constructor
GNEMoveOperation * getMoveOperation()
get move operation
bool isValid(SumoXMLAttr key, const std::string &value)
method for checking if the key and their correspondent attribute are valids
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...
void changeAttribute(GNEChange_Attribute *change)
special method for change attributes, avoid empty changes, always execute
void updateSinglePosGeometry(const Position &position, const double rotation)
update position and rotation
const PositionVector & getShape() const
The shape of the additional element.
const std::string & getMicrosimID() const
Returns the id of the object as known to microsim.
Definition: GUIGlObject.h:141
virtual void setMicrosimID(const std::string &newID)
Changes the microsimID of the object.
Stores the information about how to visualize structures.
GUIVisualizationAdditionalSettings additionalSettings
Additional settings.
Static storage of an output device and its base (abstract) implementation.
Definition: OutputDevice.h:61
OutputDevice & writeAttr(const SumoXMLAttr attr, const T &val)
writes a named attribute
Definition: OutputDevice.h:251
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.
Definition: Parameterised.h:41
static bool areParametersValid(const std::string &value, bool report=false, const std::string kvsep="=", const std::string sep="|")
check if given string can be parsed to a parameters map "key1=value1|key2=value2|....
std::map< std::string, std::string > Map
parameters map
Definition: Parameterised.h:45
void setParametersStr(const std::string &paramsString, const std::string kvsep="=", const std::string sep="|")
set the inner key/value map in string format "key1=value1|key2=value2|...|keyN=valueN"
void writeParams(OutputDevice &device) const
write Params in the given outputdevice
std::string getParametersStr(const std::string kvsep="=", const std::string sep="|") const
Returns the inner key/value map in string format "key1=value1|key2=value2|...|keyN=valueN".
A point in 2D or 3D with translation and scaling methods.
Definition: Position.h:37
Boundary getBoxBoundary() const
Returns a boundary enclosing this list of lines.
static const RGBColor connectionColor
connection color
static const double tractionSubstationSize
tractionSubstation size