Eclipse SUMO - Simulation of Urban MObility
GNEEdgeData.cpp
Go to the documentation of this file.
1 /****************************************************************************/
2 // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.org/sumo
3 // Copyright (C) 2001-2022 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 
22 // ===========================================================================
23 // included modules
24 // ===========================================================================
25 #include <config.h>
26 
27 #include <netedit/GNEUndoList.h>
28 #include <netedit/GNENet.h>
29 #include <netedit/GNEViewNet.h>
30 #include <netedit/GNEViewParent.h>
33 #include <utils/gui/div/GLHelper.h>
35 
36 #include "GNEEdgeData.h"
37 #include "GNEDataInterval.h"
38 
39 
40 // ===========================================================================
41 // member method definitions
42 // ===========================================================================
43 
44 // ---------------------------------------------------------------------------
45 // GNEEdgeData - methods
46 // ---------------------------------------------------------------------------
47 
48 GNEEdgeData::GNEEdgeData(GNEDataInterval* dataIntervalParent, GNEEdge* edgeParent, const Parameterised::Map& parameters) :
49  GNEGenericData(SUMO_TAG_MEANDATA_EDGE, GUIIconSubSys::getIcon(GUIIcon::EDGEDATA), GLO_EDGEDATA, dataIntervalParent, parameters,
50 {}, {edgeParent}, {}, {}, {}, {}) {
51 }
52 
53 
55 
56 
57 void
59  // set default color
60  RGBColor col = RGBColor::RED;
64  // user defined rainbow
65  const double val = getColorValue(s, s.dataColorer.getActive());
66  col = s.dataColorer.getScheme().getColor(val);
68  // get selected data interval and filtered attribute
70  const std::string filteredAttribute = myNet->getViewNet()->getViewParent()->getEdgeDataFrame()->getAttributeSelector()->getFilteredAttribute();
71  // continue if there is a selected data interval and filtered attribute
72  if (dataInterval && (filteredAttribute.size() > 0)) {
73  if (dataInterval->getSpecificAttributeColors().at(myTagProperty.getTag()).exist(filteredAttribute)) {
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  // return color
80  col = GNEViewNetHelper::getRainbowScaledColor(minValue, maxValue, value);
81  }
82  }
83  }
84  GLHelper::setColor(col);
85 }
86 
87 
88 double
89 GNEEdgeData::getColorValue(const GUIVisualizationSettings& s, int activeScheme) const {
90  switch (activeScheme) {
91  case 0:
92  return 0;
93  case 1:
95  case 2:
96  return 0; // setfunctional color const GNEAdditional* TAZA = getParentAdditionals().front();
97  case 3:
98  return 0; // setfunctional color const GNEAdditional* TAZA = getParentAdditionals().back();
99  case 4:
100  // by numerical attribute value
101  try {
102  if (knowsParameter(s.relDataAttr)) {
104  } else {
106  }
107  } catch (NumberFormatException&) {
109  }
110  }
111  return 0;
112 }
113 
114 
115 bool
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 (myDataIntervalParent->getNet()->getViewNet()->getViewParent()->getEdgeDataFrame()->shown()) {
123  // get selected data interval and filtered attribute
125  const std::string filteredAttribute = myNet->getViewNet()->getViewParent()->getEdgeDataFrame()->getAttributeSelector()->getFilteredAttribute();
126  // check interval
127  if ((dataInterval != nullptr) && (dataInterval != myDataIntervalParent)) {
128  return false;
129  }
130  // check attribute
131  if ((filteredAttribute.size() > 0) && (getParametersMap().count(filteredAttribute) == 0)) {
132  return false;
133  }
134  // all checks ok, then return true
135  return true;
136  } else {
137  // GNEEdgeDataFrame hidden, then return false
138  return false;
139  }
140 }
141 
142 
143 void
145  // calculate path
147 }
148 
149 
150 Position
152  return getParentEdges().front()->getPositionInView();
153 }
154 
155 
156 void
158  // open device (don't use SUMO_TAG_MEANDATA_EDGE)
159  device.openTag(SUMO_TAG_EDGE);
160  // write edge ID
161  device.writeAttr(SUMO_ATTR_ID, getParentEdges().front()->getID());
162  // iterate over attributes
163  for (const auto& attribute : getParametersMap()) {
164  // write attribute (don't use writeParams)
165  device.writeAttr(attribute.first, attribute.second);
166  }
167  // close device
168  device.closeTag();
169 }
170 
171 
172 bool
174  return true;
175 }
176 
177 
178 std::string
180  return "";
181 }
182 
183 
184 void
186  throw InvalidArgument(getTagStr() + " cannot fix any problem");
187 }
188 
189 
190 void
192  // Nothing to draw
193 }
194 
195 
196 double
198  return 1;
199 }
200 
201 
202 void
204  // nothing to compute
205 }
206 
207 
208 void
209 GNEEdgeData::drawPartialGL(const GUIVisualizationSettings& s, const GNELane* lane, const GNEPathManager::Segment* /*segment*/, const double offsetFront) const {
211  // get flag for only draw contour
212  const bool onlyDrawContour = !isGenericDataVisible();
213  // Start drawing adding an gl identificator
214  if (!onlyDrawContour) {
216  }
217  // draw over all edge's lanes
218  for (const auto& laneEdge : lane->getParentEdge()->getLanes()) {
219  // get lane width
220  const double laneWidth = s.addSize.getExaggeration(s, laneEdge) * s.edgeRelWidthExaggeration *
221  (laneEdge->getParentEdge()->getNBEdge()->getLaneWidth(laneEdge->getIndex()) * 0.5);
222  // Add a draw matrix
224  // Start with the drawing of the area translating matrix to origin
227  // draw box lines
229  laneEdge->getLaneShape(), laneEdge->getShapeRotations(),
230  laneEdge->getShapeLengths(), {}, laneWidth, onlyDrawContour);
231  // translate to top
232  glTranslated(0, 0, 0.01);
233  setColor(s);
234  // draw interne box lines
236  laneEdge->getLaneShape(), laneEdge->getShapeRotations(),
237  laneEdge->getShapeLengths(), {}, (laneWidth - 0.1), onlyDrawContour);
238  // Pop last matrix
240  // draw lock icon
242  // check if mouse is over element
243  for (const auto& laneEdgeParent : laneEdge->getParentEdge()->getLanes()) {
244  // get lane drawing constants
245  GNELane::LaneDrawingConstants laneDrawingConstants(s, laneEdgeParent);
246  mouseWithinGeometry(laneEdgeParent->getLaneShape(), laneDrawingConstants.halfWidth * s.edgeRelWidthExaggeration);
247  }
248  // draw filtered attribute
249  if (getParentEdges().front()->getLanes().front() == laneEdge) {
250  drawFilteredAttribute(s, laneEdge->getLaneShape(),
253  }
254  // inspect contour
257  laneEdge->getParentEdge(), true, true, s.edgeRelWidthExaggeration);
258  }
259  // front contour
260  if (myNet->getViewNet()->getFrontAttributeCarrier() == this) {
262  laneEdge->getParentEdge(), true, true, s.edgeRelWidthExaggeration);
263  }
264  // delete contour
265  if (myNet->getViewNet()->drawDeleteContour(this, this)) {
267  laneEdge->getParentEdge(), true, true, s.edgeRelWidthExaggeration);
268  }
269  // select contour
270  if (myNet->getViewNet()->drawSelectContour(this, this)) {
272  laneEdge->getParentEdge(), true, true, s.edgeRelWidthExaggeration);
273  }
274  }
275  // Pop name
276  if (!onlyDrawContour) {
278  }
279  }
280 }
281 
282 
283 void
284 GNEEdgeData::drawPartialGL(const GUIVisualizationSettings& /*s*/, const GNELane* /*fromLane*/, const GNELane* /*toLane*/, const GNEPathManager::Segment* /*segment*/, const double /*offsetFront*/) const {
285  // EdgeDatas don't use drawPartialGL over junction
286 }
287 
288 
289 GNELane*
291  /* temporal */
292  return nullptr;
293 }
294 
295 
296 GNELane*
298  /* temporal */
299  return nullptr;
300 }
301 
302 
303 Boundary
305  return getParentEdges().front()->getCenteringBoundary();
306 }
307 
308 
309 std::string
311  switch (key) {
312  case SUMO_ATTR_ID:
313  return getPartialID() + getParentEdges().front()->getID();
314  case GNE_ATTR_DATASET:
316  case GNE_ATTR_SELECTED:
318  case GNE_ATTR_PARAMETERS:
319  return getParametersStr();
320  default:
321  throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
322  }
323 }
324 
325 
326 double
328  throw InvalidArgument(getTagStr() + " doesn't have a double attribute of type '" + toString(key) + "'");
329 }
330 
331 
332 void
333 GNEEdgeData::setAttribute(SumoXMLAttr key, const std::string& value, GNEUndoList* undoList) {
334  if (value == getAttribute(key)) {
335  return; //avoid needless changes, later logic relies on the fact that attributes have changed
336  }
337  switch (key) {
338  case GNE_ATTR_SELECTED:
339  case GNE_ATTR_PARAMETERS:
340  undoList->changeAttribute(new GNEChange_Attribute(this, key, value));
341  break;
342  default:
343  throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
344  }
345 }
346 
347 
348 bool
349 GNEEdgeData::isValid(SumoXMLAttr key, const std::string& value) {
350  switch (key) {
351  case GNE_ATTR_SELECTED:
352  return canParse<bool>(value);
353  case GNE_ATTR_PARAMETERS:
354  return Parameterised::areAttributesValid(value, true);
355  default:
356  throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
357  }
358 }
359 
360 
362  switch (key) {
363  case SUMO_ATTR_ID:
364  return false;
365  default:
366  return true;
367  }
368 }
369 
370 
371 std::string
373  return getTagStr();
374 }
375 
376 
377 std::string
379  return getTagStr() + ": " + getParentEdges().front()->getID();
380 }
381 
382 
383 void
384 GNEEdgeData::setAttribute(SumoXMLAttr key, const std::string& value) {
385  switch (key) {
386  case GNE_ATTR_SELECTED:
387  if (parse<bool>(value)) {
389  } else {
391  }
392  break;
393  case GNE_ATTR_PARAMETERS:
394  setParametersStr(value);
395  // update attribute colors
397  break;
398  default:
399  throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
400  }
401 }
402 
403 /****************************************************************************/
DataEditMode
@brie 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
@ SUMO_TAG_MEANDATA_EDGE
an edge based mean data detector
@ SUMO_TAG_EDGE
begin/end of the description of an edge
SumoXMLAttr
Numbers representing SUMO-XML - attributes.
@ GNE_ATTR_SELECTED
element is selected
@ GNE_ATTR_PARAMETERS
parameters "key1=value1|key2=value2|...|keyN=valueN"
@ 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:583
static void pushName(unsigned int name)
push Name
Definition: GLHelper.cpp:139
static void popMatrix()
pop matrix
Definition: GLHelper.cpp:130
static void popName()
pop Name
Definition: GLHelper.cpp:148
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
friend class GNEChange_Attribute
declare friend class
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
An Element which don't belong to GNENet but has influence in the simulation.
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:137
bool isGenericDataVisible() const
check if current edge data is visible
GNEEdgeData(GNEDataInterval *dataIntervalParent, GNEEdge *edgeParent, const Parameterised::Map &parameters)
Constructor.
Definition: GNEEdgeData.cpp:48
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
Definition: GNEEdgeData.cpp:89
void drawPartialGL(const GUIVisualizationSettings &s, const GNELane *lane, const GNEPathManager::Segment *segment, const double offsetFront) const
Draws partial object (lane)
Boundary getCenteringBoundary() const
~GNEEdgeData()
Destructor.
Definition: GNEEdgeData.cpp:54
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...
double getExaggeration(const GUIVisualizationSettings &s) const
return exaggeration associated with this GLObject
void fixGenericDataProblem()
fix data set problem (by default throw an exception, has to be reimplemented in children)
void setColor(const GUIVisualizationSettings &s) const
get edge data color
Definition: GNEEdgeData.cpp:58
Position getPositionInView() const
Returns element position in view.
A road/street connecting two junctions (netedit-version)
Definition: GNEEdge.h:53
static void drawDottedContourEdge(const GUIVisualizationSettings &s, const GUIDottedGeometry::DottedContourType type, const GNEEdge *edge, const bool drawFrontExtreme, const bool drawBackExtreme, const double exaggeration=1)
draw dotted contour for the given dottedGeometries
Definition: GNEEdge.cpp:1464
const std::vector< GNELane * > & getLanes() const
returns a reference to the lane vector
Definition: GNEEdge.cpp:839
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
FOX-declaration.
Definition: GNELane.h:52
const double halfWidth
Draw as a normal lane, and reduce width to make sure that a selected edge can still be seen.
Definition: GNELane.h:68
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:124
GNEPathManager * getPathManager()
get path manager
Definition: GNENet.cpp:138
GNEViewNet * getViewNet() const
get view net
Definition: GNENet.cpp:1987
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
void changeAttribute(GNEChange_Attribute *change)
special method for change attributes, avoid empty changes, always execute
const GNEAttributeCarrier * getFrontAttributeCarrier() const
get front attributeCarrier
const GNEViewNetHelper::EditModes & getEditModes() const
get edit modes
Definition: GNEViewNet.cpp:632
bool drawSelectContour(const GUIGlObject *GLObject, const GNEAttributeCarrier *AC) const
check if draw select contour
bool drawDeleteContour(const GUIGlObject *GLObject, const GNEAttributeCarrier *AC) const
check if draw delete contour
void drawTranslateFrontAttributeCarrier(const GNEAttributeCarrier *AC, double typeOrLayer, const double extraOffset=0)
draw front attributeCarrier
GNEViewParent * getViewParent() const
get the net object
bool isAttributeCarrierInspected(const GNEAttributeCarrier *AC) const
check if attribute carrier is being inspected
GNEEdgeDataFrame * getEdgeDataFrame() const
get frame for DATA_EDGEDATA
static void drawLaneGeometry(const GUIVisualizationSettings &s, const Position &mousePos, const PositionVector &shape, const std::vector< double > &rotations, const std::vector< double > &lengths, const std::vector< RGBColor > &colors, double width, const bool onlyContour=false, const double offset=0)
draw lane geometry (use their own function due colors)
void mouseWithinGeometry(const Position center, const double radius) const
check if mouse is within elements geometry (for circles)
GUIGlObjectType getType() const
Returns the type of the object as coded in GUIGlObjectType.
Definition: GUIGlObject.h:154
GUIGlID getGlID() const
Returns the numerical id of the object.
Definition: GUIGlObject.h:102
const T getColor(const double value) const
const std::string & getName() const
virtual Position getPositionInformation() const
Returns the cursor's x/y position within the network.
Stores the information about how to visualize structures.
static const std::string SCHEME_NAME_DATA_ATTRIBUTE_NUMERICAL
GUIVisualizationSizeSettings addSize
GUIVisualizationColorSettings colorSettings
color settings
double edgeRelWidthExaggeration
The edgeRelation exaggeration (upscale thickness)
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:251
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|....
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".
bool knowsParameter(const std::string &key) const
Returns whether the parameter is known.
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 GNEAttributeCarrier *AC, GUIGlObjectType type, const Position viewPosition, 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
double getExaggeration(const GUIVisualizationSettings &s, const GUIGlObject *o, double factor=20) const
return the drawing size including exaggeration and constantSize values