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 );
81 setMenuShown( false );
83 myDisplayer = new HYDROGUI_Displayer( this );
86 bool HYDROGUI_Module::activateModule( SUIT_Study* theStudy )
89 return LightApp_Module::activateModule( theStudy );
92 void HYDROGUI_Module::windows( QMap<int, int>& theMap ) const
95 theMap.insert( LightApp_Application::WT_LogWindow, Qt::BottomDockWidgetArea );
96 theMap.insert( LightApp_Application::WT_ObjectBrowser, Qt::LeftDockWidgetArea );
99 void HYDROGUI_Module::viewManagers( QStringList& theTypesList ) const
101 theTypesList << GraphicsView_Viewer::Type();
104 void HYDROGUI_Module::update( const int flags )
106 if( !isUpdateEnabled() )
109 QApplication::setOverrideCursor( Qt::WaitCursor );
111 // To prevent calling this method recursively
112 // from one of the methods called below
113 setUpdateEnabled( false );
115 if( ( flags & UF_Model ) && getDataModel() )
117 getDataModel()->update( getStudyId() );
122 if( ( flags & UF_ObjBrowser ) && getObjectBrowser() )
123 updateObjectBrowser();
127 if( ( flags & UF_Viewer ) )
128 updateGV( flags & UF_GV_Init,
129 flags & UF_GV_Forced );
131 if( ( flags & UF_Controls ) && getApp() )
132 getApp()->updateActions();
134 setUpdateEnabled( true );
136 QApplication::restoreOverrideCursor();
139 HYDROGUI_DataModel* HYDROGUI_Module::getDataModel() const
141 return (HYDROGUI_DataModel*)dataModel();
144 HYDROGUI_Displayer* HYDROGUI_Module::getDisplayer() const
149 GraphicsView_Viewer* HYDROGUI_Module::getViewer( const int theViewerId ) const
151 ViewManagerList aViewManagerList;
152 getApp()->viewManagers( GraphicsView_Viewer::Type(), aViewManagerList );
154 ViewManagerList::iterator anIter, anIterEnd = aViewManagerList.end();
155 for( anIter = aViewManagerList.begin(); anIter != anIterEnd; anIter++ )
157 GraphicsView_ViewManager* aViewManager =
158 dynamic_cast<GraphicsView_ViewManager*>( *anIter );
159 if( aViewManager && aViewManager->getId() == theViewerId )
160 return aViewManager->getViewer();
165 CAM_DataModel* HYDROGUI_Module::createDataModel()
167 return new HYDROGUI_DataModel( this );
170 void HYDROGUI_Module::onViewManagerAdded( SUIT_ViewManager* theViewManager )
172 LightApp_Module::onViewManagerAdded( theViewManager );
174 if( theViewManager->getType() == GraphicsView_Viewer::Type() )
176 createSelector( theViewManager ); // replace the default selector
178 connect( theViewManager, SIGNAL( viewCreated( SUIT_ViewWindow* ) ),
179 this, SLOT( onViewCreated( SUIT_ViewWindow* ) ) );
183 void HYDROGUI_Module::onViewManagerRemoved( SUIT_ViewManager* theViewManager )
185 LightApp_Module::onViewManagerRemoved( theViewManager );
187 createSelector( theViewManager ); // replace the default selector
190 void HYDROGUI_Module::onViewCreated( SUIT_ViewWindow* theWnd )
194 void HYDROGUI_Module::updateGV( const bool theIsInit,
195 const bool theIsForced )
197 if( !getDisplayer() )
200 ViewManagerList aViewManagerList;
201 getApp()->viewManagers( GraphicsView_Viewer::Type(), aViewManagerList );
203 ViewManagerList::iterator anIter, anIterEnd = aViewManagerList.end();
204 for( anIter = aViewManagerList.begin(); anIter != anIterEnd; anIter++ )
206 GraphicsView_ViewManager* aViewManager =
207 dynamic_cast<GraphicsView_ViewManager*>( *anIter );
209 getDisplayer()->UpdateAll( aViewManager->getId(), theIsInit, theIsForced );
213 void HYDROGUI_Module::createSelector( SUIT_ViewManager* theViewManager )
215 if( !theViewManager )
218 LightApp_SelectionMgr* aSelectionMgr = getApp()->selectionMgr();
222 QString aViewType = theViewManager->getType();
223 if( aViewType != GraphicsView_Viewer::Type() )
226 GraphicsView_ViewManager* aViewManager =
227 dynamic_cast<GraphicsView_ViewManager*>( theViewManager );
231 QList<SUIT_Selector*> aSelectorList;
232 aSelectionMgr->selectors( aViewType, aSelectorList );
234 // disable all alien selectors
235 QList<SUIT_Selector*>::iterator anIter, anIterEnd = aSelectorList.end();
236 for( anIter = aSelectorList.begin(); anIter != anIterEnd; anIter++ )
238 SUIT_Selector* aSelector = *anIter;
239 if( aSelector && !dynamic_cast<HYDROGUI_GVSelector*>( aSelector ) )
240 aSelector->setEnabled( false );
243 new HYDROGUI_GVSelector( this, aViewManager->getViewer(), aSelectionMgr );
246 bool HYDROGUI_Module::setUpdateEnabled( const bool theState )
248 bool aPrevState = myIsUpdateEnabled;
249 myIsUpdateEnabled = theState;
253 bool HYDROGUI_Module::isUpdateEnabled() const
255 return myIsUpdateEnabled;