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>
25 #pragma warning ( disable: 4251 )
28 #include <LightApp_Module.h>
29 #include <LightApp_Application.h>
32 #include <HYDROGUI_DataObject.h>
35 #pragma warning ( default: 4251 )
38 class QGraphicsSceneMouseEvent;
39 class GraphicsView_Viewer;
40 class OCCViewer_Viewer;
43 class SUIT_ViewWindow;
44 class SUIT_ViewManager;
46 class HYDROData_StricklerTable;
48 class HYDROGUI_DataModel;
49 class HYDROGUI_Displayer;
50 class HYDROGUI_OCCDisplayer;
51 class HYDROGUI_VTKPrsDisplayer;
52 class HYDROGUI_AbstractDisplayer;
54 class HYDROGUI_VTKPrs;
55 class HYDROGUI_Operation;
56 class HYDROGUI_Overview;
58 /**\class HYDROGUI_Module
59 *\brief The class representing the HYDROGUI module
61 class HYDROGUI_Module : public LightApp_Module
65 enum CustomEvent { NewViewEvent = QEvent::User + 100 };
66 enum CustomWindows { OverviewWindow = LightApp_Application::WT_User + 100 };
82 CT_PointingHandCursor,
100 //VMR_PreviewZone, // totally unused, to delete
101 VMR_PreviewCaseZones // actually unused, to review
103 typedef QPair< SUIT_ViewManager*, ViewManagerRole > ViewManagerInfo;
105 typedef QMap < int, ViewManagerInfo > ViewManagerMap;
106 typedef QMapIterator< int, ViewManagerInfo > ViewManagerMapIterator;
113 ObjectState() : Visibility( false ), Transparency( 1.0 ), ZValue( 0.0 ) {}
115 typedef QMap< QString, ObjectState > Entry2ObjectStateMap;
116 typedef QMap< int, Entry2ObjectStateMap > ViewId2Entry2ObjectStateMap;
118 typedef QList<HYDROGUI_Shape*> ListOfShapes;
119 typedef QMap<int,ListOfShapes> ViewId2ListOfShapes;
121 typedef QList<HYDROGUI_VTKPrs*> ListOfVTKPrs;
122 typedef QMap<int,ListOfVTKPrs> ViewId2ListOfVTKPrs;
124 typedef QMap<int, Handle(HYDROData_StricklerTable)> ViewId2StricklerTable;
128 virtual ~HYDROGUI_Module();
130 int getStudyId() const;
132 virtual void initialize( CAM_Application* );
133 virtual void windows( QMap<int, int>& ) const;
134 virtual void viewManagers( QStringList& ) const;
136 virtual void contextMenuPopup( const QString&, QMenu*, QString& );
137 virtual void createPreferences();
139 virtual void update( const int );
140 virtual void updateCommandsStatus();
142 virtual void selectionChanged();
144 SUIT_ViewManager* getViewManager( const int theId ) const;
145 HYDROGUI_DataModel* getDataModel() const;
146 HYDROGUI_Displayer* getDisplayer() const;
147 HYDROGUI_OCCDisplayer* getOCCDisplayer() const;
148 HYDROGUI_VTKPrsDisplayer* getVTKDisplayer() const;
150 GraphicsView_Viewer* getViewer( const int theId ) const;
151 OCCViewer_Viewer* getOCCViewer( const int theId ) const;
152 SVTK_Viewer* getVTKViewer( const int theId ) const;
154 int getViewManagerId( SUIT_ViewManager* theViewManager );
155 ViewManagerRole getViewManagerRole( SUIT_ViewManager* theViewManager );
156 void setViewManagerRole( SUIT_ViewManager* theViewManager,
157 const ViewManagerRole theRole );
159 bool isObjectVisible( const int theViewId,
160 const Handle(HYDROData_Entity)& theObject ) const;
161 void setObjectVisible( const int theViewId,
162 const Handle(HYDROData_Entity)& theObject,
163 const bool theState );
165 virtual void preferencesChanged( const QString&, const QString& );
167 void resetViewState();
170 * Set IsToUpdate flag for all presentations of the given object to recompute them during
171 * the next viewer(s) updating.
172 * @param theObject the data model object
173 * @param theState the flag to set for object's presentations, it's true by default.
175 void setIsToUpdate( const Handle(HYDROData_Entity)& theObject,
176 const bool theState = true );
177 QList<HYDROGUI_Shape*> getObjectShapes( const int theViewId,
178 ObjectKind theKind ) const;
179 HYDROGUI_Shape* getObjectShape( const int theViewId,
180 const Handle(HYDROData_Entity)& theObject ) const;
181 void setObjectShape( const int theViewId,
182 const Handle(HYDROData_Entity)& theObject,
183 HYDROGUI_Shape* theShape );
184 void removeViewShapes( const int theViewId );
185 void removeObjectShape( const int theViewId,
186 const Handle(HYDROData_Entity)& theObject );
188 HYDROGUI_VTKPrs* getObjectVTKPrs( const int theViewId,
189 const Handle(HYDROData_Entity)& theObject ) const;
190 void setObjectVTKPrs( const int theViewId,
191 const Handle(HYDROData_Entity)& theObject,
192 HYDROGUI_VTKPrs* theShape );
193 void removeViewVTKPrs( const int theViewId );
194 void removeObjectVTKPrs( const int theViewId,
195 const Handle(HYDROData_Entity)& theObject );
197 void removeObjectVTKPrs( const int theViewId,
198 const QString& theEntry );
201 * Update global imposed range of Z values for the given VTK viewer id
203 void updateVTKZRange( const int theViewId, double theRange[] );
206 * Returns true if the object with the given entry can be renamed.
207 * @param theEntry the object entry
209 virtual bool renameAllowed( const QString& theEntry ) const;
211 * Returns true if the object with the given entry is renamed.
212 * @param theEntry the object entry
213 * @param theName the new name
215 virtual bool renameObject( const QString& theEntry, const QString& theName );
217 QStack<HYDROGUI_Operation*>& getActiveOperations();
218 HYDROGUI_Operation* activeOperation();
221 * Returns the cursor defined for edition operations in module preferences.
222 * \return specific cursor
224 QCursor getPrefEditCursor() const;
228 bool isDraggable( const SUIT_DataObject* what ) const;
230 bool isDropAccepted( const SUIT_DataObject* where ) const;
232 void dropObjects( const DataObjectList& what, SUIT_DataObject* where,
233 const int row, Qt::DropAction action );
236 * Returns Strickler table used for Land Cover scalar map coloring in the given view.
237 * @param theViewId the view id
238 * @return the Strickler table used for scalar map coloring of Land Covers in the given view;
239 null - if scalar map coloring is off for the view
241 Handle(HYDROData_StricklerTable) getLandCoverColoringTable( const int theViewId ) const;
244 * Set Strickler table to be used for Land Cover scalar map coloring in the given view.
245 * @param theViewId the view id
246 * @param theTable the Strickler table
248 void setLandCoverColoringTable( const int theViewId,
249 const Handle(HYDROData_StricklerTable)& theTable );
251 * Set Land Cover scalar map coloring mode off for the given view.
252 * @param theViewId the view id
254 void setLandCoversScalarMapModeOff( const int theViewId );
257 * Check if Land Cover scalar map coloring mode is on in the given view.
258 * @param theViewId the view id
259 * @return true if the mode is on, false if the mode is off
261 bool isLandCoversScalarMapModeOn( const int theViewId ) const;
264 * Set object as removed.
265 * @param theObject the removed object
267 void setObjectRemoved( const Handle(HYDROData_Entity)& theObject );
269 void enableLCMActions();
271 bool arrowsVisible() const;
272 void setArrowsVisible( bool );
275 CAM_DataModel* createDataModel();
276 void setAutoZoomToAllViewManagers(bool bAutoZoom);
277 void setAutoZoom(SUIT_ViewManager* aVMgr, bool bAutoZoom);
279 virtual bool activateModule( SUIT_Study* );
280 virtual bool deactivateModule( SUIT_Study* );
281 virtual void onObjectClicked( SUIT_DataObject*, int );
284 virtual LightApp_Operation* createOperation( const int ) const;
285 virtual bool reusableOperation( const int id );
287 virtual void customEvent( QEvent* );
288 virtual bool eventFilter( QObject*, QEvent* );
293 void onBathymetrySelection();
294 void onBathymetryText();
297 bool onUndo( int theNumActions );
298 bool onRedo( int theNumActions );
300 virtual void onViewManagerAdded( SUIT_ViewManager* );
301 virtual void onViewManagerRemoved( SUIT_ViewManager* );
302 virtual void onViewCreated( SUIT_ViewWindow* );
304 void onViewActivated( SUIT_ViewManager* );
306 void onViewPortMouseEvent( QGraphicsSceneMouseEvent* );
308 void onMouseMove( SUIT_ViewWindow*, QMouseEvent* );
311 void updateViewer( HYDROGUI_AbstractDisplayer* theDisplayer,
312 const bool theIsInit = false,
313 const bool theIsForced = false,
314 const bool theDoFitAll = false );
316 void createSelector( SUIT_ViewManager* viewMgr );
318 bool setUpdateEnabled( const bool theState );
319 bool isUpdateEnabled() const;
321 QStringList storeSelection() const;
322 void restoreSelection( const QStringList& theEntryList );
325 void createActions();
328 void createToolbars();
330 void createUndoRedoActions();
331 void updateUndoRedoControls();
334 QAction* createAction( const int theId, const QString& theSuffix,
335 const QString& theImg = QString::null,
336 const int theKey = 0, const bool isToggle = false,
337 const QString& theSlot = QString::null );
340 HYDROGUI_Displayer* myDisplayer;
341 HYDROGUI_OCCDisplayer* myOCCDisplayer;
342 HYDROGUI_VTKPrsDisplayer* myVTKDisplayer;
344 ViewManagerMap myViewManagerMap;
345 ViewId2Entry2ObjectStateMap myObjectStateMap;
347 QStack<HYDROGUI_Operation*> myActiveOperationMap;
349 ViewId2ListOfShapes myShapesMap;
350 ViewId2ListOfVTKPrs myVTKPrsMap;
351 bool myIsUpdateEnabled;
353 QStringList myGeomObjectsToImport; ///< entries of GEOM objects to be imported
355 ViewId2StricklerTable myLandCoverColoringMap;
357 HYDROGUI_Overview* myOverview;