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->getFilename(), false),
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
195bool
197 return true;
198}
199
200
201std::string
203 return "";
204}
205
206
207void
209 throw InvalidArgument(getTagStr() + " cannot fix any problem");
210}
211
212
217
218
219void
221 // check that GenericData wasn't previously inserted
222 if (!hasGenericDataChild(genericData)) {
223 myGenericDataChildren.push_back(genericData);
224 // update generic data IDs
226 // check if add to boundary
227 if (genericData->getTagProperty()->isPlacedInRTree()) {
228 myNet->addGLObjectIntoGrid(genericData);
229 }
230 // update geometry after insertion if myUpdateGeometryEnabled is enabled
232 // update generic data RTREE
233 genericData->updateGeometry();
234 }
235 // add reference in attributeCarriers
237 // update colors
239 } else {
240 throw ProcessError(TL("GenericData was already inserted"));
241 }
242}
243
244
245void
247 auto it = std::find(myGenericDataChildren.begin(), myGenericDataChildren.end(), genericData);
248 // check that GenericData was previously inserted
249 if (it != myGenericDataChildren.end()) {
250 // remove generic data child
251 myGenericDataChildren.erase(it);
252 // remove it from inspected ACs and GNEElementTree
255 // update colors
257 // delete path element
258 myNet->getDataPathManager()->removePath(genericData);
259 // check if remove from RTREE
260 if (genericData->getTagProperty()->isPlacedInRTree()) {
261 myNet->removeGLObjectFromGrid(genericData);
262 }
263 // remove reference from attributeCarriers
265 } else {
266 throw ProcessError(TL("GenericData wasn't previously inserted"));
267 }
268}
269
270
271bool
273 return std::find(myGenericDataChildren.begin(), myGenericDataChildren.end(), genericData) != myGenericDataChildren.end();
274}
275
276
277const std::vector<GNEGenericData*>&
281
282
283bool
285 // interate over all edgeRels and check edge parents
286 for (const auto& genericData : myGenericDataChildren) {
287 if ((genericData->getTagProperty()->getTag() == GNE_TAG_EDGEREL_SINGLE) &&
288 (genericData->getParentEdges().front() == edge)) {
289 return true;
290 }
291 }
292 return false;
293}
294
295
296bool
297GNEDataInterval::edgeRelExists(const GNEEdge* fromEdge, const GNEEdge* toEdge) const {
298 // interate over all edgeRels and check edge parents
299 for (const auto& genericData : myGenericDataChildren) {
300 if ((genericData->getTagProperty()->getTag() == SUMO_TAG_EDGEREL) &&
301 (genericData->getParentEdges().front() == fromEdge) &&
302 (genericData->getParentEdges().back() == toEdge)) {
303 return true;
304 }
305 }
306 return false;
307}
308
309
310bool
312 // interate over all TAZRels and check TAZ parents
313 for (const auto& genericData : myGenericDataChildren) {
314 if ((genericData->getTagProperty()->getTag() == SUMO_TAG_TAZREL) &&
315 (genericData->getParentAdditionals().size() == 1) &&
316 (genericData->getParentAdditionals().front() == TAZ)) {
317 return true;
318 }
319 }
320 return false;
321}
322
323
324bool
325GNEDataInterval::TAZRelExists(const GNEAdditional* fromTAZ, const GNEAdditional* toTAZ) const {
326 // interate over all TAZRels and check TAZ parents
327 for (const auto& genericData : myGenericDataChildren) {
328 if ((genericData->getTagProperty()->getTag() == SUMO_TAG_TAZREL) &&
329 (genericData->getParentAdditionals().size() == 2) &&
330 (genericData->getParentAdditionals().front() == fromTAZ) &&
331 (genericData->getParentAdditionals().back() == toTAZ)) {
332 return true;
333 }
334 }
335 return false;
336}
337
338
339std::string
341 switch (key) {
342 case SUMO_ATTR_ID:
344 case SUMO_ATTR_BEGIN:
345 return toString(myBegin);
346 case SUMO_ATTR_END:
347 return toString(myEnd);
348 default:
349 return getCommonAttribute(key);
350 }
351}
352
353
354double
356 switch (key) {
357 case SUMO_ATTR_BEGIN:
358 return myBegin;
359 case SUMO_ATTR_END:
360 return myEnd;
361 default:
362 return getCommonAttributeDouble(key);
363 }
364}
365
366
371
372
377
378
379void
380GNEDataInterval::setAttribute(SumoXMLAttr key, const std::string& value, GNEUndoList* undoList) {
381 switch (key) {
382 case SUMO_ATTR_BEGIN:
383 case SUMO_ATTR_END:
384 GNEChange_Attribute::changeAttribute(this, key, value, undoList);
385 break;
386 default:
387 setCommonAttribute(key, value, undoList);
388 break;
389 }
390}
391
392
393bool
394GNEDataInterval::isValid(SumoXMLAttr key, const std::string& value) {
395 switch (key) {
396 case SUMO_ATTR_BEGIN:
397 return canParse<double>(value);
398 case SUMO_ATTR_END:
399 return canParse<double>(value);
400 default:
401 return isCommonAttributeValid(key, value);
402 }
403}
404
405
406bool
408 switch (key) {
409 case SUMO_ATTR_ID:
410 return false;
411 default:
412 return true;
413 }
414}
415
416
417std::string
419 return getTagStr();
420}
421
422
423std::string
425 return "interval: " + getAttribute(SUMO_ATTR_BEGIN) + " -> " + getAttribute(SUMO_ATTR_END);
426}
427
428
429void
430GNEDataInterval::setAttribute(SumoXMLAttr key, const std::string& value) {
431 switch (key) {
432 case SUMO_ATTR_BEGIN:
433 myBegin = parse<double>(value);
434 // update Generic Data IDs
436 break;
437 case SUMO_ATTR_END:
438 myEnd = parse<double>(value);
439 // update Generic Data IDs
441 break;
442 default:
443 setCommonAttribute(key, value);
444 break;
445 }
446 // mark interval toolbar for update
448}
449
450/****************************************************************************/
#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
const std::string getID() const
get ID (all Attribute Carriers have one)
double getCommonAttributeDouble(SumoXMLAttr key) const
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
Position getCommonAttributePosition(SumoXMLAttr key) const
const GNETagProperties * getTagProperty() const
get tagProperty associated with this Attribute Carrier
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
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.
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...
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
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:1440
GNEPathManager * getDataPathManager()
get data path manager
Definition GNENet.cpp:180
void removeGLObjectFromGrid(GNEAttributeCarrier *AC)
add GL Object into net
Definition GNENet.cpp:1450
GNENetHelper::AttributeCarriers * getAttributeCarriers() const
get all attribute carriers used in this net
Definition GNENet.cpp:144
bool isUpdateGeometryEnabled() const
check if update geometry after inserting or removing has to be updated
Definition GNENet.cpp:2907
bool isUpdateDataEnabled() const
check if update data after inserting or removing has to be updated
Definition GNENet.cpp:2930
GNEViewNet * getViewNet() const
get view net
Definition GNENet.cpp:2193
void removePath(GNEPathElement *pathElement)
remove path
bool isPlacedInRTree() const
return true if Tag correspond to an element that has to be placed in RTREE
void uninspectAC(GNEAttributeCarrier *AC)
uninspect AC
GNEViewNetHelper::InspectedElements & getInspectedElements()
get inspected elements
GNEViewNetHelper::IntervalBar & getIntervalBar()
get interval bar
GNEViewParent * getViewParent() const
get the net object
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.