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 virtual void preferencesChanged( const QString&, const QString& );
154 * Set IsToUpdate flag for all presentations of the given object to recompute them during
155 * the next viewer(s) updating.
156 * @param theObject the data model object
157 * @param theState the flag to set for object's presentations, it's true by default.
159 void setIsToUpdate( const Handle(HYDROData_Entity)& theObject,
160 const bool theState = true );
161 QList<HYDROGUI_Shape*> getObjectShapes( const int theViewId,
162 ObjectKind theKind ) const;
163 HYDROGUI_Shape* getObjectShape( const int theViewId,
164 const Handle(HYDROData_Entity)& theObject ) const;
165 void setObjectShape( const int theViewId,
166 const Handle(HYDROData_Entity)& theObject,
167 HYDROGUI_Shape* theShape );
168 void removeViewShapes( const int theViewId );
169 void removeObjectShape( const int theViewId,
170 const Handle(HYDROData_Entity)& theObject );
172 HYDROGUI_VTKPrs* getObjectVTKPrs( const int theViewId,
173 const Handle(HYDROData_Entity)& theObject ) const;
174 void setObjectVTKPrs( const int theViewId,
175 const Handle(HYDROData_Entity)& theObject,
176 HYDROGUI_VTKPrs* theShape );
177 void removeViewVTKPrs( const int theViewId );
178 void removeObjectVTKPrs( const int theViewId,
179 const Handle(HYDROData_Entity)& theObject );
181 void removeObjectVTKPrs( const int theViewId,
182 const QString& theEntry );
185 * Update global imposed range of Z values for the given VTK viewer id
187 void updateVTKZRange( const int theViewId, double theRange[] );
190 * Returns true if the object with the given entry can be renamed.
191 * @param theEntry the object entry
193 virtual bool renameAllowed( const QString& theEntry ) const;
195 * Returns true if the object with the given entry is renamed.
196 * @param theEntry the object entry
197 * @param theName the new name
199 virtual bool renameObject( const QString& theEntry, const QString& theName );
201 QStack<HYDROGUI_Operation*>& getActiveOperations();
202 HYDROGUI_Operation* activeOperation();
205 * Returns the cursor defined for edition operations in module preferences.
206 * \return specific cursor
208 QCursor getPrefEditCursor() const;
213 CAM_DataModel* createDataModel();
216 virtual bool activateModule( SUIT_Study* );
217 virtual bool deactivateModule( SUIT_Study* );
218 virtual void onObjectClicked( SUIT_DataObject*, int );
221 virtual LightApp_Operation* createOperation( const int ) const;
222 virtual bool reusableOperation( const int id );
224 virtual void customEvent( QEvent* );
225 virtual bool eventFilter( QObject*, QEvent* );
232 bool onUndo( int theNumActions );
233 bool onRedo( int theNumActions );
235 virtual void onViewManagerAdded( SUIT_ViewManager* );
236 virtual void onViewManagerRemoved( SUIT_ViewManager* );
237 virtual void onViewCreated( SUIT_ViewWindow* );
239 void onViewPortMouseEvent( QGraphicsSceneMouseEvent* );
241 void onMouseMove( SUIT_ViewWindow*, QMouseEvent* );
244 void updateViewer( HYDROGUI_AbstractDisplayer* theDisplayer,
245 const bool theIsInit = false,
246 const bool theIsForced = false,
247 const bool theDoFitAll = false );
249 void createSelector( SUIT_ViewManager* viewMgr );
251 bool setUpdateEnabled( const bool theState );
252 bool isUpdateEnabled() const;
254 QStringList storeSelection() const;
255 void restoreSelection( const QStringList& theEntryList );
258 void createActions();
261 void createToolbars();
263 void createUndoRedoActions();
264 void updateUndoRedoControls();
267 QAction* createAction( const int theId, const QString& theSuffix,
268 const QString& theImg = QString::null,
269 const int theKey = 0, const bool isToggle = false,
270 const QString& theSlot = QString::null );
273 HYDROGUI_Displayer* myDisplayer;
274 HYDROGUI_OCCDisplayer* myOCCDisplayer;
275 HYDROGUI_VTKPrsDisplayer* myVTKDisplayer;
277 ViewManagerMap myViewManagerMap;
278 ViewId2Entry2ObjectStateMap myObjectStateMap;
280 QStack<HYDROGUI_Operation*> myActiveOperationMap;
282 ViewId2ListOfShapes myShapesMap;
283 ViewId2ListOfVTKPrs myVTKPrsMap;
284 bool myIsUpdateEnabled;
286 QStringList myGeomObjectsToImport; ///< entries of GEOM objects to be imported