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 // draw dotted contour
164 }
165 // calculate contour
167 myAdditionalGeometry.getShapeRotations().front(), entryExitExaggeration);
168 }
169}
170
171
172std::string
174 switch (key) {
175 case GNE_ATTR_PARENT:
176 return getParentAdditionals().at(0)->getID();
177 default:
178 return getDetectorAttribute(key);
179 }
180}
181
182
183double
185 switch (key) {
187 return myPositionOverLane;
188 default:
189 throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
190 }
191}
192
193
194void
195GNEEntryExitDetector::setAttribute(SumoXMLAttr key, const std::string& value, GNEUndoList* undoList) {
196 switch (key) {
197 case GNE_ATTR_PARENT:
198 GNEChange_Attribute::changeAttribute(this, key, value, undoList);
199 break;
200 default:
201 setDetectorAttribute(key, value, undoList);
202 break;
203 }
204}
205
206
207bool
208GNEEntryExitDetector::isValid(SumoXMLAttr key, const std::string& value) {
209 switch (key) {
210 case GNE_ATTR_PARENT:
211 return (myNet->getAttributeCarriers()->retrieveAdditional(SUMO_TAG_ENTRY_EXIT_DETECTOR, value, false) != nullptr);
212 default:
213 return isDetectorValid(key, value);
214 }
215}
216
217
218void
220 const RGBColor& color, const double exaggeration) const {
221 // check detail level
223 // Push polygon matrix
225 // set color
226 GLHelper::setColor(color);
227 // set polygon mode
228 glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
229 // move to position
230 glTranslated(myAdditionalGeometry.getShape().front().x(), myAdditionalGeometry.getShape().front().y(), 0);
231 // rotate over lane
233 // scale
234 glScaled(exaggeration, exaggeration, 1);
235 // check detail level
237 // Draw polygon
238 glBegin(GL_LINES);
239 glVertex2d(1.7, 0);
240 glVertex2d(-1.7, 0);
241 glEnd();
242 glBegin(GL_QUADS);
243 glVertex2d(-1.7, .5);
244 glVertex2d(-1.7, -.5);
245 glVertex2d(1.7, -.5);
246 glVertex2d(1.7, .5);
247 glEnd();
248 // first Arrow
249 glTranslated(1.5, 0, 0);
250 GLHelper::drawBoxLine(Position(0, 4), 0, 2, .05);
251 GLHelper::drawTriangleAtEnd(Position(0, 4), Position(0, 1), (double) 1, (double) .25);
252 // second Arrow
253 glTranslated(-3, 0, 0);
254 GLHelper::drawBoxLine(Position(0, 4), 0, 2, .05);
255 GLHelper::drawTriangleAtEnd(Position(0, 4), Position(0, 1), (double) 1, (double) .25);
256 } else {
257 // Draw square in drawy for selecting mode
258 glBegin(GL_QUADS);
259 glVertex2d(-1.7, 4.3);
260 glVertex2d(-1.7, -.5);
261 glVertex2d(1.7, -.5);
262 glVertex2d(1.7, 4.3);
263 glEnd();
264 }
265 // Pop polygon matrix
267 }
268}
269
270
271void
273 const RGBColor& color, const double exaggeration) const {
274 // check detail level
276 // Push matrix
278 // set color
279 GLHelper::setColor(color);
280 // Traslate to center of detector
281 glTranslated(myAdditionalGeometry.getShape().front().x(), myAdditionalGeometry.getShape().front().y(), getType() + 0.1);
282 // rotate over lane
284 //move to logo position
285 glTranslated(1.9, 0, 0);
286 // scale
287 glScaled(exaggeration, exaggeration, 1);
288 //move to logo position
289 glTranslated(1.7, 0, 0);
290 // rotate 90 degrees lane
291 glRotated(90, 0, 0, 1);
292 // draw Entry or Exit text if isn't being drawn for selecting
295 GLHelper::drawText("Entry", Position(), .1, 1, color, 180);
296 } else if (myTagProperty.getTag() == SUMO_TAG_DET_EXIT) {
297 GLHelper::drawText("Exit", Position(), .1, 1, color, 180);
298 }
299 } else {
300 GLHelper::drawBoxLine(Position(0, 1), 0, 2, 1);
301 }
302 // pop matrix
304 }
305}
306
307
308void
310 const RGBColor& color, const double exaggeration) const {
311 // check detail level
313 // Push matrix
315 // set color
316 GLHelper::setColor(color);
317 // Traslate to center of detector
318 glTranslated(myAdditionalGeometry.getShape().front().x(), myAdditionalGeometry.getShape().front().y(), getType() + 0.1);
319 // rotate over lane
321 //move to logo position
322 glTranslated(1.9, 0, 0);
323 // scale
324 glScaled(exaggeration, exaggeration, 1);
325 // draw E3 logo
326 GLHelper::drawText("E3", Position(0, 0), .1, 2.8, color);
327 // pop matrix
329 }
330}
331
332
333void
334GNEEntryExitDetector::setAttribute(SumoXMLAttr key, const std::string& value) {
335 switch (key) {
336 case GNE_ATTR_PARENT:
338 break;
339 default:
340 setDetectorAttribute(key, value);
341 break;
342 }
343}
344
345
346void
348 // change position
349 myPositionOverLane = moveResult.newFirstPos;
350 // set lateral offset
352 // update geometry
354}
355
356
357void
359 // reset lateral offset
361 // begin change attribute
362 undoList->begin(this, "position of " + getTagStr());
363 // set startPosition
364 setAttribute(SUMO_ATTR_POSITION, toString(moveResult.newFirstPos), undoList);
365 // check if lane has to be changed
366 if (moveResult.newFirstLane) {
367 // set new lane
368 setAttribute(SUMO_ATTR_LANE, moveResult.newFirstLane->getID(), undoList);
369 }
370 // end change attribute
371 undoList->end();
372}
373
374/****************************************************************************/
@ 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:654
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:629
static void popMatrix()
pop matrix
Definition GLHelper.cpp:130
static void drawBoxLine(const Position &beg, double rot, double visLength, double width, double offset=0)
Draws a thick line.
Definition GLHelper.cpp:295
static void pushMatrix()
push matrix
Definition GLHelper.cpp:117
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:756
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.
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
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
calculate contour (for rectangled elements)
void 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...)
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:2155
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
void drawTranslateFrontAttributeCarrier(const GNEAttributeCarrier *AC, double typeOrLayer, const double extraOffset=0)
draw front attributeCarrier
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