Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
eclipse
GitHub Repository: eclipse/sumo
Path: blob/main/src/netedit/elements/data/GNEDataInterval.cpp
169684 views
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
/****************************************************************************/
14
/// @file GNEDataInterval.cpp
15
/// @author Pablo Alvarez Lopez
16
/// @date Jan 2020
17
///
18
// A abstract class for data sets
19
/****************************************************************************/
20
21
#include <netedit/GNENet.h>
22
#include <netedit/GNETagProperties.h>
23
#include <netedit/GNEViewParent.h>
24
#include <netedit/changes/GNEChange_Attribute.h>
25
#include <netedit/frames/GNEElementTree.h>
26
#include <netedit/frames/common/GNEInspectorFrame.h>
27
28
#include "GNEDataInterval.h"
29
30
// ===========================================================================
31
// member method definitions
32
// ===========================================================================
33
34
GNEDataInterval::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
42
GNEDataInterval::~GNEDataInterval() {}
43
44
45
GNEHierarchicalElement*
46
GNEDataInterval::getHierarchicalElement() {
47
return this;
48
}
49
50
51
void
52
GNEDataInterval::updateGenericDataIDs() {
53
if (myNet->isUpdateDataEnabled()) {
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
70
void
71
GNEDataInterval::updateAttributeColors() {
72
if (myNet->isUpdateDataEnabled()) {
73
// first clear both container
74
myAllAttributeColors.clear();
75
mySpecificAttributeColors.clear();
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
93
const GNEDataSet::AttributeColors&
94
GNEDataInterval::getAllAttributeColors() const {
95
return myAllAttributeColors;
96
}
97
98
99
const std::map<SumoXMLTag, GNEDataSet::AttributeColors>&
100
GNEDataInterval::getSpecificAttributeColors() const {
101
return mySpecificAttributeColors;
102
}
103
104
105
GUIGlObject*
106
GNEDataInterval::getGUIGlObject() {
107
return nullptr;
108
}
109
110
111
const GUIGlObject*
112
GNEDataInterval::getGUIGlObject() const {
113
return nullptr;
114
}
115
116
117
void
118
GNEDataInterval::updateGeometry() {
119
// nothing to update
120
}
121
122
123
Position
124
GNEDataInterval::getPositionInView() const {
125
return Position();
126
}
127
128
129
bool
130
GNEDataInterval::checkDrawFromContour() const {
131
return false;
132
}
133
134
135
bool
136
GNEDataInterval::checkDrawToContour() const {
137
return false;
138
}
139
140
141
bool
142
GNEDataInterval::checkDrawRelatedContour() const {
143
return false;
144
}
145
146
147
bool
148
GNEDataInterval::checkDrawOverContour() const {
149
return false;
150
}
151
152
153
bool
154
GNEDataInterval::checkDrawDeleteContour() const {
155
return false;
156
}
157
158
159
bool
160
GNEDataInterval::checkDrawDeleteContourSmall() const {
161
return false;
162
}
163
164
165
bool
166
GNEDataInterval::checkDrawSelectContour() const {
167
return false;
168
}
169
170
171
bool
172
GNEDataInterval::checkDrawMoveContour() const {
173
return false;
174
}
175
176
177
bool
178
GNEDataInterval::isDataIntervalValid() const {
179
return true;
180
}
181
182
183
std::string
184
GNEDataInterval::getDataIntervalProblem() const {
185
return "";
186
}
187
188
189
void
190
GNEDataInterval::fixDataIntervalProblem() {
191
throw InvalidArgument(getTagStr() + " cannot fix any problem");
192
}
193
194
195
GNEDataSet*
196
GNEDataInterval::getDataSetParent() const {
197
return myDataSetParent;
198
}
199
200
201
void
202
GNEDataInterval::addGenericDataChild(GNEGenericData* genericData) {
203
// check that GenericData wasn't previously inserted
204
if (!hasGenericDataChild(genericData)) {
205
myGenericDataChildren.push_back(genericData);
206
// update generic data IDs
207
updateGenericDataIDs();
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
213
if (myNet->isUpdateGeometryEnabled()) {
214
// update generic data RTREE
215
genericData->updateGeometry();
216
}
217
// add reference in attributeCarriers
218
myNet->getAttributeCarriers()->insertGenericData(genericData);
219
// update colors
220
genericData->getDataIntervalParent()->getDataSetParent()->updateAttributeColors();
221
} else {
222
throw ProcessError(TL("GenericData was already inserted"));
223
}
224
}
225
226
227
void
228
GNEDataInterval::removeGenericDataChild(GNEGenericData* genericData) {
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
235
myDataSetParent->getNet()->getViewNet()->getInspectedElements().uninspectAC(genericData);
236
myDataSetParent->getNet()->getViewNet()->getViewParent()->getInspectorFrame()->getHierarchicalElementTree()->removeCurrentEditedAttributeCarrier(genericData);
237
// update colors
238
genericData->getDataIntervalParent()->getDataSetParent()->updateAttributeColors();
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
246
myNet->getAttributeCarriers()->deleteGenericData(genericData);
247
} else {
248
throw ProcessError(TL("GenericData wasn't previously inserted"));
249
}
250
}
251
252
253
bool
254
GNEDataInterval::hasGenericDataChild(GNEGenericData* genericData) const {
255
return std::find(myGenericDataChildren.begin(), myGenericDataChildren.end(), genericData) != myGenericDataChildren.end();
256
}
257
258
259
const std::vector<GNEGenericData*>&
260
GNEDataInterval::getGenericDataChildren() const {
261
return myGenericDataChildren;
262
}
263
264
265
bool
266
GNEDataInterval::edgeRelSingleExists(const GNEEdge* edge) const {
267
// interate over all edgeRels and check edge parents
268
for (const auto& genericData : myGenericDataChildren) {
269
if ((genericData->getTagProperty()->getTag() == GNE_TAG_EDGEREL_SINGLE) &&
270
(genericData->getParentEdges().front() == edge)) {
271
return true;
272
}
273
}
274
return false;
275
}
276
277
278
bool
279
GNEDataInterval::edgeRelExists(const GNEEdge* fromEdge, const GNEEdge* toEdge) const {
280
// interate over all edgeRels and check edge parents
281
for (const auto& genericData : myGenericDataChildren) {
282
if ((genericData->getTagProperty()->getTag() == SUMO_TAG_EDGEREL) &&
283
(genericData->getParentEdges().front() == fromEdge) &&
284
(genericData->getParentEdges().back() == toEdge)) {
285
return true;
286
}
287
}
288
return false;
289
}
290
291
292
bool
293
GNEDataInterval::TAZRelExists(const GNEAdditional* TAZ) 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() == 1) &&
298
(genericData->getParentAdditionals().front() == TAZ)) {
299
return true;
300
}
301
}
302
return false;
303
}
304
305
306
bool
307
GNEDataInterval::TAZRelExists(const GNEAdditional* fromTAZ, const GNEAdditional* toTAZ) const {
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() == 2) &&
312
(genericData->getParentAdditionals().front() == fromTAZ) &&
313
(genericData->getParentAdditionals().back() == toTAZ)) {
314
return true;
315
}
316
}
317
return false;
318
}
319
320
321
std::string
322
GNEDataInterval::getAttribute(SumoXMLAttr key) const {
323
switch (key) {
324
case SUMO_ATTR_ID:
325
return myDataSetParent->getAttribute(SUMO_ATTR_ID);
326
case SUMO_ATTR_BEGIN:
327
return toString(myBegin);
328
case SUMO_ATTR_END:
329
return toString(myEnd);
330
default:
331
return getCommonAttribute(this, key);
332
}
333
}
334
335
336
double
337
GNEDataInterval::getAttributeDouble(SumoXMLAttr key) const {
338
switch (key) {
339
case SUMO_ATTR_BEGIN:
340
return myBegin;
341
case SUMO_ATTR_END:
342
return myEnd;
343
default:
344
throw InvalidArgument(getTagStr() + " doesn't have a double attribute of type '" + toString(key) + "'");
345
}
346
}
347
348
349
void
350
GNEDataInterval::setAttribute(SumoXMLAttr key, const std::string& value, GNEUndoList* undoList) {
351
switch (key) {
352
case SUMO_ATTR_BEGIN:
353
case SUMO_ATTR_END:
354
GNEChange_Attribute::changeAttribute(this, key, value, undoList);
355
break;
356
default:
357
setCommonAttribute(key, value, undoList);
358
break;
359
}
360
}
361
362
363
bool
364
GNEDataInterval::isValid(SumoXMLAttr key, const std::string& value) {
365
switch (key) {
366
case SUMO_ATTR_BEGIN:
367
return canParse<double>(value);
368
case SUMO_ATTR_END:
369
return canParse<double>(value);
370
default:
371
return isCommonValid(key, value);
372
}
373
}
374
375
376
bool
377
GNEDataInterval::isAttributeEnabled(SumoXMLAttr key) const {
378
switch (key) {
379
case SUMO_ATTR_ID:
380
return false;
381
default:
382
return true;
383
}
384
}
385
386
387
std::string
388
GNEDataInterval::getPopUpID() const {
389
return getTagStr();
390
}
391
392
393
std::string
394
GNEDataInterval::getHierarchyName() const {
395
return "interval: " + getAttribute(SUMO_ATTR_BEGIN) + " -> " + getAttribute(SUMO_ATTR_END);
396
}
397
398
399
const Parameterised::Map&
400
GNEDataInterval::getACParametersMap() const {
401
return getParametersMap();
402
}
403
404
405
void
406
GNEDataInterval::setAttribute(SumoXMLAttr key, const std::string& value) {
407
switch (key) {
408
case SUMO_ATTR_BEGIN:
409
myBegin = parse<double>(value);
410
// update Generic Data IDs
411
updateGenericDataIDs();
412
break;
413
case SUMO_ATTR_END:
414
myEnd = parse<double>(value);
415
// update Generic Data IDs
416
updateGenericDataIDs();
417
break;
418
default:
419
setCommonAttribute(this, key, value);
420
break;
421
}
422
// mark interval toolbar for update
423
myNet->getViewNet()->getIntervalBar().markForUpdate();
424
}
425
426
/****************************************************************************/
427
428