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 <pqApplicationCore.h>
46 #include <pqActiveServer.h>
47 #include <pqObjectBuilder.h>
49 #include <pqServerManagerModel.h>
50 #include <pqServerResource.h>
51 #include <pqViewManager.h>
52 #include <vtkPVMain.h>
53 #include <vtkProcessModule.h>
56 * Make sure all the kits register their classes with vtkInstantiator.
57 * Since ParaView uses Tcl wrapping, all of VTK is already compiled in
58 * anyway. The instantiators will add no more code for the linker to
62 #include <vtkCommonInstantiator.h>
63 #include <vtkFilteringInstantiator.h>
64 #include <vtkGenericFilteringInstantiator.h>
65 #include <vtkIOInstantiator.h>
66 #include <vtkImagingInstantiator.h>
67 #include <vtkInfovisInstantiator.h>
68 #include <vtkGraphicsInstantiator.h>
70 #include <vtkRenderingInstantiator.h>
71 #include <vtkVolumeRenderingInstantiator.h>
72 #include <vtkHybridInstantiator.h>
73 #include <vtkParallelInstantiator.h>
75 #include <vtkPVServerCommonInstantiator.h>
76 #include <vtkPVFiltersInstantiator.h>
77 #include <vtkPVServerManagerInstantiator.h>
78 #include <vtkClientServerInterpreter.h>
81 //----------------------------------------------------------------------------
82 // ClientServer wrapper initialization functions.
83 // Taken from ParaView sources (file pqMain.cxx)
84 extern "C" void vtkCommonCS_Initialize(vtkClientServerInterpreter*);
85 extern "C" void vtkFilteringCS_Initialize(vtkClientServerInterpreter*);
86 extern "C" void vtkGenericFilteringCS_Initialize(vtkClientServerInterpreter*);
87 extern "C" void vtkImagingCS_Initialize(vtkClientServerInterpreter*);
88 extern "C" void vtkInfovisCS_Initialize(vtkClientServerInterpreter*);
89 extern "C" void vtkGraphicsCS_Initialize(vtkClientServerInterpreter*);
90 extern "C" void vtkIOCS_Initialize(vtkClientServerInterpreter*);
91 extern "C" void vtkRenderingCS_Initialize(vtkClientServerInterpreter*);
92 extern "C" void vtkVolumeRenderingCS_Initialize(vtkClientServerInterpreter*);
93 extern "C" void vtkHybridCS_Initialize(vtkClientServerInterpreter*);
94 extern "C" void vtkWidgetsCS_Initialize(vtkClientServerInterpreter*);
95 extern "C" void vtkParallelCS_Initialize(vtkClientServerInterpreter*);
96 extern "C" void vtkPVServerCommonCS_Initialize(vtkClientServerInterpreter*);
97 extern "C" void vtkPVFiltersCS_Initialize(vtkClientServerInterpreter*);
98 extern "C" void vtkXdmfCS_Initialize(vtkClientServerInterpreter *);
100 //----------------------------------------------------------------------------
101 void ParaViewInitializeInterpreter(vtkProcessModule* pm)
103 // Initialize built-in wrapper modules.
104 vtkCommonCS_Initialize(pm->GetInterpreter());
105 vtkFilteringCS_Initialize(pm->GetInterpreter());
106 vtkGenericFilteringCS_Initialize(pm->GetInterpreter());
107 vtkImagingCS_Initialize(pm->GetInterpreter());
108 vtkInfovisCS_Initialize(pm->GetInterpreter());
109 vtkGraphicsCS_Initialize(pm->GetInterpreter());
110 vtkIOCS_Initialize(pm->GetInterpreter());
111 vtkRenderingCS_Initialize(pm->GetInterpreter());
112 vtkVolumeRenderingCS_Initialize(pm->GetInterpreter());
113 vtkHybridCS_Initialize(pm->GetInterpreter());
114 vtkWidgetsCS_Initialize(pm->GetInterpreter());
115 vtkParallelCS_Initialize(pm->GetInterpreter());
116 vtkPVServerCommonCS_Initialize(pm->GetInterpreter());
117 vtkPVFiltersCS_Initialize(pm->GetInterpreter());
118 vtkXdmfCS_Initialize(pm->GetInterpreter());
121 vtkPVMain* PVGUI_Module::myPVMain = 0;
122 pqOptions* PVGUI_Module::myPVOptions = 0;
123 PVGUI_ProcessModuleHelper* PVGUI_Module::myPVHelper = 0;
127 \brief Implementation of light (no-CORBA-engine)
128 SALOME module wrapping ParaView GUI.
132 \brief Constructor. Sets the default name for the module.
134 PVGUI_Module::PVGUI_Module()
135 : LightApp_Module( "PARAVIS" ),
143 PVGUI_Module::~PVGUI_Module()
148 \brief Initialize module. Creates menus, prepares context menu, etc.
149 \param app application instance
151 void PVGUI_Module::initialize( CAM_Application* app )
153 LightApp_Module::initialize( app );
155 SUIT_Desktop* desk = application()->desktop();
168 createAction( lgLoadFile, tr( "TOP_LOAD_FILE" ), QIcon(), tr( "MEN_LOAD_FILE" ),
169 tr( "STB_LOAD_FILE" ), 0, desk, false, this, SLOT( onLoadFile() ) );
170 createAction( lgDisplayLine, tr( "TOP_DISPLAY_LINE" ), QIcon(), tr( "MEN_DISPLAY_LINE" ),
171 tr( "STB_DISPLAY_LINE" ), 0, desk, false, this, SLOT( onDisplayLine() ) );
172 createAction( lgEraseLine, tr( "TOP_ERASE_LINE" ), QIcon(), tr( "MEN_ERASE_LINE" ),
173 tr( "STB_ERASE_LINE" ), 0, desk, false, this, SLOT( onEraseLine() ) );
174 createAction( lgSaveFile, tr( "TOP_SAVE_FILE" ), QIcon(), tr( "MEN_SAVE_FILE" ),
175 tr( "STB_SAVE_FILE" ), 0, desk, false, this, SLOT( onSaveFile() ) );
176 createAction( lgEditLine, tr( "TOP_EDIT_LINE" ), QIcon(), tr( "MEN_EDIT_LINE" ),
177 tr( "STB_EDIT_LINE" ), 0, desk, false, this, SLOT( onEditLine() ) );
178 createAction( lgAddLine, tr( "TOP_ADD_LINE" ), QIcon(), tr( "MEN_ADD_LINE" ),
179 tr( "STB_ADD_LINE" ), 0, desk, false, this, SLOT( onAddLine() ) );
180 createAction( lgDelLine, tr( "TOP_DEL_LINE" ), QIcon(), tr( "MEN_DEL_LINE" ),
181 tr( "STB_DEL_LINE" ), 0, desk, false, this, SLOT( onDelLine() ) );
182 createAction( lgClear, tr( "TOP_CLEAR_ALL" ), QIcon(), tr( "MEN_CLEAR_ALL" ),
183 tr( "STB_CLEAR_ALL" ), 0, desk, false, this, SLOT( onClear() ) );
185 int aFileMnu = createMenu( tr( "MEN_FILE" ), -1, -1 );
186 createMenu( separator(), aFileMnu, -1, 10 );
187 createMenu( lgLoadFile, aFileMnu, 10 );
188 createMenu( lgSaveFile, aFileMnu, 10 );
190 int aLightMnu = createMenu( tr( "MEN_LIGHT" ), -1, -1, 50 );
191 createMenu( lgAddLine, aLightMnu, 10 );
192 createMenu( lgEditLine, aLightMnu, 10 );
193 createMenu( lgDelLine, aLightMnu, 10 );
194 createMenu( separator(), aLightMnu, -1, 10 );
195 createMenu( lgClear, aLightMnu, 10 );
197 QString rule = "(client='ObjectBrowser' or client='OCCViewer') and selcount=1 and type='TextLine' and !empty";
199 popupMgr()->insert ( action( lgDisplayLine ), -1, 0 );
200 popupMgr()->setRule( action( lgDisplayLine ), rule + " and !visible" );
202 popupMgr()->insert ( action( lgEraseLine ), -1, 0 );
203 popupMgr()->setRule( action( lgEraseLine ), rule + " and activeView='OCCViewer' and visible" );
205 rule = "client='ObjectBrowser' and selcount=1 and type='TextLine'";
207 popupMgr()->insert ( action( lgEditLine ), -1, 0 );
208 popupMgr()->setRule( action( lgEditLine ), rule );
210 popupMgr()->insert ( action( lgAddLine ), -1, 0 );
211 popupMgr()->setRule( action( lgAddLine ), rule );
213 popupMgr()->insert ( separator(), -1, 0 );
215 popupMgr()->insert ( action( lgDelLine ), -1, 0 );
216 popupMgr()->setRule( action( lgDelLine ), rule );
218 rule = "client='ObjectBrowser'";
220 popupMgr()->insert ( action( lgClear ), -1, 0 );
221 popupMgr()->setRule( action( lgClear ), rule );*/
225 \brief Get list of compliant dockable GUI elements
226 \param m map to be filled in ("type":"default_position")
228 void PVGUI_Module::windows( QMap<int, int>& m ) const
230 m.insert( LightApp_Application::WT_ObjectBrowser, Qt::LeftDockWidgetArea );
231 // TODO: creation of Python console leads to SIGSEGV on Python initialization...
232 //m.insert( LightApp_Application::WT_PyConsole, Qt::BottomDockWidgetArea );
233 // ParaView diagnostic output redirected here
234 m.insert( LightApp_Application::WT_LogWindow, Qt::BottomDockWidgetArea );
238 \brief Create custom popup menu selection object.
239 \return new selected object
241 /*LightApp_Selection* PVGUI_Module::createSelection() const
243 return new PVGUI_Selection();
247 \brief Create data model.
248 \return module specific data model
250 /*CAM_DataModel* PVGUI_Module::createDataModel()
252 return new PVGUI_DataModel( this );
256 \brief Static method, performs initialization of ParaView session.
257 \return \c true if ParaView has been initialized successfully, otherwise false
259 bool PVGUI_Module::pvInit()
262 // Obtain command-line arguments
264 QStringList args = QApplication::arguments();
265 char** argv = new char*[args.size()];
266 for ( QStringList::const_iterator it = args.begin(); argc < 1 && it != args.end(); it++, argc++ )
267 argv[argc] = strdup( (*it).toLatin1().constData() );
269 vtkPVMain::SetInitializeMPI(0); // pvClient never runs with MPI.
270 vtkPVMain::Initialize(&argc, &argv); // Perform any initializations.
272 // TODO: Set plugin dir from preferences
273 //QApplication::setLibraryPaths(QStringList(dir.absolutePath()));
275 myPVMain = vtkPVMain::New();
277 myPVOptions = pqOptions::New();
279 myPVHelper = PVGUI_ProcessModuleHelper::New();
281 myPVOptions->SetProcessType(vtkPVOptions::PVCLIENT);
283 // This creates the Process Module and initializes it.
284 int ret = myPVMain->Initialize(myPVOptions, myPVHelper, ParaViewInitializeInterpreter,
287 // Tell process module that we support Multiple connections.
288 // This must be set before starting the event loop.
289 vtkProcessModule::GetProcessModule()->SupportMultipleConnectionsOn();
290 ret = myPVHelper->Run(myPVOptions);
301 \brief Static method, cleans up ParaView session at application exit.
303 void PVGUI_Module::pvShutdown()
309 \brief Shows (toShow = true) or hides ParaView view window
311 void PVGUI_Module::showView( bool toShow )
313 // TODO: check if ParaView view already exists
314 LightApp_Application* anApp = getApp();
315 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
316 PVGUI_ViewManager* viewMgr = new PVGUI_ViewManager( anApp->activeStudy(), anApp->desktop() );
317 anApp->addViewManager( viewMgr );
318 connect( viewMgr, SIGNAL( lastViewClosed( SUIT_ViewManager* ) ),
319 anApp, SLOT( onCloseView( SUIT_ViewManager* ) ) );
320 //connect( viewMgr, SIGNAL( viewCreated( SUIT_ViewWindow* ) ), vm, SLOT( onViewCreated( SUIT_ViewWindow* ) ) );
321 //connect( viewMgr, SIGNAL( deleteView( SUIT_ViewWindow* ) ), this, SLOT( onViewDeleted( SUIT_ViewWindow* ) ) );
322 SUIT_ViewWindow* wnd = viewMgr->createViewWindow();
326 \brief Create actions for ParaView GUI operations
327 duplicating menus and toolbars in pqMainWindow ParaView class
329 void PVGUI_Module::pvCreateActions()
335 \brief Returns the active ParaView server connection.
337 pqServer* PVGUI_Module::getActiveServer() const
339 return myActiveServer->current();
343 \brief Returns the ParaView multi-view manager.
345 pqViewManager* PVGUI_Module::getMultiViewManager() const
347 pqViewManager* aMVM = 0;
348 LightApp_Application* anApp = getApp();
349 PVGUI_ViewManager* aPVMgr = dynamic_cast<PVGUI_ViewManager*>( anApp->activeViewManager() );
351 aMVM = aPVMgr->getMultiViewManager();
356 \brief Creates a built-in server connection.
358 void PVGUI_Module::makeDefaultConnectionIfNoneExists()
360 if (this->getActiveServer())
365 pqApplicationCore* core = pqApplicationCore::instance();
366 if (core->getServerManagerModel()->getNumberOfItems<pqServer*>() != 0)
368 // cannot really happen, however, if no active server, yet
369 // server connection exists, we don't try to make a new server connection.
373 pqServerResource resource = pqServerResource("builtin:");
374 core->getObjectBuilder()->createServer(resource);
379 \brief Activate module.
380 \param study current study
381 \return \c true if activaion is done successfully or 0 to prevent
384 bool PVGUI_Module::activateModule( SUIT_Study* study )
386 bool isDone = LightApp_Module::activateModule( study );
387 if ( !isDone ) return false;
389 setMenuShown( true );
393 // Make default server connection
394 // see pqMainWindowCore::makeDefaultConnectionIfNoneExists()
395 if ( !myActiveServer && getMultiViewManager() ) {
396 myActiveServer = new pqActiveServer( this );
397 QObject::connect ( myActiveServer, SIGNAL(changed(pqServer*)),
398 getMultiViewManager(), SLOT(setActiveServer(pqServer*)) );
401 makeDefaultConnectionIfNoneExists();
408 \brief Deactivate module.
409 \param study current study
410 \return \c true if deactivaion is done successfully or 0 to prevent
411 deactivation on error
413 bool PVGUI_Module::deactivateModule( SUIT_Study* study )
416 setMenuShown( false );
418 return LightApp_Module::deactivateModule( study );
422 \fn CAM_Module* createModule();
423 \brief Export module instance (factory function).
424 \return new created instance of the module
428 #define PVGUI_EXPORT __declspec(dllexport)
434 PVGUI_EXPORT CAM_Module* createModule() {
435 return new PVGUI_Module();