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-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
23#include <netedit/GNENet.h>
26
28
29// ===========================================================================
30// member method definitions
31// ===========================================================================
32
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 GNEAdditionalSquared(this, pos),
43 Parameterised(parameters),
44 myVoltage(voltage),
45 myCurrentLimit(currentLimit) {
46 // update centering boundary without updating grid
48}
49
50
53
54
59
60
65
66
67const Parameterised*
69 return this;
70}
71
72
73void
76 // write common additional attributes
78 // write move atributes
80 // write specific attributes
83 }
86 }
87 // write parameters
88 writeParams(device);
89 device.closeTag();
90}
91
92
93bool
95 return true;
96}
97
98
99std::string
103
104
105void
107 // nothing to fix
108}
109
110
111bool
113 // get edit modes
114 const auto& editModes = myNet->getViewNet()->getEditModes();
115 // check if we're in move mode
116 if (!myNet->getViewNet()->isCurrentlyMovingElements() && editModes.isCurrentSupermodeNetwork() &&
118 (editModes.networkEditMode == NetworkEditMode::NETWORK_MOVE) && myNet->getViewNet()->checkOverLockedElement(this, mySelected)) {
119 // only move the first element
121 } else {
122 return false;
123 }
124}
125
126
127void
131
132
137
138
139void
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
159 // first check if additional has to be drawn
161 // draw parent and child lines
163 // draw TractionSubstation
165 }
166}
167
168
169std::string
171 switch (key) {
172 case SUMO_ATTR_ID:
173 return getMicrosimID();
174 case SUMO_ATTR_EDGES: {
175 std::vector<std::string> edges;
176 for (const auto& tractionSubstationSymbol : getChildAdditionals()) {
177 if (tractionSubstationSymbol->getTagProperty()->isSymbol()) {
178 edges.push_back(tractionSubstationSymbol->getAttribute(SUMO_ATTR_EDGE));
179 }
180 }
181 return toString(edges);
182 }
184 return toString(myVoltage);
186 return toString(myCurrentLimit);
187 default:
189 }
190}
191
192
193double
197
198
203
204
209
210
211void
212GNETractionSubstation::setAttribute(SumoXMLAttr key, const std::string& value, GNEUndoList* undoList) {
213 if (value == getAttribute(key)) {
214 return; //avoid needless changes, later logic relies on the fact that attributes have changed
215 }
216 switch (key) {
217 // special case for lanes due tractionSubstation Symbols
218 case SUMO_ATTR_EDGES:
219 case SUMO_ATTR_ID:
222 GNEChange_Attribute::changeAttribute(this, key, value, undoList);
223 break;
224 default:
225 myMoveElementView->setMovingAttribute(key, value, undoList);
226 break;
227 }
228}
229
230
231bool
232GNETractionSubstation::isValid(SumoXMLAttr key, const std::string& value) {
233 switch (key) {
234 case SUMO_ATTR_ID:
235 return isValidAdditionalID(value);
236 case SUMO_ATTR_EDGES:
237 return canParse<std::vector<GNEEdge*> >(myNet, value, false);
240 if (canParse<double>(value)) {
241 return (parse<double>(value) >= 0);
242 } else {
243 return false;
244 }
245 default:
246 return myMoveElementView->isMovingAttributeValid(key, value);
247 }
248}
249
250
251std::string
253 return getTagStr() + ": " + getID();
254}
255
256
257std::string
261
262// ===========================================================================
263// private
264// ===========================================================================
265
266void
267GNETractionSubstation::setAttribute(SumoXMLAttr key, const std::string& value) {
268 switch (key) {
269 case SUMO_ATTR_EDGES:
270 throw InvalidArgument(getTagStr() + " cannot be edited");
271 case SUMO_ATTR_ID:
272 // update microsimID
273 setAdditionalID(value);
274 break;
276 myVoltage = parse<double>(value);
277 break;
279 myCurrentLimit = parse<double>(value);
280 break;
281 default:
283 break;
284 }
285 // update boundary (except for template)
286 if (getID().size() > 0) {
288 }
289}
290
291/****************************************************************************/
@ 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
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
Definition ToString.h:46
bool isValidAdditionalID(const std::string &value) const
check if a new additional ID is valid
void setAdditionalID(const std::string &newID)
set additional ID
void writeAdditionalAttributes(OutputDevice &device) const
write common additional attributes
void drawParentChildLines(const GUIVisualizationSettings &s, const RGBColor &color, const bool onlySymbols=false) const
draw parent and child lines
void updatedSquaredGeometry()
updated squared geometry
Position myPosOverView
position over view
void updatedSquaredCenteringBoundary(const bool updateGrid)
updated squared centering boundary
GNEMoveElementView * myMoveElementView
move element over view
void drawSquaredAdditional(const GUIVisualizationSettings &s, const double size, GUITexture texture, GUITexture selectedTexture) const
draw squared additional
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)
const std::string & getTagStr() const
get tag assigned to this object in string format
GNENet * myNet
pointer to net
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
Position getMovingAttributePosition(SumoXMLAttr key) const override
get moving attribute position
void writeMoveAttributes(OutputDevice &device) const
write move attributes
void setMovingAttribute(SumoXMLAttr key, const std::string &value, GNEUndoList *undoList) override
set moving attribute (using undo-list)
PositionVector getMovingAttributePositionVector(SumoXMLAttr key) const override
get moving attribute positionVector
double getMovingAttributeDouble(SumoXMLAttr key) const override
get moving attribute double
std::string getMovingAttribute(SumoXMLAttr key) const override
get moving attribute
bool isMovingAttributeValid(SumoXMLAttr key, const std::string &value) const override
check if the given moving attribute is valid
A NBNetBuilder extended by visualisation and editing capabilities.
Definition GNENet.h:42
GNEViewNet * getViewNet() const
get view net
Definition GNENet.cpp:2193
double getDefaultDoubleValue(SumoXMLAttr attr) const
get default double value
PositionVector getAttributePositionVector(SumoXMLAttr key) const override
Position getPositionInView() const
Returns position of additional in view.
void splitEdgeGeometry(const double splitPosition, const GNENetworkElement *originalElement, const GNENetworkElement *newElement, GNEUndoList *undoList)
split geometry
void updateGeometry() override
update pre-computed geometry information
void writeAdditional(OutputDevice &device) const
write additional element into a xml file
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.
Position getAttributePosition(SumoXMLAttr key) const override
std::string getHierarchyName() const override
get Hierarchy Name (Used in AC Hierarchy)
double myCurrentLimit
current limit
std::string getAdditionalProblem() const
return a string with the current additional problem (must be reimplemented in all detector children)
std::string getAttribute(SumoXMLAttr key) const override
void setAttribute(SumoXMLAttr key, const std::string &value, GNEUndoList *undoList) override
Parameterised * getParameters() override
get parameters associated with this tractionSubstation
double getAttributeDouble(SumoXMLAttr key) const override
bool checkDrawMoveContour() const override
check if draw move contour (red)
std::string getPopUpID() const override
get PopPup ID (Used in AC Hierarchy)
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
GNEMoveElement * getMoveElement() const override
methods to retrieve the elements linked to this tractionSubstation
bool isValid(SumoXMLAttr key, const std::string &value) override
const GUIGlObject * getGUIGlObjectFront() const
get front GUIGLObject or a pointer to nullptr
bool isCurrentlyMovingElements() const
check if an element is being moved
const GNEViewNetHelper::DataViewOptions & getDataViewOptions() const
get data view options
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
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
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
A list of positions.
bool showAdditionals() const
check if additionals has to be drawn
GNENetworkElement * getEditedNetworkElement() const
pointer to edited network element
static const RGBColor connectionColor
connection color
static const double tractionSubstationSize
tractionSubstation size