From: abn Date: Tue, 16 Sep 2014 15:24:57 +0000 (+0200) Subject: Further work on view isolation plus various imps. X-Git-Tag: V7_5_0b1~27^2~9 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=6fef21f4e3db722755bb715722605d327a61e75e;p=modules%2Fparavis.git Further work on view isolation plus various imps. DumpPython working again. Better handling of the connection from script part. Still a big crash when trying to replay a script ... to be continued. --- diff --git a/CMakeLists.txt b/CMakeLists.txt index 227d0be0..8ebed900 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -141,7 +141,7 @@ INCLUDE_DIRECTORIES(${GUI_INCLUDE_DIRS}) ## ## From GUI: part 2 ## -FIND_PACKAGE(SalomeCAS REQUIRED) +FIND_PACKAGE(SalomeCAS REQUIRED) # [ABN] I wish I could avoid that ... ## ## From MED diff --git a/idl/no_wrap/PARAVIS_Gen.idl b/idl/no_wrap/PARAVIS_Gen.idl index 11f68e87..e3e5ffb1 100644 --- a/idl/no_wrap/PARAVIS_Gen.idl +++ b/idl/no_wrap/PARAVIS_Gen.idl @@ -66,6 +66,12 @@ module PARAVIS_ORB { */ void PutPythonTraceStringToEngine(in string trace); + /*! Indicates if the GUI process is already connected to the pvserver. + * This avoids multiple attempts to connect from a single thread (makes ParaView crash). */ + void SetGUIConnected(in boolean isConnected); + + boolean GetGUIConnected(); + }; }; diff --git a/src/ENGINE/no_wrap/PARAVIS.py.in b/src/ENGINE/no_wrap/PARAVIS.py.in index 2992b5be..1dbc89ff 100644 --- a/src/ENGINE/no_wrap/PARAVIS.py.in +++ b/src/ENGINE/no_wrap/PARAVIS.py.in @@ -49,6 +49,7 @@ class PARAVIS_Impl: self.pvserverPort = -1 self.pvserverPop = None # Popen object from subprocess module self.lastTrace = "" + self.isGUIConnected = False # whether there is an active connection from the GUI. """ Private. Identify a free port to launch the PVServer. @@ -120,8 +121,14 @@ class PARAVIS_Impl: def PutPythonTraceStringToEngine( self, t ): self.lastTrace = t - def GetPythonTraceString (self): + def GetPythonTraceString(self): return self.lastTrace + + def SetGUIConnected( self, isConnected ): + self.isGUIConnected = isConnected + + def GetGUIConnected( self ): + return self.isGUIConnected class PARAVIS(PARAVIS_ORB__POA.PARAVIS_Gen, SALOME_ComponentPy.SALOME_ComponentPy_i, @@ -166,6 +173,7 @@ class PARAVIS(PARAVIS_ORB__POA.PARAVIS_Gen, Create object. """ def createObject( self, study, name ): + MESSAGE("createObject()") self._createdNew = True # used for getModifiedData method builder = study.NewBuilder() father = findOrCreateComponent( study ) @@ -173,44 +181,27 @@ class PARAVIS(PARAVIS_ORB__POA.PARAVIS_Gen, attr = builder.FindOrCreateAttribute( object, "AttributeName" ) attr.SetValue( name ) attr = builder.FindOrCreateAttribute( object, "AttributeLocalID" ) - attr.SetValue( objectID() ) + attr.SetValue( PARAVIS_utils.objectID() ) pass """ Dump module data to the Python script. """ - def DumpPython( self, study, isPublished ): - print "@@@@ DumpPython" - abuffer = [] - abuffer.append( "def RebuildData( theStudy ):" ) - names = [] - father = study.FindComponent( moduleName() ) - if father: - iter = study.NewChildIterator( father ) - while iter.More(): - name = iter.Value().GetName() - if name: names.append( name ) - iter.Next() - pass - pass - if names: - abuffer += [ " from batchmode_salome import lcc" ] - abuffer += [ " import PARAVIS_ORB" ] - abuffer += [ " " ] - abuffer += [ " pyhello = lcc.FindOrLoadComponent( 'FactoryServerPy', '%s' )" % moduleName() ] - abuffer += [ " " ] - abuffer += [ " pyhello.createObject( theStudy, '%s' )" % name for name in names ] - pass - abuffer += [ " " ] - abuffer.append( " pass" ) - abuffer.append( "\0" ) + def DumpPython( self, study, isPublished, isMultiFile ): + MESSAGE("dumpPython()") + abuffer = self.GetPythonTraceString().split("\n") + if isMultiFile: + abuffer = [ " " + s for s in abuffer ] + abuffer[0:0] = [ "def RebuildData( theStudy ):" ] + abuffer += [ " pass" ] + abuffer += [ "\0" ] return ("\n".join( abuffer ), 1) """ Import file to restore module data """ def importData(self, studyId, dataContainer, options): - print "@@@@ ImportData" + MESSAGE("importData()") # get study by Id obj = self._naming_service.Resolve("myStudyManager") myStudyManager = obj._narrow(SALOMEDS.StudyManager) @@ -224,7 +215,7 @@ class PARAVIS(PARAVIS_ORB__POA.PARAVIS_Gen, return ["objects"] # identifier what is in this file def getModifiedData(self, studyId): - print "@@@@ GetModifiedData" + MESSAGE("getModifiedData()") if self._createdNew: # get study by Id obj = self._naming_service.Resolve("myStudyManager") diff --git a/src/PVGUI/CMakeLists.txt b/src/PVGUI/CMakeLists.txt index 6614e038..091812c5 100644 --- a/src/PVGUI/CMakeLists.txt +++ b/src/PVGUI/CMakeLists.txt @@ -39,8 +39,8 @@ ADD_SUBDIRECTORY(view) # additional preprocessor / compiler flags ADD_DEFINITIONS(${CAS_DEFINITIONS}) -ADD_DEFINITIONS(${KERNEL_DEFINITIONS}) ADD_DEFINITIONS(${OMNIORB_DEFINITIONS}) +ADD_DEFINITIONS(${KERNEL_DEFINITIONS}) # libraries to link to SET(_PARAVIEW_APP_COMPO_LIB @@ -50,15 +50,12 @@ SET(_PARAVIEW_APP_COMPO_LIB SET(_link_LIBRARIES ${OMNIORB_LIBRARIES} ${QT_LIBRARIES} -# ${CAS_KERNEL} ${PYTHON_LIBS} - ${KERNEL_LDFLAGS} ${KERNEL_SalomeDS} ${KERNEL_SALOMELocalTrace} ${KERNEL_SalomeIDLKernel} - ${KERNEL_SalomeNS} ${KERNEL_SalomeLifeCycleCORBA} ${KERNEL_SalomeContainer} ${KERNEL_TOOLSDS} - ${GUI_LDFLAGS} ${GUI_SalomeApp} ${GUI_LightApp} ${GUI_CAM} ${GUI_qtx} ${GUI_suit} ${GUI_Event} ${GUI_PyInterp} + ${KERNEL_LDFLAGS} + ${GUI_LDFLAGS} ${GUI_SalomeApp} ${GUI_LightApp} ${GUI_CAM} ${GUI_qtx} ${GUI_suit} ${GUI_Event} ${GUI_SalomeObject} ${GUI_vtkTools} ${MED_SalomeIDLMED} ${_PARAVIEW_APP_COMPO_LIB} - SalomeIDLPARAVIS PVViewer ) diff --git a/src/PVGUI/PVGUI_Module.cxx b/src/PVGUI/PVGUI_Module.cxx index c7a6f540..fb126fec 100644 --- a/src/PVGUI/PVGUI_Module.cxx +++ b/src/PVGUI/PVGUI_Module.cxx @@ -34,13 +34,11 @@ #include CORBA_SERVER_HEADER(SALOME_ModuleCatalog) #include CORBA_SERVER_HEADER(SALOMEDS) -#include "PVGUI_ViewModel.h" #include "PVGUI_ViewManager.h" #include "PVGUI_ViewWindow.h" +#include "PVGUI_ViewModel.h" #include "PVGUI_Tools.h" #include "PVGUI_ParaViewSettingsPane.h" -#include "PVGUI_OutputWindowAdapter.h" -#include "PVGUI_Behaviors.h" // SALOME Includes #include @@ -106,7 +104,7 @@ #include #include -//#include +#include #include #include #include @@ -127,7 +125,6 @@ #include #include #include -#include //---------------------------------------------------------------------------- PVGUI_Module* ParavisModule = 0; @@ -199,6 +196,46 @@ PVGUI_Module* ParavisModule = 0; SALOME module wrapping ParaView GUI. */ +_PTR(SComponent) +ClientFindOrCreateParavisComponent(_PTR(Study) theStudyDocument) +{ + _PTR(SComponent) aSComponent = theStudyDocument->FindComponent("PARAVIS"); + if (!aSComponent) { + _PTR(StudyBuilder) aStudyBuilder = theStudyDocument->NewBuilder(); + aStudyBuilder->NewCommand(); + int aLocked = theStudyDocument->GetProperties()->IsLocked(); + if (aLocked) theStudyDocument->GetProperties()->SetLocked(false); + aSComponent = aStudyBuilder->NewComponent("PARAVIS"); + _PTR(GenericAttribute) anAttr = + aStudyBuilder->FindOrCreateAttribute(aSComponent, "AttributeName"); + _PTR(AttributeName) aName (anAttr); + + ORB_INIT& init = *SINGLETON_::Instance(); + CORBA::ORB_var anORB = init( qApp->argc(), qApp->argv() ); + + SALOME_NamingService *NamingService = new SALOME_NamingService( anORB ); + CORBA::Object_var objVarN = NamingService->Resolve("/Kernel/ModulCatalog"); + SALOME_ModuleCatalog::ModuleCatalog_var Catalogue = + SALOME_ModuleCatalog::ModuleCatalog::_narrow(objVarN); + SALOME_ModuleCatalog::Acomponent_var Comp = Catalogue->GetComponent( "PARAVIS" ); + if (!Comp->_is_nil()) { + aName->SetValue(Comp->componentusername()); + } + + anAttr = aStudyBuilder->FindOrCreateAttribute(aSComponent, "AttributePixMap"); + _PTR(AttributePixMap) aPixmap (anAttr); + aPixmap->SetPixMap( "pqAppIcon16.png" ); + + // Create Attribute parameters for future using + anAttr = aStudyBuilder->FindOrCreateAttribute(aSComponent, "AttributeParameter"); + + aStudyBuilder->DefineComponentInstance(aSComponent, PVGUI_Module::GetEngine()->GetIOR()); + if (aLocked) theStudyDocument->GetProperties()->SetLocked(true); + aStudyBuilder->CommitCommand(); + } + return aSComponent; +} + /*! Clean up function; used to stop ParaView progress events when exception is caught by global exception handler. @@ -257,18 +294,16 @@ PVGUI_Module::~PVGUI_Module() delete myPushTraceTimer; if (myInitTimer) delete myInitTimer; - // Disconnect from server - pqServer* server = pqActiveObjects::instance().activeServer(); - if (server && server->isRemote()) - { - MESSAGE("~PVGUI_Module(): Disconnecting from remote server ..."); - pqServerDisconnectReaction::disconnectFromServer(); - } } PARAVIS_ORB::PARAVIS_Gen_var PVGUI_Module::GetEngine() { - return PVGUI_ViewerModel::GetEngine(); + return PVGUI_ViewManager::GetEngine(); +} + +pqPVApplicationCore * PVGUI_Module::GetPVApplication() +{ + return PVGUI_ViewManager::GetPVApplication(); } /*! @@ -292,19 +327,23 @@ void PVGUI_Module::initialize( CAM_Application* app ) aa = aa; } */ - - // Initialize ParaView client - pvInit(); - // Create GUI elements (menus, toolbars, dock widgets) SalomeApp_Application* anApp = getApp(); SUIT_Desktop* aDesktop = anApp->desktop(); + // Initialize ParaView client and associated behaviors + // and connect to externally launched pvserver + PVGUI_ViewManager::ParaviewInitApp(aDesktop); + // Remember current state of desktop toolbars QList foreignToolbars = aDesktop->findChildren(); setupDockWidgets(); + // Behaviors and connection must be instanciated *after* widgets are in place: + PVGUI_ViewManager::ParaviewInitBehaviors(true, aDesktop); + PVGUI_ViewManager::ConnectToExternalPVServer(aDesktop); + pvCreateActions(); pvCreateToolBars(); pvCreateMenus(); @@ -312,9 +351,6 @@ void PVGUI_Module::initialize( CAM_Application* app ) QList activeDocks = aDesktop->findChildren(); QList activeMenus = aDesktop->findChildren(); - PVGUI_Behaviors * behav = new PVGUI_Behaviors(this); - behav->instanciateAllBehaviors(aDesktop); - // Setup quick-launch shortcuts. QShortcut *ctrlSpace = new QShortcut(Qt::CTRL + Qt::Key_Space, aDesktop); QObject::connect(ctrlSpace, SIGNAL(activated()), @@ -345,14 +381,13 @@ void PVGUI_Module::initialize( CAM_Application* app ) SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr(); QString aPath = resMgr->stringValue("resources", "PARAVIS", QString()); if (!aPath.isNull()) { - MyCoreApp->loadConfiguration(aPath + QDir::separator() + "ParaViewFilters.xml"); - MyCoreApp->loadConfiguration(aPath + QDir::separator() + "ParaViewReaders.xml"); - MyCoreApp->loadConfiguration(aPath + QDir::separator() + "ParaViewSources.xml"); - MyCoreApp->loadConfiguration(aPath + QDir::separator() + "ParaViewWriters.xml"); + pqPVApplicationCore * pvApp = GetPVApplication(); + pvApp->loadConfiguration(aPath + QDir::separator() + "ParaViewFilters.xml"); + pvApp->loadConfiguration(aPath + QDir::separator() + "ParaViewReaders.xml"); + pvApp->loadConfiguration(aPath + QDir::separator() + "ParaViewSources.xml"); + pvApp->loadConfiguration(aPath + QDir::separator() + "ParaViewWriters.xml"); } - // Force creation of the PARAVIS engine - GetEngine(); updateObjBrowser(); // Find created toolbars @@ -430,7 +465,7 @@ void PVGUI_Module::onDataRepresentationUpdated() { void PVGUI_Module::onInitTimer() { #ifndef PARAVIS_WITH_FULL_CORBA - connectToExternalPVServer(); +// connectToExternalPVServer(); #endif startTrace(); } @@ -486,7 +521,6 @@ void PVGUI_Module::windows( QMap& m ) const */ void PVGUI_Module::showView( bool toShow ) { - PVGUI_ViewManager SalomeApp_Application* anApp = getApp(); PVGUI_ViewManager* viewMgr = dynamic_cast( anApp->getViewManager( PVGUI_Viewer::Type(), false ) ); @@ -606,7 +640,7 @@ bool PVGUI_Module::activateModule( SUIT_Study* study ) if ( myRecentMenuId != -1 ) menuMgr()->show(myRecentMenuId); -// ClientFindOrCreateParavisComponent(PARAVIS::GetCStudy(this)); + ClientFindOrCreateParavisComponent(PARAVIS::GetCStudy(this)); return isDone; } @@ -681,11 +715,11 @@ bool PVGUI_Module::deactivateModule( SUIT_Study* study ) */ void PVGUI_Module::onApplicationClosed( SUIT_Application* theApp ) { - pqApplicationCore::instance()->settings()->sync(); + PVGUI_ViewManager::ParaviewCleanup(); + int aAppsNb = SUIT_Session::session()->applications().size(); if (aAppsNb == 1) { deleteTemporaryFiles(); - MyCoreApp->deleteLater(); } CAM_Module::onApplicationClosed(theApp); } diff --git a/src/PVGUI/PVGUI_Module.h b/src/PVGUI/PVGUI_Module.h index a94831e5..c9787b31 100644 --- a/src/PVGUI/PVGUI_Module.h +++ b/src/PVGUI/PVGUI_Module.h @@ -165,7 +165,8 @@ public: virtual void contextMenuPopup(const QString& theClient, QMenu* theMenu, QString& theTitle); - inline static PARAVIS_ORB::PARAVIS_Gen_var GetEngine() { return PVGUI_ViewerModel::GetEngine(); } + inline static PARAVIS_ORB::PARAVIS_Gen_var GetEngine(); + inline static pqPVApplicationCore * GetPVApplication(); public slots: //void onImportFromVisu(QString theEntry); diff --git a/src/PVGUI/PVGUI_Module_widgets.cxx b/src/PVGUI/PVGUI_Module_widgets.cxx index 6e8b543d..31792aba 100644 --- a/src/PVGUI/PVGUI_Module_widgets.cxx +++ b/src/PVGUI/PVGUI_Module_widgets.cxx @@ -65,31 +65,31 @@ #include #include -class ResizeHelper : public pqPVAnimationWidget -{ - // TEMPORARILY WORKAROUND AROUND PARAVIEW 3.14 BUG: - // WHEN ANIMATION VIEW IS RESIZED, ITS CONTENTS IS NOT PREPERLY RE-ARRANGED - // CAUSING SOME CONTROLS TO STAY NON-VISIBLE - // THIS BUG IS NATURALLY FIXED BY ADDING - // this->updateGeometries(); - // TO THE - // void pqAnimationWidget::resizeEvent(QResizeEvent* e); - // BUT THIS CANNOT BE DONE DIRECTLY, SINCE CORRESPONDING API IS NOT PUBLIC - // THE ONLY WAY TO DO THIS BY SENDING SHOW EVENT TO THE WIDGET - -public: - ResizeHelper( QWidget* parent ) : pqPVAnimationWidget( parent ) {} -protected: - void resizeEvent(QResizeEvent* e) - { - pqAnimationWidget* w = findChild( "pqAnimationWidget" ); - if ( w ) { - QShowEvent e; - QApplication::sendEvent( w, &e ); - } - pqPVAnimationWidget::resizeEvent( e ); - } -}; +//class ResizeHelper : public pqPVAnimationWidget +//{ +// // TEMPORARILY WORKAROUND AROUND PARAVIEW 3.14 BUG: +// // WHEN ANIMATION VIEW IS RESIZED, ITS CONTENTS IS NOT PREPERLY RE-ARRANGED +// // CAUSING SOME CONTROLS TO STAY NON-VISIBLE +// // THIS BUG IS NATURALLY FIXED BY ADDING +// // this->updateGeometries(); +// // TO THE +// // void pqAnimationWidget::resizeEvent(QResizeEvent* e); +// // BUT THIS CANNOT BE DONE DIRECTLY, SINCE CORRESPONDING API IS NOT PUBLIC +// // THE ONLY WAY TO DO THIS BY SENDING SHOW EVENT TO THE WIDGET +// +//public: +// ResizeHelper( QWidget* parent ) : pqPVAnimationWidget( parent ) {} +//protected: +// void resizeEvent(QResizeEvent* e) +// { +// pqAnimationWidget* w = findChild( "pqAnimationWidget" ); +// if ( w ) { +// QShowEvent e; +// QApplication::sendEvent( w, &e ); +// } +// pqPVAnimationWidget::resizeEvent( e ); +// } +//}; /*! \brief Create dock widgets for ParaView widgets such as object inspector, pipeline browser, etc. @@ -173,7 +173,7 @@ void PVGUI_Module::setupDockWidgets() QDockWidget* animationViewDock = new QDockWidget( tr( "TTL_ANIMATION_VIEW" ), desk ); animationViewDock->setObjectName("animationViewDock"); desk->addDockWidget( Qt::BottomDockWidgetArea, animationViewDock ); - pqPVAnimationWidget* animation_panel = new ResizeHelper(animationViewDock); //pqPVAnimationWidget + pqPVAnimationWidget* animation_panel = new pqPVAnimationWidget(animationViewDock); // [ABN] was resizeHelper animationViewDock->setWidget(animation_panel); myDockWidgets[animationViewDock] = false; // hidden by default diff --git a/src/PVGUI/view/CMakeLists.txt b/src/PVGUI/view/CMakeLists.txt index 7f44bf67..231579c5 100644 --- a/src/PVGUI/view/CMakeLists.txt +++ b/src/PVGUI/view/CMakeLists.txt @@ -30,9 +30,14 @@ SET(_PARAVIEW_APP_COMPO_LIB pqApplicationComponents ) +ADD_DEFINITIONS(${KERNEL_DEFINITIONS}) +ADD_DEFINITIONS(${OMNIORB_DEFINITIONS}) + SET(_link_LIBRARIES - ${KERNEL_LDFLAGS} ${KERNEL_SALOMELocalTrace} - ${GUI_LDFLAGS} ${GUI_LightApp} ${GUI_suit} ${GUI_Event} ${_PARAVIEW_APP_COMPO_LIB} + ${KERNEL_LDFLAGS} ${KERNEL_SALOMELocalTrace} ${KERNEL_SalomeLifeCycleCORBA} + ${GUI_LDFLAGS} ${GUI_SalomeApp} ${GUI_LightApp} ${GUI_suit} ${GUI_Event} + ${_PARAVIEW_APP_COMPO_LIB} + SalomeIDLPARAVIS ) # --- headers --- @@ -47,7 +52,7 @@ SET(_moc_HEADERS # header files / no moc processing SET(_other_HEADERS - PVGUI_OutputWindowAdapter.h + PVGUI_LogWindowAdapter.h ) # header files / to install SET(PVViewer_HEADERS ${_moc_HEADERS} ${_other_HEADERS}) @@ -62,7 +67,7 @@ SET(_other_SOURCES PVGUI_ViewManager.cxx PVGUI_ViewModel.cxx PVGUI_ViewWindow.cxx - PVGUI_OutputWindowAdapter.cxx + PVGUI_LogWindowAdapter.cxx PVGUI_Behaviors.cxx ) diff --git a/src/PVGUI/view/PVGUI_Behaviors.cxx b/src/PVGUI/view/PVGUI_Behaviors.cxx index f03a5118..2a1a2a38 100644 --- a/src/PVGUI/view/PVGUI_Behaviors.cxx +++ b/src/PVGUI/view/PVGUI_Behaviors.cxx @@ -52,7 +52,7 @@ bool PVGUI_Behaviors::hasMinimalInstanciated = false; -PVGUI_Behaviors::PVGUI_Behaviors(SalomeApp_Module * parent) +PVGUI_Behaviors::PVGUI_Behaviors(SUIT_Desktop * parent) : QObject(static_cast(parent)) { } diff --git a/src/PVGUI/view/PVGUI_Behaviors.h b/src/PVGUI/view/PVGUI_Behaviors.h index b6617626..63639056 100644 --- a/src/PVGUI/view/PVGUI_Behaviors.h +++ b/src/PVGUI/view/PVGUI_Behaviors.h @@ -37,7 +37,7 @@ class PVGUI_Behaviors: public QObject Q_OBJECT public: - PVGUI_Behaviors(SalomeApp_Module * parent); + PVGUI_Behaviors(SUIT_Desktop * parent); void instanciateMinimalBehaviors(SUIT_Desktop * desk); diff --git a/src/PVGUI/view/PVGUI_LogWindowAdapter.cxx b/src/PVGUI/view/PVGUI_LogWindowAdapter.cxx new file mode 100644 index 00000000..6469f0f5 --- /dev/null +++ b/src/PVGUI/view/PVGUI_LogWindowAdapter.cxx @@ -0,0 +1,119 @@ +// Copyright (C) 2010-2014 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 +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// + +#include "PVGUI_LogWindowAdapter.h" + +#include + +#include +#include +#include +#include + +vtkStandardNewMacro(PVGUI_LogWindowAdapter); + + + +/*! + * Put the message in the log window. + */ +class TEvent: public SALOME_Event { + LogWindow* myWindow; + QString myMsg; + QColor myColor; + int myFlags; + public: + TEvent( LogWindow* theWindow, const QString theMsg, const QColor theColor, const int flags) : + myWindow ( theWindow ), + myMsg ( theMsg ), + myColor ( theColor ), + myFlags (flags) + {} + + virtual void Execute() { + if(myWindow) + myWindow->putMessage(myMsg, myColor, myFlags); + } +}; + + +PVGUI_LogWindowAdapter::PVGUI_LogWindowAdapter() : + TextCount(0), + ErrorCount(0), + WarningCount(0), + GenericWarningCount(0) +{ +} + +PVGUI_LogWindowAdapter::~PVGUI_LogWindowAdapter() +{ +} + +const unsigned int PVGUI_LogWindowAdapter::getTextCount() +{ + return this->TextCount; +} + +const unsigned int PVGUI_LogWindowAdapter::getErrorCount() +{ + return this->ErrorCount; +} + +const unsigned int PVGUI_LogWindowAdapter::getWarningCount() +{ + return this->WarningCount; +} + +const unsigned int PVGUI_LogWindowAdapter::getGenericWarningCount() +{ + return this->GenericWarningCount; +} + +static LogWindow* getLogWindow() +{ + LogWindow* wnd = 0; + LightApp_Application* anApp = dynamic_cast( SUIT_Session::session()->activeApplication() ); + if ( anApp ) + wnd = anApp->logWindow(); + return wnd; +} + +void PVGUI_LogWindowAdapter::DisplayText(const char* text) +{ + ++this->TextCount; + ProcessVoidEvent( new TEvent( getLogWindow(), text, Qt::darkGreen, LogWindow::DisplayNormal )); +} + +void PVGUI_LogWindowAdapter::DisplayErrorText(const char* text) +{ + ++this->ErrorCount; + ProcessVoidEvent( new TEvent( getLogWindow(), text, Qt::darkRed, LogWindow::DisplayNormal )); +} + +void PVGUI_LogWindowAdapter::DisplayWarningText(const char* text) +{ + ++this->WarningCount; + ProcessVoidEvent( new TEvent( getLogWindow(), text, Qt::black, LogWindow::DisplayNormal )); +} + +void PVGUI_LogWindowAdapter::DisplayGenericWarningText(const char* text) +{ + ++this->GenericWarningCount; + ProcessVoidEvent( new TEvent( getLogWindow() , text, Qt::black, LogWindow::DisplayNormal )); +} diff --git a/src/PVGUI/view/PVGUI_LogWindowAdapter.h b/src/PVGUI/view/PVGUI_LogWindowAdapter.h new file mode 100644 index 00000000..ef539420 --- /dev/null +++ b/src/PVGUI/view/PVGUI_LogWindowAdapter.h @@ -0,0 +1,65 @@ +// Copyright (C) 2010-2014 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 +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// + +#ifndef _PVGUI_LogWindowAdapter_h +#define _PVGUI_LogWindowAdapter_h + +#include + +/*! +vtkOutputWindow implementation that puts VTK output messages to SALOME log window. + +To use, create an instance of PVGUI_LogWindowAdapter and pass it to the +vtkOutputWindow::setInstance() static method. + +This class is based on pqOutputWindow ParaView class. +*/ +class PVGUI_LogWindowAdapter : public vtkOutputWindow +{ +public: + static PVGUI_LogWindowAdapter *New(); + vtkTypeMacro(PVGUI_LogWindowAdapter, vtkOutputWindow); + + //! Returns the number of text messages received + const unsigned int getTextCount(); + //! Returns the number of error messages received + const unsigned int getErrorCount(); + //! Returns the number of warning messages received + const unsigned int getWarningCount(); + //! Returns the number of generic warning messages received + const unsigned int getGenericWarningCount(); + +private: + PVGUI_LogWindowAdapter(); + PVGUI_LogWindowAdapter(const PVGUI_LogWindowAdapter&); + PVGUI_LogWindowAdapter& operator=(const PVGUI_LogWindowAdapter&); + ~PVGUI_LogWindowAdapter(); + + unsigned int TextCount; + unsigned int ErrorCount; + unsigned int WarningCount; + unsigned int GenericWarningCount; + + virtual void DisplayText(const char*); + virtual void DisplayErrorText(const char*); + virtual void DisplayWarningText(const char*); + virtual void DisplayGenericWarningText(const char*); +}; + +#endif // !_PVGUI_LogWindowAdapter_h diff --git a/src/PVGUI/view/PVGUI_OutputWindowAdapter.cxx b/src/PVGUI/view/PVGUI_OutputWindowAdapter.cxx deleted file mode 100644 index 6fe2dbf2..00000000 --- a/src/PVGUI/view/PVGUI_OutputWindowAdapter.cxx +++ /dev/null @@ -1,119 +0,0 @@ -// Copyright (C) 2010-2014 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 -// License as published by the Free Software Foundation; either -// version 2.1 of the License, or (at your option) any later version. -// -// This library is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -// Lesser General Public License for more details. -// -// You should have received a copy of the GNU Lesser General Public -// License along with this library; if not, write to the Free Software -// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -// -// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com -// - -#include "PVGUI_OutputWindowAdapter.h" - -#include - -#include -#include -#include -#include - -vtkStandardNewMacro(PVGUI_OutputWindowAdapter); - - - -/*! - * Put the message in the log window. - */ -class TEvent: public SALOME_Event { - LogWindow* myWindow; - QString myMsg; - QColor myColor; - int myFlags; - public: - TEvent( LogWindow* theWindow, const QString theMsg, const QColor theColor, const int flags) : - myWindow ( theWindow ), - myMsg ( theMsg ), - myColor ( theColor ), - myFlags (flags) - {} - - virtual void Execute() { - if(myWindow) - myWindow->putMessage(myMsg, myColor, myFlags); - } -}; - - -PVGUI_OutputWindowAdapter::PVGUI_OutputWindowAdapter() : - TextCount(0), - ErrorCount(0), - WarningCount(0), - GenericWarningCount(0) -{ -} - -PVGUI_OutputWindowAdapter::~PVGUI_OutputWindowAdapter() -{ -} - -const unsigned int PVGUI_OutputWindowAdapter::getTextCount() -{ - return this->TextCount; -} - -const unsigned int PVGUI_OutputWindowAdapter::getErrorCount() -{ - return this->ErrorCount; -} - -const unsigned int PVGUI_OutputWindowAdapter::getWarningCount() -{ - return this->WarningCount; -} - -const unsigned int PVGUI_OutputWindowAdapter::getGenericWarningCount() -{ - return this->GenericWarningCount; -} - -static LogWindow* getLogWindow() -{ - LogWindow* wnd = 0; - LightApp_Application* anApp = dynamic_cast( SUIT_Session::session()->activeApplication() ); - if ( anApp ) - wnd = anApp->logWindow(); - return wnd; -} - -void PVGUI_OutputWindowAdapter::DisplayText(const char* text) -{ - ++this->TextCount; - ProcessVoidEvent( new TEvent( getLogWindow(), text, Qt::darkGreen, LogWindow::DisplayNormal )); -} - -void PVGUI_OutputWindowAdapter::DisplayErrorText(const char* text) -{ - ++this->ErrorCount; - ProcessVoidEvent( new TEvent( getLogWindow(), text, Qt::darkRed, LogWindow::DisplayNormal )); -} - -void PVGUI_OutputWindowAdapter::DisplayWarningText(const char* text) -{ - ++this->WarningCount; - ProcessVoidEvent( new TEvent( getLogWindow(), text, Qt::black, LogWindow::DisplayNormal )); -} - -void PVGUI_OutputWindowAdapter::DisplayGenericWarningText(const char* text) -{ - ++this->GenericWarningCount; - ProcessVoidEvent( new TEvent( getLogWindow() , text, Qt::black, LogWindow::DisplayNormal )); -} diff --git a/src/PVGUI/view/PVGUI_OutputWindowAdapter.h b/src/PVGUI/view/PVGUI_OutputWindowAdapter.h deleted file mode 100644 index f37fd505..00000000 --- a/src/PVGUI/view/PVGUI_OutputWindowAdapter.h +++ /dev/null @@ -1,65 +0,0 @@ -// Copyright (C) 2010-2014 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 -// License as published by the Free Software Foundation; either -// version 2.1 of the License, or (at your option) any later version. -// -// This library is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -// Lesser General Public License for more details. -// -// You should have received a copy of the GNU Lesser General Public -// License along with this library; if not, write to the Free Software -// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -// -// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com -// - -#ifndef _PVGUI_OutputWindowAdapter_h -#define _PVGUI_OutputWindowAdapter_h - -#include - -/*! -vtkOutputWindow implementation that puts VTK output messages to SALOME log window. - -To use, create an instance of PVGUI_OutputWindowAdapter and pass it to the -vtkOutputWindow::setInstance() static method. - -This class is based on pqOutputWindow ParaView class. -*/ -class PVGUI_OutputWindowAdapter : public vtkOutputWindow -{ -public: - static PVGUI_OutputWindowAdapter *New(); - vtkTypeMacro(PVGUI_OutputWindowAdapter, vtkOutputWindow); - - //! Returns the number of text messages received - const unsigned int getTextCount(); - //! Returns the number of error messages received - const unsigned int getErrorCount(); - //! Returns the number of warning messages received - const unsigned int getWarningCount(); - //! Returns the number of generic warning messages received - const unsigned int getGenericWarningCount(); - -private: - PVGUI_OutputWindowAdapter(); - PVGUI_OutputWindowAdapter(const PVGUI_OutputWindowAdapter&); - PVGUI_OutputWindowAdapter& operator=(const PVGUI_OutputWindowAdapter&); - ~PVGUI_OutputWindowAdapter(); - - unsigned int TextCount; - unsigned int ErrorCount; - unsigned int WarningCount; - unsigned int GenericWarningCount; - - virtual void DisplayText(const char*); - virtual void DisplayErrorText(const char*); - virtual void DisplayWarningText(const char*); - virtual void DisplayGenericWarningText(const char*); -}; - -#endif // !_PVGUI_OutputWindowAdapter_h diff --git a/src/PVGUI/view/PVGUI_ViewManager.cxx b/src/PVGUI/view/PVGUI_ViewManager.cxx index 5841a112..1688e863 100644 --- a/src/PVGUI/view/PVGUI_ViewManager.cxx +++ b/src/PVGUI/view/PVGUI_ViewManager.cxx @@ -19,8 +19,36 @@ #include #include #include -#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include + +#include +#include +#include +#include +#include #include +#include +#include + +//---------- Static init ----------------- +pqPVApplicationCore* PVGUI_ViewManager::MyCoreApp = 0; +PARAVIS_ORB::PARAVIS_Gen_var PVGUI_ViewManager::MyEngine; + /*! Constructor @@ -28,13 +56,163 @@ PVGUI_ViewManager::PVGUI_ViewManager( SUIT_Study* study, SUIT_Desktop* desk ) : SUIT_ViewManager( study, desk, new PVGUI_Viewer() ) { + MESSAGE("PARAVIS - view manager created ...") setTitle( tr( "PARAVIEW_VIEW_TITLE" ) ); } +pqPVApplicationCore * PVGUI_ViewManager::GetPVApplication() +{ + return MyCoreApp; +} + /*! - \brief Returns the ParaView multi-view manager for the active view window + \brief Static method, performs initialization of ParaView session. + \param fullSetup whether to instanciate all behaviors or just the minimal ones. + \return \c true if ParaView has been initialized successfully, otherwise false */ -pqTabbedMultiViewWidget* PVGUI_ViewManager::getMultiViewManager() +bool PVGUI_ViewManager::ParaviewInitApp(SUIT_Desktop * aDesktop) +{ + if ( ! MyCoreApp) { + // Obtain command-line arguments + int argc = 0; + char** argv = 0; + QString aOptions = getenv("PARAVIS_OPTIONS"); + QStringList aOptList = aOptions.split(":", QString::SkipEmptyParts); + argv = new char*[aOptList.size() + 1]; + QStringList args = QApplication::arguments(); + argv[0] = (args.size() > 0)? strdup(args[0].toLatin1().constData()) : strdup("paravis"); + argc++; + + foreach (QString aStr, aOptList) { + argv[argc] = strdup( aStr.toLatin1().constData() ); + argc++; + } + MyCoreApp = new pqPVApplicationCore (argc, argv); + if (MyCoreApp->getOptions()->GetHelpSelected() || + MyCoreApp->getOptions()->GetUnknownArgument() || + MyCoreApp->getOptions()->GetErrorMessage() || + MyCoreApp->getOptions()->GetTellVersion()) { + return false; + } + + // Direct VTK log messages to our SALOME window - TODO: review this + vtkOutputWindow::SetInstance(PVGUI_LogWindowAdapter::New()); + + new pqTabbedMultiViewWidget(); // registers a "MULTIVIEW_WIDGET" on creation + + // At this stage, the pqPythonManager has been initialized, i.e. the current process has + // activated the embedded Python interpreter. "paraview" package has also been imported once already. + // Make sure the current process executes paraview's Python command with the "fromGUI" flag. + // This is used in pvsimple.py to avoid reconnecting the GUI thread to the pvserver (when + // user types "import pvsimple" in SALOME's console). + SalomeApp_Application* app = + dynamic_cast< SalomeApp_Application* >(SUIT_Session::session()->activeApplication()); + PyConsole_Interp* pyInterp = app->pythonConsole()->getInterp(); + { + PyLockWrapper aGil; + std::string cmd = "import paraview; paraview.fromGUI = True;"; + pyInterp->run(cmd.c_str()); + } + + for (int i = 0; i < argc; i++) + free(argv[i]); + delete[] argv; + } + + return true; +} + +void PVGUI_ViewManager::ParaviewInitBehaviors(bool fullSetup, SUIT_Desktop* aDesktop) { - return qobject_cast(pqApplicationCore::instance()->manager("MULTIVIEW_WIDGET")); + PVGUI_Behaviors * behav = new PVGUI_Behaviors(aDesktop); + if(fullSetup) + behav->instanciateAllBehaviors(aDesktop); + else + behav->instanciateMinimalBehaviors(aDesktop); +} + +void PVGUI_ViewManager::ParaviewCleanup() +{ + // Disconnect from server + pqServer* server = pqActiveObjects::instance().activeServer(); + if (server && server->isRemote()) + { + MESSAGE("~PVGUI_Module(): Disconnecting from remote server ..."); + pqServerDisconnectReaction::disconnectFromServer(); + } + + pqApplicationCore::instance()->settings()->sync(); + + pqPVApplicationCore * app = GetPVApplication(); + // Schedule destruction of PVApplication singleton: + if (app) + app->deleteLater(); +} + +PARAVIS_ORB::PARAVIS_Gen_var PVGUI_ViewManager::GetEngine() +{ + // initialize PARAVIS module engine (load, if necessary) + if ( CORBA::is_nil( MyEngine ) ) { + Engines::EngineComponent_var comp = + SalomeApp_Application::lcc()->FindOrLoad_Component( "FactoryServer", "PARAVIS" ); + MyEngine = PARAVIS_ORB::PARAVIS_Gen::_narrow( comp ); + } + return MyEngine; +} + +bool PVGUI_ViewManager::ConnectToExternalPVServer(SUIT_Desktop* aDesktop) +{ + pqServer* server = pqActiveObjects::instance().activeServer(); + if (server && server->isRemote()) + { + // Already connected to an external server, do nothing + MESSAGE("connectToExternalPVServer(): Already connected to an external PVServer, won't reconnect."); + return false; + } + + if (GetEngine()->GetGUIConnected()) + { + // Should never be there as the above should already tell us that we are connected. + std::stringstream msg2; + msg2 << "Internal error while connecting to the pvserver."; + msg2 << "ParaView doesn't see a connection, but PARAVIS engine tells us there is already one!" << std::endl; + qWarning(msg2.str().c_str()); // will go to the ParaView console (see ParavisMessageOutput below) + SUIT_MessageBox::warning( aDesktop, + QString("Error connecting to PVServer"), QString(msg2.str().c_str())); + return false; + } + + std::stringstream msg; + + // Try to connect to the external PVServer - gives priority to an externally specified URL: + QString serverUrlEnv = getenv("PARAVIS_PVSERVER_URL"); + std::string serverUrl; + if (!serverUrlEnv.isEmpty()) + serverUrl = serverUrlEnv.toStdString(); + else + { + // Get the URL from the engine (possibly starting the pvserver) + CORBA::String_var url = GetEngine()->FindOrStartPVServer(0); // take the first free port + serverUrl = (char *)url; + } + + msg << "connectToExternalPVServer(): Trying to connect to the external PVServer '" << serverUrl << "' ..."; + MESSAGE(msg.str()); + + if (!pqServerConnectReaction::connectToServer(pqServerResource(serverUrl.c_str()))) + { + std::stringstream msg2; + msg2 << "Error while connecting to the requested pvserver '" << serverUrl; + msg2 << "'. Might use default built-in connection instead!" << std::endl; + qWarning(msg2.str().c_str()); // will go to the ParaView console (see ParavisMessageOutput below) + SUIT_MessageBox::warning( aDesktop, + QString("Error connecting to PVServer"), QString(msg2.str().c_str())); + return false; + } + else + { + MESSAGE("connectToExternalPVServer(): Connected!"); + GetEngine()->SetGUIConnected(true); + } + return true; } diff --git a/src/PVGUI/view/PVGUI_ViewManager.h b/src/PVGUI/view/PVGUI_ViewManager.h index 83cada48..be03a4e7 100644 --- a/src/PVGUI/view/PVGUI_ViewManager.h +++ b/src/PVGUI/view/PVGUI_ViewManager.h @@ -20,10 +20,13 @@ #define PVGUI_VIEWMANAGER_H #include +#include +#include CORBA_SERVER_HEADER(PARAVIS_Gen) class SUIT_Desktop; class SUIT_Study; class pqTabbedMultiViewWidget; +class pqPVApplicationCore; class PVGUI_ViewManager : public SUIT_ViewManager { @@ -33,7 +36,23 @@ public: PVGUI_ViewManager( SUIT_Study*, SUIT_Desktop* ); ~PVGUI_ViewManager() {} - pqTabbedMultiViewWidget* getMultiViewManager(); + static pqPVApplicationCore * GetPVApplication(); + static PARAVIS_ORB::PARAVIS_Gen_var GetEngine(); + + //! Initialize ParaView if not yet done (once per session) + static bool ParaviewInitApp(SUIT_Desktop* aDesktop); + static void ParaviewInitBehaviors(bool fullSetup=false, SUIT_Desktop* aDesktop=0); + + static void ParaviewCleanup(); + + //! Connect to the external PVServer, using the PARAVIS engine to launch it if it is not + //! already up. + static bool ConnectToExternalPVServer(SUIT_Desktop* aDesktop); + +private: + static pqPVApplicationCore* MyCoreApp; + static PARAVIS_ORB::PARAVIS_Gen_var MyEngine; + }; #endif diff --git a/src/PVGUI/view/PVGUI_ViewModel.cxx b/src/PVGUI/view/PVGUI_ViewModel.cxx index cf91a0e2..98039462 100644 --- a/src/PVGUI/view/PVGUI_ViewModel.cxx +++ b/src/PVGUI/view/PVGUI_ViewModel.cxx @@ -19,108 +19,19 @@ #include "PVGUI_ViewModel.h" #include "PVGUI_ViewWindow.h" -#include "PVGUI_OutputWindowAdapter.h" -#include "utilities.h" -#include - -#include -#include +#include +#include -//---------- Static init ----------------- -pqPVApplicationCore* PVGUI_Viewer::MyCoreApp = 0; -PARAVIS_ORB::PARAVIS_Gen_var PVGUI_Viewer::MyEngine; +#include //---------------------------------------- PVGUI_Viewer::PVGUI_Viewer() :SUIT_ViewModel() { - MESSAGE("PVGUI_Viewer: creating view ..."); + MESSAGE("PVGUI_Viewer: creating view model ..."); } -pqPVApplicationCore* PVGUI_Viewer::GetPVApplication() -{ - if(!MyCoreApp) - pvInit(); - return MyCoreApp; -} - -/*! - \brief Static method, performs initialization of ParaView session. - \return \c true if ParaView has been initialized successfully, otherwise false -*/ -bool PVGUI_Viewer::pvInit() -{ - // if ( !pqImplementation::Core ){ - if ( ! MyCoreApp) { - // Obtain command-line arguments - int argc = 0; - char** argv = 0; - QString aOptions = getenv("PARAVIS_OPTIONS"); - QStringList aOptList = aOptions.split(":", QString::SkipEmptyParts); - argv = new char*[aOptList.size() + 1]; - QStringList args = QApplication::arguments(); - argv[0] = (args.size() > 0)? strdup(args[0].toLatin1().constData()) : strdup("paravis"); - argc++; - - foreach (QString aStr, aOptList) { - argv[argc] = strdup( aStr.toLatin1().constData() ); - argc++; - } - MyCoreApp = new pqPVApplicationCore (argc, argv); - if (MyCoreApp->getOptions()->GetHelpSelected() || - MyCoreApp->getOptions()->GetUnknownArgument() || - MyCoreApp->getOptions()->GetErrorMessage() || - MyCoreApp->getOptions()->GetTellVersion()) { - return false; - } - - /* VTN: Looks like trash. For porting see branded_paraview_initializer.cxx.in - // 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; - } - - // Load optional plugins. - plugin_string = ""; - plugin_list = plugin_string.split(';',QString::SkipEmptyParts); - loader.loadPlugins(plugin_list, true); //quietly skip not-found plugins. - */ - // End of Initializer code - - vtkOutputWindow::SetInstance(PVGUI_OutputWindowAdapter::New()); - - new pqTabbedMultiViewWidget(); // it registers as "MULTIVIEW_WIDGET" on creation - - for (int i = 0; i < argc; i++) - free(argv[i]); - delete[] argv; - } - - return true; -} - - -PARAVIS_ORB::PARAVIS_Gen_var PVGUI_Viewer::GetEngine() -{ - // initialize PARAVIS module engine (load, if necessary) - if ( CORBA::is_nil( myEngine ) ) { - Engines::EngineComponent_var comp = - SalomeApp_Application::lcc()->FindOrLoad_Component( "FactoryServer", "PARAVIS" ); - myEngine = PARAVIS_ORB::PARAVIS_Gen::_narrow( comp ); - } - return myEngine; -} /*! Create new instance of view window on desktop \a theDesktop. @@ -132,44 +43,3 @@ SUIT_ViewWindow* PVGUI_Viewer::createView(SUIT_Desktop* theDesktop) return aPVView; } -bool PVGUI_Viewer::connectToExternalPVServer() -{ - pqServer* server = pqActiveObjects::instance().activeServer(); - if (server && server->isRemote()) - { - // Already connected to an external server, do nothing - MESSAGE("connectToExternalPVServer(): Already connected to an external PVServer, won't reconnect."); - return false; - } - - std::stringstream msg; - - // Try to connect to the external PVServer - gives priority to an externally specified URL: - QString serverUrlEnv = getenv("PARAVIS_PVSERVER_URL"); - std::string serverUrl; - if (!serverUrlEnv.isEmpty()) - serverUrl = serverUrlEnv.toStdString(); - else - { - // Get the URL from the engine (possibly starting the pvserver) - CORBA::String_var url = GetEngine()->FindOrStartPVServer(0); // take the first free port - serverUrl = (char *)url; - } - - msg << "connectToExternalPVServer(): Trying to connect to the external PVServer '" << serverUrl << "' ..."; - MESSAGE(msg.str()); - - if (!pqServerConnectReaction::connectToServer(pqServerResource(serverUrl.c_str()))) - { - std::stringstream msg2; - msg2 << "Error while connecting to the requested pvserver '" << serverUrl; - msg2 << "'. Might use default built-in connection instead!" << std::endl; - qWarning(msg2.str().c_str()); // will go to the ParaView console (see ParavisMessageOutput below) - SUIT_MessageBox::warning( getApp()->desktop(), - QString("Error connecting to PVServer"), QString(msg2.str().c_str())); - return false; - } - else - MESSAGE("connectToExternalPVServer(): Connected!"); - return true; -} diff --git a/src/PVGUI/view/PVGUI_ViewModel.h b/src/PVGUI/view/PVGUI_ViewModel.h index 7ecc2e28..664d15ef 100644 --- a/src/PVGUI/view/PVGUI_ViewModel.h +++ b/src/PVGUI/view/PVGUI_ViewModel.h @@ -20,11 +20,10 @@ #define _PVGUI_VIEWMODEL_H #include -#include CORBA_SERVER_HEADER(PARAVIS_Gen) class SUIT_ViewWindow; class SUIT_Desktop; -class pqPVApplicationCore; +class SUIT_Desktop; class PVGUI_Viewer: public SUIT_ViewModel { @@ -38,20 +37,6 @@ public: virtual QString getType() const { return Type(); } static QString Type() { return "ParaView"; } - pqPVApplicationCore * getPVApplication(); - static PARAVIS_ORB::PARAVIS_Gen_var GetEngine(); - - //! Initialize ParaView if not yet done (once per session) - static bool pvInit(); - - //! Connect to the external PVServer, using the PARAVIS engine to launch it if it is not - //! already up. - bool connectToExternalPVServer(); - -private: - static pqPVApplicationCore* MyCoreApp; - static PARAVIS_ORB::PARAVIS_Gen_var MyEngine; - }; #endif // !defined(_PVGUI_VIEWMODEL_H) diff --git a/src/PV_SWIG/no_wrap/paravisSM.py b/src/PV_SWIG/no_wrap/paravisSM.py index 04775112..3f5b3b17 100644 --- a/src/PV_SWIG/no_wrap/paravisSM.py +++ b/src/PV_SWIG/no_wrap/paravisSM.py @@ -18,13 +18,13 @@ # r""" This module is a direct forward to the initial -'servermanager' module of ParaView. +'servermanager' module of ParaView. We keep it for backward compatibility only. """ -from paraview.servermanager import * +from paraview import servermanager -# for name in dir(servermanager): -# if name != "__file__": -# globals()[name] = getattr(servermanager, name) -# del servermanager -# +for name in dir(servermanager): + if not name.startswith("__"): + globals()[name] = getattr(servermanager, name) +del servermanager + diff --git a/src/PV_SWIG/no_wrap/pvsimple.py b/src/PV_SWIG/no_wrap/pvsimple.py index 788c2eaf..e528bdec 100644 --- a/src/PV_SWIG/no_wrap/pvsimple.py +++ b/src/PV_SWIG/no_wrap/pvsimple.py @@ -23,30 +23,42 @@ On top of that it also establishes a connection to a valid PVServer whose addres is provided by the PARAVIS engine. """ -from paraview.simple import * -import paraview.servermanager # local import - see test on 'fromGUI' below -import paravis ## Triggers the "FindOrLoadCompo(PARAVIS)" +import paraview +import paravis + +# Forward namespace of simple into current pvsimple: +from paraview import simple +for name in dir(simple): + if not name.startswith("__"): + globals()[name] = getattr(simple, name) +del simple def __my_log(msg): print "[PARAVIS] %s" % msg def SalomeConnectToPVServer(): + """ + Automatically connect to the right PVServer when not ("inside SALOME GUI" and "already connected"). + """ __my_log("Connecting to PVServer ...") server_url = "" try: + isGUIConnected = paravis.myParavisEngine.GetGUIConnected() + if isGUIConnected and paraview.fromGUI: + __my_log("Importing pvsimple from GUI and already connected. Won't reconnect.") + return server_url = paravis.myParavisEngine.FindOrStartPVServer(0) # Extract host and port from URL: a = server_url.split(':') b = a[1].split('//') host, port = b[-1], int(a[-1]) Connect(host, port) + __my_log("Connected to %s!" % server_url) except Exception as e: __my_log("*******************************************") __my_log("** Could not connect to a running PVServer!") __my_log("*******************************************") raise e - __my_log("Connected to %s!" % server_url) + pass -# Automatically connect to the right PVServer when not inside SALOME GUI: -if not paraview.fromGUI: - SalomeConnectToPVServer() +SalomeConnectToPVServer()