Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
eclipse
GitHub Repository: eclipse/sumo
Path: blob/main/src/netedit/elements/GNEAttributeCarrier.h
169678 views
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
/****************************************************************************/
14
/// @file GNEAttributeCarrier.h
15
/// @author Jakob Erdmann
16
/// @date Mar 2011
17
///
18
// Abstract Base class for gui objects which carry attributes
19
/****************************************************************************/
20
#pragma once
21
#include <config.h>
22
23
#include <netedit/GNEReferenceCounter.h>
24
#include <utils/foxtools/fxheader.h>
25
26
// ===========================================================================
27
// class declarations
28
// ===========================================================================
29
30
class GNEHierarchicalElement;
31
class GNELane;
32
class GNENet;
33
class GNETagProperties;
34
class GNEUndoList;
35
class GUIGlObject;
36
37
// ===========================================================================
38
// class definitions
39
// ===========================================================================
40
/**
41
* @class GNEAttributeCarrier
42
*
43
* Abstract Base class for gui objects which carry attributes
44
* inherits from GNEReferenceCounter for convenience
45
*/
46
class GNEAttributeCarrier : public GNEReferenceCounter {
47
48
/// @brief declare friend class
49
friend class GNEChange_Attribute;
50
friend class GNEChange_ToggleAttribute;
51
friend class GNEAttributesEditorType;
52
53
public:
54
55
/**@brief Constructor
56
* @param[in] tag SUMO Tag assigned to this type of object
57
* @param[in] net GNENet in which this AttributeCarrier is stored
58
* @param[in] filename file in which this AttributeCarrier is stored
59
* @param[in] isTemplate flag to mark this AttributeCarrier as template
60
*/
61
GNEAttributeCarrier(const SumoXMLTag tag, GNENet* net, const std::string& filename, const bool isTemplate);
62
63
/// @brief Destructor
64
virtual ~GNEAttributeCarrier();
65
66
/// @brief get ID (all Attribute Carriers have one)
67
const std::string getID() const;
68
69
/// @brief get pointer to net
70
GNENet* getNet() const;
71
72
/// @brief get filename in which save this AC
73
const std::string& getFilename() const;
74
75
/// @brief change defaultFilename (only used in SavingFilesHandler)
76
void changeDefaultFilename(const std::string& file);
77
78
/// @brief select attribute carrier using GUIGlobalSelection
79
void selectAttributeCarrier();
80
81
/// @brief unselect attribute carrier using GUIGlobalSelection
82
void unselectAttributeCarrier();
83
84
/// @brief check if attribute carrier is selected
85
bool isAttributeCarrierSelected() const;
86
87
/// @brief check if attribute carrier must be drawn using selecting color.
88
bool drawUsingSelectColor() const;
89
90
/// @brief get GNEHierarchicalElement associated with this AttributeCarrier
91
virtual GNEHierarchicalElement* getHierarchicalElement() = 0;
92
93
/// @name Function related front elements
94
/// @{
95
96
/// @brief mark for drawing front
97
void markForDrawingFront();
98
99
/// @brief unmark for drawing front
100
void unmarkForDrawingFront();
101
102
/// @brief check if this AC is marked for drawing front
103
bool isMarkedForDrawingFront() const;
104
105
/// @brief draw element in the given layer, or in front if corresponding flag is enabled
106
void drawInLayer(const double typeOrLayer, const double extraOffset = 0) const;
107
108
/// @}
109
110
/// @name Function related with grid (needed for elements that aren't always in grid)
111
/// @{
112
/// @brief mark if this AC was inserted in grid or not
113
void setInGrid(bool value);
114
115
/// @brief check if this AC was inserted in grid
116
bool inGrid() const;
117
118
/// @}
119
120
/// @name Function related with graphics (must be implemented in all children)
121
/// @{
122
/// @brief get GUIGlObject associated with this AttributeCarrier
123
virtual GUIGlObject* getGUIGlObject() = 0;
124
125
/// @brief get GUIGlObject associated with this AttributeCarrier (constant)
126
virtual const GUIGlObject* getGUIGlObject() const = 0;
127
128
/// @brief update pre-computed geometry information
129
virtual void updateGeometry() = 0;
130
131
/// @}
132
133
/// @name Function related with contourdrawing (can be implemented in children)
134
/// @{
135
136
/// @brief check if draw inspect contour (black/white)
137
bool checkDrawInspectContour() const;
138
139
/// @brief check if draw front contour (green/blue)
140
bool checkDrawFrontContour() const;
141
142
/// @brief check if draw from contour (green)
143
virtual bool checkDrawFromContour() const = 0;
144
145
/// @brief check if draw from contour (magenta)
146
virtual bool checkDrawToContour() const = 0;
147
148
/// @brief check if draw related contour (cyan)
149
virtual bool checkDrawRelatedContour() const = 0;
150
151
/// @brief check if draw over contour (orange)
152
virtual bool checkDrawOverContour() const = 0;
153
154
/// @brief check if draw delete contour (pink/white)
155
virtual bool checkDrawDeleteContour() const = 0;
156
157
/// @brief check if draw delete contour small (pink/white)
158
virtual bool checkDrawDeleteContourSmall() const = 0;
159
160
/// @brief check if draw select contour (blue)
161
virtual bool checkDrawSelectContour() const = 0;
162
163
/// @brief check if draw move contour (red)
164
virtual bool checkDrawMoveContour() const = 0;
165
166
/// @}
167
168
/// @brief reset attribute carrier to their default values
169
void resetDefaultValues(const bool allowUndoRedo);
170
171
/// @name Functions related with attributes (must be implemented in all children)
172
/// @{
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
221
/// @brief get PopPup ID (Used in AC Hierarchy)
222
virtual std::string getPopUpID() const = 0;
223
224
/// @brief get Hierarchy Name (Used in AC Hierarchy)
225
virtual std::string getHierarchyName() const = 0;
226
227
/// @}
228
229
/// @name Function related with parameters
230
/// @{
231
/// @brief get parameters map
232
virtual const Parameterised::Map& getACParametersMap() const = 0;
233
234
/// @brief set parameters (string vector)
235
void setACParameters(const std::vector<std::pair<std::string, std::string> >& parameters);
236
237
/// @brief set parameters (string vector, undoList)
238
void setACParameters(const std::vector<std::pair<std::string, std::string> >& parameters, GNEUndoList* undoList);
239
240
/// @brief set parameters (map, undoList)
241
void setACParameters(const Parameterised::Map& parameters, GNEUndoList* undoList);
242
243
/// @}
244
245
/* @brief method for return an alternative value for disabled attributes. Used only in GNEFrames
246
* @param[in] key The attribute key
247
*/
248
std::string getAlternativeValueForDisabledAttributes(SumoXMLAttr key) const;
249
250
/// @brief method for getting the attribute in the context of object selection
251
virtual std::string getAttributeForSelection(SumoXMLAttr key) const;
252
253
/// @brief get tag assigned to this object in string format
254
const std::string& getTagStr() const;
255
256
/// @brief get FXIcon associated to this AC
257
FXIcon* getACIcon() const;
258
259
/// @brief check if this AC is template
260
bool isTemplate() const;
261
262
/// @brief get tagProperty associated with this Attribute Carrier
263
const GNETagProperties* getTagProperty() const;
264
265
/// @name parse functions
266
/// @{
267
268
/// @brief true if a value of type T can be parsed from string
269
template<typename T>
270
static bool canParse(const std::string& string);
271
272
/// @brief parses a value of type T from string (used for basic types: int, double, bool, etc.)
273
template<typename T>
274
static T parse(const std::string& string);
275
276
/**@brief true if a value of type T can be parsed from string (requieres network)
277
* @note checkConsecutivity doesn't check connectivity trought connections
278
*/
279
template<typename T>
280
static bool canParse(const GNENet* net, const std::string& value, const bool checkConsecutivity);
281
282
/// @brief parses a complex value of type T from string (use for list of edges, list of lanes, etc.)
283
template<typename T>
284
static T parse(const GNENet* net, const std::string& value);
285
286
/// @brief parses a list of specific Attribute Carriers into a string of IDs
287
template<typename T>
288
static std::string parseIDs(const std::vector<T>& ACs);
289
290
/// @}
291
292
/// @name Certain attributes and ACs (for example, connections) can be either loaded or guessed. The following static variables are used to remark it.
293
/// @{
294
295
/// @brief feature is still unchanged after being loaded (implies approval)
296
static const std::string FEATURE_LOADED;
297
298
/// @brief feature has been reguessed (may still be unchanged be we can't tell (yet)
299
static const std::string FEATURE_GUESSED;
300
301
/// @brief feature has been manually modified (implies approval)
302
static const std::string FEATURE_MODIFIED;
303
304
/// @brief feature has been approved but not changed (i.e. after being reguessed)
305
static const std::string FEATURE_APPROVED;
306
307
/// @brief lane start
308
static const std::string LANE_START;
309
310
/// @brief lane end
311
static const std::string LANE_END;
312
313
/// @}
314
315
/// @brief true value in string format (used for comparing boolean values in getAttribute(...))
316
static const std::string TRUE_STR;
317
318
/// @brief true value in string format(used for comparing boolean values in getAttribute(...))
319
static const std::string FALSE_STR;
320
321
protected:
322
/// @brief reference to tagProperty associated with this attribute carrier
323
const GNETagProperties* myTagProperty;
324
325
/// @brief pointer to net
326
GNENet* myNet = nullptr;
327
328
/// @brief boolean to check if this AC is selected (more quickly as checking GUIGlObjectStorage)
329
bool mySelected = false;
330
331
/// @brief boolean to check if drawn this AC over other elements
332
bool myDrawInFront = false;
333
334
/// @brief boolean to check if this AC is in grid
335
bool myInGrid = false;
336
337
/// @brief filename in which save this AC
338
std::string myFilename;
339
340
/// @brief boolean to check if center this element after creation
341
bool myCenterAfterCreation = true;
342
343
/// @brief whether the current object is a template object (used for edit attributes)
344
const bool myIsTemplate = false;
345
346
/// @brief method for enable or disable the attribute and nothing else (used in GNEChange_ToggleAttribute)
347
virtual void toggleAttribute(SumoXMLAttr key, const bool value);
348
349
/// @name Functions related with common attributes
350
/// @{
351
/* @brief method for getting the common attribute of an XML key
352
* @param[in] key The attribute key
353
* @return string with the value associated to key
354
*/
355
std::string getCommonAttribute(const Parameterised* parameterised, SumoXMLAttr key) const;
356
357
/* @brief method for setting the common attribute and letting the object perform additional changes
358
* @param[in] key The attribute key
359
* @param[in] value The new value
360
* @param[in] undoList The undoList on which to register changes
361
*/
362
void setCommonAttribute(SumoXMLAttr key, const std::string& value, GNEUndoList* undoList);
363
364
/* @brief method for check if new value for certain common attribute is valid
365
* @param[in] key The attribute key
366
* @param[in] value The new value
367
*/
368
bool isCommonValid(SumoXMLAttr key, const std::string& value) const;
369
370
/// @brief method for setting the common attribute and nothing else (used in GNEChange_Attribute)
371
void setCommonAttribute(Parameterised* parameterised, SumoXMLAttr key, const std::string& value);
372
373
/// @}
374
375
private:
376
/// @brief method for setting the attribute and nothing else (used in GNEChange_Attribute)
377
virtual void setAttribute(SumoXMLAttr key, const std::string& value) = 0;
378
379
/// @brief Invalidated copy constructor.
380
GNEAttributeCarrier(const GNEAttributeCarrier&) = delete;
381
382
/// @brief Invalidated assignment operator
383
GNEAttributeCarrier& operator=(const GNEAttributeCarrier& src) = delete;
384
};
385
386