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
22#include <netedit/GNENet.h>
24#include <netedit/GNEUndoList.h>
25#include <netedit/GNEViewNet.h>
32
35
36// ===========================================================================
37// member method definitions
38// ===========================================================================
39
41 GNEDetector(net, entryExitTag) {
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, pos, 0, lane, "", "", friendlyPos, parameters) {
48 // update centering boundary without updating grid
50}
51
52
54
55
56void
58 device.openTag(getTagProperty()->getTag());
59 device.writeAttr(SUMO_ATTR_LANE, getParentLanes().front()->getID());
61 // write common detector parameters
62 writeDetectorValues(device);
63 // write parameters
64 writeParams(device);
65 device.closeTag();
66}
67
68
69bool
71 // with friendly position enabled position are "always fixed"
73 return true;
74 } else {
75 return fabs(myPositionOverLane) <= getParentLanes().front()->getParentEdge()->getNBEdge()->getFinalLength();
76 }
77}
78
79
80std::string
82 // obtain final length
83 const double len = getParentLanes().front()->getParentEdge()->getNBEdge()->getFinalLength();
84 // check if detector has a problem
86 return "";
87 } else {
88 // declare variable for error position
89 std::string errorPosition;
90 // check positions over lane
91 if (myPositionOverLane < 0) {
92 errorPosition = (toString(SUMO_ATTR_POSITION) + " < 0");
93 }
94 if (myPositionOverLane > len) {
95 errorPosition = (toString(SUMO_ATTR_POSITION) + TL(" > lanes's length"));
96 }
97 return errorPosition;
98 }
99}
100
101
102void
104 // declare new position
105 double newPositionOverLane = myPositionOverLane;
106 // fix pos and length checkAndFixDetectorPosition
107 double length = 0;
108 GNEAdditionalHandler::fixLanePosition(newPositionOverLane, length, getParentLanes().front()->getParentEdge()->getNBEdge()->getFinalLength());
109 // set new position
111}
112
113
114void
116 // update geometry
118 // update centering boundary without updating grid
120}
121
122
123void
125 // first check if additional has to be drawn
128 // Set initial values
129 const double entryExitExaggeration = getExaggeration(s);
130 // get detail level
131 const auto d = s.getDetailLevel(entryExitExaggeration);
132 // draw geometry only if we'rent in drawForObjectUnderCursor mode
134 // draw parent and child lines
136 // Push layer matrix
138 // translate to front
140 // Set color
141 RGBColor color;
142 if (drawUsingSelectColor()) {
144 } else if (myTagProperty->getTag() == SUMO_TAG_DET_ENTRY) {
146 } else if (myTagProperty->getTag() == SUMO_TAG_DET_EXIT) {
148 }
149 // draw parts
150 drawBody(d, color, entryExitExaggeration);
151 drawEntryLogo(d, color, entryExitExaggeration);
152 drawE3Logo(d, color, entryExitExaggeration);
153 // pop layer matrix
155 // draw additional name
157 // draw lock icon
159 entryExitExaggeration);
160 // draw dotted contour
162 }
163 // calculate contour
165 getType(), 2, 0, myAdditionalGeometry.getShapeRotations().front(), entryExitExaggeration,
166 getParentLanes().front()->getParentEdge());
167 }
168}
169
170
171std::string
173 switch (key) {
174 case GNE_ATTR_PARENT:
175 return getParentAdditionals().at(0)->getID();
176 default:
177 return getDetectorAttribute(key);
178 }
179}
180
181
182double
184 switch (key) {
186 return myPositionOverLane;
187 default:
188 throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
189 }
190}
191
192
193void
194GNEEntryExitDetector::setAttribute(SumoXMLAttr key, const std::string& value, GNEUndoList* undoList) {
195 switch (key) {
196 case GNE_ATTR_PARENT:
197 GNEChange_Attribute::changeAttribute(this, key, value, undoList);
198 break;
199 default:
200 setDetectorAttribute(key, value, undoList);
201 break;
202 }
203}
204
205
206bool
207GNEEntryExitDetector::isValid(SumoXMLAttr key, const std::string& value) {
208 switch (key) {
209 case GNE_ATTR_PARENT:
210 return (myNet->getAttributeCarriers()->retrieveAdditional(SUMO_TAG_ENTRY_EXIT_DETECTOR, value, false) != nullptr);
211 default:
212 return isDetectorValid(key, value);
213 }
214}
215
216
217void
219 const RGBColor& color, const double exaggeration) const {
220 // check detail level
222 // Push polygon matrix
224 // set color
225 GLHelper::setColor(color);
226 // set polygon mode
227 glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
228 // move to position
229 glTranslated(myAdditionalGeometry.getShape().front().x(), myAdditionalGeometry.getShape().front().y(), 0);
230 // rotate over lane
232 // scale
233 glScaled(exaggeration, exaggeration, 1);
234 // check detail level
236 // Draw polygon
237 glBegin(GL_LINES);
238 glVertex2d(1.7, 0);
239 glVertex2d(-1.7, 0);
240 glEnd();
241 glBegin(GL_QUADS);
242 glVertex2d(-1.7, .5);
243 glVertex2d(-1.7, -.5);
244 glVertex2d(1.7, -.5);
245 glVertex2d(1.7, .5);
246 glEnd();
247 // first Arrow
248 glTranslated(1.5, 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 // second Arrow
252 glTranslated(-3, 0, 0);
253 GLHelper::drawBoxLine(Position(0, 4), 0, 2, .05);
254 GLHelper::drawTriangleAtEnd(Position(0, 4), Position(0, 1), (double) 1, (double) .25);
255 } else {
256 // Draw square in drawy for selecting mode
257 glBegin(GL_QUADS);
258 glVertex2d(-1.7, 4.3);
259 glVertex2d(-1.7, -.5);
260 glVertex2d(1.7, -.5);
261 glVertex2d(1.7, 4.3);
262 glEnd();
263 }
264 // Pop polygon matrix
266 }
267}
268
269
270void
272 const RGBColor& color, const double exaggeration) const {
273 // check detail level
275 // Push matrix
277 // set color
278 GLHelper::setColor(color);
279 // Traslate to center of detector
280 glTranslated(myAdditionalGeometry.getShape().front().x(), myAdditionalGeometry.getShape().front().y(), getType() + 0.1);
281 // rotate over lane
283 //move to logo position
284 glTranslated(1.9, 0, 0);
285 // scale
286 glScaled(exaggeration, exaggeration, 1);
287 //move to logo position
288 glTranslated(1.7, 0, 0);
289 // rotate 90 degrees lane
290 glRotated(90, 0, 0, 1);
291 // draw Entry or Exit text if isn't being drawn for selecting
294 GLHelper::drawText("Entry", Position(), .1, 1, color, 180);
295 } else if (myTagProperty->getTag() == SUMO_TAG_DET_EXIT) {
296 GLHelper::drawText("Exit", Position(), .1, 1, color, 180);
297 }
298 } else {
299 GLHelper::drawBoxLine(Position(0, 1), 0, 2, 1);
300 }
301 // pop matrix
303 }
304}
305
306
307void
309 const RGBColor& color, const double exaggeration) const {
310 // check detail level
312 // Push matrix
314 // set color
315 GLHelper::setColor(color);
316 // Traslate to center of detector
317 glTranslated(myAdditionalGeometry.getShape().front().x(), myAdditionalGeometry.getShape().front().y(), getType() + 0.1);
318 // rotate over lane
320 //move to logo position
321 glTranslated(1.9, 0, 0);
322 // scale
323 glScaled(exaggeration, exaggeration, 1);
324 // draw E3 logo
325 GLHelper::drawText("E3", Position(0, 0), .1, 2.8, color);
326 // pop matrix
328 }
329}
330
331
332void
333GNEEntryExitDetector::setAttribute(SumoXMLAttr key, const std::string& value) {
334 switch (key) {
335 case GNE_ATTR_PARENT:
337 break;
338 default:
339 setDetectorAttribute(key, value);
340 break;
341 }
342}
343
344
345void
347 // change position
348 myPositionOverLane = moveResult.newFirstPos;
349 // set lateral offset
351 // update geometry
353}
354
355
356void
358 // reset lateral offset
360 // begin change attribute
361 undoList->begin(this, "position of " + getTagStr());
362 // set startPosition
363 setAttribute(SUMO_ATTR_POSITION, toString(moveResult.newFirstPos), undoList);
364 // check if lane has to be changed
365 if (moveResult.newFirstLane) {
366 // set new lane
367 setAttribute(SUMO_ATTR_LANE, moveResult.newFirstLane->getID(), undoList);
368 }
369 // end change attribute
370 undoList->end();
371}
372
373/****************************************************************************/
@ GLO_DET_ENTRY
a DetEntry detector
#define TL(string)
Definition MsgHandler.h:305
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
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
Definition ToString.h:46
static void setColor(const RGBColor &c)
Sets the gl-color to this value.
Definition GLHelper.cpp:653
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:628
static void popMatrix()
pop matrix
Definition GLHelper.cpp:135
static void drawBoxLine(const Position &beg, double rot, double visLength, double width, double offset=0)
Draws a thick line.
Definition GLHelper.cpp:300
static void pushMatrix()
push matrix
Definition GLHelper.cpp:122
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:747
static bool checkLanePosition(double pos, const double length, const double laneLength, const bool friendlyPos)
check if the given position over a lane is valid
static void fixLanePosition(double &pos, double &length, const double laneLength)
fix given position over lane
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(...)
double getExaggeration(const GUIVisualizationSettings &s) const
return exaggeration associated with this GLObject
void drawAdditionalName(const GUIVisualizationSettings &s) const
draw additional name
void drawParentChildLines(const GUIVisualizationSettings &s, const RGBColor &color, const bool onlySymbols=false) const
draw parent and child lines
const std::string getID() const
get ID (all Attribute Carriers have one)
bool isAttributeCarrierSelected() const
check if attribute carrier is selected
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.
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)
double myPositionOverLane
position of detector over Lane
bool isDetectorValid(SumoXMLAttr key, const std::string &value)
double getGeometryPositionOverLane() const
get position over lane that is applicable to the shape
void setDetectorAttribute(SumoXMLAttr key, const std::string &value, GNEUndoList *undoList)
void writeDetectorValues(OutputDevice &device) const
write additional element into a xml file
bool myFriendlyPosition
Flag for friendly position.
void updateCenteringBoundary(const bool updateGrid)
update centering boundary (implies change in RTREE)
std::string getDetectorAttribute(SumoXMLAttr key) const
double getAttributeDouble(SumoXMLAttr key) const
void setAttribute(SumoXMLAttr key, const std::string &value, GNEUndoList *undoList)
method for setting the attribute and letting the object perform additional changes
void setMoveShape(const GNEMoveResult &moveResult)
set move shape
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
void drawBody(const GUIVisualizationSettings::Detail d, const RGBColor &color, const double exaggeration) const
draw body
void drawGL(const GUIVisualizationSettings &s) const
Draws the object.
void commitMoveShape(const GNEMoveResult &moveResult, GNEUndoList *undoList)
commit move shape
void updateGeometry()
update pre-computed geometry information
~GNEEntryExitDetector()
destructor
bool isValid(SumoXMLAttr key, const std::string &value)
method for checking if the key and their correspondent attribute are valids
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
std::string getAttribute(SumoXMLAttr key) const
const GNEHierarchicalContainerParents< GNEAdditional * > & getParentAdditionals() const
get parent additionals
const GNEHierarchicalContainerParents< GNELane * > & getParentLanes() const
get parent lanes
This lane is powered by an underlying GNEEdge and basically knows how to draw itself.
Definition GNELane.h:46
double myMoveElementLateralOffset
move element lateral offset (used by elements placed over lanes
move result
const GNELane * newFirstLane
new first Lane
double newFirstPos
new first position
double firstLaneOffset
lane offset
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:147
GNEViewNet * getViewNet() const
get view net
Definition GNENet.cpp:2195
SumoXMLTag getTag() const
get Tag vinculated with this attribute Property
void end()
End undo command sub-group. If the sub-group is still empty, it will be deleted; otherwise,...
void begin(GUIIcon icon, const std::string &description)
Begin undo command sub-group with current supermode. This begins a new group of commands that are tre...
const GNEViewNetHelper::DataViewOptions & getDataViewOptions() const
get data view options
GNEUndoList * getUndoList() const
get the undoList object
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 & writeAttr(const SumoXMLAttr attr, const T &val)
writes a named attribute
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