Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
eclipse
GitHub Repository: eclipse/sumo
Path: blob/main/src/netedit/frames/common/GNESelectorFrame.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 GNESelectorFrame.h
15
/// @author Jakob Erdmann
16
/// @date Mar 2011
17
///
18
// The Widget for modifying selections of network-elements
19
// (some elements adapted from GUIDialog_GLChosenEditor)
20
/****************************************************************************/
21
#pragma once
22
#include <config.h>
23
24
#include <unordered_map>
25
#include <netedit/frames/GNEFrame.h>
26
#include <netedit/GNEViewNetHelper.h>
27
#include <utils/foxtools/MFXComboBoxIcon.h>
28
29
// ===========================================================================
30
// class declaration
31
// ===========================================================================
32
33
class GNEAttributeProperties;
34
class GNEMatchAttribute;
35
class GNEMatchGenericDataAttribute;
36
class GNETagProperties;
37
38
// ===========================================================================
39
// class definitions
40
// ===========================================================================
41
/**
42
* @class GNESelectorFrame
43
* The Widget for modifying selections of network-elements
44
*/
45
class GNESelectorFrame : public GNEFrame {
46
47
public:
48
// ===========================================================================
49
// class SelectionInformation
50
// ===========================================================================
51
52
class SelectionInformation : public MFXGroupBoxModule {
53
54
public:
55
/// @brief constructor
56
SelectionInformation(GNESelectorFrame* selectorFrameParent);
57
58
/// @brief destructor
59
~SelectionInformation();
60
61
/// @brief update information label
62
void updateInformationLabel();
63
64
protected:
65
/// @brief update information label
66
void updateInformationLabel(const std::string& element, int number);
67
68
private:
69
/// @brief string for keep information
70
std::string myInformation;
71
72
/// @brief information label
73
FXLabel* myInformationLabel;
74
75
/// @brief pointer to Selector Frame Parent
76
GNESelectorFrame* mySelectorFrameParent;
77
78
/// @brief Invalidated copy constructor.
79
SelectionInformation(const SelectionInformation&) = delete;
80
81
/// @brief Invalidated assignment operator.
82
SelectionInformation& operator=(const SelectionInformation&) = delete;
83
};
84
85
// ===========================================================================
86
// class ModificationMode
87
// ===========================================================================
88
89
class ModificationMode : public MFXGroupBoxModule {
90
/// @brief FOX-declaration
91
FXDECLARE(GNESelectorFrame::ModificationMode)
92
93
public:
94
/// @brief operations of selector
95
enum class Operation {
96
ADD,
97
SUB,
98
RESTRICT,
99
REPLACE,
100
DEFAULT
101
};
102
103
/// @brief constructor
104
ModificationMode(GNESelectorFrame* selectorFrameParent);
105
106
/// @brief destructor
107
~ModificationMode();
108
109
/// @brief get current modification mode
110
Operation getModificationMode() const;
111
112
/// @name FOX-callbacks
113
/// @{
114
/// @brief called when user change type of selection operation
115
long onCmdSelectModificationMode(FXObject*, FXSelector, void*);
116
117
/// @}
118
119
protected:
120
/// @brief FOX need this
121
FOX_CONSTRUCTOR(ModificationMode)
122
123
private:
124
/// @brief add radio button
125
FXRadioButton* myAddRadioButton;
126
127
/// @brief remove radio button
128
FXRadioButton* myRemoveRadioButton;
129
130
/// @brief keep button
131
FXRadioButton* myKeepRadioButton;
132
133
/// @brief replace radio button
134
FXRadioButton* myReplaceRadioButton;
135
136
/// @brief how to modify selection
137
Operation myModificationModeType;
138
139
/// @brief Invalidated copy constructor.
140
ModificationMode(const ModificationMode&) = delete;
141
142
/// @brief Invalidated assignment operator.
143
ModificationMode& operator=(const ModificationMode&) = delete;
144
};
145
146
// ===========================================================================
147
// class VisualScaling
148
// ===========================================================================
149
150
class VisualScaling : public MFXGroupBoxModule {
151
/// @brief FOX-declaration
152
FXDECLARE(GNESelectorFrame::VisualScaling)
153
154
public:
155
/// @brief constructor
156
VisualScaling(GNESelectorFrame* selectorFrameParent);
157
158
/// @brief destructor
159
~VisualScaling();
160
161
/// @name FOX-callbacks
162
/// @{
163
164
/// @brief Called when the user changes visual scaling
165
long onCmdScaleSelection(FXObject*, FXSelector, void*);
166
167
/// @}
168
169
protected:
170
/// @brief FOX need this
171
FOX_CONSTRUCTOR(VisualScaling)
172
173
private:
174
/// @brief pointer to Selector Frame Parent
175
GNESelectorFrame* mySelectorFrameParent;
176
177
/// @brief Spinner for selection scaling
178
FXRealSpinner* mySelectionScaling;
179
180
/// @brief Invalidated copy constructor.
181
VisualScaling(const VisualScaling&) = delete;
182
183
/// @brief Invalidated assignment operator.
184
VisualScaling& operator=(const VisualScaling&) = delete;
185
};
186
187
// ===========================================================================
188
// class SelectionOperation
189
// ===========================================================================
190
191
class SelectionOperation : public MFXGroupBoxModule {
192
/// @brief FOX-declaration
193
FXDECLARE(GNESelectorFrame::SelectionOperation)
194
195
public:
196
/// @brief constructor
197
SelectionOperation(GNESelectorFrame* selectorFrameParent);
198
199
/// @brief destructor
200
~SelectionOperation();
201
202
/// @brief load from file
203
void loadFromFile(const std::string& file) const;
204
205
/// @name FOX-callbacks
206
/// @{
207
208
/**@brief Called when the user presses the Load-button
209
* @note Opens a file dialog and forces the parent to load the list of selected
210
* objects when a file was chosen. Rebuilds the list, then, and redraws itself.
211
*/
212
long onCmdLoad(FXObject*, FXSelector, void*);
213
214
/** @brief Called when the user presses the Save-button
215
* @note Opens a file dialog and forces the selection container to save the list
216
of selected objects when a file was chosen. If the saving failed, a message window is shown.
217
*/
218
long onCmdSave(FXObject*, FXSelector, void*);
219
220
/**@brief Called when the user presses the Clear-button
221
* @note Clear the internal list and calls GUISelectedStorage::clear and repaints itself
222
*/
223
long onCmdClear(FXObject*, FXSelector, void*);
224
225
/**@brief Called when the user presses the delete-button
226
*/
227
long onCmdDelete(FXObject*, FXSelector, void*);
228
229
/**@brief Called when the user presses the Invert-button
230
* @note invert the selection and repaints itself
231
*/
232
long onCmdInvert(FXObject*, FXSelector, void*);
233
234
/**@brief Called when the user presses the Reduce-button
235
* @note Reduce network
236
*/
237
long onCmdReduce(FXObject*, FXSelector, void*);
238
239
/// @}
240
241
protected:
242
/// @brief FOX need this
243
FOX_CONSTRUCTOR(SelectionOperation)
244
245
/// @brief struct used for massive selections
246
struct MassiveSelection {
247
248
/// @brief constructor with bucket size (normally the max number of elements)
249
MassiveSelection(const int bucketSize);
250
251
/// @brief destructor
252
~MassiveSelection();
253
254
/// @brief check if there are element to process
255
bool isElementToProcess() const;
256
257
/// @brief ACs to select (the bool flag shows if element is locked)
258
std::unordered_map<GNEAttributeCarrier*, bool> ACsToSelect;
259
260
/// @brief ACs to select (the bool flag shows if element is locked)
261
std::unordered_map<GNEAttributeCarrier*, bool> ACsToUnselect;
262
263
/// @brief locked types
264
std::map<GUIGlObjectType, bool> lockedTypes;
265
266
private:
267
/// @brief constructor (invalidated)
268
MassiveSelection();
269
};
270
271
/// @brief process massive network element selection
272
MassiveSelection processMassiveNetworkElementSelection(const bool filterLanes) const;
273
274
/// @brief process massive demand element selection
275
MassiveSelection processMassiveDemandElementSelection() const;
276
277
/// @brief process massive dataelement selection
278
MassiveSelection processMassiveDataElementSelection() const;
279
280
/// @brief ask if continue due locking
281
bool askContinueIfLock() const;
282
283
private:
284
/// @brief pointer to Selector Frame Parent
285
GNESelectorFrame* mySelectorFrameParent;
286
287
/// @brief Invalidated copy constructor.
288
SelectionOperation(const SelectionOperation&) = delete;
289
290
/// @brief Invalidated assignment operator.
291
SelectionOperation& operator=(const SelectionOperation&) = delete;
292
};
293
294
// ===========================================================================
295
// class SelectionHierarchy
296
// ===========================================================================
297
298
class SelectionHierarchy : public MFXGroupBoxModule {
299
/// @brief FOX-declaration
300
FXDECLARE(GNESelectorFrame::SelectionHierarchy)
301
302
public:
303
/// @brief constructor
304
SelectionHierarchy(GNESelectorFrame* selectorFrameParent);
305
306
/// @brief destructor
307
~SelectionHierarchy();
308
309
/// @name FOX-callbacks
310
/// @{
311
312
/// @brief called when user select an item in comboBox
313
long onCmdSelectItem(FXObject* obj, FXSelector, void*);
314
315
/// @brief called when user press select/unselect parents button
316
long onCmdParents(FXObject* obj, FXSelector, void*);
317
318
/// @brief called when user press select/unselect children button
319
long onCmdChildren(FXObject* obj, FXSelector, void*);
320
321
/// @}
322
323
protected:
324
/// @brief FOX need this
325
FOX_CONSTRUCTOR(SelectionHierarchy)
326
327
private:
328
/// @brief enum used in comboBox
329
enum class Selection {
330
ALL,
331
JUNCTION,
332
EDGE,
333
LANE,
334
CONNECTION,
335
CROSSING,
336
ADDITIONAL,
337
WIRE,
338
SHAPE,
339
DEMAND,
340
DATA,
341
NOTHING,
342
};
343
344
/// @brief pointer to Selector Frame Parent
345
GNESelectorFrame* mySelectorFrameParent;
346
347
/// @brief comboBox for parents
348
MFXComboBoxIcon* myParentsComboBox = nullptr;
349
350
/// @brief comboBox for children
351
MFXComboBoxIcon* myChildrenComboBox = nullptr;
352
353
/// @brief select parents button
354
FXButton* mySelectParentsButton = nullptr;
355
356
/// @brief unselect parents button
357
FXButton* myUnselectParentsButton = nullptr;
358
359
/// @brief select children button
360
FXButton* mySelectChildrenButton = nullptr;
361
362
/// @brief unselect parents button
363
FXButton* myUnselectChildrenButton = nullptr;
364
365
// @brief items
366
const std::vector<std::pair<Selection, std::string> > myItems = {
367
std::make_pair(Selection::ALL, "all"),
368
std::make_pair(Selection::JUNCTION, "junction"),
369
std::make_pair(Selection::EDGE, "edge"),
370
std::make_pair(Selection::LANE, "lane"),
371
std::make_pair(Selection::CONNECTION, "connection"),
372
std::make_pair(Selection::CROSSING, "crossing"),
373
std::make_pair(Selection::ADDITIONAL, "additionalElements"),
374
std::make_pair(Selection::WIRE, "wireElements"),
375
std::make_pair(Selection::SHAPE, "shapeElements"),
376
std::make_pair(Selection::DEMAND, "demandElements"),
377
std::make_pair(Selection::DATA, "dataElements")
378
};
379
380
/// @brief current selected parent
381
Selection myCurrentSelectedParent;
382
383
/// @brief current selected child
384
Selection myCurrentSelectedChild;
385
386
/// @brief Invalidated copy constructor.
387
SelectionHierarchy(const SelectionHierarchy&) = delete;
388
389
/// @brief Invalidated assignment operator.
390
SelectionHierarchy& operator=(const SelectionHierarchy&) = delete;
391
};
392
393
// ===========================================================================
394
// class Legend
395
// ===========================================================================
396
397
class Information : public MFXGroupBoxModule {
398
399
public:
400
/// @brief constructor
401
Information(GNESelectorFrame* selectorFrameParent);
402
403
/// @brief destructor
404
~Information();
405
};
406
407
/**@brief Constructor
408
* @brief viewParent GNEViewParent in which this GNEFrame is placed
409
* @brief viewNet viewNet that uses this GNEFrame
410
*/
411
GNESelectorFrame(GNEViewParent* viewParent, GNEViewNet* viewNet);
412
413
/// @brief Destructor
414
~GNESelectorFrame();
415
416
/// @brief show Frame
417
void show();
418
419
/// @brief hide Frame
420
void hide();
421
422
/// @brief function called after undo/redo in the current frame
423
void updateFrameAfterUndoRedo();
424
425
/// @brief clear current selection with possibility of undo/redo
426
void clearCurrentSelection() const;
427
428
/**@brief select attribute carrier (element)
429
* @param viewObjects objects under cursors
430
*/
431
bool selectAttributeCarrier(const GNEViewNetHelper::ViewObjectsSelector& viewObjects);
432
433
/**@brief apply list of ids to the current selection according to Operation,
434
* @note if setop==DEFAULT than the currently set mode (myOperation) is used
435
*/
436
void handleIDs(const std::vector<GNEAttributeCarrier*>& ACs, const ModificationMode::Operation setop = ModificationMode::Operation::DEFAULT);
437
438
/// @brief get vertical frame that holds all widgets of frame
439
FXVerticalFrame* getContentFrame() const;
440
441
/// @brief get modification mode modul
442
ModificationMode* getModificationModeModul() const;
443
444
/// @brief get selection operation modul
445
GNESelectorFrame::SelectionOperation* getSelectionOperationModul() const;
446
447
/// @brief get modul for selection information
448
SelectionInformation* getSelectionInformation() const;
449
450
private:
451
/// @brief modul for selection information
452
GNESelectorFrame::SelectionInformation* mySelectionInformation = nullptr;
453
454
/// @brief modul for change modification mode
455
GNESelectorFrame::ModificationMode* myModificationMode = nullptr;
456
457
/// @brief modul for match attribute
458
GNEMatchAttribute* myMatchAttribute = nullptr;
459
460
/// @brief modul for visual scaling
461
GNESelectorFrame::VisualScaling* myVisualScaling = nullptr;
462
463
/// @brief modul for selection operations
464
GNESelectorFrame::SelectionOperation* mySelectionOperation = nullptr;
465
466
/// @brief modul for selection hierarchy
467
GNESelectorFrame::SelectionHierarchy* mySelectionHierarchy = nullptr;
468
469
/// @brief information modul
470
GNESelectorFrame::Information* myInformation = nullptr;
471
472
/// @brief Invalidated copy constructor.
473
GNESelectorFrame(const GNESelectorFrame&) = delete;
474
475
/// @brief Invalidated assignment operator.
476
GNESelectorFrame& operator=(const GNESelectorFrame&) = delete;
477
};
478
479