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-2026 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
34#ifdef _MSC_VER
35#pragma warning(push)
36#pragma warning(disable: 4355) // mask warning about "this" in initializers
37#endif
40 myMoveElementLaneDouble(new GNEMoveElementLaneDouble(this, SUMO_ATTR_STARTPOS, myStartPosOverLane,
41 SUMO_ATTR_ENDPOS, myEndPosPosOverLane, myFriendlyPosition)) {
42}
43
44
45GNEOverheadWire::GNEOverheadWire(const std::string& id, GNENet* net, FileBucket* fileBucket, std::vector<GNELane*> lanes, GNEAdditional* substation,
46 const double startPos, const double endPos, const bool friendlyPos, const std::vector<std::string>& forbiddenInnerLanes,
47 const Parameterised::Map& parameters) :
48 GNEAdditional(id, net, SUMO_TAG_OVERHEAD_WIRE_SECTION, fileBucket, ""),
49 Parameterised(parameters),
50 myStartPosOverLane(startPos),
51 myEndPosPosOverLane(endPos),
52 myFriendlyPosition(friendlyPos),
53 myForbiddenInnerLanes(forbiddenInnerLanes),
54 myMoveElementLaneDouble(new GNEMoveElementLaneDouble(this, SUMO_ATTR_STARTPOS, myStartPosOverLane,
55 SUMO_ATTR_ENDPOS, myEndPosPosOverLane, myFriendlyPosition)) {
56 // set parents
57 setParents<GNELane*>(lanes);
58 setParent<GNEAdditional*>(substation);
59 // update centering boundary without updating grid
61}
62#ifdef _MSC_VER
63#pragma warning(pop)
64#endif
65
66
70
71
76
77
80 return this;
81}
82
83
84const Parameterised*
86 return this;
87}
88
89
90void
93 // write common additional attributes
95 // write move atributes
97 // write specific attributes
99 if (!myForbiddenInnerLanes.empty()) {
101 }
102 // write parameters
103 writeParams(device);
104 device.closeTag();
105}
106
107
108bool
110 // only movement problems
112}
113
114
115std::string
117 // only movement problems
119}
120
121
122void
124 // only movement problems
126}
127
128
129bool
131 return false;
132}
133
134
135void
137 // compute path
139}
140
141
146
147
148void
149GNEOverheadWire::updateCenteringBoundary(const bool /* updateGrid */) {
150 // nothing to update
151}
152
153
154void
155GNEOverheadWire::splitEdgeGeometry(const double /* splitPosition */, const GNENetworkElement* originalElement, const GNENetworkElement* newElement, GNEUndoList* undoList) {
156 // obtain new list of lanes
157 std::string newLanes = getNewListOfParents(originalElement, newElement);
158 // update Lanes
159 if (newLanes.size() > 0) {
160 setAttribute(SUMO_ATTR_LANES, newLanes, undoList);
161 }
162}
163
164
165void
167 // nothing to draw
168}
169
170
171void
176
177
178void
179GNEOverheadWire::drawLanePartialGL(const GUIVisualizationSettings& s, const GNESegment* segment, const double offsetFront) const {
180 // calculate overheadWire width
181 const double overheadWireWidth = s.addSize.getExaggeration(s, segment->getLane());
182 // check if E2 can be drawn
183 if (segment->getLane() && myNet->getViewNet()->getDataViewOptions().showAdditionals()) {
184 // get detail level
185 const auto d = s.getDetailLevel(overheadWireWidth);
186 // calculate startPos
187 const double geometryDepartPos = getAttributeDouble(SUMO_ATTR_STARTPOS);
188 // get endPos
189 const double geometryEndPos = getAttributeDouble(SUMO_ATTR_ENDPOS);
190 // declare path geometry
191 GUIGeometry overheadWireGeometry;
192 // update pathGeometry depending of first and last segment
193 if (segment->isFirstSegment() && segment->isLastSegment()) {
194 overheadWireGeometry.updateGeometry(segment->getLane()->getLaneGeometry().getShape(),
195 geometryDepartPos,
197 geometryEndPos,
199 } else if (segment->isFirstSegment()) {
200 overheadWireGeometry.updateGeometry(segment->getLane()->getLaneGeometry().getShape(),
201 geometryDepartPos,
203 -1,
205 } else if (segment->isLastSegment()) {
206 overheadWireGeometry.updateGeometry(segment->getLane()->getLaneGeometry().getShape(),
207 -1,
209 geometryEndPos,
211 } else {
212 overheadWireGeometry = segment->getLane()->getLaneGeometry();
213 }
214 // get both geometries
215 auto overheadWireGeometryTop = overheadWireGeometry;
216 auto overheadWireGeometryBot = overheadWireGeometry;
217 // move to sides
218 overheadWireGeometryTop.moveGeometryToSide(overheadWireWidth * 0.5);
219 overheadWireGeometryBot.moveGeometryToSide(overheadWireWidth * -0.5);
220 // draw geometry only if we'rent in drawForObjectUnderCursor mode
222 // obtain color
225 // push layer matrix
227 // Start with the drawing of the area traslating matrix to origin
228 glTranslated(0, 0, getType() + offsetFront);
229 // Set top color
230 GLHelper::setColor(overheadWireColorTop);
231 // draw top geometry
232 GUIGeometry::drawGeometry(d, overheadWireGeometryTop, 0.2);
233 // Set bot color
234 GLHelper::setColor(overheadWireColorBot);
235 // draw bot geometry
236 GUIGeometry::drawGeometry(d, overheadWireGeometryBot, 0.2);
237 // draw geometry points
238 if (segment->isFirstSegment() && segment->isLastSegment()) {
239 drawLeftGeometryPoint(s, d, overheadWireGeometry.getShape().front(), overheadWireGeometry.getShapeRotations().front(), overheadWireColorTop, true);
240 drawRightGeometryPoint(s, d, overheadWireGeometry.getShape().back(), overheadWireGeometry.getShapeRotations().back(), overheadWireColorTop, true);
241 } else if (segment->isFirstSegment()) {
242 drawLeftGeometryPoint(s, d, overheadWireGeometry.getShape().front(), overheadWireGeometry.getShapeRotations().front(), overheadWireColorTop, true);
243 } else if (segment->isLastSegment()) {
244 drawRightGeometryPoint(s, d, overheadWireGeometry.getShape().back(), overheadWireGeometry.getShapeRotations().back(), overheadWireColorTop, true);
245 }
246 // Pop layer matrix
248 // draw dotted contour
250 }
251 // declare trim geometry to draw
252 const auto shape = (segment->isFirstSegment() || segment->isLastSegment()) ? overheadWireGeometry.getShape() : segment->getLane()->getLaneShape();
253 // calculate contour and draw dotted geometry
254 myAdditionalContour.calculateContourExtrudedShape(s, d, this, shape, getType(), overheadWireWidth, 1, true, true, 0, segment, segment->getLane()->getParentEdge());
255 }
256}
257
258
259void
260GNEOverheadWire::drawJunctionPartialGL(const GUIVisualizationSettings& s, const GNESegment* segment, const double offsetFront) const {
261 // calculate overheadWire width
262 const double overheadWireWidth = s.addSize.getExaggeration(s, segment->getPreviousLane());
263 // check if overhead wire can be drawn
264 if (myNet->getViewNet()->getDataViewOptions().showAdditionals() && segment->getPreviousLane() && segment->getNextLane()) {
265 // obtain color
268 // declare geometry
269 GUIGeometry overheadWireGeometry({segment->getPreviousLane()->getLaneShape().back(), segment->getNextLane()->getLaneShape().front()});
270 // get detail level
271 const auto d = s.getDetailLevel(1);
272 // check if exist connection
273 if (segment->getPreviousLane()->getLane2laneConnections().exist(segment->getNextLane())) {
274 overheadWireGeometry = segment->getPreviousLane()->getLane2laneConnections().getLane2laneGeometry(segment->getNextLane());
275 }
276 // get both geometries
277 auto overheadWireGeometryTop = overheadWireGeometry;
278 auto overheadWireGeometryBot = overheadWireGeometry;
279 // move to sides
280 overheadWireGeometryTop.moveGeometryToSide(overheadWireWidth * 0.5);
281 overheadWireGeometryBot.moveGeometryToSide(overheadWireWidth * -0.5);
282 // draw geometry only if we'rent in drawForObjectUnderCursor mode
284 // Add a draw matrix
286 // Start with the drawing of the area traslating matrix to origin
287 glTranslated(0, 0, getType() + offsetFront);
288 // Set top color
289 GLHelper::setColor(overheadWireColorTop);
290 // draw top geometry
291 GUIGeometry::drawGeometry(d, overheadWireGeometryTop, 0.2);
292 // Set bot color
293 GLHelper::setColor(overheadWireColorBot);
294 // draw bot geometry
295 GUIGeometry::drawGeometry(d, overheadWireGeometryBot, 0.2);
296 // Pop last matrix
298 // draw dotted contour
300 }
301 // draw contours
302 if (segment->getPreviousLane()->getLane2laneConnections().exist(segment->getNextLane())) {
303 // get shape
304 const auto& shape = segment->getPreviousLane()->getLane2laneConnections().getLane2laneGeometry(segment->getNextLane()).getShape();
305 // calculate contour and draw dotted geometry
306 myAdditionalContour.calculateContourExtrudedShape(s, d, this, shape, getType(), overheadWireWidth, 1, true, true, 0, segment, segment->getJunction());
307 }
308 }
309}
310
311
312std::string
314 switch (key) {
315 case SUMO_ATTR_ID:
316 return getMicrosimID();
318 return getParentAdditionals().front()->getID();
319 case SUMO_ATTR_LANES:
320 return parseIDs(getParentLanes());
323 case SUMO_ATTR_ENDPOS:
328 return "";
329 default:
331 }
332}
333
334
335double
337 switch (key) {
339 if (myStartPosOverLane < 0) {
340 return 0;
341 } else if (myStartPosOverLane > getParentLanes().front()->getParentEdge()->getNBEdge()->getFinalLength()) {
342 return getParentLanes().front()->getParentEdge()->getNBEdge()->getFinalLength();
343 } else {
344 return myStartPosOverLane;
345 }
346 case SUMO_ATTR_ENDPOS:
347 if (myEndPosPosOverLane < 0) {
348 return 0;
349 } else if (myEndPosPosOverLane > getParentLanes().back()->getParentEdge()->getNBEdge()->getFinalLength()) {
350 return getParentLanes().back()->getParentEdge()->getNBEdge()->getFinalLength();
351 } else {
352 return myEndPosPosOverLane;
353 }
354 default:
356 }
357}
358
359
364
365
370
371
372void
373GNEOverheadWire::setAttribute(SumoXMLAttr key, const std::string& value, GNEUndoList* undoList) {
374 switch (key) {
375 case SUMO_ATTR_ID:
377 case SUMO_ATTR_LANES:
379 case SUMO_ATTR_ENDPOS:
381 GNEChange_Attribute::changeAttribute(this, key, value, undoList);
382 break;
383 default:
384 myMoveElementLaneDouble->setMovingAttribute(key, value, undoList);
385 break;
386 }
387}
388
389
390bool
391GNEOverheadWire::isValid(SumoXMLAttr key, const std::string& value) {
392 switch (key) {
393 case SUMO_ATTR_ID:
394 return isValidAdditionalID(value);
396 if (value.empty()) {
397 return false;
398 } else {
399 return (myNet->getAttributeCarriers()->retrieveAdditional(SUMO_TAG_TRACTION_SUBSTATION, value, false) != nullptr);
400 }
402 return true;
403 default:
405 }
406}
407
408
409std::string
411 return getTagStr() + ": " + getID();
412}
413
414
415std::string
417 return getTagStr();
418}
419
420// ===========================================================================
421// private
422// ===========================================================================
423
424void
425GNEOverheadWire::setAttribute(SumoXMLAttr key, const std::string& value) {
426 switch (key) {
427 case SUMO_ATTR_ID:
428 // update microsimID
429 setAdditionalID(value);
430 break;
433 break;
434 case SUMO_ATTR_LANES:
436 break;
438 myForbiddenInnerLanes = parse<std::vector<std::string> >(value);
439 break;
442 break;
443 default:
445 break;
446 }
447 // update geometry (except for template)
448 if (getParentLanes().size() > 0) {
450 }
451}
452
453/****************************************************************************/
@ 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:49
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.
GNENetHelper::AttributeCarriers * getAttributeCarriers() const
get all attribute carriers used in this net
Definition GNENet.cpp:174
GNEPathManager * getNetworkPathManager()
get network path manager
Definition GNENet.cpp:192
GNEViewNet * getViewNet() const
get view net (used for simplify code)
Definition GNENet.cpp:144
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 & openTag(const std::string &xmlElement)
Opens an XML tag.
OutputDevice & writeAttr(const ATTR_TYPE &attr, const T &val, const bool isNull=false)
writes a named attribute
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