Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
eclipse
GitHub Repository: eclipse/sumo
Path: blob/main/src/netedit/elements/data/GNEDataSet.h
194300 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 GNEDataSet.h
15
/// @author Pablo Alvarez Lopez
16
/// @date Jan 2020
17
///
18
// A abstract class for data elements
19
/****************************************************************************/
20
#pragma once
21
#include <config.h>
22
23
#include <netedit/elements/GNEAttributeCarrier.h>
24
#include <netedit/elements/GNEHierarchicalElement.h>
25
#include <utils/common/Parameterised.h>
26
27
// ===========================================================================
28
// class declarations
29
// ===========================================================================
30
31
class GNENet;
32
class GNEDataInterval;
33
34
// ===========================================================================
35
// class definitions
36
// ===========================================================================
37
38
class GNEDataSet : public GNEAttributeCarrier, public GNEHierarchicalElement {
39
40
public:
41
/// @brief attribute colors
42
class AttributeColors {
43
44
public:
45
/// @brief default constructor
46
AttributeColors();
47
48
/// @brief update value for an specific attribute
49
void updateValues(const std::string& attribute, const double value);
50
51
/// @brief update value for all attributes
52
void updateAllValues(const AttributeColors& attributeColors);
53
54
/// @brief check if given attribute exist (needed for non-double attributes)
55
bool exist(const std::string& attribute) const;
56
57
/// @brief get minimum value
58
double getMinValue(const std::string& attribute) const;
59
60
/// @brief get maximum value
61
double getMaxValue(const std::string& attribute) const;
62
63
/// @brief clear AttributeColors
64
void clear();
65
66
private:
67
/// @brief map with the minimum and maximum value
68
std::map<std::string, std::pair<double, double> > myMinMaxValue;
69
70
/// @brief Invalidated assignment operator.
71
AttributeColors& operator=(const AttributeColors&) = delete;
72
};
73
74
/**@brief Constructor
75
* @param[in] net pointer to GNEViewNet of this data element element belongs
76
*/
77
GNEDataSet(GNENet* net);
78
79
/**@brief Constructor
80
* @param[in] net pointer to GNEViewNet of this data element element belongs
81
* @param[in] dataSetID data set ID
82
* @param[in] fileBucket file in which this element is stored
83
*/
84
GNEDataSet(const std::string& dataSetID, GNENet* net, FileBucket* fileBucket);
85
86
/// @brief Destructor
87
~GNEDataSet();
88
89
/// @brief methods to retrieve the elements linked to this dataSet
90
/// @{
91
92
/// @brief get GNEHierarchicalElement associated with this dataSet
93
GNEHierarchicalElement* getHierarchicalElement() override;
94
95
/// @brief get GNEMoveElement associated with this dataSet
96
GNEMoveElement* getMoveElement() const override;
97
98
/// @brief get parameters associated with this dataSet
99
Parameterised* getParameters() override;
100
101
/// @brief get parameters associated with this dataSet (constant)
102
const Parameterised* getParameters() const override;
103
104
/// @brief get GUIGlObject associated with this dataSet
105
GUIGlObject* getGUIGlObject() override;
106
107
/// @brief get GUIGlObject associated with this dataSet (constant)
108
const GUIGlObject* getGUIGlObject() const override;
109
110
/// @}
111
112
/// @brief get reference to fileBucket in which save this AC
113
FileBucket* getFileBucket() const override;
114
115
/// @brief update attribute colors deprecated
116
void updateAttributeColors();
117
118
/// @brief all attribute colors
119
const GNEDataSet::AttributeColors& getAllAttributeColors() const;
120
121
/// @brief specific attribute colors
122
const std::map<SumoXMLTag, GNEDataSet::AttributeColors>& getSpecificAttributeColors() const;
123
124
/// @brief update pre-computed geometry information
125
void updateGeometry() override;
126
127
/// @brief Returns element position in view
128
Position getPositionInView() const;
129
130
/// @brief write data set
131
void writeDataSet(OutputDevice& device) const;
132
133
/// @name Function related with contour drawing
134
/// @{
135
136
/// @brief check if draw from contour (green)
137
bool checkDrawFromContour() const override;
138
139
/// @brief check if draw from contour (magenta)
140
bool checkDrawToContour() const override;
141
142
/// @brief check if draw related contour (cyan)
143
bool checkDrawRelatedContour() const override;
144
145
/// @brief check if draw over contour (orange)
146
bool checkDrawOverContour() const override;
147
148
/// @brief check if draw delete contour (pink/white)
149
bool checkDrawDeleteContour() const override;
150
151
/// @brief check if draw delete contour small (pink/white)
152
bool checkDrawDeleteContourSmall() const override;
153
154
/// @brief check if draw select contour (blue)
155
bool checkDrawSelectContour() const override;
156
157
/// @brief check if draw move contour (red)
158
bool checkDrawMoveContour() const override;
159
160
/// @}
161
162
/// @name data interval children
163
/// @{
164
165
/// @brief add data interval child
166
void addDataIntervalChild(GNEDataInterval* dataInterval);
167
168
/// @brief add data interval child
169
void removeDataIntervalChild(GNEDataInterval* dataInterval);
170
171
/// @brief check if given data interval exist
172
bool dataIntervalChildrenExist(GNEDataInterval* dataInterval) const;
173
174
/// @brief update data interval begin
175
void updateDataIntervalBegin(const double oldBegin);
176
177
/// @brief check if a new GNEDataInterval with the given begin and end can be inserted in current GNEDataSet
178
bool checkNewInterval(const double newBegin, const double newEnd);
179
180
/// @brief check if new begin or end for given GNEDataInterval is given
181
bool checkNewBeginEnd(const GNEDataInterval* dataInterval, const double newBegin, const double newEnd);
182
183
/// @brief return interval
184
GNEDataInterval* retrieveInterval(const double begin, const double end) const;
185
186
/// @brief get data interval children
187
const std::map<const double, GNEDataInterval*>& getDataIntervalChildren() const;
188
189
/// @}
190
191
/// @name inherited from GNEAttributeCarrier
192
/// @{
193
/* @brief method for getting the Attribute of an XML key
194
* @param[in] key The attribute key
195
* @return string with the value associated to key
196
*/
197
std::string getAttribute(SumoXMLAttr key) const override;
198
199
/* @brief method for getting the Attribute of an XML key in double format (to avoid unnecessary parse<double>(...) for certain attributes)
200
* @param[in] key The attribute key
201
* @return double with the value associated to key
202
*/
203
double getAttributeDouble(SumoXMLAttr key) const override;
204
205
/* @brief method for getting the Attribute of an XML key in position format
206
* @param[in] key The attribute key
207
* @return position with the value associated to key
208
*/
209
Position getAttributePosition(SumoXMLAttr key) const override;
210
211
/* @brief method for getting the Attribute of an XML key in positionVector format
212
* @param[in] key The attribute key
213
* @return positionVector with the value associated to key
214
*/
215
PositionVector getAttributePositionVector(SumoXMLAttr key) const override;
216
217
/**@brief method for setting the attribute and letting the object perform data element changes
218
* @param[in] key The attribute key
219
* @param[in] value The new value
220
* @param[in] undoList The undoList on which to register changes
221
*/
222
void setAttribute(SumoXMLAttr key, const std::string& value, GNEUndoList* undoList) override;
223
224
/**@brief method for checking if the key and their conrrespond attribute are valids
225
* @param[in] key The attribute key
226
* @param[in] value The value associated to key key
227
* @return true if the value is valid, false in other case
228
*/
229
bool isValid(SumoXMLAttr key, const std::string& value) override;
230
231
/// @brief get PopPup ID (Used in AC Hierarchy)
232
std::string getPopUpID() const override;
233
234
/// @brief get Hierarchy Name (Used in AC Hierarchy)
235
std::string getHierarchyName() const override;
236
/// @}
237
238
protected:
239
/// @brief dataSet ID
240
std::string myDataSetID;
241
242
/// @brief map with dataIntervals children sorted by begin
243
std::map<const double, GNEDataInterval*> myDataIntervalChildren;
244
245
/// @brief all attribute colors
246
GNEDataSet::AttributeColors myAllAttributeColors;
247
248
/// @brief specific attribute colors
249
std::map<SumoXMLTag, GNEDataSet::AttributeColors> mySpecificAttributeColors;
250
251
private:
252
/// @brief method for setting the attribute and nothing else (used in GNEChange_Attribute)
253
void setAttribute(SumoXMLAttr key, const std::string& value) override;
254
255
/// @brief check if a new GNEDataInterval with the given begin and end can be inserted in current GNEDataSet
256
static bool checkNewInterval(const std::map<const double, GNEDataInterval*>& dataIntervalMap, const double newBegin, const double newEnd);
257
258
/// @brief Invalidated copy constructor.
259
GNEDataSet(const GNEDataSet&) = delete;
260
261
/// @brief Invalidated assignment operator.
262
GNEDataSet& operator=(const GNEDataSet&) = delete;
263
};
264
265
/****************************************************************************/
266
267