Eclipse SUMO - Simulation of Urban MObility
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>
29 #include <netedit/GNEViewParent.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 
47 }
48 
49 
50 void
51 GNEDataSet::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 
68 void
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 
88 bool
89 GNEDataSet::AttributeColors::exist(const std::string& attribute) const {
90  return (myMinMaxValue.count(attribute) > 0);
91 }
92 
93 
94 double
95 GNEDataSet::AttributeColors::getMinValue(const std::string& attribute) const {
96  return myMinMaxValue.at(attribute).first;
97 }
98 
99 
100 double
101 GNEDataSet::AttributeColors::getMaxValue(const std::string& attribute) const {
102  return myMinMaxValue.at(attribute).second;
103 }
104 
105 
106 void
108  myMinMaxValue.clear();
109 }
110 
111 // ---------------------------------------------------------------------------
112 // GNEDataSet - methods
113 // ---------------------------------------------------------------------------
114 
115 GNEDataSet::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 
136 const GUIGlObject*
138  return nullptr;
139 }
140 
141 
142 void
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 
166  return myAllAttributeColors;
167 }
168 
169 
170 const std::map<SumoXMLTag, GNEDataSet::AttributeColors>&
173 }
174 
175 
176 void
178  // nothing to update
179 }
180 
181 
182 Position
184  return Position(0, 0);
185 }
186 
187 
188 void
190  // iterate over intervals
191  for (const auto& interval : myDataIntervalChildren) {
192  // open device
193  device.openTag(SUMO_TAG_INTERVAL);
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 
211 bool
213  return false;
214 }
215 
216 
217 bool
219  return false;
220 }
221 
222 
223 bool
225  return false;
226 }
227 
228 
229 bool
231  return false;
232 }
233 
234 
235 bool
237  return false;
238 }
239 
240 
241 bool
243  return false;
244 }
245 
246 
247 bool
249  return false;
250 }
251 
252 
253 void
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 
267 void
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 
284 bool
286  for (const auto& interval : myDataIntervalChildren) {
287  if (interval.second == dataInterval) {
288  return true;
289  }
290  }
291  return false;
292 }
293 
294 void
295 GNEDataSet::updateDataIntervalBegin(const double oldBegin) {
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 
308 bool
309 GNEDataSet::checkNewInterval(const double newBegin, const double newEnd) {
310  return checkNewInterval(myDataIntervalChildren, newBegin, newEnd);
311 }
312 
313 
314 bool
315 GNEDataSet::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 
328 GNEDataSet::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 
339 const std::map<const double, GNEDataInterval*>&
341  return myDataIntervalChildren;
342 }
343 
344 
345 std::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 
356 double
358  throw InvalidArgument(getTagStr() + " doesn't have a double attribute of type '" + toString(key) + "'");
359 }
360 
361 
362 void
363 GNEDataSet::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 
374 bool
375 GNEDataSet::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 
389 std::string
391  return getTagStr();
392 }
393 
394 
395 std::string
397  return getTagStr() + ": " + myDataSetID;
398 }
399 
400 
401 const Parameterised::Map&
403  return getParametersMap();
404 }
405 
406 
407 void
408 GNEDataSet::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 
425 bool
426 GNEDataSet::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
attribute colors
Definition: GNEDataSet.h:47
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
Definition: GNEDataSet.cpp:69
bool exist(const std::string &attribute) const
check if given attribute exist (needed for non-double attributes)
Definition: GNEDataSet.cpp:89
double getMaxValue(const std::string &attribute) const
get maximum value
Definition: GNEDataSet.cpp:101
AttributeColors()
default constructor
Definition: GNEDataSet.cpp:46
double getMinValue(const std::string &attribute) const
get minimum value
Definition: GNEDataSet.cpp:95
void clear()
clear AttributeColors
Definition: GNEDataSet.cpp:107
void updateValues(const std::string &attribute, const double value)
update value for an specific attribute
Definition: GNEDataSet.cpp:51
void setAttribute(SumoXMLAttr key, const std::string &value, GNEUndoList *undoList)
method for setting the attribute and letting the object perform data element changes
Definition: GNEDataSet.cpp:363
bool isValid(SumoXMLAttr key, const std::string &value)
method for checking if the key and their conrrespond attribute are valids
Definition: GNEDataSet.cpp:375
Position getPositionInView() const
Returns element position in view.
Definition: GNEDataSet.cpp:183
GUIGlObject * getGUIGlObject()
get GUIGlObject associated with this AttributeCarrier
Definition: GNEDataSet.cpp:131
void writeDataSet(OutputDevice &device) const
write data set
Definition: GNEDataSet.cpp:189
std::string myDataSetID
dataSet ID
Definition: GNEDataSet.h:209
bool dataIntervalChildrenExist(GNEDataInterval *dataInterval) const
check if given data interval exist
Definition: GNEDataSet.cpp:285
std::string getAttribute(SumoXMLAttr key) const
Definition: GNEDataSet.cpp:346
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
Definition: GNEDataSet.cpp:268
std::string getPopUpID() const
get PopPup ID (Used in AC Hierarchy)
Definition: GNEDataSet.cpp:390
GNEDataInterval * retrieveInterval(const double begin, const double end) const
return interval
Definition: GNEDataSet.cpp:328
GNEHierarchicalElement * getHierarchicalElement()
get GNEHierarchicalElement associated with this AttributeCarrier
Definition: GNEDataSet.cpp:125
std::string getHierarchyName() const
get Hierarchy Name (Used in AC Hierarchy)
Definition: GNEDataSet.cpp:396
bool checkDrawMoveContour() const
check if draw move contour (red)
Definition: GNEDataSet.cpp:248
bool checkDrawOverContour() const
check if draw over contour (orange)
Definition: GNEDataSet.cpp:230
bool checkDrawFromContour() const
check if draw from contour (green)
Definition: GNEDataSet.cpp:212
~GNEDataSet()
Destructor.
Definition: GNEDataSet.cpp:121
const Parameterised::Map & getACParametersMap() const
get parameters map
Definition: GNEDataSet.cpp:402
const GNEDataSet::AttributeColors & getAllAttributeColors() const
all attribute colors
Definition: GNEDataSet.cpp:165
void updateAttributeColors()
update attribute colors deprecated
Definition: GNEDataSet.cpp:143
double getAttributeDouble(SumoXMLAttr key) const
Definition: GNEDataSet.cpp:357
bool checkDrawRelatedContour() const
check if draw related contour (cyan)
Definition: GNEDataSet.cpp:224
std::map< SumoXMLTag, GNEDataSet::AttributeColors > mySpecificAttributeColors
specific attribute colors
Definition: GNEDataSet.h:218
bool checkDrawSelectContour() const
check if draw select contour (blue)
Definition: GNEDataSet.cpp:242
bool checkNewBeginEnd(const GNEDataInterval *dataInterval, const double newBegin, const double newEnd)
check if new begin or end for given GNEDataInterval is given
Definition: GNEDataSet.cpp:315
GNEDataSet::AttributeColors myAllAttributeColors
all attribute colors
Definition: GNEDataSet.h:215
GNEDataSet(GNENet *net, const std::string dataSetID)
Constructor.
Definition: GNEDataSet.cpp:115
const std::map< SumoXMLTag, GNEDataSet::AttributeColors > & getSpecificAttributeColors() const
specific attribute colors
Definition: GNEDataSet.cpp:171
bool checkDrawToContour() const
check if draw from contour (magenta)
Definition: GNEDataSet.cpp:218
bool checkDrawDeleteContour() const
check if draw delete contour (pink/white)
Definition: GNEDataSet.cpp:236
const std::map< const double, GNEDataInterval * > & getDataIntervalChildren() const
get data interval children
Definition: GNEDataSet.cpp:340
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
Definition: GNEDataSet.cpp:309
void updateGeometry()
update pre-computed geometry information
Definition: GNEDataSet.cpp:177
void addDataIntervalChild(GNEDataInterval *dataInterval)
add data interval child
Definition: GNEDataSet.cpp:254
void updateDataIntervalBegin(const double oldBegin)
update data interval begin
Definition: GNEDataSet.cpp:295
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:122
GNEViewNet * getViewNet() const
get view net
Definition: GNENet.cpp:2055
GNEViewNetHelper::IntervalBar & getIntervalBar()
get interval bar
GNEViewParent * getViewParent() const
get the net object
void removeFromAttributeCarrierInspected(const GNEAttributeCarrier *AC)
remove given AC of list of inspected Attribute Carriers
GNEInspectorFrame * getInspectorFrame() const
get frame for inspect elements
Static storage of an output device and its base (abstract) implementation.
Definition: OutputDevice.h:61
OutputDevice & openTag(const std::string &xmlElement)
Opens an XML tag.
OutputDevice & writeAttr(const SumoXMLAttr attr, const T &val)
writes a named attribute
Definition: OutputDevice.h:254
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
Definition: Parameterised.h:45
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