Salome HOME
Corrected for bug IPAL12571.
[modules/smesh.git] / src / StdMeshers / StdMeshers_Quadrangle_2D.cxx
index 589ca5267154eb5c1ee17ab5217ee835f5e54a02..c880c9ce16707d8da51f351f9f775fa7b44bd3d3 100644 (file)
@@ -36,6 +36,7 @@
 #include "SMESH_subMesh.hxx"
 #include "SMESH_MesherHelper.hxx"
 #include "SMESH_Block.hxx"
+#include "SMESH_Comment.hxx"
 
 #include "SMDS_MeshElement.hxx"
 #include "SMDS_MeshNode.hxx"
@@ -74,6 +75,7 @@ DEFINE_ARRAY2(StdMeshers_Array2OfNode,
 using namespace std;
 
 typedef gp_XY gp_UV;
+typedef SMESH_Comment TComm;
 
 //=============================================================================
 /*!
@@ -117,7 +119,7 @@ bool StdMeshers_Quadrangle_2D::CheckHypothesis
   aStatus = SMESH_Hypothesis::HYP_OK;
 
   // there is only one compatible Hypothesis so far
-  const list <const SMESHDS_Hypothesis * >&hyps = GetUsedHypothesis(aMesh, aShape);
+  const list <const SMESHDS_Hypothesis * >&hyps = GetUsedHypothesis(aMesh, aShape, false);
   myQuadranglePreference = hyps.size() > 0;
 
   return isOk;
@@ -130,9 +132,10 @@ bool StdMeshers_Quadrangle_2D::CheckHypothesis
 //=============================================================================
 
 bool StdMeshers_Quadrangle_2D::Compute (SMESH_Mesh& aMesh,
-                                        const TopoDS_Shape& aShape) throw (SALOME_Exception)
+                                        const TopoDS_Shape& aShape)// throw (SALOME_Exception)
 {
-  Unexpect aCatch(SalomeException);
+  // PAL14921. Enable catching std::bad_alloc and Standard_OutOfMemory outside
+  //Unexpect aCatchSalomeException);
 
   SMESHDS_Mesh * meshDS = aMesh.GetMeshDS();
   aMesh.GetSubMesh(aShape);
@@ -560,10 +563,8 @@ bool StdMeshers_Quadrangle_2D::Compute (SMESH_Mesh& aMesh,
 
 FaceQuadStruct* StdMeshers_Quadrangle_2D::CheckNbEdges(SMESH_Mesh &         aMesh,
                                                        const TopoDS_Shape & aShape)
-     throw(SALOME_Exception)
+  //throw(SALOME_Exception)
 {
-  Unexpect aCatch(SalomeException);
-
   const TopoDS_Face & F = TopoDS::Face(aShape);
   const bool ignoreMediumNodes = _quadraticMesh;
 
@@ -573,7 +574,7 @@ FaceQuadStruct* StdMeshers_Quadrangle_2D::CheckNbEdges(SMESH_Mesh &         aMes
   list< int > nbEdgesInWire;
   int nbWire = SMESH_Block::GetOrderedEdges (F, V, edges, nbEdgesInWire);
   if (nbWire != 1) {
-    INFOS("only 1 wire by face (quadrangles)");
+    error(COMPERR_BAD_SHAPE, TComm("Wrong number of wires: ") << nbWire);
     return 0;
   }
   FaceQuadStruct* quad = new FaceQuadStruct;
@@ -594,16 +595,14 @@ FaceQuadStruct* StdMeshers_Quadrangle_2D::CheckNbEdges(SMESH_Mesh &         aMes
       sideEdges.splice( sideEdges.end(), edges, edges.begin()); // edges.front() -> sideEdges.end()
       bool sameSide = true;
       while ( !edges.empty() && sameSide ) {
-        GeomAbs_Shape cont = SMESH_Algo::Continuity( sideEdges.back(), edges.front() );
-        sameSide = ( cont >= GeomAbs_G1 );
+        sameSide = SMESH_Algo::IsContinuous( sideEdges.back(), edges.front() );
         if ( sameSide )
           sideEdges.splice( sideEdges.end(), edges, edges.begin());
       }
       if ( nbSides == 0 ) { // go backward from the first edge
         sameSide = true;
         while ( !edges.empty() && sameSide ) {
-          GeomAbs_Shape cont = SMESH_Algo::Continuity( sideEdges.front(), edges.back() );
-          sameSide = ( cont >= GeomAbs_G1 );
+          sameSide = SMESH_Algo::IsContinuous( sideEdges.front(), edges.back() );
           if ( sameSide )
             sideEdges.splice( sideEdges.begin(), edges, --edges.end());
         }
@@ -623,9 +622,10 @@ FaceQuadStruct* StdMeshers_Quadrangle_2D::CheckNbEdges(SMESH_Mesh &         aMes
       cout << ")";
     }
     cout << endl;
-#else
-    INFOS("face must have 4 edges / quadrangle");
 #endif
+    if ( !nbSides )
+      nbSides = nbEdgesInWire.front();
+    error(COMPERR_BAD_SHAPE, TComm("Face must have 4 sides but not ") << nbSides);
     delete quad;
     quad = 0;
   }
@@ -642,10 +642,8 @@ FaceQuadStruct* StdMeshers_Quadrangle_2D::CheckNbEdges(SMESH_Mesh &         aMes
 FaceQuadStruct *StdMeshers_Quadrangle_2D::CheckAnd2Dcompute
                            (SMESH_Mesh &         aMesh,
                             const TopoDS_Shape & aShape,
-                            const bool           CreateQuadratic) throw(SALOME_Exception)
+                            const bool           CreateQuadratic) //throw(SALOME_Exception)
 {
-  Unexpect aCatch(SalomeException);
-
   _quadraticMesh = CreateQuadratic;
 
   FaceQuadStruct *quad = CheckNbEdges(aMesh, aShape);
@@ -653,7 +651,12 @@ FaceQuadStruct *StdMeshers_Quadrangle_2D::CheckAnd2Dcompute
   if(!quad) return 0;
 
   // set normalized grid on unit square in parametric domain
-  SetNormalizedGrid(aMesh, aShape, quad);
+  bool stat = SetNormalizedGrid(aMesh, aShape, quad);
+  if(!stat) {
+    if(!quad)
+      delete quad;
+    quad = 0;
+  }
 
   return quad;
 }
@@ -668,7 +671,6 @@ faceQuadStruct::~faceQuadStruct()
 {
   for (int i = 0; i < side.size(); i++) {
     if (side[i])     delete side[i];
-    //if (uv_edges[i]) delete [] uv_edges[i];
   }
   if (uv_grid)       delete [] uv_grid;
 }
@@ -676,7 +678,7 @@ faceQuadStruct::~faceQuadStruct()
 namespace {
   inline const vector<UVPtStruct>& GetUVPtStructIn(FaceQuadStruct* quad, int i, int nbSeg)
   {
-    bool isXConst = ( i == BOTTOM_SIDE || i == TOP_SIDE );
+    bool   isXConst   = ( i == BOTTOM_SIDE || i == TOP_SIDE );
     double constValue = ( i == BOTTOM_SIDE || i == LEFT_SIDE ) ? 0 : 1;
     return
       quad->isEdgeOut[i] ?
@@ -693,9 +695,8 @@ namespace {
 
 bool StdMeshers_Quadrangle_2D::SetNormalizedGrid (SMESH_Mesh & aMesh,
                                                   const TopoDS_Shape& aShape,
-                                                  FaceQuadStruct* & quad) throw (SALOME_Exception)
+                                                  FaceQuadStruct* & quad) //throw (SALOME_Exception)
 {
-  Unexpect aCatch(SalomeException);
   // Algorithme décrit dans "Génération automatique de maillages"
   // P.L. GEORGE, MASSON, § 6.4.1 p. 84-85
   // traitement dans le domaine paramétrique 2d u,v
@@ -735,10 +736,9 @@ bool StdMeshers_Quadrangle_2D::SetNormalizedGrid (SMESH_Mesh & aMesh,
   const vector<UVPtStruct>& uv_e2 = GetUVPtStructIn( quad, 2, nbhoriz - 1 );
   const vector<UVPtStruct>& uv_e3 = GetUVPtStructIn( quad, 3, nbvertic - 1 );
 
-  if ( uv_e0.empty() || uv_e1.empty() || uv_e2.empty() || uv_e3.empty() ) {
-    MESSAGE("Nodes from edges not loaded");
-    return false;
-  }
+  if ( uv_e0.empty() || uv_e1.empty() || uv_e2.empty() || uv_e3.empty() )
+    //return error( "Can't find nodes on sides");
+    return error( COMPERR_BAD_INPUT_MESH );
 
   // nodes Id on "in" edges
   if (! quad->isEdgeOut[0]) {
@@ -876,39 +876,31 @@ static gp_UV CalcUV(double x0, double x1, double y0, double y1,
 
   uv -= (1 - x) * (1 - y) * a0 + x * (1 - y) * a1 + x * y * a2 + (1 - x) * y * a3;
 
-  //cout<<"x0="<<x0<<" x1="<<x1<<" y0="<<y0<<" y1="<<y1<<endl;
-  //cout<<"x="<<x<<" y="<<y<<endl;
-  //cout<<"param_b="<<param_b<<" param_t="<<param_t<<" param_r="<<param_r<<" param_l="<<param_l<<endl;
-  //cout<<"u="<<u<<" v="<<v<<endl;
-
   return uv;
 }
 
-//=======================================================================
-//function : ComputeQuadPref
-//purpose  : 
 //=======================================================================
 /*!
- * Special function for creation only quandrangle faces
+ * Create only quandrangle faces
  */
-bool StdMeshers_Quadrangle_2D::ComputeQuadPref
-                          (SMESH_Mesh &        aMesh,
-                           const TopoDS_Shape& aShape,
-                           FaceQuadStruct*     quad) throw (SALOME_Exception)
-{
-  Unexpect aCatch(SalomeException);
+//=======================================================================
 
+bool StdMeshers_Quadrangle_2D::ComputeQuadPref (SMESH_Mesh &        aMesh,
+                                                const TopoDS_Shape& aShape,
+                                                FaceQuadStruct*     quad)
+{
   SMESHDS_Mesh * meshDS = aMesh.GetMeshDS();
   const TopoDS_Face& F = TopoDS::Face(aShape);
   Handle(Geom_Surface) S = BRep_Tool::Surface(F);
-  const TopoDS_Wire& W = BRepTools::OuterWire(F);
-  bool WisF = false;
-  if(W.Orientation()==TopAbs_FORWARD) 
-    WisF = true;
+//  const TopoDS_Wire& W = BRepTools::OuterWire(F);
+  bool WisF = true;
+//   if(W.Orientation()==TopAbs_FORWARD) 
+//     WisF = true;
   //if(WisF) cout<<"W is FORWARD"<<endl;
   //else cout<<"W is REVERSED"<<endl;
-  bool FisF = (F.Orientation()==TopAbs_FORWARD);
-  if(!FisF) WisF = !WisF;
+//   bool FisF = (F.Orientation()==TopAbs_FORWARD);
+//   if(!FisF) WisF = !WisF;
+//  WisF = FisF;
   int i,j,geomFaceID = meshDS->ShapeToIndex( F );
 
   int nb = quad->side[0]->NbPoints();