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>
13 #include <GeomAPI_ProjectPointOnCurve.hxx>
14 #include <GeomAdaptor_Curve.hxx>
15 #include <Geom_Line.hxx>
16 #include <Geom_BSplineCurve.hxx>
18 #include <GCPnts_AbscissaPoint.hxx>
20 #include <ImageComposer_MetaTypes.h>
25 #include <NCollection_Map.hxx>
27 #include <TCollection_ExtendedString.hxx>
29 #include <TDataStd_ListIteratorOfListOfByte.hxx>
30 #include <TColStd_ListIteratorOfListOfInteger.hxx>
31 #include <TColStd_ListIteratorOfListOfReal.hxx>
33 #include <TColStd_Array1OfReal.hxx>
35 #include <TDataStd_BooleanList.hxx>
36 #include <TDataStd_ExtStringList.hxx>
37 #include <TDataStd_IntegerList.hxx>
38 #include <TDataStd_ListIteratorOfListOfExtendedString.hxx>
39 #include <TDataStd_RealList.hxx>
40 #include <TDataStd_UAttribute.hxx>
42 #include <TopoDS_Iterator.hxx>
43 #include <TopTools_ListIteratorOfListOfShape.hxx>
44 #include <TopTools_HSequenceOfShape.hxx>
45 #include <TopExp_Explorer.hxx>
46 #include <ShapeAnalysis_FreeBounds.hxx>
49 #include <QPainterPath>
52 static const Standard_GUID GUID_IS_UNEDITABLE("e5799736-9030-4051-91a4-2e58321fa153");
54 #define PYTHON_POLYLINEXY_ID "KIND_POLYLINEXY"
56 const double LOCAL_SELECTION_TOLERANCE = 0.0001;
58 TCollection_AsciiString getUniqueSectionName( const NCollection_Sequence<TCollection_AsciiString>& theNamesSeq )
60 NCollection_Map<TCollection_AsciiString> aNamesMap;
62 for ( int i = 1, n = theNamesSeq.Size(); i <= n; ++i )
64 const TCollection_AsciiString& aSectName = theNamesSeq.Value( i );
65 aNamesMap.Add( aSectName );
68 TCollection_AsciiString aResName;
73 aResName = TCollection_AsciiString( "Section_" ) + aPrefIdx;
76 while ( aNamesMap.Contains( aResName ) );
81 TCollection_AsciiString getUniqueSectionName( const Handle(TDataStd_ExtStringList)& theNamesList )
83 NCollection_Sequence<TCollection_AsciiString> aNamesSeq;
85 TDataStd_ListIteratorOfListOfExtendedString aNamesIter( theNamesList->List() );
86 for ( ; aNamesIter.More(); aNamesIter.Next() )
87 aNamesSeq.Append( aNamesIter.Value() );
89 return getUniqueSectionName( aNamesSeq );
92 IMPLEMENT_STANDARD_HANDLE(HYDROData_PolylineXY, HYDROData_IPolyline)
93 IMPLEMENT_STANDARD_RTTIEXT(HYDROData_PolylineXY, HYDROData_IPolyline)
95 HYDROData_PolylineXY::HYDROData_PolylineXY()
96 : HYDROData_IPolyline()
100 HYDROData_PolylineXY::~HYDROData_PolylineXY()
104 QStringList HYDROData_PolylineXY::DumpToPython( MapOfTreatedObjects& theTreatedObjects ) const
106 QStringList aResList;
108 Handle(HYDROData_Document) aDocument = HYDROData_Document::Document( myLab );
109 if ( aDocument.IsNull() )
112 QString aDocName = aDocument->GetDocPyName();
113 QString aPolylineName = GetName();
115 aResList << QString( "%1 = %2.CreateObject( %3 );" )
116 .arg( aPolylineName ).arg( aDocName ).arg( PYTHON_POLYLINEXY_ID );
117 aResList << QString( "%1.SetName( \"%1\" );" ).arg( aPolylineName );
120 NCollection_Sequence<TCollection_AsciiString> aSectNames;
121 NCollection_Sequence<HYDROData_PolylineXY::SectionType> aSectTypes;
122 NCollection_Sequence<bool> aSectClosures;
123 GetSections( aSectNames, aSectTypes, aSectClosures );
125 for ( int i = 1, n = aSectNames.Size(); i <= n; ++i )
127 const TCollection_AsciiString& aSectName = aSectNames.Value( i );
128 const SectionType& aSectType = aSectTypes.Value( i );
129 bool aSectClosure = aSectClosures.Value( i );
131 aResList << QString( "%1.AddSection( \"%2\", %3, %4 );" ).arg( aPolylineName )
132 .arg( aSectName.ToCString() ).arg( aSectType ).arg( aSectClosure );
134 HYDROData_PolylineXY::PointsList aSectPointsList = GetPoints( i );
135 for ( int k = 1, aNbPoints = aSectPointsList.Size(); k <= aNbPoints; ++k )
137 const Point& aSectPoint = aSectPointsList.Value( k );
139 aResList << QString( "%1.AddPoint( %2, QPointF( %3, %4 ) );" ).arg( aPolylineName )
140 .arg( i - 1 ).arg( aSectPoint.X() ).arg( aSectPoint.Y() );
147 QVariant HYDROData_PolylineXY::GetDataVariant()
149 QPainterPath aPath = GetPainterPath();
152 aVarData.setValue<QPainterPath>( aPath );
157 QColor HYDROData_PolylineXY::DefaultWireColor()
159 return QColor( Qt::red );
162 TopoDS_Shape HYDROData_PolylineXY::GetShape() const
164 return getPolylineShape();
167 bool convertEdgeToSection( const TopoDS_Edge& theEdge,
168 NCollection_Sequence<TCollection_AsciiString>& theSectNames,
169 NCollection_Sequence<HYDROData_PolylineXY::SectionType>& theSectTypes,
170 NCollection_Sequence<bool>& theSectClosures,
171 NCollection_Sequence<HYDROData_PolylineXY::PointsList>& theSectPoints,
172 const bool theIsCanBeClosed )
174 Standard_Real aFirst = 0.0, aLast = 0.0;
175 Handle(Geom_Curve) anEdgeGeomCurve = BRep_Tool::Curve( theEdge, aFirst, aLast );
176 if ( anEdgeGeomCurve.IsNull() )
179 TCollection_AsciiString aSectName = getUniqueSectionName( theSectNames );
180 bool anIsEdgeClosed = anEdgeGeomCurve->IsClosed();
182 HYDROData_PolylineXY::SectionType aSectionType = HYDROData_PolylineXY::SECTION_POLYLINE;
183 HYDROData_PolylineXY::PointsList aPointsList;
185 if ( anEdgeGeomCurve->IsKind( STANDARD_TYPE(Geom_Line) ) )
187 Handle(Geom_Line) aGeomLine = Handle(Geom_Line)::DownCast( anEdgeGeomCurve );
189 gp_Pnt aFirstPoint, aLastPoint;
190 aGeomLine->D0( aFirst, aFirstPoint );
191 aGeomLine->D0( aLast, aLastPoint );
193 HYDROData_PolylineXY::Point aSectFirstPoint( aFirstPoint.X(), aFirstPoint.Y() );
194 aPointsList.Append( aSectFirstPoint );
196 HYDROData_PolylineXY::Point aSectLastPoint( aLastPoint.X(), aLastPoint.Y() );
197 aPointsList.Append( aSectLastPoint );
199 else if ( anEdgeGeomCurve->IsKind( STANDARD_TYPE(Geom_BSplineCurve) ) )
201 aSectionType = HYDROData_PolylineXY::SECTION_SPLINE;
203 Handle(Geom_BSplineCurve) aGeomSpline =
204 Handle(Geom_BSplineCurve)::DownCast( anEdgeGeomCurve );
206 int aNbKnots = aGeomSpline->NbKnots();
208 TColStd_Array1OfReal aSplineKnots( 1, aNbKnots );
209 aGeomSpline->Knots( aSplineKnots );
211 // Decrease the number of imported knots because of last one
212 // knot is the closing point which are the start point
213 if ( anIsEdgeClosed ) aNbKnots--;
215 for ( int i = 1; i <= aNbKnots; ++i )
217 const Standard_Real& aKnot = aSplineKnots.Value( i );
220 aGeomSpline->D0( aKnot, aPoint );
222 HYDROData_PolylineXY::Point aSectPoint( aPoint.X(), aPoint.Y() );
223 aPointsList.Append( aSectPoint );
228 // Other curve types are not supported
232 if ( aPointsList.IsEmpty() )
235 theSectNames.Append( aSectName );
236 theSectTypes.Append( aSectionType );
237 theSectClosures.Append( anIsEdgeClosed );
238 theSectPoints.Append( aPointsList );
243 bool HYDROData_PolylineXY::ImportShape( const TopoDS_Shape& theShape )
245 if ( theShape.IsNull() )
250 bool anIsCanBeImported = false;
252 NCollection_Sequence<TCollection_AsciiString> aSectNames;
253 NCollection_Sequence<SectionType> aSectTypes;
254 NCollection_Sequence<bool> aSectClosures;
255 NCollection_Sequence<PointsList> aSectPoints;
257 if ( theShape.ShapeType() == TopAbs_EDGE )
259 TopoDS_Edge anEdge = TopoDS::Edge( theShape );
260 anIsCanBeImported = convertEdgeToSection( anEdge, aSectNames, aSectTypes, aSectClosures, aSectPoints, true );
262 else if ( theShape.ShapeType() == TopAbs_WIRE )
264 TopTools_SequenceOfShape anEdges;
265 HYDROData_ShapesTool::ExploreShapeToShapes( theShape, TopAbs_EDGE, anEdges );
267 anIsCanBeImported = !anEdges.IsEmpty();
268 for ( int i = 1, n = anEdges.Length(); i <= n && anIsCanBeImported; ++i )
270 TopoDS_Edge aWireEdge = TopoDS::Edge( anEdges.Value( i ) );
271 anIsCanBeImported = convertEdgeToSection( aWireEdge, aSectNames, aSectTypes, aSectClosures, aSectPoints, false );
275 if ( anIsCanBeImported )
277 for ( int i = 1, n = aSectNames.Length(); i <= n; ++i )
279 const TCollection_AsciiString& aSectName = aSectNames.Value( i );
280 const SectionType& aSectType = aSectTypes.Value( i );
281 bool anIsSectionClosed = aSectClosures.Value( i );
282 const PointsList& aSectPointsList = aSectPoints( i );
284 AddSection( aSectName, aSectType, anIsSectionClosed );
285 SetPoints( i - 1, aSectPointsList );
290 TopoDS_Shape aShape = theShape;
292 if ( theShape.ShapeType() == TopAbs_EDGE )
294 // We make the wire from incoming edge because of other algorithms
295 // are waiting at least the wire from polyline
296 TopoDS_Edge anEdge = TopoDS::Edge( theShape );
297 BRepBuilderAPI_MakeWire aMakeWire( anEdge );
299 if ( aMakeWire.IsDone() )
300 aShape = aMakeWire.Wire();
303 setPolylineShape( aShape );
306 setEditable( anIsCanBeImported );
311 TopoDS_Wire HYDROData_PolylineXY::BuildWire( const SectionType& theType,
312 const bool& theIsClosed,
313 const NCollection_Sequence<gp_XYZ>& thePoints )
315 BRepBuilderAPI_MakeWire aMakeWire;
317 if( theType == SECTION_POLYLINE )
319 for( int i = 1, n = thePoints.Size(); i <= n; ++i )
321 const gp_XYZ& aFirstPoint = thePoints.Value( i );
327 aLastPoint = thePoints.Value( 1 );
333 aLastPoint = thePoints.Value( i + 1 );
336 gp_Pnt aPnt1( aFirstPoint.X(), aFirstPoint.Y(), aFirstPoint.Z() );
337 gp_Pnt aPnt2( aLastPoint.X(), aLastPoint.Y(), aLastPoint.Z() );
339 if ( aPnt1.IsEqual( aPnt2, LOCAL_SELECTION_TOLERANCE ) )
342 TopoDS_Edge anEdge = BRepBuilderAPI_MakeEdge( aPnt1, aPnt2 ).Edge();
343 aMakeWire.Add( anEdge );
346 else //if( theType == PolylineSection::SECTION_SPLINE )
348 HYDROData_BSplineOperation aBSpline( thePoints, theIsClosed, LOCAL_SELECTION_TOLERANCE );
350 TopoDS_Edge anEdge = BRepBuilderAPI_MakeEdge( aBSpline.Curve() ).Edge();
351 aMakeWire.Add( anEdge );
356 if ( aMakeWire.IsDone() )
362 void HYDROData_PolylineXY::BuildPainterPath( QPainterPath& thePath,
363 const SectionType& theType,
364 const bool& theIsClosed,
365 const NCollection_Sequence<gp_XYZ>& thePoints )
367 if ( thePoints.IsEmpty() )
370 if ( theType == SECTION_POLYLINE )
372 const gp_XYZ& aFirstPoint = thePoints.Value( 1 );
373 thePath.moveTo( aFirstPoint.X(), aFirstPoint.Y() );
375 for( int i = 2, n = thePoints.Size(); i <= n; ++i )
377 const gp_XYZ& aSectPoint = thePoints.Value( i );
379 thePath.lineTo( aSectPoint.X(), aSectPoint.Y() );
383 thePath.closeSubpath();
387 HYDROData_BSplineOperation aBSpline( thePoints, theIsClosed, LOCAL_SELECTION_TOLERANCE );
388 aBSpline.ComputePath( thePath );
392 void HYDROData_PolylineXY::Update()
396 // If polyline is not editable we no need to update it wire
397 SetToUpdate( false );
401 HYDROData_IPolyline::Update();
403 NCollection_Sequence<TCollection_AsciiString> aSectNames;
404 NCollection_Sequence<HYDROData_PolylineXY::SectionType> aSectTypes;
405 NCollection_Sequence<bool> aSectClosures;
406 GetSections( aSectNames, aSectTypes, aSectClosures );
408 BRepBuilderAPI_MakeWire aMakeWire;
410 TopTools_ListOfShape aSectionWiresList;
412 for ( int aSectionId = 1, aNbSects = aSectNames.Size(); aSectionId <= aNbSects; aSectionId++ )
414 TCollection_AsciiString aSectName = aSectNames.Value( aSectionId );
415 SectionType aSectionType = aSectTypes.Value( aSectionId );
416 bool anIsSectionClosed = aSectClosures.Value( aSectionId );
418 PointsList aSectPointsList = GetPoints( aSectionId - 1 );
419 if ( aSectPointsList.IsEmpty() )
422 NCollection_Sequence<gp_XYZ> aPoints;
423 for( int i = 1, n = aSectPointsList.Size(); i <= n; ++i )
425 const Point& aSectPoint = aSectPointsList.Value( i );
427 gp_XYZ aPoint( aSectPoint.X(), aSectPoint.Y(), 0.0 );
428 aPoints.Append( aPoint );
431 TopoDS_Wire aSectionWire = BuildWire( aSectionType, anIsSectionClosed, aPoints );
432 if ( !aSectionWire.IsNull() ) {
433 aSectionWiresList.Append( aSectionWire );
434 aMakeWire.Add( aSectionWire );
437 // all input wires in the <aSectionWiresList>
438 Handle(TopTools_HSequenceOfShape) aSeqWires = new TopTools_HSequenceOfShape;
439 Handle(TopTools_HSequenceOfShape) aSeqEdges = new TopTools_HSequenceOfShape;
440 TopTools_ListIteratorOfListOfShape it(aSectionWiresList);
441 for(;it.More();it.Next())
443 TopExp_Explorer it2(it.Value(), TopAbs_EDGE);
444 for(;it2.More();it2.Next())
445 aSeqEdges->Append(it2.Current());
449 TopoDS_Compound aCmp;
450 TopoDS_Shape aResult;
451 aBB.MakeCompound(aCmp);
452 if(aSeqEdges->Length() >1)
454 ShapeAnalysis_FreeBounds::ConnectEdgesToWires(aSeqEdges,1E-5,Standard_False,aSeqWires);
456 if( aSeqWires->Length()==1 )
457 aResult = aSeqWires->Value( 1 );
460 for (Standard_Integer i = 1; i <= aSeqWires->Length();i++)
462 const TopoDS_Shape& aS1 = aSeqWires->Value(i);
468 else if (aSeqEdges->Length() == 1)
470 BRepBuilderAPI_MakeWire mkWire (TopoDS::Edge(aSeqEdges->Value(1)));
472 aResult = mkWire.Wire();
475 setPolylineShape( aResult );
478 bool HYDROData_PolylineXY::IsEditable() const
480 return !myLab.IsAttribute( GUID_IS_UNEDITABLE );
483 void HYDROData_PolylineXY::setEditable( const bool theIsEditable )
485 if ( !theIsEditable )
486 TDataStd_UAttribute::Set( myLab, GUID_IS_UNEDITABLE );
488 myLab.ForgetAttribute( GUID_IS_UNEDITABLE );
492 * Returns true if polyline is closed
494 bool HYDROData_PolylineXY::IsClosed( const bool theIsSimpleCheck ) const
496 bool anIsClosed = false;
498 TopoDS_Shape aShape = GetShape();
499 if ( aShape.IsNull() )
502 TopTools_SequenceOfShape aWires;
503 HYDROData_ShapesTool::ExploreShapeToShapes( aShape, TopAbs_WIRE, aWires );
505 int aNbWires = aWires.Length();
506 if ( theIsSimpleCheck )
508 anIsClosed = aNbWires > 0;
509 for ( int i = 1; i <= aNbWires && anIsClosed; ++i )
511 const TopoDS_Shape& aWire = aWires.Value( i );
512 anIsClosed = BRep_Tool::IsClosed( aWire );
517 anIsClosed = aNbWires == 1 && BRep_Tool::IsClosed( aWires.First() );
523 double HYDROData_PolylineXY::GetDistance( const int theSectionIndex,
524 const int thePointIndex ) const
526 double aResDistance = -1;
527 if ( theSectionIndex < 0 || theSectionIndex >= NbSections() )
530 if ( thePointIndex == 0 )
533 SectionType aSectionType = GetSectionType( theSectionIndex );
534 bool anIsSectionClosed = IsClosedSection( theSectionIndex );
535 PointsList aSectPointsList = GetPoints( theSectionIndex );
536 if ( thePointIndex < 0 || thePointIndex >= aSectPointsList.Size() )
539 if ( aSectionType == SECTION_POLYLINE )
543 Point aPrevPoint = aSectPointsList.Value( 1 );
544 for ( int i = 2, aNbPoints = aSectPointsList.Size(); i <= aNbPoints; ++i )
546 const Point& aSectPoint = aSectPointsList.Value( i );
547 aResDistance += gp_Pnt2d( aPrevPoint ).Distance( aSectPoint );
548 aPrevPoint = aSectPoint;
550 if ( thePointIndex == i - 1 )
558 int aSectNbPoints = aSectPointsList.Size();
559 NCollection_Sequence<gp_XYZ> aPoints;
560 for( int i = 1 ; i <= aSectNbPoints; ++i )
562 const Point& aSectPoint = aSectPointsList.Value( i );
564 gp_XYZ aPoint( aSectPoint.X(), aSectPoint.Y(), 0.0 );
565 aPoints.Append( aPoint );
567 if ( thePointIndex == i - 1 )
568 aPointToTest = aPoint;
571 HYDROData_BSplineOperation aBSpline( aPoints, anIsSectionClosed, LOCAL_SELECTION_TOLERANCE );
573 Quantity_Parameter aFirstParam = aBSpline.Curve()->FirstParameter();
574 Quantity_Parameter aSecondParam = aBSpline.Curve()->LastParameter();
576 if ( thePointIndex != aSectNbPoints - 1 )
578 GeomAPI_ProjectPointOnCurve aProject( aPointToTest, aBSpline.Curve() );
579 aSecondParam = aProject.LowerDistanceParameter();
582 GeomAdaptor_Curve anAdap( aBSpline.Curve() );
584 aResDistance = GCPnts_AbscissaPoint::Length( anAdap, aFirstParam, aSecondParam );
590 int HYDROData_PolylineXY::NbSections() const
592 Handle(TDataStd_ExtStringList) aNamesList;
593 Handle(TDataStd_IntegerList) aTypesList;
594 Handle(TDataStd_BooleanList) aClosuresList;
595 getSectionsLists( aNamesList, aTypesList, aClosuresList, false );
597 return !aClosuresList.IsNull() ? aClosuresList->Extent() : 0;
600 void HYDROData_PolylineXY::AddSection( const TCollection_AsciiString& theSectName,
601 const SectionType theSectionType,
602 const bool theIsClosed )
604 Handle(TDataStd_ExtStringList) aNamesList;
605 Handle(TDataStd_IntegerList) aTypesList;
606 Handle(TDataStd_BooleanList) aClosuresList;
607 getSectionsLists( aNamesList, aTypesList, aClosuresList );
609 TCollection_ExtendedString aSectName( theSectName );
610 if ( aSectName.Length() <= 0 )
611 aSectName = getUniqueSectionName( aNamesList );
613 aNamesList->Append( aSectName );
614 aTypesList->Append( theSectionType );
615 aClosuresList->Append( theIsClosed );
620 TCollection_AsciiString HYDROData_PolylineXY::GetSectionName( const int theSectionIndex ) const
622 TCollection_AsciiString aResName;
624 Handle(TDataStd_ExtStringList) aNamesList;
625 Handle(TDataStd_IntegerList) aTypesList;
626 Handle(TDataStd_BooleanList) aClosuresList;
627 getSectionsLists( aNamesList, aTypesList, aClosuresList, false );
628 if ( aNamesList.IsNull() || theSectionIndex >= aNamesList->Extent() )
631 TDataStd_ListIteratorOfListOfExtendedString aNamesIter( aNamesList->List() );
632 for ( int i = 0; aNamesIter.More() && i != theSectionIndex; aNamesIter.Next(), ++i );
634 if ( aNamesIter.More() )
635 aResName = aNamesIter.Value();
640 void HYDROData_PolylineXY::SetSectionName( const int theSectionIndex,
641 const TCollection_AsciiString& theSectionName )
643 Handle(TDataStd_ExtStringList) aNamesList;
644 Handle(TDataStd_IntegerList) aTypesList;
645 Handle(TDataStd_BooleanList) aClosuresList;
646 getSectionsLists( aNamesList, aTypesList, aClosuresList, false );
647 if ( aNamesList.IsNull() || theSectionIndex >= aNamesList->Extent() )
650 TDataStd_ListOfExtendedString anOldNamesList;
651 anOldNamesList = aNamesList->List();
653 // Refill the existing list
656 TCollection_ExtendedString aNewSectName = theSectionName;
658 TDataStd_ListIteratorOfListOfExtendedString aNamesIter( anOldNamesList );
659 for ( int i = 0; aNamesIter.More(); aNamesIter.Next(), ++i )
660 aNamesList->Append( i == theSectionIndex ? aNewSectName : aNamesIter.Value() );
665 HYDROData_PolylineXY::SectionType HYDROData_PolylineXY::GetSectionType( const int theSectionIndex ) const
667 Handle(TDataStd_ExtStringList) aNamesList;
668 Handle(TDataStd_IntegerList) aTypesList;
669 Handle(TDataStd_BooleanList) aClosuresList;
670 getSectionsLists( aNamesList, aTypesList, aClosuresList, false );
671 if ( aTypesList.IsNull() || theSectionIndex >= aTypesList->Extent() )
672 return SECTION_POLYLINE;
674 TColStd_ListIteratorOfListOfInteger aTypesIter( aTypesList->List() );
675 for ( int i = 0; aTypesIter.More() && i != theSectionIndex; aTypesIter.Next(), ++i );
677 return aTypesIter.More() ? (SectionType)aTypesIter.Value() : SECTION_POLYLINE;
680 void HYDROData_PolylineXY::SetSectionType( const int theSectionIndex,
681 const SectionType theSectionType )
683 Handle(TDataStd_ExtStringList) aNamesList;
684 Handle(TDataStd_IntegerList) aTypesList;
685 Handle(TDataStd_BooleanList) aClosuresList;
686 getSectionsLists( aNamesList, aTypesList, aClosuresList, false );
687 if ( aTypesList.IsNull() || theSectionIndex >= aTypesList->Extent() )
690 TColStd_ListOfInteger anOldTypesList;
691 anOldTypesList = aTypesList->List();
693 // Refill the existing list
696 TColStd_ListIteratorOfListOfInteger aTypesIter( anOldTypesList );
697 for ( int i = 0; aTypesIter.More(); aTypesIter.Next(), ++i )
698 aTypesList->Append( i == theSectionIndex ? theSectionType : aTypesIter.Value() );
703 bool HYDROData_PolylineXY::IsClosedSection( const int theSectionIndex ) const
705 Handle(TDataStd_ExtStringList) aNamesList;
706 Handle(TDataStd_IntegerList) aTypesList;
707 Handle(TDataStd_BooleanList) aClosuresList;
708 getSectionsLists( aNamesList, aTypesList, aClosuresList, false );
709 if ( aClosuresList.IsNull() || theSectionIndex >= aClosuresList->Extent() )
712 TDataStd_ListIteratorOfListOfByte aClosuresIter( aClosuresList->List() );
713 for ( int i = 0; aClosuresIter.More() && i != theSectionIndex; aClosuresIter.Next(), ++i );
715 return aClosuresIter.More() ? (bool)aClosuresIter.Value() : false;
718 void HYDROData_PolylineXY::SetSectionClosed( const int theSectionIndex,
719 const bool theIsClosed )
721 Handle(TDataStd_ExtStringList) aNamesList;
722 Handle(TDataStd_IntegerList) aTypesList;
723 Handle(TDataStd_BooleanList) aClosuresList;
724 getSectionsLists( aNamesList, aTypesList, aClosuresList, false );
725 if ( aClosuresList.IsNull() || theSectionIndex >= aClosuresList->Extent() )
728 TDataStd_ListOfByte anOldClosuresList;
729 anOldClosuresList = aClosuresList->List();
731 // Refill the existing list
732 aClosuresList->Clear();
734 TDataStd_ListIteratorOfListOfByte aClosuresIter( anOldClosuresList );
735 for ( int i = 0; aClosuresIter.More(); aClosuresIter.Next(), ++i )
736 aClosuresList->Append( i == theSectionIndex ? theIsClosed : (bool)aClosuresIter.Value() );
741 void HYDROData_PolylineXY::GetSections( NCollection_Sequence<TCollection_AsciiString>& theSectNames,
742 NCollection_Sequence<SectionType>& theSectTypes,
743 NCollection_Sequence<bool>& theSectClosures ) const
745 theSectNames.Clear();
746 theSectTypes.Clear();
747 theSectClosures.Clear();
749 Handle(TDataStd_ExtStringList) aNamesList;
750 Handle(TDataStd_IntegerList) aTypesList;
751 Handle(TDataStd_BooleanList) aClosuresList;
752 getSectionsLists( aNamesList, aTypesList, aClosuresList, false );
753 if ( aNamesList.IsNull() || aTypesList.IsNull() || aClosuresList.IsNull() )
756 TDataStd_ListIteratorOfListOfExtendedString aNamesIter( aNamesList->List() );
757 TColStd_ListIteratorOfListOfInteger aTypesIter( aTypesList->List() );
758 TDataStd_ListIteratorOfListOfByte aClosuresIter( aClosuresList->List() );
759 for ( ; aNamesIter.More() && aTypesIter.More() && aClosuresIter.More();
760 aNamesIter.Next(), aTypesIter.Next(), aClosuresIter.Next() )
762 const TCollection_ExtendedString& aSectName = aNamesIter.Value();
763 SectionType aSectType = (SectionType)aTypesIter.Value();
764 bool aSectClosures = aClosuresIter.Value();
766 theSectNames.Append( aSectName );
767 theSectTypes.Append( aSectType );
768 theSectClosures.Append( aSectClosures );
772 void HYDROData_PolylineXY::RemoveSection( const int theSectionIndex )
774 Handle(TDataStd_ExtStringList) aNamesList;
775 Handle(TDataStd_IntegerList) aTypesList;
776 Handle(TDataStd_BooleanList) aClosuresList;
777 getSectionsLists( aNamesList, aTypesList, aClosuresList, false );
778 if ( aNamesList.IsNull() || theSectionIndex >= aNamesList->Extent() )
781 if ( aNamesList->Extent() == 1 )
783 removeSectionsLists();
788 TDataStd_ListOfExtendedString anOldNamesList;
789 anOldNamesList = aNamesList->List();
791 TColStd_ListOfInteger anOldTypesList;
792 anOldTypesList = aTypesList->List();
794 TDataStd_ListOfByte anOldClosuresList;
795 anOldClosuresList = aClosuresList->List();
797 // Refill the existing lists
800 aClosuresList->Clear();
802 TDataStd_ListIteratorOfListOfExtendedString aNamesIter( anOldNamesList );
803 TColStd_ListIteratorOfListOfInteger aTypesIter( anOldTypesList );
804 TDataStd_ListIteratorOfListOfByte aClosuresIter( anOldClosuresList );
805 for ( int i = 0; aNamesIter.More() && aTypesIter.More() && aClosuresIter.More();
806 aNamesIter.Next(), aTypesIter.Next(), aClosuresIter.Next(), ++i )
808 if ( i == theSectionIndex )
809 continue; // skip index to remove
811 aNamesList->Append( aNamesIter.Value() );
812 aTypesList->Append( aTypesIter.Value() );
813 aClosuresList->Append( (bool)aClosuresIter.Value() );
816 // Remove points that belongs to removed section
817 removePointsLists( theSectionIndex );
823 void HYDROData_PolylineXY::RemoveSections()
825 removeSectionsLists();
830 void HYDROData_PolylineXY::AddPoint( const int theSectionIndex,
831 const Point& thePoint,
832 const int thePointIndex )
834 Handle(TDataStd_RealList) aListX, aListY;
835 getPointsLists( theSectionIndex, aListX, aListY );
837 if ( thePointIndex < 0 || thePointIndex >= aListX->Extent() )
839 aListX->Append( thePoint.X() );
840 aListY->Append( thePoint.Y() );
844 TColStd_ListOfReal anOldListX;
845 anOldListX = aListX->List();
847 TColStd_ListOfReal anOldListY;
848 anOldListY = aListY->List();
850 // Refill the existing lists
854 TColStd_ListIteratorOfListOfReal anIterX( anOldListX );
855 TColStd_ListIteratorOfListOfReal anIterY( anOldListY );
856 for ( int i = 0; anIterX.More() && anIterY.More(); anIterX.Next(), anIterY.Next(), ++i )
858 double aCoordX = anIterX.Value();
859 double aCoordY = anIterY.Value();
861 if ( i == thePointIndex )
863 // Insert our new point
864 aListX->Append( thePoint.X() );
865 aListY->Append( thePoint.Y() );
868 aListX->Append( aCoordX );
869 aListY->Append( aCoordY );
876 void HYDROData_PolylineXY::SetPoint( const int theSectionIndex,
877 const Point& thePoint,
878 const int thePointIndex )
880 Handle(TDataStd_RealList) aListX, aListY;
881 getPointsLists( theSectionIndex, aListX, aListY );
883 if ( thePointIndex < 0 )
885 aListX->Prepend( thePoint.X() );
886 aListY->Prepend( thePoint.Y() );
888 else if ( thePointIndex >= aListX->Extent() )
890 aListX->Append( thePoint.X() );
891 aListY->Append( thePoint.Y() );
895 TColStd_ListOfReal anOldListX;
896 anOldListX = aListX->List();
898 TColStd_ListOfReal anOldListY;
899 anOldListY = aListY->List();
901 // Refill the existing lists
905 TColStd_ListIteratorOfListOfReal anIterX( anOldListX );
906 TColStd_ListIteratorOfListOfReal anIterY( anOldListY );
907 for ( int i = 0; anIterX.More() && anIterY.More(); anIterX.Next(), anIterY.Next(), ++i )
909 double aCoordX = anIterX.Value();
910 double aCoordY = anIterY.Value();
912 if ( i == thePointIndex )
914 // Insert our new point instead of old one
915 aCoordX = thePoint.X();
916 aCoordY = thePoint.Y();
919 aListX->Append( aCoordX );
920 aListY->Append( aCoordY );
927 void HYDROData_PolylineXY::SetPoints( const int theSectionIndex,
928 const PointsList& thePoints )
930 Handle(TDataStd_RealList) aListX, aListY;
931 getPointsLists( theSectionIndex, aListX, aListY );
936 for ( int i = 1, n = thePoints.Length(); i <= n; ++i )
938 const Point& aPoint = thePoints.Value( i );
939 aListX->Append( aPoint.X() );
940 aListY->Append( aPoint.Y() );
944 void HYDROData_PolylineXY::RemovePoint( const int theSectionIndex,
945 const int thePointIndex )
947 Handle(TDataStd_RealList) aListX, aListY;
948 getPointsLists( theSectionIndex, aListX, aListY, false );
949 if ( aListX.IsNull() || aListY.IsNull() || aListX->IsEmpty() )
952 if ( aListX->Extent() == 1 )
954 removePointsLists( theSectionIndex );
958 TColStd_ListOfReal anOldListX;
959 anOldListX = aListX->List();
961 TColStd_ListOfReal anOldListY;
962 anOldListY = aListY->List();
964 // Refill the existing lists
968 TColStd_ListIteratorOfListOfReal anIterX( anOldListX );
969 TColStd_ListIteratorOfListOfReal anIterY( anOldListY );
970 for ( int i = 0; anIterX.More() && anIterY.More(); anIterX.Next(), anIterY.Next(), ++i )
972 if ( i == thePointIndex )
973 continue; // skip index to remove
975 aListX->Append( anIterX.Value() );
976 aListY->Append( anIterY.Value() );
983 HYDROData_PolylineXY::PointsList HYDROData_PolylineXY::GetPoints( const int theSectionIndex ) const
987 Handle(TDataStd_RealList) aListX, aListY;
988 getPointsLists( theSectionIndex, aListX, aListY, false );
989 if ( aListX.IsNull() || aListY.IsNull() || aListX->IsEmpty() )
992 TColStd_ListIteratorOfListOfReal anIterX( aListX->List() );
993 TColStd_ListIteratorOfListOfReal anIterY( aListY->List() );
994 for ( ; anIterX.More() && anIterY.More(); anIterX.Next(), anIterY.Next() )
996 Point aPoint( anIterX.Value(), anIterY.Value() );
997 aResList.Append( aPoint );
1003 QPainterPath HYDROData_PolylineXY::GetPainterPath() const
1007 NCollection_Sequence<TCollection_AsciiString> aSectNames;
1008 NCollection_Sequence<HYDROData_PolylineXY::SectionType> aSectTypes;
1009 NCollection_Sequence<bool> aSectClosures;
1010 GetSections( aSectNames, aSectTypes, aSectClosures );
1012 for ( int aSectionId = 1, aNbSects = aSectNames.Size(); aSectionId <= aNbSects; aSectionId++ )
1014 TCollection_AsciiString aSectName = aSectNames.Value( aSectionId );
1015 SectionType aSectionType = aSectTypes.Value( aSectionId );
1016 bool anIsSectionClosed = aSectClosures.Value( aSectionId );
1018 PointsList aSectPointsList = GetPoints( aSectionId - 1 );
1019 if ( aSectPointsList.IsEmpty() )
1022 NCollection_Sequence<gp_XYZ> aPoints;
1023 for( int i = 1, n = aSectPointsList.Size(); i <= n; ++i )
1025 const Point& aSectPoint = aSectPointsList.Value( i );
1027 gp_XYZ aPoint( aSectPoint.X(), aSectPoint.Y(), 0.0 );
1028 aPoints.Append( aPoint );
1031 BuildPainterPath( aPath, aSectionType, anIsSectionClosed, aPoints );