Salome HOME
04039c96a9f4a9591437404d3247bae5f60824f4
[modules/hydro.git] / src / HYDROData / HYDROData_PolylineXY.cxx
1
2 #include "HYDROData_PolylineXY.h"
3
4 #include "HYDROData_BSplineOperation.h"
5 #include "HYDROData_Document.h"
6 #include "HYDROData_Tool.h"
7
8 #include <BRep_Builder.hxx>
9 #include <BRepBuilderAPI_MakeEdge.hxx>
10 #include <BRepBuilderAPI_MakeWire.hxx>
11
12 #include <ImageComposer_MetaTypes.h>
13
14 #include <gp_Pnt.hxx>
15 #include <gp_XY.hxx>
16
17 #include <NCollection_Map.hxx>
18
19 #include <TCollection_ExtendedString.hxx>
20
21 #include <TDataStd_ListIteratorOfListOfByte.hxx>
22 #include <TColStd_ListIteratorOfListOfInteger.hxx>
23 #include <TColStd_ListIteratorOfListOfReal.hxx>
24
25 #include <TDataStd_BooleanList.hxx>
26 #include <TDataStd_ExtStringList.hxx>
27 #include <TDataStd_IntegerList.hxx>
28 #include <TDataStd_ListIteratorOfListOfExtendedString.hxx>
29 #include <TDataStd_RealList.hxx>
30
31 #include <TopTools_ListIteratorOfListOfShape.hxx>
32
33 #include <QPainterPath>
34 #include <QVariant>
35
36 #define PYTHON_POLYLINEXY_ID "KIND_POLYLINEXY"
37
38 IMPLEMENT_STANDARD_HANDLE(HYDROData_PolylineXY, HYDROData_IPolyline)
39 IMPLEMENT_STANDARD_RTTIEXT(HYDROData_PolylineXY, HYDROData_IPolyline)
40
41 HYDROData_PolylineXY::HYDROData_PolylineXY()
42 : HYDROData_IPolyline()
43 {
44 }
45
46 HYDROData_PolylineXY::~HYDROData_PolylineXY()
47 {
48 }
49
50 QStringList HYDROData_PolylineXY::DumpToPython( MapOfTreatedObjects& theTreatedObjects ) const
51 {
52   QStringList aResList;
53
54   Handle(HYDROData_Document) aDocument = HYDROData_Document::Document( myLab );
55   if ( aDocument.IsNull() )
56     return aResList;
57                              
58   QString aDocName = aDocument->GetDocPyName();
59   QString aPolylineName = GetName();
60
61   aResList << QString( "%1 = %2.CreateObject( %3 );" )
62               .arg( aPolylineName ).arg( aDocName ).arg( PYTHON_POLYLINEXY_ID );
63   aResList << QString( "%1.SetName( \"%1\" );" ).arg( aPolylineName );
64
65   // Set polilyne data
66   NCollection_Sequence<TCollection_AsciiString>           aSectNames;
67   NCollection_Sequence<HYDROData_PolylineXY::SectionType> aSectTypes;
68   NCollection_Sequence<bool>                              aSectClosures;
69   GetSections( aSectNames, aSectTypes, aSectClosures );
70
71   for ( int i = 1, n = aSectNames.Size(); i <= n; ++i )
72   {
73     const TCollection_AsciiString& aSectName = aSectNames.Value( i );
74     const SectionType& aSectType = aSectTypes.Value( i );
75     bool aSectClosure = aSectClosures.Value( i );
76
77     aResList << QString( "%1.AddSection( \"%2\", %3, %4 );" ).arg( aPolylineName )
78                 .arg( aSectName.ToCString() ).arg( aSectType ).arg( aSectClosure );
79
80     HYDROData_PolylineXY::PointsList aSectPointsList = GetPoints( i );
81     for ( int k = 1, aNbPoints = aSectPointsList.Size(); k <= aNbPoints; ++k )
82     {
83       const HYDROData_PolylineXY::Point& aSectPoint = aSectPointsList.Value( k );
84
85       aResList << QString( "%1.AddPoint( %2, QPointF( %3, %4 ) );" ).arg( aPolylineName )
86         .arg( i - 1 ).arg( aSectPoint.X() ).arg( aSectPoint.Y() );
87     }
88   }
89
90   return aResList;
91 }
92
93 QVariant HYDROData_PolylineXY::GetDataVariant()
94 {
95   QPainterPath aPath = GetPainterPath();
96
97   QVariant aVarData;
98   aVarData.setValue<QPainterPath>( aPath );
99   
100   return aVarData;
101 }
102
103 TopoDS_Shape HYDROData_PolylineXY::GetShape()
104 {
105   return getPolylineShape();
106 }
107
108 void HYDROData_PolylineXY::Update()
109 {
110   NCollection_Sequence<TCollection_AsciiString>           aSectNames;
111   NCollection_Sequence<HYDROData_PolylineXY::SectionType> aSectTypes;
112   NCollection_Sequence<bool>                              aSectClosures;
113   GetSections( aSectNames, aSectTypes, aSectClosures );
114
115   BRepBuilderAPI_MakeWire aMakeWire;
116
117   TopTools_ListOfShape aSectionWiresList;
118
119   for ( int aSectionId = 1, aNbSects = aSectNames.Size(); aSectionId <= aNbSects; aSectionId++ )
120   {
121     TCollection_AsciiString aSectName = aSectNames.Value( aSectionId );
122     SectionType aSectionType = aSectTypes.Value( aSectionId );
123     bool anIsSectionClosed = aSectClosures.Value( aSectionId );
124
125     PointsList aSectPointsList = GetPoints( aSectionId - 1 );
126     if ( aSectPointsList.IsEmpty() )
127       continue;
128
129     BRepBuilderAPI_MakeWire aMakeSectionWire;
130     if( aSectionType == SECTION_POLYLINE )
131     {
132       for( int i = 1, n = aSectPointsList.Size(); i <= n; ++i )
133       {
134         const Point& aFirstPoint = aSectPointsList.Value( i );
135
136         Point aLastPoint;
137         if ( i == n )
138         {
139           if( anIsSectionClosed )
140             aLastPoint = aSectPointsList.Value( 1 );
141           else
142             break;
143         }
144         else
145         {
146           aLastPoint = aSectPointsList.Value( i + 1 );
147         }
148
149         gp_Pnt aPnt1( aFirstPoint.X(), aFirstPoint.Y(), 0.0 );
150         gp_Pnt aPnt2( aLastPoint.X(), aLastPoint.Y(), 0.0 );
151
152         TopoDS_Edge anEdge = BRepBuilderAPI_MakeEdge( aPnt1, aPnt2 ).Edge();
153         aMakeSectionWire.Add( anEdge );
154       }
155     }
156     else //if( aSectionType == PolylineSection::SECTION_SPLINE )
157     {
158       QList<double> aPoints;
159       for( int i = 1, n = aSectPointsList.Size(); i <= n; ++i )
160       {
161         const Point& aSectPoint = aSectPointsList.Value( i );
162         aPoints << aSectPoint.X() << aSectPoint.Y();
163       }
164
165       HYDROData_BSplineOperation aBSpline( aPoints, 0.0, anIsSectionClosed );
166
167       TopoDS_Edge anEdge = BRepBuilderAPI_MakeEdge( aBSpline.Curve() ).Edge();
168       aMakeSectionWire.Add( anEdge );
169     }
170    
171     TopoDS_Wire aSectionWire = aMakeSectionWire.Wire();
172     aSectionWiresList.Append( aSectionWire );
173     aMakeWire.Add( aSectionWire );
174   }
175
176   TopoDS_Shape aShape;
177
178   if ( aMakeWire.IsDone() )
179   {
180     aShape = aMakeWire.Shape();
181   }
182   else if ( !aSectionWiresList.IsEmpty() )
183   {
184     // build compound
185     TopoDS_Compound aCompound;
186     
187     BRep_Builder aBuilder;
188     aBuilder.MakeCompound( aCompound );
189     
190     TopTools_ListIteratorOfListOfShape anIter( aSectionWiresList );
191     for ( ; anIter.More(); anIter.Next() )
192     {
193       aBuilder.Add( aCompound, anIter.Value() );
194     }
195     
196     aShape = aCompound;
197   }
198
199   setPolylineShape( aShape );
200 }
201
202 /**
203  * Returns true if polyline is closed
204  */
205 bool HYDROData_PolylineXY::IsClosed() const
206 {
207   NCollection_Sequence<TCollection_AsciiString>           aSectNames;
208   NCollection_Sequence<HYDROData_PolylineXY::SectionType> aSectTypes;
209   NCollection_Sequence<bool>                              aSectClosures;
210   GetSections( aSectNames, aSectTypes, aSectClosures );
211   if( aSectNames.IsEmpty() )
212     return false;
213
214   bool anIsClosed = true;
215   for( int i = 1, n = aSectClosures.Size(); i <= n && anIsClosed; ++i )
216     anIsClosed = anIsClosed && aSectClosures.Value( i );
217
218   return anIsClosed;
219 }
220
221 int HYDROData_PolylineXY::NbSections() const
222 {
223   Handle(TDataStd_ExtStringList) aNamesList;
224   Handle(TDataStd_IntegerList)   aTypesList;
225   Handle(TDataStd_BooleanList)   aClosuresList;
226   getSectionsLists( aNamesList, aTypesList, aClosuresList, false );
227
228   return !aClosuresList.IsNull() ? aClosuresList->Extent() : 0;
229 }
230
231 TCollection_ExtendedString getUniqueSectionName( const Handle(TDataStd_ExtStringList)& theNamesList )
232 {
233   NCollection_Map<TCollection_ExtendedString> aNamesMap;
234
235   TDataStd_ListIteratorOfListOfExtendedString aNamesIter( theNamesList->List() );
236   for ( ; aNamesIter.More(); aNamesIter.Next() )
237     aNamesMap.Add( aNamesIter.Value() );
238
239   TCollection_ExtendedString aResName;
240
241   int aPrefIdx = 1;
242   do
243   {
244     aResName = "Section_" + aPrefIdx;
245     ++aPrefIdx;
246   }
247   while ( aNamesMap.Contains( aResName ) );
248
249   return aResName;
250 }
251
252 void HYDROData_PolylineXY::AddSection( const TCollection_AsciiString& theSectName,
253                                        const SectionType              theSectionType,
254                                        const bool                     theIsClosed )
255 {
256   Handle(TDataStd_ExtStringList) aNamesList;
257   Handle(TDataStd_IntegerList)   aTypesList;
258   Handle(TDataStd_BooleanList)   aClosuresList;
259   getSectionsLists( aNamesList, aTypesList, aClosuresList );
260
261   TCollection_ExtendedString aSectName( theSectName );
262   if ( aSectName.Length() <= 0 )
263     aSectName = getUniqueSectionName( aNamesList );
264
265   aNamesList->Append( aSectName );
266   aTypesList->Append( theSectionType );
267   aClosuresList->Append( theIsClosed );
268 }
269
270 TCollection_AsciiString HYDROData_PolylineXY::GetSectionName( const int theSectionIndex ) const
271 {
272   TCollection_AsciiString aResName;
273
274   Handle(TDataStd_ExtStringList) aNamesList;
275   Handle(TDataStd_IntegerList) aTypesList;
276   Handle(TDataStd_BooleanList) aClosuresList;
277   getSectionsLists( aNamesList, aTypesList, aClosuresList, false );
278   if ( aNamesList.IsNull() || theSectionIndex >= aNamesList->Extent() )
279     return aResName;
280
281   TDataStd_ListIteratorOfListOfExtendedString aNamesIter( aNamesList->List() );
282   for ( int i = 0; aNamesIter.More() && i != theSectionIndex; aNamesIter.Next(), ++i );
283
284   if ( aNamesIter.More() )
285     aResName = aNamesIter.Value();
286
287   return aResName;
288 }
289
290 void HYDROData_PolylineXY::SetSectionName( const int                      theSectionIndex, 
291                                            const TCollection_AsciiString& theSectionName )
292 {
293   Handle(TDataStd_ExtStringList) aNamesList;
294   Handle(TDataStd_IntegerList) aTypesList;
295   Handle(TDataStd_BooleanList) aClosuresList;
296   getSectionsLists( aNamesList, aTypesList, aClosuresList, false );
297   if ( aNamesList.IsNull() || theSectionIndex >= aNamesList->Extent() )
298     return;
299
300   TDataStd_ListOfExtendedString anOldNamesList;
301   anOldNamesList = aNamesList->List();
302
303   // Refill the existing list
304   aNamesList->Clear();
305
306   TDataStd_ListIteratorOfListOfExtendedString aNamesIter( aNamesList->List() );
307   for ( int i = 0; aNamesIter.More(); aNamesIter.Next(), ++i )
308     aNamesList->Append( i == theSectionIndex ? theSectionName : aNamesIter.Value() );
309 }
310
311 HYDROData_PolylineXY::SectionType HYDROData_PolylineXY::GetSectionType( const int theSectionIndex ) const
312 {
313   Handle(TDataStd_ExtStringList) aNamesList;
314   Handle(TDataStd_IntegerList) aTypesList;
315   Handle(TDataStd_BooleanList) aClosuresList;
316   getSectionsLists( aNamesList, aTypesList, aClosuresList, false );
317   if ( aTypesList.IsNull() || theSectionIndex >= aTypesList->Extent() )
318     return SECTION_POLYLINE;
319
320   TColStd_ListIteratorOfListOfInteger aTypesIter( aTypesList->List() );
321   for ( int i = 0; aTypesIter.More() && i != theSectionIndex; aTypesIter.Next(), ++i );
322
323   return aTypesIter.More() ? (SectionType)aTypesIter.Value() : SECTION_POLYLINE;
324 }
325
326 void HYDROData_PolylineXY::SetSectionType( const int         theSectionIndex, 
327                                            const SectionType theSectionType )
328 {
329   Handle(TDataStd_ExtStringList) aNamesList;
330   Handle(TDataStd_IntegerList) aTypesList;
331   Handle(TDataStd_BooleanList) aClosuresList;
332   getSectionsLists( aNamesList, aTypesList, aClosuresList, false );
333   if ( aTypesList.IsNull() || theSectionIndex >= aTypesList->Extent() )
334     return;
335
336   TColStd_ListOfInteger anOldTypesList;
337   anOldTypesList = aTypesList->List();
338
339   // Refill the existing list
340   aTypesList->Clear();
341
342   TColStd_ListIteratorOfListOfInteger aTypesIter( anOldTypesList );
343   for ( int i = 0; aTypesIter.More(); aTypesIter.Next(), ++i )
344     aTypesList->Append( i == theSectionIndex ? theSectionType : aTypesIter.Value() );
345 }
346
347 bool HYDROData_PolylineXY::IsClosedSection( const int theSectionIndex ) const
348 {
349   Handle(TDataStd_ExtStringList) aNamesList;
350   Handle(TDataStd_IntegerList) aTypesList;
351   Handle(TDataStd_BooleanList) aClosuresList;
352   getSectionsLists( aNamesList, aTypesList, aClosuresList, false );
353   if ( aClosuresList.IsNull() || theSectionIndex >= aClosuresList->Extent() )
354     return false;
355
356   TDataStd_ListIteratorOfListOfByte aClosuresIter( aClosuresList->List() );
357   for ( int i = 0; aClosuresIter.More() && i != theSectionIndex; aClosuresIter.Next(), ++i );
358
359   return aClosuresIter.More() ? (bool)aClosuresIter.Value() : false;
360 }
361
362 void HYDROData_PolylineXY::SetSectionClosed( const int  theSectionIndex, 
363                                              const bool theIsClosed )
364 {
365   Handle(TDataStd_ExtStringList) aNamesList;
366   Handle(TDataStd_IntegerList) aTypesList;
367   Handle(TDataStd_BooleanList) aClosuresList;
368   getSectionsLists( aNamesList, aTypesList, aClosuresList, false );
369   if ( aClosuresList.IsNull() || theSectionIndex >= aClosuresList->Extent() )
370     return;
371
372   TDataStd_ListOfByte anOldClosuresList;
373   anOldClosuresList = aClosuresList->List();
374
375   // Refill the existing list
376   aClosuresList->Clear();
377
378   TDataStd_ListIteratorOfListOfByte aClosuresIter( anOldClosuresList );
379   for ( int i = 0; aClosuresIter.More(); aClosuresIter.Next(), ++i )
380     aClosuresList->Append( i == theSectionIndex ? theIsClosed : (bool)aClosuresIter.Value() );
381 }
382
383 void HYDROData_PolylineXY::GetSections( NCollection_Sequence<TCollection_AsciiString>& theSectNames,
384                                         NCollection_Sequence<SectionType>&             theSectTypes,
385                                         NCollection_Sequence<bool>&                    theSectClosures ) const
386 {
387   theSectNames.Clear();
388   theSectTypes.Clear();
389   theSectClosures.Clear();
390
391   Handle(TDataStd_ExtStringList) aNamesList;
392   Handle(TDataStd_IntegerList) aTypesList;
393   Handle(TDataStd_BooleanList) aClosuresList;
394   getSectionsLists( aNamesList, aTypesList, aClosuresList, false );
395   if ( aNamesList.IsNull() || aTypesList.IsNull() || aClosuresList.IsNull() )
396     return;
397
398   TDataStd_ListIteratorOfListOfExtendedString aNamesIter( aNamesList->List() );
399   TColStd_ListIteratorOfListOfInteger aTypesIter( aTypesList->List() );
400   TDataStd_ListIteratorOfListOfByte aClosuresIter( aClosuresList->List() );
401   for ( ; aNamesIter.More() && aTypesIter.More() && aClosuresIter.More();
402           aNamesIter.Next(), aTypesIter.Next(), aClosuresIter.Next() )
403   {
404     const TCollection_ExtendedString& aSectName = aNamesIter.Value();
405     SectionType aSectType = (SectionType)aTypesIter.Value();
406     bool aSectClosures = aClosuresIter.Value();
407
408     theSectNames.Append( aSectName );
409     theSectTypes.Append( aSectType );
410     theSectClosures.Append( aSectClosures );
411   }
412 }
413
414 void HYDROData_PolylineXY::RemoveSection( const int theSectionIndex )
415 {
416   Handle(TDataStd_ExtStringList) aNamesList;
417   Handle(TDataStd_IntegerList)   aTypesList;
418   Handle(TDataStd_BooleanList)   aClosuresList;
419   getSectionsLists( aNamesList, aTypesList, aClosuresList, false );
420   if ( aNamesList.IsNull() || theSectionIndex >= aNamesList->Extent() )
421     return;
422
423   if ( aNamesList->Extent() == 1 )
424   {
425     removeSectionsLists();
426     removePointsLists();
427   }
428   else
429   {
430     TDataStd_ListOfExtendedString anOldNamesList;
431     anOldNamesList = aNamesList->List();
432
433     TColStd_ListOfInteger anOldTypesList;
434     anOldTypesList = aTypesList->List();
435
436     TDataStd_ListOfByte anOldClosuresList;
437     anOldClosuresList = aClosuresList->List();
438
439     // Refill the existing lists
440     aNamesList->Clear();
441     aTypesList->Clear();
442     aClosuresList->Clear();
443
444     TDataStd_ListIteratorOfListOfExtendedString aNamesIter( anOldNamesList );
445     TColStd_ListIteratorOfListOfInteger aTypesIter( anOldTypesList );
446     TDataStd_ListIteratorOfListOfByte aClosuresIter( anOldClosuresList );
447     for ( int i = 0; aNamesIter.More() && aTypesIter.More() && aClosuresIter.More();
448                      aNamesIter.Next(), aTypesIter.Next(), aClosuresIter.Next(), ++i )
449     {
450       if ( i == theSectionIndex )
451         continue; // skip index to remove
452
453       aNamesList->Append( aNamesIter.Value() );
454       aTypesList->Append( aTypesIter.Value() );
455       aClosuresList->Append( (bool)aClosuresIter.Value() );
456     }
457
458     // Remove points that belongs to removed section
459     removePointsLists( theSectionIndex );
460   }
461 }
462
463 void HYDROData_PolylineXY::RemoveSections()
464 {
465   removeSectionsLists();
466   removePointsLists();
467 }
468
469 void HYDROData_PolylineXY::AddPoint( const int    theSectionIndex,
470                                      const Point& thePoint,
471                                      const int    thePointIndex )
472 {
473   Handle(TDataStd_RealList) aListX, aListY;
474   getPointsLists( theSectionIndex, aListX, aListY );
475
476   if ( thePointIndex < 0 || thePointIndex >= aListX->Extent() )
477   {
478     aListX->Append( thePoint.X() );
479     aListY->Append( thePoint.Y() );
480   }
481   else
482   {
483     TColStd_ListOfReal anOldListX;
484     anOldListX = aListX->List();
485
486     TColStd_ListOfReal anOldListY;
487     anOldListY = aListY->List();
488
489     // Refill the existing lists
490     aListX->Clear();
491     aListY->Clear();
492
493     TColStd_ListIteratorOfListOfReal anIterX( anOldListX );
494     TColStd_ListIteratorOfListOfReal anIterY( anOldListY );
495     for ( int i = 0; anIterX.More() && anIterY.More(); anIterX.Next(), anIterY.Next(), ++i )
496     {
497       double aCoordX = anIterX.Value();
498       double aCoordY = anIterY.Value();
499
500       if ( i == thePointIndex )
501       {
502         // Insert our new point
503         aListX->Append( thePoint.X() );
504         aListY->Append( thePoint.Y() );
505       }
506
507       aListX->Append( aCoordX );
508       aListY->Append( aCoordY );
509     }
510   }
511 }
512
513 void HYDROData_PolylineXY::SetPoint( const int    theSectionIndex,
514                                      const Point& thePoint,
515                                      const int    thePointIndex )
516 {
517   Handle(TDataStd_RealList) aListX, aListY;
518   getPointsLists( theSectionIndex, aListX, aListY );
519
520   if ( thePointIndex < 0 )
521   {
522     aListX->Prepend( thePoint.X() );
523     aListY->Prepend( thePoint.Y() );
524   }
525   else if ( thePointIndex >= aListX->Extent() )
526   {
527     aListX->Append( thePoint.X() );
528     aListY->Append( thePoint.Y() );
529   }
530   else
531   {
532     TColStd_ListOfReal anOldListX;
533     anOldListX = aListX->List();
534
535     TColStd_ListOfReal anOldListY;
536     anOldListY = aListY->List();
537
538     // Refill the existing lists
539     aListX->Clear();
540     aListY->Clear();
541
542     TColStd_ListIteratorOfListOfReal anIterX( anOldListX );
543     TColStd_ListIteratorOfListOfReal anIterY( anOldListY );
544     for ( int i = 0; anIterX.More() && anIterY.More(); anIterX.Next(), anIterY.Next(), ++i )
545     {
546       double aCoordX = anIterX.Value();
547       double aCoordY = anIterY.Value();
548
549       if ( i == thePointIndex )
550       {
551         // Insert our new point instead of old one
552         aCoordX = thePoint.X();
553         aCoordY = thePoint.Y();
554       }
555
556       aListX->Append( aCoordX );
557       aListY->Append( aCoordY );
558     }
559   }
560 }
561
562 void HYDROData_PolylineXY::RemovePoint( const int theSectionIndex,
563                                         const int thePointIndex )
564 {
565   Handle(TDataStd_RealList) aListX, aListY;
566   getPointsLists( theSectionIndex, aListX, aListY, false );
567   if ( aListX.IsNull() || aListY.IsNull() || aListX->IsEmpty() )
568     return;
569
570   if ( aListX->Extent() == 1 )
571   {
572     removePointsLists( theSectionIndex );
573   }
574   else
575   {
576     TColStd_ListOfReal anOldListX;
577     anOldListX = aListX->List();
578
579     TColStd_ListOfReal anOldListY;
580     anOldListY = aListY->List();
581
582     // Refill the existing lists
583     aListX->Clear();
584     aListY->Clear();
585
586     TColStd_ListIteratorOfListOfReal anIterX( anOldListX );
587     TColStd_ListIteratorOfListOfReal anIterY( anOldListY );
588     for ( int i = 0; anIterX.More() && anIterY.More(); anIterX.Next(), anIterY.Next(), ++i )
589     {
590       if ( i == thePointIndex )
591         continue; // skip index to remove
592
593       aListX->Append( anIterX.Value() );
594       aListY->Append( anIterY.Value() );
595     }
596   }
597 }
598
599 HYDROData_PolylineXY::PointsList HYDROData_PolylineXY::GetPoints( const int theSectionIndex ) const
600 {
601   PointsList aResList;
602
603   Handle(TDataStd_RealList) aListX, aListY;
604   getPointsLists( theSectionIndex, aListX, aListY, false );
605   if ( aListX.IsNull() || aListY.IsNull() || aListX->IsEmpty() )
606     return aResList;
607
608   TColStd_ListIteratorOfListOfReal anIterX( aListX->List() );
609   TColStd_ListIteratorOfListOfReal anIterY( aListY->List() );
610   for ( ; anIterX.More() && anIterY.More(); anIterX.Next(), anIterY.Next() )
611   {
612     Point aPoint( anIterX.Value(), anIterY.Value() );
613     aResList.Append( aPoint );
614   }
615
616   return aResList;
617 }
618
619 QPainterPath HYDROData_PolylineXY::GetPainterPath() const
620 {
621   QPainterPath aPath;
622
623   NCollection_Sequence<TCollection_AsciiString>           aSectNames;
624   NCollection_Sequence<HYDROData_PolylineXY::SectionType> aSectTypes;
625   NCollection_Sequence<bool>                              aSectClosures;
626   GetSections( aSectNames, aSectTypes, aSectClosures );
627   if( aSectNames.IsEmpty() )
628     return aPath;
629
630   PointsList aSectPointsList = GetPoints( 0 );
631   if( aSectPointsList.IsEmpty() )
632     return aPath;
633
634   SectionType aSectionType = aSectTypes.Value( 1 );
635   bool anIsSectionClosed = aSectClosures.Value( 1 );
636
637   if ( aSectionType == SECTION_POLYLINE )
638   {
639     aPath.moveTo( aSectPointsList.Value( 1 ).X(), aSectPointsList.Value( 1 ).Y() );
640
641     for( int i = 2, n = aSectPointsList.Size(); i <= n; ++i )
642     {
643       const Point& aSectPoint = aSectPointsList.Value( i );
644
645       aPath.lineTo( aSectPoint.X(), aSectPoint.Y() );
646     }
647
648     if( anIsSectionClosed )
649       aPath.closeSubpath();
650   }
651   else
652   {
653     QList<double> aPoints;
654     for( int i = 1, n = aSectPointsList.Size(); i <= n; ++i )
655     {
656       const Point& aSectPoint = aSectPointsList.Value( i );
657       aPoints << aSectPoint.X() << aSectPoint.Y();
658     }
659
660     HYDROData_BSplineOperation aBSpline( aPoints, 0, anIsSectionClosed );
661     aPath = aBSpline.ComputePath();
662   }
663
664   return aPath;
665 }
666
667