Salome HOME
52459: Viscous layers are not normal to the surface.
[modules/smesh.git] / src / SMESH / SMESH_Mesh.cxx
index a7c20a0c5d844fc7fa88e65648da134d2e11e8ef..dcdf7fe3f81ecb4cba3b7eff76455e3e5347230b 100644 (file)
@@ -773,7 +773,30 @@ const SMESH_Hypothesis * SMESH_Mesh::GetHypothesis(const TopoDS_Shape &    aSubS
                                                    const bool              andAncestors,
                                                    TopoDS_Shape*           assignedTo) const
 {
+  return GetHypothesis( const_cast< SMESH_Mesh* >(this)->GetSubMesh( aSubShape ),
+                        aFilter, andAncestors, assignedTo );
+}
+
+//=======================================================================
+/*!
+ * \brief Return the hypothesis assigned to the shape of a sub-mesh
+ *  \param aSubMesh     - the sub-mesh to check
+ *  \param aFilter      - the hypothesis filter
+ *  \param andAncestors - flag to check hypos assigned to ancestors of the shape
+ *  \param assignedTo   - to return the shape the found hypo is assigned to
+ *  \retval SMESH_Hypothesis* - the first hypo passed through aFilter
+ */
+//=======================================================================
+
+const SMESH_Hypothesis * SMESH_Mesh::GetHypothesis(const SMESH_subMesh *   aSubMesh,
+                                                   const SMESH_HypoFilter& aFilter,
+                                                   const bool              andAncestors,
+                                                   TopoDS_Shape*           assignedTo) const
+{
+  if ( !aSubMesh ) return 0;
+
   {
+    const TopoDS_Shape & aSubShape = aSubMesh->GetSubShape();
     const list<const SMESHDS_Hypothesis*>& hypList = _myMeshDS->GetHypothesis(aSubShape);
     list<const SMESHDS_Hypothesis*>::const_iterator hyp = hypList.begin();
     for ( ; hyp != hypList.end(); hyp++ ) {
@@ -787,9 +810,12 @@ const SMESH_Hypothesis * SMESH_Mesh::GetHypothesis(const TopoDS_Shape &    aSubS
   if ( andAncestors )
   {
     // user sorted submeshes of ancestors, according to stored submesh priority
-    getAncestorsSubMeshes( aSubShape, _ancestorSubMeshes );
-    vector<SMESH_subMesh*>::const_iterator smIt = _ancestorSubMeshes.begin(); 
-    for ( ; smIt != _ancestorSubMeshes.end(); smIt++ )
+    std::vector< SMESH_subMesh * > & ancestors =
+      const_cast< std::vector< SMESH_subMesh * > & > ( aSubMesh->GetAncestors() );
+    SortByMeshOrder( ancestors );
+
+    vector<SMESH_subMesh*>::const_iterator smIt = ancestors.begin(); 
+    for ( ; smIt != ancestors.end(); smIt++ )
     {
       const TopoDS_Shape& curSh = (*smIt)->GetSubShape();
       const list<const SMESHDS_Hypothesis*>& hypList = _myMeshDS->GetHypothesis(curSh);
@@ -808,7 +834,7 @@ const SMESH_Hypothesis * SMESH_Mesh::GetHypothesis(const TopoDS_Shape &    aSubS
 
 //================================================================================
 /*!
- * \brief Return hypothesis assigned to the shape
+ * \brief Return hypotheses assigned to the shape
   * \param aSubShape - the shape to check
   * \param aFilter - the hypothesis filter
   * \param aHypList - the list of the found hypotheses
@@ -823,6 +849,29 @@ int SMESH_Mesh::GetHypotheses(const TopoDS_Shape &                aSubShape,
                               const bool                          andAncestors,
                               list< TopoDS_Shape > *              assignedTo/*=0*/) const
 {
+  return GetHypotheses( const_cast< SMESH_Mesh* >(this)->GetSubMesh( aSubShape ),
+                        aFilter, aHypList, andAncestors, assignedTo );
+}
+
+//================================================================================
+/*!
+ * \brief Return hypotheses assigned to the shape of a sub-mesh
+  * \param aSubShape - the sub-mesh to check
+  * \param aFilter - the hypothesis filter
+  * \param aHypList - the list of the found hypotheses
+  * \param andAncestors - flag to check hypos assigned to ancestors of the shape
+  * \retval int - number of unique hypos in aHypList
+ */
+//================================================================================
+
+int SMESH_Mesh::GetHypotheses(const SMESH_subMesh *               aSubMesh,
+                              const SMESH_HypoFilter&             aFilter,
+                              list <const SMESHDS_Hypothesis * >& aHypList,
+                              const bool                          andAncestors,
+                              list< TopoDS_Shape > *              assignedTo/*=0*/) const
+{
+  if ( !aSubMesh ) return 0;
+
   set<string> hypTypes; // to exclude same type hypos from the result list
   int nbHyps = 0;
 
@@ -840,6 +889,7 @@ int SMESH_Mesh::GetHypotheses(const TopoDS_Shape &                aSubShape,
 
   // get hypos from aSubShape
   {
+    const TopoDS_Shape & aSubShape = aSubMesh->GetSubShape();
     const list<const SMESHDS_Hypothesis*>& hypList = _myMeshDS->GetHypothesis(aSubShape);
     for ( hyp = hypList.begin(); hyp != hypList.end(); hyp++ )
       if ( aFilter.IsOk (cSMESH_Hyp( *hyp ), aSubShape) &&
@@ -857,16 +907,15 @@ int SMESH_Mesh::GetHypotheses(const TopoDS_Shape &                aSubShape,
   // get hypos from ancestors of aSubShape
   if ( andAncestors )
   {
-    TopTools_MapOfShape map;
-
     // user sorted submeshes of ancestors, according to stored submesh priority
-    getAncestorsSubMeshes( aSubShape, _ancestorSubMeshes );
-    vector<SMESH_subMesh*>::const_iterator smIt = _ancestorSubMeshes.begin();
-    for ( ; smIt != _ancestorSubMeshes.end(); smIt++ )
+    std::vector< SMESH_subMesh * > & ancestors =
+      const_cast< std::vector< SMESH_subMesh * > & > ( aSubMesh->GetAncestors() );
+    SortByMeshOrder( ancestors );
+
+    vector<SMESH_subMesh*>::const_iterator smIt = ancestors.begin();
+    for ( ; smIt != ancestors.end(); smIt++ )
     {
       const TopoDS_Shape& curSh = (*smIt)->GetSubShape();
-      if ( !map.Add( curSh ))
-        continue;
       const list<const SMESHDS_Hypothesis*>& hypList = _myMeshDS->GetHypothesis(curSh);
       for ( hyp = hypList.begin(); hyp != hypList.end(); hyp++ )
         if (( aFilter.IsOk( cSMESH_Hyp( *hyp ), curSh ))         &&
@@ -935,6 +984,8 @@ SMESH_subMesh *SMESH_Mesh::GetSubMesh(const TopoDS_Shape & aSubShape)
   throw(SALOME_Exception)
 {
   int index = _myMeshDS->ShapeToIndex(aSubShape);
+  if ( !index && aSubShape.IsNull() )
+    return 0;
 
   // for submeshes on GEOM Group
   if (( !index || index > _nbSubShapes ) && aSubShape.ShapeType() == TopAbs_COMPOUND ) {
@@ -947,14 +998,29 @@ SMESH_subMesh *SMESH_Mesh::GetSubMesh(const TopoDS_Shape & aSubShape)
         fillAncestorsMap( _myMeshDS->IndexToShape( ++_nbSubShapes ));
     }
   }
-//   if ( !index )
-//     return NULL; // neither sub-shape nor a group
+  // if ( !index )
+  //   return NULL; // neither sub-shape nor a group
 
   SMESH_subMesh* aSubMesh = _subMeshHolder->Get( index );
   if ( !aSubMesh )
   {
     aSubMesh = new SMESH_subMesh(index, this, _myMeshDS, aSubShape);
     _subMeshHolder->Add( index, aSubMesh );
+
+    // include non-computable sub-meshes in SMESH_subMesh::_ancestors of sub-submeshes
+    switch ( aSubShape.ShapeType() ) {
+    case TopAbs_COMPOUND:
+    case TopAbs_WIRE:
+    case TopAbs_SHELL:
+      for ( TopoDS_Iterator subIt( aSubShape ); subIt.More(); subIt.Next() )
+      {
+        SMESH_subMesh* sm = GetSubMesh( subIt.Value() );
+        SMESH_subMeshIteratorPtr smIt = sm->getDependsOnIterator(/*inclideSelf=*/true);
+        while ( smIt->more() )
+          smIt->next()->ClearAncestors();
+      }
+    default:;
+    }
   }
   return aSubMesh;
 }
@@ -1047,9 +1113,7 @@ bool SMESH_Mesh::IsUsedHypothesis(SMESHDS_Hypothesis * anHyp,
   if ( !aSubMesh || !aSubMesh->IsApplicableHypotesis( hyp ))
     return false;
 
-  const TopoDS_Shape & aSubShape = const_cast<SMESH_subMesh*>( aSubMesh )->GetSubShape();
-
-  SMESH_Algo *algo = _gen->GetAlgo(*this, aSubShape );
+  SMESH_Algo *algo = aSubMesh->GetAlgo();
 
   // algorithm
   if (anHyp->GetType() > SMESHDS_Hypothesis::PARAM_ALGO)
@@ -1062,7 +1126,7 @@ bool SMESH_Mesh::IsUsedHypothesis(SMESHDS_Hypothesis * anHyp,
     const SMESH_HypoFilter* hypoKind;
     if (( hypoKind = algo->GetCompatibleHypoFilter( !hyp->IsAuxiliary() ))) {
       list <const SMESHDS_Hypothesis * > usedHyps;
-      if ( GetHypotheses( aSubShape, *hypoKind, usedHyps, true ))
+      if ( GetHypotheses( aSubMesh, *hypoKind, usedHyps, true ))
         return ( find( usedHyps.begin(), usedHyps.end(), anHyp ) != usedHyps.end() );
     }
   }
@@ -1110,6 +1174,9 @@ void SMESH_Mesh::NotifySubMeshesHypothesisModification(const SMESH_Hypothesis* h
   const SMESH_HypoFilter* compatibleHypoKind;
   list <const SMESHDS_Hypothesis * > usedHyps;
 
+  // keep sub-meshes not to miss ones whose state can change due to notifying others
+  vector< SMESH_subMesh* > smToNotify;
+
   SMESH_subMeshIteratorPtr smIt( _subMeshHolder->GetIterator() );
   while ( smIt->more() )
   {
@@ -1134,14 +1201,20 @@ void SMESH_Mesh::NotifySubMeshesHypothesisModification(const SMESH_Hypothesis* h
     {
       // check if hyp is used by algo
       usedHyps.clear();
-      if ( GetHypotheses( aSubShape, *compatibleHypoKind, usedHyps, true ) &&
+      if ( GetHypotheses( aSubMesh, *compatibleHypoKind, usedHyps, true ) &&
            find( usedHyps.begin(), usedHyps.end(), hyp ) != usedHyps.end() )
       {
-        aSubMesh->AlgoStateEngine(SMESH_subMesh::MODIF_HYP,
-                                  const_cast< SMESH_Hypothesis*>( hyp ));
+        smToNotify.push_back( aSubMesh );
       }
     }
   }
+
+  for ( size_t i = 0; i < smToNotify.size(); ++i )
+  {
+    smToNotify[i]->AlgoStateEngine(SMESH_subMesh::MODIF_HYP,
+                                   const_cast< SMESH_Hypothesis*>( hyp ));
+  }
+
   HasModificationsToDiscard(); // to reset _isModified flag if mesh becomes empty
   GetMeshDS()->Modified();
 }
@@ -2141,6 +2214,7 @@ void SMESH_Mesh::fillAncestorsMap(const TopoDS_Shape& theShape)
           ancList.InsertBefore( theShape, ancIt );
       }
   }
+  else // else added for 52457: Addition of hypotheses is 8 time longer than meshing
   {
     for ( desType = TopAbs_VERTEX; desType > TopAbs_COMPOUND; desType-- )
       for ( ancType = desType - 1; ancType >= TopAbs_COMPOUND; ancType-- )
@@ -2152,9 +2226,11 @@ void SMESH_Mesh::fillAncestorsMap(const TopoDS_Shape& theShape)
   // visit COMPOUNDs inside a COMPOUND that are not reachable by TopExp_Explorer
   if ( theShape.ShapeType() == TopAbs_COMPOUND )
   {
-    for ( TopoDS_Iterator sIt(theShape); sIt.More(); sIt.Next() )
-      if ( sIt.Value().ShapeType() == TopAbs_COMPOUND )
-        fillAncestorsMap( sIt.Value() );
+    TopoDS_Iterator sIt(theShape);
+    if ( sIt.More() && sIt.Value().ShapeType() == TopAbs_COMPOUND )
+      for ( ; sIt.More(); sIt.Next() )
+        if ( sIt.Value().ShapeType() == TopAbs_COMPOUND )
+          fillAncestorsMap( sIt.Value() );
   }
 }