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, "", 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 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
100
101
102void
104 if ((myTagProperty->getTag() == GNE_TAG_EDGEREL_SINGLE) && (shape.length() > 0)) {
105 // obtain pointer to edge data frame (only for code legibly)
106 const GNEEdgeDataFrame* edgeDataFrame = myDataIntervalParent->getNet()->getViewNet()->getViewParent()->getEdgeDataFrame();
107 // check if we have to filter generic data
108 if (edgeDataFrame->shown()) {
109 // check attribute
110 if ((edgeDataFrame->getAttributeSelector()->getFilteredAttribute().size() > 0) &&
111 (getParametersMap().count(edgeDataFrame->getAttributeSelector()->getFilteredAttribute()) > 0)) {
112 // get value
113 const std::string value = getParametersMap().at(edgeDataFrame->getAttributeSelector()->getFilteredAttribute());
114 // calculate center position
115 const Position centerPosition = shape.positionAtOffset2D(shape.length2D() / 2);
116 // Add a draw matrix
118 GLHelper::drawText(value, centerPosition, GLO_MAX, 2, RGBColor::BLUE);
119 // pop draw matrix
121 }
122 }
123 }
124}
125
126
127bool
129 return false;
130}
131
132
133bool
135 return false;
136}
137
138
139bool
141 // check opened popup
142 if (myNet->getViewNet()->getPopup()) {
143 return myNet->getViewNet()->getPopup()->getGLObject() == this;
144 }
145 return false;
146}
147
148
149bool
151 return false;
152}
153
154
155bool
157 // get edit modes
158 const auto& editModes = myNet->getViewNet()->getEditModes();
159 // check if we're in delete mode
160 if (editModes.isCurrentSupermodeData() && (editModes.dataEditMode == DataEditMode::DATA_DELETE)) {
161 return myNet->getViewNet()->checkOverLockedElement(this, mySelected);
162 } else {
163 return false;
164 }
165}
166
167
168bool
170 return false;
171}
172
173
174bool
176 // get edit modes
177 const auto& editModes = myNet->getViewNet()->getEditModes();
178 // check if we're in select mode
179 if (editModes.isCurrentSupermodeData() && (editModes.dataEditMode == DataEditMode::DATA_SELECT)) {
180 return myNet->getViewNet()->checkOverLockedElement(this, mySelected);
181 } else {
182 return false;
183 }
184}
185
186
187bool
189 return false;
190}
191
192
193bool
195 return true;
196}
197
198
199std::string
201 return "";
202}
203
204
205void
207 throw InvalidArgument(getTagStr() + " cannot fix any problem");
208}
209
210
213 // create popup
214 GUIGLObjectPopupMenu* ret = new GUIGLObjectPopupMenu(app, parent, this);
215 // build common options
216 buildPopUpMenuCommonOptions(ret, app, myNet->getViewNet(), myTagProperty->getTag(), mySelected);
217 // show option to open additional dialog
218 if (myTagProperty->hasDialog()) {
219 GUIDesigns::buildFXMenuCommand(ret, (TLF("Open % Dialog", getTagStr())).c_str(), getACIcon(), &parent, MID_OPEN_ADDITIONAL_DIALOG);
220 new FXMenuSeparator(ret);
221 } else {
222 GUIDesigns::buildFXMenuCommand(ret, (TL("Cursor position in view: ") + toString(getPositionInView().x()) + "," + toString(getPositionInView().y())).c_str(), nullptr, nullptr, 0);
223 }
224 return ret;
225}
226
227
230 // Create table
232 // Iterate over attributes
233 for (const auto& tagProperty : myTagProperty->getAttributeProperties()) {
234 // Add attribute and set it dynamic if aren't unique
235 if (tagProperty->isUnique()) {
236 ret->mkItem(tagProperty->getAttrStr().c_str(), false, getAttribute(tagProperty->getAttr()));
237 } else {
238 ret->mkItem(tagProperty->getAttrStr().c_str(), true, getAttribute(tagProperty->getAttr()));
239 }
240 }
241 // close building
242 ret->closeBuilding();
243 return ret;
244}
245
246
247void
249 myNet->deleteGenericData(this, myNet->getViewNet()->getUndoList());
250}
251
252
253void
257 } else {
259 }
260 // update information label
261 myNet->getViewNet()->getViewParent()->getSelectorFrame()->getSelectionInformation()->updateInformationLabel();
262}
263
264
265void
269
270
275
276
281
282
283bool
287
288// ---------------------------------------------------------------------------
289// GNEGenericData - protected methods
290// ---------------------------------------------------------------------------
291
292void
293GNEGenericData::drawFilteredAttribute(const GUIVisualizationSettings& s, const PositionVector& laneShape, const std::string& attribute, const GNEDataInterval* dataIntervalParent) const {
294 if ((myDataIntervalParent == dataIntervalParent) && (getParametersMap().count(attribute) > 0)) {
295 const Position pos = laneShape.positionAtOffset2D(laneShape.length2D() * 0.5);
296 const double rot = laneShape.rotationDegreeAtOffset(laneShape.length2D() * 0.5);
297 // Add a draw matrix for details
299 // draw value
300 GLHelper::drawText(getParameter(attribute), pos, GLO_MAX - 1, 2, RGBColor::BLACK, s.getTextAngle(rot + 90));
301 // pop draw matrix
303 }
304}
305
306
307bool
309 // get toolbar
310 const GNEViewNetHelper::IntervalBar& toolBar = myNet->getViewNet()->getIntervalBar();
311 // declare flag
312 bool draw = true;
313 // check filter by generic data type
314 if ((toolBar.getGenericDataType() != SUMO_TAG_NOTHING) && (toolBar.getGenericDataType() != myTagProperty->getTag())) {
315 draw = false;
316 }
317 // check filter by data set
318 if (toolBar.getDataSet() && (toolBar.getDataSet() != myDataIntervalParent->getDataSetParent())) {
319 draw = false;
320 }
321 // check filter by begin
322 if ((toolBar.getBegin() != INVALID_DOUBLE) && (toolBar.getBegin() > myDataIntervalParent->getAttributeDouble(SUMO_ATTR_BEGIN))) {
323 draw = false;
324 }
325 // check filter by end
326 if ((toolBar.getEnd() != INVALID_DOUBLE) && (toolBar.getEnd() < myDataIntervalParent->getAttributeDouble(SUMO_ATTR_END))) {
327 draw = false;
328 }
329 // check filter by attribute
330 if ((toolBar.getParameter().size() > 0) && (getParametersMap().count(toolBar.getParameter()) == 0)) {
331 draw = false;
332 }
333 // return flag
334 return draw;
335}
336
337void
339 auto newEdge = myNet->getAttributeCarriers()->retrieveEdge(value);
340 GNEHierarchicalElement::updateParent(this, 0, newEdge);
341}
342
343
344void
346 auto newEdge = myNet->getAttributeCarriers()->retrieveEdge(value);
347 GNEHierarchicalElement::updateParent(this, (int)getParentEdges().size() - 1, newEdge);
348}
349
350
351void
352GNEGenericData::replaceParentTAZElement(const int index, const std::string& value) {
353 std::vector<GNEAdditional*> newTAZs = getParentAdditionals();
354 auto TAZ = myNet->getAttributeCarriers()->retrieveAdditional(SUMO_TAG_TAZ, value);
355 // continue depending of index and number of TAZs
356 if (index == 0) {
357 if (newTAZs.size() == 2) {
358 if (newTAZs.at(1)->getID() == value) {
359 newTAZs = {TAZ};
360 } else {
361 newTAZs[0] = TAZ;
362 }
363 } else if (newTAZs.at(0) != TAZ) {
364 newTAZs = {TAZ, newTAZs.at(0)};
365 }
366 } else if (index == 1) {
367 if (newTAZs.size() == 2) {
368 if (newTAZs.at(0)->getID() == value) {
369 newTAZs = {TAZ};
370 } else {
371 newTAZs[1] = TAZ;
372 }
373 } else if (newTAZs.at(0) != TAZ) {
374 newTAZs = {newTAZs.at(0), TAZ};
375 }
376 } else {
377 throw ProcessError(TL("Invalid index"));
378 }
380}
381
382
383std::string
389
390/****************************************************************************/
@ 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
const std::string invalid_return< std::string >::value
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:135
static void pushMatrix()
push matrix
Definition GLHelper.cpp:122
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:747
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)
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
Position getCommonAttributePosition(SumoXMLAttr key) const
const std::string & getFilename() const
get filename in which save this AC
const GNETagProperties * getTagProperty() const
get tagProperty associated with this Attribute Carrier
GNEAttributeCarrier(const SumoXMLTag tag, GNENet *net, const std::string &filename, const bool isTemplate)
Constructor.
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
GNEDataSet * getDataSetParent() const
Returns a pointer to GNEDataSet parent.
std::string getAttribute(SumoXMLAttr key) const override
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
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
A NBNetBuilder extended by visualisation and editing capabilities.
Definition GNENet.h:42
GNEPathElement(const GNEPathElement::Options options)
constructor
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
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 buildPopUpMenuCommonOptions(GUIGLObjectPopupMenu *ret, GUIMainWindow &app, GUISUMOAbstractView *parent, const SumoXMLTag tag, const bool selected, bool addSeparator=true)
GUIGlObject(GUIGlObjectType type, const std::string &microsimID, FXIcon *icon)
Constructor.
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
Parameterised()
Default constructor.
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