Eclipse SUMO - Simulation of Urban MObility
Loading...
Searching...
No Matches
GNEEdgeRelData.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 relation 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 "GNEEdgeRelData.h"
32#include "GNEDataInterval.h"
33
34
35// ===========================================================================
36// member method definitions
37// ===========================================================================
38
39// ---------------------------------------------------------------------------
40// GNEEdgeRelData - methods
41// ---------------------------------------------------------------------------
42
43GNEEdgeRelData::GNEEdgeRelData(GNEDataInterval* dataIntervalParent, GNEEdge* fromEdge, GNEEdge* toEdge,
44 const Parameterised::Map& parameters) :
46 dataIntervalParent, parameters, {}, {fromEdge, toEdge}, {}, {}, {}, {}) {
47}
48
49
51
52
55 // set default color
60 // user defined rainbow
61 double val = getColorValue(s, s.dataColorer.getActive());
62 col = s.dataColorer.getScheme().getColor(val);
64 // get selected data interval and filtered attribute
66 const std::string filteredAttribute = myNet->getViewNet()->getViewParent()->getEdgeRelDataFrame()->getAttributeSelector()->getFilteredAttribute();
67 // continue if there is a selected data interval and filtered attribute
68 if (dataInterval && (filteredAttribute.size() > 0)) {
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 col = GNEViewNetHelper::getRainbowScaledColor(minValue, maxValue, value);
75 }
76 }
77 return col;
78}
79
80
81double
83 switch (activeScheme) {
84 case 0:
85 return 0;
86 case 1:
88 case 2:
89 return 0; // setfunctional color const GNEAdditional* TAZA = getParentAdditionals().front();
90 case 3:
91 return 0; // setfunctional color const GNEAdditional* TAZA = getParentAdditionals().back();
92 case 4:
93 // by numerical attribute value
94 try {
97 } else {
99 }
100 } catch (NumberFormatException&) {
102 }
103 }
104 return 0;
105}
106
107
108bool
110 // obtain pointer to edge data frame (only for code legibly)
111 const GNEEdgeRelDataFrame* edgeRelDataFrame = myNet->getViewNet()->getViewParent()->getEdgeRelDataFrame();
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 (edgeRelDataFrame->shown()) {
118 // check interval
119 if ((edgeRelDataFrame->getIntervalSelector()->getDataInterval() != nullptr) &&
120 (edgeRelDataFrame->getIntervalSelector()->getDataInterval() != myDataIntervalParent)) {
121 return false;
122 }
123 // check attribute
124 if ((edgeRelDataFrame->getAttributeSelector()->getFilteredAttribute().size() > 0) &&
125 (getParametersMap().count(edgeRelDataFrame->getAttributeSelector()->getFilteredAttribute()) == 0)) {
126 return false;
127 }
128 // all checks ok, then return true
129 return true;
130 } else {
131 // GNEEdgeRelDataFrame hidden, then return false
132 return false;
133 }
134}
135
136
137void
139 // just compute path
141}
142
143
144void
146 // Nothing to draw
147}
148
149
150void
155
156
157void
158GNEEdgeRelData::drawLanePartialGL(const GUIVisualizationSettings& s, const GNESegment* segment, const double offsetFront) const {
159 // get color
160 const auto color = setColor(s);
161 if (segment->getLane() && (color.alpha() != 0) && myNet->getViewNet()->getEditModes().isCurrentSupermodeData()) {
162 // get detail level
163 const auto d = s.getDetailLevel(1);
164 // draw over all edge's lanes
165 for (const auto& laneEdge : segment->getLane()->getParentEdge()->getLanes()) {
166 // get lane width
167 const double laneWidth = s.addSize.getExaggeration(s, laneEdge) * s.edgeRelWidthExaggeration *
168 (laneEdge->getParentEdge()->getNBEdge()->getLaneWidth(laneEdge->getIndex()) * 0.5);
169 // Add a draw matrix
171 // Start with the drawing of the area translating matrix to origin
172 drawInLayer(GLO_EDGERELDATA, offsetFront);
174 // draw box lines
175
176
177 GLHelper::drawBoxLines(laneEdge->getLaneShape(), laneEdge->getShapeRotations(),
178 laneEdge->getShapeLengths(), laneWidth);
179 // translate to top
180 glTranslated(0, 0, 0.01);
181 GLHelper::setColor(color);
182 // draw internal box lines
183 GLHelper::drawBoxLines(laneEdge->getLaneShape(), laneEdge->getShapeRotations(),
184 laneEdge->getShapeLengths(), (laneWidth - 0.1));
185 // Pop last matrix
187 // draw lock icon
189 // draw filtered attribute
190 if (getParentEdges().front()->getLanes().front() == laneEdge) {
191 drawFilteredAttribute(s, laneEdge->getLaneShape(),
194 }
195 // draw dotted contour
196 segment->getContour()->drawDottedContours(s, d, this, s.dottedContourSettings.segmentWidth, true);
197 }
198 // draw dotted contour
199 if (getParentEdges().front() == segment->getLane()->getParentEdge()) {
200 segment->getContour()->calculateContourEdge(s, d, getParentEdges().front(), this, getType(), true, false);
201 }
202 if (getParentEdges().back() == segment->getLane()->getParentEdge()) {
203 segment->getContour()->calculateContourEdge(s, d, getParentEdges().back(), this, getType(), false, true);
204 }
205 // check if add this path element to redraw buffer
208 }
209
210 }
211}
212
213
214void
215GNEEdgeRelData::drawJunctionPartialGL(const GUIVisualizationSettings& s, const GNESegment* segment, const double /*offsetFront*/) const {
216 // get color
217 const auto color = setColor(s);
218 if ((color.alpha() != 0) && myNet->getViewNet()->getEditModes().isCurrentSupermodeData()) {
219 // get detail level
220 const auto d = s.getDetailLevel(1);
221 // get flag for only draw contour
222
223 // finish
224
225 // draw dotted contour
226 if (segment->getPreviousLane() && segment->getNextLane()) {
227 segment->getContour()->calculateContourEdges(s, d, segment->getPreviousLane()->getParentEdge(), segment->getNextLane()->getParentEdge());
228 }
229 // check if add this path element to redraw buffer
232 }
233 }
234}
235
236
237GNELane*
239 /* temporal */
240 return nullptr;
241}
242
243
244GNELane*
246 /* temporal */
247 return nullptr;
248}
249
250
253 return getParentEdges().front()->getPositionInView();
254}
255
256
257void
259 // open device
261 // write from
262 device.writeAttr(SUMO_ATTR_FROM, getParentEdges().front()->getID());
263 // write to
264 device.writeAttr(SUMO_ATTR_TO, getParentEdges().back()->getID());
265 // iterate over attributes
266 for (const auto& attribute : getParametersMap()) {
267 // write attribute (don't use writeParams)
268 device.writeAttr(attribute.first, attribute.second);
269 }
270 // close device
271 device.closeTag();
272}
273
274
275bool
277 return true;
278}
279
280
281std::string
283 return "";
284}
285
286
287void
289 throw InvalidArgument(getTagStr() + " cannot fix any problem");
290}
291
292
295 return getParentEdges().front()->getCenteringBoundary();
296}
297
298
299std::string
301 switch (key) {
302 case SUMO_ATTR_ID:
303 return getPartialID() + getParentEdges().front()->getID();
304 case SUMO_ATTR_FROM:
305 return getParentEdges().front()->getID();
306 case SUMO_ATTR_TO:
307 return getParentEdges().back()->getID();
308 case GNE_ATTR_DATASET:
310 case SUMO_ATTR_BEGIN:
312 case SUMO_ATTR_END:
315 return getParametersStr();
316 default:
317 return getCommonAttribute(key);
318 }
319}
320
321
322double
324 throw InvalidArgument(getTagStr() + " doesn't have a double attribute of type '" + toString(key) + "'");
325}
326
327
328void
329GNEEdgeRelData::setAttribute(SumoXMLAttr key, const std::string& value, GNEUndoList* undoList) {
330 if (value == getAttribute(key)) {
331 return; //avoid needless changes, later logic relies on the fact that attributes have changed
332 }
333 switch (key) {
334 case SUMO_ATTR_FROM:
335 case SUMO_ATTR_TO:
337 GNEChange_Attribute::changeAttribute(this, key, value, undoList);
338 break;
339 default:
340 setCommonAttribute(key, value, undoList);
341 break;
342 }
343}
344
345
346bool
347GNEEdgeRelData::isValid(SumoXMLAttr key, const std::string& value) {
348 switch (key) {
349 case SUMO_ATTR_FROM:
350 return SUMOXMLDefinitions::isValidNetID(value) && (myNet->getAttributeCarriers()->retrieveEdge(value, false) != nullptr) &&
351 (value != getParentEdges().back()->getID());
352 case SUMO_ATTR_TO:
353 return SUMOXMLDefinitions::isValidNetID(value) && (myNet->getAttributeCarriers()->retrieveEdge(value, false) != nullptr) &&
354 (value != getParentEdges().front()->getID());
356 return Parameterised::areAttributesValid(value, true);
357 default:
358 return isCommonValid(key, value);
359 }
360}
361
362
364 switch (key) {
365 case SUMO_ATTR_ID:
366 return false;
367 default:
368 return true;
369 }
370}
371
372
373std::string
375 return getTagStr();
376}
377
378
379std::string
381 return getTagStr() + ": " + getParentEdges().front()->getID() + "->" + getParentEdges().back()->getID();
382}
383
384
385void
386GNEEdgeRelData::setAttribute(SumoXMLAttr key, const std::string& value) {
387 switch (key) {
388 case SUMO_ATTR_FROM: {
389 // change first edge
391 break;
392 }
393 case SUMO_ATTR_TO: {
394 // change last edge
396 break;
397 }
399 setParametersStr(value);
400 // update attribute colors
402 break;
403 default:
404 setCommonAttribute(key, value);
405 break;
406 }
407 // mark interval toolbar for update
409}
410
411/****************************************************************************/
DataEditMode
enum for data edit modes
@ DATA_EDGERELDATA
mode for create edgeRelData elements
@ DATA_SELECT
mode for selecting data elements
@ DATA_INSPECT
mode for inspecting data elements
@ DATA_DELETE
mode for deleting data elements
@ GLO_EDGERELDATA
edge relation data
GUIViewObjectsHandler gViewObjectsHandler
GUIIcon
An enumeration of icons used by the gui applications.
Definition GUIIcons.h:33
@ SVC_IGNORING
vehicles ignoring classes
@ SUMO_TAG_EDGEREL
a relation between two edges
SumoXMLAttr
Numbers representing SUMO-XML - attributes.
@ SUMO_ATTR_BEGIN
weights: time range begin
@ GNE_ATTR_PARAMETERS
parameters "key1=value1|key2=value2|...|keyN=valueN"
@ SUMO_ATTR_TO
@ SUMO_ATTR_FROM
@ 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 drawBoxLines(const PositionVector &geom, const std::vector< double > &rots, const std::vector< double > &lengths, double width, int cornerDetail=0, double offset=0)
Draws thick lines.
Definition GLHelper.cpp:348
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
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 isCommonValid(SumoXMLAttr key, const std::string &value)
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
std::string getCommonAttribute(SumoXMLAttr key) const
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 calculateContourEdges(const GUIVisualizationSettings &s, const GUIVisualizationSettings::Detail d, const GNEEdge *fromEdge, const GNEEdge *toEdge) const
calculate contour between two consecutive edges
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...)
bool checkDrawPathContour(const GUIVisualizationSettings &s, const GUIVisualizationSettings::Detail d, const GNEAttributeCarrier *AC) const
drawing contour functions
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
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
Position getPositionInView() const
Returns element position in view.
bool isGenericDataValid() const
check if current data set is valid to be written into XML (by default true, can be reimplemented in c...
std::string getHierarchyName() const
get Hierarchy Name (Used in AC Hierarchy)
GNELane * getLastPathLane() const
get last path lane
double getAttributeDouble(SumoXMLAttr key) const
std::string getAttribute(SumoXMLAttr key) const
void setAttribute(SumoXMLAttr key, const std::string &value, GNEUndoList *undoList)
method for setting the attribute and letting the object perform data set changes
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.
bool isAttributeEnabled(SumoXMLAttr key) const
void fixGenericDataProblem()
fix data set problem (by default throw an exception, has to be reimplemented in children)
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...
bool isGenericDataVisible() const
check if current edge rel data is visible
Boundary getCenteringBoundary() const
void drawGL(const GUIVisualizationSettings &s) const
Draws the object.
RGBColor setColor(const GUIVisualizationSettings &s) const
get edge rel data color
~GNEEdgeRelData()
Destructor.
void writeGenericData(OutputDevice &device) const
write data set element into a xml file
std::string getPopUpID() const
get PopPup ID (Used in AC Hierarchy)
double getColorValue(const GUIVisualizationSettings &s, int activeScheme) const
GNEEdgeRelData(GNEDataInterval *dataIntervalParent, GNEEdge *fromEdge, GNEEdge *toEdge, const Parameterised::Map &parameters)
Constructor.
void updateGeometry()
update pre-computed geometry information
GNELane * getFirstPathLane() const
get first path lane
bool isValid(SumoXMLAttr key, const std::string &value)
method for checking if the key and their conrrespond attribute are valids
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 replaceFirstParentEdge(const std::string &value)
replace the first parent edge
void drawFilteredAttribute(const GUIVisualizationSettings &s, const PositionVector &laneShape, const std::string &attribute, const GNEDataInterval *dataIntervalParent) const
draw filtered attribute
void replaceLastParentEdge(const std::string &value)
replace the last parent edge
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
GNEEdge * retrieveEdge(const std::string &id, bool hardFail=true) const
get edge by id
GNEPathManager * getDataPathManager()
get data path manager
Definition GNENet.cpp:151
GNENetHelper::AttributeCarriers * getAttributeCarriers() const
get all attribute carriers used in this net
Definition GNENet.cpp:127
GNEViewNet * getViewNet() const
get view net
Definition GNENet.cpp:2163
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
const GNELane * getNextLane() const
get next lane
const GNELane * getPreviousLane() const
get previous lane
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
GNEEdgeRelDataFrame * getEdgeRelDataFrame() const
get frame for DATA_EDGERELDATA
GUIGlObjectType getType() const
Returns the type of the object as coded in GUIGlObjectType.
T getColor(const double value) const
const std::string & getName() const
void addToRedrawPathElements(const GNEPathElement *pathElement)
add path element to redrawing set
bool isPathElementMarkForRedraw(const GNEPathElement *pathElement) const
check if the given path element has to be redraw again
Stores the information about how to visualize structures.
static const std::string SCHEME_NAME_DATA_ATTRIBUTE_NUMERICAL
GUIVisualizationSizeSettings addSize
Detail getDetailLevel(const double exaggeration) const
return the detail level
GUIVisualizationColorSettings colorSettings
color settings
double edgeRelWidthExaggeration
The edgeRelation exaggeration (upscale thickness)
GUIVisualizationDottedContourSettings dottedContourSettings
dotted contour settings
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 GREEN
Definition RGBColor.h:186
static const RGBColor BLACK
Definition RGBColor.h:193
static bool isValidNetID(const std::string &value)
whether the given string is a valid id for a network element
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
double getExaggeration(const GUIVisualizationSettings &s, const GUIGlObject *o, double factor=20) const
return the drawing size including exaggeration and constantSize values