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"
30 #include "PVGUI_ViewWindow.h"
32 #include <SUIT_MessageBox.h>
33 #include <SUIT_Desktop.h>
34 #include <SUIT_Session.h>
35 #include <LightApp_Application.h>
36 #include <LightApp_SelectionMgr.h>
38 #include <QApplication>
39 #include <QInputDialog>
40 #include <QStringList>
45 #include <pqOptions.h>
46 #include <pqApplicationCore.h>
47 #include <pqActiveServer.h>
48 #include <pqMainWindowCore.h>
49 #include <pqObjectBuilder.h>
51 #include <pqServerManagerModel.h>
52 #include <pqServerResource.h>
53 #include <pqViewManager.h>
54 #include <vtkPVMain.h>
55 #include <vtkProcessModule.h>
58 * Make sure all the kits register their classes with vtkInstantiator.
59 * Since ParaView uses Tcl wrapping, all of VTK is already compiled in
60 * anyway. The instantiators will add no more code for the linker to
64 #include <vtkCommonInstantiator.h>
65 #include <vtkFilteringInstantiator.h>
66 #include <vtkGenericFilteringInstantiator.h>
67 #include <vtkIOInstantiator.h>
68 #include <vtkImagingInstantiator.h>
69 #include <vtkInfovisInstantiator.h>
70 #include <vtkGraphicsInstantiator.h>
72 #include <vtkRenderingInstantiator.h>
73 #include <vtkVolumeRenderingInstantiator.h>
74 #include <vtkHybridInstantiator.h>
75 #include <vtkParallelInstantiator.h>
77 #include <vtkPVServerCommonInstantiator.h>
78 #include <vtkPVFiltersInstantiator.h>
79 #include <vtkPVServerManagerInstantiator.h>
80 #include <vtkClientServerInterpreter.h>
83 //----------------------------------------------------------------------------
84 // ClientServer wrapper initialization functions.
85 // Taken from ParaView sources (file pqMain.cxx)
86 extern "C" void vtkCommonCS_Initialize(vtkClientServerInterpreter*);
87 extern "C" void vtkFilteringCS_Initialize(vtkClientServerInterpreter*);
88 extern "C" void vtkGenericFilteringCS_Initialize(vtkClientServerInterpreter*);
89 extern "C" void vtkImagingCS_Initialize(vtkClientServerInterpreter*);
90 extern "C" void vtkInfovisCS_Initialize(vtkClientServerInterpreter*);
91 extern "C" void vtkGraphicsCS_Initialize(vtkClientServerInterpreter*);
92 extern "C" void vtkIOCS_Initialize(vtkClientServerInterpreter*);
93 extern "C" void vtkRenderingCS_Initialize(vtkClientServerInterpreter*);
94 extern "C" void vtkVolumeRenderingCS_Initialize(vtkClientServerInterpreter*);
95 extern "C" void vtkHybridCS_Initialize(vtkClientServerInterpreter*);
96 extern "C" void vtkWidgetsCS_Initialize(vtkClientServerInterpreter*);
97 extern "C" void vtkParallelCS_Initialize(vtkClientServerInterpreter*);
98 extern "C" void vtkPVServerCommonCS_Initialize(vtkClientServerInterpreter*);
99 extern "C" void vtkPVFiltersCS_Initialize(vtkClientServerInterpreter*);
100 extern "C" void vtkXdmfCS_Initialize(vtkClientServerInterpreter *);
102 //----------------------------------------------------------------------------
103 void ParaViewInitializeInterpreter(vtkProcessModule* pm)
105 // Initialize built-in wrapper modules.
106 vtkCommonCS_Initialize(pm->GetInterpreter());
107 vtkFilteringCS_Initialize(pm->GetInterpreter());
108 vtkGenericFilteringCS_Initialize(pm->GetInterpreter());
109 vtkImagingCS_Initialize(pm->GetInterpreter());
110 vtkInfovisCS_Initialize(pm->GetInterpreter());
111 vtkGraphicsCS_Initialize(pm->GetInterpreter());
112 vtkIOCS_Initialize(pm->GetInterpreter());
113 vtkRenderingCS_Initialize(pm->GetInterpreter());
114 vtkVolumeRenderingCS_Initialize(pm->GetInterpreter());
115 vtkHybridCS_Initialize(pm->GetInterpreter());
116 vtkWidgetsCS_Initialize(pm->GetInterpreter());
117 vtkParallelCS_Initialize(pm->GetInterpreter());
118 vtkPVServerCommonCS_Initialize(pm->GetInterpreter());
119 vtkPVFiltersCS_Initialize(pm->GetInterpreter());
120 vtkXdmfCS_Initialize(pm->GetInterpreter());
123 //////////////////////////////////////////////////////////////////////////////
124 // PVGUI_Module::pqImplementation
126 class PVGUI_Module::pqImplementation
129 pqImplementation(QWidget* parent) :
130 //AssistantClient(0),
132 //RecentFilesMenu(0),
140 //delete this->ViewMenu;
141 //delete this->ToolbarsMenu;
142 //if(this->AssistantClient)
144 // this->AssistantClient->closeAssistant();
145 // delete this->AssistantClient;
149 //QPointer<QAssistantClient> AssistantClient;
151 pqMainWindowCore Core;
152 //pqRecentFilesMenu* RecentFilesMenu;
153 //pqViewMenu* ViewMenu;
154 //pqViewMenu* ToolbarsMenu;
155 //QLineEdit* CurrentTimeWidget;
156 //QSpinBox* CurrentTimeIndexWidget;
157 QPointer<pqServer> ActiveServer;
158 QString DocumentationDir;
160 static vtkPVMain* myPVMain;
161 static pqOptions* myPVOptions;
162 static PVGUI_ProcessModuleHelper* myPVHelper;
166 vtkPVMain* PVGUI_Module::pqImplementation::myPVMain = 0;
167 pqOptions* PVGUI_Module::pqImplementation::myPVOptions = 0;
168 PVGUI_ProcessModuleHelper* PVGUI_Module::pqImplementation::myPVHelper = 0;
172 \brief Implementation of light (no-CORBA-engine)
173 SALOME module wrapping ParaView GUI.
177 \brief Constructor. Sets the default name for the module.
179 PVGUI_Module::PVGUI_Module()
180 : LightApp_Module( "PARAVIS" ),
188 PVGUI_Module::~PVGUI_Module()
193 \brief Initialize module. Creates menus, prepares context menu, etc.
194 \param app application instance
196 void PVGUI_Module::initialize( CAM_Application* app )
198 LightApp_Module::initialize( app );
210 createAction( lgLoadFile, tr( "TOP_LOAD_FILE" ), QIcon(), tr( "MEN_LOAD_FILE" ),
211 tr( "STB_LOAD_FILE" ), 0, desk, false, this, SLOT( onLoadFile() ) );
212 createAction( lgDisplayLine, tr( "TOP_DISPLAY_LINE" ), QIcon(), tr( "MEN_DISPLAY_LINE" ),
213 tr( "STB_DISPLAY_LINE" ), 0, desk, false, this, SLOT( onDisplayLine() ) );
214 createAction( lgEraseLine, tr( "TOP_ERASE_LINE" ), QIcon(), tr( "MEN_ERASE_LINE" ),
215 tr( "STB_ERASE_LINE" ), 0, desk, false, this, SLOT( onEraseLine() ) );
216 createAction( lgSaveFile, tr( "TOP_SAVE_FILE" ), QIcon(), tr( "MEN_SAVE_FILE" ),
217 tr( "STB_SAVE_FILE" ), 0, desk, false, this, SLOT( onSaveFile() ) );
218 createAction( lgEditLine, tr( "TOP_EDIT_LINE" ), QIcon(), tr( "MEN_EDIT_LINE" ),
219 tr( "STB_EDIT_LINE" ), 0, desk, false, this, SLOT( onEditLine() ) );
220 createAction( lgAddLine, tr( "TOP_ADD_LINE" ), QIcon(), tr( "MEN_ADD_LINE" ),
221 tr( "STB_ADD_LINE" ), 0, desk, false, this, SLOT( onAddLine() ) );
222 createAction( lgDelLine, tr( "TOP_DEL_LINE" ), QIcon(), tr( "MEN_DEL_LINE" ),
223 tr( "STB_DEL_LINE" ), 0, desk, false, this, SLOT( onDelLine() ) );
224 createAction( lgClear, tr( "TOP_CLEAR_ALL" ), QIcon(), tr( "MEN_CLEAR_ALL" ),
225 tr( "STB_CLEAR_ALL" ), 0, desk, false, this, SLOT( onClear() ) );
227 int aFileMnu = createMenu( tr( "MEN_FILE" ), -1, -1 );
228 createMenu( separator(), aFileMnu, -1, 10 );
229 createMenu( lgLoadFile, aFileMnu, 10 );
230 createMenu( lgSaveFile, aFileMnu, 10 );
232 int aLightMnu = createMenu( tr( "MEN_LIGHT" ), -1, -1, 50 );
233 createMenu( lgAddLine, aLightMnu, 10 );
234 createMenu( lgEditLine, aLightMnu, 10 );
235 createMenu( lgDelLine, aLightMnu, 10 );
236 createMenu( separator(), aLightMnu, -1, 10 );
237 createMenu( lgClear, aLightMnu, 10 );
239 QString rule = "(client='ObjectBrowser' or client='OCCViewer') and selcount=1 and type='TextLine' and !empty";
241 popupMgr()->insert ( action( lgDisplayLine ), -1, 0 );
242 popupMgr()->setRule( action( lgDisplayLine ), rule + " and !visible" );
244 popupMgr()->insert ( action( lgEraseLine ), -1, 0 );
245 popupMgr()->setRule( action( lgEraseLine ), rule + " and activeView='OCCViewer' and visible" );
247 rule = "client='ObjectBrowser' and selcount=1 and type='TextLine'";
249 popupMgr()->insert ( action( lgEditLine ), -1, 0 );
250 popupMgr()->setRule( action( lgEditLine ), rule );
252 popupMgr()->insert ( action( lgAddLine ), -1, 0 );
253 popupMgr()->setRule( action( lgAddLine ), rule );
255 popupMgr()->insert ( separator(), -1, 0 );
257 popupMgr()->insert ( action( lgDelLine ), -1, 0 );
258 popupMgr()->setRule( action( lgDelLine ), rule );
260 rule = "client='ObjectBrowser'";
262 popupMgr()->insert ( action( lgClear ), -1, 0 );
263 popupMgr()->setRule( action( lgClear ), rule );*/
267 \brief Get list of compliant dockable GUI elements
268 \param m map to be filled in ("type":"default_position")
270 void PVGUI_Module::windows( QMap<int, int>& m ) const
272 m.insert( LightApp_Application::WT_ObjectBrowser, Qt::LeftDockWidgetArea );
273 // TODO: creation of Python console leads to SIGSEGV on Python initialization...
274 //m.insert( LightApp_Application::WT_PyConsole, Qt::BottomDockWidgetArea );
275 // ParaView diagnostic output redirected here
276 m.insert( LightApp_Application::WT_LogWindow, Qt::BottomDockWidgetArea );
280 \brief Create custom popup menu selection object.
281 \return new selected object
283 /*LightApp_Selection* PVGUI_Module::createSelection() const
285 return new PVGUI_Selection();
289 \brief Create data model.
290 \return module specific data model
292 /*CAM_DataModel* PVGUI_Module::createDataModel()
294 return new PVGUI_DataModel( this );
298 \brief Static method, performs initialization of ParaView session.
299 \return \c true if ParaView has been initialized successfully, otherwise false
301 bool PVGUI_Module::pvInit()
303 if ( !pqImplementation::myPVMain ){
304 // Obtain command-line arguments
306 QStringList args = QApplication::arguments();
307 char** argv = new char*[args.size()];
308 for ( QStringList::const_iterator it = args.begin(); argc < 1 && it != args.end(); it++, argc++ )
309 argv[argc] = strdup( (*it).toLatin1().constData() );
311 vtkPVMain::SetInitializeMPI(0); // pvClient never runs with MPI.
312 vtkPVMain::Initialize(&argc, &argv); // Perform any initializations.
314 // TODO: Set plugin dir from preferences
315 //QApplication::setLibraryPaths(QStringList(dir.absolutePath()));
317 pqImplementation::myPVMain = vtkPVMain::New();
318 if ( !pqImplementation::myPVOptions )
319 pqImplementation::myPVOptions = pqOptions::New();
320 if ( !pqImplementation::myPVHelper )
321 pqImplementation::myPVHelper = PVGUI_ProcessModuleHelper::New();
323 pqImplementation::myPVOptions->SetProcessType(vtkPVOptions::PVCLIENT);
325 // This creates the Process Module and initializes it.
326 int ret = pqImplementation::myPVMain->Initialize(pqImplementation::myPVOptions,
327 pqImplementation::myPVHelper,
328 ParaViewInitializeInterpreter,
331 // Tell process module that we support Multiple connections.
332 // This must be set before starting the event loop.
333 vtkProcessModule::GetProcessModule()->SupportMultipleConnectionsOn();
334 ret = pqImplementation::myPVHelper->Run(pqImplementation::myPVOptions);
345 \brief Static method, cleans up ParaView session at application exit.
347 void PVGUI_Module::pvShutdown()
353 \brief Shows (toShow = true) or hides ParaView view window
355 void PVGUI_Module::showView( bool toShow )
357 // TODO: check if ParaView view already exists
358 if ( !Implementation ){
359 LightApp_Application* anApp = getApp();
360 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
361 PVGUI_ViewManager* viewMgr = new PVGUI_ViewManager( anApp->activeStudy(), anApp->desktop() );
362 anApp->addViewManager( viewMgr );
363 connect( viewMgr, SIGNAL( lastViewClosed( SUIT_ViewManager* ) ),
364 anApp, SLOT( onCloseView( SUIT_ViewManager* ) ) );
365 //connect( viewMgr, SIGNAL( viewCreated( SUIT_ViewWindow* ) ), vm, SLOT( onViewCreated( SUIT_ViewWindow* ) ) );
366 //connect( viewMgr, SIGNAL( deleteView( SUIT_ViewWindow* ) ), this, SLOT( onViewDeleted( SUIT_ViewWindow* ) ) );
367 SUIT_ViewWindow* wnd = viewMgr->createViewWindow();
369 // Simulate ParaView client main window
370 Implementation = new pqImplementation( wnd );
371 PVGUI_ViewWindow* pvWnd = dynamic_cast<PVGUI_ViewWindow*>( wnd );
372 pvWnd->setMultiViewManager( &Implementation->Core.multiViewManager() );
380 \brief Create actions for ParaView GUI operations
381 duplicating menus and toolbars in pqMainWindow ParaView class
383 void PVGUI_Module::pvCreateActions()
386 SUIT_Desktop* desk = application()->desktop();
389 int actionManagePlugins = 999;
390 createAction( actionManagePlugins, tr( "TOP_MANAGE_PLUGINS" ), QIcon(), tr( "MEN_MANAGE_PLUGINS" ),
391 tr( "STB_MANAGE_PLUGINS" ), 0, desk, false, &Implementation->Core, SLOT( onManagePlugins() ) );
392 int aPVMnu = createMenu( tr( "MEN_TEST_PARAVIEW" ), -1, -1, 50 );
393 createMenu( actionManagePlugins, aPVMnu, 10 );
398 \brief Create dock widgets for ParaView widgets such as object inspector, pipeline browser, etc.
400 void PVGUI_Module::setupDockWidgets()
405 \brief Returns the ParaView multi-view manager.
407 pqViewManager* PVGUI_Module::getMultiViewManager() const
409 pqViewManager* aMVM = 0;
410 if ( Implementation )
411 aMVM = &Implementation->Core.multiViewManager();
417 \brief Activate module.
418 \param study current study
419 \return \c true if activaion is done successfully or 0 to prevent
422 bool PVGUI_Module::activateModule( SUIT_Study* study )
424 bool isDone = LightApp_Module::activateModule( study );
425 if ( !isDone ) return false;
427 setMenuShown( true );
431 // Make default server connection
432 if ( Implementation )
433 Implementation->Core.makeDefaultConnectionIfNoneExists();
440 \brief Deactivate module.
441 \param study current study
442 \return \c true if deactivaion is done successfully or 0 to prevent
443 deactivation on error
445 bool PVGUI_Module::deactivateModule( SUIT_Study* study )
448 setMenuShown( false );
450 return LightApp_Module::deactivateModule( study );
454 \fn CAM_Module* createModule();
455 \brief Export module instance (factory function).
456 \return new created instance of the module
460 #define PVGUI_EXPORT __declspec(dllexport)
466 PVGUI_EXPORT CAM_Module* createModule() {
467 return new PVGUI_Module();