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"
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>
38 #include <QApplication>
39 #include <QInputDialog>
40 #include <QStringList>
45 #include <pqOptions.h>
46 #include <vtkPVMain.h>
47 #include <vtkProcessModule.h>
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
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>
64 #include <vtkRenderingInstantiator.h>
65 #include <vtkVolumeRenderingInstantiator.h>
66 #include <vtkHybridInstantiator.h>
67 #include <vtkParallelInstantiator.h>
69 #include <vtkPVServerCommonInstantiator.h>
70 #include <vtkPVFiltersInstantiator.h>
71 #include <vtkPVServerManagerInstantiator.h>
72 #include <vtkClientServerInterpreter.h>
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 *);
94 //----------------------------------------------------------------------------
95 void ParaViewInitializeInterpreter(vtkProcessModule* pm)
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());
115 vtkPVMain* PVGUI_Module::myPVMain = 0;
116 pqOptions* PVGUI_Module::myPVOptions = 0;
117 PVGUI_ProcessModuleHelper* PVGUI_Module::myPVHelper = 0;
121 \brief Implementation of light (no-CORBA-engine)
122 SALOME module wrapping ParaView GUI.
126 \brief Constructor. Sets the default name for the module.
128 PVGUI_Module::PVGUI_Module()
129 : LightApp_Module( "PARAVIS" )
136 PVGUI_Module::~PVGUI_Module()
141 \brief Initialize module. Creates menus, prepares context menu, etc.
142 \param app application instance
144 void PVGUI_Module::initialize( CAM_Application* app )
146 LightApp_Module::initialize( app );
148 SUIT_Desktop* desk = application()->desktop();
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() ) );
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 );
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 );
183 QString rule = "(client='ObjectBrowser' or client='OCCViewer') and selcount=1 and type='TextLine' and !empty";
185 popupMgr()->insert ( action( lgDisplayLine ), -1, 0 );
186 popupMgr()->setRule( action( lgDisplayLine ), rule + " and !visible" );
188 popupMgr()->insert ( action( lgEraseLine ), -1, 0 );
189 popupMgr()->setRule( action( lgEraseLine ), rule + " and activeView='OCCViewer' and visible" );
191 rule = "client='ObjectBrowser' and selcount=1 and type='TextLine'";
193 popupMgr()->insert ( action( lgEditLine ), -1, 0 );
194 popupMgr()->setRule( action( lgEditLine ), rule );
196 popupMgr()->insert ( action( lgAddLine ), -1, 0 );
197 popupMgr()->setRule( action( lgAddLine ), rule );
199 popupMgr()->insert ( separator(), -1, 0 );
201 popupMgr()->insert ( action( lgDelLine ), -1, 0 );
202 popupMgr()->setRule( action( lgDelLine ), rule );
204 rule = "client='ObjectBrowser'";
206 popupMgr()->insert ( action( lgClear ), -1, 0 );
207 popupMgr()->setRule( action( lgClear ), rule );*/
211 \brief Get list of compliant dockable GUI elements
212 \param m map to be filled in ("type":"default_position")
214 void PVGUI_Module::windows( QMap<int, int>& m ) const
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 );
224 \brief Create custom popup menu selection object.
225 \return new selected object
227 /*LightApp_Selection* PVGUI_Module::createSelection() const
229 return new PVGUI_Selection();
233 \brief Create data model.
234 \return module specific data model
236 /*CAM_DataModel* PVGUI_Module::createDataModel()
238 return new PVGUI_DataModel( this );
242 \brief Static method, performs initialization of ParaView session.
243 \return \c true if ParaView has been initialized successfully, otherwise false
245 bool PVGUI_Module::pvInit()
248 // Obtain command-line arguments
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() );
255 vtkPVMain::SetInitializeMPI(0); // pvClient never runs with MPI.
256 vtkPVMain::Initialize(&argc, &argv); // Perform any initializations.
258 // TODO: Set plugin dir from preferences
259 //QApplication::setLibraryPaths(QStringList(dir.absolutePath()));
261 myPVMain = vtkPVMain::New();
263 myPVOptions = pqOptions::New();
265 myPVHelper = PVGUI_ProcessModuleHelper::New();
267 myPVOptions->SetProcessType(vtkPVOptions::PVCLIENT);
269 // This creates the Process Module and initializes it.
270 int ret = myPVMain->Initialize(myPVOptions, myPVHelper, ParaViewInitializeInterpreter,
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);
280 cout << "*** ParaView client initalized!!!" << endl;
288 \brief Static method, cleans up ParaView session at application exit.
290 void PVGUI_Module::pvShutdown()
296 \brief Create actions for ParaView GUI operations
297 duplicating menus and toolbars in pqMainWindow ParaView class
299 void PVGUI_Module::pvCreateActions()
305 \brief Activate module.
306 \param study current study
307 \return \c true if activaion is done successfully or 0 to prevent
310 bool PVGUI_Module::activateModule( SUIT_Study* study )
312 bool isDone = LightApp_Module::activateModule( study );
313 if ( !isDone ) return false;
315 setMenuShown( true );
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
326 bool PVGUI_Module::deactivateModule( SUIT_Study* study )
329 setMenuShown( false );
331 return LightApp_Module::deactivateModule( study );
335 \fn CAM_Module* createModule();
336 \brief Export module instance (factory function).
337 \return new created instance of the module
341 #define PVGUI_EXPORT __declspec(dllexport)
347 PVGUI_EXPORT CAM_Module* createModule() {
348 return new PVGUI_Module();