Eclipse SUMO - Simulation of Urban MObility
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 
22 // ===========================================================================
23 // included modules
24 // ===========================================================================
25 #include <config.h>
26 
27 #include <netedit/GNENet.h>
28 #include <netedit/GNEUndoList.h>
29 #include <netedit/GNEViewNet.h>
30 #include <netedit/GNEViewParent.h>
33 #include <utils/gui/div/GLHelper.h>
35 
36 #include "GNEEdgeRelData.h"
37 #include "GNEDataInterval.h"
38 
39 
40 // ===========================================================================
41 // member method definitions
42 // ===========================================================================
43 
44 // ---------------------------------------------------------------------------
45 // GNEEdgeRelData - methods
46 // ---------------------------------------------------------------------------
47 
48 GNEEdgeRelData::GNEEdgeRelData(GNEDataInterval* dataIntervalParent, GNEEdge* fromEdge, GNEEdge* toEdge,
49  const Parameterised::Map& parameters) :
51  dataIntervalParent, parameters, {}, {fromEdge, toEdge}, {}, {}, {}, {}) {
52 }
53 
54 
56 
57 
60  // set default color
65  // user defined rainbow
66  double val = getColorValue(s, s.dataColorer.getActive());
67  col = s.dataColorer.getScheme().getColor(val);
69  // get selected data interval and filtered attribute
71  const std::string filteredAttribute = myNet->getViewNet()->getViewParent()->getEdgeRelDataFrame()->getAttributeSelector()->getFilteredAttribute();
72  // continue if there is a selected data interval and filtered attribute
73  if (dataInterval && (filteredAttribute.size() > 0)) {
74  // obtain minimum and maximum value
75  const double minValue = dataInterval->getSpecificAttributeColors().at(myTagProperty.getTag()).getMinValue(filteredAttribute);
76  const double maxValue = dataInterval->getSpecificAttributeColors().at(myTagProperty.getTag()).getMaxValue(filteredAttribute);
77  // get value
78  const double value = parse<double>(getParameter(filteredAttribute, "0"));
79  col = GNEViewNetHelper::getRainbowScaledColor(minValue, maxValue, value);
80  }
81  }
82  return col;
83 }
84 
85 
86 double
87 GNEEdgeRelData::getColorValue(const GUIVisualizationSettings& s, int activeScheme) const {
88  switch (activeScheme) {
89  case 0:
90  return 0;
91  case 1:
93  case 2:
94  return 0; // setfunctional color const GNEAdditional* TAZA = getParentAdditionals().front();
95  case 3:
96  return 0; // setfunctional color const GNEAdditional* TAZA = getParentAdditionals().back();
97  case 4:
98  // by numerical attribute value
99  try {
100  if (hasParameter(s.relDataAttr)) {
102  } else {
104  }
105  } catch (NumberFormatException&) {
107  }
108  }
109  return 0;
110 }
111 
112 
113 bool
115  // obtain pointer to edge data frame (only for code legibly)
116  const GNEEdgeRelDataFrame* edgeRelDataFrame = myNet->getViewNet()->getViewParent()->getEdgeRelDataFrame();
117  // get current data edit mode
119  // check if we have to filter generic data
120  if ((dataMode == DataEditMode::DATA_INSPECT) || (dataMode == DataEditMode::DATA_DELETE) || (dataMode == DataEditMode::DATA_SELECT)) {
122  } else if (edgeRelDataFrame->shown()) {
123  // check interval
124  if ((edgeRelDataFrame->getIntervalSelector()->getDataInterval() != nullptr) &&
125  (edgeRelDataFrame->getIntervalSelector()->getDataInterval() != myDataIntervalParent)) {
126  return false;
127  }
128  // check attribute
129  if ((edgeRelDataFrame->getAttributeSelector()->getFilteredAttribute().size() > 0) &&
130  (getParametersMap().count(edgeRelDataFrame->getAttributeSelector()->getFilteredAttribute()) == 0)) {
131  return false;
132  }
133  // all checks ok, then return true
134  return true;
135  } else {
136  // GNEEdgeRelDataFrame hidden, then return false
137  return false;
138  }
139 }
140 
141 
142 void
144  // just compute path
146 }
147 
148 
149 void
151  // Nothing to draw
152 }
153 
154 
155 void
157  // calculate path
159 }
160 
161 
162 void
163 GNEEdgeRelData::drawLanePartialGL(const GUIVisualizationSettings& s, const GNEPathManager::Segment* segment, const double offsetFront) const {
164  // get color
165  const auto color = setColor(s);
166  if (segment->getLane() && (color.alpha() != 0) && myNet->getViewNet()->getEditModes().isCurrentSupermodeData()) {
167  // get detail level
168  const auto d = s.getDetailLevel(1);
169  // draw over all edge's lanes
170  for (const auto& laneEdge : segment->getLane()->getParentEdge()->getLanes()) {
171  // get lane width
172  const double laneWidth = s.addSize.getExaggeration(s, laneEdge) * s.edgeRelWidthExaggeration *
173  (laneEdge->getParentEdge()->getNBEdge()->getLaneWidth(laneEdge->getIndex()) * 0.5);
174  // Add a draw matrix
176  // Start with the drawing of the area translating matrix to origin
179  // draw box lines
180 
181 
182  GLHelper::drawBoxLines(laneEdge->getLaneShape(), laneEdge->getShapeRotations(),
183  laneEdge->getShapeLengths(), laneWidth);
184  // translate to top
185  glTranslated(0, 0, 0.01);
186  GLHelper::setColor(color);
187  // draw internal box lines
188  GLHelper::drawBoxLines(laneEdge->getLaneShape(), laneEdge->getShapeRotations(),
189  laneEdge->getShapeLengths(), (laneWidth - 0.1));
190  // Pop last matrix
192  // draw lock icon
194  // draw filtered attribute
195  if (getParentEdges().front()->getLanes().front() == laneEdge) {
196  drawFilteredAttribute(s, laneEdge->getLaneShape(),
199  }
200  // draw dotted contour
201  segment->getContour()->drawDottedContours(s, d, this, s.dottedContourSettings.segmentWidth, true);
202  }
203  // draw dotted contour
204  if (getParentEdges().front() == segment->getLane()->getParentEdge()) {
205  segment->getContour()->calculateContourEdge(s, d, getParentEdges().front(), true, false);
206  }
207  if (getParentEdges().back() == segment->getLane()->getParentEdge()) {
208  segment->getContour()->calculateContourEdge(s, d, getParentEdges().back(), false, true);
209  }
210  }
211 }
212 
213 
214 void
215 GNEEdgeRelData::drawJunctionPartialGL(const GUIVisualizationSettings& s, const GNEPathManager::Segment* 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  }
230 }
231 
232 
233 GNELane*
235  /* temporal */
236  return nullptr;
237 }
238 
239 
240 GNELane*
242  /* temporal */
243  return nullptr;
244 }
245 
246 
247 Position
249  return getParentEdges().front()->getPositionInView();
250 }
251 
252 
253 void
255  // open device
256  device.openTag(SUMO_TAG_EDGEREL);
257  // write from
258  device.writeAttr(SUMO_ATTR_FROM, getParentEdges().front()->getID());
259  // write to
260  device.writeAttr(SUMO_ATTR_TO, getParentEdges().back()->getID());
261  // iterate over attributes
262  for (const auto& attribute : getParametersMap()) {
263  // write attribute (don't use writeParams)
264  device.writeAttr(attribute.first, attribute.second);
265  }
266  // close device
267  device.closeTag();
268 }
269 
270 
271 bool
273  return true;
274 }
275 
276 
277 std::string
279  return "";
280 }
281 
282 
283 void
285  throw InvalidArgument(getTagStr() + " cannot fix any problem");
286 }
287 
288 
289 Boundary
291  return getParentEdges().front()->getCenteringBoundary();
292 }
293 
294 
295 std::string
297  switch (key) {
298  case SUMO_ATTR_ID:
299  return getPartialID() + getParentEdges().front()->getID();
300  case SUMO_ATTR_FROM:
301  return getParentEdges().front()->getID();
302  case SUMO_ATTR_TO:
303  return getParentEdges().back()->getID();
304  case GNE_ATTR_DATASET:
306  case SUMO_ATTR_BEGIN:
308  case SUMO_ATTR_END:
310  case GNE_ATTR_SELECTED:
312  case GNE_ATTR_PARAMETERS:
313  return getParametersStr();
314  default:
315  throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
316  }
317 }
318 
319 
320 double
322  throw InvalidArgument(getTagStr() + " doesn't have a double attribute of type '" + toString(key) + "'");
323 }
324 
325 
326 void
327 GNEEdgeRelData::setAttribute(SumoXMLAttr key, const std::string& value, GNEUndoList* undoList) {
328  if (value == getAttribute(key)) {
329  return; //avoid needless changes, later logic relies on the fact that attributes have changed
330  }
331  switch (key) {
332  case SUMO_ATTR_FROM:
333  case SUMO_ATTR_TO:
334  case GNE_ATTR_SELECTED:
335  case GNE_ATTR_PARAMETERS:
336  GNEChange_Attribute::changeAttribute(this, key, value, undoList);
337  break;
338  default:
339  throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
340  }
341 }
342 
343 
344 bool
345 GNEEdgeRelData::isValid(SumoXMLAttr key, const std::string& value) {
346  switch (key) {
347  case SUMO_ATTR_FROM:
348  return SUMOXMLDefinitions::isValidNetID(value) && (myNet->getAttributeCarriers()->retrieveEdge(value, false) != nullptr) &&
349  (value != getParentEdges().back()->getID());
350  case SUMO_ATTR_TO:
351  return SUMOXMLDefinitions::isValidNetID(value) && (myNet->getAttributeCarriers()->retrieveEdge(value, false) != nullptr) &&
352  (value != getParentEdges().front()->getID());
353  case GNE_ATTR_SELECTED:
354  return canParse<bool>(value);
355  case GNE_ATTR_PARAMETERS:
356  return Parameterised::areAttributesValid(value, true);
357  default:
358  throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
359  }
360 }
361 
362 
364  switch (key) {
365  case SUMO_ATTR_ID:
366  return false;
367  default:
368  return true;
369  }
370 }
371 
372 
373 std::string
375  return getTagStr();
376 }
377 
378 
379 std::string
381  return getTagStr() + ": " + getParentEdges().front()->getID() + "->" + getParentEdges().back()->getID();
382 }
383 
384 
385 void
386 GNEEdgeRelData::setAttribute(SumoXMLAttr key, const std::string& value) {
387  switch (key) {
388  case SUMO_ATTR_FROM: {
389  // change first edge
390  replaceFirstParentEdge(value);
391  break;
392  }
393  case SUMO_ATTR_TO: {
394  // change last edge
395  replaceLastParentEdge(value);
396  break;
397  }
398  case GNE_ATTR_SELECTED:
399  if (parse<bool>(value)) {
401  } else {
403  }
404  break;
405  case GNE_ATTR_PARAMETERS:
406  setParametersStr(value);
407  // update attribute colors
409  break;
410  default:
411  throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
412  }
413  // mark interval toolbar for update
415 }
416 
417 /****************************************************************************/
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
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.
@ 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_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:655
static void popMatrix()
pop matrix
Definition: GLHelper.cpp:130
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:347
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
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 calculateContourEdges(const GUIVisualizationSettings &s, const GUIVisualizationSettings::Detail d, const GNEEdge *fromEdge, const GNEEdge *toEdge) const
calculate contour between two consecutive edges
Definition: GNEContour.cpp:142
void calculateContourEdge(const GUIVisualizationSettings &s, const GUIVisualizationSettings::Detail d, const GNEEdge *edge, const bool closeFirstExtrem, const bool closeLastExtrem) const
calculate contour edge
Definition: GNEContour.cpp:129
void drawDottedContours(const GUIVisualizationSettings &s, const GUIVisualizationSettings::Detail d, const GNEAttributeCarrier *AC, const double lineWidth, const bool addOffset) const
drawing contour functions
Definition: GNEContour.cpp:263
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
Definition: GNEDataSet.cpp:143
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:1047
void drawJunctionPartialGL(const GUIVisualizationSettings &s, const GNEPathManager::Segment *segment, const double offsetFront) const
Draws partial object over junction.
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
bool isAttributeEnabled(SumoXMLAttr key) const
void drawLanePartialGL(const GUIVisualizationSettings &s, const GNEPathManager::Segment *segment, const double offsetFront) const
Draws partial object over lane.
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
GNENetHelper::AttributeCarriers * getAttributeCarriers() const
get all attribute carriers used in this net
Definition: GNENet.cpp:121
GNEPathManager * getPathManager()
get path manager
Definition: GNENet.cpp:133
GNEViewNet * getViewNet() const
get view net
Definition: GNENet.cpp:2022
const GNELane * getPreviousLane() const
get previous lane
GNEContour * getContour() const
getcontour associated with segment
const GNELane * getNextLane() const
get next lane
const GNELane * getLane() const
get lane associated with this segment
void calculateConsecutivePathEdges(PathElement *pathElement, SUMOVehicleClass vClass, const std::vector< GNEEdge * > edges)
calculate consecutive path edges
SumoXMLTag getTag() const
get Tag vinculated with this attribute Property
const GNEViewNetHelper::EditModes & getEditModes() const
get edit modes
Definition: GNEViewNet.cpp:703
void drawTranslateFrontAttributeCarrier(const GNEAttributeCarrier *AC, double typeOrLayer, const double extraOffset=0)
draw front attributeCarrier
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.
Definition: GUIGlObject.h:156
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
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.
Definition: OutputDevice.h:61
OutputDevice & openTag(const std::string &xmlElement)
Opens an XML tag.
OutputDevice & writeAttr(const SumoXMLAttr attr, const T &val)
writes a named attribute
Definition: OutputDevice.h:254
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
Definition: Parameterised.h:45
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