Salome HOME
cefe99bfddfafc1970be36fa22602abd74a1b61d
[modules/hydro.git] / src / HYDROGUI / HYDROGUI_CalculationOp.h
1 // Copyright (C) 2014-2015  EDF-R&D
2 // This library is free software; you can redistribute it and/or
3 // modify it under the terms of the GNU Lesser General Public
4 // License as published by the Free Software Foundation; either
5 // version 2.1 of the License, or (at your option) any later version.
6 //
7 // This library is distributed in the hope that it will be useful,
8 // but WITHOUT ANY WARRANTY; without even the implied warranty of
9 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
10 // Lesser General Public License for more details.
11 //
12 // You should have received a copy of the GNU Lesser General Public
13 // License along with this library; if not, write to the Free Software
14 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
15 //
16 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
17 //
18
19
20 #ifndef HYDROGUI_CALCULATIONOP_H
21 #define HYDROGUI_CALCULATIONOP_H
22
23 #include "HYDROGUI_Operation.h"
24
25 #include "HYDROData_SplitToZonesTool.h"
26 #include "HYDROGUI_Shape.h"
27
28 #include <HYDROData_CalculationCase.h>
29 #include <HYDROData_Region.h>
30
31 class SUIT_ViewManager;
32 class OCCViewer_ViewManager;
33 class HYDROGUI_CalculationDlg;
34 class SUIT_DataObject;
35
36 class HYDROGUI_CalculationOp : public HYDROGUI_Operation
37 {
38   Q_OBJECT
39
40 public:
41   HYDROGUI_CalculationOp( HYDROGUI_Module* theModule, bool theIsEdit );
42   virtual ~HYDROGUI_CalculationOp();
43
44 protected:
45   virtual void                    startOperation();
46   virtual void                    abortOperation();
47   virtual void                    commitOperation();
48
49   virtual HYDROGUI_InputPanel*    createInputPanel() const;
50
51   virtual void                    onApply();
52   virtual bool                    processApply( int& theUpdateFlags, QString& theErrorMsg,
53                                                 QStringList& theBrowseObjectsEntries );
54
55   void setAvailableGroups();
56
57 protected slots:
58
59   /**
60    * Change the creation mode.
61    * @param theMode the mode to set
62    */
63   void                            onChangeMode( int theMode );
64
65   /**
66    * Add geometry objects selected in the module browser to the calculation case.
67    */
68   void                            onAddObjects();
69   /**
70    * Remove selected objects from the calculation case.
71    */
72   void                            onRemoveObjects();
73
74   /**
75    * Add geometry groups selected in the module browser to the calculation case.
76    */
77   void                            onAddGroups();
78   /**
79    * Remove selected groups from the calculation case.
80    */
81   void                            onRemoveGroups();
82
83   /**
84    * Change the creation mode related to land covers.
85    * @param theMode the mode to set
86    */
87   void                            onChangeLandCoverMode( int theMode );
88
89   /**
90    * Add land covers selected in the module browser to the calculation case.
91    */
92   void                            onAddLandCovers();
93   /**
94    * Remove selected land covers from the calculation case.
95    */
96   void                            onRemoveLandCovers();
97
98   /**
99    * Set the given bathymetry/type merge type to the current zone.
100    */
101   void                            onSetMergeType( int theMergeType, QString& theMergeObjectName );
102   /**
103    * Set the given Strickler merge type to the current zone.
104    */
105   void                            onSetMergeStricklerType( int theMergeType, QString& theStricklerTypeName );
106   /**
107    * Selected zones are moved to the existing region.
108    */
109   void                            onMoveZones( SUIT_DataObject* theRegionItem, 
110                                                const QList<SUIT_DataObject*>& theZonesList,
111                                                bool theLandCover );
112   /**
113    * Selected zones are moved to the new region to be created.
114    */
115   void                            onCreateRegion( const QList<SUIT_DataObject*>& theZonesList );
116   /**
117    * Selected land cover zones are moved to the new region to be created.
118    */
119   void                            onCreateLandCoverRegion( const QList<SUIT_DataObject*>& theZonesList );
120   /**
121    * Case objects must be splitted to zones if the case has been modified or new.
122    */
123   void                            onNext( const int );
124   void                            onLastViewClosed( SUIT_ViewManager* );
125   /**
126    * The zone is selected in the browser on the second page of the wizard.
127    */
128   void                            onClickedInZonesBrowser( SUIT_DataObject* theItem );
129   /**
130    * Slot called on back button click.
131    */
132   void                            onHideZones( const int );
133   /** 
134    * Geometry object is selected in the list on the first wizard page
135    */
136   void                            onObjectsSelected();
137   /** 
138    * Land cover is selected in the list on the third wizard page
139    */
140   void                            onLandCoversSelected();
141   /** 
142    * Boundary polyline is selected in the list on the first wizard page
143    */
144   void                            onBoundarySelected( const QString & theObjName );
145   /** 
146    * Strickler table name is selected in the list on the third wizard page
147    */
148   void                            onStricklerTableSelected( const QString & theObjName );
149
150   void onOrderChanged( bool& isConfirmed );
151   void onOrderLandCoverChanged( bool& isConfirmed );
152
153   void onRuleChanged( bool& isConfirmed );
154   void onRuleLandCoverChanged( bool& isConfirmed );
155
156 private:
157   void                            createPreview( const bool theLandCover);
158   void                            closePreview( bool theRemoveViewManager = true );
159   void                            setObjectVisibility( Handle(HYDROData_Entity) theEntity, const bool theIsVisible );
160   void                            setZonesVisible( bool theIsVisible, const bool theLandCover );
161   void                            setGeomObjectsVisible( bool theIsVisible );
162   void                            setLandCoversVisible( bool theIsVisible );
163   void                            getNamesAndEntries( const HYDROData_SequenceOfObjects& theSeq, 
164                                                       QStringList& theNames, QStringList& theEntries ) const;
165
166   /**
167    * Internal method that used to assign unique default colors for zones
168    */
169   void                            AssignDefaultZonesColors( const bool theLandCover );
170   /**
171    * Internal method that used to generate default color for zone
172    * @param theIndex the index of color to be generated
173    * @param theSaturation the saturation of the color in the range 0 to 1,
174    * and the bigger it is, the stronger the color is. Grayish colors have
175    * saturation near 0, very strong colors have saturation near 1.
176    * The defalt value is 0.5.
177    * @param theValue the value in the range 0 to 1, represents lightness or
178    * brightness of the color. 0 is black, 1 is as far from black as possible.
179    * The defalt value is 0.95.
180    * \return the generated color
181    */
182   QColor                          GenerateDefaultZonesColor( int theIndex,
183                                                              float theSaturation = 0.5,
184                                                              float theValue = 0.95 ) const;
185
186   void                            setRules( HYDROData_CalculationCase::DataTag theDataTag );
187
188   bool                            createRegion( const QList<SUIT_DataObject*>& theZonesList,
189                                                 const bool theLandCover );
190
191   bool confirmRegionsChange() const;
192   bool confirmModeChange() const;
193   bool confirmOrderChange() const;
194   bool confirmRuleChange() const;
195   bool confirmContinueWithWarning( const HYDROData_Warning& theWarning ) const;
196
197   bool confirmLandCoverRegionsChange() const;
198   bool confirmLandCoverModeChange() const;
199   bool confirmLandCoverOrderChange() const;
200   bool confirmLandCoverRuleChange() const;
201
202 private:
203   bool                            myIsEdit;
204   bool                            myShowZones;
205   bool                            myShowGeomObjects;
206   bool                            myShowLandCovers;
207   bool                            myUpdateLandCoverZonesPrs;
208   Handle(HYDROData_CalculationCase) myEditedObject;
209
210   SUIT_ViewManager*               myActiveViewManager;
211   OCCViewer_ViewManager*          myPreviewViewManager;
212 };
213
214 #endif
215
216