Salome HOME
refs #514: add 'Cursor for specific operations' section into preferences of HYDRO...
[modules/hydro.git] / src / HYDROGUI / HYDROGUI_Module.h
1 // Copyright (C) 2007-2015  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 // Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
5 //
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License, or (at your option) any later version.
10 //
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14 // Lesser General Public License for more details.
15 //
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
19 //
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 //
22
23 #ifndef HYDROGUI_MODULE_H
24 #define HYDROGUI_MODULE_H
25
26 #include <HYDROData_Entity.h>
27
28 #include <LightApp_Module.h>
29
30 #include <QEvent>
31 #include <QStack>
32
33 class QGraphicsSceneMouseEvent;
34
35 class GraphicsView_Viewer;
36 class OCCViewer_Viewer;
37 class SVTK_Viewer;
38
39 class SUIT_ViewWindow;
40 class SUIT_ViewManager;
41
42 class HYDROGUI_DataModel;
43 class HYDROGUI_Displayer;
44 class HYDROGUI_OCCDisplayer;
45 class HYDROGUI_VTKPrsDisplayer;
46 class HYDROGUI_AbstractDisplayer;
47 class HYDROGUI_Shape;
48 class HYDROGUI_VTKPrs;
49 class HYDROGUI_Operation;
50
51 /**\class HYDROGUI_Module
52  *\brief The class representing the HYDROGUI module
53  */
54 class HYDROGUI_Module : public LightApp_Module
55 {
56   Q_OBJECT
57
58   enum CustomEvent { NewViewEvent = QEvent::User + 100 };
59
60   enum CursorType
61   {
62     CT_ArrowCursor = 0,
63     CT_UpArrowCursor,
64     CT_CrossCursor,
65     CT_IBeamCursor,
66     CT_WaitCursor,
67     CT_BusyCursor,
68     CT_ForbiddenCursor,
69     CT_PointingHandCursor,
70     CT_WhatsThisCursor,
71     CT_SizeVerCursor,
72     CT_SizeHorCursor,
73     CT_SizeBDiagCursor,
74     CT_SizeFDiagCursor,
75     CT_SizeAllCursor,
76     CT_SplitVCursor,
77     CT_SplitHCursor,
78     CT_OpenHandCursor,
79     CT_ClosedHandCursor,
80     CT_User
81   };
82
83 public:
84   
85   enum ViewManagerRole
86   {
87     VMR_Unknown = 0,
88     VMR_General,
89     VMR_TransformImage,
90     VMR_ReferenceImage,
91     VMR_ObserveImage,
92     //VMR_PreviewZone, // totally unused, to delete
93     VMR_PreviewCaseZones // actually unused, to review
94   };
95   typedef QPair< SUIT_ViewManager*, ViewManagerRole > ViewManagerInfo;
96
97   typedef QMap        < int, ViewManagerInfo > ViewManagerMap;
98   typedef QMapIterator< int, ViewManagerInfo > ViewManagerMapIterator;
99
100   struct ObjectState
101   {
102     bool Visibility;
103     double Transparency;
104     double ZValue;
105     ObjectState() : Visibility( false ), Transparency( 1.0 ), ZValue( 0.0 ) {}
106   };
107   typedef QMap< QString, ObjectState > Entry2ObjectStateMap;
108   typedef QMap< int, Entry2ObjectStateMap > ViewId2Entry2ObjectStateMap;
109
110   typedef QList<HYDROGUI_Shape*> ListOfShapes;
111   typedef QMap<int,ListOfShapes> ViewId2ListOfShapes;
112
113   typedef QList<HYDROGUI_VTKPrs*> ListOfVTKPrs;
114   typedef QMap<int,ListOfVTKPrs> ViewId2ListOfVTKPrs;
115
116 public:
117   HYDROGUI_Module();
118   virtual ~HYDROGUI_Module();
119
120   int                             getStudyId() const;
121
122   virtual void                    initialize( CAM_Application* );
123   virtual void                    windows( QMap<int, int>& ) const;
124   virtual void                    viewManagers( QStringList& ) const;
125
126   virtual void                    contextMenuPopup( const QString&, QMenu*, QString& );
127   virtual void                    createPreferences();
128
129   virtual void                    update( const int );
130   virtual void                    updateCommandsStatus();
131
132   virtual void                    selectionChanged();
133
134   SUIT_ViewManager*               getViewManager( const int theId ) const;
135   HYDROGUI_DataModel*             getDataModel() const;
136   HYDROGUI_Displayer*             getDisplayer() const;
137   HYDROGUI_OCCDisplayer*          getOCCDisplayer() const;
138   HYDROGUI_VTKPrsDisplayer*       getVTKDisplayer() const;
139
140   GraphicsView_Viewer*            getViewer( const int theId ) const;
141   OCCViewer_Viewer*               getOCCViewer( const int theId ) const;
142   SVTK_Viewer*                    getVTKViewer( const int theId ) const;
143
144   int                             getViewManagerId( SUIT_ViewManager* theViewManager );
145   ViewManagerRole                 getViewManagerRole( SUIT_ViewManager* theViewManager );
146   void                            setViewManagerRole( SUIT_ViewManager* theViewManager,
147                                                       const ViewManagerRole theRole );
148
149   bool                            isObjectVisible( const int theViewId,
150                                                    const Handle(HYDROData_Entity)& theObject ) const;
151   void                            setObjectVisible( const int theViewId,
152                                                     const Handle(HYDROData_Entity)& theObject,
153                                                     const bool theState );
154   /** 
155    * Set IsToUpdate flag for all presentations of the given object to recompute them during 
156    * the next viewer(s) updating.
157    * @param theObject the data model object
158    * @param theState  the flag to set for object's presentations, it's true by default.
159    */
160   void                            setIsToUpdate( const Handle(HYDROData_Entity)& theObject,
161                                                  const bool theState = true );
162   QList<HYDROGUI_Shape*>          getObjectShapes( const int  theViewId,
163                                                    ObjectKind theKind ) const;
164   HYDROGUI_Shape*                 getObjectShape( const int                       theViewId,
165                                                   const Handle(HYDROData_Entity)& theObject ) const;
166   void                            setObjectShape( const int                       theViewId,
167                                                   const Handle(HYDROData_Entity)& theObject,
168                                                   HYDROGUI_Shape*                 theShape );
169   void                            removeViewShapes( const int                     theViewId );
170   void                            removeObjectShape( const int                       theViewId,
171                                                      const Handle(HYDROData_Entity)& theObject );
172
173   HYDROGUI_VTKPrs*                getObjectVTKPrs( const int                       theViewId,
174                                                    const Handle(HYDROData_Entity)& theObject ) const;
175   void                            setObjectVTKPrs( const int                       theViewId,
176                                                    const Handle(HYDROData_Entity)& theObject,
177                                                    HYDROGUI_VTKPrs*                theShape );
178   void                            removeViewVTKPrs( const int                      theViewId );
179   void                            removeObjectVTKPrs( const int                      theViewId,
180                                                      const Handle(HYDROData_Entity)& theObject );
181
182   void                            removeObjectVTKPrs( const int      theViewId,
183                                                       const QString& theEntry );
184
185   /**
186    * Update global imposed range of Z values for the given VTK viewer id
187    */
188   void                            updateVTKZRange( const int theViewId, double theRange[] );
189
190   /**
191    * Returns true if the object with the given entry can be renamed.
192    * @param theEntry the object entry
193    */
194   virtual bool                    renameAllowed( const QString& theEntry ) const;
195   /**
196    * Returns true if the object with the given entry is renamed.
197    * @param theEntry the object entry
198    * @param theName the new name
199    */
200   virtual bool                    renameObject( const QString& theEntry, const QString& theName );
201
202   QStack<HYDROGUI_Operation*>&    getActiveOperations();
203   HYDROGUI_Operation*             activeOperation();
204
205 protected:
206   CAM_DataModel*                  createDataModel();
207
208 public slots:
209   virtual bool                    activateModule( SUIT_Study* );
210   virtual bool                    deactivateModule( SUIT_Study* );
211
212 protected:
213   virtual LightApp_Operation*     createOperation( const int ) const;
214   virtual bool                    reusableOperation( const int id );
215
216   virtual void                    customEvent( QEvent* );
217   virtual bool                    eventFilter( QObject*, QEvent* );
218
219 protected slots:
220   void                            onOperation();
221   void                            onDelete();
222
223
224   bool                            onUndo( int theNumActions );
225   bool                            onRedo( int theNumActions );
226
227   virtual void                    onViewManagerAdded( SUIT_ViewManager* );
228   virtual void                    onViewManagerRemoved( SUIT_ViewManager* );
229   virtual void                    onViewCreated( SUIT_ViewWindow* );
230
231   void                            onViewPortMouseEvent( QGraphicsSceneMouseEvent* );
232
233   void                            onMouseMove( SUIT_ViewWindow*, QMouseEvent* );
234
235 private:
236   void                            updateViewer( HYDROGUI_AbstractDisplayer* theDisplayer, 
237                                                 const bool theIsInit = false, 
238                                                 const bool theIsForced = false, 
239                                                 const bool theDoFitAll = false );
240
241   void                            createSelector( SUIT_ViewManager* viewMgr );
242
243   bool                            setUpdateEnabled( const bool theState );
244   bool                            isUpdateEnabled() const;
245
246   QStringList                     storeSelection() const;
247   void                            restoreSelection( const QStringList& theEntryList );
248
249 private:
250   void                            createActions();
251   void                            createMenus();
252   void                            createPopups();
253   void                            createToolbars();
254
255   void                            createUndoRedoActions();
256   void                            updateUndoRedoControls();
257
258 private:
259   QAction*                        createAction( const int theId, const QString& theSuffix,
260                                                 const QString& theImg = QString::null,
261                                                 const int theKey = 0, const bool isToggle = false,
262                                                 const QString& theSlot = QString::null );
263
264 private:
265   HYDROGUI_Displayer*             myDisplayer;
266   HYDROGUI_OCCDisplayer*          myOCCDisplayer;
267   HYDROGUI_VTKPrsDisplayer*       myVTKDisplayer;
268
269   ViewManagerMap                  myViewManagerMap;
270   ViewId2Entry2ObjectStateMap     myObjectStateMap;
271
272   QStack<HYDROGUI_Operation*>     myActiveOperationMap;
273
274   ViewId2ListOfShapes             myShapesMap;
275   ViewId2ListOfVTKPrs             myVTKPrsMap;
276   bool                            myIsUpdateEnabled;
277
278   QStringList                     myGeomObjectsToImport; ///< entries of GEOM objects to be imported
279 };
280
281 #endif