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 std::map<std::string, std::string>& parameters) :
49  GNEGenericData(SUMO_TAG_MEANDATA_EDGE, GLO_EDGEDATA, dataIntervalParent, parameters,
50 {}, {edgeParent}, {}, {}, {}, {}, {}, {}) {
51 }
52 
53 
55 
56 
57 const RGBColor&
60  // get selected data interval and filtered attribute
62  const std::string filteredAttribute = myNet->getViewNet()->getViewParent()->getEdgeDataFrame()->getAttributeSelector()->getFilteredAttribute();
63  // continue if there is a selected data interval and filtered attribute
64  if (dataInterval && (filteredAttribute.size() > 0)) {
65  if (dataInterval->getSpecificAttributeColors().at(myTagProperty.getTag()).exist(filteredAttribute)) {
66  // obtain minimum and maximum value
67  const double minValue = dataInterval->getSpecificAttributeColors().at(myTagProperty.getTag()).getMinValue(filteredAttribute);
68  const double maxValue = dataInterval->getSpecificAttributeColors().at(myTagProperty.getTag()).getMaxValue(filteredAttribute);
69  // get value
70  const double value = parse<double>(getParameter(filteredAttribute, "0"));
71  // return color
72  return GNEViewNetHelper::getRainbowScaledColor(minValue, maxValue, value);
73  }
74  }
75  }
76  // return default color
77  return RGBColor::RED;
78 }
79 
80 
81 bool
83  // get current data edit mode
85  // check if we have to filter generic data
86  if ((dataMode == DataEditMode::DATA_INSPECT) || (dataMode == DataEditMode::DATA_DELETE) || (dataMode == DataEditMode::DATA_SELECT)) {
88  } else if (myDataIntervalParent->getNet()->getViewNet()->getViewParent()->getEdgeDataFrame()->shown()) {
89  // get selected data interval and filtered attribute
91  const std::string filteredAttribute = myNet->getViewNet()->getViewParent()->getEdgeDataFrame()->getAttributeSelector()->getFilteredAttribute();
92  // check interval
93  if ((dataInterval != nullptr) && (dataInterval != myDataIntervalParent)) {
94  return false;
95  }
96  // check attribute
97  if ((filteredAttribute.size() > 0) && (getParametersMap().count(filteredAttribute) == 0)) {
98  return false;
99  }
100  // all checks ok, then return true
101  return true;
102  } else {
103  // GNEEdgeDataFrame hidden, then return false
104  return false;
105  }
106 }
107 
108 
109 void
111  // calculate path
113 }
114 
115 
116 Position
118  return getParentEdges().front()->getPositionInView();
119 }
120 
121 
122 void
124  // open device (don't use SUMO_TAG_MEANDATA_EDGE)
125  device.openTag(SUMO_TAG_EDGE);
126  // write edge ID
127  device.writeAttr(SUMO_ATTR_ID, getParentEdges().front()->getID());
128  // iterate over attributes
129  for (const auto& attribute : getParametersMap()) {
130  // write attribute (don't use writeParams)
131  device.writeAttr(attribute.first, attribute.second);
132  }
133  // close device
134  device.closeTag();
135 }
136 
137 
138 bool
140  return true;
141 }
142 
143 
144 std::string
146  return "";
147 }
148 
149 
150 void
152  throw InvalidArgument(getTagStr() + " cannot fix any problem");
153 }
154 
155 
156 void
158  // Nothing to draw
159 }
160 
161 
162 double
164  return 1;
165 }
166 
167 
168 void
170  // nothing to compute
171 }
172 
173 
174 void
175 GNEEdgeData::drawPartialGL(const GUIVisualizationSettings& s, const GNELane* lane, const GNEPathManager::Segment* /*segment*/, const double offsetFront) const {
177  // get flag for only draw contour
178  const bool onlyDrawContour = !isGenericDataVisible();
179  // get lane width
180  const double laneWidth = s.addSize.getExaggeration(s, lane) * (lane->getParentEdge()->getNBEdge()->getLaneWidth(lane->getIndex()) * 0.5);
181  // Start drawing adding an gl identificator
182  if (!onlyDrawContour) {
184  }
185  // Add a draw matrix
187  // Start with the drawing of the area traslating matrix to origin
189  // Set orange color
191  // draw box lines
192  GUIGeometry::drawLaneGeometry(s, myNet->getViewNet()->getPositionInformation(), lane->getLaneShape(), lane->getShapeRotations(), lane->getShapeLengths(), {}, laneWidth, onlyDrawContour);
193  // translate to top
194  glTranslated(0, 0, 0.01);
195  // Set color
198  } else {
200  }
201  // draw interne box lines
202  GUIGeometry::drawLaneGeometry(s, myNet->getViewNet()->getPositionInformation(), lane->getLaneShape(), lane->getShapeRotations(), lane->getShapeLengths(), {}, laneWidth - 0.1, onlyDrawContour);
203  // Pop last matrix
205  // Pop name
206  if (!onlyDrawContour) {
208  }
209  // draw lock icon
211  // draw filtered attribute
212  if (getParentEdges().front()->getLanes().front() == lane) {
214  }
215  // check if shape dotted contour has to be drawn
218  }
219  }
220 }
221 
222 
223 void
224 GNEEdgeData::drawPartialGL(const GUIVisualizationSettings& /*s*/, const GNELane* /*fromLane*/, const GNELane* /*toLane*/, const GNEPathManager::Segment* /*segment*/, const double /*offsetFront*/) const {
225  // EdgeDatas don't use drawPartialGL over junction
226 }
227 
228 
229 GNELane*
231  /* temporal */
232  return nullptr;
233 }
234 
235 
236 GNELane*
238  /* temporal */
239  return nullptr;
240 }
241 
242 
243 Boundary
245  return getParentEdges().front()->getCenteringBoundary();
246 }
247 
248 
249 std::string
251  switch (key) {
252  case SUMO_ATTR_ID:
253  return getParentEdges().front()->getID();
254  case GNE_ATTR_DATASET:
256  case GNE_ATTR_SELECTED:
258  case GNE_ATTR_PARAMETERS:
259  return getParametersStr();
260  default:
261  throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
262  }
263 }
264 
265 
266 double
268  throw InvalidArgument(getTagStr() + " doesn't have a double attribute of type '" + toString(key) + "'");
269 }
270 
271 
272 void
273 GNEEdgeData::setAttribute(SumoXMLAttr key, const std::string& value, GNEUndoList* undoList) {
274  if (value == getAttribute(key)) {
275  return; //avoid needless changes, later logic relies on the fact that attributes have changed
276  }
277  switch (key) {
278  case GNE_ATTR_SELECTED:
279  case GNE_ATTR_PARAMETERS:
280  undoList->changeAttribute(new GNEChange_Attribute(this, key, value));
281  break;
282  default:
283  throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
284  }
285 }
286 
287 
288 bool
289 GNEEdgeData::isValid(SumoXMLAttr key, const std::string& value) {
290  switch (key) {
291  case GNE_ATTR_SELECTED:
292  return canParse<bool>(value);
293  case GNE_ATTR_PARAMETERS:
294  return Parameterised::areParametersValid(value);
295  default:
296  throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
297  }
298 }
299 
300 
301 void
303  // Nothing to enable
304 }
305 
306 
307 void
309  // Nothing to disable enable
310 }
311 
312 
314  switch (key) {
315  case SUMO_ATTR_ID:
316  return false;
317  default:
318  return true;
319  }
320 }
321 
322 
323 std::string
325  return getTagStr();
326 }
327 
328 
329 std::string
331  return getTagStr() + ": " + getParentEdges().front()->getID();
332 }
333 
334 
335 void
336 GNEEdgeData::setAttribute(SumoXMLAttr key, const std::string& value) {
337  switch (key) {
338  case GNE_ATTR_SELECTED:
339  if (parse<bool>(value)) {
341  } else {
343  }
344  break;
345  case GNE_ATTR_PARAMETERS:
346  setParametersStr(value);
347  // update attribute colors
349  break;
350  default:
351  throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
352  }
353 }
354 
355 
356 void
357 GNEEdgeData::toogleAttribute(SumoXMLAttr /*key*/, const bool /*value*/, const int /*previousParameters*/) {
358  throw InvalidArgument("Nothing to enable");
359 }
360 
361 /****************************************************************************/
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
@ 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:507
static void pushName(unsigned int name)
push Name
Definition: GLHelper.cpp:132
static void popMatrix()
pop matrix
Definition: GLHelper.cpp:123
static void popName()
pop Name
Definition: GLHelper.cpp:141
static void pushMatrix()
push matrix
Definition: GLHelper.cpp:114
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 belongs to GNENet but has influency in the simulation.
GNEDataSet * getDataSetParent() const
Returns a pointer to GNEDataSet parent.
const std::map< SumoXMLTag, GNEDataSet::AttributeColors > & getSpecificAttributeColors() const
specific attribute colors
const std::string & getID() const
get ID
Definition: GNEDataSet.cpp:131
void updateAttributeColors()
update attribute colors deprecated
Definition: GNEDataSet.cpp:143
bool isGenericDataVisible() const
check if current edge data is visible
Definition: GNEEdgeData.cpp:82
std::string getAttribute(SumoXMLAttr key) const
void writeGenericData(OutputDevice &device) const
writte 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
void enableAttribute(SumoXMLAttr key, GNEUndoList *undoList)
bool isAttributeEnabled(SumoXMLAttr key) const
std::string getHierarchyName() const
get Hierarchy Name (Used in AC Hierarchy)
void disableAttribute(SumoXMLAttr key, GNEUndoList *undoList)
void toogleAttribute(SumoXMLAttr key, const bool value, const int previousParameters)
method for enable or disable the attribute and nothing else (used in GNEChange_EnableAttribute)
double getAttributeDouble(SumoXMLAttr key) const
std::string getPopUpID() const
get PopPup ID (Used in AC Hierarchy)
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...
const RGBColor & getColor() const
get edge data color
Definition: GNEEdgeData.cpp:58
void updateGeometry()
update pre-computed geometry information
void drawGL(const GUIVisualizationSettings &s) const
Draws the object.
GNEEdgeData(GNEDataInterval *dataIntervalParent, GNEEdge *edgeParent, const std::map< std::string, std::string > &parameters)
Constructor.
Definition: GNEEdgeData.cpp:48
bool isGenericDataValid() const
check if current data set is valid to be writed into XML (by default true, can be reimplemented in ch...
double getExaggeration(const GUIVisualizationSettings &s) const
return exaggeration asociated with this GLObject
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
NBEdge * getNBEdge() const
returns the internal NBEdge
Definition: GNEEdge.cpp:435
static void drawDottedContourEdge(const GUIDottedGeometry::DottedContourType type, const GUIVisualizationSettings &s, const GNEEdge *edge, const bool drawFrontExtreme, const bool drawBackExtreme)
draw dotted contour for the given dottedGeometries
Definition: GNEEdge.cpp:1379
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 belongs to GNENet but has influency in the simulation.
void drawFilteredAttribute(const GUIVisualizationSettings &s, const PositionVector &laneShape, const std::string &attribute) const
draw filtered attribute
GNEDataInterval * myDataIntervalParent
dataInterval Parent
bool isVisibleInspectDeleteSelect() const
check if attribute is visible in inspect, delete or select mode
const std::string & getID() const
get ID
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
const PositionVector & getLaneShape() const
get elements shape
Definition: GNELane.cpp:131
int getIndex() const
returns the index of the lane
Definition: GNELane.cpp:797
const std::vector< double > & getShapeRotations() const
get rotations of the single shape parts
Definition: GNELane.cpp:141
const std::vector< double > & getShapeLengths() const
get lengths of the single shape parts
Definition: GNELane.cpp:147
GNEEdge * getParentEdge() const
get arent edge
Definition: GNELane.cpp:113
GNEPathManager * getPathManager()
get path manager
Definition: GNENet.cpp:131
GNEViewNet * getViewNet() const
get view net
Definition: GNENet.cpp:1964
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 GNEViewNetHelper::EditModes & getEditModes() const
get edit modes
Definition: GNEViewNet.cpp:513
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)
draw lane geometry (use their own function due colors)
GUIGlObjectType getType() const
Returns the type of the object as coded in GUIGlObjectType.
GUIGlID getGlID() const
Returns the numerical id of the object.
Position getPositionInformation() const
Returns the cursor's x/y position within the network.
Stores the information about how to visualize structures.
GUIVisualizationSizeSettings addSize
GUIVisualizationColorSettings colorSettings
color settings
double getLaneWidth() const
Returns the default width of lanes of this edge.
Definition: NBEdge.h:630
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:248
bool closeTag(const std::string &comment="")
Closes the most recently opened tag and optionally adds a comment.
static bool areParametersValid(const std::string &value, bool report=false, const std::string kvsep="=", const std::string sep="|")
check if given string can be parsed to a parameters map "key1=value1|key2=value2|....
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.
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".
const std::map< std::string, std::string > & 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:193
static const RGBColor RED
named colors
Definition: RGBColor.h:185
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