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-2024 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
21#include <netedit/GNENet.h>
22#include <netedit/GNEUndoList.h>
23#include <netedit/GNEViewNet.h>
30
33
34
35// ===========================================================================
36// member method definitions
37// ===========================================================================
38
40 GNEDetector("", net, GLO_DET_ENTRY, entryExitTag, GUIIconSubSys::getIcon(GUIIcon::E3ENTRY), 0, 0, {}, "", {}, {}, "", "", false, Parameterised::Map()) {
41 // reset default values
42 resetDefaultValues();
43}
44
45
46GNEEntryExitDetector::GNEEntryExitDetector(SumoXMLTag entryExitTag, GNENet* net, GNEAdditional* parent, GNELane* lane, const double pos,
47 const bool friendlyPos, const Parameterised::Map& parameters) :
48 GNEDetector(parent, net, GLO_DET_ENTRY, entryExitTag, GUIIconSubSys::getIcon(GUIIcon::E3ENTRY), pos, 0, {
49 lane
50}, "", "", friendlyPos, parameters) {
51 // update centering boundary without updating grid
52 updateCenteringBoundary(false);
53}
54
55
57
58
59void
61 device.openTag(getTagProperty().getTag());
62 device.writeAttr(SUMO_ATTR_LANE, getParentLanes().front()->getID());
64 // write common detector parameters
65 writeDetectorValues(device);
66 // write parameters
67 writeParams(device);
68 device.closeTag();
69}
70
71
72bool
74 // with friendly position enabled position are "always fixed"
76 return true;
77 } else {
78 return fabs(myPositionOverLane) <= getParentLanes().front()->getParentEdge()->getNBEdge()->getFinalLength();
79 }
80}
81
82
83std::string
85 // obtain final length
86 const double len = getParentLanes().front()->getParentEdge()->getNBEdge()->getFinalLength();
87 // check if detector has a problem
89 return "";
90 } else {
91 // declare variable for error position
92 std::string errorPosition;
93 // check positions over lane
94 if (myPositionOverLane < 0) {
95 errorPosition = (toString(SUMO_ATTR_POSITION) + " < 0");
96 }
97 if (myPositionOverLane > len) {
98 errorPosition = (toString(SUMO_ATTR_POSITION) + TL(" > lanes's length"));
99 }
100 return errorPosition;
101 }
102}
103
104
105void
107 // declare new position
108 double newPositionOverLane = myPositionOverLane;
109 // fix pos and length checkAndFixDetectorPosition
110 double length = 0;
111 GNEAdditionalHandler::fixLanePosition(newPositionOverLane, length, getParentLanes().front()->getParentEdge()->getNBEdge()->getFinalLength());
112 // set new position
114}
115
116
117void
119 // update geometry
121 // update centering boundary without updating grid
123}
124
125
126void
128 // first check if additional has to be drawn
131 // Set initial values
132 const double entryExitExaggeration = getExaggeration(s);
133 // get detail level
134 const auto d = s.getDetailLevel(entryExitExaggeration);
135 // draw geometry only if we'rent in drawForObjectUnderCursor mode
137 // draw parent and child lines
139 // Push layer matrix
141 // translate to front
143 // Set color
144 RGBColor color;
145 if (drawUsingSelectColor()) {
147 } else if (myTagProperty.getTag() == SUMO_TAG_DET_ENTRY) {
149 } else if (myTagProperty.getTag() == SUMO_TAG_DET_EXIT) {
151 }
152 // draw parts
153 drawBody(d, color, entryExitExaggeration);
154 drawEntryLogo(d, color, entryExitExaggeration);
155 drawE3Logo(d, color, entryExitExaggeration);
156 // pop layer matrix
158 // draw additional name
160 // draw lock icon
162 entryExitExaggeration);
163 // draw dotted contour
165 }
166 // calculate contour
168 getType(), 2, 0, myAdditionalGeometry.getShapeRotations().front(), entryExitExaggeration,
169 getParentLanes().front()->getParentEdge());
170 }
171}
172
173
174std::string
176 switch (key) {
177 case GNE_ATTR_PARENT:
178 return getParentAdditionals().at(0)->getID();
179 default:
180 return getDetectorAttribute(key);
181 }
182}
183
184
185double
187 switch (key) {
189 return myPositionOverLane;
190 default:
191 throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
192 }
193}
194
195
196void
197GNEEntryExitDetector::setAttribute(SumoXMLAttr key, const std::string& value, GNEUndoList* undoList) {
198 switch (key) {
199 case GNE_ATTR_PARENT:
200 GNEChange_Attribute::changeAttribute(this, key, value, undoList);
201 break;
202 default:
203 setDetectorAttribute(key, value, undoList);
204 break;
205 }
206}
207
208
209bool
210GNEEntryExitDetector::isValid(SumoXMLAttr key, const std::string& value) {
211 switch (key) {
212 case GNE_ATTR_PARENT:
213 return (myNet->getAttributeCarriers()->retrieveAdditional(SUMO_TAG_ENTRY_EXIT_DETECTOR, value, false) != nullptr);
214 default:
215 return isDetectorValid(key, value);
216 }
217}
218
219
220void
222 const RGBColor& color, const double exaggeration) const {
223 // check detail level
225 // Push polygon matrix
227 // set color
228 GLHelper::setColor(color);
229 // set polygon mode
230 glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
231 // move to position
232 glTranslated(myAdditionalGeometry.getShape().front().x(), myAdditionalGeometry.getShape().front().y(), 0);
233 // rotate over lane
235 // scale
236 glScaled(exaggeration, exaggeration, 1);
237 // check detail level
239 // Draw polygon
240 glBegin(GL_LINES);
241 glVertex2d(1.7, 0);
242 glVertex2d(-1.7, 0);
243 glEnd();
244 glBegin(GL_QUADS);
245 glVertex2d(-1.7, .5);
246 glVertex2d(-1.7, -.5);
247 glVertex2d(1.7, -.5);
248 glVertex2d(1.7, .5);
249 glEnd();
250 // first Arrow
251 glTranslated(1.5, 0, 0);
252 GLHelper::drawBoxLine(Position(0, 4), 0, 2, .05);
253 GLHelper::drawTriangleAtEnd(Position(0, 4), Position(0, 1), (double) 1, (double) .25);
254 // second Arrow
255 glTranslated(-3, 0, 0);
256 GLHelper::drawBoxLine(Position(0, 4), 0, 2, .05);
257 GLHelper::drawTriangleAtEnd(Position(0, 4), Position(0, 1), (double) 1, (double) .25);
258 } else {
259 // Draw square in drawy for selecting mode
260 glBegin(GL_QUADS);
261 glVertex2d(-1.7, 4.3);
262 glVertex2d(-1.7, -.5);
263 glVertex2d(1.7, -.5);
264 glVertex2d(1.7, 4.3);
265 glEnd();
266 }
267 // Pop polygon matrix
269 }
270}
271
272
273void
275 const RGBColor& color, const double exaggeration) const {
276 // check detail level
278 // Push matrix
280 // set color
281 GLHelper::setColor(color);
282 // Traslate to center of detector
283 glTranslated(myAdditionalGeometry.getShape().front().x(), myAdditionalGeometry.getShape().front().y(), getType() + 0.1);
284 // rotate over lane
286 //move to logo position
287 glTranslated(1.9, 0, 0);
288 // scale
289 glScaled(exaggeration, exaggeration, 1);
290 //move to logo position
291 glTranslated(1.7, 0, 0);
292 // rotate 90 degrees lane
293 glRotated(90, 0, 0, 1);
294 // draw Entry or Exit text if isn't being drawn for selecting
297 GLHelper::drawText("Entry", Position(), .1, 1, color, 180);
298 } else if (myTagProperty.getTag() == SUMO_TAG_DET_EXIT) {
299 GLHelper::drawText("Exit", Position(), .1, 1, color, 180);
300 }
301 } else {
302 GLHelper::drawBoxLine(Position(0, 1), 0, 2, 1);
303 }
304 // pop matrix
306 }
307}
308
309
310void
312 const RGBColor& color, const double exaggeration) const {
313 // check detail level
315 // Push matrix
317 // set color
318 GLHelper::setColor(color);
319 // Traslate to center of detector
320 glTranslated(myAdditionalGeometry.getShape().front().x(), myAdditionalGeometry.getShape().front().y(), getType() + 0.1);
321 // rotate over lane
323 //move to logo position
324 glTranslated(1.9, 0, 0);
325 // scale
326 glScaled(exaggeration, exaggeration, 1);
327 // draw E3 logo
328 GLHelper::drawText("E3", Position(0, 0), .1, 2.8, color);
329 // pop matrix
331 }
332}
333
334
335void
336GNEEntryExitDetector::setAttribute(SumoXMLAttr key, const std::string& value) {
337 switch (key) {
338 case GNE_ATTR_PARENT:
340 break;
341 default:
342 setDetectorAttribute(key, value);
343 break;
344 }
345}
346
347
348void
350 // change position
351 myPositionOverLane = moveResult.newFirstPos;
352 // set lateral offset
354 // update geometry
356}
357
358
359void
361 // reset lateral offset
363 // begin change attribute
364 undoList->begin(this, "position of " + getTagStr());
365 // set startPosition
366 setAttribute(SUMO_ATTR_POSITION, toString(moveResult.newFirstPos), undoList);
367 // check if lane has to be changed
368 if (moveResult.newFirstLane) {
369 // set new lane
370 setAttribute(SUMO_ATTR_LANE, moveResult.newFirstLane->getID(), undoList);
371 }
372 // end change attribute
373 undoList->end();
374}
375
376/****************************************************************************/
@ GLO_DET_ENTRY
a DetEntry detector
GUIIcon
An enumeration of icons used by the gui applications.
Definition GUIIcons.h:33
#define TL(string)
Definition MsgHandler.h:315
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: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:751
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
An Element which don't belong to GNENet but has influence in the simulation.
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
const GNETagProperties & getTagProperty() const
get tagProperty associated with this Attribute Carrier
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
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 std::vector< GNEAdditional * > & getParentAdditionals() const
get parent additionals
const std::vector< 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:127
GNEViewNet * getViewNet() const
get view net
Definition GNENet.cpp:2163
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