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
21#include <netedit/GNENet.h>
26
27#include "GNEDataSet.h"
28#include "GNEDataInterval.h"
29
30// ===========================================================================
31// member method definitions
32// ===========================================================================
33
34// ---------------------------------------------------------------------------
35// GNEDataSet::AttributeColors - methods
36// ---------------------------------------------------------------------------
37
40
41
42void
43GNEDataSet::AttributeColors::updateValues(const std::string& attribute, const double value) {
44 // check if exist
45 if (myMinMaxValue.count(attribute) == 0) {
46 myMinMaxValue[attribute] = std::make_pair(value, value);
47 } else {
48 // update min value
49 if (value < myMinMaxValue.at(attribute).first) {
50 myMinMaxValue.at(attribute).first = value;
51 }
52 // update max value
53 if (value > myMinMaxValue.at(attribute).second) {
54 myMinMaxValue.at(attribute).second = value;
55 }
56 }
57}
58
59
60void
62 // iterate over map
63 for (const auto& attributeColor : attributeColors.myMinMaxValue) {
64 if (myMinMaxValue.count(attributeColor.first) == 0) {
65 myMinMaxValue[attributeColor.first] = attributeColor.second;
66 } else {
67 // update min value
68 if (attributeColor.second.first < myMinMaxValue.at(attributeColor.first).first) {
69 myMinMaxValue.at(attributeColor.first).first = attributeColor.second.first;
70 }
71 // update max value
72 if (attributeColor.second.second > myMinMaxValue.at(attributeColor.first).second) {
73 myMinMaxValue.at(attributeColor.first).second = attributeColor.second.second;
74 }
75 }
76 }
77}
78
79
80bool
81GNEDataSet::AttributeColors::exist(const std::string& attribute) const {
82 return (myMinMaxValue.count(attribute) > 0);
83}
84
85
86double
87GNEDataSet::AttributeColors::getMinValue(const std::string& attribute) const {
88 return myMinMaxValue.at(attribute).first;
89}
90
91
92double
93GNEDataSet::AttributeColors::getMaxValue(const std::string& attribute) const {
94 return myMinMaxValue.at(attribute).second;
95}
96
97
98void
100 myMinMaxValue.clear();
101}
102
103// ---------------------------------------------------------------------------
104// GNEDataSet - methods
105// ---------------------------------------------------------------------------
106
107GNEDataSet::GNEDataSet(const std::string& dataSetID, GNENet* net, const std::string& filename) :
108 GNEAttributeCarrier(SUMO_TAG_DATASET, net, filename, false),
109 myDataSetID(dataSetID) {
110}
111
112
114
115
118 return this;
119}
120
121
124 return nullptr;
125}
126
127
130 return nullptr;
131}
132
133
134const Parameterised*
136 return nullptr;
137}
138
139
142 return nullptr;
143}
144
145
146const GUIGlObject*
148 return nullptr;
149}
150
151
152void
154 // first update attribute colors in data interval childrens
155 for (const auto& interval : myDataIntervalChildren) {
156 interval.second->updateAttributeColors();
157 }
158 // continue with data sets containers
161 // iterate over all data interval children
162 for (const auto& interval : myDataIntervalChildren) {
163 myAllAttributeColors.updateAllValues(interval.second->getAllAttributeColors());
164 }
165 // iterate over specificdata interval children
166 for (const auto& interval : myDataIntervalChildren) {
167 for (const auto& specificAttributeColor : interval.second->getSpecificAttributeColors()) {
168 mySpecificAttributeColors[specificAttributeColor.first].updateAllValues(specificAttributeColor.second);
169 }
170 }
171}
172
173
178
179
180const std::map<SumoXMLTag, GNEDataSet::AttributeColors>&
184
185
186void
188 // nothing to update
189}
190
191
194 return Position(0, 0);
195}
196
197
198void
200 // iterate over intervals
201 for (const auto& interval : myDataIntervalChildren) {
202 // open device
204 // write ID
205 device.writeAttr(SUMO_ATTR_ID, getID());
206 // write begin
207 device.writeAttr(SUMO_ATTR_BEGIN, interval.second->getAttribute(SUMO_ATTR_BEGIN));
208 // write end
209 device.writeAttr(SUMO_ATTR_END, interval.second->getAttribute(SUMO_ATTR_END));
210 // iterate over interval generic datas
211 for (const auto& genericData : interval.second->getGenericDataChildren()) {
212 // write generic data
213 genericData->writeGenericData(device);
214 }
215 // close device
216 device.closeTag();
217 }
218}
219
220
221bool
223 return false;
224}
225
226
227bool
229 return false;
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
269void
271 // check that dataInterval wasn't previously inserted
272 if (myDataIntervalChildren.count(dataInterval->getAttributeDouble(SUMO_ATTR_BEGIN)) == 0) {
273 // add data interval child
274 myDataIntervalChildren[dataInterval->getAttributeDouble(SUMO_ATTR_BEGIN)] = dataInterval;
275 // add reference in attributeCarriers
276 myNet->getAttributeCarriers()->insertDataInterval(dataInterval, dataInterval);
277 } else {
278 throw ProcessError(TL("DataInterval was already inserted"));
279 }
280}
281
282
283void
285 // check that dataInterval was previously inserted
286 if (myDataIntervalChildren.count(dataInterval->getAttributeDouble(SUMO_ATTR_BEGIN)) == 1) {
287 // remove data interval child
289 // remove it from inspected elements and GNEElementTree
292 // remove reference from attributeCarriers
294 } else {
295 throw ProcessError(TL("DataInterval wasn't previously inserted"));
296 }
297}
298
299
300bool
302 for (const auto& interval : myDataIntervalChildren) {
303 if (interval.second == dataInterval) {
304 return true;
305 }
306 }
307 return false;
308}
309
310void
312 // check that dataInterval was previously inserted
313 if (myDataIntervalChildren.count(oldBegin) == 1) {
314 // get data interval
315 GNEDataInterval* dataInterval = myDataIntervalChildren.at(oldBegin);
316 // insert again using new begin
317 myDataIntervalChildren[dataInterval->getAttributeDouble(SUMO_ATTR_BEGIN)] = dataInterval;
318 } else {
319 throw ProcessError(TL("DataInterval wasn't previously inserted"));
320 }
321}
322
323
324bool
325GNEDataSet::checkNewInterval(const double newBegin, const double newEnd) {
326 return checkNewInterval(myDataIntervalChildren, newBegin, newEnd);
327}
328
329
330bool
331GNEDataSet::checkNewBeginEnd(const GNEDataInterval* dataInterval, const double newBegin, const double newEnd) {
332 // make a copy of myDataIntervalChildren without dataInterval, and check checkNewInterval
333 std::map<const double, GNEDataInterval*> copyOfDataIntervalMap;
334 for (const auto& element : myDataIntervalChildren) {
335 if (element.second != dataInterval) {
336 copyOfDataIntervalMap.insert(element);
337 }
338 }
339 return checkNewInterval(copyOfDataIntervalMap, newBegin, newEnd);
340}
341
342
344GNEDataSet::retrieveInterval(const double begin, const double end) const {
345 if (myDataIntervalChildren.count(begin) == 0) {
346 return nullptr;
347 } else if (myDataIntervalChildren.at(begin)->getAttributeDouble(SUMO_ATTR_END) != end) {
348 return nullptr;
349 } else {
350 return myDataIntervalChildren.at(begin);
351 }
352}
353
354
355const std::map<const double, GNEDataInterval*>&
359
360
361std::string
363 switch (key) {
364 case SUMO_ATTR_ID:
365 return myDataSetID;
366 default:
367 return getCommonAttribute(key);
368 }
369}
370
371
372double
376
377
382
383
387
388
389void
390GNEDataSet::setAttribute(SumoXMLAttr key, const std::string& value, GNEUndoList* undoList) {
391 switch (key) {
392 case SUMO_ATTR_ID:
393 GNEChange_Attribute::changeAttribute(this, key, value, undoList);
394 break;
395 default:
396 setCommonAttribute(key, value, undoList);
397 break;
398 }
399}
400
401
402bool
403GNEDataSet::isValid(SumoXMLAttr key, const std::string& value) {
404 switch (key) {
405 case SUMO_ATTR_ID:
406 if (SUMOXMLDefinitions::isValidNetID(value) && (myNet->getAttributeCarriers()->retrieveDataSet(value, false) == nullptr)) {
407 return true;
408 } else {
409 return false;
410 }
411 default:
412 return isCommonAttributeValid(key, value);
413 }
414}
415
416
417std::string
419 return getTagStr();
420}
421
422
423std::string
425 return getTagStr() + ": " + myDataSetID;
426}
427
428
429void
430GNEDataSet::setAttribute(SumoXMLAttr key, const std::string& value) {
431 switch (key) {
432 case SUMO_ATTR_ID:
433 myDataSetID = value;
434 // update all intervals
435 for (const auto& interval : myDataIntervalChildren) {
436 interval.second->updateGenericDataIDs();
437 }
438 break;
439 default:
440 setCommonAttribute(key, value);
441 break;
442 }
443 // mark interval toolbar for update
445}
446
447
448bool
449GNEDataSet::checkNewInterval(const std::map<const double, GNEDataInterval*>& dataIntervalMap, const double newBegin, const double newEnd) {
450 if (dataIntervalMap.empty()) {
451 return true;
452 } else {
453 // declare first and last element
454 const auto itFirstElement = dataIntervalMap.begin();
455 const auto itLastElement = dataIntervalMap.rbegin();
456 if (newBegin > newEnd) {
457 return false;
458 } else if (dataIntervalMap.count(newBegin) == 1) {
459 return false;
460 } else if (newBegin < itFirstElement->first) {
461 return (newEnd <= itFirstElement->first);
462 } else if (newBegin > itLastElement->first) {
463 return (newBegin >= itLastElement->second->getAttributeDouble(SUMO_ATTR_END));
464 } else {
465 // iterate over myDataIntervalChildren
466 for (auto it = itFirstElement; it != dataIntervalMap.end(); it++) {
467 if (newBegin < it->first) {
468 // obtain previous edge
469 auto itPrevious = it;
470 itPrevious--;
471 // check overlapping with end
472 if (itPrevious->second->getAttributeDouble(SUMO_ATTR_END) < newBegin) {
473 return true;
474 }
475 }
476 }
477 }
478 return false;
479 }
480}
481
482/****************************************************************************/
#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
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
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:232
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:235
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:241
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:238
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(const std::string &dataSetID, GNENet *net, const std::string &filename)
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
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
GNEViewNet * getViewNet() const
get view net
Definition GNENet.cpp:2193
void uninspectAC(GNEAttributeCarrier *AC)
uninspect AC
GNEViewNetHelper::InspectedElements & getInspectedElements()
get inspected elements
GNEViewNetHelper::IntervalBar & getIntervalBar()
get interval bar
GNEViewParent * getViewParent() const
get the net object
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