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-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>
27
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
39 GNEDetector(net, entryExitTag),
40 myMoveElementLaneSingle(new GNEMoveElementLaneSingle(this, SUMO_ATTR_POSITION, myPosOverLane, myFriendlyPos,
41 GNEMoveElementLaneSingle::PositionType::SINGLE)) {
42}
43
44
45GNEEntryExitDetector::GNEEntryExitDetector(SumoXMLTag entryExitTag, GNEAdditional* parent, GNELane* lane, const double pos,
46 const bool friendlyPos, const Parameterised::Map& parameters) :
47 GNEDetector(parent, entryExitTag, 0, "", "", parameters),
48 myPosOverLane(pos),
49 myFriendlyPos(friendlyPos),
50 myMoveElementLaneSingle(new GNEMoveElementLaneSingle(this, SUMO_ATTR_POSITION, myPosOverLane, myFriendlyPos,
51 GNEMoveElementLaneSingle::PositionType::SINGLE)) {
52 // set parents
53 setParent<GNELane*>(lane);
54 // update centering boundary without updating grid
56}
57#ifdef _MSC_VER
58#pragma warning(pop)
59#endif
60
61
65
66
71
72
73void
75 device.openTag(getTagProperty()->getTag());
76 // write common additional attributes
78 // write move attributes
80 // write common detector parameters
81 writeDetectorValues(device);
82 // write parameters
83 writeParams(device);
84 device.closeTag();
85}
86
87
88bool
90 // only movement problems
92}
93
94
95std::string
97 // only movement problems
99}
100
101
102void
107
108
109void
111 // update geometry
113 // update centering boundary without updating grid
115}
116
117
118void
120 // first check if additional has to be drawn
123 // Set initial values
124 const double entryExitExaggeration = getExaggeration(s);
125 // get detail level
126 const auto d = s.getDetailLevel(entryExitExaggeration);
127 // draw geometry only if we'rent in drawForObjectUnderCursor mode
129 // draw parent and child lines
131 // Push layer matrix
133 // translate to front
135 // Set color
136 RGBColor color;
137 if (drawUsingSelectColor()) {
139 } else if (myTagProperty->getTag() == SUMO_TAG_DET_ENTRY) {
141 } else if (myTagProperty->getTag() == SUMO_TAG_DET_EXIT) {
143 }
144 // draw parts
145 drawBody(d, color, entryExitExaggeration);
146 drawEntryLogo(d, color, entryExitExaggeration);
147 drawE3Logo(d, color, entryExitExaggeration);
148 // pop layer matrix
150 // draw additional name
152 // draw lock icon
154 entryExitExaggeration);
155 // draw dotted contour
157 }
158 // calculate contour
160 getType(), 2, 0, myAdditionalGeometry.getShapeRotations().front(), entryExitExaggeration,
161 getParentLanes().front()->getParentEdge());
162 }
163}
164
165
166std::string
168 switch (key) {
169 case GNE_ATTR_PARENT:
170 return getParentAdditionals().at(0)->getID();
171 default:
172 return getDetectorAttribute(key);
173 }
174}
175
176
177double
181
182
187
188
189void
190GNEEntryExitDetector::setAttribute(SumoXMLAttr key, const std::string& value, GNEUndoList* undoList) {
191 switch (key) {
192 case GNE_ATTR_PARENT:
193 GNEChange_Attribute::changeAttribute(this, key, value, undoList);
194 break;
195 default:
196 setDetectorAttribute(key, value, undoList);
197 break;
198 }
199}
200
201
202bool
203GNEEntryExitDetector::isValid(SumoXMLAttr key, const std::string& value) {
204 switch (key) {
205 case GNE_ATTR_PARENT:
206 return (myNet->getAttributeCarriers()->retrieveAdditional(SUMO_TAG_ENTRY_EXIT_DETECTOR, value, false) != nullptr);
207 default:
208 return isDetectorValid(key, value);
209 }
210}
211
212
213void
215 const RGBColor& color, const double exaggeration) const {
216 // check detail level
218 // Push polygon matrix
220 // set color
221 GLHelper::setColor(color);
222 // set polygon mode
223 glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
224 // move to position
225 glTranslated(myAdditionalGeometry.getShape().front().x(), myAdditionalGeometry.getShape().front().y(), 0);
226 // rotate over lane
228 // scale
229 glScaled(exaggeration, exaggeration, 1);
230 // check detail level
232 // Draw polygon
233 glBegin(GL_LINES);
234 glVertex2d(1.7, 0);
235 glVertex2d(-1.7, 0);
236 glEnd();
237 glBegin(GL_QUADS);
238 glVertex2d(-1.7, .5);
239 glVertex2d(-1.7, -.5);
240 glVertex2d(1.7, -.5);
241 glVertex2d(1.7, .5);
242 glEnd();
243 // first Arrow
244 glTranslated(1.5, 0, 0);
245 GLHelper::drawBoxLine(Position(0, 4), 0, 2, .05);
246 GLHelper::drawTriangleAtEnd(Position(0, 4), Position(0, 1), (double) 1, (double) .25);
247 // second Arrow
248 glTranslated(-3, 0, 0);
249 GLHelper::drawBoxLine(Position(0, 4), 0, 2, .05);
250 GLHelper::drawTriangleAtEnd(Position(0, 4), Position(0, 1), (double) 1, (double) .25);
251 } else {
252 // Draw square in drawy for selecting mode
253 glBegin(GL_QUADS);
254 glVertex2d(-1.7, 4.3);
255 glVertex2d(-1.7, -.5);
256 glVertex2d(1.7, -.5);
257 glVertex2d(1.7, 4.3);
258 glEnd();
259 }
260 // Pop polygon matrix
262 }
263}
264
265
266void
268 const RGBColor& color, const double exaggeration) const {
269 // check detail level
271 // Push matrix
273 // set color
274 GLHelper::setColor(color);
275 // Traslate to center of detector
276 glTranslated(myAdditionalGeometry.getShape().front().x(), myAdditionalGeometry.getShape().front().y(), getType() + 0.1);
277 // rotate over lane
279 //move to logo position
280 glTranslated(1.9, 0, 0);
281 // scale
282 glScaled(exaggeration, exaggeration, 1);
283 //move to logo position
284 glTranslated(1.7, 0, 0);
285 // rotate 90 degrees lane
286 glRotated(90, 0, 0, 1);
287 // draw Entry or Exit text if isn't being drawn for selecting
290 GLHelper::drawText("Entry", Position(), .1, 1, color, 180);
291 } else if (myTagProperty->getTag() == SUMO_TAG_DET_EXIT) {
292 GLHelper::drawText("Exit", Position(), .1, 1, color, 180);
293 }
294 } else {
295 GLHelper::drawBoxLine(Position(0, 1), 0, 2, 1);
296 }
297 // pop matrix
299 }
300}
301
302
303void
305 const RGBColor& color, const double exaggeration) const {
306 // check detail level
308 // Push matrix
310 // set color
311 GLHelper::setColor(color);
312 // Traslate to center of detector
313 glTranslated(myAdditionalGeometry.getShape().front().x(), myAdditionalGeometry.getShape().front().y(), getType() + 0.1);
314 // rotate over lane
316 //move to logo position
317 glTranslated(1.9, 0, 0);
318 // scale
319 glScaled(exaggeration, exaggeration, 1);
320 // draw E3 logo
321 GLHelper::drawText("E3", Position(0, 0), .1, 2.8, color);
322 // pop matrix
324 }
325}
326
327
328void
329GNEEntryExitDetector::setAttribute(SumoXMLAttr key, const std::string& value) {
330 switch (key) {
331 case SUMO_ATTR_LANE:
332 // set hier because GNEHierarchicalElement is a template
334 break;
335 case GNE_ATTR_PARENT:
337 break;
338 default:
339 setDetectorAttribute(key, value);
340 break;
341 }
342}
343
344/****************************************************************************/
@ 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.
GNENetHelper::AttributeCarriers * getAttributeCarriers() const
get all attribute carriers used in this net
Definition GNENet.cpp:174
GNEViewNet * getViewNet() const
get view net (used for simplify code)
Definition GNENet.cpp:144
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