-// LIGHT : sample (no-corba-engine) SALOME module
+// PARAVIS : ParaView wrapper SALOME module
//
// Copyright (C) 2003 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
// Author : Julia DOROVSKIKH
//
+#include <vtkPython.h> // Python first
#include "PVGUI_Module.h"
-#include "PVGUI_ProcessModuleHelper.h"
+
+#include "SALOMEconfig.h"
+#include CORBA_CLIENT_HEADER(VISU_Gen)
+#include CORBA_SERVER_HEADER(SALOMEDS)
+
+
+#include "PARAVIS_Gen_i.hh"
+
+#include "PVGUI_Module_impl.h"
#include "PVGUI_ViewModel.h"
#include "PVGUI_ViewManager.h"
+#include "PVGUI_ViewWindow.h"
+#include "PVGUI_Tools.h"
+//#include "PVGUI_Trace.h"
-#include <SUIT_MessageBox.h>
#include <SUIT_Desktop.h>
+#include <SUIT_MessageBox.h>
+#include <SUIT_ResourceMgr.h>
#include <SUIT_Session.h>
-#include <LightApp_Application.h>
+#include <SUIT_OverrideCursor.h>
+
+// SALOME Includes
+#include "SALOME_LifeCycleCORBA.hxx"
+#include "SALOME_ListIteratorOfListIO.hxx"
+#include "SALOMEDS_SObject.hxx"
+
#include <LightApp_SelectionMgr.h>
+#include <SalomeApp_Application.h>
+#include <SalomeApp_Study.h>
+#include <SALOME_ListIO.hxx>
+#include <SALOMEDS_Tool.hxx>
+#include <PyInterp_Dispatcher.h>
+
+#include <QtxActionMenuMgr.h>
+#include <QtxActionToolMgr.h>
+#include <QAction>
#include <QApplication>
-#include <QInputDialog>
-#include <QStringList>
-#include <QMenu>
+#include <QCursor>
+#include <QDir>
+#include <QFile>
+#include <QFileInfo>
#include <QIcon>
+#include <QInputDialog>
+#include <QStatusBar>
#include <QString>
+#include <QStringList>
+#include <QTimer>
+#include <QToolBar>
+#include <QTextStream>
+#include <QShortcut>
-#include <pqOptions.h>
#include <pqApplicationCore.h>
-#include <pqActiveServer.h>
+#include <pqActiveView.h>
#include <pqObjectBuilder.h>
+#include <pqOptions.h>
+#include <pqRenderView.h>
#include <pqServer.h>
-#include <pqServerManagerModel.h>
-#include <pqServerResource.h>
+#include <pqUndoStack.h>
+#include <pqVCRController.h>
#include <pqViewManager.h>
+#include <pqPipelineSource.h>
#include <vtkPVMain.h>
#include <vtkProcessModule.h>
+#include <pqParaViewBehaviors.h>
+#include <pqHelpReaction.h>
+#include <vtkOutputWindow.h>
+#include <pqPluginManager.h>
+#include <vtkPVPluginInformation.h>
+#include <pqSettings.h>
+#include <pqPythonDialog.h>
+#include <pqPythonManager.h>
+#include <pqPythonShell.h>
+#include "pqBrandPluginsLoader.h"
+#include <pqLoadDataReaction.h>
/*
* Make sure all the kits register their classes with vtkInstantiator.
#include <vtkHybridInstantiator.h>
#include <vtkParallelInstantiator.h>
-#include <vtkPVServerCommonInstantiator.h>
-#include <vtkPVFiltersInstantiator.h>
-#include <vtkPVServerManagerInstantiator.h>
-#include <vtkClientServerInterpreter.h>
+#include <pqAlwaysConnectedBehavior.h>
+#include <pqApplicationCore.h>
+#include <pqAutoLoadPluginXMLBehavior.h>
+#include <pqCommandLineOptionsBehavior.h>
+#include <pqCrashRecoveryBehavior.h>
+#include <pqDataTimeStepBehavior.h>
+#include <pqDefaultViewBehavior.h>
+#include <pqDeleteBehavior.h>
+#include <pqPersistentMainWindowStateBehavior.h>
+#include <pqPluginActionGroupBehavior.h>
+#include <pqPluginDockWidgetsBehavior.h>
+#include <pqPluginManager.h>
+#include <pqPVNewSourceBehavior.h>
+//#include <pqQtMessageHandlerBehavior.h>
+#include <pqSpreadSheetVisibilityBehavior.h>
+#include <pqStandardViewModules.h>
+#include <pqUndoRedoBehavior.h>
+#include <pqViewFrameActionsBehavior.h>
//----------------------------------------------------------------------------
-// ClientServer wrapper initialization functions.
-// Taken from ParaView sources (file pqMain.cxx)
-extern "C" void vtkCommonCS_Initialize(vtkClientServerInterpreter*);
-extern "C" void vtkFilteringCS_Initialize(vtkClientServerInterpreter*);
-extern "C" void vtkGenericFilteringCS_Initialize(vtkClientServerInterpreter*);
-extern "C" void vtkImagingCS_Initialize(vtkClientServerInterpreter*);
-extern "C" void vtkInfovisCS_Initialize(vtkClientServerInterpreter*);
-extern "C" void vtkGraphicsCS_Initialize(vtkClientServerInterpreter*);
-extern "C" void vtkIOCS_Initialize(vtkClientServerInterpreter*);
-extern "C" void vtkRenderingCS_Initialize(vtkClientServerInterpreter*);
-extern "C" void vtkVolumeRenderingCS_Initialize(vtkClientServerInterpreter*);
-extern "C" void vtkHybridCS_Initialize(vtkClientServerInterpreter*);
-extern "C" void vtkWidgetsCS_Initialize(vtkClientServerInterpreter*);
-extern "C" void vtkParallelCS_Initialize(vtkClientServerInterpreter*);
-extern "C" void vtkPVServerCommonCS_Initialize(vtkClientServerInterpreter*);
-extern "C" void vtkPVFiltersCS_Initialize(vtkClientServerInterpreter*);
-extern "C" void vtkXdmfCS_Initialize(vtkClientServerInterpreter *);
+pqApplicationCore* PVGUI_Module::pqImplementation::Core = 0;
+PVGUI_OutputWindowAdapter* PVGUI_Module::pqImplementation::OutputWindowAdapter = 0;
+QPointer<pqHelpWindow> PVGUI_Module::pqImplementation::helpWindow = 0;
-//----------------------------------------------------------------------------
-void ParaViewInitializeInterpreter(vtkProcessModule* pm)
-{
- // Initialize built-in wrapper modules.
- vtkCommonCS_Initialize(pm->GetInterpreter());
- vtkFilteringCS_Initialize(pm->GetInterpreter());
- vtkGenericFilteringCS_Initialize(pm->GetInterpreter());
- vtkImagingCS_Initialize(pm->GetInterpreter());
- vtkInfovisCS_Initialize(pm->GetInterpreter());
- vtkGraphicsCS_Initialize(pm->GetInterpreter());
- vtkIOCS_Initialize(pm->GetInterpreter());
- vtkRenderingCS_Initialize(pm->GetInterpreter());
- vtkVolumeRenderingCS_Initialize(pm->GetInterpreter());
- vtkHybridCS_Initialize(pm->GetInterpreter());
- vtkWidgetsCS_Initialize(pm->GetInterpreter());
- vtkParallelCS_Initialize(pm->GetInterpreter());
- vtkPVServerCommonCS_Initialize(pm->GetInterpreter());
- vtkPVFiltersCS_Initialize(pm->GetInterpreter());
- vtkXdmfCS_Initialize(pm->GetInterpreter());
-}
+PVGUI_Module* ParavisModule = 0;
+
+/*!
+ \mainpage
+
+ <h2>Building and installing PARAVIS</h2>
+ As any other SALOME module, PARAVIS requires PARAVIS_ROOT_DIR environment variable to be set to PARAVIS
+ installation directory.
+ Other variables needed for correct detection of ParaView location:
+ \li PVHOME - points at the ParaView installation directory tree
+ \li PVVERSION - number of ParaView version
+
+ It also requires common SALOME environment including GUI_ROOT_DIR and other prerequsites.
+
+
+ PARAVIS module can be launched using the following commands:
+ \li Full SALOME configuration
+ \code
+ runSalome --modules="PARAVIS"
+ \endcode
+
+ <h2>ParaView GUI integration</h2>
+ <h3>ParaView GUI integration overview</h3>
+
+ The main idea is to reuse ParaView GUI internal logic as much as possible, providing a layer
+ between it and SALOME GUI that hides the following SALOME GUI implementation details from ParaView:
-vtkPVMain* PVGUI_Module::myPVMain = 0;
-pqOptions* PVGUI_Module::myPVOptions = 0;
-PVGUI_ProcessModuleHelper* PVGUI_Module::myPVHelper = 0;
+ \li SALOME GUI executable and Qt event loop
+ \li SALOME GUI desktop
+ \li Dock windows areas
+ \li SALOME menu and toolbar managers
+
+ Major part of the integration is implemented in PVGUI_Module class.
+
+ <h3>ParaView client initalization</h3>
+
+ ParaView client initalization is performed when an instance of PVGUI_Module class has been created
+ and \link PVGUI_Module::initialize() PVGUI_Module::initialize()\endlink method is called by SALOME GUI.
+ The actual client start-up is done in \link PVGUI_Module::pvInit() PVGUI_Module::pvInit()\endlink method.
+
+
+ <h3>Multi-view manager</h3>
+
+ SALOME GUI requires that each kind of view be implemnted with help of (at least) three classes. For ParaView multi-view manager
+ these are:
+
+ \li PVGUI_ViewManager - view manager class
+ \li PVGUI_Viewer - view model class
+ \li PVGUI_ViewWindow - view window class that acts as a parent for %pqViewManager
+
+ Single instances of PVGUI_ViewManager and PVGUI_ViewWindow classes are created by \link PVGUI_Module::showView()
+ PVGUI_Module::showView()\endlink method upon the first PARAVIS module activation. The same method hides the multi-view manager
+ when the module is deactivated (the user switches to another module or a study is closed).
+ A special trick is used to make PVGUI_ViewWindow the parent of %pqViewManager widget. It is created initally by %pqMainWindowCore
+ with the desktop as a parent, so when it is shown PVGUI_ViewWindow instance is passed to its setParent() method. In
+ \link PVGUI_ViewWindow::~PVGUI_ViewWindow() PVGUI_ViewWindow::~PVGUI_ViewWindow()\endlink the parent is nullified to avoid deletion
+ of %pqViewManager widget that would break %pqMainWindowCore class.
+
+ <h3>ParaView plugins</h3>
+ ParaView server and client plugins are managed by %pqMainWindowCore slots that has full access to PARAVIS menus and toolbars.
+ As a result they appears automatically in PARAVIS menus and toolbars if loaded successfully.
+*/
/*!
\class PVGUI_Module
- \brief Implementation of light (no-CORBA-engine)
+ \brief Implementation
SALOME module wrapping ParaView GUI.
*/
\brief Constructor. Sets the default name for the module.
*/
PVGUI_Module::PVGUI_Module()
- : LightApp_Module( "PARAVIS" ),
- myActiveServer( 0 )
+ : SalomeApp_Module( "PARAVIS" ),
+ LightApp_Module( "PARAVIS" ),
+ Implementation( 0 ),
+ mySelectionControlsTb( -1 ),
+ mySourcesMenuId( -1 ),
+ myFiltersMenuId( -1 ),
+ myMacrosMenuId(-1),
+ myToolbarsMenuId(-1),
+ myOldMsgHandler(0)
{
+ ParavisModule = this;
}
/*!
{
}
+
+
/*!
\brief Initialize module. Creates menus, prepares context menu, etc.
- \param app application instance
+ \param app SALOME GUI application instance
*/
void PVGUI_Module::initialize( CAM_Application* app )
{
- LightApp_Module::initialize( app );
-
- SUIT_Desktop* desk = application()->desktop();
+ SalomeApp_Module::initialize( app );
+ // Uncomment to debug ParaView initialization
+ // "aa" used instead of "i" as GDB doesn't like "i" variables :)
/*
- int i = 1;
- while( i ){
- i = i;
+ int aa = 1;
+ while( aa ){
+ aa = aa;
}
*/
+
+ // Initialize ParaView client
+ pvInit();
+
+ // Create GUI elements (menus, toolbars, dock widgets)
+ if ( !Implementation ){
+ SalomeApp_Application* anApp = getApp();
- if ( pvInit() ) {
+ // Simulate ParaView client main window
+ Implementation = new pqImplementation( anApp->desktop() );
+
+ setupDockWidgets();
+
pvCreateActions();
+ pvCreateToolBars();
+ pvCreateMenus();
+
+ // new pqParaViewBehaviors(anApp->desktop(), this);
+ // Has to be replaced in order to exclude using of pqQtMessageHandlerBehaviour
+ // Start pqParaViewBehaviors
+ // Register ParaView interfaces.
+ pqPluginManager* pgm = pqApplicationCore::instance()->getPluginManager();
+
+ // * adds support for standard paraview views.
+ pgm->addInterface(new pqStandardViewModules(pgm));
+
+ // Load plugins distributed with application.
+ pqApplicationCore::instance()->loadDistributedPlugins();
+
+ // Define application behaviors.
+ //new pqQtMessageHandlerBehavior(this);
+ new pqDataTimeStepBehavior(this);
+ new pqViewFrameActionsBehavior(this);
+ new pqSpreadSheetVisibilityBehavior(this);
+ new pqDefaultViewBehavior(this);
+ new pqAlwaysConnectedBehavior(this);
+ new pqPVNewSourceBehavior(this);
+ new pqDeleteBehavior(this);
+ new pqUndoRedoBehavior(this);
+ new pqCrashRecoveryBehavior(this);
+ new pqAutoLoadPluginXMLBehavior(this);
+ new pqPluginDockWidgetsBehavior(getApp()->desktop());
+ new pqPluginActionGroupBehavior(getApp()->desktop());
+ new pqCommandLineOptionsBehavior(this);
+ new pqPersistentMainWindowStateBehavior(getApp()->desktop());
+
+ // Setup quick-launch shortcuts.
+ QShortcut *ctrlSpace = new QShortcut(Qt::CTRL + Qt::Key_Space,
+ getApp()->desktop());
+ QObject::connect(ctrlSpace, SIGNAL(activated()),
+ pqApplicationCore::instance(), SLOT(quickLaunch()));
+ QShortcut *altSpace = new QShortcut(Qt::ALT + Qt::Key_Space,
+ getApp()->desktop());
+ QObject::connect(altSpace, SIGNAL(activated()),
+ pqApplicationCore::instance(), SLOT(quickLaunch()));
+ // End pqParaViewBehaviors
+
+
+ SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
+ QString aPath = resMgr->stringValue("resources", "PARAVIS", QString());
+ if (!aPath.isNull()) {
+ pqImplementation::Core->loadConfiguration(aPath + QDir::separator() + "ParaViewFilters.xml");
+ pqImplementation::Core->loadConfiguration(aPath + QDir::separator() + "ParaViewReaders.xml");
+ pqImplementation::Core->loadConfiguration(aPath + QDir::separator() + "ParaViewSources.xml");
+ pqImplementation::Core->loadConfiguration(aPath + QDir::separator() + "ParaViewWriters.xml");
+ }
+ // Now that we're ready, initialize everything ...
+
+
+ // Force creation of engine
+ PARAVIS::GetParavisGen(this);
+ updateObjBrowser();
+ }
+
+ // Initialize list of toolbars
+ QCoreApplication::processEvents();
+ QList<QToolBar*> aBars = getParaViewToolbars();
+ foreach (QToolBar* aBar, aBars) {
+ myToolbarState[aBar] = true;
+ }
+
+ SUIT_ResourceMgr* aResourceMgr = SUIT_Session::session()->resourceMgr();
+ bool isStop = aResourceMgr->booleanValue( "PARAVIS", "stop_trace", false );
+ if(!isStop)
+ QTimer::singleShot(50, this, SLOT(activateTrace()));
+}
+
+
+void PVGUI_Module::activateTrace()
+{
+ PyInterp_Dispatcher* aDispatcher = PyInterp_Dispatcher::Get();
+ if (aDispatcher->IsBusy()) {
+ QTimer::singleShot(50, this, SLOT(activateTrace()));
+ return;
+ }
+
+ pqPythonDialog* pyDiag = 0;
+ pqPythonManager* manager = qobject_cast<pqPythonManager*>(
+ pqApplicationCore::instance()->manager("PYTHON_MANAGER"));
+ if (manager) {
+ pyDiag = manager->pythonShellDialog();
+ }
+ if (pyDiag) {
+ pyDiag->runString("try:\n"
+ " from paraview import smtrace\n"
+ " smtrace.start_trace()\n"
+ " print 'Trace started.'\n"
+ "except: raise RuntimeError('could not import paraview.smtrace')\n");
}
- /*
- createAction( lgLoadFile, tr( "TOP_LOAD_FILE" ), QIcon(), tr( "MEN_LOAD_FILE" ),
- tr( "STB_LOAD_FILE" ), 0, desk, false, this, SLOT( onLoadFile() ) );
- createAction( lgDisplayLine, tr( "TOP_DISPLAY_LINE" ), QIcon(), tr( "MEN_DISPLAY_LINE" ),
- tr( "STB_DISPLAY_LINE" ), 0, desk, false, this, SLOT( onDisplayLine() ) );
- createAction( lgEraseLine, tr( "TOP_ERASE_LINE" ), QIcon(), tr( "MEN_ERASE_LINE" ),
- tr( "STB_ERASE_LINE" ), 0, desk, false, this, SLOT( onEraseLine() ) );
- createAction( lgSaveFile, tr( "TOP_SAVE_FILE" ), QIcon(), tr( "MEN_SAVE_FILE" ),
- tr( "STB_SAVE_FILE" ), 0, desk, false, this, SLOT( onSaveFile() ) );
- createAction( lgEditLine, tr( "TOP_EDIT_LINE" ), QIcon(), tr( "MEN_EDIT_LINE" ),
- tr( "STB_EDIT_LINE" ), 0, desk, false, this, SLOT( onEditLine() ) );
- createAction( lgAddLine, tr( "TOP_ADD_LINE" ), QIcon(), tr( "MEN_ADD_LINE" ),
- tr( "STB_ADD_LINE" ), 0, desk, false, this, SLOT( onAddLine() ) );
- createAction( lgDelLine, tr( "TOP_DEL_LINE" ), QIcon(), tr( "MEN_DEL_LINE" ),
- tr( "STB_DEL_LINE" ), 0, desk, false, this, SLOT( onDelLine() ) );
- createAction( lgClear, tr( "TOP_CLEAR_ALL" ), QIcon(), tr( "MEN_CLEAR_ALL" ),
- tr( "STB_CLEAR_ALL" ), 0, desk, false, this, SLOT( onClear() ) );
-
- int aFileMnu = createMenu( tr( "MEN_FILE" ), -1, -1 );
- createMenu( separator(), aFileMnu, -1, 10 );
- createMenu( lgLoadFile, aFileMnu, 10 );
- createMenu( lgSaveFile, aFileMnu, 10 );
-
- int aLightMnu = createMenu( tr( "MEN_LIGHT" ), -1, -1, 50 );
- createMenu( lgAddLine, aLightMnu, 10 );
- createMenu( lgEditLine, aLightMnu, 10 );
- createMenu( lgDelLine, aLightMnu, 10 );
- createMenu( separator(), aLightMnu, -1, 10 );
- createMenu( lgClear, aLightMnu, 10 );
-
- QString rule = "(client='ObjectBrowser' or client='OCCViewer') and selcount=1 and type='TextLine' and !empty";
-
- popupMgr()->insert ( action( lgDisplayLine ), -1, 0 );
- popupMgr()->setRule( action( lgDisplayLine ), rule + " and !visible" );
-
- popupMgr()->insert ( action( lgEraseLine ), -1, 0 );
- popupMgr()->setRule( action( lgEraseLine ), rule + " and activeView='OCCViewer' and visible" );
-
- rule = "client='ObjectBrowser' and selcount=1 and type='TextLine'";
-
- popupMgr()->insert ( action( lgEditLine ), -1, 0 );
- popupMgr()->setRule( action( lgEditLine ), rule );
-
- popupMgr()->insert ( action( lgAddLine ), -1, 0 );
- popupMgr()->setRule( action( lgAddLine ), rule );
-
- popupMgr()->insert ( separator(), -1, 0 );
-
- popupMgr()->insert ( action( lgDelLine ), -1, 0 );
- popupMgr()->setRule( action( lgDelLine ), rule );
-
- rule = "client='ObjectBrowser'";
-
- popupMgr()->insert ( action( lgClear ), -1, 0 );
- popupMgr()->setRule( action( lgClear ), rule );*/
}
+
+
/*!
\brief Get list of compliant dockable GUI elements
\param m map to be filled in ("type":"default_position")
void PVGUI_Module::windows( QMap<int, int>& m ) const
{
m.insert( LightApp_Application::WT_ObjectBrowser, Qt::LeftDockWidgetArea );
- // TODO: creation of Python console leads to SIGSEGV on Python initialization...
- //m.insert( LightApp_Application::WT_PyConsole, Qt::BottomDockWidgetArea );
+ m.insert( LightApp_Application::WT_PyConsole, Qt::BottomDockWidgetArea );
// ParaView diagnostic output redirected here
m.insert( LightApp_Application::WT_LogWindow, Qt::BottomDockWidgetArea );
}
-/*!
- \brief Create custom popup menu selection object.
- \return new selected object
-*/
-/*LightApp_Selection* PVGUI_Module::createSelection() const
-{
- return new PVGUI_Selection();
-}*/
-
-/*!
- \brief Create data model.
- \return module specific data model
-*/
-/*CAM_DataModel* PVGUI_Module::createDataModel()
-{
- return new PVGUI_DataModel( this );
-}*/
-
/*!
\brief Static method, performs initialization of ParaView session.
\return \c true if ParaView has been initialized successfully, otherwise false
*/
bool PVGUI_Module::pvInit()
{
- if ( !myPVMain ){
+ if ( !pqImplementation::Core ){
// Obtain command-line arguments
int argc = 0;
QStringList args = QApplication::arguments();
char** argv = new char*[args.size()];
- for ( QStringList::const_iterator it = args.begin(); argc < 1 && it != args.end(); it++, argc++ )
+ for ( QStringList::const_iterator it = args.begin(); argc < 1 && it != args.end(); it++, argc++ ) {
argv[argc] = strdup( (*it).toLatin1().constData() );
+ }
+ pqImplementation::Core = new pqPVApplicationCore (argc, argv);
+ if (pqImplementation::Core->getOptions()->GetHelpSelected() ||
+ pqImplementation::Core->getOptions()->GetUnknownArgument() ||
+ pqImplementation::Core->getOptions()->GetErrorMessage() ||
+ pqImplementation::Core->getOptions()->GetTellVersion()) {
+ return false;
+ }
+ // VSV: Code from Initializer - it seems that it does nothing
+
+ // Not sure why this is needed. Andy added this ages ago with comment saying
+ // needed for Mac apps. Need to check that it's indeed still required.
+ QDir dir(QApplication::applicationDirPath());
+ dir.cdUp();
+ dir.cd("Plugins");
+ QApplication::addLibraryPath(dir.absolutePath());
+ // Load required application plugins.
+ QString plugin_string = "";
+ QStringList plugin_list = plugin_string.split(';',QString::SkipEmptyParts);
+ pqBrandPluginsLoader loader;
+ if (loader.loadPlugins(plugin_list) == false) {
+ printf("Failed to load required plugins for this application\n");
+ return false;
+ }
- vtkPVMain::SetInitializeMPI(0); // pvClient never runs with MPI.
- vtkPVMain::Initialize(&argc, &argv); // Perform any initializations.
-
- // TODO: Set plugin dir from preferences
- //QApplication::setLibraryPaths(QStringList(dir.absolutePath()));
+ // Load optional plugins.
+ plugin_string = "";
+ plugin_list = plugin_string.split(';',QString::SkipEmptyParts);
+ loader.loadPlugins(plugin_list, true); //quietly skip not-found plugins.
- myPVMain = vtkPVMain::New();
- if ( !myPVOptions )
- myPVOptions = pqOptions::New();
- if ( !myPVHelper )
- myPVHelper = PVGUI_ProcessModuleHelper::New();
+ // End of Initializer code
- myPVOptions->SetProcessType(vtkPVOptions::PVCLIENT);
+ //qInstallMsgHandler(0); // switch off standard Paraview message handler
+ pqImplementation::OutputWindowAdapter = PVGUI_OutputWindowAdapter::New();
+ vtkOutputWindow::SetInstance(pqImplementation::OutputWindowAdapter);
- // This creates the Process Module and initializes it.
- int ret = myPVMain->Initialize(myPVOptions, myPVHelper, ParaViewInitializeInterpreter,
- argc, argv);
- if (!ret){
- // Tell process module that we support Multiple connections.
- // This must be set before starting the event loop.
- vtkProcessModule::GetProcessModule()->SupportMultipleConnectionsOn();
- ret = myPVHelper->Run(myPVOptions);
- }
+ //pqPluginManager* pgm = pqApplicationCore::instance()->getPluginManager();
+ //pgm->loadExtensions(NULL);
+ new pqViewManager(); // it registers as "MULTIVIEW_MANAGER on creation
+
+ if (argc == 1)
+ free(argv[0]); // because in creation argc < 1
delete[] argv;
- return !ret;
}
return true;
}
/*!
- \brief Static method, cleans up ParaView session at application exit.
+ \brief Shows (toShow = true) or hides ParaView view window
*/
-void PVGUI_Module::pvShutdown()
+void PVGUI_Module::showView( bool toShow )
{
- // TODO...
-}
+ SalomeApp_Application* anApp = getApp();
+ PVGUI_ViewManager* viewMgr =
+ dynamic_cast<PVGUI_ViewManager*>( anApp->getViewManager( PVGUI_Viewer::Type(), false ) );
+ if ( !viewMgr ) {
+ viewMgr = new PVGUI_ViewManager( anApp->activeStudy(), anApp->desktop() );
+ anApp->addViewManager( viewMgr );
+ connect( viewMgr, SIGNAL( lastViewClosed( SUIT_ViewManager* ) ),
+ anApp, SLOT( onCloseView( SUIT_ViewManager* ) ) );
+ }
+
+ PVGUI_ViewWindow* pvWnd = dynamic_cast<PVGUI_ViewWindow*>( viewMgr->getActiveView() );
+ if ( !pvWnd ) {
+ pvWnd = dynamic_cast<PVGUI_ViewWindow*>( viewMgr->createViewWindow() );
+ }
+
+ pvWnd->setShown( toShow );
+}
+
+
+// void PVGUI_Module::connectToPlay()
+// {
+// connect( action(PlayId), SIGNAL( triggered() ), &Implementation->Core.VCRController(), SLOT( onPlay() ) );
+// }
+
/*!
- \brief Shows (toShow = true) or hides ParaView view window
+ \brief Slot to show help for proxy.
*/
-void PVGUI_Module::showView( bool toShow )
+void PVGUI_Module::showHelpForProxy( const QString& proxy )
{
- // TODO: check if ParaView view already exists
- LightApp_Application* anApp = getApp();
- SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
- PVGUI_ViewManager* viewMgr = new PVGUI_ViewManager( anApp->activeStudy(), anApp->desktop() );
- anApp->addViewManager( viewMgr );
- connect( viewMgr, SIGNAL( lastViewClosed( SUIT_ViewManager* ) ),
- anApp, SLOT( onCloseView( SUIT_ViewManager* ) ) );
- //connect( viewMgr, SIGNAL( viewCreated( SUIT_ViewWindow* ) ), vm, SLOT( onViewCreated( SUIT_ViewWindow* ) ) );
- //connect( viewMgr, SIGNAL( deleteView( SUIT_ViewWindow* ) ), this, SLOT( onViewDeleted( SUIT_ViewWindow* ) ) );
- SUIT_ViewWindow* wnd = viewMgr->createViewWindow();
+ //pqHelpReaction::showHelp(QString("qthelp://paraview.org/paraview/%1.html").arg(proxy));
+ showHelp(QString("qthelp://paraview.org/paraview/%1.html").arg(proxy));
}
-
+
+void PVGUI_Module::showParaViewHelp()
+{
+ showHelp(QString());
+}
+
+void PVGUI_Module::showHelp(const QString& url)
+{
+ if (pqImplementation::helpWindow) {
+ // raise assistant window;
+ pqImplementation::helpWindow->show();
+ pqImplementation::helpWindow->raise();
+ if (!url.isEmpty()) {
+ pqImplementation::helpWindow->showPage(url);
+ }
+ return;
+ }
+
+ // * Discover help project files from the resources.
+ QString aPVHome(getenv("PVHOME"));
+ if (aPVHome.isNull()) {
+ qWarning("Wariable PVHOME is not defined");
+ return;
+ }
+ QChar aSep = QDir::separator();
+ QString aFile = aPVHome + aSep + "doc" + aSep + "paraview.qch";
+
+ if (!QFile::exists(aFile)) {
+ qWarning("Help file do not found");
+ return;
+ }
+
+ pqImplementation::helpWindow = new pqHelpWindow(QString("ParaView Online Help"), getApp()->desktop());
+ QString namespace_name = pqImplementation::helpWindow->registerDocumentation(aFile);
+
+ pqImplementation::helpWindow->showHomePage(namespace_name);
+ pqImplementation::helpWindow->show();
+ pqImplementation::helpWindow->raise();
+ if (!url.isEmpty()) {
+ pqImplementation::helpWindow->showPage(url);
+ }
+}
+
+
+
/*!
- \brief Create actions for ParaView GUI operations
- duplicating menus and toolbars in pqMainWindow ParaView class
+ \brief Slot to show the waiting state.
*/
-void PVGUI_Module::pvCreateActions()
+void PVGUI_Module::onPreAccept()
{
- // TODO...
+ getApp()->desktop()->statusBar()->showMessage(tr("STB_PREACCEPT"));
+ QApplication::setOverrideCursor(QCursor(Qt::WaitCursor));
}
/*!
- \brief Returns the active ParaView server connection.
+ \brief Slot to show the ready state.
*/
-pqServer* PVGUI_Module::getActiveServer() const
+void PVGUI_Module::onPostAccept()
{
- return myActiveServer->current();
+ getApp()->desktop()->statusBar()->showMessage(tr("STB_POSTACCEPT"), 2000);
+ QTimer::singleShot(0, this, SLOT(endWaitCursor()));
}
/*!
- \brief Returns the ParaView multi-view manager.
+ \brief Slot to switch off wait cursor.
*/
-pqViewManager* PVGUI_Module::getMultiViewManager() const
+void PVGUI_Module::endWaitCursor()
{
- pqViewManager* aMVM = 0;
- LightApp_Application* anApp = getApp();
- PVGUI_ViewManager* aPVMgr = dynamic_cast<PVGUI_ViewManager*>( anApp->activeViewManager() );
- if ( aPVMgr )
- aMVM = aPVMgr->getMultiViewManager();
- return aMVM;
+ QApplication::restoreOverrideCursor();
}
/*!
- \brief Creates a built-in server connection.
+ \brief Returns the ParaView multi-view manager.
*/
-void PVGUI_Module::makeDefaultConnectionIfNoneExists()
+pqViewManager* PVGUI_Module::getMultiViewManager() const
{
- if (this->getActiveServer())
- {
- return ;
- }
+ return qobject_cast<pqViewManager*>(pqApplicationCore::instance()->manager("MULTIVIEW_MANAGER"));
+}
- pqApplicationCore* core = pqApplicationCore::instance();
- if (core->getServerManagerModel()->getNumberOfItems<pqServer*>() != 0)
+
+static void ParavisMessageOutput(QtMsgType type, const char *msg)
+{
+ switch(type)
{
- // cannot really happen, however, if no active server, yet
- // server connection exists, we don't try to make a new server connection.
- return ;
+ case QtDebugMsg:
+ vtkOutputWindow::GetInstance()->DisplayText(msg);
+ break;
+ case QtWarningMsg:
+ vtkOutputWindow::GetInstance()->DisplayErrorText(msg);
+ break;
+ case QtCriticalMsg:
+ vtkOutputWindow::GetInstance()->DisplayErrorText(msg);
+ break;
+ case QtFatalMsg:
+ vtkOutputWindow::GetInstance()->DisplayErrorText(msg);
+ break;
}
-
- pqServerResource resource = pqServerResource("builtin:");
- core->getObjectBuilder()->createServer(resource);
}
+
/*!
\brief Activate module.
\param study current study
*/
bool PVGUI_Module::activateModule( SUIT_Study* study )
{
- bool isDone = LightApp_Module::activateModule( study );
- if ( !isDone ) return false;
+ myOldMsgHandler = qInstallMsgHandler(ParavisMessageOutput);
- setMenuShown( true );
+ bool isDone = SalomeApp_Module::activateModule( study );
+ if ( !isDone ) return false;
showView( true );
-
- // Make default server connection
- // see pqMainWindowCore::makeDefaultConnectionIfNoneExists()
- if ( !myActiveServer && getMultiViewManager() ) {
- myActiveServer = new pqActiveServer( this );
- QObject::connect ( myActiveServer, SIGNAL(changed(pqServer*)),
- getMultiViewManager(), SLOT(setActiveServer(pqServer*)) );
+ if ( mySourcesMenuId != -1 ) menuMgr()->show(mySourcesMenuId);
+ if ( myFiltersMenuId != -1 ) menuMgr()->show(myFiltersMenuId);
+ if ( myFiltersMenuId != -1 ) menuMgr()->show(myMacrosMenuId);
+ if ( myFiltersMenuId != -1 ) menuMgr()->show(myToolbarsMenuId);
+ setMenuShown( true );
+ setToolShown( true );
+
+ if (myToolbarState.size() > 0) {
+ SUIT_Desktop* desk = application()->desktop();
+ QList<QToolBar*> aToolbars = myToolbarState.keys();
+ foreach(QToolBar* aBar, aToolbars) {
+ aBar->setParent(desk);
+ aBar->setVisible(myToolbarState[aBar]);
+ }
}
- makeDefaultConnectionIfNoneExists();
+ restoreDockWidgetsState();
return isDone;
}
*/
bool PVGUI_Module::deactivateModule( SUIT_Study* study )
{
+ if (pqImplementation::helpWindow) {
+ pqImplementation::helpWindow->hide();
+ }
+ showView( false );
+
// hide menus
+ menuMgr()->hide(mySourcesMenuId);
+ menuMgr()->hide(myFiltersMenuId);
+ menuMgr()->hide(myMacrosMenuId);
+ menuMgr()->hide(myToolbarsMenuId);
setMenuShown( false );
+ setToolShown( false );
+
+ saveDockWidgetsState();
+
+ // hide toolbars
+ QList<QToolBar*> aToolbars = myToolbarState.keys();
+ foreach(QToolBar* aBar, aToolbars) {
+ myToolbarState[aBar] = aBar->isVisible();
+ aBar->hide();
+ aBar->setParent(0);
+ }
+
+ if (myOldMsgHandler)
+ qInstallMsgHandler(myOldMsgHandler);
+ return SalomeApp_Module::deactivateModule( study );
+}
+
+
+/*!
+ \brief Called when application is closed.
+
+ Process finalize application functionality from ParaView in order to save server settings
+ and nullify application pointer if the application is being closed.
+
+ \param theApp application
+*/
+void PVGUI_Module::onApplicationClosed( SUIT_Application* theApp )
+{
+ pqApplicationCore::instance()->settings()->sync();
+ int aAppsNb = SUIT_Session::session()->applications().size();
+ if (aAppsNb == 1) {
+ deleteTemporaryFiles();
+ //pvShutdown();
+ }
+ CAM_Module::onApplicationClosed(theApp);
+}
+
+/*!
+ \brief Compares the contents of the window with the given reference image,
+ returns true if they "match" within some tolerance.
+*/
+/*VSV it seems that this method is obsolete
+bool PVGUI_Module::compareView( const QString& ReferenceImage, double Threshold,
+ std::ostream& Output, const QString& TempDirectory )
+{
+ if ( Implementation )
+ return Implementation->Core.compareView( ReferenceImage, Threshold, Output, TempDirectory );
+ return false;
+}
+*/
+QString PVGUI_Module::engineIOR() const
+{
+ CORBA::String_var anIOR = PARAVIS::GetParavisGen(this)->GetIOR();
+ return QString(anIOR.in());
+}
+
+
+/*!
+ \brief Open file of format supported by ParaView
+*/
+void PVGUI_Module::openFile(const char* theName)
+{
+ QStringList aFiles;
+ aFiles<<theName;
+ pqLoadDataReaction::loadData(aFiles);
+}
+
+/*!
+ \brief Returns trace string
+*/
+QString PVGUI_Module::getTraceString()
+{
+ pqPythonDialog* pyDiag = 0;
+ pqPythonManager* manager = qobject_cast<pqPythonManager*>(
+ pqApplicationCore::instance()->manager("PYTHON_MANAGER"));
+ if (manager) {
+ pyDiag = manager->pythonShellDialog();
+ }
+
+ QString traceString;
+ if (pyDiag) {
+ pyDiag->runString("try:\n"
+ " from paraview import smtrace\n"
+ " __smtraceString = smtrace.get_trace_string()\n"
+ "except:\n"
+ " __smtraceString = str()\n"
+ " raise RuntimeError('could not import paraview.smtrace')\n");
+ pyDiag->shell()->makeCurrent();
+ PyObject* main_module = PyImport_AddModule((char*)"__main__");
+ PyObject* global_dict = PyModule_GetDict(main_module);
+ PyObject* string_object = PyDict_GetItemString(global_dict, "__smtraceString");
+ char* string_ptr = PyString_AsString(string_object);
+ if (string_ptr) {
+ traceString = string_ptr;
+ }
+ pyDiag->shell()->releaseControl();
+ }
+ return traceString;
+}
- return LightApp_Module::deactivateModule( study );
+/*!
+ \brief Saves trace string to disk file
+*/
+void PVGUI_Module::saveTrace(const char* theName)
+{
+ //save_trace(theName);
+ QFile file(theName);
+ if (!file.open(QIODevice::WriteOnly | QIODevice::Text)) {
+ MESSAGE( "Could not open file:" << theName );
+ return;
+ }
+ QTextStream out(&file);
+ out << getTraceString();
+ file.close();
+}
+
+/*!
+ \brief Saves ParaView state to a disk file
+*/
+void PVGUI_Module::saveParaviewState(const char* theFileName)
+{
+ Implementation->Core->saveState(theFileName);
+}
+
+/*!
+ \brief Restores ParaView state from a disk file
+*/
+void PVGUI_Module::loadParaviewState(const char* theFileName)
+{
+ Implementation->Core->loadState(theFileName, getActiveServer());
}
+/*!
+ \brief Imports MED data from VISU module by data entry
+*/
+void PVGUI_Module::onImportFromVisu(QString theEntry)
+{
+#ifdef WITH_VISU
+ SUIT_OverrideCursor aWaitCursor;
+
+ // get active study
+ SalomeApp_Study* activeStudy = dynamic_cast<SalomeApp_Study*>(application()->activeStudy());
+ if(!activeStudy) return;
+
+ // get SALOMEDS client study
+ _PTR(Study) aStudy = activeStudy->studyDS();
+ if(!aStudy) return;
+
+ // find VISU component in a study
+ _PTR(SComponent) aVisuComp = aStudy->FindComponent( "VISU" );
+ if(!aVisuComp) return;
+
+ // get SObject client by entry
+ _PTR(SObject) aSObj = aStudy->FindObjectID(qPrintable(theEntry));
+ if (!aSObj) return;
+
+ // get CORBA SObject
+ SALOMEDS_SObject* aSObject = _CAST(SObject, aSObj);
+ if ( !aSObject ) return;
+
+ // load VISU engine
+ SALOME_NamingService* aNamingService = SalomeApp_Application::namingService();
+ SALOME_LifeCycleCORBA aLCC(aNamingService);
+
+ Engines::Component_var aComponent = aLCC.FindOrLoad_Component("FactoryServer","VISU");
+ VISU::VISU_Gen_var aVISU = VISU::VISU_Gen::_narrow(aComponent);
+ if(CORBA::is_nil(aVISU)) return;
+
+ _PTR(StudyBuilder) aStudyBuilder = aStudy->NewBuilder();
+ aStudyBuilder->LoadWith( aVisuComp, SalomeApp_Application::orb()->object_to_string(aVISU) );
+
+ // set current study to VISU engine
+ //aVISU->SetCurrentStudy(aStudyVar);
+
+ // get VISU result object
+ CORBA::Object_var aResultObject = aSObject->GetObject();
+ if (CORBA::is_nil(aResultObject)) return;
+ VISU::Result_var aResult = VISU::Result::_narrow( aResultObject );
+ if (CORBA::is_nil(aResult)) return;
+
+ // export VISU result to the MED file
+ std::string aTmpDir = SALOMEDS_Tool::GetTmpDir();
+ std::string aFileName = aSObject->GetName();
+ std::string aFilePath = aTmpDir + aFileName;
+
+ if (aResult->ExportMED(aFilePath.c_str())) {
+ openFile(aFilePath.c_str());
+ myTemporaryFiles.append(QString(aFilePath.c_str()));
+ }
+#else
+ MESSAGE("Visu module is not found.");
+#endif
+}
+
+/*!
+ \brief Deletes temporary files created during import operation from VISU
+*/
+void PVGUI_Module::deleteTemporaryFiles()
+{
+ foreach(QString aFile, myTemporaryFiles) {
+ if (QFile::exists(aFile)) {
+ QFile::remove(aFile);
+ }
+ }
+}
+
+
+/*!
+ \brief Returns current active ParaView server
+*/
+pqServer* PVGUI_Module::getActiveServer()
+{
+ return Implementation->Core->getActiveServer();
+}
+
+
+/*!
+ \brief Creates PARAVIS preference pane
+*/
+void PVGUI_Module::createPreferences()
+{
+ int TraceTab = addPreference( tr( "TIT_TRACE" ) );
+ addPreference( tr( "PREF_STOP_TRACE" ), TraceTab, LightApp_Preferences::Bool, "PARAVIS", "stop_trace");
+
+ int aSaveType = addPreference(tr( "PREF_SAVE_TYPE_LBL" ), TraceTab,
+ LightApp_Preferences::Selector,
+ "PARAVIS", "savestate_type");
+ QList<QVariant> aIndices;
+ QStringList aStrings;
+ aIndices<<0<<1<<2;
+ aStrings<<tr("PREF_SAVE_TYPE_0");
+ aStrings<<tr("PREF_SAVE_TYPE_1");
+ aStrings<<tr("PREF_SAVE_TYPE_2");
+ setPreferenceProperty(aSaveType, "strings", aStrings);
+ setPreferenceProperty(aSaveType, "indexes", aIndices);
+}
+
+
+
/*!
\fn CAM_Module* createModule();
\brief Export module instance (factory function).