Salome HOME
Merge branch 'master' into pre/penta18
[modules/smesh.git] / src / StdMeshers / StdMeshers_Regular_1D.cxx
index 1b2ba291f06a886ea4d02ef6b8d7fee14235eb00..6746a502c1daef9cd0bd9655ceae17c87baafcde 100644 (file)
@@ -50,8 +50,8 @@
 #include "StdMeshers_SegmentLengthAroundVertex.hxx"
 #include "StdMeshers_StartEndLength.hxx"
 
-#include "Utils_SALOME_Exception.hxx"
-#include "utilities.h"
+#include <Utils_SALOME_Exception.hxx>
+#include <utilities.h>
 
 #include <BRepAdaptor_Curve.hxx>
 #include <BRep_Tool.hxx>
@@ -122,10 +122,11 @@ bool StdMeshers_Regular_1D::CheckHypothesis( SMESH_Mesh&         aMesh,
                                              const TopoDS_Shape& aShape,
                                              Hypothesis_Status&  aStatus )
 {
-  _hypType = NONE;
-  _quadraticMesh = false;
+  _hypType        = NONE;
+  _quadraticMesh  = false;
   _onlyUnaryInput = true;
 
+  // check propagation in a redefined GetUsedHypothesis()
   const list <const SMESHDS_Hypothesis * > & hyps =
     GetUsedHypothesis(aMesh, aShape, /*ignoreAuxiliaryHyps=*/false);
 
@@ -156,13 +157,17 @@ bool StdMeshers_Regular_1D::CheckHypothesis( SMESH_Mesh&         aMesh,
 
   string hypName = theHyp->GetName();
 
-  if ( hypName == "LocalLength" )
+  if ( !_mainEdge.IsNull() && _hypType == DISTRIB_PROPAGATION )
+  {
+    aStatus = SMESH_Hypothesis::HYP_OK;
+  }
+  else if ( hypName == "LocalLength" )
   {
     const StdMeshers_LocalLength * hyp =
       dynamic_cast <const StdMeshers_LocalLength * >(theHyp);
     ASSERT(hyp);
     _value[ BEG_LENGTH_IND ] = hyp->GetLength();
-    _value[ PRECISION_IND ] = hyp->GetPrecision();
+    _value[ PRECISION_IND  ] = hyp->GetPrecision();
     ASSERT( _value[ BEG_LENGTH_IND ] > 0 );
     _hypType = LOCAL_LENGTH;
     aStatus = SMESH_Hypothesis::HYP_OK;
@@ -386,6 +391,7 @@ static bool computeParamByFunc(Adaptor3d_Curve& C3d,
   }
   if ( theReverse )
     theParams.reverse();
+
   return true;
 }
 
@@ -393,15 +399,15 @@ static bool computeParamByFunc(Adaptor3d_Curve& C3d,
 //================================================================================
 /*!
  * \brief adjust internal node parameters so that the last segment length == an
 * \param a1 - the first segment length
 * \param an - the last segment length
 * \param U1 - the first edge parameter
 * \param Un - the last edge parameter
 * \param length - the edge length
 * \param C3d - the edge curve
 * \param theParams - internal node parameters to adjust
 * \param adjustNeighbors2an - to adjust length of segments next to the last one
 *  and not to remove parameters
 \param a1 - the first segment length
 \param an - the last segment length
 \param U1 - the first edge parameter
 \param Un - the last edge parameter
 \param length - the edge length
 \param C3d - the edge curve
 \param theParams - internal node parameters to adjust
 \param adjustNeighbors2an - to adjust length of segments next to the last one
  and not to remove parameters
  */
 //================================================================================
 
@@ -496,7 +502,7 @@ static void compensateError(double a1, double an,
 //    * \brief Clean mesh on edges
 //    * \param event - algo_event or compute_event itself (of SMESH_subMesh)
 //    * \param eventType - ALGO_EVENT or COMPUTE_EVENT (of SMESH_subMesh)
-//    * \param subMesh - the submesh where the event occures
+//    * \param subMesh - the submesh where the event occurs
 //    */
 //   void ProcessEvent(const int event, const int eventType, SMESH_subMesh* subMesh,
 //                     EventListenerData*, const SMESH_Hypothesis*)
@@ -672,10 +678,10 @@ bool StdMeshers_Regular_1D::computeInternalParameters(SMESH_Mesh &     theMesh,
 
   // Propagation Of Distribution
   //
-  if ( !_mainEdge.IsNull() && _isPropagOfDistribution )
+  if ( !_mainEdge.IsNull() && _hypType == DISTRIB_PROPAGATION )
   {
     TopoDS_Edge mainEdge = TopoDS::Edge( _mainEdge ); // should not be a reference!
-    _gen->Compute( theMesh, mainEdge, /*aShapeOnly=*/true, /*anUpward=*/true);
+    _gen->Compute( theMesh, mainEdge, SMESH_Gen::SHAPE_ONLY_UPWARD );
 
     SMESHDS_SubMesh* smDS = theMesh.GetMeshDS()->MeshElements( mainEdge );
     if ( !smDS )
@@ -992,8 +998,6 @@ bool StdMeshers_Regular_1D::computeInternalParameters(SMESH_Mesh &     theMesh,
   {
     const std::vector<double>& aPnts = _fpHyp->GetPoints();
     std::vector<int>          nbsegs = _fpHyp->GetNbSegments();
-    if ( theReverse )
-      std::reverse( nbsegs.begin(), nbsegs.end() );
 
     // sort normalized params, taking into account theReverse
     TColStd_SequenceOfReal Params;
@@ -1031,6 +1035,16 @@ bool StdMeshers_Regular_1D::computeInternalParameters(SMESH_Mesh &     theMesh,
     uVec.back() = theLastU;
 
     // divide segments
+    if ( theReverse )
+    {
+      if ((int) nbsegs.size() > Params.Length() + 1 )
+        nbsegs.resize( Params.Length() + 1 );
+      std::reverse( nbsegs.begin(), nbsegs.end() );
+    }
+    if ( nbsegs.empty() )
+    {
+      nbsegs.push_back( 1 );
+    }
     Params.InsertBefore( 1, 0.0 );
     Params.Append( 1.0 );
     double eltSize, segmentSize, par1, par2;
@@ -1120,15 +1134,14 @@ bool StdMeshers_Regular_1D::Compute(SMESH_Mesh & theMesh, const TopoDS_Shape & t
 
   ASSERT(!VFirst.IsNull());
   ASSERT(!VLast.IsNull());
-  const SMDS_MeshNode * idFirst = SMESH_Algo::VertexNode( VFirst, meshDS );
-  const SMDS_MeshNode * idLast = SMESH_Algo::VertexNode( VLast, meshDS );
-  if (!idFirst || !idLast)
+  const SMDS_MeshNode * nFirst = SMESH_Algo::VertexNode( VFirst, meshDS );
+  const SMDS_MeshNode *  nLast = SMESH_Algo::VertexNode( VLast,  meshDS );
+  if ( !nFirst || !nLast )
     return error( COMPERR_BAD_INPUT_MESH, "No node on vertex");
 
   // remove elements created by e.g. patern mapping (PAL21999)
   // CLEAN event is incorrectly ptopagated seemingly due to Propagation hyp
   // so TEMPORARY solution is to clean the submesh manually
-  //theMesh.GetSubMesh(theShape)->ComputeStateEngine( SMESH_subMesh::CLEAN );
   if (SMESHDS_SubMesh * subMeshDS = meshDS->MeshElements(theShape))
   {
     SMDS_ElemIteratorPtr ite = subMeshDS->GetElements();
@@ -1144,7 +1157,8 @@ bool StdMeshers_Regular_1D::Compute(SMESH_Mesh & theMesh, const TopoDS_Shape & t
     }
   }
 
-  if (!Curve.IsNull())
+  double length = EdgeLength( E );
+  if ( !Curve.IsNull() && length > 0 )
   {
     list< double > params;
     bool reversed = false;
@@ -1156,7 +1170,7 @@ bool StdMeshers_Regular_1D::Compute(SMESH_Mesh & theMesh, const TopoDS_Shape & t
       // take into account reversing the edge the hypothesis is propagated from
       // (_mainEdge.Orientation() marks mutual orientation of EDGEs in propagation chain)
       reversed = ( _mainEdge.Orientation() == TopAbs_REVERSED );
-      if ( !_isPropagOfDistribution ) {
+      if ( _hypType != DISTRIB_PROPAGATION ) {
         int mainID = meshDS->ShapeToIndex(_mainEdge);
         if ( std::find( _revEdgesIDs.begin(), _revEdgesIDs.end(), mainID) != _revEdgesIDs.end())
           reversed = !reversed;
@@ -1167,7 +1181,6 @@ bool StdMeshers_Regular_1D::Compute(SMESH_Mesh & theMesh, const TopoDS_Shape & t
       reversed = !reversed;
 
     BRepAdaptor_Curve C3d( E );
-    double length = EdgeLength( E );
     if ( ! computeInternalParameters( theMesh, C3d, length, f, l, params, reversed, true )) {
       return false;
     }
@@ -1176,19 +1189,10 @@ bool StdMeshers_Regular_1D::Compute(SMESH_Mesh & theMesh, const TopoDS_Shape & t
     // edge extrema (indexes : 1 & NbPoints) already in SMDS (TopoDS_Vertex)
     // only internal nodes receive an edge position with param on curve
 
-    const SMDS_MeshNode * idPrev = idFirst;
+    const SMDS_MeshNode * nPrev = nFirst;
     double parPrev = f;
     double parLast = l;
 
-    /* NPAL18025
-    if (reversed) {
-      idPrev = idLast;
-      idLast = idFirst;
-      idFirst = idPrev;
-      parPrev = l;
-      parLast = f;
-    }
-    */
     for (list<double>::iterator itU = params.begin(); itU != params.end(); itU++) {
       double param = *itU;
       gp_Pnt P = Curve->Value(param);
@@ -1200,18 +1204,18 @@ bool StdMeshers_Regular_1D::Compute(SMESH_Mesh & theMesh, const TopoDS_Shape & t
       if(_quadraticMesh) {
         // create medium node
         double prm = ( parPrev + param )/2;
-        gp_Pnt PM = Curve->Value(prm);
+        gp_Pnt  PM = Curve->Value(prm);
         SMDS_MeshNode * NM = meshDS->AddNode(PM.X(), PM.Y(), PM.Z());
         meshDS->SetNodeOnEdge(NM, shapeID, prm);
-        SMDS_MeshEdge * edge = meshDS->AddEdge(idPrev, node, NM);
+        SMDS_MeshEdge * edge = meshDS->AddEdge(nPrev, node, NM);
         meshDS->SetMeshElementOnShape(edge, shapeID);
       }
       else {
-        SMDS_MeshEdge * edge = meshDS->AddEdge(idPrev, node);
+        SMDS_MeshEdge * edge = meshDS->AddEdge(nPrev, node);
         meshDS->SetMeshElementOnShape(edge, shapeID);
       }
 
-      idPrev = node;
+      nPrev   = node;
       parPrev = param;
     }
     if(_quadraticMesh) {
@@ -1219,11 +1223,11 @@ bool StdMeshers_Regular_1D::Compute(SMESH_Mesh & theMesh, const TopoDS_Shape & t
       gp_Pnt PM = Curve->Value(prm);
       SMDS_MeshNode * NM = meshDS->AddNode(PM.X(), PM.Y(), PM.Z());
       meshDS->SetNodeOnEdge(NM, shapeID, prm);
-      SMDS_MeshEdge * edge = meshDS->AddEdge(idPrev, idLast, NM);
+      SMDS_MeshEdge * edge = meshDS->AddEdge(nPrev, nLast, NM);
       meshDS->SetMeshElementOnShape(edge, shapeID);
     }
     else {
-      SMDS_MeshEdge* edge = meshDS->AddEdge(idPrev, idLast);
+      SMDS_MeshEdge* edge = meshDS->AddEdge(nPrev, nLast);
       meshDS->SetMeshElementOnShape(edge, shapeID);
     }
   }
@@ -1236,7 +1240,7 @@ bool StdMeshers_Regular_1D::Compute(SMESH_Mesh & theMesh, const TopoDS_Shape & t
 
     gp_Pnt P = BRep_Tool::Pnt(VFirst);
 
-    const SMDS_MeshNode * idPrev = idFirst;
+    const SMDS_MeshNode * nPrev = nFirst;
     for (int i = 2; i < NbPoints; i++) {
       double param = f + (i - 1) * du;
       SMDS_MeshNode * node = meshDS->AddNode(P.X(), P.Y(), P.Z());
@@ -1245,26 +1249,26 @@ bool StdMeshers_Regular_1D::Compute(SMESH_Mesh & theMesh, const TopoDS_Shape & t
         double prm = param - du/2.;
         SMDS_MeshNode * NM = meshDS->AddNode(P.X(), P.Y(), P.Z());
         meshDS->SetNodeOnEdge(NM, shapeID, prm);
-        SMDS_MeshEdge * edge = meshDS->AddEdge(idPrev, node, NM);
+        SMDS_MeshEdge * edge = meshDS->AddEdge(nPrev, node, NM);
         meshDS->SetMeshElementOnShape(edge, shapeID);
       }
       else {
-        SMDS_MeshEdge * edge = meshDS->AddEdge(idPrev, node);
+        SMDS_MeshEdge * edge = meshDS->AddEdge(nPrev, node);
         meshDS->SetMeshElementOnShape(edge, shapeID);
       }
       meshDS->SetNodeOnEdge(node, shapeID, param);
-      idPrev = node;
+      nPrev = node;
     }
     if(_quadraticMesh) {
       // create medium node
       double prm = l - du/2.;
       SMDS_MeshNode * NM = meshDS->AddNode(P.X(), P.Y(), P.Z());
       meshDS->SetNodeOnEdge(NM, shapeID, prm);
-      SMDS_MeshEdge * edge = meshDS->AddEdge(idPrev, idLast, NM);
+      SMDS_MeshEdge * edge = meshDS->AddEdge(nPrev, nLast, NM);
       meshDS->SetMeshElementOnShape(edge, shapeID);
     }
     else {
-      SMDS_MeshEdge * edge = meshDS->AddEdge(idPrev, idLast);
+      SMDS_MeshEdge * edge = meshDS->AddEdge(nPrev, nLast);
       meshDS->SetMeshElementOnShape(edge, shapeID);
     }
   }
@@ -1278,9 +1282,9 @@ bool StdMeshers_Regular_1D::Compute(SMESH_Mesh & theMesh, const TopoDS_Shape & t
  */
 //=============================================================================
 
-bool StdMeshers_Regular_1D::Evaluate(SMESH_Mesh & theMesh,
+bool StdMeshers_Regular_1D::Evaluate(SMESH_Mesh &         theMesh,
                                      const TopoDS_Shape & theShape,
-                                     MapShapeNbElems& aResMap)
+                                     MapShapeNbElems&     theResMap)
 {
   if ( _hypType == NONE )
     return false;
@@ -1288,7 +1292,7 @@ bool StdMeshers_Regular_1D::Evaluate(SMESH_Mesh & theMesh,
   if ( _hypType == ADAPTIVE )
   {
     _adaptiveHyp->GetAlgo()->InitComputeError();
-    _adaptiveHyp->GetAlgo()->Evaluate( theMesh, theShape, aResMap );
+    _adaptiveHyp->GetAlgo()->Evaluate( theMesh, theShape, theResMap );
     return error( _adaptiveHyp->GetAlgo()->GetComputeError() );
   }
 
@@ -1306,14 +1310,14 @@ bool StdMeshers_Regular_1D::Evaluate(SMESH_Mesh & theMesh,
 
   std::vector<int> aVec(SMDSEntity_Last,0);
 
-  if (!Curve.IsNull()) {
+  double length = EdgeLength( E );
+  if ( !Curve.IsNull() && length > 0 )
+  {
     list< double > params;
-
     BRepAdaptor_Curve C3d( E );
-    double length = EdgeLength( E );
     if ( ! computeInternalParameters( theMesh, C3d, length, f, l, params, false, true )) {
       SMESH_subMesh * sm = theMesh.GetSubMesh(theShape);
-      aResMap.insert(std::make_pair(sm,aVec));
+      theResMap.insert(std::make_pair(sm,aVec));
       SMESH_ComputeErrorPtr& smError = sm->GetComputeError();
       smError.reset( new SMESH_ComputeError(COMPERR_ALGO_FAILED,"Submesh can not be evaluated",this));
       return false;
@@ -1321,19 +1325,19 @@ bool StdMeshers_Regular_1D::Evaluate(SMESH_Mesh & theMesh,
     redistributeNearVertices( theMesh, C3d, length, params, VFirst, VLast );
 
     if(_quadraticMesh) {
-      aVec[SMDSEntity_Node] = 2*params.size() + 1;
+      aVec[SMDSEntity_Node     ] = 2*params.size() + 1;
       aVec[SMDSEntity_Quad_Edge] = params.size() + 1;
     }
     else {
       aVec[SMDSEntity_Node] = params.size();
       aVec[SMDSEntity_Edge] = params.size() + 1;
     }
-    
+
   }
   else {
     // Edge is a degenerated Edge : We put n = 5 points on the edge.
     if ( _quadraticMesh ) {
-      aVec[SMDSEntity_Node] = 11;
+      aVec[SMDSEntity_Node     ] = 11;
       aVec[SMDSEntity_Quad_Edge] = 6;
     }
     else {
@@ -1342,8 +1346,8 @@ bool StdMeshers_Regular_1D::Evaluate(SMESH_Mesh & theMesh,
     }
   }
 
-  SMESH_subMesh * sm = theMesh.GetSubMesh(theShape);
-  aResMap.insert(std::make_pair(sm,aVec));
+  SMESH_subMesh * sm = theMesh.GetSubMesh( theShape );
+  theResMap.insert( std::make_pair( sm, aVec ));
 
   return true;
 }
@@ -1372,10 +1376,13 @@ StdMeshers_Regular_1D::GetUsedHypothesis(SMESH_Mesh &         aMesh,
   if (nbHyp == 0 && aShape.ShapeType() == TopAbs_EDGE)
   {
     // Check, if propagated from some other edge
+    bool isPropagOfDistribution = false;
     _mainEdge = StdMeshers_Propagation::GetPropagationSource( aMesh, aShape,
-                                                              _isPropagOfDistribution );
+                                                              isPropagOfDistribution );
     if ( !_mainEdge.IsNull() )
     {
+      if ( isPropagOfDistribution )
+        _hypType = DISTRIB_PROPAGATION;
       // Propagation of 1D hypothesis from <aMainEdge> on this edge;
       // get non-auxiliary assigned to _mainEdge
       nbHyp = aMesh.GetHypotheses( _mainEdge, *compatibleFilter, _usedHypList, true );