2 #include "HYDROData_PolylineXY.h"
4 #include "HYDROData_BSplineOperation.h"
5 #include "HYDROData_Document.h"
6 #include "HYDROData_Tool.h"
8 #include <BRep_Builder.hxx>
9 #include <BRepBuilderAPI_MakeEdge.hxx>
10 #include <BRepBuilderAPI_MakeWire.hxx>
12 #include <GeomAPI_ProjectPointOnCurve.hxx>
13 #include <GeomAdaptor_Curve.hxx>
15 #include <GCPnts_AbscissaPoint.hxx>
17 #include <ImageComposer_MetaTypes.h>
22 #include <NCollection_Map.hxx>
24 #include <TCollection_ExtendedString.hxx>
26 #include <TDataStd_ListIteratorOfListOfByte.hxx>
27 #include <TColStd_ListIteratorOfListOfInteger.hxx>
28 #include <TColStd_ListIteratorOfListOfReal.hxx>
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>
36 #include <TopoDS_Iterator.hxx>
37 #include <TopTools_ListIteratorOfListOfShape.hxx>
38 #include <TopTools_HSequenceOfShape.hxx>
39 #include <TopExp_Explorer.hxx>
40 #include <ShapeAnalysis_FreeBounds.hxx>
43 #include <QPainterPath>
46 #define PYTHON_POLYLINEXY_ID "KIND_POLYLINEXY"
48 const double LOCAL_SELECTION_TOLERANCE = 0.0001;
50 IMPLEMENT_STANDARD_HANDLE(HYDROData_PolylineXY, HYDROData_IPolyline)
51 IMPLEMENT_STANDARD_RTTIEXT(HYDROData_PolylineXY, HYDROData_IPolyline)
53 HYDROData_PolylineXY::HYDROData_PolylineXY()
54 : HYDROData_IPolyline()
58 HYDROData_PolylineXY::~HYDROData_PolylineXY()
62 QStringList HYDROData_PolylineXY::DumpToPython( MapOfTreatedObjects& theTreatedObjects ) const
66 Handle(HYDROData_Document) aDocument = HYDROData_Document::Document( myLab );
67 if ( aDocument.IsNull() )
70 QString aDocName = aDocument->GetDocPyName();
71 QString aPolylineName = GetName();
73 aResList << QString( "%1 = %2.CreateObject( %3 );" )
74 .arg( aPolylineName ).arg( aDocName ).arg( PYTHON_POLYLINEXY_ID );
75 aResList << QString( "%1.SetName( \"%1\" );" ).arg( aPolylineName );
78 NCollection_Sequence<TCollection_AsciiString> aSectNames;
79 NCollection_Sequence<HYDROData_PolylineXY::SectionType> aSectTypes;
80 NCollection_Sequence<bool> aSectClosures;
81 GetSections( aSectNames, aSectTypes, aSectClosures );
83 for ( int i = 1, n = aSectNames.Size(); i <= n; ++i )
85 const TCollection_AsciiString& aSectName = aSectNames.Value( i );
86 const SectionType& aSectType = aSectTypes.Value( i );
87 bool aSectClosure = aSectClosures.Value( i );
89 aResList << QString( "%1.AddSection( \"%2\", %3, %4 );" ).arg( aPolylineName )
90 .arg( aSectName.ToCString() ).arg( aSectType ).arg( aSectClosure );
92 HYDROData_PolylineXY::PointsList aSectPointsList = GetPoints( i );
93 for ( int k = 1, aNbPoints = aSectPointsList.Size(); k <= aNbPoints; ++k )
95 const Point& aSectPoint = aSectPointsList.Value( k );
97 aResList << QString( "%1.AddPoint( %2, QPointF( %3, %4 ) );" ).arg( aPolylineName )
98 .arg( i - 1 ).arg( aSectPoint.X() ).arg( aSectPoint.Y() );
105 QVariant HYDROData_PolylineXY::GetDataVariant()
107 QPainterPath aPath = GetPainterPath();
110 aVarData.setValue<QPainterPath>( aPath );
115 QColor HYDROData_PolylineXY::DefaultWireColor()
117 return QColor( Qt::red );
120 TopoDS_Shape HYDROData_PolylineXY::GetShape()
122 return getPolylineShape();
125 TopoDS_Wire HYDROData_PolylineXY::BuildWire( const SectionType& theType,
126 const bool& theIsClosed,
127 const NCollection_Sequence<gp_XYZ>& thePoints )
129 BRepBuilderAPI_MakeWire aMakeWire;
131 if( theType == SECTION_POLYLINE )
133 for( int i = 1, n = thePoints.Size(); i <= n; ++i )
135 const gp_XYZ& aFirstPoint = thePoints.Value( i );
141 aLastPoint = thePoints.Value( 1 );
147 aLastPoint = thePoints.Value( i + 1 );
150 gp_Pnt aPnt1( aFirstPoint.X(), aFirstPoint.Y(), aFirstPoint.Z() );
151 gp_Pnt aPnt2( aLastPoint.X(), aLastPoint.Y(), aLastPoint.Z() );
153 if ( aPnt1.IsEqual( aPnt2, LOCAL_SELECTION_TOLERANCE ) )
156 TopoDS_Edge anEdge = BRepBuilderAPI_MakeEdge( aPnt1, aPnt2 ).Edge();
157 aMakeWire.Add( anEdge );
160 else //if( theType == PolylineSection::SECTION_SPLINE )
162 HYDROData_BSplineOperation aBSpline( thePoints, theIsClosed, LOCAL_SELECTION_TOLERANCE );
164 TopoDS_Edge anEdge = BRepBuilderAPI_MakeEdge( aBSpline.Curve() ).Edge();
165 aMakeWire.Add( anEdge );
170 if ( aMakeWire.IsDone() )
176 void HYDROData_PolylineXY::BuildPainterPath( QPainterPath& thePath,
177 const SectionType& theType,
178 const bool& theIsClosed,
179 const NCollection_Sequence<gp_XYZ>& thePoints )
181 if ( thePoints.IsEmpty() )
184 if ( theType == SECTION_POLYLINE )
186 const gp_XYZ& aFirstPoint = thePoints.Value( 1 );
187 thePath.moveTo( aFirstPoint.X(), aFirstPoint.Y() );
189 for( int i = 2, n = thePoints.Size(); i <= n; ++i )
191 const gp_XYZ& aSectPoint = thePoints.Value( i );
193 thePath.lineTo( aSectPoint.X(), aSectPoint.Y() );
197 thePath.closeSubpath();
201 HYDROData_BSplineOperation aBSpline( thePoints, theIsClosed, LOCAL_SELECTION_TOLERANCE );
202 aBSpline.ComputePath( thePath );
206 void HYDROData_PolylineXY::Update()
208 HYDROData_IPolyline::Update();
210 NCollection_Sequence<TCollection_AsciiString> aSectNames;
211 NCollection_Sequence<HYDROData_PolylineXY::SectionType> aSectTypes;
212 NCollection_Sequence<bool> aSectClosures;
213 GetSections( aSectNames, aSectTypes, aSectClosures );
215 BRepBuilderAPI_MakeWire aMakeWire;
217 TopTools_ListOfShape aSectionWiresList;
219 for ( int aSectionId = 1, aNbSects = aSectNames.Size(); aSectionId <= aNbSects; aSectionId++ )
221 TCollection_AsciiString aSectName = aSectNames.Value( aSectionId );
222 SectionType aSectionType = aSectTypes.Value( aSectionId );
223 bool anIsSectionClosed = aSectClosures.Value( aSectionId );
225 PointsList aSectPointsList = GetPoints( aSectionId - 1 );
226 if ( aSectPointsList.IsEmpty() )
229 NCollection_Sequence<gp_XYZ> aPoints;
230 for( int i = 1, n = aSectPointsList.Size(); i <= n; ++i )
232 const Point& aSectPoint = aSectPointsList.Value( i );
234 gp_XYZ aPoint( aSectPoint.X(), aSectPoint.Y(), 0.0 );
235 aPoints.Append( aPoint );
238 TopoDS_Wire aSectionWire = BuildWire( aSectionType, anIsSectionClosed, aPoints );
239 if ( !aSectionWire.IsNull() ) {
240 aSectionWiresList.Append( aSectionWire );
241 aMakeWire.Add( aSectionWire );
244 // all input wires in the <aSectionWiresList>
245 Handle(TopTools_HSequenceOfShape) aSeqWires = new TopTools_HSequenceOfShape;
246 Handle(TopTools_HSequenceOfShape) aSeqEdges = new TopTools_HSequenceOfShape;
247 TopTools_ListIteratorOfListOfShape it(aSectionWiresList);
248 for(;it.More();it.Next())
250 TopExp_Explorer it2(it.Value(), TopAbs_EDGE);
251 for(;it2.More();it2.Next())
252 aSeqEdges->Append(it2.Current());
255 TopoDS_Compound aCmp;
256 TopoDS_Shape aResult;
257 aBB.MakeCompound(aCmp);
258 if(aSeqEdges->Length() >1)
260 ShapeAnalysis_FreeBounds::ConnectEdgesToWires(aSeqEdges,1E-5,Standard_False,aSeqWires);
262 if( aSeqWires->Length()==1 )
263 aResult = aSeqWires->Value( 1 );
266 for (Standard_Integer i = 1; i <= aSeqWires->Length();i++)
268 const TopoDS_Shape& aS1 = aSeqWires->Value(i);
274 else if (aSeqEdges->Length() == 1)
276 BRepBuilderAPI_MakeWire mkWire (TopoDS::Edge(aSeqEdges->Value(1)));
278 aResult = mkWire.Wire();
281 setPolylineShape( aResult );
285 * Returns true if polyline is closed
287 bool HYDROData_PolylineXY::IsClosed() const
289 NCollection_Sequence<TCollection_AsciiString> aSectNames;
290 NCollection_Sequence<HYDROData_PolylineXY::SectionType> aSectTypes;
291 NCollection_Sequence<bool> aSectClosures;
292 GetSections( aSectNames, aSectTypes, aSectClosures );
293 if( aSectNames.IsEmpty() )
296 bool anIsClosed = true;
297 for( int i = 1, n = aSectClosures.Size(); i <= n && anIsClosed; ++i )
298 anIsClosed = anIsClosed && aSectClosures.Value( i );
303 double HYDROData_PolylineXY::GetDistance( const int theSectionIndex,
304 const int thePointIndex ) const
306 double aResDistance = -1;
307 if ( theSectionIndex < 0 || theSectionIndex >= NbSections() )
310 if ( thePointIndex == 0 )
313 SectionType aSectionType = GetSectionType( theSectionIndex );
314 bool anIsSectionClosed = IsClosedSection( theSectionIndex );
315 PointsList aSectPointsList = GetPoints( theSectionIndex );
316 if ( thePointIndex < 0 || thePointIndex >= aSectPointsList.Size() )
319 if ( aSectionType == SECTION_POLYLINE )
323 Point aPrevPoint = aSectPointsList.Value( 1 );
324 for ( int i = 2, aNbPoints = aSectPointsList.Size(); i <= aNbPoints; ++i )
326 const Point& aSectPoint = aSectPointsList.Value( i );
327 aResDistance += gp_Pnt2d( aPrevPoint ).Distance( aSectPoint );
328 aPrevPoint = aSectPoint;
330 if ( thePointIndex == i - 1 )
338 int aSectNbPoints = aSectPointsList.Size();
339 NCollection_Sequence<gp_XYZ> aPoints;
340 for( int i = 1 ; i <= aSectNbPoints; ++i )
342 const Point& aSectPoint = aSectPointsList.Value( i );
344 gp_XYZ aPoint( aSectPoint.X(), aSectPoint.Y(), 0.0 );
345 aPoints.Append( aPoint );
347 if ( thePointIndex == i - 1 )
348 aPointToTest = aPoint;
351 HYDROData_BSplineOperation aBSpline( aPoints, anIsSectionClosed, LOCAL_SELECTION_TOLERANCE );
353 Quantity_Parameter aFirstParam = aBSpline.Curve()->FirstParameter();
354 Quantity_Parameter aSecondParam = aBSpline.Curve()->LastParameter();
356 if ( thePointIndex != aSectNbPoints - 1 )
358 GeomAPI_ProjectPointOnCurve aProject( aPointToTest, aBSpline.Curve() );
359 aSecondParam = aProject.LowerDistanceParameter();
362 GeomAdaptor_Curve anAdap( aBSpline.Curve() );
364 aResDistance = GCPnts_AbscissaPoint::Length( anAdap, aFirstParam, aSecondParam );
370 int HYDROData_PolylineXY::NbSections() const
372 Handle(TDataStd_ExtStringList) aNamesList;
373 Handle(TDataStd_IntegerList) aTypesList;
374 Handle(TDataStd_BooleanList) aClosuresList;
375 getSectionsLists( aNamesList, aTypesList, aClosuresList, false );
377 return !aClosuresList.IsNull() ? aClosuresList->Extent() : 0;
380 TCollection_ExtendedString getUniqueSectionName( const Handle(TDataStd_ExtStringList)& theNamesList )
382 NCollection_Map<TCollection_ExtendedString> aNamesMap;
384 TDataStd_ListIteratorOfListOfExtendedString aNamesIter( theNamesList->List() );
385 for ( ; aNamesIter.More(); aNamesIter.Next() )
386 aNamesMap.Add( aNamesIter.Value() );
388 TCollection_ExtendedString aResName;
393 aResName = "Section_" + aPrefIdx;
396 while ( aNamesMap.Contains( aResName ) );
401 void HYDROData_PolylineXY::AddSection( const TCollection_AsciiString& theSectName,
402 const SectionType theSectionType,
403 const bool theIsClosed )
405 Handle(TDataStd_ExtStringList) aNamesList;
406 Handle(TDataStd_IntegerList) aTypesList;
407 Handle(TDataStd_BooleanList) aClosuresList;
408 getSectionsLists( aNamesList, aTypesList, aClosuresList );
410 TCollection_ExtendedString aSectName( theSectName );
411 if ( aSectName.Length() <= 0 )
412 aSectName = getUniqueSectionName( aNamesList );
414 aNamesList->Append( aSectName );
415 aTypesList->Append( theSectionType );
416 aClosuresList->Append( theIsClosed );
421 TCollection_AsciiString HYDROData_PolylineXY::GetSectionName( const int theSectionIndex ) const
423 TCollection_AsciiString aResName;
425 Handle(TDataStd_ExtStringList) aNamesList;
426 Handle(TDataStd_IntegerList) aTypesList;
427 Handle(TDataStd_BooleanList) aClosuresList;
428 getSectionsLists( aNamesList, aTypesList, aClosuresList, false );
429 if ( aNamesList.IsNull() || theSectionIndex >= aNamesList->Extent() )
432 TDataStd_ListIteratorOfListOfExtendedString aNamesIter( aNamesList->List() );
433 for ( int i = 0; aNamesIter.More() && i != theSectionIndex; aNamesIter.Next(), ++i );
435 if ( aNamesIter.More() )
436 aResName = aNamesIter.Value();
441 void HYDROData_PolylineXY::SetSectionName( const int theSectionIndex,
442 const TCollection_AsciiString& theSectionName )
444 Handle(TDataStd_ExtStringList) aNamesList;
445 Handle(TDataStd_IntegerList) aTypesList;
446 Handle(TDataStd_BooleanList) aClosuresList;
447 getSectionsLists( aNamesList, aTypesList, aClosuresList, false );
448 if ( aNamesList.IsNull() || theSectionIndex >= aNamesList->Extent() )
451 TDataStd_ListOfExtendedString anOldNamesList;
452 anOldNamesList = aNamesList->List();
454 // Refill the existing list
457 TCollection_ExtendedString aNewSectName = theSectionName;
459 TDataStd_ListIteratorOfListOfExtendedString aNamesIter( anOldNamesList );
460 for ( int i = 0; aNamesIter.More(); aNamesIter.Next(), ++i )
461 aNamesList->Append( i == theSectionIndex ? aNewSectName : aNamesIter.Value() );
466 HYDROData_PolylineXY::SectionType HYDROData_PolylineXY::GetSectionType( const int theSectionIndex ) const
468 Handle(TDataStd_ExtStringList) aNamesList;
469 Handle(TDataStd_IntegerList) aTypesList;
470 Handle(TDataStd_BooleanList) aClosuresList;
471 getSectionsLists( aNamesList, aTypesList, aClosuresList, false );
472 if ( aTypesList.IsNull() || theSectionIndex >= aTypesList->Extent() )
473 return SECTION_POLYLINE;
475 TColStd_ListIteratorOfListOfInteger aTypesIter( aTypesList->List() );
476 for ( int i = 0; aTypesIter.More() && i != theSectionIndex; aTypesIter.Next(), ++i );
478 return aTypesIter.More() ? (SectionType)aTypesIter.Value() : SECTION_POLYLINE;
481 void HYDROData_PolylineXY::SetSectionType( const int theSectionIndex,
482 const SectionType theSectionType )
484 Handle(TDataStd_ExtStringList) aNamesList;
485 Handle(TDataStd_IntegerList) aTypesList;
486 Handle(TDataStd_BooleanList) aClosuresList;
487 getSectionsLists( aNamesList, aTypesList, aClosuresList, false );
488 if ( aTypesList.IsNull() || theSectionIndex >= aTypesList->Extent() )
491 TColStd_ListOfInteger anOldTypesList;
492 anOldTypesList = aTypesList->List();
494 // Refill the existing list
497 TColStd_ListIteratorOfListOfInteger aTypesIter( anOldTypesList );
498 for ( int i = 0; aTypesIter.More(); aTypesIter.Next(), ++i )
499 aTypesList->Append( i == theSectionIndex ? theSectionType : aTypesIter.Value() );
504 bool HYDROData_PolylineXY::IsClosedSection( const int theSectionIndex ) const
506 Handle(TDataStd_ExtStringList) aNamesList;
507 Handle(TDataStd_IntegerList) aTypesList;
508 Handle(TDataStd_BooleanList) aClosuresList;
509 getSectionsLists( aNamesList, aTypesList, aClosuresList, false );
510 if ( aClosuresList.IsNull() || theSectionIndex >= aClosuresList->Extent() )
513 TDataStd_ListIteratorOfListOfByte aClosuresIter( aClosuresList->List() );
514 for ( int i = 0; aClosuresIter.More() && i != theSectionIndex; aClosuresIter.Next(), ++i );
516 return aClosuresIter.More() ? (bool)aClosuresIter.Value() : false;
519 void HYDROData_PolylineXY::SetSectionClosed( const int theSectionIndex,
520 const bool theIsClosed )
522 Handle(TDataStd_ExtStringList) aNamesList;
523 Handle(TDataStd_IntegerList) aTypesList;
524 Handle(TDataStd_BooleanList) aClosuresList;
525 getSectionsLists( aNamesList, aTypesList, aClosuresList, false );
526 if ( aClosuresList.IsNull() || theSectionIndex >= aClosuresList->Extent() )
529 TDataStd_ListOfByte anOldClosuresList;
530 anOldClosuresList = aClosuresList->List();
532 // Refill the existing list
533 aClosuresList->Clear();
535 TDataStd_ListIteratorOfListOfByte aClosuresIter( anOldClosuresList );
536 for ( int i = 0; aClosuresIter.More(); aClosuresIter.Next(), ++i )
537 aClosuresList->Append( i == theSectionIndex ? theIsClosed : (bool)aClosuresIter.Value() );
542 void HYDROData_PolylineXY::GetSections( NCollection_Sequence<TCollection_AsciiString>& theSectNames,
543 NCollection_Sequence<SectionType>& theSectTypes,
544 NCollection_Sequence<bool>& theSectClosures ) const
546 theSectNames.Clear();
547 theSectTypes.Clear();
548 theSectClosures.Clear();
550 Handle(TDataStd_ExtStringList) aNamesList;
551 Handle(TDataStd_IntegerList) aTypesList;
552 Handle(TDataStd_BooleanList) aClosuresList;
553 getSectionsLists( aNamesList, aTypesList, aClosuresList, false );
554 if ( aNamesList.IsNull() || aTypesList.IsNull() || aClosuresList.IsNull() )
557 TDataStd_ListIteratorOfListOfExtendedString aNamesIter( aNamesList->List() );
558 TColStd_ListIteratorOfListOfInteger aTypesIter( aTypesList->List() );
559 TDataStd_ListIteratorOfListOfByte aClosuresIter( aClosuresList->List() );
560 for ( ; aNamesIter.More() && aTypesIter.More() && aClosuresIter.More();
561 aNamesIter.Next(), aTypesIter.Next(), aClosuresIter.Next() )
563 const TCollection_ExtendedString& aSectName = aNamesIter.Value();
564 SectionType aSectType = (SectionType)aTypesIter.Value();
565 bool aSectClosures = aClosuresIter.Value();
567 theSectNames.Append( aSectName );
568 theSectTypes.Append( aSectType );
569 theSectClosures.Append( aSectClosures );
573 void HYDROData_PolylineXY::RemoveSection( const int theSectionIndex )
575 Handle(TDataStd_ExtStringList) aNamesList;
576 Handle(TDataStd_IntegerList) aTypesList;
577 Handle(TDataStd_BooleanList) aClosuresList;
578 getSectionsLists( aNamesList, aTypesList, aClosuresList, false );
579 if ( aNamesList.IsNull() || theSectionIndex >= aNamesList->Extent() )
582 if ( aNamesList->Extent() == 1 )
584 removeSectionsLists();
589 TDataStd_ListOfExtendedString anOldNamesList;
590 anOldNamesList = aNamesList->List();
592 TColStd_ListOfInteger anOldTypesList;
593 anOldTypesList = aTypesList->List();
595 TDataStd_ListOfByte anOldClosuresList;
596 anOldClosuresList = aClosuresList->List();
598 // Refill the existing lists
601 aClosuresList->Clear();
603 TDataStd_ListIteratorOfListOfExtendedString aNamesIter( anOldNamesList );
604 TColStd_ListIteratorOfListOfInteger aTypesIter( anOldTypesList );
605 TDataStd_ListIteratorOfListOfByte aClosuresIter( anOldClosuresList );
606 for ( int i = 0; aNamesIter.More() && aTypesIter.More() && aClosuresIter.More();
607 aNamesIter.Next(), aTypesIter.Next(), aClosuresIter.Next(), ++i )
609 if ( i == theSectionIndex )
610 continue; // skip index to remove
612 aNamesList->Append( aNamesIter.Value() );
613 aTypesList->Append( aTypesIter.Value() );
614 aClosuresList->Append( (bool)aClosuresIter.Value() );
617 // Remove points that belongs to removed section
618 removePointsLists( theSectionIndex );
624 void HYDROData_PolylineXY::RemoveSections()
626 removeSectionsLists();
631 void HYDROData_PolylineXY::AddPoint( const int theSectionIndex,
632 const Point& thePoint,
633 const int thePointIndex )
635 Handle(TDataStd_RealList) aListX, aListY;
636 getPointsLists( theSectionIndex, aListX, aListY );
638 if ( thePointIndex < 0 || thePointIndex >= aListX->Extent() )
640 aListX->Append( thePoint.X() );
641 aListY->Append( thePoint.Y() );
645 TColStd_ListOfReal anOldListX;
646 anOldListX = aListX->List();
648 TColStd_ListOfReal anOldListY;
649 anOldListY = aListY->List();
651 // Refill the existing lists
655 TColStd_ListIteratorOfListOfReal anIterX( anOldListX );
656 TColStd_ListIteratorOfListOfReal anIterY( anOldListY );
657 for ( int i = 0; anIterX.More() && anIterY.More(); anIterX.Next(), anIterY.Next(), ++i )
659 double aCoordX = anIterX.Value();
660 double aCoordY = anIterY.Value();
662 if ( i == thePointIndex )
664 // Insert our new point
665 aListX->Append( thePoint.X() );
666 aListY->Append( thePoint.Y() );
669 aListX->Append( aCoordX );
670 aListY->Append( aCoordY );
677 void HYDROData_PolylineXY::SetPoint( const int theSectionIndex,
678 const Point& thePoint,
679 const int thePointIndex )
681 Handle(TDataStd_RealList) aListX, aListY;
682 getPointsLists( theSectionIndex, aListX, aListY );
684 if ( thePointIndex < 0 )
686 aListX->Prepend( thePoint.X() );
687 aListY->Prepend( thePoint.Y() );
689 else if ( thePointIndex >= aListX->Extent() )
691 aListX->Append( thePoint.X() );
692 aListY->Append( thePoint.Y() );
696 TColStd_ListOfReal anOldListX;
697 anOldListX = aListX->List();
699 TColStd_ListOfReal anOldListY;
700 anOldListY = aListY->List();
702 // Refill the existing lists
706 TColStd_ListIteratorOfListOfReal anIterX( anOldListX );
707 TColStd_ListIteratorOfListOfReal anIterY( anOldListY );
708 for ( int i = 0; anIterX.More() && anIterY.More(); anIterX.Next(), anIterY.Next(), ++i )
710 double aCoordX = anIterX.Value();
711 double aCoordY = anIterY.Value();
713 if ( i == thePointIndex )
715 // Insert our new point instead of old one
716 aCoordX = thePoint.X();
717 aCoordY = thePoint.Y();
720 aListX->Append( aCoordX );
721 aListY->Append( aCoordY );
728 void HYDROData_PolylineXY::RemovePoint( const int theSectionIndex,
729 const int thePointIndex )
731 Handle(TDataStd_RealList) aListX, aListY;
732 getPointsLists( theSectionIndex, aListX, aListY, false );
733 if ( aListX.IsNull() || aListY.IsNull() || aListX->IsEmpty() )
736 if ( aListX->Extent() == 1 )
738 removePointsLists( theSectionIndex );
742 TColStd_ListOfReal anOldListX;
743 anOldListX = aListX->List();
745 TColStd_ListOfReal anOldListY;
746 anOldListY = aListY->List();
748 // Refill the existing lists
752 TColStd_ListIteratorOfListOfReal anIterX( anOldListX );
753 TColStd_ListIteratorOfListOfReal anIterY( anOldListY );
754 for ( int i = 0; anIterX.More() && anIterY.More(); anIterX.Next(), anIterY.Next(), ++i )
756 if ( i == thePointIndex )
757 continue; // skip index to remove
759 aListX->Append( anIterX.Value() );
760 aListY->Append( anIterY.Value() );
767 HYDROData_PolylineXY::PointsList HYDROData_PolylineXY::GetPoints( const int theSectionIndex ) const
771 Handle(TDataStd_RealList) aListX, aListY;
772 getPointsLists( theSectionIndex, aListX, aListY, false );
773 if ( aListX.IsNull() || aListY.IsNull() || aListX->IsEmpty() )
776 TColStd_ListIteratorOfListOfReal anIterX( aListX->List() );
777 TColStd_ListIteratorOfListOfReal anIterY( aListY->List() );
778 for ( ; anIterX.More() && anIterY.More(); anIterX.Next(), anIterY.Next() )
780 Point aPoint( anIterX.Value(), anIterY.Value() );
781 aResList.Append( aPoint );
787 QPainterPath HYDROData_PolylineXY::GetPainterPath() const
791 NCollection_Sequence<TCollection_AsciiString> aSectNames;
792 NCollection_Sequence<HYDROData_PolylineXY::SectionType> aSectTypes;
793 NCollection_Sequence<bool> aSectClosures;
794 GetSections( aSectNames, aSectTypes, aSectClosures );
796 for ( int aSectionId = 1, aNbSects = aSectNames.Size(); aSectionId <= aNbSects; aSectionId++ )
798 TCollection_AsciiString aSectName = aSectNames.Value( aSectionId );
799 SectionType aSectionType = aSectTypes.Value( aSectionId );
800 bool anIsSectionClosed = aSectClosures.Value( aSectionId );
802 PointsList aSectPointsList = GetPoints( aSectionId - 1 );
803 if ( aSectPointsList.IsEmpty() )
806 NCollection_Sequence<gp_XYZ> aPoints;
807 for( int i = 1, n = aSectPointsList.Size(); i <= n; ++i )
809 const Point& aSectPoint = aSectPointsList.Value( i );
811 gp_XYZ aPoint( aSectPoint.X(), aSectPoint.Y(), 0.0 );
812 aPoints.Append( aPoint );
815 BuildPainterPath( aPath, aSectionType, anIsSectionClosed, aPoints );