Eclipse SUMO - Simulation of Urban MObility
Loading...
Searching...
No Matches
GNETractionSubstation.cpp
Go to the documentation of this file.
1/****************************************************************************/
2// Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo
3// Copyright (C) 2021-2023 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
56
57
58void
73
74
75bool
77 return true;
78}
79
80
81std::string
85
86
87void
91
92
95 // return move operation for additional placed in view
96 return new GNEMoveOperation(this, myPosition);
97}
98
99
100void
105
106
111
112
113void
115 // remove additional from grid
116 if (updateGrid) {
118 }
119 // now update geometry
121 // add shape boundary
123 // grow
125 // add additional into RTREE again
126 if (updateGrid) {
128 }
129}
130
131
132void
133GNETractionSubstation::splitEdgeGeometry(const double /*splitPosition*/, const GNENetworkElement* /*originalElement*/, const GNENetworkElement* /*newElement*/, GNEUndoList* /*undoList*/) {
134 // geometry of this element cannot be splitted
135}
136
137
138std::string
142
143
144void
151
152
153std::string
155 switch (key) {
156 case SUMO_ATTR_ID:
157 return getMicrosimID();
158 case SUMO_ATTR_EDGES: {
159 std::vector<std::string> edges;
160 for (const auto& tractionSubstationSymbol : getChildAdditionals()) {
161 if (tractionSubstationSymbol->getTagProperty().isSymbol()) {
162 edges.push_back(tractionSubstationSymbol->getAttribute(SUMO_ATTR_EDGE));
163 }
164 }
165 return toString(edges);
166 }
168 return toString(myPosition);
170 return toString(myVoltage);
172 return toString(myCurrentLimit);
176 return getParametersStr();
177 default:
178 throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
179 }
180}
181
182
183double
185 throw InvalidArgument(getTagStr() + " doesn't have a double attribute of type '" + toString(key) + "'");
186}
187
188
189const
193
194
195void
196GNETractionSubstation::setAttribute(SumoXMLAttr key, const std::string& value, GNEUndoList* undoList) {
197 if (value == getAttribute(key)) {
198 return; //avoid needless changes, later logic relies on the fact that attributes have changed
199 }
200 switch (key) {
201 // special case for lanes due tractionSubstation Symbols
202 case SUMO_ATTR_EDGES:
203 case SUMO_ATTR_ID:
209 undoList->changeAttribute(new GNEChange_Attribute(this, key, value));
210 break;
211 default:
212 throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
213 }
214}
215
216
217bool
218GNETractionSubstation::isValid(SumoXMLAttr key, const std::string& value) {
219 switch (key) {
220 case SUMO_ATTR_ID:
221 return isValidAdditionalID(value);
222 case SUMO_ATTR_EDGES:
223 return canParse<std::vector<GNEEdge*> >(myNet, value, false);
225 return canParse<Position>(value);
228 if (canParse<double>(value)) {
229 return (parse<double>(value) >= 0);
230 } else {
231 return false;
232 }
234 return canParse<bool>(value);
236 return areParametersValid(value);
237 default:
238 throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
239 }
240}
241
242
243std::string
245 return getTagStr() + ": " + getID();
246}
247
248
249std::string
253
254// ===========================================================================
255// private
256// ===========================================================================
257
258void
259GNETractionSubstation::setAttribute(SumoXMLAttr key, const std::string& value) {
260 switch (key) {
261 case SUMO_ATTR_EDGES:
262 throw InvalidArgument(getTagStr() + " cannot be edited");
263 case SUMO_ATTR_ID:
264 // update microsimID
265 setMicrosimID(value);
266 break;
268 myPosition = parse<Position>(value);
269 // update boundary (except for template)
270 if (getID().size() > 0) {
272 }
273 break;
275 myVoltage = parse<double>(value);
276 break;
278 myCurrentLimit = parse<double>(value);
279 break;
281 if (parse<bool>(value)) {
283 } else {
285 }
286 break;
288 setParametersStr(value);
289 break;
290 default:
291 throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
292 }
293}
294
295
296void
298 // update position
299 myPosition = moveResult.shapeToUpdate.front();
300 // update geometry
302}
303
304
305void
307 undoList->begin(GUIIcon::TRACTION_SUBSTATION, "position of " + getTagStr());
308 undoList->changeAttribute(new GNEChange_Attribute(this, SUMO_ATTR_POSITION, toString(moveResult.shapeToUpdate.front())));
309 undoList->end();
310}
311
312/****************************************************************************/
@ 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.
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:1248
void removeGLObjectFromGrid(GNEAttributeCarrier *AC)
add GL Object into net
Definition GNENet.cpp:1260
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
bool isAdditionalValid() const
check if current additional is valid to be writed into XML (must be reimplemented in all detector chi...
std::string getParentName() const
Returns the name of the parent object.
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 getAdditionalProblem() const
return a string with the current additional problem (must be reimplemented in all detector children)
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 fixAdditionalProblem()
fix additional problem (must be reimplemented in all detector children)
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.
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.
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.
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
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