]> SALOME platform Git repositories - modules/smesh.git/blobdiff - src/SMESH_I/SMESH_Gen_i_1.cxx
Salome HOME
PAL 14158 Add the Octree and OctreeNode classes to accelerate detection of close...
[modules/smesh.git] / src / SMESH_I / SMESH_Gen_i_1.cxx
index 4e50171a648b0b8e3008c47a33cff4e9d063c95e..2021f22e2df7a4c43c62934b4ee3757577eb3a6e 100644 (file)
@@ -17,7 +17,7 @@
 //  License along with this library; if not, write to the Free Software 
 //  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA 
 // 
-//  See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org 
+// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
 //
 //
 // File      : SMESH_Gen_i_1.cxx
@@ -146,7 +146,10 @@ long SMESH_Gen_i::GetVolumeGroupsTag()
 
 bool SMESH_Gen_i::CanPublishInStudy(CORBA::Object_ptr theIOR)
 {
-  if(MYDEBUG) MESSAGE("CanPublishInStudy");
+  if(MYDEBUG) MESSAGE("CanPublishInStudy - "<<!CORBA::is_nil(myCurrentStudy));
+  if(CORBA::is_nil(myCurrentStudy))
+    return false;
+  
   SMESH::SMESH_Mesh_var aMesh       = SMESH::SMESH_Mesh::_narrow(theIOR);
   if( !aMesh->_is_nil() )
     return true;
@@ -306,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;
-      }
-      if ( !isReferred ) {
-        aReferenceSO = aStudyBuilder->NewObject( theSObject );
-        aStudyBuilder->Addreference( aReferenceSO, aToObjSO );
+      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 )
+        return;
+      if ( !theTag )
+        theTag = tag;
     }
-    else {
-      if ( !theSObject->FindSubObject( theTag, aReferenceSO ))
-        aReferenceSO = aStudyBuilder->NewObjectToTag( theSObject, theTag );
-      aStudyBuilder->Addreference( aReferenceSO, aToObjSO );
-    }
+    if ( !theSObject->FindSubObject( theTag, aReferenceSO ))
+      aReferenceSO = aStudyBuilder->NewObjectToTag( theSObject, theTag );
+    aStudyBuilder->Addreference( aReferenceSO, aToObjSO );
   }
 }
 
@@ -471,7 +481,7 @@ SALOMEDS::SObject_ptr SMESH_Gen_i::PublishMesh (SALOMEDS::Study_ptr   theStudy,
     else
       aTag++;
 
-    aMeshSO = publish (theStudy, theMesh, father, aTag, "ICON_SMESH_TREE_MESH" );
+    aMeshSO = publish (theStudy, theMesh, father, aTag, "ICON_SMESH_TREE_MESH_WARN" );
     if ( aMeshSO->_is_nil() )
       return aMeshSO._retn();
   }
@@ -593,7 +603,7 @@ SALOMEDS::SObject_ptr SMESH_Gen_i::PublishSubMesh (SALOMEDS::Study_ptr      theS
     SetName( aRootSO, aRootName );
 
     // Add new submesh to corresponding sub-tree
-    aSubMeshSO = publish (theStudy, theSubMesh, aRootSO, 0, "ICON_SMESH_TREE_MESH");
+    aSubMeshSO = publish (theStudy, theSubMesh, aRootSO, 0, "ICON_SMESH_TREE_MESH_WARN");
     if ( aSubMeshSO->_is_nil() )
       return aSubMeshSO._retn();
   }
@@ -773,7 +783,19 @@ bool SMESH_Gen_i::AddHypothesisToShape(SALOMEDS::Study_ptr         theStudy,
   SALOMEDS::SObject_var aMeshOrSubMesh =
     GetMeshOrSubmeshByShape( theStudy, theMesh, theShape );
   if ( aMeshOrSubMesh->_is_nil() )
-    return false;
+  {
+    // publish submesh
+    TopoDS_Shape aShape = GeomObjectToShape( theShape );
+    SMESH_Mesh_i* mesh_i = objectToServant<SMESH_Mesh_i>( theMesh );
+    if ( !aShape.IsNull() && mesh_i && mesh_i->GetImpl().GetMeshDS() ) {
+      SMESHDS_Mesh* meshDS = mesh_i->GetImpl().GetMeshDS();
+      int shapeID = meshDS->ShapeToIndex( aShape );
+      SMESH::SMESH_subMesh_var aSubMesh = mesh_i->getSubMesh(shapeID);
+      aMeshOrSubMesh = PublishSubMesh( theStudy, theMesh, aSubMesh, theShape );
+    }
+    if ( aMeshOrSubMesh->_is_nil() )
+      return false;
+  }
 
   //Find or Create Applied Hypothesis root
   bool aIsAlgo = !SMESH::SMESH_Algo::_narrow( theHyp )->_is_nil();