Eclipse SUMO - Simulation of Urban MObility
Loading...
Searching...
No Matches
GNEGenericData.cpp
Go to the documentation of this file.
1/****************************************************************************/
2// Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo
3// Copyright (C) 2001-2023 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
74
75
76void
78 if ((myTagProperty.getTag() == GNE_TAG_EDGEREL_SINGLE) && (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, TLF("Copy % name to clipboard", getTagStr()), nullptr, ret, MID_COPY_NAME);
129 GUIDesigns::buildFXMenuCommand(ret, TLF("Copy % name to clipboard", getTagStr()), 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, (TLF("Open % Dialog", getTagStr())).c_str(), getACIcon(), &parent, MID_OPEN_ADDITIONAL_DIALOG);
137 new FXMenuSeparator(ret);
138 } else {
139 GUIDesigns::buildFXMenuCommand(ret, (TL("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
168
169
170void
180
181
182void
186
187
188bool
192
193
194double
196 return 0;
197}
198
199
204
205
206double
210
211
216
217
222
223// ---------------------------------------------------------------------------
224// GNEGenericData - protected methods
225// ---------------------------------------------------------------------------
226
227void
228GNEGenericData::drawFilteredAttribute(const GUIVisualizationSettings& s, const PositionVector& laneShape, const std::string& attribute, const GNEDataInterval* dataIntervalParent) const {
229 if ((myDataIntervalParent == dataIntervalParent) && (getParametersMap().count(attribute) > 0)) {
230 const Position pos = laneShape.positionAtOffset2D(laneShape.length2D() * 0.5);
231 const double rot = laneShape.rotationDegreeAtOffset(laneShape.length2D() * 0.5);
232 // Add a draw matrix for details
234 // draw value
235 GLHelper::drawText(getParameter(attribute), pos, GLO_MAX - 1, 2, RGBColor::BLACK, s.getTextAngle(rot + 90));
236 // pop draw matrix
238 }
239}
240
241
242bool
244 // get toolbar
246 // declare flag
247 bool draw = true;
248 // check filter by generic data type
249 if ((toolBar.getGenericDataType() != SUMO_TAG_NOTHING) && (toolBar.getGenericDataType() != myTagProperty.getTag())) {
250 draw = false;
251 }
252 // check filter by data set
253 if (toolBar.getDataSet() && (toolBar.getDataSet() != myDataIntervalParent->getDataSetParent())) {
254 draw = false;
255 }
256 // check filter by begin
258 draw = false;
259 }
260 // check filter by end
262 draw = false;
263 }
264 // check filter by attribute
265 if ((toolBar.getParameter().size() > 0) && (getParametersMap().count(toolBar.getParameter()) == 0)) {
266 draw = false;
267 }
268 // return flag
269 return draw;
270}
271
272void
273GNEGenericData::replaceFirstParentEdge(const std::string& value) {
274 std::vector<GNEEdge*> parentEdges = getParentEdges();
275 parentEdges[0] = myNet->getAttributeCarriers()->retrieveEdge(value);
276 // replace parent edges
277 replaceParentElements(this, parentEdges);
278}
279
280
281void
282GNEGenericData::replaceLastParentEdge(const std::string& value) {
283 std::vector<GNEEdge*> parentEdges = getParentEdges();
284 parentEdges[(int)parentEdges.size() - 1] = myNet->getAttributeCarriers()->retrieveEdge(value);
285 // replace parent edges
286 replaceParentElements(this, parentEdges);
287}
288
289
290void
291GNEGenericData::replaceParentTAZElement(const int index, const std::string& value) {
292 std::vector<GNEAdditional*> parentTAZElements = getParentAdditionals();
294 // continue depending of index and number of TAZs
295 if (index == 0) {
296 if (parentTAZElements.size() == 2) {
297 if (parentTAZElements.at(1)->getID() == value) {
298 parentTAZElements = {TAZ};
299 } else {
300 parentTAZElements[0] = TAZ;
301 }
302 } else if (parentTAZElements.at(0) != TAZ) {
303 parentTAZElements = {TAZ, parentTAZElements.at(0)};
304 }
305 } else if (index == 1) {
306 if (parentTAZElements.size() == 2) {
307 if (parentTAZElements.at(0)->getID() == value) {
308 parentTAZElements = {TAZ};
309 } else {
310 parentTAZElements[1] = TAZ;
311 }
312 } else if (parentTAZElements.at(0) != TAZ) {
313 parentTAZElements = {parentTAZElements.at(0), TAZ};
314 }
315 } else {
316 throw ProcessError(TL("Invalid index"));
317 }
318 // replace parent TAZElements
319 replaceParentElements(this, parentTAZElements);
320}
321
322
323std::string
329
330/****************************************************************************/
@ 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:462
@ MID_COPY_NAME
Copy object name - popup entry.
Definition GUIAppEnum.h:448
GUIGlObjectType
@ GLO_MAX
empty max
#define TL(string)
Definition MsgHandler.h:287
#define TLF(string,...)
Definition MsgHandler.h:288
SumoXMLTag
Numbers representing SUMO-XML - element names.
@ SUMO_TAG_TAZ
a traffic assignment zone
@ SUMO_TAG_NOTHING
invalid tag
@ GNE_TAG_EDGEREL_SINGLE
@ SUMO_ATTR_BEGIN
weights: time range begin
@ SUMO_ATTR_END
weights: time range end
const double INVALID_DOUBLE
invalid double
Definition StdDefs.h:64
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
bool mySelected
boolean to check if this AC is selected (instead of GUIGlObjectStorage)
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
bool isPathElementSelected() const
check if path element is selected
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:697
GNENetHelper::AttributeCarriers * getAttributeCarriers() const
get all attribute carriers used in this net
Definition GNENet.cpp:120
GNEViewNet * getViewNet() const
get view net
Definition GNENet.cpp:2030
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.
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
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.
std::map< std::string, std::string > Map
parameters map
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