Eclipse SUMO - Simulation of Urban MObility
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
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-2025 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 generic datas
19/****************************************************************************/
20
21#include <netedit/GNENet.h>
30
31#include "GNEDataInterval.h"
32#include "GNEGenericData.h"
33
34// ===========================================================================
35// member method definitions
36// ===========================================================================
37
39 GNEAttributeCarrier(tag, net, "", true),
40 GUIGlObject(net->getTagPropertiesDatabase()->getTagProperty(tag, true)->getGLType(), "",
41 GUIIconSubSys::getIcon(net->getTagPropertiesDatabase()->getTagProperty(tag, true)->getGUIIcon())),
43 myDataIntervalParent(nullptr) {
44}
45
46
47GNEGenericData::GNEGenericData(const SumoXMLTag tag, GNEDataInterval* dataIntervalParent, const Parameterised::Map& parameters) :
48 GNEAttributeCarrier(tag, dataIntervalParent->getNet(), dataIntervalParent->getFilename(), false),
49 GUIGlObject(dataIntervalParent->getNet()->getTagPropertiesDatabase()->getTagProperty(tag, true)->getGLType(), dataIntervalParent->getID(),
50 GUIIconSubSys::getIcon(dataIntervalParent->getNet()->getTagPropertiesDatabase()->getTagProperty(tag, true)->getGUIIcon())),
52 Parameterised(parameters),
53 myDataIntervalParent(dataIntervalParent) {
54}
55
56
58
59
64
65
68 return this;
69}
70
71
72const GUIGlObject*
74 return this;
75}
76
77
82
83
84void
86 if ((myTagProperty->getTag() == GNE_TAG_EDGEREL_SINGLE) && (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
109bool
111 return false;
112}
113
114
115bool
117 return false;
118}
119
120
121bool
123 // check opened popup
124 if (myNet->getViewNet()->getPopup()) {
125 return myNet->getViewNet()->getPopup()->getGLObject() == this;
126 }
127 return false;
128}
129
130
131bool
133 return false;
134}
135
136
137bool
139 // get edit modes
140 const auto& editModes = myNet->getViewNet()->getEditModes();
141 // check if we're in delete mode
142 if (editModes.isCurrentSupermodeData() && (editModes.dataEditMode == DataEditMode::DATA_DELETE)) {
144 } else {
145 return false;
146 }
147}
148
149
150bool
152 return false;
153}
154
155
156bool
158 // get edit modes
159 const auto& editModes = myNet->getViewNet()->getEditModes();
160 // check if we're in select mode
161 if (editModes.isCurrentSupermodeData() && (editModes.dataEditMode == DataEditMode::DATA_SELECT)) {
163 } else {
164 return false;
165 }
166}
167
168
169bool
171 return false;
172}
173
174
175bool
177 return true;
178}
179
180
181std::string
183 return "";
184}
185
186
187void
189 throw InvalidArgument(getTagStr() + " cannot fix any problem");
190}
191
192
195 // create popup
196 GUIGLObjectPopupMenu* ret = new GUIGLObjectPopupMenu(app, parent, this);
197 // build common options
199 // show option to open additional dialog
200 if (myTagProperty->hasDialog()) {
201 GUIDesigns::buildFXMenuCommand(ret, (TLF("Open % Dialog", getTagStr())).c_str(), getACIcon(), &parent, MID_OPEN_ADDITIONAL_DIALOG);
202 new FXMenuSeparator(ret);
203 } else {
204 GUIDesigns::buildFXMenuCommand(ret, (TL("Cursor position in view: ") + toString(getPositionInView().x()) + "," + toString(getPositionInView().y())).c_str(), nullptr, nullptr, 0);
205 }
206 return ret;
207}
208
209
212 // Create table
214 // Iterate over attributes
215 for (const auto& tagProperty : myTagProperty->getAttributeProperties()) {
216 // Add attribute and set it dynamic if aren't unique
217 if (tagProperty->isUnique()) {
218 ret->mkItem(tagProperty->getAttrStr().c_str(), false, getAttribute(tagProperty->getAttr()));
219 } else {
220 ret->mkItem(tagProperty->getAttrStr().c_str(), true, getAttribute(tagProperty->getAttr()));
221 }
222 }
223 // close building
224 ret->closeBuilding();
225 return ret;
226}
227
228
229void
233
234
235void
245
246
247void
251
252
253bool
257
258
263
264// ---------------------------------------------------------------------------
265// GNEGenericData - protected methods
266// ---------------------------------------------------------------------------
267
268void
269GNEGenericData::drawFilteredAttribute(const GUIVisualizationSettings& s, const PositionVector& laneShape, const std::string& attribute, const GNEDataInterval* dataIntervalParent) const {
270 if ((myDataIntervalParent == dataIntervalParent) && (getParametersMap().count(attribute) > 0)) {
271 const Position pos = laneShape.positionAtOffset2D(laneShape.length2D() * 0.5);
272 const double rot = laneShape.rotationDegreeAtOffset(laneShape.length2D() * 0.5);
273 // Add a draw matrix for details
275 // draw value
276 GLHelper::drawText(getParameter(attribute), pos, GLO_MAX - 1, 2, RGBColor::BLACK, s.getTextAngle(rot + 90));
277 // pop draw matrix
279 }
280}
281
282
283bool
285 // get toolbar
287 // declare flag
288 bool draw = true;
289 // check filter by generic data type
290 if ((toolBar.getGenericDataType() != SUMO_TAG_NOTHING) && (toolBar.getGenericDataType() != myTagProperty->getTag())) {
291 draw = false;
292 }
293 // check filter by data set
294 if (toolBar.getDataSet() && (toolBar.getDataSet() != myDataIntervalParent->getDataSetParent())) {
295 draw = false;
296 }
297 // check filter by begin
299 draw = false;
300 }
301 // check filter by end
303 draw = false;
304 }
305 // check filter by attribute
306 if ((toolBar.getParameter().size() > 0) && (getParametersMap().count(toolBar.getParameter()) == 0)) {
307 draw = false;
308 }
309 // return flag
310 return draw;
311}
312
313void
314GNEGenericData::replaceFirstParentEdge(const std::string& value) {
315 auto newEdge = myNet->getAttributeCarriers()->retrieveEdge(value);
316 GNEHierarchicalElement::updateParent(this, 0, newEdge);
317}
318
319
320void
321GNEGenericData::replaceLastParentEdge(const std::string& value) {
322 auto newEdge = myNet->getAttributeCarriers()->retrieveEdge(value);
323 GNEHierarchicalElement::updateParent(this, (int)getParentEdges().size() - 1, newEdge);
324}
325
326
327void
328GNEGenericData::replaceParentTAZElement(const int index, const std::string& value) {
329 std::vector<GNEAdditional*> newTAZs = getParentAdditionals();
331 // continue depending of index and number of TAZs
332 if (index == 0) {
333 if (newTAZs.size() == 2) {
334 if (newTAZs.at(1)->getID() == value) {
335 newTAZs = {TAZ};
336 } else {
337 newTAZs[0] = TAZ;
338 }
339 } else if (newTAZs.at(0) != TAZ) {
340 newTAZs = {TAZ, newTAZs.at(0)};
341 }
342 } else if (index == 1) {
343 if (newTAZs.size() == 2) {
344 if (newTAZs.at(0)->getID() == value) {
345 newTAZs = {TAZ};
346 } else {
347 newTAZs[1] = TAZ;
348 }
349 } else if (newTAZs.at(0) != TAZ) {
350 newTAZs = {newTAZs.at(0), TAZ};
351 }
352 } else {
353 throw ProcessError(TL("Invalid index"));
354 }
356}
357
358
359std::string
365
366/****************************************************************************/
@ DATA_SELECT
mode for selecting data elements
@ DATA_DELETE
mode for deleting data elements
@ MID_OPEN_ADDITIONAL_DIALOG
open additional dialog (used in netedit)
Definition GUIAppEnum.h:469
@ GLO_MAX
empty max
#define TL(string)
Definition MsgHandler.h:305
#define TLF(string,...)
Definition MsgHandler.h:307
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:131
static void pushMatrix()
push matrix
Definition GLHelper.cpp:118
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:748
const std::string getID() const
get ID (all Attribute Carriers have one)
bool isAttributeCarrierSelected() const
check if attribute carrier is selected
void selectAttributeCarrier()
select attribute carrier using GUIGlobalSelection
FXIcon * getACIcon() const
get FXIcon associated to this AC
bool mySelected
boolean to check if this AC is selected (more quickly as checking GUIGlObjectStorage)
void unselectAttributeCarrier()
unselect attribute carrier using GUIGlobalSelection
const std::string & getTagStr() const
get tag assigned to this object in string format
GNENet * myNet
pointer to net
GNENet * getNet() const
get pointer to net
const GNETagProperties * myTagProperty
reference to tagProperty associated with this attribute carrier
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...
bool checkDrawDeleteContourSmall() const
check if draw delete contour small (pink/white)
virtual ~GNEGenericData()
Destructor.
GNEHierarchicalElement * getHierarchicalElement()
get GNEHierarchicalElement associated with this AttributeCarrier
GUIParameterTableWindow * getParameterWindow(GUIMainWindow &app, GUISUMOAbstractView &parent)
Returns an own parameter window.
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...
GNEGenericData(SumoXMLTag tag, GNENet *net)
default Constructor
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 GNEHierarchicalContainerParents< GNEAdditional * > & getParentAdditionals() const
get parent additionals
const GNEHierarchicalContainerParents< GNEEdge * > & getParentEdges() const
get parent edges
static void updateParent(ElementType element, const int index, ParentType newParent)
update single parent element
static void updateParents(ElementType element, GNEHierarchicalContainerParents< ParentType > newParents)
update all 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
A NBNetBuilder extended by visualisation and editing capabilities.
Definition GNENet.h:42
void deleteGenericData(GNEGenericData *genericData, GNEUndoList *undoList)
remove generic data
Definition GNENet.cpp:800
GNENetHelper::AttributeCarriers * getAttributeCarriers() const
get all attribute carriers used in this net
Definition GNENet.cpp:146
GNEViewNet * getViewNet() const
get view net
Definition GNENet.cpp:2194
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
const std::vector< const GNEAttributeProperties * > & getAttributeProperties() const
get all attribute properties
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
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.
GUIGlObject * getGLObject() const
The object that belongs to this popup-menu.
void buildPopUpMenuCommonOptions(GUIGLObjectPopupMenu *ret, GUIMainWindow &app, GUISUMOAbstractView *parent, const SumoXMLTag tag, const bool selected, bool addSeparator=true)
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.
GUIGLObjectPopupMenu * getPopup() const
ge the current popup-menu
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, bool extrapolateBeyond=false) const
Returns the position at the given length.
static const RGBColor BLUE
Definition RGBColor.h:190
static const RGBColor BLACK
Definition RGBColor.h:196