Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
eclipse
GitHub Repository: eclipse/sumo
Path: blob/main/src/netedit/GNEAttributeProperties.h
169666 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 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
NO_PROPERTY = 1 << 26, // No property defined
69
};
70
71
/// @brief enum class with all edit modes
72
enum class Edit : int {
73
CREATEMODE = 1 << 0, // Attribute can be modified in create mode
74
EDITMODE = 1 << 1, // Attribute can be modified in edit mode
75
NETEDITEDITOR = 1 << 2, // Attribute can be edited only in netedit editor
76
EXTENDEDEDITOR = 1 << 3, // Attribute cannot be edited in editor, but is editable in extended Dialog
77
GEOEDITOR = 1 << 4, // Attribute can be edited only in geo editor
78
FLOWEDITOR = 1 << 5, // Attribute can be edited only in flow editor
79
DIALOGEDITOR = 1 << 6, // Attribute can be edited in dialog editor
80
NO_EDIT = 1 << 7, // No edit property defined
81
};
82
83
/// @brief parameter constructor for attribute properties without default values
84
GNEAttributeProperties(GNETagProperties* tagProperties, const SumoXMLAttr attribute, const Property attributeProperty,
85
const Edit editProperty, const std::string& definition);
86
87
/// @brief parameter constructor for attribute properties with default values specific
88
GNEAttributeProperties(GNETagProperties* tagProperties, const SumoXMLAttr attribute, const Property attributeProperty,
89
const Edit editProperty, const std::string& definition, const std::string& defaultValue);
90
91
/// @brief parameter constructor for attribute properties with default values generic
92
GNEAttributeProperties(GNETagProperties* tagProperties, const SumoXMLAttr attribute, const Property attributeProperty,
93
const Edit editProperty, const std::string& definition, const std::string& defaultValueMask,
94
const std::string& defaultValue);
95
96
/// @brief parameter constructor for special attribute properties (ej: no common)
97
GNEAttributeProperties(GNETagProperties* tagProperties, const SumoXMLAttr attribute, const std::string& definition);
98
99
/// @brief destructor
100
~GNEAttributeProperties();
101
102
/// @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)
103
void checkAttributeIntegrity() const;
104
105
/// @brief set discrete values
106
void setDiscreteValues(const std::vector<std::string>& discreteValues);
107
108
/// @brief set discrete values
109
void setFilenameExtensions(const std::vector<std::string>& extensions);
110
111
/// @brief set default activated value
112
void setDefaultActivated(const bool value);
113
114
/// @brief set synonim
115
void setSynonym(const SumoXMLAttr synonym);
116
117
/// @brief set range
118
void setRange(const double minimum, const double maximum);
119
120
/// @brief set tag property parent
121
void setTagPropertyParent(GNETagProperties* tagPropertyParent);
122
123
/// @brief set alternative name
124
void setAlternativeName(const std::string& alternativeName);
125
126
/// @brief get XML Attribute
127
SumoXMLAttr getAttr() const;
128
129
/// @brief get XML Attribute in string format (can be updated using alternative name)
130
const std::string& getAttrStr() const;
131
132
/// @brief get reference to tagProperty parent
133
const GNETagProperties* getTagPropertyParent() const;
134
135
/// @brief get position in list (used in frames for listing attributes with certain sort)
136
int getPositionListed() const;
137
138
/// @brief get default value
139
const std::string& getDefinition() const;
140
141
/// @brief get default value in string format
142
const std::string& getDefaultStringValue() const;
143
144
/// @brief get default int value
145
int getDefaultIntValue() const;
146
147
/// @brief get default double value
148
double getDefaultDoubleValue() const;
149
150
/// @brief get default time value
151
SUMOTime getDefaultTimeValue() const;
152
153
/// @brief get default bool value
154
bool getDefaultBoolValue() const;
155
156
/// @brief get default bool value
157
const RGBColor& getDefaultColorValue() const;
158
159
/// @brief get default position value
160
const Position& getDefaultPositionValue() const;
161
162
/// @brief get default active value
163
bool getDefaultActivated() const;
164
165
/// @brief return category (based on Edit)
166
std::string getCategory() const;
167
168
/// @brief return a description of attribute
169
std::string getDescription() const;
170
171
/// @brief get discrete values
172
const std::vector<std::string>& getDiscreteValues() const;
173
174
/// @brief get filename extensions in string format used in open dialogs
175
const std::vector<std::string>& getFilenameExtensions() const;
176
177
/// @brief get tag synonym
178
SumoXMLAttr getAttrSynonym() const;
179
180
/// @brief get minimum range
181
double getMinimumRange() const;
182
183
/// @brief get maximum range
184
double getMaximumRange() const;
185
186
/// @brief return true if attribute owns a default value
187
bool hasDefaultValue() const;
188
189
/// @brief return true if Attr correspond to an element that will be written in XML with another name
190
bool hasAttrSynonym() const;
191
192
/// @brief return true if Attr correspond to an element that only accept a range of values
193
bool hasAttrRange() const;
194
195
/// @brief return true if attribute is an integer
196
bool isInt() const;
197
198
/// @brief return true if attribute is a float
199
bool isFloat() const;
200
201
/// @brief return true if attribute is a SUMOTime
202
bool isSUMOTime() const;
203
204
/// @brief return true if attribute is boolean
205
bool isBool() const;
206
207
/// @brief return true if attribute is a string
208
bool isString() const;
209
210
/// @brief return true if attribute is a position
211
bool isPosition() const;
212
213
/// @brief return true if attribute is a probability
214
bool isProbability() const;
215
216
/// @brief return true if attribute is an angle
217
bool isAngle() const;
218
219
/// @brief return true if attribute is numerical (int or float)
220
bool isNumerical() const;
221
222
/// @brief return true if attribute is positive
223
bool isPositive() const;
224
225
/// @brief return true if attribute is a color
226
bool isColor() const;
227
228
/// @brief return true if attribute is a VType or vTypeDistribution
229
bool isVType() const;
230
231
/// @brief return true if attribute is a filename open
232
bool isFileOpen() const;
233
234
/// @brief return true if attribute is a filename save
235
bool isFileSave() const;
236
237
/// @brief return true if attribute is a VehicleClass
238
bool isVClass() const;
239
240
/// @brief return true if attribute is a VehicleClass
241
bool isSVCPermission() const;
242
243
/// @brief return true if attribute is a list
244
bool isList() const;
245
246
/// @brief return true if attribute is sequential
247
bool isSecuential() const;
248
249
/// @brief return true if attribute is unique
250
bool isUnique() const;
251
252
/// @brief return true if attribute is discrete
253
bool isDiscrete() const;
254
255
/// @brief return true if attribute requires a update geometry in setAttribute(...)
256
bool requireUpdateGeometry() const;
257
258
/// @brief return true if attribute is activatable
259
bool isActivatable() const;
260
261
/// @brief return true if attribute is part of a flow definition
262
bool isFlow() const;
263
264
/// @brief return true if attribute is copyable
265
bool isCopyable() const;
266
267
/// @brief return true if attribute is always enabled
268
bool isAlwaysEnabled() const;
269
270
/// @name edit modes
271
/// @{
272
273
/// @brief return true if this attribute can be edited in basic editor
274
bool isBasicEditor() const;
275
276
/// @brief return true if this attribute cannot be edited in editor
277
bool isExtendedEditor() const;
278
279
/// @brief return true if this attribute can be edited only in GEO editor
280
bool isGeoEditor() const;
281
282
/// @brief return true if this attribute can be edited only in flow editor
283
bool isFlowEditor() const;
284
285
/// @brief return true if this attribute can be edited only in netedit editor
286
bool isNeteditEditor() const;
287
288
/// @brief return true if attribute can be modified in create mode
289
bool isCreateMode() const;
290
291
/// @brief return true if attribute can be modified in edit mode
292
bool isEditMode() const;
293
294
/// @brief return true if attribute can be modified in dialog editor
295
bool isDialogEditor() const;
296
297
/// @}
298
299
private:
300
/// @brief pointer to tagProperty parent
301
const GNETagProperties* myTagPropertyParent;
302
303
/// @brief XML Attribute
304
SumoXMLAttr myAttribute = SUMO_ATTR_NOTHING;
305
306
/// @brief string with the Attribute in text format (to avoid unnecesaries toStrings(...) calls)
307
std::string myAttrStr;
308
309
/// @brief attribute properties
310
Property myAttributeProperty = Property::NO_PROPERTY;
311
312
/// @brief edit properties
313
Edit myEditProperty = Edit::NO_EDIT;
314
315
/// @brief text with a definition of attribute
316
std::string myDefinition;
317
318
/// @brief default string value
319
std::string myDefaultStringValue;
320
321
/// @brief default int value
322
int myDefaultIntValue = 0;
323
324
/// @brief default double value
325
double myDefaultDoubleValue = 0;
326
327
/// @brief default time value
328
SUMOTime myDefaultTimeValue = 0;
329
330
/// @brief default bool value
331
bool myDefaultBoolValue = false;
332
333
/// @brief get default bool value
334
RGBColor myDefaultColorValue = RGBColor::INVISIBLE;
335
336
/// @brief get default position value
337
Position myDefaultPositionValue = Position::INVALID;
338
339
/// @brief default activated (by default false)
340
bool myDefaultActivated = false;
341
342
/// @brief discrete values that can take this Attribute (by default empty)
343
std::vector<std::string> myDiscreteValues;
344
345
/// @brief filename extensions used in open dialogs (by default empty)
346
std::vector<std::string> myFilenameExtensions;
347
348
/// @brief Attribute written in XML (If is SUMO_ATTR_NOTHING), original Attribute will be written)
349
SumoXMLAttr myAttrSynonym = SUMO_ATTR_NOTHING;
350
351
/// @brief minimun Range
352
double myMinimumRange = 0;
353
354
/// @brief maxium Range
355
double myMaximumRange = 0;
356
357
/// @brief check build constraints
358
void checkBuildConstraints() const;
359
360
/// @brief parse default values
361
void parseDefaultValues(const std::string& defaultValue, const bool overWritteDefaultString);
362
363
/// @brief invalidate default constructor
364
GNEAttributeProperties() = delete;
365
366
/// @brief Invalidated copy constructor.
367
GNEAttributeProperties(const GNEAttributeProperties&) = delete;
368
369
/// @brief Invalidated assignment operator
370
GNEAttributeProperties& operator=(const GNEAttributeProperties& src) = delete;
371
};
372
373
/// @brief override attribute parent bit operator
374
constexpr GNEAttributeProperties::Property operator|(GNEAttributeProperties::Property a, GNEAttributeProperties::Property b) {
375
return static_cast<GNEAttributeProperties::Property>(static_cast<int>(a) | static_cast<int>(b));
376
}
377
378
/// @brief override attribute parent bit operator
379
constexpr bool operator&(GNEAttributeProperties::Property a, GNEAttributeProperties::Property b) {
380
return (static_cast<int>(a) & static_cast<int>(b)) != 0;
381
}
382
383
/// @brief override attribute parent bit operator
384
constexpr GNEAttributeProperties::Edit operator|(GNEAttributeProperties::Edit a, GNEAttributeProperties::Edit b) {
385
return static_cast<GNEAttributeProperties::Edit>(static_cast<int>(a) | static_cast<int>(b));
386
}
387
388
/// @brief override attribute parent bit operator
389
constexpr bool operator&(GNEAttributeProperties::Edit a, GNEAttributeProperties::Edit b) {
390
return (static_cast<int>(a) & static_cast<int>(b)) != 0;
391
}
392
393
/****************************************************************************/
394
395