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-2020 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  // obtain minimum and maximum value
66  const double minValue = dataInterval->getSpecificAttributeColors().at(myTagProperty.getTag()).getMinValue(filteredAttribute);
67  const double maxValue = dataInterval->getSpecificAttributeColors().at(myTagProperty.getTag()).getMaxValue(filteredAttribute);
68  // get value
69  const double value = parse<double>(getParameter(filteredAttribute, "0"));
70  // return color
71  return GNEViewNetHelper::getRainbowScaledColor(minValue, maxValue, value);
72  }
73  }
74  // return default color
75  return RGBColor::RED;
76 }
77 
78 
79 bool
81  // first check if we're in supermode data
83  return false;
84  }
85  // get current data edit mode
87  // check if we have to filter generic data
88  if ((dataMode == DataEditMode::DATA_INSPECT) || (dataMode == DataEditMode::DATA_DELETE) || (dataMode == DataEditMode::DATA_SELECT)) {
90  } else if (myDataIntervalParent->getNet()->getViewNet()->getViewParent()->getEdgeDataFrame()->shown()) {
91  // get selected data interval and filtered attribute
93  const std::string filteredAttribute = myNet->getViewNet()->getViewParent()->getEdgeDataFrame()->getAttributeSelector()->getFilteredAttribute();
94  // check interval
95  if ((dataInterval != nullptr) && (dataInterval != myDataIntervalParent)) {
96  return false;
97  }
98  // check attribute
99  if ((filteredAttribute.size() > 0) && (getParametersMap().count(filteredAttribute) == 0)) {
100  return false;
101  }
102  // all checks ok, then return true
103  return true;
104  } else {
105  // GNEEdgeDataFrame hidden, then return false
106  return false;
107  }
108 }
109 
110 
111 void
113  // calculate generic data path
115 }
116 
117 
118 Position
120  return getParentEdges().front()->getPositionInView();
121 }
122 
123 
124 void
126  // open device (don't use SUMO_TAG_MEANDATA_EDGE)
127  device.openTag(SUMO_TAG_EDGE);
128  // write edge ID
129  device.writeAttr(SUMO_ATTR_ID, getParentEdges().front()->getID());
130  // iterate over attributes
131  for (const auto& attribute : getParametersMap()) {
132  // write attribute (don't use writeParams)
133  device.writeAttr(attribute.first, attribute.second);
134  }
135  // close device
136  device.closeTag();
137 }
138 
139 
140 bool
142  return true;
143 }
144 
145 
146 std::string
148  return "";
149 }
150 
151 
152 void
154  throw InvalidArgument(getTagStr() + " cannot fix any problem");
155 }
156 
157 
158 void
160  // Nothing to draw
161 }
162 
163 
164 void
165 GNEEdgeData::drawPartialGL(const GUIVisualizationSettings& s, const GNELane* lane, const double offsetFront) const {
166  // get lane width
167  const double laneWidth = s.addSize.getExaggeration(s, lane) * (lane->getParentEdge()->getNBEdge()->getLaneWidth(lane->getIndex()) * 0.5);
168  // Start drawing adding an gl identificator
169  glPushName(getGlID());
170  // Add a draw matrix
171  glPushMatrix();
172  // Start with the drawing of the area traslating matrix to origin
174  // Set orange color
176  // draw box lines
177  GNEGeometry::drawLaneGeometry(myNet->getViewNet(), lane->getLaneShape(), lane->getShapeRotations(), lane->getShapeLengths(), {}, laneWidth);
178  // translate to top
179  glTranslated(0, 0, 0.01);
180  // Set color
183  } else {
185  }
186  // draw interne box lines
187  GNEGeometry::drawLaneGeometry(myNet->getViewNet(), lane->getLaneShape(), lane->getShapeRotations(), lane->getShapeLengths(), {}, laneWidth - 0.1);
188  // Pop last matrix
189  glPopMatrix();
190  // Pop name
191  glPopName();
192  // draw filtered attribute
193  if (getParentEdges().front()->getLanes().front() == lane) {
195  }
196  // check if shape dotted contour has to be drawn
199  }
200 }
201 
202 
203 void
204 GNEEdgeData::drawPartialGL(const GUIVisualizationSettings& /*s*/, const GNELane* /*fromLane*/, const GNELane* /*toLane*/, const double /*offsetFront*/) const {
205  // EdgeDatas don't use drawPartialGL over junction
206 }
207 
208 
209 Boundary
211  return getParentEdges().front()->getCenteringBoundary();
212 }
213 
214 
215 std::string
217  switch (key) {
218  case SUMO_ATTR_ID:
219  return getParentEdges().front()->getID();
220  case GNE_ATTR_DATASET:
222  case GNE_ATTR_SELECTED:
224  case GNE_ATTR_PARAMETERS:
225  return getParametersStr();
226  default:
227  throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
228  }
229 }
230 
231 
232 double
234  throw InvalidArgument(getTagStr() + " doesn't have a double attribute of type '" + toString(key) + "'");
235 }
236 
237 
238 void
239 GNEEdgeData::setAttribute(SumoXMLAttr key, const std::string& value, GNEUndoList* undoList) {
240  if (value == getAttribute(key)) {
241  return; //avoid needless changes, later logic relies on the fact that attributes have changed
242  }
243  switch (key) {
244  case GNE_ATTR_SELECTED:
245  case GNE_ATTR_PARAMETERS:
246  undoList->p_add(new GNEChange_Attribute(this, key, value));
247  break;
248  default:
249  throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
250  }
251 }
252 
253 
254 bool
255 GNEEdgeData::isValid(SumoXMLAttr key, const std::string& value) {
256  switch (key) {
257  case GNE_ATTR_SELECTED:
258  return canParse<bool>(value);
259  case GNE_ATTR_PARAMETERS:
260  return Parameterised::areParametersValid(value);
261  default:
262  throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
263  }
264 }
265 
266 
267 void
269  // Nothing to enable
270 }
271 
272 
273 void
275  // Nothing to disable enable
276 }
277 
278 
280  switch (key) {
281  case SUMO_ATTR_ID:
282  return false;
283  default:
284  return true;
285  }
286 }
287 
288 
289 std::string
291  return getTagStr();
292 }
293 
294 
295 std::string
297  return getTagStr() + ": " + getParentEdges().front()->getID();
298 }
299 
300 
301 void
302 GNEEdgeData::setAttribute(SumoXMLAttr key, const std::string& value) {
303  switch (key) {
304  case GNE_ATTR_SELECTED:
305  if (parse<bool>(value)) {
307  } else {
309  }
310  break;
311  case GNE_ATTR_PARAMETERS:
312  setParametersStr(value);
313  // update attribute colors
315  break;
316  default:
317  throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
318  }
319 }
320 
321 
322 void
323 GNEEdgeData::setEnabledAttribute(const int /*enabledAttributes*/) {
324  throw InvalidArgument("Nothing to enable");
325 }
326 
327 /****************************************************************************/
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
@ 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:44
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:446
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
the xml tag to which this attribute carrier corresponds
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:119
void updateAttributeColors()
update attribute colors deprecated
Definition: GNEDataSet.cpp:142
bool isGenericDataVisible() const
check if current edge data is visible
Definition: GNEEdgeData.cpp:80
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
void enableAttribute(SumoXMLAttr key, GNEUndoList *undoList)
void setEnabledAttribute(const int enabledAttributes)
method for enabling the attribute and nothing else (used in GNEChange_EnableAttribute)
bool isAttributeEnabled(SumoXMLAttr key) const
std::string getHierarchyName() const
get Hierarchy Name (Used in AC Hierarchy)
void disableAttribute(SumoXMLAttr key, GNEUndoList *undoList)
double getAttributeDouble(SumoXMLAttr key) const
std::string getPopUpID() const
get PopPup ID (Used in AC Hierarchy)
Boundary getCenteringBoundary() const
~GNEEdgeData()
Destructor.
Definition: GNEEdgeData.cpp:54
std::string getGenericDataProblem() const
return a string with the current data set problem (by default empty, can be reimplemented in children...
void drawPartialGL(const GUIVisualizationSettings &s, const GNELane *lane, const double offsetFront) const
Draws partial object (lane)
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...
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:49
NBEdge * getNBEdge() const
returns the internal NBEdge
Definition: GNEEdge.cpp:399
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:45
const PositionVector & getLaneShape() const
Definition: GNELane.cpp:117
int getIndex() const
returns the index of the lane
Definition: GNELane.cpp:733
const std::vector< double > & getShapeRotations() const
get rotations of the single shape parts
Definition: GNELane.cpp:123
const std::vector< double > & getShapeLengths() const
get lengths of the single shape parts
Definition: GNELane.cpp:129
GNEEdge * getParentEdge() const
get arent edge
Definition: GNELane.cpp:111
GNEViewNet * getViewNet() const
get view net
Definition: GNENet.cpp:2245
void calculateGenericDataLanePath(const std::vector< GNEEdge * > &edges)
calculate consecutive path lanes (used by genericdatas)
SumoXMLTag getTag() const
get Tag vinculated with this attribute Property
void p_add(GNEChange_Attribute *cmd)
special method, avoid empty changes, always execute
const GNEViewNetHelper::EditModes & getEditModes() const
get edit modes
Definition: GNEViewNet.cpp:467
GNEViewParent * getViewParent() const
get the net object
bool isAttributeCarrierInspected(const GNEAttributeCarrier *AC) const
check if attribute carrier is being inspected
void drawTranslateFrontAttributeCarrier(const GNEAttributeCarrier *AC, GUIGlObjectType objectType, const double extraOffset=0)
draw front attributeCarrier
GNEEdgeDataFrame * getEdgeDataFrame() const
get frame for DATA_EDGEDATA
GUIGlID getGlID() const
Returns the numerical id of the object.
Stores the information about how to visualize structures.
GUIVisualizationSizeSettings addSize
bool drawDottedContour() const
check if dotted contour can be drawn
GUIVisualizationColorSettings colorSettings
color settings
double getLaneWidth() const
Returns the default width of lanes of this edge.
Definition: NBEdge.h:605
Static storage of an output device and its base (abstract) implementation.
Definition: OutputDevice.h:60
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:239
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, ParameterisedAttrType attrType=ParameterisedAttrType::STRING, 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"
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:36
static const RGBColor BLACK
Definition: RGBColor.h:188
static const RGBColor RED
named colors
Definition: RGBColor.h:180
static void drawDottedContourEdge(const DottedContourType type, const GUIVisualizationSettings &s, const GNEEdge *edge, const bool drawFrontExtreme, const bool drawBackExtreme)
draw dotted contour for the given dottedGeometries (used by edges)
static void drawLaneGeometry(const GNEViewNet *viewNet, const PositionVector &shape, const std::vector< double > &rotations, const std::vector< double > &lengths, const std::vector< RGBColor > &colors, double width)
draw lane geometry (use their own function due colors)
DataEditMode dataEditMode
the current Data edit mode
bool isCurrentSupermodeData() const
@check if current supermode is Data
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