Eclipse SUMO - Simulation of Urban MObility
Loading...
Searching...
No Matches
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 default:
108 return 0;
109 }
110}
111
112
113bool
115 // get current data edit mode
117 // check if we have to filter generic data
118 if ((dataMode == DataEditMode::DATA_INSPECT) || (dataMode == DataEditMode::DATA_DELETE) || (dataMode == DataEditMode::DATA_SELECT)) {
120 } else if (myDataIntervalParent->getNet()->getViewNet()->getViewParent()->getEdgeDataFrame()->shown()) {
121 // get selected data interval and filtered attribute
123 const std::string filteredAttribute = myNet->getViewNet()->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
141void
146
147
150 return getParentEdges().front()->getPositionInView();
151}
152
153
154void
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
170bool
172 return true;
173}
174
175
176std::string
178 return "";
179}
180
181
182void
184 throw InvalidArgument(getTagStr() + " cannot fix any problem");
185}
186
187
188void
190 // Nothing to draw
191}
192
193
194void
196 // nothing to compute
197}
198
199
200void
201GNEEdgeData::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
209 // draw over all edge's lanes
210 for (const auto& laneEdge : segment->getLane()->getParentEdge()->getChildLanes()) {
211 // Add a draw matrix
213 // Start with the drawing of the area translating matrix to origin
214 drawInLayer(GLO_EDGEDATA, offsetFront);
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
225 // draw lock icon
227 // draw filtered attribute
228 if (getParentEdges().front()->getChildLanes().front() == laneEdge) {
229 drawFilteredAttribute(s, laneEdge->getLaneShape(),
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
243void
244GNEEdgeData::drawJunctionPartialGL(const GUIVisualizationSettings& /*s*/, const GNESegment* /*segment*/, const double /*offsetFront*/) const {
245 // EdgeDatas don't use drawJunctionPartialGL over junction
246}
247
248
249GNELane*
251 /* temporal */
252 return nullptr;
253}
254
255
256GNELane*
258 /* temporal */
259 return nullptr;
260}
261
262
265 return getParentEdges().front()->getCenteringBoundary();
266}
267
268
269std::string
271 switch (key) {
272 case SUMO_ATTR_ID:
273 return getPartialID() + getParentEdges().front()->getID();
274 case GNE_ATTR_DATASET:
276 case SUMO_ATTR_BEGIN:
278 case SUMO_ATTR_END:
280 default:
281 return getCommonAttribute(key);
282 }
283}
284
285
286double
290
291
292void
293GNEEdgeData::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
301bool
302GNEEdgeData::isValid(SumoXMLAttr key, const std::string& value) {
303 return isCommonAttributeValid(key, value);
304}
305
306
308 switch (key) {
309 case SUMO_ATTR_ID:
310 return false;
311 default:
312 return true;
313 }
314}
315
316
317std::string
319 return getTagStr();
320}
321
322
323std::string
325 return getTagStr() + ": " + getParentEdges().front()->getID();
326}
327
328
329void
330GNEEdgeData::setAttribute(SumoXMLAttr key, const std::string& value) {
331 setCommonAttribute(key, value);
332 if (!isTemplate()) {
334 }
335 // mark interval toolbar for update
337}
338
339/****************************************************************************/
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
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
bool isAttributeCarrierSelected() const
check if attribute carrier is selected
double getCommonAttributeDouble(SumoXMLAttr key) const
const std::string getID() const override
get ID (all Attribute Carriers have one)
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
GNENet * getNet() const
get pointer to net
bool isCommonAttributeValid(SumoXMLAttr key, const std::string &value) const
std::string getCommonAttribute(SumoXMLAttr key) const
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...)
GNEDataSet * getDataSetParent() const
Returns a pointer to GNEDataSet parent.
const std::map< SumoXMLTag, GNEDataSet::AttributeColors > & getSpecificAttributeColors() const
specific attribute colors
std::string getAttribute(SumoXMLAttr key) const override
void updateAttributeColors()
update attribute colors deprecated
bool isGenericDataValid() const override
check if current data set is valid to be written into XML (by default true, can be reimplemented in c...
GNELane * getLastPathLane() const override
get last path lane
bool isGenericDataVisible() const override
check if current edge data is visible
std::string getPopUpID() const override
get PopPup ID (Used in AC Hierarchy)
GNELane * getFirstPathLane() const override
get first path lane
void writeGenericData(OutputDevice &device) const override
write data set element into a xml file
bool isAttributeEnabled(SumoXMLAttr key) const override
void fixGenericDataProblem() override
fix data set problem (by default throw an exception, has to be reimplemented in children)
void drawGL(const GUIVisualizationSettings &s) const override
Draws the object.
std::string getHierarchyName() const override
get Hierarchy Name (Used in AC Hierarchy)
void computePathElement() override
compute pathElement
double getAttributeDouble(SumoXMLAttr key) const override
~GNEEdgeData()
Destructor.
RGBColor setColor(const GUIVisualizationSettings &s) const
get edge data color
double getColorValue(const GUIVisualizationSettings &s, int activeScheme) const override
Position getPositionInView() const override
Returns element position in view.
GNEEdgeData(GNENet *net)
default Constructor
void drawLanePartialGL(const GUIVisualizationSettings &s, const GNESegment *segment, const double offsetFront) const override
Draws partial object over lane.
void updateGeometry() override
update pre-computed geometry information
Boundary getCenteringBoundary() const override
bool isValid(SumoXMLAttr key, const std::string &value) override
method for checking if the key and their conrrespond attribute are valids
void drawJunctionPartialGL(const GUIVisualizationSettings &s, const GNESegment *segment, const double offsetFront) const override
Draws partial object over junction.
std::string getGenericDataProblem() const override
return a string with the current data set problem (by default empty, can be reimplemented in children...
void setAttribute(SumoXMLAttr key, const std::string &value, GNEUndoList *undoList) override
method for setting the attribute and letting the object perform data set changes
std::string getAttribute(SumoXMLAttr key) const override
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
GNEEdge * getParentEdge() const
get parent edge
Definition GNELane.cpp:214
A NBNetBuilder extended by visualisation and editing capabilities.
Definition GNENet.h:42
GNEPathManager * getDataPathManager()
get data path manager
Definition GNENet.cpp:180
GNEViewNet * getViewNet() const
get view net
Definition GNENet.cpp:2193
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