1 // Copyright (C) 2007-2013 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
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.
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.
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
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
23 #include "HYDROGUI_Module.h"
26 #include "HYDROGUI_DataModel.h"
27 #include "HYDROGUI_Displayer.h"
28 #include "HYDROGUI_GVSelector.h"
29 #include "HYDROGUI_InputPanel.h"
30 #include "HYDROGUI_ObjSelector.h"
31 #include "HYDROGUI_Operations.h"
32 #include "HYDROGUI_PrsImage.h"
33 #include "HYDROGUI_UpdateFlags.h"
35 #include <GraphicsView_ViewFrame.h>
36 #include <GraphicsView_ViewManager.h>
37 #include <GraphicsView_ViewPort.h>
38 #include <GraphicsView_Viewer.h>
40 #include <LightApp_Application.h>
41 #include <LightApp_DataOwner.h>
42 #include <LightApp_GVSelector.h>
43 #include <LightApp_SelectionMgr.h>
44 #include <LightApp_UpdateFlags.h>
46 #include <SALOME_Event.h>
48 #include <SUIT_Study.h>
49 #include <SUIT_ViewManager.h>
52 #include <QApplication>
55 extern "C" HYDRO_EXPORT CAM_Module* createModule()
57 return new HYDROGUI_Module();
60 HYDROGUI_Module::HYDROGUI_Module()
61 : LightApp_Module( "HYDRO" ),
63 myIsUpdateEnabled( true )
67 HYDROGUI_Module::~HYDROGUI_Module()
71 int HYDROGUI_Module::getStudyId() const
73 LightApp_Application* anApp = getApp();
74 return anApp ? anApp->activeStudy()->id() : 0;
77 void HYDROGUI_Module::initialize( CAM_Application* theApp )
79 LightApp_Module::initialize( theApp );
82 createUndoRedoActions();
87 setMenuShown( false );
88 setToolShown( false );
90 myDisplayer = new HYDROGUI_Displayer( this );
93 bool HYDROGUI_Module::activateModule( SUIT_Study* theStudy )
95 bool aRes = LightApp_Module::activateModule( theStudy );
102 updateCommandsStatus();
107 bool HYDROGUI_Module::deactivateModule( SUIT_Study* theStudy )
109 setMenuShown( false );
110 setToolShown( false );
112 return LightApp_Module::deactivateModule( theStudy );
115 void HYDROGUI_Module::windows( QMap<int, int>& theMap ) const
118 theMap.insert( LightApp_Application::WT_LogWindow, Qt::BottomDockWidgetArea );
119 theMap.insert( LightApp_Application::WT_ObjectBrowser, Qt::LeftDockWidgetArea );
122 void HYDROGUI_Module::viewManagers( QStringList& theTypesList ) const
124 theTypesList << GraphicsView_Viewer::Type();
127 void HYDROGUI_Module::contextMenuPopup( const QString& theClient,
131 HYDROGUI_DataModel* aModel = getDataModel();
133 LightApp_SelectionMgr* aSelectionMgr = getApp()->selectionMgr();
137 SUIT_DataOwnerPtrList anOwners;
138 aSelectionMgr->selected( anOwners );
140 bool anIsSelection = false;
141 bool anIsVisibleInSelection = false;
142 bool anIsHiddenInSelection = false;
144 bool anIsImage = false;
146 foreach( SUIT_DataOwner* aSUITOwner, anOwners )
148 if( LightApp_DataOwner* anOwner = dynamic_cast<LightApp_DataOwner*>( aSUITOwner ) )
150 Handle(HYDROData_Object) anObject = aModel->objectByEntry( anOwner->entry() );
151 if( !anObject.IsNull() )
153 anIsSelection = true;
155 bool aVisibility = anObject->GetVisibility();
156 anIsVisibleInSelection |= aVisibility;
157 anIsHiddenInSelection |= !aVisibility;
159 if( anObject->GetKind() == KIND_IMAGE )
165 if( anOwners.count() == 1 && anIsImage )
167 theMenu->addAction( action( EditImageId ) );
168 theMenu->addSeparator();
173 theMenu->addAction( action( DeleteId ) );
174 theMenu->addSeparator();
179 if( anIsHiddenInSelection )
180 theMenu->addAction( action( ShowId ) );
181 theMenu->addAction( action( ShowOnlyId ) );
182 if( anIsVisibleInSelection )
183 theMenu->addAction( action( HideId ) );
184 theMenu->addSeparator();
186 theMenu->addAction( action( ShowAllId ) );
187 theMenu->addAction( action( HideAllId ) );
188 theMenu->addSeparator();
191 void HYDROGUI_Module::update( const int flags )
193 if( !isUpdateEnabled() )
196 QApplication::setOverrideCursor( Qt::WaitCursor );
198 // To prevent calling this method recursively
199 // from one of the methods called below
200 setUpdateEnabled( false );
202 if( ( flags & UF_Model ) && getDataModel() )
204 getDataModel()->update( getStudyId() );
209 if( ( flags & UF_ObjBrowser ) && getObjectBrowser() )
210 updateObjectBrowser();
214 if( ( flags & UF_Viewer ) )
215 updateGV( flags & UF_GV_Init,
216 flags & UF_GV_Forced );
218 if( ( flags & UF_Controls ) && getApp() )
219 getApp()->updateActions();
221 setUpdateEnabled( true );
223 QApplication::restoreOverrideCursor();
226 void HYDROGUI_Module::updateCommandsStatus()
228 LightApp_Module::updateCommandsStatus();
230 updateUndoRedoControls();
233 //action( ... )->setEnabled( ... );
236 HYDROGUI_DataModel* HYDROGUI_Module::getDataModel() const
238 return (HYDROGUI_DataModel*)dataModel();
241 HYDROGUI_Displayer* HYDROGUI_Module::getDisplayer() const
246 GraphicsView_Viewer* HYDROGUI_Module::getViewer( const int theViewerId ) const
248 ViewManagerList aViewManagerList;
249 getApp()->viewManagers( GraphicsView_Viewer::Type(), aViewManagerList );
251 ViewManagerList::iterator anIter, anIterEnd = aViewManagerList.end();
252 for( anIter = aViewManagerList.begin(); anIter != anIterEnd; anIter++ )
254 GraphicsView_ViewManager* aViewManager =
255 dynamic_cast<GraphicsView_ViewManager*>( *anIter );
256 if( aViewManager && aViewManager->getId() == theViewerId )
257 return aViewManager->getViewer();
262 CAM_DataModel* HYDROGUI_Module::createDataModel()
264 return new HYDROGUI_DataModel( this );
267 void HYDROGUI_Module::customEvent( QEvent* e )
269 int aType = e->type();
270 if ( aType == NewViewEvent )
272 SALOME_CustomEvent* ce = ( SALOME_CustomEvent* )e;
273 if( GraphicsView_ViewFrame* aViewFrame = ( GraphicsView_ViewFrame* )ce->data() )
275 if( GraphicsView_Viewer* aViewer = dynamic_cast<GraphicsView_Viewer*>( aViewFrame->getViewer() ) )
277 //update( UF_Viewer | UF_GV_Forced ); // ouv: to do
278 aViewer->activateTransform( GraphicsView_Viewer::FitAll );
280 if( GraphicsView_ViewPort* aViewPort = aViewer->getActiveViewPort() )
282 aViewPort->setInteractionFlag( GraphicsView_ViewPort::TraceBoundingRect );
283 aViewPort->setInteractionFlag( GraphicsView_ViewPort::ImmediateContextMenu );
284 aViewPort->setInteractionFlag( GraphicsView_ViewPort::ImmediateSelection );
287 aViewPort->setMousePositionEnabled( true );
294 bool HYDROGUI_Module::eventFilter( QObject* theObj, QEvent* theEvent )
296 QEvent::Type aType = theEvent->type();
297 if( theObj->inherits( "GraphicsView_ViewFrame" ) )
299 if( aType == QEvent::Show )
301 SALOME_CustomEvent* e = new SALOME_CustomEvent( NewViewEvent );
302 e->setData( theObj );
303 QApplication::postEvent( this, e );
304 theObj->removeEventFilter( this );
307 return LightApp_Module::eventFilter( theObj, theEvent );
310 void HYDROGUI_Module::onViewManagerAdded( SUIT_ViewManager* theViewManager )
312 LightApp_Module::onViewManagerAdded( theViewManager );
314 if( theViewManager->getType() == GraphicsView_Viewer::Type() )
316 createSelector( theViewManager ); // replace the default selector
318 connect( theViewManager, SIGNAL( viewCreated( SUIT_ViewWindow* ) ),
319 this, SLOT( onViewCreated( SUIT_ViewWindow* ) ) );
323 void HYDROGUI_Module::onViewManagerRemoved( SUIT_ViewManager* theViewManager )
325 LightApp_Module::onViewManagerRemoved( theViewManager );
327 createSelector( theViewManager ); // replace the default selector
330 void HYDROGUI_Module::onViewCreated( SUIT_ViewWindow* theViewWindow )
332 if( theViewWindow && theViewWindow->inherits( "GraphicsView_ViewFrame" ) )
334 if( GraphicsView_ViewFrame* aViewFrame = dynamic_cast<GraphicsView_ViewFrame*>( theViewWindow ) )
336 aViewFrame->installEventFilter( this );
341 void HYDROGUI_Module::updateGV( const bool theIsInit,
342 const bool theIsForced )
344 if( !getDisplayer() )
347 ViewManagerList aViewManagerList;
348 getApp()->viewManagers( GraphicsView_Viewer::Type(), aViewManagerList );
350 ViewManagerList::iterator anIter, anIterEnd = aViewManagerList.end();
351 for( anIter = aViewManagerList.begin(); anIter != anIterEnd; anIter++ )
353 GraphicsView_ViewManager* aViewManager =
354 dynamic_cast<GraphicsView_ViewManager*>( *anIter );
356 getDisplayer()->UpdateAll( aViewManager->getId(), theIsInit, theIsForced );
360 void HYDROGUI_Module::createSelector( SUIT_ViewManager* theViewManager )
362 if( !theViewManager )
365 LightApp_SelectionMgr* aSelectionMgr = getApp()->selectionMgr();
369 QString aViewType = theViewManager->getType();
370 if( aViewType != GraphicsView_Viewer::Type() )
373 GraphicsView_ViewManager* aViewManager =
374 dynamic_cast<GraphicsView_ViewManager*>( theViewManager );
378 QList<SUIT_Selector*> aSelectorList;
379 aSelectionMgr->selectors( aViewType, aSelectorList );
381 // disable all alien selectors
382 QList<SUIT_Selector*>::iterator anIter, anIterEnd = aSelectorList.end();
383 for( anIter = aSelectorList.begin(); anIter != anIterEnd; anIter++ )
385 SUIT_Selector* aSelector = *anIter;
386 if( aSelector && !dynamic_cast<HYDROGUI_GVSelector*>( aSelector ) )
387 aSelector->setEnabled( false );
390 new HYDROGUI_GVSelector( this, aViewManager->getViewer(), aSelectionMgr );
393 bool HYDROGUI_Module::setUpdateEnabled( const bool theState )
395 bool aPrevState = myIsUpdateEnabled;
396 myIsUpdateEnabled = theState;
400 bool HYDROGUI_Module::isUpdateEnabled() const
402 return myIsUpdateEnabled;