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