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-2024 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>
22#include <netedit/GNESegment.h>
23#include <netedit/GNEUndoList.h>
24#include <netedit/GNEViewNet.h>
30
31#include "GNEEdgeData.h"
32#include "GNEDataInterval.h"
33
34
35// ===========================================================================
36// member method definitions
37// ===========================================================================
38
39// ---------------------------------------------------------------------------
40// GNEEdgeData - methods
41// ---------------------------------------------------------------------------
42
43GNEEdgeData::GNEEdgeData(GNEDataInterval* dataIntervalParent, GNEEdge* edgeParent, const Parameterised::Map& parameters) :
44 GNEGenericData(GNE_TAG_EDGEREL_SINGLE, GUIIconSubSys::getIcon(GUIIcon::EDGEDATA), GLO_EDGEDATA, dataIntervalParent, parameters,
45{}, {edgeParent}, {}, {}, {}, {}) {
46}
47
48
50
51
54 // set default color
59 // user defined rainbow
60 const double val = getColorValue(s, s.dataColorer.getActive());
61 col = s.dataColorer.getScheme().getColor(val);
63 // get selected data interval and filtered attribute
65 const std::string filteredAttribute = myNet->getViewNet()->getViewParent()->getEdgeDataFrame()->getAttributeSelector()->getFilteredAttribute();
66 // continue if there is a selected data interval and filtered attribute
67 if (dataInterval && (filteredAttribute.size() > 0)) {
68 if (dataInterval->getSpecificAttributeColors().at(myTagProperty.getTag()).exist(filteredAttribute)) {
69 // obtain minimum and maximum value
70 const double minValue = dataInterval->getSpecificAttributeColors().at(myTagProperty.getTag()).getMinValue(filteredAttribute);
71 const double maxValue = dataInterval->getSpecificAttributeColors().at(myTagProperty.getTag()).getMaxValue(filteredAttribute);
72 // get value
73 const double value = parse<double>(getParameter(filteredAttribute, "0"));
74 // return color
75 col = GNEViewNetHelper::getRainbowScaledColor(minValue, maxValue, value);
76 }
77 }
78 }
79 return col;
80}
81
82
83double
84GNEEdgeData::getColorValue(const GUIVisualizationSettings& s, int activeScheme) const {
85 switch (activeScheme) {
86 case 0:
87 return 0;
88 case 1:
90 case 2:
91 return 0; // setfunctional color const GNEAdditional* TAZA = getParentAdditionals().front();
92 case 3:
93 return 0; // setfunctional color const GNEAdditional* TAZA = getParentAdditionals().back();
94 case 4:
95 // by numerical attribute value
96 try {
99 } else {
101 }
102 } catch (NumberFormatException&) {
104 }
105 }
106 return 0;
107}
108
109
110bool
112 // get current data edit mode
114 // check if we have to filter generic data
115 if ((dataMode == DataEditMode::DATA_INSPECT) || (dataMode == DataEditMode::DATA_DELETE) || (dataMode == DataEditMode::DATA_SELECT)) {
117 } else if (myDataIntervalParent->getNet()->getViewNet()->getViewParent()->getEdgeDataFrame()->shown()) {
118 // get selected data interval and filtered attribute
120 const std::string filteredAttribute = myNet->getViewNet()->getViewParent()->getEdgeDataFrame()->getAttributeSelector()->getFilteredAttribute();
121 // check interval
122 if ((dataInterval != nullptr) && (dataInterval != myDataIntervalParent)) {
123 return false;
124 }
125 // check attribute
126 if ((filteredAttribute.size() > 0) && (getParametersMap().count(filteredAttribute) == 0)) {
127 return false;
128 }
129 // all checks ok, then return true
130 return true;
131 } else {
132 // GNEEdgeDataFrame hidden, then return false
133 return false;
134 }
135}
136
137
138void
143
144
147 return getParentEdges().front()->getPositionInView();
148}
149
150
151void
153 // open device (don't use SUMO_TAG_MEANDATA_EDGE)
154 device.openTag(SUMO_TAG_EDGE);
155 // write edge ID
156 device.writeAttr(SUMO_ATTR_ID, getParentEdges().front()->getID());
157 // iterate over attributes
158 for (const auto& attribute : getParametersMap()) {
159 // write attribute (don't use writeParams)
160 device.writeAttr(attribute.first, attribute.second);
161 }
162 // close device
163 device.closeTag();
164}
165
166
167bool
169 return true;
170}
171
172
173std::string
175 return "";
176}
177
178
179void
181 throw InvalidArgument(getTagStr() + " cannot fix any problem");
182}
183
184
185void
187 // Nothing to draw
188}
189
190
191void
193 // nothing to compute
194}
195
196
197void
198GNEEdgeData::drawLanePartialGL(const GUIVisualizationSettings& s, const GNESegment* segment, const double offsetFront) const {
199 // get color
200 const auto color = setColor(s);
201 if (segment->getLane() && (color.alpha() != 0) && myNet->getViewNet()->getEditModes().isCurrentSupermodeData()) {
202 // get detail level
203 const auto d = s.getDetailLevel(1);
204 // draw geometry only if we'rent in drawForObjectUnderCursor mode
206 // draw over all edge's lanes
207 for (const auto& laneEdge : segment->getLane()->getParentEdge()->getLanes()) {
208 // Add a draw matrix
210 // Start with the drawing of the area translating matrix to origin
213 // draw geometry
214 GUIGeometry::drawGeometry(laneEdge->getDrawingConstants()->getDetail(), laneEdge->getLaneGeometry(), laneEdge->getDrawingConstants()->getDrawingWidth());
215 // translate to top
216 glTranslated(0, 0, 0.01);
217 GLHelper::setColor(color);
218 // draw internal box lines
219 GUIGeometry::drawGeometry(laneEdge->getDrawingConstants()->getDetail(), laneEdge->getLaneGeometry(), (laneEdge->getDrawingConstants()->getDrawingWidth() - 0.1));
220 // Pop last matrix
222 // draw lock icon
224 // draw filtered attribute
225 if (getParentEdges().front()->getLanes().front() == laneEdge) {
226 drawFilteredAttribute(s, laneEdge->getLaneShape(),
229 }
230 }
231 // draw dotted contour
232 segment->getContour()->drawDottedContours(s, d, this, s.dottedContourSettings.segmentWidth, true);
233 }
234 // calculate contour and draw dotted geometry
235 segment->getContour()->calculateContourEdge(s, d, segment->getLane()->getParentEdge(), this, getType(), true, true);
236 }
237}
238
239
240void
241GNEEdgeData::drawJunctionPartialGL(const GUIVisualizationSettings& /*s*/, const GNESegment* /*segment*/, const double /*offsetFront*/) const {
242 // EdgeDatas don't use drawJunctionPartialGL over junction
243}
244
245
246GNELane*
248 /* temporal */
249 return nullptr;
250}
251
252
253GNELane*
255 /* temporal */
256 return nullptr;
257}
258
259
262 return getParentEdges().front()->getCenteringBoundary();
263}
264
265
266std::string
268 switch (key) {
269 case SUMO_ATTR_ID:
270 return getPartialID() + getParentEdges().front()->getID();
271 case GNE_ATTR_DATASET:
273 case SUMO_ATTR_BEGIN:
275 case SUMO_ATTR_END:
280 return getParametersStr();
281 default:
282 throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
283 }
284}
285
286
287double
289 throw InvalidArgument(getTagStr() + " doesn't have a double attribute of type '" + toString(key) + "'");
290}
291
292
293void
294GNEEdgeData::setAttribute(SumoXMLAttr key, const std::string& value, GNEUndoList* undoList) {
295 if (value == getAttribute(key)) {
296 return; //avoid needless changes, later logic relies on the fact that attributes have changed
297 }
298 switch (key) {
301 GNEChange_Attribute::changeAttribute(this, key, value, undoList);
302 break;
303 default:
304 throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
305 }
306}
307
308
309bool
310GNEEdgeData::isValid(SumoXMLAttr key, const std::string& value) {
311 switch (key) {
313 return canParse<bool>(value);
315 return Parameterised::areAttributesValid(value, true);
316 default:
317 throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
318 }
319}
320
321
323 switch (key) {
324 case SUMO_ATTR_ID:
325 return false;
326 default:
327 return true;
328 }
329}
330
331
332std::string
334 return getTagStr();
335}
336
337
338std::string
340 return getTagStr() + ": " + getParentEdges().front()->getID();
341}
342
343
344void
345GNEEdgeData::setAttribute(SumoXMLAttr key, const std::string& value) {
346 switch (key) {
348 if (parse<bool>(value)) {
350 } else {
352 }
353 break;
355 setParametersStr(value);
356 // update attribute colors
358 break;
359 default:
360 throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
361 }
362}
363
364/****************************************************************************/
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
GUIIcon
An enumeration of icons used by the gui applications.
Definition GUIIcons.h:33
@ 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.
@ GNE_ATTR_SELECTED
element is selected
@ SUMO_ATTR_BEGIN
weights: time range begin
@ GNE_ATTR_PARAMETERS
parameters "key1=value1|key2=value2|...|keyN=valueN"
@ 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:654
static void popMatrix()
pop matrix
Definition GLHelper.cpp:130
static void pushMatrix()
push matrix
Definition GLHelper.cpp:117
const std::string getID() const
get ID (all Attribute Carriers have one)
bool isAttributeCarrierSelected() const
check if attribute carrier is selected
const std::string & getTagStr() const
get tag assigned to this object in string format
void unselectAttributeCarrier(const bool changeFlag=true)
unselect attribute carrier using GUIGlobalSelection
GNENet * myNet
pointer to net
GNENet * getNet() const
get pointer to net
void selectAttributeCarrier(const bool changeFlag=true)
select attribute carrier using GUIGlobalSelection
const GNETagProperties & myTagProperty
reference to tagProperty associated with this attribute carrier
static void changeAttribute(GNEAttributeCarrier *AC, SumoXMLAttr key, const std::string &value, GNEUndoList *undoList, const bool force=false)
change attribute
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
void 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...)
An Element which don't belong to GNENet but has influence in the simulation.
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
GNEEdgeData(GNEDataInterval *dataIntervalParent, GNEEdge *edgeParent, const Parameterised::Map &parameters)
Constructor.
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
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
const std::vector< GNELane * > & getLanes() const
returns a reference to the lane vector
Definition GNEEdge.cpp:1118
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
An Element which don't belong to GNENet but has influence in the simulation.
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 std::vector< GNEEdge * > & getParentEdges() const
get parent edges
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:196
GNEPathManager * getDataPathManager()
get data path manager
Definition GNENet.cpp:151
GNEViewNet * getViewNet() const
get view net
Definition GNENet.cpp:2155
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
void drawTranslateFrontAttributeCarrier(const GNEAttributeCarrier *AC, double typeOrLayer, const double extraOffset=0)
draw front attributeCarrier
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.
static bool areAttributesValid(const std::string &value, bool report=false, const std::string kvsep="=", const std::string sep="|")
check if given string can be parsed to an attributes map "key1=value1|key2=value2|....
bool hasParameter(const std::string &key) const
Returns whether the parameter is set.
std::map< std::string, std::string > Map
parameters map
void setParametersStr(const std::string &paramsString, const std::string kvsep="=", const std::string sep="|")
set the inner key/value map in string format "key1=value1|key2=value2|...|keyN=valueN"
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.
std::string getParametersStr(const std::string kvsep="=", const std::string sep="|") const
Returns the inner key/value map in string format "key1=value1|key2=value2|...|keyN=valueN".
A point in 2D or 3D with translation and scaling methods.
Definition Position.h:37
static const RGBColor BLACK
Definition RGBColor.h:193
static const RGBColor RED
named colors
Definition RGBColor.h:185
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