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-2024 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
22// ===========================================================================
23// included modules
24// ===========================================================================
25#include <config.h>
26
27#include <netedit/GNENet.h>
28#include <netedit/GNEViewNet.h>
30#include <netedit/GNEUndoList.h>
33
34#include "GNEDataSet.h"
35#include "GNEDataInterval.h"
36
37
38// ===========================================================================
39// member method definitions
40// ===========================================================================
41
42// ---------------------------------------------------------------------------
43// GNEDataSet::AttributeColors - methods
44// ---------------------------------------------------------------------------
45
48
49
50void
51GNEDataSet::AttributeColors::updateValues(const std::string& attribute, const double value) {
52 // check if exist
53 if (myMinMaxValue.count(attribute) == 0) {
54 myMinMaxValue[attribute] = std::make_pair(value, value);
55 } else {
56 // update min value
57 if (value < myMinMaxValue.at(attribute).first) {
58 myMinMaxValue.at(attribute).first = value;
59 }
60 // update max value
61 if (value > myMinMaxValue.at(attribute).second) {
62 myMinMaxValue.at(attribute).second = value;
63 }
64 }
65}
66
67
68void
70 // iterate over map
71 for (const auto& attributeColor : attributeColors.myMinMaxValue) {
72 if (myMinMaxValue.count(attributeColor.first) == 0) {
73 myMinMaxValue[attributeColor.first] = attributeColor.second;
74 } else {
75 // update min value
76 if (attributeColor.second.first < myMinMaxValue.at(attributeColor.first).first) {
77 myMinMaxValue.at(attributeColor.first).first = attributeColor.second.first;
78 }
79 // update max value
80 if (attributeColor.second.second > myMinMaxValue.at(attributeColor.first).second) {
81 myMinMaxValue.at(attributeColor.first).second = attributeColor.second.second;
82 }
83 }
84 }
85}
86
87
88bool
89GNEDataSet::AttributeColors::exist(const std::string& attribute) const {
90 return (myMinMaxValue.count(attribute) > 0);
91}
92
93
94double
95GNEDataSet::AttributeColors::getMinValue(const std::string& attribute) const {
96 return myMinMaxValue.at(attribute).first;
97}
98
99
100double
101GNEDataSet::AttributeColors::getMaxValue(const std::string& attribute) const {
102 return myMinMaxValue.at(attribute).second;
103}
104
105
106void
108 myMinMaxValue.clear();
109}
110
111// ---------------------------------------------------------------------------
112// GNEDataSet - methods
113// ---------------------------------------------------------------------------
114
115GNEDataSet::GNEDataSet(GNENet* net, const std::string dataSetID) :
117 myDataSetID(dataSetID) {
118}
119
120
122
123
126 return nullptr;
127}
128
129
132 return nullptr;
133}
134
135
136const GUIGlObject*
138 return nullptr;
139}
140
141
142void
144 // first update attribute colors in data interval childrens
145 for (const auto& interval : myDataIntervalChildren) {
146 interval.second->updateAttributeColors();
147 }
148 // continue with data sets containers
151 // iterate over all data interval children
152 for (const auto& interval : myDataIntervalChildren) {
153 myAllAttributeColors.updateAllValues(interval.second->getAllAttributeColors());
154 }
155 // iterate over specificdata interval children
156 for (const auto& interval : myDataIntervalChildren) {
157 for (const auto& specificAttributeColor : interval.second->getSpecificAttributeColors()) {
158 mySpecificAttributeColors[specificAttributeColor.first].updateAllValues(specificAttributeColor.second);
159 }
160 }
161}
162
163
168
169
170const std::map<SumoXMLTag, GNEDataSet::AttributeColors>&
174
175
176void
178 // nothing to update
179}
180
181
184 return Position(0, 0);
185}
186
187
188void
190 // iterate over intervals
191 for (const auto& interval : myDataIntervalChildren) {
192 // open device
194 // write ID
195 device.writeAttr(SUMO_ATTR_ID, getID());
196 // write begin
197 device.writeAttr(SUMO_ATTR_BEGIN, interval.second->getAttribute(SUMO_ATTR_BEGIN));
198 // write end
199 device.writeAttr(SUMO_ATTR_END, interval.second->getAttribute(SUMO_ATTR_END));
200 // iterate over interval generic datas
201 for (const auto& genericData : interval.second->getGenericDataChildren()) {
202 // write generic data
203 genericData->writeGenericData(device);
204 }
205 // close device
206 device.closeTag();
207 }
208}
209
210
211bool
213 return false;
214}
215
216
217bool
219 return false;
220}
221
222
223bool
225 return false;
226}
227
228
229bool
231 return false;
232}
233
234
235bool
237 return false;
238}
239
240
241bool
243 return false;
244}
245
246
247bool
249 return false;
250}
251
252
253void
255 // check that dataInterval wasn't previously inserted
256 if (myDataIntervalChildren.count(dataInterval->getAttributeDouble(SUMO_ATTR_BEGIN)) == 0) {
257 // add data interval child
258 myDataIntervalChildren[dataInterval->getAttributeDouble(SUMO_ATTR_BEGIN)] = dataInterval;
259 // add reference in attributeCarriers
260 myNet->getAttributeCarriers()->insertDataInterval(dataInterval, dataInterval);
261 } else {
262 throw ProcessError(TL("DataInterval was already inserted"));
263 }
264}
265
266
267void
269 // check that dataInterval was previously inserted
270 if (myDataIntervalChildren.count(dataInterval->getAttributeDouble(SUMO_ATTR_BEGIN)) == 1) {
271 // remove data interval child
273 // remove it from inspected elements and GNEElementTree
276 // remove reference from attributeCarriers
278 } else {
279 throw ProcessError(TL("DataInterval wasn't previously inserted"));
280 }
281}
282
283
284bool
286 for (const auto& interval : myDataIntervalChildren) {
287 if (interval.second == dataInterval) {
288 return true;
289 }
290 }
291 return false;
292}
293
294void
296 // check that dataInterval was previously inserted
297 if (myDataIntervalChildren.count(oldBegin) == 1) {
298 // get data interval
299 GNEDataInterval* dataInterval = myDataIntervalChildren.at(oldBegin);
300 // insert again using new begin
301 myDataIntervalChildren[dataInterval->getAttributeDouble(SUMO_ATTR_BEGIN)] = dataInterval;
302 } else {
303 throw ProcessError(TL("DataInterval wasn't previously inserted"));
304 }
305}
306
307
308bool
309GNEDataSet::checkNewInterval(const double newBegin, const double newEnd) {
310 return checkNewInterval(myDataIntervalChildren, newBegin, newEnd);
311}
312
313
314bool
315GNEDataSet::checkNewBeginEnd(const GNEDataInterval* dataInterval, const double newBegin, const double newEnd) {
316 // make a copy of myDataIntervalChildren without dataInterval, and check checkNewInterval
317 std::map<const double, GNEDataInterval*> copyOfDataIntervalMap;
318 for (const auto& element : myDataIntervalChildren) {
319 if (element.second != dataInterval) {
320 copyOfDataIntervalMap.insert(element);
321 }
322 }
323 return checkNewInterval(copyOfDataIntervalMap, newBegin, newEnd);
324}
325
326
328GNEDataSet::retrieveInterval(const double begin, const double end) const {
329 if (myDataIntervalChildren.count(begin) == 0) {
330 return nullptr;
331 } else if (myDataIntervalChildren.at(begin)->getAttributeDouble(SUMO_ATTR_END) != end) {
332 return nullptr;
333 } else {
334 return myDataIntervalChildren.at(begin);
335 }
336}
337
338
339const std::map<const double, GNEDataInterval*>&
343
344
345std::string
347 switch (key) {
348 case SUMO_ATTR_ID:
349 return myDataSetID;
350 default:
351 throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
352 }
353}
354
355
356double
358 throw InvalidArgument(getTagStr() + " doesn't have a double attribute of type '" + toString(key) + "'");
359}
360
361
362void
363GNEDataSet::setAttribute(SumoXMLAttr key, const std::string& value, GNEUndoList* undoList) {
364 switch (key) {
365 case SUMO_ATTR_ID:
366 GNEChange_Attribute::changeAttribute(this, key, value, undoList);
367 break;
368 default:
369 throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
370 }
371}
372
373
374bool
375GNEDataSet::isValid(SumoXMLAttr key, const std::string& value) {
376 switch (key) {
377 case SUMO_ATTR_ID:
378 if (SUMOXMLDefinitions::isValidNetID(value) && (myNet->getAttributeCarriers()->retrieveDataSet(value, false) == nullptr)) {
379 return true;
380 } else {
381 return false;
382 }
383 default:
384 throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
385 }
386}
387
388
389std::string
391 return getTagStr();
392}
393
394
395std::string
397 return getTagStr() + ": " + myDataSetID;
398}
399
400
405
406
407void
408GNEDataSet::setAttribute(SumoXMLAttr key, const std::string& value) {
409 switch (key) {
410 case SUMO_ATTR_ID:
411 myDataSetID = value;
412 // update all intervals
413 for (const auto& interval : myDataIntervalChildren) {
414 interval.second->updateGenericDataIDs();
415 }
416 break;
417 default:
418 throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
419 }
420 // mark interval toolbar for update
422}
423
424
425bool
426GNEDataSet::checkNewInterval(const std::map<const double, GNEDataInterval*>& dataIntervalMap, const double newBegin, const double newEnd) {
427 if (dataIntervalMap.empty()) {
428 return true;
429 } else {
430 // declare first and last element
431 const auto itFirstElement = dataIntervalMap.begin();
432 const auto itLastElement = dataIntervalMap.rbegin();
433 if (newBegin > newEnd) {
434 return false;
435 } else if (dataIntervalMap.count(newBegin) == 1) {
436 return false;
437 } else if (newBegin < itFirstElement->first) {
438 return (newEnd <= itFirstElement->first);
439 } else if (newBegin > itLastElement->first) {
440 return (newBegin >= itLastElement->second->getAttributeDouble(SUMO_ATTR_END));
441 } else {
442 // iterate over myDataIntervalChildren
443 for (auto it = itFirstElement; it != dataIntervalMap.end(); it++) {
444 if (newBegin < it->first) {
445 // obtain previous edge
446 auto itPrevious = it;
447 itPrevious--;
448 // check overlapping with end
449 if (itPrevious->second->getAttributeDouble(SUMO_ATTR_END) < newBegin) {
450 return true;
451 }
452 }
453 }
454 }
455 return false;
456 }
457}
458
459/****************************************************************************/
#define TL(string)
Definition MsgHandler.h:315
@ 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
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)
const std::string & getTagStr() const
get tag assigned to this object in string format
GNENet * myNet
pointer to net
static void changeAttribute(GNEAttributeCarrier *AC, SumoXMLAttr key, const std::string &value, GNEUndoList *undoList, const bool force=false)
change attribute
An Element which don't belong to GNENet but has influence in the simulation.
double getAttributeDouble(SumoXMLAttr key) const
std::map< std::string, std::pair< double, double > > myMinMaxValue
map with the minimum and maximum value
Definition GNEDataSet.h:73
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
void setAttribute(SumoXMLAttr key, const std::string &value, GNEUndoList *undoList)
method for setting the attribute and letting the object perform data element changes
bool isValid(SumoXMLAttr key, const std::string &value)
method for checking if the key and their conrrespond attribute are valids
Position getPositionInView() const
Returns element position in view.
GUIGlObject * getGUIGlObject()
get GUIGlObject associated with this AttributeCarrier
void writeDataSet(OutputDevice &device) const
write data set
std::string myDataSetID
dataSet ID
Definition GNEDataSet.h:209
bool dataIntervalChildrenExist(GNEDataInterval *dataInterval) const
check if given data interval exist
std::string getAttribute(SumoXMLAttr key) const
std::map< const double, GNEDataInterval * > myDataIntervalChildren
map with dataIntervals children sorted by begin
Definition GNEDataSet.h:212
void removeDataIntervalChild(GNEDataInterval *dataInterval)
add data interval child
std::string getPopUpID() const
get PopPup ID (Used in AC Hierarchy)
GNEDataInterval * retrieveInterval(const double begin, const double end) const
return interval
GNEHierarchicalElement * getHierarchicalElement()
get GNEHierarchicalElement associated with this AttributeCarrier
std::string getHierarchyName() const
get Hierarchy Name (Used in AC Hierarchy)
bool checkDrawMoveContour() const
check if draw move contour (red)
bool checkDrawOverContour() const
check if draw over contour (orange)
bool checkDrawFromContour() const
check if draw from contour (green)
~GNEDataSet()
Destructor.
const Parameterised::Map & getACParametersMap() const
get parameters map
const GNEDataSet::AttributeColors & getAllAttributeColors() const
all attribute colors
void updateAttributeColors()
update attribute colors deprecated
double getAttributeDouble(SumoXMLAttr key) const
bool checkDrawRelatedContour() const
check if draw related contour (cyan)
std::map< SumoXMLTag, GNEDataSet::AttributeColors > mySpecificAttributeColors
specific attribute colors
Definition GNEDataSet.h:218
bool checkDrawSelectContour() const
check if draw select contour (blue)
bool checkNewBeginEnd(const GNEDataInterval *dataInterval, const double newBegin, const double newEnd)
check if new begin or end for given GNEDataInterval is given
GNEDataSet::AttributeColors myAllAttributeColors
all attribute colors
Definition GNEDataSet.h:215
GNEDataSet(GNENet *net, const std::string dataSetID)
Constructor.
const std::map< SumoXMLTag, GNEDataSet::AttributeColors > & getSpecificAttributeColors() const
specific attribute colors
bool checkDrawToContour() const
check if draw from contour (magenta)
bool checkDrawDeleteContour() const
check if draw delete contour (pink/white)
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
void updateGeometry()
update pre-computed geometry information
void addDataIntervalChild(GNEDataInterval *dataInterval)
add data interval child
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:127
GNEViewNet * getViewNet() const
get view net
Definition GNENet.cpp:2155
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.
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 bool isValidNetID(const std::string &value)
whether the given string is a valid id for a network element