Salome HOME
00c87819cb5da34642811bc1494b8f7b0c87a420
[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   void                            resetViewState();
167
168   /** 
169    * Set IsToUpdate flag for all presentations of the given object to recompute them during 
170    * the next viewer(s) updating.
171    * @param theObject the data model object
172    * @param theState  the flag to set for object's presentations, it's true by default.
173    */
174   void                            setIsToUpdate( const Handle(HYDROData_Entity)& theObject,
175                                                  const bool theState = true );
176   QList<HYDROGUI_Shape*>          getObjectShapes( const int  theViewId,
177                                                    ObjectKind theKind ) const;
178   HYDROGUI_Shape*                 getObjectShape( const int                       theViewId,
179                                                   const Handle(HYDROData_Entity)& theObject ) const;
180   void                            setObjectShape( const int                       theViewId,
181                                                   const Handle(HYDROData_Entity)& theObject,
182                                                   HYDROGUI_Shape*                 theShape );
183   void                            removeViewShapes( const int                     theViewId );
184   void                            removeObjectShape( const int                       theViewId,
185                                                      const Handle(HYDROData_Entity)& theObject );
186
187   HYDROGUI_VTKPrs*                getObjectVTKPrs( const int                       theViewId,
188                                                    const Handle(HYDROData_Entity)& theObject ) const;
189   void                            setObjectVTKPrs( const int                       theViewId,
190                                                    const Handle(HYDROData_Entity)& theObject,
191                                                    HYDROGUI_VTKPrs*                theShape );
192   void                            removeViewVTKPrs( const int                      theViewId );
193   void                            removeObjectVTKPrs( const int                      theViewId,
194                                                      const Handle(HYDROData_Entity)& theObject );
195
196   void                            removeObjectVTKPrs( const int      theViewId,
197                                                       const QString& theEntry );
198
199   /**
200    * Update global imposed range of Z values for the given VTK viewer id
201    */
202   void                            updateVTKZRange( const int theViewId, double theRange[] );
203
204   /**
205    * Returns true if the object with the given entry can be renamed.
206    * @param theEntry the object entry
207    */
208   virtual bool                    renameAllowed( const QString& theEntry ) const;
209   /**
210    * Returns true if the object with the given entry is renamed.
211    * @param theEntry the object entry
212    * @param theName the new name
213    */
214   virtual bool                    renameObject( const QString& theEntry, const QString& theName );
215
216   QStack<HYDROGUI_Operation*>&    getActiveOperations();
217   HYDROGUI_Operation*             activeOperation();
218
219   /**
220    * Returns the cursor defined for edition operations in module preferences.
221    * \return specific cursor
222    */
223   QCursor                         getPrefEditCursor() const;
224
225   void                            clearCache();
226
227   /**
228    * Returns Strickler table used for Land Cover scalar map coloring in the given view.
229    * @param theViewId the view id
230    * @return the Strickler table used for scalar map coloring of Land Covers in the given view;
231              null - if scalar map coloring is off for the view  
232    */
233   Handle(HYDROData_StricklerTable) getLandCoverColoringTable( const int theViewId ) const;
234
235   /**
236    * Set Strickler table to be used for Land Cover scalar map coloring in the given view.
237    * @param theViewId the view id
238    * @param theTable the Strickler table
239    */
240   void                             setLandCoverColoringTable( const int theViewId,
241                                                               const Handle(HYDROData_StricklerTable)& theTable );
242   /**
243    * Set Land Cover scalar map coloring mode off for the given view.
244    * @param theViewId the view id
245    */
246   void                             setLandCoversScalarMapModeOff( const int theViewId );
247
248   /**
249    * Check if Land Cover scalar map coloring mode is on in the given view.
250    * @param theViewId the view id
251    * @return true if the mode is on, false if the mode is off
252    */
253   bool                             isLandCoversScalarMapModeOn( const int theViewId ) const;
254
255   /**
256    * Set object as removed.
257    * @param theObject the removed object
258    */
259   void                            setObjectRemoved( const Handle(HYDROData_Entity)& theObject );
260
261   void                            enableLCMActions();
262
263   bool arrowsVisible() const;
264   void setArrowsVisible( bool );
265
266 protected:
267   CAM_DataModel*                  createDataModel();
268   void                            setAutoZoomToAllViewManagers(bool bAutoZoom);
269   void                            setAutoZoom(SUIT_ViewManager* aVMgr, bool bAutoZoom);
270 public slots:
271   virtual bool                    activateModule( SUIT_Study* );
272   virtual bool                    deactivateModule( SUIT_Study* );
273   virtual void                    onObjectClicked( SUIT_DataObject*, int );
274
275 protected:
276   virtual LightApp_Operation*     createOperation( const int ) const;
277   virtual bool                    reusableOperation( const int id );
278
279   virtual void                    customEvent( QEvent* );
280   virtual bool                    eventFilter( QObject*, QEvent* );
281
282 protected slots:
283   void                            onOperation();
284   void                            onDelete();
285   void                            onBathymetrySelection();
286   void                            onBathymetryText();
287
288
289   bool                            onUndo( int theNumActions );
290   bool                            onRedo( int theNumActions );
291
292   virtual void                    onViewManagerAdded( SUIT_ViewManager* );
293   virtual void                    onViewManagerRemoved( SUIT_ViewManager* );
294   virtual void                    onViewCreated( SUIT_ViewWindow* );
295
296   void                            onViewActivated( SUIT_ViewManager* );
297
298   void                            onViewPortMouseEvent( QGraphicsSceneMouseEvent* );
299
300   void                            onMouseMove( SUIT_ViewWindow*, QMouseEvent* );
301
302 private:
303   void                            updateViewer( HYDROGUI_AbstractDisplayer* theDisplayer, 
304                                                 const bool theIsInit = false, 
305                                                 const bool theIsForced = false, 
306                                                 const bool theDoFitAll = false );
307
308   void                            createSelector( SUIT_ViewManager* viewMgr );
309
310   bool                            setUpdateEnabled( const bool theState );
311   bool                            isUpdateEnabled() const;
312
313   QStringList                     storeSelection() const;
314   void                            restoreSelection( const QStringList& theEntryList );
315
316 private:
317   void                            createActions();
318   void                            createMenus();
319   void                            createPopups();
320   void                            createToolbars();
321
322   void                            createUndoRedoActions();
323   void                            updateUndoRedoControls();
324
325 private:
326   QAction*                        createAction( const int theId, const QString& theSuffix,
327                                                 const QString& theImg = QString::null,
328                                                 const int theKey = 0, const bool isToggle = false,
329                                                 const QString& theSlot = QString::null );
330
331 private:
332   HYDROGUI_Displayer*             myDisplayer;
333   HYDROGUI_OCCDisplayer*          myOCCDisplayer;
334   HYDROGUI_VTKPrsDisplayer*       myVTKDisplayer;
335
336   ViewManagerMap                  myViewManagerMap;
337   ViewId2Entry2ObjectStateMap     myObjectStateMap;
338
339   QStack<HYDROGUI_Operation*>     myActiveOperationMap;
340
341   ViewId2ListOfShapes             myShapesMap;
342   ViewId2ListOfVTKPrs             myVTKPrsMap;
343   bool                            myIsUpdateEnabled;
344
345   QStringList                     myGeomObjectsToImport; ///< entries of GEOM objects to be imported
346
347   ViewId2StricklerTable           myLandCoverColoringMap;
348
349   HYDROGUI_Overview*              myOverview;
350 };
351
352 #endif