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-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 // 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(parameters),
57  GNEHierarchicalElement(dataIntervalParent->getNet(), tag, junctionParents, edgeParents, laneParents, additionalParents, shapeParents, TAZElementParents, demandElementParents, genericDataParents),
58  GNEPathManager::PathElement(GNEPathManager::PathElement::Options::DATA_ELEMENT),
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
100  GLHelper::drawText(value, centerPosition, GLO_MAX, 2, RGBColor::BLUE);
101  // pop draw matrix
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 double
174  return 0;
175 }
176 
177 
178 Position
180  return Position();
181 }
182 
183 
184 double
186  return 0;
187 }
188 
189 
190 Position
192  return Position();
193 }
194 
195 
196 bool
198  return false;
199 }
200 
201 
202 const std::map<std::string, std::string>&
204  return getParametersMap();
205 }
206 
207 // ---------------------------------------------------------------------------
208 // GNEGenericData - protected methods
209 // ---------------------------------------------------------------------------
210 
211 void
212 GNEGenericData::drawFilteredAttribute(const GUIVisualizationSettings& s, const PositionVector& laneShape, const std::string& attribute) const {
213  if (getParametersMap().count(attribute) > 0) {
214  const Position pos = laneShape.positionAtOffset2D(laneShape.length2D() * 0.5);
215  const double rot = laneShape.rotationDegreeAtOffset(laneShape.length2D() * 0.5);
216  // Add a draw matrix for details
218  // draw value
219  GLHelper::drawText(getParameter(attribute), pos, GLO_MAX - 1, 2, RGBColor::BLACK, s.getTextAngle(rot + 90));
220  // pop draw matrix
222  }
223 }
224 
225 
226 bool
228  // get toolbar
230  // declare flag
231  bool draw = true;
232  // check filter by generic data type
233  if ((toolBar.getGenericDataTypeStr().size() > 0) && (toolBar.getGenericDataTypeStr() != myTagProperty.getTagStr())) {
234  draw = false;
235  }
236  // check filter by data set
237  if ((toolBar.getDataSetStr().size() > 0) && (toolBar.getDataSetStr() != myDataIntervalParent->getID())) {
238  draw = false;
239  }
240  // check filter by begin
241  if ((toolBar.getBeginStr().size() > 0) && (parse<double>(toolBar.getBeginStr()) > myDataIntervalParent->getAttributeDouble(SUMO_ATTR_BEGIN))) {
242  draw = false;
243  }
244  // check filter by end
245  if ((toolBar.getEndStr().size() > 0) && (parse<double>(toolBar.getEndStr()) < myDataIntervalParent->getAttributeDouble(SUMO_ATTR_END))) {
246  draw = false;
247  }
248  // check filter by attribute
249  if ((toolBar.getAttributeStr().size() > 0) && (getParametersMap().count(toolBar.getAttributeStr()) == 0)) {
250  draw = false;
251  }
252  // return flag
253  return draw;
254 }
255 
256 void
257 GNEGenericData::replaceFirstParentEdge(const std::string& value) {
258  std::vector<GNEEdge*> parentEdges = getParentEdges();
259  parentEdges[0] = myNet->getAttributeCarriers()->retrieveEdge(value);
260  // replace parent edges
261  replaceParentElements(this, parentEdges);
262 }
263 
264 
265 void
266 GNEGenericData::replaceLastParentEdge(const std::string& value) {
267  std::vector<GNEEdge*> parentEdges = getParentEdges();
268  parentEdges[(int)parentEdges.size() - 1] = myNet->getAttributeCarriers()->retrieveEdge(value);
269  // replace parent edges
270  replaceParentElements(this, parentEdges);
271 }
272 
273 
274 void
276  std::vector<GNETAZElement*> parentTAZElements = getParentTAZElements();
277  parentTAZElements[0] = myNet->getAttributeCarriers()->retrieveTAZElement(tag, value);
278  // replace parent TAZElements
279  replaceParentElements(this, parentTAZElements);
280 }
281 
282 
283 void
285  std::vector<GNETAZElement*> parentTAZElements = getParentTAZElements();
286  if (value.empty()) {
287  parentTAZElements.pop_back();
288  } else if (parentTAZElements.size() == 1) {
289  parentTAZElements.push_back(myNet->getAttributeCarriers()->retrieveTAZElement(tag, value));
290  } else {
291  parentTAZElements.at(1) = myNet->getAttributeCarriers()->retrieveTAZElement(tag, value);
292  }
293  // replace parent TAZElements
294  replaceParentElements(this, parentTAZElements);
295 }
296 
297 /****************************************************************************/
@ MID_COPY_TYPED_NAME
Copy typed object name - popup entry.
Definition: GUIAppEnum.h:413
@ MID_OPEN_ADDITIONAL_DIALOG
open additional dialog (used in netedit)
Definition: GUIAppEnum.h:423
@ MID_COPY_NAME
Copy object name - popup entry.
Definition: GUIAppEnum.h:411
GUIGlObjectType
@ GLO_MAX
empty max
SumoXMLTag
Numbers representing SUMO-XML - element names.
@ SUMO_TAG_MEANDATA_EDGE
an edge based mean data detector
SumoXMLAttr
Numbers representing SUMO-XML - attributes.
@ 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:46
static void popMatrix()
pop matrix
Definition: GLHelper.cpp:123
static void pushMatrix()
push matrix
Definition: GLHelper.cpp:114
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:609
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
reference to tagProperty associated with this attribute carrier
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.
Position getPathElementDepartPos() const
get path element depart position
GUIGlObject * getGUIGlObject()
get GUIGlObject associated with this AttributeCarrier
void replaceSecondParentTAZElement(SumoXMLTag tag, const std::string &value)
replace the second parent TAZElement
double getPathElementDepartValue() const
get path element depart lane pos
virtual void fixGenericDataProblem()
fix data set problem (by default throw an exception, has to be reimplemented in children)
double getPathElementArrivalValue() const
get path element arrival lane pos
void drawAttribute(const PositionVector &shape) const
bool isAttributeComputed(SumoXMLAttr key) 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.
Position getPathElementArrivalPos() const
get path element arrival position
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
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
GNETAZElement * retrieveTAZElement(SumoXMLTag type, const std::string &id, bool hardFail=true) const
Returns the named TAZElement.
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:125
GNEViewNet * getViewNet() const
get view net
Definition: GNENet.cpp:1964
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:432
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:42
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:41
virtual 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:37
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:187
static const RGBColor BLACK
Definition: RGBColor.h:193