Salome HOME
0021153: [CEA] non regression test fails
[modules/smesh.git] / src / SMESHDS / SMESHDS_SubMesh.cxx
index 58f29ea4e422efd0cbe95ee64ed346b90aaa4c54..78fcd528203f64424f54e7763632e606a3d2304e 100644 (file)
 
 using namespace std;
 
+
+//================================================================================
+/*!
+ * \brief Constructor
+ */
+//================================================================================
+
 SMESHDS_SubMesh::SMESHDS_SubMesh(SMESHDS_Mesh *parent, int index)
 {
   myParent = parent;
@@ -46,6 +53,16 @@ SMESHDS_SubMesh::SMESHDS_SubMesh(SMESHDS_Mesh *parent, int index)
   myUnusedIdElements = 0;
 }
 
+//================================================================================
+/*!
+ * \brief Destructor
+ */
+//================================================================================
+
+SMESHDS_SubMesh::~SMESHDS_SubMesh()
+{
+}
+
 //=======================================================================
 //function : AddElement
 //purpose  : 
@@ -55,13 +72,39 @@ void SMESHDS_SubMesh::AddElement(const SMDS_MeshElement * ME)
   if (!IsComplexSubmesh())
     {
       //MESSAGE("in " << myIndex << " AddElement "<< ME->GetID());
-      int idInSubShape = ME->getIdInShape();
-      if (idInSubShape != -1)
+      int oldShapeId = ME->getshapeId();
+      if ( oldShapeId > 0 )
         {
-          MESSAGE("add element in subshape already belonging to a subshape "
-              << ME->GetID() << "  " << ME->getIdInShape() << " " << ME->getshapeId());
-          throw SALOME_Exception(LOCALIZED("add element in subshape already belonging to a subshape"));
+          if (oldShapeId != myIndex)
+            {
+              MESSAGE("add element in subshape already belonging to another subshape "
+                << ME->GetID() << " " << oldShapeId << " " << myIndex);
+              throw SALOME_Exception(LOCALIZED("add element in subshape already belonging to a subshape"));
+            }
+          else
+            {
+              int idInSubShape = ME->getIdInShape();
+              if (idInSubShape >= 0)
+                {
+                  MESSAGE("add element in subshape already belonging to that subshape "
+                      << ME->GetID() << " " << oldShapeId << " " << idInSubShape);
+                  // check if ok: do nothing if ok
+                  if (idInSubShape >= myElements.size())
+                    {
+                      MESSAGE("out of bounds " << idInSubShape << " " << myElements.size());
+                      throw SALOME_Exception(LOCALIZED("out of bounds"));
+                    }
+                  if (ME != myElements[idInSubShape])
+                    {
+                      MESSAGE("not the same element");
+                      throw SALOME_Exception(LOCALIZED("not the same element"));
+                    }
+                  MESSAGE("already done, OK, nothing to do");
+                  return;
+                }
+            }
         }
+
       SMDS_MeshElement* elem = (SMDS_MeshElement*) (ME);
       elem->setShapeId(myIndex);
       elem->setIdInShape(myElements.size());
@@ -83,8 +126,8 @@ bool SMESHDS_SubMesh::RemoveElement(const SMDS_MeshElement * ME, bool isElemDele
   //MESSAGE("-----------------> RemoveElement "<< ME->GetID() << " " << isElemDeleted);
   if (!IsComplexSubmesh())
     {
-      //      if (!isElemDeleted) // alive element has valid ID and can be found
-      //  {
+      if ( ME->getshapeId() != myIndex )
+        return false;
       int idInSubShape = ME->getIdInShape();
       //MESSAGE("in "<< myIndex << " RemoveElement " << ME->GetID() << " " << idInSubShape << " " << myUnusedIdElements);
       SMDS_MeshElement* elem = (SMDS_MeshElement*) (ME);
@@ -139,6 +182,8 @@ bool SMESHDS_SubMesh::RemoveNode(const SMDS_MeshNode * N, bool isNodeDeleted)
     {
       // if (!isNodeDeleted) // alive node has valid ID and can be found
       // {
+      if ( N->getshapeId() != myIndex )
+        return false;
       int idInSubShape = N->getIdInShape();
       //int shapeId = N->getshapeId();
       //MESSAGE("in "<< myIndex << " RemoveNode " << shapeId << " " << idInSubShape << " " << N->GetID());
@@ -379,6 +424,16 @@ bool SMESHDS_SubMesh::RemoveSubMesh( const SMESHDS_SubMesh* theSubMesh )
   return mySubMeshes.erase( theSubMesh );
 }
 
+//=======================================================================
+//function : RemoveAllSubmeshes
+//purpose  : 
+//=======================================================================
+
+void SMESHDS_SubMesh::RemoveAllSubmeshes()
+{
+  mySubMeshes.clear();
+}
+
 //=======================================================================
 //function : ContainsSubMesh
 //purpose  :