]> SALOME platform Git repositories - modules/kernel.git/commitdiff
Salome HOME
Fix on [Bug PAL7023] Problem loading MED file with a large number of families (same...
authorapo <apo@opencascade.com>
Tue, 18 Jan 2005 10:39:44 +0000 (10:39 +0000)
committerapo <apo@opencascade.com>
Tue, 18 Jan 2005 10:39:44 +0000 (10:39 +0000)
15 files changed:
src/SALOMEDS/SALOMEDS_AttributeTarget_i.cxx
src/SALOMEDS/SALOMEDS_ChildIterator_i.cxx
src/SALOMEDS/SALOMEDS_ChildIterator_i.hxx
src/SALOMEDS/SALOMEDS_SComponentIterator_i.cxx
src/SALOMEDS/SALOMEDS_SComponentIterator_i.hxx
src/SALOMEDS/SALOMEDS_SComponent_i.cxx
src/SALOMEDS/SALOMEDS_SComponent_i.hxx
src/SALOMEDS/SALOMEDS_SObject_i.cxx
src/SALOMEDS/SALOMEDS_SObject_i.hxx
src/SALOMEDS/SALOMEDS_StudyBuilder_i.cxx
src/SALOMEDS/SALOMEDS_StudyManager_i.cxx
src/SALOMEDS/SALOMEDS_Study_i.cxx
src/SALOMEDS/SALOMEDS_Study_i.hxx
src/SALOMEDS/SALOMEDS_UseCaseBuilder_i.cxx
src/SALOMEDS/SALOMEDS_UseCaseIterator_i.cxx

index 80b1c2e66a8ba7c2b952c349eb05ce883c53e9fd..70f7b81b920ef1d04812a3412ddf4a17d819d3c4 100644 (file)
@@ -57,8 +57,7 @@ SALOMEDS::Study::ListOfSObject* SALOMEDS_AttributeTarget_i::Get() {
   SALOMEDS_Study_i* aStudy = _mySObject->GetStudyServant();
   for(int index = 0; anIter.More(); anIter.Next(), index++){
     const TDF_Label& aLabel = anIter.Value();
-    SALOMEDS_SObject_i* anSO = SALOMEDS_SObject_i::New(aStudy,aLabel);
-    aSList[index] = anSO->_this();
+    aSList[index] = SALOMEDS_SObject_i::NewRef(aStudy,aLabel)._retn();
   }
   return aSList._retn();
 }
index c1dca11d9f41fd6e6a46322d83ea747f99b91d05..6396ada74e12ca7840cdd9836a000887b5f0556d 100644 (file)
@@ -40,14 +40,14 @@ using namespace std;
  */
 //============================================================================
 SALOMEDS_ChildIterator_i::SALOMEDS_ChildIterator_i(SALOMEDS_Study_i* theStudy,
-                                                  const TDF_Label& theLabel): 
-  _it(theLabel),
+                                                  const TDF_Label& theLabel,
+                                                  bool theIsAllLevels): 
+  _it(theLabel,theIsAllLevels),
   _lab(theLabel),
   _study(theStudy)
 {
   TCollection_AsciiString anEntry;
   TDF_Tool::Entry(theLabel,anEntry);
-  //cout<<"SALOMEDS_ChildIterator_i::New - "<<anEntry.ToCString()<<endl;
 }
 
 //============================================================================
@@ -99,7 +99,6 @@ void SALOMEDS_ChildIterator_i::Next()
   _it.Next();
   TCollection_AsciiString anEntry;
   TDF_Tool::Entry(_it.Value(),anEntry);
-  //cout<<"SALOMEDS_ChildIterator_i::Next - "<<anEntry.ToCString()<<endl;
 }
 
 
@@ -111,6 +110,6 @@ void SALOMEDS_ChildIterator_i::Next()
 
 SALOMEDS::SObject_ptr SALOMEDS_ChildIterator_i::Value()
 {
-  return SALOMEDS_SObject_i::New(_study,_it.Value())->_this();
+  return SALOMEDS_SObject_i::NewRef(_study,_it.Value())._retn();
 }
 
index cf9b71ce971bc4315db27423ca37a9c85d7e1ef4..083fd9935d62f3aecf8e121720110dfa623c3969 100644 (file)
@@ -52,10 +52,13 @@ private:
 
 public:
   SALOMEDS_ChildIterator_i(SALOMEDS_Study_i* theStudy,
-                          const TDF_Label& theLabel);
+                          const TDF_Label& theLabel,
+                          bool theIsAllLevels = false);
 
   ~SALOMEDS_ChildIterator_i();
   
+  TDF_Label GetValue() { return _it.Value();}
+
   virtual void Init();
   virtual void InitEx(CORBA::Boolean);
   virtual CORBA::Boolean More();
index 541d90b493dc4ab09fe247fb0b952d859c491a42..adf77476a5223f2cf658c074305075e77924ff40 100644 (file)
@@ -97,6 +97,6 @@ void SALOMEDS_SComponentIterator_i::Next()
 //============================================================================
 SALOMEDS::SComponent_ptr SALOMEDS_SComponentIterator_i::Value()
 {
-  return SALOMEDS_SComponent_i::New(_study,_it.Value())->_this();
+  return SALOMEDS_SComponent_i::NewRef(_study,_it.Value())._retn();
 }
 
index ca2f51f478fca7e7e255035ca7b6273193569f63..919f65fabe5b3d59bf920863b5197c85b3090dc6 100644 (file)
@@ -57,6 +57,8 @@ public:
   
   ~SALOMEDS_SComponentIterator_i();
   
+  TDF_Label GetValue() { return _it.Value();}
+
   virtual void Init();
   virtual CORBA::Boolean More();
   virtual void Next();
index 53cfc55503879957f78cf02c81b6dc2a6baddbd8..c9cc82ac6ca69a5b3dca9426020a60f7525fa18f 100644 (file)
 
 using namespace std;
 
-SALOMEDS_SComponent_i* SALOMEDS_SComponent_i::New(SALOMEDS_Study_i* theStudy,
-                                                 const TDF_Label& theLabel)
+SALOMEDS_Study_i::TSObjectHolder 
+SALOMEDS_SComponent_i::New(SALOMEDS_Study_i* theStudy,
+                          const TDF_Label& theLabel)
 {
-  SALOMEDS_SComponent_i* aSComponent = NULL;
+  SALOMEDS_Study_i::TSObjectHolder aSObjectHolder;
   SALOMEDS_Study_i::TSObjectMap& anSObjectMap = theStudy->GetSObjectMap();
   SALOMEDS_Study_i::TSObjectMap::const_iterator anIter = anSObjectMap.find(theLabel);
-  //cout<<"SALOMEDS_SComponent_i::New - "<<theLabel.Tag()<<" - "<<anSObjectMap.size()<<endl;
   if(anIter != anSObjectMap.end()){
-    SALOMEDS_SObject_i* aSObject = anIter->second;
-    aSComponent = dynamic_cast<SALOMEDS_SComponent_i*>(aSObject);
+    aSObjectHolder = anIter->second;
+    SALOMEDS_SObject_i* aSObject = aSObjectHolder.first;
+    if(dynamic_cast<SALOMEDS_SComponent_i*>(aSObject))
+      return aSObjectHolder;
   }
-  if(aSComponent == NULL){
-    aSComponent = new SALOMEDS_SComponent_i(theStudy,theLabel);
-    anSObjectMap[theLabel] = aSComponent;
-  }
-  return aSComponent;
+  TCollection_AsciiString anEntry;
+  TDF_Tool::Entry(theLabel,anEntry);
+  SALOMEDS_SComponent_i* aSComponent = new SALOMEDS_SComponent_i(theStudy,theLabel);
+  aSObjectHolder.first = aSComponent;
+  aSObjectHolder.second = aSComponent->_this();
+  anSObjectMap[theLabel] = aSObjectHolder;
+
+  return aSObjectHolder;
+}
+
+SALOMEDS_SComponent_i*
+SALOMEDS_SComponent_i::NewPtr(SALOMEDS_Study_i* theStudy,
+                             const TDF_Label& theLabel)
+{
+  return dynamic_cast<SALOMEDS_SComponent_i*>(New(theStudy,theLabel).first);
+}
+
+SALOMEDS::SComponent_var
+SALOMEDS_SComponent_i::NewRef(SALOMEDS_Study_i* theStudy,
+                             const TDF_Label& theLabel)
+{
+  return SALOMEDS::SComponent::_narrow(New(theStudy,theLabel).second);
 }
 
 //============================================================================
index 3373a4175265dc8e5f774c3720cc463823d562ce..1018b7bb5ad69b3568840846e8cb1c0ad6375dbd 100644 (file)
@@ -41,9 +41,22 @@ class SALOMEDS_SComponent_i: public virtual POA_SALOMEDS::SComponent,
                        const TDF_Label& theLabel);
   
 public:
-  static SALOMEDS_SComponent_i* New(SALOMEDS_Study_i* theStudy,
-                                   const TDF_Label& theLabel);
-  
+
+  static 
+  SALOMEDS_Study_i::TSObjectHolder 
+  New(SALOMEDS_Study_i* theStudy,
+      const TDF_Label& theLabel);
+
+  static 
+  SALOMEDS_SComponent_i* 
+  NewPtr(SALOMEDS_Study_i* theStudy,
+        const TDF_Label& theLabel);
+
+  static 
+  SALOMEDS::SComponent_var 
+  NewRef(SALOMEDS_Study_i* theStudy,
+        const TDF_Label& theLabel);
+
   ~SALOMEDS_SComponent_i();
   
   virtual char* ComponentDataType();
index 62b2f3d89077cb89cae6c7ab19454368010d7fdb..5d6e163825e2b97cedfc328308e12615355ace29 100644 (file)
@@ -276,22 +276,38 @@ namespace SALOMEDS{
 }  
   
 //============================================================================
-SALOMEDS_SObject_i* SALOMEDS_SObject_i::New(SALOMEDS_Study_i* theStudy,
-                                           const TDF_Label& theLabel)
+SALOMEDS_Study_i::TSObjectHolder
+SALOMEDS_SObject_i::New(SALOMEDS_Study_i* theStudy,
+                       const TDF_Label& theLabel)
 {
-  SALOMEDS_SObject_i* aSObject = NULL;
+  SALOMEDS_Study_i::TSObjectHolder aSObjectHolder;
   SALOMEDS_Study_i::TSObjectMap& anSObjectMap = theStudy->GetSObjectMap();
   SALOMEDS_Study_i::TSObjectMap::const_iterator anIter = anSObjectMap.find(theLabel);
   if(anIter != anSObjectMap.end())
-    aSObject = anIter->second;
+    aSObjectHolder = anIter->second;
   else{
     TCollection_AsciiString anEntry;
     TDF_Tool::Entry(theLabel,anEntry);
-    //cout<<"SALOMEDS_SObject_i::New - "<<anEntry.ToCString()<<endl;
-    aSObject = new SALOMEDS_SObject_i(theStudy,theLabel);
-    anSObjectMap[theLabel] = aSObject;
+    SALOMEDS_SObject_i* aSObject = new SALOMEDS_SObject_i(theStudy,theLabel);
+    aSObjectHolder.first = aSObject;
+    aSObjectHolder.second = aSObject->_this();
+    anSObjectMap[theLabel] = aSObjectHolder;
   }
-  return aSObject;
+  return aSObjectHolder;
+}
+
+SALOMEDS_SObject_i*
+SALOMEDS_SObject_i::NewPtr(SALOMEDS_Study_i* theStudy,
+                          const TDF_Label& theLabel)
+{
+  return New(theStudy,theLabel).first;
+}
+
+SALOMEDS::SObject_var
+SALOMEDS_SObject_i::NewRef(SALOMEDS_Study_i* theStudy,
+                          const TDF_Label& theLabel)
+{
+  return New(theStudy,theLabel).second;
 }
 
 //============================================================================
@@ -353,7 +369,7 @@ SALOMEDS::SComponent_ptr SALOMEDS_SObject_i::GetFatherComponent()
   while(!SALOMEDS_SComponent_i::IsA(aSCompLabel) && !aSCompLabel.IsRoot()){
     aSCompLabel = aSCompLabel.Father();
   }
-  return SALOMEDS_SComponent_i::New(_study,aSCompLabel)->_this();
+  return SALOMEDS_SComponent_i::NewRef(_study,aSCompLabel)._retn();
 }
   
 //============================================================================
@@ -363,7 +379,7 @@ SALOMEDS::SComponent_ptr SALOMEDS_SObject_i::GetFatherComponent()
 //============================================================================
 SALOMEDS::SObject_ptr SALOMEDS_SObject_i::GetFather()
 {
-  return SALOMEDS_SObject_i::New(_study,_lab.Father())->_this();
+  return SALOMEDS_SObject_i::NewRef(_study,_lab.Father())._retn();
 }
 
 //============================================================================
@@ -387,7 +403,7 @@ CORBA::Boolean SALOMEDS_SObject_i::ReferencedObject(SALOMEDS::SObject_out theSOb
   if (!_lab.FindAttribute(TDF_Reference::GetID(),aRef))
     return false;
   
-  theSObject = SALOMEDS_SObject_i::New(_study,aRef->Get())->_this(); 
+  theSObject = SALOMEDS_SObject_i::NewRef(_study,aRef->Get())._retn(); 
   return true;
 }
 
@@ -402,7 +418,7 @@ CORBA::Boolean SALOMEDS_SObject_i::FindSubObject(CORBA::Long theTag, SALOMEDS::S
   if(aLabel.IsNull()) 
     return false;
   
-  theSObject = SALOMEDS_SObject_i::New(_study,aLabel)->_this(); 
+  theSObject = SALOMEDS_SObject_i::NewRef(_study,aLabel)._retn(); 
   return true;
 }  
 
index d7562acf75dc68096bb94f1798d8cfdca2be1c55..2f28e74c2c12131545b5654b1bee667902656686 100644 (file)
 #include <TDocStd_Document.hxx>
 #include <Standard_GUID.hxx>
 
+#include "SALOMEDS_Study_i.hxx"
+
 // IDL headers
 #include <SALOMEconfig.h>
 #include CORBA_SERVER_HEADER(SALOMEDS)
 
-class SALOMEDS_Study_i;
 class SALOMEDS_GenericAttribute_i;
 
 
@@ -60,8 +61,20 @@ class SALOMEDS_SObject_i: public virtual POA_SALOMEDS::SObject,
                          public virtual PortableServer::RefCountServantBase 
 {
 public:
-  static SALOMEDS_SObject_i* New(SALOMEDS_Study_i* theStudy,
-                                const TDF_Label& theLabel);
+  static 
+  SALOMEDS_Study_i::TSObjectHolder 
+  New(SALOMEDS_Study_i* theStudy,
+      const TDF_Label& theLabel);
+
+  static 
+  SALOMEDS_SObject_i* 
+  NewPtr(SALOMEDS_Study_i* theStudy,
+        const TDF_Label& theLabel);
+
+  static 
+  SALOMEDS::SObject_var 
+  NewRef(SALOMEDS_Study_i* theStudy,
+        const TDF_Label& theLabel);
 
   virtual SALOMEDS::SObject_ptr GetFather() ;
   virtual SALOMEDS::SComponent_ptr GetFatherComponent();
index e875fb894a1c5e10ef913e57d4231c282500a3bc..143d3c0b7eb38a9c6e2bbc8b97cb8108cdd1fe88 100644 (file)
@@ -131,8 +131,7 @@ SALOMEDS_StudyBuilder_i::NewComponent(const char* DataType)
    TDataStd_Comment::Set(NL,Standard_CString(DataType));
    //  TDataStd_Comment::Set(NL,Standard_CString(CORBA::string_dup(DataType)));
 
-  SALOMEDS_SComponent_i* aServant = SALOMEDS_SComponent_i::New(_study,NL);
-  SALOMEDS::SComponent_var aSComponent = aServant->_this(); 
+  SALOMEDS::SComponent_var aSComponent = SALOMEDS_SComponent_i::NewRef(_study,NL); 
 
   OnAddSObject(aSComponent);
 
@@ -204,8 +203,7 @@ SALOMEDS_StudyBuilder_i::NewObject(SALOMEDS::SObject_ptr theFatherObject)
   imax++;
   TDF_Label aNewLabel = aLabel.FindChild(imax);
   
-  SALOMEDS_SObject_i* aServant = SALOMEDS_SObject_i::New(_study,aNewLabel);
-  SALOMEDS::SObject_var aSObject = aServant->_this(); 
+  SALOMEDS::SObject_var aSObject = SALOMEDS_SObject_i::NewRef(_study,aNewLabel); 
 
   OnAddSObject(aSObject);
 
@@ -234,8 +232,7 @@ SALOMEDS_StudyBuilder_i::NewObjectToTag(SALOMEDS::SObject_ptr theFatherObject,
   //Create or find label
   TDF_Label aNewLab = Lab.FindChild(theTag,1);
 
-  SALOMEDS_SObject_i* aServant = SALOMEDS_SObject_i::New(_study,aNewLab);
-  SALOMEDS::SObject_var aSObject = aServant->_this(); 
+  SALOMEDS::SObject_var aSObject = SALOMEDS_SObject_i::NewRef(_study,aNewLab); 
 
   OnAddSObject(aSObject);
 
@@ -353,8 +350,7 @@ static void  Translate_persistentID_to_IOR(TDF_Label theLabel,
       TCollection_ExtendedString res = Handle(TDataStd_Comment)::DownCast(anAttr)->Get();
       TCollection_AsciiString ch(res);
       
-      SALOMEDS_SObject_i* aServant = SALOMEDS_SObject_i::New(theStudy,aCurrentLabel);
-      SALOMEDS::SObject_var aSObject = aServant->_this(); 
+      SALOMEDS::SObject_var aSObject = SALOMEDS_SObject_i::NewRef(theStudy,aCurrentLabel); 
 
       CORBA::String_var anIOR = 
        theDriver->LocalPersistentIDToIOR(aSObject,ch.ToCString(),theIsMultiFile,theIsASCII);
@@ -671,8 +667,7 @@ void SALOMEDS_StudyBuilder_i::AddDirectory(const char* thePath)
   TCollection_AsciiString aPath(CORBA::string_dup(thePath)), aContext(""), aFatherPath;
   Handle(TDataStd_Name) aName;
   TDF_Label aLabel;
-  SALOMEDS_SObject_i* aServant = SALOMEDS_SObject_i::New(_study,_doc->Main());
-  SALOMEDS::SObject_var anObject = aServant->_this(); 
+  SALOMEDS::SObject_var anObject = SALOMEDS_SObject_i::NewRef(_study,_doc->Main()); 
   SALOMEDS::Study_var aStudy = anObject->GetStudy();
 
   try { 
index 2da9950d8a249afe2365c5b5ea098f00a80494f8..5030d08803b1a680caceb6a49ffc66806bfc9068 100644 (file)
@@ -1343,7 +1343,5 @@ SALOMEDS::SObject_ptr SALOMEDS_StudyManager_i::Paste(SALOMEDS::SObject_ptr theOb
     PasteLabel(aStudy,anEngine,anIterator.Value(),aStartLabel,aCStudyID,false);
   }
 
-  SALOMEDS_SObject_i* aSObjectServant = SALOMEDS_SObject_i::New(aStudy,aStartLabel);
-
-  return aSObjectServant->_this();
+  return SALOMEDS_SObject_i::NewRef(aStudy,aStartLabel)._retn();
 }
index e8161cc02f6132906ddaad8f5a3236f211f0c07d..9345988002fe8e82905ff5da059c27f7be3da5f9 100644 (file)
@@ -44,6 +44,8 @@
 
 #include "SALOMEDS_StudyManager_i.hxx"
 #include "SALOMEDS_Callback_i.hxx"
+
+#include "SALOMEDS_SComponent_i.hxx"
 #include "SALOMEDS_SObject_i.hxx"
 
 #include "SALOMEDS_StudyBuilder_i.hxx"
 
 using namespace std;
 
-
 bool operator<(const TDF_Label& theLeft, const TDF_Label& theRight)
 {
   TColStd_ListOfInteger aTagLeftList;
   TDF_Tool::TagList(theLeft,aTagLeftList);
   TColStd_ListIteratorOfListOfInteger anLeftIter(aTagLeftList);
-
+  
   TColStd_ListOfInteger aTagRightList;
   TDF_Tool::TagList(theRight,aTagRightList);
   TColStd_ListIteratorOfListOfInteger anRightIter(aTagRightList);
-
+  
   for(;;){
     Standard_Boolean aLeftMore = anLeftIter.More();
     Standard_Boolean aRightMore = anRightIter.More();
     
     if(!aLeftMore && !aRightMore)
       return Standard_False;
-
+    
     if(!aLeftMore)
       return Standard_True;
-
+    
     if(!aRightMore)
       return Standard_False;
-
+    
     Standard_Integer aLeftTag = anLeftIter.Value();
     anLeftIter.Next();
-
+    
     Standard_Integer aRightTag = anRightIter.Value();
     anRightIter.Next();
-
+    
     if(aLeftTag == aRightTag)
       continue;
-
+    
     return aLeftTag < aRightTag;
   }
-
+  
   return Standard_False;
 }
 
-
+  
 //============================================================================
 /*! Function : SALOMEDS_Study_i
  *  Purpose  : SALOMEDS_Study_i constructor
@@ -272,26 +273,21 @@ CORBA::Boolean SALOMEDS_Study_i::IsEmpty()
  *  Purpose  : Find a Component with ComponentDataType = aComponentName
  */
 //============================================================================
-SALOMEDS::SComponent_ptr SALOMEDS_Study_i::FindComponent (const char* aComponentName)
+SALOMEDS::SComponent_ptr 
+SALOMEDS_Study_i::FindComponent(const char* theComponentName)
 {
-  bool _find = false;
-  Standard_CString name;
-  SALOMEDS::SComponentIterator_var itcomp = NewComponentIterator();
-  SALOMEDS::SComponent_var compo;
-
-  for (; itcomp->More(); itcomp->Next()) {
-    SALOMEDS::SComponent_var SC = itcomp->Value();
-    name = SC->ComponentDataType();
-    if(strcmp(aComponentName,name) == 0){
-      _find = true;
-      return SALOMEDS::SComponent::_narrow(SC); 
+  bool anIsFound = false;
+  SALOMEDS::SComponent_var aSComponent;
+  SALOMEDS_SComponentIterator_i aComponentIter(this,_doc);
+  for(; aComponentIter.More() && !anIsFound; aComponentIter.Next()){
+    SALOMEDS::SComponent_var aSComp = aComponentIter.Value();
+    CORBA::String_var aName = aSComp->ComponentDataType();
+    if(strcmp(theComponentName,aName.in()) == 0){
+      aSComponent = aSComp;
+      anIsFound = true;
     }
   }
-  if(!_find)
-    {
-      return SALOMEDS::SComponent::_nil();
-    }
-  return compo;
+  return aSComponent._retn();
 }
 
 //============================================================================
@@ -307,9 +303,9 @@ SALOMEDS::SComponent_ptr SALOMEDS_Study_i::FindComponentID(const char* aComponen
   char *ID;
   SALOMEDS::SComponent_ptr compo;
 
-  SALOMEDS::SComponentIterator_var itcomp = NewComponentIterator();
-  for (; itcomp->More(); itcomp->Next()) {
-    SALOMEDS::SComponent_var SC = itcomp->Value();
+  SALOMEDS_SComponentIterator_i itcomp(this,_doc);
+  for (; itcomp.More(); itcomp.Next()) {
+    SALOMEDS::SComponent_var SC = itcomp.Value();
     ID = SC->GetID();
     if(strcmp(aComponentID,ID)==0)
       {
@@ -330,34 +326,29 @@ SALOMEDS::SComponent_ptr SALOMEDS_Study_i::FindComponentID(const char* aComponen
  *  Purpose  : Find an Object with SALOMEDS::Name = anObjectName
  */
 //============================================================================
-SALOMEDS::SObject_ptr SALOMEDS_Study_i::FindObject(const char* anObjectName)
+SALOMEDS::SObject_ptr SALOMEDS_Study_i::FindObject(const char* theObjectName)
 {
   // Iterate to all components defined in the study
   // After testing the component name, iterate in all objects defined under
   // components (function _FindObject)
-  bool _find = false;
-  SALOMEDS::SObject_ptr RefSO = SALOMEDS::SObject::_nil();
-
-  SALOMEDS::SComponentIterator_var it = NewComponentIterator();
-  for (; it->More();it->Next()){
-    if(!_find)
-      {
-       SALOMEDS::SComponent_var SC = it->Value();
-       SALOMEDS::GenericAttribute_var anAttr;
-       if (SC->FindAttribute(anAttr,"AttributeName")) 
-       {
-         SALOMEDS::AttributeName_var Name = SALOMEDS::AttributeName::_narrow(anAttr);
-         CORBA::String_var Val = Name->Value();
-         if (strcmp(Val, anObjectName) == 0)
-           {
-             _find = true;
-             RefSO = SALOMEDS::SObject::_narrow(SC);
-           }
-       }
-       if (!_find) RefSO =  _FindObject(SC,anObjectName, _find);
+  bool aIsFound = false;
+  SALOMEDS::SObject_var aRefSO;
+  SALOMEDS_SComponentIterator_i aComponentIter(this,_doc);
+  for(; aComponentIter.More() && !aIsFound; aComponentIter.Next()){
+    TDF_Label aLab = aComponentIter.GetValue();
+    Handle(TDataStd_Name) anAttr;
+    if(aLab.FindAttribute(TDataStd_Name::GetID(),anAttr)){
+      TCollection_AsciiString aString(anAttr->Get());
+      if(strcmp(aString.ToCString(),theObjectName) == 0){
+       aRefSO = SALOMEDS_SComponent_i::NewRef(this,aLab)._retn();
+       aIsFound = true;
       }
+    }
+    if(!aIsFound) 
+      aRefSO = _FindObject(aLab,theObjectName,aIsFound);
   }
-  return RefSO;
+
+  return aRefSO._retn();
 }
 
 //============================================================================
@@ -374,7 +365,7 @@ SALOMEDS::SObject_ptr SALOMEDS_Study_i::FindObjectID(const char* anObjectID)
   if (Lab.IsNull()) 
     return SALOMEDS::SObject::_nil();
 
-  return SALOMEDS_SObject_i::New(this,Lab)->_this();
+  return SALOMEDS_SObject_i::NewRef(this,Lab)._retn();
 
 }
 
@@ -392,7 +383,7 @@ SALOMEDS::SObject_ptr SALOMEDS_Study_i::CreateObjectID(const char* anObjectID)
   if (Lab.IsNull()) 
     return SALOMEDS::SObject::_nil();
 
-  return SALOMEDS_SObject_i::New(this,Lab)->_this();
+  return SALOMEDS_SObject_i::NewRef(this,Lab)._retn();
 }
 
 //============================================================================
@@ -401,53 +392,44 @@ SALOMEDS::SObject_ptr SALOMEDS_Study_i::CreateObjectID(const char* anObjectID)
  *           : with ComponentDataType = aComponentName
  */
 //============================================================================
-SALOMEDS::Study::ListOfSObject* SALOMEDS_Study_i::FindObjectByName( const char* anObjectName,
-                                                                   const char* aComponentName )
+SALOMEDS::Study::ListOfSObject* 
+SALOMEDS_Study_i::FindObjectByName(const char* theObjectName,
+                                  const char* theComponentName)
 {
-  SALOMEDS::Study::ListOfSObject_var listSO = new SALOMEDS::Study::ListOfSObject ;
-  listSO->length(0);
-  
-  SALOMEDS::SComponent_ptr compo = FindComponent(aComponentName) ;
-  if ( compo->_is_nil() ) {
-    MESSAGE ("In FindObjectByName() :  Component named " << aComponentName << " not found ");
-    return listSO._retn();
+  SALOMEDS::Study::ListOfSObject_var aListOfSObj = new SALOMEDS::Study::ListOfSObject ;
+  aListOfSObj->length(0);
+
+  SALOMEDS::SComponent_ptr aSComponent = FindComponent(theComponentName) ;
+  if(aSComponent->_is_nil()){
+    MESSAGE ("In FindObjectByName() :  Component named " << theComponentName << " not found ");
+    return aListOfSObj._retn();
   }
 
   // Iterate on each object and subobject of the component
   // If objectName is found add it to the list of SObjects 
-  char *name;
-  SALOMEDS::SObject_ptr addSO = SALOMEDS::SObject::_nil();
-
-  CORBA::String_var compoId = compo->GetID();
-  SALOMEDS::ChildIterator_var it = NewChildIterator(compo);
-  int length = 0 ;
-  for ( ; it->More();it->Next() ) {
-    
-    SALOMEDS::SObject_var CSO = it->Value();
-    SALOMEDS::GenericAttribute_var anAttr;
-    SALOMEDS::AttributeName_var    aName;
-    if ( CSO->FindAttribute(anAttr, "AttributeName") ) {
-      aName = SALOMEDS::AttributeName::_narrow(anAttr);
-      name = aName->Value();
-      if ( strcmp( name, anObjectName ) == 0) {
-       addSO = SALOMEDS::SObject::_narrow(CSO);
+  TDF_Label aLabel;
+  CORBA::String_var anEntry = aSComponent->GetID();
+  TDF_Tool::Label(_doc->GetData(),const_cast<char*>(anEntry.in()),aLabel);
+  
+  int aLength = 0 ;
+  SALOMEDS::SObject_var aRefSO;
+  TDF_ChildIterator aChildIter(aLabel,true);
+  for(; aChildIter.More(); aChildIter.Next()){
+    TDF_Label aLab = aChildIter.Value();
+    Handle(TDataStd_Name) anAttr;
+    if(aLab.FindAttribute(TDataStd_Name::GetID(),anAttr)){
+      TCollection_AsciiString aString(anAttr->Get());
+      if(strcmp(aString.ToCString(),theObjectName) == 0){
+       aRefSO = SALOMEDS_SObject_i::NewRef(this,aLab)._retn();
        /* add to list */
-       length++ ;
-       listSO->length(length);
-       listSO[length-1] = addSO ;
-      }
-      
-      /* looks also for eventual children */
-      bool found;
-      addSO = _FindObject( CSO, anObjectName, found ) ;
-      if( found) {
-       length++ ;
-       listSO->length(length);
-       listSO[length-1] = addSO ;
+       aLength++ ;
+       aListOfSObj->length(aLength);
+       aListOfSObj[aLength-1] = aRefSO;
       }
     }
   }
-  return listSO._retn() ;
+
+  return aListOfSObj._retn() ;
 }
 
 
@@ -462,40 +444,39 @@ 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_i* aResult = SALOMEDS_SObject_i::New(this,myIORLabels.Find(anIOR));
+    SALOMEDS::SObject_var aResult = SALOMEDS_SObject_i::NewRef(this,myIORLabels.Find(anIOR));
     // 11 oct 2002: forbidden attributes must be checked here
     SALOMEDS::GenericAttribute_var anAttr;
     if (!aResult->FindAttribute(anAttr,"AttributeIOR")) {
       myIORLabels.UnBind(anIOR);
     } else 
-      return aResult->_this();
+      return aResult._retn();
   }
+
   // Iterate to all components defined in the study
   // After testing the component name, iterate in all objects defined under
   // components (function _FindObject)
-  bool _find = false;
-  SALOMEDS::SObject_ptr RefSO = SALOMEDS::SObject::_nil();
-
-  SALOMEDS::SComponentIterator_var it = NewComponentIterator();
-  for (; it->More();it->Next()){
-    if(!_find){
-      SALOMEDS::SComponent_var SC = it->Value();
-      SALOMEDS::GenericAttribute_var anAttr;
-      if(SC->FindAttribute(anAttr,"AttributeIOR")){
-       SALOMEDS::AttributeIOR_var IOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
-       CORBA::String_var aVal = IOR->Value();
-       if (strcmp(aVal,theObjectIOR) == 0){
-         _find = true;
-         RefSO = SALOMEDS::SObject::_narrow(SC);
-       }
+  bool aIsFound = false;
+  SALOMEDS::SObject_var aRefSO;
+  SALOMEDS_SComponentIterator_i aComponentIter(this,_doc);
+  for(; aComponentIter.More() && !aIsFound; aComponentIter.Next()){
+    TDF_Label aLab = aComponentIter.GetValue();
+    Handle(SALOMEDS_IORAttribute) anAttr;
+    if(aLab.FindAttribute(SALOMEDS_IORAttribute::GetID(),anAttr)){
+      TCollection_AsciiString aString(anAttr->Get());
+      if(strcmp(aString.ToCString(),theObjectIOR) == 0){
+       aRefSO = SALOMEDS_SComponent_i::NewRef(this,aLab);
+       aIsFound = true;
       }
-      if (!_find) 
-       RefSO =  _FindObjectIOR(SC,theObjectIOR,_find);
     }
+    if(!aIsFound) 
+      aRefSO = _FindObjectIOR(aLab,theObjectIOR,aIsFound);
   }
-  if (!RefSO->_is_nil()) MESSAGE("SALOMEDS_Study_i::FindObjectIOR: found label with old methods");
 
-  return RefSO;
+  if(!aRefSO->_is_nil()) 
+    MESSAGE("SALOMEDS_Study_i::FindObjectIOR: found label with old methods");
+
+  return aRefSO._retn();
 }
 
 //============================================================================
@@ -511,7 +492,7 @@ SALOMEDS::SObject_ptr SALOMEDS_Study_i::FindObjectByPath(const char* thePath)
   bool isRelative = false;
 
   if(aLength == 0) {  //Empty path - return the current context
-    return SALOMEDS_SObject_i::New(this,_current)->_this();
+    return SALOMEDS_SObject_i::NewRef(this,_current)._retn();
   }
 
   if(aPath.Value(1) != '/')  //Relative path 
@@ -527,7 +508,7 @@ SALOMEDS::SObject_ptr SALOMEDS_Study_i::FindObjectByPath(const char* thePath)
   }
   else {
     if(aPath.Length() == 1 && aPath.Value(1) == '/') {    //Root
-      return SALOMEDS_SObject_i::New (this,_doc->Main())->_this();
+      return SALOMEDS_SObject_i::NewRef(this,_doc->Main())._retn();
     }
     anIterator.Initialize(_doc->Main(), Standard_False);
   }
@@ -543,7 +524,7 @@ SALOMEDS::SObject_ptr SALOMEDS_Study_i::FindObjectByPath(const char* thePath)
        if(anAttr->Get() == aToken) {
          aToken = aPath.Token("/", i+1); //Check if it was the last part of the path
          if(aToken.Length() == 0) {  //The searched label is found (no part of the path is left)
-           return SALOMEDS_SObject_i::New(this,aLabel)->_this();
+           return SALOMEDS_SObject_i::NewRef(this,aLabel)._retn();
          }
 
          anIterator.Initialize(aLabel, Standard_False);
@@ -648,8 +629,8 @@ char* SALOMEDS_Study_i::GetContext()
 {
   if(_current.IsNull()) 
     throw SALOMEDS::Study::StudyInvalidContext();   
-  SALOMEDS_SObject_i* aServant = SALOMEDS_SObject_i::New(this,_current);
-  SALOMEDS::SObject_var aSObject = aServant->_this(); 
+
+  SALOMEDS::SObject_var aSObject = SALOMEDS_SObject_i::NewRef(this,_current);
   return GetObjectPath(aSObject);
 }
 
@@ -942,35 +923,28 @@ void SALOMEDS_Study_i::URL(const char* url)
  *  Purpose  : Find an Object with SALOMEDS::Name = anObjectName
  */
 //============================================================================
-SALOMEDS::SObject_ptr SALOMEDS_Study_i::_FindObject(SALOMEDS::SObject_ptr SO,
-                                                   const char* anObjectName, 
-                                                   bool& _find)
+SALOMEDS::SObject_ptr 
+SALOMEDS_Study_i::_FindObject(TDF_Label theLabel,
+                             const char* theObjectName, 
+                             bool& theIsFound)
 {
-  _find = false;
+  theIsFound = false;
   // Iterate on each objects and subobjects of the component
   // If objectName find, stop the loop and get the object reference
-  SALOMEDS::SObject_ptr RefSO = SALOMEDS::SObject::_nil();
-  CORBA::String_var soid = SO->GetID();
-  SALOMEDS::ChildIterator_var it = NewChildIterator(SO);
-  for (; it->More();it->Next()){
-    if(!_find)
-      {
-       SALOMEDS::SObject_var CSO = it->Value();
-       SALOMEDS::GenericAttribute_var anAttr;
-       if (CSO->FindAttribute(anAttr,"AttributeName")) 
-       {
-         SALOMEDS::AttributeName_var Name = SALOMEDS::AttributeName::_narrow(anAttr);
-          CORBA::String_var Val = Name->Value();
-         if (strcmp(Val, anObjectName) == 0)
-           {
-             RefSO = SALOMEDS::SObject::_narrow(CSO);
-             _find = true;
-           }
-       }
-       if (!_find) RefSO =  _FindObject(CSO, anObjectName, _find);
+  SALOMEDS::SObject_var aRefSO;
+  TDF_ChildIterator aChildIter(theLabel,true);
+  for(; aChildIter.More() && !theIsFound; aChildIter.Next()){
+    TDF_Label aLab = aChildIter.Value();
+    Handle(TDataStd_Name) anAttr;
+    if(aLab.FindAttribute(TDataStd_Name::GetID(),anAttr)){
+      TCollection_AsciiString aString(anAttr->Get());
+      if(strcmp(aString.ToCString(),theObjectName) == 0){
+       aRefSO = SALOMEDS_SObject_i::NewRef(this,aLab);
+       theIsFound = true;
       }
+    }
   }
-  return RefSO;
+  return aRefSO._retn();
 }
 
 //============================================================================
@@ -979,34 +953,26 @@ SALOMEDS::SObject_ptr SALOMEDS_Study_i::_FindObject(SALOMEDS::SObject_ptr SO,
  */
 //============================================================================
 SALOMEDS::SObject_ptr 
-SALOMEDS_Study_i::_FindObjectIOR(SALOMEDS::SObject_ptr SO,
-                             const char* anObjectIOR, 
-                             bool& _find)
+SALOMEDS_Study_i::_FindObjectIOR(TDF_Label theLabel,
+                                const char* theObjectIOR, 
+                                bool& theIsFound)
 {
   // Iterate on each objects and subobjects of the component
   // If objectName find, stop the loop and get the object reference
-  SALOMEDS::SObject_ptr RefSO = SALOMEDS::SObject::_nil();
-
-  SALOMEDS::ChildIterator_var it = NewChildIterator(SO);
-  for (; it->More();it->Next()){
-    if(!_find)
-      {
-       SALOMEDS::SObject_var CSO = it->Value();
-       SALOMEDS::GenericAttribute_var anAttr;
-       if (CSO->FindAttribute(anAttr,"AttributeIOR")) 
-       {
-         SALOMEDS::AttributeIOR_var IOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
-          CORBA::String_var Val = IOR->Value();
-         if (strcmp(Val, anObjectIOR) == 0)
-           {
-             RefSO = SALOMEDS::SObject::_narrow(CSO);
-             _find = true;
-           }
-       }
-       if (!_find) RefSO =  _FindObjectIOR(CSO, anObjectIOR, _find);
+  SALOMEDS::SObject_var aRefSO;
+  TDF_ChildIterator aChildIter(theLabel,true);
+  for(; aChildIter.More() && !theIsFound; aChildIter.Next()){
+    TDF_Label aLab = aChildIter.Value();
+    Handle(SALOMEDS_IORAttribute) anAttr;
+    if(aLab.FindAttribute(SALOMEDS_IORAttribute::GetID(),anAttr)){
+      TCollection_AsciiString aString(anAttr->Get());
+      if(strcmp(aString.ToCString(),theObjectIOR) == 0){
+       aRefSO = SALOMEDS_SObject_i::NewRef(this,aLab);
+       theIsFound = true;
       }
+    }
   }
-  return RefSO;
+  return aRefSO._retn();
 }
 
 CORBA::Short SALOMEDS_Study_i::StudyId()
@@ -1107,11 +1073,11 @@ SALOMEDS::ListOfDates* SALOMEDS_Study_i::GetModificationsDate() {
 //============================================================================
 void SALOMEDS_Study_i::Close()
 {
-  SALOMEDS::SComponentIterator_var itcomponent = NewComponentIterator();
+  SALOMEDS_SComponentIterator_i itcomponent(this,_doc);
 
   const CORBA::ORB_var& anORB = GetORB();
-  for (; itcomponent->More(); itcomponent->Next()) {
-    SALOMEDS::SComponent_var sco = itcomponent->Value();
+  for (; itcomponent.More(); itcomponent.Next()) {
+    SALOMEDS::SComponent_var sco = itcomponent.Value();
          
     MESSAGE ( "Look for an engine for data type :"<< sco->ComponentDataType());
     // if there is an associated Engine call its method for closing
index f70e7107fb893c3795fa7dd09f14f20c6c6b0de3..bbb151bab04ff7965017292d30b06ac7ee5c6a40 100644 (file)
@@ -63,7 +63,7 @@ class SALOMEDS_Study_i: public virtual POA_SALOMEDS::Study,
 {
 public:
   typedef TDF_Label TSObjectID;
-  typedef SALOMEDS_SObject_i* TSObjectHolder;
+  typedef std::pair<SALOMEDS_SObject_i*,SALOMEDS::SObject_var> TSObjectHolder;
   typedef std::map<TSObjectID,TSObjectHolder> TSObjectMap;
 
   SALOMEDS_Study_i(SALOMEDS_StudyManager_i* theStudyManager,
@@ -336,12 +336,12 @@ private:
   TDF_Label                _current;
   bool                     _autoFill;  
 
-  SALOMEDS::SObject_ptr    _FindObject(SALOMEDS::SObject_ptr SO,
-                                      const char* anObjectName,
-                                      bool& _find);
-  SALOMEDS::SObject_ptr    _FindObjectIOR(SALOMEDS::SObject_ptr SO,
-                                         const char* anObjectIOR,
-                                         bool& _find);
+  SALOMEDS::SObject_ptr    _FindObject(TDF_Label theLabel,
+                                      const char* theObjectIOR, 
+                                      bool& theIsFound);
+  SALOMEDS::SObject_ptr    _FindObjectIOR(TDF_Label theLabel,
+                                         const char* theObjectIOR, 
+                                         bool& theIsFound);
 
   SALOMEDS_Study_i(); // Not implemented
   void operator=(const SALOMEDS_Study_i&); // Not implemented
index 81454daa7d8ff39698eec8e1beb399bc70b30649..c35e2f560283d1db9e0edea2c1d716311476c765 100644 (file)
@@ -319,7 +319,7 @@ SALOMEDS::SObject_ptr SALOMEDS_UseCaseBuilder_i::GetCurrentObject()
   TDF_Label aCurrent = aRef->Get();  
   if(aCurrent.IsNull()) return NULL;
 
-  return SALOMEDS_SObject_i::New(_study,aCurrent)->_this();
+  return SALOMEDS_SObject_i::NewRef(_study,aCurrent)._retn();
 }
 
 //============================================================================
@@ -388,7 +388,7 @@ SALOMEDS::SObject_ptr SALOMEDS_UseCaseBuilder_i::AddUseCase(const char* theName)
   aFatherNode->Append(aNode);
   TDataStd_Name::Set(aChild, TCollection_ExtendedString(const_cast<char*>(theName)));
 
-  return SALOMEDS_SObject_i::New(_study,aChild)->_this();
+  return SALOMEDS_SObject_i::NewRef(_study,aChild)._retn();
 }
 
 //============================================================================
index f4c89cc96ebb6b593cd3152ce703f6740b492a15..38dbd0568f403f2fd229defb7ba15959214b788a 100644 (file)
@@ -82,6 +82,6 @@ void SALOMEDS_UseCaseIterator_i::Next()
 SALOMEDS::SObject_ptr SALOMEDS_UseCaseIterator_i::Value()
 {
   TDF_Label L = _it.Value()->Label();
-  return SALOMEDS_SObject_i::New(_study,L)->_this();
+  return SALOMEDS_SObject_i::NewRef(_study,L)._retn();
 }