Eclipse SUMO - Simulation of Urban MObility
Loading...
Searching...
No Matches
GNEMultiEntryExitDetector.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// multi entry-exit (E3) detector
19/****************************************************************************/
20
23#include <netedit/GNENet.h>
25
27
28// ===========================================================================
29// member method definitions
30// ===========================================================================
31
36
37
38GNEMultiEntryExitDetector::GNEMultiEntryExitDetector(const std::string& id, GNENet* net, const std::string& filename, const Position pos, const SUMOTime freq,
39 const std::string& outputFilename, const std::vector<std::string>& vehicleTypes, const std::vector<std::string>& nextEdges, const std::string& detectPersons,
40 const std::string& name, const SUMOTime timeThreshold, const double speedThreshold, const bool openEntry, const bool expectedArrival, const Parameterised::Map& parameters) :
41 GNEAdditional(id, net, filename, SUMO_TAG_ENTRY_EXIT_DETECTOR, name),
42 GNEAdditionalSquared(this, pos),
43 Parameterised(parameters),
44 myPeriod(freq),
45 myOutputFilename(outputFilename),
46 myVehicleTypes(vehicleTypes),
47 myNextEdges(nextEdges),
48 myDetectPersons(detectPersons),
49 myTimeThreshold(timeThreshold),
50 mySpeedThreshold(speedThreshold),
51 myOpenEntry(openEntry),
52 myExpectedArrival(expectedArrival) {
53 // update centering boundary without updating grid
55 // set default output filename
56 if (outputFilename.empty()) {
57 myOutputFilename = id + ".xml";
58 }
59}
60
61
64
65
70
71
76
77
78const Parameterised*
80 return this;
81}
82
83
84void
86 bool entry = false;
87 bool exit = false;
88 // first check if E3 has at least one entry and one exit
89 for (const auto& additionalChild : getChildAdditionals()) {
90 if (additionalChild->getTagProperty()->getTag() == SUMO_TAG_DET_ENTRY) {
91 entry = true;
92 } else if (additionalChild->getTagProperty()->getTag() == SUMO_TAG_DET_EXIT) {
93 exit = true;
94 }
95 }
96 // check entry/exits
97 if (entry && exit) {
98 device.openTag(getTagProperty()->getTag());
99 // write common additional attributes
101 // write move atributes
103 // write specific attributes
104 if (getAttribute(SUMO_ATTR_PERIOD).size() > 0) {
106 }
107 if (myOutputFilename.size() > 0) {
109 }
110 if (myVehicleTypes.size() > 0) {
112 }
115 }
118 }
121 }
124 }
125 // write all entry/exits
126 for (const auto& access : getChildAdditionals()) {
127 access->writeAdditional(device);
128 }
129 // write parameters (Always after children to avoid problems with additionals.xsd)
130 writeParams(device);
131 device.closeTag();
132 } else {
133 WRITE_WARNING("E3 '" + getID() + TL("' needs at least one entry and one exit"));
134 }
135}
136
137
138bool
140 return true;
141}
142
143
144std::string
148
149
150void
154
155
156bool
158 // get edit modes
159 const auto& editModes = myNet->getViewNet()->getEditModes();
160 // check if we're in move mode
161 if (!myNet->getViewNet()->isCurrentlyMovingElements() && editModes.isCurrentSupermodeNetwork() &&
163 (editModes.networkEditMode == NetworkEditMode::NETWORK_MOVE) && myNet->getViewNet()->checkOverLockedElement(this, mySelected)) {
164 // only move the first element
166 } else {
167 return false;
168 }
169}
170
171
172void
176
177
182
183
184void
188
189
190void
191GNEMultiEntryExitDetector::splitEdgeGeometry(const double /*splitPosition*/, const GNENetworkElement* /*originalElement*/, const GNENetworkElement* /*newElement*/, GNEUndoList* /*undoList*/) {
192 // geometry of this element cannot be splitted
193}
194
195
196std::string
200
201
202void
204 // first check if additional has to be drawn
207 // draw parent and child lines
209 // draw E3
211 }
212}
213
214
215std::string
217 switch (key) {
218 case SUMO_ATTR_ID:
219 return getMicrosimID();
220 case SUMO_ATTR_PERIOD:
222 return "";
223 } else {
224 return time2string(myPeriod);
225 }
226 case SUMO_ATTR_NAME:
227 return myAdditionalName;
228 case SUMO_ATTR_FILE:
229 return myOutputFilename;
230 case SUMO_ATTR_VTYPES:
231 return toString(myVehicleTypes);
233 return toString(myNextEdges);
241 return toString(myOpenEntry);
244 default:
246 }
247}
248
249
250double
254
255
260
261
266
267
268void
269GNEMultiEntryExitDetector::setAttribute(SumoXMLAttr key, const std::string& value, GNEUndoList* undoList) {
270 if (value == getAttribute(key)) {
271 return; //avoid needless changes, later logic relies on the fact that attributes have changed
272 }
273 switch (key) {
274 case SUMO_ATTR_ID:
275 case SUMO_ATTR_PERIOD:
276 case SUMO_ATTR_NAME:
277 case SUMO_ATTR_FILE:
278 case SUMO_ATTR_VTYPES:
285 GNEChange_Attribute::changeAttribute(this, key, value, undoList);
286 break;
287 default:
288 myMoveElementView->setMovingAttribute(key, value, undoList);
289 break;
290 }
291}
292
293
294bool
295GNEMultiEntryExitDetector::isValid(SumoXMLAttr key, const std::string& value) {
296 switch (key) {
297 case SUMO_ATTR_ID:
298 return isValidDetectorID(value);
299 case SUMO_ATTR_PERIOD:
300 if (value.empty()) {
301 return true;
302 } else {
303 return (canParse<double>(value) && (parse<double>(value) >= 0));
304 }
305 case SUMO_ATTR_NAME:
307 case SUMO_ATTR_FILE:
309 case SUMO_ATTR_VTYPES:
310 if (value.empty()) {
311 return true;
312 } else {
314 }
316 if (value.empty()) {
317 return true;
318 } else {
320 }
322 if (value.empty()) {
323 return true;
324 } else {
326 }
329 return canParse<double>(value) && (parse<double>(value) >= 0);
332 return canParse<bool>(value);
333 default:
334 return myMoveElementView->isMovingAttributeValid(key, value);
335 }
336}
337
338
339bool
341 int numEntrys = 0;
342 int numExits = 0;
343 // iterate over additional chidls and obtain number of entrys and exits
344 for (auto i : getChildAdditionals()) {
345 if (i->getTagProperty()->getTag() == SUMO_TAG_DET_ENTRY) {
346 numEntrys++;
347 } else if (i->getTagProperty()->getTag() == SUMO_TAG_DET_EXIT) {
348 numExits++;
349 }
350 }
351 // write warnings
352 if (numEntrys == 0) {
353 WRITE_WARNING(TL("An entry-exit detector needs at least one entry detector"));
354 }
355 if (numExits == 0) {
356 WRITE_WARNING(TL("An entry-exit detector needs at least one exit detector"));
357 }
358 // return false depending of number of Entrys and Exits
359 return ((numEntrys != 0) && (numExits != 0));
360}
361
362
363std::string
365 return getTagStr() + ":" + getID();
366}
367
368
369std::string
373
374// ===========================================================================
375// private
376// ===========================================================================
377
378void
380 switch (key) {
381 case SUMO_ATTR_ID:
382 // update microsimID
383 setAdditionalID(value);
384 break;
385 case SUMO_ATTR_PERIOD:
386 if (value.empty()) {
388 } else {
389 myPeriod = string2time(value);
390 }
391 break;
392 case SUMO_ATTR_NAME:
393 myAdditionalName = value;
394 break;
395 case SUMO_ATTR_FILE:
396 myOutputFilename = value;
397 break;
398 case SUMO_ATTR_VTYPES:
399 myVehicleTypes = parse<std::vector<std::string> >(value);
400 break;
402 myNextEdges = parse<std::vector<std::string> >(value);
403 break;
405 myDetectPersons = value;
406 break;
408 myTimeThreshold = parse<SUMOTime>(value);
409 break;
411 mySpeedThreshold = parse<double>(value);
412 break;
414 myOpenEntry = parse<bool>(value);
415 break;
417 myExpectedArrival = parse<bool>(value);
418 break;
419 default:
421 break;
422 }
423 // update boundary (except for template)
424 if (getID().size() > 0) {
426 }
427}
428
429/****************************************************************************/
@ NETWORK_MOVE
mode for moving network elements
long long int SUMOTime
Definition GUI.h:36
#define WRITE_WARNING(msg)
Definition MsgHandler.h:286
#define TL(string)
Definition MsgHandler.h:304
SUMOTime string2time(const std::string &r)
convert string to SUMOTime
Definition SUMOTime.cpp:46
std::string time2string(SUMOTime t, bool humanReadable)
convert SUMOTime to string (independently of global format setting)
Definition SUMOTime.cpp:91
#define SUMOTime_MAX_PERIOD
Definition SUMOTime.h:36
@ 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_EXPECT_ARRIVAL
@ SUMO_ATTR_NEXT_EDGES
@ SUMO_ATTR_FILE
@ SUMO_ATTR_HALTING_TIME_THRESHOLD
@ SUMO_ATTR_VTYPES
@ SUMO_ATTR_NAME
@ SUMO_ATTR_PERIOD
@ SUMO_ATTR_HALTING_SPEED_THRESHOLD
@ SUMO_ATTR_ID
@ SUMO_ATTR_OPEN_ENTRY
@ SUMO_ATTR_DETECT_PERSONS
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
Definition ToString.h:46
void setAdditionalID(const std::string &newID)
set additional ID
bool isValidDetectorID(const std::string &value) const
check if a new detector ID is valid
std::string myAdditionalName
name of additional
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
void updatedSquaredGeometry()
updated squared geometry
Position myPosOverView
position over view
void updatedSquaredCenteringBoundary(const bool updateGrid)
updated squared centering boundary
GNEMoveElementView * myMoveElementView
move element over view
void drawSquaredAdditional(const GUIVisualizationSettings &s, const double size, GUITexture texture, GUITexture selectedTexture) const
draw squared additional
const std::string getID() const
get ID (all Attribute Carriers have one)
bool mySelected
boolean to check if this AC is selected (more quickly as checking GUIGlObjectStorage)
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
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
const GNEHierarchicalContainerChildren< GNEAdditional * > & getChildAdditionals() const
return child additionals
Position getMovingAttributePosition(SumoXMLAttr key) const override
get moving attribute position
void writeMoveAttributes(OutputDevice &device) const
write move attributes
void setMovingAttribute(SumoXMLAttr key, const std::string &value, GNEUndoList *undoList) override
set moving attribute (using undo-list)
PositionVector getMovingAttributePositionVector(SumoXMLAttr key) const override
get moving attribute positionVector
double getMovingAttributeDouble(SumoXMLAttr key) const override
get moving attribute double
std::string getMovingAttribute(SumoXMLAttr key) const override
get moving attribute
bool isMovingAttributeValid(SumoXMLAttr key, const std::string &value) const override
check if the given moving attribute is valid
bool isAdditionalValid() const
check if current additional is valid to be written into XML (must be reimplemented in all detector ch...
bool myExpectedArrival
flag for enable/disable expected arrival
std::vector< std::string > myNextEdges
next edges
double getAttributeDouble(SumoXMLAttr key) const override
std::vector< std::string > myVehicleTypes
attribute vehicle types
std::string getHierarchyName() const override
get Hierarchy Name (Used in AC Hierarchy)
std::string myOutputFilename
fielname of E3 detector
void updateCenteringBoundary(const bool updateGrid)
update centering boundary (implies change in RTREE)
SUMOTime myTimeThreshold
The time-based threshold that describes how much time has to pass until a vehicle is recognized as ha...
bool checkChildAdditionalRestriction() const
check restriction with the number of children
Parameterised * getParameters() override
get parameters associated with this multiEntryExitDetector
void drawGL(const GUIVisualizationSettings &s) const
Draws the object.
void fixAdditionalProblem()
fix additional problem (must be reimplemented in all detector children)
Position getPositionInView() const
Returns position of additional in view.
bool isValid(SumoXMLAttr key, const std::string &value) override
std::string getParentName() const
Returns the name of the parent object.
std::string myDetectPersons
detect persons
~GNEMultiEntryExitDetector()
GNEMultiEntryExitDetector Destructor.
PositionVector getAttributePositionVector(SumoXMLAttr key) const override
void splitEdgeGeometry(const double splitPosition, const GNENetworkElement *originalElement, const GNENetworkElement *newElement, GNEUndoList *undoList)
split geometry
GNEMultiEntryExitDetector(GNENet *net)
default constructor
std::string getPopUpID() const override
get PopPup ID (Used in AC Hierarchy)
std::string getAdditionalProblem() const
return a string with the current additional problem (must be reimplemented in all detector children)
std::string getAttribute(SumoXMLAttr key) const override
bool checkDrawMoveContour() const override
check if draw move contour (red)
SUMOTime myPeriod
period of E3 detector
void updateGeometry() override
update pre-computed geometry information
void writeAdditional(OutputDevice &device) const
write additional element into a xml file
bool myOpenEntry
@brie open entry
GNEMoveElement * getMoveElement() const override
methods to retrieve the elements linked to this multiEntryExitDetector
void setAttribute(SumoXMLAttr key, const std::string &value, GNEUndoList *undoList) override
Position getAttributePosition(SumoXMLAttr key) const override
double mySpeedThreshold
The speed-based threshold that describes how slow a vehicle has to be to be recognized as halting.
A NBNetBuilder extended by visualisation and editing capabilities.
Definition GNENet.h:42
GNEViewNet * getViewNet() const
get view net
Definition GNENet.cpp:2193
bool getDefaultBoolValue(SumoXMLAttr attr) const
get default bool value
double getDefaultDoubleValue(SumoXMLAttr attr) const
get default double value
SUMOTime getDefaultTimeValue(SumoXMLAttr attr) const
get default time value
SumoXMLTag getTag() const
get Tag vinculated with this attribute Property
const GUIGlObject * getGUIGlObjectFront() const
get front GUIGLObject or a pointer to nullptr
bool isCurrentlyMovingElements() const
check if an element is being moved
const GNEViewNetHelper::DataViewOptions & getDataViewOptions() const
get data view options
const GNEViewNetHelper::EditModes & getEditModes() const
get edit modes
const GNEViewNetHelper::EditNetworkElementShapes & getEditNetworkElementShapes() const
get Edit Shape module
bool checkOverLockedElement(const GUIGlObject *GLObject, const bool isSelected) const
check if given element is locked (used for drawing select and delete contour)
const GNEViewNetHelper::ViewObjectsSelector & getViewObjectsSelector() const
get objects under cursor
bool selectingDetectorsTLSMode() const
check if we're selecting detectors in TLS mode
const std::string & getMicrosimID() const
Returns the id of the object as known to microsim.
Stores the information about how to visualize structures.
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.
An upper class for objects with additional parameters.
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
A list of positions.
static StringBijection< PersonMode > PersonModeValues
person modes
static bool isValidListOfNetIDs(const std::string &value)
whether the given string is a valid list of id for a network (empty aren't allowed)
static bool isValidFilename(const std::string &value)
whether the given string is a valid attribute for a filename (for example, a name)
static bool isValidListOfTypeID(const std::string &value)
whether the given string is a valid list of ids for an edge or vehicle type (empty aren't allowed)
static bool isValidAttribute(const std::string &value)
whether the given string is a valid attribute for a certain key (for example, a name)
bool hasString(const std::string &str) const
check if the given string exist
bool showAdditionals() const
check if additionals has to be drawn
GNENetworkElement * getEditedNetworkElement() const
pointer to edited network element
static const RGBColor connectionColor
connection color
static const double E3Size
E3 detector size.