Eclipse SUMO - Simulation of Urban MObility
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
GNEAttributeCarrier.h
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// Abstract Base class for gui objects which carry attributes
19/****************************************************************************/
20#pragma once
21#include <config.h>
22
25
26// ===========================================================================
27// class declarations
28// ===========================================================================
29
31class GNELane;
32class GNENet;
34class GNEUndoList;
35class GUIGlObject;
36
37// ===========================================================================
38// class definitions
39// ===========================================================================
47
49 friend class GNEChange_Attribute;
52
53public:
54
61 GNEAttributeCarrier(const SumoXMLTag tag, GNENet* net, const std::string& filename, const bool isTemplate);
62
64 virtual ~GNEAttributeCarrier();
65
67 const std::string getID() const;
68
70 GNENet* getNet() const;
71
73 const std::string& getFilename() const;
74
76 void changeDefaultFilename(const std::string& file);
77
80
83
85 bool isAttributeCarrierSelected() const;
86
88 bool drawUsingSelectColor() const;
89
92
95
98
101
103 bool isMarkedForDrawingFront() const;
104
106 void drawInLayer(const double typeOrLayer, const double extraOffset = 0) const;
107
109
113 void setInGrid(bool value);
114
116 bool inGrid() const;
117
119
124
126 virtual const GUIGlObject* getGUIGlObject() const = 0;
127
129 virtual void updateGeometry() = 0;
130
132
135
137 bool checkDrawInspectContour() const;
138
140 bool checkDrawFrontContour() const;
141
143 virtual bool checkDrawFromContour() const = 0;
144
146 virtual bool checkDrawToContour() const = 0;
147
149 virtual bool checkDrawRelatedContour() const = 0;
150
152 virtual bool checkDrawOverContour() const = 0;
153
155 virtual bool checkDrawDeleteContour() const = 0;
156
158 virtual bool checkDrawDeleteContourSmall() const = 0;
159
161 virtual bool checkDrawSelectContour() const = 0;
162
164 virtual bool checkDrawMoveContour() const = 0;
165
167
169 void resetDefaultValues(const bool allowUndoRedo);
170
173 /* @brief method for getting the Attribute of an XML key
174 * @param[in] key The attribute key
175 * @return string with the value associated to key
176 */
177 virtual std::string getAttribute(SumoXMLAttr key) const = 0;
178
179 /* @brief method for setting the attribute and letting the object perform additional changes
180 * @param[in] key The attribute key
181 * @param[in] value The new value
182 * @param[in] undoList The undoList on which to register changes
183 */
184 virtual void setAttribute(SumoXMLAttr key, const std::string& value, GNEUndoList* undoList) = 0;
185
186 /* @brief method for check if new value for certain attribute is valid
187 * @param[in] key The attribute key
188 * @param[in] value The new value
189 */
190 virtual bool isValid(SumoXMLAttr key, const std::string& value) = 0;
191
192 /* @brief method for enable attribute
193 * @param[in] key The attribute key
194 * @param[in] undoList The undoList on which to register changes
195 * @note certain attributes can be only enabled, and can produce the disabling of other attributes
196 */
197 virtual void enableAttribute(SumoXMLAttr key, GNEUndoList* undoList);
198
199 /* @brief method for disable attribute
200 * @param[in] key The attribute key
201 * @param[in] undoList The undoList on which to register changes
202 * @note certain attributes can be only enabled, and can produce the disabling of other attributes
203 */
204 virtual void disableAttribute(SumoXMLAttr key, GNEUndoList* undoList);
205
206 /* @brief method for check if the value for certain attribute is set
207 * @param[in] key The attribute key
208 */
209 virtual bool isAttributeEnabled(SumoXMLAttr key) const;
210
211 /* @brief method for check if the value for certain attribute is computed (for example, due a network recomputing)
212 * @param[in] key The attribute key
213 */
214 virtual bool isAttributeComputed(SumoXMLAttr key) const;
215
216 /* @brief method for check if the value for certain attribute is set
217 * @param[in] key The attribute key
218 */
219 bool hasAttribute(SumoXMLAttr key) const;
220
222 virtual std::string getPopUpID() const = 0;
223
225 virtual std::string getHierarchyName() const = 0;
226
228
232 virtual const Parameterised::Map& getACParametersMap() const = 0;
233
235 template<typename T>
237
239 void setACParameters(const std::string& parameters, GNEUndoList* undoList);
240
242 void setACParameters(const std::vector<std::pair<std::string, std::string> >& parameters, GNEUndoList* undoList);
243
245 void setACParameters(const Parameterised::Map& parameters, GNEUndoList* undoList);
246
248 void addACParameters(const std::string& key, const std::string& attribute, GNEUndoList* undoList);
249
251 void removeACParametersKeys(const std::vector<std::string>& keepKeys, GNEUndoList* undoList);
252
254
255 /* @brief method for return an alternative value for disabled attributes. Used only in GNEFrames
256 * @param[in] key The attribute key
257 */
259
261 virtual std::string getAttributeForSelection(SumoXMLAttr key) const;
262
264 const std::string& getTagStr() const;
265
267 FXIcon* getACIcon() const;
268
270 bool isTemplate() const;
271
273 const GNETagProperties* getTagProperty() const;
274
277
279 template<typename T>
280 static bool canParse(const std::string& string);
281
283 template<typename T>
284 static T parse(const std::string& string);
285
289 template<typename T>
290 static bool canParse(const GNENet* net, const std::string& value, const bool checkConsecutivity);
291
293 template<typename T>
294 static T parse(const GNENet* net, const std::string& value);
295
297 template<typename T>
298 static std::string parseIDs(const std::vector<T>& ACs);
299
301
304
306 static const std::string FEATURE_LOADED;
307
309 static const std::string FEATURE_GUESSED;
310
312 static const std::string FEATURE_MODIFIED;
313
315 static const std::string FEATURE_APPROVED;
316
318
320 static const std::string True;
321
323 static const std::string False;
324
325protected:
328
330 GNENet* myNet = nullptr;
331
333 bool mySelected = false;
334
336 bool myDrawInFront = false;
337
339 bool myInGrid = false;
340
342 std::string myFilename;
343
346
348 const bool myIsTemplate = false;
349
351 virtual void toggleAttribute(SumoXMLAttr key, const bool value);
352
355 /* @brief method for getting the common attribute of an XML key
356 * @param[in] key The attribute key
357 * @return string with the value associated to key
358 */
359 std::string getCommonAttribute(const Parameterised* parameterised, SumoXMLAttr key) const;
360
361 /* @brief method for setting the common attribute and letting the object perform additional changes
362 * @param[in] key The attribute key
363 * @param[in] value The new value
364 * @param[in] undoList The undoList on which to register changes
365 */
366 void setCommonAttribute(SumoXMLAttr key, const std::string& value, GNEUndoList* undoList);
367
368 /* @brief method for check if new value for certain common attribute is valid
369 * @param[in] key The attribute key
370 * @param[in] value The new value
371 */
372 bool isCommonValid(SumoXMLAttr key, const std::string& value) const;
373
375 void setCommonAttribute(Parameterised* parameterised, SumoXMLAttr key, const std::string& value);
376
378
379private:
381 virtual void setAttribute(SumoXMLAttr key, const std::string& value) = 0;
382
385
388};
SumoXMLTag
Numbers representing SUMO-XML - element names.
SumoXMLAttr
Numbers representing SUMO-XML - attributes.
GNEAttributeCarrier(const GNEAttributeCarrier &)=delete
Invalidated copy constructor.
virtual std::string getAttributeForSelection(SumoXMLAttr key) const
method for getting the attribute in the context of object selection
const std::string getID() const
get ID (all Attribute Carriers have one)
bool isAttributeCarrierSelected() const
check if attribute carrier is selected
virtual bool checkDrawMoveContour() const =0
check if draw move contour (red)
void markForDrawingFront()
mark for drawing front
virtual bool checkDrawDeleteContourSmall() const =0
check if draw delete contour small (pink/white)
GNEAttributeCarrier & operator=(const GNEAttributeCarrier &src)=delete
Invalidated assignment operator.
virtual void enableAttribute(SumoXMLAttr key, GNEUndoList *undoList)
void selectAttributeCarrier()
select attribute carrier using GUIGlobalSelection
virtual bool checkDrawRelatedContour() const =0
check if draw related contour (cyan)
bool isMarkedForDrawingFront() const
check if this AC is marked for drawing front
bool myDrawInFront
boolean to check if drawn this AC over other elements
bool myCenterAfterCreation
boolean to check if center this element after creation
FXIcon * getACIcon() const
get FXIcon associated to this AC
bool mySelected
boolean to check if this AC is selected (more quickly as checking GUIGlObjectStorage)
virtual const GUIGlObject * getGUIGlObject() const =0
get GUIGlObject associated with this AttributeCarrier (constant)
static bool canParse(const GNENet *net, const std::string &value, const bool checkConsecutivity)
true if a value of type T can be parsed from string (requieres network)
virtual bool checkDrawToContour() const =0
check if draw from contour (magenta)
void setACParameters(const std::string &parameters, GNEUndoList *undoList)
set parameters (string)
bool checkDrawFrontContour() const
check if draw front contour (green/blue)
const bool myIsTemplate
whether the current object is a template object (used for edit attributes)
virtual void setAttribute(SumoXMLAttr key, const std::string &value)=0
method for setting the attribute and nothing else (used in GNEChange_Attribute)
virtual bool checkDrawFromContour() const =0
check if draw from contour (green)
virtual void toggleAttribute(SumoXMLAttr key, const bool value)
method for enable or disable the attribute and nothing else (used in GNEChange_ToggleAttribute)
static const std::string FEATURE_LOADED
feature is still unchanged after being loaded (implies approval)
virtual std::string getPopUpID() const =0
get PopPup ID (Used in AC Hierarchy)
std::string getCommonAttribute(const Parameterised *parameterised, SumoXMLAttr key) const
static const std::string FEATURE_APPROVED
feature has been approved but not changed (i.e. after being reguessed)
static T parse(const std::string &string)
parses a value of type T from string (used for basic types: int, double, bool, etc....
bool myInGrid
boolean to check if this AC is in grid
std::string getAlternativeValueForDisabledAttributes(SumoXMLAttr key) const
virtual bool isAttributeComputed(SumoXMLAttr key) const
static const std::string True
true value in string format (used for comparing boolean values in getAttribute(......
std::string myFilename
filename in which save this AC
void unselectAttributeCarrier()
unselect attribute carrier using GUIGlobalSelection
void removeACParametersKeys(const std::vector< std::string > &keepKeys, GNEUndoList *undoList)
remove keys
void setCommonAttribute(SumoXMLAttr key, const std::string &value, GNEUndoList *undoList)
virtual bool isAttributeEnabled(SumoXMLAttr key) const
const std::string & getTagStr() const
get tag assigned to this object in string format
static const std::string FEATURE_GUESSED
feature has been reguessed (may still be unchanged be we can't tell (yet)
bool isTemplate() const
check if this AC is template
virtual const Parameterised::Map & getACParametersMap() const =0
bool drawUsingSelectColor() const
check if attribute carrier must be drawn using selecting color.
void drawInLayer(const double typeOrLayer, const double extraOffset=0) const
draw element in the given layer, or in front if corresponding flag is enabled
void addACParameters(const std::string &key, const std::string &attribute, GNEUndoList *undoList)
add (or update attribute) key and attribute
static bool canParse(const std::string &string)
true if a value of type T can be parsed from string
static T parse(const GNENet *net, const std::string &value)
parses a complex value of type T from string (use for list of edges, list of lanes,...
void resetDefaultValues(const bool allowUndoRedo)
reset attribute carrier to their default values
const std::string & getFilename() const
get filename in which save this AC
bool hasAttribute(SumoXMLAttr key) const
const GNETagProperties * getTagProperty() const
get tagProperty associated with this Attribute Carrier
virtual bool checkDrawSelectContour() const =0
check if draw select contour (blue)
virtual bool isValid(SumoXMLAttr key, const std::string &value)=0
virtual GNEHierarchicalElement * getHierarchicalElement()=0
get GNEHierarchicalElement associated with this AttributeCarrier
GNENet * myNet
pointer to net
bool inGrid() const
check if this AC was inserted in grid
void unmarkForDrawingFront()
unmark for drawing front
virtual std::string getHierarchyName() const =0
get Hierarchy Name (Used in AC Hierarchy)
bool isCommonValid(SumoXMLAttr key, const std::string &value) const
GNENet * getNet() const
get pointer to net
virtual void disableAttribute(SumoXMLAttr key, GNEUndoList *undoList)
static std::string parseIDs(const std::vector< T > &ACs)
parses a list of specific Attribute Carriers into a string of IDs
static const std::string FEATURE_MODIFIED
feature has been manually modified (implies approval)
static const std::string False
true value in string format(used for comparing boolean values in getAttribute(...))
virtual void updateGeometry()=0
update pre-computed geometry information
virtual void setAttribute(SumoXMLAttr key, const std::string &value, GNEUndoList *undoList)=0
T getACParameters() const
get parameters
virtual ~GNEAttributeCarrier()
Destructor.
virtual std::string getAttribute(SumoXMLAttr key) const =0
bool checkDrawInspectContour() const
check if draw inspect contour (black/white)
virtual GUIGlObject * getGUIGlObject()=0
void changeDefaultFilename(const std::string &file)
change defaultFilename (only used in SavingFilesHandler)
virtual bool checkDrawOverContour() const =0
check if draw over contour (orange)
virtual bool checkDrawDeleteContour() const =0
check if draw delete contour (pink/white)
const GNETagProperties * myTagProperty
reference to tagProperty associated with this attribute carrier
the function-object for an editing operation (abstract base)
the function-object for an editing operation (abstract base)
This lane is powered by an underlying GNEEdge and basically knows how to draw itself.
Definition GNELane.h:46
A NBNetBuilder extended by visualisation and editing capabilities.
Definition GNENet.h:42
An upper class for objects with additional parameters.
std::map< std::string, std::string > Map
parameters map