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