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 // add id RTREE
227 myNet->addGLObjectIntoGrid(genericData);
228 // update geometry after insertion if myUpdateGeometryEnabled is enabled
230 // update generic data RTREE
231 genericData->updateGeometry();
232 }
233 // add reference in attributeCarriers
235 // update colors
237 } else {
238 throw ProcessError(TL("GenericData was already inserted"));
239 }
240}
241
242
243void
245 auto it = std::find(myGenericDataChildren.begin(), myGenericDataChildren.end(), genericData);
246 // check that GenericData was previously inserted
247 if (it != myGenericDataChildren.end()) {
248 // remove generic data child
249 myGenericDataChildren.erase(it);
250 // remove it from inspected ACs and GNEElementTree
253 // update colors
255 // delete path element
256 myNet->getDataPathManager()->removePath(genericData);
257 // add in RTREE
258 myNet->removeGLObjectFromGrid(genericData);
259 // remove reference from attributeCarriers
261 } else {
262 throw ProcessError(TL("GenericData wasn't previously inserted"));
263 }
264}
265
266
267bool
269 return std::find(myGenericDataChildren.begin(), myGenericDataChildren.end(), genericData) != myGenericDataChildren.end();
270}
271
272
273const std::vector<GNEGenericData*>&
277
278
279bool
281 // interate over all edgeRels and check edge parents
282 for (const auto& genericData : myGenericDataChildren) {
283 if ((genericData->getTagProperty()->getTag() == GNE_TAG_EDGEREL_SINGLE) &&
284 (genericData->getParentEdges().front() == edge)) {
285 return true;
286 }
287 }
288 return false;
289}
290
291
292bool
293GNEDataInterval::edgeRelExists(const GNEEdge* fromEdge, const GNEEdge* toEdge) const {
294 // interate over all edgeRels and check edge parents
295 for (const auto& genericData : myGenericDataChildren) {
296 if ((genericData->getTagProperty()->getTag() == SUMO_TAG_EDGEREL) &&
297 (genericData->getParentEdges().front() == fromEdge) &&
298 (genericData->getParentEdges().back() == toEdge)) {
299 return true;
300 }
301 }
302 return false;
303}
304
305
306bool
308 // interate over all TAZRels and check TAZ parents
309 for (const auto& genericData : myGenericDataChildren) {
310 if ((genericData->getTagProperty()->getTag() == SUMO_TAG_TAZREL) &&
311 (genericData->getParentAdditionals().size() == 1) &&
312 (genericData->getParentAdditionals().front() == TAZ)) {
313 return true;
314 }
315 }
316 return false;
317}
318
319
320bool
321GNEDataInterval::TAZRelExists(const GNEAdditional* fromTAZ, const GNEAdditional* toTAZ) const {
322 // interate over all TAZRels and check TAZ parents
323 for (const auto& genericData : myGenericDataChildren) {
324 if ((genericData->getTagProperty()->getTag() == SUMO_TAG_TAZREL) &&
325 (genericData->getParentAdditionals().size() == 2) &&
326 (genericData->getParentAdditionals().front() == fromTAZ) &&
327 (genericData->getParentAdditionals().back() == toTAZ)) {
328 return true;
329 }
330 }
331 return false;
332}
333
334
335std::string
337 switch (key) {
338 case SUMO_ATTR_ID:
340 case SUMO_ATTR_BEGIN:
341 return toString(myBegin);
342 case SUMO_ATTR_END:
343 return toString(myEnd);
344 default:
345 return getCommonAttribute(key);
346 }
347}
348
349
350double
352 switch (key) {
353 case SUMO_ATTR_BEGIN:
354 return myBegin;
355 case SUMO_ATTR_END:
356 return myEnd;
357 default:
358 return getCommonAttributeDouble(key);
359 }
360}
361
362
367
368
373
374
375void
376GNEDataInterval::setAttribute(SumoXMLAttr key, const std::string& value, GNEUndoList* undoList) {
377 switch (key) {
378 case SUMO_ATTR_BEGIN:
379 case SUMO_ATTR_END:
380 GNEChange_Attribute::changeAttribute(this, key, value, undoList);
381 break;
382 default:
383 setCommonAttribute(key, value, undoList);
384 break;
385 }
386}
387
388
389bool
390GNEDataInterval::isValid(SumoXMLAttr key, const std::string& value) {
391 switch (key) {
392 case SUMO_ATTR_BEGIN:
393 return canParse<double>(value);
394 case SUMO_ATTR_END:
395 return canParse<double>(value);
396 default:
397 return isCommonAttributeValid(key, value);
398 }
399}
400
401
402bool
404 switch (key) {
405 case SUMO_ATTR_ID:
406 return false;
407 default:
408 return true;
409 }
410}
411
412
413std::string
415 return getTagStr();
416}
417
418
419std::string
421 return "interval: " + getAttribute(SUMO_ATTR_BEGIN) + " -> " + getAttribute(SUMO_ATTR_END);
422}
423
424
425void
426GNEDataInterval::setAttribute(SumoXMLAttr key, const std::string& value) {
427 switch (key) {
428 case SUMO_ATTR_BEGIN:
429 myBegin = parse<double>(value);
430 // update Generic Data IDs
432 break;
433 case SUMO_ATTR_END:
434 myEnd = parse<double>(value);
435 // update Generic Data IDs
437 break;
438 default:
439 setCommonAttribute(key, value);
440 break;
441 }
442 // mark interval toolbar for update
444}
445
446/****************************************************************************/
#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
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...
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:2879
bool isUpdateDataEnabled() const
check if update data after inserting or removing has to be updated
Definition GNENet.cpp:2902
GNEViewNet * getViewNet() const
get view net
Definition GNENet.cpp:2193
void removePath(GNEPathElement *pathElement)
remove path
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.