Salome HOME
Fix error on attempt to assign a hypothesis.
[modules/smesh.git] / src / SMESHDS / SMESHDS_Mesh.cxx
index c1d3cc45c57837ba80a211819b53d54db8c78341..9f48b7b15b588585f9f0e66f6e016f1105d7b208 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
 //
 //
 //
 
 using namespace std;
 
+/*Standard_Boolean IsEqual( const TopoDS_Shape& S1, const TopoDS_Shape& S2 ) 
+  {
+    return S1.IsSame( S2 );
+  }*/
+
 //=======================================================================
 //function : Create
 //purpose  : 
 //=======================================================================
 SMESHDS_Mesh::SMESHDS_Mesh(int theMeshID, bool theIsEmbeddedMode):
+  myMeshID(theMeshID),
   myIsEmbeddedMode(theIsEmbeddedMode),
-  myMeshID(theMeshID)
+  myCurSubID(-1)
 {
   myScript = new SMESHDS_Script(theIsEmbeddedMode);
+  myCurSubMesh = 0;
 }
 
 //=======================================================================
@@ -68,7 +75,7 @@ void SMESHDS_Mesh::ShapeToMesh(const TopoDS_Shape & S)
   {
     // removal of a shape to mesh, delete ...
     // - hypotheses
-    myShapeToHypothesis.clear();
+    myShapeToHypothesis.Clear();
     // - shape indices in SMDS_Position of nodes
     map<int,SMESHDS_SubMesh*>::iterator i_sub = myShapeIndexToSubMesh.begin();
     for ( ; i_sub != myShapeIndexToSubMesh.end(); i_sub++ ) {
@@ -103,18 +110,22 @@ void SMESHDS_Mesh::ShapeToMesh(const TopoDS_Shape & S)
 //=======================================================================
 
 bool SMESHDS_Mesh::AddHypothesis(const TopoDS_Shape & SS,
-       const SMESHDS_Hypothesis * H)
+                                 const SMESHDS_Hypothesis * H)
 {
-       list<const SMESHDS_Hypothesis *>& alist=myShapeToHypothesis[SS];
+  if (!myShapeToHypothesis.IsBound(SS.Oriented(TopAbs_FORWARD))) {
+    list<const SMESHDS_Hypothesis *> aList;
+    myShapeToHypothesis.Bind(SS.Oriented(TopAbs_FORWARD), aList);
+  }
+  list<const SMESHDS_Hypothesis *>& alist =
+    myShapeToHypothesis(SS.Oriented(TopAbs_FORWARD)); // ignore orientation of SS
 
-       //Check if the Hypothesis is still present
-       list<const SMESHDS_Hypothesis*>::iterator ith=alist.begin();
+  //Check if the Hypothesis is still present
+  list<const SMESHDS_Hypothesis*>::iterator ith = find(alist.begin(),alist.end(), H );
 
-       for (; ith!=alist.end(); ith++)
-               if (H == *ith) return false;
+  if (alist.end() != ith) return false;
 
-       alist.push_back(H);
-       return true;
+  alist.push_back(H);
+  return true;
 }
 
 //=======================================================================
@@ -122,22 +133,20 @@ bool SMESHDS_Mesh::AddHypothesis(const TopoDS_Shape & SS,
 //purpose  : 
 //=======================================================================
 
-bool SMESHDS_Mesh::RemoveHypothesis(const TopoDS_Shape & S,
-       const SMESHDS_Hypothesis * H)
+bool SMESHDS_Mesh::RemoveHypothesis(const TopoDS_Shape &       S,
+                                    const SMESHDS_Hypothesis * H)
 {
-       ShapeToHypothesis::iterator its=myShapeToHypothesis.find(S);
-       if(its!=myShapeToHypothesis.end())
-       {
-               list<const SMESHDS_Hypothesis*>::iterator ith=(*its).second.begin();
-
-               for (; ith!=(*its).second.end(); ith++)
-                       if (H == *ith)
-                       {
-                               (*its).second.erase(ith);
-                               return true;
-                       }
-       }
-       return false;
+  if( myShapeToHypothesis.IsBound( S.Oriented(TopAbs_FORWARD) ) )
+  {
+    list<const SMESHDS_Hypothesis *>& alist=myShapeToHypothesis.ChangeFind( S.Oriented(TopAbs_FORWARD) );
+    list<const SMESHDS_Hypothesis*>::iterator ith=find(alist.begin(),alist.end(), H );
+    if (ith != alist.end())
+    {
+      alist.erase(ith);
+      return true;
+    }
+  }
+  return false;
 }
 
 //=======================================================================
@@ -711,7 +720,8 @@ void SMESHDS_Mesh::RemoveFreeNode(const SMDS_MeshNode * n, SMESHDS_SubMesh * sub
 
   // Rm from sub-mesh
   // Node should belong to only one sub-mesh
-  subMesh->RemoveNode(n);
+  if( subMesh )
+    subMesh->RemoveNode(n);
 
   SMDS_Mesh::RemoveFreeElement(n);
 }
@@ -768,7 +778,8 @@ void SMESHDS_Mesh::RemoveFreeElement(const SMDS_MeshElement * elt, SMESHDS_SubMe
 
   // Rm from sub-mesh
   // Element should belong to only one sub-mesh
-  subMesh->RemoveElement(elt);
+  if( subMesh )
+    subMesh->RemoveElement(elt);
 
   SMDS_Mesh::RemoveFreeElement(elt);
 }
@@ -846,7 +857,8 @@ bool SMESHDS_Mesh::add(const SMDS_MeshElement* elem, SMESHDS_SubMesh* subMesh )
 void SMESHDS_Mesh::SetNodeInVolume(SMDS_MeshNode *      aNode,
                                    const TopoDS_Shell & S)
 {
-  add( aNode, getSubmesh(S) );
+  if ( add( aNode, getSubmesh(S) ))
+    const_cast<SMDS_Position*>( aNode->GetPosition().get() )->SetShapeId( myCurSubID );
 }
 //=======================================================================
 //function : SetNodeOnVolume
@@ -855,7 +867,8 @@ void SMESHDS_Mesh::SetNodeInVolume(SMDS_MeshNode *      aNode,
 void SMESHDS_Mesh::SetNodeInVolume(SMDS_MeshNode *      aNode,
                                    const TopoDS_Solid & S)
 {
-  add( aNode, getSubmesh(S) );
+  if ( add( aNode, getSubmesh(S) ))
+    const_cast<SMDS_Position*>( aNode->GetPosition().get() )->SetShapeId( myCurSubID );
 }
 
 //=======================================================================
@@ -1009,14 +1022,14 @@ list<int> SMESHDS_Mesh::SubMeshIndices()
 //purpose  : 
 //=======================================================================
 
-const list<const SMESHDS_Hypothesis*>& SMESHDS_Mesh::GetHypothesis(
-       const TopoDS_Shape & S) const
+const list<const SMESHDS_Hypothesis*>&
+SMESHDS_Mesh::GetHypothesis(const TopoDS_Shape & S) const
 {
-       if (myShapeToHypothesis.find(S)!=myShapeToHypothesis.end())
-               return myShapeToHypothesis.find(S)->second;
+  if ( myShapeToHypothesis.IsBound( S.Oriented(TopAbs_FORWARD) ) ) // ignore orientation of S
+     return myShapeToHypothesis.Find( S.Oriented(TopAbs_FORWARD) );
 
-       static list<const SMESHDS_Hypothesis*> empty;
-       return empty;
+  static list<const SMESHDS_Hypothesis*> empty;
+  return empty;
 }
 
 //=======================================================================
@@ -1054,7 +1067,7 @@ bool SMESHDS_Mesh::HasMeshElements(const TopoDS_Shape & S)
 //=======================================================================
 bool SMESHDS_Mesh::HasHypothesis(const TopoDS_Shape & S)
 {
-       return myShapeToHypothesis.find(S)!=myShapeToHypothesis.end();
+  return myShapeToHypothesis.IsBound(S.Oriented(TopAbs_FORWARD));
 }
 
 //=======================================================================
@@ -1140,7 +1153,8 @@ int SMESHDS_Mesh::ShapeToIndex(const TopoDS_Shape & S) const
 //=======================================================================
 void SMESHDS_Mesh::SetNodeInVolume(const SMDS_MeshNode* aNode, int Index)
 {
-  add( aNode, getSubmesh( Index ));
+  if ( add( aNode, getSubmesh( Index )))
+    const_cast<SMDS_Position*>( aNode->GetPosition().get() )->SetShapeId( Index );
 }
 
 //=======================================================================