Salome HOME
c3430af05eed4bbd54719167bbd881ac0743312e
[modules/smesh.git] / src / StdMeshers / StdMeshers_Regular_1D.cxx
1 // Copyright (C) 2007-2016  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 // Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
5 //
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License, or (at your option) any later version.
10 //
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14 // Lesser General Public License for more details.
15 //
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
19 //
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 //
22
23 //  File   : StdMeshers_Regular_1D.cxx
24 //           Moved here from SMESH_Regular_1D.cxx
25 //  Author : Paul RASCLE, EDF
26 //  Module : SMESH
27 //
28 #include "StdMeshers_Regular_1D.hxx"
29
30 #include "SMDS_MeshElement.hxx"
31 #include "SMDS_MeshNode.hxx"
32 #include "SMESHDS_Mesh.hxx"
33 #include "SMESH_Comment.hxx"
34 #include "SMESH_Gen.hxx"
35 #include "SMESH_HypoFilter.hxx"
36 #include "SMESH_Mesh.hxx"
37 #include "SMESH_subMesh.hxx"
38 #include "SMESH_subMeshEventListener.hxx"
39 #include "StdMeshers_Adaptive1D.hxx"
40 #include "StdMeshers_Arithmetic1D.hxx"
41 #include "StdMeshers_AutomaticLength.hxx"
42 #include "StdMeshers_Geometric1D.hxx"
43 #include "StdMeshers_Deflection1D.hxx"
44 #include "StdMeshers_Distribution.hxx"
45 #include "StdMeshers_FixedPoints1D.hxx"
46 #include "StdMeshers_LocalLength.hxx"
47 #include "StdMeshers_MaxLength.hxx"
48 #include "StdMeshers_NumberOfSegments.hxx"
49 #include "StdMeshers_Propagation.hxx"
50 #include "StdMeshers_SegmentLengthAroundVertex.hxx"
51 #include "StdMeshers_StartEndLength.hxx"
52
53 #include "Utils_SALOME_Exception.hxx"
54 #include "utilities.h"
55
56 #include <BRepAdaptor_Curve.hxx>
57 #include <BRep_Tool.hxx>
58 #include <GCPnts_AbscissaPoint.hxx>
59 #include <GCPnts_UniformAbscissa.hxx>
60 #include <GCPnts_UniformDeflection.hxx>
61 #include <Precision.hxx>
62 #include <TopExp.hxx>
63 #include <TopExp_Explorer.hxx>
64 #include <TopoDS.hxx>
65 #include <TopoDS_Edge.hxx>
66 #include <TopoDS_Vertex.hxx>
67
68 #include <string>
69 #include <limits>
70
71 using namespace std;
72 using namespace StdMeshers;
73
74 //=============================================================================
75 /*!
76  *
77  */
78 //=============================================================================
79
80 StdMeshers_Regular_1D::StdMeshers_Regular_1D(int         hypId,
81                                              int         studyId,
82                                              SMESH_Gen * gen)
83   :SMESH_1D_Algo( hypId, studyId, gen )
84 {
85   _name = "Regular_1D";
86   _shapeType = (1 << TopAbs_EDGE);
87   _fpHyp = 0;
88
89   _compatibleHypothesis.push_back("LocalLength");
90   _compatibleHypothesis.push_back("MaxLength");
91   _compatibleHypothesis.push_back("NumberOfSegments");
92   _compatibleHypothesis.push_back("StartEndLength");
93   _compatibleHypothesis.push_back("Deflection1D");
94   _compatibleHypothesis.push_back("Arithmetic1D");
95   _compatibleHypothesis.push_back("GeometricProgression");
96   _compatibleHypothesis.push_back("FixedPoints1D");
97   _compatibleHypothesis.push_back("AutomaticLength");
98   _compatibleHypothesis.push_back("Adaptive1D");
99   // auxiliary:
100   _compatibleHypothesis.push_back("QuadraticMesh");
101   _compatibleHypothesis.push_back("Propagation");
102   _compatibleHypothesis.push_back("PropagOfDistribution");
103 }
104
105 //=============================================================================
106 /*!
107  *
108  */
109 //=============================================================================
110
111 StdMeshers_Regular_1D::~StdMeshers_Regular_1D()
112 {
113 }
114
115 //=============================================================================
116 /*!
117  *
118  */
119 //=============================================================================
120
121 bool StdMeshers_Regular_1D::CheckHypothesis( SMESH_Mesh&         aMesh,
122                                              const TopoDS_Shape& aShape,
123                                              Hypothesis_Status&  aStatus )
124 {
125   _hypType = NONE;
126   _quadraticMesh = false;
127   _onlyUnaryInput = true;
128
129   const list <const SMESHDS_Hypothesis * > & hyps =
130     GetUsedHypothesis(aMesh, aShape, /*ignoreAuxiliaryHyps=*/false);
131
132   const SMESH_HypoFilter & propagFilter = StdMeshers_Propagation::GetFilter();
133
134   // find non-auxiliary hypothesis
135   const SMESHDS_Hypothesis *theHyp = 0;
136   set< string > propagTypes;
137   list <const SMESHDS_Hypothesis * >::const_iterator h = hyps.begin();
138   for ( ; h != hyps.end(); ++h ) {
139     if ( static_cast<const SMESH_Hypothesis*>(*h)->IsAuxiliary() ) {
140       if ( strcmp( "QuadraticMesh", (*h)->GetName() ) == 0 )
141         _quadraticMesh = true;
142       if ( propagFilter.IsOk( static_cast< const SMESH_Hypothesis*>( *h ), aShape ))
143         propagTypes.insert( (*h)->GetName() );
144     }
145     else {
146       if ( !theHyp )
147         theHyp = *h; // use only the first non-auxiliary hypothesis
148     }
149   }
150
151   if ( !theHyp )
152   {
153     aStatus = SMESH_Hypothesis::HYP_MISSING;
154     return false;  // can't work without a hypothesis
155   }
156
157   string hypName = theHyp->GetName();
158
159   if ( hypName == "LocalLength" )
160   {
161     const StdMeshers_LocalLength * hyp =
162       dynamic_cast <const StdMeshers_LocalLength * >(theHyp);
163     ASSERT(hyp);
164     _value[ BEG_LENGTH_IND ] = hyp->GetLength();
165     _value[ PRECISION_IND ] = hyp->GetPrecision();
166     ASSERT( _value[ BEG_LENGTH_IND ] > 0 );
167     _hypType = LOCAL_LENGTH;
168     aStatus = SMESH_Hypothesis::HYP_OK;
169   }
170
171   else if ( hypName == "MaxLength" )
172   {
173     const StdMeshers_MaxLength * hyp =
174       dynamic_cast <const StdMeshers_MaxLength * >(theHyp);
175     ASSERT(hyp);
176     _value[ BEG_LENGTH_IND ] = hyp->GetLength();
177     if ( hyp->GetUsePreestimatedLength() ) {
178       if ( int nbSeg = aMesh.GetGen()->GetBoundaryBoxSegmentation() )
179         _value[ BEG_LENGTH_IND ] = aMesh.GetShapeDiagonalSize() / nbSeg;
180     }
181     ASSERT( _value[ BEG_LENGTH_IND ] > 0 );
182     _hypType = MAX_LENGTH;
183     aStatus = SMESH_Hypothesis::HYP_OK;
184   }
185
186   else if ( hypName == "NumberOfSegments" )
187   {
188     const StdMeshers_NumberOfSegments * hyp =
189       dynamic_cast <const StdMeshers_NumberOfSegments * >(theHyp);
190     ASSERT(hyp);
191     _ivalue[ NB_SEGMENTS_IND  ] = hyp->GetNumberOfSegments();
192     ASSERT( _ivalue[ NB_SEGMENTS_IND ] > 0 );
193     _ivalue[ DISTR_TYPE_IND ] = (int) hyp->GetDistrType();
194     switch (_ivalue[ DISTR_TYPE_IND ])
195     {
196     case StdMeshers_NumberOfSegments::DT_Scale:
197       _value[ SCALE_FACTOR_IND ] = hyp->GetScaleFactor();
198       _revEdgesIDs = hyp->GetReversedEdges();
199       break;
200     case StdMeshers_NumberOfSegments::DT_TabFunc:
201       _vvalue[ TAB_FUNC_IND ] = hyp->GetTableFunction();
202       _revEdgesIDs = hyp->GetReversedEdges();
203       break;
204     case StdMeshers_NumberOfSegments::DT_ExprFunc:
205       _svalue[ EXPR_FUNC_IND ] = hyp->GetExpressionFunction();
206       _revEdgesIDs = hyp->GetReversedEdges();
207       break;
208     case StdMeshers_NumberOfSegments::DT_Regular:
209       break;
210     default:
211       ASSERT(0);
212       break;
213     }
214     if (_ivalue[ DISTR_TYPE_IND ] == StdMeshers_NumberOfSegments::DT_TabFunc ||
215         _ivalue[ DISTR_TYPE_IND ] == StdMeshers_NumberOfSegments::DT_ExprFunc)
216         _ivalue[ CONV_MODE_IND ] = hyp->ConversionMode();
217     _hypType = NB_SEGMENTS;
218     aStatus = SMESH_Hypothesis::HYP_OK;
219   }
220
221   else if ( hypName == "Arithmetic1D" )
222   {
223     const StdMeshers_Arithmetic1D * hyp =
224       dynamic_cast <const StdMeshers_Arithmetic1D * >(theHyp);
225     ASSERT(hyp);
226     _value[ BEG_LENGTH_IND ] = hyp->GetLength( true );
227     _value[ END_LENGTH_IND ] = hyp->GetLength( false );
228     ASSERT( _value[ BEG_LENGTH_IND ] > 0 && _value[ END_LENGTH_IND ] > 0 );
229     _hypType = ARITHMETIC_1D;
230
231     _revEdgesIDs = hyp->GetReversedEdges();
232
233     aStatus = SMESH_Hypothesis::HYP_OK;
234   }
235
236   else if ( hypName == "GeometricProgression" )
237   {
238     const StdMeshers_Geometric1D * hyp =
239       dynamic_cast <const StdMeshers_Geometric1D * >(theHyp);
240     ASSERT(hyp);
241     _value[ BEG_LENGTH_IND ] = hyp->GetStartLength();
242     _value[ END_LENGTH_IND ] = hyp->GetCommonRatio();
243     ASSERT( _value[ BEG_LENGTH_IND ] > 0 && _value[ END_LENGTH_IND ] > 0 );
244     _hypType = GEOMETRIC_1D;
245
246     _revEdgesIDs = hyp->GetReversedEdges();
247
248     aStatus = SMESH_Hypothesis::HYP_OK;
249   }
250
251   else if ( hypName == "FixedPoints1D" ) {
252     _fpHyp = dynamic_cast <const StdMeshers_FixedPoints1D*>(theHyp);
253     ASSERT(_fpHyp);
254     _hypType = FIXED_POINTS_1D;
255
256     _revEdgesIDs = _fpHyp->GetReversedEdges();
257
258     aStatus = SMESH_Hypothesis::HYP_OK;
259   }
260
261   else if ( hypName == "StartEndLength" )
262   {
263     const StdMeshers_StartEndLength * hyp =
264       dynamic_cast <const StdMeshers_StartEndLength * >(theHyp);
265     ASSERT(hyp);
266     _value[ BEG_LENGTH_IND ] = hyp->GetLength( true );
267     _value[ END_LENGTH_IND ] = hyp->GetLength( false );
268     ASSERT( _value[ BEG_LENGTH_IND ] > 0 && _value[ END_LENGTH_IND ] > 0 );
269     _hypType = BEG_END_LENGTH;
270
271     _revEdgesIDs = hyp->GetReversedEdges();
272
273     aStatus = SMESH_Hypothesis::HYP_OK;
274   }
275
276   else if ( hypName == "Deflection1D" )
277   {
278     const StdMeshers_Deflection1D * hyp =
279       dynamic_cast <const StdMeshers_Deflection1D * >(theHyp);
280     ASSERT(hyp);
281     _value[ DEFLECTION_IND ] = hyp->GetDeflection();
282     ASSERT( _value[ DEFLECTION_IND ] > 0 );
283     _hypType = DEFLECTION;
284     aStatus = SMESH_Hypothesis::HYP_OK;
285   }
286
287   else if ( hypName == "AutomaticLength" )
288   {
289     StdMeshers_AutomaticLength * hyp = const_cast<StdMeshers_AutomaticLength *>
290       (dynamic_cast <const StdMeshers_AutomaticLength * >(theHyp));
291     ASSERT(hyp);
292     _value[ BEG_LENGTH_IND ] = _value[ END_LENGTH_IND ] = hyp->GetLength( &aMesh, aShape );
293     ASSERT( _value[ BEG_LENGTH_IND ] > 0 );
294     _hypType = MAX_LENGTH;
295     aStatus = SMESH_Hypothesis::HYP_OK;
296   }
297   else if ( !_mainEdge.IsNull() && _hypType == DISTRIB_PROPAGATION ) // !!! before "Adaptive1D"
298   {
299     aStatus = SMESH_Hypothesis::HYP_OK;
300   }
301   else if ( hypName == "Adaptive1D" )
302   {
303     _adaptiveHyp = dynamic_cast < const StdMeshers_Adaptive1D* >(theHyp);
304     ASSERT(_adaptiveHyp);
305     _hypType = ADAPTIVE;
306     _onlyUnaryInput = false;
307     aStatus = SMESH_Hypothesis::HYP_OK;
308   }
309   else
310   {
311     aStatus = SMESH_Hypothesis::HYP_INCOMPATIBLE;
312   }
313
314   if ( propagTypes.size() > 1 && aStatus == HYP_OK )
315   {
316     // detect concurrent Propagation hyps
317     _usedHypList.clear();
318     list< TopoDS_Shape > assignedTo;
319     if ( aMesh.GetHypotheses( aShape, propagFilter, _usedHypList, true, &assignedTo ) > 1 )
320     {
321       // find most simple shape and a hyp on it
322       int simpleShape = TopAbs_COMPOUND;
323       const SMESHDS_Hypothesis* localHyp = 0;
324       list< TopoDS_Shape >::iterator            shape = assignedTo.begin();
325       list< const SMESHDS_Hypothesis *>::iterator hyp = _usedHypList.begin();
326       for ( ; shape != assignedTo.end(); ++shape )
327         if ( shape->ShapeType() > simpleShape )
328         {
329           simpleShape = shape->ShapeType();
330           localHyp = (*hyp);
331         }
332       // check if there a different hyp on simpleShape
333       shape = assignedTo.begin();
334       hyp = _usedHypList.begin();
335       for ( ; hyp != _usedHypList.end(); ++hyp, ++shape )
336         if ( shape->ShapeType() == simpleShape &&
337              !localHyp->IsSameName( **hyp ))
338         {
339           aStatus = HYP_INCOMPAT_HYPS;
340           return error( SMESH_Comment("Hypotheses of both \"")
341                         << StdMeshers_Propagation::GetName() << "\" and \""
342                         << StdMeshers_PropagOfDistribution::GetName()
343                         << "\" types can't be applied to the same edge");
344         }
345     }
346   }
347
348   return ( aStatus == SMESH_Hypothesis::HYP_OK );
349 }
350
351 static bool computeParamByFunc(Adaptor3d_Curve& C3d,
352                                double first, double last, double length,
353                                bool theReverse, int nbSeg, Function& func,
354                                list<double>& theParams)
355 {
356   // never do this way
357   //OSD::SetSignal( true );
358
359   if ( nbSeg <= 0 )
360     return false;
361
362   int nbPnt = 1 + nbSeg;
363   vector<double> x( nbPnt, 0. );
364
365   if ( !buildDistribution( func, 0.0, 1.0, nbSeg, x, 1E-4 ))
366      return false;
367
368   // apply parameters in range [0,1] to the space of the curve
369   double prevU = first;
370   double  sign = 1.;
371   if ( theReverse )
372   {
373     prevU = last;
374     sign  = -1.;
375   }
376
377   for ( int i = 1; i < nbSeg; i++ )
378   {
379     double curvLength = length * (x[i] - x[i-1]) * sign;
380     double tol        = Min( Precision::Confusion(), curvLength / 100. );
381     GCPnts_AbscissaPoint Discret( tol, C3d, curvLength, prevU );
382     if ( !Discret.IsDone() )
383       return false;
384     double U = Discret.Parameter();
385     if ( U > first && U < last )
386       theParams.push_back( U );
387     else
388       return false;
389     prevU = U;
390   }
391   if ( theReverse )
392     theParams.reverse();
393   return true;
394 }
395
396
397 //================================================================================
398 /*!
399  * \brief adjust internal node parameters so that the last segment length == an
400   * \param a1 - the first segment length
401   * \param an - the last segment length
402   * \param U1 - the first edge parameter
403   * \param Un - the last edge parameter
404   * \param length - the edge length
405   * \param C3d - the edge curve
406   * \param theParams - internal node parameters to adjust
407   * \param adjustNeighbors2an - to adjust length of segments next to the last one
408   *  and not to remove parameters
409  */
410 //================================================================================
411
412 static void compensateError(double a1, double an,
413                             double U1, double Un,
414                             double            length,
415                             Adaptor3d_Curve&  C3d,
416                             list<double> &    theParams,
417                             bool              adjustNeighbors2an = false)
418 {
419   int i, nPar = theParams.size();
420   if ( a1 + an <= length && nPar > 1 )
421   {
422     bool reverse = ( U1 > Un );
423     double tol   = Min( Precision::Confusion(), 0.01 * an );
424     GCPnts_AbscissaPoint Discret( tol, C3d, reverse ? an : -an, Un );
425     if ( !Discret.IsDone() )
426       return;
427     double Utgt = Discret.Parameter(); // target value of the last parameter
428     list<double>::reverse_iterator itU = theParams.rbegin();
429     double Ul = *itU++; // real value of the last parameter
430     double dUn = Utgt - Ul; // parametric error of <an>
431     double dU = Abs( Ul - *itU ); // parametric length of the last but one segment
432     if ( Abs(dUn) <= 1e-3 * dU )
433       return;
434     if ( adjustNeighbors2an || Abs(dUn) < 0.5 * dU ) { // last segment is a bit shorter than it should
435       // move the last parameter to the edge beginning
436     }
437     else {  // last segment is much shorter than it should -> remove the last param and
438       theParams.pop_back(); nPar--; // move the rest points toward the edge end
439       dUn = Utgt - theParams.back();
440     }
441
442     if ( !adjustNeighbors2an )
443     {
444       double q = dUn / ( Utgt - Un ); // (signed) factor of segment length change
445       for ( itU = theParams.rbegin(), i = 1; i < nPar; i++ ) {
446         double prevU = *itU;
447         (*itU) += dUn;
448         ++itU;
449         dUn = q * (*itU - prevU) * (prevU-U1)/(Un-U1);
450       }
451     }
452     else if ( nPar == 1 )
453     {
454       theParams.back() += dUn;
455     }
456     else
457     {
458       double q  = dUn / ( nPar - 1 );
459       theParams.back() += dUn;
460       double sign = reverse ? -1 : 1;
461       double prevU = theParams.back();
462       itU = theParams.rbegin();
463       for ( ++itU, i = 2; i < nPar; ++itU, i++ ) {
464         double newU = *itU + dUn;
465         if ( newU*sign < prevU*sign ) {
466           prevU = *itU = newU;
467           dUn -= q;
468         }
469         else { // set U between prevU and next valid param
470           list<double>::reverse_iterator itU2 = itU;
471           ++itU2;
472           int nb = 2;
473           while ( (*itU2)*sign > prevU*sign ) {
474             ++itU2; ++nb;
475           }
476           dU = ( *itU2 - prevU ) / nb;
477           while ( itU != itU2 ) {
478             *itU += dU; ++itU;
479           }
480           break;
481         }
482       }
483     }
484   }
485 }
486
487 //================================================================================
488 /*!
489  * \brief Class used to clean mesh on edges when 0D hyp modified.
490  * Common approach doesn't work when 0D algo is missing because the 0D hyp is
491  * considered as not participating in computation whereas it is used by 1D algo.
492  */
493 //================================================================================
494
495 // struct VertexEventListener : public SMESH_subMeshEventListener
496 // {
497 //   VertexEventListener():SMESH_subMeshEventListener(0) // won't be deleted by submesh
498 //   {}
499 //   /*!
500 //    * \brief Clean mesh on edges
501 //    * \param event - algo_event or compute_event itself (of SMESH_subMesh)
502 //    * \param eventType - ALGO_EVENT or COMPUTE_EVENT (of SMESH_subMesh)
503 //    * \param subMesh - the submesh where the event occures
504 //    */
505 //   void ProcessEvent(const int event, const int eventType, SMESH_subMesh* subMesh,
506 //                     EventListenerData*, const SMESH_Hypothesis*)
507 //   {
508 //     if ( eventType == SMESH_subMesh::ALGO_EVENT) // all algo events
509 //     {
510 //       subMesh->ComputeStateEngine( SMESH_subMesh::MODIF_ALGO_STATE );
511 //     }
512 //   }
513 // }; // struct VertexEventListener
514
515 //=============================================================================
516 /*!
517  * \brief Sets event listener to vertex submeshes
518  * \param subMesh - submesh where algo is set
519  *
520  * This method is called when a submesh gets HYP_OK algo_state.
521  * After being set, event listener is notified on each event of a submesh.
522  */
523 //=============================================================================
524
525 void StdMeshers_Regular_1D::SetEventListener(SMESH_subMesh* subMesh)
526 {
527   StdMeshers_Propagation::SetPropagationMgr( subMesh );
528 }
529
530 //=============================================================================
531 /*!
532  * \brief Do nothing
533  * \param subMesh - restored submesh
534  *
535  * This method is called only if a submesh has HYP_OK algo_state.
536  */
537 //=============================================================================
538
539 void StdMeshers_Regular_1D::SubmeshRestored(SMESH_subMesh* subMesh)
540 {
541 }
542
543 //=============================================================================
544 /*!
545  * \brief Return StdMeshers_SegmentLengthAroundVertex assigned to vertex
546  */
547 //=============================================================================
548
549 const StdMeshers_SegmentLengthAroundVertex*
550 StdMeshers_Regular_1D::getVertexHyp(SMESH_Mesh &          theMesh,
551                                     const TopoDS_Vertex & theV)
552 {
553   static SMESH_HypoFilter filter( SMESH_HypoFilter::HasName("SegmentAroundVertex_0D"));
554   if ( const SMESH_Hypothesis * h = theMesh.GetHypothesis( theV, filter, true ))
555   {
556     SMESH_Algo* algo = const_cast< SMESH_Algo* >( static_cast< const SMESH_Algo* > ( h ));
557     const list <const SMESHDS_Hypothesis *> & hypList = algo->GetUsedHypothesis( theMesh, theV, 0 );
558     if ( !hypList.empty() && string("SegmentLengthAroundVertex") == hypList.front()->GetName() )
559       return static_cast<const StdMeshers_SegmentLengthAroundVertex*>( hypList.front() );
560   }
561   return 0;
562 }
563
564 //================================================================================
565 /*!
566  * \brief Tune parameters to fit "SegmentLengthAroundVertex" hypothesis
567   * \param theC3d - wire curve
568   * \param theLength - curve length
569   * \param theParameters - internal nodes parameters to modify
570   * \param theVf - 1st vertex
571   * \param theVl - 2nd vertex
572  */
573 //================================================================================
574
575 void StdMeshers_Regular_1D::redistributeNearVertices (SMESH_Mesh &          theMesh,
576                                                       Adaptor3d_Curve &     theC3d,
577                                                       double                theLength,
578                                                       std::list< double > & theParameters,
579                                                       const TopoDS_Vertex & theVf,
580                                                       const TopoDS_Vertex & theVl)
581 {
582   double f = theC3d.FirstParameter(), l = theC3d.LastParameter();
583   int nPar = theParameters.size();
584   for ( int isEnd1 = 0; isEnd1 < 2; ++isEnd1 )
585   {
586     const TopoDS_Vertex & V = isEnd1 ? theVf : theVl;
587     const StdMeshers_SegmentLengthAroundVertex* hyp = getVertexHyp (theMesh, V );
588     if ( hyp ) {
589       double vertexLength = hyp->GetLength();
590       if ( vertexLength > theLength / 2.0 )
591         continue;
592       if ( isEnd1 ) { // to have a segment of interest at end of theParameters
593         theParameters.reverse();
594         std::swap( f, l );
595       }
596       if ( _hypType == NB_SEGMENTS )
597       {
598         compensateError(0, vertexLength, f, l, theLength, theC3d, theParameters, true );
599       }
600       else if ( nPar <= 3 )
601       {
602         if ( !isEnd1 )
603           vertexLength = -vertexLength;
604         double tol = Min( Precision::Confusion(), 0.01 * vertexLength );
605         GCPnts_AbscissaPoint Discret( tol, theC3d, vertexLength, l );
606         if ( Discret.IsDone() ) {
607           if ( nPar == 0 )
608             theParameters.push_back( Discret.Parameter());
609           else {
610             double L = GCPnts_AbscissaPoint::Length( theC3d, theParameters.back(), l);
611             if ( vertexLength < L / 2.0 )
612               theParameters.push_back( Discret.Parameter());
613             else
614               compensateError(0, vertexLength, f, l, theLength, theC3d, theParameters, true );
615           }
616         }
617       }
618       else
619       {
620         // recompute params between the last segment and a middle one.
621         // find size of a middle segment
622         int nHalf = ( nPar-1 ) / 2;
623         list< double >::reverse_iterator itU = theParameters.rbegin();
624         std::advance( itU, nHalf );
625         double Um = *itU++;
626         double Lm = GCPnts_AbscissaPoint::Length( theC3d, Um, *itU);
627         double L = GCPnts_AbscissaPoint::Length( theC3d, *itU, l);
628         static StdMeshers_Regular_1D* auxAlgo = 0;
629         if ( !auxAlgo ) {
630           auxAlgo = new StdMeshers_Regular_1D( _gen->GetANewId(), _studyId, _gen );
631           auxAlgo->_hypType = BEG_END_LENGTH;
632         }
633         auxAlgo->_value[ BEG_LENGTH_IND ] = Lm;
634         auxAlgo->_value[ END_LENGTH_IND ] = vertexLength;
635         double from = *itU, to = l;
636         if ( isEnd1 ) {
637           std::swap( from, to );
638           std::swap( auxAlgo->_value[ BEG_LENGTH_IND ], auxAlgo->_value[ END_LENGTH_IND ]);
639         }
640         list<double> params;
641         if ( auxAlgo->computeInternalParameters( theMesh, theC3d, L, from, to, params, false ))
642         {
643           if ( isEnd1 ) params.reverse();
644           while ( 1 + nHalf-- )
645             theParameters.pop_back();
646           theParameters.splice( theParameters.end(), params );
647         }
648         else
649         {
650           compensateError(0, vertexLength, f, l, theLength, theC3d, theParameters, true );
651         }
652       }
653       if ( isEnd1 )
654         theParameters.reverse();
655     }
656   }
657 }
658
659 //=============================================================================
660 /*!
661  *  
662  */
663 //=============================================================================
664 bool StdMeshers_Regular_1D::computeInternalParameters(SMESH_Mesh &     theMesh,
665                                                       Adaptor3d_Curve& theC3d,
666                                                       double           theLength,
667                                                       double           theFirstU,
668                                                       double           theLastU,
669                                                       list<double> &   theParams,
670                                                       const bool       theReverse,
671                                                       bool             theConsiderPropagation)
672 {
673   theParams.clear();
674
675   double f = theFirstU, l = theLastU;
676
677   // Propagation Of Distribution
678   //
679   if ( !_mainEdge.IsNull() && _hypType == DISTRIB_PROPAGATION )
680   {
681     TopoDS_Edge mainEdge = TopoDS::Edge( _mainEdge ); // should not be a reference!
682     _gen->Compute( theMesh, mainEdge, SMESH_Gen::SHAPE_ONLY_UPWARD );
683
684     SMESHDS_SubMesh* smDS = theMesh.GetMeshDS()->MeshElements( mainEdge );
685     if ( !smDS )
686       return error("No mesh on the source edge of Propagation Of Distribution");
687     if ( smDS->NbNodes() < 1 )
688       return true; // 1 segment
689
690     map< double, const SMDS_MeshNode* > mainEdgeParamsOfNodes;
691     if ( ! SMESH_Algo::GetSortedNodesOnEdge( theMesh.GetMeshDS(), mainEdge, _quadraticMesh,
692                                              mainEdgeParamsOfNodes, SMDSAbs_Edge ))
693       return error("Bad node parameters on the source edge of Propagation Of Distribution");
694     vector< double > segLen( mainEdgeParamsOfNodes.size() - 1 );
695     double totalLen = 0;
696     BRepAdaptor_Curve mainEdgeCurve( mainEdge );
697     map< double, const SMDS_MeshNode* >::iterator
698       u_n2 = mainEdgeParamsOfNodes.begin(), u_n1 = u_n2++;
699     for ( size_t i = 1; i < mainEdgeParamsOfNodes.size(); ++i, ++u_n1, ++u_n2 )
700     {
701       segLen[ i-1 ] = GCPnts_AbscissaPoint::Length( mainEdgeCurve,
702                                                     u_n1->first,
703                                                     u_n2->first);
704       totalLen += segLen[ i-1 ];
705     }
706     for ( size_t i = 0; i < segLen.size(); ++i )
707       segLen[ i ] *= theLength / totalLen;
708
709     size_t  iSeg = theReverse ? segLen.size()-1 : 0;
710     size_t  dSeg = theReverse ? -1 : +1;
711     double param = theFirstU;
712     size_t nbParams = 0;
713     for ( int i = 0, nb = segLen.size()-1; i < nb; ++i, iSeg += dSeg )
714     {
715       double tol = Min( Precision::Confusion(), 0.01 * segLen[ iSeg ]);
716       GCPnts_AbscissaPoint Discret( tol, theC3d, segLen[ iSeg ], param );
717       if ( !Discret.IsDone() ) break;
718       param = Discret.Parameter();
719       theParams.push_back( param );
720       ++nbParams;
721     }
722     if ( nbParams != segLen.size()-1 )
723       return error( SMESH_Comment("Can't divide into ") << segLen.size() << " segments");
724
725     compensateError( segLen[ theReverse ? segLen.size()-1 : 0 ],
726                      segLen[ theReverse ? 0 : segLen.size()-1 ],
727                      f, l, theLength, theC3d, theParams, true );
728     return true;
729   }
730
731
732   switch( _hypType )
733   {
734   case LOCAL_LENGTH:
735   case MAX_LENGTH:
736   case NB_SEGMENTS:
737   {
738     double eltSize = 1;
739     int nbSegments;
740     if ( _hypType == MAX_LENGTH )
741     {
742       double nbseg = ceil(theLength / _value[ BEG_LENGTH_IND ]); // integer sup
743       if (nbseg <= 0)
744         nbseg = 1; // degenerated edge
745       eltSize = theLength / nbseg * ( 1. - 1e-9 );
746       nbSegments = (int) nbseg;
747     }
748     else if ( _hypType == LOCAL_LENGTH )
749     {
750       // Local Length hypothesis
751       double nbseg = ceil(theLength / _value[ BEG_LENGTH_IND ]); // integer sup
752
753       // NPAL17873:
754       bool isFound = false;
755       if (theConsiderPropagation && !_mainEdge.IsNull()) // propagated from some other edge
756       {
757         // Advanced processing to assure equal number of segments in case of Propagation
758         SMESH_subMesh* sm = theMesh.GetSubMeshContaining(_mainEdge);
759         if (sm) {
760           bool computed = sm->IsMeshComputed();
761           if (!computed) {
762             if (sm->GetComputeState() == SMESH_subMesh::READY_TO_COMPUTE) {
763               _gen->Compute( theMesh, _mainEdge, /*anUpward=*/true);
764               computed = sm->IsMeshComputed();
765             }
766           }
767           if (computed) {
768             SMESHDS_SubMesh* smds = sm->GetSubMeshDS();
769             int       nb_segments = smds->NbElements();
770             if (nbseg - 1 <= nb_segments && nb_segments <= nbseg + 1) {
771               isFound = true;
772               nbseg = nb_segments;
773             }
774           }
775         }
776       }
777       if (!isFound) // not found by meshed edge in the propagation chain, use precision
778       {
779         double aPrecision = _value[ PRECISION_IND ];
780         double nbseg_prec = ceil((theLength / _value[ BEG_LENGTH_IND ]) - aPrecision);
781         if (nbseg_prec == (nbseg - 1)) nbseg--;
782       }
783
784       if (nbseg <= 0)
785         nbseg = 1;                        // degenerated edge
786       eltSize = theLength / nbseg;
787       nbSegments = (int) nbseg;
788     }
789     else
790     {
791       // Number Of Segments hypothesis
792       nbSegments = _ivalue[ NB_SEGMENTS_IND ];
793       if ( nbSegments < 1 )  return false;
794       if ( nbSegments == 1 ) return true;
795
796       switch (_ivalue[ DISTR_TYPE_IND ])
797       {
798       case StdMeshers_NumberOfSegments::DT_Scale:
799         {
800           double scale = _value[ SCALE_FACTOR_IND ];
801
802           if (fabs(scale - 1.0) < Precision::Confusion()) {
803             // special case to avoid division by zero
804             for (int i = 1; i < nbSegments; i++) {
805               double param = f + (l - f) * i / nbSegments;
806               theParams.push_back( param );
807             }
808           } else {
809             // general case of scale distribution
810             if ( theReverse )
811               scale = 1.0 / scale;
812
813             double  alpha = pow(scale, 1.0 / (nbSegments - 1));
814             double factor = (l - f) / (1.0 - pow(alpha, nbSegments));
815
816             for (int i = 1; i < nbSegments; i++) {
817               double param = f + factor * (1.0 - pow(alpha, i));
818               theParams.push_back( param );
819             }
820           }
821           const double lenFactor = theLength/(l-f);
822           const double minSegLen = Min( theParams.front() - f, l - theParams.back() );
823           const double       tol = Min( Precision::Confusion(), 0.01 * minSegLen );
824           list<double>::iterator u = theParams.begin(), uEnd = theParams.end();
825           for ( ; u != uEnd; ++u )
826           {
827             GCPnts_AbscissaPoint Discret( tol, theC3d, ((*u)-f) * lenFactor, f );
828             if ( Discret.IsDone() )
829               *u = Discret.Parameter();
830           }
831           return true;
832         }
833         break;
834       case StdMeshers_NumberOfSegments::DT_TabFunc:
835         {
836           FunctionTable func(_vvalue[ TAB_FUNC_IND ], _ivalue[ CONV_MODE_IND ]);
837           return computeParamByFunc(theC3d, f, l, theLength, theReverse,
838                                     _ivalue[ NB_SEGMENTS_IND ], func,
839                                     theParams);
840         }
841         break;
842       case StdMeshers_NumberOfSegments::DT_ExprFunc:
843         {
844           FunctionExpr func(_svalue[ EXPR_FUNC_IND ].c_str(), _ivalue[ CONV_MODE_IND ]);
845           return computeParamByFunc(theC3d, f, l, theLength, theReverse,
846                                     _ivalue[ NB_SEGMENTS_IND ], func,
847                                     theParams);
848         }
849         break;
850       case StdMeshers_NumberOfSegments::DT_Regular:
851         eltSize = theLength / nbSegments;
852         break;
853       default:
854         return false;
855       }
856     }
857
858     double tol = Min( Precision::Confusion(), 0.01 * eltSize );
859     GCPnts_UniformAbscissa Discret(theC3d, nbSegments + 1, f, l, tol );
860     if ( !Discret.IsDone() )
861       return error( "GCPnts_UniformAbscissa failed");
862     if ( Discret.NbPoints() < nbSegments + 1 )
863       Discret.Initialize(theC3d, nbSegments + 2, f, l, tol );
864
865     int NbPoints = Min( Discret.NbPoints(), nbSegments + 1 );
866     for ( int i = 2; i < NbPoints; i++ ) // skip 1st and last points
867     {
868       double param = Discret.Parameter(i);
869       theParams.push_back( param );
870     }
871     compensateError( eltSize, eltSize, f, l, theLength, theC3d, theParams, true ); // for PAL9899
872     return true;
873   }
874
875
876   case BEG_END_LENGTH: {
877
878     // geometric progression: SUM(n) = ( a1 - an * q ) / ( 1 - q ) = theLength
879
880     double a1 = _value[ BEG_LENGTH_IND ];
881     double an = _value[ END_LENGTH_IND ];
882     double q  = ( theLength - a1 ) / ( theLength - an );
883     if ( q < theLength/1e6 || 1.01*theLength < a1 + an)
884       return error ( SMESH_Comment("Invalid segment lengths (")<<a1<<" and "<<an<<") "<<
885                      "for an edge of length "<<theLength);
886
887     double      U1 = theReverse ? l : f;
888     double      Un = theReverse ? f : l;
889     double   param = U1;
890     double eltSize = theReverse ? -a1 : a1;
891     double     tol = Min( Precision::Confusion(), 0.01 * Min( a1, an ));
892     while ( 1 ) {
893       // computes a point on a curve <theC3d> at the distance <eltSize>
894       // from the point of parameter <param>.
895       GCPnts_AbscissaPoint Discret( tol, theC3d, eltSize, param );
896       if ( !Discret.IsDone() ) break;
897       param = Discret.Parameter();
898       if ( f < param && param < l )
899         theParams.push_back( param );
900       else
901         break;
902       eltSize *= q;
903     }
904     compensateError( a1, an, U1, Un, theLength, theC3d, theParams );
905     if (theReverse) theParams.reverse(); // NPAL18025
906     return true;
907   }
908
909   case ARITHMETIC_1D:
910   {
911     // arithmetic progression: SUM(n) = ( an - a1 + q ) * ( a1 + an ) / ( 2 * q ) = theLength
912
913     double a1 = _value[ BEG_LENGTH_IND ];
914     double an = _value[ END_LENGTH_IND ];
915     if ( 1.01*theLength < a1 + an )
916       return error ( SMESH_Comment("Invalid segment lengths (")<<a1<<" and "<<an<<") "<<
917                      "for an edge of length "<<theLength);
918
919     double q = ( an - a1 ) / ( 2 *theLength/( a1 + an ) - 1 );
920     int    n = int(fabs(q) > numeric_limits<double>::min() ? ( 1+( an-a1 )/q ) : ( 1+theLength/a1 ));
921
922     double      U1 = theReverse ? l : f;
923     double      Un = theReverse ? f : l;
924     double   param = U1;
925     double eltSize = a1;
926     double     tol = Min( Precision::Confusion(), 0.01 * Min( a1, an ));
927     if ( theReverse ) {
928       eltSize = -eltSize;
929       q = -q;
930     }
931     while ( n-- > 0 && eltSize * ( Un - U1 ) > 0 ) {
932       // computes a point on a curve <theC3d> at the distance <eltSize>
933       // from the point of parameter <param>.
934       GCPnts_AbscissaPoint Discret( tol, theC3d, eltSize, param );
935       if ( !Discret.IsDone() ) break;
936       param = Discret.Parameter();
937       if ( param > f && param < l )
938         theParams.push_back( param );
939       else
940         break;
941       eltSize += q;
942     }
943     compensateError( a1, an, U1, Un, theLength, theC3d, theParams );
944     if ( theReverse ) theParams.reverse(); // NPAL18025
945
946     return true;
947   }
948
949   case GEOMETRIC_1D:
950   {
951     double a1 = _value[ BEG_LENGTH_IND ], an = 0;
952     double q  = _value[ END_LENGTH_IND ];
953
954     double U1 = theReverse ? l : f;
955     double Un = theReverse ? f : l;
956     double param = U1;
957     double eltSize = a1;
958     if ( theReverse )
959       eltSize = -eltSize;
960
961     int nbParams = 0;
962     while ( true ) {
963       // computes a point on a curve <theC3d> at the distance <eltSize>
964       // from the point of parameter <param>.
965       double tol = Min( Precision::Confusion(), 0.01 * eltSize );
966       GCPnts_AbscissaPoint Discret( tol, theC3d, eltSize, param );
967       if ( !Discret.IsDone() ) break;
968       param = Discret.Parameter();
969       if ( f < param && param < l )
970         theParams.push_back( param );
971       else
972         break;
973       an = eltSize;
974       eltSize *= q;
975       ++nbParams;
976     }
977     if ( nbParams > 1 )
978     {
979       if ( Abs( param - Un ) < 0.2 * Abs( param - theParams.back() ))
980       {
981         compensateError( a1, Abs(eltSize), U1, Un, theLength, theC3d, theParams );
982       }
983       else if ( Abs( Un - theParams.back() ) <
984                 0.2 * Abs( theParams.back() - *(++theParams.rbegin())))
985       {
986         theParams.pop_back();
987         compensateError( a1, Abs(an), U1, Un, theLength, theC3d, theParams );
988       }
989     }
990     if (theReverse) theParams.reverse(); // NPAL18025
991
992     return true;
993   }
994
995   case FIXED_POINTS_1D:
996   {
997     const std::vector<double>& aPnts = _fpHyp->GetPoints();
998     std::vector<int>          nbsegs = _fpHyp->GetNbSegments();
999
1000     // sort normalized params, taking into account theReverse
1001     TColStd_SequenceOfReal Params;
1002     double tol = 1e-7 / theLength; // GCPnts_UniformAbscissa allows u2-u1 > 1e-7
1003     for ( size_t i = 0; i < aPnts.size(); i++ )
1004     {
1005       if( aPnts[i] < tol || aPnts[i] > 1 - tol )
1006         continue;
1007       double u = theReverse ? ( 1 - aPnts[i] ) : aPnts[i];
1008       int    j = 1;
1009       bool IsExist = false;
1010       for ( ; j <= Params.Length(); j++ ) {
1011         if ( Abs( u - Params.Value(j) ) < tol ) {
1012           IsExist = true;
1013           break;
1014         }
1015         if ( u < Params.Value(j) ) break;
1016       }
1017       if ( !IsExist ) Params.InsertBefore( j, u );
1018     }
1019
1020     // transform normalized Params into real ones
1021     std::vector< double > uVec( Params.Length() + 2 );
1022     uVec[ 0 ] = theFirstU;
1023     double abscissa;
1024     for ( int i = 1; i <= Params.Length(); i++ )
1025     {
1026       abscissa = Params( i ) * theLength;
1027       tol      = Min( Precision::Confusion(), 0.01 * abscissa );
1028       GCPnts_AbscissaPoint APnt( tol, theC3d, abscissa, theFirstU );
1029       if ( !APnt.IsDone() )
1030         return error( "GCPnts_AbscissaPoint failed");
1031       uVec[ i ] = APnt.Parameter();
1032     }
1033     uVec.back() = theLastU;
1034
1035     // divide segments
1036     if ( theReverse )
1037     {
1038       if ((int) nbsegs.size() > Params.Length() + 1 )
1039         nbsegs.resize( Params.Length() + 1 );
1040       std::reverse( nbsegs.begin(), nbsegs.end() );
1041     }
1042     if ( nbsegs.empty() )
1043     {
1044       nbsegs.push_back( 1 );
1045     }
1046     Params.InsertBefore( 1, 0.0 );
1047     Params.Append( 1.0 );
1048     double eltSize, segmentSize, par1, par2;
1049     for ( size_t i = 0; i < uVec.size()-1; i++ )
1050     {
1051       par1 = uVec[ i   ];
1052       par2 = uVec[ i+1 ];
1053       int nbseg = ( i < nbsegs.size() ) ? nbsegs[i] : nbsegs[0];
1054       if ( nbseg == 1 )
1055       {
1056         theParams.push_back( par2 );
1057       }
1058       else
1059       {
1060         segmentSize = ( Params( i+2 ) - Params( i+1 )) * theLength;
1061         eltSize     = segmentSize / nbseg;
1062         tol         = Min( Precision::Confusion(), 0.01 * eltSize );
1063         GCPnts_UniformAbscissa Discret( theC3d, eltSize, par1, par2, tol );
1064         if ( !Discret.IsDone() )
1065           return error( "GCPnts_UniformAbscissa failed");
1066         if ( Discret.NbPoints() < nbseg + 1 ) {
1067           eltSize = segmentSize / ( nbseg + 0.5 );
1068           Discret.Initialize( theC3d, eltSize, par1, par2, tol );
1069         }
1070         int NbPoints = Discret.NbPoints();
1071         for ( int i = 2; i <= NbPoints; i++ ) {
1072           double param = Discret.Parameter(i);
1073           theParams.push_back( param );
1074         }
1075       }
1076     }
1077     theParams.pop_back();
1078
1079     return true;
1080   }
1081
1082   case DEFLECTION:
1083   {
1084     GCPnts_UniformDeflection Discret( theC3d, _value[ DEFLECTION_IND ], f, l, true );
1085     if ( !Discret.IsDone() )
1086       return false;
1087
1088     int NbPoints = Discret.NbPoints();
1089     for ( int i = 2; i < NbPoints; i++ )
1090     {
1091       double param = Discret.Parameter(i);
1092       theParams.push_back( param );
1093     }
1094     return true;
1095   }
1096
1097   default:;
1098   }
1099
1100   return false;
1101 }
1102
1103 //=============================================================================
1104 /*!
1105  *  
1106  */
1107 //=============================================================================
1108
1109 bool StdMeshers_Regular_1D::Compute(SMESH_Mesh & theMesh, const TopoDS_Shape & theShape)
1110 {
1111   if ( _hypType == NONE )
1112     return false;
1113
1114   if ( _hypType == ADAPTIVE )
1115   {
1116     _adaptiveHyp->GetAlgo()->InitComputeError();
1117     _adaptiveHyp->GetAlgo()->Compute( theMesh, theShape );
1118     return error( _adaptiveHyp->GetAlgo()->GetComputeError() );
1119   }
1120
1121   SMESHDS_Mesh * meshDS = theMesh.GetMeshDS();
1122
1123   const TopoDS_Edge & EE = TopoDS::Edge(theShape);
1124   TopoDS_Edge E = TopoDS::Edge(EE.Oriented(TopAbs_FORWARD));
1125   int shapeID = meshDS->ShapeToIndex( E );
1126
1127   double f, l;
1128   Handle(Geom_Curve) Curve = BRep_Tool::Curve(E, f, l);
1129
1130   TopoDS_Vertex VFirst, VLast;
1131   TopExp::Vertices(E, VFirst, VLast);   // Vfirst corresponds to f and Vlast to l
1132
1133   ASSERT(!VFirst.IsNull());
1134   ASSERT(!VLast.IsNull());
1135   const SMDS_MeshNode * nFirst = SMESH_Algo::VertexNode( VFirst, meshDS );
1136   const SMDS_MeshNode *  nLast = SMESH_Algo::VertexNode( VLast,  meshDS );
1137   if ( !nFirst || !nLast )
1138     return error( COMPERR_BAD_INPUT_MESH, "No node on vertex");
1139
1140   // remove elements created by e.g. patern mapping (PAL21999)
1141   // CLEAN event is incorrectly ptopagated seemingly due to Propagation hyp
1142   // so TEMPORARY solution is to clean the submesh manually
1143   if (SMESHDS_SubMesh * subMeshDS = meshDS->MeshElements(theShape))
1144   {
1145     SMDS_ElemIteratorPtr ite = subMeshDS->GetElements();
1146     while (ite->more())
1147       meshDS->RemoveFreeElement(ite->next(), subMeshDS);
1148     SMDS_NodeIteratorPtr itn = subMeshDS->GetNodes();
1149     while (itn->more()) {
1150       const SMDS_MeshNode * node = itn->next();
1151       if ( node->NbInverseElements() == 0 )
1152         meshDS->RemoveFreeNode(node, subMeshDS);
1153       else
1154         meshDS->RemoveNode(node);
1155     }
1156   }
1157
1158   double length = EdgeLength( E );
1159   if ( !Curve.IsNull() && length > 0 )
1160   {
1161     list< double > params;
1162     bool reversed = false;
1163     if ( theMesh.GetShapeToMesh().ShapeType() >= TopAbs_WIRE && _revEdgesIDs.empty() ) {
1164       // if the shape to mesh is WIRE or EDGE
1165       reversed = ( EE.Orientation() == TopAbs_REVERSED );
1166     }
1167     if ( !_mainEdge.IsNull() ) {
1168       // take into account reversing the edge the hypothesis is propagated from
1169       // (_mainEdge.Orientation() marks mutual orientation of EDGEs in propagation chain)
1170       reversed = ( _mainEdge.Orientation() == TopAbs_REVERSED );
1171       if ( _hypType != DISTRIB_PROPAGATION ) {
1172         int mainID = meshDS->ShapeToIndex(_mainEdge);
1173         if ( std::find( _revEdgesIDs.begin(), _revEdgesIDs.end(), mainID) != _revEdgesIDs.end())
1174           reversed = !reversed;
1175       }
1176     }
1177     // take into account this edge reversing
1178     if ( std::find( _revEdgesIDs.begin(), _revEdgesIDs.end(), shapeID) != _revEdgesIDs.end())
1179       reversed = !reversed;
1180
1181     BRepAdaptor_Curve C3d( E );
1182     if ( ! computeInternalParameters( theMesh, C3d, length, f, l, params, reversed, true )) {
1183       return false;
1184     }
1185     redistributeNearVertices( theMesh, C3d, length, params, VFirst, VLast );
1186
1187     // edge extrema (indexes : 1 & NbPoints) already in SMDS (TopoDS_Vertex)
1188     // only internal nodes receive an edge position with param on curve
1189
1190     const SMDS_MeshNode * nPrev = nFirst;
1191     double parPrev = f;
1192     double parLast = l;
1193
1194     for (list<double>::iterator itU = params.begin(); itU != params.end(); itU++) {
1195       double param = *itU;
1196       gp_Pnt P = Curve->Value(param);
1197
1198       //Add the Node in the DataStructure
1199       SMDS_MeshNode * node = meshDS->AddNode(P.X(), P.Y(), P.Z());
1200       meshDS->SetNodeOnEdge(node, shapeID, param);
1201
1202       if(_quadraticMesh) {
1203         // create medium node
1204         double prm = ( parPrev + param )/2;
1205         gp_Pnt  PM = Curve->Value(prm);
1206         SMDS_MeshNode * NM = meshDS->AddNode(PM.X(), PM.Y(), PM.Z());
1207         meshDS->SetNodeOnEdge(NM, shapeID, prm);
1208         SMDS_MeshEdge * edge = meshDS->AddEdge(nPrev, node, NM);
1209         meshDS->SetMeshElementOnShape(edge, shapeID);
1210       }
1211       else {
1212         SMDS_MeshEdge * edge = meshDS->AddEdge(nPrev, node);
1213         meshDS->SetMeshElementOnShape(edge, shapeID);
1214       }
1215
1216       nPrev   = node;
1217       parPrev = param;
1218     }
1219     if(_quadraticMesh) {
1220       double prm = ( parPrev + parLast )/2;
1221       gp_Pnt PM = Curve->Value(prm);
1222       SMDS_MeshNode * NM = meshDS->AddNode(PM.X(), PM.Y(), PM.Z());
1223       meshDS->SetNodeOnEdge(NM, shapeID, prm);
1224       SMDS_MeshEdge * edge = meshDS->AddEdge(nPrev, nLast, NM);
1225       meshDS->SetMeshElementOnShape(edge, shapeID);
1226     }
1227     else {
1228       SMDS_MeshEdge* edge = meshDS->AddEdge(nPrev, nLast);
1229       meshDS->SetMeshElementOnShape(edge, shapeID);
1230     }
1231   }
1232   else
1233   {
1234     // Edge is a degenerated Edge : We put n = 5 points on the edge.
1235     const int NbPoints = 5;
1236     BRep_Tool::Range( E, f, l ); // PAL15185
1237     double du = (l - f) / (NbPoints - 1);
1238
1239     gp_Pnt P = BRep_Tool::Pnt(VFirst);
1240
1241     const SMDS_MeshNode * nPrev = nFirst;
1242     for (int i = 2; i < NbPoints; i++) {
1243       double param = f + (i - 1) * du;
1244       SMDS_MeshNode * node = meshDS->AddNode(P.X(), P.Y(), P.Z());
1245       if(_quadraticMesh) {
1246         // create medium node
1247         double prm = param - du/2.;
1248         SMDS_MeshNode * NM = meshDS->AddNode(P.X(), P.Y(), P.Z());
1249         meshDS->SetNodeOnEdge(NM, shapeID, prm);
1250         SMDS_MeshEdge * edge = meshDS->AddEdge(nPrev, node, NM);
1251         meshDS->SetMeshElementOnShape(edge, shapeID);
1252       }
1253       else {
1254         SMDS_MeshEdge * edge = meshDS->AddEdge(nPrev, node);
1255         meshDS->SetMeshElementOnShape(edge, shapeID);
1256       }
1257       meshDS->SetNodeOnEdge(node, shapeID, param);
1258       nPrev = node;
1259     }
1260     if(_quadraticMesh) {
1261       // create medium node
1262       double prm = l - du/2.;
1263       SMDS_MeshNode * NM = meshDS->AddNode(P.X(), P.Y(), P.Z());
1264       meshDS->SetNodeOnEdge(NM, shapeID, prm);
1265       SMDS_MeshEdge * edge = meshDS->AddEdge(nPrev, nLast, NM);
1266       meshDS->SetMeshElementOnShape(edge, shapeID);
1267     }
1268     else {
1269       SMDS_MeshEdge * edge = meshDS->AddEdge(nPrev, nLast);
1270       meshDS->SetMeshElementOnShape(edge, shapeID);
1271     }
1272   }
1273   return true;
1274 }
1275
1276
1277 //=============================================================================
1278 /*!
1279  *  
1280  */
1281 //=============================================================================
1282
1283 bool StdMeshers_Regular_1D::Evaluate(SMESH_Mesh & theMesh,
1284                                      const TopoDS_Shape & theShape,
1285                                      MapShapeNbElems& aResMap)
1286 {
1287   if ( _hypType == NONE )
1288     return false;
1289
1290   if ( _hypType == ADAPTIVE )
1291   {
1292     _adaptiveHyp->GetAlgo()->InitComputeError();
1293     _adaptiveHyp->GetAlgo()->Evaluate( theMesh, theShape, aResMap );
1294     return error( _adaptiveHyp->GetAlgo()->GetComputeError() );
1295   }
1296
1297   const TopoDS_Edge & EE = TopoDS::Edge(theShape);
1298   TopoDS_Edge E = TopoDS::Edge(EE.Oriented(TopAbs_FORWARD));
1299
1300   double f, l;
1301   Handle(Geom_Curve) Curve = BRep_Tool::Curve(E, f, l);
1302
1303   TopoDS_Vertex VFirst, VLast;
1304   TopExp::Vertices(E, VFirst, VLast);   // Vfirst corresponds to f and Vlast to l
1305
1306   ASSERT(!VFirst.IsNull());
1307   ASSERT(!VLast.IsNull());
1308
1309   std::vector<int> aVec(SMDSEntity_Last,0);
1310
1311   double length = EdgeLength( E );
1312   if ( !Curve.IsNull() && length > 0 )
1313   {
1314     list< double > params;
1315     BRepAdaptor_Curve C3d( E );
1316     if ( ! computeInternalParameters( theMesh, C3d, length, f, l, params, false, true )) {
1317       SMESH_subMesh * sm = theMesh.GetSubMesh(theShape);
1318       aResMap.insert(std::make_pair(sm,aVec));
1319       SMESH_ComputeErrorPtr& smError = sm->GetComputeError();
1320       smError.reset( new SMESH_ComputeError(COMPERR_ALGO_FAILED,"Submesh can not be evaluated",this));
1321       return false;
1322     }
1323     redistributeNearVertices( theMesh, C3d, length, params, VFirst, VLast );
1324
1325     if(_quadraticMesh) {
1326       aVec[SMDSEntity_Node] = 2*params.size() + 1;
1327       aVec[SMDSEntity_Quad_Edge] = params.size() + 1;
1328     }
1329     else {
1330       aVec[SMDSEntity_Node] = params.size();
1331       aVec[SMDSEntity_Edge] = params.size() + 1;
1332     }
1333
1334   }
1335   else {
1336     // Edge is a degenerated Edge : We put n = 5 points on the edge.
1337     if ( _quadraticMesh ) {
1338       aVec[SMDSEntity_Node] = 11;
1339       aVec[SMDSEntity_Quad_Edge] = 6;
1340     }
1341     else {
1342       aVec[SMDSEntity_Node] = 5;
1343       aVec[SMDSEntity_Edge] = 6;
1344     }
1345   }
1346
1347   SMESH_subMesh * sm = theMesh.GetSubMesh(theShape);
1348   aResMap.insert(std::make_pair(sm,aVec));
1349
1350   return true;
1351 }
1352
1353
1354 //=============================================================================
1355 /*!
1356  *  See comments in SMESH_Algo.cxx
1357  */
1358 //=============================================================================
1359
1360 const list <const SMESHDS_Hypothesis *> &
1361 StdMeshers_Regular_1D::GetUsedHypothesis(SMESH_Mesh &         aMesh,
1362                                          const TopoDS_Shape & aShape,
1363                                          const bool           ignoreAuxiliary)
1364 {
1365   _usedHypList.clear();
1366   _mainEdge.Nullify();
1367
1368   SMESH_HypoFilter auxiliaryFilter( SMESH_HypoFilter::IsAuxiliary() );
1369   const SMESH_HypoFilter* compatibleFilter = GetCompatibleHypoFilter(/*ignoreAux=*/true );
1370
1371   // get non-auxiliary assigned directly to aShape
1372   int nbHyp = aMesh.GetHypotheses( aShape, *compatibleFilter, _usedHypList, false );
1373
1374   if (nbHyp == 0 && aShape.ShapeType() == TopAbs_EDGE)
1375   {
1376     // Check, if propagated from some other edge
1377     bool isPropagOfDistribution = false;
1378     _mainEdge = StdMeshers_Propagation::GetPropagationSource( aMesh, aShape,
1379                                                               isPropagOfDistribution );
1380     if ( !_mainEdge.IsNull() )
1381     {
1382       if ( isPropagOfDistribution )
1383         _hypType = DISTRIB_PROPAGATION;
1384       // Propagation of 1D hypothesis from <aMainEdge> on this edge;
1385       // get non-auxiliary assigned to _mainEdge
1386       nbHyp = aMesh.GetHypotheses( _mainEdge, *compatibleFilter, _usedHypList, true );
1387     }
1388   }
1389
1390   if (nbHyp == 0) // nothing propagated nor assigned to aShape
1391   {
1392     SMESH_Algo::GetUsedHypothesis( aMesh, aShape, ignoreAuxiliary );
1393     nbHyp = _usedHypList.size();
1394   }
1395   else
1396   {
1397     // get auxiliary hyps from aShape
1398     aMesh.GetHypotheses( aShape, auxiliaryFilter, _usedHypList, true );
1399   }
1400   if ( nbHyp > 1 && ignoreAuxiliary )
1401     _usedHypList.clear(); //only one compatible non-auxiliary hypothesis allowed
1402
1403   return _usedHypList;
1404 }
1405
1406 //================================================================================
1407 /*!
1408  * \brief Pass CancelCompute() to a child algorithm
1409  */
1410 //================================================================================
1411
1412 void StdMeshers_Regular_1D::CancelCompute()
1413 {
1414   SMESH_Algo::CancelCompute();
1415   if ( _hypType == ADAPTIVE )
1416     _adaptiveHyp->GetAlgo()->CancelCompute();
1417 }