Salome HOME
22364: EDF SMESH: Create Mesh dialog box improvement: hide inapplicable algorithms...
[modules/smesh.git] / src / StdMeshers / StdMeshers_Quadrangle_2D.cxx
index fd0cdb6ca1995b86efa725ac046f77a565c4f7e6..52bdb0aa560743b64e3cac0db68abdb3e52f726f 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
 #include "StdMeshers_QuadrangleParams.hxx"
 #include "StdMeshers_ViscousLayers2D.hxx"
 
+#include <BRepBndLib.hxx>
 #include <BRepClass_FaceClassifier.hxx>
 #include <BRep_Tool.hxx>
+#include <Bnd_Box.hxx>
 #include <GeomAPI_ProjectPointOnSurf.hxx>
 #include <Geom_Surface.hxx>
 #include <NCollection_DefineArray2.hxx>
@@ -902,6 +904,42 @@ bool StdMeshers_Quadrangle_2D::Evaluate(SMESH_Mesh&         aMesh,
   return true;
 }
 
+//================================================================================
+/*!
+ * \brief Return true if the algorithm can mesh this shape
+ *  \param [in] aShape - shape to check
+ *  \param [in] toCheckAll - if true, this check returns OK if all shapes are OK,
+ *              else, returns OK if at least one shape is OK
+ */
+//================================================================================
+
+bool StdMeshers_Quadrangle_2D::IsApplicable( const TopoDS_Shape & aShape, bool toCheckAll )
+{
+  int nbFoundFaces = 0;
+  for (TopExp_Explorer exp( aShape, TopAbs_FACE ); exp.More(); exp.Next(), ++nbFoundFaces )
+  {
+    TopoDS_Face aFace = TopoDS::Face(exp.Current());
+    if ( aFace.Orientation() >= TopAbs_INTERNAL ) aFace.Orientation( TopAbs_FORWARD );
+
+    list< TopoDS_Edge > aWire;
+    list< int > nbEdgesInWire;
+    int nbWire = SMESH_Block::GetOrderedEdges (aFace, aWire, nbEdgesInWire);
+    if ( nbWire != 1 ) {
+      if ( toCheckAll ) return false;
+      continue;
+    }
+
+    int nbNoDegenEdges = 0;
+    list<TopoDS_Edge>::iterator edge = aWire.begin();
+    for ( ; edge != aWire.end(); ++edge ) {
+      if ( !SMESH_Algo::isDegenerated( *edge ))
+        ++nbNoDegenEdges;
+    }
+    if ( toCheckAll  && nbNoDegenEdges <  3 ) return false;
+    if ( !toCheckAll && nbNoDegenEdges >= 3 ) return true;
+  }
+  return ( toCheckAll && nbFoundFaces != 0 );
+}
 
 //================================================================================
 /*!
@@ -3736,6 +3774,8 @@ void StdMeshers_Quadrangle_2D::smooth (FaceQuadStruct::Ptr quad)
 
   // Get nodes to smooth
 
+  // TODO: do not smooth fixed nodes
+
   typedef map< const SMDS_MeshNode*, TSmoothNode, TIDCompare > TNo2SmooNoMap;
   TNo2SmooNoMap smooNoMap;
 
@@ -4205,6 +4245,9 @@ bool StdMeshers_Quadrangle_2D::getEnforcedUV()
   surf->Bounds( u1,u2,v1,v2 );
   GeomAPI_ProjectPointOnSurf project;
   project.Init(surf, u1,u2, v1,v2, tol );
+  Bnd_Box bbox;
+  BRepBndLib::Add( face, bbox );
+  double farTol = 0.01 * sqrt( bbox.SquareExtent() );
 
   for ( size_t iP = 0; iP < points.size(); ++iP )
   {
@@ -4217,7 +4260,7 @@ bool StdMeshers_Quadrangle_2D::getEnforcedUV()
            << points[ iP ].X() << ", "<< points[ iP ].Y() << ", "<< points[ iP ].Z() << " )");
       continue;
     }
-    if ( project.LowerDistance() > tol*1000 )
+    if ( project.LowerDistance() > farTol )
     {
       if ( isStrictCheck && iP < nbPoints )
         return error