Salome HOME
Fix error on attempt to assign a hypothesis.
[modules/smesh.git] / src / SMESHDS / SMESHDS_Mesh.cxx
index 36e185f8a94854228a98f33907a794cf86404c43..9f48b7b15b588585f9f0e66f6e016f1105d7b208 100644 (file)
@@ -110,25 +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 ) )
-    myShapeToHypothesis.Bind( SS, list<const SMESHDS_Hypothesis *>() );
-
-  list<const SMESHDS_Hypothesis *>& alist = myShapeToHypothesis.ChangeFind( 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;
 }
 
 //=======================================================================
@@ -136,34 +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;
-                       }
-       }*/
-  if ( myShapeToHypothesis.IsBound( S ) )
+  if( myShapeToHypothesis.IsBound( S.Oriented(TopAbs_FORWARD) ) )
   {
-    list<const SMESHDS_Hypothesis *>& alist = myShapeToHypothesis.ChangeFind( S );
-    list<const SMESHDS_Hypothesis*>::iterator ith = alist.begin();
-
-               for (; ith != alist.end(); ith++)
-                       if (H == *ith)
-                       {
-                               alist.erase(ith);
-                               return true;
-                       }
+    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;
+  return false;
 }
 
 //=======================================================================
@@ -1039,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.IsBound(S) )
-               return myShapeToHypothesis.Find(S);
+  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;
 }
 
 //=======================================================================
@@ -1084,7 +1067,7 @@ bool SMESHDS_Mesh::HasMeshElements(const TopoDS_Shape & S)
 //=======================================================================
 bool SMESHDS_Mesh::HasHypothesis(const TopoDS_Shape & S)
 {
-       return myShapeToHypothesis.IsBound(S);
+  return myShapeToHypothesis.IsBound(S.Oriented(TopAbs_FORWARD));
 }
 
 //=======================================================================