]> SALOME platform Git repositories - modules/smesh.git/commitdiff
Salome HOME
fix bug 11757. Use free labels when publishing a reference
authoreap <eap@opencascade.com>
Wed, 3 May 2006 14:53:45 +0000 (14:53 +0000)
committereap <eap@opencascade.com>
Wed, 3 May 2006 14:53:45 +0000 (14:53 +0000)
src/SMESH_I/SMESH_Gen_i_1.cxx

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