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