Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
eclipse
GitHub Repository: eclipse/sumo
Path: blob/main/src/netedit/elements/data/GNEDataSet.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 GNEDataSet.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/GNEViewParent.h>
23
#include <netedit/changes/GNEChange_Attribute.h>
24
#include <netedit/frames/common/GNEInspectorFrame.h>
25
#include <netedit/frames/GNEElementTree.h>
26
27
#include "GNEDataSet.h"
28
#include "GNEDataInterval.h"
29
30
// ===========================================================================
31
// member method definitions
32
// ===========================================================================
33
34
// ---------------------------------------------------------------------------
35
// GNEDataSet::AttributeColors - methods
36
// ---------------------------------------------------------------------------
37
38
GNEDataSet::AttributeColors::AttributeColors() {
39
}
40
41
42
void
43
GNEDataSet::AttributeColors::updateValues(const std::string& attribute, const double value) {
44
// check if exist
45
if (myMinMaxValue.count(attribute) == 0) {
46
myMinMaxValue[attribute] = std::make_pair(value, value);
47
} else {
48
// update min value
49
if (value < myMinMaxValue.at(attribute).first) {
50
myMinMaxValue.at(attribute).first = value;
51
}
52
// update max value
53
if (value > myMinMaxValue.at(attribute).second) {
54
myMinMaxValue.at(attribute).second = value;
55
}
56
}
57
}
58
59
60
void
61
GNEDataSet::AttributeColors::updateAllValues(const AttributeColors& attributeColors) {
62
// iterate over map
63
for (const auto& attributeColor : attributeColors.myMinMaxValue) {
64
if (myMinMaxValue.count(attributeColor.first) == 0) {
65
myMinMaxValue[attributeColor.first] = attributeColor.second;
66
} else {
67
// update min value
68
if (attributeColor.second.first < myMinMaxValue.at(attributeColor.first).first) {
69
myMinMaxValue.at(attributeColor.first).first = attributeColor.second.first;
70
}
71
// update max value
72
if (attributeColor.second.second > myMinMaxValue.at(attributeColor.first).second) {
73
myMinMaxValue.at(attributeColor.first).second = attributeColor.second.second;
74
}
75
}
76
}
77
}
78
79
80
bool
81
GNEDataSet::AttributeColors::exist(const std::string& attribute) const {
82
return (myMinMaxValue.count(attribute) > 0);
83
}
84
85
86
double
87
GNEDataSet::AttributeColors::getMinValue(const std::string& attribute) const {
88
return myMinMaxValue.at(attribute).first;
89
}
90
91
92
double
93
GNEDataSet::AttributeColors::getMaxValue(const std::string& attribute) const {
94
return myMinMaxValue.at(attribute).second;
95
}
96
97
98
void
99
GNEDataSet::AttributeColors::clear() {
100
myMinMaxValue.clear();
101
}
102
103
// ---------------------------------------------------------------------------
104
// GNEDataSet - methods
105
// ---------------------------------------------------------------------------
106
107
GNEDataSet::GNEDataSet(const std::string& dataSetID, GNENet* net, const std::string& filename) :
108
GNEAttributeCarrier(SUMO_TAG_DATASET, net, filename, false),
109
myDataSetID(dataSetID) {
110
}
111
112
113
GNEDataSet::~GNEDataSet() {}
114
115
116
GNEHierarchicalElement*
117
GNEDataSet::getHierarchicalElement() {
118
return this;
119
}
120
121
122
GUIGlObject*
123
GNEDataSet::getGUIGlObject() {
124
return nullptr;
125
}
126
127
128
const GUIGlObject*
129
GNEDataSet::getGUIGlObject() const {
130
return nullptr;
131
}
132
133
134
void
135
GNEDataSet::updateAttributeColors() {
136
// first update attribute colors in data interval childrens
137
for (const auto& interval : myDataIntervalChildren) {
138
interval.second->updateAttributeColors();
139
}
140
// continue with data sets containers
141
myAllAttributeColors.clear();
142
mySpecificAttributeColors.clear();
143
// iterate over all data interval children
144
for (const auto& interval : myDataIntervalChildren) {
145
myAllAttributeColors.updateAllValues(interval.second->getAllAttributeColors());
146
}
147
// iterate over specificdata interval children
148
for (const auto& interval : myDataIntervalChildren) {
149
for (const auto& specificAttributeColor : interval.second->getSpecificAttributeColors()) {
150
mySpecificAttributeColors[specificAttributeColor.first].updateAllValues(specificAttributeColor.second);
151
}
152
}
153
}
154
155
156
const GNEDataSet::AttributeColors&
157
GNEDataSet::getAllAttributeColors() const {
158
return myAllAttributeColors;
159
}
160
161
162
const std::map<SumoXMLTag, GNEDataSet::AttributeColors>&
163
GNEDataSet::getSpecificAttributeColors() const {
164
return mySpecificAttributeColors;
165
}
166
167
168
void
169
GNEDataSet::updateGeometry() {
170
// nothing to update
171
}
172
173
174
Position
175
GNEDataSet::getPositionInView() const {
176
return Position(0, 0);
177
}
178
179
180
void
181
GNEDataSet::writeDataSet(OutputDevice& device) const {
182
// iterate over intervals
183
for (const auto& interval : myDataIntervalChildren) {
184
// open device
185
device.openTag(SUMO_TAG_INTERVAL);
186
// write ID
187
device.writeAttr(SUMO_ATTR_ID, getID());
188
// write begin
189
device.writeAttr(SUMO_ATTR_BEGIN, interval.second->getAttribute(SUMO_ATTR_BEGIN));
190
// write end
191
device.writeAttr(SUMO_ATTR_END, interval.second->getAttribute(SUMO_ATTR_END));
192
// iterate over interval generic datas
193
for (const auto& genericData : interval.second->getGenericDataChildren()) {
194
// write generic data
195
genericData->writeGenericData(device);
196
}
197
// close device
198
device.closeTag();
199
}
200
}
201
202
203
bool
204
GNEDataSet::checkDrawFromContour() const {
205
return false;
206
}
207
208
209
bool
210
GNEDataSet::checkDrawToContour() const {
211
return false;
212
}
213
214
215
bool
216
GNEDataSet::checkDrawRelatedContour() const {
217
return false;
218
}
219
220
221
bool
222
GNEDataSet::checkDrawOverContour() const {
223
return false;
224
}
225
226
227
bool
228
GNEDataSet::checkDrawDeleteContour() const {
229
return false;
230
}
231
232
233
bool
234
GNEDataSet::checkDrawDeleteContourSmall() const {
235
return false;
236
}
237
238
239
bool
240
GNEDataSet::checkDrawSelectContour() const {
241
return false;
242
}
243
244
245
bool
246
GNEDataSet::checkDrawMoveContour() const {
247
return false;
248
}
249
250
251
void
252
GNEDataSet::addDataIntervalChild(GNEDataInterval* dataInterval) {
253
// check that dataInterval wasn't previously inserted
254
if (myDataIntervalChildren.count(dataInterval->getAttributeDouble(SUMO_ATTR_BEGIN)) == 0) {
255
// add data interval child
256
myDataIntervalChildren[dataInterval->getAttributeDouble(SUMO_ATTR_BEGIN)] = dataInterval;
257
// add reference in attributeCarriers
258
myNet->getAttributeCarriers()->insertDataInterval(dataInterval, dataInterval);
259
} else {
260
throw ProcessError(TL("DataInterval was already inserted"));
261
}
262
}
263
264
265
void
266
GNEDataSet::removeDataIntervalChild(GNEDataInterval* dataInterval) {
267
// check that dataInterval was previously inserted
268
if (myDataIntervalChildren.count(dataInterval->getAttributeDouble(SUMO_ATTR_BEGIN)) == 1) {
269
// remove data interval child
270
myDataIntervalChildren.erase(dataInterval->getAttributeDouble(SUMO_ATTR_BEGIN));
271
// remove it from inspected elements and GNEElementTree
272
myNet->getViewNet()->getInspectedElements().uninspectAC(dataInterval);
273
myNet->getViewNet()->getViewParent()->getInspectorFrame()->getHierarchicalElementTree()->removeCurrentEditedAttributeCarrier(dataInterval);
274
// remove reference from attributeCarriers
275
myNet->getAttributeCarriers()->deleteDataInterval(dataInterval);
276
} else {
277
throw ProcessError(TL("DataInterval wasn't previously inserted"));
278
}
279
}
280
281
282
bool
283
GNEDataSet::dataIntervalChildrenExist(GNEDataInterval* dataInterval) const {
284
for (const auto& interval : myDataIntervalChildren) {
285
if (interval.second == dataInterval) {
286
return true;
287
}
288
}
289
return false;
290
}
291
292
void
293
GNEDataSet::updateDataIntervalBegin(const double oldBegin) {
294
// check that dataInterval was previously inserted
295
if (myDataIntervalChildren.count(oldBegin) == 1) {
296
// get data interval
297
GNEDataInterval* dataInterval = myDataIntervalChildren.at(oldBegin);
298
// insert again using new begin
299
myDataIntervalChildren[dataInterval->getAttributeDouble(SUMO_ATTR_BEGIN)] = dataInterval;
300
} else {
301
throw ProcessError(TL("DataInterval wasn't previously inserted"));
302
}
303
}
304
305
306
bool
307
GNEDataSet::checkNewInterval(const double newBegin, const double newEnd) {
308
return checkNewInterval(myDataIntervalChildren, newBegin, newEnd);
309
}
310
311
312
bool
313
GNEDataSet::checkNewBeginEnd(const GNEDataInterval* dataInterval, const double newBegin, const double newEnd) {
314
// make a copy of myDataIntervalChildren without dataInterval, and check checkNewInterval
315
std::map<const double, GNEDataInterval*> copyOfDataIntervalMap;
316
for (const auto& element : myDataIntervalChildren) {
317
if (element.second != dataInterval) {
318
copyOfDataIntervalMap.insert(element);
319
}
320
}
321
return checkNewInterval(copyOfDataIntervalMap, newBegin, newEnd);
322
}
323
324
325
GNEDataInterval*
326
GNEDataSet::retrieveInterval(const double begin, const double end) const {
327
if (myDataIntervalChildren.count(begin) == 0) {
328
return nullptr;
329
} else if (myDataIntervalChildren.at(begin)->getAttributeDouble(SUMO_ATTR_END) != end) {
330
return nullptr;
331
} else {
332
return myDataIntervalChildren.at(begin);
333
}
334
}
335
336
337
const std::map<const double, GNEDataInterval*>&
338
GNEDataSet::getDataIntervalChildren() const {
339
return myDataIntervalChildren;
340
}
341
342
343
std::string
344
GNEDataSet::getAttribute(SumoXMLAttr key) const {
345
switch (key) {
346
case SUMO_ATTR_ID:
347
return myDataSetID;
348
default:
349
return getCommonAttribute(this, key);
350
}
351
}
352
353
354
double
355
GNEDataSet::getAttributeDouble(SumoXMLAttr key) const {
356
throw InvalidArgument(getTagStr() + " doesn't have a double attribute of type '" + toString(key) + "'");
357
}
358
359
360
void
361
GNEDataSet::setAttribute(SumoXMLAttr key, const std::string& value, GNEUndoList* undoList) {
362
switch (key) {
363
case SUMO_ATTR_ID:
364
GNEChange_Attribute::changeAttribute(this, key, value, undoList);
365
break;
366
default:
367
setCommonAttribute(key, value, undoList);
368
break;
369
}
370
}
371
372
373
bool
374
GNEDataSet::isValid(SumoXMLAttr key, const std::string& value) {
375
switch (key) {
376
case SUMO_ATTR_ID:
377
if (SUMOXMLDefinitions::isValidNetID(value) && (myNet->getAttributeCarriers()->retrieveDataSet(value, false) == nullptr)) {
378
return true;
379
} else {
380
return false;
381
}
382
default:
383
return isCommonValid(key, value);
384
}
385
}
386
387
388
std::string
389
GNEDataSet::getPopUpID() const {
390
return getTagStr();
391
}
392
393
394
std::string
395
GNEDataSet::getHierarchyName() const {
396
return getTagStr() + ": " + myDataSetID;
397
}
398
399
400
const Parameterised::Map&
401
GNEDataSet::getACParametersMap() const {
402
return getParametersMap();
403
}
404
405
406
void
407
GNEDataSet::setAttribute(SumoXMLAttr key, const std::string& value) {
408
switch (key) {
409
case SUMO_ATTR_ID:
410
myDataSetID = value;
411
// update all intervals
412
for (const auto& interval : myDataIntervalChildren) {
413
interval.second->updateGenericDataIDs();
414
}
415
break;
416
default:
417
setCommonAttribute(this, key, value);
418
break;
419
}
420
// mark interval toolbar for update
421
myNet->getViewNet()->getIntervalBar().markForUpdate();
422
}
423
424
425
bool
426
GNEDataSet::checkNewInterval(const std::map<const double, GNEDataInterval*>& dataIntervalMap, const double newBegin, const double newEnd) {
427
if (dataIntervalMap.empty()) {
428
return true;
429
} else {
430
// declare first and last element
431
const auto itFirstElement = dataIntervalMap.begin();
432
const auto itLastElement = dataIntervalMap.rbegin();
433
if (newBegin > newEnd) {
434
return false;
435
} else if (dataIntervalMap.count(newBegin) == 1) {
436
return false;
437
} else if (newBegin < itFirstElement->first) {
438
return (newEnd <= itFirstElement->first);
439
} else if (newBegin > itLastElement->first) {
440
return (newBegin >= itLastElement->second->getAttributeDouble(SUMO_ATTR_END));
441
} else {
442
// iterate over myDataIntervalChildren
443
for (auto it = itFirstElement; it != dataIntervalMap.end(); it++) {
444
if (newBegin < it->first) {
445
// obtain previous edge
446
auto itPrevious = it;
447
itPrevious--;
448
// check overlapping with end
449
if (itPrevious->second->getAttributeDouble(SUMO_ATTR_END) < newBegin) {
450
return true;
451
}
452
}
453
}
454
}
455
return false;
456
}
457
}
458
459
/****************************************************************************/
460
461