1 // LIGHT : sample (no-corba-engine) SALOME module
3 // Copyright (C) 2003 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
22 // File : PVGUI_Module.cxx
23 // Author : Julia DOROVSKIKH
26 #include "PVGUI_Module.h"
27 #include "PVGUI_ProcessModuleHelper.h"
28 #include "PVGUI_ViewModel.h"
29 #include "PVGUI_ViewManager.h"
31 #include <SUIT_MessageBox.h>
32 #include <SUIT_Desktop.h>
33 #include <SUIT_Session.h>
34 #include <LightApp_Application.h>
35 #include <LightApp_SelectionMgr.h>
37 #include <QApplication>
38 #include <QInputDialog>
39 #include <QStringList>
44 #include <pqOptions.h>
45 #include <vtkPVMain.h>
46 #include <vtkProcessModule.h>
49 * Make sure all the kits register their classes with vtkInstantiator.
50 * Since ParaView uses Tcl wrapping, all of VTK is already compiled in
51 * anyway. The instantiators will add no more code for the linker to
55 #include <vtkCommonInstantiator.h>
56 #include <vtkFilteringInstantiator.h>
57 #include <vtkGenericFilteringInstantiator.h>
58 #include <vtkIOInstantiator.h>
59 #include <vtkImagingInstantiator.h>
60 #include <vtkInfovisInstantiator.h>
61 #include <vtkGraphicsInstantiator.h>
63 #include <vtkRenderingInstantiator.h>
64 #include <vtkVolumeRenderingInstantiator.h>
65 #include <vtkHybridInstantiator.h>
66 #include <vtkParallelInstantiator.h>
68 #include <vtkPVServerCommonInstantiator.h>
69 #include <vtkPVFiltersInstantiator.h>
70 #include <vtkPVServerManagerInstantiator.h>
71 #include <vtkClientServerInterpreter.h>
74 //----------------------------------------------------------------------------
75 // ClientServer wrapper initialization functions.
76 // Taken from ParaView sources (file pqMain.cxx)
77 extern "C" void vtkCommonCS_Initialize(vtkClientServerInterpreter*);
78 extern "C" void vtkFilteringCS_Initialize(vtkClientServerInterpreter*);
79 extern "C" void vtkGenericFilteringCS_Initialize(vtkClientServerInterpreter*);
80 extern "C" void vtkImagingCS_Initialize(vtkClientServerInterpreter*);
81 extern "C" void vtkInfovisCS_Initialize(vtkClientServerInterpreter*);
82 extern "C" void vtkGraphicsCS_Initialize(vtkClientServerInterpreter*);
83 extern "C" void vtkIOCS_Initialize(vtkClientServerInterpreter*);
84 extern "C" void vtkRenderingCS_Initialize(vtkClientServerInterpreter*);
85 extern "C" void vtkVolumeRenderingCS_Initialize(vtkClientServerInterpreter*);
86 extern "C" void vtkHybridCS_Initialize(vtkClientServerInterpreter*);
87 extern "C" void vtkWidgetsCS_Initialize(vtkClientServerInterpreter*);
88 extern "C" void vtkParallelCS_Initialize(vtkClientServerInterpreter*);
89 extern "C" void vtkPVServerCommonCS_Initialize(vtkClientServerInterpreter*);
90 extern "C" void vtkPVFiltersCS_Initialize(vtkClientServerInterpreter*);
91 extern "C" void vtkXdmfCS_Initialize(vtkClientServerInterpreter *);
93 //----------------------------------------------------------------------------
94 void ParaViewInitializeInterpreter(vtkProcessModule* pm)
96 // Initialize built-in wrapper modules.
97 vtkCommonCS_Initialize(pm->GetInterpreter());
98 vtkFilteringCS_Initialize(pm->GetInterpreter());
99 vtkGenericFilteringCS_Initialize(pm->GetInterpreter());
100 vtkImagingCS_Initialize(pm->GetInterpreter());
101 vtkInfovisCS_Initialize(pm->GetInterpreter());
102 vtkGraphicsCS_Initialize(pm->GetInterpreter());
103 vtkIOCS_Initialize(pm->GetInterpreter());
104 vtkRenderingCS_Initialize(pm->GetInterpreter());
105 vtkVolumeRenderingCS_Initialize(pm->GetInterpreter());
106 vtkHybridCS_Initialize(pm->GetInterpreter());
107 vtkWidgetsCS_Initialize(pm->GetInterpreter());
108 vtkParallelCS_Initialize(pm->GetInterpreter());
109 vtkPVServerCommonCS_Initialize(pm->GetInterpreter());
110 vtkPVFiltersCS_Initialize(pm->GetInterpreter());
111 vtkXdmfCS_Initialize(pm->GetInterpreter());
114 vtkPVMain* PVGUI_Module::myPVMain = 0;
115 pqOptions* PVGUI_Module::myPVOptions = 0;
116 PVGUI_ProcessModuleHelper* PVGUI_Module::myPVHelper = 0;
120 \brief Implementation of light (no-CORBA-engine)
121 SALOME module wrapping ParaView GUI.
125 \brief Constructor. Sets the default name for the module.
127 PVGUI_Module::PVGUI_Module()
128 : LightApp_Module( "PARAVIS" )
135 PVGUI_Module::~PVGUI_Module()
140 \brief Initialize module. Creates menus, prepares context menu, etc.
141 \param app application instance
143 void PVGUI_Module::initialize( CAM_Application* app )
145 LightApp_Module::initialize( app );
147 SUIT_Desktop* desk = application()->desktop();
160 createAction( lgLoadFile, tr( "TOP_LOAD_FILE" ), QIcon(), tr( "MEN_LOAD_FILE" ),
161 tr( "STB_LOAD_FILE" ), 0, desk, false, this, SLOT( onLoadFile() ) );
162 createAction( lgDisplayLine, tr( "TOP_DISPLAY_LINE" ), QIcon(), tr( "MEN_DISPLAY_LINE" ),
163 tr( "STB_DISPLAY_LINE" ), 0, desk, false, this, SLOT( onDisplayLine() ) );
164 createAction( lgEraseLine, tr( "TOP_ERASE_LINE" ), QIcon(), tr( "MEN_ERASE_LINE" ),
165 tr( "STB_ERASE_LINE" ), 0, desk, false, this, SLOT( onEraseLine() ) );
166 createAction( lgSaveFile, tr( "TOP_SAVE_FILE" ), QIcon(), tr( "MEN_SAVE_FILE" ),
167 tr( "STB_SAVE_FILE" ), 0, desk, false, this, SLOT( onSaveFile() ) );
168 createAction( lgEditLine, tr( "TOP_EDIT_LINE" ), QIcon(), tr( "MEN_EDIT_LINE" ),
169 tr( "STB_EDIT_LINE" ), 0, desk, false, this, SLOT( onEditLine() ) );
170 createAction( lgAddLine, tr( "TOP_ADD_LINE" ), QIcon(), tr( "MEN_ADD_LINE" ),
171 tr( "STB_ADD_LINE" ), 0, desk, false, this, SLOT( onAddLine() ) );
172 createAction( lgDelLine, tr( "TOP_DEL_LINE" ), QIcon(), tr( "MEN_DEL_LINE" ),
173 tr( "STB_DEL_LINE" ), 0, desk, false, this, SLOT( onDelLine() ) );
174 createAction( lgClear, tr( "TOP_CLEAR_ALL" ), QIcon(), tr( "MEN_CLEAR_ALL" ),
175 tr( "STB_CLEAR_ALL" ), 0, desk, false, this, SLOT( onClear() ) );
177 int aFileMnu = createMenu( tr( "MEN_FILE" ), -1, -1 );
178 createMenu( separator(), aFileMnu, -1, 10 );
179 createMenu( lgLoadFile, aFileMnu, 10 );
180 createMenu( lgSaveFile, aFileMnu, 10 );
182 int aLightMnu = createMenu( tr( "MEN_LIGHT" ), -1, -1, 50 );
183 createMenu( lgAddLine, aLightMnu, 10 );
184 createMenu( lgEditLine, aLightMnu, 10 );
185 createMenu( lgDelLine, aLightMnu, 10 );
186 createMenu( separator(), aLightMnu, -1, 10 );
187 createMenu( lgClear, aLightMnu, 10 );
189 QString rule = "(client='ObjectBrowser' or client='OCCViewer') and selcount=1 and type='TextLine' and !empty";
191 popupMgr()->insert ( action( lgDisplayLine ), -1, 0 );
192 popupMgr()->setRule( action( lgDisplayLine ), rule + " and !visible" );
194 popupMgr()->insert ( action( lgEraseLine ), -1, 0 );
195 popupMgr()->setRule( action( lgEraseLine ), rule + " and activeView='OCCViewer' and visible" );
197 rule = "client='ObjectBrowser' and selcount=1 and type='TextLine'";
199 popupMgr()->insert ( action( lgEditLine ), -1, 0 );
200 popupMgr()->setRule( action( lgEditLine ), rule );
202 popupMgr()->insert ( action( lgAddLine ), -1, 0 );
203 popupMgr()->setRule( action( lgAddLine ), rule );
205 popupMgr()->insert ( separator(), -1, 0 );
207 popupMgr()->insert ( action( lgDelLine ), -1, 0 );
208 popupMgr()->setRule( action( lgDelLine ), rule );
210 rule = "client='ObjectBrowser'";
212 popupMgr()->insert ( action( lgClear ), -1, 0 );
213 popupMgr()->setRule( action( lgClear ), rule );*/
217 \brief Get list of compliant dockable GUI elements
218 \param m map to be filled in ("type":"default_position")
220 void PVGUI_Module::windows( QMap<int, int>& m ) const
222 m.insert( LightApp_Application::WT_ObjectBrowser, Qt::LeftDockWidgetArea );
223 // TODO: creation of Python console leads to SIGSEGV on Python initialization...
224 //m.insert( LightApp_Application::WT_PyConsole, Qt::BottomDockWidgetArea );
225 // ParaView diagnostic output redirected here
226 m.insert( LightApp_Application::WT_LogWindow, Qt::BottomDockWidgetArea );
230 \brief Create custom popup menu selection object.
231 \return new selected object
233 /*LightApp_Selection* PVGUI_Module::createSelection() const
235 return new PVGUI_Selection();
239 \brief Create data model.
240 \return module specific data model
242 /*CAM_DataModel* PVGUI_Module::createDataModel()
244 return new PVGUI_DataModel( this );
248 \brief Static method, performs initialization of ParaView session.
249 \return \c true if ParaView has been initialized successfully, otherwise false
251 bool PVGUI_Module::pvInit()
254 // Obtain command-line arguments
256 QStringList args = QApplication::arguments();
257 char** argv = new char*[args.size()];
258 for ( QStringList::const_iterator it = args.begin(); argc < 1 && it != args.end(); it++, argc++ )
259 argv[argc] = strdup( (*it).toLatin1().constData() );
261 vtkPVMain::SetInitializeMPI(0); // pvClient never runs with MPI.
262 vtkPVMain::Initialize(&argc, &argv); // Perform any initializations.
264 // TODO: Set plugin dir from preferences
265 //QApplication::setLibraryPaths(QStringList(dir.absolutePath()));
267 myPVMain = vtkPVMain::New();
269 myPVOptions = pqOptions::New();
271 myPVHelper = PVGUI_ProcessModuleHelper::New();
273 myPVOptions->SetProcessType(vtkPVOptions::PVCLIENT);
275 // This creates the Process Module and initializes it.
276 int ret = myPVMain->Initialize(myPVOptions, myPVHelper, ParaViewInitializeInterpreter,
279 // Tell process module that we support Multiple connections.
280 // This must be set before starting the event loop.
281 vtkProcessModule::GetProcessModule()->SupportMultipleConnectionsOn();
282 ret = myPVHelper->Run(myPVOptions);
286 cout << "*** ParaView client initalized!!!" << endl;
294 \brief Static method, cleans up ParaView session at application exit.
296 void PVGUI_Module::pvShutdown()
302 \brief Shows (toShow = true) or hides ParaView view window
304 void PVGUI_Module::showView( bool toShow )
306 // TODO: check if ParaView view already exists
307 LightApp_Application* anApp = getApp();
308 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
309 PVGUI_ViewManager* viewMgr = new PVGUI_ViewManager( anApp->activeStudy(), anApp->desktop() );
310 anApp->addViewManager( viewMgr );
311 connect( viewMgr, SIGNAL( lastViewClosed( SUIT_ViewManager* ) ),
312 anApp, SLOT( onCloseView( SUIT_ViewManager* ) ) );
313 //connect( viewMgr, SIGNAL( viewCreated( SUIT_ViewWindow* ) ), vm, SLOT( onViewCreated( SUIT_ViewWindow* ) ) );
314 //connect( viewMgr, SIGNAL( deleteView( SUIT_ViewWindow* ) ), this, SLOT( onViewDeleted( SUIT_ViewWindow* ) ) );
315 SUIT_ViewWindow* wnd = viewMgr->createViewWindow();
319 \brief Create actions for ParaView GUI operations
320 duplicating menus and toolbars in pqMainWindow ParaView class
322 void PVGUI_Module::pvCreateActions()
328 \brief Activate module.
329 \param study current study
330 \return \c true if activaion is done successfully or 0 to prevent
333 bool PVGUI_Module::activateModule( SUIT_Study* study )
335 bool isDone = LightApp_Module::activateModule( study );
336 if ( !isDone ) return false;
338 setMenuShown( true );
346 \brief Deactivate module.
347 \param study current study
348 \return \c true if deactivaion is done successfully or 0 to prevent
349 deactivation on error
351 bool PVGUI_Module::deactivateModule( SUIT_Study* study )
354 setMenuShown( false );
356 return LightApp_Module::deactivateModule( study );
360 \fn CAM_Module* createModule();
361 \brief Export module instance (factory function).
362 \return new created instance of the module
366 #define PVGUI_EXPORT __declspec(dllexport)
372 PVGUI_EXPORT CAM_Module* createModule() {
373 return new PVGUI_Module();