Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
eclipse
GitHub Repository: eclipse/sumo
Path: blob/main/src/netedit/elements/data/GNEEdgeData.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 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->getViewNet()->getViewParent()->getEdgeDataFrame()->getIntervalSelector()->getDataInterval();
67
const std::string filteredAttribute = myNet->getViewNet()->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
}
108
return 0;
109
}
110
111
112
bool
113
GNEEdgeData::isGenericDataVisible() const {
114
// get current data edit mode
115
DataEditMode dataMode = myNet->getViewNet()->getEditModes().dataEditMode;
116
// check if we have to filter generic data
117
if ((dataMode == DataEditMode::DATA_INSPECT) || (dataMode == DataEditMode::DATA_DELETE) || (dataMode == DataEditMode::DATA_SELECT)) {
118
return isVisibleInspectDeleteSelect();
119
} else if (myDataIntervalParent->getNet()->getViewNet()->getViewParent()->getEdgeDataFrame()->shown()) {
120
// get selected data interval and filtered attribute
121
const GNEDataInterval* dataInterval = myNet->getViewNet()->getViewParent()->getEdgeDataFrame()->getIntervalSelector()->getDataInterval();
122
const std::string filteredAttribute = myNet->getViewNet()->getViewParent()->getEdgeDataFrame()->getAttributeSelector()->getFilteredAttribute();
123
// check interval
124
if ((dataInterval != nullptr) && (dataInterval != myDataIntervalParent)) {
125
return false;
126
}
127
// check attribute
128
if ((filteredAttribute.size() > 0) && (getParametersMap().count(filteredAttribute) == 0)) {
129
return false;
130
}
131
// all checks ok, then return true
132
return true;
133
} else {
134
// GNEEdgeDataFrame hidden, then return false
135
return false;
136
}
137
}
138
139
140
void
141
GNEEdgeData::updateGeometry() {
142
// calculate path
143
myNet->getDataPathManager()->calculateConsecutivePathEdges(this, SVC_IGNORING, getParentEdges());
144
}
145
146
147
Position
148
GNEEdgeData::getPositionInView() const {
149
return getParentEdges().front()->getPositionInView();
150
}
151
152
153
void
154
GNEEdgeData::writeGenericData(OutputDevice& device) const {
155
// open device (don't use SUMO_TAG_MEANDATA_EDGE)
156
device.openTag(SUMO_TAG_EDGE);
157
// write edge ID
158
device.writeAttr(SUMO_ATTR_ID, getParentEdges().front()->getID());
159
// iterate over attributes
160
for (const auto& attribute : getParametersMap()) {
161
// write attribute (don't use writeParams)
162
device.writeAttr(attribute.first, attribute.second);
163
}
164
// close device
165
device.closeTag();
166
}
167
168
169
bool
170
GNEEdgeData::isGenericDataValid() const {
171
return true;
172
}
173
174
175
std::string
176
GNEEdgeData::getGenericDataProblem() const {
177
return "";
178
}
179
180
181
void
182
GNEEdgeData::fixGenericDataProblem() {
183
throw InvalidArgument(getTagStr() + " cannot fix any problem");
184
}
185
186
187
void
188
GNEEdgeData::drawGL(const GUIVisualizationSettings& /*s*/) const {
189
// Nothing to draw
190
}
191
192
193
void
194
GNEEdgeData::computePathElement() {
195
// nothing to compute
196
}
197
198
199
void
200
GNEEdgeData::drawLanePartialGL(const GUIVisualizationSettings& s, const GNESegment* segment, const double offsetFront) const {
201
// get color
202
const auto color = setColor(s);
203
if (segment->getLane() && (color.alpha() != 0) && myNet->getViewNet()->getEditModes().isCurrentSupermodeData()) {
204
// get detail level
205
const auto d = s.getDetailLevel(1);
206
// draw geometry only if we'rent in drawForObjectUnderCursor mode
207
if (!s.drawForViewObjectsHandler) {
208
// draw over all edge's lanes
209
for (const auto& laneEdge : segment->getLane()->getParentEdge()->getChildLanes()) {
210
// Add a draw matrix
211
GLHelper::pushMatrix();
212
// Start with the drawing of the area translating matrix to origin
213
drawInLayer(GLO_EDGEDATA, offsetFront);
214
GLHelper::setColor(RGBColor::BLACK);
215
// draw geometry
216
GUIGeometry::drawGeometry(laneEdge->getDrawingConstants()->getDetail(), laneEdge->getLaneGeometry(), laneEdge->getDrawingConstants()->getDrawingWidth());
217
// translate to top
218
glTranslated(0, 0, 0.01);
219
GLHelper::setColor(color);
220
// draw internal box lines
221
GUIGeometry::drawGeometry(laneEdge->getDrawingConstants()->getDetail(), laneEdge->getLaneGeometry(), (laneEdge->getDrawingConstants()->getDrawingWidth() - 0.1));
222
// Pop last matrix
223
GLHelper::popMatrix();
224
// draw lock icon
225
GNEViewNetHelper::LockIcon::drawLockIcon(d, this, getType(), getPositionInView(), 1);
226
// draw filtered attribute
227
if (getParentEdges().front()->getChildLanes().front() == laneEdge) {
228
drawFilteredAttribute(s, laneEdge->getLaneShape(),
229
myNet->getViewNet()->getViewParent()->getEdgeDataFrame()->getAttributeSelector()->getFilteredAttribute(),
230
myNet->getViewNet()->getViewParent()->getEdgeDataFrame()->getIntervalSelector()->getDataInterval());
231
}
232
}
233
// draw dotted contour
234
segment->getContour()->drawDottedContours(s, d, this, s.dottedContourSettings.segmentWidth, true);
235
}
236
// calculate contour and draw dotted geometry
237
segment->getContour()->calculateContourEdge(s, d, segment->getLane()->getParentEdge(), this, getType(), true, true);
238
}
239
}
240
241
242
void
243
GNEEdgeData::drawJunctionPartialGL(const GUIVisualizationSettings& /*s*/, const GNESegment* /*segment*/, const double /*offsetFront*/) const {
244
// EdgeDatas don't use drawJunctionPartialGL over junction
245
}
246
247
248
GNELane*
249
GNEEdgeData::getFirstPathLane() const {
250
/* temporal */
251
return nullptr;
252
}
253
254
255
GNELane*
256
GNEEdgeData::getLastPathLane() const {
257
/* temporal */
258
return nullptr;
259
}
260
261
262
Boundary
263
GNEEdgeData::getCenteringBoundary() const {
264
return getParentEdges().front()->getCenteringBoundary();
265
}
266
267
268
std::string
269
GNEEdgeData::getAttribute(SumoXMLAttr key) const {
270
switch (key) {
271
case SUMO_ATTR_ID:
272
return getPartialID() + getParentEdges().front()->getID();
273
case GNE_ATTR_DATASET:
274
return myDataIntervalParent->getDataSetParent()->getID();
275
case SUMO_ATTR_BEGIN:
276
return myDataIntervalParent->getAttribute(SUMO_ATTR_BEGIN);
277
case SUMO_ATTR_END:
278
return myDataIntervalParent->getAttribute(SUMO_ATTR_END);
279
default:
280
return getCommonAttribute(this, key);
281
}
282
}
283
284
285
double
286
GNEEdgeData::getAttributeDouble(SumoXMLAttr key) const {
287
throw InvalidArgument(getTagStr() + " doesn't have a double attribute of type '" + toString(key) + "'");
288
}
289
290
291
void
292
GNEEdgeData::setAttribute(SumoXMLAttr key, const std::string& value, GNEUndoList* undoList) {
293
if (value == getAttribute(key)) {
294
return; //avoid needless changes, later logic relies on the fact that attributes have changed
295
}
296
setCommonAttribute(key, value, undoList);
297
}
298
299
300
bool
301
GNEEdgeData::isValid(SumoXMLAttr key, const std::string& value) {
302
return isCommonValid(key, value);
303
}
304
305
306
bool GNEEdgeData::isAttributeEnabled(SumoXMLAttr key) const {
307
switch (key) {
308
case SUMO_ATTR_ID:
309
return false;
310
default:
311
return true;
312
}
313
}
314
315
316
std::string
317
GNEEdgeData::getPopUpID() const {
318
return getTagStr();
319
}
320
321
322
std::string
323
GNEEdgeData::getHierarchyName() const {
324
return getTagStr() + ": " + getParentEdges().front()->getID();
325
}
326
327
328
void
329
GNEEdgeData::setAttribute(SumoXMLAttr key, const std::string& value) {
330
setCommonAttribute(this, key, value);
331
if (!isTemplate()) {
332
myDataIntervalParent->getDataSetParent()->updateAttributeColors();
333
}
334
// mark interval toolbar for update
335
myNet->getViewNet()->getIntervalBar().markForUpdate();
336
}
337
338
/****************************************************************************/
339
340