Salome HOME
PR: synchro V7_main tag mergefrom_V6_main_28Feb13
[modules/smesh.git] / src / SMESH / SMESH_MesherHelper.cxx
index 661d8da8975e76d17bfb32c0a2f50234de7fbde1..4f732effc61f0fa0f569a847094c4184d174144a 100644 (file)
 #include "SMDS_FacePosition.hxx" 
 #include "SMDS_IteratorOnIterators.hxx"
 #include "SMDS_VolumeTool.hxx"
+#include "SMESH_Block.hxx"
 #include "SMESH_ProxyMesh.hxx"
 #include "SMESH_subMesh.hxx"
 
 #include <BRepAdaptor_Curve.hxx>
 #include <BRepAdaptor_Surface.hxx>
-#include <BRepClass3d_SolidClassifier.hxx>
 #include <BRepTools.hxx>
-#include <BRepTools_WireExplorer.hxx>
 #include <BRep_Tool.hxx>
 #include <Geom2d_Curve.hxx>
 #include <GeomAPI_ProjectPointOnCurve.hxx>
@@ -199,7 +198,7 @@ bool SMESH_MesherHelper::IsQuadraticSubMesh(const TopoDS_Shape& aSh)
 
 //=======================================================================
 //function : SetSubShape
-//purpose  : Set geomerty to make elements on
+//purpose  : Set geometry to make elements on
 //=======================================================================
 
 void SMESH_MesherHelper::SetSubShape(const int aShID)
@@ -214,7 +213,7 @@ void SMESH_MesherHelper::SetSubShape(const int aShID)
 
 //=======================================================================
 //function : SetSubShape
-//purpose  : Set geomerty to create elements on
+//purpose  : Set geometry to create elements on
 //=======================================================================
 
 void SMESH_MesherHelper::SetSubShape(const TopoDS_Shape& aSh)
@@ -283,6 +282,18 @@ void SMESH_MesherHelper::SetSubShape(const TopoDS_Shape& aSh)
             myDegenShapeIds.insert( meshDS->ShapeToIndex( v.Current() ));
         }
       }
+      if ( !myDegenShapeIds.empty() && !myParIndex ) {
+        if ( surface->IsUPeriodic() || surface->IsUClosed() ) {
+          myParIndex |= U_periodic;
+          myPar1[0] = surf.FirstUParameter();
+          myPar2[0] = surf.LastUParameter();
+        }
+        else if ( surface->IsVPeriodic() || surface->IsVClosed() ) {
+          myParIndex |= V_periodic;
+          myPar1[1] = surf.FirstVParameter();
+          myPar2[1] = surf.LastVParameter();
+        }
+      }
     }
   }
 }
@@ -329,7 +340,7 @@ bool SMESH_MesherHelper::IsMedium(const SMDS_MeshNode*      node,
 TopoDS_Shape SMESH_MesherHelper::GetSubShapeByNode(const SMDS_MeshNode* node,
                                                    const SMESHDS_Mesh*  meshDS)
 {
-  int shapeID = node->getshapeId();
+  int shapeID = node ? node->getshapeId() : 0;
   if ( 0 < shapeID && shapeID <= meshDS->MaxShapeIndex() )
     return meshDS->IndexToShape( shapeID );
   else
@@ -1697,6 +1708,25 @@ namespace
   }
 }
 
+//=======================================================================
+//function : IsSameElemGeometry
+//purpose  : Returns true if all elements of a sub-mesh are of same shape
+//=======================================================================
+
+bool SMESH_MesherHelper::IsSameElemGeometry(const SMESHDS_SubMesh* smDS,
+                                            SMDSAbs_GeometryType   shape,
+                                            const bool             nullSubMeshRes)
+{
+  if ( !smDS ) return nullSubMeshRes;
+
+  SMDS_ElemIteratorPtr elemIt = smDS->GetElements();
+  while ( elemIt->more() )
+    if ( elemIt->next()->GetGeomType() != shape )
+      return false;
+
+  return true;
+}
+
 //=======================================================================
 //function : LoadNodeColumns
 //purpose  : Load nodes bound to face into a map of node columns
@@ -1726,7 +1756,7 @@ bool SMESH_MesherHelper::LoadNodeColumns(TParam2ColumnMap &            theParam2
                                          SMESHDS_Mesh*                 theMesh,
                                          SMESH_ProxyMesh*              theProxyMesh)
 {
-  // get a right submesh of theFace
+  // get a right sub-mesh of theFace
 
   const SMESHDS_SubMesh* faceSubMesh = 0;
   if ( theProxyMesh )
@@ -1746,70 +1776,74 @@ bool SMESH_MesherHelper::LoadNodeColumns(TParam2ColumnMap &            theParam2
   if ( !faceSubMesh || faceSubMesh->NbElements() == 0 )
     return false;
 
-  // get data of edges for normalization of params
-
-  vector< double > length;
-  double fullLen = 0;
-  list<TopoDS_Edge>::const_iterator edge;
+  if ( theParam2ColumnMap.empty() )
   {
-    for ( edge = theBaseSide.begin(); edge != theBaseSide.end(); ++edge )
+    // get data of edges for normalization of params
+
+    vector< double > length;
+    double fullLen = 0;
+    list<TopoDS_Edge>::const_iterator edge;
     {
-      double len = std::max( 1e-10, SMESH_Algo::EdgeLength( *edge ));
-      fullLen += len;
-      length.push_back( len );
+      for ( edge = theBaseSide.begin(); edge != theBaseSide.end(); ++edge )
+      {
+        double len = std::max( 1e-10, SMESH_Algo::EdgeLength( *edge ));
+        fullLen += len;
+        length.push_back( len );
+      }
     }
-  }
-
-  // get nodes on theBaseEdge sorted by param on edge and initialize theParam2ColumnMap with them
-  edge = theBaseSide.begin();
-  for ( int iE = 0; edge != theBaseSide.end(); ++edge, ++iE )
-  {
-    map< double, const SMDS_MeshNode*> sortedBaseNodes;
-    SMESH_Algo::GetSortedNodesOnEdge( theMesh, *edge,/*noMedium=*/true, sortedBaseNodes);
-    if ( sortedBaseNodes.empty() ) continue;
 
-    map< double, const SMDS_MeshNode*>::iterator u_n = sortedBaseNodes.begin();
-    if ( theProxyMesh ) // from sortedBaseNodes remove nodes not shared by faces of faceSubMesh
+    // get nodes on theBaseEdge sorted by param on edge and initialize theParam2ColumnMap with them
+    edge = theBaseSide.begin();
+    for ( int iE = 0; edge != theBaseSide.end(); ++edge, ++iE )
     {
-      const SMDS_MeshNode* n1 = sortedBaseNodes.begin()->second;
-      const SMDS_MeshNode* n2 = sortedBaseNodes.rbegin()->second;
-      bool allNodesAreProxy = ( n1 != theProxyMesh->GetProxyNode( n1 ) &&
-                                n2 != theProxyMesh->GetProxyNode( n2 ));
-      if ( allNodesAreProxy )
-        for ( u_n = sortedBaseNodes.begin(); u_n != sortedBaseNodes.end(); u_n++ )
-          u_n->second = theProxyMesh->GetProxyNode( u_n->second );
-
-      if ( u_n = sortedBaseNodes.begin(), !isNodeInSubMesh( u_n->second, faceSubMesh ))
+      map< double, const SMDS_MeshNode*> sortedBaseNN;
+      SMESH_Algo::GetSortedNodesOnEdge( theMesh, *edge,/*noMedium=*/true, sortedBaseNN);
+      if ( sortedBaseNN.empty() ) continue;
+
+      map< double, const SMDS_MeshNode*>::iterator u_n = sortedBaseNN.begin();
+      if ( theProxyMesh ) // from sortedBaseNN remove nodes not shared by faces of faceSubMesh
       {
-        while ( ++u_n != sortedBaseNodes.end() && !isNodeInSubMesh( u_n->second, faceSubMesh ));
-        sortedBaseNodes.erase( sortedBaseNodes.begin(), u_n );
+        const SMDS_MeshNode* n1 = sortedBaseNN.begin()->second;
+        const SMDS_MeshNode* n2 = sortedBaseNN.rbegin()->second;
+        bool allNodesAreProxy = ( n1 != theProxyMesh->GetProxyNode( n1 ) &&
+                                  n2 != theProxyMesh->GetProxyNode( n2 ));
+        if ( allNodesAreProxy )
+          for ( u_n = sortedBaseNN.begin(); u_n != sortedBaseNN.end(); u_n++ )
+            u_n->second = theProxyMesh->GetProxyNode( u_n->second );
+
+        if ( u_n = sortedBaseNN.begin(), !isNodeInSubMesh( u_n->second, faceSubMesh ))
+        {
+          while ( ++u_n != sortedBaseNN.end() && !isNodeInSubMesh( u_n->second, faceSubMesh ));
+          sortedBaseNN.erase( sortedBaseNN.begin(), u_n );
+        }
+        else if ( u_n = --sortedBaseNN.end(), !isNodeInSubMesh( u_n->second, faceSubMesh ))
+        {
+          while ( u_n != sortedBaseNN.begin() && !isNodeInSubMesh( (--u_n)->second, faceSubMesh ));
+          sortedBaseNN.erase( ++u_n, sortedBaseNN.end() );
+        }
+        if ( sortedBaseNN.empty() ) continue;
       }
-      else if ( u_n = --sortedBaseNodes.end(), !isNodeInSubMesh( u_n->second, faceSubMesh ))
+
+      double f, l;
+      BRep_Tool::Range( *edge, f, l );
+      if ( edge->Orientation() == TopAbs_REVERSED ) std::swap( f, l );
+      const double coeff = 1. / ( l - f ) * length[iE] / fullLen;
+      const double prevPar = theParam2ColumnMap.empty() ? 0 : theParam2ColumnMap.rbegin()->first;
+      for ( u_n = sortedBaseNN.begin(); u_n != sortedBaseNN.end(); u_n++ )
       {
-        while ( u_n != sortedBaseNodes.begin() && !isNodeInSubMesh( (--u_n)->second, faceSubMesh ));
-        sortedBaseNodes.erase( ++u_n, sortedBaseNodes.end() );
+        double par = prevPar + coeff * ( u_n->first - f );
+        TParam2ColumnMap::iterator u2nn =
+          theParam2ColumnMap.insert( theParam2ColumnMap.end(), make_pair( par, TNodeColumn()));
+        u2nn->second.push_back( u_n->second );
       }
-      if ( sortedBaseNodes.empty() ) continue;
-    }
-
-    double f, l;
-    BRep_Tool::Range( *edge, f, l );
-    if ( edge->Orientation() == TopAbs_REVERSED ) std::swap( f, l );
-    const double coeff = 1. / ( l - f ) * length[iE] / fullLen;
-    const double prevPar = theParam2ColumnMap.empty() ? 0 : theParam2ColumnMap.rbegin()->first;
-    for ( u_n = sortedBaseNodes.begin(); u_n != sortedBaseNodes.end(); u_n++ )
-    {
-      double par = prevPar + coeff * ( u_n->first - f );
-      TParam2ColumnMap::iterator u2nn =
-        theParam2ColumnMap.insert( theParam2ColumnMap.end(), make_pair( par, TNodeColumn()));
-      u2nn->second.push_back( u_n->second );
     }
+    if ( theParam2ColumnMap.empty() )
+      return false;
   }
-  if ( theParam2ColumnMap.empty() )
-    return false;
-
 
-  int nbRows = 1 + faceSubMesh->NbElements() / ( theParam2ColumnMap.size()-1 );
+  // nb rows of nodes
+  int prevNbRows     = theParam2ColumnMap.begin()->second.size(); // current, at least 1 here
+  int expectedNbRows = faceSubMesh->NbElements() / ( theParam2ColumnMap.size()-1 ); // to be added
 
   // fill theParam2ColumnMap column by column by passing from nodes on
   // theBaseEdge up via mesh faces on theFace
@@ -1822,35 +1856,245 @@ bool SMESH_MesherHelper::LoadNodeColumns(TParam2ColumnMap &            theParam2
   {
     vector<const SMDS_MeshNode*>& nCol1 = par_nVec_1->second;
     vector<const SMDS_MeshNode*>& nCol2 = par_nVec_2->second;
-    nCol1.resize( nbRows );
-    nCol2.resize( nbRows );
+    nCol1.resize( prevNbRows + expectedNbRows );
+    nCol2.resize( prevNbRows + expectedNbRows );
 
-    int i1, i2, iRow = 0;
-    const SMDS_MeshNode *n1 = nCol1[0], *n2 = nCol2[0];
+    int i1, i2, foundNbRows = 0;
+    const SMDS_MeshNode *n1 = nCol1[ prevNbRows-1 ];
+    const SMDS_MeshNode *n2 = nCol2[ prevNbRows-1 ];
     // find face sharing node n1 and n2 and belonging to faceSubMesh
     while ( const SMDS_MeshElement* face =
             SMESH_MeshEditor::FindFaceInSet( n1, n2, emptySet, avoidSet, &i1, &i2))
     {
       if ( faceSubMesh->Contains( face ))
       {
-        int nbNodes = face->IsQuadratic() ? face->NbNodes()/2 : face->NbNodes();
+        int nbNodes = face->NbCornerNodes();
         if ( nbNodes != 4 )
           return false;
+        if ( foundNbRows + 1 > expectedNbRows )
+          return false;
         n1 = face->GetNode( (i2+2) % 4 ); // opposite corner of quadrangle face
         n2 = face->GetNode( (i1+2) % 4 );
-        if ( ++iRow >= nbRows )
-          return false;
-        nCol1[ iRow ] = n1;
-        nCol2[ iRow ] = n2;
-        avoidSet.clear();
+        nCol1[ prevNbRows + foundNbRows] = n1;
+        nCol2[ prevNbRows + foundNbRows] = n2;
+        ++foundNbRows;
       }
       avoidSet.insert( face );
     }
-    // set a real height
-    nCol1.resize( iRow + 1 );
-    nCol2.resize( iRow + 1 );
+    if ( foundNbRows != expectedNbRows )
+      return false;
+    avoidSet.clear();
+  }
+  return ( theParam2ColumnMap.size() > 1 &&
+           theParam2ColumnMap.begin()->second.size() == prevNbRows + expectedNbRows );
+}
+
+namespace
+{
+  //================================================================================
+  /*!
+   * \brief Return true if a node is at a corner of a 2D structured mesh of FACE
+   */
+  //================================================================================
+
+  bool isCornerOfStructure( const SMDS_MeshNode*   n,
+                            const SMESHDS_SubMesh* faceSM )
+  {
+    int nbFacesInSM = 0;
+    if ( n ) {
+      SMDS_ElemIteratorPtr fIt = n->GetInverseElementIterator( SMDSAbs_Face );
+      while ( fIt->more() )
+        nbFacesInSM += faceSM->Contains( fIt->next() );
+    }
+    return ( nbFacesInSM == 1 );
+  }
+}
+
+//=======================================================================
+//function : IsStructured
+//purpose  : Return true if 2D mesh on FACE is structured
+//=======================================================================
+
+bool SMESH_MesherHelper::IsStructured( SMESH_subMesh* faceSM )
+{
+  SMESHDS_SubMesh* fSM = faceSM->GetSubMeshDS();
+  if ( !fSM || fSM->NbElements() == 0 )
+    return false;
+
+  list< TopoDS_Edge > edges;
+  list< int > nbEdgesInWires;
+  int nbWires = SMESH_Block::GetOrderedEdges( TopoDS::Face( faceSM->GetSubShape() ),
+                                              edges, nbEdgesInWires );
+  if ( nbWires != 1 )
+    return false;
+
+  // algo: find corners of a structure and then analyze nb of faces and
+  // length of structure sides
+
+  SMESHDS_Mesh* meshDS = faceSM->GetFather()->GetMeshDS();
+
+  // rotate edges to get the first node being at corner
+  // (in principle it's not necessary but so far none SALOME algo can make
+  //  such a structured mesh that all corner nodes are not on VERTEXes)
+  bool isCorner     = false;
+  int nbRemainEdges = nbEdgesInWires.front();
+  do {
+    TopoDS_Vertex V = IthVertex( 0, edges.front() );
+    isCorner = isCornerOfStructure( SMESH_Algo::VertexNode( V, meshDS ), fSM);
+    if ( !isCorner ) {
+      edges.splice( edges.end(), edges, edges.begin() );
+      --nbRemainEdges;
+    }
+  }
+  while ( !isCorner && nbRemainEdges > 0 );
+
+  if ( !isCorner )
+    return false;
+
+  // get all nodes from EDGEs
+  list< const SMDS_MeshNode* > nodes;
+  list< TopoDS_Edge >::iterator edge = edges.begin();
+  for ( ; edge != edges.end(); ++edge )
+  {
+    map< double, const SMDS_MeshNode* > u2Nodes;
+    if ( !SMESH_Algo::GetSortedNodesOnEdge( meshDS, *edge,
+                                            /*skipMedium=*/true, u2Nodes ))
+      return false;
+
+    list< const SMDS_MeshNode* > edgeNodes;
+    map< double, const SMDS_MeshNode* >::iterator u2n = u2Nodes.begin();
+    if ( !nodes.empty() && nodes.back() == u2n->second )
+      ++u2n;
+    map< double, const SMDS_MeshNode* >::iterator u2nEnd = --u2Nodes.end();
+    if ( nodes.empty() || nodes.back() != u2nEnd->second )
+      ++u2nEnd;
+    for ( ; u2n != u2nEnd; ++u2n )
+      edgeNodes.push_back( u2n->second );
+
+    if ( edge->Orientation() == TopAbs_REVERSED )
+      edgeNodes.reverse();
+    nodes.splice( nodes.end(), edgeNodes, edgeNodes.begin(), edgeNodes.end() );
+  }
+
+  // get length of structured sides
+  vector<int> nbEdgesInSide;
+  int nbEdges = 0;
+  list< const SMDS_MeshNode* >::iterator n = ++nodes.begin();
+  for ( ; n != nodes.end(); ++n )
+  {
+    ++nbEdges;
+    if ( isCornerOfStructure( *n, fSM )) {
+      nbEdgesInSide.push_back( nbEdges );
+      nbEdges = 0;
+    }
+  }
+
+  // checks
+  if ( nbEdgesInSide.size() != 4 )
+    return false;
+  if ( nbEdgesInSide[0] != nbEdgesInSide[2] )
+    return false;
+  if ( nbEdgesInSide[1] != nbEdgesInSide[3] )
+    return false;
+  if ( nbEdgesInSide[0] * nbEdgesInSide[1] != fSM->NbElements() )
+    return false;
+
+  return true;
+}
+
+//================================================================================
+/*!
+ * \brief Find out elements orientation on a geometrical face
+ * \param theFace - The face correctly oriented in the shape being meshed
+ * \retval bool - true if the face normal and the normal of first element
+ *                in the correspoding submesh point in different directions
+ */
+//================================================================================
+
+bool SMESH_MesherHelper::IsReversedSubMesh (const TopoDS_Face& theFace)
+{
+  if ( theFace.IsNull() )
+    return false;
+
+  // find out orientation of a meshed face
+  int faceID = GetMeshDS()->ShapeToIndex( theFace );
+  TopoDS_Shape aMeshedFace = GetMeshDS()->IndexToShape( faceID );
+  bool isReversed = ( theFace.Orientation() != aMeshedFace.Orientation() );
+
+  const SMESHDS_SubMesh * aSubMeshDSFace = GetMeshDS()->MeshElements( faceID );
+  if ( !aSubMeshDSFace )
+    return isReversed;
+
+  // find an element with a good normal
+  gp_Vec Ne;
+  bool normalOK = false;
+  gp_XY uv;
+  SMDS_ElemIteratorPtr iteratorElem = aSubMeshDSFace->GetElements();
+  while ( !normalOK && iteratorElem->more() ) // loop on elements on theFace
+  {
+    const SMDS_MeshElement* elem = iteratorElem->next();
+    if ( elem && elem->NbCornerNodes() > 2 )
+    {
+      SMESH_TNodeXYZ nPnt[3];
+      SMDS_ElemIteratorPtr nodesIt = elem->nodesIterator();
+      for ( int iN = 0; nodesIt->more() && iN < 3; ++iN) // loop on nodes
+        nPnt[ iN ] = nodesIt->next();
+
+      // compute normal
+      gp_Vec v01( nPnt[0], nPnt[1] ), v02( nPnt[0], nPnt[2] );
+      if ( v01.SquareMagnitude() > RealSmall() &&
+           v02.SquareMagnitude() > RealSmall() )
+      {
+        Ne = v01 ^ v02;
+        if (( normalOK = ( Ne.SquareMagnitude() > RealSmall() )))
+          uv = GetNodeUV( theFace, nPnt[0]._node, nPnt[2]._node, &normalOK );
+      }
+    }
+  }
+  if ( !normalOK )
+    return isReversed;
+
+  // face normal at node position
+  TopLoc_Location loc;
+  Handle(Geom_Surface) surf = BRep_Tool::Surface( theFace, loc );
+  // if ( surf.IsNull() || surf->Continuity() < GeomAbs_C1 )
+  // some surfaces not detected as GeomAbs_C1 are nevertheless correct for meshing
+  if ( surf.IsNull() || surf->Continuity() < GeomAbs_C0 )
+    {
+      if (!surf.IsNull())
+        MESSAGE("surf->Continuity() < GeomAbs_C1 " << (surf->Continuity() < GeomAbs_C1));
+      return isReversed;
+    }
+  gp_Vec d1u, d1v; gp_Pnt p;
+  surf->D1( uv.X(), uv.Y(), p, d1u, d1v );
+  gp_Vec Nf = (d1u ^ d1v).Transformed( loc );
+
+  if ( theFace.Orientation() == TopAbs_REVERSED )
+    Nf.Reverse();
+
+  return Ne * Nf < 0.;
+}
+
+//=======================================================================
+//function : Count
+//purpose  : Count nb of sub-shapes
+//=======================================================================
+
+int SMESH_MesherHelper::Count(const TopoDS_Shape&    shape,
+                              const TopAbs_ShapeEnum type,
+                              const bool             ignoreSame)
+{
+  if ( ignoreSame ) {
+    TopTools_IndexedMapOfShape map;
+    TopExp::MapShapes( shape, type, map );
+    return map.Extent();
+  }
+  else {
+    int nb = 0;
+    for ( TopExp_Explorer exp( shape, type ); exp.More(); exp.Next() )
+      ++nb;
+    return nb;
   }
-  return theParam2ColumnMap.size() > 1 && theParam2ColumnMap.begin()->second.size() > 1;
 }
 
 //=======================================================================
@@ -2025,6 +2269,8 @@ SMESH_MesherHelper:: MType SMESH_MesherHelper::IsQuadraticMesh()
   int NbFacesAndEdges=0;
   //All faces and edges
   NbAllEdgsAndFaces = myMesh->NbEdges() + myMesh->NbFaces();
+  if ( NbAllEdgsAndFaces == 0 )
+    return SMESH_MesherHelper::LINEAR;
   
   //Quadratic faces and edges
   NbQuadFacesAndEdgs = myMesh->NbEdges(ORDER_QUADRATIC) + myMesh->NbFaces(ORDER_QUADRATIC);
@@ -3426,7 +3672,7 @@ namespace { // Structures used by FixQuadraticElements()
  */
 //=======================================================================
 
-void SMESH_MesherHelper::FixQuadraticElements(SMESH_ComputeErrorPtr& error,
+void SMESH_MesherHelper::FixQuadraticElements(SMESH_ComputeErrorPtr& compError,
                                               bool                   volumeOnly)
 {
   // setenv NO_FixQuadraticElements to know if FixQuadraticElements() is guilty of bad conversion
@@ -3460,7 +3706,8 @@ void SMESH_MesherHelper::FixQuadraticElements(SMESH_ComputeErrorPtr& error,
 #endif
         SMESH_MesherHelper h(*myMesh);
         h.SetSubShape( s.Current() );
-        h.FixQuadraticElements( error, false );
+        h.ToFixNodeParameters(true);
+        h.FixQuadraticElements( compError, false );
       }
     }
     // fix nodes on geom faces
@@ -3471,12 +3718,12 @@ void SMESH_MesherHelper::FixQuadraticElements(SMESH_ComputeErrorPtr& error,
       MSG("FIX FACE " << nbfaces-- << " #" << GetMeshDS()->ShapeToIndex(fIt.Key()));
       SMESH_MesherHelper h(*myMesh);
       h.SetSubShape( fIt.Key() );
-      h.FixQuadraticElements( error, true);
       h.ToFixNodeParameters(true);
+      h.FixQuadraticElements( compError, true);
     }
     //perf_print_all_meters(1);
-    if ( error && error->myName == EDITERR_NO_MEDIUM_ON_GEOM )
-      error->myComment = "during conversion to quadratic, "
+    if ( compError && compError->myName == EDITERR_NO_MEDIUM_ON_GEOM )
+      compError->myComment = "during conversion to quadratic, "
         "some medium nodes were not placed on geometry to avoid distorting elements";
     return;
   }
@@ -3519,7 +3766,7 @@ void SMESH_MesherHelper::FixQuadraticElements(SMESH_ComputeErrorPtr& error,
   // Issue 0020982
   // Move medium nodes to the link middle for elements whose corner nodes
   // are out of geometrical boundary to fix distorted elements.
-  force3DOutOfBoundary( *this, error );
+  force3DOutOfBoundary( *this, compError );
 
   if ( elemType == SMDSAbs_Volume )
   {
@@ -3593,7 +3840,9 @@ void SMESH_MesherHelper::FixQuadraticElements(SMESH_ComputeErrorPtr& error,
         QLink link( face->GetNode(iN), face->GetNode((iN+1)%nbN), face->GetNode(iN+nbN) );
         pLink = links.insert( link ).first;
         faceLinks[ iN ] = & *pLink;
-        if ( !isCurved )
+        if ( !isCurved &&
+             link.node1()->GetPosition()->GetTypeOfPosition() < 2 &&
+             link.node2()->GetPosition()->GetTypeOfPosition() < 2 )
           isCurved = !link.IsStraight();
       }
       // store QFace