]> SALOME platform Git repositories - modules/hydro.git/blob - src/HYDROGUI/HYDROGUI_Module.cxx
Salome HOME
Undo/Redo operation.
[modules/hydro.git] / src / HYDROGUI / HYDROGUI_Module.cxx
1 // Copyright (C) 2007-2013  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 // Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
5 //
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.
10 //
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.
15 //
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
19 //
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 //
22
23 #include "HYDROGUI_Module.h"
24
25 #include "HYDROGUI.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"
34
35 #include <GraphicsView_ViewFrame.h>
36 #include <GraphicsView_ViewManager.h>
37 #include <GraphicsView_ViewPort.h>
38 #include <GraphicsView_Viewer.h>
39
40 #include <LightApp_Application.h>
41 #include <LightApp_GVSelector.h>
42 #include <LightApp_SelectionMgr.h>
43 #include <LightApp_UpdateFlags.h>
44
45 #include <SUIT_Study.h>
46 #include <SUIT_ViewManager.h>
47
48 #include <QApplication>
49
50 extern "C" HYDRO_EXPORT CAM_Module* createModule()
51 {
52   return new HYDROGUI_Module();
53 }
54
55 HYDROGUI_Module::HYDROGUI_Module()
56 : LightApp_Module( "HYDRO" ),
57   myDisplayer( 0 ),
58   myIsUpdateEnabled( true )
59 {
60 }
61
62 HYDROGUI_Module::~HYDROGUI_Module()
63 {
64 }
65
66 int HYDROGUI_Module::getStudyId() const
67 {
68   LightApp_Application* anApp = getApp();
69   return anApp ? anApp->activeStudy()->id() : 0;
70 }
71
72 void HYDROGUI_Module::initialize( CAM_Application* theApp )
73 {
74   LightApp_Module::initialize( theApp );
75
76   createActions();
77   createUndoRedoActions();
78   createMenus();
79   createPopups();
80   createToolbars();
81
82   setMenuShown( false );
83   setToolShown( false );
84
85   myDisplayer = new HYDROGUI_Displayer( this );
86 }
87
88 bool HYDROGUI_Module::activateModule( SUIT_Study* theStudy )
89 {
90   bool aRes = LightApp_Module::activateModule( theStudy );
91
92   setMenuShown( true );
93   setToolShown( true );
94
95   updateCommandsStatus();
96
97   return aRes;
98 }
99
100 bool HYDROGUI_Module::deactivateModule( SUIT_Study* theStudy )
101 {
102   setMenuShown( false );
103   setToolShown( false );
104
105   return LightApp_Module::deactivateModule( theStudy );
106 }
107
108 void HYDROGUI_Module::windows( QMap<int, int>& theMap ) const
109 {
110   theMap.clear();
111   theMap.insert( LightApp_Application::WT_LogWindow,     Qt::BottomDockWidgetArea );
112   theMap.insert( LightApp_Application::WT_ObjectBrowser, Qt::LeftDockWidgetArea   );
113 }
114
115 void HYDROGUI_Module::viewManagers( QStringList& theTypesList ) const
116 {
117   theTypesList << GraphicsView_Viewer::Type();
118 }
119
120 void HYDROGUI_Module::update( const int flags )
121 {
122   if( !isUpdateEnabled() )
123     return;
124
125   QApplication::setOverrideCursor( Qt::WaitCursor );
126
127   // To prevent calling this method recursively
128   // from one of the methods called below
129   setUpdateEnabled( false );
130
131   if( ( flags & UF_Model ) && getDataModel() )
132   {
133     getDataModel()->update( getStudyId() );
134   }
135   else
136   {
137     /* to do
138     if( ( flags & UF_ObjBrowser ) && getObjectBrowser() )
139       updateObjectBrowser();
140     */
141   }
142
143   if( ( flags & UF_Viewer ) )
144     updateGV( flags & UF_GV_Init,
145               flags & UF_GV_Forced );
146
147   if( ( flags & UF_Controls ) && getApp() )
148     getApp()->updateActions();
149
150   setUpdateEnabled( true );
151
152   QApplication::restoreOverrideCursor();
153 }
154
155 void HYDROGUI_Module::updateCommandsStatus()
156 {
157   LightApp_Module::updateCommandsStatus();
158
159   updateUndoRedoControls();
160
161   // to do
162   //action( ... )->setEnabled( ... );
163 }
164
165 HYDROGUI_DataModel* HYDROGUI_Module::getDataModel() const
166 {
167   return (HYDROGUI_DataModel*)dataModel();
168 }
169
170 HYDROGUI_Displayer* HYDROGUI_Module::getDisplayer() const
171 {
172   return myDisplayer;
173 }
174
175 GraphicsView_Viewer* HYDROGUI_Module::getViewer( const int theViewerId ) const
176 {
177   ViewManagerList aViewManagerList;
178   getApp()->viewManagers( GraphicsView_Viewer::Type(), aViewManagerList );
179
180   ViewManagerList::iterator anIter, anIterEnd = aViewManagerList.end();
181   for( anIter = aViewManagerList.begin(); anIter != anIterEnd; anIter++ )
182   {
183     GraphicsView_ViewManager* aViewManager =
184       dynamic_cast<GraphicsView_ViewManager*>( *anIter );
185     if( aViewManager && aViewManager->getId() == theViewerId )
186       return aViewManager->getViewer();
187   }
188   return NULL;
189 }
190
191 CAM_DataModel* HYDROGUI_Module::createDataModel()
192 {
193   return new HYDROGUI_DataModel( this );
194 }
195
196 void HYDROGUI_Module::onViewManagerAdded( SUIT_ViewManager* theViewManager )
197 {
198   LightApp_Module::onViewManagerAdded( theViewManager );
199
200   if( theViewManager->getType() == GraphicsView_Viewer::Type() )
201   { 
202     createSelector( theViewManager ); // replace the default selector
203
204     connect( theViewManager, SIGNAL( viewCreated( SUIT_ViewWindow* ) ),
205              this, SLOT( onViewCreated( SUIT_ViewWindow* ) ) );
206   }
207 }
208
209 void HYDROGUI_Module::onViewManagerRemoved( SUIT_ViewManager* theViewManager )
210 {
211   LightApp_Module::onViewManagerRemoved( theViewManager );
212
213   createSelector( theViewManager ); // replace the default selector
214 }
215
216 void HYDROGUI_Module::onViewCreated( SUIT_ViewWindow* theWnd )
217 {
218 }
219
220 void HYDROGUI_Module::updateGV( const bool theIsInit,
221                                 const bool theIsForced )
222 {
223   if( !getDisplayer() )
224     return;
225
226   ViewManagerList aViewManagerList;
227   getApp()->viewManagers( GraphicsView_Viewer::Type(), aViewManagerList );
228
229   ViewManagerList::iterator anIter, anIterEnd = aViewManagerList.end();
230   for( anIter = aViewManagerList.begin(); anIter != anIterEnd; anIter++ )
231   {
232     GraphicsView_ViewManager* aViewManager =
233       dynamic_cast<GraphicsView_ViewManager*>( *anIter );
234     if( aViewManager )
235       getDisplayer()->UpdateAll( aViewManager->getId(), theIsInit, theIsForced );
236   }
237 }
238
239 void HYDROGUI_Module::createSelector( SUIT_ViewManager* theViewManager )
240 {
241   if( !theViewManager )
242     return;
243
244   LightApp_SelectionMgr* aSelectionMgr = getApp()->selectionMgr();
245   if( !aSelectionMgr )
246     return;
247
248   QString aViewType = theViewManager->getType();
249   if( aViewType != GraphicsView_Viewer::Type() )
250     return;
251
252   GraphicsView_ViewManager* aViewManager =
253     dynamic_cast<GraphicsView_ViewManager*>( theViewManager );
254   if( !aViewManager )
255     return;
256
257   QList<SUIT_Selector*> aSelectorList;
258   aSelectionMgr->selectors( aViewType, aSelectorList );
259
260   // disable all alien selectors
261   QList<SUIT_Selector*>::iterator anIter, anIterEnd = aSelectorList.end();
262   for( anIter = aSelectorList.begin(); anIter != anIterEnd; anIter++ )
263   {
264     SUIT_Selector* aSelector = *anIter;
265     if( aSelector && !dynamic_cast<HYDROGUI_GVSelector*>( aSelector ) )
266       aSelector->setEnabled( false );
267   }
268
269   new HYDROGUI_GVSelector( this, aViewManager->getViewer(), aSelectionMgr );
270 }
271
272 bool HYDROGUI_Module::setUpdateEnabled( const bool theState )
273 {
274   bool aPrevState = myIsUpdateEnabled;
275   myIsUpdateEnabled = theState;
276   return aPrevState;
277 }
278
279 bool HYDROGUI_Module::isUpdateEnabled() const
280 {
281   return myIsUpdateEnabled;
282 }