Salome HOME
Merge remote-tracking branch 'remotes/origin/BR_2017' into HEAD
[modules/hydro.git] / src / HYDROGUI / HYDROGUI_Module.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 #ifndef HYDROGUI_MODULE_H
20 #define HYDROGUI_MODULE_H
21
22 #include <HYDROData_Entity.h>
23
24 #ifdef WIN32
25   #pragma warning ( disable: 4251 )
26 #endif
27
28 #include <LightApp_Module.h>
29 #include <LightApp_Application.h>
30 #include <QEvent>
31 #include <QStack>
32
33 #ifdef WIN32
34   #pragma warning ( default: 4251 )
35 #endif
36
37 class QGraphicsSceneMouseEvent;
38 class GraphicsView_Viewer;
39 class OCCViewer_Viewer;
40 class SVTK_Viewer;
41
42 class SUIT_ViewWindow;
43 class SUIT_ViewManager;
44
45 class HYDROData_StricklerTable;
46
47 class HYDROGUI_DataModel;
48 class HYDROGUI_Displayer;
49 class HYDROGUI_OCCDisplayer;
50 class HYDROGUI_VTKPrsDisplayer;
51 class HYDROGUI_AbstractDisplayer;
52 class HYDROGUI_Shape;
53 class HYDROGUI_VTKPrs;
54 class HYDROGUI_Operation;
55 class HYDROGUI_Overview;
56
57 /**\class HYDROGUI_Module
58  *\brief The class representing the HYDROGUI module
59  */
60 class HYDROGUI_Module : public LightApp_Module
61 {
62   Q_OBJECT
63
64   enum CustomEvent { NewViewEvent = QEvent::User + 100 };
65   enum CustomWindows { OverviewWindow = LightApp_Application::WT_User + 100 };
66
67   enum CursorType
68   {
69     CT_ArrowCursor = 0,
70     CT_UpArrowCursor,
71     CT_CrossCursor,
72     CT_WaitCursor,
73     CT_IBeamCursor,
74     CT_SizeVerCursor,
75     CT_SizeHorCursor,
76     CT_SizeBDiagCursor,
77     CT_SizeFDiagCursor,
78     CT_SizeAllCursor,
79     CT_SplitVCursor,
80     CT_SplitHCursor,
81     CT_PointingHandCursor,
82     CT_ForbiddenCursor,
83     CT_WhatsThisCursor,
84     CT_BusyCursor,
85     CT_OpenHandCursor,
86     CT_ClosedHandCursor,
87     CT_User
88   };
89
90 public:
91   
92   enum ViewManagerRole
93   {
94     VMR_Unknown = 0,
95     VMR_General,
96     VMR_TransformImage,
97     VMR_ReferenceImage,
98     VMR_ObserveImage,
99     //VMR_PreviewZone, // totally unused, to delete
100     VMR_PreviewCaseZones // actually unused, to review
101   };
102   typedef QPair< SUIT_ViewManager*, ViewManagerRole > ViewManagerInfo;
103
104   typedef QMap        < int, ViewManagerInfo > ViewManagerMap;
105   typedef QMapIterator< int, ViewManagerInfo > ViewManagerMapIterator;
106
107   struct ObjectState
108   {
109     bool Visibility;
110     double Transparency;
111     double ZValue;
112     ObjectState() : Visibility( false ), Transparency( 1.0 ), ZValue( 0.0 ) {}
113   };
114   typedef QMap< QString, ObjectState > Entry2ObjectStateMap;
115   typedef QMap< int, Entry2ObjectStateMap > ViewId2Entry2ObjectStateMap;
116
117   typedef QList<HYDROGUI_Shape*> ListOfShapes;
118   typedef QMap<int,ListOfShapes> ViewId2ListOfShapes;
119
120   typedef QList<HYDROGUI_VTKPrs*> ListOfVTKPrs;
121   typedef QMap<int,ListOfVTKPrs> ViewId2ListOfVTKPrs;
122
123   typedef QMap<int, Handle(HYDROData_StricklerTable)> ViewId2StricklerTable;
124
125 public:
126   HYDROGUI_Module();
127   virtual ~HYDROGUI_Module();
128
129   int                             getStudyId() const;
130
131   virtual void                    initialize( CAM_Application* );
132   virtual void                    windows( QMap<int, int>& ) const;
133   virtual void                    viewManagers( QStringList& ) const;
134
135   virtual void                    contextMenuPopup( const QString&, QMenu*, QString& );
136   virtual void                    createPreferences();
137
138   virtual void                    update( const int );
139   virtual void                    updateCommandsStatus();
140
141   virtual void                    selectionChanged();
142
143   SUIT_ViewManager*               getViewManager( const int theId ) const;
144   HYDROGUI_DataModel*             getDataModel() const;
145   HYDROGUI_Displayer*             getDisplayer() const;
146   HYDROGUI_OCCDisplayer*          getOCCDisplayer() const;
147   HYDROGUI_VTKPrsDisplayer*       getVTKDisplayer() const;
148
149   GraphicsView_Viewer*            getViewer( const int theId ) const;
150   OCCViewer_Viewer*               getOCCViewer( const int theId ) const;
151   SVTK_Viewer*                    getVTKViewer( const int theId ) const;
152
153   int                             getViewManagerId( SUIT_ViewManager* theViewManager );
154   ViewManagerRole                 getViewManagerRole( SUIT_ViewManager* theViewManager );
155   void                            setViewManagerRole( SUIT_ViewManager* theViewManager,
156                                                       const ViewManagerRole theRole );
157
158   bool                            isObjectVisible( const int theViewId,
159                                                    const Handle(HYDROData_Entity)& theObject ) const;
160   void                            setObjectVisible( const int theViewId,
161                                                     const Handle(HYDROData_Entity)& theObject,
162                                                     const bool theState );
163
164   virtual void                    preferencesChanged( const QString&, const QString& );
165
166   /** 
167    * Set IsToUpdate flag for all presentations of the given object to recompute them during 
168    * the next viewer(s) updating.
169    * @param theObject the data model object
170    * @param theState  the flag to set for object's presentations, it's true by default.
171    */
172   void                            setIsToUpdate( const Handle(HYDROData_Entity)& theObject,
173                                                  const bool theState = true );
174   QList<HYDROGUI_Shape*>          getObjectShapes( const int  theViewId,
175                                                    ObjectKind theKind ) const;
176   HYDROGUI_Shape*                 getObjectShape( const int                       theViewId,
177                                                   const Handle(HYDROData_Entity)& theObject ) const;
178   void                            setObjectShape( const int                       theViewId,
179                                                   const Handle(HYDROData_Entity)& theObject,
180                                                   HYDROGUI_Shape*                 theShape );
181   void                            removeViewShapes( const int                     theViewId );
182   void                            removeObjectShape( const int                       theViewId,
183                                                      const Handle(HYDROData_Entity)& theObject );
184
185   HYDROGUI_VTKPrs*                getObjectVTKPrs( const int                       theViewId,
186                                                    const Handle(HYDROData_Entity)& theObject ) const;
187   void                            setObjectVTKPrs( const int                       theViewId,
188                                                    const Handle(HYDROData_Entity)& theObject,
189                                                    HYDROGUI_VTKPrs*                theShape );
190   void                            removeViewVTKPrs( const int                      theViewId );
191   void                            removeObjectVTKPrs( const int                      theViewId,
192                                                      const Handle(HYDROData_Entity)& theObject );
193
194   void                            removeObjectVTKPrs( const int      theViewId,
195                                                       const QString& theEntry );
196
197   /**
198    * Update global imposed range of Z values for the given VTK viewer id
199    */
200   void                            updateVTKZRange( const int theViewId, double theRange[] );
201
202   /**
203    * Returns true if the object with the given entry can be renamed.
204    * @param theEntry the object entry
205    */
206   virtual bool                    renameAllowed( const QString& theEntry ) const;
207   /**
208    * Returns true if the object with the given entry is renamed.
209    * @param theEntry the object entry
210    * @param theName the new name
211    */
212   virtual bool                    renameObject( const QString& theEntry, const QString& theName );
213
214   QStack<HYDROGUI_Operation*>&    getActiveOperations();
215   HYDROGUI_Operation*             activeOperation();
216
217   /**
218    * Returns the cursor defined for edition operations in module preferences.
219    * \return specific cursor
220    */
221   QCursor                         getPrefEditCursor() const;
222
223   void                            clearCache();
224
225   /**
226    * Returns Strickler table used for Land Cover scalar map coloring in the given view.
227    * @param theViewId the view id
228    * @return the Strickler table used for scalar map coloring of Land Covers in the given view;
229              null - if scalar map coloring is off for the view  
230    */
231   Handle(HYDROData_StricklerTable) getLandCoverColoringTable( const int theViewId ) const;
232
233   /**
234    * Set Strickler table to be used for Land Cover scalar map coloring in the given view.
235    * @param theViewId the view id
236    * @param theTable the Strickler table
237    */
238   void                             setLandCoverColoringTable( const int theViewId,
239                                                               const Handle(HYDROData_StricklerTable)& theTable );
240   /**
241    * Set Land Cover scalar map coloring mode off for the given view.
242    * @param theViewId the view id
243    */
244   void                             setLandCoversScalarMapModeOff( const int theViewId );
245
246   /**
247    * Check if Land Cover scalar map coloring mode is on in the given view.
248    * @param theViewId the view id
249    * @return true if the mode is on, false if the mode is off
250    */
251   bool                             isLandCoversScalarMapModeOn( const int theViewId ) const;
252
253   /**
254    * Set object as removed.
255    * @param theObject the removed object
256    */
257   void                            setObjectRemoved( const Handle(HYDROData_Entity)& theObject );
258
259   void                            enableLCMActions();
260
261   bool arrowsVisible() const;
262   void setArrowsVisible( bool );
263
264 protected:
265   CAM_DataModel*                  createDataModel();
266
267 public slots:
268   virtual bool                    activateModule( SUIT_Study* );
269   virtual bool                    deactivateModule( SUIT_Study* );
270   virtual void                    onObjectClicked( SUIT_DataObject*, int );
271
272 protected:
273   virtual LightApp_Operation*     createOperation( const int ) const;
274   virtual bool                    reusableOperation( const int id );
275
276   virtual void                    customEvent( QEvent* );
277   virtual bool                    eventFilter( QObject*, QEvent* );
278
279 protected slots:
280   void                            onOperation();
281   void                            onDelete();
282   void                            onBathymetrySelection();
283   void                            onBathymetryText();
284
285
286   bool                            onUndo( int theNumActions );
287   bool                            onRedo( int theNumActions );
288
289   virtual void                    onViewManagerAdded( SUIT_ViewManager* );
290   virtual void                    onViewManagerRemoved( SUIT_ViewManager* );
291   virtual void                    onViewCreated( SUIT_ViewWindow* );
292
293   void                            onViewActivated( SUIT_ViewManager* );
294
295   void                            onViewPortMouseEvent( QGraphicsSceneMouseEvent* );
296
297   void                            onMouseMove( SUIT_ViewWindow*, QMouseEvent* );
298
299 private:
300   void                            updateViewer( HYDROGUI_AbstractDisplayer* theDisplayer, 
301                                                 const bool theIsInit = false, 
302                                                 const bool theIsForced = false, 
303                                                 const bool theDoFitAll = false );
304
305   void                            createSelector( SUIT_ViewManager* viewMgr );
306
307   bool                            setUpdateEnabled( const bool theState );
308   bool                            isUpdateEnabled() const;
309
310   QStringList                     storeSelection() const;
311   void                            restoreSelection( const QStringList& theEntryList );
312
313 private:
314   void                            createActions();
315   void                            createMenus();
316   void                            createPopups();
317   void                            createToolbars();
318
319   void                            createUndoRedoActions();
320   void                            updateUndoRedoControls();
321
322 private:
323   QAction*                        createAction( const int theId, const QString& theSuffix,
324                                                 const QString& theImg = QString::null,
325                                                 const int theKey = 0, const bool isToggle = false,
326                                                 const QString& theSlot = QString::null );
327
328 private:
329   HYDROGUI_Displayer*             myDisplayer;
330   HYDROGUI_OCCDisplayer*          myOCCDisplayer;
331   HYDROGUI_VTKPrsDisplayer*       myVTKDisplayer;
332
333   ViewManagerMap                  myViewManagerMap;
334   ViewId2Entry2ObjectStateMap     myObjectStateMap;
335
336   QStack<HYDROGUI_Operation*>     myActiveOperationMap;
337
338   ViewId2ListOfShapes             myShapesMap;
339   ViewId2ListOfVTKPrs             myVTKPrsMap;
340   bool                            myIsUpdateEnabled;
341
342   QStringList                     myGeomObjectsToImport; ///< entries of GEOM objects to be imported
343
344   ViewId2StricklerTable           myLandCoverColoringMap;
345
346   HYDROGUI_Overview*              myOverview;
347 };
348
349 #endif