Eclipse SUMO - Simulation of Urban MObility
Loading...
Searching...
No Matches
GNEDataInterval.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-2023 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>
33
34#include "GNEDataInterval.h"
35
36
37// ===========================================================================
38// member method definitions
39// ===========================================================================
40
41// ---------------------------------------------------------------------------
42// GNEDataInterval - methods
43// ---------------------------------------------------------------------------
44
45GNEDataInterval::GNEDataInterval(GNEDataSet* dataSetParent, const double begin, const double end) :
46 GNEHierarchicalElement(dataSetParent->getNet(), SUMO_TAG_DATAINTERVAL, {}, {}, {}, {}, {}, {}),
47 myDataSetParent(dataSetParent),
48 myBegin(begin),
49myEnd(end) {
50}
51
52
54
55
56void
59 // iterate over generic data childrens
60 for (const auto& genericData : myGenericDataChildren) {
61 if (genericData->getTagProperty().getTag() == GNE_TAG_EDGEREL_SINGLE) {
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
75void
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
102
103
104const std::map<SumoXMLTag, GNEDataSet::AttributeColors>&
108
109
112 return nullptr;
113}
114
115
116void
118 // nothing to update
119}
120
121
124 return Position();
125}
126
127
128bool
130 return true;
131}
132
133
134std::string
136 return "";
137}
138
139
140void
142 throw InvalidArgument(getTagStr() + " cannot fix any problem");
143}
144
145
150
151
152void
154 // check that GenericData wasn't previously inserted
155 if (!hasGenericDataChild(genericData)) {
156 myGenericDataChildren.push_back(genericData);
157 // update generic data IDs
159 // check if add to boundary
160 if (genericData->getTagProperty().isPlacedInRTree()) {
162 }
163 // update geometry after insertion if myUpdateGeometryEnabled is enabled
165 // update generic data RTREE
166 genericData->updateGeometry();
167 }
168 // add reference in attributeCarriers
170 // update colors
172 } else {
173 throw ProcessError(TL("GenericData was already inserted"));
174 }
175}
176
177
178void
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 GNEElementTree
188 // update colors
190 // delete path element
191 myNet->getPathManager()->removePath(genericData);
192 // check if remove from RTREE
193 if (genericData->getTagProperty().isPlacedInRTree()) {
195 }
196 // remove reference from attributeCarriers
198 } else {
199 throw ProcessError(TL("GenericData wasn't previously inserted"));
200 }
201}
202
203
204bool
206 return std::find(myGenericDataChildren.begin(), myGenericDataChildren.end(), genericData) != myGenericDataChildren.end();
207}
208
209
210const std::vector<GNEGenericData*>&
214
215
216bool
218 // interate over all generic datas and check TAZ parents
219 for (const auto& genericData : myGenericDataChildren) {
220 if ((genericData->getTagProperty().getTag() == SUMO_TAG_TAZREL) &&
221 (genericData->getParentAdditionals().size() == 1) &&
222 (genericData->getParentAdditionals().front() == TAZ)) {
223 return true;
224 }
225 }
226 return false;
227}
228
229
230bool
231GNEDataInterval::TAZRelExists(const GNEAdditional* fromTAZ, const GNEAdditional* toTAZ) const {
232 // interate over all generic datas and check TAZ parents
233 for (const auto& genericData : myGenericDataChildren) {
234 if ((genericData->getTagProperty().getTag() == SUMO_TAG_TAZREL) &&
235 (genericData->getParentAdditionals().size() == 2) &&
236 (genericData->getParentAdditionals().front() == fromTAZ) &&
237 (genericData->getParentAdditionals().back() == toTAZ)) {
238 return true;
239 }
240 }
241 return false;
242}
243
244
245std::string
247 switch (key) {
248 case SUMO_ATTR_ID:
250 case SUMO_ATTR_BEGIN:
251 return toString(myBegin);
252 case SUMO_ATTR_END:
253 return toString(myEnd);
254 default:
255 throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
256 }
257}
258
259
260double
262 switch (key) {
263 case SUMO_ATTR_BEGIN:
264 return myBegin;
265 case SUMO_ATTR_END:
266 return myEnd;
267 default:
268 throw InvalidArgument(getTagStr() + " doesn't have a double attribute of type '" + toString(key) + "'");
269 }
270}
271
272
273void
274GNEDataInterval::setAttribute(SumoXMLAttr key, const std::string& value, GNEUndoList* undoList) {
275 switch (key) {
276 case SUMO_ATTR_BEGIN:
277 case SUMO_ATTR_END:
278 undoList->changeAttribute(new GNEChange_Attribute(this, key, value));
279 break;
280 default:
281 throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
282 }
283}
284
285
286bool
287GNEDataInterval::isValid(SumoXMLAttr key, const std::string& value) {
288 switch (key) {
289 case SUMO_ATTR_BEGIN:
290 return canParse<double>(value);
291 case SUMO_ATTR_END:
292 return canParse<double>(value);
293 default:
294 throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
295 }
296}
297
298
299bool
301 switch (key) {
302 case SUMO_ATTR_ID:
303 return false;
304 default:
305 return true;
306 }
307}
308
309
310std::string
312 return getTagStr();
313}
314
315
316std::string
318 return "interval: " + getAttribute(SUMO_ATTR_BEGIN) + " -> " + getAttribute(SUMO_ATTR_END);
319}
320
321
326
327
328void
329GNEDataInterval::setAttribute(SumoXMLAttr key, const std::string& value) {
330 switch (key) {
331 case SUMO_ATTR_BEGIN:
332 myBegin = parse<double>(value);
333 // update Generic Data IDs
335 break;
336 case SUMO_ATTR_END:
337 myEnd = parse<double>(value);
338 // update Generic Data IDs
340 break;
341 default:
342 throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
343 }
344 // mark interval toolbar for update
346}
347
348/****************************************************************************/
#define TL(string)
Definition MsgHandler.h:287
@ SUMO_TAG_EDGEREL
a relation between two edges
@ SUMO_TAG_DATAINTERVAL
@ GNE_TAG_EDGEREL_SINGLE
@ 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
An Element which don't belong to GNENet but has influence in the simulation.
const std::string getID() const
get ID (all Attribute Carriers have one)
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
const Parameterised::Map & getACParametersMap() const
get parameters map
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
bool hasGenericDataChild(GNEGenericData *genericData) const
check if given generic data is child of this data interval
bool TAZRelExists(const GNEAdditional *TAZ) const
check if there is already a TAZRel defined in one TAZ
GNEDataSet::AttributeColors myAllAttributeColors
all attribute colors
const std::vector< GNEGenericData * > & getGenericDataChildren() const
get generic data children
double myEnd
end interval
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...
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
void clear()
clear AttributeColors
void updateValues(const std::string &attribute, const double value)
update value for an specific attribute
std::string getAttribute(SumoXMLAttr key) const
void updateAttributeColors()
update attribute colors deprecated
void removeCurrentEditedAttributeCarrier(const GNEAttributeCarrier *HE)
if given AttributeCarrier is the same of myHE, set it as nullptr
An Element which don't belong to GNENet but has influence 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
GNEElementTree * getHierarchicalElementTree() const
get GNEElementTree 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:145
GNENetHelper::AttributeCarriers * getAttributeCarriers() const
get all attribute carriers used in this net
Definition GNENet.cpp:120
bool isUpdateGeometryEnabled() const
check if update geometry after inserting or removing has to be updated
Definition GNENet.cpp:2632
bool isUpdateDataEnabled() const
check if update data after inserting or removing has to be updated
Definition GNENet.cpp:2655
GNEPathManager * getPathManager()
get path manager
Definition GNENet.cpp:132
GNEViewNet * getViewNet() const
get view net
Definition GNENet.cpp:2030
void removePath(PathElement *pathElement)
remove path
bool isPlacedInRTree() const
return true if Tag correspond to an element that has to be placed in RTREE
void changeAttribute(GNEChange_Attribute *change)
special method for change attributes, avoid empty changes, always execute
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
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
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:160