Salome HOME
f13f1cbce7006c94025f0a9a0f38868b06117c60
[modules/smesh.git] / src / StdMeshers / StdMeshers_Regular_1D.cxx
1 //  SMESH SMESH : implementaion of SMESH idl descriptions
2 //
3 //  Copyright (C) 2003  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 //
24 //  File   : StdMeshers_Regular_1D.cxx
25 //           Moved here from SMESH_Regular_1D.cxx
26 //  Author : Paul RASCLE, EDF
27 //  Module : SMESH
28 //  $Header$
29
30 using namespace std;
31
32 #include "StdMeshers_Regular_1D.hxx"
33 #include "StdMeshers_Distribution.hxx"
34 #include "SMESH_Gen.hxx"
35 #include "SMESH_Mesh.hxx"
36 #include "SMESH_HypoFilter.hxx"
37 #include "SMESH_subMesh.hxx"
38
39 #include "StdMeshers_LocalLength.hxx"
40 #include "StdMeshers_NumberOfSegments.hxx"
41 #include "StdMeshers_Arithmetic1D.hxx"
42 #include "StdMeshers_StartEndLength.hxx"
43 #include "StdMeshers_Deflection1D.hxx"
44 #include "StdMeshers_AutomaticLength.hxx"
45
46 #include "SMDS_MeshElement.hxx"
47 #include "SMDS_MeshNode.hxx"
48 #include "SMDS_EdgePosition.hxx"
49
50 #include "Utils_SALOME_Exception.hxx"
51 #include "utilities.h"
52
53 #include <BRep_Tool.hxx>
54 #include <TopoDS_Edge.hxx>
55 #include <TopoDS_Shape.hxx>
56 #include <TopTools_ListIteratorOfListOfShape.hxx>
57 #include <GeomAdaptor_Curve.hxx>
58 #include <GCPnts_AbscissaPoint.hxx>
59 #include <GCPnts_UniformAbscissa.hxx>
60 #include <GCPnts_UniformDeflection.hxx>
61 #include <Standard_ErrorHandler.hxx>
62 #include <Precision.hxx>
63 #include <Expr_GeneralExpression.hxx>
64 #include <Expr_NamedUnknown.hxx>
65 #include <Expr_Array1OfNamedUnknown.hxx>
66 #include <TColStd_Array1OfReal.hxx>
67 #include <ExprIntrp_GenExp.hxx>
68 #include <OSD.hxx>
69
70 #include <string>
71 #include <math.h>
72
73 using namespace std;
74
75 //=============================================================================
76 /*!
77  *  
78  */
79 //=============================================================================
80
81 StdMeshers_Regular_1D::StdMeshers_Regular_1D(int hypId, int studyId,
82         SMESH_Gen * gen):SMESH_1D_Algo(hypId, studyId, gen)
83 {
84         MESSAGE("StdMeshers_Regular_1D::StdMeshers_Regular_1D");
85         _name = "Regular_1D";
86         _shapeType = (1 << TopAbs_EDGE);
87
88         _compatibleHypothesis.push_back("LocalLength");
89         _compatibleHypothesis.push_back("NumberOfSegments");
90         _compatibleHypothesis.push_back("StartEndLength");
91         _compatibleHypothesis.push_back("Deflection1D");
92         _compatibleHypothesis.push_back("Arithmetic1D");
93         _compatibleHypothesis.push_back("AutomaticLength");
94
95         _compatibleHypothesis.push_back("QuadraticMesh"); // 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 bool ignoreAuxiliaryHyps = false;
123   const list <const SMESHDS_Hypothesis * > & hyps =
124     GetUsedHypothesis(aMesh, aShape, ignoreAuxiliaryHyps);
125
126   // find non-auxiliary hypothesis
127   const SMESHDS_Hypothesis *theHyp = 0;
128   list <const SMESHDS_Hypothesis * >::const_iterator h = hyps.begin();
129   for ( ; h != hyps.end(); ++h ) {
130     if ( static_cast<const SMESH_Hypothesis*>(*h)->IsAuxiliary() ) {
131       if ( strcmp( "QuadraticMesh", (*h)->GetName() ) == 0 )
132         _quadraticMesh = true;
133     }
134     else {
135       if ( !theHyp )
136         theHyp = *h; // use only the first non-auxiliary hypothesis
137     }
138   }
139
140   if ( !theHyp )
141   {
142     aStatus = SMESH_Hypothesis::HYP_MISSING;
143     return false;  // can't work without a hypothesis
144   }
145
146   string hypName = theHyp->GetName();
147
148   if (hypName == "LocalLength")
149   {
150     const StdMeshers_LocalLength * hyp =
151       dynamic_cast <const StdMeshers_LocalLength * >(theHyp);
152     ASSERT(hyp);
153     _value[ BEG_LENGTH_IND ] = _value[ END_LENGTH_IND ] = hyp->GetLength();
154     ASSERT( _value[ BEG_LENGTH_IND ] > 0 );
155     _hypType = LOCAL_LENGTH;
156     aStatus = SMESH_Hypothesis::HYP_OK;
157   }
158
159   else if (hypName == "NumberOfSegments")
160   {
161     const StdMeshers_NumberOfSegments * hyp =
162       dynamic_cast <const StdMeshers_NumberOfSegments * >(theHyp);
163     ASSERT(hyp);
164     _ivalue[ NB_SEGMENTS_IND  ] = hyp->GetNumberOfSegments();
165     ASSERT( _ivalue[ NB_SEGMENTS_IND ] > 0 );
166     _ivalue[ DISTR_TYPE_IND ] = (int) hyp->GetDistrType();
167     switch (_ivalue[ DISTR_TYPE_IND ])
168     {
169     case StdMeshers_NumberOfSegments::DT_Scale:
170       _value[ SCALE_FACTOR_IND ] = hyp->GetScaleFactor();
171       break;
172     case StdMeshers_NumberOfSegments::DT_TabFunc:
173       _vvalue[ TAB_FUNC_IND ] = hyp->GetTableFunction();
174       break;
175     case StdMeshers_NumberOfSegments::DT_ExprFunc:
176       _svalue[ EXPR_FUNC_IND ] = hyp->GetExpressionFunction();
177       break;
178     case StdMeshers_NumberOfSegments::DT_Regular:
179       break;
180     default:
181       ASSERT(0);
182       break;
183     }
184     if (_ivalue[ DISTR_TYPE_IND ] == StdMeshers_NumberOfSegments::DT_TabFunc ||
185         _ivalue[ DISTR_TYPE_IND ] == StdMeshers_NumberOfSegments::DT_ExprFunc)
186         _ivalue[ CONV_MODE_IND ] = hyp->ConversionMode();
187     _hypType = NB_SEGMENTS;
188     aStatus = SMESH_Hypothesis::HYP_OK;
189   }
190
191   else if (hypName == "Arithmetic1D")
192   {
193     const StdMeshers_Arithmetic1D * hyp =
194       dynamic_cast <const StdMeshers_Arithmetic1D * >(theHyp);
195     ASSERT(hyp);
196     _value[ BEG_LENGTH_IND ] = hyp->GetLength( true );
197     _value[ END_LENGTH_IND ] = hyp->GetLength( false );
198     ASSERT( _value[ BEG_LENGTH_IND ] > 0 && _value[ END_LENGTH_IND ] > 0 );
199     _hypType = ARITHMETIC_1D;
200     aStatus = SMESH_Hypothesis::HYP_OK;
201   }
202
203   else if (hypName == "StartEndLength")
204   {
205     const StdMeshers_StartEndLength * hyp =
206       dynamic_cast <const StdMeshers_StartEndLength * >(theHyp);
207     ASSERT(hyp);
208     _value[ BEG_LENGTH_IND ] = hyp->GetLength( true );
209     _value[ END_LENGTH_IND ] = hyp->GetLength( false );
210     ASSERT( _value[ BEG_LENGTH_IND ] > 0 && _value[ END_LENGTH_IND ] > 0 );
211     _hypType = BEG_END_LENGTH;
212     aStatus = SMESH_Hypothesis::HYP_OK;
213   }
214
215   else if (hypName == "Deflection1D")
216   {
217     const StdMeshers_Deflection1D * hyp =
218       dynamic_cast <const StdMeshers_Deflection1D * >(theHyp);
219     ASSERT(hyp);
220     _value[ DEFLECTION_IND ] = hyp->GetDeflection();
221     ASSERT( _value[ DEFLECTION_IND ] > 0 );
222     _hypType = DEFLECTION;
223     aStatus = SMESH_Hypothesis::HYP_OK;
224   }
225
226   else if (hypName == "AutomaticLength")
227   {
228     StdMeshers_AutomaticLength * hyp = const_cast<StdMeshers_AutomaticLength *>
229       (dynamic_cast <const StdMeshers_AutomaticLength * >(theHyp));
230     ASSERT(hyp);
231     _value[ BEG_LENGTH_IND ] = _value[ END_LENGTH_IND ] = hyp->GetLength( &aMesh, aShape );
232     ASSERT( _value[ BEG_LENGTH_IND ] > 0 );
233     _hypType = LOCAL_LENGTH;
234     aStatus = SMESH_Hypothesis::HYP_OK;
235   }
236   else
237     aStatus = SMESH_Hypothesis::HYP_INCOMPATIBLE;
238
239   return ( _hypType != NONE );
240 }
241
242 //=======================================================================
243 //function : compensateError
244 //purpose  : adjust theParams so that the last segment length == an
245 //=======================================================================
246
247 static void compensateError(double a1, double an,
248                             double U1, double Un,
249                             double             length,
250                             GeomAdaptor_Curve& C3d,
251                             list<double> &     theParams)
252 {
253   int i, nPar = theParams.size();
254   if ( a1 + an < length && nPar > 1 )
255   {
256     list<double>::reverse_iterator itU = theParams.rbegin();
257     double Ul = *itU++;
258     // dist from the last point to the edge end <Un>, it should be equal <an>
259     double Ln = GCPnts_AbscissaPoint::Length( C3d, Ul, Un );
260     double dLn = an - Ln; // error of <an>
261     if ( Abs( dLn ) <= Precision::Confusion() )
262       return;
263     double dU = Abs( Ul - *itU ); // parametric length of the last but one segment
264     double dUn = dLn * Abs( Un - U1 ) / length; // parametric error of <an>
265     if ( dUn < 0.5 * dU ) { // last segment is a bit shorter than it should
266       dUn = -dUn; // move the last parameter to the edge beginning
267     }
268     else {  // last segment is much shorter than it should -> remove the last param and
269       theParams.pop_back(); nPar--; // move the rest points toward the edge end
270       Ln = GCPnts_AbscissaPoint::Length( C3d, theParams.back(), Un );
271       dUn = ( an - Ln ) * Abs( Un - U1 ) / length;
272       if ( dUn < 0.5 * dU )
273         dUn = -dUn;
274     }
275     if ( U1 > Un )
276       dUn = -dUn;
277     double q  = dUn / ( nPar - 1 );
278     for ( itU = theParams.rbegin(), i = 1; i < nPar; itU++, i++ ) {
279       (*itU) += dUn;
280       dUn -= q;
281     }
282   }
283 }
284
285 static bool computeParamByFunc(Adaptor3d_Curve& C3d, double first, double last,
286                                double length, bool theReverse, 
287                                int nbSeg, Function& func,
288                                list<double>& theParams)
289 {
290   // never do this way
291   //OSD::SetSignal( true );
292
293   if( nbSeg<=0 )
294     return false;
295
296   MESSAGE( "computeParamByFunc" );
297
298   int nbPnt = 1 + nbSeg;
299   vector<double> x(nbPnt, 0.);
300
301   if( !buildDistribution( func, 0.0, 1.0, nbSeg, x, 1E-4 ) )
302      return false;
303
304   MESSAGE( "Points:\n" );
305   char buf[1024];
306   for( int i=0; i<=nbSeg; i++ )
307   {
308     sprintf(  buf, "%f\n", float(x[i] ) );
309     MESSAGE( buf );
310   }
311     
312
313
314   // apply parameters in range [0,1] to the space of the curve
315   double prevU = first;
316   double sign = 1.;
317   if (theReverse)
318   {
319     prevU = last;
320     sign = -1.;
321   }
322   for( int i = 1; i < nbSeg; i++ )
323   {
324     double curvLength = length * (x[i] - x[i-1]) * sign;
325     GCPnts_AbscissaPoint Discret( C3d, curvLength, prevU );
326     if ( !Discret.IsDone() )
327       return false;
328     double U = Discret.Parameter();
329     if ( U > first && U < last )
330       theParams.push_back( U );
331     else
332       return false;
333     prevU = U;
334   }
335   return true;
336 }
337
338 //=============================================================================
339 /*!
340  *  
341  */
342 //=============================================================================
343 bool StdMeshers_Regular_1D::computeInternalParameters(const TopoDS_Edge& theEdge,
344                                                       list<double> &     theParams,
345                                                       const bool         theReverse) const
346 {
347   theParams.clear();
348
349   double f, l;
350   Handle(Geom_Curve) Curve = BRep_Tool::Curve(theEdge, f, l);
351   GeomAdaptor_Curve C3d (Curve, f, l);
352
353   double length = EdgeLength(theEdge);
354
355   switch( _hypType )
356   {
357   case LOCAL_LENGTH:
358   case NB_SEGMENTS: {
359
360     double eltSize = 1;
361     if ( _hypType == LOCAL_LENGTH )
362     {
363       // Local Length hypothesis
364       double nbseg = ceil(length / _value[ BEG_LENGTH_IND ]); // integer sup
365       if (nbseg <= 0)
366         nbseg = 1;                        // degenerated edge
367       eltSize = length / nbseg;
368     }
369     else
370     {
371       // Number Of Segments hypothesis
372       int NbSegm = _ivalue[ NB_SEGMENTS_IND ];
373       if ( NbSegm < 1 )  return false;
374       if ( NbSegm == 1 ) return true;
375
376       switch (_ivalue[ DISTR_TYPE_IND ])
377       {
378       case StdMeshers_NumberOfSegments::DT_Scale:
379         {
380           double scale = _value[ SCALE_FACTOR_IND ];
381
382           if (fabs(scale - 1.0) < Precision::Confusion()) {
383             // special case to avoid division on zero
384             for (int i = 1; i < NbSegm; i++) {
385               double param = f + (l - f) * i / NbSegm;
386               theParams.push_back( param );
387             }
388           } else {
389             // general case of scale distribution
390             if ( theReverse )
391               scale = 1.0 / scale;
392
393             double alpha = pow(scale, 1.0 / (NbSegm - 1));
394             double factor = (l - f) / (1.0 - pow(alpha, NbSegm));
395
396             for (int i = 1; i < NbSegm; i++) {
397               double param = f + factor * (1.0 - pow(alpha, i));
398               theParams.push_back( param );
399             }
400           }
401           return true;
402         }
403         break;
404       case StdMeshers_NumberOfSegments::DT_TabFunc:
405         {
406           FunctionTable func(_vvalue[ TAB_FUNC_IND ], _ivalue[ CONV_MODE_IND ]);
407           return computeParamByFunc(C3d, f, l, length, theReverse,
408                                     _ivalue[ NB_SEGMENTS_IND ], func,
409                                     theParams);
410         }
411         break;
412       case StdMeshers_NumberOfSegments::DT_ExprFunc:
413         {
414           FunctionExpr func(_svalue[ EXPR_FUNC_IND ].c_str(), _ivalue[ CONV_MODE_IND ]);
415           return computeParamByFunc(C3d, f, l, length, theReverse,
416                                     _ivalue[ NB_SEGMENTS_IND ], func,
417                                     theParams);
418         }
419         break;
420       case StdMeshers_NumberOfSegments::DT_Regular:
421         eltSize = length / _ivalue[ NB_SEGMENTS_IND ];
422         break;
423       default:
424         return false;
425       }
426     }
427     GCPnts_UniformAbscissa Discret(C3d, eltSize, f, l);
428     if ( !Discret.IsDone() )
429       return false;
430
431     int NbPoints = Discret.NbPoints();
432     for ( int i = 2; i < NbPoints; i++ )
433     {
434       double param = Discret.Parameter(i);
435       theParams.push_back( param );
436     }
437     compensateError( eltSize, eltSize, f, l, length, C3d, theParams ); // for PAL9899
438     return true;
439   }
440
441   case BEG_END_LENGTH: {
442
443     // geometric progression: SUM(n) = ( a1 - an * q ) / ( 1 - q ) = length
444
445     double a1 = _value[ BEG_LENGTH_IND ];
446     double an = _value[ END_LENGTH_IND ];
447     double q  = ( length - a1 ) / ( length - an );
448
449     double U1 = theReverse ? l : f;
450     double Un = theReverse ? f : l;
451     double param = U1;
452     double eltSize = theReverse ? -a1 : a1;
453     while ( 1 ) {
454       // computes a point on a curve <C3d> at the distance <eltSize>
455       // from the point of parameter <param>.
456       GCPnts_AbscissaPoint Discret( C3d, eltSize, param );
457       if ( !Discret.IsDone() ) break;
458       param = Discret.Parameter();
459       if ( param > f && param < l )
460         theParams.push_back( param );
461       else
462         break;
463       eltSize *= q;
464     }
465     compensateError( a1, an, U1, Un, length, C3d, theParams );
466     return true;
467   }
468
469   case ARITHMETIC_1D: {
470
471     // arithmetic progression: SUM(n) = ( an - a1 + q ) * ( a1 + an ) / ( 2 * q ) = length
472
473     double a1 = _value[ BEG_LENGTH_IND ];
474     double an = _value[ END_LENGTH_IND ];
475
476     double  q = ( an - a1 ) / ( 2 *length/( a1 + an ) - 1 );
477     int     n = int( 1 + ( an - a1 ) / q );
478
479     double U1 = theReverse ? l : f;
480     double Un = theReverse ? f : l;
481     double param = U1;
482     double eltSize = a1;
483     if ( theReverse ) {
484       eltSize = -eltSize;
485       q = -q;
486     }
487     while ( n-- > 0 && eltSize * ( Un - U1 ) > 0 ) {
488       // computes a point on a curve <C3d> at the distance <eltSize>
489       // from the point of parameter <param>.
490       GCPnts_AbscissaPoint Discret( C3d, eltSize, param );
491       if ( !Discret.IsDone() ) break;
492       param = Discret.Parameter();
493       if ( param > f && param < l )
494         theParams.push_back( param );
495       else
496         break;
497       eltSize += q;
498     }
499     compensateError( a1, an, U1, Un, length, C3d, theParams );
500
501     return true;
502   }
503
504   case DEFLECTION: {
505
506     GCPnts_UniformDeflection Discret(C3d, _value[ DEFLECTION_IND ], f, l, true);
507     if ( !Discret.IsDone() )
508       return false;
509
510     int NbPoints = Discret.NbPoints();
511     for ( int i = 2; i < NbPoints; i++ )
512     {
513       double param = Discret.Parameter(i);
514       theParams.push_back( param );
515     }
516     return true;
517     
518   }
519
520   default:;
521   }
522
523   return false;
524 }
525
526 //=============================================================================
527 /*!
528  *  
529  */
530 //=============================================================================
531
532 bool StdMeshers_Regular_1D::Compute(SMESH_Mesh & aMesh, const TopoDS_Shape & aShape)
533 {
534   MESSAGE("StdMeshers_Regular_1D::Compute");
535
536   if ( _hypType == NONE )
537     return false;
538
539   SMESHDS_Mesh * meshDS = aMesh.GetMeshDS();
540   aMesh.GetSubMesh(aShape);
541
542   const TopoDS_Edge & EE = TopoDS::Edge(aShape);
543   TopoDS_Edge E = TopoDS::Edge(EE.Oriented(TopAbs_FORWARD));
544   int shapeID = meshDS->ShapeToIndex( E );
545
546   double f, l;
547   Handle(Geom_Curve) Curve = BRep_Tool::Curve(E, f, l);
548
549   TopoDS_Vertex VFirst, VLast;
550   TopExp::Vertices(E, VFirst, VLast);   // Vfirst corresponds to f and Vlast to l
551
552   ASSERT(!VFirst.IsNull());
553   SMDS_NodeIteratorPtr lid= aMesh.GetSubMesh(VFirst)->GetSubMeshDS()->GetNodes();
554   if (!lid->more())
555   {
556     MESSAGE (" NO NODE BUILT ON VERTEX ");
557     return false;
558   }
559   const SMDS_MeshNode * idFirst = lid->next();
560
561   ASSERT(!VLast.IsNull());
562   lid=aMesh.GetSubMesh(VLast)->GetSubMeshDS()->GetNodes();
563   if (!lid->more()) {
564     MESSAGE (" NO NODE BUILT ON VERTEX ");
565     return false;
566   }
567   const SMDS_MeshNode * idLast = lid->next();
568
569   if (!Curve.IsNull()) {
570     list< double > params;
571     bool reversed = false;
572     if ( !_mainEdge.IsNull() )
573       reversed = aMesh.IsReversedInChain( EE, _mainEdge );
574     try {
575       if ( ! computeInternalParameters( E, params, reversed )) {
576         //cout << "computeInternalParameters() failed" <<endl;
577         return false;
578       }
579     }
580     catch ( Standard_Failure ) {
581       //cout << "computeInternalParameters() failed, Standard_Failure" <<endl;
582       return false;
583     }
584
585     // edge extrema (indexes : 1 & NbPoints) already in SMDS (TopoDS_Vertex)
586     // only internal nodes receive an edge position with param on curve
587
588     const SMDS_MeshNode * idPrev = idFirst;
589     double parPrev = f;
590     double parLast = l;
591 //     if(reversed) {
592 //       parPrev = l;
593 //       parLast = f;
594 //     }
595     
596     for (list<double>::iterator itU = params.begin(); itU != params.end(); itU++) {
597       double param = *itU;
598       gp_Pnt P = Curve->Value(param);
599
600       //Add the Node in the DataStructure
601       SMDS_MeshNode * node = meshDS->AddNode(P.X(), P.Y(), P.Z());
602       meshDS->SetNodeOnEdge(node, shapeID, param);
603
604       if(_quadraticMesh) {
605         // create medium node
606         double prm = ( parPrev + param )/2;
607         gp_Pnt PM = Curve->Value(prm);
608         SMDS_MeshNode * NM = meshDS->AddNode(PM.X(), PM.Y(), PM.Z());
609         meshDS->SetNodeOnEdge(NM, shapeID, prm);
610         SMDS_MeshEdge * edge = meshDS->AddEdge(idPrev, node, NM);
611         meshDS->SetMeshElementOnShape(edge, shapeID);
612       }
613       else {
614         SMDS_MeshEdge * edge = meshDS->AddEdge(idPrev, node);
615         meshDS->SetMeshElementOnShape(edge, shapeID);
616       }
617
618       idPrev = node;
619       parPrev = param;
620     }
621     if(_quadraticMesh) {
622       double prm = ( parPrev + parLast )/2;
623       gp_Pnt PM = Curve->Value(prm);
624       SMDS_MeshNode * NM = meshDS->AddNode(PM.X(), PM.Y(), PM.Z());
625       meshDS->SetNodeOnEdge(NM, shapeID, prm);
626       SMDS_MeshEdge * edge = meshDS->AddEdge(idPrev, idLast, NM);
627       meshDS->SetMeshElementOnShape(edge, shapeID);
628     }
629     else {
630       SMDS_MeshEdge* edge = meshDS->AddEdge(idPrev, idLast);
631       meshDS->SetMeshElementOnShape(edge, shapeID);
632     }
633   }
634   else {
635     // Edge is a degenerated Edge : We put n = 5 points on the edge.
636     const int NbPoints = 5;
637     BRep_Tool::Range(E, f, l);
638     double du = (l - f) / (NbPoints - 1);
639     //MESSAGE("************* Degenerated edge! *****************");
640
641     TopoDS_Vertex V1, V2;
642     TopExp::Vertices(E, V1, V2);
643     gp_Pnt P = BRep_Tool::Pnt(V1);
644
645     const SMDS_MeshNode * idPrev = idFirst;
646     for (int i = 2; i < NbPoints; i++) {
647       double param = f + (i - 1) * du;
648       SMDS_MeshNode * node = meshDS->AddNode(P.X(), P.Y(), P.Z());
649       if(_quadraticMesh) {
650         // create medium node
651         double prm = param - du/2.;
652         SMDS_MeshNode * NM = meshDS->AddNode(P.X(), P.Y(), P.Z());
653         meshDS->SetNodeOnEdge(NM, shapeID, prm);
654         SMDS_MeshEdge * edge = meshDS->AddEdge(idPrev, node, NM);
655         meshDS->SetMeshElementOnShape(edge, shapeID);
656       }
657       else {
658         SMDS_MeshEdge * edge = meshDS->AddEdge(idPrev, node);
659         meshDS->SetMeshElementOnShape(edge, shapeID);
660       }
661       meshDS->SetNodeOnEdge(node, shapeID, param);
662       idPrev = node;
663     }
664     if(_quadraticMesh) {
665       // create medium node
666       double prm = l - du/2.;
667       SMDS_MeshNode * NM = meshDS->AddNode(P.X(), P.Y(), P.Z());
668       meshDS->SetNodeOnEdge(NM, shapeID, prm);
669       SMDS_MeshEdge * edge = meshDS->AddEdge(idPrev, idLast, NM);
670       meshDS->SetMeshElementOnShape(edge, shapeID);
671     }
672     else {
673       SMDS_MeshEdge * edge = meshDS->AddEdge(idPrev, idLast);
674       meshDS->SetMeshElementOnShape(edge, shapeID);
675     }
676   }
677   return true;
678 }
679
680 //=============================================================================
681 /*!
682  *  See comments in SMESH_Algo.cxx
683  */
684 //=============================================================================
685
686 const list <const SMESHDS_Hypothesis *> &
687 StdMeshers_Regular_1D::GetUsedHypothesis(SMESH_Mesh &         aMesh,
688                                          const TopoDS_Shape & aShape,
689                                          const bool           ignoreAuxiliary)
690 {
691   _usedHypList.clear();
692   _mainEdge.Nullify();
693
694   SMESH_HypoFilter auxiliaryFilter, compatibleFilter;
695   auxiliaryFilter.Init( SMESH_HypoFilter::IsAuxiliary() );
696   const bool ignoreAux = true;
697   InitCompatibleHypoFilter( compatibleFilter, ignoreAux );
698
699   // get non-auxiliary assigned to aShape
700   int nbHyp = aMesh.GetHypotheses( aShape, compatibleFilter, _usedHypList, false );
701
702   if (nbHyp == 0)
703   {
704     // Check, if propagated from some other edge
705     if (aShape.ShapeType() == TopAbs_EDGE &&
706         aMesh.IsPropagatedHypothesis(aShape, _mainEdge))
707     {
708       // Propagation of 1D hypothesis from <aMainEdge> on this edge;
709       // get non-auxiliary assigned to _mainEdge
710       nbHyp = aMesh.GetHypotheses( _mainEdge, compatibleFilter, _usedHypList, true );
711     }
712   }
713
714   if (nbHyp == 0) // nothing propagated nor assigned to aShape
715   {
716     SMESH_Algo::GetUsedHypothesis( aMesh, aShape, ignoreAuxiliary );
717     nbHyp = _usedHypList.size();
718   }
719   else
720   {
721     // get auxiliary hyps from aShape
722     aMesh.GetHypotheses( aShape, auxiliaryFilter, _usedHypList, true );
723   }
724   if ( nbHyp > 1 && ignoreAuxiliary )
725     _usedHypList.clear(); //only one compatible non-auxiliary hypothesis allowed
726
727   return _usedHypList;
728 }
729
730 //=============================================================================
731 /*!
732  *  
733  */
734 //=============================================================================
735
736 ostream & StdMeshers_Regular_1D::SaveTo(ostream & save)
737 {
738   return save;
739 }
740
741 //=============================================================================
742 /*!
743  *  
744  */
745 //=============================================================================
746
747 istream & StdMeshers_Regular_1D::LoadFrom(istream & load)
748 {
749   return load;
750 }
751
752 //=============================================================================
753 /*!
754  *  
755  */
756 //=============================================================================
757
758 ostream & operator <<(ostream & save, StdMeshers_Regular_1D & hyp)
759 {
760   return hyp.SaveTo( save );
761 }
762
763 //=============================================================================
764 /*!
765  *  
766  */
767 //=============================================================================
768
769 istream & operator >>(istream & load, StdMeshers_Regular_1D & hyp)
770 {
771   return hyp.LoadFrom( load );
772 }