]> SALOME platform Git repositories - modules/kernel.git/commitdiff
Salome HOME
Fix on [Bug PAL7750] Regression of UNDO in GEOM
authorapo <apo@opencascade.com>
Thu, 20 Jan 2005 13:55:20 +0000 (13:55 +0000)
committerapo <apo@opencascade.com>
Thu, 20 Jan 2005 13:55:20 +0000 (13:55 +0000)
The regression was caused by last refactoring of SALOMEDS concerning improving memory menagement.
Bug PAL7023 - Problem loading MED file with a large number of families (same as VISU6154))

13 files changed:
src/SALOMEDS/SALOMEDS_AttributeIOR_i.cxx
src/SALOMEDS/SALOMEDS_ChildIterator_i.cxx
src/SALOMEDS/SALOMEDS_ChildIterator_i.hxx
src/SALOMEDS/SALOMEDS_IORAttribute.cxx
src/SALOMEDS/SALOMEDS_IORAttribute.hxx
src/SALOMEDS/SALOMEDS_SObject_i.cxx
src/SALOMEDS/SALOMEDS_SObject_i.hxx
src/SALOMEDS/SALOMEDS_StudyBuilder_i.cxx
src/SALOMEDS/SALOMEDS_StudyBuilder_i.hxx
src/SALOMEDS/SALOMEDS_StudyManager_i.cxx
src/SALOMEDS/SALOMEDS_StudyManager_i.hxx
src/SALOMEDS/SALOMEDS_Study_i.cxx
src/SALOMEDS/SALOMEDS_Study_i.hxx

index be6969df4bb3d35f32bbd27204d8984f8ea945ac..dec61d3587609e21ab4a7f134df77b547de384be 100644 (file)
@@ -44,13 +44,12 @@ char* SALOMEDS_AttributeIOR_i::Value()
 void SALOMEDS_AttributeIOR_i::SetValue(const char* value) 
 {
   CheckLocked();
-  const CORBA::ORB_var& anORB = _mySObject->GetORB();
 
-  SALOMEDS::Study_var aStudy = SALOMEDS_Study_i::GetStudy(_myAttr->Label(),anORB);
+  SALOMEDS_Study_i* aStudy = _mySObject->GetStudyServant();
   aStudy->AddCreatedPostponed(value);
   aStudy->AddPostponed(Value());
 
   CORBA::String_var Str = CORBA::string_dup(value);
   Handle(TDataStd_Comment)::DownCast(_myAttr)->Set(TCollection_ExtendedString(Str));
-  SALOMEDS_Study_i::IORUpdated(Handle(SALOMEDS_IORAttribute)::DownCast(_myAttr),anORB);
+  aStudy->IORUpdated(Handle(SALOMEDS_IORAttribute)::DownCast(_myAttr));
 }
index 6396ada74e12ca7840cdd9836a000887b5f0556d..d256bb669257b046510e90b42459d42978ed5f83 100644 (file)
@@ -46,8 +46,6 @@ SALOMEDS_ChildIterator_i::SALOMEDS_ChildIterator_i(SALOMEDS_Study_i* theStudy,
   _lab(theLabel),
   _study(theStudy)
 {
-  TCollection_AsciiString anEntry;
-  TDF_Tool::Entry(theLabel,anEntry);
 }
 
 //============================================================================
@@ -66,7 +64,7 @@ SALOMEDS_ChildIterator_i::~SALOMEDS_ChildIterator_i()
 //============================================================================
 void SALOMEDS_ChildIterator_i::Init()
 { 
-  _it.Initialize (_lab);
+  _it.Initialize(_lab);
 }
 
 //============================================================================
@@ -74,9 +72,9 @@ void SALOMEDS_ChildIterator_i::Init()
  * 
  */
 //============================================================================
-void SALOMEDS_ChildIterator_i::InitEx(CORBA::Boolean allLevels)
+void SALOMEDS_ChildIterator_i::InitEx(CORBA::Boolean theIsAllLevels)
 { 
-  _it.Initialize (_lab, allLevels);
+  _it.Initialize(_lab,theIsAllLevels);
 }
 
 //============================================================================
@@ -97,8 +95,6 @@ CORBA::Boolean SALOMEDS_ChildIterator_i::More()
 void SALOMEDS_ChildIterator_i::Next()
 {
   _it.Next();
-  TCollection_AsciiString anEntry;
-  TDF_Tool::Entry(_it.Value(),anEntry);
 }
 
 
@@ -113,3 +109,7 @@ SALOMEDS::SObject_ptr SALOMEDS_ChildIterator_i::Value()
   return SALOMEDS_SObject_i::NewRef(_study,_it.Value())._retn();
 }
 
+SALOMEDS_SObject_i* SALOMEDS_ChildIterator_i::GetValue()
+{
+  return SALOMEDS_SObject_i::NewPtr(_study,_it.Value());
+}
index 083fd9935d62f3aecf8e121720110dfa623c3969..dc7cfbe9cea0d05ae9a1fb74208e72f88c191ec3 100644 (file)
@@ -38,6 +38,7 @@
 #include <TDF_Label.hxx>
 
 class SALOMEDS_Study_i;
+class SALOMEDS_SObject_i;
 
 class SALOMEDS_ChildIterator_i: public POA_SALOMEDS::ChildIterator,
                                public PortableServer::RefCountServantBase 
@@ -57,7 +58,7 @@ public:
 
   ~SALOMEDS_ChildIterator_i();
   
-  TDF_Label GetValue() { return _it.Value();}
+  SALOMEDS_SObject_i* GetValue();
 
   virtual void Init();
   virtual void InitEx(CORBA::Boolean);
index f71b538fd5d59051bb0018ac78ce8b719bf74881..b749c54644b014c073aaeb6c80d7ff6bbdf6b8c9 100644 (file)
 //  Module : SALOME
 //  $Header$
 
-#include "SALOMEDS_IORAttribute.ixx"
 #include <TDataStd_Comment.hxx>
 #include <TCollection_ExtendedString.hxx>
+
+#include "SALOMEDS_IORAttribute.ixx"
 #include "SALOMEDS_Study_i.hxx"
+
 using namespace std;
 
 //=======================================================================
@@ -52,7 +54,7 @@ const Standard_GUID& SALOMEDS_IORAttribute::GetID ()
 
 Handle(SALOMEDS_IORAttribute) SALOMEDS_IORAttribute::Set (const TDF_Label& L,
                                                          const TCollection_ExtendedString& S,
-                                                         CORBA::ORB_ptr orb
+                                                         SALOMEDS_Study_i* theStudy
 {
   Handle(SALOMEDS_IORAttribute) A;
   if (!L.FindAttribute(SALOMEDS_IORAttribute::GetID(),A)) {
@@ -61,7 +63,7 @@ Handle(SALOMEDS_IORAttribute) SALOMEDS_IORAttribute::Set (const TDF_Label& L,
   }
   
   (Handle(TDataStd_Comment)::DownCast(A))->Set (S); 
-  SALOMEDS_Study_i::IORUpdated(A,orb);
+  theStudy->IORUpdated(A);
   return A;
 }
 
index 5bd63c9add9fbe119b88ef808afab952c4095c8c..8f9fd314a106f27f121f507a3a20af0af4c0aa0a 100644 (file)
@@ -54,7 +54,7 @@ class TDF_Label;
 class TCollection_ExtendedString;
 class TDF_Attribute;
 class TDF_RelocationTable;
-
+class SALOMEDS_Study_i;
 
 class SALOMEDS_IORAttribute : public TDataStd_Comment {
 
@@ -79,7 +79,9 @@ public:
  // Methods PUBLIC
  // 
 Standard_EXPORT static const Standard_GUID& GetID() ;
-Standard_EXPORT static Handle_SALOMEDS_IORAttribute Set(const TDF_Label& label,const TCollection_ExtendedString& string, CORBA::ORB_ptr orb) ;
+Standard_EXPORT static Handle_SALOMEDS_IORAttribute Set(const TDF_Label& label,
+                                                       const TCollection_ExtendedString& string,
+                                                       SALOMEDS_Study_i* theStudy) ;
 Standard_EXPORT SALOMEDS_IORAttribute();
 Standard_EXPORT  const Standard_GUID& ID() const;
 Standard_EXPORT   void Restore(const Handle(TDF_Attribute)& with) ;
index 5d6e163825e2b97cedfc328308e12615355ace29..2ff17b580562eb0865da39a5ac79f742419fde2a 100644 (file)
@@ -286,12 +286,14 @@ SALOMEDS_SObject_i::New(SALOMEDS_Study_i* theStudy,
   if(anIter != anSObjectMap.end())
     aSObjectHolder = anIter->second;
   else{
-    TCollection_AsciiString anEntry;
-    TDF_Tool::Entry(theLabel,anEntry);
     SALOMEDS_SObject_i* aSObject = new SALOMEDS_SObject_i(theStudy,theLabel);
     aSObjectHolder.first = aSObject;
     aSObjectHolder.second = aSObject->_this();
     anSObjectMap[theLabel] = aSObjectHolder;
+
+    //TCollection_AsciiString anEntry;
+    //TDF_Tool::Entry(theLabel,anEntry);
+    //cout<<"APO - SALOMEDS_SObject_i::New - anEntry = "<<anEntry.ToCString()<<endl;
   }
   return aSObjectHolder;
 }
@@ -525,10 +527,10 @@ char* SALOMEDS_SObject_i::GetIOR() {
  *  Purpose  : Returns list of all attributes for this sobject
  */
 //============================================================================
-SALOMEDS_GenericAttribute_i* 
+SALOMEDS_SObject_i::TAttrHolder 
 SALOMEDS_SObject_i::_FindGenAttribute(const Handle(TDF_Attribute)& theAttr)
 {
-  SALOMEDS_GenericAttribute_i* anGenAttr = NULL;
+  TAttrHolder anGenAttr;
 
   Standard_GUID aGUID = theAttr->ID();
 
@@ -540,9 +542,10 @@ SALOMEDS_SObject_i::_FindGenAttribute(const Handle(TDF_Attribute)& theAttr)
     if(anIter != myAttrMap.end())
       anGenAttr = anIter->second;
 
-    if(anGenAttr != NULL){
-      if(anGenAttr->GetAttribute() != theAttr)
-       anGenAttr->SetAttribute(theAttr);
+    SALOMEDS_GenericAttribute_i* anAttr = anGenAttr.first;
+    if(anAttr != NULL){
+      if(anAttr->GetAttribute() != theAttr)
+       anAttr->SetAttribute(theAttr);
     }else{
       anGenAttr = _CreateGenAttribute(theAttr,anAttributeID.c_str());
     }
@@ -559,10 +562,12 @@ SALOMEDS::ListOfAttributes* SALOMEDS_SObject_i::GetAllAttributes()
     Standard_Integer i = 0;
     for(TDF_AttributeIterator iter(_lab); iter.More(); iter.Next()) {
       Handle(TDF_Attribute) anAttr = iter.Value();
-      if(SALOMEDS_GenericAttribute_i* anGenAttr = _FindGenAttribute(anAttr))
+      TAttrHolder anAttrHolder = _FindGenAttribute(anAttr);
+      SALOMEDS::GenericAttribute_var anGenAttr = anAttrHolder.second;
+      if(!anGenAttr->_is_nil())
       {
        aSeqOfAttr->length(++i);
-       aSeqOfAttr[i-1] = anGenAttr->_this();
+       aSeqOfAttr[i-1] = anGenAttr._retn();
       }
     }
   }
@@ -576,11 +581,11 @@ SALOMEDS::ListOfAttributes* SALOMEDS_SObject_i::GetAllAttributes()
  *  Purpose  : Find attribute of given type on this SObject
  */
 //============================================================================
-SALOMEDS_GenericAttribute_i* 
+SALOMEDS_SObject_i::TAttrHolder 
 SALOMEDS_SObject_i::_CreateGenAttribute(const Handle(TDF_Attribute)& theAttr,
                                        const char* theType) 
 {
-  
+  SALOMEDS_GenericAttribute_i* anAttr;
   TAttrID2FunMap::const_iterator anIter = __AttrID2FunMap__.find(theType);
   if(anIter != __AttrID2FunMap__.end()){
     const TAttrID2FunMap::data_type& aValue = anIter->second;
@@ -588,56 +593,66 @@ SALOMEDS_SObject_i::_CreateGenAttribute(const Handle(TDF_Attribute)& theAttr,
     if(aValue.myIsCheckLockedStudy())
       _study->CheckLocked();
     
-    return aValue.myNewInstance(theAttr,this);
+    anAttr = aValue.myNewInstance(theAttr,this);
+    return TAttrHolder(anAttr,anAttr->_this());
   }
   
   if(strncmp(theType,"AttributeTreeNode",17) == 0){
-    return new SALOMEDS_AttributeTreeNode_i(theAttr,this);
+    anAttr = new SALOMEDS_AttributeTreeNode_i(theAttr,this);
+    return TAttrHolder(anAttr,anAttr->_this());
   }
   
   if(strncmp(theType,"AttributeUserID",15) == 0){
-    return new SALOMEDS_AttributeUserID_i(theAttr,this);
+    anAttr =  new SALOMEDS_AttributeUserID_i(theAttr,this);
+    return TAttrHolder(anAttr,anAttr->_this());
   }
   
-  return NULL;
+  return TAttrHolder();
 }
 
 
-SALOMEDS_GenericAttribute_i* 
+SALOMEDS_SObject_i::TAttrHolder 
 SALOMEDS_SObject_i::_FindGenAttribute(const char* theType)
 {
-  SALOMEDS_GenericAttribute_i* anGenAttr = NULL;
+  TAttrHolder anAttrHolder;
   TAttrMap::const_iterator anIter = myAttrMap.find(theType);
   if(anIter != myAttrMap.end())
-    anGenAttr = anIter->second;
+    anAttrHolder = anIter->second;
 
   Standard_GUID aGUID = ::GetGUID(theType);
   Handle(TDF_Attribute) anAttr;
 
   if(_lab.FindAttribute(aGUID,anAttr)){
-    if(anGenAttr != NULL){
-      if(anGenAttr->GetAttribute() != anAttr)
-       anGenAttr->SetAttribute(anAttr);
+    SALOMEDS_GenericAttribute_i* aGenAttr = anAttrHolder.first;
+    if(aGenAttr != NULL){
+      if(aGenAttr->GetAttribute() != anAttr)
+       aGenAttr->SetAttribute(anAttr);
     }else{
-      anGenAttr = _CreateGenAttribute(anAttr,theType);
+      anAttrHolder = _CreateGenAttribute(anAttr,theType);
     }
-    if(anGenAttr != NULL)
-      myAttrMap[theType] = anGenAttr;
+    aGenAttr = anAttrHolder.first;
+    if(aGenAttr != NULL)
+      myAttrMap[theType] = anAttrHolder;
   }else{
     myAttrMap.erase(theType);
     //if(anGenAttr != NULL)
     //  anGenAttr->Destroy();
+    return TAttrHolder();
   }
 
-  return anGenAttr;
+  return anAttrHolder;
 }
 
 
 SALOMEDS::GenericAttribute_ptr 
 SALOMEDS_SObject_i::_FindCORBAAttribute(const char* theType)
 {
-  if(SALOMEDS_GenericAttribute_i* anGenAttr = _FindGenAttribute(theType))
-    return anGenAttr->_this();
+  TAttrHolder anAttr = _FindGenAttribute(theType);
+  SALOMEDS::GenericAttribute_var anGenAttr = anAttr.second;
+  if(!CORBA::is_nil(anGenAttr)){
+    return anGenAttr._retn();
+  }
+
   return SALOMEDS::GenericAttribute::_nil();
 }
 
@@ -707,14 +722,19 @@ Handle(TDF_Attribute)
 SALOMEDS::GenericAttribute_ptr 
 SALOMEDS_SObject_i::FindOrCreateAttribute(const char* theType)
 {
-  if(SALOMEDS_GenericAttribute_i* anGenAttr = _FindGenAttribute(theType))
-    return anGenAttr->_this();
+  TAttrHolder anAttrHolder = _FindGenAttribute(theType);
+  SALOMEDS::GenericAttribute_var anGenAttr = anAttrHolder.second;
+  if(!anGenAttr->_is_nil())
+    return anGenAttr._retn();
+
   Handle(TDF_Attribute) anAttr = _AddAttribute(theType);
   if(!anAttr.IsNull()){
-    if(SALOMEDS_GenericAttribute_i* anGenAttr = _CreateGenAttribute(anAttr,theType)){
-      return anGenAttr->_this();
-    }
+    anAttrHolder = _CreateGenAttribute(anAttr,theType);
+    anGenAttr = anAttrHolder.second;
+    if(!anGenAttr->_is_nil())
+      return anGenAttr._retn();
   }
+
   return SALOMEDS::GenericAttribute::_nil();
 }
 
@@ -741,3 +761,23 @@ void SALOMEDS_SObject_i::RemoveAttribute(const char* theType)
   _lab.ForgetAttribute(::GetGUID(theType));
 }
 
+
+void SALOMEDS_SObject_i::OnRemove()
+{
+  Handle(TDF_Reference) aReference;
+  if(_lab.FindAttribute(TDF_Reference::GetID(),aReference)){
+    Handle(SALOMEDS_TargetAttribute) aTarget;
+    if(aReference->Get().FindAttribute(SALOMEDS_TargetAttribute::GetID(),aTarget))
+      aTarget->Remove(_lab);
+  }
+
+  Handle(SALOMEDS_IORAttribute) anAttr; // postponed removing of CORBA objects
+  if(_lab.FindAttribute(SALOMEDS_IORAttribute::GetID(),anAttr)){
+    _study->AddPostponed(TCollection_AsciiString(anAttr->Get()).ToCString());
+  }
+
+  myAttrMap.clear();
+
+  SALOMEDS_Study_i::TSObjectMap& anSObjectMap = _study->GetSObjectMap();
+  anSObjectMap.erase(_lab);
+}
index 2f28e74c2c12131545b5654b1bee667902656686..a4c73ce43c8bffcf6bef0355079e5c7e01d1ace8 100644 (file)
@@ -105,9 +105,12 @@ public:
   FindOrCreateAttribute(const char* theTypeOfAttribute);
 
   void RemoveAttribute(const char* theTypeOfAttribute);
+  void OnRemove();
 
   SALOMEDS_Study_i* GetStudyServant(){ return _study;}
 
+  TDF_Label GetLabel(){ return _lab;}
+
   CORBA::ORB_var GetORB() const;
 
   PortableServer::POA_var GetPOA() const;
@@ -115,14 +118,19 @@ public:
 protected:
   friend class SALOMEDS_GenericAttribute_i;
 
-  SALOMEDS_GenericAttribute_i* 
+  typedef std::string TAttributeID;
+  typedef std::pair<SALOMEDS_GenericAttribute_i*,SALOMEDS::GenericAttribute_var> TAttrHolder;
+  typedef std::map<TAttributeID,TAttrHolder> TAttrMap;
+  TAttrMap myAttrMap;
+
+  TAttrHolder 
   _FindGenAttribute(const Handle(TDF_Attribute)& theAttr);
 
-  SALOMEDS_GenericAttribute_i* 
+  TAttrHolder 
   _CreateGenAttribute(const Handle(TDF_Attribute)& theAttr,
                      const char* theTypeOfAttribute);
 
-  SALOMEDS_GenericAttribute_i* 
+  TAttrHolder 
   _FindGenAttribute(const char* theTypeOfAttribute);
 
   SALOMEDS::GenericAttribute_ptr 
@@ -135,11 +143,6 @@ protected:
   std::string _name;
   TDF_Label _lab;
 
-  typedef std::string TAttributeID;
-  typedef SALOMEDS_GenericAttribute_i* TAttrHolder;
-  typedef std::map<TAttributeID,TAttrHolder> TAttrMap;
-  TAttrMap myAttrMap;
-
   SALOMEDS_SObject_i(SALOMEDS_Study_i* theStudy, 
                     const TDF_Label& theLabel);
   
index 143d3c0b7eb38a9c6e2bbc8b97cb8108cdd1fe88..c6b74d1318669ae5709f671109cde56e66825bed 100644 (file)
@@ -32,6 +32,7 @@
 
 #include "SALOMEDS_SObject_i.hxx"
 #include "SALOMEDS_SComponent_i.hxx"
+#include "SALOMEDS_ChildIterator_i.hxx"
 
 #include "SALOMEDS_TargetAttribute.hxx"
 #include "SALOMEDS_IORAttribute.hxx"
@@ -158,7 +159,7 @@ void SALOMEDS_StudyBuilder_i::DefineComponentInstance(SALOMEDS::SComponent_ptr t
 
   //add theObject definition 
   aString = GetORB()->object_to_string(theObject);
-  SALOMEDS_IORAttribute::Set(Lab,const_cast<char*>(aString.in()),GetORB());
+  SALOMEDS_IORAttribute::Set(Lab,const_cast<char*>(aString.in()),_study);
 }
 
 //============================================================================
@@ -246,31 +247,26 @@ SALOMEDS_StudyBuilder_i::NewObjectToTag(SALOMEDS::SObject_ptr theFatherObject,
 //============================================================================
 void SALOMEDS_StudyBuilder_i::RemoveObject(SALOMEDS::SObject_ptr theSObject)
 {
-  CheckLocked();
-
-  if(CORBA::is_nil(theSObject))
-    return;
-
-  OnRemoveSObject(theSObject);
-
-  TDF_Label Lab;
-  CORBA::String_var aString(theSObject->GetID());
-  TDF_Tool::Label(_doc->GetData(),const_cast<char*>(aString.in()),Lab);
+  RemoveSObject(theSObject);
+}
 
-  Handle(TDF_Reference) aReference;
-  if(Lab.FindAttribute(TDF_Reference::GetID(),aReference)){
-    Handle(SALOMEDS_TargetAttribute) aTarget;
-    if(aReference->Get().FindAttribute(SALOMEDS_TargetAttribute::GetID(),aTarget))
-      aTarget->Remove(Lab);
-  }
+SALOMEDS_SObject_i*
+SALOMEDS_StudyBuilder_i::RemoveSObject(SALOMEDS::SObject_ptr theSObject,
+                                      bool theIsForgetAllAttributes)
+{
+  CheckLocked();
 
-  Handle(SALOMEDS_IORAttribute) anAttr; // postponed removing of CORBA objects
-  if (Lab.FindAttribute(SALOMEDS_IORAttribute::GetID(), anAttr)){
-    SALOMEDS::Study_ptr aStudy = SALOMEDS_Study_i::GetStudy(_doc->Main(),GetORB());
-    aStudy->AddPostponed(TCollection_AsciiString(anAttr->Get()).ToCString());
+  if(SALOMEDS_SObject_i* aSObject = _study->DownCast(theSObject)){
+    OnRemoveSObject(theSObject);
+    aSObject->OnRemove();
+    if(theIsForgetAllAttributes){
+      TDF_Label aLabel = aSObject->GetLabel();
+      aLabel.ForgetAllAttributes();
+    }
+    return aSObject;
   }
 
-  Lab.ForgetAllAttributes();
+  return NULL;
 }
 
 //============================================================================
@@ -280,48 +276,15 @@ void SALOMEDS_StudyBuilder_i::RemoveObject(SALOMEDS::SObject_ptr theSObject)
 //============================================================================
 void SALOMEDS_StudyBuilder_i::RemoveObjectWithChildren(SALOMEDS::SObject_ptr theSObject)
 {
-  CheckLocked();
-
-  if(CORBA::is_nil(theSObject))
-    return;
-
-  OnRemoveSObject(theSObject);
-
-  TDF_Label Lab;
-  CORBA::String_var aString(theSObject->GetID());
-  TDF_Tool::Label(_doc->GetData(),aString,Lab);
-
-  Handle(TDF_Reference) aReference;
-  if (Lab.FindAttribute(TDF_Reference::GetID(), aReference)) {
-    Handle(SALOMEDS_TargetAttribute) aTarget;
-    if (aReference->Get().FindAttribute(SALOMEDS_TargetAttribute::GetID(),aTarget))
-      aTarget->Remove(Lab);
-  }
-
-  Handle(SALOMEDS_IORAttribute) anAttr; // postponed removing of CORBA objects
-  if (Lab.FindAttribute(SALOMEDS_IORAttribute::GetID(), anAttr)){
-    SALOMEDS::Study_ptr aStudy = SALOMEDS_Study_i::GetStudy(_doc->Main(),GetORB());
-    aStudy->AddPostponed(TCollection_AsciiString(anAttr->Get()).ToCString());
-  }
-
-  TDF_ChildIterator it(Lab, Standard_True);
-  for(;it.More();it.Next()) {
-    TDF_Label aLabel = it.Value();
-
-    if (aLabel.FindAttribute(TDF_Reference::GetID(), aReference)) {
-      Handle(SALOMEDS_TargetAttribute) aTarget;
-      if (aReference->Get().FindAttribute(SALOMEDS_TargetAttribute::GetID(),aTarget))
-       aTarget->Remove(aLabel);
-    }
-
-    Handle(SALOMEDS_IORAttribute) anAttr; // postponed removing of CORBA objects
-    if (aLabel.FindAttribute(SALOMEDS_IORAttribute::GetID(), anAttr)){
-      SALOMEDS::Study_ptr aStudy = SALOMEDS_Study_i::GetStudy(_doc->Main(),GetORB());
-      aStudy->AddPostponed(TCollection_AsciiString(anAttr->Get()).ToCString());
+  if(SALOMEDS_SObject_i* aSObject = RemoveSObject(theSObject,false)){
+    SALOMEDS_ChildIterator_i aChildIter(_study,aSObject->GetLabel(),true);
+    for(; aChildIter.More(); aChildIter.Next()){
+      if(SALOMEDS_SObject_i* aSObj = aChildIter.GetValue())
+       aSObj->OnRemove();
     }
+    TDF_Label aLabel = aSObject->GetLabel();
+    aLabel.ForgetAllAttributes(Standard_True);
   }
-
-  Lab.ForgetAllAttributes(Standard_True);
 }
 
 //============================================================================
@@ -331,7 +294,6 @@ void SALOMEDS_StudyBuilder_i::RemoveObjectWithChildren(SALOMEDS::SObject_ptr the
 //============================================================================
 static void  Translate_persistentID_to_IOR(TDF_Label theLabel,
                                           SALOMEDS::Driver_ptr theDriver,
-                                          CORBA::ORB_ptr theORB,
                                           SALOMEDS_Study_i* theStudy,
                                           CORBA::Boolean theIsMultiFile,
                                           CORBA::Boolean theIsASCII)
@@ -354,10 +316,10 @@ static void  Translate_persistentID_to_IOR(TDF_Label theLabel,
 
       CORBA::String_var anIOR = 
        theDriver->LocalPersistentIDToIOR(aSObject,ch.ToCString(),theIsMultiFile,theIsASCII);
-      SALOMEDS_IORAttribute::Set (aCurrentLabel,const_cast<char*>(anIOR.in()),theORB); 
+      SALOMEDS_IORAttribute::Set(aCurrentLabel,const_cast<char*>(anIOR.in()),theStudy); 
     }
 
-    Translate_persistentID_to_IOR(aCurrentLabel,theDriver,theORB,theStudy,theIsMultiFile,theIsASCII);
+    Translate_persistentID_to_IOR(aCurrentLabel,theDriver,theStudy,theIsMultiFile,theIsASCII);
   }
 }
 
@@ -387,14 +349,14 @@ void SALOMEDS_StudyBuilder_i::LoadWith(SALOMEDS::SComponent_ptr theSComponent,
     if(CORBA::is_nil(theDriver))
       return;
 
-    int aLocked = theSComponent->GetStudy()->GetProperties()->IsLocked();
+    int aLocked = _study->GetProperties()->IsLocked();
     if(aLocked) 
-      theSComponent->GetStudy()->GetProperties()->SetLocked(false);
+      _study->GetProperties()->SetLocked(false);
     
     // mpv 06.03.2003: SAL1927 - if component data if already loaded, it is not necessary to do it again
     if (Lab.FindAttribute(SALOMEDS_IORAttribute::GetID(), Att)) {
       if(aLocked) 
-       theSComponent->GetStudy()->GetProperties()->SetLocked(true);
+       _study->GetProperties()->SetLocked(true);
       return;
     }
     DefineComponentInstance (theSComponent,theDriver);
@@ -496,21 +458,21 @@ void SALOMEDS_StudyBuilder_i::LoadWith(SALOMEDS::SComponent_ptr theSComponent,
        SALOMEDS_Tool::RemoveTemporaryFiles(aDir,aFilesToRemove,true);
       }
       if(aLocked)
-       theSComponent->GetStudy()->GetProperties()->SetLocked(true);
+       _study->GetProperties()->SetLocked(true);
       THROW_SALOME_CORBA_EXCEPTION("No persistent file Name found",SALOME::BAD_PARAM);
     }
     
     try {
-      Translate_persistentID_to_IOR(Lab,theDriver,GetORB(),_study, aMultifileState[0]=='M', ASCIIfileState[0] == 'A');
+      Translate_persistentID_to_IOR(Lab,theDriver,_study,aMultifileState[0]=='M',ASCIIfileState[0] == 'A');
     } catch (SALOME::SALOME_Exception) {
       INFOS("Can't translate PersRef to IOR");
       if (aLocked) 
-       theSComponent->GetStudy()->GetProperties()->SetLocked(true);
+       _study->GetProperties()->SetLocked(true);
       THROW_SALOME_CORBA_EXCEPTION("Unable to convert component persistent data to the transient",SALOME::BAD_PARAM);
       //        throw HDFexception("Unable to load component data");
     }
     if(aLocked)
-      theSComponent->GetStudy()->GetProperties()->SetLocked(true);
+      _study->GetProperties()->SetLocked(true);
   } else
     MESSAGE("No persistent file Name");
 }
@@ -536,15 +498,9 @@ SALOMEDS::GenericAttribute_ptr
 SALOMEDS_StudyBuilder_i::FindOrCreateAttribute(SALOMEDS::SObject_ptr theObject, 
                                               const char* theTypeOfAttribute)
 {
-  if(!CORBA::is_nil(theObject)){
-    PortableServer::POA_var aPOA = GetPOA();
-    PortableServer::ServantBase_var aServant = SALOMEDS::GetServant(theObject,aPOA);
-    if(aServant.in() != NULL){
-      if(SALOMEDS_SObject_i* anSObject = dynamic_cast<SALOMEDS_SObject_i*>(aServant.in())){
-       return anSObject->FindOrCreateAttribute(theTypeOfAttribute);
-      }
-    }
-  }
+  if(SALOMEDS_SObject_i* aSObject = _study->DownCast(theObject))
+    return aSObject->FindOrCreateAttribute(theTypeOfAttribute);
+
   return SALOMEDS::GenericAttribute::_nil();
 }
 
@@ -558,14 +514,9 @@ CORBA::Boolean SALOMEDS_StudyBuilder_i::FindAttribute(SALOMEDS::SObject_ptr theO
                                                      SALOMEDS::GenericAttribute_out theAttr, 
                                                      const char* theTypeOfAttribute)
 {
-  if(!CORBA::is_nil(theObject)){
-    PortableServer::ServantBase_var aServant = SALOMEDS::GetServant(theObject,GetPOA());
-    if(aServant.in() != NULL){
-      if(SALOMEDS_SObject_i* anSObject = dynamic_cast<SALOMEDS_SObject_i*>(aServant.in())){
-       return anSObject->FindAttribute(theAttr,theTypeOfAttribute);
-      }
-    }
-  }
+  if(SALOMEDS_SObject_i* aSObject = _study->DownCast(theObject))
+    return aSObject->FindAttribute(theAttr,theTypeOfAttribute);
+
   return Standard_False;
 }
 
@@ -590,8 +541,9 @@ void SALOMEDS_StudyBuilder_i::RemoveAttribute(SALOMEDS::SObject_ptr theSObject,
   if (strcmp(aTypeOfAttribute, "AttributeIOR") == 0) { // postponed removing of CORBA objects
     Handle(SALOMEDS_IORAttribute) anAttr;
     if (Lab.FindAttribute(SALOMEDS_IORAttribute::GetID(), anAttr))
-      SALOMEDS_Study_i::GetStudy(_doc->Main(),GetORB())->AddPostponed(TCollection_AsciiString(anAttr->Get()).ToCString());
-    else return;
+      _study->AddPostponed(TCollection_AsciiString(anAttr->Get()).ToCString());
+    else
+      return;
   }
 
   Lab.ForgetAttribute(SALOMEDS::GetGUID(aTypeOfAttribute));
@@ -668,10 +620,9 @@ void SALOMEDS_StudyBuilder_i::AddDirectory(const char* thePath)
   Handle(TDataStd_Name) aName;
   TDF_Label aLabel;
   SALOMEDS::SObject_var anObject = SALOMEDS_SObject_i::NewRef(_study,_doc->Main()); 
-  SALOMEDS::Study_var aStudy = anObject->GetStudy();
 
   try { 
-    anObject = aStudy->FindObjectByPath(thePath); //Check if the directory already exists
+    anObject = _study->FindObjectByPath(thePath); //Check if the directory already exists
   }
   catch(...) { }
 
@@ -679,7 +630,7 @@ void SALOMEDS_StudyBuilder_i::AddDirectory(const char* thePath)
 
   if(aPath.Value(1) != '/') { //Relative path 
     aPath.Prepend('/');
-    aPath = TCollection_AsciiString(aStudy->GetContext()) + aPath;
+    aPath = TCollection_AsciiString(_study->GetContext()) + aPath;
   }
 
   TCollection_AsciiString aToken = aPath.Token("/", 1);
@@ -696,7 +647,7 @@ void SALOMEDS_StudyBuilder_i::AddDirectory(const char* thePath)
 
   anObject = SALOMEDS::SObject::_nil();
   try { 
-    anObject = aStudy->FindObjectByPath(aFatherPath.ToCString()); //Check if the father directory exists
+    anObject = _study->FindObjectByPath(aFatherPath.ToCString()); //Check if the father directory exists
   }
   catch(...) { ; }
   if(anObject->_is_nil()) 
@@ -792,7 +743,7 @@ void SALOMEDS_StudyBuilder_i::CommitCommand() throw (SALOMEDS::StudyBuilder::Loc
     AbortCommand();
     throw SALOMEDS::StudyBuilder::LockProtection();
   } else {
-    SALOMEDS_Study_i::GetStudy(_doc->Main(),GetORB())->RemovePostponed(_doc->GetUndoLimit());
+    _study->RemovePostponed(_doc->GetUndoLimit());
 
     int aModif = anAttr->GetModified();
     if (aModif < 0) aModif = 1000; // if user make undo and then - new transaction "modify" will never be zero
@@ -818,7 +769,7 @@ CORBA::Boolean SALOMEDS_StudyBuilder_i::HasOpenCommand()
 //============================================================================
 void SALOMEDS_StudyBuilder_i::AbortCommand()
 {
-  SALOMEDS_Study_i::GetStudy(_doc->Main(),GetORB())->UndoPostponed(0);
+  _study->UndoPostponed(0);
   
   _doc->AbortCommand();
 }
@@ -840,7 +791,7 @@ void SALOMEDS_StudyBuilder_i::Undo() throw (SALOMEDS::StudyBuilder::LockProtecti
     MESSAGE("Locked document modification !!!");
     throw SALOMEDS::StudyBuilder::LockProtection();
   } else {
-    SALOMEDS_Study_i::GetStudy(_doc->Main(),GetORB())->UndoPostponed(1);
+    _study->UndoPostponed(1);
     _doc->Undo();
     anAttr->SetModified(anAttr->GetModified()-1);
   }
@@ -865,7 +816,7 @@ void SALOMEDS_StudyBuilder_i::Redo() throw (SALOMEDS::StudyBuilder::LockProtecti
     throw SALOMEDS::StudyBuilder::LockProtection();
   } else {
     _doc->Redo();
-    SALOMEDS_Study_i::GetStudy(_doc->Main(),GetORB())->UndoPostponed(-1);
+    _study->UndoPostponed(-1);
     anAttr->SetModified(anAttr->GetModified()+1);
   }
  }
@@ -1010,5 +961,5 @@ void SALOMEDS_StudyBuilder_i::SetIOR(SALOMEDS::SObject_ptr theSO, const char* th
   TDF_Label aLabel;
   CORBA::String_var aSOID = theSO->GetID();
   TDF_Tool::Label(_doc->GetData(), aSOID, aLabel);
-  SALOMEDS_IORAttribute::Set(aLabel, TCollection_ExtendedString((char*)theValue),GetORB());
+  SALOMEDS_IORAttribute::Set(aLabel, TCollection_ExtendedString((char*)theValue),_study);
 }
index b2bddafa5903ee0ab6ed71089a04dc0c9f1b32d6..38f29b44078d34e8752fd7ba4918414d7b1fb1b0 100644 (file)
@@ -38,6 +38,7 @@
 #include <TDocStd_Document.hxx>
 
 class SALOMEDS_Study_i;
+class SALOMEDS_SObject_i;
 class SALOMEDS_Callback_i;
 
 class SALOMEDS_StudyBuilder_i: public virtual POA_SALOMEDS::StudyBuilder,
@@ -110,6 +111,8 @@ public:
     throw(SALOME::SALOME_Exception);
   virtual void Load(SALOMEDS::SObject_ptr sco);
 
+  SALOMEDS_SObject_i* RemoveSObject(SALOMEDS::SObject_ptr theSObject,
+                                   bool theIsForgetAllAttributes = true);
   virtual void RemoveObject(SALOMEDS::SObject_ptr anObject);
   virtual void RemoveObjectWithChildren(SALOMEDS::SObject_ptr anObject);
 
index 5030d08803b1a680caceb6a49ffc66806bfc9068..614ca3611a66a59a6bd572c4fa47ac994c499b62 100644 (file)
 
 #include "SALOMEDS_StudyManager_i.hxx"
 #include "SALOME_LifeCycleCORBA.hxx"
-#include "SALOMEDS_SObject_i.hxx"
+
 #include "SALOMEDS_Study_i.hxx"
+#include "SALOMEDS_SObject_i.hxx"
+#include "SALOMEDS_StudyBuilder_i.hxx"
 
 #include "SALOMEDS_IORAttribute.hxx"
 #include "SALOMEDS_PersRefAttribute.hxx"
@@ -112,9 +114,11 @@ namespace SALOMEDS{
 //===========================================================================
 //Function : LoadAttributes
 //===========================================================================
-static void ReadAttributes(SALOMEDS::Study_ptr theStudy,
-                          SALOMEDS::SObject_ptr aSO,
-                          HDFdataset* hdf_dataset)
+static 
+void 
+ReadAttributes(SALOMEDS_Study_i* theStudy,
+              SALOMEDS::SObject_ptr aSO,
+              HDFdataset* hdf_dataset)
 {
   hdf_dataset->OpenOnDisk();
 
@@ -124,15 +128,15 @@ static void ReadAttributes(SALOMEDS::Study_ptr theStudy,
   hdf_dataset->ReadFromDisk(current_string);
 
   if (!strcmp(hdf_dataset->GetName(),"COMPONENTDATATYPE")) {
-    anAttr = theStudy->NewBuilder()->FindOrCreateAttribute(aSO, "AttributeComment");
+    anAttr = theStudy->GetBuilder()->FindOrCreateAttribute(aSO, "AttributeComment");
   } else if (!strcmp(hdf_dataset->GetName(),"Reference")) {
-    theStudy->NewBuilder()->Addreference(aSO, theStudy->CreateObjectID(current_string));
+    theStudy->GetBuilder()->Addreference(aSO, theStudy->CreateObjectID(current_string));
     delete(current_string);
     hdf_dataset->CloseOnDisk();
     return;
   } else {
     MESSAGE("Read attribute "<<hdf_dataset->GetName())
-    anAttr = theStudy->NewBuilder()->FindOrCreateAttribute(aSO, hdf_dataset->GetName());
+    anAttr = theStudy->GetBuilder()->FindOrCreateAttribute(aSO, hdf_dataset->GetName());
   }
 
   if (!CORBA::is_nil(anAttr)) {
@@ -149,18 +153,18 @@ static void ReadAttributes(SALOMEDS::Study_ptr theStudy,
 //============================================================================
 //Function : Translate_IOR_to_persistentID
 //============================================================================
-static void Translate_IOR_to_persistentID (SALOMEDS::Study_ptr theStudy,
-                                          SALOMEDS::StudyBuilder_ptr theBuilder,
-                                          SALOMEDS::SObject_ptr theSObject,
-                                          SALOMEDS::Driver_ptr theEngine,
-                                          CORBA::Boolean theIsMultiFile,
-                                          CORBA::Boolean theIsASCII)
+static void Translate_IOR_to_persistentID(SALOMEDS_Study_i* theStudy,
+                                         SALOMEDS_StudyBuilder_i* theBuilder,
+                                         SALOMEDS::SObject_ptr theSObject,
+                                         SALOMEDS::Driver_ptr theEngine,
+                                         CORBA::Boolean theIsMultiFile,
+                                         CORBA::Boolean theIsASCII)
 {
   MESSAGE("In Translate_IOR_to_persistentID");
-  SALOMEDS::ChildIterator_var anIter = theStudy->NewChildIterator(theSObject);
-  for (; anIter->More(); anIter->Next()){
+  SALOMEDS_ChildIterator_i anIter = theStudy->GetChildIterator(theSObject);
+  for(; anIter.More(); anIter.Next()){
     SALOMEDS::GenericAttribute_var anAttr;
-    SALOMEDS::SObject_var aSObject = anIter->Value();
+    SALOMEDS::SObject_var aSObject = anIter.Value();
     if(aSObject->FindAttribute(anAttr,"AttributeIOR")){
       SALOMEDS::AttributeIOR_var anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
       CORBA::String_var aString = anIOR->Value();
@@ -178,7 +182,9 @@ static void Translate_IOR_to_persistentID (SALOMEDS::Study_ptr theStudy,
 //============================================================================
 //Function : BuildlTree
 //============================================================================
-static void BuildTree (SALOMEDS::Study_ptr theStudy,HDFgroup* hdf_current_group)
+static 
+void 
+BuildTree(SALOMEDS_Study_i* theStudy, HDFgroup* hdf_current_group)
 {
   hdf_current_group->OpenOnDisk();
   
@@ -210,7 +216,7 @@ static void BuildTree (SALOMEDS::Study_ptr theStudy,HDFgroup* hdf_current_group)
     else if (type == HDF_GROUP)   {
       MESSAGE( "--> Group: Internal Object Name : " << name);
       HDFgroup* new_group = new HDFgroup(name,hdf_current_group);
-      BuildTree (theStudy, new_group);
+      BuildTree(theStudy, new_group);
       new_group = 0; // will be deleted by father destructor
     }
   }
@@ -247,6 +253,18 @@ SALOMEDS_StudyManager_i::~SALOMEDS_StudyManager_i()
   _name_service.Destroy_Directory("/Study");
 }
 
+SALOMEDS_Study_i* 
+SALOMEDS_StudyManager_i::DownCast(SALOMEDS::Study_ptr theStudy) const
+{
+  if(!CORBA::is_nil(theStudy)){
+    PortableServer::POA_var aPOA = GetPOA();
+    PortableServer::ServantBase_var aServant = SALOMEDS::GetServant(theStudy,aPOA);
+    if(aServant.in())
+      return dynamic_cast<SALOMEDS_Study_i*>(aServant.in());
+  }
+  return NULL;
+}
+
 //============================================================================
 /*! Function : register_name
  *  Purpose  : Register the study Manager in the naming service under the  
@@ -286,7 +304,9 @@ SALOMEDS::Study_ptr SALOMEDS_StudyManager_i::NewStudy(const char* theStudyName)
                                                   
   // Assign the value of the IOR in the study->root
   CORBA::String_var anIOR = _orb->object_to_string(aStudy);
-  SALOMEDS_IORAttribute::Set(aDocument->Main().Root(),const_cast<char*>(anIOR.in()),_orb);
+  SALOMEDS_IORAttribute::Set(aDocument->Main().Root(),
+                            const_cast<char*>(anIOR.in()),
+                            aStudyServant);
 
   // set Study properties
   SALOMEDS::AttributeStudyProperties_var aProp = aStudyServant->GetProperties();
@@ -350,12 +370,14 @@ SALOMEDS::Study_ptr  SALOMEDS_StudyManager_i::Open(const char* theURL)
   aStudy->StudyId( _IDcounter );
 
   // Assign the value of the URL in the study object
-  aStudy->URL(theURL);
+  aStudyServant->URL(theURL);
   SCRUTE(theURL);
 
   // Assign the value of the IOR in the study->root
   CORBA::String_var anIOR = _orb->object_to_string(aStudy);
-  SALOMEDS_IORAttribute::Set(Doc->Main().Root(),const_cast<char*>(anIOR.in()),_orb);
+  SALOMEDS_IORAttribute::Set(Doc->Main().Root(),
+                            const_cast<char*>(anIOR.in()),
+                            aStudyServant);
 
   SALOMEDS_PersRefAttribute::Set(Doc->Main(),const_cast<char*>(theURL)); 
 
@@ -370,7 +392,7 @@ SALOMEDS::Study_ptr  SALOMEDS_StudyManager_i::Open(const char* theURL)
   Handle(TDF_Data) DF = Doc->GetData();
 
   try{
-    BuildTree (aStudy,hdf_group_study_structure);
+    BuildTree(aStudyServant,hdf_group_study_structure);
   }catch(HDFexception){
     std::ostringstream aStream;
     aStream<<"Can't open file "<<theURL;
@@ -385,7 +407,7 @@ SALOMEDS::Study_ptr  SALOMEDS_StudyManager_i::Open(const char* theURL)
   if(!_name_service.Change_Directory("/Study")){
     MESSAGE( "Unable to access the study directory" );
   }else{
-    CORBA::String_var aString(aStudy->Name());
+    CORBA::String_var aString(aStudyServant->Name());
     _name_service.Register(aStudy,aString.in());
   }
 
@@ -590,12 +612,10 @@ static void SaveAttributes(SALOMEDS::SObject_ptr SO, HDFgroup *hdf_group_sobject
  *  Purpose  : save the study properties in HDF file
  */
 //============================================================================
-void SALOMEDS_StudyManager_i::_SaveProperties(SALOMEDS::Study_ptr aStudy, HDFgroup *hdf_group) 
+void SALOMEDS_StudyManager_i::_SaveProperties(SALOMEDS_Study_i* theStudy, HDFgroup *hdf_group) 
 {
   // add modifications list (user and date of save)
-  SALOMEDS::AttributeStudyProperties_ptr aProp = aStudy->GetProperties();
-  SALOMEDS::StudyBuilder_var SB= aStudy->NewBuilder();
-//    SB->NewCommand();
+  SALOMEDS::AttributeStudyProperties_ptr aProp = theStudy->GetProperties();
   int aLocked = aProp->IsLocked();
   if (aLocked) 
     aProp->SetLocked(Standard_False);
@@ -609,7 +629,6 @@ void SALOMEDS_StudyManager_i::_SaveProperties(SALOMEDS::Study_ptr aStudy, HDFgro
                         CORBA::Long(aDate.Year()));
   if(aLocked) 
     aProp->SetLocked(Standard_True);
-//    SB->CommitCommand();
 
   SALOMEDS::StringSeq_var aNames;
   SALOMEDS::LongSeq_var aMinutes, aHours, aDays, aMonths, aYears;
@@ -647,7 +666,7 @@ void SALOMEDS_StudyManager_i::_SaveProperties(SALOMEDS::Study_ptr aStudy, HDFgro
  */
 //============================================================================
 void SALOMEDS_StudyManager_i::_SaveAs(const char* aUrl, 
-                                     SALOMEDS::Study_ptr aStudy,
+                                     SALOMEDS::Study_ptr theStudy,
                                      CORBA::Boolean theMultiFile,
                                      CORBA::Boolean theASCII)
 {
@@ -657,72 +676,66 @@ void SALOMEDS_StudyManager_i::_SaveAs(const char* aUrl,
   // * Study Structure -> Exactly what is contained in OCAF document
   //   Informations in data group hdf_group_study_structure
 
-  HDFfile *hdf_file=0;         
-  HDFgroup *hdf_group_study_structure =0;
-  HDFgroup *hdf_sco_group =0;
-  HDFgroup *hdf_sco_group2 =0;
+  if(SALOMEDS_Study_i* aStudy = DownCast(theStudy)){
+    HDFfile *hdf_file=0;         
+    HDFgroup *hdf_group_study_structure =0;
+    HDFgroup *hdf_sco_group =0;
+    HDFgroup *hdf_sco_group2 =0;
 
-  HDFgroup *hdf_group_datacomponent =0;
-  HDFdataset *hdf_dataset =0;
-  hdf_size size[1];
-  hdf_int32 name_len = 0;
-
-  int aLocked = aStudy->GetProperties()->IsLocked();
-  if (aLocked) aStudy->GetProperties()->SetLocked(false);
-
-  SALOMEDS::StudyBuilder_var SB= aStudy->NewBuilder();
+    HDFgroup *hdf_group_datacomponent =0;
+    HDFdataset *hdf_dataset =0;
+    hdf_size size[1];
+    hdf_int32 name_len = 0;
+  
+    int aLocked = aStudy->GetProperties()->IsLocked();
+    if(aLocked) 
+      aStudy->GetProperties()->SetLocked(false);
 
-  ASSERT(!CORBA::is_nil(aStudy));
-  try
-    {
+    SALOMEDS_StudyBuilder_i* SB= aStudy->GetBuilder();
+    try{
       // mpv 15.12.2003: for saving components we have to load all data from all modules
-
-      SALOMEDS::SComponentIterator_var itcomponent1 = aStudy->NewComponentIterator();
-      for (; itcomponent1->More(); itcomponent1->Next())
-       {
-         SALOMEDS::SComponent_var sco = itcomponent1->Value();
-         // if there is an associated Engine call its method for saving
-         CORBA::String_var IOREngine;
-         try {
+      SALOMEDS_SComponentIterator_i aComponentIter = aStudy->GetComponentIterator();
+      for(; aComponentIter.More(); aComponentIter.Next()){
+       SALOMEDS::SComponent_var sco = aComponentIter.Value();
+       // if there is an associated Engine call its method for saving
+       CORBA::String_var IOREngine;
+       try{
+         if(!sco->ComponentIOR(IOREngine)){
+           SALOMEDS::GenericAttribute_var aGeneric;
+           SALOMEDS::AttributeName_var aName;
+           if(sco->FindAttribute(aGeneric, "AttributeName"))
+             aName = SALOMEDS::AttributeName::_narrow(aGeneric);
            
-           if (!sco->ComponentIOR(IOREngine)) {
-             SALOMEDS::GenericAttribute_var aGeneric;
-             SALOMEDS::AttributeName_var aName;
-             if(sco->FindAttribute(aGeneric, "AttributeName"))
-               aName = SALOMEDS::AttributeName::_narrow(aGeneric);
-
-             if (!aName->_is_nil()) {
-               
-               CORBA::String_var aCompType = aName->Value();
-
-               
-               CORBA::String_var aFactoryType;
-               if (strcmp(aCompType, "SUPERV") == 0) aFactoryType = "SuperVisionContainer";
-               else aFactoryType = "FactoryServer";
+           if(!aName->_is_nil()){
+             CORBA::String_var aCompType = aName->Value();
+
+             CORBA::String_var aFactoryType;
+             if(strcmp(aCompType, "SUPERV") == 0) 
+               aFactoryType = "SuperVisionContainer";
+             else
+               aFactoryType = "FactoryServer";
+             
+             Engines::Component_var aComp =
+               SALOME_LifeCycleCORBA(&_name_service).FindOrLoad_Component(aFactoryType, aCompType);
                
+             if(aComp->_is_nil()){
                Engines::Component_var aComp =
-                 SALOME_LifeCycleCORBA(&_name_service).FindOrLoad_Component(aFactoryType, aCompType);
-               
-               if (aComp->_is_nil()) {
-                 Engines::Component_var aComp =
-                   SALOME_LifeCycleCORBA(&_name_service).FindOrLoad_Component("FactoryServerPy", aCompType);
-               }
+                 SALOME_LifeCycleCORBA(&_name_service).FindOrLoad_Component("FactoryServerPy", aCompType);
+             }
                
-               if (!aComp->_is_nil()) {
-                 SALOMEDS::Driver_var aDriver = SALOMEDS::Driver::_narrow(aComp);
-                 if (!CORBA::is_nil(aDriver)) {
-                   SB->LoadWith(sco, aDriver);
-                 }
+             if(!aComp->_is_nil()){
+               SALOMEDS::Driver_var aDriver = SALOMEDS::Driver::_narrow(aComp);
+               if (!CORBA::is_nil(aDriver)) {
+                 SB->LoadWith(sco, aDriver);
                }
              }
            }
-         } catch(...) {
-           MESSAGE("Can not restore information to resave it");
-           return;
          }
+       }catch(...){
+         MESSAGE("Can not restore information to resave it");
+         return;
        }
-
-
+      }
 
       CORBA::String_var anOldName = aStudy->Name();
       aStudy->URL(aUrl);
@@ -739,116 +752,112 @@ void SALOMEDS_StudyManager_i::_SaveAs(const char* aUrl,
       hdf_group_datacomponent = new HDFgroup("DATACOMPONENT",hdf_file);
       hdf_group_datacomponent->CreateOnDisk();
 
-      SALOMEDS::SComponentIterator_var itcomponent = aStudy->NewComponentIterator();
-      
       //SRN: Added 17 Nov, 2003
       SALOMEDS::SObject_var anAutoSaveSO = aStudy->FindObjectID(AUTO_SAVE_TAG);
       //SRN: End
 
-      for (; itcomponent->More(); itcomponent->Next())
-       {
-         SALOMEDS::SComponent_var sco = itcomponent->Value();
+      aComponentIter.Init();
+      for(; aComponentIter.More(); aComponentIter.Next()){
+       SALOMEDS::SComponent_var sco = aComponentIter.Value();
          
-         CORBA::String_var scoid = sco->GetID();
-         hdf_sco_group = new HDFgroup(scoid,hdf_group_datacomponent);
-         hdf_sco_group->CreateOnDisk();
-
-         CORBA::String_var componentDataType = sco->ComponentDataType();
-         MESSAGE ( "Look for  an engine for data type :"<< componentDataType);
-
-         //SRN: Added 17 Nov 2003: If there is a specified attribute, the component peforms a special save       
-         if(!CORBA::is_nil(anAutoSaveSO) && SB->IsGUID(sco, AUTO_SAVE_GUID)) {     
-       
-           SALOMEDS::GenericAttribute_var aGeneric;
-           SALOMEDS::AttributeTableOfString_var aTable;
-           if(anAutoSaveSO->FindAttribute(aGeneric, "AttributeTableOfString")) {
-             aTable = SALOMEDS::AttributeTableOfString::_narrow(aGeneric);
-             Standard_Integer nbRows = aTable->GetNbRows(), k, aTimeOut = 0;
-              if(nbRows > 0 && aTable->GetNbColumns() > 1) {   
-
-               SALOMEDS::StringSeq_var aRow;
-               for(k=1; k<=nbRows; k++) {
-                 aRow = aTable->GetRow(k);
-                 if (strcmp(aRow[0], componentDataType) == 0) {
-                   CORBA::String_var anEntry = CORBA::string_dup(aRow[1]);
-                   SALOMEDS::SObject_var aCompSpecificSO = aStudy->FindObjectID(anEntry);
-                   if(!CORBA::is_nil(aCompSpecificSO)) {
-                     SALOMEDS::AttributeInteger_var anInteger;
-                     if(aCompSpecificSO->FindAttribute(aGeneric, "AttributeInteger")) {
-                       anInteger = SALOMEDS::AttributeInteger::_narrow(aGeneric);
-                       anInteger->SetValue(-1);
-                       while(anInteger->Value() < 0) { sleep(2); if(++aTimeOut > AUTO_SAVE_TIME_OUT_IN_SECONDS) break; }
-                     }  // if(aCompSpecificSO->FindAttribute(anInteger, "AttributeInteger"))
-                   }  // if(!CORBA::is_nil(aCompSpecificSO)) 
-                 }  // if (strcmp(aRow[0], componentDataType) == 0)
-               }  // for
-
-             }  // if(nbRows > 0 && aTable->GetNbColumns() > 1)
-
-           }  // if(anAutoSaveSO->FindAttribute(aTable, "AttributeTableOfString")
-
-         }  // if(SB->IsGUID(AUTO_SAVE_GUID)
-
-         //SRN: End
-
-         CORBA::String_var IOREngine;
-         if (sco->ComponentIOR(IOREngine))
-           {
-             // we have found the associated engine to write the data 
-             MESSAGE ( "We have found an engine for data type :"<< componentDataType);
-             CORBA::Object_var obj = _orb->string_to_object(IOREngine);
-             SALOMEDS::Driver_var Engine = SALOMEDS::Driver::_narrow(obj) ;
+       CORBA::String_var scoid = sco->GetID();
+       hdf_sco_group = new HDFgroup(scoid,hdf_group_datacomponent);
+       hdf_sco_group->CreateOnDisk();
+       
+       CORBA::String_var componentDataType = sco->ComponentDataType();
+       MESSAGE ( "Look for  an engine for data type :"<< componentDataType);
+       
+       //SRN: Added 17 Nov 2003: If there is a specified attribute, the component peforms a special save         
+       if(!CORBA::is_nil(anAutoSaveSO) && SB->IsGUID(sco, AUTO_SAVE_GUID)){        
+         SALOMEDS::GenericAttribute_var aGeneric;
+         SALOMEDS::AttributeTableOfString_var aTable;
+         if(anAutoSaveSO->FindAttribute(aGeneric, "AttributeTableOfString")){
+           aTable = SALOMEDS::AttributeTableOfString::_narrow(aGeneric);
+           Standard_Integer nbRows = aTable->GetNbRows(), k, aTimeOut = 0;
+           if(nbRows > 0 && aTable->GetNbColumns() > 1) {      
+             SALOMEDS::StringSeq_var aRow;
+             for(k=1; k<=nbRows; k++){
+               aRow = aTable->GetRow(k);
+               if(strcmp(aRow[0], componentDataType) == 0){
+                 CORBA::String_var anEntry = CORBA::string_dup(aRow[1]);
+                 SALOMEDS::SObject_var aCompSpecificSO = aStudy->FindObjectID(anEntry);
+                 if(!CORBA::is_nil(aCompSpecificSO)) {
+                   SALOMEDS::AttributeInteger_var anInteger;
+                   if(aCompSpecificSO->FindAttribute(aGeneric, "AttributeInteger")) {
+                     anInteger = SALOMEDS::AttributeInteger::_narrow(aGeneric);
+                     anInteger->SetValue(-1);
+                     while(anInteger->Value() < 0) { sleep(2); if(++aTimeOut > AUTO_SAVE_TIME_OUT_IN_SECONDS) break; }
+                   }  // if(aCompSpecificSO->FindAttribute(anInteger, "AttributeInteger"))
+                 }  // if(!CORBA::is_nil(aCompSpecificSO)) 
+               }  // if (strcmp(aRow[0], componentDataType) == 0)
+             }  // for
              
-             if (!CORBA::is_nil(Engine))
-               {
-                 MESSAGE ( "Save the data of type:"<< componentDataType);
-                 MESSAGE("Engine :"<<Engine->ComponentDataType());
-
-                 SALOMEDS::TMPFile_var aStream;
-
-                  if (theASCII) aStream = Engine->SaveASCII(sco,SALOMEDS_Tool::GetDirFromPath(aUrl).c_str(),theMultiFile);
-                 else aStream = Engine->Save(sco,SALOMEDS_Tool::GetDirFromPath(aUrl).c_str(),theMultiFile);
-
-                 HDFdataset *hdf_dataset;
-                 hdf_size aHDFSize[1];
-                 if(aStream->length() > 0) {  //The component saved some auxiliary files, then put them into HDF file 
-
-                   aHDFSize[0] = aStream->length();
-                     
-                   HDFdataset *hdf_dataset = new HDFdataset("FILE_STREAM", hdf_sco_group, HDF_STRING, aHDFSize, 1);
-                   hdf_dataset->CreateOnDisk();
-                   hdf_dataset->WriteOnDisk((unsigned char*) &aStream[0]);  //Save the stream in the HDF file
-                   hdf_dataset->CloseOnDisk();
-                 }
-                 // store multifile state
-                 aHDFSize[0] = 2;
-                 hdf_dataset = new HDFdataset("MULTIFILE_STATE", hdf_sco_group, HDF_STRING, aHDFSize, 1);
-                 hdf_dataset->CreateOnDisk();
-                 hdf_dataset->WriteOnDisk((void*)(theMultiFile?"M":"S")); // save: multi or single
-                 hdf_dataset->CloseOnDisk();
-                 hdf_dataset=0; //will be deleted by hdf_sco_AuxFiles destructor                
-
-                 // store ASCII state
-                 aHDFSize[0] = 2;
-                 hdf_dataset = new HDFdataset("ASCII_STATE", hdf_sco_group, HDF_STRING, aHDFSize, 1);
-                 hdf_dataset->CreateOnDisk();
-                 hdf_dataset->WriteOnDisk((void*)(theASCII?"A":"B")); // save: ASCII or BINARY
-                 hdf_dataset->CloseOnDisk();
-                 hdf_dataset=0; //will be deleted by hdf_sco_AuxFiles destructor                
-
-                 Translate_IOR_to_persistentID (aStudy,SB,sco,Engine,theMultiFile, theASCII);
-                 MESSAGE("After Translate_IOR_to_persistentID");
-                 
-                 // Creation of the persistance reference  attribute
-               }
+           }  // if(nbRows > 0 && aTable->GetNbColumns() > 1)
+           
+         }  // if(anAutoSaveSO->FindAttribute(aTable, "AttributeTableOfString")
+         
+       }  // if(SB->IsGUID(AUTO_SAVE_GUID)
+       
+       //SRN: End
+       
+       CORBA::String_var IOREngine;
+       if(sco->ComponentIOR(IOREngine)){
+         // we have found the associated engine to write the data 
+         MESSAGE ( "We have found an engine for data type :"<< componentDataType);
+         CORBA::Object_var obj = _orb->string_to_object(IOREngine);
+         SALOMEDS::Driver_var Engine = SALOMEDS::Driver::_narrow(obj) ;
+         
+         if(!CORBA::is_nil(Engine)){
+           MESSAGE ( "Save the data of type:"<< componentDataType);
+           MESSAGE("Engine :"<<Engine->ComponentDataType());
+           
+           SALOMEDS::TMPFile_var aStream;
+           
+           if(theASCII) 
+             aStream = Engine->SaveASCII(sco,SALOMEDS_Tool::GetDirFromPath(aUrl).c_str(),theMultiFile);
+           else
+             aStream = Engine->Save(sco,SALOMEDS_Tool::GetDirFromPath(aUrl).c_str(),theMultiFile);
+
+           HDFdataset *hdf_dataset;
+           hdf_size aHDFSize[1];
+           if(aStream->length() > 0){  //The component saved some auxiliary files, then put them into HDF file 
+             
+             aHDFSize[0] = aStream->length();
+             
+             HDFdataset *hdf_dataset = new HDFdataset("FILE_STREAM", hdf_sco_group, HDF_STRING, aHDFSize, 1);
+             hdf_dataset->CreateOnDisk();
+             hdf_dataset->WriteOnDisk((unsigned char*) &aStream[0]);  //Save the stream in the HDF file
+             hdf_dataset->CloseOnDisk();
            }
-         hdf_sco_group->CloseOnDisk();
-         hdf_sco_group=0; // will be deleted by hdf_group_datacomponent destructor
+           // store multifile state
+           aHDFSize[0] = 2;
+           hdf_dataset = new HDFdataset("MULTIFILE_STATE", hdf_sco_group, HDF_STRING, aHDFSize, 1);
+           hdf_dataset->CreateOnDisk();
+           hdf_dataset->WriteOnDisk((void*)(theMultiFile?"M":"S")); // save: multi or single
+           hdf_dataset->CloseOnDisk();
+           hdf_dataset=0; //will be deleted by hdf_sco_AuxFiles destructor              
+           
+           // store ASCII state
+           aHDFSize[0] = 2;
+           hdf_dataset = new HDFdataset("ASCII_STATE", hdf_sco_group, HDF_STRING, aHDFSize, 1);
+           hdf_dataset->CreateOnDisk();
+           hdf_dataset->WriteOnDisk((void*)(theASCII?"A":"B")); // save: ASCII or BINARY
+           hdf_dataset->CloseOnDisk();
+           hdf_dataset=0; //will be deleted by hdf_sco_AuxFiles destructor              
+           
+           Translate_IOR_to_persistentID(aStudy,SB,sco,Engine,theMultiFile, theASCII);
+           MESSAGE("After Translate_IOR_to_persistentID");
+                 
+           // Creation of the persistance reference  attribute
+         }
        }
+       hdf_sco_group->CloseOnDisk();
+       hdf_sco_group=0; // will be deleted by hdf_group_datacomponent destructor
+      }
       hdf_group_datacomponent->CloseOnDisk();
       hdf_group_datacomponent =0;  // will be deleted by hdf_file destructor
-
-
+      
+      
       //-----------------------------------------------------------------------
       //3 - Write the Study Structure
       //-----------------------------------------------------------------------
@@ -856,36 +865,35 @@ void SALOMEDS_StudyManager_i::_SaveAs(const char* aUrl,
       hdf_group_study_structure->CreateOnDisk();
 
       // save component attributes
-      SALOMEDS::SComponentIterator_var itcomp = aStudy->NewComponentIterator();
-      for (; itcomp->More(); itcomp->Next()) 
-       {
-         SALOMEDS::SComponent_var SC = itcomp->Value();
-         
-         CORBA::String_var scid = SC->GetID();
-         hdf_sco_group2 = new HDFgroup(scid,hdf_group_study_structure);
-         hdf_sco_group2->CreateOnDisk();
-          SaveAttributes(SC, hdf_sco_group2);
-         // ComponentDataType treatment
-         CORBA::String_var component_name = SC->ComponentDataType();
-         MESSAGE("Component data type " << component_name << " treated");
-         
-         name_len = (hdf_int32) strlen(component_name.in());
-         size[0] = name_len +1 ; 
-         hdf_dataset = new HDFdataset("COMPONENTDATATYPE",hdf_sco_group2,HDF_STRING,size,1);
-         hdf_dataset->CreateOnDisk();
-         hdf_dataset->WriteOnDisk(const_cast<char*>(component_name.in()));
-         MESSAGE("component name " <<  component_name << " wrote on file");
-         hdf_dataset->CloseOnDisk();
-         hdf_dataset=0; //will be deleted by hdf_sco_group destructor
-         _SaveObject(aStudy, SC, hdf_sco_group2);
-         hdf_sco_group2->CloseOnDisk();
-         hdf_sco_group2=0; // will be deleted by hdf_group_study_structure destructor
-       }
+      aComponentIter.Init();
+      for(; aComponentIter.More(); aComponentIter.Next()){
+       SALOMEDS::SComponent_var SC = aComponentIter.Value();
+       
+       CORBA::String_var scid = SC->GetID();
+       hdf_sco_group2 = new HDFgroup(scid,hdf_group_study_structure);
+       hdf_sco_group2->CreateOnDisk();
+       SaveAttributes(SC, hdf_sco_group2);
+       // ComponentDataType treatment
+       CORBA::String_var component_name = SC->ComponentDataType();
+       MESSAGE("Component data type " << component_name << " treated");
+       
+       name_len = (hdf_int32) strlen(component_name.in());
+       size[0] = name_len +1 ; 
+       hdf_dataset = new HDFdataset("COMPONENTDATATYPE",hdf_sco_group2,HDF_STRING,size,1);
+       hdf_dataset->CreateOnDisk();
+       hdf_dataset->WriteOnDisk(const_cast<char*>(component_name.in()));
+       MESSAGE("component name " <<  component_name << " wrote on file");
+       hdf_dataset->CloseOnDisk();
+       hdf_dataset=0; //will be deleted by hdf_sco_group destructor
+       _SaveObject(aStudy, SC, hdf_sco_group2);
+       hdf_sco_group2->CloseOnDisk();
+       hdf_sco_group2=0; // will be deleted by hdf_group_study_structure destructor
+      }
       //-----------------------------------------------------------------------
       //4 - Write the Study UseCases Structure
       //-----------------------------------------------------------------------
       SALOMEDS::SObject_var aSO = aStudy->FindObjectID(USE_CASE_LABEL_ID);
-      if (!aSO->_is_nil()) {
+      if(!aSO->_is_nil()){
        HDFgroup *hdf_soo_group = new HDFgroup(USE_CASE_LABEL_ID,hdf_group_study_structure);
        hdf_soo_group->CreateOnDisk();
        SaveAttributes(aSO, hdf_soo_group);
@@ -895,7 +903,8 @@ void SALOMEDS_StudyManager_i::_SaveAs(const char* aUrl,
        hdf_soo_group=0; // will be deleted by hdf_group_study_structure destructor
       }
 
-      if (aLocked) aStudy->GetProperties()->SetLocked(true);
+      if (aLocked) 
+       aStudy->GetProperties()->SetLocked(true);
       //-----------------------------------------------------------------------
       //5 - Write the Study Properties
       //-----------------------------------------------------------------------
@@ -916,18 +925,17 @@ void SALOMEDS_StudyManager_i::_SaveAs(const char* aUrl,
 
       _name_service.Change_Directory("/Study");
       _name_service.Destroy_Name(anOldName);
-      _name_service.Register(aStudy, aStudy->Name());
+      _name_service.Register(theStudy, aStudy->Name());
 
       aStudy->IsSaved(true);
       hdf_group_study_structure =0; // will be deleted by hdf_file destructor
       delete hdf_file; // recursively deletes all hdf objects...
+    }catch(HDFexception){
+      MESSAGE( "HDFexception ! " );
     }
-  catch (HDFexception)
-    {
-      MESSAGE( "HDFexception ! " )
+    if(theASCII){ // save file in ASCII format
+      HDFascii::ConvertFromHDFToASCII(aUrl, true);
     }
-  if (theASCII) { // save file in ASCII format
-    HDFascii::ConvertFromHDFToASCII(aUrl, true);
   }
 }
 
@@ -936,8 +944,8 @@ void SALOMEDS_StudyManager_i::_SaveAs(const char* aUrl,
  *  Purpose  :
  */
 //============================================================================
-void SALOMEDS_StudyManager_i::_SaveObject(SALOMEDS::Study_ptr aStudy, 
-                                         SALOMEDS::SObject_ptr SC
+void SALOMEDS_StudyManager_i::_SaveObject(SALOMEDS_Study_i* theStudy, 
+                                         SALOMEDS::SObject_ptr theSObject
                                          HDFgroup *hdf_group_datatype)
 {
   // Write in group hdf_group_datatype all informations of SObject SC
@@ -945,36 +953,37 @@ void SALOMEDS_StudyManager_i::_SaveObject(SALOMEDS::Study_ptr aStudy,
   SALOMEDS::SObject_var RefSO;
   HDFgroup *hdf_group_sobject = 0;
 
-  SALOMEDS::ChildIterator_var itchild = aStudy->NewChildIterator(SC);
-  for (; itchild->More(); itchild->Next()) 
-    {
-      SALOMEDS::SObject_var SO = itchild->Value();
-
-      // mpv: don't save empty labels
-      if (SO->GetAllAttributes()->length() == 0 && !SO->ReferencedObject(RefSO)) {
-       SALOMEDS::ChildIterator_var subchild = aStudy->NewChildIterator(SC);
-       if (!subchild->More()) {
-         continue;
-       }
-       subchild->InitEx(true);
-       bool anEmpty = true;
-       for (; subchild->More() && anEmpty; subchild->Next()) 
-         if (subchild->Value()->GetAllAttributes()->length() != 0 ||
-              subchild->Value()->ReferencedObject(RefSO)) anEmpty = false;
-       if (anEmpty) {
-         continue;
-       }
+  SALOMEDS_ChildIterator_i aChildIter = theStudy->GetChildIterator(theSObject);
+  for(; aChildIter.More(); aChildIter.Next()){
+    SALOMEDS::SObject_var aSObject = aChildIter.Value();
+    SALOMEDS::ListOfAttributes_var anAllAttributes = aSObject->GetAllAttributes();
+    
+    // mpv: don't save empty labels
+    if(anAllAttributes->length() == 0 && !aSObject->ReferencedObject(RefSO)){
+      SALOMEDS_ChildIterator_i aSubChildIter = theStudy->GetChildIterator(theSObject);
+      if(!aSubChildIter.More())
+       continue;
+
+      aSubChildIter.InitEx(true);
+      bool anEmpty = true;
+      for(; aSubChildIter.More() && anEmpty; aSubChildIter.Next()){
+       SALOMEDS::SObject_var aSObj = aSubChildIter.Value();
+       SALOMEDS::ListOfAttributes_var anAllAttr = aSObj->GetAllAttributes();
+       if(anAllAttr->length() != 0 || aSObj->ReferencedObject(RefSO)) 
+         anEmpty = false;
       }
-
-      CORBA::String_var scoid(SO->GetID());
-      hdf_group_sobject = new HDFgroup(scoid,hdf_group_datatype);
-      hdf_group_sobject->CreateOnDisk();
-      SaveAttributes(SO, hdf_group_sobject);
-      _SaveObject(aStudy,SO, hdf_group_sobject);
-      hdf_group_sobject->CloseOnDisk();
-      hdf_group_sobject =0; // will be deleted by father hdf object destructor
-
+      if(anEmpty)
+       continue;
     }
+
+    CORBA::String_var scoid(aSObject->GetID());
+    hdf_group_sobject = new HDFgroup(scoid,hdf_group_datatype);
+    hdf_group_sobject->CreateOnDisk();
+    SaveAttributes(aSObject, hdf_group_sobject);
+    _SaveObject(theStudy,aSObject, hdf_group_sobject);
+    hdf_group_sobject->CloseOnDisk();
+    hdf_group_sobject =0; // will be deleted by father hdf object destructor
+  }
 }
 
 //============================================================================
index 7b11df5ef50a226b62f88858c04b485411fb05bc..a6e4c9e6cb748880cb0603ead29b89cdb3090187 100644 (file)
@@ -87,13 +87,13 @@ private:
                       CORBA::Boolean theMultiFile,
                       CORBA::Boolean theASCII);
   // _SaveObject private function called by _SaveAs
-  virtual void _SaveObject(SALOMEDS::Study_ptr aStudy, 
-                          SALOMEDS::SObject_ptr SC, 
-                          HDFgroup *hdf_group_datatype);
+  void _SaveObject(SALOMEDS_Study_i* theStudy, 
+                  SALOMEDS::SObject_ptr SC, 
+                  HDFgroup *hdf_group_datatype);
   // _SubstituteSlash function called by Open and GetStudyByName
   virtual std::string _SubstituteSlash(const char *aUrl);
 
-  virtual void _SaveProperties(SALOMEDS::Study_ptr aStudy, HDFgroup *hdf_group);
+  void _SaveProperties(SALOMEDS_Study_i* theStudy, HDFgroup *hdf_group);
 
 public:
   //! standard constructor
@@ -106,6 +106,8 @@ public:
 
   PortableServer::POA_var GetPOA() const { return _poa; }
 
+  SALOMEDS_Study_i* DownCast(SALOMEDS::Study_ptr theStudy) const;
+
  //! method to Register study Manager in the naming service
   /*!
     \param char* arguments, the context to register the study manager in the NS
index 9345988002fe8e82905ff5da059c27f7be3da5f9..1f8e0aa75067bc52597819a1a6e0a3bb702dd13a 100644 (file)
@@ -162,6 +162,19 @@ PortableServer::POA_var SALOMEDS_Study_i::GetPOA() const
   return _StudyManager->GetPOA();
 }
 
+
+SALOMEDS_SObject_i* 
+SALOMEDS_Study_i::DownCast(SALOMEDS::SObject_ptr theSObject) const
+{
+  if(!CORBA::is_nil(theSObject)){
+    PortableServer::POA_var aPOA = GetPOA();
+    PortableServer::ServantBase_var aServant = SALOMEDS::GetServant(theSObject,aPOA);
+    if(aServant.in())
+      return dynamic_cast<SALOMEDS_SObject_i*>(aServant.in());
+  }
+  return NULL;
+}
+
 //============================================================================
 /*! Function : SetOnAddSObject
  *  Purpose  : 
@@ -443,14 +456,18 @@ SALOMEDS::SObject_ptr SALOMEDS_Study_i::FindObjectIOR(const char* theObjectIOR)
 {
   // firstly searching in the datamap for optimization
   char* anIOR = const_cast<char*>(theObjectIOR);
-  if (myIORLabels.IsBound(anIOR)) {
-    SALOMEDS::SObject_var aResult = SALOMEDS_SObject_i::NewRef(this,myIORLabels.Find(anIOR));
+  if(myIORLabels.IsBound(anIOR)){
+    TDF_Label aLabel = myIORLabels.Find(anIOR);
+    TSObjectHolder aSObjectHolder = SALOMEDS_SObject_i::New(this,aLabel);
+    SALOMEDS_SObject_i* aSObjectPtr = aSObjectHolder.first;
+    SALOMEDS::SObject_var aSObject = aSObjectHolder.second;
     // 11 oct 2002: forbidden attributes must be checked here
     SALOMEDS::GenericAttribute_var anAttr;
-    if (!aResult->FindAttribute(anAttr,"AttributeIOR")) {
+    if(!aSObjectPtr->FindAttribute(anAttr,"AttributeIOR")){
       myIORLabels.UnBind(anIOR);
-    } else 
-      return aResult._retn();
+    }else{
+      return aSObject._retn();
+    }
   }
 
   // Iterate to all components defined in the study
@@ -782,29 +799,43 @@ SALOMEDS::ListOfStrings* SALOMEDS_Study_i::GetComponentNames(const char* theCont
  *  Purpose  : Create a ChildIterator from an SObject
  */
 //============================================================================
-SALOMEDS::ChildIterator_ptr SALOMEDS_Study_i::NewChildIterator(SALOMEDS::SObject_ptr aSO)
+SALOMEDS::ChildIterator_ptr 
+SALOMEDS_Study_i::NewChildIterator(SALOMEDS::SObject_ptr theSObject)
 {
-  //Convert aSO->GetID in TDF_Label.
-  TDF_Label Lab;
-  TDF_Tool::Label(_doc->GetData(), aSO->GetID(), Lab);
+  SALOMEDS_ChildIterator_i* aServant = 
+    new SALOMEDS_ChildIterator_i(GetChildIterator(theSObject));
 
-  //Create iterator
-  SALOMEDS_ChildIterator_i* aServant = new SALOMEDS_ChildIterator_i(this,Lab);
   return aServant->_this();
 }
 
+SALOMEDS_ChildIterator_i 
+SALOMEDS_Study_i::GetChildIterator(SALOMEDS::SObject_ptr theSObject)
+{
+  TDF_Label aLab;
+  TDF_Tool::Label(_doc->GetData(),theSObject->GetID(),aLab);
+  return SALOMEDS_ChildIterator_i(this,aLab);
+}
 
 //============================================================================
 /*! Function : NewComponentIterator
  *  Purpose  : Create a SComponentIterator
  */
 //============================================================================
-SALOMEDS::SComponentIterator_ptr SALOMEDS_Study_i::NewComponentIterator()
+SALOMEDS::SComponentIterator_ptr 
+SALOMEDS_Study_i::NewComponentIterator()
 {
-  SALOMEDS_SComponentIterator_i* aServant = new SALOMEDS_SComponentIterator_i(this,_doc);
+  SALOMEDS_SComponentIterator_i* aServant = 
+    new SALOMEDS_SComponentIterator_i(GetComponentIterator());
+
   return aServant->_this();
 }
 
+SALOMEDS_SComponentIterator_i 
+SALOMEDS_Study_i::GetComponentIterator()
+{
+  return SALOMEDS_SComponentIterator_i(this,_doc);
+}
+
 //============================================================================
 /*! Function : GetUseCaseBuilder
  *  Purpose  : Returns a UseCase builder
@@ -820,9 +851,14 @@ SALOMEDS::UseCaseBuilder_ptr SALOMEDS_Study_i::GetUseCaseBuilder()
  *  Purpose  : Create a StudyBuilder
  */
 //============================================================================
+SALOMEDS_StudyBuilder_i* SALOMEDS_Study_i::GetBuilder()
+{
+  return _Builder;
+}
 SALOMEDS::StudyBuilder_ptr SALOMEDS_Study_i::NewBuilder()
 {
-  return _Builder->_this();
+  return GetBuilder()->_this();
 }
  
 //============================================================================
@@ -994,25 +1030,11 @@ void SALOMEDS_Study_i::UpdateIORLabelMap(const char* anIOR,const char* anEntry)
   myIORLabels.Bind(TCollection_ExtendedString(IOR), aLabel);
 }
 
-SALOMEDS::Study_ptr SALOMEDS_Study_i::GetStudy(const TDF_Label theLabel, CORBA::ORB_ptr orb) {
-  Handle(SALOMEDS_IORAttribute) Att;
-  if (theLabel.Root().FindAttribute(SALOMEDS_IORAttribute::GetID(),Att)){
-    char* IOR = CORBA::string_dup(TCollection_AsciiString(Att->Get()).ToCString());
-    CORBA::Object_var obj = orb->string_to_object(IOR);
-    SALOMEDS::Study_ptr aStudy = SALOMEDS::Study::_narrow(obj) ;
-    ASSERT(!CORBA::is_nil(aStudy));
-    return SALOMEDS::Study::_duplicate(aStudy);
-  } else {
-    MESSAGE("GetStudy: Problem to get study");
-  }
-  return SALOMEDS::Study::_nil();
-}
-
-void SALOMEDS_Study_i::IORUpdated(const Handle(SALOMEDS_IORAttribute) theAttribute, CORBA::ORB_ptr orb) {
+void SALOMEDS_Study_i::IORUpdated(const Handle(SALOMEDS_IORAttribute) theAttribute) {
   TCollection_AsciiString aString;
-  TDF_Tool::Entry(theAttribute->Label(), aString);
-  GetStudy(theAttribute->Label(), orb)->UpdateIORLabelMap(TCollection_AsciiString(theAttribute->Get()).ToCString(),
-                                                         aString.ToCString());
+  TDF_Tool::Entry(theAttribute->Label(),aString);
+  TCollection_AsciiString aValue(theAttribute->Get());
+  UpdateIORLabelMap(aValue.ToCString(),aString.ToCString());
 }
 
 SALOMEDS::Study::ListOfSObject* SALOMEDS_Study_i::FindDependances(SALOMEDS::SObject_ptr anObject) {
@@ -1026,9 +1048,12 @@ SALOMEDS::Study::ListOfSObject* SALOMEDS_Study_i::FindDependances(SALOMEDS::SObj
 }
 
 
-SALOMEDS::AttributeStudyProperties_ptr SALOMEDS_Study_i::GetProperties() {
-  SALOMEDS::GenericAttribute_ptr anAttr =  NewBuilder()->FindOrCreateAttribute(FindObjectID("0:1"),
-                                                                              "AttributeStudyProperties");
+SALOMEDS::AttributeStudyProperties_ptr SALOMEDS_Study_i::GetProperties(){
+  SALOMEDS::SObject_var aSObject = FindObjectID("0:1");
+
+  SALOMEDS::GenericAttribute_var anAttr =  
+    GetBuilder()->FindOrCreateAttribute(aSObject,"AttributeStudyProperties");
+
   return SALOMEDS::AttributeStudyProperties::_narrow(anAttr);
 }
 
@@ -1111,7 +1136,7 @@ void SALOMEDS_Study_i::Close()
  */
  //============================================================================
 void SALOMEDS_Study_i::AddPostponed(const char* theIOR) {
-  if (!NewBuilder()->HasOpenCommand()) return;
+  if (!GetBuilder()->HasOpenCommand()) return;
   try {
     CORBA::Object_var obj = GetORB()->string_to_object(theIOR);
     if (!CORBA::is_nil(obj)) {
@@ -1127,7 +1152,7 @@ void SALOMEDS_Study_i::AddPostponed(const char* theIOR) {
 }
 
 void SALOMEDS_Study_i::AddCreatedPostponed(const char* theIOR) {
-  if (!NewBuilder()->HasOpenCommand()) return;
+  if (!GetBuilder()->HasOpenCommand()) return;
   try {
     CORBA::Object_var obj = GetORB()->string_to_object(theIOR);
     if (!CORBA::is_nil(obj)) {
index bbb151bab04ff7965017292d30b06ac7ee5c6a40..18b9ef8fbc2cbbdb74eb7b0205374440bcc3d092 100644 (file)
@@ -49,6 +49,9 @@
 #include "SALOMEDS_DataMapStringLabel.hxx"
 #include "SALOMEDS_IORAttribute.hxx"
 
+#include "SALOMEDS_SComponentIterator_i.hxx"
+#include "SALOMEDS_ChildIterator_i.hxx"
+
 class SALOMEDS_StudyManager_i;
 class SALOMEDS_UseCaseBuilder_i;
 class SALOMEDS_StudyBuilder_i;
@@ -82,7 +85,9 @@ public:
   CORBA::ORB_var GetORB() const;
 
   PortableServer::POA_var GetPOA() const;
-  
+
+  SALOMEDS_SObject_i* DownCast(SALOMEDS::SObject_ptr theSObject) const;
+
   SALOMEDS::Callback_ptr SetOnAddSObject(SALOMEDS::Callback_ptr theCallback);
 
   SALOMEDS::Callback_ptr SetOnRemoveSObject(SALOMEDS::Callback_ptr theCallback);
@@ -220,17 +225,20 @@ public:
     \return ChildIterator_ptr arguments, the created ChildIterator
   */  
   virtual SALOMEDS::ChildIterator_ptr NewChildIterator(SALOMEDS::SObject_ptr aSO);
+  SALOMEDS_ChildIterator_i GetChildIterator(SALOMEDS::SObject_ptr theSObject);
 
   //! method to Create a SComponentIterator 
   /*!
     \return SComponentIterator_ptr arguments, the created SComponentIterator
   */  
   virtual SALOMEDS::SComponentIterator_ptr NewComponentIterator();
+  SALOMEDS_SComponentIterator_i GetComponentIterator();
 
   //! method to Create a StudyBuilder
   /*!
     \return StudyBuilder_ptr arguments, the created StudyBuilder
   */  
+  SALOMEDS_StudyBuilder_i* GetBuilder();
   virtual SALOMEDS::StudyBuilder_ptr NewBuilder();
  
   //! method to get study name
@@ -278,9 +286,7 @@ public:
   virtual CORBA::Short StudyId();
   virtual void  StudyId(CORBA::Short id);
 
-  static SALOMEDS::Study_ptr GetStudy(const TDF_Label theLabel, CORBA::ORB_ptr orb);
-
-  static void IORUpdated(const Handle(SALOMEDS_IORAttribute) theAttribute, CORBA::ORB_ptr orb);
+  void IORUpdated(const Handle(SALOMEDS_IORAttribute) theAttribute);
 
   virtual void UpdateIORLabelMap(const char* anIOR, const char* aLabel);