Eclipse SUMO - Simulation of Urban MObility
GNEDataInterval.cpp
Go to the documentation of this file.
1 /****************************************************************************/
2 // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.org/sumo
3 // Copyright (C) 2001-2022 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/GNEUndoList.h>
30 #include <netedit/GNEViewParent.h>
33 
34 #include "GNEDataInterval.h"
35 
36 
37 // ===========================================================================
38 // member method definitions
39 // ===========================================================================
40 
41 // ---------------------------------------------------------------------------
42 // GNEDataInterval - methods
43 // ---------------------------------------------------------------------------
44 
45 GNEDataInterval::GNEDataInterval(GNEDataSet* dataSetParent, const double begin, const double end) :
46  GNEHierarchicalElement(dataSetParent->getNet(), SUMO_TAG_DATAINTERVAL, {}, {}, {}, {}, {}, {}, {}, {}),
47  myDataSetParent(dataSetParent),
48  myBegin(begin),
49 myEnd(end) {
50 }
51 
52 
54 
55 
56 void
58  if (myNet->isUpdateDataEnabled()) {
59  // iterate over generic data childrens
60  for (const auto& genericData : myGenericDataChildren) {
61  if (genericData->getTagProperty().getTag() == SUMO_TAG_MEANDATA_EDGE) {
62  // {dataset}[{begin}m{end}]{edge}
63  genericData->setMicrosimID(myDataSetParent->getID() + "[" + toString(myBegin) + "," + toString(myEnd) + "]" +
64  genericData->getParentEdges().front()->getID());
65  } else if (genericData->getTagProperty().getTag() == SUMO_TAG_EDGEREL) {
66  // {dataset}[{begin}m{end}]{from}->{to}
67  genericData->setMicrosimID(myDataSetParent->getID() + "[" + toString(myBegin) + "," + toString(myEnd) + "]" +
68  genericData->getParentEdges().front()->getID() + "->" + genericData->getParentEdges().back()->getID());
69  }
70  }
71  }
72 }
73 
74 
75 void
77  if (myNet->isUpdateDataEnabled()) {
78  // first clear both container
81  // iterate over generic data children
82  for (const auto& genericData : myGenericDataChildren) {
83  for (const auto& param : genericData->getParametersMap()) {
84  // check if value can be parsed
85  if (canParse<double>(param.second)) {
86  // parse param value
87  const double value = parse<double>(param.second);
88  // update values in both containers
89  myAllAttributeColors.updateValues(param.first, value);
90  mySpecificAttributeColors[genericData->getTagProperty().getTag()].updateValues(param.first, value);
91  }
92  }
93  }
94  }
95 }
96 
97 
100  return myAllAttributeColors;
101 }
102 
103 
104 const std::map<SumoXMLTag, GNEDataSet::AttributeColors>&
107 }
108 
109 
110 const std::string&
112  return myDataSetParent->getID();
113 }
114 
115 
118  return nullptr;
119 }
120 
121 
122 void
124  // nothing to update
125 }
126 
127 
128 Position
130  return Position();
131 }
132 
133 
134 bool
136  return true;
137 }
138 
139 
140 std::string
142  return "";
143 }
144 
145 
146 void
148  throw InvalidArgument(getTagStr() + " cannot fix any problem");
149 }
150 
151 
152 GNEDataSet*
154  return myDataSetParent;
155 }
156 
157 
158 void
160  // check that GenericData wasn't previously inserted
161  if (!hasGenericDataChild(genericData)) {
162  myGenericDataChildren.push_back(genericData);
163  // update generic data IDs
165  // check if add to boundary
166  if (genericData->getTagProperty().isPlacedInRTree()) {
168  }
169  // update geometry after insertion if myUpdateGeometryEnabled is enabled
171  // update generic data RTREE
172  genericData->updateGeometry();
173  }
174  // add reference in attributeCarriers
176  // update colors
178  } else {
179  throw ProcessError("GenericData was already inserted");
180  }
181 }
182 
183 
184 void
186  auto it = std::find(myGenericDataChildren.begin(), myGenericDataChildren.end(), genericData);
187  // check that GenericData was previously inserted
188  if (it != myGenericDataChildren.end()) {
189  // remove generic data child
190  myGenericDataChildren.erase(it);
191  // remove it from inspected ACs and HierarchicalElementTree
194  // update colors
196  // delete path element
197  myNet->getPathManager()->removePath(genericData);
198  // check if remove from RTREE
199  if (genericData->getTagProperty().isPlacedInRTree()) {
201  }
202  // remove reference from attributeCarriers
204  } else {
205  throw ProcessError("GenericData wasn't previously inserted");
206  }
207 }
208 
209 
210 bool
212  return std::find(myGenericDataChildren.begin(), myGenericDataChildren.end(), genericData) != myGenericDataChildren.end();
213 }
214 
215 
216 const std::vector<GNEGenericData*>&
218  return myGenericDataChildren;
219 }
220 
221 
222 bool
224  // interate over all generic datas and check TAZ parents
225  for (const auto& genericData : myGenericDataChildren) {
226  if ((genericData->getTagProperty().getTag() == SUMO_TAG_TAZREL) &&
227  (genericData->getParentTAZElements().size() == 1) &&
228  (genericData->getParentTAZElements().front() == TAZ)) {
229  return true;
230  }
231  }
232  return false;
233 }
234 
235 
236 bool
237 GNEDataInterval::TAZRelExists(const GNETAZElement* fromTAZ, const GNETAZElement* toTAZ) const {
238  // interate over all generic datas and check TAZ parents
239  for (const auto& genericData : myGenericDataChildren) {
240  if ((genericData->getTagProperty().getTag() == SUMO_TAG_TAZREL) &&
241  (genericData->getParentTAZElements().size() == 2) &&
242  (genericData->getParentTAZElements().front() == fromTAZ) &&
243  (genericData->getParentTAZElements().back() == toTAZ)) {
244  return true;
245  }
246  }
247  return false;
248 }
249 
250 
251 std::string
253  switch (key) {
254  case SUMO_ATTR_ID:
256  case SUMO_ATTR_BEGIN:
257  return toString(myBegin);
258  case SUMO_ATTR_END:
259  return toString(myEnd);
260  default:
261  throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
262  }
263 }
264 
265 
266 double
268  switch (key) {
269  case SUMO_ATTR_BEGIN:
270  return myBegin;
271  case SUMO_ATTR_END:
272  return myEnd;
273  default:
274  throw InvalidArgument(getTagStr() + " doesn't have a double attribute of type '" + toString(key) + "'");
275  }
276 }
277 
278 
279 void
280 GNEDataInterval::setAttribute(SumoXMLAttr key, const std::string& value, GNEUndoList* undoList) {
281  switch (key) {
282  case SUMO_ATTR_BEGIN:
283  case SUMO_ATTR_END:
284  undoList->changeAttribute(new GNEChange_Attribute(this, key, value));
285  break;
286  default:
287  throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
288  }
289 }
290 
291 
292 bool
293 GNEDataInterval::isValid(SumoXMLAttr key, const std::string& value) {
294  switch (key) {
295  case SUMO_ATTR_BEGIN:
296  return canParse<double>(value);
297  case SUMO_ATTR_END:
298  return canParse<double>(value);
299  default:
300  throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
301  }
302 }
303 
304 
305 void
307  // Nothing to enable
308 }
309 
310 
311 void
313  // Nothing to disable
314 }
315 
316 
317 bool
319  switch (key) {
320  case SUMO_ATTR_ID:
321  return false;
322  default:
323  return true;
324  }
325 }
326 
327 
328 bool
330  return false;
331 }
332 
333 
334 std::string
336  return getTagStr();
337 }
338 
339 
340 std::string
342  return "interval: " + getAttribute(SUMO_ATTR_BEGIN) + " -> " + getAttribute(SUMO_ATTR_END);
343 }
344 
345 
346 const std::map<std::string, std::string>&
348  return getParametersMap();
349 }
350 
351 
352 void
353 GNEDataInterval::setAttribute(SumoXMLAttr key, const std::string& value) {
354  switch (key) {
355  case SUMO_ATTR_BEGIN:
356  myBegin = parse<double>(value);
357  // update Generic Data IDs
359  break;
360  case SUMO_ATTR_END:
361  myEnd = parse<double>(value);
362  // update Generic Data IDs
364  break;
365  default:
366  throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
367  }
368 }
369 
370 
371 void
372 GNEDataInterval::toogleAttribute(SumoXMLAttr /*key*/, const bool /*value*/, const int /*previousParameters*/) {
373  throw InvalidArgument("Nothing to enable");
374 }
375 
376 /****************************************************************************/
@ SUMO_TAG_EDGEREL
a relation between two edges
@ SUMO_TAG_DATAINTERVAL
@ SUMO_TAG_MEANDATA_EDGE
an edge based mean data detector
@ SUMO_TAG_TAZREL
a relation between two TAZs
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
friend class GNEChange_Attribute
declare friend class
const std::string & getTagStr() const
get tag assigned to this object in string format
const GNETagProperties & getTagProperty() const
get tagProperty associated with this Attribute Carrier
GNENet * myNet
pointer to net
GNENet * getNet() const
get pointer to net
void fixDataIntervalProblem()
fix data element problem (by default throw an exception, has to be reimplemented in children)
bool isAttributeEnabled(SumoXMLAttr key) const
double myBegin
begin interval
Position getPositionInView() const
Returns element position in view.
GNEDataInterval(GNEDataSet *dataSetParent, const double begin, const double end)
Constructor.
GNEDataSet * myDataSetParent
GNEDataSet parent to which this data interval belongs.
void setAttribute(SumoXMLAttr key, const std::string &value, GNEUndoList *undoList)
method for setting the attribute and letting the object perform data element changes
void toogleAttribute(SumoXMLAttr key, const bool value, const int previousParameters)
method for enable or disable the attribute and nothing else (used in GNEChange_EnableAttribute)
void removeGenericDataChild(GNEGenericData *genericData)
add generic data child
std::string getAttribute(SumoXMLAttr key) const
double getAttributeDouble(SumoXMLAttr key) const
GUIGlObject * getGUIGlObject()
get GUIGlObject associated with this AttributeCarrier
bool isDataIntervalValid() const
GNEDataSet * getDataSetParent() const
Returns a pointer to GNEDataSet parent.
bool isValid(SumoXMLAttr key, const std::string &value)
method for checking if the key and their conrrespond attribute are valids
const std::string & getID() const
get ID
bool hasGenericDataChild(GNEGenericData *genericData) const
check if given generic data is child of this data interval
GNEDataSet::AttributeColors myAllAttributeColors
all attribute colors
const std::vector< GNEGenericData * > & getGenericDataChildren() const
get generic data children
double myEnd
end interval
void enableAttribute(SumoXMLAttr key, GNEUndoList *undoList)
std::string getPopUpID() const
get PopPup ID (Used in AC Hierarchy)
const std::map< SumoXMLTag, GNEDataSet::AttributeColors > & getSpecificAttributeColors() const
specific attribute colors
void updateGenericDataIDs()
update generic data child IDs
~GNEDataInterval()
Destructor.
std::map< SumoXMLTag, GNEDataSet::AttributeColors > mySpecificAttributeColors
specific attribute colors
std::string getHierarchyName() const
get Hierarchy Name (Used in AC Hierarchy)
bool TAZRelExists(const GNETAZElement *TAZ) const
check if there is already a TAZRel defined in one TAZ
std::string getDataIntervalProblem() const
return a string with the current data element problem (by default empty, can be reimplemented in chil...
void disableAttribute(SumoXMLAttr key, GNEUndoList *undoList)
const std::map< std::string, std::string > & getACParametersMap() const
get parameters map
const GNEDataSet::AttributeColors & getAllAttributeColors() const
all attribute colors
bool isAttributeComputed(SumoXMLAttr key) const
std::vector< GNEGenericData * > myGenericDataChildren
vector with generic data children
void addGenericDataChild(GNEGenericData *genericData)
add generic data child
void updateGeometry()
update pre-computed geometry information
void updateAttributeColors()
update attribute colors deprecated
@bief attribute colors
Definition: GNEDataSet.h:47
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
std::string getAttribute(SumoXMLAttr key) const
Definition: GNEDataSet.cpp:304
const std::string & getID() const
get ID
Definition: GNEDataSet.cpp:131
void updateAttributeColors()
update attribute colors deprecated
Definition: GNEDataSet.cpp:143
void removeCurrentEditedAttributeCarrier(const GNEAttributeCarrier *HE)
if given AttributeCarrier is the same of myHE, set it as nullptr
An Element which don't belongs to GNENet but has influency in the simulation.
GUIGlObject * getGUIGlObject()
get GUIGlObject associated with this AttributeCarrier
virtual void updateGeometry()=0
update pre-computed geometry information
GNEDataInterval * getDataIntervalParent() const
get data interval parent
GNEFrameModules::HierarchicalElementTree * getHierarchicalElementTree() const
get HierarchicalElementTree modul
void insertGenericData(GNEGenericData *genericData)
insert generic data
void deleteGenericData(GNEGenericData *genericData)
delete generic data
SUMORTree & getGrid()
Returns the RTree used for visualisation speed-up.
Definition: GNENet.cpp:144
GNENetHelper::AttributeCarriers * getAttributeCarriers() const
get all attribute carriers used in this net
Definition: GNENet.cpp:125
bool isUpdateGeometryEnabled() const
check if update geometry after inserting or removing has to be updated
Definition: GNENet.cpp:2461
bool isUpdateDataEnabled() const
check if update data after inserting or removing has to be updated
Definition: GNENet.cpp:2484
GNEPathManager * getPathManager()
get path manager
Definition: GNENet.cpp:131
GNEViewNet * getViewNet() const
get view net
Definition: GNENet.cpp:1964
void removePath(PathElement *pathElement)
remove path
An Element which don't belongs to GNENet but has influency in the simulation.
Definition: GNETAZElement.h:45
bool isPlacedInRTree() const
return true if Tag correspond to an element that has has to be placed in RTREE
void changeAttribute(GNEChange_Attribute *change)
special method for change attributes, avoid empty changes, always execute
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
const std::map< std::string, std::string > & getParametersMap() const
Returns the inner key/value map.
A point in 2D or 3D with translation and scaling methods.
Definition: Position.h:37
void addAdditionalGLObject(GUIGlObject *o, const double exaggeration=1)
Adds an additional object (detector/shape/trigger) for visualisation.
Definition: SUMORTree.h:124
void removeAdditionalGLObject(GUIGlObject *o, const double exaggeration=1)
Removes an additional object (detector/shape/trigger) from being visualised.
Definition: SUMORTree.h:158