Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
eclipse
GitHub Repository: eclipse/sumo
Path: blob/main/src/netedit/elements/data/GNEEdgeData.cpp
193674 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 GNEEdgeData.cpp
15
/// @author Pablo Alvarez Lopez
16
/// @date Jan 2020
17
///
18
// class for edge data
19
/****************************************************************************/
20
21
#include <netedit/GNENet.h>
22
#include <netedit/GNETagProperties.h>
23
#include <netedit/GNESegment.h>
24
#include <netedit/GNEUndoList.h>
25
#include <netedit/GNEViewNet.h>
26
#include <netedit/GNEViewParent.h>
27
#include <netedit/changes/GNEChange_Attribute.h>
28
#include <netedit/frames/data/GNEEdgeDataFrame.h>
29
#include <utils/gui/div/GLHelper.h>
30
#include <utils/gui/globjects/GLIncludes.h>
31
32
#include "GNEEdgeData.h"
33
#include "GNEDataInterval.h"
34
35
// ===========================================================================
36
// member method definitions
37
// ===========================================================================
38
39
GNEEdgeData::GNEEdgeData(GNENet* net) :
40
GNEGenericData(GNE_TAG_EDGEREL_SINGLE, net) {
41
}
42
43
44
GNEEdgeData::GNEEdgeData(GNEDataInterval* dataIntervalParent, GNEEdge* edge, const Parameterised::Map& parameters) :
45
GNEGenericData(GNE_TAG_EDGEREL_SINGLE, dataIntervalParent, parameters) {
46
// set parents
47
setParent<GNEEdge*>(edge);
48
}
49
50
51
GNEEdgeData::~GNEEdgeData() {}
52
53
54
RGBColor
55
GNEEdgeData::setColor(const GUIVisualizationSettings& s) const {
56
// set default color
57
RGBColor col = RGBColor::RED;
58
if (isAttributeCarrierSelected()) {
59
col = s.colorSettings.selectedEdgeDataColor;
60
} else if (s.dataColorer.getScheme().getName() == GUIVisualizationSettings::SCHEME_NAME_DATA_ATTRIBUTE_NUMERICAL) {
61
// user defined rainbow
62
const double val = getColorValue(s, s.dataColorer.getActive());
63
col = s.dataColorer.getScheme().getColor(val);
64
} else if (myNet->getViewNet()->getEditModes().dataEditMode == DataEditMode::DATA_EDGEDATA) {
65
// get selected data interval and filtered attribute
66
const GNEDataInterval* dataInterval = myNet->getViewParent()->getEdgeDataFrame()->getIntervalSelector()->getDataInterval();
67
const std::string filteredAttribute = myNet->getViewParent()->getEdgeDataFrame()->getAttributeSelector()->getFilteredAttribute();
68
// continue if there is a selected data interval and filtered attribute
69
if (dataInterval && (filteredAttribute.size() > 0)) {
70
if (dataInterval->getSpecificAttributeColors().at(myTagProperty->getTag()).exist(filteredAttribute)) {
71
// obtain minimum and maximum value
72
const double minValue = dataInterval->getSpecificAttributeColors().at(myTagProperty->getTag()).getMinValue(filteredAttribute);
73
const double maxValue = dataInterval->getSpecificAttributeColors().at(myTagProperty->getTag()).getMaxValue(filteredAttribute);
74
// get value
75
const double value = parse<double>(getParameter(filteredAttribute, "0"));
76
// return color
77
col = GNEViewNetHelper::getRainbowScaledColor(minValue, maxValue, value);
78
}
79
}
80
}
81
return col;
82
}
83
84
85
double
86
GNEEdgeData::getColorValue(const GUIVisualizationSettings& s, int activeScheme) const {
87
switch (activeScheme) {
88
case 0:
89
return 0;
90
case 1:
91
return isAttributeCarrierSelected();
92
case 2:
93
return 0; // setfunctional color const GNEAdditional* TAZA = getParentAdditionals().front();
94
case 3:
95
return 0; // setfunctional color const GNEAdditional* TAZA = getParentAdditionals().back();
96
case 4:
97
// by numerical attribute value
98
try {
99
if (hasParameter(s.relDataAttr)) {
100
return StringUtils::toDouble(getParameter(s.relDataAttr, "-1"));
101
} else {
102
return GUIVisualizationSettings::MISSING_DATA;
103
}
104
} catch (NumberFormatException&) {
105
return GUIVisualizationSettings::MISSING_DATA;
106
}
107
default:
108
return 0;
109
}
110
}
111
112
113
bool
114
GNEEdgeData::isGenericDataVisible() const {
115
// get current data edit mode
116
DataEditMode dataMode = myNet->getViewNet()->getEditModes().dataEditMode;
117
// check if we have to filter generic data
118
if ((dataMode == DataEditMode::DATA_INSPECT) || (dataMode == DataEditMode::DATA_DELETE) || (dataMode == DataEditMode::DATA_SELECT)) {
119
return isVisibleInspectDeleteSelect();
120
} else if (myDataIntervalParent->getNet()->getViewParent()->getEdgeDataFrame()->shown()) {
121
// get selected data interval and filtered attribute
122
const GNEDataInterval* dataInterval = myNet->getViewParent()->getEdgeDataFrame()->getIntervalSelector()->getDataInterval();
123
const std::string filteredAttribute = myNet->getViewParent()->getEdgeDataFrame()->getAttributeSelector()->getFilteredAttribute();
124
// check interval
125
if ((dataInterval != nullptr) && (dataInterval != myDataIntervalParent)) {
126
return false;
127
}
128
// check attribute
129
if ((filteredAttribute.size() > 0) && (getParametersMap().count(filteredAttribute) == 0)) {
130
return false;
131
}
132
// all checks ok, then return true
133
return true;
134
} else {
135
// GNEEdgeDataFrame hidden, then return false
136
return false;
137
}
138
}
139
140
141
void
142
GNEEdgeData::updateGeometry() {
143
// calculate path
144
myNet->getDataPathManager()->calculateConsecutivePathEdges(this, SVC_IGNORING, getParentEdges());
145
}
146
147
148
Position
149
GNEEdgeData::getPositionInView() const {
150
return getParentEdges().front()->getPositionInView();
151
}
152
153
154
void
155
GNEEdgeData::writeGenericData(OutputDevice& device) const {
156
// open device (don't use SUMO_TAG_MEANDATA_EDGE)
157
device.openTag(SUMO_TAG_EDGE);
158
// write edge ID
159
device.writeAttr(SUMO_ATTR_ID, getParentEdges().front()->getID());
160
// iterate over attributes
161
for (const auto& attribute : getParametersMap()) {
162
// write attribute (don't use writeParams)
163
device.writeAttr(attribute.first, attribute.second);
164
}
165
// close device
166
device.closeTag();
167
}
168
169
170
bool
171
GNEEdgeData::isGenericDataValid() const {
172
return true;
173
}
174
175
176
std::string
177
GNEEdgeData::getGenericDataProblem() const {
178
return "";
179
}
180
181
182
void
183
GNEEdgeData::fixGenericDataProblem() {
184
throw InvalidArgument(getTagStr() + " cannot fix any problem");
185
}
186
187
188
void
189
GNEEdgeData::drawGL(const GUIVisualizationSettings& /*s*/) const {
190
// Nothing to draw
191
}
192
193
194
void
195
GNEEdgeData::computePathElement() {
196
// nothing to compute
197
}
198
199
200
void
201
GNEEdgeData::drawLanePartialGL(const GUIVisualizationSettings& s, const GNESegment* segment, const double offsetFront) const {
202
// get color
203
const auto color = setColor(s);
204
if (segment->getLane() && (color.alpha() != 0) && myNet->getViewNet()->getEditModes().isCurrentSupermodeData()) {
205
// get detail level
206
const auto d = s.getDetailLevel(1);
207
// draw geometry only if we'rent in drawForObjectUnderCursor mode
208
if (!s.drawForViewObjectsHandler) {
209
// draw over all edge's lanes
210
for (const auto& laneEdge : segment->getLane()->getParentEdge()->getChildLanes()) {
211
// Add a draw matrix
212
GLHelper::pushMatrix();
213
// Start with the drawing of the area translating matrix to origin
214
drawInLayer(GLO_EDGEDATA, offsetFront);
215
GLHelper::setColor(RGBColor::BLACK);
216
// draw geometry
217
GUIGeometry::drawGeometry(laneEdge->getDrawingConstants()->getDetail(), laneEdge->getLaneGeometry(), laneEdge->getDrawingConstants()->getDrawingWidth());
218
// translate to top
219
glTranslated(0, 0, 0.01);
220
GLHelper::setColor(color);
221
// draw internal box lines
222
GUIGeometry::drawGeometry(laneEdge->getDrawingConstants()->getDetail(), laneEdge->getLaneGeometry(), (laneEdge->getDrawingConstants()->getDrawingWidth() - 0.1));
223
// Pop last matrix
224
GLHelper::popMatrix();
225
// draw lock icon
226
GNEViewNetHelper::LockIcon::drawLockIcon(d, this, getType(), getPositionInView(), 1);
227
// draw filtered attribute
228
if (getParentEdges().front()->getChildLanes().front() == laneEdge) {
229
drawFilteredAttribute(s, laneEdge->getLaneShape(),
230
myNet->getViewParent()->getEdgeDataFrame()->getAttributeSelector()->getFilteredAttribute(),
231
myNet->getViewParent()->getEdgeDataFrame()->getIntervalSelector()->getDataInterval());
232
}
233
}
234
// draw dotted contour
235
segment->getContour()->drawDottedContours(s, d, this, s.dottedContourSettings.segmentWidth, true);
236
}
237
// calculate contour and draw dotted geometry
238
segment->getContour()->calculateContourEdge(s, d, segment->getLane()->getParentEdge(), this, getType(), true, true);
239
}
240
}
241
242
243
void
244
GNEEdgeData::drawJunctionPartialGL(const GUIVisualizationSettings& /*s*/, const GNESegment* /*segment*/, const double /*offsetFront*/) const {
245
// EdgeDatas don't use drawJunctionPartialGL over junction
246
}
247
248
249
GNELane*
250
GNEEdgeData::getFirstPathLane() const {
251
/* temporal */
252
return nullptr;
253
}
254
255
256
GNELane*
257
GNEEdgeData::getLastPathLane() const {
258
/* temporal */
259
return nullptr;
260
}
261
262
263
Boundary
264
GNEEdgeData::getCenteringBoundary() const {
265
return getParentEdges().front()->getCenteringBoundary();
266
}
267
268
269
std::string
270
GNEEdgeData::getAttribute(SumoXMLAttr key) const {
271
switch (key) {
272
case SUMO_ATTR_ID:
273
return getPartialID() + getParentEdges().front()->getID();
274
case GNE_ATTR_DATASET:
275
return myDataIntervalParent->getDataSetParent()->getID();
276
case SUMO_ATTR_BEGIN:
277
return myDataIntervalParent->getAttribute(SUMO_ATTR_BEGIN);
278
case SUMO_ATTR_END:
279
return myDataIntervalParent->getAttribute(SUMO_ATTR_END);
280
default:
281
return getCommonAttribute(key);
282
}
283
}
284
285
286
double
287
GNEEdgeData::getAttributeDouble(SumoXMLAttr key) const {
288
return getCommonAttributeDouble(key);
289
}
290
291
292
void
293
GNEEdgeData::setAttribute(SumoXMLAttr key, const std::string& value, GNEUndoList* undoList) {
294
if (value == getAttribute(key)) {
295
return; //avoid needless changes, later logic relies on the fact that attributes have changed
296
}
297
setCommonAttribute(key, value, undoList);
298
}
299
300
301
bool
302
GNEEdgeData::isValid(SumoXMLAttr key, const std::string& value) {
303
return isCommonAttributeValid(key, value);
304
}
305
306
307
bool GNEEdgeData::isAttributeEnabled(SumoXMLAttr key) const {
308
switch (key) {
309
case SUMO_ATTR_ID:
310
return false;
311
default:
312
return true;
313
}
314
}
315
316
317
std::string
318
GNEEdgeData::getPopUpID() const {
319
return getTagStr();
320
}
321
322
323
std::string
324
GNEEdgeData::getHierarchyName() const {
325
return getTagStr() + ": " + getParentEdges().front()->getID();
326
}
327
328
329
void
330
GNEEdgeData::setAttribute(SumoXMLAttr key, const std::string& value) {
331
setCommonAttribute(key, value);
332
if (!isTemplate()) {
333
myDataIntervalParent->getDataSetParent()->updateAttributeColors();
334
}
335
// mark interval toolbar for update
336
if (!isTemplate()) {
337
myNet->getViewNet()->getIntervalBar().markForUpdate();
338
}
339
}
340
341
/****************************************************************************/
342
343