1 /****************************************************************************/
2 // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.org/sumo
3 // Copyright (C) 2001-2019 German Aerospace Center (DLR) and others.
4 // This program and the accompanying materials
5 // are made available under the terms of the Eclipse Public License v2.0
6 // which accompanies this distribution, and is available at
7 // http://www.eclipse.org/legal/epl-v20.html
8 // SPDX-License-Identifier: EPL-2.0
9 /****************************************************************************/
10 /// @file    GNESelectorFrame.h
11 /// @author  Jakob Erdmann
12 /// @date    Mar 2011
13 /// @version $Id$
14 ///
15 // The Widget for modifying selections of network-elements
16 // (some elements adapted from GUIDialog_GLChosenEditor)
17 /****************************************************************************/
18 #ifndef GNESelectorFrame_h
19 #define GNESelectorFrame_h
20 
21 // ===========================================================================
22 // included modules
23 // ===========================================================================
24 #include "GNEFrame.h"
25 
26 // ===========================================================================
27 // class definitions
28 // ===========================================================================
29 /**
30  * @class GNESelectorFrame
31  * The Widget for modifying selections of network-elements
32  */
33 class GNESelectorFrame : public GNEFrame {
34 
35 public:
36 
37     // ===========================================================================
38     // class LockGLObjectTypes
39     // ===========================================================================
40 
41     class LockGLObjectTypes : protected FXGroupBox {
42 
43     public:
44         /// @brief class for object types entries
45         class ObjectTypeEntry : protected FXObject {
46             /// @brief FOX-declaration
47             FXDECLARE(GNESelectorFrame::LockGLObjectTypes::ObjectTypeEntry)
48 
49         public:
50             /// @brief constructor
51             ObjectTypeEntry(FXMatrix* matrixParent, const std::string& label);
52 
53             /// @brief show ObjectTypeEntry
54             void showObjectTypeEntry();
55 
56             /// @brief hide ObjectTypeEntry
57             void hideObjectTypeEntry();
58 
59             /// @brief up count
60             void counterUp();
61 
62             /// @brief down count
63             void counterDown();
64 
65             /// @brief check if current GLType is blocked
66             bool isGLTypeLocked() const;
67 
68             /// @name FOX-callbacks
69             /// @{
70             /// @brief called when user change the CheckBox
71             long onCmdSetCheckBox(FXObject*, FXSelector, void*);
72 
73             /// @}
74 
75         protected:
76             /// @brief FOX needs this
ObjectTypeEntry()77             ObjectTypeEntry() {}
78 
79         private:
80             /// @brief label counter
81             FXLabel* myLabelCounter;
82 
83             /// @brief label type nane
84             FXLabel* myLabelTypeName;
85 
86             /// @brief check box to check if GLObject type is blocked
87             FXCheckButton* myCheckBoxLocked;
88 
89             /// @brief counter
90             int myCounter;
91         };
92 
93         /// @brief constructor
94         LockGLObjectTypes(GNESelectorFrame* selectorFrameParent);
95 
96         /// @brief destructor
97         ~LockGLObjectTypes();
98 
99         /// @brief set object selected
100         void addedLockedObject(const GUIGlObjectType type);
101 
102         /// @brief set object unselected
103         void removeLockedObject(const GUIGlObjectType type);
104 
105         /// @brief check if an object is locked
106         bool IsObjectTypeLocked(const GUIGlObjectType type) const;
107 
108         /// @brief show type Entries (depending if we're in Network or demand supermode)
109         void showTypeEntries();
110 
111     private:
112         /// @brief pointer to Selector Frame Parent
113         GNESelectorFrame* mySelectorFrameParent;
114 
115         /// @brief check boxes for type-based selection locking and selected object counts
116         std::map<GUIGlObjectType, std::pair<Supermode, ObjectTypeEntry* > > myTypeEntries;
117     };
118 
119     // ===========================================================================
120     // class ModificationMode
121     // ===========================================================================
122 
123     class ModificationMode : protected FXGroupBox {
124         /// @brief FOX-declaration
125         FXDECLARE(GNESelectorFrame::ModificationMode)
126 
127     public:
128         /// @brief operations of selector
129         enum SetOperation {
130             SET_ADD      = 1,
131             SET_SUB      = 2,
132             SET_RESTRICT = 3,
133             SET_REPLACE  = 4,
134             SET_DEFAULT  = 5  // use mySetOperation instead of override
135         };
136 
137         /// @brief constructor
138         ModificationMode(GNESelectorFrame* selectorFrameParent);
139 
140         /// @brief destructor
141         ~ModificationMode();
142 
143         /// @brief get current modification mode
144         SetOperation getModificationMode() const;
145 
146         /// @name FOX-callbacks
147         /// @{
148         /// @brief called when user change type of selction operation
149         long onCmdSelectModificationMode(FXObject*, FXSelector, void*);
150 
151         /// @}
152 
153     protected:
154         /// @brief FOX needs this
ModificationMode()155         ModificationMode() {}
156 
157     private:
158         /// @brief pointer to Selector Frame Parent
159         GNESelectorFrame* mySelectorFrameParent;
160 
161         /// @brief add radio button
162         FXRadioButton* myAddRadioButton;
163 
164         /// @brief remove radio button
165         FXRadioButton* myRemoveRadioButton;
166 
167         /// @brief keep button
168         FXRadioButton* myKeepRadioButton;
169 
170         /// @brief replace radio button
171         FXRadioButton* myReplaceRadioButton;
172 
173         /// @brief how to modify selection
174         SetOperation myModificationModeType;
175     };
176 
177     // ===========================================================================
178     // class ElementSet
179     // ===========================================================================
180 
181     class ElementSet : protected FXGroupBox {
182         /// @brief FOX-declaration
183         FXDECLARE(GNESelectorFrame::ElementSet)
184 
185     public:
186         /// @brief type of Set
187         enum ElementSetType {
188             ELEMENTSET_NETELEMENT    = 1,
189             ELEMENTSET_ADDITIONAL    = 2,
190             ELEMENTSET_SHAPE         = 3,
191             ELEMENTSET_DEMANDELEMENT = 4,
192             ELEMENTSET_INVALID       = 5,
193         };
194 
195         /// @brief constructor
196         ElementSet(GNESelectorFrame* selectorFrameParent);
197 
198         /// @brief destructor
199         ~ElementSet();
200 
201         /// @brief get current selected element set
202         ElementSetType getElementSet() const;
203 
204         /// @brief refresh element set
205         void refreshElementSet();
206 
207         /// @brief update current element set (called after
208 
209         /// @name FOX-callbacks
210         /// @{
211 
212         /// @brief Called when the user change the set of element to search (netElement, Additional or shape)
213         long onCmdSelectElementSet(FXObject*, FXSelector, void*);
214 
215         /// @}
216 
217     protected:
218         /// @brief FOX needs this
ElementSet()219         ElementSet() {}
220 
221     private:
222         /// @brief pointer to Selector Frame Parent
223         GNESelectorFrame* mySelectorFrameParent;
224 
225         /// @brief Combo Box with the element sets
226         FXComboBox* mySetComboBox;
227 
228         /// @brief current element set selected
229         ElementSetType myCurrentElementSet;
230     };
231 
232     // ===========================================================================
233     // class MatchAttribute
234     // ===========================================================================
235 
236     class MatchAttribute : protected FXGroupBox {
237         /// @brief FOX-declaration
238         FXDECLARE(GNESelectorFrame::MatchAttribute)
239 
240     public:
241         /// @brief constructor
242         MatchAttribute(GNESelectorFrame* selectorFrameParent);
243 
244         /// @brief destructor
245         ~MatchAttribute();
246 
247         /// @brief enable match attributes
248         void enableMatchAttribute();
249 
250         /// @brief disable match attributes
251         void disableMatchAttribute();
252 
253         /// @name FOX-callbacks
254         /// @{
255 
256         /**@brief Called when the user selectes a tag in the match box
257          * @note updates the attr listbox and repaints itself
258          */
259         long onCmdSelMBTag(FXObject*, FXSelector, void*);
260 
261         /**@brief Called when the user selectes a tag in the match box
262          * @note updates the attr listbox and repaints itself
263          */
264         long onCmdSelMBAttribute(FXObject*, FXSelector, void*);
265 
266         /**@brief Called when the user enters a new selection expression
267          * @note validates expression and modifies current selection
268          */
269         long onCmdSelMBString(FXObject*, FXSelector, void*);
270 
271         /**@brief Called when the user clicks the help button
272          * @note pop up help window
273          */
274         long onCmdHelp(FXObject*, FXSelector, void*);
275 
276         /// @}
277 
278     protected:
279         /// @brief FOX needs this
MatchAttribute()280         MatchAttribute() {}
281 
282     private:
283         /// @brief pointer to Selector Frame Parent
284         GNESelectorFrame* mySelectorFrameParent;
285 
286         /// @brief tag of the match box
287         FXComboBox* myMatchTagComboBox;
288 
289         /// @brief attributes of the match box
290         FXComboBox* myMatchAttrComboBox;
291 
292         /// @brief current SumoXMLTag tag
293         SumoXMLTag myCurrentTag;
294 
295         /// @brief current SumoXMLTag Attribute
296         SumoXMLAttr myCurrentAttribute;
297 
298         /// @brief string of the match
299         FXTextField* myMatchString;
300     };
301 
302     // ===========================================================================
303     // class VisualScaling
304     // ===========================================================================
305 
306     class VisualScaling : protected FXGroupBox {
307         /// @brief FOX-declaration
308         FXDECLARE(GNESelectorFrame::VisualScaling)
309 
310     public:
311         /// @brief constructor
312         VisualScaling(GNESelectorFrame* selectorFrameParent);
313 
314         /// @brief destructor
315         ~VisualScaling();
316 
317         /// @name FOX-callbacks
318         /// @{
319 
320         /// @brief Called when the user changes visual scaling
321         long onCmdScaleSelection(FXObject*, FXSelector, void*);
322 
323         /// @}
324 
325     protected:
326         /// @brief FOX needs this
VisualScaling()327         VisualScaling() {}
328 
329     private:
330         /// @brief pointer to Selector Frame Parent
331         GNESelectorFrame* mySelectorFrameParent;
332 
333         /// @brief Spinner for selection scaling
334         FXRealSpinner* mySelectionScaling;
335     };
336 
337     // ===========================================================================
338     // class SelectionOperation
339     // ===========================================================================
340 
341     class SelectionOperation : protected FXGroupBox {
342         /// @brief FOX-declaration
343         FXDECLARE(GNESelectorFrame::SelectionOperation)
344 
345     public:
346         /// @brief constructor
347         SelectionOperation(GNESelectorFrame* selectorFrameParent);
348 
349         /// @brief destructor
350         ~SelectionOperation();
351 
352         /// @name FOX-callbacks
353         /// @{
354 
355         /**@brief Called when the user presses the Load-button
356          * @note Opens a file dialog and forces the parent to load the list of selected
357          * objects when a file was chosen. Rebuilds the list, then, and redraws itself.
358          */
359         long onCmdLoad(FXObject*, FXSelector, void*);
360 
361         /** @brief Called when the user presses the Save-button
362          * @note Opens a file dialog and forces the selection container to save the list
363            of selected objects when a file was chosen. If the saveing failed, a message window is shown.
364          */
365         long onCmdSave(FXObject*, FXSelector, void*);
366 
367         /**@brief Called when the user presses the Clear-button
368          * @note Clear the internal list and calls GUISelectedStorage::clear and repaints itself
369          */
370         long onCmdClear(FXObject*, FXSelector, void*);
371 
372         /**@brief Called when the user presses the Invert-button
373          * @note invert the selection and repaints itself
374          */
375         long onCmdInvert(FXObject*, FXSelector, void*);
376 
377         /// @}
378 
379     protected:
380         /// @brief FOX needs this
SelectionOperation()381         SelectionOperation() {}
382 
383     private:
384         /// @brief pointer to Selector Frame Parent
385         GNESelectorFrame* mySelectorFrameParent;
386     };
387 
388     /**@brief Constructor
389      * @brief parent FXHorizontalFrame in which this GNEFrame is placed
390      * @brief viewNet viewNet that uses this GNEFrame
391      */
392     GNESelectorFrame(FXHorizontalFrame* horizontalFrameParent, GNEViewNet* viewNet);
393 
394     /// @brief Destructor
395     ~GNESelectorFrame();
396 
397     /// @brief show Frame
398     void show();
399 
400     /// @brief hide Frame
401     void hide();
402 
403     /// @brief clear current selection with possibility of undo/redo
404     void clearCurrentSelection() const;
405 
406     /**@brief apply list of ids to the current selection according to SetOperation,
407      * @note if setop==SET_DEFAULT than the currently set mode (mySetOperation) is used
408      */
409     void handleIDs(const std::vector<GNEAttributeCarrier*>& ACs, ModificationMode::SetOperation setop = ModificationMode::SET_DEFAULT);
410 
411     /// @brief get selected items Modul
412     LockGLObjectTypes* getLockGLObjectTypes() const;
413 
414     /// @brief get modification mode modul
415     ModificationMode* getModificationModeModul() const;
416 
417 private:
418     /// @brief modul for lock selected items
419     LockGLObjectTypes* myLockGLObjectTypes;
420 
421     /// @brief modul for change modification mode
422     ModificationMode* myModificationMode;
423 
424     /// @brief modul for select element set
425     ElementSet* myElementSet;
426 
427     /// @brief modul for matchA ttribute
428     MatchAttribute* myMatchAttribute;
429 
430     /// @brief modul for visual scaling
431     VisualScaling* myVisualScaling;
432 
433     /// @brief modul for selection operations
434     SelectionOperation* mySelectionOperation;
435 
436 private:
437     /**@brief return ACs of the given type with matching attrs
438      * @param[in] ACTag XML Tag of AttributeCarrier
439      * @param[in] ACAttr XML Attribute of AttributeCarrier
440      * @param[in] compOp One of {<,>,=} for matching against val or '@' for matching against expr
441      */
442     std::vector<GNEAttributeCarrier*> getMatches(SumoXMLTag ACTag, SumoXMLAttr ACAttr, char compOp, double val, const std::string& expr);
443 };
444 
445 
446 #endif
447 
448 /****************************************************************************/
449 
450