Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
eclipse
GitHub Repository: eclipse/sumo
Path: blob/main/src/netedit/elements/GNEAttributeCarrier.h
193906 views
1
/****************************************************************************/
2
// Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo
3
// Copyright (C) 2001-2026 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/common/FileBucket.h>
25
#include <utils/foxtools/fxheader.h>
26
27
// ===========================================================================
28
// class declarations
29
// ===========================================================================
30
31
class FileBucket;
32
class GNEHierarchicalElement;
33
class GNELane;
34
class GNEMoveElement;
35
class GNENet;
36
class GNETagProperties;
37
class GNEUndoList;
38
class GUIGlObject;
39
class Parameterised;
40
41
// ===========================================================================
42
// class definitions
43
// ===========================================================================
44
45
class GNEAttributeCarrier : public GNEReferenceCounter {
46
47
/// @brief declare friend class
48
friend class GNEChange_Attribute;
49
friend class GNEChange_ToggleAttribute;
50
friend class GNEAttributesEditorType;
51
52
public:
53
/**@brief Constructor for templates
54
* @param[in] tag SUMO Tag assigned to this type of object
55
* @param[in] net GNENet in which this AttributeCarrier is stored
56
*/
57
GNEAttributeCarrier(const SumoXMLTag tag, GNENet* net);
58
59
/**@brief Constructor
60
* @param[in] tag SUMO Tag assigned to this type of object
61
* @param[in] net GNENet in which this AttributeCarrier is stored
62
* @param[in] fileBucket bucket in which this AttributeCarrier is stored
63
*/
64
GNEAttributeCarrier(const SumoXMLTag tag, GNENet* net, FileBucket* fileBucket);
65
66
/// @brief Destructor
67
virtual ~GNEAttributeCarrier();
68
69
/// @brief methods to retrieve the elements linked to this AttributeCarrier
70
/// @{
71
72
/// @brief get GNEHierarchicalElement associated with this AttributeCarrier
73
virtual GNEHierarchicalElement* getHierarchicalElement() = 0;
74
75
/// @brief get GNEMoveElement associated with this AttributeCarrier
76
virtual GNEMoveElement* getMoveElement() const = 0;
77
78
/// @brief get parameters associated with this AttributeCarrier
79
virtual Parameterised* getParameters() = 0;
80
81
/// @brief get parameters associated with this AttributeCarrier (constant)
82
virtual const Parameterised* getParameters() const = 0;
83
84
/// @brief get GUIGlObject associated with this AttributeCarrier
85
virtual GUIGlObject* getGUIGlObject() = 0;
86
87
/// @brief get GUIGlObject associated with this AttributeCarrier (constant)
88
virtual const GUIGlObject* getGUIGlObject() const = 0;
89
90
/// @}
91
92
/// @brief get ID (all Attribute Carriers have one)
93
const std::string getID() const override;
94
95
/// @brief get pointer to net
96
GNENet* getNet() const;
97
98
/// @brief get reference to fileBucket in which save this AC
99
virtual FileBucket* getFileBucket() const = 0;
100
101
/// @brief update pre-computed geometry information
102
virtual void updateGeometry() = 0;
103
104
/// @name Function related with selection
105
/// @{
106
/// @brief select attribute carrier using GUIGlobalSelection
107
void selectAttributeCarrier();
108
109
/// @brief unselect attribute carrier using GUIGlobalSelection
110
void unselectAttributeCarrier();
111
112
/// @brief check if attribute carrier is selected
113
bool isAttributeCarrierSelected() const;
114
115
/// @}
116
117
/// @name Function related with drawing
118
/// @{
119
120
/// @brief check if attribute carrier must be drawn using selecting color.
121
bool drawUsingSelectColor() const;
122
123
/// @brief check if draw moving geometry points
124
bool drawMovingGeometryPoints() const;
125
126
/// @}
127
128
/// @name Function related with front elements
129
/// @{
130
131
/// @brief mark for drawing front
132
void markForDrawingFront();
133
134
/// @brief unmark for drawing front
135
void unmarkForDrawingFront();
136
137
/// @brief check if this AC is marked for drawing front
138
bool isMarkedForDrawingFront() const;
139
140
/// @brief draw element in the given layer, or in front if corresponding flag is enabled
141
void drawInLayer(const double typeOrLayer, const double extraOffset = 0) const;
142
143
/// @}
144
145
/// @name Function related with grid (needed for elements that aren't always in grid)
146
/// @{
147
148
/// @brief mark if this AC was inserted in grid or not
149
void setInGrid(bool value);
150
151
/// @brief check if this AC was inserted in grid
152
bool inGrid() const;
153
154
/// @}
155
156
/// @name Function related with contour drawing
157
/// @{
158
159
/// @brief check if draw inspect contour (black/white)
160
bool checkDrawInspectContour() const;
161
162
/// @brief check if draw front contour (green/blue)
163
bool checkDrawFrontContour() const;
164
165
/// @brief check if draw from contour (green)
166
virtual bool checkDrawFromContour() const = 0;
167
168
/// @brief check if draw from contour (magenta)
169
virtual bool checkDrawToContour() const = 0;
170
171
/// @brief check if draw related contour (cyan)
172
virtual bool checkDrawRelatedContour() const = 0;
173
174
/// @brief check if draw over contour (orange)
175
virtual bool checkDrawOverContour() const = 0;
176
177
/// @brief check if draw delete contour (pink/white)
178
virtual bool checkDrawDeleteContour() const = 0;
179
180
/// @brief check if draw delete contour small (pink/white)
181
virtual bool checkDrawDeleteContourSmall() const = 0;
182
183
/// @brief check if draw select contour (blue)
184
virtual bool checkDrawSelectContour() const = 0;
185
186
/// @brief check if draw move contour (red)
187
virtual bool checkDrawMoveContour() const = 0;
188
189
/// @}
190
191
/// @brief reset attribute carrier to their default values
192
void resetDefaultValues(const bool allowUndoRedo);
193
194
/// @name Functions related with attributes (must be implemented in all children)
195
/// @{
196
197
/* @brief method for getting the Attribute of an XML key
198
* @param[in] key The attribute key
199
* @return string with the value associated to key
200
*/
201
virtual std::string getAttribute(SumoXMLAttr key) const = 0;
202
203
/* @brief method for getting the Attribute of an XML key in double format
204
* @param[in] key The attribute key
205
* @return double with the value associated to key
206
*/
207
virtual double getAttributeDouble(SumoXMLAttr key) const = 0;
208
209
/* @brief method for getting the Attribute of an XML key in position format
210
* @param[in] key The attribute key
211
* @return position with the value associated to key
212
*/
213
virtual Position getAttributePosition(SumoXMLAttr key) const = 0;
214
215
/* @brief method for getting the Attribute of an XML key in positionVector format
216
* @param[in] key The attribute key
217
* @return positionVector with the value associated to key
218
*/
219
virtual PositionVector getAttributePositionVector(SumoXMLAttr key) const = 0;
220
221
/* @brief method for setting the attribute and letting the object perform additional changes
222
* @param[in] key The attribute key
223
* @param[in] value The new value
224
* @param[in] undoList The undoList on which to register changes
225
*/
226
virtual void setAttribute(SumoXMLAttr key, const std::string& value, GNEUndoList* undoList) = 0;
227
228
/* @brief method for check if new value for certain attribute is valid
229
* @param[in] key The attribute key
230
* @param[in] value The new value
231
*/
232
virtual bool isValid(SumoXMLAttr key, const std::string& value) = 0;
233
234
/* @brief method for enable attribute
235
* @param[in] key The attribute key
236
* @param[in] undoList The undoList on which to register changes
237
* @note certain attributes can be only enabled, and can produce the disabling of other attributes
238
*/
239
virtual void enableAttribute(SumoXMLAttr key, GNEUndoList* undoList);
240
241
/* @brief method for disable attribute
242
* @param[in] key The attribute key
243
* @param[in] undoList The undoList on which to register changes
244
* @note certain attributes can be only enabled, and can produce the disabling of other attributes
245
*/
246
virtual void disableAttribute(SumoXMLAttr key, GNEUndoList* undoList);
247
248
/* @brief method for check if the value for certain attribute is set
249
* @param[in] key The attribute key
250
*/
251
virtual bool isAttributeEnabled(SumoXMLAttr key) const;
252
253
/* @brief method for check if the value for certain attribute is computed (for example, due a network recomputing)
254
* @param[in] key The attribute key
255
*/
256
virtual bool isAttributeComputed(SumoXMLAttr key) const;
257
258
/* @brief method for check if the value for certain attribute is set
259
* @param[in] key The attribute key
260
*/
261
bool hasAttribute(SumoXMLAttr key) const;
262
263
/// @brief get PopPup ID (Used in AC Hierarchy)
264
virtual std::string getPopUpID() const = 0;
265
266
/// @brief get Hierarchy Name (Used in AC Hierarchy)
267
virtual std::string getHierarchyName() const = 0;
268
269
/// @}
270
271
/// @name Function related with parameters
272
/// @{
273
274
/// @brief set parameters (string vector)
275
void setACParameters(const std::vector<std::pair<std::string, std::string> >& parameters);
276
277
/// @brief set parameters (string vector, undoList)
278
void setACParameters(const std::vector<std::pair<std::string, std::string> >& parameters, GNEUndoList* undoList);
279
280
/// @brief set parameters (map, undoList)
281
void setACParameters(const Parameterised::Map& parameters, GNEUndoList* undoList);
282
283
/// @}
284
285
/* @brief method for return an alternative value for disabled attributes. Used only in GNEFrames
286
* @param[in] key The attribute key
287
*/
288
std::string getAlternativeValueForDisabledAttributes(SumoXMLAttr key) const;
289
290
/// @brief method for getting the attribute in the context of object selection
291
virtual std::string getAttributeForSelection(SumoXMLAttr key) const;
292
293
/// @brief get tag assigned to this object in string format
294
const std::string& getTagStr() const;
295
296
/// @brief get FXIcon associated to this AC
297
FXIcon* getACIcon() const;
298
299
/// @brief check if this AC is template
300
bool isTemplate() const;
301
302
/// @brief get tagProperty associated with this Attribute Carrier
303
const GNETagProperties* getTagProperty() const;
304
305
/// @name parse functions
306
/// @{
307
308
/// @brief true if a value of type T can be parsed from string
309
template<typename T>
310
static bool canParse(const std::string& string);
311
312
/// @brief parses a value of type T from string (used for basic types: int, double, bool, etc.)
313
template<typename T>
314
static T parse(const std::string& string);
315
316
/**@brief true if a value of type T can be parsed from string (requieres network)
317
* @note checkConsecutivity doesn't check connectivity trought connections
318
*/
319
template<typename T>
320
static bool canParse(const GNENet* net, const std::string& value, const bool checkConsecutivity);
321
322
/// @brief parses a complex value of type T from string (use for list of edges, list of lanes, etc.)
323
template<typename T>
324
static T parse(const GNENet* net, const std::string& value);
325
326
/// @brief parses a list of specific Attribute Carriers into a string of IDs
327
template<typename T>
328
static std::string parseIDs(const std::vector<T>& ACs);
329
330
/// @}
331
332
/// @name Functions related with common attributes
333
/// @{
334
/* @brief method for getting the common attribute of an XML key
335
* @param[in] key The attribute key
336
* @return string with the value associated to key
337
*/
338
std::string getCommonAttribute(SumoXMLAttr key) const;
339
340
/* @brief method for getting the common attribute of an XML key in double format
341
* @param[in] key The attribute key
342
* @return double with the value associated to key
343
*/
344
double getCommonAttributeDouble(SumoXMLAttr key) const;
345
346
/* @brief method for getting the common attribute of an XML key in position format
347
* @param[in] key The attribute key
348
* @return double with the value associated to key
349
*/
350
Position getCommonAttributePosition(SumoXMLAttr key) const;
351
352
/* @brief method for getting the common attribute of an XML key in positionVector format
353
* @param[in] key The attribute key
354
* @return double with the value associated to key
355
*/
356
PositionVector getCommonAttributePositionVector(SumoXMLAttr key) const;
357
358
/* @brief method for setting the common attribute and letting the object perform additional changes
359
* @param[in] key The attribute key
360
* @param[in] value The new value
361
* @param[in] undoList The undoList on which to register changes
362
*/
363
void setCommonAttribute(SumoXMLAttr key, const std::string& value, GNEUndoList* undoList);
364
365
/* @brief method for check if new value for certain common attribute is valid
366
* @param[in] key The attribute key
367
* @param[in] value The new value
368
*/
369
bool isCommonAttributeValid(SumoXMLAttr key, const std::string& value) const;
370
371
/// @brief method for setting the common attribute and nothing else (used in GNEChange_Attribute)
372
void setCommonAttribute(SumoXMLAttr key, const std::string& value);
373
374
/// @}
375
376
/// @name Certain attributes and ACs (for example, connections) can be either loaded or guessed. The following static variables are used to remark it.
377
/// @{
378
379
/// @brief feature is still unchanged after being loaded (implies approval)
380
static const std::string FEATURE_LOADED;
381
382
/// @brief feature has been reguessed (may still be unchanged be we can't tell (yet)
383
static const std::string FEATURE_GUESSED;
384
385
/// @brief feature has been manually modified (implies approval)
386
static const std::string FEATURE_MODIFIED;
387
388
/// @brief feature has been approved but not changed (i.e. after being reguessed)
389
static const std::string FEATURE_APPROVED;
390
391
/// @}
392
393
/// @brief true value in string format (used for comparing boolean values in getAttribute(...))
394
static const std::string TRUE_STR;
395
396
/// @brief true value in string format(used for comparing boolean values in getAttribute(...))
397
static const std::string FALSE_STR;
398
399
protected:
400
/// @brief reference to tagProperty associated with this attribute carrier
401
const GNETagProperties* myTagProperty;
402
403
/// @brief pointer to net
404
GNENet* myNet = nullptr;
405
406
/// @brief boolean to check if this AC is selected (more quickly as checking GUIGlObjectStorage)
407
bool mySelected = false;
408
409
/// @brief boolean to check if drawn this AC over other elements
410
bool myDrawInFront = false;
411
412
/// @brief boolean to check if this AC is in grid
413
bool myInGrid = false;
414
415
/// @brief filebucket vinculated whith this AC
416
FileBucket* myFileBucket = nullptr;
417
418
/// @brief boolean to check if center this element after creation
419
bool myCenterAfterCreation = true;
420
421
/// @brief whether the current object is a template object (used for edit attributes)
422
const bool myIsTemplate = false;
423
424
/// @brief method for enable or disable the attribute and nothing else (used in GNEChange_ToggleAttribute)
425
virtual void toggleAttribute(SumoXMLAttr key, const bool value);
426
427
private:
428
/// @brief method for setting the attribute and nothing else (used in GNEChange_Attribute)
429
virtual void setAttribute(SumoXMLAttr key, const std::string& value) = 0;
430
431
/// @brief Invalidated copy constructor.
432
GNEAttributeCarrier(const GNEAttributeCarrier&) = delete;
433
434
/// @brief Invalidated assignment operator
435
GNEAttributeCarrier& operator=(const GNEAttributeCarrier& src) = delete;
436
};
437
438