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
51void
54 // iterate over generic data childrens
55 for (const auto& genericData : myGenericDataChildren) {
56 if (genericData->getTagProperty()->getTag() == GNE_TAG_EDGEREL_SINGLE) {
57 // {dataset}[{begin}m{end}]{edge}
58 genericData->setMicrosimID(myDataSetParent->getID() + "[" + toString(myBegin) + "," + toString(myEnd) + "]" +
59 genericData->getParentEdges().front()->getID());
60 } else if (genericData->getTagProperty()->getTag() == SUMO_TAG_EDGEREL) {
61 // {dataset}[{begin}m{end}]{from}->{to}
62 genericData->setMicrosimID(myDataSetParent->getID() + "[" + toString(myBegin) + "," + toString(myEnd) + "]" +
63 genericData->getParentEdges().front()->getID() + "->" + genericData->getParentEdges().back()->getID());
64 }
65 }
66 }
67}
68
69
70void
73 // first clear both container
76 // iterate over generic data children
77 for (const auto& genericData : myGenericDataChildren) {
78 for (const auto& param : genericData->getParametersMap()) {
79 // check if value can be parsed
80 if (canParse<double>(param.second)) {
81 // parse param value
82 const double value = parse<double>(param.second);
83 // update values in both containers
84 myAllAttributeColors.updateValues(param.first, value);
85 mySpecificAttributeColors[genericData->getTagProperty()->getTag()].updateValues(param.first, value);
86 }
87 }
88 }
89 }
90}
91
92
97
98
99const std::map<SumoXMLTag, GNEDataSet::AttributeColors>&
103
104
107 return nullptr;
108}
109
110
111const GUIGlObject*
113 return nullptr;
114}
115
116
117void
119 // nothing to update
120}
121
122
125 return Position();
126}
127
128
129bool
131 return false;
132}
133
134
135bool
137 return false;
138}
139
140
141bool
143 return false;
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 true;
180}
181
182
183std::string
185 return "";
186}
187
188
189void
191 throw InvalidArgument(getTagStr() + " cannot fix any problem");
192}
193
194
199
200
201void
203 // check that GenericData wasn't previously inserted
204 if (!hasGenericDataChild(genericData)) {
205 myGenericDataChildren.push_back(genericData);
206 // update generic data IDs
208 // check if add to boundary
209 if (genericData->getTagProperty()->isPlacedInRTree()) {
210 myNet->addGLObjectIntoGrid(genericData);
211 }
212 // update geometry after insertion if myUpdateGeometryEnabled is enabled
214 // update generic data RTREE
215 genericData->updateGeometry();
216 }
217 // add reference in attributeCarriers
219 // update colors
221 } else {
222 throw ProcessError(TL("GenericData was already inserted"));
223 }
224}
225
226
227void
229 auto it = std::find(myGenericDataChildren.begin(), myGenericDataChildren.end(), genericData);
230 // check that GenericData was previously inserted
231 if (it != myGenericDataChildren.end()) {
232 // remove generic data child
233 myGenericDataChildren.erase(it);
234 // remove it from inspected ACs and GNEElementTree
237 // update colors
239 // delete path element
240 myNet->getDataPathManager()->removePath(genericData);
241 // check if remove from RTREE
242 if (genericData->getTagProperty()->isPlacedInRTree()) {
243 myNet->removeGLObjectFromGrid(genericData);
244 }
245 // remove reference from attributeCarriers
247 } else {
248 throw ProcessError(TL("GenericData wasn't previously inserted"));
249 }
250}
251
252
253bool
255 return std::find(myGenericDataChildren.begin(), myGenericDataChildren.end(), genericData) != myGenericDataChildren.end();
256}
257
258
259const std::vector<GNEGenericData*>&
263
264
265bool
266GNEDataInterval::edgeRelExists(const GNEEdge* fromEdge, const GNEEdge* toEdge) const {
267 // interate over all edgeRels and check edge parents
268 for (const auto& genericData : myGenericDataChildren) {
269 if ((genericData->getTagProperty()->getTag() == SUMO_TAG_EDGEREL) &&
270 (genericData->getParentEdges().front() == fromEdge) &&
271 (genericData->getParentEdges().back() == toEdge)) {
272 return true;
273 }
274 }
275 return false;
276}
277
278
279bool
281 // interate over all TAZRels and check TAZ parents
282 for (const auto& genericData : myGenericDataChildren) {
283 if ((genericData->getTagProperty()->getTag() == SUMO_TAG_TAZREL) &&
284 (genericData->getParentAdditionals().size() == 1) &&
285 (genericData->getParentAdditionals().front() == TAZ)) {
286 return true;
287 }
288 }
289 return false;
290}
291
292
293bool
294GNEDataInterval::TAZRelExists(const GNEAdditional* fromTAZ, const GNEAdditional* toTAZ) const {
295 // interate over all TAZRels and check TAZ parents
296 for (const auto& genericData : myGenericDataChildren) {
297 if ((genericData->getTagProperty()->getTag() == SUMO_TAG_TAZREL) &&
298 (genericData->getParentAdditionals().size() == 2) &&
299 (genericData->getParentAdditionals().front() == fromTAZ) &&
300 (genericData->getParentAdditionals().back() == toTAZ)) {
301 return true;
302 }
303 }
304 return false;
305}
306
307
308std::string
310 switch (key) {
311 case SUMO_ATTR_ID:
313 case SUMO_ATTR_BEGIN:
314 return toString(myBegin);
315 case SUMO_ATTR_END:
316 return toString(myEnd);
317 default:
318 return getCommonAttribute(this, key);
319 }
320}
321
322
323double
325 switch (key) {
326 case SUMO_ATTR_BEGIN:
327 return myBegin;
328 case SUMO_ATTR_END:
329 return myEnd;
330 default:
331 throw InvalidArgument(getTagStr() + " doesn't have a double attribute of type '" + toString(key) + "'");
332 }
333}
334
335
336void
337GNEDataInterval::setAttribute(SumoXMLAttr key, const std::string& value, GNEUndoList* undoList) {
338 switch (key) {
339 case SUMO_ATTR_BEGIN:
340 case SUMO_ATTR_END:
341 GNEChange_Attribute::changeAttribute(this, key, value, undoList);
342 break;
343 default:
344 setCommonAttribute(key, value, undoList);
345 break;
346 }
347}
348
349
350bool
351GNEDataInterval::isValid(SumoXMLAttr key, const std::string& value) {
352 switch (key) {
353 case SUMO_ATTR_BEGIN:
354 return canParse<double>(value);
355 case SUMO_ATTR_END:
356 return canParse<double>(value);
357 default:
358 return isCommonValid(key, value);
359 }
360}
361
362
363bool
365 switch (key) {
366 case SUMO_ATTR_ID:
367 return false;
368 default:
369 return true;
370 }
371}
372
373
374std::string
376 return getTagStr();
377}
378
379
380std::string
382 return "interval: " + getAttribute(SUMO_ATTR_BEGIN) + " -> " + getAttribute(SUMO_ATTR_END);
383}
384
385
390
391
392void
393GNEDataInterval::setAttribute(SumoXMLAttr key, const std::string& value) {
394 switch (key) {
395 case SUMO_ATTR_BEGIN:
396 myBegin = parse<double>(value);
397 // update Generic Data IDs
399 break;
400 case SUMO_ATTR_END:
401 myEnd = parse<double>(value);
402 // update Generic Data IDs
404 break;
405 default:
406 setCommonAttribute(this, key, value);
407 break;
408 }
409 // mark interval toolbar for update
411}
412
413/****************************************************************************/
#define TL(string)
Definition MsgHandler.h:305
@ 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)
std::string getCommonAttribute(const Parameterised *parameterised, 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
const GNETagProperties * getTagProperty() const
get tagProperty associated with this Attribute Carrier
GNENet * myNet
pointer to net
bool isCommonValid(SumoXMLAttr key, const std::string &value) const
GNENet * getNet() const
get pointer to net
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...
bool checkDrawDeleteContourSmall() const
check if draw delete contour small (pink/white)
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
GNEHierarchicalElement * getHierarchicalElement()
get GNEHierarchicalElement associated with this AttributeCarrier
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
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:1443
GNEPathManager * getDataPathManager()
get data path manager
Definition GNENet.cpp:183
void removeGLObjectFromGrid(GNEAttributeCarrier *AC)
add GL Object into net
Definition GNENet.cpp:1453
GNENetHelper::AttributeCarriers * getAttributeCarriers() const
get all attribute carriers used in this net
Definition GNENet.cpp:147
bool isUpdateGeometryEnabled() const
check if update geometry after inserting or removing has to be updated
Definition GNENet.cpp:2918
bool isUpdateDataEnabled() const
check if update data after inserting or removing has to be updated
Definition GNENet.cpp:2941
GNEViewNet * getViewNet() const
get view net
Definition GNENet.cpp:2195
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