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