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