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.dev/sumo
3 // Copyright (C) 2021-2024 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/GNEViewNet.h>
22 #include <netedit/GNEUndoList.h>
24 
25 #include "GNETractionSubstation.h"
26 
27 
28 // ===========================================================================
29 // member method definitions
30 // ===========================================================================
31 
34  GUIIconSubSys::getIcon(GUIIcon::TRACTION_SUBSTATION), "", {}, {}, {}, {}, {}, {}),
35  myVoltage(0),
36 myCurrentLimit(0) {
37  // reset default values
38  resetDefaultValues();
39 }
40 
41 
42 GNETractionSubstation::GNETractionSubstation(const std::string& id, GNENet* net, const Position& pos, const double voltage,
43  const double currentLimit, const Parameterised::Map& parameters) :
45  GUIIconSubSys::getIcon(GUIIcon::TRACTION_SUBSTATION), "", {}, {}, {}, {}, {}, {}),
46 Parameterised(parameters),
47 myPosition(pos),
48 myVoltage(voltage),
49 myCurrentLimit(currentLimit) {
50  // update centering boundary without updating grid
51  updateCenteringBoundary(false);
52 }
53 
54 
56 }
57 
58 
59 void
62  device.writeAttr(SUMO_ATTR_ID, getID());
66  }
69  }
70  // write parameters
71  writeParams(device);
72  device.closeTag();
73 }
74 
75 
76 bool
78  return true;
79 }
80 
81 
82 std::string
84  return "";
85 }
86 
87 
88 void
90  // nothing to fix
91 }
92 
93 
94 bool
96  // get edit modes
97  const auto& editModes = myNet->getViewNet()->getEditModes();
98  // check if we're in move mode
99  if (!myNet->getViewNet()->isCurrentlyMovingElements() && editModes.isCurrentSupermodeNetwork() &&
101  (editModes.networkEditMode == NetworkEditMode::NETWORK_MOVE) && myNet->getViewNet()->checkOverLockedElement(this, mySelected)) {
102  // only move the first element
104  } else {
105  return false;
106  }
107 }
108 
109 
112  // return move operation for additional placed in view
113  return new GNEMoveOperation(this, myPosition);
114 }
115 
116 
117 void
119  // update additional geometry
121 }
122 
123 
124 Position
126  return myPosition;
127 }
128 
129 
130 void
132  // remove additional from grid
133  if (updateGrid) {
135  }
136  // now update geometry
137  updateGeometry();
138  // add shape boundary
140  // grow
142  // add additional into RTREE again
143  if (updateGrid) {
144  myNet->addGLObjectIntoGrid(this);
145  }
146 }
147 
148 
149 void
150 GNETractionSubstation::splitEdgeGeometry(const double /*splitPosition*/, const GNENetworkElement* /*originalElement*/, const GNENetworkElement* /*newElement*/, GNEUndoList* /*undoList*/) {
151  // geometry of this element cannot be splitted
152 }
153 
154 
155 std::string
157  return myNet->getMicrosimID();
158 }
159 
160 
161 void
163  // draw parent and child lines
165  // draw TractionSubstation
167 }
168 
169 
170 std::string
172  switch (key) {
173  case SUMO_ATTR_ID:
174  return getMicrosimID();
175  case SUMO_ATTR_EDGES: {
176  std::vector<std::string> edges;
177  for (const auto& tractionSubstationSymbol : getChildAdditionals()) {
178  if (tractionSubstationSymbol->getTagProperty().isSymbol()) {
179  edges.push_back(tractionSubstationSymbol->getAttribute(SUMO_ATTR_EDGE));
180  }
181  }
182  return toString(edges);
183  }
184  case SUMO_ATTR_POSITION:
185  return toString(myPosition);
186  case SUMO_ATTR_VOLTAGE:
187  return toString(myVoltage);
189  return toString(myCurrentLimit);
190  case GNE_ATTR_SELECTED:
192  case GNE_ATTR_PARAMETERS:
193  return getParametersStr();
194  default:
195  throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
196  }
197 }
198 
199 
200 double
202  throw InvalidArgument(getTagStr() + " doesn't have a double attribute of type '" + toString(key) + "'");
203 }
204 
205 
206 const
208  return PARAMETERS_EMPTY;
209 }
210 
211 
212 void
213 GNETractionSubstation::setAttribute(SumoXMLAttr key, const std::string& value, GNEUndoList* undoList) {
214  if (value == getAttribute(key)) {
215  return; //avoid needless changes, later logic relies on the fact that attributes have changed
216  }
217  switch (key) {
218  // special case for lanes due tractionSubstation Symbols
219  case SUMO_ATTR_EDGES:
220  case SUMO_ATTR_ID:
221  case SUMO_ATTR_POSITION:
222  case SUMO_ATTR_VOLTAGE:
224  case GNE_ATTR_SELECTED:
225  case GNE_ATTR_PARAMETERS:
226  GNEChange_Attribute::changeAttribute(this, key, value, undoList);
227  break;
228  default:
229  throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
230  }
231 }
232 
233 
234 bool
235 GNETractionSubstation::isValid(SumoXMLAttr key, const std::string& value) {
236  switch (key) {
237  case SUMO_ATTR_ID:
238  return isValidAdditionalID(value);
239  case SUMO_ATTR_EDGES:
240  return canParse<std::vector<GNEEdge*> >(myNet, value, false);
241  case SUMO_ATTR_POSITION:
242  return canParse<Position>(value);
243  case SUMO_ATTR_VOLTAGE:
245  if (canParse<double>(value)) {
246  return (parse<double>(value) >= 0);
247  } else {
248  return false;
249  }
250  case GNE_ATTR_SELECTED:
251  return canParse<bool>(value);
252  case GNE_ATTR_PARAMETERS:
253  return areParametersValid(value);
254  default:
255  throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
256  }
257 }
258 
259 
260 std::string
262  return getTagStr() + ": " + getID();
263 }
264 
265 
266 std::string
268  return getTagStr();
269 }
270 
271 // ===========================================================================
272 // private
273 // ===========================================================================
274 
275 void
276 GNETractionSubstation::setAttribute(SumoXMLAttr key, const std::string& value) {
277  switch (key) {
278  case SUMO_ATTR_EDGES:
279  throw InvalidArgument(getTagStr() + " cannot be edited");
280  case SUMO_ATTR_ID:
281  // update microsimID
282  setAdditionalID(value);
283  break;
284  case SUMO_ATTR_POSITION:
285  myPosition = parse<Position>(value);
286  // update boundary (except for template)
287  if (getID().size() > 0) {
289  }
290  break;
291  case SUMO_ATTR_VOLTAGE:
292  myVoltage = parse<double>(value);
293  break;
295  myCurrentLimit = parse<double>(value);
296  break;
297  case GNE_ATTR_SELECTED:
298  if (parse<bool>(value)) {
300  } else {
302  }
303  break;
304  case GNE_ATTR_PARAMETERS:
305  setParametersStr(value);
306  break;
307  default:
308  throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
309  }
310 }
311 
312 
313 void
315  // update position
316  myPosition = moveResult.shapeToUpdate.front();
317  // update geometry
318  updateGeometry();
319 }
320 
321 
322 void
324  undoList->begin(this, "position of " + getTagStr());
326  undoList->end();
327 }
328 
329 /****************************************************************************/
@ NETWORK_MOVE
mode for moving network elements
@ 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:319
An Element which don't belong to GNENet but has influence in the simulation.
Definition: GNEAdditional.h:49
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 isAttributeCarrierSelected() const
check if attribute carrier is selected
bool mySelected
boolean to check if this AC is selected (instead of GUIGlObjectStorage)
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
static void changeAttribute(GNEAttributeCarrier *AC, SumoXMLAttr key, const std::string &value, GNEUndoList *undoList, const bool force=false)
change attribute
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:1368
void removeGLObjectFromGrid(GNEAttributeCarrier *AC)
add GL Object into net
Definition: GNENet.cpp:1378
GNEViewNet * getViewNet() const
get view net
Definition: GNENet.cpp:2136
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 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 attribute carrier or a pointer to nullptr
bool isCurrentlyMovingElements() const
check if an element is being moved
const GNEViewNetHelper::EditModes & getEditModes() const
get edit modes
Definition: GNEViewNet.cpp:723
const GNEViewNetHelper::EditNetworkElementShapes & getEditNetworkElementShapes() const
get Edit Shape module
Definition: GNEViewNet.cpp:759
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
Definition: GNEViewNet.cpp:477
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:143
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 & openTag(const std::string &xmlElement)
Opens an XML tag.
OutputDevice & writeAttr(const SumoXMLAttr attr, const T &val)
writes a named attribute
Definition: OutputDevice.h:254
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.
GNENetworkElement * getEditedNetworkElement() const
pointer to edited network element
static const RGBColor connectionColor
connection color
static const double tractionSubstationSize
tractionSubstation size