Eclipse SUMO - Simulation of Urban MObility
Loading...
Searching...
No Matches
GNEMeanData.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-2024 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// Class for representing MeanData
19/****************************************************************************/
20#include <config.h>
21
22#include <netedit/GNENet.h>
23#include <netedit/GNEUndoList.h>
24#include <netedit/GNEViewNet.h>
36
37#include "GNEMeanData.h"
38
39
40// ===========================================================================
41// member method definitions
42// ===========================================================================
43
44GNEMeanData::GNEMeanData(GNENet* net, SumoXMLTag tag, const std::string& id) :
45 GNEHierarchicalElement(net, tag, {}, {}, {}, {}, {}, {}),
46myID(id) {
47 // reset default values
49 // set file
50 if (myFile.empty()) {
51 myFile = (myID + ".xml");
52 }
53}
54
55
56GNEMeanData::GNEMeanData(GNENet* net, SumoXMLTag tag, std::string ID, std::string file, SUMOTime period,
57 SUMOTime begin, SUMOTime end, const bool trackVehicles, const std::vector<SumoXMLAttr>& writtenAttributes,
58 const bool aggregate, const std::vector<std::string>& edges, const std::string& edgeFile,
59 std::string excludeEmpty, const bool withInternal, const std::vector<std::string>& detectPersons,
60 const double minSamples, const double maxTravelTime, const std::vector<std::string>& vTypes, const double speedThreshold) :
61 GNEHierarchicalElement(net, tag, {}, {}, {}, {}, {}, {}),
62myID(ID),
63myFile(file),
64myPeriod(period),
65myBegin(begin),
66myEnd(end),
67myTrackVehicles(trackVehicles),
68myWrittenAttributes(writtenAttributes),
69myAggregate(aggregate),
70myEdges(edges),
71myEdgeFile(edgeFile),
72myExcludeEmpty(excludeEmpty),
73myWithInternal(withInternal),
74myDetectPersons(detectPersons),
75myMinSamples(minSamples),
76myMaxTravelTime(maxTravelTime),
77myVTypes(vTypes),
78mySpeedThreshold(speedThreshold) {
79 // set file
80 if (myFile.empty()) {
81 myFile = (myID + ".xml");
82 }
83}
84
85
87
88
89void
91 device.openTag(getTagProperty().getTag());
92 // write needed attributes
93 device.writeAttr(SUMO_ATTR_ID, getID());
95 // write optional attributes
96 if (myPeriod != -1) {
98 }
99 if (myBegin != -1) {
101 }
102 if (myEnd != -1) {
104 }
105 if (myExcludeEmpty != "default") {
107 }
108 if (myWithInternal) {
110 }
111 if (myMaxTravelTime != 100000) {
113 }
114 if (myMinSamples != 0) {
116 }
117 if (mySpeedThreshold != 0.1) {
119 }
120 if (myVTypes.size() > 0) {
122 }
123 if (myTrackVehicles) {
125 }
126 if (myDetectPersons.size() > 0) {
128 }
129 if (myWrittenAttributes.size() > 0) {
131 }
132 if (myEdges.size() > 0) {
134 }
135 if (myEdgeFile.size() > 0) {
137 }
138 if (myAggregate) {
139 device.writeAttr(SUMO_ATTR_AGGREGATE, true);
140 }
141 device.closeTag();
142}
143
144
147 return nullptr;
148}
149
150
151const GUIGlObject*
153 return nullptr;
154}
155
156
157void
159 // nothing to update
160}
161
162
165 return Position();
166}
167
168
169bool
171 return false;
172}
173
174
175bool
177 return false;
178}
179
180
181bool
183 return false;
184}
185
186
187bool
189 return false;
190}
191
192
193bool
195 return false;
196}
197
198
199bool
201 return false;
202}
203
204
205bool
207 return false;
208}
209
210
211std::string
213 switch (key) {
214 case SUMO_ATTR_ID:
215 return myID;
216 case SUMO_ATTR_FILE:
217 return myFile;
218 case SUMO_ATTR_PERIOD:
219 if (myPeriod == -1) {
220 return "";
221 } else {
222 return time2string(myPeriod);
223 }
224 case SUMO_ATTR_BEGIN:
225 if (myBegin == -1) {
226 return "";
227 } else {
228 return time2string(myBegin);
229 }
230 case SUMO_ATTR_END:
231 if (myEnd == -1) {
232 return "";
233 } else {
234 return time2string(myEnd);
235 }
237 return myExcludeEmpty;
239 return toString(myWithInternal);
243 return toString(myMinSamples);
246 case SUMO_ATTR_VTYPES:
247 return toString(myVTypes);
254 case SUMO_ATTR_EDGES:
255 return toString(myEdges);
257 return myEdgeFile;
259 return toString(myAggregate);
260 default:
261 return getCommonAttribute(key);
262 }
263}
264
265
266double
268 throw InvalidArgument(getTagStr() + " doesn't have a double attribute of type '" + toString(key) + "'");
269}
270
271
272void
273GNEMeanData::setAttribute(SumoXMLAttr key, const std::string& value, GNEUndoList* undoList) {
274 if (value == getAttribute(key)) {
275 return; //avoid needless changes, later logic relies on the fact that attributes have changed
276 }
277 switch (key) {
278 case SUMO_ATTR_ID:
279 case SUMO_ATTR_FILE:
280 case SUMO_ATTR_PERIOD:
281 case SUMO_ATTR_BEGIN:
282 case SUMO_ATTR_END:
288 case SUMO_ATTR_VTYPES:
292 case SUMO_ATTR_EDGES:
295 GNEChange_Attribute::changeAttribute(this, key, value, undoList);
296 break;
297 default:
298 setCommonAttribute(key, value, undoList);
299 break;
300 }
301}
302
303
304bool
305GNEMeanData::isValid(SumoXMLAttr key, const std::string& value) {
306 switch (key) {
307 case SUMO_ATTR_ID:
308 return SUMOXMLDefinitions::isValidNetID(value) && (myNet->getAttributeCarriers()->retrieveMeanData(myTagProperty.getTag(), value, false) == nullptr);
309 case SUMO_ATTR_FILE:
311 case SUMO_ATTR_PERIOD:
312 case SUMO_ATTR_BEGIN:
313 case SUMO_ATTR_END:
314 if (value.empty()) {
315 return true;
316 } else {
317 return (canParse<SUMOTime>(value) && (parse<SUMOTime>(value) >= 0));
318 }
320 if (canParse<bool>(value)) {
321 return true;
322 } else {
323 return (value == "default");
324 }
326 return (canParse<bool>(value));
328 if (value.empty()) {
329 return true;
330 } else {
331 return (canParse<double>(value) && (parse<double>(value) >= 0));
332 }
334 return (canParse<double>(value) && (parse<double>(value) >= 0));
336 return (canParse<double>(value) && (parse<double>(value) >= 0));
337 case SUMO_ATTR_VTYPES:
338 return true;
340 return (canParse<bool>(value));
342 if (value.empty()) {
343 return true;
344 } else {
345 return (value == "walk");
346 }
348 return canParse<std::vector<SumoXMLAttr> >(value);
349 case SUMO_ATTR_EDGES:
350 return canParse<std::vector<GNEEdge*> >(myNet, value, false);
354 return (canParse<bool>(value));
355 default:
356 return isCommonValid(key, value);
357 }
358}
359
360
361std::string
363 return getTagStr();
364}
365
366
367std::string
369 return getTagStr();
370}
371
372
377
378
379void
380GNEMeanData::setAttribute(SumoXMLAttr key, const std::string& value) {
381 switch (key) {
382 case SUMO_ATTR_ID:
384 myID = value;
385 break;
386 case SUMO_ATTR_FILE:
387 myFile = value;
388 break;
389 case SUMO_ATTR_PERIOD:
390 if (value.empty()) {
391 myPeriod = -1;
392 } else {
393 myPeriod = string2time(value);
394 }
395 break;
396 case SUMO_ATTR_BEGIN:
397 if (value.empty()) {
398 myBegin = -1;
399 } else {
400 myBegin = string2time(value);
401 }
402 break;
403 case SUMO_ATTR_END:
404 if (value.empty()) {
405 myEnd = -1;
406 } else {
407 myEnd = string2time(value);
408 }
409 break;
411 myExcludeEmpty = value;
412 break;
414 myWithInternal = parse<bool>(value);
415 break;
417 if (value.empty()) {
418 myMaxTravelTime = 100000;
419 } else {
420 myMaxTravelTime = parse<double>(value);
421 }
422 break;
424 myMinSamples = parse<double>(value);
425 break;
427 mySpeedThreshold = parse<double>(value);
428 break;
429 case SUMO_ATTR_VTYPES:
430 myVTypes = parse<std::vector<std::string> >(value);
431 break;
433 myTrackVehicles = parse<bool>(value);
434 break;
436 myDetectPersons = parse<std::vector<std::string> >(value);
437 break;
439 myWrittenAttributes = parse<std::vector<SumoXMLAttr> >(value);
440 break;
441 case SUMO_ATTR_EDGES:
442 myEdges = parse<std::vector<std::string> >(value);
443 break;
445 myEdgeFile = value;
446 break;
448 myAggregate = parse<bool>(value);
449 break;
450 default:
451 setCommonAttribute(key, value);
452 break;
453 }
454}
455
456/****************************************************************************/
long long int SUMOTime
Definition GUI.h:36
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 STEPS2TIME(x)
Definition SUMOTime.h:55
SumoXMLTag
Numbers representing SUMO-XML - element names.
SumoXMLAttr
Numbers representing SUMO-XML - attributes.
@ SUMO_ATTR_FILE
@ SUMO_ATTR_TRACK_VEHICLES
@ SUMO_ATTR_BEGIN
weights: time range begin
@ SUMO_ATTR_WITH_INTERNAL
@ SUMO_ATTR_EDGES
the edges of a route
@ SUMO_ATTR_AGGREGATE
@ SUMO_ATTR_VTYPES
@ SUMO_ATTR_MAX_TRAVELTIME
@ SUMO_ATTR_PERIOD
@ SUMO_ATTR_HALTING_SPEED_THRESHOLD
@ SUMO_ATTR_END
weights: time range end
@ SUMO_ATTR_MIN_SAMPLES
@ SUMO_ATTR_ID
@ SUMO_ATTR_WRITE_ATTRIBUTES
@ SUMO_ATTR_DETECT_PERSONS
@ SUMO_ATTR_EXCLUDE_EMPTY
@ SUMO_ATTR_EDGESFILE
std::string joinToString(const std::vector< T > &v, const T_BETWEEN &between, std::streamsize accuracy=gPrecision)
Definition ToString.h:283
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
Definition ToString.h:46
const std::string getID() const
get ID (all Attribute Carriers have one)
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
bool isCommonValid(SumoXMLAttr key, const std::string &value)
static const Parameterised::Map PARAMETERS_EMPTY
empty parameter maps (used by ACs without parameters)
void resetDefaultValues()
reset attribute carrier to their default values
GNENet * myNet
pointer to net
std::string getCommonAttribute(SumoXMLAttr key) 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
SUMOTime myBegin
begin
double myMinSamples
minSamples
std::string myExcludeEmpty
exclude empty
std::string myEdgeFile
edge file
bool checkDrawOverContour() const
check if draw over contour (orange)
SUMOTime myEnd
end
bool myAggregate
whether the data for all edges shall be aggregated
bool checkDrawDeleteContour() const
check if draw delete contour (pink/white)
bool checkDrawSelectContour() const
check if draw select contour (blue)
std::vector< std::string > myDetectPersons
detect persons
GNEMeanData(GNENet *net, SumoXMLTag tag, const std::string &id)
Default constructor.
std::vector< std::string > myVTypes
VTypes.
const Parameterised::Map & getACParametersMap() const
get parameters map
GUIGlObject * getGUIGlObject()
get GUIGlObject associated with this AttributeCarrier
void setAttribute(SumoXMLAttr key, const std::string &value, GNEUndoList *undoList)
method for setting the attribute and letting the object perform data set changes
SUMOTime myPeriod
period
std::vector< SumoXMLAttr > myWrittenAttributes
bit mask for checking attributes to be written
std::string myFile
filename
double getAttributeDouble(SumoXMLAttr key) const
std::string myID
id
double mySpeedThreshold
speed threshold
bool isValid(SumoXMLAttr key, const std::string &value)
method for checking if the key and their conrrespond attribute are valids
std::vector< std::string > myEdges
list of edges
std::string getPopUpID() const
get PopPup ID (Used in AC Hierarchy)
bool checkDrawFromContour() const
check if draw from contour (green)
void updateGeometry()
update pre-computed geometry information
bool myWithInternal
width internal
bool myTrackVehicles
Whether vehicles are tracked.
std::string getHierarchyName() const
get Hierarchy Name (Used in AC Hierarchy)
bool checkDrawToContour() const
check if draw from contour (magenta)
std::string getAttribute(SumoXMLAttr key) const
Position getPositionInView() const
Returns element position in view.
bool checkDrawRelatedContour() const
check if draw related contour (cyan)
bool checkDrawMoveContour() const
check if draw move contour (red)
double myMaxTravelTime
max travel time
~GNEMeanData()
Destructor.
void writeMeanData(OutputDevice &device) const
write meanData element into a xml file
GNEMeanData * retrieveMeanData(SumoXMLTag type, const std::string &id, bool hardFail=true) const
Returns the named meanData.
void updateMeanDataID(GNEMeanData *meanData, const std::string &newID)
update meanData ID in container
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:127
SumoXMLTag getTag() const
get Tag vinculated with this attribute Property
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.
std::map< std::string, std::string > Map
parameters map
A point in 2D or 3D with translation and scaling methods.
Definition Position.h:37
static bool isValidFilename(const std::string &value)
whether the given string is a valid attribute for a filename (for example, a name)
static bool isValidNetID(const std::string &value)
whether the given string is a valid id for a network element