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>
37 #include <QtxActionMenuMgr.h>
39 #include <QApplication>
40 #include <QInputDialog>
41 #include <QStringList>
46 #include <pqOptions.h>
47 #include <pqApplicationCore.h>
48 #include <pqActiveServer.h>
49 #include <pqMainWindowCore.h>
50 #include <pqObjectBuilder.h>
52 #include <pqServerManagerModel.h>
53 #include <pqServerResource.h>
54 #include <pqViewManager.h>
55 #include <vtkPVMain.h>
56 #include <vtkProcessModule.h>
59 * Make sure all the kits register their classes with vtkInstantiator.
60 * Since ParaView uses Tcl wrapping, all of VTK is already compiled in
61 * anyway. The instantiators will add no more code for the linker to
65 #include <vtkCommonInstantiator.h>
66 #include <vtkFilteringInstantiator.h>
67 #include <vtkGenericFilteringInstantiator.h>
68 #include <vtkIOInstantiator.h>
69 #include <vtkImagingInstantiator.h>
70 #include <vtkInfovisInstantiator.h>
71 #include <vtkGraphicsInstantiator.h>
73 #include <vtkRenderingInstantiator.h>
74 #include <vtkVolumeRenderingInstantiator.h>
75 #include <vtkHybridInstantiator.h>
76 #include <vtkParallelInstantiator.h>
78 #include <vtkPVServerCommonInstantiator.h>
79 #include <vtkPVFiltersInstantiator.h>
80 #include <vtkPVServerManagerInstantiator.h>
81 #include <vtkClientServerInterpreter.h>
84 //----------------------------------------------------------------------------
85 // ClientServer wrapper initialization functions.
86 // Taken from ParaView sources (file pqMain.cxx)
87 extern "C" void vtkCommonCS_Initialize(vtkClientServerInterpreter*);
88 extern "C" void vtkFilteringCS_Initialize(vtkClientServerInterpreter*);
89 extern "C" void vtkGenericFilteringCS_Initialize(vtkClientServerInterpreter*);
90 extern "C" void vtkImagingCS_Initialize(vtkClientServerInterpreter*);
91 extern "C" void vtkInfovisCS_Initialize(vtkClientServerInterpreter*);
92 extern "C" void vtkGraphicsCS_Initialize(vtkClientServerInterpreter*);
93 extern "C" void vtkIOCS_Initialize(vtkClientServerInterpreter*);
94 extern "C" void vtkRenderingCS_Initialize(vtkClientServerInterpreter*);
95 extern "C" void vtkVolumeRenderingCS_Initialize(vtkClientServerInterpreter*);
96 extern "C" void vtkHybridCS_Initialize(vtkClientServerInterpreter*);
97 extern "C" void vtkWidgetsCS_Initialize(vtkClientServerInterpreter*);
98 extern "C" void vtkParallelCS_Initialize(vtkClientServerInterpreter*);
99 extern "C" void vtkPVServerCommonCS_Initialize(vtkClientServerInterpreter*);
100 extern "C" void vtkPVFiltersCS_Initialize(vtkClientServerInterpreter*);
101 extern "C" void vtkXdmfCS_Initialize(vtkClientServerInterpreter *);
103 //----------------------------------------------------------------------------
104 void ParaViewInitializeInterpreter(vtkProcessModule* pm)
106 // Initialize built-in wrapper modules.
107 vtkCommonCS_Initialize(pm->GetInterpreter());
108 vtkFilteringCS_Initialize(pm->GetInterpreter());
109 vtkGenericFilteringCS_Initialize(pm->GetInterpreter());
110 vtkImagingCS_Initialize(pm->GetInterpreter());
111 vtkInfovisCS_Initialize(pm->GetInterpreter());
112 vtkGraphicsCS_Initialize(pm->GetInterpreter());
113 vtkIOCS_Initialize(pm->GetInterpreter());
114 vtkRenderingCS_Initialize(pm->GetInterpreter());
115 vtkVolumeRenderingCS_Initialize(pm->GetInterpreter());
116 vtkHybridCS_Initialize(pm->GetInterpreter());
117 vtkWidgetsCS_Initialize(pm->GetInterpreter());
118 vtkParallelCS_Initialize(pm->GetInterpreter());
119 vtkPVServerCommonCS_Initialize(pm->GetInterpreter());
120 vtkPVFiltersCS_Initialize(pm->GetInterpreter());
121 vtkXdmfCS_Initialize(pm->GetInterpreter());
124 //////////////////////////////////////////////////////////////////////////////
125 // PVGUI_Module::pqImplementation
127 class PVGUI_Module::pqImplementation
130 pqImplementation(QWidget* parent) :
131 //AssistantClient(0),
133 //RecentFilesMenu(0),
141 //delete this->ViewMenu;
142 //delete this->ToolbarsMenu;
143 //if(this->AssistantClient)
145 // this->AssistantClient->closeAssistant();
146 // delete this->AssistantClient;
150 //QPointer<QAssistantClient> AssistantClient;
152 pqMainWindowCore Core;
153 //pqRecentFilesMenu* RecentFilesMenu;
154 //pqViewMenu* ViewMenu;
155 //pqViewMenu* ToolbarsMenu;
156 //QLineEdit* CurrentTimeWidget;
157 //QSpinBox* CurrentTimeIndexWidget;
158 QPointer<pqServer> ActiveServer;
159 QString DocumentationDir;
161 static vtkPVMain* myPVMain;
162 static pqOptions* myPVOptions;
163 static PVGUI_ProcessModuleHelper* myPVHelper;
167 vtkPVMain* PVGUI_Module::pqImplementation::myPVMain = 0;
168 pqOptions* PVGUI_Module::pqImplementation::myPVOptions = 0;
169 PVGUI_ProcessModuleHelper* PVGUI_Module::pqImplementation::myPVHelper = 0;
173 \brief Implementation of light (no-CORBA-engine)
174 SALOME module wrapping ParaView GUI.
178 \brief Constructor. Sets the default name for the module.
180 PVGUI_Module::PVGUI_Module()
181 : LightApp_Module( "PARAVIS" ),
189 PVGUI_Module::~PVGUI_Module()
194 \brief Initialize module. Creates menus, prepares context menu, etc.
195 \param app application instance
197 void PVGUI_Module::initialize( CAM_Application* app )
199 LightApp_Module::initialize( app );
211 createAction( lgLoadFile, tr( "TOP_LOAD_FILE" ), QIcon(), tr( "MEN_LOAD_FILE" ),
212 tr( "STB_LOAD_FILE" ), 0, desk, false, this, SLOT( onLoadFile() ) );
213 createAction( lgDisplayLine, tr( "TOP_DISPLAY_LINE" ), QIcon(), tr( "MEN_DISPLAY_LINE" ),
214 tr( "STB_DISPLAY_LINE" ), 0, desk, false, this, SLOT( onDisplayLine() ) );
215 createAction( lgEraseLine, tr( "TOP_ERASE_LINE" ), QIcon(), tr( "MEN_ERASE_LINE" ),
216 tr( "STB_ERASE_LINE" ), 0, desk, false, this, SLOT( onEraseLine() ) );
217 createAction( lgSaveFile, tr( "TOP_SAVE_FILE" ), QIcon(), tr( "MEN_SAVE_FILE" ),
218 tr( "STB_SAVE_FILE" ), 0, desk, false, this, SLOT( onSaveFile() ) );
219 createAction( lgEditLine, tr( "TOP_EDIT_LINE" ), QIcon(), tr( "MEN_EDIT_LINE" ),
220 tr( "STB_EDIT_LINE" ), 0, desk, false, this, SLOT( onEditLine() ) );
221 createAction( lgAddLine, tr( "TOP_ADD_LINE" ), QIcon(), tr( "MEN_ADD_LINE" ),
222 tr( "STB_ADD_LINE" ), 0, desk, false, this, SLOT( onAddLine() ) );
223 createAction( lgDelLine, tr( "TOP_DEL_LINE" ), QIcon(), tr( "MEN_DEL_LINE" ),
224 tr( "STB_DEL_LINE" ), 0, desk, false, this, SLOT( onDelLine() ) );
225 createAction( lgClear, tr( "TOP_CLEAR_ALL" ), QIcon(), tr( "MEN_CLEAR_ALL" ),
226 tr( "STB_CLEAR_ALL" ), 0, desk, false, this, SLOT( onClear() ) );
228 int aFileMnu = createMenu( tr( "MEN_FILE" ), -1, -1 );
229 createMenu( separator(), aFileMnu, -1, 10 );
230 createMenu( lgLoadFile, aFileMnu, 10 );
231 createMenu( lgSaveFile, aFileMnu, 10 );
233 int aLightMnu = createMenu( tr( "MEN_LIGHT" ), -1, -1, 50 );
234 createMenu( lgAddLine, aLightMnu, 10 );
235 createMenu( lgEditLine, aLightMnu, 10 );
236 createMenu( lgDelLine, aLightMnu, 10 );
237 createMenu( separator(), aLightMnu, -1, 10 );
238 createMenu( lgClear, aLightMnu, 10 );
240 QString rule = "(client='ObjectBrowser' or client='OCCViewer') and selcount=1 and type='TextLine' and !empty";
242 popupMgr()->insert ( action( lgDisplayLine ), -1, 0 );
243 popupMgr()->setRule( action( lgDisplayLine ), rule + " and !visible" );
245 popupMgr()->insert ( action( lgEraseLine ), -1, 0 );
246 popupMgr()->setRule( action( lgEraseLine ), rule + " and activeView='OCCViewer' and visible" );
248 rule = "client='ObjectBrowser' and selcount=1 and type='TextLine'";
250 popupMgr()->insert ( action( lgEditLine ), -1, 0 );
251 popupMgr()->setRule( action( lgEditLine ), rule );
253 popupMgr()->insert ( action( lgAddLine ), -1, 0 );
254 popupMgr()->setRule( action( lgAddLine ), rule );
256 popupMgr()->insert ( separator(), -1, 0 );
258 popupMgr()->insert ( action( lgDelLine ), -1, 0 );
259 popupMgr()->setRule( action( lgDelLine ), rule );
261 rule = "client='ObjectBrowser'";
263 popupMgr()->insert ( action( lgClear ), -1, 0 );
264 popupMgr()->setRule( action( lgClear ), rule );*/
268 \brief Get list of compliant dockable GUI elements
269 \param m map to be filled in ("type":"default_position")
271 void PVGUI_Module::windows( QMap<int, int>& m ) const
273 m.insert( LightApp_Application::WT_ObjectBrowser, Qt::LeftDockWidgetArea );
274 // TODO: creation of Python console leads to SIGSEGV on Python initialization...
275 //m.insert( LightApp_Application::WT_PyConsole, Qt::BottomDockWidgetArea );
276 // ParaView diagnostic output redirected here
277 m.insert( LightApp_Application::WT_LogWindow, Qt::BottomDockWidgetArea );
281 \brief Create custom popup menu selection object.
282 \return new selected object
284 /*LightApp_Selection* PVGUI_Module::createSelection() const
286 return new PVGUI_Selection();
290 \brief Create data model.
291 \return module specific data model
293 /*CAM_DataModel* PVGUI_Module::createDataModel()
295 return new PVGUI_DataModel( this );
299 \brief Static method, performs initialization of ParaView session.
300 \return \c true if ParaView has been initialized successfully, otherwise false
302 bool PVGUI_Module::pvInit()
304 if ( !pqImplementation::myPVMain ){
305 // Obtain command-line arguments
307 QStringList args = QApplication::arguments();
308 char** argv = new char*[args.size()];
309 for ( QStringList::const_iterator it = args.begin(); argc < 1 && it != args.end(); it++, argc++ )
310 argv[argc] = strdup( (*it).toLatin1().constData() );
312 vtkPVMain::SetInitializeMPI(0); // pvClient never runs with MPI.
313 vtkPVMain::Initialize(&argc, &argv); // Perform any initializations.
315 // TODO: Set plugin dir from preferences
316 //QApplication::setLibraryPaths(QStringList(dir.absolutePath()));
318 pqImplementation::myPVMain = vtkPVMain::New();
319 if ( !pqImplementation::myPVOptions )
320 pqImplementation::myPVOptions = pqOptions::New();
321 if ( !pqImplementation::myPVHelper )
322 pqImplementation::myPVHelper = PVGUI_ProcessModuleHelper::New();
324 pqImplementation::myPVOptions->SetProcessType(vtkPVOptions::PVCLIENT);
326 // This creates the Process Module and initializes it.
327 int ret = pqImplementation::myPVMain->Initialize(pqImplementation::myPVOptions,
328 pqImplementation::myPVHelper,
329 ParaViewInitializeInterpreter,
332 // Tell process module that we support Multiple connections.
333 // This must be set before starting the event loop.
334 vtkProcessModule::GetProcessModule()->SupportMultipleConnectionsOn();
335 ret = pqImplementation::myPVHelper->Run(pqImplementation::myPVOptions);
346 \brief Static method, cleans up ParaView session at application exit.
348 void PVGUI_Module::pvShutdown()
354 \brief Shows (toShow = true) or hides ParaView view window
356 void PVGUI_Module::showView( bool toShow )
358 // TODO: check if ParaView view already exists
359 if ( !Implementation ){
360 LightApp_Application* anApp = getApp();
361 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
362 PVGUI_ViewManager* viewMgr = new PVGUI_ViewManager( anApp->activeStudy(), anApp->desktop() );
363 anApp->addViewManager( viewMgr );
364 connect( viewMgr, SIGNAL( lastViewClosed( SUIT_ViewManager* ) ),
365 anApp, SLOT( onCloseView( SUIT_ViewManager* ) ) );
366 //connect( viewMgr, SIGNAL( viewCreated( SUIT_ViewWindow* ) ), vm, SLOT( onViewCreated( SUIT_ViewWindow* ) ) );
367 //connect( viewMgr, SIGNAL( deleteView( SUIT_ViewWindow* ) ), this, SLOT( onViewDeleted( SUIT_ViewWindow* ) ) );
368 SUIT_ViewWindow* wnd = viewMgr->createViewWindow();
370 // Simulate ParaView client main window
371 Implementation = new pqImplementation( anApp->desktop() );
372 PVGUI_ViewWindow* pvWnd = dynamic_cast<PVGUI_ViewWindow*>( wnd );
373 pvWnd->setMultiViewManager( &Implementation->Core.multiViewManager() );
381 \brief Create actions for ParaView GUI operations
382 duplicating menus and toolbars in MainWindow class of
383 the standard ParaView GUI client application.
385 In particular, ParaView is responsible for updating "Sources" and "Filters" menus.
386 For this, specific menu managers created by pqMainWindowCore class are used, and PVGUI_Module
387 is responsible for creation of corresponding QMenu objects only.
389 void PVGUI_Module::pvCreateActions()
392 SUIT_Desktop* desk = application()->desktop();
395 int actionManagePlugins = 999;
396 createAction( actionManagePlugins, tr( "TOP_MANAGE_PLUGINS" ), QIcon(), tr( "MEN_MANAGE_PLUGINS" ),
397 tr( "STB_MANAGE_PLUGINS" ), 0, desk, false, &Implementation->Core, SLOT( onManagePlugins() ) );
398 int aPVMnu = createMenu( tr( "MEN_TOOLS" ), -1, -1, 50 );
399 createMenu( actionManagePlugins, aPVMnu, 10 );
401 // Install ParaView managers for "Sources" and "Filters" menus
403 aPVMnu = createMenu( tr( "Sources" ), -1, -1, 60 );
404 res = getMenu( aPVMnu );
406 Implementation->Core.setSourceMenu( res );
407 connect(&this->Implementation->Core,
408 SIGNAL(enableSourceCreate(bool)),
410 SLOT(setEnabled(bool)));
412 aPVMnu = createMenu( tr( "Filters" ), -1, -1, 70 );
413 res = getMenu( aPVMnu );
415 Implementation->Core.setFilterMenu( res );
416 connect(&this->Implementation->Core,
417 SIGNAL(enableFilterCreate(bool)),
419 SLOT(setEnabled(bool)));
425 \brief Create dock widgets for ParaView widgets such as object inspector, pipeline browser, etc.
427 void PVGUI_Module::setupDockWidgets()
432 \brief Returns the ParaView multi-view manager.
434 pqViewManager* PVGUI_Module::getMultiViewManager() const
436 pqViewManager* aMVM = 0;
437 if ( Implementation )
438 aMVM = &Implementation->Core.multiViewManager();
442 QMenu* PVGUI_Module::getMenu( const int id )
445 LightApp_Application* anApp = getApp();
446 SUIT_Desktop* desk = anApp->desktop();
448 QtxActionMenuMgr* menuMgr = desk->menuMgr();
449 res = menuMgr->findMenu( id );
455 \brief Activate module.
456 \param study current study
457 \return \c true if activaion is done successfully or 0 to prevent
460 bool PVGUI_Module::activateModule( SUIT_Study* study )
462 bool isDone = LightApp_Module::activateModule( study );
463 if ( !isDone ) return false;
465 setMenuShown( true );
469 // Make default server connection
470 if ( Implementation )
471 Implementation->Core.makeDefaultConnectionIfNoneExists();
478 \brief Deactivate module.
479 \param study current study
480 \return \c true if deactivaion is done successfully or 0 to prevent
481 deactivation on error
483 bool PVGUI_Module::deactivateModule( SUIT_Study* study )
486 setMenuShown( false );
488 return LightApp_Module::deactivateModule( study );
492 \fn CAM_Module* createModule();
493 \brief Export module instance (factory function).
494 \return new created instance of the module
498 #define PVGUI_EXPORT __declspec(dllexport)
504 PVGUI_EXPORT CAM_Module* createModule() {
505 return new PVGUI_Module();