Salome HOME
PAL10237. Add StdMeshers_AutomaticLength 1D hypothesis
[modules/smesh.git] / src / StdMeshers / StdMeshers_Regular_1D.cxx
index be3e69f1d9fcc6549ec165fc5308af920f886309..2bdf91da96956ac58406489b7ecdb57d4b526be3 100644 (file)
@@ -38,6 +38,7 @@ using namespace std;
 #include "StdMeshers_Arithmetic1D.hxx"
 #include "StdMeshers_StartEndLength.hxx"
 #include "StdMeshers_Deflection1D.hxx"
+#include <StdMeshers_AutomaticLength.hxx>
 
 #include "SMDS_MeshElement.hxx"
 #include "SMDS_MeshNode.hxx"
@@ -84,6 +85,7 @@ StdMeshers_Regular_1D::StdMeshers_Regular_1D(int hypId, int studyId,
        _compatibleHypothesis.push_back("StartEndLength");
        _compatibleHypothesis.push_back("Deflection1D");
        _compatibleHypothesis.push_back("Arithmetic1D");
+       _compatibleHypothesis.push_back("AutomaticLength");
 }
 
 //=============================================================================
@@ -198,6 +200,17 @@ bool StdMeshers_Regular_1D::CheckHypothesis
     _hypType = DEFLECTION;
     aStatus = SMESH_Hypothesis::HYP_OK;
   }
+
+  else if (hypName == "AutomaticLength")
+  {
+    StdMeshers_AutomaticLength * hyp = const_cast<StdMeshers_AutomaticLength *>
+      (dynamic_cast <const StdMeshers_AutomaticLength * >(theHyp));
+    ASSERT(hyp);
+    _value[ BEG_LENGTH_IND ] = _value[ END_LENGTH_IND ] = hyp->GetLength( &aMesh, aShape );
+    ASSERT( _value[ BEG_LENGTH_IND ] > 0 );
+    _hypType = LOCAL_LENGTH;
+    aStatus = SMESH_Hypothesis::HYP_OK;
+  }
   else
     aStatus = SMESH_Hypothesis::HYP_INCOMPATIBLE;
 
@@ -699,6 +712,7 @@ bool StdMeshers_Regular_1D::Compute(SMESH_Mesh & aMesh, const TopoDS_Shape & aSh
 
   const TopoDS_Edge & EE = TopoDS::Edge(aShape);
   TopoDS_Edge E = TopoDS::Edge(EE.Oriented(TopAbs_FORWARD));
+  int shapeID = meshDS->ShapeToIndex( E );
 
   double f, l;
   Handle(Geom_Curve) Curve = BRep_Tool::Curve(E, f, l);
@@ -750,19 +764,14 @@ bool StdMeshers_Regular_1D::Compute(SMESH_Mesh & aMesh, const TopoDS_Shape & aSh
 
       //Add the Node in the DataStructure
       SMDS_MeshNode * node = meshDS->AddNode(P.X(), P.Y(), P.Z());
-      meshDS->SetNodeOnEdge(node, E);
-
-      // **** edgePosition associe au point = param. 
-      SMDS_EdgePosition* epos =
-        dynamic_cast<SMDS_EdgePosition *>(node->GetPosition().get());
-      epos->SetUParameter(param);
+      meshDS->SetNodeOnEdge(node, shapeID, param);
 
       SMDS_MeshEdge * edge = meshDS->AddEdge(idPrev, node);
-      meshDS->SetMeshElementOnShape(edge, E);
+      meshDS->SetMeshElementOnShape(edge, shapeID);
       idPrev = node;
     }
     SMDS_MeshEdge* edge = meshDS->AddEdge(idPrev, idLast);
-    meshDS->SetMeshElementOnShape(edge, E);
+    meshDS->SetMeshElementOnShape(edge, shapeID);
   }
   else
   {
@@ -781,18 +790,14 @@ bool StdMeshers_Regular_1D::Compute(SMESH_Mesh & aMesh, const TopoDS_Shape & aSh
     {
       double param = f + (i - 1) * du;
       SMDS_MeshNode * node = meshDS->AddNode(P.X(), P.Y(), P.Z());
-      meshDS->SetNodeOnEdge(node, E);
-
-      SMDS_EdgePosition* epos =
-        dynamic_cast<SMDS_EdgePosition*>(node->GetPosition().get());
-      epos->SetUParameter(param);
+      meshDS->SetNodeOnEdge(node, shapeID, param);
 
       SMDS_MeshEdge * edge = meshDS->AddEdge(idPrev, node);
-      meshDS->SetMeshElementOnShape(edge, E);
+      meshDS->SetMeshElementOnShape(edge, shapeID);
       idPrev = node;
     }
     SMDS_MeshEdge * edge = meshDS->AddEdge(idPrev, idLast);
-    meshDS->SetMeshElementOnShape(edge, E);
+    meshDS->SetMeshElementOnShape(edge, shapeID);
   }
   return true;
 }