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_GVSelector.h>
42 #include <LightApp_SelectionMgr.h>
43 #include <LightApp_UpdateFlags.h>
45 #include <SUIT_Study.h>
46 #include <SUIT_ViewManager.h>
48 #include <QApplication>
50 extern "C" HYDRO_EXPORT CAM_Module* createModule()
52 return new HYDROGUI_Module();
55 HYDROGUI_Module::HYDROGUI_Module()
56 : LightApp_Module( "HYDRO" ),
58 myIsUpdateEnabled( true )
62 HYDROGUI_Module::~HYDROGUI_Module()
66 int HYDROGUI_Module::getStudyId() const
68 LightApp_Application* anApp = getApp();
69 return anApp ? anApp->activeStudy()->id() : 0;
72 void HYDROGUI_Module::initialize( CAM_Application* theApp )
74 LightApp_Module::initialize( theApp );
77 createUndoRedoActions();
82 setMenuShown( false );
83 setToolShown( false );
85 myDisplayer = new HYDROGUI_Displayer( this );
88 bool HYDROGUI_Module::activateModule( SUIT_Study* theStudy )
90 bool aRes = LightApp_Module::activateModule( theStudy );
95 updateCommandsStatus();
100 bool HYDROGUI_Module::deactivateModule( SUIT_Study* theStudy )
102 setMenuShown( false );
103 setToolShown( false );
105 return LightApp_Module::deactivateModule( theStudy );
108 void HYDROGUI_Module::windows( QMap<int, int>& theMap ) const
111 theMap.insert( LightApp_Application::WT_LogWindow, Qt::BottomDockWidgetArea );
112 theMap.insert( LightApp_Application::WT_ObjectBrowser, Qt::LeftDockWidgetArea );
115 void HYDROGUI_Module::viewManagers( QStringList& theTypesList ) const
117 theTypesList << GraphicsView_Viewer::Type();
120 void HYDROGUI_Module::update( const int flags )
122 if( !isUpdateEnabled() )
125 QApplication::setOverrideCursor( Qt::WaitCursor );
127 // To prevent calling this method recursively
128 // from one of the methods called below
129 setUpdateEnabled( false );
131 if( ( flags & UF_Model ) && getDataModel() )
133 getDataModel()->update( getStudyId() );
138 if( ( flags & UF_ObjBrowser ) && getObjectBrowser() )
139 updateObjectBrowser();
143 if( ( flags & UF_Viewer ) )
144 updateGV( flags & UF_GV_Init,
145 flags & UF_GV_Forced );
147 if( ( flags & UF_Controls ) && getApp() )
148 getApp()->updateActions();
150 setUpdateEnabled( true );
152 QApplication::restoreOverrideCursor();
155 void HYDROGUI_Module::updateCommandsStatus()
157 LightApp_Module::updateCommandsStatus();
159 updateUndoRedoControls();
162 //action( ... )->setEnabled( ... );
165 HYDROGUI_DataModel* HYDROGUI_Module::getDataModel() const
167 return (HYDROGUI_DataModel*)dataModel();
170 HYDROGUI_Displayer* HYDROGUI_Module::getDisplayer() const
175 GraphicsView_Viewer* HYDROGUI_Module::getViewer( const int theViewerId ) const
177 ViewManagerList aViewManagerList;
178 getApp()->viewManagers( GraphicsView_Viewer::Type(), aViewManagerList );
180 ViewManagerList::iterator anIter, anIterEnd = aViewManagerList.end();
181 for( anIter = aViewManagerList.begin(); anIter != anIterEnd; anIter++ )
183 GraphicsView_ViewManager* aViewManager =
184 dynamic_cast<GraphicsView_ViewManager*>( *anIter );
185 if( aViewManager && aViewManager->getId() == theViewerId )
186 return aViewManager->getViewer();
191 CAM_DataModel* HYDROGUI_Module::createDataModel()
193 return new HYDROGUI_DataModel( this );
196 void HYDROGUI_Module::onViewManagerAdded( SUIT_ViewManager* theViewManager )
198 LightApp_Module::onViewManagerAdded( theViewManager );
200 if( theViewManager->getType() == GraphicsView_Viewer::Type() )
202 createSelector( theViewManager ); // replace the default selector
204 connect( theViewManager, SIGNAL( viewCreated( SUIT_ViewWindow* ) ),
205 this, SLOT( onViewCreated( SUIT_ViewWindow* ) ) );
209 void HYDROGUI_Module::onViewManagerRemoved( SUIT_ViewManager* theViewManager )
211 LightApp_Module::onViewManagerRemoved( theViewManager );
213 createSelector( theViewManager ); // replace the default selector
216 void HYDROGUI_Module::onViewCreated( SUIT_ViewWindow* theWnd )
220 void HYDROGUI_Module::updateGV( const bool theIsInit,
221 const bool theIsForced )
223 if( !getDisplayer() )
226 ViewManagerList aViewManagerList;
227 getApp()->viewManagers( GraphicsView_Viewer::Type(), aViewManagerList );
229 ViewManagerList::iterator anIter, anIterEnd = aViewManagerList.end();
230 for( anIter = aViewManagerList.begin(); anIter != anIterEnd; anIter++ )
232 GraphicsView_ViewManager* aViewManager =
233 dynamic_cast<GraphicsView_ViewManager*>( *anIter );
235 getDisplayer()->UpdateAll( aViewManager->getId(), theIsInit, theIsForced );
239 void HYDROGUI_Module::createSelector( SUIT_ViewManager* theViewManager )
241 if( !theViewManager )
244 LightApp_SelectionMgr* aSelectionMgr = getApp()->selectionMgr();
248 QString aViewType = theViewManager->getType();
249 if( aViewType != GraphicsView_Viewer::Type() )
252 GraphicsView_ViewManager* aViewManager =
253 dynamic_cast<GraphicsView_ViewManager*>( theViewManager );
257 QList<SUIT_Selector*> aSelectorList;
258 aSelectionMgr->selectors( aViewType, aSelectorList );
260 // disable all alien selectors
261 QList<SUIT_Selector*>::iterator anIter, anIterEnd = aSelectorList.end();
262 for( anIter = aSelectorList.begin(); anIter != anIterEnd; anIter++ )
264 SUIT_Selector* aSelector = *anIter;
265 if( aSelector && !dynamic_cast<HYDROGUI_GVSelector*>( aSelector ) )
266 aSelector->setEnabled( false );
269 new HYDROGUI_GVSelector( this, aViewManager->getViewer(), aSelectionMgr );
272 bool HYDROGUI_Module::setUpdateEnabled( const bool theState )
274 bool aPrevState = myIsUpdateEnabled;
275 myIsUpdateEnabled = theState;
279 bool HYDROGUI_Module::isUpdateEnabled() const
281 return myIsUpdateEnabled;