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-2024 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 GNEPathElement(type, dataIntervalParent->getID(), icon, GNEPathElement::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
70const GUIGlObject*
72 return this;
73}
74
75
80
81
82void
84 if ((myTagProperty.getTag() == GNE_TAG_EDGEREL_SINGLE) && (shape.length() > 0)) {
85 // obtain pointer to edge data frame (only for code legibly)
87 // check if we have to filter generic data
88 if (edgeDataFrame->shown()) {
89 // check attribute
90 if ((edgeDataFrame->getAttributeSelector()->getFilteredAttribute().size() > 0) &&
91 (getParametersMap().count(edgeDataFrame->getAttributeSelector()->getFilteredAttribute()) > 0)) {
92 // get value
93 const std::string value = getParametersMap().at(edgeDataFrame->getAttributeSelector()->getFilteredAttribute());
94 // calculate center position
95 const Position centerPosition = shape.positionAtOffset2D(shape.length2D() / 2);
96 // Add a draw matrix
98 GLHelper::drawText(value, centerPosition, GLO_MAX, 2, RGBColor::BLUE);
99 // pop draw matrix
101 }
102 }
103 }
104}
105
106
107bool
109 return false;
110}
111
112
113bool
115 return false;
116}
117
118
119bool
121 return false;
122}
123
124
125bool
127 return false;
128}
129
130
131bool
133 // get edit modes
134 const auto& editModes = myNet->getViewNet()->getEditModes();
135 // check if we're in delete mode
136 if (editModes.isCurrentSupermodeData() && (editModes.dataEditMode == DataEditMode::DATA_DELETE)) {
138 } else {
139 return false;
140 }
141}
142
143
144bool
146 // get edit modes
147 const auto& editModes = myNet->getViewNet()->getEditModes();
148 // check if we're in select mode
149 if (editModes.isCurrentSupermodeData() && (editModes.dataEditMode == DataEditMode::DATA_SELECT)) {
151 } else {
152 return false;
153 }
154}
155
156
157bool
159 return false;
160}
161
162
163bool
165 return true;
166}
167
168
169std::string
171 return "";
172}
173
174
175void
177 throw InvalidArgument(getTagStr() + " cannot fix any problem");
178}
179
180
183 GUIGLObjectPopupMenu* ret = new GUIGLObjectPopupMenu(app, parent, *this);
184 // build header
185 buildPopupHeader(ret, app);
186 // build menu command for center button and copy cursor position to clipboard
188 buildPositionCopyEntry(ret, app);
189 // build menu commands for names
190 GUIDesigns::buildFXMenuCommand(ret, TLF("Copy % name to clipboard", getTagStr()), nullptr, ret, MID_COPY_NAME);
191 GUIDesigns::buildFXMenuCommand(ret, TLF("Copy % name to clipboard", getTagStr()), nullptr, ret, MID_COPY_TYPED_NAME);
192 new FXMenuSeparator(ret);
193 // build selection and show parameters menu
196 // show option to open additional dialog
197 if (myTagProperty.hasDialog()) {
198 GUIDesigns::buildFXMenuCommand(ret, (TLF("Open % Dialog", getTagStr())).c_str(), getACIcon(), &parent, MID_OPEN_ADDITIONAL_DIALOG);
199 new FXMenuSeparator(ret);
200 } else {
201 GUIDesigns::buildFXMenuCommand(ret, (TL("Cursor position in view: ") + toString(getPositionInView().x()) + "," + toString(getPositionInView().y())).c_str(), nullptr, nullptr, 0);
202 }
203 return ret;
204}
205
206
209 // Create table
211 // Iterate over attributes
212 for (const auto& tagProperty : myTagProperty) {
213 // Add attribute and set it dynamic if aren't unique
214 if (tagProperty.isUnique()) {
215 ret->mkItem(tagProperty.getAttrStr().c_str(), false, getAttribute(tagProperty.getAttr()));
216 } else {
217 ret->mkItem(tagProperty.getAttrStr().c_str(), true, getAttribute(tagProperty.getAttr()));
218 }
219 }
220 // close building
221 ret->closeBuilding();
222 return ret;
223}
224
225
226void
230
231
232void
242
243
244void
248
249
250bool
254
255
260
261// ---------------------------------------------------------------------------
262// GNEGenericData - protected methods
263// ---------------------------------------------------------------------------
264
265void
266GNEGenericData::drawFilteredAttribute(const GUIVisualizationSettings& s, const PositionVector& laneShape, const std::string& attribute, const GNEDataInterval* dataIntervalParent) const {
267 if ((myDataIntervalParent == dataIntervalParent) && (getParametersMap().count(attribute) > 0)) {
268 const Position pos = laneShape.positionAtOffset2D(laneShape.length2D() * 0.5);
269 const double rot = laneShape.rotationDegreeAtOffset(laneShape.length2D() * 0.5);
270 // Add a draw matrix for details
272 // draw value
273 GLHelper::drawText(getParameter(attribute), pos, GLO_MAX - 1, 2, RGBColor::BLACK, s.getTextAngle(rot + 90));
274 // pop draw matrix
276 }
277}
278
279
280bool
282 // get toolbar
284 // declare flag
285 bool draw = true;
286 // check filter by generic data type
287 if ((toolBar.getGenericDataType() != SUMO_TAG_NOTHING) && (toolBar.getGenericDataType() != myTagProperty.getTag())) {
288 draw = false;
289 }
290 // check filter by data set
291 if (toolBar.getDataSet() && (toolBar.getDataSet() != myDataIntervalParent->getDataSetParent())) {
292 draw = false;
293 }
294 // check filter by begin
296 draw = false;
297 }
298 // check filter by end
300 draw = false;
301 }
302 // check filter by attribute
303 if ((toolBar.getParameter().size() > 0) && (getParametersMap().count(toolBar.getParameter()) == 0)) {
304 draw = false;
305 }
306 // return flag
307 return draw;
308}
309
310void
311GNEGenericData::replaceFirstParentEdge(const std::string& value) {
312 std::vector<GNEEdge*> parentEdges = getParentEdges();
313 parentEdges[0] = myNet->getAttributeCarriers()->retrieveEdge(value);
314 // replace parent edges
315 replaceParentElements(this, parentEdges);
316}
317
318
319void
320GNEGenericData::replaceLastParentEdge(const std::string& value) {
321 std::vector<GNEEdge*> parentEdges = getParentEdges();
322 parentEdges[(int)parentEdges.size() - 1] = myNet->getAttributeCarriers()->retrieveEdge(value);
323 // replace parent edges
324 replaceParentElements(this, parentEdges);
325}
326
327
328void
329GNEGenericData::replaceParentTAZElement(const int index, const std::string& value) {
330 std::vector<GNEAdditional*> parentTAZElements = getParentAdditionals();
332 // continue depending of index and number of TAZs
333 if (index == 0) {
334 if (parentTAZElements.size() == 2) {
335 if (parentTAZElements.at(1)->getID() == value) {
336 parentTAZElements = {TAZ};
337 } else {
338 parentTAZElements[0] = TAZ;
339 }
340 } else if (parentTAZElements.at(0) != TAZ) {
341 parentTAZElements = {TAZ, parentTAZElements.at(0)};
342 }
343 } else if (index == 1) {
344 if (parentTAZElements.size() == 2) {
345 if (parentTAZElements.at(0)->getID() == value) {
346 parentTAZElements = {TAZ};
347 } else {
348 parentTAZElements[1] = TAZ;
349 }
350 } else if (parentTAZElements.at(0) != TAZ) {
351 parentTAZElements = {parentTAZElements.at(0), TAZ};
352 }
353 } else {
354 throw ProcessError(TL("Invalid index"));
355 }
356 // replace parent TAZElements
357 replaceParentElements(this, parentTAZElements);
358}
359
360
361std::string
367
368/****************************************************************************/
@ DATA_SELECT
mode for selecting data elements
@ DATA_DELETE
mode for deleting data elements
@ MID_COPY_TYPED_NAME
Copy typed object name - popup entry.
Definition GUIAppEnum.h:455
@ MID_OPEN_ADDITIONAL_DIALOG
open additional dialog (used in netedit)
Definition GUIAppEnum.h:469
@ MID_COPY_NAME
Copy object name - popup entry.
Definition GUIAppEnum.h:453
GUIGlObjectType
@ GLO_MAX
empty max
#define TL(string)
Definition MsgHandler.h:315
#define TLF(string,...)
Definition MsgHandler.h:317
SumoXMLTag
Numbers representing SUMO-XML - element names.
@ SUMO_TAG_TAZ
a traffic assignment zone
@ SUMO_TAG_NOTHING
invalid tag, must be the last one
@ 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:756
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.)
GUIGlObject * getGUIGlObject()
get GUIGlObject associated with this AttributeCarrier
bool checkDrawFromContour() const
check if draw from contour (green)
bool checkDrawSelectContour() const
check if draw select contour (blue)
virtual void fixGenericDataProblem()
fix data set problem (by default throw an exception, has to be reimplemented in children)
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.
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
bool checkDrawDeleteContour() const
check if draw delete contour (pink/white)
GNEDataInterval * myDataIntervalParent
dataInterval Parent
bool checkDrawToContour() const
check if draw from contour (magenta)
void selectGLObject()
select element
std::string getPartialID() const
get partial ID
virtual bool isGenericDataValid() const
check if current data set is valid to be written into XML (by default true, can be reimplemented in c...
bool isVisibleInspectDeleteSelect() const
check if attribute is visible in inspect, delete or select mode
void deleteGLObject()
delete element
bool checkDrawMoveContour() const
check if draw move contour (red)
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.
bool checkDrawOverContour() const
check if draw over contour (orange)
bool checkDrawRelatedContour() const
check if draw related contour (cyan)
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:749
GNENetHelper::AttributeCarriers * getAttributeCarriers() const
get all attribute carriers used in this net
Definition GNENet.cpp:127
GNEViewNet * getViewNet() const
get view net
Definition GNENet.cpp:2155
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
const GNEViewNetHelper::EditModes & getEditModes() const
get edit modes
GNEViewNetHelper::IntervalBar & getIntervalBar()
get interval bar
GNEViewParent * getViewParent() const
get the net object
bool checkOverLockedElement(const GUIGlObject *GLObject, const bool isSelected) const
check if given element is locked (used for drawing select and delete contour)
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, const bool disable=false)
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