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