Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
eclipse
GitHub Repository: eclipse/sumo
Path: blob/main/src/netedit/GNEAttributeProperties.h
193904 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 GNEAttributeProperties.h
15
/// @author Pablo Alvarez Lopez
16
/// @date Jan 2020
17
///
18
// Abstract Base class for attribute properties used in GNEAttributeCarrier
19
/****************************************************************************/
20
#pragma once
21
#include <config.h>
22
23
#include <utils/geom/Position.h>
24
#include <utils/xml/SUMOSAXAttributes.h>
25
26
// ===========================================================================
27
// class declarations
28
// ===========================================================================
29
30
class GNETagProperties;
31
32
// ===========================================================================
33
// class definitions
34
// ===========================================================================
35
36
class GNEAttributeProperties {
37
38
public:
39
40
/// @brief enum class with all attribute properties
41
enum class Property : int {
42
INT = 1 << 0, // Attribute is an integer (Including Zero)
43
FLOAT = 1 << 1, // Attribute is a float
44
SUMOTIME = 1 << 2, // Attribute is a SUMOTime
45
BOOL = 1 << 3, // Attribute is boolean (0/1, true/false)
46
STRING = 1 << 4, // Attribute is a string
47
POSITION = 1 << 5, // Attribute is a position defined by doubles (x,y or x,y,z)
48
COLOR = 1 << 6, // Attribute is a color defined by a specifically word (Red, green) or by a special format (XXX,YYY,ZZZ)
49
VTYPE = 1 << 7, // Attribute corresponds to a Vtype or VTypeDistribution
50
VCLASS = 1 << 8, // Attribute is a VClass (passenger, bus, motorcicle...)
51
POSITIVE = 1 << 9, // Attribute is positive (Including Zero)
52
UNIQUE = 1 << 10, // Attribute is unique (cannot be edited in a selection of similar elements (ID, Position...)
53
FILEOPEN = 1 << 11, // Attribute is a filename that opens an existent file
54
FILESAVE = 1 << 12, // Attribute is a filename that can create a new file
55
DISCRETE = 1 << 13, // Attribute is discrete (only certain values are allowed)
56
PROBABILITY = 1 << 14, // Attribute is probability (only allowed values between 0 and 1, including both)
57
ANGLE = 1 << 15, // Attribute is an angle (only takes values between 0 and 360, including both, another value will be automatically reduced
58
LIST = 1 << 16, // Attribute is a list of other elements separated by spaces
59
SECUENCIAL = 1 << 17, // Attribute is a special sequence of elements (for example: secuencial lanes in Multi Lane E2 detectors)
60
DEFAULTVALUE = 1 << 18, // Attribute owns a static default value
61
SYNONYM = 1 << 19, // Attribute will be written with a different name in der XML
62
RANGE = 1 << 20, // Attribute only accept a range of elements (example: Probability [0,1])
63
UPDATEGEOMETRY = 1 << 21, // Attribute require update geometry at the end of function setAttribute(...)
64
ACTIVATABLE = 1 << 22, // Attribute can be switch on/off using a checkbox in frame
65
FLOW = 1 << 23, // Attribute is part of a flow definition (Number, vehsPerHour...)
66
COPYABLE = 1 << 24, // Attribute can be copied over other element with the same tagProperty (used for edge/lane templates)
67
ALWAYSENABLED = 1 << 25, // Attribute cannot be disabled
68
SORTABLE = 1 << 26, // Attribute can be used for sort elements in dialog
69
NO_PROPERTY = 1 << 27, // No property defined
70
};
71
72
/// @brief enum class with all edit modes
73
enum class Edit : int {
74
CREATEMODE = 1 << 0, // Attribute can be modified in create mode
75
EDITMODE = 1 << 1, // Attribute can be modified in edit mode
76
NETEDITEDITOR = 1 << 2, // Attribute can be edited only in netedit editor
77
EXTENDEDEDITOR = 1 << 3, // Attribute cannot be edited in editor, but is editable in extended Dialog
78
GEOEDITOR = 1 << 4, // Attribute can be edited only in geo editor
79
FLOWEDITOR = 1 << 5, // Attribute can be edited only in flow editor
80
DIALOGEDITOR = 1 << 6, // Attribute can be edited in dialog editor
81
NO_EDIT = 1 << 7, // No edit property defined
82
};
83
84
/// @brief parameter constructor for attribute properties without default values
85
GNEAttributeProperties(GNETagProperties* tagProperties, const SumoXMLAttr attribute, const Property attributeProperty,
86
const Edit editProperty, const std::string& definition);
87
88
/// @brief parameter constructor for attribute properties with default values specific
89
GNEAttributeProperties(GNETagProperties* tagProperties, const SumoXMLAttr attribute, const Property attributeProperty,
90
const Edit editProperty, const std::string& definition, const std::string& defaultValue);
91
92
/// @brief parameter constructor for attribute properties with default values generic
93
GNEAttributeProperties(GNETagProperties* tagProperties, const SumoXMLAttr attribute, const Property attributeProperty,
94
const Edit editProperty, const std::string& definition, const std::string& defaultValueMask,
95
const std::string& defaultValue);
96
97
/// @brief parameter constructor for special attribute properties (ej: no common)
98
GNEAttributeProperties(GNETagProperties* tagProperties, const SumoXMLAttr attribute, const std::string& definition);
99
100
/// @brief destructor
101
~GNEAttributeProperties();
102
103
/// @brief check Attribute integrity (For example, throw an exception if tag has a Float default value, but given default value cannot be parse to float)
104
void checkAttributeIntegrity() const;
105
106
/// @brief set discrete values
107
void setDiscreteValues(const std::vector<std::string>& discreteValues);
108
109
/// @brief set discrete values
110
void setFilenameExtensions(const std::vector<std::string>& extensions);
111
112
/// @brief set default activated value
113
void setDefaultActivated(const bool value);
114
115
/// @brief set synonim
116
void setSynonym(const SumoXMLAttr synonym);
117
118
/// @brief set range
119
void setRange(const double minimum, const double maximum);
120
121
/// @brief set tag property parent
122
void setTagPropertyParent(GNETagProperties* tagPropertyParent);
123
124
/// @brief set alternative name
125
void setAlternativeName(const std::string& alternativeName);
126
127
/// @brief get XML Attribute
128
SumoXMLAttr getAttr() const;
129
130
/// @brief get XML Attribute in string format (can be updated using alternative name)
131
const std::string& getAttrStr() const;
132
133
/// @brief get reference to tagProperty parent
134
const GNETagProperties* getTagPropertyParent() const;
135
136
/// @brief get position in list (used in frames for listing attributes with certain sort)
137
int getPositionListed() const;
138
139
/// @brief get default value
140
const std::string& getDefinition() const;
141
142
/// @brief get default value in string format
143
const std::string& getDefaultStringValue() const;
144
145
/// @brief get default int value
146
int getDefaultIntValue() const;
147
148
/// @brief get default double value
149
double getDefaultDoubleValue() const;
150
151
/// @brief get default time value
152
SUMOTime getDefaultTimeValue() const;
153
154
/// @brief get default bool value
155
bool getDefaultBoolValue() const;
156
157
/// @brief get default bool value
158
const RGBColor& getDefaultColorValue() const;
159
160
/// @brief get default position value
161
const Position& getDefaultPositionValue() const;
162
163
/// @brief get default active value
164
bool getDefaultActivated() const;
165
166
/// @brief return category (based on Edit)
167
std::string getCategory() const;
168
169
/// @brief return a description of attribute
170
std::string getDescription() const;
171
172
/// @brief get discrete values
173
const std::vector<std::string>& getDiscreteValues() const;
174
175
/// @brief get filename extensions in string format used in open dialogs
176
const std::vector<std::string>& getFilenameExtensions() const;
177
178
/// @brief get tag synonym
179
SumoXMLAttr getAttrSynonym() const;
180
181
/// @brief get minimum range
182
double getMinimumRange() const;
183
184
/// @brief get maximum range
185
double getMaximumRange() const;
186
187
/// @brief return true if attribute owns a default value
188
bool hasDefaultValue() const;
189
190
/// @brief return true if Attr correspond to an element that will be written in XML with another name
191
bool hasAttrSynonym() const;
192
193
/// @brief return true if Attr correspond to an element that only accept a range of values
194
bool hasAttrRange() const;
195
196
/// @brief return true if attribute is an integer
197
bool isInt() const;
198
199
/// @brief return true if attribute is a float
200
bool isFloat() const;
201
202
/// @brief return true if attribute is a SUMOTime
203
bool isSUMOTime() const;
204
205
/// @brief return true if attribute is boolean
206
bool isBool() const;
207
208
/// @brief return true if attribute is a string
209
bool isString() const;
210
211
/// @brief return true if attribute is a position
212
bool isPosition() const;
213
214
/// @brief return true if attribute is a probability
215
bool isProbability() const;
216
217
/// @brief return true if attribute is an angle
218
bool isAngle() const;
219
220
/// @brief return true if attribute is numerical (int or float)
221
bool isNumerical() const;
222
223
/// @brief return true if attribute is positive
224
bool isPositive() const;
225
226
/// @brief return true if attribute is a color
227
bool isColor() const;
228
229
/// @brief return true if attribute is a VType or vTypeDistribution
230
bool isVType() const;
231
232
/// @brief return true if attribute is a filename open
233
bool isFileOpen() const;
234
235
/// @brief return true if attribute is a filename save
236
bool isFileSave() const;
237
238
/// @brief return true if attribute is a VehicleClass
239
bool isVClass() const;
240
241
/// @brief return true if attribute is a VehicleClass
242
bool isSVCPermission() const;
243
244
/// @brief return true if attribute is a list
245
bool isList() const;
246
247
/// @brief return true if attribute is sequential
248
bool isSecuential() const;
249
250
/// @brief return true if attribute is unique
251
bool isUnique() const;
252
253
/// @brief return true if attribute is discrete
254
bool isDiscrete() const;
255
256
/// @brief return true if attribute requires a update geometry in setAttribute(...)
257
bool requireUpdateGeometry() const;
258
259
/// @brief return true if attribute is activatable
260
bool isActivatable() const;
261
262
/// @brief return true if attribute is part of a flow definition
263
bool isFlow() const;
264
265
/// @brief return true if attribute is copyable
266
bool isCopyable() const;
267
268
/// @brief return true if attribute is always enabled
269
bool isAlwaysEnabled() const;
270
271
/// @brief return true if attribute can be used for sorting elements in dialogs
272
bool isSortable() const;
273
274
/// @name edit modes
275
/// @{
276
277
/// @brief return true if this attribute can be edited in basic editor
278
bool isBasicEditor() const;
279
280
/// @brief return true if this attribute cannot be edited in editor
281
bool isExtendedEditor() const;
282
283
/// @brief return true if this attribute can be edited only in GEO editor
284
bool isGeoEditor() const;
285
286
/// @brief return true if this attribute can be edited only in flow editor
287
bool isFlowEditor() const;
288
289
/// @brief return true if this attribute can be edited only in netedit editor
290
bool isNeteditEditor() const;
291
292
/// @brief return true if attribute can be modified in create mode
293
bool isCreateMode() const;
294
295
/// @brief return true if attribute can be modified in edit mode
296
bool isEditMode() const;
297
298
/// @brief return true if attribute can be modified in dialog editor
299
bool isDialogEditor() const;
300
301
/// @}
302
303
private:
304
/// @brief pointer to tagProperty parent
305
const GNETagProperties* myTagPropertyParent;
306
307
/// @brief XML Attribute
308
SumoXMLAttr myAttribute = SUMO_ATTR_NOTHING;
309
310
/// @brief string with the Attribute in text format (to avoid unnecesaries toStrings(...) calls)
311
std::string myAttrStr;
312
313
/// @brief attribute properties
314
Property myAttributeProperty = Property::NO_PROPERTY;
315
316
/// @brief edit properties
317
Edit myEditProperty = Edit::NO_EDIT;
318
319
/// @brief text with a definition of attribute
320
std::string myDefinition;
321
322
/// @brief default string value
323
std::string myDefaultStringValue;
324
325
/// @brief default int value
326
int myDefaultIntValue = 0;
327
328
/// @brief default double value
329
double myDefaultDoubleValue = 0;
330
331
/// @brief default time value
332
SUMOTime myDefaultTimeValue = 0;
333
334
/// @brief default bool value
335
bool myDefaultBoolValue = false;
336
337
/// @brief get default bool value
338
RGBColor myDefaultColorValue = RGBColor::INVISIBLE;
339
340
/// @brief get default position value
341
Position myDefaultPositionValue = Position::INVALID;
342
343
/// @brief default activated (by default false)
344
bool myDefaultActivated = false;
345
346
/// @brief discrete values that can take this Attribute (by default empty)
347
std::vector<std::string> myDiscreteValues;
348
349
/// @brief filename extensions used in open dialogs (by default empty)
350
std::vector<std::string> myFilenameExtensions;
351
352
/// @brief Attribute written in XML (If is SUMO_ATTR_NOTHING), original Attribute will be written)
353
SumoXMLAttr myAttrSynonym = SUMO_ATTR_NOTHING;
354
355
/// @brief minimun Range
356
double myMinimumRange = 0;
357
358
/// @brief maxium Range
359
double myMaximumRange = 0;
360
361
/// @brief check build constraints
362
void checkBuildConstraints() const;
363
364
/// @brief parse default values
365
void parseDefaultValues(const std::string& defaultValue, const bool overWritteDefaultString);
366
367
/// @brief invalidate default constructor
368
GNEAttributeProperties() = delete;
369
370
/// @brief Invalidated copy constructor.
371
GNEAttributeProperties(const GNEAttributeProperties&) = delete;
372
373
/// @brief Invalidated assignment operator
374
GNEAttributeProperties& operator=(const GNEAttributeProperties& src) = delete;
375
};
376
377
/// @brief override attribute parent bit operator
378
constexpr GNEAttributeProperties::Property operator|(GNEAttributeProperties::Property a, GNEAttributeProperties::Property b) {
379
return static_cast<GNEAttributeProperties::Property>(static_cast<int>(a) | static_cast<int>(b));
380
}
381
382
/// @brief override attribute parent bit operator
383
constexpr bool operator&(GNEAttributeProperties::Property a, GNEAttributeProperties::Property b) {
384
return (static_cast<int>(a) & static_cast<int>(b)) != 0;
385
}
386
387
/// @brief override attribute parent bit operator
388
constexpr GNEAttributeProperties::Edit operator|(GNEAttributeProperties::Edit a, GNEAttributeProperties::Edit b) {
389
return static_cast<GNEAttributeProperties::Edit>(static_cast<int>(a) | static_cast<int>(b));
390
}
391
392
/// @brief override attribute parent bit operator
393
constexpr bool operator&(GNEAttributeProperties::Edit a, GNEAttributeProperties::Edit b) {
394
return (static_cast<int>(a) & static_cast<int>(b)) != 0;
395
}
396
397
/****************************************************************************/
398
399