Eclipse SUMO - Simulation of Urban MObility
Loading...
Searching...
No Matches
GNEEntryExitDetector.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
23#include <netedit/GNENet.h>
26
28
29// ===========================================================================
30// member method definitions
31// ===========================================================================
32
34 GNEDetector(net, entryExitTag),
35 myMoveElementLaneSingle(new GNEMoveElementLaneSingle(this, SUMO_ATTR_POSITION, myPosOverLane, myFriendlyPos,
36 GNEMoveElementLaneSingle::PositionType::SINGLE)) {
37}
38
39
40GNEEntryExitDetector::GNEEntryExitDetector(SumoXMLTag entryExitTag, GNEAdditional* parent, GNELane* lane, const double pos,
41 const bool friendlyPos, const Parameterised::Map& parameters) :
42 GNEDetector(parent, entryExitTag, 0, "", "", parameters),
43 myPosOverLane(pos),
44 myFriendlyPos(friendlyPos),
45 myMoveElementLaneSingle(new GNEMoveElementLaneSingle(this, SUMO_ATTR_POSITION, myPosOverLane, myFriendlyPos,
46 GNEMoveElementLaneSingle::PositionType::SINGLE)) {
47 // set parents
48 setParent<GNELane*>(lane);
49 // update centering boundary without updating grid
51}
52
53
57
58
63
64
65void
67 device.openTag(getTagProperty()->getTag());
68 // write common additional attributes
70 // write move attributes
72 // write common detector parameters
73 writeDetectorValues(device);
74 // write parameters
75 writeParams(device);
76 device.closeTag();
77}
78
79
80bool
82 // only movement problems
84}
85
86
87std::string
89 // only movement problems
91}
92
93
94void
99
100
101void
103 // update geometry
105 // update centering boundary without updating grid
107}
108
109
110void
112 // first check if additional has to be drawn
115 // Set initial values
116 const double entryExitExaggeration = getExaggeration(s);
117 // get detail level
118 const auto d = s.getDetailLevel(entryExitExaggeration);
119 // draw geometry only if we'rent in drawForObjectUnderCursor mode
121 // draw parent and child lines
123 // Push layer matrix
125 // translate to front
127 // Set color
128 RGBColor color;
129 if (drawUsingSelectColor()) {
131 } else if (myTagProperty->getTag() == SUMO_TAG_DET_ENTRY) {
133 } else if (myTagProperty->getTag() == SUMO_TAG_DET_EXIT) {
135 }
136 // draw parts
137 drawBody(d, color, entryExitExaggeration);
138 drawEntryLogo(d, color, entryExitExaggeration);
139 drawE3Logo(d, color, entryExitExaggeration);
140 // pop layer matrix
142 // draw additional name
144 // draw lock icon
146 entryExitExaggeration);
147 // draw dotted contour
149 }
150 // calculate contour
152 getType(), 2, 0, myAdditionalGeometry.getShapeRotations().front(), entryExitExaggeration,
153 getParentLanes().front()->getParentEdge());
154 }
155}
156
157
158std::string
160 switch (key) {
161 case GNE_ATTR_PARENT:
162 return getParentAdditionals().at(0)->getID();
163 default:
164 return getDetectorAttribute(key);
165 }
166}
167
168
169double
173
174
179
180
181void
182GNEEntryExitDetector::setAttribute(SumoXMLAttr key, const std::string& value, GNEUndoList* undoList) {
183 switch (key) {
184 case GNE_ATTR_PARENT:
185 GNEChange_Attribute::changeAttribute(this, key, value, undoList);
186 break;
187 default:
188 setDetectorAttribute(key, value, undoList);
189 break;
190 }
191}
192
193
194bool
195GNEEntryExitDetector::isValid(SumoXMLAttr key, const std::string& value) {
196 switch (key) {
197 case GNE_ATTR_PARENT:
198 return (myNet->getAttributeCarriers()->retrieveAdditional(SUMO_TAG_ENTRY_EXIT_DETECTOR, value, false) != nullptr);
199 default:
200 return isDetectorValid(key, value);
201 }
202}
203
204
205void
207 const RGBColor& color, const double exaggeration) const {
208 // check detail level
210 // Push polygon matrix
212 // set color
213 GLHelper::setColor(color);
214 // set polygon mode
215 glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
216 // move to position
217 glTranslated(myAdditionalGeometry.getShape().front().x(), myAdditionalGeometry.getShape().front().y(), 0);
218 // rotate over lane
220 // scale
221 glScaled(exaggeration, exaggeration, 1);
222 // check detail level
224 // Draw polygon
225 glBegin(GL_LINES);
226 glVertex2d(1.7, 0);
227 glVertex2d(-1.7, 0);
228 glEnd();
229 glBegin(GL_QUADS);
230 glVertex2d(-1.7, .5);
231 glVertex2d(-1.7, -.5);
232 glVertex2d(1.7, -.5);
233 glVertex2d(1.7, .5);
234 glEnd();
235 // first Arrow
236 glTranslated(1.5, 0, 0);
237 GLHelper::drawBoxLine(Position(0, 4), 0, 2, .05);
238 GLHelper::drawTriangleAtEnd(Position(0, 4), Position(0, 1), (double) 1, (double) .25);
239 // second Arrow
240 glTranslated(-3, 0, 0);
241 GLHelper::drawBoxLine(Position(0, 4), 0, 2, .05);
242 GLHelper::drawTriangleAtEnd(Position(0, 4), Position(0, 1), (double) 1, (double) .25);
243 } else {
244 // Draw square in drawy for selecting mode
245 glBegin(GL_QUADS);
246 glVertex2d(-1.7, 4.3);
247 glVertex2d(-1.7, -.5);
248 glVertex2d(1.7, -.5);
249 glVertex2d(1.7, 4.3);
250 glEnd();
251 }
252 // Pop polygon matrix
254 }
255}
256
257
258void
260 const RGBColor& color, const double exaggeration) const {
261 // check detail level
263 // Push matrix
265 // set color
266 GLHelper::setColor(color);
267 // Traslate to center of detector
268 glTranslated(myAdditionalGeometry.getShape().front().x(), myAdditionalGeometry.getShape().front().y(), getType() + 0.1);
269 // rotate over lane
271 //move to logo position
272 glTranslated(1.9, 0, 0);
273 // scale
274 glScaled(exaggeration, exaggeration, 1);
275 //move to logo position
276 glTranslated(1.7, 0, 0);
277 // rotate 90 degrees lane
278 glRotated(90, 0, 0, 1);
279 // draw Entry or Exit text if isn't being drawn for selecting
282 GLHelper::drawText("Entry", Position(), .1, 1, color, 180);
283 } else if (myTagProperty->getTag() == SUMO_TAG_DET_EXIT) {
284 GLHelper::drawText("Exit", Position(), .1, 1, color, 180);
285 }
286 } else {
287 GLHelper::drawBoxLine(Position(0, 1), 0, 2, 1);
288 }
289 // pop matrix
291 }
292}
293
294
295void
297 const RGBColor& color, const double exaggeration) const {
298 // check detail level
300 // Push matrix
302 // set color
303 GLHelper::setColor(color);
304 // Traslate to center of detector
305 glTranslated(myAdditionalGeometry.getShape().front().x(), myAdditionalGeometry.getShape().front().y(), getType() + 0.1);
306 // rotate over lane
308 //move to logo position
309 glTranslated(1.9, 0, 0);
310 // scale
311 glScaled(exaggeration, exaggeration, 1);
312 // draw E3 logo
313 GLHelper::drawText("E3", Position(0, 0), .1, 2.8, color);
314 // pop matrix
316 }
317}
318
319
320void
321GNEEntryExitDetector::setAttribute(SumoXMLAttr key, const std::string& value) {
322 switch (key) {
323 case SUMO_ATTR_LANE:
324 // set hier because GNEHierarchicalElement is a template
326 break;
327 case GNE_ATTR_PARENT:
329 break;
330 default:
331 setDetectorAttribute(key, value);
332 break;
333 }
334}
335
336/****************************************************************************/
@ GLO_DET_ENTRY
a DetEntry detector
SumoXMLTag
Numbers representing SUMO-XML - element names.
@ SUMO_TAG_DET_ENTRY
an e3 entry point
@ SUMO_TAG_DET_EXIT
an e3 exit point
@ SUMO_TAG_ENTRY_EXIT_DETECTOR
alternative tag for e3 detector
SumoXMLAttr
Numbers representing SUMO-XML - attributes.
@ SUMO_ATTR_LANE
@ GNE_ATTR_PARENT
parent of an additional element
@ SUMO_ATTR_POSITION
static void setColor(const RGBColor &c)
Sets the gl-color to this value.
Definition GLHelper.cpp:649
static void drawTriangleAtEnd(const Position &p1, const Position &p2, double tLength, double tWidth, const double extraOffset=0)
Draws a triangle at the end of the given line.
Definition GLHelper.cpp:624
static void popMatrix()
pop matrix
Definition GLHelper.cpp:131
static void drawBoxLine(const Position &beg, double rot, double visLength, double width, double offset=0)
Draws a thick line.
Definition GLHelper.cpp:296
static void pushMatrix()
push matrix
Definition GLHelper.cpp:118
static void drawText(const std::string &text, const Position &pos, const double layer, const double size, const RGBColor &col=RGBColor::BLACK, const double angle=0, const int align=0, double width=-1)
Definition GLHelper.cpp:742
double getExaggeration(const GUIVisualizationSettings &s) const override
return exaggeration associated with this GLObject
void replaceAdditionalParent(SumoXMLTag tag, const std::string &value, const int parentIndex)
replace additional parent
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 drawAdditionalName(const GUIVisualizationSettings &s) const
draw additional name
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
bool isAttributeCarrierSelected() const
check if attribute carrier is selected
bool drawUsingSelectColor() const
check if attribute carrier must be drawn using selecting color.
void drawInLayer(const double typeOrLayer, const double extraOffset=0) const
draw element in the given layer, or in front if corresponding flag is enabled
const GNETagProperties * getTagProperty() const
get tagProperty associated with this Attribute Carrier
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
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...)
void calculateContourRectangleShape(const GUIVisualizationSettings &s, const GUIVisualizationSettings::Detail d, const GUIGlObject *glObject, const Position &pos, const double width, const double height, const double layer, const double offsetX, const double offsetY, const double rot, const double scale, const GUIGlObject *boundaryParent) const
calculate contour (for rectangled elements)
Position getDetectorAttributePosition(SumoXMLAttr key) const
bool isDetectorValid(SumoXMLAttr key, const std::string &value)
void setDetectorAttribute(SumoXMLAttr key, const std::string &value, GNEUndoList *undoList)
double getDetectorAttributeDouble(SumoXMLAttr key) const
void writeDetectorValues(OutputDevice &device) const
write additional element into a xml file
void updateCenteringBoundary(const bool updateGrid)
update centering boundary (implies change in RTREE)
std::string getDetectorAttribute(SumoXMLAttr key) const
void updateGeometry() override
update pre-computed geometry information
GNEMoveElement * getMoveElement() const override
methods to retrieve the elements linked to this GNEAdditional
void writeAdditional(OutputDevice &device) const
write additional element into a xml file
std::string getAdditionalProblem() const
return a string with the current additional problem
bool isAdditionalValid() const
check if current additional is valid to be written into XML
void fixAdditionalProblem()
fix additional problem
Position getAttributePosition(SumoXMLAttr key) const override
void drawBody(const GUIVisualizationSettings::Detail d, const RGBColor &color, const double exaggeration) const
draw body
GNEMoveElementLaneSingle * myMoveElementLaneSingle
move element lane single
std::string getAttribute(SumoXMLAttr key) const override
void drawGL(const GUIVisualizationSettings &s) const
Draws the object.
double getAttributeDouble(SumoXMLAttr key) const override
void setAttribute(SumoXMLAttr key, const std::string &value, GNEUndoList *undoList) override
~GNEEntryExitDetector()
destructor
bool isValid(SumoXMLAttr key, const std::string &value) override
void drawE3Logo(const GUIVisualizationSettings::Detail d, const RGBColor &color, const double exaggeration) const
draw E3 logo
void drawEntryLogo(const GUIVisualizationSettings::Detail d, const RGBColor &color, const double exaggeration) const
draw entry logo
GNEEntryExitDetector(SumoXMLTag entryExitTag, GNENet *net)
default Constructor
const GNEHierarchicalContainerParents< GNEAdditional * > & getParentAdditionals() const
get parent additionals
const GNEHierarchicalContainerParents< GNELane * > & getParentLanes() const
get parent lanes
double myMovingLateralOffset
move element lateral offset
bool isMoveElementValid() const
check if current moving element is valid to be written into XML
std::string getMovingProblem() const
return a string with the current moving problem
void writeMoveAttributes(OutputDevice &device) const
write move attributes
double getFixedPositionOverLane(const bool adjustGeometryFactor) const
get fixed offset position over lane
void fixMovingProblem()
fix moving problem
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
GNEViewNet * getViewNet() const
get view net
Definition GNENet.cpp:2193
SumoXMLTag getTag() const
get Tag vinculated with this attribute Property
const GNEViewNetHelper::DataViewOptions & getDataViewOptions() const
get data view options
bool selectingDetectorsTLSMode() const
check if we're selecting detectors in TLS mode
static void rotateOverLane(const double rot)
rotate over lane (used by Lock icons, detector logos, etc.)
const std::vector< double > & getShapeRotations() const
The rotations of the single shape parts.
const PositionVector & getShape() const
The shape of the additional element.
void updateGeometry(const PositionVector &shape)
update entire geometry
GUIGlObjectType getType() const
Returns the type of the object as coded in GUIGlObjectType.
Stores the information about how to visualize structures.
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.
GUIVisualizationDetectorSettings detectorSettings
Detector settings.
Static storage of an output device and its base (abstract) implementation.
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.
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
Position getCentroid() const
Returns the centroid (closes the polygon if unclosed)
bool showAdditionals() const
check if additionals has to be drawn
static void drawLockIcon(const GUIVisualizationSettings::Detail d, const GNEAttributeCarrier *AC, GUIGlObjectType type, const Position position, const double exaggeration, const double size=0.5, const double offsetx=0, const double offsety=0)
draw lock icon
static const RGBColor connectionColor
connection color
RGBColor selectedAdditionalColor
additional selection color (busStops, Detectors...)
static const RGBColor E3ExitColor
color for Exits
static const RGBColor E3EntryColor
color for Entrys
static const double segmentWidth
width of dotted contour segments