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#include <config.h>
21
22#include <netedit/GNENet.h>
24#include <netedit/GNEUndoList.h>
25#include <netedit/GNEViewNet.h>
29
31
32// ===========================================================================
33// member method definitions
34// ===========================================================================
35
39
40
41GNEMultiEntryExitDetector::GNEMultiEntryExitDetector(const std::string& id, GNENet* net, const std::string& filename, const Position pos, const SUMOTime freq,
42 const std::string& outputFilename, const std::vector<std::string>& vehicleTypes, const std::vector<std::string>& nextEdges, const std::string& detectPersons,
43 const std::string& name, const SUMOTime timeThreshold, const double speedThreshold, const bool openEntry, const bool expectedArrival, const Parameterised::Map& parameters) :
44 GNEAdditional(id, net, filename, SUMO_TAG_ENTRY_EXIT_DETECTOR, name),
45 Parameterised(parameters),
46 myPosition(pos),
47 myPeriod(freq),
48 myOutputFilename(outputFilename),
49 myVehicleTypes(vehicleTypes),
50 myNextEdges(nextEdges),
51 myDetectPersons(detectPersons),
52 myTimeThreshold(timeThreshold),
53 mySpeedThreshold(speedThreshold),
54 myOpenEntry(openEntry),
55 myExpectedArrival(expectedArrival) {
56 // update centering boundary without updating grid
58 // set default output filename
59 if (outputFilename.empty()) {
60 myOutputFilename = id + ".xml";
61 }
62}
63
64
66
67
70 // return move operation for additional placed in view
71 return new GNEMoveOperation(this, myPosition);
72}
73
74
75void
77 bool entry = false;
78 bool exit = false;
79 // first check if E3 has at least one entry and one exit
80 for (const auto& additionalChild : getChildAdditionals()) {
81 if (additionalChild->getTagProperty()->getTag() == SUMO_TAG_DET_ENTRY) {
82 entry = true;
83 } else if (additionalChild->getTagProperty()->getTag() == SUMO_TAG_DET_EXIT) {
84 exit = true;
85 }
86 }
87 // check entry/exits
88 if (entry && exit) {
89 device.openTag(getTagProperty()->getTag());
90 device.writeAttr(SUMO_ATTR_ID, getID());
91 if (!myAdditionalName.empty()) {
93 }
95 if (getAttribute(SUMO_ATTR_PERIOD).size() > 0) {
97 }
98 if (myOutputFilename.size() > 0) {
100 }
101 if (myVehicleTypes.size() > 0) {
103 }
106 }
109 }
112 }
115 }
116 // write all entry/exits
117 for (const auto& access : getChildAdditionals()) {
118 access->writeAdditional(device);
119 }
120 // write parameters (Always after children to avoid problems with additionals.xsd)
121 writeParams(device);
122 device.closeTag();
123 } else {
124 WRITE_WARNING("E3 '" + getID() + TL("' needs at least one entry and one exit"));
125 }
126}
127
128
129bool
131 return true;
132}
133
134
135std::string
139
140
141void
145
146
147bool
149 // get edit modes
150 const auto& editModes = myNet->getViewNet()->getEditModes();
151 // check if we're in move mode
152 if (!myNet->getViewNet()->isCurrentlyMovingElements() && editModes.isCurrentSupermodeNetwork() &&
154 (editModes.networkEditMode == NetworkEditMode::NETWORK_MOVE) && myNet->getViewNet()->checkOverLockedElement(this, mySelected)) {
155 // only move the first element
157 } else {
158 return false;
159 }
160}
161
162
163void
168
169
174
175
176void
178 // remove additional from grid
179 if (updateGrid) {
181 }
182 // now update geometry
184 // add shape boundary
186 // grow
188 // add additional into RTREE again
189 if (updateGrid) {
191 }
192}
193
194
195void
196GNEMultiEntryExitDetector::splitEdgeGeometry(const double /*splitPosition*/, const GNENetworkElement* /*originalElement*/, const GNENetworkElement* /*newElement*/, GNEUndoList* /*undoList*/) {
197 // geometry of this element cannot be splitted
198}
199
200
201std::string
205
206
207void
209 // first check if additional has to be drawn
212 // draw parent and child lines
214 // draw E3
216 }
217}
218
219
220std::string
222 switch (key) {
223 case SUMO_ATTR_ID:
224 return getMicrosimID();
226 return toString(myPosition);
227 case SUMO_ATTR_PERIOD:
229 return "";
230 } else {
231 return time2string(myPeriod);
232 }
233 case SUMO_ATTR_NAME:
234 return myAdditionalName;
235 case SUMO_ATTR_FILE:
236 return myOutputFilename;
237 case SUMO_ATTR_VTYPES:
238 return toString(myVehicleTypes);
240 return toString(myNextEdges);
248 return toString(myOpenEntry);
251 default:
252 return getCommonAttribute(this, key);
253 }
254}
255
256
257double
259 throw InvalidArgument(getTagStr() + " doesn't have a double attribute of type '" + toString(key) + "'");
260}
261
262
267
268
269void
270GNEMultiEntryExitDetector::setAttribute(SumoXMLAttr key, const std::string& value, GNEUndoList* undoList) {
271 if (value == getAttribute(key)) {
272 return; //avoid needless changes, later logic relies on the fact that attributes have changed
273 }
274 switch (key) {
275 case SUMO_ATTR_ID:
276 case SUMO_ATTR_PERIOD:
278 case SUMO_ATTR_NAME:
279 case SUMO_ATTR_FILE:
280 case SUMO_ATTR_VTYPES:
287 GNEChange_Attribute::changeAttribute(this, key, value, undoList);
288 break;
289 default:
290 setCommonAttribute(key, value, undoList);
291 break;
292 }
293}
294
295
296bool
297GNEMultiEntryExitDetector::isValid(SumoXMLAttr key, const std::string& value) {
298 switch (key) {
299 case SUMO_ATTR_ID:
300 return isValidDetectorID(value);
302 return canParse<Position>(value);
303 case SUMO_ATTR_PERIOD:
304 if (value.empty()) {
305 return true;
306 } else {
307 return (canParse<double>(value) && (parse<double>(value) >= 0));
308 }
309 case SUMO_ATTR_NAME:
311 case SUMO_ATTR_FILE:
313 case SUMO_ATTR_VTYPES:
314 if (value.empty()) {
315 return true;
316 } else {
318 }
320 if (value.empty()) {
321 return true;
322 } else {
324 }
326 if (value.empty()) {
327 return true;
328 } else {
330 }
333 return canParse<double>(value) && (parse<double>(value) >= 0);
336 return canParse<bool>(value);
337 default:
338 return isCommonValid(key, value);
339 }
340}
341
342
343bool
345 int numEntrys = 0;
346 int numExits = 0;
347 // iterate over additional chidls and obtain number of entrys and exits
348 for (auto i : getChildAdditionals()) {
349 if (i->getTagProperty()->getTag() == SUMO_TAG_DET_ENTRY) {
350 numEntrys++;
351 } else if (i->getTagProperty()->getTag() == SUMO_TAG_DET_EXIT) {
352 numExits++;
353 }
354 }
355 // write warnings
356 if (numEntrys == 0) {
357 WRITE_WARNING(TL("An entry-exit detector needs at least one entry detector"));
358 }
359 if (numExits == 0) {
360 WRITE_WARNING(TL("An entry-exit detector needs at least one exit detector"));
361 }
362 // return false depending of number of Entrys and Exits
363 return ((numEntrys != 0) && (numExits != 0));
364}
365
366
367std::string
369 return getTagStr() + ":" + getID();
370}
371
372
373std::string
377
378// ===========================================================================
379// private
380// ===========================================================================
381
382void
384 switch (key) {
385 case SUMO_ATTR_ID:
386 // update microsimID
387 setAdditionalID(value);
388 break;
390 myPosition = parse<Position>(value);
391 // update boundary (except for template)
392 if (getID().size() > 0) {
394 }
395 break;
396 case SUMO_ATTR_PERIOD:
397 if (value.empty()) {
399 } else {
400 myPeriod = string2time(value);
401 }
402 break;
403 case SUMO_ATTR_NAME:
404 myAdditionalName = value;
405 break;
406 case SUMO_ATTR_FILE:
407 myOutputFilename = value;
408 break;
409 case SUMO_ATTR_VTYPES:
410 myVehicleTypes = parse<std::vector<std::string> >(value);
411 break;
413 myNextEdges = parse<std::vector<std::string> >(value);
414 break;
416 myDetectPersons = value;
417 break;
419 myTimeThreshold = parse<SUMOTime>(value);
420 break;
422 mySpeedThreshold = parse<double>(value);
423 break;
425 myOpenEntry = parse<bool>(value);
426 break;
428 myExpectedArrival = parse<bool>(value);
429 break;
430 default:
431 setCommonAttribute(this, key, value);
432 break;
433 }
434}
435
436
437void
439 // update position
440 myPosition = moveResult.shapeToUpdate.front();
441 // update geometry
443}
444
445
446void
448 undoList->begin(this, "position of " + getTagStr());
450 undoList->end();
451}
452
453
454/****************************************************************************/
@ NETWORK_MOVE
mode for moving network elements
long long int SUMOTime
Definition GUI.h:36
#define WRITE_WARNING(msg)
Definition MsgHandler.h:287
#define TL(string)
Definition MsgHandler.h:305
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_POSITION
@ SUMO_ATTR_DETECT_PERSONS
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
Definition ToString.h:46
Boundary & grow(double by)
extends the boundary by the given amount
Definition Boundary.cpp:340
void setAdditionalID(const std::string &newID)
set additional ID
GUIGeometry myAdditionalGeometry
geometry to be precomputed in updateGeometry(...)
bool isValidDetectorID(const std::string &value) const
check if a new detector ID is valid
std::string myAdditionalName
name of additional
void drawSquaredAdditional(const GUIVisualizationSettings &s, const Position &pos, const double size, GUITexture texture, GUITexture selectedTexture) const
draw squared additional
Boundary myAdditionalBoundary
Additional Boundary (used only by additionals placed over grid)
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 mySelected
boolean to check if this AC is selected (more quickly as checking GUIGlObjectStorage)
std::string getCommonAttribute(const Parameterised *parameterised, SumoXMLAttr key) const
void setCommonAttribute(SumoXMLAttr key, const std::string &value, GNEUndoList *undoList)
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
bool isCommonValid(SumoXMLAttr key, const std::string &value) const
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
move operation
move result
PositionVector shapeToUpdate
shape to update (edited in moveElement)
bool isAdditionalValid() const
check if current additional is valid to be written into XML (must be reimplemented in all detector ch...
std::string getHierarchyName() const
get Hierarchy Name (Used in AC Hierarchy)
bool myExpectedArrival
flag for enable/disable expected arrival
bool checkDrawMoveContour() const
check if draw move contour (red)
std::string getAttribute(SumoXMLAttr key) const
void setMoveShape(const GNEMoveResult &moveResult)
set move shape
std::vector< std::string > myNextEdges
next edges
std::vector< std::string > myVehicleTypes
attribute vehicle types
std::string myOutputFilename
fielname of E3 detector
std::string getPopUpID() const
get PopPup ID (Used in AC Hierarchy)
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
bool isValid(SumoXMLAttr key, const std::string &value)
method for checking if the key and their correspondent attribute are valids
Position myPosition
position of E3 in view
double getAttributeDouble(SumoXMLAttr key) const
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.
std::string getParentName() const
Returns the name of the parent object.
std::string myDetectPersons
detect persons
~GNEMultiEntryExitDetector()
GNEMultiEntryExitDetector Destructor.
void splitEdgeGeometry(const double splitPosition, const GNENetworkElement *originalElement, const GNENetworkElement *newElement, GNEUndoList *undoList)
split geometry
void setAttribute(SumoXMLAttr key, const std::string &value, GNEUndoList *undoList)
method for setting the attribute and letting the object perform additional changes
GNEMultiEntryExitDetector(GNENet *net)
default constructor
std::string getAdditionalProblem() const
return a string with the current additional problem (must be reimplemented in all detector children)
SUMOTime myPeriod
period of E3 detector
void writeAdditional(OutputDevice &device) const
write additional element into a xml file
const Parameterised::Map & getACParametersMap() const
get parameters map
void commitMoveShape(const GNEMoveResult &moveResult, GNEUndoList *undoList)
commit move shape
bool myOpenEntry
@brie open entry
void updateGeometry()
update pre-computed geometry information
GNEMoveOperation * getMoveOperation()
get move operation
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
void addGLObjectIntoGrid(GNEAttributeCarrier *AC)
add GL Object into net
Definition GNENet.cpp:1443
void removeGLObjectFromGrid(GNEAttributeCarrier *AC)
add GL Object into net
Definition GNENet.cpp:1453
GNEViewNet * getViewNet() const
get view net
Definition GNENet.cpp:2195
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
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 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
void updateSinglePosGeometry(const Position &position, const double rotation)
update position and rotation
const PositionVector & getShape() const
The shape of the additional element.
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
const Parameterised::Map & getParametersMap() const
Returns the inner key/value 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
Boundary getBoxBoundary() const
Returns a boundary enclosing this list of lines.
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
static std::string escapeXML(const std::string &orig, const bool maskDoubleHyphen=false)
Replaces the standard escapes by their XML entities.
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.