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 std::string& type,
40 const SUMOTime period, 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 myType(type),
48 myPeriod(period),
49 myBegin(begin),
50 myEnd(end),
51 myTrackVehicles(trackVehicles),
52 myWrittenAttributes(writtenAttributes),
53 myAggregate(aggregate),
54 myEdges(edges),
55 myEdgeFile(edgeFile),
56 myExcludeEmpty(excludeEmpty),
57 myWithInternal(withInternal),
58 myDetectPersons(detectPersons),
59 myMinSamples(minSamples),
60 myMaxTravelTime(maxTravelTime),
61 myVTypes(vTypes),
62 mySpeedThreshold(speedThreshold) {
63 // set file
64 if (myFile.empty()) {
65 myFile = (myID + ".xml");
66 }
67}
68
69
71
72
77
78
81 return nullptr;
82}
83
84
87 return nullptr;
88}
89
90
91const Parameterised*
93 return nullptr;
94}
95
96
99 return nullptr;
100}
101
102
103const GUIGlObject*
105 return nullptr;
106}
107
108
109void
111 device.openTag(getTagProperty()->getTag());
112 // write needed attributes
113 device.writeAttr(SUMO_ATTR_ID, getID());
114 if (myFile.empty()) {
115 device.writeAttr(SUMO_ATTR_FILE, myID + ".xml");
116 } else {
118 }
119 // write optional attributes
122 }
125 }
128 }
131 }
134 }
135 if (myWithInternal) {
137 }
140 }
143 }
146 }
147 if (myVTypes.size() > 0) {
149 }
150 if (myTrackVehicles) {
152 }
155 }
156 if (myWrittenAttributes.size() > 0) {
158 }
159 if (myEdges.size() > 0) {
161 }
162 if (myEdgeFile.size() > 0) {
164 }
165 if (myAggregate) {
166 device.writeAttr(SUMO_ATTR_AGGREGATE, true);
167 }
168 device.closeTag();
169}
170
171
172void
174 // nothing to update
175}
176
177
180 return Position();
181}
182
183
184bool
186 return false;
187}
188
189
190bool
192 return false;
193}
194
195
196bool
198 return false;
199}
200
201
202bool
204 return false;
205}
206
207
208bool
210 return false;
211}
212
213
214bool
216 return false;
217}
218
219
220bool
222 return false;
223}
224
225
226bool
228 return false;
229}
230
231
232std::string
234 switch (key) {
235 case SUMO_ATTR_ID:
236 return myID;
237 case SUMO_ATTR_FILE:
238 return myFile;
239 case SUMO_ATTR_TYPE:
240 return myType;
241 case SUMO_ATTR_PERIOD:
243 return "";
244 } else {
245 return time2string(myPeriod);
246 }
247 case SUMO_ATTR_BEGIN:
249 return "";
250 } else {
251 return time2string(myBegin);
252 }
253 case SUMO_ATTR_END:
255 return "";
256 } else {
257 return time2string(myEnd);
258 }
260 return myExcludeEmpty;
262 return toString(myWithInternal);
266 return toString(myMinSamples);
269 case SUMO_ATTR_VTYPES:
270 return toString(myVTypes);
277 case SUMO_ATTR_EDGES:
278 return toString(myEdges);
280 return myEdgeFile;
282 return toString(myAggregate);
283 default:
284 return getCommonAttribute(key);
285 }
286}
287
288
289double
293
294
299
300
305
306
307void
308GNEMeanData::setAttribute(SumoXMLAttr key, const std::string& value, GNEUndoList* undoList) {
309 if (value == getAttribute(key)) {
310 return; //avoid needless changes, later logic relies on the fact that attributes have changed
311 }
312 switch (key) {
313 case SUMO_ATTR_ID:
314 case SUMO_ATTR_FILE:
315 case SUMO_ATTR_TYPE:
316 case SUMO_ATTR_PERIOD:
317 case SUMO_ATTR_BEGIN:
318 case SUMO_ATTR_END:
324 case SUMO_ATTR_VTYPES:
328 case SUMO_ATTR_EDGES:
331 GNEChange_Attribute::changeAttribute(this, key, value, undoList);
332 break;
333 default:
334 setCommonAttribute(key, value, undoList);
335 break;
336 }
337}
338
339
340bool
341GNEMeanData::isValid(SumoXMLAttr key, const std::string& value) {
342 switch (key) {
343 case SUMO_ATTR_ID:
344 return SUMOXMLDefinitions::isValidNetID(value) && (myNet->getAttributeCarriers()->retrieveMeanData(myTagProperty->getTag(), value, false) == nullptr);
345 case SUMO_ATTR_FILE:
347 case SUMO_ATTR_TYPE:
349 case SUMO_ATTR_PERIOD:
350 case SUMO_ATTR_BEGIN:
351 case SUMO_ATTR_END:
352 if (value.empty()) {
353 return true;
354 } else {
355 return (canParse<SUMOTime>(value) && (parse<SUMOTime>(value) >= 0));
356 }
358 if (canParse<bool>(value)) {
359 return true;
360 } else {
362 }
364 return (canParse<bool>(value));
366 if (value.empty()) {
367 return true;
368 } else {
369 return (canParse<double>(value) && (parse<double>(value) >= 0));
370 }
372 return (canParse<double>(value) && (parse<double>(value) >= 0));
374 return (canParse<double>(value) && (parse<double>(value) >= 0));
375 case SUMO_ATTR_VTYPES:
376 return true;
378 return (canParse<bool>(value));
380 if (value.empty()) {
381 return true;
382 } else {
384 }
386 return canParse<std::vector<SumoXMLAttr> >(value);
387 case SUMO_ATTR_EDGES:
388 return canParse<std::vector<GNEEdge*> >(myNet, value, false);
392 return (canParse<bool>(value));
393 default:
394 return isCommonAttributeValid(key, value);
395 }
396}
397
398
399std::string
401 return getTagStr();
402}
403
404
405std::string
407 return getTagStr();
408}
409
410
411void
412GNEMeanData::setAttribute(SumoXMLAttr key, const std::string& value) {
413 switch (key) {
414 case SUMO_ATTR_ID:
416 myID = value;
417 break;
418 case SUMO_ATTR_FILE:
419 if (value.empty()) {
420 myFile = (myID + ".xml");
421 } else {
422 myFile = value;
423 }
424 break;
425 case SUMO_ATTR_TYPE:
426 myType = value;
427 break;
428 case SUMO_ATTR_PERIOD:
429 if (value.empty()) {
431 } else {
432 myPeriod = string2time(value);
433 }
434 break;
435 case SUMO_ATTR_BEGIN:
436 if (value.empty()) {
438 } else {
439 myBegin = string2time(value);
440 }
441 break;
442 case SUMO_ATTR_END:
443 if (value.empty()) {
445 } else {
446 myEnd = string2time(value);
447 }
448 break;
451 myExcludeEmpty = value;
452 } else if (parse<bool>(value)) {
454 } else {
456 }
457 break;
459 myWithInternal = parse<bool>(value);
460 break;
462 if (value.empty()) {
464 } else {
465 myMaxTravelTime = parse<double>(value);
466 }
467 break;
469 if (value.empty()) {
471 } else {
472 myMinSamples = parse<double>(value);
473 }
474 break;
476 if (value.empty()) {
478 } else {
479 mySpeedThreshold = parse<double>(value);
480 }
481 break;
482 case SUMO_ATTR_VTYPES:
483 myVTypes = parse<std::vector<std::string> >(value);
484 break;
486 myTrackVehicles = parse<bool>(value);
487 break;
489 myDetectPersons.clear();
490 if (value.empty()) {
492 } else {
493 myDetectPersons = parse<std::vector<std::string> >(value);
494 }
495 break;
497 myWrittenAttributes = parse<std::vector<SumoXMLAttr> >(value);
498 break;
499 case SUMO_ATTR_EDGES:
500 myEdges = parse<std::vector<std::string> >(value);
501 break;
503 myEdgeFile = value;
504 break;
506 myAggregate = parse<bool>(value);
507 break;
508 default:
509 setCommonAttribute(key, value);
510 break;
511 }
512}
513
514/****************************************************************************/
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: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)
double getCommonAttributeDouble(SumoXMLAttr key) const
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, const std::string &filename)
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.
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.
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