2 #include "HYDROData_PolylineXY.h"
4 #include "HYDROData_BSplineOperation.h"
5 #include "HYDROData_Document.h"
6 #include "HYDROData_ShapesTool.h"
7 #include "HYDROData_Tool.h"
9 #include <BRep_Builder.hxx>
10 #include <BRepBuilderAPI_MakeEdge.hxx>
11 #include <BRepBuilderAPI_MakeWire.hxx>
12 #include <BRepBuilderAPI_MakePolygon.hxx>
13 #include <BRepBuilderAPI_MakeFace.hxx>
14 #include <BRepOffsetAPI_NormalProjection.hxx>
16 #include <GeomAPI_ProjectPointOnCurve.hxx>
17 #include <GeomAdaptor_Curve.hxx>
18 #include <Geom_Line.hxx>
19 #include <Geom_BSplineCurve.hxx>
21 #include <GCPnts_AbscissaPoint.hxx>
23 #include <ImageComposer_MetaTypes.h>
29 #include <NCollection_Map.hxx>
31 #include <TCollection_ExtendedString.hxx>
33 #include <TDataStd_ListIteratorOfListOfByte.hxx>
34 #include <TColStd_ListIteratorOfListOfInteger.hxx>
35 #include <TColStd_ListIteratorOfListOfReal.hxx>
37 #include <TColStd_Array1OfReal.hxx>
39 #include <TDataStd_BooleanList.hxx>
40 #include <TDataStd_ExtStringList.hxx>
41 #include <TDataStd_IntegerList.hxx>
42 #include <TDataStd_ListIteratorOfListOfExtendedString.hxx>
43 #include <TDataStd_RealList.hxx>
44 #include <TDataStd_UAttribute.hxx>
46 #include <TopoDS_Iterator.hxx>
47 #include <TopTools_ListIteratorOfListOfShape.hxx>
48 #include <TopTools_HSequenceOfShape.hxx>
49 #include <TopExp_Explorer.hxx>
50 #include <ShapeAnalysis_FreeBounds.hxx>
54 #include <QPainterPath>
57 static const Standard_GUID GUID_IS_UNEDITABLE("e5799736-9030-4051-91a4-2e58321fa153");
59 #define PYTHON_POLYLINEXY_ID "KIND_POLYLINEXY"
61 const double LOCAL_SELECTION_TOLERANCE = 0.0001;
63 TCollection_AsciiString getUniqueSectionName( const NCollection_Sequence<TCollection_AsciiString>& theNamesSeq )
65 NCollection_Map<TCollection_AsciiString> aNamesMap;
67 for ( int i = 1, n = theNamesSeq.Size(); i <= n; ++i )
69 const TCollection_AsciiString& aSectName = theNamesSeq.Value( i );
70 aNamesMap.Add( aSectName );
73 TCollection_AsciiString aResName;
78 aResName = TCollection_AsciiString( "Section_" ) + aPrefIdx;
81 while ( aNamesMap.Contains( aResName ) );
86 TCollection_AsciiString getUniqueSectionName( const Handle(TDataStd_ExtStringList)& theNamesList )
88 NCollection_Sequence<TCollection_AsciiString> aNamesSeq;
90 TDataStd_ListIteratorOfListOfExtendedString aNamesIter( theNamesList->List() );
91 for ( ; aNamesIter.More(); aNamesIter.Next() )
92 aNamesSeq.Append( aNamesIter.Value() );
94 return getUniqueSectionName( aNamesSeq );
97 IMPLEMENT_STANDARD_HANDLE(HYDROData_PolylineXY, HYDROData_IPolyline)
98 IMPLEMENT_STANDARD_RTTIEXT(HYDROData_PolylineXY, HYDROData_IPolyline)
100 HYDROData_PolylineXY::HYDROData_PolylineXY()
101 : HYDROData_IPolyline()
105 HYDROData_PolylineXY::~HYDROData_PolylineXY()
109 QStringList HYDROData_PolylineXY::DumpToPython( MapOfTreatedObjects& theTreatedObjects ) const
111 QStringList aResList;
113 Handle(HYDROData_Document) aDocument = HYDROData_Document::Document( myLab );
114 if ( aDocument.IsNull() )
117 QString aDocName = aDocument->GetDocPyName();
118 QString aPolylineName = GetName();
120 aResList << QString( "%1 = %2.CreateObject( %3 );" )
121 .arg( aPolylineName ).arg( aDocName ).arg( PYTHON_POLYLINEXY_ID );
122 aResList << QString( "%1.SetName( \"%1\" );" ).arg( aPolylineName );
125 NCollection_Sequence<TCollection_AsciiString> aSectNames;
126 NCollection_Sequence<HYDROData_PolylineXY::SectionType> aSectTypes;
127 NCollection_Sequence<bool> aSectClosures;
128 GetSections( aSectNames, aSectTypes, aSectClosures );
130 for ( int i = 1, n = aSectNames.Size(); i <= n; ++i )
132 const TCollection_AsciiString& aSectName = aSectNames.Value( i );
133 const SectionType& aSectType = aSectTypes.Value( i );
134 bool aSectClosure = aSectClosures.Value( i );
136 aResList << QString( "%1.AddSection( \"%2\", %3, %4 );" ).arg( aPolylineName )
137 .arg( aSectName.ToCString() ).arg( aSectType ).arg( aSectClosure );
139 HYDROData_PolylineXY::PointsList aSectPointsList = GetPoints( i );
140 for ( int k = 1, aNbPoints = aSectPointsList.Size(); k <= aNbPoints; ++k )
142 const Point& aSectPoint = aSectPointsList.Value( k );
144 aResList << QString( "%1.AddPoint( %2, QPointF( %3, %4 ) );" ).arg( aPolylineName )
145 .arg( i - 1 ).arg( aSectPoint.X() ).arg( aSectPoint.Y() );
152 QVariant HYDROData_PolylineXY::GetDataVariant()
154 QPainterPath aPath = GetPainterPath();
157 aVarData.setValue<QPainterPath>( aPath );
162 QColor HYDROData_PolylineXY::DefaultWireColor()
164 return QColor( Qt::red );
167 TopoDS_Shape HYDROData_PolylineXY::GetShape() const
169 return getPolylineShape();
172 bool convertEdgeToSection( const TopoDS_Edge& theEdge,
173 NCollection_Sequence<TCollection_AsciiString>& theSectNames,
174 NCollection_Sequence<HYDROData_PolylineXY::SectionType>& theSectTypes,
175 NCollection_Sequence<bool>& theSectClosures,
176 NCollection_Sequence<HYDROData_PolylineXY::PointsList>& theSectPoints,
177 const bool theIsCanBeClosed )
179 Standard_Real aFirst = 0.0, aLast = 0.0;
180 Handle(Geom_Curve) anEdgeGeomCurve = BRep_Tool::Curve( theEdge, aFirst, aLast );
181 if ( anEdgeGeomCurve.IsNull() )
184 TCollection_AsciiString aSectName = getUniqueSectionName( theSectNames );
185 bool anIsEdgeClosed = anEdgeGeomCurve->IsClosed();
187 HYDROData_PolylineXY::SectionType aSectionType = HYDROData_PolylineXY::SECTION_POLYLINE;
188 HYDROData_PolylineXY::PointsList aPointsList;
190 if ( anEdgeGeomCurve->IsKind( STANDARD_TYPE(Geom_Line) ) )
192 Handle(Geom_Line) aGeomLine = Handle(Geom_Line)::DownCast( anEdgeGeomCurve );
194 gp_Pnt aFirstPoint, aLastPoint;
195 aGeomLine->D0( aFirst, aFirstPoint );
196 aGeomLine->D0( aLast, aLastPoint );
198 HYDROData_PolylineXY::Point aSectFirstPoint( aFirstPoint.X(), aFirstPoint.Y() );
199 aPointsList.Append( aSectFirstPoint );
201 HYDROData_PolylineXY::Point aSectLastPoint( aLastPoint.X(), aLastPoint.Y() );
202 aPointsList.Append( aSectLastPoint );
204 else if ( anEdgeGeomCurve->IsKind( STANDARD_TYPE(Geom_BSplineCurve) ) )
206 aSectionType = HYDROData_PolylineXY::SECTION_SPLINE;
208 Handle(Geom_BSplineCurve) aGeomSpline =
209 Handle(Geom_BSplineCurve)::DownCast( anEdgeGeomCurve );
211 int aNbKnots = aGeomSpline->NbKnots();
213 TColStd_Array1OfReal aSplineKnots( 1, aNbKnots );
214 aGeomSpline->Knots( aSplineKnots );
216 // Decrease the number of imported knots because of last one
217 // knot is the closing point which are the start point
218 if ( anIsEdgeClosed ) aNbKnots--;
220 for ( int i = 1; i <= aNbKnots; ++i )
222 const Standard_Real& aKnot = aSplineKnots.Value( i );
225 aGeomSpline->D0( aKnot, aPoint );
227 HYDROData_PolylineXY::Point aSectPoint( aPoint.X(), aPoint.Y() );
228 aPointsList.Append( aSectPoint );
233 // Other curve types are not supported
237 if ( aPointsList.IsEmpty() )
240 theSectNames.Append( aSectName );
241 theSectTypes.Append( aSectionType );
242 theSectClosures.Append( anIsEdgeClosed );
243 theSectPoints.Append( aPointsList );
248 bool HYDROData_PolylineXY::ImportShape( const TopoDS_Shape& theShape )
250 if ( theShape.IsNull() )
255 bool anIsCanBeImported = false;
257 NCollection_Sequence<TCollection_AsciiString> aSectNames;
258 NCollection_Sequence<SectionType> aSectTypes;
259 NCollection_Sequence<bool> aSectClosures;
260 NCollection_Sequence<PointsList> aSectPoints;
262 if ( theShape.ShapeType() == TopAbs_EDGE )
264 TopoDS_Edge anEdge = TopoDS::Edge( theShape );
265 anIsCanBeImported = convertEdgeToSection( anEdge, aSectNames, aSectTypes, aSectClosures, aSectPoints, true );
267 else if ( theShape.ShapeType() == TopAbs_WIRE )
269 TopTools_SequenceOfShape anEdges;
270 HYDROData_ShapesTool::ExploreShapeToShapes( theShape, TopAbs_EDGE, anEdges );
272 anIsCanBeImported = !anEdges.IsEmpty();
273 for ( int i = 1, n = anEdges.Length(); i <= n && anIsCanBeImported; ++i )
275 TopoDS_Edge aWireEdge = TopoDS::Edge( anEdges.Value( i ) );
276 anIsCanBeImported = convertEdgeToSection( aWireEdge, aSectNames, aSectTypes, aSectClosures, aSectPoints, false );
280 if ( anIsCanBeImported )
282 for ( int i = 1, n = aSectNames.Length(); i <= n; ++i )
284 const TCollection_AsciiString& aSectName = aSectNames.Value( i );
285 const SectionType& aSectType = aSectTypes.Value( i );
286 bool anIsSectionClosed = aSectClosures.Value( i );
287 const PointsList& aSectPointsList = aSectPoints( i );
289 AddSection( aSectName, aSectType, anIsSectionClosed );
290 SetPoints( i - 1, aSectPointsList );
295 TopoDS_Shape aShape = theShape;
297 if ( theShape.ShapeType() == TopAbs_EDGE )
299 // We make the wire from incoming edge because of other algorithms
300 // are waiting at least the wire from polyline
301 TopoDS_Edge anEdge = TopoDS::Edge( theShape );
302 BRepBuilderAPI_MakeWire aMakeWire( anEdge );
304 if ( aMakeWire.IsDone() )
305 aShape = aMakeWire.Wire();
308 gp_Pln aPlane( gp_Pnt( 0, 0, 0 ), gp_Dir( 0, 0, 1 ) );
309 BRepBuilderAPI_MakeFace aMakeFace( aPlane );
311 BRepOffsetAPI_NormalProjection aProj( aMakeFace.Face() );
314 TopoDS_Shape aResult;
316 aResult = aProj.Shape();
318 setPolylineShape( aResult );
321 setEditable( anIsCanBeImported );
326 TopoDS_Wire HYDROData_PolylineXY::BuildWire( const SectionType& theType,
327 const bool& theIsClosed,
328 const NCollection_Sequence<gp_XYZ>& thePoints )
331 if( theType == SECTION_POLYLINE )
333 BRepBuilderAPI_MakePolygon aMakeWire;
334 for ( int i = 1, n = thePoints.Length(); i <= n ; ++i )
336 gp_XYZ aPoint = thePoints.Value( i );
337 gp_Pnt aPnt( aPoint.X(), aPoint.Y(), aPoint.Z() );
338 aMakeWire.Add( aPnt );
343 if ( aMakeWire.IsDone() )
344 aWire = aMakeWire.Wire();
346 else //if( theType == PolylineSection::SECTION_SPLINE )
348 BRepBuilderAPI_MakeWire aMakeWire;
350 if ( thePoints.Size() > 1 )
352 HYDROData_BSplineOperation aBSpline( thePoints, theIsClosed, LOCAL_SELECTION_TOLERANCE );
354 TopoDS_Edge anEdge = BRepBuilderAPI_MakeEdge( aBSpline.Curve() ).Edge();
355 aMakeWire.Add( anEdge );
358 if ( aMakeWire.IsDone() )
365 void HYDROData_PolylineXY::BuildPainterPath( QPainterPath& thePath,
366 const SectionType& theType,
367 const bool& theIsClosed,
368 const NCollection_Sequence<gp_XYZ>& thePoints )
370 if ( thePoints.IsEmpty() )
373 if ( theType == SECTION_POLYLINE )
375 const gp_XYZ& aFirstPoint = thePoints.Value( 1 );
376 thePath.moveTo( aFirstPoint.X(), aFirstPoint.Y() );
378 for( int i = 2, n = thePoints.Size(); i <= n; ++i )
380 const gp_XYZ& aSectPoint = thePoints.Value( i );
382 thePath.lineTo( aSectPoint.X(), aSectPoint.Y() );
386 thePath.closeSubpath();
390 HYDROData_BSplineOperation aBSpline( thePoints, theIsClosed, LOCAL_SELECTION_TOLERANCE );
391 aBSpline.ComputePath( thePath );
395 void HYDROData_PolylineXY::Update()
399 // If polyline is not editable we no need to update it wire
400 SetToUpdate( false );
404 HYDROData_IPolyline::Update();
406 NCollection_Sequence<TCollection_AsciiString> aSectNames;
407 NCollection_Sequence<HYDROData_PolylineXY::SectionType> aSectTypes;
408 NCollection_Sequence<bool> aSectClosures;
409 GetSections( aSectNames, aSectTypes, aSectClosures );
411 BRepBuilderAPI_MakeWire aMakeWire;
413 TopTools_ListOfShape aSectionWiresList;
415 for ( int aSectionId = 1, aNbSects = aSectNames.Size(); aSectionId <= aNbSects; aSectionId++ )
417 TCollection_AsciiString aSectName = aSectNames.Value( aSectionId );
418 SectionType aSectionType = aSectTypes.Value( aSectionId );
419 bool anIsSectionClosed = aSectClosures.Value( aSectionId );
421 PointsList aSectPointsList = GetPoints( aSectionId - 1 );
422 if ( aSectPointsList.IsEmpty() )
425 NCollection_Sequence<gp_XYZ> aPoints;
426 for( int i = 1, n = aSectPointsList.Size(); i <= n; ++i )
428 const Point& aSectPoint = aSectPointsList.Value( i );
430 gp_XYZ aPoint( aSectPoint.X(), aSectPoint.Y(), 0.0 );
431 aPoints.Append( aPoint );
434 TopoDS_Wire aSectionWire = BuildWire( aSectionType, anIsSectionClosed, aPoints );
435 if ( !aSectionWire.IsNull() ) {
436 aSectionWiresList.Append( aSectionWire );
437 aMakeWire.Add( aSectionWire );
440 // all input wires in the <aSectionWiresList>
441 Handle(TopTools_HSequenceOfShape) aSeqWires = new TopTools_HSequenceOfShape;
442 Handle(TopTools_HSequenceOfShape) aSeqEdges = new TopTools_HSequenceOfShape;
443 TopTools_ListIteratorOfListOfShape it(aSectionWiresList);
444 for(;it.More();it.Next())
446 TopExp_Explorer it2(it.Value(), TopAbs_EDGE);
447 for(;it2.More();it2.Next())
448 aSeqEdges->Append(it2.Current());
452 TopoDS_Compound aCmp;
453 TopoDS_Shape aResult;
454 aBB.MakeCompound(aCmp);
455 if(aSeqEdges->Length() >1)
457 ShapeAnalysis_FreeBounds::ConnectEdgesToWires(aSeqEdges,1E-5,Standard_False,aSeqWires);
459 if( aSeqWires->Length()==1 )
460 aResult = aSeqWires->Value( 1 );
463 for (Standard_Integer i = 1; i <= aSeqWires->Length();i++)
465 const TopoDS_Shape& aS1 = aSeqWires->Value(i);
471 else if (aSeqEdges->Length() == 1)
473 BRepBuilderAPI_MakeWire mkWire (TopoDS::Edge(aSeqEdges->Value(1)));
475 aResult = mkWire.Wire();
478 setPolylineShape( aResult );
481 bool HYDROData_PolylineXY::IsEditable() const
483 return !myLab.IsAttribute( GUID_IS_UNEDITABLE );
486 void HYDROData_PolylineXY::setEditable( const bool theIsEditable )
488 if ( !theIsEditable )
489 TDataStd_UAttribute::Set( myLab, GUID_IS_UNEDITABLE );
491 myLab.ForgetAttribute( GUID_IS_UNEDITABLE );
495 * Returns true if polyline is closed
497 bool HYDROData_PolylineXY::IsClosed( const bool theIsSimpleCheck ) const
499 bool anIsClosed = false;
501 TopoDS_Shape aShape = GetShape();
502 if ( aShape.IsNull() )
505 TopTools_SequenceOfShape aWires;
506 HYDROData_ShapesTool::ExploreShapeToShapes( aShape, TopAbs_WIRE, aWires );
508 int aNbWires = aWires.Length();
509 if ( theIsSimpleCheck )
511 anIsClosed = aNbWires > 0;
512 for ( int i = 1; i <= aNbWires && anIsClosed; ++i )
514 const TopoDS_Shape& aWire = aWires.Value( i );
515 anIsClosed = BRep_Tool::IsClosed( aWire );
520 anIsClosed = aNbWires == 1 && BRep_Tool::IsClosed( aWires.First() );
526 double HYDROData_PolylineXY::GetDistance( const int theSectionIndex,
527 const int thePointIndex ) const
529 double aResDistance = -1;
530 if ( theSectionIndex < 0 || theSectionIndex >= NbSections() )
533 if ( thePointIndex == 0 )
536 SectionType aSectionType = GetSectionType( theSectionIndex );
537 bool anIsSectionClosed = IsClosedSection( theSectionIndex );
538 PointsList aSectPointsList = GetPoints( theSectionIndex );
539 if ( thePointIndex < 0 || thePointIndex >= aSectPointsList.Size() )
542 if ( aSectionType == SECTION_POLYLINE )
546 Point aPrevPoint = aSectPointsList.Value( 1 );
547 for ( int i = 2, aNbPoints = aSectPointsList.Size(); i <= aNbPoints; ++i )
549 const Point& aSectPoint = aSectPointsList.Value( i );
550 aResDistance += gp_Pnt2d( aPrevPoint ).Distance( aSectPoint );
551 aPrevPoint = aSectPoint;
553 if ( thePointIndex == i - 1 )
561 int aSectNbPoints = aSectPointsList.Size();
562 NCollection_Sequence<gp_XYZ> aPoints;
563 for( int i = 1 ; i <= aSectNbPoints; ++i )
565 const Point& aSectPoint = aSectPointsList.Value( i );
567 gp_XYZ aPoint( aSectPoint.X(), aSectPoint.Y(), 0.0 );
568 aPoints.Append( aPoint );
570 if ( thePointIndex == i - 1 )
571 aPointToTest = aPoint;
574 HYDROData_BSplineOperation aBSpline( aPoints, anIsSectionClosed, LOCAL_SELECTION_TOLERANCE );
576 Quantity_Parameter aFirstParam = aBSpline.Curve()->FirstParameter();
577 Quantity_Parameter aSecondParam = aBSpline.Curve()->LastParameter();
579 if ( thePointIndex != aSectNbPoints - 1 )
581 GeomAPI_ProjectPointOnCurve aProject( aPointToTest, aBSpline.Curve() );
582 aSecondParam = aProject.LowerDistanceParameter();
585 GeomAdaptor_Curve anAdap( aBSpline.Curve() );
587 aResDistance = GCPnts_AbscissaPoint::Length( anAdap, aFirstParam, aSecondParam );
593 int HYDROData_PolylineXY::NbSections() const
595 Handle(TDataStd_ExtStringList) aNamesList;
596 Handle(TDataStd_IntegerList) aTypesList;
597 Handle(TDataStd_BooleanList) aClosuresList;
598 getSectionsLists( aNamesList, aTypesList, aClosuresList, false );
600 return !aClosuresList.IsNull() ? aClosuresList->Extent() : 0;
603 void HYDROData_PolylineXY::AddSection( const TCollection_AsciiString& theSectName,
604 const SectionType theSectionType,
605 const bool theIsClosed )
607 Handle(TDataStd_ExtStringList) aNamesList;
608 Handle(TDataStd_IntegerList) aTypesList;
609 Handle(TDataStd_BooleanList) aClosuresList;
610 getSectionsLists( aNamesList, aTypesList, aClosuresList );
612 TCollection_ExtendedString aSectName( theSectName );
613 if ( aSectName.Length() <= 0 )
614 aSectName = getUniqueSectionName( aNamesList );
616 aNamesList->Append( aSectName );
617 aTypesList->Append( theSectionType );
618 aClosuresList->Append( theIsClosed );
623 TCollection_AsciiString HYDROData_PolylineXY::GetSectionName( const int theSectionIndex ) const
625 TCollection_AsciiString aResName;
627 Handle(TDataStd_ExtStringList) aNamesList;
628 Handle(TDataStd_IntegerList) aTypesList;
629 Handle(TDataStd_BooleanList) aClosuresList;
630 getSectionsLists( aNamesList, aTypesList, aClosuresList, false );
631 if ( aNamesList.IsNull() || theSectionIndex >= aNamesList->Extent() )
634 TDataStd_ListIteratorOfListOfExtendedString aNamesIter( aNamesList->List() );
635 for ( int i = 0; aNamesIter.More() && i != theSectionIndex; aNamesIter.Next(), ++i );
637 if ( aNamesIter.More() )
638 aResName = aNamesIter.Value();
643 void HYDROData_PolylineXY::SetSectionName( const int theSectionIndex,
644 const TCollection_AsciiString& theSectionName )
646 Handle(TDataStd_ExtStringList) aNamesList;
647 Handle(TDataStd_IntegerList) aTypesList;
648 Handle(TDataStd_BooleanList) aClosuresList;
649 getSectionsLists( aNamesList, aTypesList, aClosuresList, false );
650 if ( aNamesList.IsNull() || theSectionIndex >= aNamesList->Extent() )
653 TDataStd_ListOfExtendedString anOldNamesList;
654 anOldNamesList = aNamesList->List();
656 // Refill the existing list
659 TCollection_ExtendedString aNewSectName = theSectionName;
661 TDataStd_ListIteratorOfListOfExtendedString aNamesIter( anOldNamesList );
662 for ( int i = 0; aNamesIter.More(); aNamesIter.Next(), ++i )
663 aNamesList->Append( i == theSectionIndex ? aNewSectName : aNamesIter.Value() );
668 HYDROData_PolylineXY::SectionType HYDROData_PolylineXY::GetSectionType( const int theSectionIndex ) const
670 Handle(TDataStd_ExtStringList) aNamesList;
671 Handle(TDataStd_IntegerList) aTypesList;
672 Handle(TDataStd_BooleanList) aClosuresList;
673 getSectionsLists( aNamesList, aTypesList, aClosuresList, false );
674 if ( aTypesList.IsNull() || theSectionIndex >= aTypesList->Extent() )
675 return SECTION_POLYLINE;
677 TColStd_ListIteratorOfListOfInteger aTypesIter( aTypesList->List() );
678 for ( int i = 0; aTypesIter.More() && i != theSectionIndex; aTypesIter.Next(), ++i );
680 return aTypesIter.More() ? (SectionType)aTypesIter.Value() : SECTION_POLYLINE;
683 void HYDROData_PolylineXY::SetSectionType( const int theSectionIndex,
684 const SectionType theSectionType )
686 Handle(TDataStd_ExtStringList) aNamesList;
687 Handle(TDataStd_IntegerList) aTypesList;
688 Handle(TDataStd_BooleanList) aClosuresList;
689 getSectionsLists( aNamesList, aTypesList, aClosuresList, false );
690 if ( aTypesList.IsNull() || theSectionIndex >= aTypesList->Extent() )
693 TColStd_ListOfInteger anOldTypesList;
694 anOldTypesList = aTypesList->List();
696 // Refill the existing list
699 TColStd_ListIteratorOfListOfInteger aTypesIter( anOldTypesList );
700 for ( int i = 0; aTypesIter.More(); aTypesIter.Next(), ++i )
701 aTypesList->Append( i == theSectionIndex ? theSectionType : aTypesIter.Value() );
706 bool HYDROData_PolylineXY::IsClosedSection( const int theSectionIndex ) const
708 Handle(TDataStd_ExtStringList) aNamesList;
709 Handle(TDataStd_IntegerList) aTypesList;
710 Handle(TDataStd_BooleanList) aClosuresList;
711 getSectionsLists( aNamesList, aTypesList, aClosuresList, false );
712 if ( aClosuresList.IsNull() || theSectionIndex >= aClosuresList->Extent() )
715 TDataStd_ListIteratorOfListOfByte aClosuresIter( aClosuresList->List() );
716 for ( int i = 0; aClosuresIter.More() && i != theSectionIndex; aClosuresIter.Next(), ++i );
718 return aClosuresIter.More() ? (bool)aClosuresIter.Value() : false;
721 void HYDROData_PolylineXY::SetSectionClosed( const int theSectionIndex,
722 const bool theIsClosed )
724 Handle(TDataStd_ExtStringList) aNamesList;
725 Handle(TDataStd_IntegerList) aTypesList;
726 Handle(TDataStd_BooleanList) aClosuresList;
727 getSectionsLists( aNamesList, aTypesList, aClosuresList, false );
728 if ( aClosuresList.IsNull() || theSectionIndex >= aClosuresList->Extent() )
731 TDataStd_ListOfByte anOldClosuresList;
732 anOldClosuresList = aClosuresList->List();
734 // Refill the existing list
735 aClosuresList->Clear();
737 TDataStd_ListIteratorOfListOfByte aClosuresIter( anOldClosuresList );
738 for ( int i = 0; aClosuresIter.More(); aClosuresIter.Next(), ++i )
739 aClosuresList->Append( i == theSectionIndex ? theIsClosed : (bool)aClosuresIter.Value() );
744 void HYDROData_PolylineXY::GetSections( NCollection_Sequence<TCollection_AsciiString>& theSectNames,
745 NCollection_Sequence<SectionType>& theSectTypes,
746 NCollection_Sequence<bool>& theSectClosures ) const
748 theSectNames.Clear();
749 theSectTypes.Clear();
750 theSectClosures.Clear();
752 Handle(TDataStd_ExtStringList) aNamesList;
753 Handle(TDataStd_IntegerList) aTypesList;
754 Handle(TDataStd_BooleanList) aClosuresList;
755 getSectionsLists( aNamesList, aTypesList, aClosuresList, false );
756 if ( aNamesList.IsNull() || aTypesList.IsNull() || aClosuresList.IsNull() )
759 TDataStd_ListIteratorOfListOfExtendedString aNamesIter( aNamesList->List() );
760 TColStd_ListIteratorOfListOfInteger aTypesIter( aTypesList->List() );
761 TDataStd_ListIteratorOfListOfByte aClosuresIter( aClosuresList->List() );
762 for ( ; aNamesIter.More() && aTypesIter.More() && aClosuresIter.More();
763 aNamesIter.Next(), aTypesIter.Next(), aClosuresIter.Next() )
765 const TCollection_ExtendedString& aSectName = aNamesIter.Value();
766 SectionType aSectType = (SectionType)aTypesIter.Value();
767 bool aSectClosures = aClosuresIter.Value();
769 theSectNames.Append( aSectName );
770 theSectTypes.Append( aSectType );
771 theSectClosures.Append( aSectClosures );
775 void HYDROData_PolylineXY::RemoveSection( const int theSectionIndex )
777 Handle(TDataStd_ExtStringList) aNamesList;
778 Handle(TDataStd_IntegerList) aTypesList;
779 Handle(TDataStd_BooleanList) aClosuresList;
780 getSectionsLists( aNamesList, aTypesList, aClosuresList, false );
781 if ( aNamesList.IsNull() || theSectionIndex >= aNamesList->Extent() )
784 if ( aNamesList->Extent() == 1 )
786 removeSectionsLists();
791 TDataStd_ListOfExtendedString anOldNamesList;
792 anOldNamesList = aNamesList->List();
794 TColStd_ListOfInteger anOldTypesList;
795 anOldTypesList = aTypesList->List();
797 TDataStd_ListOfByte anOldClosuresList;
798 anOldClosuresList = aClosuresList->List();
800 // Refill the existing lists
803 aClosuresList->Clear();
805 TDataStd_ListIteratorOfListOfExtendedString aNamesIter( anOldNamesList );
806 TColStd_ListIteratorOfListOfInteger aTypesIter( anOldTypesList );
807 TDataStd_ListIteratorOfListOfByte aClosuresIter( anOldClosuresList );
808 for ( int i = 0; aNamesIter.More() && aTypesIter.More() && aClosuresIter.More();
809 aNamesIter.Next(), aTypesIter.Next(), aClosuresIter.Next(), ++i )
811 if ( i == theSectionIndex )
812 continue; // skip index to remove
814 aNamesList->Append( aNamesIter.Value() );
815 aTypesList->Append( aTypesIter.Value() );
816 aClosuresList->Append( (bool)aClosuresIter.Value() );
819 // Remove points that belongs to removed section
820 removePointsLists( theSectionIndex );
826 void HYDROData_PolylineXY::RemoveSections()
828 removeSectionsLists();
833 void HYDROData_PolylineXY::AddPoint( const int theSectionIndex,
834 const Point& thePoint,
835 const int thePointIndex )
837 Handle(TDataStd_RealList) aListX, aListY;
838 getPointsLists( theSectionIndex, aListX, aListY );
840 if ( thePointIndex < 0 || thePointIndex >= aListX->Extent() )
842 aListX->Append( thePoint.X() );
843 aListY->Append( thePoint.Y() );
847 TColStd_ListOfReal anOldListX;
848 anOldListX = aListX->List();
850 TColStd_ListOfReal anOldListY;
851 anOldListY = aListY->List();
853 // Refill the existing lists
857 TColStd_ListIteratorOfListOfReal anIterX( anOldListX );
858 TColStd_ListIteratorOfListOfReal anIterY( anOldListY );
859 for ( int i = 0; anIterX.More() && anIterY.More(); anIterX.Next(), anIterY.Next(), ++i )
861 double aCoordX = anIterX.Value();
862 double aCoordY = anIterY.Value();
864 if ( i == thePointIndex )
866 // Insert our new point
867 aListX->Append( thePoint.X() );
868 aListY->Append( thePoint.Y() );
871 aListX->Append( aCoordX );
872 aListY->Append( aCoordY );
879 void HYDROData_PolylineXY::SetPoint( const int theSectionIndex,
880 const Point& thePoint,
881 const int thePointIndex )
883 Handle(TDataStd_RealList) aListX, aListY;
884 getPointsLists( theSectionIndex, aListX, aListY );
886 if ( thePointIndex < 0 )
888 aListX->Prepend( thePoint.X() );
889 aListY->Prepend( thePoint.Y() );
891 else if ( thePointIndex >= aListX->Extent() )
893 aListX->Append( thePoint.X() );
894 aListY->Append( thePoint.Y() );
898 TColStd_ListOfReal anOldListX;
899 anOldListX = aListX->List();
901 TColStd_ListOfReal anOldListY;
902 anOldListY = aListY->List();
904 // Refill the existing lists
908 TColStd_ListIteratorOfListOfReal anIterX( anOldListX );
909 TColStd_ListIteratorOfListOfReal anIterY( anOldListY );
910 for ( int i = 0; anIterX.More() && anIterY.More(); anIterX.Next(), anIterY.Next(), ++i )
912 double aCoordX = anIterX.Value();
913 double aCoordY = anIterY.Value();
915 if ( i == thePointIndex )
917 // Insert our new point instead of old one
918 aCoordX = thePoint.X();
919 aCoordY = thePoint.Y();
922 aListX->Append( aCoordX );
923 aListY->Append( aCoordY );
930 void HYDROData_PolylineXY::SetPoints( const int theSectionIndex,
931 const PointsList& thePoints )
933 Handle(TDataStd_RealList) aListX, aListY;
934 getPointsLists( theSectionIndex, aListX, aListY );
939 for ( int i = 1, n = thePoints.Length(); i <= n; ++i )
941 const Point& aPoint = thePoints.Value( i );
942 aListX->Append( aPoint.X() );
943 aListY->Append( aPoint.Y() );
947 void HYDROData_PolylineXY::RemovePoint( const int theSectionIndex,
948 const int thePointIndex )
950 Handle(TDataStd_RealList) aListX, aListY;
951 getPointsLists( theSectionIndex, aListX, aListY, false );
952 if ( aListX.IsNull() || aListY.IsNull() || aListX->IsEmpty() )
955 if ( aListX->Extent() == 1 )
957 removePointsLists( theSectionIndex );
961 TColStd_ListOfReal anOldListX;
962 anOldListX = aListX->List();
964 TColStd_ListOfReal anOldListY;
965 anOldListY = aListY->List();
967 // Refill the existing lists
971 TColStd_ListIteratorOfListOfReal anIterX( anOldListX );
972 TColStd_ListIteratorOfListOfReal anIterY( anOldListY );
973 for ( int i = 0; anIterX.More() && anIterY.More(); anIterX.Next(), anIterY.Next(), ++i )
975 if ( i == thePointIndex )
976 continue; // skip index to remove
978 aListX->Append( anIterX.Value() );
979 aListY->Append( anIterY.Value() );
986 HYDROData_PolylineXY::PointsList HYDROData_PolylineXY::GetPoints( const int theSectionIndex ) const
990 Handle(TDataStd_RealList) aListX, aListY;
991 getPointsLists( theSectionIndex, aListX, aListY, false );
992 if ( aListX.IsNull() || aListY.IsNull() || aListX->IsEmpty() )
995 TColStd_ListIteratorOfListOfReal anIterX( aListX->List() );
996 TColStd_ListIteratorOfListOfReal anIterY( aListY->List() );
997 for ( ; anIterX.More() && anIterY.More(); anIterX.Next(), anIterY.Next() )
999 Point aPoint( anIterX.Value(), anIterY.Value() );
1000 aResList.Append( aPoint );
1006 QPainterPath HYDROData_PolylineXY::GetPainterPath() const
1010 NCollection_Sequence<TCollection_AsciiString> aSectNames;
1011 NCollection_Sequence<HYDROData_PolylineXY::SectionType> aSectTypes;
1012 NCollection_Sequence<bool> aSectClosures;
1013 GetSections( aSectNames, aSectTypes, aSectClosures );
1015 for ( int aSectionId = 1, aNbSects = aSectNames.Size(); aSectionId <= aNbSects; aSectionId++ )
1017 TCollection_AsciiString aSectName = aSectNames.Value( aSectionId );
1018 SectionType aSectionType = aSectTypes.Value( aSectionId );
1019 bool anIsSectionClosed = aSectClosures.Value( aSectionId );
1021 PointsList aSectPointsList = GetPoints( aSectionId - 1 );
1022 if ( aSectPointsList.IsEmpty() )
1025 NCollection_Sequence<gp_XYZ> aPoints;
1026 for( int i = 1, n = aSectPointsList.Size(); i <= n; ++i )
1028 const Point& aSectPoint = aSectPointsList.Value( i );
1030 gp_XYZ aPoint( aSectPoint.X(), aSectPoint.Y(), 0.0 );
1031 aPoints.Append( aPoint );
1034 BuildPainterPath( aPath, aSectionType, anIsSectionClosed, aPoints );