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-2025 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#include <netedit/GNENet.h>
27
28#include "GNEDataInterval.h"
29
30// ===========================================================================
31// member method definitions
32// ===========================================================================
33
34GNEDataInterval::GNEDataInterval(GNEDataSet* dataSetParent, const double begin, const double end) :
35 GNEAttributeCarrier(SUMO_TAG_DATAINTERVAL, dataSetParent->getNet(), dataSetParent->getFileBucket()),
36 myDataSetParent(dataSetParent),
37 myBegin(begin),
38 myEnd(end) {
39}
40
41
43
44
49
50
53 return nullptr;
54}
55
56
59 return nullptr;
60}
61
62
63const Parameterised*
65 return nullptr;
66}
67
68
71 return nullptr;
72}
73
74
75const GUIGlObject*
77 return nullptr;
78}
79
80
81void
84 // iterate over generic data childrens
85 for (const auto& genericData : myGenericDataChildren) {
86 if (genericData->getTagProperty()->getTag() == GNE_TAG_EDGEREL_SINGLE) {
87 // {dataset}[{begin}m{end}]{edge}
88 genericData->setMicrosimID(myDataSetParent->getID() + "[" + toString(myBegin) + "," + toString(myEnd) + "]" +
89 genericData->getParentEdges().front()->getID());
90 } else if (genericData->getTagProperty()->getTag() == SUMO_TAG_EDGEREL) {
91 // {dataset}[{begin}m{end}]{from}->{to}
92 genericData->setMicrosimID(myDataSetParent->getID() + "[" + toString(myBegin) + "," + toString(myEnd) + "]" +
93 genericData->getParentEdges().front()->getID() + "->" + genericData->getParentEdges().back()->getID());
94 }
95 }
96 }
97}
98
99
100void
102 if (myNet->isUpdateDataEnabled()) {
103 // first clear both container
106 // iterate over generic data children
107 for (const auto& genericData : myGenericDataChildren) {
108 for (const auto& param : genericData->getParametersMap()) {
109 // check if value can be parsed
110 if (canParse<double>(param.second)) {
111 // parse param value
112 const double value = parse<double>(param.second);
113 // update values in both containers
114 myAllAttributeColors.updateValues(param.first, value);
115 mySpecificAttributeColors[genericData->getTagProperty()->getTag()].updateValues(param.first, value);
116 }
117 }
118 }
119 }
120}
121
122
127
128
129const std::map<SumoXMLTag, GNEDataSet::AttributeColors>&
133
134
135void
137 // nothing to update
138}
139
140
143 return Position();
144}
145
146
147bool
149 return false;
150}
151
152
153bool
155 return false;
156}
157
158
159bool
161 return false;
162}
163
164
165bool
167 return false;
168}
169
170
171bool
173 return false;
174}
175
176
177bool
179 return false;
180}
181
182
183bool
185 return false;
186}
187
188
189bool
191 return false;
192}
193
194
197 if (isTemplate()) {
198 return nullptr;
199 } else {
201 }
202}
203
204
205bool
207 return true;
208}
209
210
211std::string
213 return "";
214}
215
216
217void
219 throw InvalidArgument(getTagStr() + " cannot fix any problem");
220}
221
222
227
228
229void
231 // check that GenericData wasn't previously inserted
232 if (!hasGenericDataChild(genericData)) {
233 myGenericDataChildren.push_back(genericData);
234 // update generic data IDs
236 // add id RTREE
237 myNet->addGLObjectIntoGrid(genericData);
238 // update geometry after insertion if myUpdateGeometryEnabled is enabled
240 // update generic data RTREE
241 genericData->updateGeometry();
242 }
243 // add reference in attributeCarriers
245 // update colors
247 } else {
248 throw ProcessError(TL("GenericData was already inserted"));
249 }
250}
251
252
253void
255 auto it = std::find(myGenericDataChildren.begin(), myGenericDataChildren.end(), genericData);
256 // check that GenericData was previously inserted
257 if (it != myGenericDataChildren.end()) {
258 // remove generic data child
259 myGenericDataChildren.erase(it);
260 // remove it from inspected ACs and GNEElementTree
263 // update colors
265 // delete path element
266 myNet->getDataPathManager()->removePath(genericData);
267 // add in RTREE
268 myNet->removeGLObjectFromGrid(genericData);
269 // remove reference from attributeCarriers
271 } else {
272 throw ProcessError(TL("GenericData wasn't previously inserted"));
273 }
274}
275
276
277bool
279 return std::find(myGenericDataChildren.begin(), myGenericDataChildren.end(), genericData) != myGenericDataChildren.end();
280}
281
282
283const std::vector<GNEGenericData*>&
287
288
289bool
291 // interate over all edgeRels and check edge parents
292 for (const auto& genericData : myGenericDataChildren) {
293 if ((genericData->getTagProperty()->getTag() == GNE_TAG_EDGEREL_SINGLE) &&
294 (genericData->getParentEdges().front() == edge)) {
295 return true;
296 }
297 }
298 return false;
299}
300
301
302bool
303GNEDataInterval::edgeRelExists(const GNEEdge* fromEdge, const GNEEdge* toEdge) const {
304 // interate over all edgeRels and check edge parents
305 for (const auto& genericData : myGenericDataChildren) {
306 if ((genericData->getTagProperty()->getTag() == SUMO_TAG_EDGEREL) &&
307 (genericData->getParentEdges().front() == fromEdge) &&
308 (genericData->getParentEdges().back() == toEdge)) {
309 return true;
310 }
311 }
312 return false;
313}
314
315
316bool
318 // interate over all TAZRels and check TAZ parents
319 for (const auto& genericData : myGenericDataChildren) {
320 if ((genericData->getTagProperty()->getTag() == SUMO_TAG_TAZREL) &&
321 (genericData->getParentAdditionals().size() == 1) &&
322 (genericData->getParentAdditionals().front() == TAZ)) {
323 return true;
324 }
325 }
326 return false;
327}
328
329
330bool
331GNEDataInterval::TAZRelExists(const GNEAdditional* fromTAZ, const GNEAdditional* toTAZ) const {
332 // interate over all TAZRels and check TAZ parents
333 for (const auto& genericData : myGenericDataChildren) {
334 if ((genericData->getTagProperty()->getTag() == SUMO_TAG_TAZREL) &&
335 (genericData->getParentAdditionals().size() == 2) &&
336 (genericData->getParentAdditionals().front() == fromTAZ) &&
337 (genericData->getParentAdditionals().back() == toTAZ)) {
338 return true;
339 }
340 }
341 return false;
342}
343
344
345std::string
347 switch (key) {
348 case SUMO_ATTR_ID:
350 case SUMO_ATTR_BEGIN:
351 return toString(myBegin);
352 case SUMO_ATTR_END:
353 return toString(myEnd);
354 default:
355 return getCommonAttribute(key);
356 }
357}
358
359
360double
362 switch (key) {
363 case SUMO_ATTR_BEGIN:
364 return myBegin;
365 case SUMO_ATTR_END:
366 return myEnd;
367 default:
368 return getCommonAttributeDouble(key);
369 }
370}
371
372
377
378
383
384
385void
386GNEDataInterval::setAttribute(SumoXMLAttr key, const std::string& value, GNEUndoList* undoList) {
387 switch (key) {
388 case SUMO_ATTR_BEGIN:
389 case SUMO_ATTR_END:
390 GNEChange_Attribute::changeAttribute(this, key, value, undoList);
391 break;
392 default:
393 setCommonAttribute(key, value, undoList);
394 break;
395 }
396}
397
398
399bool
400GNEDataInterval::isValid(SumoXMLAttr key, const std::string& value) {
401 switch (key) {
402 case SUMO_ATTR_BEGIN:
403 return canParse<double>(value);
404 case SUMO_ATTR_END:
405 return canParse<double>(value);
406 default:
407 return isCommonAttributeValid(key, value);
408 }
409}
410
411
412bool
414 switch (key) {
415 case SUMO_ATTR_ID:
416 return false;
417 default:
418 return true;
419 }
420}
421
422
423std::string
425 return getTagStr();
426}
427
428
429std::string
431 return "interval: " + getAttribute(SUMO_ATTR_BEGIN) + " -> " + getAttribute(SUMO_ATTR_END);
432}
433
434
435void
436GNEDataInterval::setAttribute(SumoXMLAttr key, const std::string& value) {
437 switch (key) {
438 case SUMO_ATTR_BEGIN:
439 myBegin = parse<double>(value);
440 // update Generic Data IDs
442 break;
443 case SUMO_ATTR_END:
444 myEnd = parse<double>(value);
445 // update Generic Data IDs
447 break;
448 default:
449 setCommonAttribute(key, value);
450 break;
451 }
452 // mark interval toolbar for update
454}
455
456/****************************************************************************/
#define TL(string)
Definition MsgHandler.h:304
@ 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
double getCommonAttributeDouble(SumoXMLAttr key) const
const std::string getID() const override
get ID (all Attribute Carriers have one)
PositionVector getCommonAttributePositionVector(SumoXMLAttr key) const
void setCommonAttribute(SumoXMLAttr key, const std::string &value, GNEUndoList *undoList)
const std::string & getTagStr() const
get tag assigned to this object in string format
bool isTemplate() const
check if this AC is template
Position getCommonAttributePosition(SumoXMLAttr key) const
GNENet * myNet
pointer to net
GNENet * getNet() const
get pointer to net
bool isCommonAttributeValid(SumoXMLAttr key, const std::string &value) const
virtual void updateGeometry()=0
update pre-computed geometry information
std::string getCommonAttribute(SumoXMLAttr key) const
static void changeAttribute(GNEAttributeCarrier *AC, SumoXMLAttr key, const std::string &value, GNEUndoList *undoList, const bool force=false)
change attribute
void fixDataIntervalProblem()
fix data element problem (by default throw an exception, has to be reimplemented in children)
Position getAttributePosition(SumoXMLAttr key) const override
double myBegin
begin interval
Position getPositionInView() const
Returns element position in view.
bool isAttributeEnabled(SumoXMLAttr key) const override
GNEDataInterval(GNEDataSet *dataSetParent, const double begin, const double end)
Constructor.
bool edgeRelExists(const GNEEdge *fromEdge, const GNEEdge *toEdge) const
check if there is already a edgeRel defined between two edges
GNEDataSet * myDataSetParent
GNEDataSet parent to which this data interval belongs.
double getAttributeDouble(SumoXMLAttr key) const override
void removeGenericDataChild(GNEGenericData *genericData)
add generic data child
bool checkDrawDeleteContourSmall() const override
check if draw delete contour small (pink/white)
Parameterised * getParameters() override
get parameters associated with this dataInterval
bool isValid(SumoXMLAttr key, const std::string &value) override
method for checking if the key and their conrrespond attribute are valids
void setAttribute(SumoXMLAttr key, const std::string &value, GNEUndoList *undoList) override
method for setting the attribute and letting the object perform data element changes
GNEHierarchicalElement * getHierarchicalElement() override
methods to retrieve the elements linked to this dataInterval
bool isDataIntervalValid() const
bool checkDrawFromContour() const override
check if draw from contour (green)
GNEDataSet * getDataSetParent() const
Returns a pointer to GNEDataSet parent.
std::string getHierarchyName() const override
get Hierarchy Name (Used in AC Hierarchy)
void updateGeometry() override
update pre-computed geometry information
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
bool edgeRelSingleExists(const GNEEdge *edge) const
check if there is already a edgeRel single defined in the given edge
GNEDataSet::AttributeColors myAllAttributeColors
all attribute colors
GNEMoveElement * getMoveElement() const override
get GNEMoveElement associated with this dataInterval
bool checkDrawRelatedContour() const override
check if draw related contour (cyan)
bool checkDrawOverContour() const override
check if draw over contour (orange)
const std::vector< GNEGenericData * > & getGenericDataChildren() const
get generic data children
bool checkDrawMoveContour() const override
check if draw move contour (red)
double myEnd
end interval
std::string getPopUpID() const override
get PopPup ID (Used in AC Hierarchy)
const std::map< SumoXMLTag, GNEDataSet::AttributeColors > & getSpecificAttributeColors() const
specific attribute colors
std::string getAttribute(SumoXMLAttr key) const override
void updateGenericDataIDs()
update generic data child IDs
~GNEDataInterval()
Destructor.
bool checkDrawToContour() const override
check if draw from contour (magenta)
std::map< SumoXMLTag, GNEDataSet::AttributeColors > mySpecificAttributeColors
specific attribute colors
std::string getDataIntervalProblem() const
return a string with the current data element problem (by default empty, can be reimplemented in chil...
FileBucket * getFileBucket() const override
get reference to fileBucket in which save this AC
PositionVector getAttributePositionVector(SumoXMLAttr key) const override
const GNEDataSet::AttributeColors & getAllAttributeColors() const
all attribute colors
std::vector< GNEGenericData * > myGenericDataChildren
vector with generic data children
GUIGlObject * getGUIGlObject() override
get GUIGlObject associated with this dataInterval
void addGenericDataChild(GNEGenericData *genericData)
add generic data child
bool checkDrawDeleteContour() const override
check if draw delete contour (pink/white)
void updateAttributeColors()
update attribute colors deprecated
bool checkDrawSelectContour() const override
check if draw select contour (blue)
void clear()
clear AttributeColors
void updateValues(const std::string &attribute, const double value)
update value for an specific attribute
void updateAttributeColors()
update attribute colors deprecated
FileBucket * getFileBucket() const override
get reference to fileBucket in which save this AC
std::string getAttribute(SumoXMLAttr key) const override
void removeCurrentEditedAttributeCarrier(const GNEAttributeCarrier *HE)
if given AttributeCarrier is the same of myHE, set it as nullptr
GNEDataInterval * getDataIntervalParent() const
get data interval parent
GNEElementTree * getHierarchicalElementTree() const
get GNEElementTree modul
void insertGenericData(GNEGenericData *genericData)
insert generic data in container
void deleteGenericData(GNEGenericData *genericData)
delete generic data of container
void addGLObjectIntoGrid(GNEAttributeCarrier *AC)
add GL Object into net
Definition GNENet.cpp:1444
GNEPathManager * getDataPathManager()
get data path manager
Definition GNENet.cpp:204
void removeGLObjectFromGrid(GNEAttributeCarrier *AC)
add GL Object into net
Definition GNENet.cpp:1454
GNENetHelper::AttributeCarriers * getAttributeCarriers() const
get all attribute carriers used in this net
Definition GNENet.cpp:174
bool isUpdateGeometryEnabled() const
check if update geometry after inserting or removing has to be updated
Definition GNENet.cpp:2881
bool isUpdateDataEnabled() const
check if update data after inserting or removing has to be updated
Definition GNENet.cpp:2904
GNEViewParent * getViewParent() const
get view parent (used for simplify code)
Definition GNENet.cpp:150
GNEViewNet * getViewNet() const
get view net (used for simplify code)
Definition GNENet.cpp:144
void removePath(GNEPathElement *pathElement)
remove path
void uninspectAC(GNEAttributeCarrier *AC)
uninspect AC
GNEViewNetHelper::InspectedElements & getInspectedElements()
get inspected elements
GNEViewNetHelper::IntervalBar & getIntervalBar()
get interval bar
GNEInspectorFrame * getInspectorFrame() const
get frame for inspect elements
virtual void setMicrosimID(const std::string &newID)
Changes the microsimID of the object.
An upper class for objects with additional parameters.
A point in 2D or 3D with translation and scaling methods.
Definition Position.h:37
A list of positions.