From f2371c18cc684f0c69978de8da4885464b1ad725 Mon Sep 17 00:00:00 2001 From: apo Date: Tue, 18 Jan 2005 10:39:44 +0000 Subject: [PATCH] Fix on [Bug PAL7023] Problem loading MED file with a large number of families (same as VISU6154) --- src/SALOMEDS/SALOMEDS_AttributeTarget_i.cxx | 3 +- src/SALOMEDS/SALOMEDS_ChildIterator_i.cxx | 9 +- src/SALOMEDS/SALOMEDS_ChildIterator_i.hxx | 5 +- .../SALOMEDS_SComponentIterator_i.cxx | 2 +- .../SALOMEDS_SComponentIterator_i.hxx | 2 + src/SALOMEDS/SALOMEDS_SComponent_i.cxx | 41 ++- src/SALOMEDS/SALOMEDS_SComponent_i.hxx | 19 +- src/SALOMEDS/SALOMEDS_SObject_i.cxx | 40 ++- src/SALOMEDS/SALOMEDS_SObject_i.hxx | 19 +- src/SALOMEDS/SALOMEDS_StudyBuilder_i.cxx | 15 +- src/SALOMEDS/SALOMEDS_StudyManager_i.cxx | 4 +- src/SALOMEDS/SALOMEDS_Study_i.cxx | 304 ++++++++---------- src/SALOMEDS/SALOMEDS_Study_i.hxx | 14 +- src/SALOMEDS/SALOMEDS_UseCaseBuilder_i.cxx | 4 +- src/SALOMEDS/SALOMEDS_UseCaseIterator_i.cxx | 2 +- 15 files changed, 253 insertions(+), 230 deletions(-) diff --git a/src/SALOMEDS/SALOMEDS_AttributeTarget_i.cxx b/src/SALOMEDS/SALOMEDS_AttributeTarget_i.cxx index 80b1c2e66..70f7b81b9 100644 --- a/src/SALOMEDS/SALOMEDS_AttributeTarget_i.cxx +++ b/src/SALOMEDS/SALOMEDS_AttributeTarget_i.cxx @@ -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(); } diff --git a/src/SALOMEDS/SALOMEDS_ChildIterator_i.cxx b/src/SALOMEDS/SALOMEDS_ChildIterator_i.cxx index c1dca11d9..6396ada74 100644 --- a/src/SALOMEDS/SALOMEDS_ChildIterator_i.cxx +++ b/src/SALOMEDS/SALOMEDS_ChildIterator_i.cxx @@ -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 - "<_this(); + return SALOMEDS_SObject_i::NewRef(_study,_it.Value())._retn(); } diff --git a/src/SALOMEDS/SALOMEDS_ChildIterator_i.hxx b/src/SALOMEDS/SALOMEDS_ChildIterator_i.hxx index cf9b71ce9..083fd9935 100644 --- a/src/SALOMEDS/SALOMEDS_ChildIterator_i.hxx +++ b/src/SALOMEDS/SALOMEDS_ChildIterator_i.hxx @@ -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(); diff --git a/src/SALOMEDS/SALOMEDS_SComponentIterator_i.cxx b/src/SALOMEDS/SALOMEDS_SComponentIterator_i.cxx index 541d90b49..adf77476a 100644 --- a/src/SALOMEDS/SALOMEDS_SComponentIterator_i.cxx +++ b/src/SALOMEDS/SALOMEDS_SComponentIterator_i.cxx @@ -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(); } diff --git a/src/SALOMEDS/SALOMEDS_SComponentIterator_i.hxx b/src/SALOMEDS/SALOMEDS_SComponentIterator_i.hxx index ca2f51f47..919f65fab 100644 --- a/src/SALOMEDS/SALOMEDS_SComponentIterator_i.hxx +++ b/src/SALOMEDS/SALOMEDS_SComponentIterator_i.hxx @@ -57,6 +57,8 @@ public: ~SALOMEDS_SComponentIterator_i(); + TDF_Label GetValue() { return _it.Value();} + virtual void Init(); virtual CORBA::Boolean More(); virtual void Next(); diff --git a/src/SALOMEDS/SALOMEDS_SComponent_i.cxx b/src/SALOMEDS/SALOMEDS_SComponent_i.cxx index 53cfc5550..c9cc82ac6 100644 --- a/src/SALOMEDS/SALOMEDS_SComponent_i.cxx +++ b/src/SALOMEDS/SALOMEDS_SComponent_i.cxx @@ -33,22 +33,41 @@ 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 - "<second; - aSComponent = dynamic_cast(aSObject); + aSObjectHolder = anIter->second; + SALOMEDS_SObject_i* aSObject = aSObjectHolder.first; + if(dynamic_cast(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(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); } //============================================================================ diff --git a/src/SALOMEDS/SALOMEDS_SComponent_i.hxx b/src/SALOMEDS/SALOMEDS_SComponent_i.hxx index 3373a4175..1018b7bb5 100644 --- a/src/SALOMEDS/SALOMEDS_SComponent_i.hxx +++ b/src/SALOMEDS/SALOMEDS_SComponent_i.hxx @@ -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(); diff --git a/src/SALOMEDS/SALOMEDS_SObject_i.cxx b/src/SALOMEDS/SALOMEDS_SObject_i.cxx index 62b2f3d89..5d6e16382 100644 --- a/src/SALOMEDS/SALOMEDS_SObject_i.cxx +++ b/src/SALOMEDS/SALOMEDS_SObject_i.cxx @@ -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 - "<_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; } diff --git a/src/SALOMEDS/SALOMEDS_SObject_i.hxx b/src/SALOMEDS/SALOMEDS_SObject_i.hxx index d7562acf7..2f28e74c2 100644 --- a/src/SALOMEDS/SALOMEDS_SObject_i.hxx +++ b/src/SALOMEDS/SALOMEDS_SObject_i.hxx @@ -37,11 +37,12 @@ #include #include +#include "SALOMEDS_Study_i.hxx" + // IDL headers #include #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(); diff --git a/src/SALOMEDS/SALOMEDS_StudyBuilder_i.cxx b/src/SALOMEDS/SALOMEDS_StudyBuilder_i.cxx index e875fb894..143d3c0b7 100644 --- a/src/SALOMEDS/SALOMEDS_StudyBuilder_i.cxx +++ b/src/SALOMEDS/SALOMEDS_StudyBuilder_i.cxx @@ -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 { diff --git a/src/SALOMEDS/SALOMEDS_StudyManager_i.cxx b/src/SALOMEDS/SALOMEDS_StudyManager_i.cxx index 2da9950d8..5030d0880 100644 --- a/src/SALOMEDS/SALOMEDS_StudyManager_i.cxx +++ b/src/SALOMEDS/SALOMEDS_StudyManager_i.cxx @@ -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(); } diff --git a/src/SALOMEDS/SALOMEDS_Study_i.cxx b/src/SALOMEDS/SALOMEDS_Study_i.cxx index e8161cc02..934598800 100644 --- a/src/SALOMEDS/SALOMEDS_Study_i.cxx +++ b/src/SALOMEDS/SALOMEDS_Study_i.cxx @@ -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" @@ -67,46 +69,45 @@ 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(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(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 diff --git a/src/SALOMEDS/SALOMEDS_Study_i.hxx b/src/SALOMEDS/SALOMEDS_Study_i.hxx index f70e7107f..bbb151bab 100644 --- a/src/SALOMEDS/SALOMEDS_Study_i.hxx +++ b/src/SALOMEDS/SALOMEDS_Study_i.hxx @@ -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 TSObjectHolder; typedef std::map 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 diff --git a/src/SALOMEDS/SALOMEDS_UseCaseBuilder_i.cxx b/src/SALOMEDS/SALOMEDS_UseCaseBuilder_i.cxx index 81454daa7..c35e2f560 100644 --- a/src/SALOMEDS/SALOMEDS_UseCaseBuilder_i.cxx +++ b/src/SALOMEDS/SALOMEDS_UseCaseBuilder_i.cxx @@ -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(theName))); - return SALOMEDS_SObject_i::New(_study,aChild)->_this(); + return SALOMEDS_SObject_i::NewRef(_study,aChild)._retn(); } //============================================================================ diff --git a/src/SALOMEDS/SALOMEDS_UseCaseIterator_i.cxx b/src/SALOMEDS/SALOMEDS_UseCaseIterator_i.cxx index f4c89cc96..38dbd0568 100644 --- a/src/SALOMEDS/SALOMEDS_UseCaseIterator_i.cxx +++ b/src/SALOMEDS/SALOMEDS_UseCaseIterator_i.cxx @@ -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(); } -- 2.39.2