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-2026 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#include <config.h>
21
23
26#include <netedit/GNENet.h>
28
30
31// ===========================================================================
32// member method definitions
33// ===========================================================================
34
35#ifdef _MSC_VER
36#pragma warning(push)
37#pragma warning(disable: 4355) // mask warning about "this" in initializers
38#endif
43
44
45GNEMultiEntryExitDetector::GNEMultiEntryExitDetector(const std::string& id, GNENet* net, FileBucket* fileBucket, const Position pos, const SUMOTime freq,
46 const std::string& outputFilename, const std::vector<std::string>& vehicleTypes, const std::vector<std::string>& nextEdges, const std::string& detectPersons,
47 const std::string& name, const SUMOTime timeThreshold, const double speedThreshold, const bool openEntry, const bool expectedArrival, const Parameterised::Map& parameters) :
48 GNEAdditional(id, net, SUMO_TAG_ENTRY_EXIT_DETECTOR, fileBucket, name),
49 GNEAdditionalSquared(this, pos),
50 Parameterised(parameters),
51 myPeriod(freq),
52 myOutputFilename(outputFilename),
53 myVehicleTypes(vehicleTypes),
54 myNextEdges(nextEdges),
55 myDetectPersons(detectPersons),
56 myTimeThreshold(timeThreshold),
57 mySpeedThreshold(speedThreshold),
58 myOpenEntry(openEntry),
59 myExpectedArrival(expectedArrival) {
60 // update centering boundary without updating grid
62 // set default output filename
63 if (outputFilename.empty()) {
64 myOutputFilename = id + ".xml";
65 }
66}
67#ifdef _MSC_VER
68#pragma warning(pop)
69#endif
70
71
74
75
80
81
86
87
88const Parameterised*
90 return this;
91}
92
93
94void
96 bool entry = false;
97 bool exit = false;
98 // first check if E3 has at least one entry and one exit
99 for (const auto& additionalChild : getChildAdditionals()) {
100 if (additionalChild->getTagProperty()->getTag() == SUMO_TAG_DET_ENTRY) {
101 entry = true;
102 } else if (additionalChild->getTagProperty()->getTag() == SUMO_TAG_DET_EXIT) {
103 exit = true;
104 }
105 }
106 // check entry/exits
107 if (entry && exit) {
108 device.openTag(getTagProperty()->getTag());
109 // write common additional attributes
111 // write move atributes
113 // write specific attributes
114 if (getAttribute(SUMO_ATTR_PERIOD).size() > 0) {
116 }
117 if (myOutputFilename.size() > 0) {
119 }
120 if (myVehicleTypes.size() > 0) {
122 }
125 }
128 }
131 }
134 }
135 // write all entry/exits
136 for (const auto& access : getChildAdditionals()) {
137 access->writeAdditional(device);
138 }
139 // write parameters (Always after children to avoid problems with additionals.xsd)
140 XMLHelpers::writeParams(device, *this);
141 device.closeTag();
142 } else {
143 WRITE_WARNING("E3 '" + getID() + TL("' needs at least one entry and one exit"));
144 }
145}
146
147
148bool
150 return true;
151}
152
153
154std::string
158
159
160void
164
165
166bool
168 // get edit modes
169 const auto& editModes = myNet->getViewNet()->getEditModes();
170 // check if we're in move mode
171 if (!myNet->getViewNet()->isCurrentlyMovingElements() && editModes.isCurrentSupermodeNetwork() &&
173 (editModes.networkEditMode == NetworkEditMode::NETWORK_MOVE) && myNet->getViewNet()->checkOverLockedElement(this, mySelected)) {
174 // only move the first element
176 } else {
177 return false;
178 }
179}
180
181
182void
186
187
192
193
194void
198
199
200void
201GNEMultiEntryExitDetector::splitEdgeGeometry(const double /*splitPosition*/, const GNENetworkElement* /*originalElement*/, const GNENetworkElement* /*newElement*/, GNEUndoList* /*undoList*/) {
202 // geometry of this element cannot be splitted
203}
204
205
206std::string
210
211
212void
214 // first check if additional has to be drawn
217 // draw parent and child lines
219 // draw E3
221 }
222}
223
224
225std::string
227 switch (key) {
228 case SUMO_ATTR_ID:
229 return getMicrosimID();
230 case SUMO_ATTR_PERIOD:
232 return "";
233 } else {
234 return time2string(myPeriod);
235 }
236 case SUMO_ATTR_NAME:
237 return myAdditionalName;
238 case SUMO_ATTR_FILE:
239 return myOutputFilename;
240 case SUMO_ATTR_VTYPES:
241 return toString(myVehicleTypes);
243 return toString(myNextEdges);
251 return toString(myOpenEntry);
254 default:
256 }
257}
258
259
260double
264
265
270
271
276
277
278void
279GNEMultiEntryExitDetector::setAttribute(SumoXMLAttr key, const std::string& value, GNEUndoList* undoList) {
280 if (value == getAttribute(key)) {
281 return; //avoid needless changes, later logic relies on the fact that attributes have changed
282 }
283 switch (key) {
284 case SUMO_ATTR_ID:
285 case SUMO_ATTR_PERIOD:
286 case SUMO_ATTR_NAME:
287 case SUMO_ATTR_FILE:
288 case SUMO_ATTR_VTYPES:
295 GNEChange_Attribute::changeAttribute(this, key, value, undoList);
296 break;
297 default:
298 myMoveElementView->setMovingAttribute(key, value, undoList);
299 break;
300 }
301}
302
303
304bool
305GNEMultiEntryExitDetector::isValid(SumoXMLAttr key, const std::string& value) {
306 switch (key) {
307 case SUMO_ATTR_ID:
308 return isValidDetectorID(value);
309 case SUMO_ATTR_PERIOD:
310 if (value.empty()) {
311 return true;
312 } else {
313 return (canParse<double>(value) && (parse<double>(value) >= 0));
314 }
315 case SUMO_ATTR_NAME:
316 return StringUtils::isValidAttribute(value);
317 case SUMO_ATTR_FILE:
318 return StringUtils::isValidFilename(value);
319 case SUMO_ATTR_VTYPES:
320 if (value.empty()) {
321 return true;
322 } else {
324 }
326 if (value.empty()) {
327 return true;
328 } else {
330 }
332 if (value.empty()) {
333 return true;
334 } else {
336 }
339 return canParse<double>(value) && (parse<double>(value) >= 0);
342 return canParse<bool>(value);
343 default:
344 return myMoveElementView->isMovingAttributeValid(key, value);
345 }
346}
347
348
349bool
351 int numEntrys = 0;
352 int numExits = 0;
353 // iterate over additional chidls and obtain number of entrys and exits
354 for (auto i : getChildAdditionals()) {
355 if (i->getTagProperty()->getTag() == SUMO_TAG_DET_ENTRY) {
356 numEntrys++;
357 } else if (i->getTagProperty()->getTag() == SUMO_TAG_DET_EXIT) {
358 numExits++;
359 }
360 }
361 // write warnings
362 if (numEntrys == 0) {
363 WRITE_WARNING(TL("An entry-exit detector needs at least one entry detector"));
364 }
365 if (numExits == 0) {
366 WRITE_WARNING(TL("An entry-exit detector needs at least one exit detector"));
367 }
368 // return false depending of number of Entrys and Exits
369 return ((numEntrys != 0) && (numExits != 0));
370}
371
372
373std::string
375 return getTagStr() + ":" + getID();
376}
377
378
379std::string
383
384// ===========================================================================
385// private
386// ===========================================================================
387
388void
390 switch (key) {
391 case SUMO_ATTR_ID:
392 // update microsimID
393 setAdditionalID(value);
394 break;
395 case SUMO_ATTR_PERIOD:
396 if (value.empty()) {
398 } else {
399 myPeriod = string2time(value);
400 }
401 break;
402 case SUMO_ATTR_NAME:
403 myAdditionalName = value;
404 break;
405 case SUMO_ATTR_FILE:
406 myOutputFilename = value;
407 break;
408 case SUMO_ATTR_VTYPES:
409 myVehicleTypes = parse<std::vector<std::string> >(value);
410 break;
412 myNextEdges = parse<std::vector<std::string> >(value);
413 break;
415 myDetectPersons = value;
416 break;
418 myTimeThreshold = parse<SUMOTime>(value);
419 break;
421 mySpeedThreshold = parse<double>(value);
422 break;
424 myOpenEntry = parse<bool>(value);
425 break;
427 myExpectedArrival = parse<bool>(value);
428 break;
429 default:
431 break;
432 }
433 // update boundary (except for template)
434 if (getID().size() > 0) {
436 }
437}
438
439/****************************************************************************/
@ NETWORK_MOVE
mode for moving network elements
long long int SUMOTime
Definition GUI.h:36
#define WRITE_WARNING(msg)
Definition MsgHandler.h:298
#define TL(string)
Definition MsgHandler.h:316
SUMOTime string2time(const std::string &r)
convert string to SUMOTime
Definition SUMOTime.cpp:47
std::string time2string(SUMOTime t, bool humanReadable)
convert SUMOTime to string (independently of global format setting)
Definition SUMOTime.cpp:107
#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:57
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
bool mySelected
boolean to check if this AC is selected (more quickly as checking GUIGlObjectStorage)
const std::string getID() const override
get ID (all Attribute Carriers have one)
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 myExpectedArrival
flag for enable/disable expected arrival
bool isAdditionalValid() const override
check if current additional is valid to be written into XML (must be reimplemented in all detector ch...
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 getParentName() const override
Returns the name of the parent object.
void splitEdgeGeometry(const double splitPosition, const GNENetworkElement *originalElement, const GNENetworkElement *newElement, GNEUndoList *undoList) override
split geometry
std::string myOutputFilename
fielname of E3 detector
SUMOTime myTimeThreshold
The time-based threshold that describes how much time has to pass until a vehicle is recognized as ha...
void writeAdditional(OutputDevice &device) const override
write additional element into a xml file
Parameterised * getParameters() override
get parameters associated with this multiEntryExitDetector
void fixAdditionalProblem() override
fix additional problem (must be reimplemented in all detector children)
bool isValid(SumoXMLAttr key, const std::string &value) override
std::string myDetectPersons
detect persons
~GNEMultiEntryExitDetector()
GNEMultiEntryExitDetector Destructor.
PositionVector getAttributePositionVector(SumoXMLAttr key) const override
GNEMultiEntryExitDetector(GNENet *net)
default constructor
std::string getPopUpID() const override
get PopPup ID (Used in AC Hierarchy)
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
bool checkChildAdditionalRestriction() const override
check restriction with the number of children
bool myOpenEntry
@brie open entry
GNEMoveElement * getMoveElement() const override
methods to retrieve the elements linked to this multiEntryExitDetector
Position getPositionInView() const override
Returns position of additional in view.
void setAttribute(SumoXMLAttr key, const std::string &value, GNEUndoList *undoList) override
void drawGL(const GUIVisualizationSettings &s) const override
Draws the object.
Position getAttributePosition(SumoXMLAttr key) const override
void updateCenteringBoundary(const bool updateGrid) override
update centering boundary (implies change in RTREE)
std::string getAdditionalProblem() const override
return a string with the current additional problem (must be reimplemented in all detector children)
double mySpeedThreshold
The speed-based threshold that describes how slow a vehicle has to be to be recognized as halting.
GNEViewNet * getViewNet() const
get view net (used for simplify code)
Definition GNENet.cpp:144
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 & openTag(const std::string &xmlElement)
Opens an XML tag.
OutputDevice & writeAttr(const ATTR_TYPE &attr, const T &val, const bool isNull=false, const bool escape=false)
writes a named attribute
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
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
bool hasString(const std::string &str) const
check if the given string exist
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 isValidFilename(const std::string &value)
whether the given string is a valid attribute for a filename (for example, a name)
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 isValidAttribute(const std::string &value)
whether the given string is a valid attribute for a certain key (for example, a name)
static OutputDevice & writeParams(OutputDevice &device, const Parameterised &params)
write the parameters of the given object as param tags
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.