// PARAVIS : ParaView wrapper SALOME module
//
-// Copyright (C) 2010-2015 CEA/DEN, EDF R&D
+// Copyright (C) 2010-2019 CEA/DEN, EDF R&D
//
// This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU Lesser General Public
#include "PVGUI_Module.h"
#include "PVViewer_ViewManager.h"
+#include "PVViewer_Core.h"
#include "PVViewer_ViewWindow.h"
#include "PVViewer_ViewModel.h"
#include "PVGUI_ParaViewSettingsPane.h"
#include "PVViewer_GUIElements.h"
-#include "PVViewer_EngineWrapper.h"
+#include "PVServer_ServiceWrapper.h"
#include "PVGUI_DataModel.h"
// SALOME Includes
#include <vtkProcessModule.h>
#include <vtkPVSession.h>
#include <vtkPVProgressHandler.h>
-#include <vtkOutputWindow.h>
#include <vtkEventQtSlotConnect.h>
#include <vtkNew.h>
#include <vtkSMProxy.h>
#include <pqActiveObjects.h>
#include <pqHelpReaction.h>
#include <pqPluginManager.h>
-#include <pqPythonDialog.h>
+//#include <pqPythonDialog.h>
#include <pqPythonManager.h>
#include <pqLoadDataReaction.h>
#include <pqPythonScriptEditor.h>
#include <pqAnimationScene.h>
#include <pqServerManagerModel.h>
#include <pqAnimationTimeToolbar.h>
+#include <pqPipelineBrowserWidget.h>
+#include <pqCoreUtilities.h>
+
+#if PY_VERSION_HEX < 0x03050000
+static char*
+Py_EncodeLocale(const wchar_t *arg, size_t *size)
+{
+ return _Py_wchar2char(arg, size);
+}
+static wchar_t*
+Py_DecodeLocale(const char *arg, size_t *size)
+{
+ return _Py_char2wchar(arg, size);
+}
+#endif
//----------------------------------------------------------------------------
PVGUI_Module* ParavisModule = 0;
myFiltersMenuId( -1 ),
myMacrosMenuId(-1),
myRecentMenuId(-1),
+ myCatalystMenuId(-1),
myOldMsgHandler(0),
myTraceWindow(0),
myInitTimer(0),
Q_INIT_RESOURCE( PVGUI );
#endif
ParavisModule = this;
-
- // Clear old copies of embedded macros files
- QString aDestPath = QString( "%1/.config/%2/Macros" ).arg( QDir::homePath() ).arg( QApplication::applicationName() );
- QStringList aFilter;
- aFilter << "*.py";
-
- QDir aDestDir(aDestPath);
- QStringList aDestFiles = aDestDir.entryList(aFilter, QDir::Files);
- foreach (QString aMacrosPath, getEmbeddedMacrosList()) {
- QString aMacrosName = QFileInfo(aMacrosPath).fileName();
- if (aDestFiles.contains(aMacrosName)) {
- aDestDir.remove(aMacrosName);
- }
- }
}
/*!
by the PVViewer code in GUI (class PVViewer_EngineWrapper).
\sa GetCPPEngine()
*/
-PVViewer_EngineWrapper* PVGUI_Module::GetEngine()
+PVServer_ServiceWrapper* PVGUI_Module::GetEngine()
{
- return PVViewer_EngineWrapper::GetInstance();
+ return PVServer_ServiceWrapper::GetInstance();
}
/*!
*/
pqPVApplicationCore* PVGUI_Module::GetPVApplication()
{
- return PVViewer_ViewManager::GetPVApplication();
+ return PVViewer_Core::GetPVApplication();
}
/*!
// Initialize ParaView client and associated behaviors
// and connect to externally launched pvserver
- PVViewer_ViewManager::ParaviewInitApp(aDesktop, anApp->logWindow());
+ PVViewer_Core::ParaviewInitApp(aDesktop);
+
+ // Clear old copies of embedded macros files
+ //QString aDestPath = QString( "%1/.config/%2/Macros" ).arg( QDir::homePath() ).arg( QApplication::applicationName() );
+ QString aDestPath = pqCoreUtilities::getParaViewUserDirectory() + "/Macros";
+ QStringList aFilter;
+ aFilter << "*.py";
+
+ QDir aDestDir(aDestPath);
+ QStringList aDestFiles = aDestDir.entryList(aFilter, QDir::Files);
+ foreach(QString aMacrosPath, getEmbeddedMacrosList()) {
+ QString aMacrosName = QFileInfo(aMacrosPath).fileName();
+ if (aDestFiles.contains(aMacrosName)) {
+ aDestDir.remove(aMacrosName);
+ }
+ }
+
myGuiElements = PVViewer_GUIElements::GetInstance(aDesktop);
+
// [ABN]: careful with the order of the GUI element creation, the loading of the configuration
// and the connection to the server. This order is very sensitive if one wants to make
// sure all menus, etc ... are correctly populated.
pvCreateMenus();
pvCreateToolBars();
- PVViewer_ViewManager::ParaviewInitBehaviors(true, aDesktop);
+ PVViewer_Core::ParaviewInitBehaviors(true, aDesktop);
QList<QDockWidget*> activeDocks = aDesktop->findChildren<QDockWidget*>();
QList<QMenu*> activeMenus = aDesktop->findChildren<QMenu*>();
// Connect after toolbar creation, etc ... as some activations of the toolbars is triggered
// by the ServerConnection event:
- PVViewer_ViewManager::ParaviewLoadConfigurations(true);
+ const QString configPath(PVViewer_ViewManager::GetPVConfigPath());
+ PVViewer_Core::ParaviewLoadConfigurations(configPath, true);
PVViewer_ViewManager::ConnectToExternalPVServer(aDesktop);
updateObjBrowser();
}
}
}
+ connect( application(), SIGNAL( appClosed() ), this, SLOT( onStopTrace() ) );
}
/*!
PVViewer_ViewManager* viewMgr =
dynamic_cast<PVViewer_ViewManager*>( anApp->getViewManager( PVViewer_Viewer::Type(), false ) );
if ( !viewMgr ) {
- viewMgr = new PVViewer_ViewManager( anApp->activeStudy(), anApp->desktop(), anApp->logWindow() );
+ viewMgr = new PVViewer_ViewManager( anApp->activeStudy(), anApp->desktop() );
anApp->addViewManager( viewMgr );
connect( viewMgr, SIGNAL( lastViewClosed( SUIT_ViewManager* ) ),
anApp, SLOT( onCloseView( SUIT_ViewManager* ) ) );
// this also connects to the pvserver and instantiates relevant PV behaviors
}
- pvWnd->setShown( toShow );
+ pvWnd->setVisible( toShow );
if ( toShow ) pvWnd->setFocus();
}
QApplication::restoreOverrideCursor();
}
-/*!
- \brief Handler method for the output of messages.
-*/
-static void ParavisMessageOutput(QtMsgType type, const char *msg)
-{
- switch(type)
- {
- 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;
- }
-}
-
/*!
\brief Activate module.
\param study current study
*/
bool PVGUI_Module::activateModule( SUIT_Study* study )
{
- myOldMsgHandler = qInstallMsgHandler(ParavisMessageOutput);
-
SUIT_ExceptionHandler::addCleanUpRoutine( paravisCleanUp );
storeCommonWindowsState();
if ( mySourcesMenuId != -1 ) menuMgr()->show(mySourcesMenuId);
if ( myFiltersMenuId != -1 ) menuMgr()->show(myFiltersMenuId);
if ( myMacrosMenuId != -1 ) menuMgr()->show(myMacrosMenuId);
+ if ( myCatalystMenuId != -1 ) menuMgr()->show(myCatalystMenuId);
// Update the various menus with the content pre-loaded in myGuiElements
// QMenu* srcMenu = menuMgr()->findMenu( mySourcesMenuId );
}
if ( myRecentMenuId != -1 ) menuMgr()->show(myRecentMenuId);
-
+
+ // VSR 18/10/2018 - 0023170: Workaround to re-select current index after module activation
+ QItemSelectionModel* selection_model = myGuiElements->getPipelineBrowserWidget()->getSelectionModel();
+ QModelIndex idx = selection_model->currentIndex();
+ selection_model->clearCurrentIndex();
+ selection_model->setCurrentIndex(idx, QItemSelectionModel::ClearAndSelect);
+
return isDone;
}
menuMgr()->hide(mySourcesMenuId);
menuMgr()->hide(myFiltersMenuId);
menuMgr()->hide(myMacrosMenuId);
+ menuMgr()->hide(myCatalystMenuId);
setMenuShown( false );
setToolShown( false );
SUIT_ExceptionHandler::removeCleanUpRoutine( paravisCleanUp );
if (myOldMsgHandler)
- qInstallMsgHandler(myOldMsgHandler);
+ qInstallMessageHandler(myOldMsgHandler);
restoreCommonWindowsState();
*/
void PVGUI_Module::onApplicationClosed( SUIT_Application* theApp )
{
- PVViewer_ViewManager::ParaviewCleanup();
+ PVViewer_Core::ParaviewCleanup();
CAM_Module::onApplicationClosed(theApp);
}
*/
void PVGUI_Module::executeScript( const char* script )
{
+ // ???
+ // Not sure this is the right fix, but the PYTHON_MANAGER has a function named
+ // executeScript() which seems to do what the runScript on pyShellDialog() class
+ // was doing.
+#ifndef WNT
+ pqPythonManager* manager =
+ qobject_cast<pqPythonManager*>(pqApplicationCore::instance()->manager("PYTHON_MANAGER"));
+
+ if ( manager ) {
+ manager->executeScript(script);
+ }
+#endif
+ /*
#ifndef WNT
pqPythonManager* manager = qobject_cast<pqPythonManager*>(
pqApplicationCore::instance()->manager( "PYTHON_MANAGER" ) );
}
}
#endif
+ */
}
///**
// PyObject * elem = PyList_GetItem(lst, i);
// if (PyString_Check(elem))
// {
-// std::cout << "At pos:" << i << ", " << PyString_AsString(elem) << std::endl;
+// std::cout << "At pos:" << i << ", " << Py_EncodeLocale(PyUnicode_AS_UNICODE(elem), NULL) << std::endl;
// }
// else
// std::cout << "At pos:" << i << ", not a string!" << std::endl;
}
// Save camera position to, which is no longer output by the tracer ...
- VTK_PY_GIL_ENSURE
- PyObject * mods(PySys_GetObject(const_cast<char*>("modules")));
- PyObject * trace_mod(PyDict_GetItemString(mods, "paraview.smtrace")); // module was already (really) imported by vtkSMTrace
- if (PyModule_Check(trace_mod)) {
- vtkSmartPyObject save_cam(PyObject_GetAttrString(trace_mod, const_cast<char*>("SaveCameras")));
- vtkSmartPyObject camera_trace(PyObject_CallMethod(save_cam, const_cast<char*>("get_trace"), NULL));
- // Convert to a single string
- vtkSmartPyObject ret(PyString_FromString(end_line.toStdString().c_str()));
- vtkSmartPyObject final_string(PyObject_CallMethod(ret, const_cast<char*>("join"),
- const_cast<char*>("O"), (PyObject*)camera_trace));
- if (PyString_CheckExact(final_string))
- {
- QString camera_qs(PyString_AsString(final_string)); // deep copy
- traceString = traceString + end_line + end_line + QString("#### saving camera placements for all active views")
- + end_line + end_line + camera_qs + end_line;
- }
- }
- VTK_PY_GIL_RELEASE
+ {
+ vtkPythonScopeGilEnsurer psge;
+ PyObject * mods(PySys_GetObject(const_cast<char*>("modules")));
+ PyObject * trace_mod(PyDict_GetItemString(mods, "paraview.smtrace")); // module was already (really) imported by vtkSMTrace
+ if (trace_mod && trace_mod != Py_None && PyModule_Check(trace_mod)) {
+ vtkSmartPyObject save_cam(PyObject_GetAttrString(trace_mod, const_cast<char*>("SaveCameras")));
+ vtkSmartPyObject camera_trace(PyObject_CallMethod(save_cam, const_cast<char*>("get_trace"), NULL));
+ // Convert to a single string
+ vtkSmartPyObject ret(PyUnicode_FromUnicode(Py_DecodeLocale(end_line.toStdString().c_str(), NULL), end_line.size()));
+ vtkSmartPyObject final_string(PyObject_CallMethod(ret, const_cast<char*>("join"),
+ const_cast<char*>("O"), (PyObject*)camera_trace));
+ if (PyUnicode_CheckExact(final_string))
+ {
+ QString camera_qs(Py_EncodeLocale(PyUnicode_AS_UNICODE(final_string.GetPointer()), NULL)); // deep copy
+ traceString = traceString + end_line + end_line + QString("#### saving camera placements for all active views")
+ + end_line + end_line + camera_qs + end_line;
+ }
+ }
+ }
return traceString;
}
/*!
\brief Saves ParaView state to a disk file
*/
-void PVGUI_Module::saveParaviewState( const char* theFileName )
+void PVGUI_Module::saveParaviewState( const QString& theFileName )
{
- pqApplicationCore::instance()->saveState( theFileName );
+ pqApplicationCore::instance()->saveState( theFileName.toStdString().c_str() );
}
/*!
/*!
\brief Restores ParaView state from a disk file
*/
-void PVGUI_Module::loadParaviewState( const char* theFileName )
+void PVGUI_Module::loadParaviewState( const QString& theFileName )
{
- pqApplicationCore::instance()->loadState( theFileName, getActiveServer() );
+ pqApplicationCore::instance()->loadState( theFileName.toStdString().c_str(), getActiveServer() );
}
/*!
*/
void PVGUI_Module::createPreferences()
{
+ QList<QVariant> aIndices;
+ QStringList aStrings;
+
// Paraview settings tab
int aParaViewSettingsTab = addPreference( tr( "TIT_PVIEWSETTINGS" ) );
// Paravis settings tab
int aParaVisSettingsTab = addPreference( tr( "TIT_PVISSETTINGS" ) );
- addPreference( tr( "PREF_STOP_TRACE" ), aParaVisSettingsTab,
- LightApp_Preferences::Bool, PARAVIS_MODULE_NAME, "stop_trace" );
addPreference( tr( "PREF_NO_EXT_PVSERVER" ), aParaVisSettingsTab,
LightApp_Preferences::Bool, PARAVIS_MODULE_NAME, "no_ext_pv_server" );
LightApp_Preferences::Selector,
PARAVIS_MODULE_NAME, "savestate_type" );
- int aTraceType = addPreference( tr( "PREF_TRACE_TYPE_LBL" ), aParaVisSettingsTab,
- LightApp_Preferences::Selector,
- PARAVIS_MODULE_NAME, "tracestate_type" );
- QList<QVariant> aIndices;
- QStringList aStrings;
+ aStrings.clear();
+ aIndices.clear();
aIndices << 0 << 1 << 2;
- aStrings << tr("PREF_SAVE_TYPE_0");
- aStrings << tr("PREF_SAVE_TYPE_1");
- aStrings << tr("PREF_SAVE_TYPE_2");
+ aStrings << tr("PREF_SAVE_TYPE_0") << tr("PREF_SAVE_TYPE_1") << tr("PREF_SAVE_TYPE_2");
setPreferenceProperty( aSaveType, "strings", aStrings );
setPreferenceProperty( aSaveType, "indexes", aIndices );
+ // ... "Language" group <<start>>
+ int traceGroup = addPreference( tr( "PREF_GROUP_TRACE" ), aParaVisSettingsTab );
+
+ int stopTrace = addPreference( tr( "PREF_STOP_TRACE" ), traceGroup,
+ LightApp_Preferences::Bool, PARAVIS_MODULE_NAME, "stop_trace" );
+ setPreferenceProperty( stopTrace, "restart", true );
+
+ int aTraceType = addPreference( tr( "PREF_TRACE_TYPE_LBL" ), traceGroup,
+ LightApp_Preferences::Selector,
+ PARAVIS_MODULE_NAME, "tracestate_type" );
aStrings.clear();
- aStrings << tr("PREF_TRACE_TYPE_0");
- aStrings << tr("PREF_TRACE_TYPE_1");
- aStrings << tr("PREF_TRACE_TYPE_2");
+ aIndices.clear();
+ aIndices << 0 << 1 << 2;
+ aStrings << tr("PREF_TRACE_TYPE_0") << tr("PREF_TRACE_TYPE_1") << tr("PREF_TRACE_TYPE_2");
setPreferenceProperty( aTraceType, "strings", aStrings );
setPreferenceProperty( aTraceType, "indexes", aIndices );
+ setPreferenceProperty( aTraceType, "restart", true );
}
/*!
startTrace();
}
+/*!
+ \brief. Close ParaView python trace.
+*/
+void PVGUI_Module::onStopTrace()
+{
+ stopTrace();
+}
/*!
\brief Called when view manager is added
*/