Salome HOME
Merge from V6_main (04/10/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 //  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 #include "StdMeshers_Distribution.hxx"
30
31 #include "StdMeshers_Arithmetic1D.hxx"
32 #include "StdMeshers_AutomaticLength.hxx"
33 #include "StdMeshers_Deflection1D.hxx"
34 #include "StdMeshers_LocalLength.hxx"
35 #include "StdMeshers_MaxLength.hxx"
36 #include "StdMeshers_NumberOfSegments.hxx"
37 #include "StdMeshers_Propagation.hxx"
38 #include "StdMeshers_SegmentLengthAroundVertex.hxx"
39 #include "StdMeshers_StartEndLength.hxx"
40
41 #include "SMESH_Gen.hxx"
42 #include "SMESH_Mesh.hxx"
43 #include "SMESH_HypoFilter.hxx"
44 #include "SMESH_subMesh.hxx"
45 #include "SMESH_subMeshEventListener.hxx"
46 #include "SMESH_Comment.hxx"
47
48 #include "SMDS_MeshElement.hxx"
49 #include "SMDS_MeshNode.hxx"
50
51 #include "Utils_SALOME_Exception.hxx"
52 #include "utilities.h"
53
54 #include <BRepAdaptor_Curve.hxx>
55 #include <BRep_Tool.hxx>
56 #include <GCPnts_AbscissaPoint.hxx>
57 #include <GCPnts_UniformAbscissa.hxx>
58 #include <GCPnts_UniformDeflection.hxx>
59 #include <Precision.hxx>
60 #include <TopExp.hxx>
61 #include <TopExp_Explorer.hxx>
62 #include <TopoDS.hxx>
63 #include <TopoDS_Edge.hxx>
64 #include <TopoDS_Vertex.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     if ( !adjustNeighbors2an )
379     {
380       double q = dUn / ( Utgt - Un ); // (signed) factor of segment length change
381       for ( itU = theParams.rbegin(), i = 1; i < nPar; i++ ) {
382         double prevU = *itU;
383         (*itU) += dUn;
384         ++itU;
385         dUn = q * (*itU - prevU) * (prevU-U1)/(Un-U1);
386       }
387     }
388     else if ( nPar == 1 )
389     {
390       theParams.back() += dUn;
391     }
392     else
393     {
394       double q  = dUn / ( nPar - 1 );
395       theParams.back() += dUn;
396       double sign = reverse ? -1 : 1;
397       double prevU = theParams.back();
398       itU = theParams.rbegin();
399       for ( ++itU, i = 2; i < nPar; ++itU, i++ ) {
400         double newU = *itU + dUn;
401         if ( newU*sign < prevU*sign ) {
402           prevU = *itU = newU;
403           dUn -= q;
404         }
405         else { // set U between prevU and next valid param
406           list<double>::reverse_iterator itU2 = itU;
407           ++itU2;
408           int nb = 2;
409           while ( (*itU2)*sign > prevU*sign ) {
410             ++itU2; ++nb;
411           }
412           dU = ( *itU2 - prevU ) / nb;
413           while ( itU != itU2 ) {
414             *itU += dU; ++itU;
415           }
416           break;
417         }
418       }
419     }
420   }
421 }
422
423 //================================================================================
424 /*!
425  * \brief Class used to clean mesh on edges when 0D hyp modified.
426  * Common approach doesn't work when 0D algo is missing because the 0D hyp is
427  * considered as not participating in computation whereas it is used by 1D algo.
428  */
429 //================================================================================
430
431 // struct VertexEventListener : public SMESH_subMeshEventListener
432 // {
433 //   VertexEventListener():SMESH_subMeshEventListener(0) // won't be deleted by submesh
434 //   {}
435 //   /*!
436 //    * \brief Clean mesh on edges
437 //    * \param event - algo_event or compute_event itself (of SMESH_subMesh)
438 //    * \param eventType - ALGO_EVENT or COMPUTE_EVENT (of SMESH_subMesh)
439 //    * \param subMesh - the submesh where the event occures
440 //    */
441 //   void ProcessEvent(const int event, const int eventType, SMESH_subMesh* subMesh,
442 //                     EventListenerData*, const SMESH_Hypothesis*)
443 //   {
444 //     if ( eventType == SMESH_subMesh::ALGO_EVENT) // all algo events
445 //     {
446 //       subMesh->ComputeStateEngine( SMESH_subMesh::MODIF_ALGO_STATE );
447 //     }
448 //   }
449 // }; // struct VertexEventListener
450
451 //=============================================================================
452 /*!
453  * \brief Sets event listener to vertex submeshes
454  * \param subMesh - submesh where algo is set
455  *
456  * This method is called when a submesh gets HYP_OK algo_state.
457  * After being set, event listener is notified on each event of a submesh.
458  */
459 //=============================================================================
460
461 void StdMeshers_Regular_1D::SetEventListener(SMESH_subMesh* subMesh)
462 {
463   StdMeshers_Propagation::SetPropagationMgr( subMesh );
464 }
465
466 //=============================================================================
467 /*!
468  * \brief Do nothing
469  * \param subMesh - restored submesh
470  *
471  * This method is called only if a submesh has HYP_OK algo_state.
472  */
473 //=============================================================================
474
475 void StdMeshers_Regular_1D::SubmeshRestored(SMESH_subMesh* subMesh)
476 {
477 }
478
479 //=============================================================================
480 /*!
481  * \brief Return StdMeshers_SegmentLengthAroundVertex assigned to vertex
482  */
483 //=============================================================================
484
485 const StdMeshers_SegmentLengthAroundVertex*
486 StdMeshers_Regular_1D::getVertexHyp(SMESH_Mesh &          theMesh,
487                                     const TopoDS_Vertex & theV)
488 {
489   static SMESH_HypoFilter filter( SMESH_HypoFilter::HasName("SegmentAroundVertex_0D"));
490   if ( const SMESH_Hypothesis * h = theMesh.GetHypothesis( theV, filter, true ))
491   {
492     SMESH_Algo* algo = const_cast< SMESH_Algo* >( static_cast< const SMESH_Algo* > ( h ));
493     const list <const SMESHDS_Hypothesis *> & hypList = algo->GetUsedHypothesis( theMesh, theV, 0 );
494     if ( !hypList.empty() && string("SegmentLengthAroundVertex") == hypList.front()->GetName() )
495       return static_cast<const StdMeshers_SegmentLengthAroundVertex*>( hypList.front() );
496   }
497   return 0;
498 }
499
500 //================================================================================
501 /*!
502  * \brief Tune parameters to fit "SegmentLengthAroundVertex" hypothesis
503   * \param theC3d - wire curve
504   * \param theLength - curve length
505   * \param theParameters - internal nodes parameters to modify
506   * \param theVf - 1st vertex
507   * \param theVl - 2nd vertex
508  */
509 //================================================================================
510
511 void StdMeshers_Regular_1D::redistributeNearVertices (SMESH_Mesh &          theMesh,
512                                                       Adaptor3d_Curve &     theC3d,
513                                                       double                theLength,
514                                                       std::list< double > & theParameters,
515                                                       const TopoDS_Vertex & theVf,
516                                                       const TopoDS_Vertex & theVl)
517 {
518   double f = theC3d.FirstParameter(), l = theC3d.LastParameter();
519   int nPar = theParameters.size();
520   for ( int isEnd1 = 0; isEnd1 < 2; ++isEnd1 )
521   {
522     const TopoDS_Vertex & V = isEnd1 ? theVf : theVl;
523     const StdMeshers_SegmentLengthAroundVertex* hyp = getVertexHyp (theMesh, V );
524     if ( hyp ) {
525       double vertexLength = hyp->GetLength();
526       if ( vertexLength > theLength / 2.0 )
527         continue;
528       if ( isEnd1 ) { // to have a segment of interest at end of theParameters
529         theParameters.reverse();
530         std::swap( f, l );
531       }
532       if ( _hypType == NB_SEGMENTS )
533       {
534         compensateError(0, vertexLength, f, l, theLength, theC3d, theParameters, true );
535       }
536       else if ( nPar <= 3 )
537       {
538         if ( !isEnd1 )
539           vertexLength = -vertexLength;
540         GCPnts_AbscissaPoint Discret(theC3d, vertexLength, l);
541         if ( Discret.IsDone() ) {
542           if ( nPar == 0 )
543             theParameters.push_back( Discret.Parameter());
544           else {
545             double L = GCPnts_AbscissaPoint::Length( theC3d, theParameters.back(), l);
546             if ( vertexLength < L / 2.0 )
547               theParameters.push_back( Discret.Parameter());
548             else
549               compensateError(0, vertexLength, f, l, theLength, theC3d, theParameters, true );
550           }
551         }
552       }
553       else
554       {
555         // recompute params between the last segment and a middle one.
556         // find size of a middle segment
557         int nHalf = ( nPar-1 ) / 2;
558         list< double >::reverse_iterator itU = theParameters.rbegin();
559         std::advance( itU, nHalf );
560         double Um = *itU++;
561         double Lm = GCPnts_AbscissaPoint::Length( theC3d, Um, *itU);
562         double L = GCPnts_AbscissaPoint::Length( theC3d, *itU, l);
563         StdMeshers_Regular_1D algo( *this );
564         algo._hypType = BEG_END_LENGTH;
565         algo._value[ BEG_LENGTH_IND ] = Lm;
566         algo._value[ END_LENGTH_IND ] = vertexLength;
567         double from = *itU, to = l;
568         if ( isEnd1 ) {
569           std::swap( from, to );
570           std::swap( algo._value[ BEG_LENGTH_IND ], algo._value[ END_LENGTH_IND ]);
571         }
572         list<double> params;
573         if ( algo.computeInternalParameters( theMesh, theC3d, L, from, to, params, false ))
574         {
575           if ( isEnd1 ) params.reverse();
576           while ( 1 + nHalf-- )
577             theParameters.pop_back();
578           theParameters.splice( theParameters.end(), params );
579         }
580         else
581         {
582           compensateError(0, vertexLength, f, l, theLength, theC3d, theParameters, true );
583         }
584       }
585       if ( isEnd1 )
586         theParameters.reverse();
587     }
588   }
589 }
590
591 //=============================================================================
592 /*!
593  *  
594  */
595 //=============================================================================
596 bool StdMeshers_Regular_1D::computeInternalParameters(SMESH_Mesh &     theMesh,
597                                                       Adaptor3d_Curve& theC3d,
598                                                       double           theLength,
599                                                       double           theFirstU,
600                                                       double           theLastU,
601                                                       list<double> &   theParams,
602                                                       const bool       theReverse,
603                                                       bool             theConsiderPropagation)
604 {
605   theParams.clear();
606
607   double f = theFirstU, l = theLastU;
608
609   switch( _hypType )
610   {
611   case LOCAL_LENGTH:
612   case MAX_LENGTH:
613   case NB_SEGMENTS: {
614
615     double eltSize = 1;
616     int nbSegments;
617     if ( _hypType == MAX_LENGTH )
618     {
619       double nbseg = ceil(theLength / _value[ BEG_LENGTH_IND ]); // integer sup
620       if (nbseg <= 0)
621         nbseg = 1;                        // degenerated edge
622       eltSize = theLength / nbseg;
623       nbSegments = (int) nbseg;
624     }
625     else if ( _hypType == LOCAL_LENGTH )
626     {
627       // Local Length hypothesis
628       double nbseg = ceil(theLength / _value[ BEG_LENGTH_IND ]); // integer sup
629
630       // NPAL17873:
631       bool isFound = false;
632       if (theConsiderPropagation && !_mainEdge.IsNull()) // propagated from some other edge
633       {
634         // Advanced processing to assure equal number of segments in case of Propagation
635         SMESH_subMesh* sm = theMesh.GetSubMeshContaining(_mainEdge);
636         if (sm) {
637           bool computed = sm->IsMeshComputed();
638           if (!computed) {
639             if (sm->GetComputeState() == SMESH_subMesh::READY_TO_COMPUTE) {
640               _gen->Compute( theMesh, _mainEdge, /*anUpward=*/true);
641               computed = sm->IsMeshComputed();
642             }
643           }
644           if (computed) {
645             SMESHDS_SubMesh* smds = sm->GetSubMeshDS();
646             int nb_segments = smds->NbElements();
647             if (nbseg - 1 <= nb_segments && nb_segments <= nbseg + 1) {
648               isFound = true;
649               nbseg = nb_segments;
650             }
651           }
652         }
653       }
654       if (!isFound) // not found by meshed edge in the propagation chain, use precision
655       {
656         double aPrecision = _value[ PRECISION_IND ];
657         double nbseg_prec = ceil((theLength / _value[ BEG_LENGTH_IND ]) - aPrecision);
658         if (nbseg_prec == (nbseg - 1)) nbseg--;
659       }
660
661       if (nbseg <= 0)
662         nbseg = 1;                        // degenerated edge
663       eltSize = theLength / nbseg;
664       nbSegments = (int) nbseg;
665     }
666     else
667     {
668       // Number Of Segments hypothesis
669       nbSegments = _ivalue[ NB_SEGMENTS_IND ];
670       if ( nbSegments < 1 )  return false;
671       if ( nbSegments == 1 ) return true;
672
673       switch (_ivalue[ DISTR_TYPE_IND ])
674       {
675       case StdMeshers_NumberOfSegments::DT_Scale:
676         {
677           double scale = _value[ SCALE_FACTOR_IND ];
678
679           if (fabs(scale - 1.0) < Precision::Confusion()) {
680             // special case to avoid division by zero
681             for (int i = 1; i < nbSegments; i++) {
682               double param = f + (l - f) * i / nbSegments;
683               theParams.push_back( param );
684             }
685           } else {
686             // general case of scale distribution
687             if ( theReverse )
688               scale = 1.0 / scale;
689
690             double alpha = pow(scale, 1.0 / (nbSegments - 1));
691             double factor = (l - f) / (1.0 - pow(alpha, nbSegments));
692
693             for (int i = 1; i < nbSegments; i++) {
694               double param = f + factor * (1.0 - pow(alpha, i));
695               theParams.push_back( param );
696             }
697           }
698           const double lenFactor = theLength/(l-f);
699           list<double>::iterator u = theParams.begin(), uEnd = theParams.end();
700           for ( ; u != uEnd; ++u )
701           {
702             GCPnts_AbscissaPoint Discret( theC3d, ((*u)-f) * lenFactor, f );
703             if ( Discret.IsDone() )
704               *u = Discret.Parameter();
705           }
706           return true;
707         }
708         break;
709       case StdMeshers_NumberOfSegments::DT_TabFunc:
710         {
711           FunctionTable func(_vvalue[ TAB_FUNC_IND ], _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_ExprFunc:
718         {
719           FunctionExpr func(_svalue[ EXPR_FUNC_IND ].c_str(), _ivalue[ CONV_MODE_IND ]);
720           return computeParamByFunc(theC3d, f, l, theLength, theReverse,
721                                     _ivalue[ NB_SEGMENTS_IND ], func,
722                                     theParams);
723         }
724         break;
725       case StdMeshers_NumberOfSegments::DT_Regular:
726         eltSize = theLength / nbSegments;
727         break;
728       default:
729         return false;
730       }
731     }
732     GCPnts_UniformAbscissa Discret(theC3d, eltSize, f, l);
733     if ( !Discret.IsDone() )
734       return error( "GCPnts_UniformAbscissa failed");
735
736     int NbPoints = Min( Discret.NbPoints(), nbSegments + 1 );
737     for ( int i = 2; i < NbPoints; i++ ) // skip 1st and last points
738     {
739       double param = Discret.Parameter(i);
740       theParams.push_back( param );
741     }
742     compensateError( eltSize, eltSize, f, l, theLength, theC3d, theParams, true ); // for PAL9899
743     return true;
744   }
745
746   case BEG_END_LENGTH: {
747
748     // geometric progression: SUM(n) = ( a1 - an * q ) / ( 1 - q ) = theLength
749
750     double a1 = _value[ BEG_LENGTH_IND ];
751     double an = _value[ END_LENGTH_IND ];
752     double q  = ( theLength - a1 ) / ( theLength - an );
753     if ( q < theLength/1e6 || 1.01*theLength < a1 + an)
754       return error ( SMESH_Comment("Invalid segment lengths (")<<a1<<" and "<<an<<") "<<
755                      "for an edge of length "<<theLength);
756
757     double U1 = theReverse ? l : f;
758     double Un = theReverse ? f : l;
759     double param = U1;
760     double eltSize = theReverse ? -a1 : a1;
761     while ( 1 ) {
762       // computes a point on a curve <theC3d> at the distance <eltSize>
763       // from the point of parameter <param>.
764       GCPnts_AbscissaPoint Discret( theC3d, eltSize, param );
765       if ( !Discret.IsDone() ) break;
766       param = Discret.Parameter();
767       if ( f < param && param < l )
768         theParams.push_back( param );
769       else
770         break;
771       eltSize *= q;
772     }
773     compensateError( a1, an, U1, Un, theLength, theC3d, theParams );
774     if (theReverse) theParams.reverse(); // NPAL18025
775     return true;
776   }
777
778   case ARITHMETIC_1D: {
779
780     // arithmetic progression: SUM(n) = ( an - a1 + q ) * ( a1 + an ) / ( 2 * q ) = theLength
781
782     double a1 = _value[ BEG_LENGTH_IND ];
783     double an = _value[ END_LENGTH_IND ];
784     if ( 1.01*theLength < a1 + an)
785       return error ( SMESH_Comment("Invalid segment lengths (")<<a1<<" and "<<an<<") "<<
786                      "for an edge of length "<<theLength);
787
788     double  q = ( an - a1 ) / ( 2 *theLength/( a1 + an ) - 1 );
789     int n = int(fabs(q) > numeric_limits<double>::min() ? ( 1+( an-a1 )/q ) : ( 1+theLength/a1 ));
790
791     double U1 = theReverse ? l : f;
792     double Un = theReverse ? f : l;
793     double param = U1;
794     double eltSize = a1;
795     if ( theReverse ) {
796       eltSize = -eltSize;
797       q = -q;
798     }
799     while ( n-- > 0 && eltSize * ( Un - U1 ) > 0 ) {
800       // computes a point on a curve <theC3d> at the distance <eltSize>
801       // from the point of parameter <param>.
802       GCPnts_AbscissaPoint Discret( theC3d, eltSize, param );
803       if ( !Discret.IsDone() ) break;
804       param = Discret.Parameter();
805       if ( param > f && param < l )
806         theParams.push_back( param );
807       else
808         break;
809       eltSize += q;
810     }
811     compensateError( a1, an, U1, Un, theLength, theC3d, theParams );
812     if (theReverse) theParams.reverse(); // NPAL18025
813
814     return true;
815   }
816
817   case FIXED_POINTS_1D: {
818     const std::vector<double>& aPnts = _fpHyp->GetPoints();
819     const std::vector<int>& nbsegs = _fpHyp->GetNbSegments();
820     int i = 0;
821     TColStd_SequenceOfReal Params;
822     for(; i<aPnts.size(); i++) {
823       if( aPnts[i]<0.0001 || aPnts[i]>0.9999 ) continue;
824       int j=1;
825       bool IsExist = false;
826       for(; j<=Params.Length(); j++) {
827         if( fabs(aPnts[i]-Params.Value(j)) < 1e-4 ) {
828           IsExist = true;
829           break;
830         }
831         if( aPnts[i]<Params.Value(j) ) break;
832       }
833       if(!IsExist) Params.InsertBefore(j,aPnts[i]);
834     }
835     double par2, par1, lp;
836     par1 = f;
837     lp = l;
838     double sign = 1.0;
839     if(theReverse) {
840       par1 = l;
841       lp = f;
842       sign = -1.0;
843     }
844     double eltSize, segmentSize = 0.;
845     double currAbscissa = 0;
846     for(i=0; i<Params.Length(); i++) {
847       int nbseg = ( i > nbsegs.size()-1 ) ? nbsegs[0] : nbsegs[i];
848       segmentSize = Params.Value(i+1)*theLength - currAbscissa;
849       currAbscissa += segmentSize;
850       GCPnts_AbscissaPoint APnt(theC3d, sign*segmentSize, par1);
851       if( !APnt.IsDone() )
852         return error( "GCPnts_AbscissaPoint failed");
853       par2 = APnt.Parameter();
854       eltSize = segmentSize/nbseg;
855       GCPnts_UniformAbscissa Discret(theC3d, eltSize, par1, par2);
856       if(theReverse)
857         Discret.Initialize(theC3d, eltSize, par2, par1);
858       else
859         Discret.Initialize(theC3d, eltSize, par1, par2);
860       if ( !Discret.IsDone() )
861         return error( "GCPnts_UniformAbscissa failed");
862       int NbPoints = Discret.NbPoints();
863       list<double> tmpParams;
864       for(int i=2; i<NbPoints; i++) {
865         double param = Discret.Parameter(i);
866         tmpParams.push_back( param );
867       }
868       if (theReverse) {
869         compensateError( eltSize, eltSize, par2, par1, segmentSize, theC3d, tmpParams );
870         tmpParams.reverse();
871       }
872       else {
873         compensateError( eltSize, eltSize, par1, par2, segmentSize, theC3d, tmpParams );
874       }
875       list<double>::iterator itP = tmpParams.begin();
876       for(; itP != tmpParams.end(); itP++) {
877         theParams.push_back( *(itP) );
878       }
879       theParams.push_back( par2 );
880
881       par1 = par2;
882     }
883     // add for last
884     int nbseg = ( nbsegs.size() > Params.Length() ) ? nbsegs[Params.Length()] : nbsegs[0];
885     segmentSize = theLength - currAbscissa;
886     eltSize = segmentSize/nbseg;
887     GCPnts_UniformAbscissa Discret;
888     if(theReverse)
889       Discret.Initialize(theC3d, eltSize, par1, lp);
890     else
891       Discret.Initialize(theC3d, eltSize, lp, par1);
892     if ( !Discret.IsDone() )
893       return error( "GCPnts_UniformAbscissa failed");
894     int NbPoints = Discret.NbPoints();
895     list<double> tmpParams;
896     for(int i=2; i<NbPoints; i++) {
897       double param = Discret.Parameter(i);
898       tmpParams.push_back( param );
899     }
900     if (theReverse) {
901       compensateError( eltSize, eltSize, lp, par1, segmentSize, theC3d, tmpParams );
902       tmpParams.reverse();
903     }
904     else {
905       compensateError( eltSize, eltSize, par1, lp, segmentSize, theC3d, tmpParams );
906     }
907     list<double>::iterator itP = tmpParams.begin();
908     for(; itP != tmpParams.end(); itP++) {
909       theParams.push_back( *(itP) );
910     }
911
912     if (theReverse) {
913       theParams.reverse(); // NPAL18025
914     }
915     return true;
916   }
917
918   case DEFLECTION: {
919
920     GCPnts_UniformDeflection Discret(theC3d, _value[ DEFLECTION_IND ], f, l, true);
921     if ( !Discret.IsDone() )
922       return false;
923
924     int NbPoints = Discret.NbPoints();
925     for ( int i = 2; i < NbPoints; i++ )
926     {
927       double param = Discret.Parameter(i);
928       theParams.push_back( param );
929     }
930     return true;
931   }
932
933   default:;
934   }
935
936   return false;
937 }
938
939 //=============================================================================
940 /*!
941  *  
942  */
943 //=============================================================================
944
945 bool StdMeshers_Regular_1D::Compute(SMESH_Mesh & theMesh, const TopoDS_Shape & theShape)
946 {
947   if ( _hypType == NONE )
948     return false;
949
950   SMESHDS_Mesh * meshDS = theMesh.GetMeshDS();
951
952   const TopoDS_Edge & EE = TopoDS::Edge(theShape);
953   TopoDS_Edge E = TopoDS::Edge(EE.Oriented(TopAbs_FORWARD));
954   int shapeID = meshDS->ShapeToIndex( E );
955
956   double f, l;
957   Handle(Geom_Curve) Curve = BRep_Tool::Curve(E, f, l);
958
959   TopoDS_Vertex VFirst, VLast;
960   TopExp::Vertices(E, VFirst, VLast);   // Vfirst corresponds to f and Vlast to l
961
962   ASSERT(!VFirst.IsNull());
963   ASSERT(!VLast.IsNull());
964   const SMDS_MeshNode * idFirst = SMESH_Algo::VertexNode( VFirst, meshDS );
965   const SMDS_MeshNode * idLast = SMESH_Algo::VertexNode( VLast, meshDS );
966   if (!idFirst || !idLast)
967     return error( COMPERR_BAD_INPUT_MESH, "No node on vertex");
968
969   // remove elements created by e.g. patern mapping (PAL21999)
970   // CLEAN event is incorrectly ptopagated seemingly due to Propagation hyp
971   // so TEMPORARY solution is to clean the submesh manually
972   //theMesh.GetSubMesh(theShape)->ComputeStateEngine( SMESH_subMesh::CLEAN );
973   if (SMESHDS_SubMesh * subMeshDS = meshDS->MeshElements(theShape))
974   {
975     SMDS_ElemIteratorPtr ite = subMeshDS->GetElements();
976     while (ite->more())
977       meshDS->RemoveFreeElement(ite->next(), subMeshDS);
978     SMDS_NodeIteratorPtr itn = subMeshDS->GetNodes();
979     while (itn->more()) {
980       const SMDS_MeshNode * node = itn->next();
981       if ( node->NbInverseElements() == 0 )
982         meshDS->RemoveFreeNode(node, subMeshDS);
983       else
984         meshDS->RemoveNode(node);
985     }
986   }
987
988   if (!Curve.IsNull())
989   {
990     list< double > params;
991     bool reversed = false;
992     if ( theMesh.GetShapeToMesh().ShapeType() >= TopAbs_WIRE ) {
993       // if the shape to mesh is WIRE or EDGE
994       reversed = ( EE.Orientation() == TopAbs_REVERSED );
995     }
996     if ( !_mainEdge.IsNull() ) {
997       // take into account reversing the edge the hypothesis is propagated from
998       reversed = ( _mainEdge.Orientation() == TopAbs_REVERSED );
999       int mainID = meshDS->ShapeToIndex(_mainEdge);
1000       if ( std::find( _revEdgesIDs.begin(), _revEdgesIDs.end(), mainID) != _revEdgesIDs.end())
1001         reversed = !reversed;
1002     }
1003     // take into account this edge reversing
1004     if ( std::find( _revEdgesIDs.begin(), _revEdgesIDs.end(), shapeID) != _revEdgesIDs.end())
1005       reversed = !reversed;
1006
1007     BRepAdaptor_Curve C3d( E );
1008     double length = EdgeLength( E );
1009     if ( ! computeInternalParameters( theMesh, C3d, length, f, l, params, reversed, true )) {
1010       return false;
1011     }
1012     redistributeNearVertices( theMesh, C3d, length, params, VFirst, VLast );
1013
1014     // edge extrema (indexes : 1 & NbPoints) already in SMDS (TopoDS_Vertex)
1015     // only internal nodes receive an edge position with param on curve
1016
1017     const SMDS_MeshNode * idPrev = idFirst;
1018     double parPrev = f;
1019     double parLast = l;
1020
1021     /* NPAL18025
1022     if (reversed) {
1023       idPrev = idLast;
1024       idLast = idFirst;
1025       idFirst = idPrev;
1026       parPrev = l;
1027       parLast = f;
1028     }
1029     */
1030     for (list<double>::iterator itU = params.begin(); itU != params.end(); itU++) {
1031       double param = *itU;
1032       gp_Pnt P = Curve->Value(param);
1033
1034       //Add the Node in the DataStructure
1035       SMDS_MeshNode * node = meshDS->AddNode(P.X(), P.Y(), P.Z());
1036       meshDS->SetNodeOnEdge(node, shapeID, param);
1037
1038       if(_quadraticMesh) {
1039         // create medium node
1040         double prm = ( parPrev + param )/2;
1041         gp_Pnt PM = Curve->Value(prm);
1042         SMDS_MeshNode * NM = meshDS->AddNode(PM.X(), PM.Y(), PM.Z());
1043         meshDS->SetNodeOnEdge(NM, shapeID, prm);
1044         SMDS_MeshEdge * edge = meshDS->AddEdge(idPrev, node, NM);
1045         meshDS->SetMeshElementOnShape(edge, shapeID);
1046       }
1047       else {
1048         SMDS_MeshEdge * edge = meshDS->AddEdge(idPrev, node);
1049         meshDS->SetMeshElementOnShape(edge, shapeID);
1050       }
1051
1052       idPrev = node;
1053       parPrev = param;
1054     }
1055     if(_quadraticMesh) {
1056       double prm = ( parPrev + parLast )/2;
1057       gp_Pnt PM = Curve->Value(prm);
1058       SMDS_MeshNode * NM = meshDS->AddNode(PM.X(), PM.Y(), PM.Z());
1059       meshDS->SetNodeOnEdge(NM, shapeID, prm);
1060       SMDS_MeshEdge * edge = meshDS->AddEdge(idPrev, idLast, NM);
1061       meshDS->SetMeshElementOnShape(edge, shapeID);
1062     }
1063     else {
1064       SMDS_MeshEdge* edge = meshDS->AddEdge(idPrev, idLast);
1065       meshDS->SetMeshElementOnShape(edge, shapeID);
1066     }
1067   }
1068   else
1069   {
1070     //MESSAGE("************* Degenerated edge! *****************");
1071
1072     // Edge is a degenerated Edge : We put n = 5 points on the edge.
1073     const int NbPoints = 5;
1074     BRep_Tool::Range( E, f, l ); // PAL15185
1075     double du = (l - f) / (NbPoints - 1);
1076
1077     gp_Pnt P = BRep_Tool::Pnt(VFirst);
1078
1079     const SMDS_MeshNode * idPrev = idFirst;
1080     for (int i = 2; i < NbPoints; i++) {
1081       double param = f + (i - 1) * du;
1082       SMDS_MeshNode * node = meshDS->AddNode(P.X(), P.Y(), P.Z());
1083       if(_quadraticMesh) {
1084         // create medium node
1085         double prm = param - du/2.;
1086         SMDS_MeshNode * NM = meshDS->AddNode(P.X(), P.Y(), P.Z());
1087         meshDS->SetNodeOnEdge(NM, shapeID, prm);
1088         SMDS_MeshEdge * edge = meshDS->AddEdge(idPrev, node, NM);
1089         meshDS->SetMeshElementOnShape(edge, shapeID);
1090       }
1091       else {
1092         SMDS_MeshEdge * edge = meshDS->AddEdge(idPrev, node);
1093         meshDS->SetMeshElementOnShape(edge, shapeID);
1094       }
1095       meshDS->SetNodeOnEdge(node, shapeID, param);
1096       idPrev = node;
1097     }
1098     if(_quadraticMesh) {
1099       // create medium node
1100       double prm = l - du/2.;
1101       SMDS_MeshNode * NM = meshDS->AddNode(P.X(), P.Y(), P.Z());
1102       meshDS->SetNodeOnEdge(NM, shapeID, prm);
1103       SMDS_MeshEdge * edge = meshDS->AddEdge(idPrev, idLast, NM);
1104       meshDS->SetMeshElementOnShape(edge, shapeID);
1105     }
1106     else {
1107       SMDS_MeshEdge * edge = meshDS->AddEdge(idPrev, idLast);
1108       meshDS->SetMeshElementOnShape(edge, shapeID);
1109     }
1110   }
1111   return true;
1112 }
1113
1114
1115 //=============================================================================
1116 /*!
1117  *  
1118  */
1119 //=============================================================================
1120
1121 bool StdMeshers_Regular_1D::Evaluate(SMESH_Mesh & theMesh,
1122                                      const TopoDS_Shape & theShape,
1123                                      MapShapeNbElems& aResMap)
1124 {
1125   if ( _hypType == NONE )
1126     return false;
1127
1128   //SMESHDS_Mesh * meshDS = theMesh.GetMeshDS();
1129
1130   const TopoDS_Edge & EE = TopoDS::Edge(theShape);
1131   TopoDS_Edge E = TopoDS::Edge(EE.Oriented(TopAbs_FORWARD));
1132   //  int shapeID = meshDS->ShapeToIndex( E );
1133
1134   double f, l;
1135   Handle(Geom_Curve) Curve = BRep_Tool::Curve(E, f, l);
1136
1137   TopoDS_Vertex VFirst, VLast;
1138   TopExp::Vertices(E, VFirst, VLast);   // Vfirst corresponds to f and Vlast to l
1139
1140   ASSERT(!VFirst.IsNull());
1141   ASSERT(!VLast.IsNull());
1142
1143   std::vector<int> aVec(SMDSEntity_Last,0);
1144
1145   if (!Curve.IsNull()) {
1146     list< double > params;
1147
1148     BRepAdaptor_Curve C3d( E );
1149     double length = EdgeLength( E );
1150     if ( ! computeInternalParameters( theMesh, C3d, length, f, l, params, false, true )) {
1151       SMESH_subMesh * sm = theMesh.GetSubMesh(theShape);
1152       aResMap.insert(std::make_pair(sm,aVec));
1153       SMESH_ComputeErrorPtr& smError = sm->GetComputeError();
1154       smError.reset( new SMESH_ComputeError(COMPERR_ALGO_FAILED,"Submesh can not be evaluated",this));
1155       return false;
1156     }
1157     redistributeNearVertices( theMesh, C3d, length, params, VFirst, VLast );
1158
1159     if(_quadraticMesh) {
1160       aVec[SMDSEntity_Node] = 2*params.size() + 1;
1161       aVec[SMDSEntity_Quad_Edge] = params.size() + 1;
1162     }
1163     else {
1164       aVec[SMDSEntity_Node] = params.size();
1165       aVec[SMDSEntity_Edge] = params.size() + 1;
1166     }
1167     
1168   }
1169   else {
1170     //MESSAGE("************* Degenerated edge! *****************");
1171     // Edge is a degenerated Edge : We put n = 5 points on the edge.
1172     if(_quadraticMesh) {
1173       aVec[SMDSEntity_Node] = 11;
1174       aVec[SMDSEntity_Quad_Edge] = 6;
1175     }
1176     else {
1177       aVec[SMDSEntity_Node] = 5;
1178       aVec[SMDSEntity_Edge] = 6;
1179     }
1180   }
1181
1182   SMESH_subMesh * sm = theMesh.GetSubMesh(theShape);
1183   aResMap.insert(std::make_pair(sm,aVec));
1184
1185   return true;
1186 }
1187
1188
1189 //=============================================================================
1190 /*!
1191  *  See comments in SMESH_Algo.cxx
1192  */
1193 //=============================================================================
1194
1195 const list <const SMESHDS_Hypothesis *> &
1196 StdMeshers_Regular_1D::GetUsedHypothesis(SMESH_Mesh &         aMesh,
1197                                          const TopoDS_Shape & aShape,
1198                                          const bool           ignoreAuxiliary)
1199 {
1200   _usedHypList.clear();
1201   _mainEdge.Nullify();
1202
1203   SMESH_HypoFilter auxiliaryFilter, compatibleFilter;
1204   auxiliaryFilter.Init( SMESH_HypoFilter::IsAuxiliary() );
1205   InitCompatibleHypoFilter( compatibleFilter, /*ignoreAux=*/true );
1206
1207   // get non-auxiliary assigned directly to aShape
1208   int nbHyp = aMesh.GetHypotheses( aShape, compatibleFilter, _usedHypList, false );
1209
1210   if (nbHyp == 0 && aShape.ShapeType() == TopAbs_EDGE)
1211   {
1212     // Check, if propagated from some other edge
1213     _mainEdge = StdMeshers_Propagation::GetPropagationSource( aMesh, aShape );
1214     if ( !_mainEdge.IsNull() )
1215     {
1216       // Propagation of 1D hypothesis from <aMainEdge> on this edge;
1217       // get non-auxiliary assigned to _mainEdge
1218       nbHyp = aMesh.GetHypotheses( _mainEdge, compatibleFilter, _usedHypList, true );
1219     }
1220   }
1221
1222   if (nbHyp == 0) // nothing propagated nor assigned to aShape
1223   {
1224     SMESH_Algo::GetUsedHypothesis( aMesh, aShape, ignoreAuxiliary );
1225     nbHyp = _usedHypList.size();
1226   }
1227   else
1228   {
1229     // get auxiliary hyps from aShape
1230     aMesh.GetHypotheses( aShape, auxiliaryFilter, _usedHypList, true );
1231   }
1232   if ( nbHyp > 1 && ignoreAuxiliary )
1233     _usedHypList.clear(); //only one compatible non-auxiliary hypothesis allowed
1234
1235   return _usedHypList;
1236 }