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
23
26#include <netedit/GNENet.h>
29
31
32// ===========================================================================
33// member method definitions
34// ===========================================================================
35
36#ifdef _MSC_VER
37#pragma warning(push)
38#pragma warning(disable: 4355) // mask warning about "this" in initializers
39#endif
41 GNEDetector(net, entryExitTag),
42 myMoveElementLaneSingle(new GNEMoveElementLaneSingle(this, SUMO_ATTR_POSITION, myPosOverLane, myFriendlyPos,
43 GNEMoveElementLaneSingle::PositionType::SINGLE)) {
44}
45
46
47GNEEntryExitDetector::GNEEntryExitDetector(SumoXMLTag entryExitTag, GNEAdditional* parent, GNELane* lane, const double pos,
48 const bool friendlyPos, const Parameterised::Map& parameters) :
49 GNEDetector(parent, entryExitTag, 0, "", "", parameters),
50 myPosOverLane(pos),
51 myFriendlyPos(friendlyPos),
52 myMoveElementLaneSingle(new GNEMoveElementLaneSingle(this, SUMO_ATTR_POSITION, myPosOverLane, myFriendlyPos,
53 GNEMoveElementLaneSingle::PositionType::SINGLE)) {
54 // set parents
55 setParent<GNELane*>(lane);
56 // update centering boundary without updating grid
58}
59#ifdef _MSC_VER
60#pragma warning(pop)
61#endif
62
63
67
68
73
74
75void
77 device.openTag(getTagProperty()->getTag());
78 // write common additional attributes
80 // write move attributes
82 // write common detector parameters
83 writeDetectorValues(device);
84 // write parameters
85 XMLHelpers::writeParams(device, *this);
86 device.closeTag();
87}
88
89
90bool
92 // only movement problems
94}
95
96
97std::string
99 // only movement problems
101}
102
103
104void
109
110
111void
113 // update geometry
115 // update centering boundary without updating grid
117}
118
119
120void
122 // first check if additional has to be drawn
125 // Set initial values
126 const double entryExitExaggeration = getExaggeration(s);
127 // get detail level
128 const auto d = s.getDetailLevel(entryExitExaggeration);
129 // draw geometry only if we'rent in drawForObjectUnderCursor mode
131 // draw parent and child lines
133 // Push layer matrix
135 // translate to front
137 // Set color
138 RGBColor color;
139 if (drawUsingSelectColor()) {
141 } else if (myTagProperty->getTag() == SUMO_TAG_DET_ENTRY) {
143 } else if (myTagProperty->getTag() == SUMO_TAG_DET_EXIT) {
145 }
146 // draw parts
147 drawBody(d, color, entryExitExaggeration);
148 drawEntryLogo(d, color, entryExitExaggeration);
149 drawE3Logo(d, color, entryExitExaggeration);
150 // pop layer matrix
152 // draw additional name
154 // draw lock icon
156 entryExitExaggeration);
157 // draw dotted contour
159 }
160 // calculate contour
162 getType(), 2, 0, myAdditionalGeometry.getShapeRotations().front(), entryExitExaggeration,
163 getParentLanes().front()->getParentEdge());
164 }
165}
166
167
168std::string
170 switch (key) {
171 case GNE_ATTR_PARENT:
172 return getParentAdditionals().at(0)->getID();
173 default:
174 return getDetectorAttribute(key);
175 }
176}
177
178
179double
183
184
189
190
191void
192GNEEntryExitDetector::setAttribute(SumoXMLAttr key, const std::string& value, GNEUndoList* undoList) {
193 switch (key) {
194 case GNE_ATTR_PARENT:
195 GNEChange_Attribute::changeAttribute(this, key, value, undoList);
196 break;
197 default:
198 setDetectorAttribute(key, value, undoList);
199 break;
200 }
201}
202
203
204bool
205GNEEntryExitDetector::isValid(SumoXMLAttr key, const std::string& value) {
206 switch (key) {
207 case GNE_ATTR_PARENT:
208 return (myNet->getAttributeCarriers()->retrieveAdditional(SUMO_TAG_ENTRY_EXIT_DETECTOR, value, false) != nullptr);
209 default:
210 return isDetectorValid(key, value);
211 }
212}
213
214
215void
217 const RGBColor& color, const double exaggeration) const {
218 // check detail level
220 // Push polygon matrix
222 // set color
223 GLHelper::setColor(color);
224 // set polygon mode
225 glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
226 // move to position
227 glTranslated(myAdditionalGeometry.getShape().front().x(), myAdditionalGeometry.getShape().front().y(), 0);
228 // rotate over lane
230 // scale
231 glScaled(exaggeration, exaggeration, 1);
232 // check detail level
234 // Draw polygon
235 glBegin(GL_LINES);
236 glVertex2d(1.7, 0);
237 glVertex2d(-1.7, 0);
238 glEnd();
239 glBegin(GL_QUADS);
240 glVertex2d(-1.7, .5);
241 glVertex2d(-1.7, -.5);
242 glVertex2d(1.7, -.5);
243 glVertex2d(1.7, .5);
244 glEnd();
245 // first Arrow
246 glTranslated(1.5, 0, 0);
247 GLHelper::drawBoxLine(Position(0, 4), 0, 2, .05);
248 GLHelper::drawTriangleAtEnd(Position(0, 4), Position(0, 1), (double) 1, (double) .25);
249 // second Arrow
250 glTranslated(-3, 0, 0);
251 GLHelper::drawBoxLine(Position(0, 4), 0, 2, .05);
252 GLHelper::drawTriangleAtEnd(Position(0, 4), Position(0, 1), (double) 1, (double) .25);
253 } else {
254 // Draw square in drawy for selecting mode
255 glBegin(GL_QUADS);
256 glVertex2d(-1.7, 4.3);
257 glVertex2d(-1.7, -.5);
258 glVertex2d(1.7, -.5);
259 glVertex2d(1.7, 4.3);
260 glEnd();
261 }
262 // Pop polygon matrix
264 }
265}
266
267
268void
270 const RGBColor& color, const double exaggeration) const {
271 // check detail level
273 // Push matrix
275 // set color
276 GLHelper::setColor(color);
277 // Translate to center of detector
278 glTranslated(myAdditionalGeometry.getShape().front().x(), myAdditionalGeometry.getShape().front().y(), getType() + 0.1);
279 // rotate over lane
281 //move to logo position
282 glTranslated(1.9, 0, 0);
283 // scale
284 glScaled(exaggeration, exaggeration, 1);
285 //move to logo position
286 glTranslated(1.7, 0, 0);
287 // rotate 90 degrees lane
288 glRotated(90, 0, 0, 1);
289 // draw Entry or Exit text if isn't being drawn for selecting
292 GLHelper::drawText("Entry", Position(), .1, 1, color, 180);
293 } else if (myTagProperty->getTag() == SUMO_TAG_DET_EXIT) {
294 GLHelper::drawText("Exit", Position(), .1, 1, color, 180);
295 }
296 } else {
297 GLHelper::drawBoxLine(Position(0, 1), 0, 2, 1);
298 }
299 // pop matrix
301 }
302}
303
304
305void
307 const RGBColor& color, const double exaggeration) const {
308 // check detail level
310 // Push matrix
312 // set color
313 GLHelper::setColor(color);
314 // Translate to center of detector
315 glTranslated(myAdditionalGeometry.getShape().front().x(), myAdditionalGeometry.getShape().front().y(), getType() + 0.1);
316 // rotate over lane
318 //move to logo position
319 glTranslated(1.9, 0, 0);
320 // scale
321 glScaled(exaggeration, exaggeration, 1);
322 // draw E3 logo
323 GLHelper::drawText("E3", Position(0, 0), .1, 2.8, color);
324 // pop matrix
326 }
327}
328
329
330void
331GNEEntryExitDetector::setAttribute(SumoXMLAttr key, const std::string& value) {
332 switch (key) {
333 case SUMO_ATTR_LANE:
334 // set hier because GNEHierarchicalElement is a template
336 break;
337 case GNE_ATTR_PARENT:
339 break;
340 default:
341 setDetectorAttribute(key, value);
342 break;
343 }
344}
345
346/****************************************************************************/
@ 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
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)
static OutputDevice & writeParams(OutputDevice &device, const Parameterised &params)
write the parameters of the given object as param tags
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