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.
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.
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
16 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
19 #ifndef HYDROGUI_MODULE_H
20 #define HYDROGUI_MODULE_H
22 #include <HYDROData_Entity.h>
24 #include <LightApp_Module.h>
29 class QGraphicsSceneMouseEvent;
31 class GraphicsView_Viewer;
32 class OCCViewer_Viewer;
35 class SUIT_ViewWindow;
36 class SUIT_ViewManager;
38 class HYDROGUI_DataModel;
39 class HYDROGUI_Displayer;
40 class HYDROGUI_OCCDisplayer;
41 class HYDROGUI_VTKPrsDisplayer;
42 class HYDROGUI_AbstractDisplayer;
44 class HYDROGUI_VTKPrs;
45 class HYDROGUI_Operation;
47 /**\class HYDROGUI_Module
48 *\brief The class representing the HYDROGUI module
50 class HYDROGUI_Module : public LightApp_Module
54 enum CustomEvent { NewViewEvent = QEvent::User + 100 };
70 CT_PointingHandCursor,
88 //VMR_PreviewZone, // totally unused, to delete
89 VMR_PreviewCaseZones // actually unused, to review
91 typedef QPair< SUIT_ViewManager*, ViewManagerRole > ViewManagerInfo;
93 typedef QMap < int, ViewManagerInfo > ViewManagerMap;
94 typedef QMapIterator< int, ViewManagerInfo > ViewManagerMapIterator;
101 ObjectState() : Visibility( false ), Transparency( 1.0 ), ZValue( 0.0 ) {}
103 typedef QMap< QString, ObjectState > Entry2ObjectStateMap;
104 typedef QMap< int, Entry2ObjectStateMap > ViewId2Entry2ObjectStateMap;
106 typedef QList<HYDROGUI_Shape*> ListOfShapes;
107 typedef QMap<int,ListOfShapes> ViewId2ListOfShapes;
109 typedef QList<HYDROGUI_VTKPrs*> ListOfVTKPrs;
110 typedef QMap<int,ListOfVTKPrs> ViewId2ListOfVTKPrs;
114 virtual ~HYDROGUI_Module();
116 int getStudyId() const;
118 virtual void initialize( CAM_Application* );
119 virtual void windows( QMap<int, int>& ) const;
120 virtual void viewManagers( QStringList& ) const;
122 virtual void contextMenuPopup( const QString&, QMenu*, QString& );
123 virtual void createPreferences();
125 virtual void update( const int );
126 virtual void updateCommandsStatus();
128 virtual void selectionChanged();
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;
136 GraphicsView_Viewer* getViewer( const int theId ) const;
137 OCCViewer_Viewer* getOCCViewer( const int theId ) const;
138 SVTK_Viewer* getVTKViewer( const int theId ) const;
140 int getViewManagerId( SUIT_ViewManager* theViewManager );
141 ViewManagerRole getViewManagerRole( SUIT_ViewManager* theViewManager );
142 void setViewManagerRole( SUIT_ViewManager* theViewManager,
143 const ViewManagerRole theRole );
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 );
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.
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 );
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 );
178 void removeObjectVTKPrs( const int theViewId,
179 const QString& theEntry );
182 * Update global imposed range of Z values for the given VTK viewer id
184 void updateVTKZRange( const int theViewId, double theRange[] );
187 * Returns true if the object with the given entry can be renamed.
188 * @param theEntry the object entry
190 virtual bool renameAllowed( const QString& theEntry ) const;
192 * Returns true if the object with the given entry is renamed.
193 * @param theEntry the object entry
194 * @param theName the new name
196 virtual bool renameObject( const QString& theEntry, const QString& theName );
198 QStack<HYDROGUI_Operation*>& getActiveOperations();
199 HYDROGUI_Operation* activeOperation();
202 * Returns the cursor defined for edition operations in module preferences.
203 * \return specific cursor
205 QCursor getPrefEditCursor() const;
208 CAM_DataModel* createDataModel();
211 virtual bool activateModule( SUIT_Study* );
212 virtual bool deactivateModule( SUIT_Study* );
213 virtual void onObjectClicked( SUIT_DataObject*, int );
216 virtual LightApp_Operation* createOperation( const int ) const;
217 virtual bool reusableOperation( const int id );
219 virtual void customEvent( QEvent* );
220 virtual bool eventFilter( QObject*, QEvent* );
227 bool onUndo( int theNumActions );
228 bool onRedo( int theNumActions );
230 virtual void onViewManagerAdded( SUIT_ViewManager* );
231 virtual void onViewManagerRemoved( SUIT_ViewManager* );
232 virtual void onViewCreated( SUIT_ViewWindow* );
234 void onViewPortMouseEvent( QGraphicsSceneMouseEvent* );
236 void onMouseMove( SUIT_ViewWindow*, QMouseEvent* );
239 void updateViewer( HYDROGUI_AbstractDisplayer* theDisplayer,
240 const bool theIsInit = false,
241 const bool theIsForced = false,
242 const bool theDoFitAll = false );
244 void createSelector( SUIT_ViewManager* viewMgr );
246 bool setUpdateEnabled( const bool theState );
247 bool isUpdateEnabled() const;
249 QStringList storeSelection() const;
250 void restoreSelection( const QStringList& theEntryList );
253 void createActions();
256 void createToolbars();
258 void createUndoRedoActions();
259 void updateUndoRedoControls();
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 );
268 HYDROGUI_Displayer* myDisplayer;
269 HYDROGUI_OCCDisplayer* myOCCDisplayer;
270 HYDROGUI_VTKPrsDisplayer* myVTKDisplayer;
272 ViewManagerMap myViewManagerMap;
273 ViewId2Entry2ObjectStateMap myObjectStateMap;
275 QStack<HYDROGUI_Operation*> myActiveOperationMap;
277 ViewId2ListOfShapes myShapesMap;
278 ViewId2ListOfVTKPrs myVTKPrsMap;
279 bool myIsUpdateEnabled;
281 QStringList myGeomObjectsToImport; ///< entries of GEOM objects to be imported