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-2023 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
69
70
71bool
73 // with friendly position enabled position are "always fixed"
75 return true;
76 } else {
77 return fabs(myPositionOverLane) <= getParentLanes().front()->getParentEdge()->getNBEdge()->getFinalLength();
78 }
79}
80
81
82std::string
84 // obtain final length
85 const double len = getParentLanes().front()->getParentEdge()->getNBEdge()->getFinalLength();
86 // check if detector has a problem
88 return "";
89 } else {
90 // declare variable for error position
91 std::string errorPosition;
92 // check positions over lane
93 if (myPositionOverLane < 0) {
94 errorPosition = (toString(SUMO_ATTR_POSITION) + " < 0");
95 }
96 if (myPositionOverLane > len) {
97 errorPosition = (toString(SUMO_ATTR_POSITION) + TL(" > lanes's length"));
98 }
99 return errorPosition;
100 }
101}
102
103
104void
106 // declare new position
107 double newPositionOverLane = myPositionOverLane;
108 // fix pos and length checkAndFixDetectorPosition
109 double length = 0;
110 GNEAdditionalHandler::fixLanePosition(newPositionOverLane, length, getParentLanes().front()->getParentEdge()->getNBEdge()->getFinalLength());
111 // set new position
113}
114
115
116void
118 // update geometry
120 // update centering boundary without updating grid
122}
123
124
125void
127 // Set initial values
128 const double entryExitExaggeration = getExaggeration(s);
129 // first check if additional has to be drawn
130 if (s.drawAdditionals(entryExitExaggeration) && myNet->getViewNet()->getDataViewOptions().showAdditionals() &&
132 // draw parent and child lines
134 // Start drawing adding gl identificator
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 // avoid draw invisible elements
150 if (color.alpha() != 0) {
151 GLHelper::setColor(color);
152 glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
153 // Push polygon matrix
155 glTranslated(myAdditionalGeometry.getShape().front().x(), myAdditionalGeometry.getShape().front().y(), 0);
156 // rotate over lane
158 // scale
159 glScaled(entryExitExaggeration, entryExitExaggeration, 1);
160 // draw details if isn't being drawn for selecting
162 // Draw polygon
163 glBegin(GL_LINES);
164 glVertex2d(1.7, 0);
165 glVertex2d(-1.7, 0);
166 glEnd();
167 glBegin(GL_QUADS);
168 glVertex2d(-1.7, .5);
169 glVertex2d(-1.7, -.5);
170 glVertex2d(1.7, -.5);
171 glVertex2d(1.7, .5);
172 glEnd();
173 // first Arrow
174 glTranslated(1.5, 0, 0);
175 GLHelper::drawBoxLine(Position(0, 4), 0, 2, .05);
176 GLHelper::drawTriangleAtEnd(Position(0, 4), Position(0, 1), (double) 1, (double) .25);
177 // second Arrow
178 glTranslated(-3, 0, 0);
179 GLHelper::drawBoxLine(Position(0, 4), 0, 2, .05);
180 GLHelper::drawTriangleAtEnd(Position(0, 4), Position(0, 1), (double) 1, (double) .25);
181 } else {
182 // Draw square in drawy for selecting mode
183 glBegin(GL_QUADS);
184 glVertex2d(-1.7, 4.3);
185 glVertex2d(-1.7, -.5);
186 glVertex2d(1.7, -.5);
187 glVertex2d(1.7, 4.3);
188 glEnd();
189 }
190 // Pop polygon matrix
192 // Check if the distance is enought to draw details
193 if (!s.drawForRectangleSelection && s.drawDetail(s.detailSettings.detectorDetails, entryExitExaggeration)) {
194 // Push matrix
196 // Traslate to center of detector
197 glTranslated(myAdditionalGeometry.getShape().front().x(), myAdditionalGeometry.getShape().front().y(), getType() + 0.1);
198 // rotate over lane
200 //move to logo position
201 glTranslated(1.9, 0, 0);
202 // scale
203 glScaled(entryExitExaggeration, entryExitExaggeration, 1);
204 // draw Entry or Exit logo if isn't being drawn for selecting
207 GLHelper::drawBoxLine(Position(0, 1), 0, 2, 1);
208 }
209 //move to logo position
210 glTranslated(1.7, 0, 0);
211 // rotate 90 degrees lane
212 glRotated(90, 0, 0, 1);
213 // draw Entry or Exit text if isn't being drawn for selecting
216 GLHelper::drawBoxLine(Position(0, 1), 0, 2, 1);
217 } else if (drawUsingSelectColor()) {
220 } else if (myTagProperty.getTag() == SUMO_TAG_DET_EXIT) {
222 }
223 } else {
225 GLHelper::drawText("Entry", Position(), .1, 1, s.detectorSettings.E3EntryColor, 180);
226 } else if (myTagProperty.getTag() == SUMO_TAG_DET_EXIT) {
228 }
229 }
230 // pop matrix
232 // check if draw E3
234 // Push matrix
236 // Traslate to center of detector
237 glTranslated(myAdditionalGeometry.getShape().front().x(), myAdditionalGeometry.getShape().front().y(), getType() + 0.1);
238 // rotate over lane
240 //move to logo position
241 glTranslated(1.9, 0, 0);
242 // scale
243 glScaled(entryExitExaggeration, entryExitExaggeration, 1);
244 // draw depending of color
245 if (drawUsingSelectColor()) {
247 } else if (myTagProperty.getTag() == SUMO_TAG_DET_ENTRY) {
249 } else if (myTagProperty.getTag() == SUMO_TAG_DET_EXIT) {
251 }
252 // pop matrix
254 }
255 }
256 // Pop layer matrix
258 // draw lock icon
260 }
261 // check if mouse is over element
262 mouseWithinGeometry(myAdditionalGeometry.getShape().front(), 2.7, 1.6, 2, 0,
264 // inspect contour
267 2.7, 1.6, 2, 0, myAdditionalGeometry.getShapeRotations().front(), entryExitExaggeration);
268 }
269 // front contour
270 if (myNet->getViewNet()->getFrontAttributeCarrier() == this) {
272 2.7, 1.6, 2, 0, myAdditionalGeometry.getShapeRotations().front(), entryExitExaggeration);
273 }
274 // delete contour
275 if (myNet->getViewNet()->drawDeleteContour(this, this)) {
277 2.7, 1.6, 2, 0, myAdditionalGeometry.getShapeRotations().front(), entryExitExaggeration);
278 }
279 // pop gl identificator
281 // draw additional name
283 }
284}
285
286
287std::string
289 switch (key) {
290 case SUMO_ATTR_ID:
291 return getParentAdditionals().front()->getID();
292 case SUMO_ATTR_LANE:
293 return getParentLanes().front()->getID();
298 case GNE_ATTR_PARENT:
299 return getParentAdditionals().at(0)->getID();
303 return getParametersStr();
305 return "";
306 default:
307 throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
308 }
309}
310
311
312double
314 switch (key) {
316 return myPositionOverLane;
317 default:
318 throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
319 }
320}
321
322
323void
324GNEEntryExitDetector::setAttribute(SumoXMLAttr key, const std::string& value, GNEUndoList* undoList) {
325 switch (key) {
326 case SUMO_ATTR_LANE:
329 case GNE_ATTR_PARENT:
333 undoList->changeAttribute(new GNEChange_Attribute(this, key, value));
334 break;
335 default:
336 throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
337 }
338}
339
340
341bool
342GNEEntryExitDetector::isValid(SumoXMLAttr key, const std::string& value) {
343 switch (key) {
344 case SUMO_ATTR_LANE:
345 return (myNet->getAttributeCarriers()->retrieveLane(value, false) != nullptr);
347 return canParse<double>(value) && fabs(parse<double>(value)) < getParentLanes().front()->getParentEdge()->getNBEdge()->getFinalLength();
349 return canParse<bool>(value);
350 case GNE_ATTR_PARENT:
351 return (myNet->getAttributeCarriers()->retrieveAdditional(SUMO_TAG_ENTRY_EXIT_DETECTOR, value, false) != nullptr);
353 return canParse<bool>(value);
355 return areParametersValid(value);
356 default:
357 throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
358 }
359}
360
361
362void
363GNEEntryExitDetector::setAttribute(SumoXMLAttr key, const std::string& value) {
364 switch (key) {
365 case SUMO_ATTR_LANE:
367 break;
369 myPositionOverLane = parse<double>(value);
370 break;
372 myFriendlyPosition = parse<bool>(value);
373 break;
374 case GNE_ATTR_PARENT:
376 break;
378 if (parse<bool>(value)) {
380 } else {
382 }
383 break;
385 setParametersStr(value);
386 break;
389 break;
390 default:
391 throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
392 }
393}
394
395
396void
398 // change position
399 myPositionOverLane = moveResult.newFirstPos;
400 // set lateral offset
402 // update geometry
404}
405
406
407void
409 // reset lateral offset
411 // begin change attribute
412 undoList->begin(myTagProperty.getGUIIcon(), "position of " + getTagStr());
413 // set startPosition
414 setAttribute(SUMO_ATTR_POSITION, toString(moveResult.newFirstPos), undoList);
415 // check if lane has to be changed
416 if (moveResult.newFirstLane) {
417 // set new lane
418 setAttribute(SUMO_ATTR_LANE, moveResult.newFirstLane->getID(), undoList);
419 }
420 // end change attribute
421 undoList->end();
422}
423
424/****************************************************************************/
@ 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:287
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
@ GNE_ATTR_SELECTED
element is selected
@ GNE_ATTR_PARAMETERS
parameters "key1=value1|key2=value2|...|keyN=valueN"
@ SUMO_ATTR_FRIENDLY_POS
@ SUMO_ATTR_ID
@ SUMO_ATTR_POSITION
@ GNE_ATTR_SHIFTLANEINDEX
shift lane index (only used by elements over lanes)
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:583
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:558
static void pushName(unsigned int name)
push Name
Definition GLHelper.cpp:139
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:277
static void popName()
pop Name
Definition GLHelper.cpp:148
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:685
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
GUIGeometry myAdditionalGeometry
geometry to be precomputed in updateGeometry(...)
void replaceAdditionalParentLanes(const std::string &value)
replace additional parent lanes
void shiftLaneIndex()
shift lane index
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
void unselectAttributeCarrier(const bool changeFlag=true)
unselect attribute carrier using GUIGlobalSelection
bool drawUsingSelectColor() const
check if attribute carrier must be drawn using selecting color.
GNENet * myNet
pointer to net
void selectAttributeCarrier(const bool changeFlag=true)
select attribute carrier using GUIGlobalSelection
const GNETagProperties & myTagProperty
reference to tagProperty associated with this attribute carrier
the function-object for an editing operation (abstract base)
double myPositionOverLane
position of detector over Lane
double getGeometryPositionOverLane() const
get position over lane that is applicable to the shape
bool myFriendlyPosition
Flag for friendly position.
void updateCenteringBoundary(const bool updateGrid)
update centering boundary (implies change in RTREE)
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 writed into XML
void fixAdditionalProblem()
fix additional problem
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
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
GNELane * retrieveLane(const std::string &id, bool hardFail=true, bool checkVolatileChange=false) const
get lane by id
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:120
GNEViewNet * getViewNet() const
get view net
Definition GNENet.cpp:2030
GUIIcon getGUIIcon() const
get GUI icon associated to this Tag
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...
void changeAttribute(GNEChange_Attribute *change)
special method for change attributes, avoid empty changes, always execute
const GNEViewNetHelper::DataViewOptions & getDataViewOptions() const
get data view options
const GNEAttributeCarrier * getFrontAttributeCarrier() const
get front attributeCarrier
bool drawDeleteContour(const GUIGlObject *GLObject, const GNEAttributeCarrier *AC) const
check if draw delete contour
void drawTranslateFrontAttributeCarrier(const GNEAttributeCarrier *AC, double typeOrLayer, const double extraOffset=0)
draw front attributeCarrier
GNEUndoList * getUndoList() const
get the undoList object
bool isAttributeCarrierInspected(const GNEAttributeCarrier *AC) const
check if attribute carrier is being inspected
bool selectingDetectorsTLSMode() const
check if we're selecting detectors in TLS mode
static void drawDottedSquaredShape(const GUIVisualizationSettings &s, const DottedContourType type, const Position &pos, const double width, const double height, const double offsetX, const double offsetY, const double rot, const double exaggeration)
draw dotted squared contour (used by additionals and demand elements)
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.
bool mouseWithinGeometry(const Position center, const double radius) const
check if mouse is within elements geometry (for circles)
GUIGlID getGlID() const
Returns the numerical id of the object.
Stores the information about how to visualize structures.
bool drawForRectangleSelection
whether drawing is performed for the purpose of selecting objects using a rectangle
GUIVisualizationDetailSettings detailSettings
detail settings
bool drawForPositionSelection
whether drawing is performed for the purpose of selecting objects with a single click
bool drawAdditionals(const double exaggeration) const
check if additionals must be drawn
GUIVisualizationColorSettings colorSettings
color settings
bool drawDetail(const double detail, const double exaggeration) const
check if details can be drawn for the given GUIVisualizationDetailSettings and current scale and exxa...
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.
static bool areParametersValid(const std::string &value, bool report=false, const std::string kvsep="=", const std::string sep="|")
check if given string can be parsed to a parameters map "key1=value1|key2=value2|....
std::map< std::string, std::string > Map
parameters map
void setParametersStr(const std::string &paramsString, const std::string kvsep="=", const std::string sep="|")
set the inner key/value map in string format "key1=value1|key2=value2|...|keyN=valueN"
std::string getParametersStr(const std::string kvsep="=", const std::string sep="|") const
Returns the inner key/value map in string format "key1=value1|key2=value2|...|keyN=valueN".
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)
unsigned char alpha() const
Returns the alpha-amount of the color.
Definition RGBColor.cpp:92
bool showAdditionals() const
check if additionals has to be drawn
static void drawLockIcon(const GNEAttributeCarrier *AC, GUIGlObjectType type, const Position viewPosition, 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 double detectorDetails
details for detectors
static const RGBColor E3ExitColor
color for Exits
static const RGBColor E3EntryColor
color for Entrys