From 01a6f9d4fc1a70ba608574962e9c14b4a2cd277b Mon Sep 17 00:00:00 2001 From: vsr Date: Wed, 31 Oct 2018 12:45:05 +0300 Subject: [PATCH] Multi-study removal: re-initialize study in the Python API after salome.salome_close() -> salome.salome_init() --- src/KERNEL_PY/__init__.py | 2 ++ src/KERNEL_PY/salome_study.py | 10 ++++++++-- src/SALOMEDSImpl/SALOMEDSImpl_Study.cxx | 5 ++++- 3 files changed, 14 insertions(+), 3 deletions(-) diff --git a/src/KERNEL_PY/__init__.py b/src/KERNEL_PY/__init__.py index cb8a968f0..7c8d97bf1 100755 --- a/src/KERNEL_PY/__init__.py +++ b/src/KERNEL_PY/__init__.py @@ -214,6 +214,8 @@ def salome_close(): pass salome_initial=True salome_iapp_close() + salome_study_close() + myStudy, myStudyName = None, None pass diff --git a/src/KERNEL_PY/salome_study.py b/src/KERNEL_PY/salome_study.py index 5626aecdf..0ebf612e3 100755 --- a/src/KERNEL_PY/salome_study.py +++ b/src/KERNEL_PY/salome_study.py @@ -271,11 +271,11 @@ def FindFileInDataDir(filename): #-------------------------------------------------------------------------- def openStudy(theStudyPath): - print("openStudy") + if verbose(): print("openStudy (begin)") global myStudy, myStudyName myStudy.Open(theStudyPath) myStudyName = myStudy._get_Name() - print(theStudyPath, myStudy._get_Name()) + if verbose(): print("openStudy (end):", theStudyPath, myStudy._get_Name()) #-------------------------------------------------------------------------- @@ -306,7 +306,13 @@ def salome_study_init(theStudyPath=None): if isinstance(theStudyPath, bytes): theStudyPath = str(theStudyPath, 'UTF8') openStudy(theStudyPath) + else: + myStudy.Init() myStudyName = myStudy._get_Name() return myStudy, myStudyName + +def salome_study_close(): + global myStudy, myStudyName + myStudy, myStudyName = None, None diff --git a/src/SALOMEDSImpl/SALOMEDSImpl_Study.cxx b/src/SALOMEDSImpl/SALOMEDSImpl_Study.cxx index 24f558ccb..56718e43f 100644 --- a/src/SALOMEDSImpl/SALOMEDSImpl_Study.cxx +++ b/src/SALOMEDSImpl/SALOMEDSImpl_Study.cxx @@ -109,7 +109,7 @@ namespace { * Purpose : SALOMEDSImpl_Study constructor */ //============================================================================ -SALOMEDSImpl_Study::SALOMEDSImpl_Study() +SALOMEDSImpl_Study::SALOMEDSImpl_Study() : _doc(NULL) { _appli = new DF_Application(); _clipboard = _appli->NewDocument("SALOME_STUDY"); @@ -137,6 +137,9 @@ SALOMEDSImpl_Study::~SALOMEDSImpl_Study() //============================================================================ void SALOMEDSImpl_Study::Init() { + if (_doc) + return; // noop: already initialized + static int _id = 0; std::stringstream sstrm; sstrm << ++_id; -- 2.39.2