Salome HOME
22806: EDF SMESH: Regression: Prism_3D error
[modules/smesh.git] / src / SMESH / SMESH_Algo.cxx
index 8beda034e2fc3fedfdceb0efe6a1ef87f09ebccb..5ec1240b00bdcb9c8fd007e413b47c2d9b18a589 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2007-2013  CEA/DEN, EDF R&D, OPEN CASCADE
+// Copyright (C) 2007-2014  CEA/DEN, EDF R&D, OPEN CASCADE
 //
 // Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
@@ -6,7 +6,7 @@
 // This library is free software; you can redistribute it and/or
 // modify it under the terms of the GNU Lesser General Public
 // License as published by the Free Software Foundation; either
-// version 2.1 of the License.
+// version 2.1 of the License, or (at your option) any later version.
 //
 // This library is distributed in the hope that it will be useful,
 // but WITHOUT ANY WARRANTY; without even the implied warranty of
@@ -178,6 +178,7 @@ const SMESH_Algo::Features& SMESH_Algo::GetFeatures( const std::string& algoType
 SMESH_Algo::SMESH_Algo (int hypId, int studyId, SMESH_Gen * gen)
   : SMESH_Hypothesis(hypId, studyId, gen)
 {
+  _compatibleAllHypFilter = _compatibleNoAuxHypFilter = NULL;
   _onlyUnaryInput = _requireDiscreteBoundary = _requireShape = true;
   _quadraticMesh = _supportSubmeshes = false;
   _error = COMPERR_OK;
@@ -193,6 +194,8 @@ SMESH_Algo::SMESH_Algo (int hypId, int studyId, SMESH_Gen * gen)
 
 SMESH_Algo::~SMESH_Algo()
 {
+  delete _compatibleNoAuxHypFilter;
+  // delete _compatibleAllHypFilter; -- _compatibleNoAuxHypFilter does it!!!
 }
 
 //=============================================================================
@@ -263,10 +266,9 @@ SMESH_Algo::GetUsedHypothesis(SMESH_Mesh &         aMesh,
 {
   SMESH_Algo* me = const_cast< SMESH_Algo* >( this );
   me->_usedHypList.clear();
-  SMESH_HypoFilter filter;
-  if ( InitCompatibleHypoFilter( filter, ignoreAuxiliary ))
+  if ( const SMESH_HypoFilter* filter = GetCompatibleHypoFilter( ignoreAuxiliary ))
   {
-    aMesh.GetHypotheses( aShape, filter, me->_usedHypList, true );
+    aMesh.GetHypotheses( aShape, *filter, me->_usedHypList, true );
     if ( ignoreAuxiliary && _usedHypList.size() > 1 )
       me->_usedHypList.clear(); //only one compatible hypothesis allowed
   }
@@ -288,9 +290,8 @@ SMESH_Algo::GetAppliedHypothesis(SMESH_Mesh &         aMesh,
 {
   SMESH_Algo* me = const_cast< SMESH_Algo* >( this );
   me->_appliedHypList.clear();
-  SMESH_HypoFilter filter;
-  if ( InitCompatibleHypoFilter( filter, ignoreAuxiliary ))
-    aMesh.GetHypotheses( aShape, filter, me->_appliedHypList, false );
+  if ( const SMESH_HypoFilter* filter = GetCompatibleHypoFilter( ignoreAuxiliary ))
+    aMesh.GetHypotheses( aShape, *filter, me->_appliedHypList, false );
 
   return _appliedHypList;
 }
@@ -410,7 +411,7 @@ bool SMESH_Algo::GetSortedNodesOnEdge(const SMESHDS_Mesh*                   theM
     return false;
 
   SMESHDS_SubMesh * eSubMesh = theMesh->MeshElements( theEdge );
-  if ( !eSubMesh || ( eSubMesh->NbElements()==0 && eSubMesh->NbNodes() == 0))
+  if ( !eSubMesh || ( eSubMesh->NbElements()==0 &&  eSubMesh->NbNodes() == 0))
     return false; // edge is not meshed
 
   int nbNodes = 0;
@@ -457,27 +458,35 @@ bool SMESH_Algo::GetSortedNodesOnEdge(const SMESHDS_Mesh*                   theM
 
 //================================================================================
 /*!
- * \brief Make filter recognize only compatible hypotheses
- * \param theFilter - the filter to initialize
- * \param ignoreAuxiliary - make filter ignore compatible auxiliary hypotheses
+ * \brief Returns the filter recognizing only compatible hypotheses
+ *  \param ignoreAuxiliary - make filter ignore auxiliary hypotheses
+ *  \retval SMESH_HypoFilter* - the filter that can be NULL
  */
 //================================================================================
 
-bool SMESH_Algo::InitCompatibleHypoFilter( SMESH_HypoFilter & theFilter,
-                                           const bool         ignoreAuxiliary) const
+const SMESH_HypoFilter*
+SMESH_Algo::GetCompatibleHypoFilter(const bool ignoreAuxiliary) const
 {
   if ( !_compatibleHypothesis.empty() )
   {
-    theFilter.Init( theFilter.HasName( _compatibleHypothesis[0] ));
-    for ( int i = 1; i < _compatibleHypothesis.size(); ++i )
-      theFilter.Or( theFilter.HasName( _compatibleHypothesis[ i ] ));
-
-    if ( ignoreAuxiliary )
-      theFilter.AndNot( theFilter.IsAuxiliary() );
-
-    return true;
+    if ( !_compatibleAllHypFilter )
+    {
+      SMESH_HypoFilter* filter = new SMESH_HypoFilter();
+      filter->Init( filter->HasName( _compatibleHypothesis[0] ));
+      for ( int i = 1; i < _compatibleHypothesis.size(); ++i )
+        filter->Or( filter->HasName( _compatibleHypothesis[ i ] ));
+
+      SMESH_HypoFilter* filterNoAux = new SMESH_HypoFilter( filter );
+      filterNoAux->AndNot( filterNoAux->IsAuxiliary() );
+
+      // _compatibleNoAuxHypFilter will detele _compatibleAllHypFilter!!!
+      SMESH_Algo* me = const_cast< SMESH_Algo* >( this );
+      me->_compatibleAllHypFilter   = filter;
+      me->_compatibleNoAuxHypFilter = filterNoAux;
+    }
+    return ignoreAuxiliary ? _compatibleNoAuxHypFilter : _compatibleAllHypFilter;
   }
-  return false;
+  return 0;
 }
 
 //================================================================================
@@ -513,9 +522,7 @@ GeomAbs_Shape SMESH_Algo::Continuity(TopoDS_Edge E1,
   Standard_Real tol = BRep_Tool::Tolerance( V );
   Standard_Real angTol = 2e-3;
   try {
-#if OCC_VERSION_LARGE > 0x06010000
     OCC_CATCH_SIGNALS;
-#endif
     return BRepLProp::Continuity(C1, C2, u1, u2, tol, angTol);
   }
   catch (Standard_Failure) {
@@ -594,6 +601,7 @@ bool SMESH_Algo::isDegenerated( const TopoDS_Edge & E )
  * \param V - the vertex
  * \param meshDS - mesh
  * \retval const SMDS_MeshNode* - found node or NULL
+ * \sa SMESH_MesherHelper::GetSubShapeByNode( const SMDS_MeshNode*, SMESHDS_Mesh* )
  */
 //================================================================================