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#include <config.h>
21
24#include <netedit/GNENet.h>
27
29
30// ===========================================================================
31// member method definitions
32// ===========================================================================
33
35 GNEDetector(net, entryExitTag),
36 myMoveElementLaneSingle(new GNEMoveElementLaneSingle(this, SUMO_ATTR_POSITION, myPosOverLane, myFriendlyPos,
37 GNEMoveElementLaneSingle::PositionType::SINGLE)) {
38}
39
40
41GNEEntryExitDetector::GNEEntryExitDetector(SumoXMLTag entryExitTag, GNEAdditional* parent, GNELane* lane, const double pos,
42 const bool friendlyPos, const Parameterised::Map& parameters) :
43 GNEDetector(parent, entryExitTag, 0, "", "", parameters),
44 myPosOverLane(pos),
45 myFriendlyPos(friendlyPos),
46 myMoveElementLaneSingle(new GNEMoveElementLaneSingle(this, SUMO_ATTR_POSITION, myPosOverLane, myFriendlyPos,
47 GNEMoveElementLaneSingle::PositionType::SINGLE)) {
48 // set parents
49 setParent<GNELane*>(lane);
50 // update centering boundary without updating grid
52}
53
54
58
59
64
65
66void
68 device.openTag(getTagProperty()->getTag());
69 // write common additional attributes
71 // write move attributes
73 // write common detector parameters
74 writeDetectorValues(device);
75 // write parameters
76 writeParams(device);
77 device.closeTag();
78}
79
80
81bool
83 // only movement problems
85}
86
87
88std::string
90 // only movement problems
92}
93
94
95void
100
101
102void
104 // update geometry
106 // update centering boundary without updating grid
108}
109
110
111void
113 // first check if additional has to be drawn
116 // Set initial values
117 const double entryExitExaggeration = getExaggeration(s);
118 // get detail level
119 const auto d = s.getDetailLevel(entryExitExaggeration);
120 // draw geometry only if we'rent in drawForObjectUnderCursor mode
122 // draw parent and child lines
124 // Push layer matrix
126 // translate to front
128 // Set color
129 RGBColor color;
130 if (drawUsingSelectColor()) {
132 } else if (myTagProperty->getTag() == SUMO_TAG_DET_ENTRY) {
134 } else if (myTagProperty->getTag() == SUMO_TAG_DET_EXIT) {
136 }
137 // draw parts
138 drawBody(d, color, entryExitExaggeration);
139 drawEntryLogo(d, color, entryExitExaggeration);
140 drawE3Logo(d, color, entryExitExaggeration);
141 // pop layer matrix
143 // draw additional name
145 // draw lock icon
147 entryExitExaggeration);
148 // draw dotted contour
150 }
151 // calculate contour
153 getType(), 2, 0, myAdditionalGeometry.getShapeRotations().front(), entryExitExaggeration,
154 getParentLanes().front()->getParentEdge());
155 }
156}
157
158
159std::string
161 switch (key) {
162 case GNE_ATTR_PARENT:
163 return getParentAdditionals().at(0)->getID();
164 default:
165 return getDetectorAttribute(key);
166 }
167}
168
169
170double
174
175
180
181
182void
183GNEEntryExitDetector::setAttribute(SumoXMLAttr key, const std::string& value, GNEUndoList* undoList) {
184 switch (key) {
185 case GNE_ATTR_PARENT:
186 GNEChange_Attribute::changeAttribute(this, key, value, undoList);
187 break;
188 default:
189 setDetectorAttribute(key, value, undoList);
190 break;
191 }
192}
193
194
195bool
196GNEEntryExitDetector::isValid(SumoXMLAttr key, const std::string& value) {
197 switch (key) {
198 case GNE_ATTR_PARENT:
199 return (myNet->getAttributeCarriers()->retrieveAdditional(SUMO_TAG_ENTRY_EXIT_DETECTOR, value, false) != nullptr);
200 default:
201 return isDetectorValid(key, value);
202 }
203}
204
205
206void
208 const RGBColor& color, const double exaggeration) const {
209 // check detail level
211 // Push polygon matrix
213 // set color
214 GLHelper::setColor(color);
215 // set polygon mode
216 glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
217 // move to position
218 glTranslated(myAdditionalGeometry.getShape().front().x(), myAdditionalGeometry.getShape().front().y(), 0);
219 // rotate over lane
221 // scale
222 glScaled(exaggeration, exaggeration, 1);
223 // check detail level
225 // Draw polygon
226 glBegin(GL_LINES);
227 glVertex2d(1.7, 0);
228 glVertex2d(-1.7, 0);
229 glEnd();
230 glBegin(GL_QUADS);
231 glVertex2d(-1.7, .5);
232 glVertex2d(-1.7, -.5);
233 glVertex2d(1.7, -.5);
234 glVertex2d(1.7, .5);
235 glEnd();
236 // first Arrow
237 glTranslated(1.5, 0, 0);
238 GLHelper::drawBoxLine(Position(0, 4), 0, 2, .05);
239 GLHelper::drawTriangleAtEnd(Position(0, 4), Position(0, 1), (double) 1, (double) .25);
240 // second Arrow
241 glTranslated(-3, 0, 0);
242 GLHelper::drawBoxLine(Position(0, 4), 0, 2, .05);
243 GLHelper::drawTriangleAtEnd(Position(0, 4), Position(0, 1), (double) 1, (double) .25);
244 } else {
245 // Draw square in drawy for selecting mode
246 glBegin(GL_QUADS);
247 glVertex2d(-1.7, 4.3);
248 glVertex2d(-1.7, -.5);
249 glVertex2d(1.7, -.5);
250 glVertex2d(1.7, 4.3);
251 glEnd();
252 }
253 // Pop polygon matrix
255 }
256}
257
258
259void
261 const RGBColor& color, const double exaggeration) const {
262 // check detail level
264 // Push matrix
266 // set color
267 GLHelper::setColor(color);
268 // Traslate to center of detector
269 glTranslated(myAdditionalGeometry.getShape().front().x(), myAdditionalGeometry.getShape().front().y(), getType() + 0.1);
270 // rotate over lane
272 //move to logo position
273 glTranslated(1.9, 0, 0);
274 // scale
275 glScaled(exaggeration, exaggeration, 1);
276 //move to logo position
277 glTranslated(1.7, 0, 0);
278 // rotate 90 degrees lane
279 glRotated(90, 0, 0, 1);
280 // draw Entry or Exit text if isn't being drawn for selecting
283 GLHelper::drawText("Entry", Position(), .1, 1, color, 180);
284 } else if (myTagProperty->getTag() == SUMO_TAG_DET_EXIT) {
285 GLHelper::drawText("Exit", Position(), .1, 1, color, 180);
286 }
287 } else {
288 GLHelper::drawBoxLine(Position(0, 1), 0, 2, 1);
289 }
290 // pop matrix
292 }
293}
294
295
296void
298 const RGBColor& color, const double exaggeration) const {
299 // check detail level
301 // Push matrix
303 // set color
304 GLHelper::setColor(color);
305 // Traslate to center of detector
306 glTranslated(myAdditionalGeometry.getShape().front().x(), myAdditionalGeometry.getShape().front().y(), getType() + 0.1);
307 // rotate over lane
309 //move to logo position
310 glTranslated(1.9, 0, 0);
311 // scale
312 glScaled(exaggeration, exaggeration, 1);
313 // draw E3 logo
314 GLHelper::drawText("E3", Position(0, 0), .1, 2.8, color);
315 // pop matrix
317 }
318}
319
320
321void
322GNEEntryExitDetector::setAttribute(SumoXMLAttr key, const std::string& value) {
323 switch (key) {
324 case SUMO_ATTR_LANE:
325 // set hier because GNEHierarchicalElement is a template
327 break;
328 case GNE_ATTR_PARENT:
330 break;
331 default:
332 setDetectorAttribute(key, value);
333 break;
334 }
335}
336
337/****************************************************************************/
@ 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) override
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 drawGL(const GUIVisualizationSettings &s) const override
Draws the object.
bool isAdditionalValid() const override
check if current additional is valid to be written into XML
Position getAttributePosition(SumoXMLAttr key) const override
void writeAdditional(OutputDevice &device) const override
write additional element into a xml file
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
double getAttributeDouble(SumoXMLAttr key) const override
void setAttribute(SumoXMLAttr key, const std::string &value, GNEUndoList *undoList) override
~GNEEntryExitDetector()
destructor
void fixAdditionalProblem() override
fix additional problem
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
std::string getAdditionalProblem() const override
return a string with the current additional problem
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