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-2024 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
116const GUIGlObject*
118 return nullptr;
119}
120
121
122void
124 // nothing to update
125}
126
127
130 return Position();
131}
132
133
134bool
136 return false;
137}
138
139
140bool
142 return false;
143}
144
145
146bool
148 return false;
149}
150
151
152bool
154 return false;
155}
156
157
158bool
160 return false;
161}
162
163
164bool
166 return false;
167}
168
169
170bool
172 return false;
173}
174
175
176bool
178 return true;
179}
180
181
182std::string
184 return "";
185}
186
187
188void
190 throw InvalidArgument(getTagStr() + " cannot fix any problem");
191}
192
193
198
199
200void
202 // check that GenericData wasn't previously inserted
203 if (!hasGenericDataChild(genericData)) {
204 myGenericDataChildren.push_back(genericData);
205 // update generic data IDs
207 // check if add to boundary
208 if (genericData->getTagProperty().isPlacedInRTree()) {
209 myNet->addGLObjectIntoGrid(genericData);
210 }
211 // update geometry after insertion if myUpdateGeometryEnabled is enabled
213 // update generic data RTREE
214 genericData->updateGeometry();
215 }
216 // add reference in attributeCarriers
218 // update colors
220 } else {
221 throw ProcessError(TL("GenericData was already inserted"));
222 }
223}
224
225
226void
228 auto it = std::find(myGenericDataChildren.begin(), myGenericDataChildren.end(), genericData);
229 // check that GenericData was previously inserted
230 if (it != myGenericDataChildren.end()) {
231 // remove generic data child
232 myGenericDataChildren.erase(it);
233 // remove it from inspected ACs and GNEElementTree
236 // update colors
238 // delete path element
239 myNet->getDataPathManager()->removePath(genericData);
240 // check if remove from RTREE
241 if (genericData->getTagProperty().isPlacedInRTree()) {
242 myNet->removeGLObjectFromGrid(genericData);
243 }
244 // remove reference from attributeCarriers
246 } else {
247 throw ProcessError(TL("GenericData wasn't previously inserted"));
248 }
249}
250
251
252bool
254 return std::find(myGenericDataChildren.begin(), myGenericDataChildren.end(), genericData) != myGenericDataChildren.end();
255}
256
257
258const std::vector<GNEGenericData*>&
262
263
264bool
265GNEDataInterval::edgeRelExists(const GNEEdge* fromEdge, const GNEEdge* toEdge) const {
266 // interate over all edgeRels and check edge parents
267 for (const auto& genericData : myGenericDataChildren) {
268 if ((genericData->getTagProperty().getTag() == SUMO_TAG_EDGEREL) &&
269 (genericData->getParentEdges().front() == fromEdge) &&
270 (genericData->getParentEdges().back() == toEdge)) {
271 return true;
272 }
273 }
274 return false;
275}
276
277
278bool
280 // interate over all TAZRels and check TAZ parents
281 for (const auto& genericData : myGenericDataChildren) {
282 if ((genericData->getTagProperty().getTag() == SUMO_TAG_TAZREL) &&
283 (genericData->getParentAdditionals().size() == 1) &&
284 (genericData->getParentAdditionals().front() == TAZ)) {
285 return true;
286 }
287 }
288 return false;
289}
290
291
292bool
293GNEDataInterval::TAZRelExists(const GNEAdditional* fromTAZ, const GNEAdditional* toTAZ) const {
294 // interate over all TAZRels and check TAZ parents
295 for (const auto& genericData : myGenericDataChildren) {
296 if ((genericData->getTagProperty().getTag() == SUMO_TAG_TAZREL) &&
297 (genericData->getParentAdditionals().size() == 2) &&
298 (genericData->getParentAdditionals().front() == fromTAZ) &&
299 (genericData->getParentAdditionals().back() == toTAZ)) {
300 return true;
301 }
302 }
303 return false;
304}
305
306
307std::string
309 switch (key) {
310 case SUMO_ATTR_ID:
312 case SUMO_ATTR_BEGIN:
313 return toString(myBegin);
314 case SUMO_ATTR_END:
315 return toString(myEnd);
316 default:
317 return getCommonAttribute(key);
318 }
319}
320
321
322double
324 switch (key) {
325 case SUMO_ATTR_BEGIN:
326 return myBegin;
327 case SUMO_ATTR_END:
328 return myEnd;
329 default:
330 throw InvalidArgument(getTagStr() + " doesn't have a double attribute of type '" + toString(key) + "'");
331 }
332}
333
334
335void
336GNEDataInterval::setAttribute(SumoXMLAttr key, const std::string& value, GNEUndoList* undoList) {
337 switch (key) {
338 case SUMO_ATTR_BEGIN:
339 case SUMO_ATTR_END:
340 GNEChange_Attribute::changeAttribute(this, key, value, undoList);
341 break;
342 default:
343 setCommonAttribute(key, value, undoList);
344 break;
345 }
346}
347
348
349bool
350GNEDataInterval::isValid(SumoXMLAttr key, const std::string& value) {
351 switch (key) {
352 case SUMO_ATTR_BEGIN:
353 return canParse<double>(value);
354 case SUMO_ATTR_END:
355 return canParse<double>(value);
356 default:
357 return isCommonValid(key, value);
358 }
359}
360
361
362bool
364 switch (key) {
365 case SUMO_ATTR_ID:
366 return false;
367 default:
368 return true;
369 }
370}
371
372
373std::string
375 return getTagStr();
376}
377
378
379std::string
381 return "interval: " + getAttribute(SUMO_ATTR_BEGIN) + " -> " + getAttribute(SUMO_ATTR_END);
382}
383
384
389
390
391void
392GNEDataInterval::setAttribute(SumoXMLAttr key, const std::string& value) {
393 switch (key) {
394 case SUMO_ATTR_BEGIN:
395 myBegin = parse<double>(value);
396 // update Generic Data IDs
398 break;
399 case SUMO_ATTR_END:
400 myEnd = parse<double>(value);
401 // update Generic Data IDs
403 break;
404 default:
405 setCommonAttribute(key, value);
406 break;
407 }
408 // mark interval toolbar for update
410}
411
412/****************************************************************************/
#define TL(string)
Definition MsgHandler.h:315
@ 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)
void setCommonAttribute(SumoXMLAttr key, const std::string &value, GNEUndoList *undoList)
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
bool isCommonValid(SumoXMLAttr key, const std::string &value)
GNENet * myNet
pointer to net
GNENet * getNet() const
get pointer to net
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)
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 checkDrawRelatedContour() const
check if draw related contour (cyan)
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.
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
bool checkDrawMoveContour() const
check if draw move contour (red)
bool checkDrawFromContour() const
check if draw from contour (green)
const std::vector< GNEGenericData * > & getGenericDataChildren() const
get generic data children
bool checkDrawToContour() const
check if draw from contour (magenta)
double myEnd
end interval
bool checkDrawOverContour() const
check if draw over contour (orange)
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
bool checkDrawSelectContour() const
check if draw select contour (blue)
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
bool checkDrawDeleteContour() const
check if draw delete contour (pink/white)
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
A road/street connecting two junctions (netedit-version)
Definition GNEEdge.h:53
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.
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 in container
void deleteGenericData(GNEGenericData *genericData)
delete generic data of container
void addGLObjectIntoGrid(GNEAttributeCarrier *AC)
add GL Object into net
Definition GNENet.cpp:1390
GNEPathManager * getDataPathManager()
get data path manager
Definition GNENet.cpp:151
void removeGLObjectFromGrid(GNEAttributeCarrier *AC)
add GL Object into net
Definition GNENet.cpp:1400
GNENetHelper::AttributeCarriers * getAttributeCarriers() const
get all attribute carriers used in this net
Definition GNENet.cpp:127
bool isUpdateGeometryEnabled() const
check if update geometry after inserting or removing has to be updated
Definition GNENet.cpp:2843
bool isUpdateDataEnabled() const
check if update data after inserting or removing has to be updated
Definition GNENet.cpp:2866
GNEViewNet * getViewNet() const
get view net
Definition GNENet.cpp:2163
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
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