Eclipse SUMO - Simulation of Urban MObility
Loading...
Searching...
No Matches
GNEDataSet.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// A abstract class for data sets
19/****************************************************************************/
20
25#include <netedit/GNENet.h>
27
28#include "GNEDataSet.h"
29#include "GNEDataInterval.h"
30
31// ===========================================================================
32// member method definitions
33// ===========================================================================
34
35// ---------------------------------------------------------------------------
36// GNEDataSet::AttributeColors - methods
37// ---------------------------------------------------------------------------
38
41
42
43void
44GNEDataSet::AttributeColors::updateValues(const std::string& attribute, const double value) {
45 // check if exist
46 if (myMinMaxValue.count(attribute) == 0) {
47 myMinMaxValue[attribute] = std::make_pair(value, value);
48 } else {
49 // update min value
50 if (value < myMinMaxValue.at(attribute).first) {
51 myMinMaxValue.at(attribute).first = value;
52 }
53 // update max value
54 if (value > myMinMaxValue.at(attribute).second) {
55 myMinMaxValue.at(attribute).second = value;
56 }
57 }
58}
59
60
61void
63 // iterate over map
64 for (const auto& attributeColor : attributeColors.myMinMaxValue) {
65 if (myMinMaxValue.count(attributeColor.first) == 0) {
66 myMinMaxValue[attributeColor.first] = attributeColor.second;
67 } else {
68 // update min value
69 if (attributeColor.second.first < myMinMaxValue.at(attributeColor.first).first) {
70 myMinMaxValue.at(attributeColor.first).first = attributeColor.second.first;
71 }
72 // update max value
73 if (attributeColor.second.second > myMinMaxValue.at(attributeColor.first).second) {
74 myMinMaxValue.at(attributeColor.first).second = attributeColor.second.second;
75 }
76 }
77 }
78}
79
80
81bool
82GNEDataSet::AttributeColors::exist(const std::string& attribute) const {
83 return (myMinMaxValue.count(attribute) > 0);
84}
85
86
87double
88GNEDataSet::AttributeColors::getMinValue(const std::string& attribute) const {
89 return myMinMaxValue.at(attribute).first;
90}
91
92
93double
94GNEDataSet::AttributeColors::getMaxValue(const std::string& attribute) const {
95 return myMinMaxValue.at(attribute).second;
96}
97
98
99void
101 myMinMaxValue.clear();
102}
103
104// ---------------------------------------------------------------------------
105// GNEDataSet - methods
106// ---------------------------------------------------------------------------
107
111
112
113GNEDataSet::GNEDataSet(const std::string& dataSetID, GNENet* net, FileBucket* fileBucket) :
114 GNEAttributeCarrier(SUMO_TAG_DATASET, net, fileBucket),
115 myDataSetID(dataSetID) {
116}
117
118
120
121
124 return this;
125}
126
127
130 return nullptr;
131}
132
133
136 return nullptr;
137}
138
139
140const Parameterised*
142 return nullptr;
143}
144
145
148 return nullptr;
149}
150
151
152const GUIGlObject*
154 return nullptr;
155}
156
157
160 return myFileBucket;
161}
162
163
164void
166 // first update attribute colors in data interval childrens
167 for (const auto& interval : myDataIntervalChildren) {
168 interval.second->updateAttributeColors();
169 }
170 // continue with data sets containers
173 // iterate over all data interval children
174 for (const auto& interval : myDataIntervalChildren) {
175 myAllAttributeColors.updateAllValues(interval.second->getAllAttributeColors());
176 }
177 // iterate over specificdata interval children
178 for (const auto& interval : myDataIntervalChildren) {
179 for (const auto& specificAttributeColor : interval.second->getSpecificAttributeColors()) {
180 mySpecificAttributeColors[specificAttributeColor.first].updateAllValues(specificAttributeColor.second);
181 }
182 }
183}
184
185
190
191
192const std::map<SumoXMLTag, GNEDataSet::AttributeColors>&
196
197
198void
200 // nothing to update
201}
202
203
206 return Position(0, 0);
207}
208
209
210void
212 // iterate over intervals
213 for (const auto& interval : myDataIntervalChildren) {
214 // open device
216 // write ID
217 device.writeAttr(SUMO_ATTR_ID, getID());
218 // write begin
219 device.writeAttr(SUMO_ATTR_BEGIN, interval.second->getAttribute(SUMO_ATTR_BEGIN));
220 // write end
221 device.writeAttr(SUMO_ATTR_END, interval.second->getAttribute(SUMO_ATTR_END));
222 // iterate over interval generic datas
223 for (const auto& genericData : interval.second->getGenericDataChildren()) {
224 // write generic data
225 genericData->writeGenericData(device);
226 }
227 // close device
228 device.closeTag();
229 }
230}
231
232
233bool
235 return false;
236}
237
238
239bool
241 return false;
242}
243
244
245bool
247 return false;
248}
249
250
251bool
253 return false;
254}
255
256
257bool
259 return false;
260}
261
262
263bool
265 return false;
266}
267
268
269bool
271 return false;
272}
273
274
275bool
277 return false;
278}
279
280
281void
283 // check that dataInterval wasn't previously inserted
284 if (myDataIntervalChildren.count(dataInterval->getAttributeDouble(SUMO_ATTR_BEGIN)) == 0) {
285 // add data interval child
286 myDataIntervalChildren[dataInterval->getAttributeDouble(SUMO_ATTR_BEGIN)] = dataInterval;
287 // add reference in attributeCarriers
288 myNet->getAttributeCarriers()->insertDataInterval(dataInterval, dataInterval);
289 } else {
290 throw ProcessError(TL("DataInterval was already inserted"));
291 }
292}
293
294
295void
297 // check that dataInterval was previously inserted
298 if (myDataIntervalChildren.count(dataInterval->getAttributeDouble(SUMO_ATTR_BEGIN)) == 1) {
299 // remove data interval child
301 // remove it from inspected elements and GNEElementTree
304 // remove reference from attributeCarriers
306 } else {
307 throw ProcessError(TL("DataInterval wasn't previously inserted"));
308 }
309}
310
311
312bool
314 for (const auto& interval : myDataIntervalChildren) {
315 if (interval.second == dataInterval) {
316 return true;
317 }
318 }
319 return false;
320}
321
322void
324 // check that dataInterval was previously inserted
325 if (myDataIntervalChildren.count(oldBegin) == 1) {
326 // get data interval
327 GNEDataInterval* dataInterval = myDataIntervalChildren.at(oldBegin);
328 // insert again using new begin
329 myDataIntervalChildren[dataInterval->getAttributeDouble(SUMO_ATTR_BEGIN)] = dataInterval;
330 } else {
331 throw ProcessError(TL("DataInterval wasn't previously inserted"));
332 }
333}
334
335
336bool
337GNEDataSet::checkNewInterval(const double newBegin, const double newEnd) {
338 return checkNewInterval(myDataIntervalChildren, newBegin, newEnd);
339}
340
341
342bool
343GNEDataSet::checkNewBeginEnd(const GNEDataInterval* dataInterval, const double newBegin, const double newEnd) {
344 // make a copy of myDataIntervalChildren without dataInterval, and check checkNewInterval
345 std::map<const double, GNEDataInterval*> copyOfDataIntervalMap;
346 for (const auto& element : myDataIntervalChildren) {
347 if (element.second != dataInterval) {
348 copyOfDataIntervalMap.insert(element);
349 }
350 }
351 return checkNewInterval(copyOfDataIntervalMap, newBegin, newEnd);
352}
353
354
356GNEDataSet::retrieveInterval(const double begin, const double end) const {
357 if (myDataIntervalChildren.count(begin) == 0) {
358 return nullptr;
359 } else if (myDataIntervalChildren.at(begin)->getAttributeDouble(SUMO_ATTR_END) != end) {
360 return nullptr;
361 } else {
362 return myDataIntervalChildren.at(begin);
363 }
364}
365
366
367const std::map<const double, GNEDataInterval*>&
371
372
373std::string
375 switch (key) {
376 case SUMO_ATTR_ID:
377 return myDataSetID;
378 default:
379 return getCommonAttribute(key);
380 }
381}
382
383
384double
388
389
394
395
399
400
401void
402GNEDataSet::setAttribute(SumoXMLAttr key, const std::string& value, GNEUndoList* undoList) {
403 switch (key) {
404 case SUMO_ATTR_ID:
405 GNEChange_Attribute::changeAttribute(this, key, value, undoList);
406 break;
407 default:
408 setCommonAttribute(key, value, undoList);
409 break;
410 }
411}
412
413
414bool
415GNEDataSet::isValid(SumoXMLAttr key, const std::string& value) {
416 switch (key) {
417 case SUMO_ATTR_ID:
418 if (SUMOXMLDefinitions::isValidNetID(value) && (myNet->getAttributeCarriers()->retrieveDataSet(value, false) == nullptr)) {
419 return true;
420 } else {
421 return false;
422 }
423 default:
424 return isCommonAttributeValid(key, value);
425 }
426}
427
428
429std::string
431 return getTagStr();
432}
433
434
435std::string
437 return getTagStr() + ": " + myDataSetID;
438}
439
440
441void
442GNEDataSet::setAttribute(SumoXMLAttr key, const std::string& value) {
443 switch (key) {
444 case SUMO_ATTR_ID:
445 myDataSetID = value;
446 // update all intervals
447 for (const auto& interval : myDataIntervalChildren) {
448 interval.second->updateGenericDataIDs();
449 }
450 break;
451 default:
452 setCommonAttribute(key, value);
453 break;
454 }
455 // mark interval toolbar for update
456 if (!isTemplate()) {
458 }
459}
460
461
462bool
463GNEDataSet::checkNewInterval(const std::map<const double, GNEDataInterval*>& dataIntervalMap, const double newBegin, const double newEnd) {
464 if (dataIntervalMap.empty()) {
465 return true;
466 } else {
467 // declare first and last element
468 const auto itFirstElement = dataIntervalMap.begin();
469 const auto itLastElement = dataIntervalMap.rbegin();
470 if (newBegin > newEnd) {
471 return false;
472 } else if (dataIntervalMap.count(newBegin) == 1) {
473 return false;
474 } else if (newBegin < itFirstElement->first) {
475 return (newEnd <= itFirstElement->first);
476 } else if (newBegin > itLastElement->first) {
477 return (newBegin >= itLastElement->second->getAttributeDouble(SUMO_ATTR_END));
478 } else {
479 // iterate over myDataIntervalChildren
480 for (auto it = itFirstElement; it != dataIntervalMap.end(); it++) {
481 if (newBegin < it->first) {
482 // obtain previous edge
483 auto itPrevious = it;
484 itPrevious--;
485 // check overlapping with end
486 if (itPrevious->second->getAttributeDouble(SUMO_ATTR_END) < newBegin) {
487 return true;
488 }
489 }
490 }
491 }
492 return false;
493 }
494}
495
496/****************************************************************************/
#define TL(string)
Definition MsgHandler.h:304
@ SUMO_TAG_INTERVAL
an aggreagated-output interval
@ SUMO_TAG_DATASET
SumoXMLAttr
Numbers representing SUMO-XML - attributes.
@ SUMO_ATTR_BEGIN
weights: time range begin
@ SUMO_ATTR_END
weights: time range end
@ SUMO_ATTR_ID
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
bool isTemplate() const
check if this AC is template
Position getCommonAttributePosition(SumoXMLAttr key) const
GNENet * myNet
pointer to net
bool isCommonAttributeValid(SumoXMLAttr key, const std::string &value) const
std::string getCommonAttribute(SumoXMLAttr key) const
static void changeAttribute(GNEAttributeCarrier *AC, SumoXMLAttr key, const std::string &value, GNEUndoList *undoList, const bool force=false)
change attribute
double getAttributeDouble(SumoXMLAttr key) const override
std::map< std::string, std::pair< double, double > > myMinMaxValue
map with the minimum and maximum value
Definition GNEDataSet.h:68
void updateAllValues(const AttributeColors &attributeColors)
update value for all attributes
bool exist(const std::string &attribute) const
check if given attribute exist (needed for non-double attributes)
double getMaxValue(const std::string &attribute) const
get maximum value
AttributeColors()
default constructor
double getMinValue(const std::string &attribute) const
get minimum value
void clear()
clear AttributeColors
void updateValues(const std::string &attribute, const double value)
update value for an specific attribute
Position getPositionInView() const
Returns element position in view.
bool checkDrawSelectContour() const override
check if draw select contour (blue)
bool checkDrawDeleteContourSmall() const override
check if draw delete contour small (pink/white)
bool checkDrawToContour() const override
check if draw from contour (magenta)
void writeDataSet(OutputDevice &device) const
write data set
std::string myDataSetID
dataSet ID
Definition GNEDataSet.h:240
bool dataIntervalChildrenExist(GNEDataInterval *dataInterval) const
check if given data interval exist
Parameterised * getParameters() override
get parameters associated with this dataSet
std::map< const double, GNEDataInterval * > myDataIntervalChildren
map with dataIntervals children sorted by begin
Definition GNEDataSet.h:243
std::string getPopUpID() const override
get PopPup ID (Used in AC Hierarchy)
void removeDataIntervalChild(GNEDataInterval *dataInterval)
add data interval child
GNEDataInterval * retrieveInterval(const double begin, const double end) const
return interval
GNEMoveElement * getMoveElement() const override
get GNEMoveElement associated with this dataSet
GUIGlObject * getGUIGlObject() override
get GUIGlObject associated with this dataSet
~GNEDataSet()
Destructor.
const GNEDataSet::AttributeColors & getAllAttributeColors() const
all attribute colors
void updateAttributeColors()
update attribute colors deprecated
GNEHierarchicalElement * getHierarchicalElement() override
methods to retrieve the elements linked to this dataSet
bool checkDrawOverContour() const override
check if draw over contour (orange)
void updateGeometry() override
update pre-computed geometry information
bool isValid(SumoXMLAttr key, const std::string &value) override
method for checking if the key and their conrrespond attribute are valids
std::string getHierarchyName() const override
get Hierarchy Name (Used in AC Hierarchy)
std::map< SumoXMLTag, GNEDataSet::AttributeColors > mySpecificAttributeColors
specific attribute colors
Definition GNEDataSet.h:249
void setAttribute(SumoXMLAttr key, const std::string &value, GNEUndoList *undoList) override
method for setting the attribute and letting the object perform data element changes
double getAttributeDouble(SumoXMLAttr key) const override
bool checkNewBeginEnd(const GNEDataInterval *dataInterval, const double newBegin, const double newEnd)
check if new begin or end for given GNEDataInterval is given
bool checkDrawDeleteContour() const override
check if draw delete contour (pink/white)
GNEDataSet::AttributeColors myAllAttributeColors
all attribute colors
Definition GNEDataSet.h:246
FileBucket * getFileBucket() const override
get reference to fileBucket in which save this AC
const std::map< SumoXMLTag, GNEDataSet::AttributeColors > & getSpecificAttributeColors() const
specific attribute colors
bool checkDrawFromContour() const override
check if draw from contour (green)
std::string getAttribute(SumoXMLAttr key) const override
const std::map< const double, GNEDataInterval * > & getDataIntervalChildren() const
get data interval children
bool checkNewInterval(const double newBegin, const double newEnd)
check if a new GNEDataInterval with the given begin and end can be inserted in current GNEDataSet
PositionVector getAttributePositionVector(SumoXMLAttr key) const override
bool checkDrawMoveContour() const override
check if draw move contour (red)
bool checkDrawRelatedContour() const override
check if draw related contour (cyan)
Position getAttributePosition(SumoXMLAttr key) const override
void addDataIntervalChild(GNEDataInterval *dataInterval)
add data interval child
GNEDataSet(GNENet *net)
Constructor.
void updateDataIntervalBegin(const double oldBegin)
update data interval begin
void removeCurrentEditedAttributeCarrier(const GNEAttributeCarrier *HE)
if given AttributeCarrier is the same of myHE, set it as nullptr
GNEElementTree * getHierarchicalElementTree() const
get GNEElementTree modul
void insertDataInterval(const GNEAttributeCarrier *AC, GNEDataInterval *dataInterval)
insert data interval in container
GNEDataSet * retrieveDataSet(const std::string &id, bool hardFail=true) const
Returns the named data set.
void deleteDataInterval(GNEDataInterval *dataInterval)
delete data interval of container
GNENetHelper::AttributeCarriers * getAttributeCarriers() const
get all attribute carriers used in this net
Definition GNENet.cpp:174
GNEViewParent * getViewParent() const
get view parent (used for simplify code)
Definition GNENet.cpp:150
GNEViewNet * getViewNet() const
get view net (used for simplify code)
Definition GNENet.cpp:144
void uninspectAC(GNEAttributeCarrier *AC)
uninspect AC
GNEViewNetHelper::InspectedElements & getInspectedElements()
get inspected elements
GNEViewNetHelper::IntervalBar & getIntervalBar()
get interval bar
GNEInspectorFrame * getInspectorFrame() const
get frame for inspect elements
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 bool isValidNetID(const std::string &value)
whether the given string is a valid id for a network element