Eclipse SUMO - Simulation of Urban MObility
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
GNEEdgeData.cpp
Go to the documentation of this file.
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/****************************************************************************/
18// class for edge data
19/****************************************************************************/
20
21#include <netedit/GNENet.h>
23#include <netedit/GNESegment.h>
24#include <netedit/GNEUndoList.h>
25#include <netedit/GNEViewNet.h>
31
32#include "GNEEdgeData.h"
33#include "GNEDataInterval.h"
34
35// ===========================================================================
36// member method definitions
37// ===========================================================================
38
42
43
44GNEEdgeData::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
52
53
56 // set default color
61 // user defined rainbow
62 const double val = getColorValue(s, s.dataColorer.getActive());
63 col = s.dataColorer.getScheme().getColor(val);
65 // get selected data interval and filtered attribute
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
85double
86GNEEdgeData::getColorValue(const GUIVisualizationSettings& s, int activeScheme) const {
87 switch (activeScheme) {
88 case 0:
89 return 0;
90 case 1:
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 {
101 } else {
103 }
104 } catch (NumberFormatException&) {
106 }
107 }
108 return 0;
109}
110
111
112bool
114 // get current data edit mode
116 // check if we have to filter generic data
117 if ((dataMode == DataEditMode::DATA_INSPECT) || (dataMode == DataEditMode::DATA_DELETE) || (dataMode == DataEditMode::DATA_SELECT)) {
119 } else if (myDataIntervalParent->getNet()->getViewNet()->getViewParent()->getEdgeDataFrame()->shown()) {
120 // get selected data interval and filtered attribute
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
140void
145
146
149 return getParentEdges().front()->getPositionInView();
150}
151
152
153void
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
169bool
171 return true;
172}
173
174
175std::string
177 return "";
178}
179
180
181void
183 throw InvalidArgument(getTagStr() + " cannot fix any problem");
184}
185
186
187void
189 // Nothing to draw
190}
191
192
193void
195 // nothing to compute
196}
197
198
199void
200GNEEdgeData::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
208 // draw over all edge's lanes
209 for (const auto& laneEdge : segment->getLane()->getParentEdge()->getChildLanes()) {
210 // Add a draw matrix
212 // Start with the drawing of the area translating matrix to origin
213 drawInLayer(GLO_EDGEDATA, offsetFront);
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
224 // draw lock icon
226 // draw filtered attribute
227 if (getParentEdges().front()->getChildLanes().front() == laneEdge) {
228 drawFilteredAttribute(s, laneEdge->getLaneShape(),
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
242void
243GNEEdgeData::drawJunctionPartialGL(const GUIVisualizationSettings& /*s*/, const GNESegment* /*segment*/, const double /*offsetFront*/) const {
244 // EdgeDatas don't use drawJunctionPartialGL over junction
245}
246
247
248GNELane*
250 /* temporal */
251 return nullptr;
252}
253
254
255GNELane*
257 /* temporal */
258 return nullptr;
259}
260
261
264 return getParentEdges().front()->getCenteringBoundary();
265}
266
267
268std::string
270 switch (key) {
271 case SUMO_ATTR_ID:
272 return getPartialID() + getParentEdges().front()->getID();
273 case GNE_ATTR_DATASET:
275 case SUMO_ATTR_BEGIN:
277 case SUMO_ATTR_END:
279 default:
280 return getCommonAttribute(this, key);
281 }
282}
283
284
285double
287 throw InvalidArgument(getTagStr() + " doesn't have a double attribute of type '" + toString(key) + "'");
288}
289
290
291void
292GNEEdgeData::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
300bool
301GNEEdgeData::isValid(SumoXMLAttr key, const std::string& value) {
302 return isCommonValid(key, value);
303}
304
305
307 switch (key) {
308 case SUMO_ATTR_ID:
309 return false;
310 default:
311 return true;
312 }
313}
314
315
316std::string
318 return getTagStr();
319}
320
321
322std::string
324 return getTagStr() + ": " + getParentEdges().front()->getID();
325}
326
327
328void
329GNEEdgeData::setAttribute(SumoXMLAttr key, const std::string& value) {
330 setCommonAttribute(this, key, value);
331 if (!isTemplate()) {
333 }
334 // mark interval toolbar for update
336}
337
338/****************************************************************************/
DataEditMode
enum for data edit modes
@ DATA_SELECT
mode for selecting data elements
@ DATA_INSPECT
mode for inspecting data elements
@ DATA_EDGEDATA
mode for create edgeData elements
@ DATA_DELETE
mode for deleting data elements
@ GLO_EDGEDATA
edge data
@ SVC_IGNORING
vehicles ignoring classes
@ GNE_TAG_EDGEREL_SINGLE
@ SUMO_TAG_EDGE
begin/end of the description of an edge
SumoXMLAttr
Numbers representing SUMO-XML - attributes.
@ SUMO_ATTR_BEGIN
weights: time range begin
@ SUMO_ATTR_END
weights: time range end
@ GNE_ATTR_DATASET
data set of a generic data
@ SUMO_ATTR_ID
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
Definition ToString.h:46
A class that stores a 2D geometrical boundary.
Definition Boundary.h:39
static void setColor(const RGBColor &c)
Sets the gl-color to this value.
Definition GLHelper.cpp:649
static void popMatrix()
pop matrix
Definition GLHelper.cpp:131
static void pushMatrix()
push matrix
Definition GLHelper.cpp:118
const std::string getID() const
get ID (all Attribute Carriers have one)
bool isAttributeCarrierSelected() const
check if attribute carrier is selected
std::string getCommonAttribute(const Parameterised *parameterised, SumoXMLAttr key) const
void setCommonAttribute(SumoXMLAttr key, const std::string &value, GNEUndoList *undoList)
const std::string & getTagStr() const
get tag assigned to this object in string format
bool isTemplate() const
check if this AC is template
void drawInLayer(const double typeOrLayer, const double extraOffset=0) const
draw element in the given layer, or in front if corresponding flag is enabled
GNENet * myNet
pointer to net
bool isCommonValid(SumoXMLAttr key, const std::string &value) const
GNENet * getNet() const
get pointer to net
const GNETagProperties * myTagProperty
reference to tagProperty associated with this attribute carrier
void calculateContourEdge(const GUIVisualizationSettings &s, const GUIVisualizationSettings::Detail d, const GNEEdge *edge, const GUIGlObject *elementToRegister, const double layer, const bool closeFirstExtrem, const bool closeLastExtrem) const
calculate contour edge
bool drawDottedContours(const GUIVisualizationSettings &s, const GUIVisualizationSettings::Detail d, const GNEAttributeCarrier *AC, const double lineWidth, const bool addOffset) const
draw dotted contours (basics, select, delete, inspect...)
std::string getAttribute(SumoXMLAttr key) const
GNEDataSet * getDataSetParent() const
Returns a pointer to GNEDataSet parent.
const std::map< SumoXMLTag, GNEDataSet::AttributeColors > & getSpecificAttributeColors() const
specific attribute colors
void updateAttributeColors()
update attribute colors deprecated
bool isGenericDataVisible() const
check if current edge data is visible
std::string getAttribute(SumoXMLAttr key) const
void writeGenericData(OutputDevice &device) const
write data set element into a xml file
bool isValid(SumoXMLAttr key, const std::string &value)
method for checking if the key and their conrrespond attribute are valids
void setAttribute(SumoXMLAttr key, const std::string &value, GNEUndoList *undoList)
method for setting the attribute and letting the object perform data set changes
GNELane * getFirstPathLane() const
get first path lane
GNELane * getLastPathLane() const
get last path lane
bool isAttributeEnabled(SumoXMLAttr key) const
std::string getHierarchyName() const
get Hierarchy Name (Used in AC Hierarchy)
double getAttributeDouble(SumoXMLAttr key) const
std::string getPopUpID() const
get PopPup ID (Used in AC Hierarchy)
double getColorValue(const GUIVisualizationSettings &s, int activeScheme) const
void drawLanePartialGL(const GUIVisualizationSettings &s, const GNESegment *segment, const double offsetFront) const
Draws partial object over lane.
void drawJunctionPartialGL(const GUIVisualizationSettings &s, const GNESegment *segment, const double offsetFront) const
Draws partial object over junction.
Boundary getCenteringBoundary() const
~GNEEdgeData()
Destructor.
RGBColor setColor(const GUIVisualizationSettings &s) const
get edge data color
void computePathElement()
compute pathElement
GNEEdgeData(GNENet *net)
default Constructor
std::string getGenericDataProblem() const
return a string with the current data set problem (by default empty, can be reimplemented in children...
void updateGeometry()
update pre-computed geometry information
void drawGL(const GUIVisualizationSettings &s) const
Draws the object.
bool isGenericDataValid() const
check if current data set is valid to be written into XML (by default true, can be reimplemented in c...
void fixGenericDataProblem()
fix data set problem (by default throw an exception, has to be reimplemented in children)
Position getPositionInView() const
Returns element position in view.
A road/street connecting two junctions (netedit-version)
Definition GNEEdge.h:53
std::string getFilteredAttribute() const
get filtered attribute
GNEDataInterval * getDataInterval() const
get current select data set ID
const AttributeSelector * getAttributeSelector() const
getattribute selector modul
const IntervalSelector * getIntervalSelector() const
get interval selector modul
GNEDataInterval * myDataIntervalParent
dataInterval Parent
std::string getPartialID() const
get partial ID
bool isVisibleInspectDeleteSelect() const
check if attribute is visible in inspect, delete or select mode
void drawFilteredAttribute(const GUIVisualizationSettings &s, const PositionVector &laneShape, const std::string &attribute, const GNEDataInterval *dataIntervalParent) const
draw filtered attribute
const GNEHierarchicalContainerParents< GNEEdge * > & getParentEdges() const
get parent edges
const GNEHierarchicalContainerChildren< GNELane * > & getChildLanes() const
get child lanes
This lane is powered by an underlying GNEEdge and basically knows how to draw itself.
Definition GNELane.h:46
GNEEdge * getParentEdge() const
get parent edge
Definition GNELane.cpp:202
A NBNetBuilder extended by visualisation and editing capabilities.
Definition GNENet.h:42
GNEPathManager * getDataPathManager()
get data path manager
Definition GNENet.cpp:182
GNEViewNet * getViewNet() const
get view net
Definition GNENet.cpp:2194
void calculateConsecutivePathEdges(GNEPathElement *pathElement, SUMOVehicleClass vClass, const std::vector< GNEEdge * > &edges, const int firstLaneIndex=-1, const int lastLaneIndex=-1)
calculate consecutive path edges
const GNELane * getLane() const
get lane associated with this segment
GNEContour * getContour() const
SumoXMLTag getTag() const
get Tag vinculated with this attribute Property
const GNEViewNetHelper::EditModes & getEditModes() const
get edit modes
GNEViewNetHelper::IntervalBar & getIntervalBar()
get interval bar
GNEViewParent * getViewParent() const
get the net object
GNEEdgeDataFrame * getEdgeDataFrame() const
get frame for DATA_EDGEDATA
static void drawGeometry(const GUIVisualizationSettings::Detail d, const GUIGeometry &geometry, const double width, double offset=0)
draw geometry
GUIGlObjectType getType() const
Returns the type of the object as coded in GUIGlObjectType.
T getColor(const double value) const
const std::string & getName() const
Stores the information about how to visualize structures.
static const std::string SCHEME_NAME_DATA_ATTRIBUTE_NUMERICAL
Detail getDetailLevel(const double exaggeration) const
return the detail level
GUIVisualizationColorSettings colorSettings
color settings
GUIVisualizationDottedContourSettings dottedContourSettings
dotted contour settings
bool drawForViewObjectsHandler
whether drawing is performed for the purpose of selecting objects in view using ViewObjectsHandler
std::string relDataAttr
key for coloring by edgeRelation / tazRelation attribute
Static storage of an output device and its base (abstract) implementation.
OutputDevice & writeAttr(const SumoXMLAttr attr, const T &val)
writes a named attribute
OutputDevice & openTag(const std::string &xmlElement)
Opens an XML tag.
bool closeTag(const std::string &comment="")
Closes the most recently opened tag and optionally adds a comment.
bool hasParameter(const std::string &key) const
Returns whether the parameter is set.
std::map< std::string, std::string > Map
parameters map
virtual const std::string getParameter(const std::string &key, const std::string defaultValue="") const
Returns the value for a given key.
const Parameterised::Map & getParametersMap() const
Returns the inner key/value map.
A point in 2D or 3D with translation and scaling methods.
Definition Position.h:37
static const RGBColor BLACK
Definition RGBColor.h:196
static const RGBColor RED
named colors
Definition RGBColor.h:188
static double toDouble(const std::string &sData)
converts a string into the double value described by it by calling the char-type converter
DataEditMode dataEditMode
the current Data edit mode
bool isCurrentSupermodeData() const
@check if current supermode is Data
static void drawLockIcon(const GUIVisualizationSettings::Detail d, const GNEAttributeCarrier *AC, GUIGlObjectType type, const Position position, const double exaggeration, const double size=0.5, const double offsetx=0, const double offsety=0)
draw lock icon
static const RGBColor & getRainbowScaledColor(const double min, const double max, const double value)
get rainbow scaled color
RGBColor selectedEdgeDataColor
edge data selection color
static const double segmentWidth
width of dotted contour segments