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