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