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>
33
34#include "GNEGenericData.h"
35#include "GNEDataInterval.h"
36
37
38// ===========================================================================
39// member method definitions
40// ===========================================================================
41
42// ---------------------------------------------------------------------------
43// GNEGenericData - methods
44// ---------------------------------------------------------------------------
45
46GNEGenericData::GNEGenericData(const SumoXMLTag tag, FXIcon* icon, const GUIGlObjectType type, GNEDataInterval* dataIntervalParent,
47 const Parameterised::Map& parameters,
48 const std::vector<GNEJunction*>& junctionParents,
49 const std::vector<GNEEdge*>& edgeParents,
50 const std::vector<GNELane*>& laneParents,
51 const std::vector<GNEAdditional*>& additionalParents,
52 const std::vector<GNEDemandElement*>& demandElementParents,
53 const std::vector<GNEGenericData*>& genericDataParents) :
54 GNEPathManager::PathElement(type, dataIntervalParent->getID(), icon, GNEPathManager::PathElement::Options::DATA_ELEMENT),
55 Parameterised(parameters),
56 GNEHierarchicalElement(dataIntervalParent->getNet(), tag, junctionParents, edgeParents, laneParents, additionalParents, demandElementParents, genericDataParents),
57 myDataIntervalParent(dataIntervalParent) {
58}
59
60
62
63
66 return this;
67}
68
69
73}
74
75
76void
78 if ((myTagProperty.getTag() == SUMO_TAG_MEANDATA_EDGE) && (shape.length() > 0)) {
79 // obtain pointer to edge data frame (only for code legibly)
81 // check if we have to filter generic data
82 if (edgeDataFrame->shown()) {
83 // check attribute
84 if ((edgeDataFrame->getAttributeSelector()->getFilteredAttribute().size() > 0) &&
85 (getParametersMap().count(edgeDataFrame->getAttributeSelector()->getFilteredAttribute()) > 0)) {
86 // get value
87 const std::string value = getParametersMap().at(edgeDataFrame->getAttributeSelector()->getFilteredAttribute());
88 // calculate center position
89 const Position centerPosition = shape.positionAtOffset2D(shape.length2D() / 2);
90 // Add a draw matrix
92 GLHelper::drawText(value, centerPosition, GLO_MAX, 2, RGBColor::BLUE);
93 // pop draw matrix
95 }
96 }
97 }
98}
99
100
101bool
103 return true;
104}
105
106
107std::string
109 return "";
110}
111
112
113void
115 throw InvalidArgument(getTagStr() + " cannot fix any problem");
116}
117
118
121 GUIGLObjectPopupMenu* ret = new GUIGLObjectPopupMenu(app, parent, *this);
122 // build header
123 buildPopupHeader(ret, app);
124 // build menu command for center button and copy cursor position to clipboard
126 buildPositionCopyEntry(ret, app);
127 // buld menu commands for names
128 GUIDesigns::buildFXMenuCommand(ret, "Copy " + getTagStr() + " name to clipboard", nullptr, ret, MID_COPY_NAME);
129 GUIDesigns::buildFXMenuCommand(ret, "Copy " + getTagStr() + " typed name to clipboard", nullptr, ret, MID_COPY_TYPED_NAME);
130 new FXMenuSeparator(ret);
131 // build selection and show parameters menu
134 // show option to open additional dialog
135 if (myTagProperty.hasDialog()) {
136 GUIDesigns::buildFXMenuCommand(ret, ("Open " + getTagStr() + " Dialog").c_str(), getACIcon(), &parent, MID_OPEN_ADDITIONAL_DIALOG);
137 new FXMenuSeparator(ret);
138 } else {
139 GUIDesigns::buildFXMenuCommand(ret, ("Cursor position in view: " + toString(getPositionInView().x()) + "," + toString(getPositionInView().y())).c_str(), nullptr, nullptr, 0);
140 }
141 return ret;
142}
143
144
147 // Create table
149 // Iterate over attributes
150 for (const auto& tagProperty : myTagProperty) {
151 // Add attribute and set it dynamic if aren't unique
152 if (tagProperty.isUnique()) {
153 ret->mkItem(tagProperty.getAttrStr().c_str(), false, getAttribute(tagProperty.getAttr()));
154 } else {
155 ret->mkItem(tagProperty.getAttrStr().c_str(), true, getAttribute(tagProperty.getAttr()));
156 }
157 }
158 // close building
159 ret->closeBuilding();
160 return ret;
161}
162
163
164void
167}
168
169
170void
174 } else {
176 }
177 // update information label
179}
180
181
182void
185}
186
187
188double
190 return 0;
191}
192
193
196 return Position();
197}
198
199
200double
202 return 0;
203}
204
205
208 return Position();
209}
210
211
214 return getParametersMap();
215}
216
217// ---------------------------------------------------------------------------
218// GNEGenericData - protected methods
219// ---------------------------------------------------------------------------
220
221void
222GNEGenericData::drawFilteredAttribute(const GUIVisualizationSettings& s, const PositionVector& laneShape, const std::string& attribute, const GNEDataInterval* dataIntervalParent) const {
223 if ((myDataIntervalParent == dataIntervalParent) && (getParametersMap().count(attribute) > 0)) {
224 const Position pos = laneShape.positionAtOffset2D(laneShape.length2D() * 0.5);
225 const double rot = laneShape.rotationDegreeAtOffset(laneShape.length2D() * 0.5);
226 // Add a draw matrix for details
228 // draw value
229 GLHelper::drawText(getParameter(attribute), pos, GLO_MAX - 1, 2, RGBColor::BLACK, s.getTextAngle(rot + 90));
230 // pop draw matrix
232 }
233}
234
235
236bool
238 // get toolbar
240 // declare flag
241 bool draw = true;
242 // check filter by generic data type
243 if ((toolBar.getGenericDataType() != SUMO_TAG_NOTHING) && (toolBar.getGenericDataType() != myTagProperty.getTag())) {
244 draw = false;
245 }
246 // check filter by data set
247 if (toolBar.getDataSet() && (toolBar.getDataSet() != myDataIntervalParent->getDataSetParent())) {
248 draw = false;
249 }
250 // check filter by begin
252 draw = false;
253 }
254 // check filter by end
256 draw = false;
257 }
258 // check filter by attribute
259 if ((toolBar.getParameter().size() > 0) && (getParametersMap().count(toolBar.getParameter()) == 0)) {
260 draw = false;
261 }
262 // return flag
263 return draw;
264}
265
266void
267GNEGenericData::replaceFirstParentEdge(const std::string& value) {
268 std::vector<GNEEdge*> parentEdges = getParentEdges();
269 parentEdges[0] = myNet->getAttributeCarriers()->retrieveEdge(value);
270 // replace parent edges
271 replaceParentElements(this, parentEdges);
272}
273
274
275void
276GNEGenericData::replaceLastParentEdge(const std::string& value) {
277 std::vector<GNEEdge*> parentEdges = getParentEdges();
278 parentEdges[(int)parentEdges.size() - 1] = myNet->getAttributeCarriers()->retrieveEdge(value);
279 // replace parent edges
280 replaceParentElements(this, parentEdges);
281}
282
283
284void
285GNEGenericData::replaceParentTAZElement(const int index, const std::string& value) {
286 std::vector<GNEAdditional*> parentTAZElements = getParentAdditionals();
288 // continue depending of index and number of TAZs
289 if (index == 0) {
290 if (parentTAZElements.size() == 2) {
291 if (parentTAZElements.at(1)->getID() == value) {
292 parentTAZElements = {TAZ};
293 } else {
294 parentTAZElements[0] = TAZ;
295 }
296 } else if (parentTAZElements.at(0) != TAZ) {
297 parentTAZElements = {TAZ, parentTAZElements.at(0)};
298 }
299 } else if (index == 1) {
300 if (parentTAZElements.size() == 2) {
301 if (parentTAZElements.at(0)->getID() == value) {
302 parentTAZElements = {TAZ};
303 } else {
304 parentTAZElements[1] = TAZ;
305 }
306 } else if (parentTAZElements.at(0) != TAZ) {
307 parentTAZElements = {parentTAZElements.at(0), TAZ};
308 }
309 } else {
310 throw ProcessError("Invalid index");
311 }
312 // replace parent TAZElements
313 replaceParentElements(this, parentTAZElements);
314}
315
316
317std::string
319 return getDataIntervalParent()->getDataSetParent()->getID() + "[" +
322}
323
324/****************************************************************************/
@ MID_COPY_TYPED_NAME
Copy typed object name - popup entry.
Definition: GUIAppEnum.h:450
@ MID_OPEN_ADDITIONAL_DIALOG
open additional dialog (used in netedit)
Definition: GUIAppEnum.h:460
@ MID_COPY_NAME
Copy object name - popup entry.
Definition: GUIAppEnum.h:448
GUIGlObjectType
@ GLO_MAX
empty max
SumoXMLTag
Numbers representing SUMO-XML - element names.
@ SUMO_TAG_TAZ
a traffic assignment zone
@ SUMO_TAG_NOTHING
invalid tag
@ SUMO_TAG_MEANDATA_EDGE
an edge based mean data detector
@ SUMO_ATTR_BEGIN
weights: time range begin
@ SUMO_ATTR_END
weights: time range end
const double INVALID_DOUBLE
Definition: StdDefs.h:60
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
Definition: ToString.h:46
static void popMatrix()
pop matrix
Definition: GLHelper.cpp:130
static void pushMatrix()
push matrix
Definition: GLHelper.cpp:117
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:685
const std::string getID() const
get ID (all Attribute Carriers have one)
bool isAttributeCarrierSelected() const
check if attribute carrier is selected
FXIcon * getACIcon() const
get FXIcon associated to this AC
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.
std::string getAttribute(SumoXMLAttr key) const
double getAttributeDouble(SumoXMLAttr key) const
GNEDataSet * getDataSetParent() const
Returns a pointer to GNEDataSet parent.
std::string getFilteredAttribute() const
get filtered attribute
const AttributeSelector * getAttributeSelector() const
getattribute selector modul
void updateGLObject()
update GLObject (geometry, ID, etc.)
Position getPathElementDepartPos() const
get path element depart position
GUIGlObject * getGUIGlObject()
get GUIGlObject associated with this AttributeCarrier
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
virtual void updateGeometry()=0
update pre-computed geometry information
virtual std::string getGenericDataProblem() const
return a string with the current data set problem (by default empty, can be reimplemented in children...
virtual ~GNEGenericData()
Destructor.
Position getPathElementArrivalPos() const
get path element arrival position
GUIParameterTableWindow * getParameterWindow(GUIMainWindow &app, GUISUMOAbstractView &parent)
Returns an own parameter window.
GNEGenericData(const SumoXMLTag tag, FXIcon *icon, const GUIGlObjectType type, GNEDataInterval *dataIntervalParent, const Parameterised::Map &parameters, const std::vector< GNEJunction * > &junctionParents, const std::vector< GNEEdge * > &edgeParents, const std::vector< GNELane * > &laneParents, const std::vector< GNEAdditional * > &additionalParents, const std::vector< GNEDemandElement * > &demandElementParents, const std::vector< GNEGenericData * > &genericDataParents)
Constructor.
virtual Position getPositionInView() const =0
Returns element position in view.
virtual std::string getAttribute(SumoXMLAttr key) const =0
GNEDataInterval * myDataIntervalParent
dataInterval Parent
void selectGLObject()
select element
std::string getPartialID() const
get partial ID
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
void deleteGLObject()
delete element
GNEDataInterval * getDataIntervalParent() const
get data interval parent
void replaceFirstParentEdge(const std::string &value)
replace the first parent edge
GUIGLObjectPopupMenu * getPopUpMenu(GUIMainWindow &app, GUISUMOAbstractView &parent)
Returns an own popup-menu.
void replaceParentTAZElement(const int index, const std::string &value)
replace the first parent TAZElement
void drawFilteredAttribute(const GUIVisualizationSettings &s, const PositionVector &laneShape, const std::string &attribute, const GNEDataInterval *dataIntervalParent) const
draw filtered attribute
const Parameterised::Map & getACParametersMap() const
get parameters map
void replaceLastParentEdge(const std::string &value)
replace the last parent edge
const std::vector< GNEAdditional * > & getParentAdditionals() const
get parent additionals
const std::vector< GNEEdge * > & getParentEdges() const
get parent edges
void replaceParentElements(T *elementChild, const U &newParents)
replace parent elements
GNEAdditional * retrieveAdditional(SumoXMLTag type, const std::string &id, bool hardFail=true) const
Returns the named additional.
GNEEdge * retrieveEdge(const std::string &id, bool hardFail=true) const
get edge by id
void deleteGenericData(GNEGenericData *genericData, GNEUndoList *undoList)
remove generic data
Definition: GNENet.cpp:706
GNENetHelper::AttributeCarriers * getAttributeCarriers() const
get all attribute carriers used in this net
Definition: GNENet.cpp:132
GNEViewNet * getViewNet() const
get view net
Definition: GNENet.cpp:1987
void updateInformationLabel()
update information label
SelectionInformation * getSelectionInformation() const
get modul for selection information
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 getParameter() const
get parameter
double getBegin() const
get begin
GNEDataSet * getDataSet() const
get dataSet
SumoXMLTag getGenericDataType() const
get generic data type
GNEViewNetHelper::IntervalBar & getIntervalBar()
get interval bar
GNEViewParent * getViewParent() const
get the net object
GNEUndoList * getUndoList() const
get the undoList object
void buildSelectionACPopupEntry(GUIGLObjectPopupMenu *ret, GNEAttributeCarrier *AC)
Builds an entry which allows to (de)select the object.
Definition: GNEViewNet.cpp:474
GNESelectorFrame * getSelectorFrame() const
get frame for select elements
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 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.
void buildPositionCopyEntry(GUIGLObjectPopupMenu *ret, const GUIMainWindow &app) const
Builds an entry which allows to copy the cursor position if geo projection is used,...
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
std::map< std::string, std::string > Map
parameters map
Definition: Parameterised.h:45
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.
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