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
23#include <netedit/GNENet.h>
25
26#include "GNEMeanData.h"
27
28// ===========================================================================
29// member method definitions
30// ===========================================================================
31
32GNEMeanData::GNEMeanData(SumoXMLTag tag, std::string ID, GNENet* net, FileBucket* fileBucket) :
33 GNEAttributeCarrier(tag, net, fileBucket),
34 myID(ID) {
35 // reset default values
36 resetDefaultValues(false);
37}
38
39
40GNEMeanData::GNEMeanData(SumoXMLTag tag, std::string ID, GNENet* net, FileBucket* fileBucket, const std::string& file,
41 const std::string& type, const SUMOTime period, const SUMOTime begin, const SUMOTime end,
42 const bool trackVehicles, const std::vector<SumoXMLAttr>& writtenAttributes, const bool aggregate,
43 const std::vector<std::string>& edges, const std::string& edgeFile, const std::string& excludeEmpty,
44 const bool withInternal, const std::vector<std::string>& detectPersons, const double minSamples,
45 const double maxTravelTime, const std::vector<std::string>& vTypes, const double speedThreshold) :
46 GNEAttributeCarrier(tag, net, fileBucket),
47 myID(ID),
48 myFile(file),
49 myType(type),
50 myPeriod(period),
51 myBegin(begin),
52 myEnd(end),
53 myTrackVehicles(trackVehicles),
54 myWrittenAttributes(writtenAttributes),
55 myAggregate(aggregate),
56 myEdges(edges),
57 myEdgeFile(edgeFile),
58 myExcludeEmpty(excludeEmpty),
59 myWithInternal(withInternal),
60 myDetectPersons(detectPersons),
61 myMinSamples(minSamples),
62 myMaxTravelTime(maxTravelTime),
63 myVTypes(vTypes),
64 mySpeedThreshold(speedThreshold) {
65 // set file
66 if (myFile.empty()) {
67 myFile = (myID + ".xml");
68 }
69}
70
71
73
74
79
80
83 return nullptr;
84}
85
86
89 return nullptr;
90}
91
92
93const Parameterised*
95 return nullptr;
96}
97
98
101 return nullptr;
102}
103
104
105const GUIGlObject*
107 return nullptr;
108}
109
110
113 return myFileBucket;
114}
115
116
117void
119 device.openTag(getTagProperty()->getTag());
120 // write needed attributes
121 device.writeAttr(SUMO_ATTR_ID, getID());
122 if (myFile.empty()) {
123 device.writeAttr(SUMO_ATTR_FILE, myID + ".xml");
124 } else {
126 }
127 // write optional attributes
130 }
133 }
136 }
139 }
142 }
143 if (myWithInternal) {
145 }
148 }
151 }
154 }
155 if (myVTypes.size() > 0) {
157 }
158 if (myTrackVehicles) {
160 }
163 }
164 if (myWrittenAttributes.size() > 0) {
166 }
167 if (myEdges.size() > 0) {
169 }
170 if (myEdgeFile.size() > 0) {
172 }
173 if (myAggregate) {
174 device.writeAttr(SUMO_ATTR_AGGREGATE, true);
175 }
176 device.closeTag();
177}
178
179
180void
182 // nothing to update
183}
184
185
188 return Position();
189}
190
191
192bool
194 return false;
195}
196
197
198bool
200 return false;
201}
202
203
204bool
206 return false;
207}
208
209
210bool
212 return false;
213}
214
215
216bool
218 return false;
219}
220
221
222bool
224 return false;
225}
226
227
228bool
230 return false;
231}
232
233
234bool
236 return false;
237}
238
239
240std::string
242 switch (key) {
243 case SUMO_ATTR_ID:
244 return myID;
245 case SUMO_ATTR_FILE:
246 return myFile;
247 case SUMO_ATTR_TYPE:
248 return myType;
249 case SUMO_ATTR_PERIOD:
251 return "";
252 } else {
253 return time2string(myPeriod);
254 }
255 case SUMO_ATTR_BEGIN:
257 return "";
258 } else {
259 return time2string(myBegin);
260 }
261 case SUMO_ATTR_END:
263 return "";
264 } else {
265 return time2string(myEnd);
266 }
268 return myExcludeEmpty;
270 return toString(myWithInternal);
274 return toString(myMinSamples);
277 case SUMO_ATTR_VTYPES:
278 return toString(myVTypes);
285 case SUMO_ATTR_EDGES:
286 return toString(myEdges);
288 return myEdgeFile;
290 return toString(myAggregate);
291 default:
292 return getCommonAttribute(key);
293 }
294}
295
296
297double
301
302
307
308
313
314
315void
316GNEMeanData::setAttribute(SumoXMLAttr key, const std::string& value, GNEUndoList* undoList) {
317 if (value == getAttribute(key)) {
318 return; //avoid needless changes, later logic relies on the fact that attributes have changed
319 }
320 switch (key) {
321 case SUMO_ATTR_ID:
322 case SUMO_ATTR_FILE:
323 case SUMO_ATTR_TYPE:
324 case SUMO_ATTR_PERIOD:
325 case SUMO_ATTR_BEGIN:
326 case SUMO_ATTR_END:
332 case SUMO_ATTR_VTYPES:
336 case SUMO_ATTR_EDGES:
339 GNEChange_Attribute::changeAttribute(this, key, value, undoList);
340 break;
341 default:
342 setCommonAttribute(key, value, undoList);
343 break;
344 }
345}
346
347
348bool
349GNEMeanData::isValid(SumoXMLAttr key, const std::string& value) {
350 switch (key) {
351 case SUMO_ATTR_ID:
352 return SUMOXMLDefinitions::isValidNetID(value) && (myNet->getAttributeCarriers()->retrieveMeanData(myTagProperty->getTag(), value, false) == nullptr);
353 case SUMO_ATTR_FILE:
355 case SUMO_ATTR_TYPE:
357 case SUMO_ATTR_PERIOD:
358 case SUMO_ATTR_BEGIN:
359 case SUMO_ATTR_END:
360 if (value.empty()) {
361 return true;
362 } else {
363 return (canParse<SUMOTime>(value) && (parse<SUMOTime>(value) >= 0));
364 }
366 if (canParse<bool>(value)) {
367 return true;
368 } else {
370 }
372 return (canParse<bool>(value));
374 if (value.empty()) {
375 return true;
376 } else {
377 return (canParse<double>(value) && (parse<double>(value) >= 0));
378 }
380 return (canParse<double>(value) && (parse<double>(value) >= 0));
382 return (canParse<double>(value) && (parse<double>(value) >= 0));
383 case SUMO_ATTR_VTYPES:
384 return true;
386 return (canParse<bool>(value));
388 if (value.empty()) {
389 return true;
390 } else {
392 }
394 return canParse<std::vector<SumoXMLAttr> >(value);
395 case SUMO_ATTR_EDGES:
396 return canParse<std::vector<GNEEdge*> >(myNet, value, false);
400 return (canParse<bool>(value));
401 default:
402 return isCommonAttributeValid(key, value);
403 }
404}
405
406
407std::string
409 return getTagStr();
410}
411
412
413std::string
415 return getTagStr();
416}
417
418
419void
420GNEMeanData::setAttribute(SumoXMLAttr key, const std::string& value) {
421 switch (key) {
422 case SUMO_ATTR_ID:
424 myID = value;
425 break;
426 case SUMO_ATTR_FILE:
427 if (value.empty()) {
428 myFile = (myID + ".xml");
429 } else {
430 myFile = value;
431 }
432 break;
433 case SUMO_ATTR_TYPE:
434 myType = value;
435 break;
436 case SUMO_ATTR_PERIOD:
437 if (value.empty()) {
439 } else {
440 myPeriod = string2time(value);
441 }
442 break;
443 case SUMO_ATTR_BEGIN:
444 if (value.empty()) {
446 } else {
447 myBegin = string2time(value);
448 }
449 break;
450 case SUMO_ATTR_END:
451 if (value.empty()) {
453 } else {
454 myEnd = string2time(value);
455 }
456 break;
459 myExcludeEmpty = value;
460 } else if (parse<bool>(value)) {
462 } else {
464 }
465 break;
467 myWithInternal = parse<bool>(value);
468 break;
470 if (value.empty()) {
472 } else {
473 myMaxTravelTime = parse<double>(value);
474 }
475 break;
477 if (value.empty()) {
479 } else {
480 myMinSamples = parse<double>(value);
481 }
482 break;
484 if (value.empty()) {
486 } else {
487 mySpeedThreshold = parse<double>(value);
488 }
489 break;
490 case SUMO_ATTR_VTYPES:
491 myVTypes = parse<std::vector<std::string> >(value);
492 break;
494 myTrackVehicles = parse<bool>(value);
495 break;
497 myDetectPersons.clear();
498 if (value.empty()) {
500 } else {
501 myDetectPersons = parse<std::vector<std::string> >(value);
502 }
503 break;
505 myWrittenAttributes = parse<std::vector<SumoXMLAttr> >(value);
506 break;
507 case SUMO_ATTR_EDGES:
508 myEdges = parse<std::vector<std::string> >(value);
509 break;
511 myEdgeFile = value;
512 break;
514 myAggregate = parse<bool>(value);
515 break;
516 default:
517 setCommonAttribute(key, value);
518 break;
519 }
520}
521
522/****************************************************************************/
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_TYPE
@ 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:289
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
Definition ToString.h:46
double getCommonAttributeDouble(SumoXMLAttr key) const
FileBucket * myFileBucket
filebucket vinculated whith this AC
const std::string getID() const override
get ID (all Attribute Carriers have one)
PositionVector getCommonAttributePositionVector(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
Position getCommonAttributePosition(SumoXMLAttr key) const
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 isCommonAttributeValid(SumoXMLAttr key, const std::string &value) const
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
GUIGlObject * getGUIGlObject() override
get GUIGlObject associated with this meanData
std::string myExcludeEmpty
exclude empty
std::string myEdgeFile
edge file
void updateGeometry() override
update pre-computed geometry information
Parameterised * getParameters() override
get parameters associated with this meanData
SUMOTime myEnd
end
bool myAggregate
whether the data for all edges shall be aggregated
bool checkDrawMoveContour() const override
check if draw move contour (red)
bool checkDrawRelatedContour() const override
check if draw related contour (cyan)
std::string getHierarchyName() const override
get Hierarchy Name (Used in AC Hierarchy)
std::vector< std::string > myDetectPersons
detect persons
std::vector< std::string > myVTypes
VTypes.
bool checkDrawDeleteContourSmall() const override
check if draw delete contour small (pink/white)
PositionVector getAttributePositionVector(SumoXMLAttr key) const override
std::string getAttribute(SumoXMLAttr key) const override
GNEMeanData(SumoXMLTag tag, std::string ID, GNENet *net, FileBucket *fileBucket)
Default constructor.
SUMOTime myPeriod
period
std::vector< SumoXMLAttr > myWrittenAttributes
bit mask for checking attributes to be written
std::string myFile
filename
std::string myID
id
double mySpeedThreshold
speed threshold
bool checkDrawDeleteContour() const override
check if draw delete contour (pink/white)
std::vector< std::string > myEdges
list of edges
bool checkDrawToContour() const override
check if draw from contour (magenta)
GNEHierarchicalElement * getHierarchicalElement() override
methods to retrieve the elements linked to this meanData
std::string getPopUpID() const override
get PopPup ID (Used in AC Hierarchy)
bool myWithInternal
width internal
bool myTrackVehicles
Whether vehicles are tracked.
bool checkDrawOverContour() const override
check if draw over contour (orange)
bool isValid(SumoXMLAttr key, const std::string &value) override
method for checking if the key and their conrrespond attribute are valids
std::string myType
type
double getAttributeDouble(SumoXMLAttr key) const override
void setAttribute(SumoXMLAttr key, const std::string &value, GNEUndoList *undoList) override
method for setting the attribute and letting the object perform data set changes
GNEMoveElement * getMoveElement() const override
get GNEMoveElement associated with this meanData
bool checkDrawSelectContour() const override
check if draw select contour (blue)
Position getAttributePosition(SumoXMLAttr key) const override
bool checkDrawFromContour() const override
check if draw from contour (green)
Position getPositionInView() const
Returns element position in view.
FileBucket * getFileBucket() const override
get reference to fileBucket in which save this AC
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
GNENetHelper::AttributeCarriers * getAttributeCarriers() const
get all attribute carriers used in this net
Definition GNENet.cpp:174
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.
An upper class for objects with additional parameters.
A point in 2D or 3D with translation and scaling methods.
Definition Position.h:37
A list of positions.
static StringBijection< MeanDataType > MeanDataTypes
reference positions (used creating certain elements in netedit)
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