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-2020 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  // update geometry after insertion if myUpdateGeometryEnabled is enabled
167  // update generic data geometry
168  genericData->updateGeometry();
169  }
170  // update colors
172  } else {
173  throw ProcessError("GenericData was already inserted");
174  }
175 }
176 
177 
178 void
180  auto it = std::find(myGenericDataChildren.begin(), myGenericDataChildren.end(), genericData);
181  // check that GenericData was previously inserted
182  if (it != myGenericDataChildren.end()) {
183  // remove generic data child
184  myGenericDataChildren.erase(it);
185  // remove it from inspected ACs and HierarchicalElementTree
188  // update colors
190  } else {
191  throw ProcessError("GenericData wasn't previously inserted");
192  }
193 }
194 
195 
196 bool
198  return std::find(myGenericDataChildren.begin(), myGenericDataChildren.end(), genericData) != myGenericDataChildren.end();
199 }
200 
201 
202 const std::vector<GNEGenericData*>&
204  return myGenericDataChildren;
205 }
206 
207 
208 std::string
210  switch (key) {
211  case SUMO_ATTR_ID:
213  case SUMO_ATTR_BEGIN:
214  return toString(myBegin);
215  case SUMO_ATTR_END:
216  return toString(myEnd);
217  default:
218  throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
219  }
220 }
221 
222 
223 double
225  switch (key) {
226  case SUMO_ATTR_BEGIN:
227  return myBegin;
228  case SUMO_ATTR_END:
229  return myEnd;
230  default:
231  throw InvalidArgument(getTagStr() + " doesn't have a double attribute of type '" + toString(key) + "'");
232  }
233 }
234 
235 
236 void
237 GNEDataInterval::setAttribute(SumoXMLAttr key, const std::string& value, GNEUndoList* undoList) {
238  switch (key) {
239  case SUMO_ATTR_BEGIN:
240  case SUMO_ATTR_END:
241  undoList->p_add(new GNEChange_Attribute(this, key, value));
242  break;
243  default:
244  throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
245  }
246 }
247 
248 
249 bool
250 GNEDataInterval::isValid(SumoXMLAttr key, const std::string& value) {
251  switch (key) {
252  case SUMO_ATTR_BEGIN:
253  return canParse<double>(value);
254  case SUMO_ATTR_END:
255  return canParse<double>(value);
256  default:
257  throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
258  }
259 }
260 
261 
262 void
264  // Nothing to enable
265 }
266 
267 
268 void
270  // Nothing to disable
271 }
272 
273 
274 bool
276  switch (key) {
277  case SUMO_ATTR_ID:
278  return false;
279  default:
280  return true;
281  }
282 }
283 
284 
285 std::string
287  return getTagStr();
288 }
289 
290 
291 std::string
293  return "interval: " + getAttribute(SUMO_ATTR_BEGIN) + " -> " + getAttribute(SUMO_ATTR_END);
294 }
295 
296 
297 const std::map<std::string, std::string>&
299  return getParametersMap();
300 }
301 
302 
303 void
304 GNEDataInterval::setAttribute(SumoXMLAttr key, const std::string& value) {
305  switch (key) {
306  case SUMO_ATTR_BEGIN:
307  myBegin = parse<double>(value);
308  // update Generic Data IDs
310  break;
311  case SUMO_ATTR_END:
312  myEnd = parse<double>(value);
313  // update Generic Data IDs
315  break;
316  default:
317  throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
318  }
319 }
320 
321 
322 void
323 GNEDataInterval::setEnabledAttribute(const int /*enabledAttributes*/) {
324  throw InvalidArgument("Nothing to enable");
325 }
326 
327 /****************************************************************************/
@ SUMO_TAG_EDGEREL
a relation between two edges
@ SUMO_TAG_DATAINTERVAL
@ SUMO_TAG_MEANDATA_EDGE
an edge based mean data detector
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:44
friend class GNEChange_Attribute
declare friend class
const std::string & getTagStr() const
get tag assigned to this object in string format
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 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)
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)
void setEnabledAttribute(const int enabledAttributes)
method for enabling the attribute and nothing else (used in GNEChange_EnableAttribute)
const std::map< std::string, std::string > & getACParametersMap() const
get parameters map
const GNEDataSet::AttributeColors & getAllAttributeColors() const
all attribute colors
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:46
void clear()
clear AttributeColors
Definition: GNEDataSet.cpp:101
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:299
const std::string & getID() const
get ID
Definition: GNEDataSet.cpp:119
void updateAttributeColors()
update attribute colors deprecated
Definition: GNEDataSet.cpp:142
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.
virtual void updateGeometry()=0
update pre-computed geometry information
GNEDataInterval * getDataIntervalParent() const
get data interval parent
GNEFrameModuls::HierarchicalElementTree * getHierarchicalElementTree() const
get HierarchicalElementTree modul
bool isUpdateGeometryEnabled() const
check if update geometry after inserting or removing has to be updated
Definition: GNENet.cpp:3121
bool isUpdateDataEnabled() const
check if update data after inserting or removing has to be updated
Definition: GNENet.cpp:3146
GNEViewNet * getViewNet() const
get view net
Definition: GNENet.cpp:2245
void p_add(GNEChange_Attribute *cmd)
special method, 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:36