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-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>
27
29
30
31// ===========================================================================
32// member method definitions
33// ===========================================================================
34
36 GNEAdditional("", net, GLO_E3DETECTOR, SUMO_TAG_ENTRY_EXIT_DETECTOR, GUIIconSubSys::getIcon(GUIIcon::E3ENTRY), "", {}, {}, {}, {}, {}, {}),
37 myPeriod(0),
38 myFilename(""),
39 myTimeThreshold(0),
40mySpeedThreshold(0) {
41 // reset default values
42 resetDefaultValues();
43}
44
45
46GNEMultiEntryExitDetector::GNEMultiEntryExitDetector(const std::string& id, GNENet* net, const Position pos, const SUMOTime freq, const std::string& filename,
47 const std::vector<std::string>& vehicleTypes, const std::string& name, SUMOTime timeThreshold, double speedThreshold,
48 const Parameterised::Map& parameters) :
49 GNEAdditional(id, net, GLO_E3DETECTOR, SUMO_TAG_ENTRY_EXIT_DETECTOR, GUIIconSubSys::getIcon(GUIIcon::E3EXIT), name, {}, {}, {}, {}, {}, {}),
50Parameterised(parameters),
51myPosition(pos),
52myPeriod(freq),
53myFilename(filename),
54myVehicleTypes(vehicleTypes),
55myTimeThreshold(timeThreshold),
56mySpeedThreshold(speedThreshold) {
57 // update centering boundary without updating grid
58 updateCenteringBoundary(false);
59}
60
61
63
64
67 // return move operation for additional placed in view
68 return new GNEMoveOperation(this, myPosition);
69}
70
71
72void
74 bool entry = false;
75 bool exit = false;
76 // first check if E3 has at least one entry and one exit
77 for (const auto& additionalChild : getChildAdditionals()) {
78 if (additionalChild->getTagProperty().getTag() == SUMO_TAG_DET_ENTRY) {
79 entry = true;
80 } else if (additionalChild->getTagProperty().getTag() == SUMO_TAG_DET_EXIT) {
81 exit = true;
82 }
83 }
84 // check entry/exits
85 if (entry && exit) {
86 device.openTag(getTagProperty().getTag());
87 device.writeAttr(SUMO_ATTR_ID, getID());
88 if (!myAdditionalName.empty()) {
90 }
92 if (getAttribute(SUMO_ATTR_PERIOD).size() > 0) {
94 }
95 if (myFilename.size() > 0) {
97 }
98 if (myVehicleTypes.size() > 0) {
100 }
103 }
106 }
107 // write all entry/exits
108 for (const auto& access : getChildAdditionals()) {
109 access->writeAdditional(device);
110 }
111 // write parameters (Always after children to avoid problems with additionals.xsd)
112 writeParams(device);
113 device.closeTag();
114 } else {
115 WRITE_WARNING("E3 '" + getID() + TL("' needs at least one entry and one exit"));
116 }
117}
118
119
120bool
122 return true;
123}
124
125
126std::string
130
131
132void
136
137
138void
143
144
149
150
151void
153 // remove additional from grid
154 if (updateGrid) {
156 }
157 // now update geometry
159 // add shape boundary
161 // add positions of all childrens
162 for (const auto& additionalChildren : getChildAdditionals()) {
163 myAdditionalBoundary.add(additionalChildren->getPositionInView());
164 }
165 // grow
167 // add additional into RTREE again
168 if (updateGrid) {
170 }
171}
172
173
174void
175GNEMultiEntryExitDetector::splitEdgeGeometry(const double /*splitPosition*/, const GNENetworkElement* /*originalElement*/, const GNENetworkElement* /*newElement*/, GNEUndoList* /*undoList*/) {
176 // geometry of this element cannot be splitted
177}
178
179
180std::string
184
185
186void
196
197
198std::string
200 switch (key) {
201 case SUMO_ATTR_ID:
202 return getMicrosimID();
204 return toString(myPosition);
205 case SUMO_ATTR_PERIOD:
207 return "";
208 } else {
209 return time2string(myPeriod);
210 }
211 case SUMO_ATTR_NAME:
212 return myAdditionalName;
213 case SUMO_ATTR_FILE:
214 return myFilename;
215 case SUMO_ATTR_VTYPES:
216 return toString(myVehicleTypes);
224 return getParametersStr();
225 default:
226 throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
227 }
228}
229
230
231double
233 throw InvalidArgument(getTagStr() + " doesn't have a double attribute of type '" + toString(key) + "'");
234}
235
236
241
242
243void
244GNEMultiEntryExitDetector::setAttribute(SumoXMLAttr key, const std::string& value, GNEUndoList* undoList) {
245 if (value == getAttribute(key)) {
246 return; //avoid needless changes, later logic relies on the fact that attributes have changed
247 }
248 switch (key) {
249 case SUMO_ATTR_ID:
250 case SUMO_ATTR_PERIOD:
252 case SUMO_ATTR_NAME:
253 case SUMO_ATTR_FILE:
254 case SUMO_ATTR_VTYPES:
259 undoList->changeAttribute(new GNEChange_Attribute(this, key, value));
260 break;
261 default:
262 throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
263 }
264}
265
266
267bool
268GNEMultiEntryExitDetector::isValid(SumoXMLAttr key, const std::string& value) {
269 switch (key) {
270 case SUMO_ATTR_ID:
271 return isValidDetectorID(value);
273 return canParse<Position>(value);
274 case SUMO_ATTR_PERIOD:
275 if (value.empty()) {
276 return true;
277 } else {
278 return (canParse<double>(value) && (parse<double>(value) >= 0));
279 }
280 case SUMO_ATTR_NAME:
282 case SUMO_ATTR_FILE:
284 case SUMO_ATTR_VTYPES:
285 if (value.empty()) {
286 return true;
287 } else {
289 }
292 return canParse<double>(value) && (parse<double>(value) >= 0);
294 return canParse<bool>(value);
296 return areParametersValid(value);
297 default:
298 throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
299 }
300}
301
302
303bool
305 int numEntrys = 0;
306 int numExits = 0;
307 // iterate over additional chidls and obtain number of entrys and exits
308 for (auto i : getChildAdditionals()) {
309 if (i->getTagProperty().getTag() == SUMO_TAG_DET_ENTRY) {
310 numEntrys++;
311 } else if (i->getTagProperty().getTag() == SUMO_TAG_DET_EXIT) {
312 numExits++;
313 }
314 }
315 // write warnings
316 if (numEntrys == 0) {
317 WRITE_WARNING(TL("An entry-exit detector needs at least one entry detector"));
318 }
319 if (numExits == 0) {
320 WRITE_WARNING(TL("An entry-exit detector needs at least one exit detector"));
321 }
322 // return false depending of number of Entrys and Exits
323 return ((numEntrys != 0) && (numExits != 0));
324}
325
326
327std::string
329 return getTagStr() + ":" + getID();
330}
331
332
333std::string
337
338// ===========================================================================
339// private
340// ===========================================================================
341
342void
344 switch (key) {
345 case SUMO_ATTR_ID:
346 // update microsimID
347 setMicrosimID(value);
348 // Change IDs of all Entry/Exits children
349 for (const auto& entryExit : getChildAdditionals()) {
350 entryExit->setMicrosimID(getID());
351 }
352 break;
354 myPosition = parse<Position>(value);
355 // update boundary (except for template)
356 if (getID().size() > 0) {
358 }
359 break;
360 case SUMO_ATTR_PERIOD:
361 if (value.empty()) {
363 } else {
364 myPeriod = string2time(value);
365 }
366 break;
367 case SUMO_ATTR_NAME:
368 myAdditionalName = value;
369 break;
370 case SUMO_ATTR_FILE:
371 myFilename = value;
372 break;
373 case SUMO_ATTR_VTYPES:
374 myVehicleTypes = parse<std::vector<std::string> >(value);
375 break;
377 myTimeThreshold = parse<SUMOTime>(value);
378 break;
380 mySpeedThreshold = parse<double>(value);
381 break;
383 if (parse<bool>(value)) {
385 } else {
387 }
388 break;
390 setParametersStr(value);
391 break;
392 default:
393 throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
394 }
395}
396
397
398void
400 // update position
401 myPosition = moveResult.shapeToUpdate.front();
402 // update geometry
404}
405
406
407void
409 undoList->begin(GUIIcon::E3, "position of " + getTagStr());
410 undoList->changeAttribute(new GNEChange_Attribute(this, SUMO_ATTR_POSITION, toString(moveResult.shapeToUpdate.front())));
411 undoList->end();
412}
413
414
415/****************************************************************************/
long long int SUMOTime
Definition GUI.h:36
@ GLO_E3DETECTOR
a E3 detector
GUIIcon
An enumeration of icons used by the gui applications.
Definition GUIIcons.h:33
#define WRITE_WARNING(msg)
Definition MsgHandler.h:270
#define TL(string)
Definition MsgHandler.h:287
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:69
#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_FILE
@ GNE_ATTR_SELECTED
element is selected
@ GNE_ATTR_PARAMETERS
parameters "key1=value1|key2=value2|...|keyN=valueN"
@ SUMO_ATTR_HALTING_TIME_THRESHOLD
@ SUMO_ATTR_VTYPES
@ SUMO_ATTR_NAME
@ SUMO_ATTR_PERIOD
@ SUMO_ATTR_HALTING_SPEED_THRESHOLD
@ SUMO_ATTR_ID
@ SUMO_ATTR_POSITION
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
Definition ToString.h:46
void add(double x, double y, double z=0)
Makes the boundary include the given coordinate.
Definition Boundary.cpp:78
Boundary & grow(double by)
extends the boundary by the given amount
Definition Boundary.cpp:300
An Element which don't belong to GNENet but has influence in the simulation.
GUIGeometry myAdditionalGeometry
geometry to be precomputed in updateGeometry(...)
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
bool isValidDetectorID(const std::string &newID) const
check if a new detector ID is valid
Boundary myAdditionalBoundary
Additional Boundary.
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
friend class GNEChange_Attribute
declare friend class
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
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
const std::vector< 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 writed into XML (must be reimplemented in all detector chi...
std::string getHierarchyName() const
get Hierarchy Name (Used in AC Hierarchy)
std::string getAttribute(SumoXMLAttr key) const
void setMoveShape(const GNEMoveResult &moveResult)
set move shape
std::vector< std::string > myVehicleTypes
attribute vehicle types
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.
~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
void updateGeometry()
update pre-computed geometry information
GNEMoveOperation * getMoveOperation()
get move operation
std::string myFilename
fielname of E3 detector
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:1248
void removeGLObjectFromGrid(GNEAttributeCarrier *AC)
add GL Object into net
Definition GNENet.cpp:1260
GNEViewNet * getViewNet() const
get view net
Definition GNENet.cpp:2030
SumoXMLTag getTag() const
get Tag vinculated with this attribute Property
const std::string & getDefaultValue(SumoXMLAttr attr) const
return the default value of the attribute of an element
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
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.
virtual void setMicrosimID(const std::string &newID)
Changes the microsimID of the object.
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.
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"
const Parameterised::Map & getParametersMap() const
Returns the inner key/value map.
void writeParams(OutputDevice &device) const
write Params in the given outputdevice
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
Boundary getBoxBoundary() const
Returns a boundary enclosing this list of lines.
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)
static std::string escapeXML(const std::string &orig, const bool maskDoubleHyphen=false)
Replaces the standard escapes by their XML entities.
static const RGBColor connectionColor
connection color
static const double E3Size
E3 detector size.