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-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),
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->getFileBucket()),
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 nullptr;
69}
70
71
74 return this;
75}
76
77
78const Parameterised*
80 return this;
81}
82
83
86 return this;
87}
88
89
90const GUIGlObject*
92 return this;
93}
94
95
98 if (isTemplate()) {
99 return nullptr;
100 } else {
102 }
103}
104
105
110
111
112void
114 if ((myTagProperty->getTag() == GNE_TAG_EDGEREL_SINGLE) && (shape.length() > 0)) {
115 // obtain pointer to edge data frame (only for code legibly)
117 // check if we have to filter generic data
118 if (edgeDataFrame->shown()) {
119 // check attribute
120 if ((edgeDataFrame->getAttributeSelector()->getFilteredAttribute().size() > 0) &&
121 (getParametersMap().count(edgeDataFrame->getAttributeSelector()->getFilteredAttribute()) > 0)) {
122 // get value
123 const std::string value = getParametersMap().at(edgeDataFrame->getAttributeSelector()->getFilteredAttribute());
124 // calculate center position
125 const Position centerPosition = shape.positionAtOffset2D(shape.length2D() / 2);
126 // Add a draw matrix
128 GLHelper::drawText(value, centerPosition, GLO_MAX, 2, RGBColor::BLUE);
129 // pop draw matrix
131 }
132 }
133 }
134}
135
136
137bool
139 return false;
140}
141
142
143bool
145 return false;
146}
147
148
149bool
151 // check opened popup
152 if (myNet->getViewNet()->getPopup()) {
153 return myNet->getViewNet()->getPopup()->getGLObject() == this;
154 }
155 return false;
156}
157
158
159bool
161 return false;
162}
163
164
165bool
167 // get edit modes
168 const auto& editModes = myNet->getViewNet()->getEditModes();
169 // check if we're in delete mode
170 if (editModes.isCurrentSupermodeData() && (editModes.dataEditMode == DataEditMode::DATA_DELETE)) {
172 } else {
173 return false;
174 }
175}
176
177
178bool
180 return false;
181}
182
183
184bool
186 // get edit modes
187 const auto& editModes = myNet->getViewNet()->getEditModes();
188 // check if we're in select mode
189 if (editModes.isCurrentSupermodeData() && (editModes.dataEditMode == DataEditMode::DATA_SELECT)) {
191 } else {
192 return false;
193 }
194}
195
196
197bool
199 return false;
200}
201
202
203bool
205 return true;
206}
207
208
209std::string
211 return "";
212}
213
214
215void
217 throw InvalidArgument(getTagStr() + " cannot fix any problem");
218}
219
220
223 // create popup
224 GUIGLObjectPopupMenu* ret = new GUIGLObjectPopupMenu(app, parent, this);
225 // build common options
227 // show option to open additional dialog
228 if (myTagProperty->hasDialog()) {
229 GUIDesigns::buildFXMenuCommand(ret, (TLF("Open % Dialog", getTagStr())).c_str(), getACIcon(), &parent, MID_OPEN_ADDITIONAL_DIALOG);
230 new FXMenuSeparator(ret);
231 } else {
232 GUIDesigns::buildFXMenuCommand(ret, (TL("Cursor position in view: ") + toString(getPositionInView().x()) + "," + toString(getPositionInView().y())).c_str(), nullptr, nullptr, 0);
233 }
234 return ret;
235}
236
237
240 // Create table
242 // Iterate over attributes
243 for (const auto& tagProperty : myTagProperty->getAttributeProperties()) {
244 // Add attribute and set it dynamic if aren't unique
245 if (tagProperty->isUnique()) {
246 ret->mkItem(tagProperty->getAttrStr().c_str(), false, getAttribute(tagProperty->getAttr()));
247 } else {
248 ret->mkItem(tagProperty->getAttrStr().c_str(), true, getAttribute(tagProperty->getAttr()));
249 }
250 }
251 // close building
252 ret->closeBuilding();
253 return ret;
254}
255
256
257void
261
262
263void
273
274
275void
279
280
285
286
291
292
293bool
297
298// ---------------------------------------------------------------------------
299// GNEGenericData - protected methods
300// ---------------------------------------------------------------------------
301
302void
303GNEGenericData::drawFilteredAttribute(const GUIVisualizationSettings& s, const PositionVector& laneShape, const std::string& attribute, const GNEDataInterval* dataIntervalParent) const {
304 if ((myDataIntervalParent == dataIntervalParent) && (getParametersMap().count(attribute) > 0)) {
305 const Position pos = laneShape.positionAtOffset2D(laneShape.length2D() * 0.5);
306 const double rot = laneShape.rotationDegreeAtOffset(laneShape.length2D() * 0.5);
307 // Add a draw matrix for details
309 // draw value
310 GLHelper::drawText(getParameter(attribute), pos, GLO_MAX - 1, 2, RGBColor::BLACK, s.getTextAngle(rot + 90));
311 // pop draw matrix
313 }
314}
315
316
317bool
319 // get toolbar
321 // declare flag
322 bool draw = true;
323 // check filter by generic data type
324 if ((toolBar.getGenericDataType() != SUMO_TAG_NOTHING) && (toolBar.getGenericDataType() != myTagProperty->getTag())) {
325 draw = false;
326 }
327 // check filter by data set
328 if (toolBar.getDataSet() && (toolBar.getDataSet() != myDataIntervalParent->getDataSetParent())) {
329 draw = false;
330 }
331 // check filter by begin
333 draw = false;
334 }
335 // check filter by end
337 draw = false;
338 }
339 // check filter by attribute
340 if ((toolBar.getParameter().size() > 0) && (getParametersMap().count(toolBar.getParameter()) == 0)) {
341 draw = false;
342 }
343 // return flag
344 return draw;
345}
346
347void
348GNEGenericData::replaceFirstParentEdge(const std::string& value) {
349 auto newEdge = myNet->getAttributeCarriers()->retrieveEdge(value);
350 GNEHierarchicalElement::updateParent(this, 0, newEdge);
351}
352
353
354void
355GNEGenericData::replaceLastParentEdge(const std::string& value) {
356 auto newEdge = myNet->getAttributeCarriers()->retrieveEdge(value);
357 GNEHierarchicalElement::updateParent(this, (int)getParentEdges().size() - 1, newEdge);
358}
359
360
361void
362GNEGenericData::replaceParentTAZElement(const int index, const std::string& value) {
363 std::vector<GNEAdditional*> newTAZs = getParentAdditionals();
365 // continue depending of index and number of TAZs
366 if (index == 0) {
367 if (newTAZs.size() == 2) {
368 if (newTAZs.at(1)->getID() == value) {
369 newTAZs = {TAZ};
370 } else {
371 newTAZs[0] = TAZ;
372 }
373 } else if (newTAZs.at(0) != TAZ) {
374 newTAZs = {TAZ, newTAZs.at(0)};
375 }
376 } else if (index == 1) {
377 if (newTAZs.size() == 2) {
378 if (newTAZs.at(0)->getID() == value) {
379 newTAZs = {TAZ};
380 } else {
381 newTAZs[1] = TAZ;
382 }
383 } else if (newTAZs.at(0) != TAZ) {
384 newTAZs = {newTAZs.at(0), TAZ};
385 }
386 } else {
387 throw ProcessError(TL("Invalid index"));
388 }
390}
391
392
393std::string
399
400/****************************************************************************/
@ 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:471
@ GLO_MAX
empty max
#define TL(string)
Definition MsgHandler.h:304
#define TLF(string,...)
Definition MsgHandler.h:306
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
SumoXMLAttr
Numbers representing SUMO-XML - attributes.
@ SUMO_ATTR_BEGIN
weights: time range begin
@ SUMO_ATTR_END
weights: time range end
const double INVALID_DOUBLE
invalid double
Definition StdDefs.h:68
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:742
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 (more quickly as checking GUIGlObjectStorage)
const std::string getID() const override
get ID (all Attribute Carriers have one)
PositionVector getCommonAttributePositionVector(SumoXMLAttr key) const
void unselectAttributeCarrier()
unselect attribute carrier using GUIGlobalSelection
const std::string & getTagStr() const
get tag assigned to this object in string format
bool isTemplate() const
check if this AC is template
Position getCommonAttributePosition(SumoXMLAttr key) const
GNENet * myNet
pointer to net
GNENet * getNet() const
get pointer to net
virtual void updateGeometry()=0
update pre-computed geometry information
virtual std::string getAttribute(SumoXMLAttr key) const =0
const GNETagProperties * myTagProperty
reference to tagProperty associated with this attribute carrier
double getAttributeDouble(SumoXMLAttr key) const override
GNEDataSet * getDataSetParent() const
Returns a pointer to GNEDataSet parent.
std::string getAttribute(SumoXMLAttr key) const override
FileBucket * getFileBucket() const override
get reference to fileBucket in which save this AC
std::string getFilteredAttribute() const
get filtered attribute
const AttributeSelector * getAttributeSelector() const
getattribute selector modul
Position getAttributePosition(SumoXMLAttr key) const override
bool isPathElementSelected() const override
check if path element is selected
bool checkDrawRelatedContour() const override
check if draw related contour (cyan)
bool checkDrawOverContour() const override
check if draw over contour (orange)
bool checkDrawDeleteContourSmall() const override
check if draw delete contour small (pink/white)
virtual void fixGenericDataProblem()
fix data set problem (by default throw an exception, has to be reimplemented in children)
GUIGlObject * getGUIGlObject() override
get GUIGlObject associated with this genericData
FileBucket * getFileBucket() const override
get reference to fileBucket in which save this AC
void selectGLObject() override
select element
void drawAttribute(const PositionVector &shape) const
GUIParameterTableWindow * getParameterWindow(GUIMainWindow &app, GUISUMOAbstractView &parent) override
Returns an own parameter window.
bool checkDrawDeleteContour() const override
check if draw delete contour (pink/white)
virtual std::string getGenericDataProblem() const
return a string with the current data set problem (by default empty, can be reimplemented in children...
bool checkDrawSelectContour() const override
check if draw select contour (blue)
virtual ~GNEGenericData()
Destructor.
GNEMoveElement * getMoveElement() const override
get GNEMoveElement associated with this genericData
bool checkDrawToContour() const override
check if draw from contour (magenta)
virtual Position getPositionInView() const =0
Returns element position in view.
bool checkDrawFromContour() const override
check if draw from contour (green)
GNEDataInterval * myDataIntervalParent
dataInterval Parent
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...
GNEHierarchicalElement * getHierarchicalElement() override
methods to retrieve the elements linked to this dataSet
GNEGenericData(SumoXMLTag tag, GNENet *net)
default Constructor
GUIGLObjectPopupMenu * getPopUpMenu(GUIMainWindow &app, GUISUMOAbstractView &parent) override
Returns an own popup-menu.
bool isVisibleInspectDeleteSelect() const
check if attribute is visible in inspect, delete or select mode
PositionVector getAttributePositionVector(SumoXMLAttr key) const override
GNEDataInterval * getDataIntervalParent() const
get data interval parent
void replaceFirstParentEdge(const std::string &value)
replace the first parent edge
void deleteGLObject() override
delete element
void updateGLObject() override
update GLObject (geometry, ID, etc.)
bool checkDrawMoveContour() const override
check if draw move contour (red)
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
Parameterised * getParameters() override
get parameters associated with this genericData
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
void deleteGenericData(GNEGenericData *genericData, GNEUndoList *undoList)
remove generic data
Definition GNENet.cpp:822
GNENetHelper::AttributeCarriers * getAttributeCarriers() const
get all attribute carriers used in this net
Definition GNENet.cpp:174
GNEViewParent * getViewParent() const
get view parent (used for simplify code)
Definition GNENet.cpp:150
GNEUndoList * getUndoList() const
get undo list(used for simplify code)
Definition GNENet.cpp:156
GNEViewNet * getViewNet() const
get view net (used for simplify code)
Definition GNENet.cpp:144
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
bool checkOverLockedElement(const GUIGlObject *GLObject, const bool isSelected) const
check if given element is locked (used for drawing select and delete contour)
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