Salome HOME
fix problem with opening study by salome.openStudy(hdf) method
[modules/kernel.git] / src / SALOMEDSImpl / SALOMEDSImpl_Study.cxx
index 7d838bc5d262159bd2071a4b47c4709d2777bd57..6e1e77792a3c13d5db00689f0efad5bb2ec5ac76 100644 (file)
@@ -142,7 +142,7 @@ void SALOMEDSImpl_Study::Init()
   sstrm << ++_id;
   _name = "Study" + std::string(sstrm.str());
   _doc = _appli->NewDocument("SALOME_STUDY");
-  _Saved = false ;
+  _Saved = false;
   _URL = "";
   _autoFill = false;
   _errorCode = "";
@@ -150,6 +150,7 @@ void SALOMEDSImpl_Study::Init()
   _builder = new SALOMEDSImpl_StudyBuilder(this);
   _cb = new SALOMEDSImpl_Callback(_useCaseBuilder);
   _notifier=0;
+  _genObjRegister=0;
   //Put on the root label a StudyHandle attribute to store the address of this object
   //It will be used to retrieve the study object by DF_Label that belongs to the study
   SALOMEDSImpl_StudyHandle::Set(_doc->Main().Root(), this);
@@ -174,6 +175,7 @@ void SALOMEDSImpl_Study::Clear()
   delete _builder;
   delete _cb;
   delete _useCaseBuilder;
+  URL("");
   _appli->Close(_doc);
   _doc = NULL;
   _mapOfSO.clear();
@@ -187,8 +189,6 @@ void SALOMEDSImpl_Study::Clear()
 //============================================================================
 bool SALOMEDSImpl_Study::Open(const std::string& aUrl)
 {
-  Clear();
-  Init();
   // Set "C" locale temporarily to avoid possible localization problems
   Kernel_Utils::Localizer loc;
 
@@ -2048,11 +2048,9 @@ std::string SALOMEDSImpl_Study::_GetStudyVariablesScript()
  *  Purpose  :
  */
 //============================================================================
-std::string SALOMEDSImpl_Study::_GetNoteBookAccess(const std::string& theStudyVar)
+std::string SALOMEDSImpl_Study::_GetNoteBookAccess()
 {
-  std::string notebook = "import salome_notebook\n";
-  notebook += _GetNoteBookAccessor() + " = salome_notebook.NoteBook(" + theStudyVar + ")" ;
-  return notebook;
+  return std::string("import salome_notebook\n");
 }
 
 bool SALOMEDSImpl_Study::IsLocked()
@@ -2367,15 +2365,11 @@ bool SALOMEDSImpl_Study::DumpStudy(const std::string& thePath,
   sfp << "import sys" << std::endl;
   sfp << "import " << aBatchModeScript << std::endl << std::endl;
 
-  std::string aStudyVar = "salome.myStudy";
   // initialization function
   sfp << aBatchModeScript << ".salome_init()" << std::endl;
-  if ( !isMultiFile ) {
-    sfp << "theStudy = " << aStudyVar << std::endl << std::endl;
-    aStudyVar = "theStudy";
-  }
+
   // notebook initialization
-  sfp << _GetNoteBookAccess(aStudyVar) << std::endl;
+  sfp << _GetNoteBookAccess() << std::endl;
 
   // extend sys.path with the directory where the script is being dumped to
   sfp << "sys.path.insert( 0, r\'" << thePath << "\')" << std::endl << std::endl;
@@ -2483,7 +2477,7 @@ bool SALOMEDSImpl_Study::DumpStudy(const std::string& thePath,
 
       //Add to the main script a call to RebuildData of the generated by the component the Python script
       sfp << "import " << aScriptName << std::endl;
-      sfp << aScriptName << ".RebuildData(" << aBatchModeScript << ".myStudy)" << std::endl;
+      sfp << aScriptName << ".RebuildData()" << std::endl;
     }
     else
       sfp << sfp2.str();
@@ -3200,6 +3194,49 @@ void SALOMEDSImpl_Study::setNotifier(SALOMEDSImpl_AbstractCallback* notifier)
   _notifier=notifier;
 }
 
+static SALOMEDSImpl_AbstractCallback* & getGenObjRegister( DF_Document* doc )
+{
+  static std::vector< SALOMEDSImpl_AbstractCallback* > _genObjRegVec;
+  if ( doc->GetDocumentID() >= (int)_genObjRegVec.size() )
+    _genObjRegVec.resize( doc->GetDocumentID() + 1, 0 );
+  return _genObjRegVec[ doc->GetDocumentID() ];
+}
+
+//================================================================================
+/*!
+ * \brief Stores theRegister
+ */
+//================================================================================
+
+void SALOMEDSImpl_Study::setGenObjRegister(SALOMEDSImpl_AbstractCallback* theRegister)
+{
+  getGenObjRegister( _doc ) = theRegister;
+}
+
+//================================================================================
+/*!
+ * \brief Indirectly invokes GenericObj_i::Register()
+ */
+//================================================================================
+
+void SALOMEDSImpl_Study::RegisterGenObj  (const std::string& theIOR, DF_Label label)
+{
+  if ( SALOMEDSImpl_AbstractCallback* goRegister = getGenObjRegister( label.GetDocument() ))
+    goRegister->RegisterGenObj( theIOR );
+}
+
+//================================================================================
+/*!
+ * \brief Indirectly invokes GenericObj_i::UnRegister()
+ */
+//================================================================================
+
+void SALOMEDSImpl_Study::UnRegisterGenObj(const std::string& theIOR, DF_Label label)
+{
+  if ( SALOMEDSImpl_AbstractCallback* goRegister = getGenObjRegister( label.GetDocument() ))
+    goRegister->UnRegisterGenObj( theIOR );
+}
+
 //#######################################################################################################
 //#                                     STATIC PRIVATE FUNCTIONS
 //#######################################################################################################