fix bug 11757. Use free labels when publishing a reference

This commit is contained in:
eap 2006-05-03 14:53:45 +00:00
parent 7d8a3a8516
commit b28dc98b3a

View File

@ -309,25 +309,32 @@ static void addReference (SALOMEDS::Study_ptr theStudy,
SALOMEDS::StudyBuilder_var aStudyBuilder = theStudy->NewBuilder(); SALOMEDS::StudyBuilder_var aStudyBuilder = theStudy->NewBuilder();
SALOMEDS::SObject_var aReferenceSO; SALOMEDS::SObject_var aReferenceSO;
if ( !theTag ) { if ( !theTag ) {
// check if the reference to theToObject already exists
// and find a free label for the reference object
bool isReferred = false; bool isReferred = false;
int tag = 1;
SALOMEDS::ChildIterator_var anIter = theStudy->NewChildIterator( theSObject ); SALOMEDS::ChildIterator_var anIter = theStudy->NewChildIterator( theSObject );
for ( ; !isReferred && anIter->More(); anIter->Next() ) { for ( ; !isReferred && anIter->More(); anIter->Next(), ++tag ) {
if ( anIter->Value()->ReferencedObject( aReferenceSO ) && if ( anIter->Value()->ReferencedObject( aReferenceSO )) {
strcmp( aReferenceSO->GetID(), aToObjSO->GetID() ) == 0 ) if ( strcmp( aReferenceSO->GetID(), aToObjSO->GetID() ) == 0 )
isReferred = true; isReferred = true;
} }
if ( !isReferred ) { else if ( !theTag ) {
aReferenceSO = aStudyBuilder->NewObject( theSObject ); SALOMEDS::GenericAttribute_var anAttr;
aStudyBuilder->Addreference( aReferenceSO, aToObjSO ); if ( !anIter->Value()->FindAttribute( anAttr, "AttributeIOR" ))
theTag = tag;
} }
} }
else { if ( isReferred )
return;
if ( !theTag )
theTag = tag;
}
if ( !theSObject->FindSubObject( theTag, aReferenceSO )) if ( !theSObject->FindSubObject( theTag, aReferenceSO ))
aReferenceSO = aStudyBuilder->NewObjectToTag( theSObject, theTag ); aReferenceSO = aStudyBuilder->NewObjectToTag( theSObject, theTag );
aStudyBuilder->Addreference( aReferenceSO, aToObjSO ); aStudyBuilder->Addreference( aReferenceSO, aToObjSO );
} }
} }
}
//============================================================================= //=============================================================================
/*! /*!