Eclipse SUMO - Simulation of Urban MObility
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
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-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//
19/****************************************************************************/
20#include <config.h>
21
22#include <netedit/GNENet.h>
24#include <netedit/GNEViewNet.h>
25#include <netedit/GNEUndoList.h>
27
29
30// ===========================================================================
31// member method definitions
32// ===========================================================================
33
37
38
39GNETractionSubstation::GNETractionSubstation(const std::string& id, GNENet* net, const std::string& filename, const Position& pos,
40 const double voltage, const double currentLimit, const Parameterised::Map& parameters) :
41 GNEAdditional(id, net, filename, SUMO_TAG_TRACTION_SUBSTATION, ""),
42 Parameterised(parameters),
43 myPosition(pos),
44 myVoltage(voltage),
45 myCurrentLimit(currentLimit) {
46 // update centering boundary without updating grid
48}
49
50
53
54
55void
70
71
72bool
74 return true;
75}
76
77
78std::string
82
83
84void
88
89
90bool
92 // get edit modes
93 const auto& editModes = myNet->getViewNet()->getEditModes();
94 // check if we're in move mode
95 if (!myNet->getViewNet()->isCurrentlyMovingElements() && editModes.isCurrentSupermodeNetwork() &&
97 (editModes.networkEditMode == NetworkEditMode::NETWORK_MOVE) && myNet->getViewNet()->checkOverLockedElement(this, mySelected)) {
98 // only move the first element
100 } else {
101 return false;
102 }
103}
104
105
108 // return move operation for additional placed in view
109 return new GNEMoveOperation(this, myPosition);
110}
111
112
113void
118
119
124
125
126void
128 // remove additional from grid
129 if (updateGrid) {
131 }
132 // now update geometry
134 // add shape boundary
136 // grow
138 // add additional into RTREE again
139 if (updateGrid) {
141 }
142}
143
144
145void
146GNETractionSubstation::splitEdgeGeometry(const double /*splitPosition*/, const GNENetworkElement* /*originalElement*/, const GNENetworkElement* /*newElement*/, GNEUndoList* /*undoList*/) {
147 // geometry of this element cannot be splitted
148}
149
150
151std::string
155
156
157void
164
165
166std::string
168 switch (key) {
169 case SUMO_ATTR_ID:
170 return getMicrosimID();
171 case SUMO_ATTR_EDGES: {
172 std::vector<std::string> edges;
173 for (const auto& tractionSubstationSymbol : getChildAdditionals()) {
174 if (tractionSubstationSymbol->getTagProperty()->isSymbol()) {
175 edges.push_back(tractionSubstationSymbol->getAttribute(SUMO_ATTR_EDGE));
176 }
177 }
178 return toString(edges);
179 }
181 return toString(myPosition);
183 return toString(myVoltage);
185 return toString(myCurrentLimit);
186 default:
187 return getCommonAttribute(this, key);
188 }
189}
190
191
192double
194 throw InvalidArgument(getTagStr() + " doesn't have a double attribute of type '" + toString(key) + "'");
195}
196
197
198const
202
203
204void
205GNETractionSubstation::setAttribute(SumoXMLAttr key, const std::string& value, GNEUndoList* undoList) {
206 if (value == getAttribute(key)) {
207 return; //avoid needless changes, later logic relies on the fact that attributes have changed
208 }
209 switch (key) {
210 // special case for lanes due tractionSubstation Symbols
211 case SUMO_ATTR_EDGES:
212 case SUMO_ATTR_ID:
216 GNEChange_Attribute::changeAttribute(this, key, value, undoList);
217 break;
218 default:
219 setCommonAttribute(key, value, undoList);
220 break;
221 }
222}
223
224
225bool
226GNETractionSubstation::isValid(SumoXMLAttr key, const std::string& value) {
227 switch (key) {
228 case SUMO_ATTR_ID:
229 return isValidAdditionalID(value);
230 case SUMO_ATTR_EDGES:
231 return canParse<std::vector<GNEEdge*> >(myNet, value, false);
233 return canParse<Position>(value);
236 if (canParse<double>(value)) {
237 return (parse<double>(value) >= 0);
238 } else {
239 return false;
240 }
241 default:
242 return isCommonValid(key, value);
243 }
244}
245
246
247std::string
249 return getTagStr() + ": " + getID();
250}
251
252
253std::string
257
258// ===========================================================================
259// private
260// ===========================================================================
261
262void
263GNETractionSubstation::setAttribute(SumoXMLAttr key, const std::string& value) {
264 switch (key) {
265 case SUMO_ATTR_EDGES:
266 throw InvalidArgument(getTagStr() + " cannot be edited");
267 case SUMO_ATTR_ID:
268 // update microsimID
269 setAdditionalID(value);
270 break;
272 myPosition = parse<Position>(value);
273 // update boundary (except for template)
274 if (getID().size() > 0) {
276 }
277 break;
279 myVoltage = parse<double>(value);
280 break;
282 myCurrentLimit = parse<double>(value);
283 break;
284 default:
285 setCommonAttribute(this, key, value);
286 break;
287 }
288}
289
290
291void
293 // update position
294 myPosition = moveResult.shapeToUpdate.front();
295 // update geometry
297}
298
299
300void
302 undoList->begin(this, "position of " + getTagStr());
304 undoList->end();
305}
306
307/****************************************************************************/
@ NETWORK_MOVE
mode for moving network elements
@ 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]
@ SUMO_ATTR_EDGES
the edges of a route
@ 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:340
bool isValidAdditionalID(const std::string &value) const
check if a new additional ID is valid
void setAdditionalID(const std::string &newID)
set additional ID
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 (used only by additionals placed over grid)
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 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
const GNEHierarchicalContainerChildren< 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:1442
void removeGLObjectFromGrid(GNEAttributeCarrier *AC)
add GL Object into net
Definition GNENet.cpp:1452
GNEViewNet * getViewNet() const
get view net
Definition GNENet.cpp:2194
double getDefaultDoubleValue(SumoXMLAttr attr) const
get default double value
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 written into XML (must be reimplemented in all detector ch...
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)
bool checkDrawMoveContour() const
check if draw move contour (red)
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...
const GUIGlObject * getGUIGlObjectFront() const
get front GUIGLObject or a pointer to nullptr
bool isCurrentlyMovingElements() const
check if an element is being moved
const GNEViewNetHelper::EditModes & getEditModes() const
get edit modes
const GNEViewNetHelper::EditNetworkElementShapes & getEditNetworkElementShapes() const
get Edit Shape module
bool checkOverLockedElement(const GUIGlObject *GLObject, const bool isSelected) const
check if given element is locked (used for drawing select and delete contour)
const GNEViewNetHelper::ViewObjectsSelector & getViewObjectsSelector() const
get objects under cursor
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.
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.
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
Boundary getBoxBoundary() const
Returns a boundary enclosing this list of lines.
GNENetworkElement * getEditedNetworkElement() const
pointer to edited network element
static const RGBColor connectionColor
connection color
static const double tractionSubstationSize
tractionSubstation size