Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
eclipse
GitHub Repository: eclipse/sumo
Path: blob/main/src/netedit/elements/data/GNEDataInterval.cpp
193867 views
1
/****************************************************************************/
2
// Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo
3
// Copyright (C) 2001-2026 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->getFileBucket()),
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
GNEMoveElement*
52
GNEDataInterval::getMoveElement() const {
53
return nullptr;
54
}
55
56
57
Parameterised*
58
GNEDataInterval::getParameters() {
59
return nullptr;
60
}
61
62
63
const Parameterised*
64
GNEDataInterval::getParameters() const {
65
return nullptr;
66
}
67
68
69
GUIGlObject*
70
GNEDataInterval::getGUIGlObject() {
71
return nullptr;
72
}
73
74
75
const GUIGlObject*
76
GNEDataInterval::getGUIGlObject() const {
77
return nullptr;
78
}
79
80
81
void
82
GNEDataInterval::updateGenericDataIDs() {
83
if (myNet->isUpdateDataEnabled()) {
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
100
void
101
GNEDataInterval::updateAttributeColors() {
102
if (myNet->isUpdateDataEnabled()) {
103
// first clear both container
104
myAllAttributeColors.clear();
105
mySpecificAttributeColors.clear();
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
123
const GNEDataSet::AttributeColors&
124
GNEDataInterval::getAllAttributeColors() const {
125
return myAllAttributeColors;
126
}
127
128
129
const std::map<SumoXMLTag, GNEDataSet::AttributeColors>&
130
GNEDataInterval::getSpecificAttributeColors() const {
131
return mySpecificAttributeColors;
132
}
133
134
135
void
136
GNEDataInterval::updateGeometry() {
137
// nothing to update
138
}
139
140
141
Position
142
GNEDataInterval::getPositionInView() const {
143
return Position();
144
}
145
146
147
bool
148
GNEDataInterval::checkDrawFromContour() const {
149
return false;
150
}
151
152
153
bool
154
GNEDataInterval::checkDrawToContour() const {
155
return false;
156
}
157
158
159
bool
160
GNEDataInterval::checkDrawRelatedContour() const {
161
return false;
162
}
163
164
165
bool
166
GNEDataInterval::checkDrawOverContour() const {
167
return false;
168
}
169
170
171
bool
172
GNEDataInterval::checkDrawDeleteContour() const {
173
return false;
174
}
175
176
177
bool
178
GNEDataInterval::checkDrawDeleteContourSmall() const {
179
return false;
180
}
181
182
183
bool
184
GNEDataInterval::checkDrawSelectContour() const {
185
return false;
186
}
187
188
189
bool
190
GNEDataInterval::checkDrawMoveContour() const {
191
return false;
192
}
193
194
195
FileBucket*
196
GNEDataInterval::getFileBucket() const {
197
if (isTemplate()) {
198
return nullptr;
199
} else {
200
return myDataSetParent->getFileBucket();
201
}
202
}
203
204
205
bool
206
GNEDataInterval::isDataIntervalValid() const {
207
return true;
208
}
209
210
211
std::string
212
GNEDataInterval::getDataIntervalProblem() const {
213
return "";
214
}
215
216
217
void
218
GNEDataInterval::fixDataIntervalProblem() {
219
throw InvalidArgument(getTagStr() + " cannot fix any problem");
220
}
221
222
223
GNEDataSet*
224
GNEDataInterval::getDataSetParent() const {
225
return myDataSetParent;
226
}
227
228
229
void
230
GNEDataInterval::addGenericDataChild(GNEGenericData* genericData) {
231
// check that GenericData wasn't previously inserted
232
if (!hasGenericDataChild(genericData)) {
233
myGenericDataChildren.push_back(genericData);
234
// update generic data IDs
235
updateGenericDataIDs();
236
// add id RTREE
237
myNet->addGLObjectIntoGrid(genericData);
238
// update geometry after insertion if myUpdateGeometryEnabled is enabled
239
if (myNet->isUpdateGeometryEnabled()) {
240
// update generic data RTREE
241
genericData->updateGeometry();
242
}
243
// add reference in attributeCarriers
244
myNet->getAttributeCarriers()->insertGenericData(genericData);
245
// update colors
246
genericData->getDataIntervalParent()->getDataSetParent()->updateAttributeColors();
247
} else {
248
throw ProcessError(TL("GenericData was already inserted"));
249
}
250
}
251
252
253
void
254
GNEDataInterval::removeGenericDataChild(GNEGenericData* genericData) {
255
auto it = std::find(myGenericDataChildren.begin(), myGenericDataChildren.end(), genericData);
256
// check that GenericData was previously inserted
257
if (it != myGenericDataChildren.end()) {
258
// remove generic data child
259
myGenericDataChildren.erase(it);
260
// remove it from inspected ACs and GNEElementTree
261
myDataSetParent->getNet()->getViewNet()->getInspectedElements().uninspectAC(genericData);
262
myDataSetParent->getNet()->getViewParent()->getInspectorFrame()->getHierarchicalElementTree()->removeCurrentEditedAttributeCarrier(genericData);
263
// update colors
264
genericData->getDataIntervalParent()->getDataSetParent()->updateAttributeColors();
265
// delete path element
266
myNet->getDataPathManager()->removePath(genericData);
267
// add in RTREE
268
myNet->removeGLObjectFromGrid(genericData);
269
// remove reference from attributeCarriers
270
myNet->getAttributeCarriers()->deleteGenericData(genericData);
271
} else {
272
throw ProcessError(TL("GenericData wasn't previously inserted"));
273
}
274
}
275
276
277
bool
278
GNEDataInterval::hasGenericDataChild(GNEGenericData* genericData) const {
279
return std::find(myGenericDataChildren.begin(), myGenericDataChildren.end(), genericData) != myGenericDataChildren.end();
280
}
281
282
283
const std::vector<GNEGenericData*>&
284
GNEDataInterval::getGenericDataChildren() const {
285
return myGenericDataChildren;
286
}
287
288
289
bool
290
GNEDataInterval::edgeRelSingleExists(const GNEEdge* edge) const {
291
// interate over all edgeRels and check edge parents
292
for (const auto& genericData : myGenericDataChildren) {
293
if ((genericData->getTagProperty()->getTag() == GNE_TAG_EDGEREL_SINGLE) &&
294
(genericData->getParentEdges().front() == edge)) {
295
return true;
296
}
297
}
298
return false;
299
}
300
301
302
bool
303
GNEDataInterval::edgeRelExists(const GNEEdge* fromEdge, const GNEEdge* toEdge) const {
304
// interate over all edgeRels and check edge parents
305
for (const auto& genericData : myGenericDataChildren) {
306
if ((genericData->getTagProperty()->getTag() == SUMO_TAG_EDGEREL) &&
307
(genericData->getParentEdges().front() == fromEdge) &&
308
(genericData->getParentEdges().back() == toEdge)) {
309
return true;
310
}
311
}
312
return false;
313
}
314
315
316
bool
317
GNEDataInterval::TAZRelExists(const GNEAdditional* TAZ) const {
318
// interate over all TAZRels and check TAZ parents
319
for (const auto& genericData : myGenericDataChildren) {
320
if ((genericData->getTagProperty()->getTag() == SUMO_TAG_TAZREL) &&
321
(genericData->getParentAdditionals().size() == 1) &&
322
(genericData->getParentAdditionals().front() == TAZ)) {
323
return true;
324
}
325
}
326
return false;
327
}
328
329
330
bool
331
GNEDataInterval::TAZRelExists(const GNEAdditional* fromTAZ, const GNEAdditional* toTAZ) const {
332
// interate over all TAZRels and check TAZ parents
333
for (const auto& genericData : myGenericDataChildren) {
334
if ((genericData->getTagProperty()->getTag() == SUMO_TAG_TAZREL) &&
335
(genericData->getParentAdditionals().size() == 2) &&
336
(genericData->getParentAdditionals().front() == fromTAZ) &&
337
(genericData->getParentAdditionals().back() == toTAZ)) {
338
return true;
339
}
340
}
341
return false;
342
}
343
344
345
std::string
346
GNEDataInterval::getAttribute(SumoXMLAttr key) const {
347
switch (key) {
348
case SUMO_ATTR_ID:
349
return myDataSetParent->getAttribute(SUMO_ATTR_ID);
350
case SUMO_ATTR_BEGIN:
351
return toString(myBegin);
352
case SUMO_ATTR_END:
353
return toString(myEnd);
354
default:
355
return getCommonAttribute(key);
356
}
357
}
358
359
360
double
361
GNEDataInterval::getAttributeDouble(SumoXMLAttr key) const {
362
switch (key) {
363
case SUMO_ATTR_BEGIN:
364
return myBegin;
365
case SUMO_ATTR_END:
366
return myEnd;
367
default:
368
return getCommonAttributeDouble(key);
369
}
370
}
371
372
373
Position
374
GNEDataInterval::getAttributePosition(SumoXMLAttr key) const {
375
return getCommonAttributePosition(key);
376
}
377
378
379
PositionVector
380
GNEDataInterval::getAttributePositionVector(SumoXMLAttr key) const {
381
return getCommonAttributePositionVector(key);
382
}
383
384
385
void
386
GNEDataInterval::setAttribute(SumoXMLAttr key, const std::string& value, GNEUndoList* undoList) {
387
switch (key) {
388
case SUMO_ATTR_BEGIN:
389
case SUMO_ATTR_END:
390
GNEChange_Attribute::changeAttribute(this, key, value, undoList);
391
break;
392
default:
393
setCommonAttribute(key, value, undoList);
394
break;
395
}
396
}
397
398
399
bool
400
GNEDataInterval::isValid(SumoXMLAttr key, const std::string& value) {
401
switch (key) {
402
case SUMO_ATTR_BEGIN:
403
return canParse<double>(value);
404
case SUMO_ATTR_END:
405
return canParse<double>(value);
406
default:
407
return isCommonAttributeValid(key, value);
408
}
409
}
410
411
412
bool
413
GNEDataInterval::isAttributeEnabled(SumoXMLAttr key) const {
414
switch (key) {
415
case SUMO_ATTR_ID:
416
return false;
417
default:
418
return true;
419
}
420
}
421
422
423
std::string
424
GNEDataInterval::getPopUpID() const {
425
return getTagStr();
426
}
427
428
429
std::string
430
GNEDataInterval::getHierarchyName() const {
431
return "interval: " + getAttribute(SUMO_ATTR_BEGIN) + " -> " + getAttribute(SUMO_ATTR_END);
432
}
433
434
435
void
436
GNEDataInterval::setAttribute(SumoXMLAttr key, const std::string& value) {
437
switch (key) {
438
case SUMO_ATTR_BEGIN:
439
myBegin = parse<double>(value);
440
// update Generic Data IDs
441
updateGenericDataIDs();
442
break;
443
case SUMO_ATTR_END:
444
myEnd = parse<double>(value);
445
// update Generic Data IDs
446
updateGenericDataIDs();
447
break;
448
default:
449
setCommonAttribute(key, value);
450
break;
451
}
452
// mark interval toolbar for update
453
myNet->getViewNet()->getIntervalBar().markForUpdate();
454
}
455
456
/****************************************************************************/
457
458