]> SALOME platform Git repositories - modules/paravis.git/blob - src/PVGUI/PVGUI_Module.cxx
Salome HOME
Imported sources
[modules/paravis.git] / src / PVGUI / PVGUI_Module.cxx
1 // LIGHT : sample (no-corba-engine) SALOME module
2 //
3 // Copyright (C) 2003  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 // File   : PVGUI_Module.cxx
23 // Author : Julia DOROVSKIKH
24 //
25
26 #include "PVGUI_Module.h"
27 #include "PVGUI_ProcessModuleHelper.h"
28
29 #include <SUIT_MessageBox.h>
30 #include <SUIT_Desktop.h>
31 #include <LightApp_Application.h>
32 #include <LightApp_SelectionMgr.h>
33 #include <LightApp_Selection.h>
34 #include <OCCViewer_ViewManager.h>
35 #include <SOCC_ViewModel.h>
36 #include <SOCC_Prs.h>
37
38 #include <QApplication>
39 #include <QInputDialog>
40 #include <QStringList>
41 #include <QMenu>
42 #include <QIcon>
43 #include <QString>
44
45 #include <pqOptions.h>
46 #include <vtkPVMain.h>
47 #include <vtkProcessModule.h>
48
49 /*
50  * Make sure all the kits register their classes with vtkInstantiator.
51  * Since ParaView uses Tcl wrapping, all of VTK is already compiled in
52  * anyway.  The instantiators will add no more code for the linker to
53  * collect.
54  */
55
56 #include <vtkCommonInstantiator.h>
57 #include <vtkFilteringInstantiator.h>
58 #include <vtkGenericFilteringInstantiator.h>
59 #include <vtkIOInstantiator.h>
60 #include <vtkImagingInstantiator.h>
61 #include <vtkInfovisInstantiator.h>
62 #include <vtkGraphicsInstantiator.h>
63
64 #include <vtkRenderingInstantiator.h>
65 #include <vtkVolumeRenderingInstantiator.h>
66 #include <vtkHybridInstantiator.h>
67 #include <vtkParallelInstantiator.h>
68
69 #include <vtkPVServerCommonInstantiator.h>
70 #include <vtkPVFiltersInstantiator.h>
71 #include <vtkPVServerManagerInstantiator.h>
72 #include <vtkClientServerInterpreter.h>
73
74
75 //----------------------------------------------------------------------------
76 // ClientServer wrapper initialization functions.
77 // Taken from ParaView sources (file pqMain.cxx)
78 extern "C" void vtkCommonCS_Initialize(vtkClientServerInterpreter*);
79 extern "C" void vtkFilteringCS_Initialize(vtkClientServerInterpreter*);
80 extern "C" void vtkGenericFilteringCS_Initialize(vtkClientServerInterpreter*);
81 extern "C" void vtkImagingCS_Initialize(vtkClientServerInterpreter*);
82 extern "C" void vtkInfovisCS_Initialize(vtkClientServerInterpreter*);
83 extern "C" void vtkGraphicsCS_Initialize(vtkClientServerInterpreter*);
84 extern "C" void vtkIOCS_Initialize(vtkClientServerInterpreter*);
85 extern "C" void vtkRenderingCS_Initialize(vtkClientServerInterpreter*);
86 extern "C" void vtkVolumeRenderingCS_Initialize(vtkClientServerInterpreter*);
87 extern "C" void vtkHybridCS_Initialize(vtkClientServerInterpreter*);
88 extern "C" void vtkWidgetsCS_Initialize(vtkClientServerInterpreter*);
89 extern "C" void vtkParallelCS_Initialize(vtkClientServerInterpreter*);
90 extern "C" void vtkPVServerCommonCS_Initialize(vtkClientServerInterpreter*);
91 extern "C" void vtkPVFiltersCS_Initialize(vtkClientServerInterpreter*);
92 extern "C" void vtkXdmfCS_Initialize(vtkClientServerInterpreter *);
93
94 //----------------------------------------------------------------------------
95 void ParaViewInitializeInterpreter(vtkProcessModule* pm)
96 {
97   // Initialize built-in wrapper modules.
98   vtkCommonCS_Initialize(pm->GetInterpreter());
99   vtkFilteringCS_Initialize(pm->GetInterpreter());
100   vtkGenericFilteringCS_Initialize(pm->GetInterpreter());
101   vtkImagingCS_Initialize(pm->GetInterpreter());
102   vtkInfovisCS_Initialize(pm->GetInterpreter());
103   vtkGraphicsCS_Initialize(pm->GetInterpreter());
104   vtkIOCS_Initialize(pm->GetInterpreter());
105   vtkRenderingCS_Initialize(pm->GetInterpreter());
106   vtkVolumeRenderingCS_Initialize(pm->GetInterpreter());
107   vtkHybridCS_Initialize(pm->GetInterpreter());
108   vtkWidgetsCS_Initialize(pm->GetInterpreter());
109   vtkParallelCS_Initialize(pm->GetInterpreter());
110   vtkPVServerCommonCS_Initialize(pm->GetInterpreter());
111   vtkPVFiltersCS_Initialize(pm->GetInterpreter());
112   vtkXdmfCS_Initialize(pm->GetInterpreter());
113 }
114
115 vtkPVMain*                 PVGUI_Module::myPVMain = 0;
116 pqOptions*                 PVGUI_Module::myPVOptions = 0;
117 PVGUI_ProcessModuleHelper* PVGUI_Module::myPVHelper = 0;
118
119 /*!
120   \class PVGUI_Module
121   \brief Implementation of light (no-CORBA-engine) 
122          SALOME module wrapping ParaView GUI.
123 */
124
125 /*!
126   \brief Constructor. Sets the default name for the module.
127 */
128 PVGUI_Module::PVGUI_Module()
129 : LightApp_Module( "PARAVIS" )
130 {
131 }
132
133 /*!
134   \brief Destructor.
135 */
136 PVGUI_Module::~PVGUI_Module()
137 {
138 }
139
140 /*!
141   \brief Initialize module. Creates menus, prepares context menu, etc.
142   \param app application instance
143 */
144 void PVGUI_Module::initialize( CAM_Application* app )
145 {
146   LightApp_Module::initialize( app );
147
148   SUIT_Desktop* desk = application()->desktop();
149
150   if ( pvInit() ) {
151     pvCreateActions();
152   }
153   /*
154   createAction( lgLoadFile, tr( "TOP_LOAD_FILE" ), QIcon(), tr( "MEN_LOAD_FILE" ),
155                 tr( "STB_LOAD_FILE" ), 0, desk, false, this, SLOT( onLoadFile() ) );
156   createAction( lgDisplayLine, tr( "TOP_DISPLAY_LINE" ), QIcon(), tr( "MEN_DISPLAY_LINE" ),
157                 tr( "STB_DISPLAY_LINE" ), 0, desk, false, this, SLOT( onDisplayLine() ) );
158   createAction( lgEraseLine, tr( "TOP_ERASE_LINE" ), QIcon(), tr( "MEN_ERASE_LINE" ),
159                 tr( "STB_ERASE_LINE" ), 0, desk, false, this, SLOT( onEraseLine() ) );
160   createAction( lgSaveFile, tr( "TOP_SAVE_FILE" ), QIcon(), tr( "MEN_SAVE_FILE" ),
161                 tr( "STB_SAVE_FILE" ), 0, desk, false, this, SLOT( onSaveFile() ) );
162   createAction( lgEditLine, tr( "TOP_EDIT_LINE" ), QIcon(), tr( "MEN_EDIT_LINE" ),
163                 tr( "STB_EDIT_LINE" ), 0, desk, false, this, SLOT( onEditLine() ) );
164   createAction( lgAddLine,  tr( "TOP_ADD_LINE" ),  QIcon(), tr( "MEN_ADD_LINE" ),
165                 tr( "STB_ADD_LINE" ),  0, desk, false, this, SLOT( onAddLine() ) );
166   createAction( lgDelLine,  tr( "TOP_DEL_LINE" ),  QIcon(), tr( "MEN_DEL_LINE" ),
167                 tr( "STB_DEL_LINE" ),  0, desk, false, this, SLOT( onDelLine() ) );
168   createAction( lgClear,    tr( "TOP_CLEAR_ALL" ), QIcon(), tr( "MEN_CLEAR_ALL" ),
169                 tr( "STB_CLEAR_ALL" ), 0, desk, false, this, SLOT( onClear() ) );
170
171   int aFileMnu = createMenu( tr( "MEN_FILE" ), -1, -1 );
172   createMenu( separator(), aFileMnu, -1, 10 );
173   createMenu( lgLoadFile,  aFileMnu, 10 );
174   createMenu( lgSaveFile,  aFileMnu, 10 );
175
176   int aLightMnu = createMenu( tr( "MEN_LIGHT" ), -1, -1, 50 );
177   createMenu( lgAddLine,      aLightMnu, 10 );
178   createMenu( lgEditLine,     aLightMnu, 10 );
179   createMenu( lgDelLine,      aLightMnu, 10 );
180   createMenu( separator(),    aLightMnu, -1, 10 );
181   createMenu( lgClear,        aLightMnu, 10 );
182
183   QString rule = "(client='ObjectBrowser' or client='OCCViewer') and selcount=1 and type='TextLine' and !empty";
184
185   popupMgr()->insert ( action( lgDisplayLine ), -1, 0 );
186   popupMgr()->setRule( action( lgDisplayLine ), rule + " and !visible"  );
187
188   popupMgr()->insert ( action( lgEraseLine ), -1, 0 );
189   popupMgr()->setRule( action( lgEraseLine ), rule + " and activeView='OCCViewer' and visible"  );
190
191   rule = "client='ObjectBrowser' and selcount=1 and type='TextLine'";
192
193   popupMgr()->insert ( action( lgEditLine ), -1, 0 );
194   popupMgr()->setRule( action( lgEditLine ), rule  );
195
196   popupMgr()->insert ( action( lgAddLine ),  -1, 0 );
197   popupMgr()->setRule( action( lgAddLine ),  rule );
198
199   popupMgr()->insert ( separator(),          -1, 0 );
200
201   popupMgr()->insert ( action( lgDelLine ),  -1, 0 );
202   popupMgr()->setRule( action( lgDelLine ),  rule );
203
204   rule = "client='ObjectBrowser'";
205
206   popupMgr()->insert ( action( lgClear ),    -1, 0 );
207   popupMgr()->setRule( action( lgClear ),    rule );*/
208 }
209
210 /*!
211   \brief Get list of compliant dockable GUI elements
212   \param m map to be filled in ("type":"default_position")
213 */
214 void PVGUI_Module::windows( QMap<int, int>& m ) const
215 {
216   m.insert( LightApp_Application::WT_ObjectBrowser, Qt::LeftDockWidgetArea );
217   // TODO: creation of Python console leads to SIGSEGV on Python initialization...
218   //m.insert( LightApp_Application::WT_PyConsole, Qt::BottomDockWidgetArea );
219   // ParaView diagnostic output redirected here
220   m.insert( LightApp_Application::WT_LogWindow, Qt::BottomDockWidgetArea );
221 }
222
223 /*!
224   \brief Create custom popup menu selection object.
225   \return new selected object
226 */
227 /*LightApp_Selection* PVGUI_Module::createSelection() const
228 {
229   return new PVGUI_Selection();
230 }*/
231
232 /*!
233   \brief Create data model.
234   \return module specific data model
235 */
236 /*CAM_DataModel* PVGUI_Module::createDataModel()
237 {
238   return new PVGUI_DataModel( this );
239 }*/
240
241 /*!
242   \brief Static method, performs initialization of ParaView session.
243   \return \c true if ParaView has been initialized successfully, otherwise false
244 */
245 bool PVGUI_Module::pvInit()
246 {
247   if ( !myPVMain ){
248     // Obtain command-line arguments
249     int argc = 0;
250     QStringList args = QApplication::arguments();
251     char** argv = new char*[args.size()];
252     for ( QStringList::const_iterator it = args.begin(); argc < 1 && it != args.end(); it++, argc++ )
253       argv[argc] = strdup( (*it).toLatin1().constData() );
254
255     vtkPVMain::SetInitializeMPI(0);  // pvClient never runs with MPI.
256     vtkPVMain::Initialize(&argc, &argv); // Perform any initializations.
257
258     // TODO: Set plugin dir from preferences
259     //QApplication::setLibraryPaths(QStringList(dir.absolutePath()));
260
261     myPVMain = vtkPVMain::New();
262     if ( !myPVOptions )
263       myPVOptions = pqOptions::New();
264     if ( !myPVHelper )
265       myPVHelper = PVGUI_ProcessModuleHelper::New();
266
267     myPVOptions->SetProcessType(vtkPVOptions::PVCLIENT);
268
269     // This creates the Process Module and initializes it.
270     int ret = myPVMain->Initialize(myPVOptions, myPVHelper, ParaViewInitializeInterpreter,
271                                    argc, argv);
272     if (!ret){
273       // Tell process module that we support Multiple connections.
274       // This must be set before starting the event loop.
275       vtkProcessModule::GetProcessModule()->SupportMultipleConnectionsOn();
276       ret = myPVHelper->Run(myPVOptions);
277     }
278
279     //delete[] argv;
280     cout << "*** ParaView client initalized!!!" << endl;
281     return !ret;
282   }
283   
284   return true;
285 }
286  
287 /*!
288   \brief Static method, cleans up ParaView session at application exit.
289 */
290 void PVGUI_Module::pvShutdown()
291 {
292   // TODO...
293 }  
294  
295 /*!
296   \brief Create actions for ParaView GUI operations
297   duplicating menus and toolbars in pqMainWindow ParaView class
298 */
299 void PVGUI_Module::pvCreateActions()
300 {
301   // TODO...
302 }
303
304 /*!
305   \brief Activate module.
306   \param study current study
307   \return \c true if activaion is done successfully or 0 to prevent
308   activation on error
309 */
310 bool PVGUI_Module::activateModule( SUIT_Study* study )
311 {
312   bool isDone = LightApp_Module::activateModule( study );
313   if ( !isDone ) return false;
314
315   setMenuShown( true );
316
317   return isDone;
318 }
319
320 /*!
321   \brief Deactivate module.
322   \param study current study
323   \return \c true if deactivaion is done successfully or 0 to prevent
324   deactivation on error
325 */
326 bool PVGUI_Module::deactivateModule( SUIT_Study* study )
327 {
328   // hide menus
329   setMenuShown( false );
330
331   return LightApp_Module::deactivateModule( study );
332 }
333
334 /*!
335   \fn CAM_Module* createModule();
336   \brief Export module instance (factory function).
337   \return new created instance of the module
338 */
339
340 #ifdef WNT
341 #define PVGUI_EXPORT __declspec(dllexport)
342 #else   // WNT
343 #define PVGUI_EXPORT
344 #endif  // WNT
345
346 extern "C" {
347   PVGUI_EXPORT CAM_Module* createModule() {
348     return new PVGUI_Module();
349   }
350 }