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    GNETAZFrame.h
11 /// @author  Pablo Alvarez Lopez
12 /// @date    Oct 2018
13 /// @version $Id$
14 ///
15 // The Widget for add TAZ elements
16 /****************************************************************************/
17 #ifndef GNETAZFrame_h
18 #define GNETAZFrame_h
19 
20 
21 // ===========================================================================
22 // included modules
23 // ===========================================================================
24 #include "GNEFrame.h"
25 
26 // ===========================================================================
27 // class definitions
28 // ===========================================================================
29 
30 class GNETAZSourceSink;
31 
32 // ===========================================================================
33 // class definitions
34 // ===========================================================================
35 /**
36  * @class GNETAZFrame
37  * The Widget for setting internal attributes of TAZ elements
38  */
39 class GNETAZFrame : public GNEFrame {
40 
41 public:
42     // ===========================================================================
43     // class TAZCurrent
44     // ===========================================================================
45 
46     class TAZCurrent : protected FXGroupBox {
47 
48     public:
49         /// @brief struct for edges and the source/sink colors
50         struct TAZEdge {
51             /// @brief constructor
52             TAZEdge(TAZCurrent* TAZCurrentParent, GNEEdge* _edge, GNETAZSourceSink* _TAZSource, GNETAZSourceSink* _TAZSink);
53 
54             /// @brief destructor (needed because RGBColors has to be deleted)
55             ~TAZEdge();
56 
57             /// @brief update colors
58             void updateColors();
59 
60             /// @brief TAZ edge
61             GNEEdge* edge;
62 
63             /// @brief source TAZ
64             GNETAZSourceSink* TAZSource;
65 
66             /// @brif sink TAZ
67             GNETAZSourceSink* TAZSink;
68 
69             /// @brief color by source [0-9]
70             int sourceColor;
71 
72             /// @brief color by sink [0-9]
73             int sinkColor;
74 
75             /// @brief color by source + sink [0-9]
76             int sourcePlusSinkColor;
77 
78             /// @brief color by source - sink [0-9]
79             int sourceMinusSinkColor;
80 
81         private:
82             /// @brief pointer to TAZCurrentParent
83             TAZCurrent* myTAZCurrentParent;
84         };
85 
86         /// @brief constructor
87         TAZCurrent(GNETAZFrame* TAZFrameParent);
88 
89         /// @brief destructor
90         ~TAZCurrent();
91 
92         /// @brief set current TAZ
93         void setTAZ(GNETAZ* editedTAZ);
94 
95         /// @brief get current TAZ
96         GNETAZ* getTAZ() const;
97 
98         /// @brief check if given edge belongs to current TAZ
99         bool isTAZEdge(GNEEdge* edge) const;
100 
101         /// @brief get current net edges
102         const std::vector<GNEEdge*>& getNetEdges() const;
103 
104         /// @brief get current selected edges
105         const std::vector<GNEEdge*>& getSelectedEdges() const;
106 
107         /// @brief get TAZEdges
108         const std::vector<TAZCurrent::TAZEdge>& getTAZEdges() const;
109 
110         /// @brief refresh TAZEdges
111         void refreshTAZEdges();
112 
113     protected:
114         /// @brief add TAZChild
115         void addTAZChild(GNETAZSourceSink* additional);
116 
117     private:
118         /// @brief pointer to TAZ Frame
119         GNETAZFrame* myTAZFrameParent;
120 
121         /// @brief current edited TAZ
122         GNETAZ* myEditedTAZ;
123 
124         /// @brief vector with pointers to edges (it's used to avoid slowdowns during Source/Sinks manipulations)
125         std::vector<GNEEdge*> myNetEdges;
126 
127         /// @brief vector with pointers to selected edges
128         std::vector<GNEEdge*> mySelectedEdges;
129 
130         /// @brief vector with TAZ's edges
131         std::vector<TAZEdge> myTAZEdges;
132 
133         /// @brief Label for current TAZ
134         FXLabel* myTAZCurrentLabel;
135 
136         /// @brief maximum source plus sink value of current TAZ Edges
137         double myMaxSourcePlusSinkWeight;
138 
139         /// @brief minimum source plus sink value of current TAZ Edges
140         double myMinSourcePlusSinkWeight;
141 
142         /// @brief maximum source minus sink value of current TAZ Edges
143         double myMaxSourceMinusSinkWeight;
144 
145         /// @brief minimum source minus sink value of current TAZ Edges
146         double myMinSourceMinusSinkWeight;
147     };
148 
149     // ===========================================================================
150     // class TAZCommonStatistics
151     // ===========================================================================
152 
153     class TAZCommonStatistics : protected FXGroupBox {
154 
155     public:
156         /// @brief constructor
157         TAZCommonStatistics(GNETAZFrame* TAZFrameParent);
158 
159         /// @brief destructor
160         ~TAZCommonStatistics();
161 
162         /// @brief show TAZ Common Statistics Modul
163         void showTAZCommonStatisticsModul();
164 
165         /// @brief hide TAZ Common Statistics Modul
166         void hideTAZCommonStatisticsModul();
167 
168     protected:
169         /// @brief update Statistics label
170         void updateStatistics();
171 
172     private:
173         /// @brief pointer to TAZFrame parent
174         GNETAZFrame* myTAZFrameParent;
175 
176         /// @brief Statistics labels
177         FXLabel* myStatisticsLabel;
178     };
179 
180     // ===========================================================================
181     // class TAZSaveChanges
182     // ===========================================================================
183 
184     class TAZSaveChanges : protected FXGroupBox {
185         /// @brief FOX-declaration
186         FXDECLARE(GNETAZFrame::TAZSaveChanges)
187 
188     public:
189         /// @brief constructor
190         TAZSaveChanges(GNETAZFrame* TAZFrameParent);
191 
192         /// @brief destructor
193         ~TAZSaveChanges();
194 
195         /// @brief show TAZ Save Changes Modul
196         void showTAZSaveChangesModul();
197 
198         /// @brief hide TAZ Save Changes Modul
199         void hideTAZSaveChangesModul();
200 
201         /// @brief enable buttons save and cancel changes (And begin Undo List)
202         void enableButtonsAndBeginUndoList();
203 
204         /// @brief return true if there is changes to save
205         bool isChangesPending() const;
206 
207         /// @name FOX-callbacks
208         /// @{
209         /// @brief Called when the user press the button save changes
210         long onCmdSaveChanges(FXObject*, FXSelector, void*);
211 
212         /// @brief Called when the user press the button cancel changes
213         long onCmdCancelChanges(FXObject*, FXSelector, void*);
214         /// @}
215 
216     protected:
217         /// @brief FOX needs this
TAZSaveChanges()218         TAZSaveChanges() {}
219 
220     private:
221         /// @brief pointer to TAZFrame parent
222         GNETAZFrame* myTAZFrameParent;
223 
224         /// @field FXButton for save changes in TAZEdges
225         FXButton* mySaveChangesButton;
226 
227         /// @field FXButton for cancel changes in TAZEdges
228         FXButton* myCancelChangesButton;
229     };
230 
231     // ===========================================================================
232     // class TAZChildDefaultParameters
233     // ===========================================================================
234 
235     class TAZChildDefaultParameters : protected FXGroupBox {
236         /// @brief FOX-declaration
237         FXDECLARE(GNETAZFrame::TAZChildDefaultParameters)
238 
239     public:
240         /// @brief constructor
241         TAZChildDefaultParameters(GNETAZFrame* TAZFrameParent);
242 
243         /// @brief destructor
244         ~TAZChildDefaultParameters();
245 
246         /// @brief show TAZ child default parameters Modul
247         void showTAZChildDefaultParametersModul();
248 
249         /// @brief hide TAZ child default parameters Modul
250         void hideTAZChildDefaultParametersModul();
251 
252         /// @brief update "select edges button"
253         void updateSelectEdgesButton();
254 
255         /// @brief get default TAZSource weight
256         double getDefaultTAZSourceWeight() const;
257 
258         /// @brief default TAZSink weight
259         double getDefaultTAZSinkWeight() const;
260 
261         /// @brief check if toggle membership is enabled
262         bool getToggleMembership() const;
263 
264         /// @name FOX-callbacks
265         /// @{
266         /// @brief Called when the user changes default values
267         long onCmdSetDefaultValues(FXObject* obj, FXSelector, void*);
268 
269         /// @brief Called when the user press use selected edges
270         long onCmdUseSelectedEdges(FXObject* obj, FXSelector, void*);
271         /// @}
272 
273     protected:
274         /// @brief FOX needs this
TAZChildDefaultParameters()275         TAZChildDefaultParameters() {}
276 
277     private:
278         /// @brief pointer to TAZFrame parent
279         GNETAZFrame* myTAZFrameParent;
280 
281         /// @brief CheckButton to enable or disable Toggle edge Membership
282         FXCheckButton* myToggleMembership;
283 
284         /// @brief Horizontal Frame for default TAZ Source Weight
285         FXHorizontalFrame* myDefaultTAZSourceFrame;
286 
287         /// @brief textField to set a default value for TAZ Sources
288         FXTextField* myTextFieldDefaultValueTAZSources;
289 
290         /// @brief Horizontal Frame for default TAZ Sink Weight
291         FXHorizontalFrame* myDefaultTAZSinkFrame;
292 
293         /// @brief textField to set a default value for TAZ Sinks
294         FXTextField* myTextFieldDefaultValueTAZSinks;
295 
296         /// @brief button for use selected edges
297         FXButton* myUseSelectedEdges;
298 
299         /// @brief information label
300         FXLabel* myInformationLabel;
301 
302         /// @brief default TAZSource weight
303         double myDefaultTAZSourceWeight;
304 
305         /// @brief default TAZSink weight
306         double myDefaultTAZSinkWeight;
307     };
308 
309     // ===========================================================================
310     // class TAZSelectionStatistics
311     // ===========================================================================
312 
313     class TAZSelectionStatistics : protected FXGroupBox {
314         /// @brief FOX-declaration
315         FXDECLARE(GNETAZFrame::TAZSelectionStatistics)
316 
317     public:
318         /// @brief constructor
319         TAZSelectionStatistics(GNETAZFrame* TAZFrameParent);
320 
321         /// @brief destructor
322         ~TAZSelectionStatistics();
323 
324         /// @brief show TAZ Selection Statistics Modul
325         void showTAZSelectionStatisticsModul();
326 
327         /// @brief hide TAZ Selection Statistics Modul
328         void hideTAZSelectionStatisticsModul();
329 
330         /// @brief add an edge and their TAZ Childs in the list of selected items
331         bool selectEdge(const TAZCurrent::TAZEdge& edge);
332 
333         /// @brief un select an edge (and their TAZ Childs)
334         bool unselectEdge(GNEEdge* edge);
335 
336         /// @brief check if an edge is selected
337         bool isEdgeSelected(GNEEdge* edge);
338 
339         /// @brief clear current TAZ childs
340         void clearSelectedEdges();
341 
342         /// @brief get map with edge and TAZChilds
343         const std::vector<TAZCurrent::TAZEdge>& getEdgeAndTAZChildsSelected() const;
344 
345         /// @name FOX-callbacks
346         /// @{
347         /// @brief Called when the user set a new value
348         long onCmdSetNewValues(FXObject* obj, FXSelector, void*);
349 
350         /// @brief Called when the user press select edges
351         long onCmdSelectEdges(FXObject* obj, FXSelector, void*);
352         /// @}
353 
354     protected:
355         /// @brief FOX needs this
TAZSelectionStatistics()356         TAZSelectionStatistics() {}
357 
358         /// @brief update TAZSelectionStatistics
359         void updateStatistics();
360 
361     private:
362         /// @brief pointer to TAZFrame parent
363         GNETAZFrame* myTAZFrameParent;
364 
365         /// @brief Horizontal Frame for default TAZ Source Weight
366         FXHorizontalFrame* myTAZSourceFrame;
367 
368         /// @brief textField for TAZ Source weight
369         FXTextField* myTextFieldTAZSourceWeight;
370 
371         /// @brief Horizontal Frame for default TAZ Sink Weight
372         FXHorizontalFrame* myTAZSinkFrame;
373 
374         /// @brief textField for TAZ Sink weight
375         FXTextField* myTextFieldTAZSinkWeight;
376 
377         /// @brief Statistics labels
378         FXLabel* myStatisticsLabel;
379 
380         /// @brief vector with the current selected edges and their associated childs
381         std::vector<TAZCurrent::TAZEdge> myEdgeAndTAZChildsSelected;
382     };
383 
384     // ===========================================================================
385     // class TAZParameters
386     // ===========================================================================
387 
388     class TAZParameters : protected FXGroupBox {
389         /// @brief FOX-declaration
390         FXDECLARE(GNETAZFrame::TAZParameters)
391 
392     public:
393         /// @brief constructor
394         TAZParameters(GNETAZFrame* TAZFrameParent);
395 
396         /// @brief destructor
397         ~TAZParameters();
398 
399         /// @brief show TAZ parameters and set the default value of parameters
400         void showTAZParametersModul();
401 
402         /// @brief hide TAZ parameters
403         void hideTAZParametersModul();
404 
405         /// @brief check if current parameters are valid
406         bool isCurrentParametersValid() const;
407 
408         /// @brief check if edges within has to be used after TAZ Creation
409         bool isAddEdgesWithinEnabled() const;
410 
411         /// @brief get a map with attributes and their values
412         std::map<SumoXMLAttr, std::string> getAttributesAndValues() const;
413 
414         /// @name FOX-callbacks
415         /// @{
416         /// @brief called when user press the "Color" button
417         long onCmdSetColorAttribute(FXObject*, FXSelector, void*);
418 
419         /// @brief Called when user set a value
420         long onCmdSetAttribute(FXObject*, FXSelector, void*);
421 
422         /// @brief Called when help button is pressed
423         long onCmdHelp(FXObject*, FXSelector, void*);
424         /// @}
425 
426     protected:
427         /// @brief FOX needs this
TAZParameters()428         TAZParameters() {}
429 
430     private:
431         /// @brief pointer to GNETAZFrame parent
432         GNETAZFrame* myTAZFrameParent;
433 
434         /// @brief Button for open color editor
435         FXButton* myColorEditor;
436 
437         /// @brief textField to modify the default value of color parameter
438         FXTextField* myTextFieldColor;
439 
440         /// @brief CheckButton to enable or disable use edges within TAZ after creation
441         FXCheckButton* myAddEdgesWithinCheckButton;
442 
443         /// @brief button for help
444         FXButton* myHelpTAZAttribute;
445     };
446 
447     // ===========================================================================
448     // class TAZEdgesGraphic
449     // ===========================================================================
450 
451     class TAZEdgesGraphic : protected FXGroupBox {
452         /// @brief FOX-declaration
453         FXDECLARE(GNETAZFrame::TAZEdgesGraphic)
454 
455     public:
456         /// @brief constructor
457         TAZEdgesGraphic(GNETAZFrame* TAZFrameParent);
458 
459         /// @brief destructor
460         ~TAZEdgesGraphic();
461 
462         /// @brief show TAZ Edges Graphic Modul
463         void showTAZEdgesGraphicModul();
464 
465         /// @brief hide TAZ Edges Graphic Modul
466         void hideTAZEdgesGraphicModul();
467 
468         /// @brief update edge colors;
469         void updateEdgeColors();
470 
471         /// @name FOX-callbacks
472         /// @{
473         /// @brief Called when the user select one kind of representation
474         long onCmdChoosenBy(FXObject* obj, FXSelector, void*);
475         /// @}
476 
477     protected:
478         /// @brief FOX needs this
TAZEdgesGraphic()479         TAZEdgesGraphic() {}
480 
481     private:
482         /// @brief pointer to TAZFrame parent
483         GNETAZFrame* myTAZFrameParent;
484 
485         /// @brief add radio button "color by source"
486         FXRadioButton* myColorBySourceWeight;
487 
488         /// @brief add radio button "color by sink"
489         FXRadioButton* myColorBySinkWeight;
490 
491         /// @brief add radio button "color source + sink"
492         FXRadioButton* myColorBySourcePlusSinkWeight;
493 
494         /// @brief add radio button "color source - Sink"
495         FXRadioButton* myColorBySourceMinusSinkWeight;
496 
497         /// @brief vector wit the scale colors
498         std::vector<RGBColor> myScaleColors;
499 
500         /// @brief default RGBColor for all edges
501         RGBColor myEdgeDefaultColor;
502 
503         /// @brief RGBColor color for selected egdes
504         RGBColor myEdgeSelectedColor;
505     };
506 
507     /**@brief Constructor
508      * @brief parent FXHorizontalFrame in which this GNEFrame is placed
509      * @brief viewNet viewNet that uses this GNEFrame
510      */
511     GNETAZFrame(FXHorizontalFrame* horizontalFrameParent, GNEViewNet* viewNet);
512 
513     /// @brief Destructor
514     ~GNETAZFrame();
515 
516     /// @brief hide TAZ frame
517     void hide();
518 
519     /**@brief process click over Viewnet
520     * @param[in] clickedPosition clicked position over ViewNet
521     * @param[in] objectsUnderCursor objects under cursors
522     * @return true if something (select TAZ or add edge) was sucefully done
523     */
524     bool processClick(const Position& clickedPosition, const GNEViewNetHelper::ObjectsUnderCursor& objectsUnderCursor);
525 
526     /// @brief process selection of edges in view net
527     void processEdgeSelection(const std::vector<GNEEdge*>& edges);
528 
529     /// @brief get drawing mode modul
530     DrawingShape* getDrawingShapeModul() const;
531 
532     /// @brief get Current TAZ modul
533     TAZCurrent* getTAZCurrentModul() const;
534 
535     /// @brief get TAZ Selection Statistics modul
536     TAZSelectionStatistics* getTAZSelectionStatisticsModul() const;
537 
538     /// @brief get TAZ Save Changes modul
539     TAZSaveChanges* getTAZSaveChangesModul() const;
540 
541 protected:
542     /**@brief build a shaped element using the drawed shape
543      * return true if was sucesfully created
544      * @note called when user stop drawing shape
545      */
546     bool buildShape();
547 
548     /// @brief add or remove a TAZSource and a TAZSink, or remove it if edge is in the list of TAZ Childs
549     bool addOrRemoveTAZMember(GNEEdge* edge);
550 
551     /// @brief drop all TAZSources and TAZ Sinks of current TAZ
552     void dropTAZMembers();
553 
554 private:
555     /// @brief current TAZ
556     TAZCurrent* myTAZCurrent;
557 
558     /// @brief TAZ Edges common parameters
559     TAZCommonStatistics* myTAZCommonStatistics;
560 
561     /// @brief TAZ parameters
562     TAZParameters* myTAZParameters;
563 
564     /// @brief Netedit parameter
565     NeteditAttributes* myNeteditAttributes;
566 
567     /// @brief Drawing shape
568     DrawingShape* myDrawingShape;
569 
570     /// @brief save TAZ Edges
571     TAZSaveChanges* myTAZSaveChanges;
572 
573     /// @brief TAZ child defaults parameters
574     TAZChildDefaultParameters* myTAZChildDefaultParameters;
575 
576     /// @brief TAZ Edges selection parameters
577     TAZSelectionStatistics* myTAZSelectionStatistics;
578 
579     /// @brief TAZ Edges Graphic
580     TAZEdgesGraphic* myTAZEdgesGraphic;
581 };
582 
583 
584 #endif
585 
586 /****************************************************************************/
587