Eclipse SUMO - Simulation of Urban MObility
Loading...
Searching...
No Matches
GNEOverheadWire.cpp
Go to the documentation of this file.
1/****************************************************************************/
2// Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo
3// Copyright (C) 2001-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
24#include <netedit/GNENet.h>
25#include <netedit/GNESegment.h>
27
28#include "GNEOverheadWire.h"
29
30// ===========================================================================
31// member method definitions
32// ===========================================================================
33
36 myMoveElementLaneDouble(new GNEMoveElementLaneDouble(this, SUMO_ATTR_STARTPOS, myStartPosOverLane,
37 SUMO_ATTR_ENDPOS, myEndPosPosOverLane, myFriendlyPosition)) {
38}
39
40
41GNEOverheadWire::GNEOverheadWire(const std::string& id, GNENet* net, const std::string& filename, std::vector<GNELane*> lanes, GNEAdditional* substation,
42 const double startPos, const double endPos, const bool friendlyPos, const std::vector<std::string>& forbiddenInnerLanes,
43 const Parameterised::Map& parameters) :
44 GNEAdditional(id, net, filename, SUMO_TAG_OVERHEAD_WIRE_SECTION, ""),
45 Parameterised(parameters),
46 myStartPosOverLane(startPos),
47 myEndPosPosOverLane(endPos),
48 myFriendlyPosition(friendlyPos),
49 myForbiddenInnerLanes(forbiddenInnerLanes),
50 myMoveElementLaneDouble(new GNEMoveElementLaneDouble(this, SUMO_ATTR_STARTPOS, myStartPosOverLane,
51 SUMO_ATTR_ENDPOS, myEndPosPosOverLane, myFriendlyPosition)) {
52 // set parents
53 setParents<GNELane*>(lanes);
54 setParent<GNEAdditional*>(substation);
55 // update centering boundary without updating grid
57}
58
59
63
64
69
70
73 return this;
74}
75
76
77const Parameterised*
79 return this;
80}
81
82
83void
86 // write common additional attributes
88 // write move atributes
90 // write specific attributes
92 if (!myForbiddenInnerLanes.empty()) {
94 }
95 // write parameters
96 writeParams(device);
97 device.closeTag();
98}
99
100
101bool
103 // only movement problems
105}
106
107
108std::string
110 // only movement problems
112}
113
114
115void
117 // only movement problems
119}
120
121
122bool
124 return false;
125}
126
127
128void
130 // compute path
132}
133
134
139
140
141void
142GNEOverheadWire::updateCenteringBoundary(const bool /* updateGrid */) {
143 // nothing to update
144}
145
146
147void
148GNEOverheadWire::splitEdgeGeometry(const double /* splitPosition */, const GNENetworkElement* originalElement, const GNENetworkElement* newElement, GNEUndoList* undoList) {
149 // obtain new list of lanes
150 std::string newLanes = getNewListOfParents(originalElement, newElement);
151 // update Lanes
152 if (newLanes.size() > 0) {
153 setAttribute(SUMO_ATTR_LANES, newLanes, undoList);
154 }
155}
156
157
158void
160 // nothing to draw
161}
162
163
164void
169
170
171void
172GNEOverheadWire::drawLanePartialGL(const GUIVisualizationSettings& s, const GNESegment* segment, const double offsetFront) const {
173 // calculate overheadWire width
174 const double overheadWireWidth = s.addSize.getExaggeration(s, segment->getLane());
175 // check if E2 can be drawn
176 if (segment->getLane() && myNet->getViewNet()->getDataViewOptions().showAdditionals()) {
177 // get detail level
178 const auto d = s.getDetailLevel(overheadWireWidth);
179 // calculate startPos
180 const double geometryDepartPos = getAttributeDouble(SUMO_ATTR_STARTPOS);
181 // get endPos
182 const double geometryEndPos = getAttributeDouble(SUMO_ATTR_ENDPOS);
183 // declare path geometry
184 GUIGeometry overheadWireGeometry;
185 // update pathGeometry depending of first and last segment
186 if (segment->isFirstSegment() && segment->isLastSegment()) {
187 overheadWireGeometry.updateGeometry(segment->getLane()->getLaneGeometry().getShape(),
188 geometryDepartPos,
190 geometryEndPos,
192 } else if (segment->isFirstSegment()) {
193 overheadWireGeometry.updateGeometry(segment->getLane()->getLaneGeometry().getShape(),
194 geometryDepartPos,
196 -1,
198 } else if (segment->isLastSegment()) {
199 overheadWireGeometry.updateGeometry(segment->getLane()->getLaneGeometry().getShape(),
200 -1,
202 geometryEndPos,
204 } else {
205 overheadWireGeometry = segment->getLane()->getLaneGeometry();
206 }
207 // get both geometries
208 auto overheadWireGeometryTop = overheadWireGeometry;
209 auto overheadWireGeometryBot = overheadWireGeometry;
210 // move to sides
211 overheadWireGeometryTop.moveGeometryToSide(overheadWireWidth * 0.5);
212 overheadWireGeometryBot.moveGeometryToSide(overheadWireWidth * -0.5);
213 // draw geometry only if we'rent in drawForObjectUnderCursor mode
215 // obtain color
218 // push layer matrix
220 // Start with the drawing of the area traslating matrix to origin
221 glTranslated(0, 0, getType() + offsetFront);
222 // Set top color
223 GLHelper::setColor(overheadWireColorTop);
224 // draw top geometry
225 GUIGeometry::drawGeometry(d, overheadWireGeometryTop, 0.2);
226 // Set bot color
227 GLHelper::setColor(overheadWireColorBot);
228 // draw bot geometry
229 GUIGeometry::drawGeometry(d, overheadWireGeometryBot, 0.2);
230 // draw geometry points
231 if (segment->isFirstSegment() && segment->isLastSegment()) {
232 drawLeftGeometryPoint(s, d, overheadWireGeometry.getShape().front(), overheadWireGeometry.getShapeRotations().front(), overheadWireColorTop, true);
233 drawRightGeometryPoint(s, d, overheadWireGeometry.getShape().back(), overheadWireGeometry.getShapeRotations().back(), overheadWireColorTop, true);
234 } else if (segment->isFirstSegment()) {
235 drawLeftGeometryPoint(s, d, overheadWireGeometry.getShape().front(), overheadWireGeometry.getShapeRotations().front(), overheadWireColorTop, true);
236 } else if (segment->isLastSegment()) {
237 drawRightGeometryPoint(s, d, overheadWireGeometry.getShape().back(), overheadWireGeometry.getShapeRotations().back(), overheadWireColorTop, true);
238 }
239 // Pop layer matrix
241 // draw dotted contour
243 }
244 // declare trim geometry to draw
245 const auto shape = (segment->isFirstSegment() || segment->isLastSegment()) ? overheadWireGeometry.getShape() : segment->getLane()->getLaneShape();
246 // calculate contour and draw dotted geometry
247 myAdditionalContour.calculateContourExtrudedShape(s, d, this, shape, getType(), overheadWireWidth, 1, true, true, 0, segment, segment->getLane()->getParentEdge());
248 }
249}
250
251
252void
253GNEOverheadWire::drawJunctionPartialGL(const GUIVisualizationSettings& s, const GNESegment* segment, const double offsetFront) const {
254 // calculate overheadWire width
255 const double overheadWireWidth = s.addSize.getExaggeration(s, segment->getPreviousLane());
256 // check if overhead wire can be drawn
257 if (myNet->getViewNet()->getDataViewOptions().showAdditionals() && segment->getPreviousLane() && segment->getNextLane()) {
258 // obtain color
261 // declare geometry
262 GUIGeometry overheadWireGeometry({segment->getPreviousLane()->getLaneShape().back(), segment->getNextLane()->getLaneShape().front()});
263 // get detail level
264 const auto d = s.getDetailLevel(1);
265 // check if exist connection
266 if (segment->getPreviousLane()->getLane2laneConnections().exist(segment->getNextLane())) {
267 overheadWireGeometry = segment->getPreviousLane()->getLane2laneConnections().getLane2laneGeometry(segment->getNextLane());
268 }
269 // get both geometries
270 auto overheadWireGeometryTop = overheadWireGeometry;
271 auto overheadWireGeometryBot = overheadWireGeometry;
272 // move to sides
273 overheadWireGeometryTop.moveGeometryToSide(overheadWireWidth * 0.5);
274 overheadWireGeometryBot.moveGeometryToSide(overheadWireWidth * -0.5);
275 // draw geometry only if we'rent in drawForObjectUnderCursor mode
277 // Add a draw matrix
279 // Start with the drawing of the area traslating matrix to origin
280 glTranslated(0, 0, getType() + offsetFront);
281 // Set top color
282 GLHelper::setColor(overheadWireColorTop);
283 // draw top geometry
284 GUIGeometry::drawGeometry(d, overheadWireGeometryTop, 0.2);
285 // Set bot color
286 GLHelper::setColor(overheadWireColorBot);
287 // draw bot geometry
288 GUIGeometry::drawGeometry(d, overheadWireGeometryBot, 0.2);
289 // Pop last matrix
291 // draw dotted contour
293 }
294 // draw contours
295 if (segment->getPreviousLane()->getLane2laneConnections().exist(segment->getNextLane())) {
296 // get shape
297 const auto& shape = segment->getPreviousLane()->getLane2laneConnections().getLane2laneGeometry(segment->getNextLane()).getShape();
298 // calculate contour and draw dotted geometry
299 myAdditionalContour.calculateContourExtrudedShape(s, d, this, shape, getType(), overheadWireWidth, 1, true, true, 0, segment, segment->getJunction());
300 }
301 }
302}
303
304
305std::string
307 switch (key) {
308 case SUMO_ATTR_ID:
309 return getMicrosimID();
311 return getParentAdditionals().front()->getID();
312 case SUMO_ATTR_LANES:
313 return parseIDs(getParentLanes());
316 case SUMO_ATTR_ENDPOS:
321 return "";
322 default:
324 }
325}
326
327
328double
330 switch (key) {
332 if (myStartPosOverLane < 0) {
333 return 0;
334 } else if (myStartPosOverLane > getParentLanes().front()->getParentEdge()->getNBEdge()->getFinalLength()) {
335 return getParentLanes().front()->getParentEdge()->getNBEdge()->getFinalLength();
336 } else {
337 return myStartPosOverLane;
338 }
339 case SUMO_ATTR_ENDPOS:
340 if (myEndPosPosOverLane < 0) {
341 return 0;
342 } else if (myEndPosPosOverLane > getParentLanes().back()->getParentEdge()->getNBEdge()->getFinalLength()) {
343 return getParentLanes().back()->getParentEdge()->getNBEdge()->getFinalLength();
344 } else {
345 return myEndPosPosOverLane;
346 }
347 default:
349 }
350}
351
352
357
358
363
364
365void
366GNEOverheadWire::setAttribute(SumoXMLAttr key, const std::string& value, GNEUndoList* undoList) {
367 switch (key) {
368 case SUMO_ATTR_ID:
370 case SUMO_ATTR_LANES:
372 case SUMO_ATTR_ENDPOS:
374 GNEChange_Attribute::changeAttribute(this, key, value, undoList);
375 break;
376 default:
377 myMoveElementLaneDouble->setMovingAttribute(key, value, undoList);
378 break;
379 }
380}
381
382
383bool
384GNEOverheadWire::isValid(SumoXMLAttr key, const std::string& value) {
385 switch (key) {
386 case SUMO_ATTR_ID:
387 return isValidAdditionalID(value);
389 if (value.empty()) {
390 return false;
391 } else {
392 return (myNet->getAttributeCarriers()->retrieveAdditional(SUMO_TAG_TRACTION_SUBSTATION, value, false) != nullptr);
393 }
395 return true;
396 default:
398 }
399}
400
401
402std::string
404 return getTagStr() + ": " + getID();
405}
406
407
408std::string
410 return getTagStr();
411}
412
413// ===========================================================================
414// private
415// ===========================================================================
416
417void
418GNEOverheadWire::setAttribute(SumoXMLAttr key, const std::string& value) {
419 switch (key) {
420 case SUMO_ATTR_ID:
421 // update microsimID
422 setAdditionalID(value);
423 break;
426 break;
427 case SUMO_ATTR_LANES:
429 break;
431 myForbiddenInnerLanes = parse<std::vector<std::string> >(value);
432 break;
435 break;
436 default:
438 break;
439 }
440 // update geometry (except for template)
441 if (getParentLanes().size() > 0) {
443 }
444}
445
446/****************************************************************************/
@ SUMO_TAG_TRACTION_SUBSTATION
A traction substation.
@ SUMO_TAG_OVERHEAD_WIRE_SECTION
An overhead wire section.
SumoXMLAttr
Numbers representing SUMO-XML - attributes.
@ SUMO_ATTR_STARTPOS
@ SUMO_ATTR_SUBSTATIONID
id of a traction substation substation
@ SUMO_ATTR_ENDPOS
@ SUMO_ATTR_OVERHEAD_WIRE_FORBIDDEN
forbidden lanes for overhead wire segment
@ SUMO_ATTR_LANES
@ SUMO_ATTR_ID
@ GNE_ATTR_SHIFTLANEINDEX
shift lane index (only used by elements over lanes)
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
Definition ToString.h:46
static void setColor(const RGBColor &c)
Sets the gl-color to this value.
Definition GLHelper.cpp:649
static void popMatrix()
pop matrix
Definition GLHelper.cpp:131
static void pushMatrix()
push matrix
Definition GLHelper.cpp:118
bool isValidAdditionalID(const std::string &value) const
check if a new additional ID is valid
void replaceAdditionalParent(SumoXMLTag tag, const std::string &value, const int parentIndex)
replace additional parent
void drawRightGeometryPoint(const GUIVisualizationSettings &s, const GUIVisualizationSettings::Detail d, const Position &pos, const double rot, const RGBColor &baseColor, const bool ignoreShift=false) const
draw right geometry point
void setAdditionalID(const std::string &newID)
set additional ID
GNEContour myAdditionalContour
variable used for draw additional contours
GUIGeometry myAdditionalGeometry
geometry to be precomputed in updateGeometry(...)
void replaceAdditionalParentLanes(const std::string &value)
replace additional parent lanes
void shiftLaneIndex()
shift lane index
void writeAdditionalAttributes(OutputDevice &device) const
write common additional attributes
void drawLeftGeometryPoint(const GUIVisualizationSettings &s, const GUIVisualizationSettings::Detail d, const Position &pos, const double rot, const RGBColor &baseColor, const bool ignoreShift=false) const
draw left geometry point
bool isAttributeCarrierSelected() const
check if attribute carrier is selected
const std::string getID() const override
get ID (all Attribute Carriers have one)
PositionVector getCommonAttributePositionVector(SumoXMLAttr key) const
const std::string & getTagStr() const
get tag assigned to this object in string format
bool drawUsingSelectColor() const
check if attribute carrier must be drawn using selecting color.
GNENet * myNet
pointer to net
static std::string parseIDs(const std::vector< T > &ACs)
parses a list of specific Attribute Carriers into a string of IDs
static void changeAttribute(GNEAttributeCarrier *AC, SumoXMLAttr key, const std::string &value, GNEUndoList *undoList, const bool force=false)
change attribute
void calculateContourExtrudedShape(const GUIVisualizationSettings &s, const GUIVisualizationSettings::Detail d, const GUIGlObject *glObject, const PositionVector &shape, const double layer, const double extrusionWidth, const double scale, const bool closeFirstExtrem, const bool closeLastExtrem, const double offset, const GNESegment *segment, const GUIGlObject *boundaryParent, const bool addToSelectedObjects=true) const
calculate contour extruded (used in elements formed by a central shape)
bool drawDottedContours(const GUIVisualizationSettings &s, const GUIVisualizationSettings::Detail d, const GNEAttributeCarrier *AC, const double lineWidth, const bool addOffset) const
draw dotted contours (basics, select, delete, inspect...)
const GNEHierarchicalContainerParents< GNEAdditional * > & getParentAdditionals() const
get parent additionals
const GNEHierarchicalContainerParents< GNELane * > & getParentLanes() const
get parent lanes
std::string getNewListOfParents(const GNENetworkElement *currentElement, const GNENetworkElement *newNextElement) const
if use edge/parent lanes as a list of consecutive elements, obtain a list of IDs of elements after in...
bool exist(const GNELane *toLane) const
check if exist a lane2lane geometry for the given toLane
const GUIGeometry & getLane2laneGeometry(const GNELane *toLane) const
get lane2lane geometry
const PositionVector & getLaneShape() const
get elements shape
Definition GNELane.cpp:232
const GNELane2laneConnection & getLane2laneConnections() const
get Lane2laneConnection struct
Definition GNELane.cpp:666
const GUIGeometry & getLaneGeometry() const
get lane geometry
Definition GNELane.cpp:226
GNEEdge * getParentEdge() const
get parent edge
Definition GNELane.cpp:214
std::string getMovingAttribute(SumoXMLAttr key) const override
get moving attribute
void fixMovingProblem()
fix moving problem
Position getMovingAttributePosition(SumoXMLAttr key) const override
get moving attribute position
double getMovingAttributeDouble(SumoXMLAttr key) const override
get moving attribute double
std::string getMovingProblem() const
return a string with the current moving problem
bool isMovingAttributeValid(SumoXMLAttr key, const std::string &value) const override
check if the given moving attribute is valid
bool isMoveElementValid() const
check if current moving element is valid to be written into XML
void writeMoveAttributes(OutputDevice &device, const bool writeLength) const
write move attributes
void setMovingAttribute(SumoXMLAttr key, const std::string &value, GNEUndoList *undoList) override
set moving attribute (using undo-list)
GNEAdditional * retrieveAdditional(SumoXMLTag type, const std::string &id, bool hardFail=true) const
Returns the named additional.
A NBNetBuilder extended by visualisation and editing capabilities.
Definition GNENet.h:42
GNENetHelper::AttributeCarriers * getAttributeCarriers() const
get all attribute carriers used in this net
Definition GNENet.cpp:144
GNEPathManager * getNetworkPathManager()
get network path manager
Definition GNENet.cpp:168
GNEViewNet * getViewNet() const
get view net
Definition GNENet.cpp:2193
void fixAdditionalProblem() override
fix additional problem
std::string getAdditionalProblem() const override
return a string with the current additional problem
Position getAttributePosition(SumoXMLAttr key) const override
void updateGeometry() override
update pre-computed geometry information
void computePathElement() override
compute pathElement
~GNEOverheadWire()
Destructor.
GNEMoveElement * getMoveElement() const override
methods to retrieve the elements linked to this overheadWire
PositionVector getAttributePositionVector(SumoXMLAttr key) const override
GNEMoveElementLaneDouble * myMoveElementLaneDouble
@brif move element lane double
void updateCenteringBoundary(const bool updateGrid) override
update centering boundary (implies change in RTREE)
Parameterised * getParameters() override
get parameters associated with this overheadWire
void drawJunctionPartialGL(const GUIVisualizationSettings &s, const GNESegment *segment, const double offsetFront) const override
Draws partial object over junction.
Position getPositionInView() const override
Returns position of additional in view.
double getAttributeDouble(SumoXMLAttr key) const override
void setAttribute(SumoXMLAttr key, const std::string &value, GNEUndoList *undoList) override
void writeAdditional(OutputDevice &device) const override
write additional element into a xml file
bool checkDrawMoveContour() const override
check if draw move contour (red)
double myEndPosPosOverLane
The end position over lane.
void drawGL(const GUIVisualizationSettings &s) const override
Draws the object.
bool isValid(SumoXMLAttr key, const std::string &value) override
bool isAdditionalValid() const override
check if current additional is valid to be written into XML
GNEOverheadWire(GNENet *net)
default Constructor
void drawLanePartialGL(const GUIVisualizationSettings &s, const GNESegment *segment, const double offsetFront) const override
Draws partial object over lane.
std::string getAttribute(SumoXMLAttr key) const override
std::string getPopUpID() const override
get PopPup ID (Used in AC Hierarchy)
std::string getHierarchyName() const override
get Hierarchy Name (Used in AC Hierarchy)
double myStartPosOverLane
The start position over lane.
void splitEdgeGeometry(const double splitPosition, const GNENetworkElement *originalElement, const GNENetworkElement *newElement, GNEUndoList *undoList) override
split geometry
std::vector< std::string > myForbiddenInnerLanes
forbidden inner lanes
void calculateConsecutivePathLanes(GNEPathElement *pathElement, const std::vector< GNELane * > &lanes)
calculate consecutive path lanes
const GNELane * getLane() const
get lane associated with this segment
const GNEJunction * getJunction() const
get junction associated with this segment
const GNELane * getNextLane() const
get next lane
const GNELane * getPreviousLane() const
get previous lane
bool isFirstSegment() const
check if segment is the first path's segment
bool isLastSegment() const
check if segment is the last path's segment
const GNEViewNetHelper::DataViewOptions & getDataViewOptions() const
get data view options
void moveGeometryToSide(const double amount)
move current shape to side
const std::vector< double > & getShapeRotations() const
The rotations of the single shape parts.
static void drawGeometry(const GUIVisualizationSettings::Detail d, const GUIGeometry &geometry, const double width, double offset=0)
draw geometry
const PositionVector & getShape() const
The shape of the additional element.
void updateGeometry(const PositionVector &shape)
update entire geometry
const std::string & getMicrosimID() const
Returns the id of the object as known to microsim.
GUIGlObjectType getType() const
Returns the type of the object as coded in GUIGlObjectType.
Stores the information about how to visualize structures.
GUIVisualizationSizeSettings addSize
bool checkDrawAdditional(Detail d, const bool selected) const
check if draw additionals
Detail getDetailLevel(const double exaggeration) const
return the detail level
GUIVisualizationColorSettings colorSettings
color settings
GUIVisualizationDottedContourSettings dottedContourSettings
dotted contour settings
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
static const Position INVALID
used to indicate that a position is valid
Definition Position.h:323
A list of positions.
Position getPolygonCenter() const
Returns the arithmetic of all corner points.
bool showAdditionals() const
check if additionals has to be drawn
static const RGBColor overheadWireColorBot
overhead wire color bot
static const RGBColor overheadWireColorTop
overhead wire color top
RGBColor selectedAdditionalColor
additional selection color (busStops, Detectors...)
static const double segmentWidth
width of dotted contour segments
double getExaggeration(const GUIVisualizationSettings &s, const GUIGlObject *o, double factor=20) const
return the drawing size including exaggeration and constantSize values