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
79 myMoveElementView->writeMoveAttributes(device);
80 // write specific attributes
81 if (myVoltage != myTagProperty->getDefaultDoubleValue(SUMO_ATTR_VOLTAGE)) {
83 }
84 if (myCurrentLimit != myTagProperty->getDefaultDoubleValue(SUMO_ATTR_CURRENTLIMIT)) {
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() &&
117 !myNet->getViewNet()->getEditNetworkElementShapes().getEditedNetworkElement() &&
118 (editModes.networkEditMode == NetworkEditMode::NETWORK_MOVE) && myNet->getViewNet()->checkOverLockedElement(this, mySelected)) {
119 // only move the first element
120 return myNet->getViewNet()->getViewObjectsSelector().getGUIGlObjectFront() == this;
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
153 return myNet->getMicrosimID();
154}
155
156
157void
159 // first check if additional has to be drawn
160 if (myNet->getViewNet()->getDataViewOptions().showAdditionals()) {
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:
188 return myMoveElementView->getMovingAttribute(key);
189 }
190}
191
192
193double
195 return myMoveElementView->getMovingAttributeDouble(key);
196}
197
198
201 return myMoveElementView->getMovingAttributePosition(key);
202}
203
204
207 return myMoveElementView->getMovingAttributePositionVector(key);
208}
209
210
211void
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
233 switch (key) {
234 case SUMO_ATTR_ID:
236 case SUMO_ATTR_EDGES:
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
268 switch (key) {
269 case SUMO_ATTR_EDGES:
270 throw InvalidArgument(getTagStr() + " cannot be edited");
271 case SUMO_ATTR_ID:
272 // update microsimID
274 break;
277 break;
280 break;
281 default:
282 myMoveElementView->setMovingAttribute(key, value);
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
Definition GUITextures.h:63
@ TRACTIONSUBSTATION
Definition GUITextures.h:62
const std::string invalid_return< std::string >::value
@ 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
friend class GNEAdditionalSquared
void writeAdditionalAttributes(OutputDevice &device) const
write common additional attributes
GNEAdditional(const std::string &id, GNENet *net, const std::string &filename, SumoXMLTag tag, const std::string &additionalName)
Constructor.
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
bool mySelected
boolean to check if this AC is selected (more quickly as checking GUIGlObjectStorage)
const std::string getID() const override
get ID (all Attribute Carriers have one)
static T parse(const std::string &string)
parses a value of type T from string (used for basic types: int, double, bool, etc....
const std::string & getTagStr() const
get tag assigned to this object in string format
static bool canParse(const std::string &string)
true if a value of type T can be parsed from string
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
A NBNetBuilder extended by visualisation and editing capabilities.
Definition GNENet.h:42
PositionVector getAttributePositionVector(SumoXMLAttr key) const override
void updateGeometry() override
update pre-computed geometry information
void writeAdditional(OutputDevice &device) const override
write additional element into a xml file
void drawGL(const GUIVisualizationSettings &s) const override
Draws the object.
void fixAdditionalProblem() override
fix additional problem (must be reimplemented in all detector children)
Position getAttributePosition(SumoXMLAttr key) const override
std::string getHierarchyName() const override
get Hierarchy Name (Used in AC Hierarchy)
double myCurrentLimit
current limit
void splitEdgeGeometry(const double splitPosition, const GNENetworkElement *originalElement, const GNENetworkElement *newElement, GNEUndoList *undoList) override
split geometry
std::string getAttribute(SumoXMLAttr key) const override
Position getPositionInView() const override
Returns position of additional in view.
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 isAdditionalValid() const override
check if current additional is valid to be written into XML (must be reimplemented in all detector ch...
bool checkDrawMoveContour() const override
check if draw move contour (red)
std::string getPopUpID() const override
get PopPup ID (Used in AC Hierarchy)
std::string getParentName() const override
Returns the name of the parent object.
GNETractionSubstation(GNENet *net)
default Constructor
GNEMoveElement * getMoveElement() const override
methods to retrieve the elements linked to this tractionSubstation
std::string getAdditionalProblem() const override
return a string with the current additional problem (must be reimplemented in all detector children)
bool isValid(SumoXMLAttr key, const std::string &value) override
void updateCenteringBoundary(const bool updateGrid) override
update centering boundary (implies change in RTREE)
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
Parameterised()
Default constructor.
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.
static const RGBColor connectionColor
connection color
static const double tractionSubstationSize
tractionSubstation size