Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
eclipse
GitHub Repository: eclipse/sumo
Path: blob/main/src/netedit/frames/demand/GNEDistributionFrame.h
169684 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 GNEDistributionFrame.h
15
/// @author Pablo Alvarez Lopez
16
/// @date Jun 2023
17
///
18
// The Widget for edit distribution elements
19
/****************************************************************************/
20
#pragma once
21
#include <config.h>
22
23
#include <netedit/frames/GNEFrame.h>
24
#include <utils/xml/SUMOXMLDefinitions.h>
25
26
// ===========================================================================
27
// class definitions
28
// ===========================================================================
29
30
class GNEAttributesEditor;
31
class GNEDemandElement;
32
class MFXComboBoxIcon;
33
class MFXTextFieldIcon;
34
35
// ===========================================================================
36
// class definitions
37
// ===========================================================================
38
39
class GNEDistributionFrame {
40
41
public:
42
// ===========================================================================
43
// class declaration
44
// ===========================================================================
45
46
class DistributionValuesEditor;
47
class DistributionSelector;
48
49
// ===========================================================================
50
// class DistributionEditor
51
// ===========================================================================
52
53
class DistributionEditor : public MFXGroupBoxModule {
54
/// @brief FOX-declaration
55
FXDECLARE(GNEDistributionFrame::DistributionEditor)
56
57
/// @brief declare friend class
58
friend class DistributionValuesEditor;
59
60
public:
61
/// @brief constructor
62
DistributionEditor(GNEFrame* frameParent, SumoXMLTag distributionTag, GUIIcon icon);
63
64
/// @brief destructor
65
~DistributionEditor();
66
67
/// @brief get distribution tag
68
SumoXMLTag getDistributionTag() const;
69
70
/// @name FOX-callbacks
71
/// @{
72
73
/// @brief Called when "create distribution" button is clicked
74
long onCmdCreateDistribution(FXObject*, FXSelector, void*);
75
76
/// @brief Called when "Delete distribution" button is clicked
77
long onCmdDeleteDistribution(FXObject*, FXSelector, void*);
78
79
/// @brief Called when "Delete distribution" button is updated
80
long onUpdDeleteDistribution(FXObject* sender, FXSelector, void*);
81
82
/// @}
83
84
protected:
85
/// @brief FOX needs this
86
FOX_CONSTRUCTOR(DistributionEditor)
87
88
private:
89
/// @brief pointer to frame parent
90
GNEFrame* myFrameParent;
91
92
/// @briuef distribution tag
93
SumoXMLTag myDistributionTag;
94
95
/// @brief distribution selector
96
DistributionSelector* myDistributionSelector = nullptr;
97
98
/// @brief "create Distribution" button
99
MFXButtonTooltip* myCreateDistributionButton = nullptr;
100
101
/// @brief "delete Distribution" button
102
MFXButtonTooltip* myDeleteDistributionButton = nullptr;
103
};
104
105
// ===========================================================================
106
// class DistributionSelector
107
// ===========================================================================
108
109
class DistributionSelector : public MFXGroupBoxModule {
110
/// @brief FOX-declaration
111
FXDECLARE(GNEDistributionFrame::DistributionSelector)
112
113
/// @brief declare friend class
114
friend class DistributionValuesEditor;
115
116
public:
117
/// @brief constructor
118
DistributionSelector(GNEFrame* frameParent);
119
120
/// @brief destructor
121
~DistributionSelector();
122
123
/// @brief refresh modul
124
void setDistribution(GNEDemandElement* distribution);
125
126
/// @brief current distribution
127
GNEDemandElement* getCurrentDistribution() const;
128
129
/// @brief refresh distribution IDs (only call when user change ID in internal attributes)
130
void refreshDistributionIDs();
131
132
/// @brief refresh modul
133
void refreshDistributionSelector();
134
135
/// @name FOX-callbacks
136
/// @{
137
138
/// @brief Called when the user select distribution in ComboBox
139
long onCmdSelectDistribution(FXObject*, FXSelector, void*);
140
141
/// @brief update distribution comboBox
142
long onCmdUpdateDistribution(FXObject* sender, FXSelector, void*);
143
144
/// @}
145
146
protected:
147
/// @brief FOX need this
148
FOX_CONSTRUCTOR(DistributionSelector)
149
150
/// @brief fill distribution comboBox
151
std::map<std::string, GNEDemandElement*> fillDistributionComboBox();
152
153
private:
154
/// @brief pointer to Frame Parent
155
GNEFrame* myFrameParent;
156
157
/// @brief pointer to distribution editor
158
DistributionEditor* myDistributionEditor = nullptr;
159
160
/// @brief attributes editor
161
GNEAttributesEditor* myAttributesEditor = nullptr;
162
163
/// @brief distribution values editor
164
DistributionValuesEditor* myDistributionValuesEditor = nullptr;
165
166
/// @brief comboBox with the list of distributions
167
MFXComboBoxIcon* myDistributionsComboBox = nullptr;
168
169
/// @brief current distribution element
170
GNEDemandElement* myCurrentDistribution = nullptr;
171
};
172
173
// ===========================================================================
174
// class DistributionRow
175
// ===========================================================================
176
177
class DistributionRow : protected FXHorizontalFrame {
178
/// @brief FOX-declaration
179
FXDECLARE(GNEDistributionFrame::DistributionRow)
180
181
public:
182
/// @brief constructor for key-probability attributes
183
DistributionRow(DistributionValuesEditor* attributeEditorParent,
184
const GNEDemandElement* key, const double probability);
185
186
/// @brief destroy DistributionRow (but don't delete)
187
void destroy();
188
189
/// @brief refresh comboBox
190
void refreshRow();
191
192
/// @brief get current probability
193
double getProbability() const;
194
195
/// @name FOX-callbacks
196
/// @{
197
198
/// @brief try to set new key
199
long onCmdSetKey(FXObject*, FXSelector, void*);
200
201
/// @brief try to set new probability
202
long onCmdSetProbability(FXObject*, FXSelector, void*);
203
204
/// @brief remove row
205
long onCmdRemoveRow(FXObject*, FXSelector, void*);
206
207
/// @}
208
209
protected:
210
/// @brief FOX need this
211
FOX_CONSTRUCTOR(DistributionRow)
212
213
/// @brief check if the given ID is valid
214
bool isValidNewKey() const;
215
216
private:
217
/// @brief pointer to DistributionValuesEditor parent
218
DistributionValuesEditor* myDistributionValuesEditorParent;
219
220
/// @brief delete row button
221
MFXButtonTooltip* myDeleteRowButton = nullptr;
222
223
/// @brief label
224
FXLabel* myIconLabel = nullptr;
225
226
/// @brief comboBox with keys
227
MFXComboBoxIcon* myComboBoxKeys = nullptr;
228
229
/// @brief textField to modify the probability attribute
230
MFXTextFieldIcon* myProbabilityTextField = nullptr;
231
232
/// @brief current Key
233
const GNEDemandElement* myKey = nullptr;
234
235
/// @brief current probability
236
double myProbability = 0;
237
};
238
239
// ===========================================================================
240
// class DistributionValuesEditor
241
// ===========================================================================
242
243
class DistributionValuesEditor : public MFXGroupBoxModule {
244
/// @brief FOX-declaration
245
FXDECLARE(GNEDistributionFrame::DistributionValuesEditor)
246
247
/// @brief declare friend class
248
friend class DistributionRow;
249
250
public:
251
/// @brief constructor
252
DistributionValuesEditor(GNEFrame* frameParent, DistributionEditor* distributionEditor,
253
DistributionSelector* distributionSelector,
254
GNEAttributesEditor* attributesEditor,
255
SumoXMLTag distributionValueTag);
256
257
/// @brief show attributes of multiple ACs
258
void showDistributionValuesEditor();
259
260
/// @brief hide attribute editor
261
void hideDistributionValuesEditor();
262
263
/// @brief destroy and remake rows
264
void remakeRows();
265
266
/// @brief refresh rows
267
void refreshRows();
268
269
/// @brief pointer to GNEFrame parent
270
GNEFrame* getFrameParent() const;
271
272
/// @brief update sum label
273
void updateSumLabel();
274
275
/// @name FOX-callbacks
276
/// @{
277
278
/// @brief Called when user press the add button
279
long onCmdAddRow(FXObject*, FXSelector, void*);
280
281
/// @brief Called when sum button button is updated
282
long onUpdAddRow(FXObject* sender, FXSelector, void*);
283
284
/// @}
285
286
protected:
287
/// @brief FOX need this
288
FOX_CONSTRUCTOR(DistributionValuesEditor)
289
290
private:
291
/// @brief pointer to frame parent
292
GNEFrame* myFrameParent;
293
294
/// @brief distribution editor
295
DistributionEditor* myDistributionEditor;
296
297
/// @brief distribution selector
298
DistributionSelector* myDistributionSelector;
299
300
/// @brief attributes editor
301
GNEAttributesEditor* myAttributesEditor;
302
303
/// @brief distribution value tag
304
SumoXMLTag myDistributionValueTag;
305
306
/// @brief list of Attribute editor rows
307
std::vector<DistributionRow*> myDistributionRows;
308
309
/// @brief bot frame
310
FXHorizontalFrame* myBotFrame = nullptr;
311
312
/// @brief sum label
313
FXLabel* mySumLabel = nullptr;
314
};
315
};
316
317