Eclipse SUMO - Simulation of Urban MObility
GNEGenericData.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 // A abstract class for data sets
19 /****************************************************************************/
20 #include <config.h>
21 
22 #include <netedit/GNENet.h>
23 #include <netedit/GNEViewNet.h>
24 #include <netedit/GNEViewParent.h>
27 #include <utils/gui/div/GLHelper.h>
32 
33 #include "GNEGenericData.h"
34 #include "GNEDataInterval.h"
35 
36 
37 // ===========================================================================
38 // member method definitions
39 // ===========================================================================
40 
41 // ---------------------------------------------------------------------------
42 // GNEGenericData - methods
43 // ---------------------------------------------------------------------------
44 
45 GNEGenericData::GNEGenericData(const SumoXMLTag tag, const GUIGlObjectType type, GNEDataInterval* dataIntervalParent,
46  const std::map<std::string, std::string>& parameters,
47  const std::vector<GNEJunction*>& junctionParents,
48  const std::vector<GNEEdge*>& edgeParents,
49  const std::vector<GNELane*>& laneParents,
50  const std::vector<GNEAdditional*>& additionalParents,
51  const std::vector<GNEShape*>& shapeParents,
52  const std::vector<GNETAZElement*>& TAZElementParents,
53  const std::vector<GNEDemandElement*>& demandElementParents,
54  const std::vector<GNEGenericData*>& genericDataParents) :
55  GUIGlObject(type, dataIntervalParent->getID()),
56  Parameterised(ParameterisedAttrType::DOUBLE, parameters),
57  GNEHierarchicalElement(dataIntervalParent->getNet(), tag, junctionParents, edgeParents, laneParents, additionalParents, shapeParents, TAZElementParents, demandElementParents, genericDataParents),
58  GNEPathElements(this),
59  myDataIntervalParent(dataIntervalParent) {
60 }
61 
62 
64 
65 
66 const std::string&
68  return getMicrosimID();
69 }
70 
71 
74  return this;
75 }
76 
77 
80  return myDataIntervalParent;
81 }
82 
83 
84 void
86  if ((myTagProperty.getTag() == SUMO_TAG_MEANDATA_EDGE) && (shape.length() > 0)) {
87  // obtain pointer to edge data frame (only for code legibly)
89  // check if we have to filter generic data
90  if (edgeDataFrame->shown()) {
91  // check attribute
92  if ((edgeDataFrame->getAttributeSelector()->getFilteredAttribute().size() > 0) &&
93  (getParametersMap().count(edgeDataFrame->getAttributeSelector()->getFilteredAttribute()) > 0)) {
94  // get value
95  const std::string value = getParametersMap().at(edgeDataFrame->getAttributeSelector()->getFilteredAttribute());
96  // calculate center position
97  const Position centerPosition = shape.positionAtOffset2D(shape.length2D() / 2);
98  // Add a draw matrix
99  glPushMatrix();
100  GLHelper::drawText(value, centerPosition, GLO_MAX, 2, RGBColor::BLUE);
101  // pop draw matrix
102  glPopMatrix();
103  }
104  }
105  }
106 }
107 
108 
109 bool
111  return true;
112 }
113 
114 
115 std::string
117  return "";
118 }
119 
120 
121 void
123  throw InvalidArgument(getTagStr() + " cannot fix any problem");
124 }
125 
126 
129  GUIGLObjectPopupMenu* ret = new GUIGLObjectPopupMenu(app, parent, *this);
130  // build header
131  buildPopupHeader(ret, app);
132  // build menu command for center button and copy cursor position to clipboard
134  buildPositionCopyEntry(ret, false);
135  // buld menu commands for names
136  GUIDesigns::buildFXMenuCommand(ret, "Copy " + getTagStr() + " name to clipboard", nullptr, ret, MID_COPY_NAME);
137  GUIDesigns::buildFXMenuCommand(ret, "Copy " + getTagStr() + " typed name to clipboard", nullptr, ret, MID_COPY_TYPED_NAME);
138  new FXMenuSeparator(ret);
139  // build selection and show parameters menu
142  // show option to open additional dialog
143  if (myTagProperty.hasDialog()) {
144  GUIDesigns::buildFXMenuCommand(ret, ("Open " + getTagStr() + " Dialog").c_str(), getIcon(), &parent, MID_OPEN_ADDITIONAL_DIALOG);
145  new FXMenuSeparator(ret);
146  } else {
147  GUIDesigns::buildFXMenuCommand(ret, ("Cursor position in view: " + toString(getPositionInView().x()) + "," + toString(getPositionInView().y())).c_str(), nullptr, nullptr, 0);
148  }
149  return ret;
150 }
151 
152 
155  // Create table
156  GUIParameterTableWindow* ret = new GUIParameterTableWindow(app, *this);
157  // Iterate over attributes
158  for (const auto& tagProperty : myTagProperty) {
159  // Add attribute and set it dynamic if aren't unique
160  if (tagProperty.isUnique()) {
161  ret->mkItem(tagProperty.getAttrStr().c_str(), false, getAttribute(tagProperty.getAttr()));
162  } else {
163  ret->mkItem(tagProperty.getAttrStr().c_str(), true, getAttribute(tagProperty.getAttr()));
164  }
165  }
166  // close building
167  ret->closeBuilding();
168  return ret;
169 }
170 
171 
172 const std::map<std::string, std::string>&
174  return getParametersMap();
175 }
176 
177 
178 void
179 GNEGenericData::drawFilteredAttribute(const GUIVisualizationSettings& s, const PositionVector& laneShape, const std::string& attribute) const {
180  if (getParametersMap().count(attribute) > 0) {
181  const Position pos = laneShape.positionAtOffset2D(laneShape.length2D() * 0.5);
182  const double rot = laneShape.rotationDegreeAtOffset(laneShape.length2D() * 0.5);
183  // Add a draw matrix for details
184  glPushMatrix();
185  // draw value
186  GLHelper::drawText(getParameter(attribute), pos, GLO_MAX - 1, 2, RGBColor::BLACK, s.getTextAngle(rot + 90));
187  // pop draw matrix
188  glPopMatrix();
189  }
190 }
191 
192 
193 bool
195  // get toolbar
197  // declare flag
198  bool draw = true;
199  // check filter by generic data type
200  if ((toolBar.getGenericDataTypeStr().size() > 0) && (toolBar.getGenericDataTypeStr() != myTagProperty.getTagStr())) {
201  draw = false;
202  }
203  // check filter by data set
204  if ((toolBar.getDataSetStr().size() > 0) && (toolBar.getDataSetStr() != myDataIntervalParent->getID())) {
205  draw = false;
206  }
207  // check filter by begin
208  if ((toolBar.getBeginStr().size() > 0) && (parse<double>(toolBar.getBeginStr()) > myDataIntervalParent->getAttributeDouble(SUMO_ATTR_BEGIN))) {
209  draw = false;
210  }
211  // check filter by end
212  if ((toolBar.getEndStr().size() > 0) && (parse<double>(toolBar.getEndStr()) < myDataIntervalParent->getAttributeDouble(SUMO_ATTR_END))) {
213  draw = false;
214  }
215  // check filter by attribute
216  if ((toolBar.getAttributeStr().size() > 0) && (getParametersMap().count(toolBar.getAttributeStr()) == 0)) {
217  draw = false;
218  }
219  // return flag
220  return draw;
221 }
222 
223 void
224 GNEGenericData::replaceFirstParentEdge(const std::string& value) {
225  std::vector<GNEEdge*> parentEdges = getParentEdges();
226  parentEdges[0] = myNet->retrieveEdge(value);
227  // replace parent edges
228  replaceParentElements(this, parentEdges);
229 }
230 
231 
232 void
233 GNEGenericData::replaceLastParentEdge(const std::string& value) {
234  std::vector<GNEEdge*> parentEdges = getParentEdges();
235  parentEdges[(int)parentEdges.size() - 1] = myNet->retrieveEdge(value);
236  // replace parent edges
237  replaceParentElements(this, parentEdges);
238 }
239 
240 
241 void
243  std::vector<GNETAZElement*> parentTAZElements = getParentTAZElements();
244  parentTAZElements[0] = myNet->retrieveTAZElement(tag, value);
245  // replace parent TAZElements
246  replaceParentElements(this, parentTAZElements);
247 }
248 
249 
250 void
252  std::vector<GNETAZElement*> parentTAZElements = getParentTAZElements();
253  parentTAZElements[(int)parentTAZElements.size() - 1] = myNet->retrieveTAZElement(tag, value);
254  // replace parent TAZElements
255  replaceParentElements(this, parentTAZElements);
256 }
257 
258 /****************************************************************************/
@ MID_COPY_TYPED_NAME
Copy typed object name - popup entry.
Definition: GUIAppEnum.h:403
@ MID_OPEN_ADDITIONAL_DIALOG
open additional dialog (used in netedit)
Definition: GUIAppEnum.h:411
@ MID_COPY_NAME
Copy object name - popup entry.
Definition: GUIAppEnum.h:401
GUIGlObjectType
@ GLO_MAX
empty max
SumoXMLTag
Numbers representing SUMO-XML - element names.
@ SUMO_TAG_MEANDATA_EDGE
an edge based mean data detector
@ SUMO_ATTR_BEGIN
weights: time range begin
@ SUMO_ATTR_END
weights: time range end
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
Definition: ToString.h:44
static void drawText(const std::string &text, const Position &pos, const double layer, const double size, const RGBColor &col=RGBColor::BLACK, const double angle=0, const int align=0, double width=-1)
Definition: GLHelper.cpp:498
const std::string & getTagStr() const
get tag assigned to this object in string format
FXIcon * getIcon() const
get FXIcon associated to this AC
GNENet * myNet
pointer to net
GNENet * getNet() const
get pointer to net
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.
double getAttributeDouble(SumoXMLAttr key) const
const std::string & getID() const
get ID
std::string getFilteredAttribute() const
get filtered attribute
const AttributeSelector * getAttributeSelector() const
getattribute selector modul
GNEGenericData(const SumoXMLTag tag, const GUIGlObjectType type, GNEDataInterval *dataIntervalParent, const std::map< std::string, std::string > &parameters, const std::vector< GNEJunction * > &junctionParents, const std::vector< GNEEdge * > &edgeParents, const std::vector< GNELane * > &laneParents, const std::vector< GNEAdditional * > &additionalParents, const std::vector< GNEShape * > &shapeParents, const std::vector< GNETAZElement * > &TAZElementParents, const std::vector< GNEDemandElement * > &demandElementParents, const std::vector< GNEGenericData * > &genericDataParents)
Constructor.
GUIGlObject * getGUIGlObject()
get GUIGlObject associated with this AttributeCarrier
virtual void fixGenericDataProblem()
fix data set problem (by default throw an exception, has to be reimplemented in children)
void drawAttribute(const PositionVector &shape) const
void drawFilteredAttribute(const GUIVisualizationSettings &s, const PositionVector &laneShape, const std::string &attribute) const
draw filtered attribute
virtual std::string getGenericDataProblem() const
return a string with the current data set problem (by default empty, can be reimplemented in children...
const std::map< std::string, std::string > & getACParametersMap() const
get parameters map
virtual ~GNEGenericData()
Destructor.
GUIParameterTableWindow * getParameterWindow(GUIMainWindow &app, GUISUMOAbstractView &parent)
Returns an own parameter window.
virtual Position getPositionInView() const =0
Returns element position in view.
void replaceFirstParentTAZElement(SumoXMLTag tag, const std::string &value)
replace the first parent TAZElement
virtual std::string getAttribute(SumoXMLAttr key) const =0
GNEDataInterval * myDataIntervalParent
dataInterval Parent
void replaceLastParentTAZElement(SumoXMLTag tag, const std::string &value)
replace the last parent TAZElement
virtual bool isGenericDataValid() const
check if current data set is valid to be writed into XML (by default true, can be reimplemented in ch...
bool isVisibleInspectDeleteSelect() const
check if attribute is visible in inspect, delete or select mode
GNEDataInterval * getDataIntervalParent() const
get data interval parent
const std::string & getID() const
get ID
void replaceFirstParentEdge(const std::string &value)
replace the first parent edge
GUIGLObjectPopupMenu * getPopUpMenu(GUIMainWindow &app, GUISUMOAbstractView &parent)
Returns an own popup-menu.
void replaceLastParentEdge(const std::string &value)
replace the last parent edge
const std::vector< GNEEdge * > & getParentEdges() const
get parent edges
const std::vector< GNETAZElement * > & getParentTAZElements() const
get parent TAZElements
void replaceParentElements(T *elementChild, const U &newParents)
replace parent elements
GNEEdge * retrieveEdge(const std::string &id, bool failHard=true) const
get edge by id
Definition: GNENet.cpp:1141
GNETAZElement * retrieveTAZElement(SumoXMLTag type, const std::string &id, bool hardFail=true) const
Returns the named TAZElement.
Definition: GNENet.cpp:3001
GNEViewNet * getViewNet() const
get view net
Definition: GNENet.cpp:2245
An special type of Attribute carrier that owns hierarchical elements.
const std::string & getTagStr() const
get Tag vinculated with this attribute Property in String Format (used to avoid multiple calls to toS...
SumoXMLTag getTag() const
get Tag vinculated with this attribute Property
bool hasDialog() const
return true if tag correspond to an element that can be edited using a dialog
class used to group all variables related to interval bar
std::string getAttributeStr() const
set attribute
std::string getDataSetStr() const
get dataSet
std::string getBeginStr() const
get begin
std::string getGenericDataTypeStr() const
get generic data type
std::string getEndStr() const
get end
GNEViewNetHelper::IntervalBar & getIntervalBar()
get interval bar
GNEViewParent * getViewParent() const
get the net object
void buildSelectionACPopupEntry(GUIGLObjectPopupMenu *ret, GNEAttributeCarrier *AC)
Builds an entry which allows to (de)select the object.
Definition: GNEViewNet.cpp:368
GNEEdgeDataFrame * getEdgeDataFrame() const
get frame for DATA_EDGEDATA
static FXMenuCommand * buildFXMenuCommand(FXComposite *p, const std::string &text, FXIcon *icon, FXObject *tgt, FXSelector sel)
build menu command
Definition: GUIDesigns.cpp:40
The popup menu of a globject.
void buildPositionCopyEntry(GUIGLObjectPopupMenu *ret, bool addSeparator=true)
Builds an entry which allows to copy the cursor position if geo projection is used,...
virtual const std::string & getMicrosimID() const
Returns the id of the object as known to microsim.
void buildShowParamsPopupEntry(GUIGLObjectPopupMenu *ret, bool addSeparator=true)
Builds an entry which allows to open the parameter window.
void buildCenterPopupEntry(GUIGLObjectPopupMenu *ret, bool addSeparator=true)
Builds an entry which allows to center to the object.
void buildPopupHeader(GUIGLObjectPopupMenu *ret, GUIMainWindow &app, bool addSeparator=true)
Builds the header.
A window containing a gl-object's parameter.
void mkItem(const char *name, bool dynamic, ValueSource< T > *src)
Adds a row which obtains its value from a ValueSource.
void closeBuilding(const Parameterised *p=0)
Closes the building of the table.
Stores the information about how to visualize structures.
double getTextAngle(double objectAngle) const
return an angle that is suitable for reading text aligned with the given angle (degrees)
An upper class for objects with additional parameters.
Definition: Parameterised.h:39
ParameterisedAttrType
@brie enum for Parameterised type
Definition: Parameterised.h:43
const std::string getParameter(const std::string &key, const std::string defaultValue="") const
Returns the value for a given key.
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
A list of positions.
double length2D() const
Returns the length.
double length() const
Returns the length.
double rotationDegreeAtOffset(double pos) const
Returns the rotation at the given length.
Position positionAtOffset2D(double pos, double lateralOffset=0) const
Returns the position at the given length.
static const RGBColor BLUE
Definition: RGBColor.h:182
static const RGBColor BLACK
Definition: RGBColor.h:188