Salome HOME
23239: [CEA 1739] Regression : crash trying to create mesh
[modules/smesh.git] / src / StdMeshers / StdMeshers_Projection_1D2D.cxx
index b64c5ad9e99f3ee2f8afad07e556108bbec1d45c..125412c9f9a67653510a28c7b40061f51e9b01e7 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2007-2013  CEA/DEN, EDF R&D, OPEN CASCADE
+// Copyright (C) 2007-2015  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
@@ -124,6 +124,38 @@ bool StdMeshers_Projection_1D2D::Compute(SMESH_Mesh& theMesh, const TopoDS_Shape
   SMESH_MesherHelper helper( theMesh );
   helper.SetSubShape( theShape );
 
+  if ( _quadraticMesh )
+  {
+    // 2a) Move some medium nodes from FACE to EDGES. They are on FACE because
+    // EDGEs are discreteized later than FACE, in this case.
+
+    SMESH_MesherHelper posFixer( theMesh );
+    posFixer.ToFixNodeParameters( true );
+    SMDS_ElemIteratorPtr fIt = faceSubMesh->GetElements();
+    vector< const SMDS_MeshNode* > nodes;
+    double dummyU, tol = 1e-7;
+    while ( fIt->more() ) // loop on mesh faces created by StdMeshers_Projection_2D
+    {
+      const SMDS_MeshElement* f = fIt->next();
+      //if ( !f->IsQuadratic() ) continue;
+      nodes.assign( SMDS_MeshElement::iterator( f->interlacedNodesElemIterator() ),
+                    SMDS_MeshElement::iterator() );
+      nodes.push_back( nodes[0] );
+      for ( size_t i = 2; i < nodes.size(); i += 2 )
+      {
+        pair<int, TopAbs_ShapeEnum> idType = helper.GetMediumPos( nodes[i], nodes[i-2] );
+        if ( idType.second == TopAbs_EDGE &&
+             idType.first  != nodes[i-1]->getshapeId() )
+        {
+          faceSubMesh->RemoveNode( nodes[i-1], /*isDeleted=*/false );
+          meshDS->SetNodeOnEdge( (SMDS_MeshNode*) nodes[i-1], idType.first );
+          posFixer.SetSubShape( idType.first );
+          posFixer.CheckNodeU( TopoDS::Edge( posFixer.GetSubShape() ),
+                               nodes[i-1], dummyU=0., tol, /*force=*/true );
+        }
+      }
+    }
+  }
   TopoDS_Face F = TopoDS::Face( theShape );
   TError err;
   TSideVector wires = StdMeshers_FaceSide::GetFaceWires( F, theMesh,