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-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// Class for representing MeanData
19/****************************************************************************/
20
21#include <netedit/GNENet.h>
24
25#include "GNEMeanData.h"
26
27// ===========================================================================
28// member method definitions
29// ===========================================================================
30
31GNEMeanData::GNEMeanData(SumoXMLTag tag, std::string ID, GNENet* net, const std::string& filename) :
32 GNEAttributeCarrier(tag, net, filename, true),
33 myID(ID) {
34 // reset default values
35 resetDefaultValues(false);
36}
37
38
39GNEMeanData::GNEMeanData(SumoXMLTag tag, std::string ID, GNENet* net, const std::string& filename, const std::string& file, const SUMOTime period,
40 const SUMOTime begin, const SUMOTime end, const bool trackVehicles, const std::vector<SumoXMLAttr>& writtenAttributes,
41 const bool aggregate, const std::vector<std::string>& edges, const std::string& edgeFile, const std::string& excludeEmpty,
42 const bool withInternal, const std::vector<std::string>& detectPersons, const double minSamples, const double maxTravelTime,
43 const std::vector<std::string>& vTypes, const double speedThreshold) :
44 GNEAttributeCarrier(tag, net, filename, false),
45 myID(ID),
46 myFile(file),
47 myPeriod(period),
48 myBegin(begin),
49 myEnd(end),
50 myTrackVehicles(trackVehicles),
51 myWrittenAttributes(writtenAttributes),
52 myAggregate(aggregate),
53 myEdges(edges),
54 myEdgeFile(edgeFile),
55 myExcludeEmpty(excludeEmpty),
56 myWithInternal(withInternal),
57 myDetectPersons(detectPersons),
58 myMinSamples(minSamples),
59 myMaxTravelTime(maxTravelTime),
60 myVTypes(vTypes),
61 mySpeedThreshold(speedThreshold) {
62 // set file
63 if (myFile.empty()) {
64 myFile = (myID + ".xml");
65 }
66}
67
68
70
71
76
77
78void
80 device.openTag(getTagProperty()->getTag());
81 // write needed attributes
82 device.writeAttr(SUMO_ATTR_ID, getID());
83 if (myFile.empty()) {
84 device.writeAttr(SUMO_ATTR_FILE, myID + ".xml");
85 } else {
87 }
88 // write optional attributes
90 std::cout << myPeriod << std::endl;
92 }
95 }
98 }
101 }
102 if (myWithInternal) {
104 }
107 }
110 }
113 }
114 if (myVTypes.size() > 0) {
116 }
117 if (myTrackVehicles) {
119 }
122 }
123 if (myWrittenAttributes.size() > 0) {
125 }
126 if (myEdges.size() > 0) {
128 }
129 if (myEdgeFile.size() > 0) {
131 }
132 if (myAggregate) {
133 device.writeAttr(SUMO_ATTR_AGGREGATE, true);
134 }
135 device.closeTag();
136}
137
138
141 return nullptr;
142}
143
144
145const GUIGlObject*
147 return nullptr;
148}
149
150
151void
153 // nothing to update
154}
155
156
159 return Position();
160}
161
162
163bool
165 return false;
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:
220 return "";
221 } else {
222 return time2string(myPeriod);
223 }
224 case SUMO_ATTR_BEGIN:
226 return "";
227 } else {
228 return time2string(myBegin);
229 }
230 case SUMO_ATTR_END:
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(this, 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 {
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 {
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 if (value.empty()) {
388 myFile = (myID + ".xml");
389 } else {
390 myFile = value;
391 }
392 break;
393 case SUMO_ATTR_PERIOD:
394 if (value.empty()) {
396 } else {
397 myPeriod = string2time(value);
398 }
399 break;
400 case SUMO_ATTR_BEGIN:
401 if (value.empty()) {
403 } else {
404 myBegin = string2time(value);
405 }
406 break;
407 case SUMO_ATTR_END:
408 if (value.empty()) {
410 } else {
411 myEnd = string2time(value);
412 }
413 break;
416 myExcludeEmpty = value;
417 } else if (parse<bool>(value)) {
419 } else {
421 }
422 break;
424 myWithInternal = parse<bool>(value);
425 break;
427 if (value.empty()) {
429 } else {
430 myMaxTravelTime = parse<double>(value);
431 }
432 break;
434 if (value.empty()) {
436 } else {
437 myMinSamples = parse<double>(value);
438 }
439 break;
441 if (value.empty()) {
443 } else {
444 mySpeedThreshold = parse<double>(value);
445 }
446 break;
447 case SUMO_ATTR_VTYPES:
448 myVTypes = parse<std::vector<std::string> >(value);
449 break;
451 myTrackVehicles = parse<bool>(value);
452 break;
454 myDetectPersons.clear();
455 if (value.empty()) {
457 } else {
458 myDetectPersons = parse<std::vector<std::string> >(value);
459 }
460 break;
462 myWrittenAttributes = parse<std::vector<SumoXMLAttr> >(value);
463 break;
464 case SUMO_ATTR_EDGES:
465 myEdges = parse<std::vector<std::string> >(value);
466 break;
468 myEdgeFile = value;
469 break;
471 myAggregate = parse<bool>(value);
472 break;
473 default:
474 setCommonAttribute(this, key, value);
475 break;
476 }
477}
478
479/****************************************************************************/
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:91
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)
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
void resetDefaultValues(const bool allowUndoRedo)
reset attribute carrier to their default values
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
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
std::vector< std::string > myVTypes
VTypes.
GNEMeanData(SumoXMLTag tag, std::string ID, GNENet *net, const std::string &filename)
Default constructor.
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 checkDrawDeleteContourSmall() const
check if draw delete contour small (pink/white)
bool checkDrawFromContour() const
check if draw from contour (green)
GNEHierarchicalElement * getHierarchicalElement()
get GNEHierarchicalElement associated with this AttributeCarrier
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:144
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 std::string & getDefaultStringValue(SumoXMLAttr attr) const
default values
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
const Parameterised::Map & getParametersMap() const
Returns the inner key/value map.
A point in 2D or 3D with translation and scaling methods.
Definition Position.h:37
static StringBijection< PersonMode > PersonModeValues
person modes
static StringBijection< ExcludeEmpty > ExcludeEmptys
exclude empty values
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
const std::string & getString(const T key) const
get string
bool hasString(const std::string &str) const
check if the given string exist