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 const double LOCAL_SELECTION_TOLERANCE = 0.0001;
61 TCollection_AsciiString getUniqueSectionName( const NCollection_Sequence<TCollection_AsciiString>& theNamesSeq )
63 NCollection_Map<TCollection_AsciiString> aNamesMap;
65 for ( int i = 1, n = theNamesSeq.Size(); i <= n; ++i )
67 const TCollection_AsciiString& aSectName = theNamesSeq.Value( i );
68 aNamesMap.Add( aSectName );
71 TCollection_AsciiString aResName;
76 aResName = TCollection_AsciiString( "Section_" ) + aPrefIdx;
79 while ( aNamesMap.Contains( aResName ) );
84 TCollection_AsciiString getUniqueSectionName( const Handle(TDataStd_ExtStringList)& theNamesList )
86 NCollection_Sequence<TCollection_AsciiString> aNamesSeq;
88 TDataStd_ListIteratorOfListOfExtendedString aNamesIter( theNamesList->List() );
89 for ( ; aNamesIter.More(); aNamesIter.Next() )
90 aNamesSeq.Append( aNamesIter.Value() );
92 return getUniqueSectionName( aNamesSeq );
95 IMPLEMENT_STANDARD_HANDLE(HYDROData_PolylineXY, HYDROData_IPolyline)
96 IMPLEMENT_STANDARD_RTTIEXT(HYDROData_PolylineXY, HYDROData_IPolyline)
98 HYDROData_PolylineXY::HYDROData_PolylineXY()
99 : HYDROData_IPolyline()
103 HYDROData_PolylineXY::~HYDROData_PolylineXY()
107 QStringList HYDROData_PolylineXY::DumpToPython( MapOfTreatedObjects& theTreatedObjects ) const
109 QStringList aResList = HYDROData_Entity::DumpToPython( theTreatedObjects );
110 QString aPolylineName = GetName();
113 NCollection_Sequence<TCollection_AsciiString> aSectNames;
114 NCollection_Sequence<HYDROData_PolylineXY::SectionType> aSectTypes;
115 NCollection_Sequence<bool> aSectClosures;
116 GetSections( aSectNames, aSectTypes, aSectClosures );
118 for ( int i = 1, n = aSectNames.Size(); i <= n; ++i )
120 const TCollection_AsciiString& aSectName = aSectNames.Value( i );
121 const SectionType& aSectType = aSectTypes.Value( i );
122 bool aSectClosure = aSectClosures.Value( i );
124 aResList << QString( "%1.AddSection( \"%2\", %3, %4 );" ).arg( aPolylineName )
125 .arg( aSectName.ToCString() ).arg( aSectType ).arg( aSectClosure );
127 HYDROData_PolylineXY::PointsList aSectPointsList = GetPoints( i );
128 for ( int k = 1, aNbPoints = aSectPointsList.Size(); k <= aNbPoints; ++k )
130 const Point& aSectPoint = aSectPointsList.Value( k );
132 aResList << QString( "%1.AddPoint( %2, QPointF( %3, %4 ) );" ).arg( aPolylineName )
133 .arg( i - 1 ).arg( aSectPoint.X() ).arg( aSectPoint.Y() );
140 QVariant HYDROData_PolylineXY::GetDataVariant()
142 QPainterPath aPath = GetPainterPath();
145 aVarData.setValue<QPainterPath>( aPath );
150 QColor HYDROData_PolylineXY::DefaultWireColor()
152 return QColor( Qt::red );
155 TopoDS_Shape HYDROData_PolylineXY::GetShape() const
157 return getPolylineShape();
160 bool convertEdgeToSection( const TopoDS_Edge& theEdge,
161 NCollection_Sequence<TCollection_AsciiString>& theSectNames,
162 NCollection_Sequence<HYDROData_PolylineXY::SectionType>& theSectTypes,
163 NCollection_Sequence<bool>& theSectClosures,
164 NCollection_Sequence<HYDROData_PolylineXY::PointsList>& theSectPoints,
165 const bool theIsCanBeClosed )
167 Standard_Real aFirst = 0.0, aLast = 0.0;
168 Handle(Geom_Curve) anEdgeGeomCurve = BRep_Tool::Curve( theEdge, aFirst, aLast );
169 if ( anEdgeGeomCurve.IsNull() )
172 TCollection_AsciiString aSectName = getUniqueSectionName( theSectNames );
173 bool anIsEdgeClosed = anEdgeGeomCurve->IsClosed();
175 HYDROData_PolylineXY::SectionType aSectionType = HYDROData_PolylineXY::SECTION_POLYLINE;
176 HYDROData_PolylineXY::PointsList aPointsList;
178 if ( anEdgeGeomCurve->IsKind( STANDARD_TYPE(Geom_Line) ) )
180 Handle(Geom_Line) aGeomLine = Handle(Geom_Line)::DownCast( anEdgeGeomCurve );
182 gp_Pnt aFirstPoint, aLastPoint;
183 aGeomLine->D0( aFirst, aFirstPoint );
184 aGeomLine->D0( aLast, aLastPoint );
186 HYDROData_PolylineXY::Point aSectFirstPoint( aFirstPoint.X(), aFirstPoint.Y() );
187 aPointsList.Append( aSectFirstPoint );
189 HYDROData_PolylineXY::Point aSectLastPoint( aLastPoint.X(), aLastPoint.Y() );
190 aPointsList.Append( aSectLastPoint );
192 else if ( anEdgeGeomCurve->IsKind( STANDARD_TYPE(Geom_BSplineCurve) ) )
194 aSectionType = HYDROData_PolylineXY::SECTION_SPLINE;
196 Handle(Geom_BSplineCurve) aGeomSpline =
197 Handle(Geom_BSplineCurve)::DownCast( anEdgeGeomCurve );
199 int aNbKnots = aGeomSpline->NbKnots();
201 TColStd_Array1OfReal aSplineKnots( 1, aNbKnots );
202 aGeomSpline->Knots( aSplineKnots );
204 // Decrease the number of imported knots because of last one
205 // knot is the closing point which are the start point
206 if ( anIsEdgeClosed ) aNbKnots--;
208 for ( int i = 1; i <= aNbKnots; ++i )
210 const Standard_Real& aKnot = aSplineKnots.Value( i );
213 aGeomSpline->D0( aKnot, aPoint );
215 HYDROData_PolylineXY::Point aSectPoint( aPoint.X(), aPoint.Y() );
216 aPointsList.Append( aSectPoint );
221 // Other curve types are not supported
225 if ( aPointsList.IsEmpty() )
228 theSectNames.Append( aSectName );
229 theSectTypes.Append( aSectionType );
230 theSectClosures.Append( anIsEdgeClosed );
231 theSectPoints.Append( aPointsList );
236 bool HYDROData_PolylineXY::ImportShape( const TopoDS_Shape& theShape )
238 if ( theShape.IsNull() )
243 bool anIsCanBeImported = false;
245 NCollection_Sequence<TCollection_AsciiString> aSectNames;
246 NCollection_Sequence<SectionType> aSectTypes;
247 NCollection_Sequence<bool> aSectClosures;
248 NCollection_Sequence<PointsList> aSectPoints;
250 if ( theShape.ShapeType() == TopAbs_EDGE )
252 TopoDS_Edge anEdge = TopoDS::Edge( theShape );
253 anIsCanBeImported = convertEdgeToSection( anEdge, aSectNames, aSectTypes, aSectClosures, aSectPoints, true );
255 else if ( theShape.ShapeType() == TopAbs_WIRE )
257 TopTools_SequenceOfShape anEdges;
258 HYDROData_ShapesTool::ExploreShapeToShapes( theShape, TopAbs_EDGE, anEdges );
260 anIsCanBeImported = !anEdges.IsEmpty();
261 for ( int i = 1, n = anEdges.Length(); i <= n && anIsCanBeImported; ++i )
263 TopoDS_Edge aWireEdge = TopoDS::Edge( anEdges.Value( i ) );
264 anIsCanBeImported = convertEdgeToSection( aWireEdge, aSectNames, aSectTypes, aSectClosures, aSectPoints, false );
268 if ( anIsCanBeImported )
270 for ( int i = 1, n = aSectNames.Length(); i <= n; ++i )
272 const TCollection_AsciiString& aSectName = aSectNames.Value( i );
273 const SectionType& aSectType = aSectTypes.Value( i );
274 bool anIsSectionClosed = aSectClosures.Value( i );
275 const PointsList& aSectPointsList = aSectPoints( i );
277 AddSection( aSectName, aSectType, anIsSectionClosed );
278 SetPoints( i - 1, aSectPointsList );
283 TopoDS_Shape aShape = theShape;
285 if ( theShape.ShapeType() == TopAbs_EDGE )
287 // We make the wire from incoming edge because of other algorithms
288 // are waiting at least the wire from polyline
289 TopoDS_Edge anEdge = TopoDS::Edge( theShape );
290 BRepBuilderAPI_MakeWire aMakeWire( anEdge );
292 if ( aMakeWire.IsDone() )
293 aShape = aMakeWire.Wire();
296 gp_Pln aPlane( gp_Pnt( 0, 0, 0 ), gp_Dir( 0, 0, 1 ) );
297 BRepBuilderAPI_MakeFace aMakeFace( aPlane );
299 BRepOffsetAPI_NormalProjection aProj( aMakeFace.Face() );
302 TopoDS_Shape aResult;
304 aResult = aProj.Shape();
306 setPolylineShape( aResult );
309 setEditable( anIsCanBeImported );
314 TopoDS_Wire HYDROData_PolylineXY::BuildWire( const SectionType& theType,
315 const bool& theIsClosed,
316 const NCollection_Sequence<gp_XYZ>& thePoints )
319 if( theType == SECTION_POLYLINE )
321 BRepBuilderAPI_MakePolygon aMakeWire;
322 for ( int i = 1, n = thePoints.Length(); i <= n ; ++i )
324 gp_XYZ aPoint = thePoints.Value( i );
325 gp_Pnt aPnt( aPoint.X(), aPoint.Y(), aPoint.Z() );
326 aMakeWire.Add( aPnt );
331 if ( aMakeWire.IsDone() )
332 aWire = aMakeWire.Wire();
334 else //if( theType == PolylineSection::SECTION_SPLINE )
336 BRepBuilderAPI_MakeWire aMakeWire;
338 if ( thePoints.Size() > 1 )
340 HYDROData_BSplineOperation aBSpline( thePoints, theIsClosed, LOCAL_SELECTION_TOLERANCE );
342 TopoDS_Edge anEdge = BRepBuilderAPI_MakeEdge( aBSpline.Curve() ).Edge();
343 aMakeWire.Add( anEdge );
346 if ( aMakeWire.IsDone() )
353 void HYDROData_PolylineXY::BuildPainterPath( QPainterPath& thePath,
354 const SectionType& theType,
355 const bool& theIsClosed,
356 const NCollection_Sequence<gp_XYZ>& thePoints )
358 if ( thePoints.IsEmpty() )
361 if ( theType == SECTION_POLYLINE )
363 const gp_XYZ& aFirstPoint = thePoints.Value( 1 );
364 thePath.moveTo( aFirstPoint.X(), aFirstPoint.Y() );
366 for( int i = 2, n = thePoints.Size(); i <= n; ++i )
368 const gp_XYZ& aSectPoint = thePoints.Value( i );
370 thePath.lineTo( aSectPoint.X(), aSectPoint.Y() );
374 thePath.closeSubpath();
378 HYDROData_BSplineOperation aBSpline( thePoints, theIsClosed, LOCAL_SELECTION_TOLERANCE );
379 aBSpline.ComputePath( thePath );
383 void HYDROData_PolylineXY::Update()
387 // If polyline is not editable we no need to update it wire
388 SetToUpdate( false );
392 HYDROData_IPolyline::Update();
394 NCollection_Sequence<TCollection_AsciiString> aSectNames;
395 NCollection_Sequence<HYDROData_PolylineXY::SectionType> aSectTypes;
396 NCollection_Sequence<bool> aSectClosures;
397 GetSections( aSectNames, aSectTypes, aSectClosures );
399 BRepBuilderAPI_MakeWire aMakeWire;
401 TopTools_ListOfShape aSectionWiresList;
403 for ( int aSectionId = 1, aNbSects = aSectNames.Size(); aSectionId <= aNbSects; aSectionId++ )
405 TCollection_AsciiString aSectName = aSectNames.Value( aSectionId );
406 SectionType aSectionType = aSectTypes.Value( aSectionId );
407 bool anIsSectionClosed = aSectClosures.Value( aSectionId );
409 PointsList aSectPointsList = GetPoints( aSectionId - 1 );
410 if ( aSectPointsList.IsEmpty() )
413 NCollection_Sequence<gp_XYZ> aPoints;
414 for( int i = 1, n = aSectPointsList.Size(); i <= n; ++i )
416 const Point& aSectPoint = aSectPointsList.Value( i );
418 gp_XYZ aPoint( aSectPoint.X(), aSectPoint.Y(), 0.0 );
419 aPoints.Append( aPoint );
422 TopoDS_Wire aSectionWire = BuildWire( aSectionType, anIsSectionClosed, aPoints );
423 if ( !aSectionWire.IsNull() ) {
424 aSectionWiresList.Append( aSectionWire );
425 aMakeWire.Add( aSectionWire );
428 // all input wires in the <aSectionWiresList>
429 Handle(TopTools_HSequenceOfShape) aSeqWires = new TopTools_HSequenceOfShape;
430 Handle(TopTools_HSequenceOfShape) aSeqEdges = new TopTools_HSequenceOfShape;
431 TopTools_ListIteratorOfListOfShape it(aSectionWiresList);
432 for(;it.More();it.Next())
434 TopExp_Explorer it2(it.Value(), TopAbs_EDGE);
435 for(;it2.More();it2.Next())
436 aSeqEdges->Append(it2.Current());
440 TopoDS_Compound aCmp;
441 TopoDS_Shape aResult;
442 aBB.MakeCompound(aCmp);
443 if(aSeqEdges->Length() >1)
445 ShapeAnalysis_FreeBounds::ConnectEdgesToWires(aSeqEdges,1E-5,Standard_False,aSeqWires);
447 if( aSeqWires->Length()==1 )
448 aResult = aSeqWires->Value( 1 );
451 for (Standard_Integer i = 1; i <= aSeqWires->Length();i++)
453 const TopoDS_Shape& aS1 = aSeqWires->Value(i);
459 else if (aSeqEdges->Length() == 1)
461 BRepBuilderAPI_MakeWire mkWire (TopoDS::Edge(aSeqEdges->Value(1)));
463 aResult = mkWire.Wire();
466 setPolylineShape( aResult );
469 bool HYDROData_PolylineXY::IsEditable() const
471 return !myLab.IsAttribute( GUID_IS_UNEDITABLE );
474 void HYDROData_PolylineXY::setEditable( const bool theIsEditable )
476 if ( !theIsEditable )
477 TDataStd_UAttribute::Set( myLab, GUID_IS_UNEDITABLE );
479 myLab.ForgetAttribute( GUID_IS_UNEDITABLE );
483 * Returns true if polyline is closed
485 bool HYDROData_PolylineXY::IsClosed( const bool theIsSimpleCheck ) const
487 bool anIsClosed = false;
489 TopoDS_Shape aShape = GetShape();
490 if ( aShape.IsNull() )
493 TopTools_SequenceOfShape aWires;
494 HYDROData_ShapesTool::ExploreShapeToShapes( aShape, TopAbs_WIRE, aWires );
496 int aNbWires = aWires.Length();
497 if ( theIsSimpleCheck )
499 anIsClosed = aNbWires > 0;
500 for ( int i = 1; i <= aNbWires && anIsClosed; ++i )
502 const TopoDS_Shape& aWire = aWires.Value( i );
503 anIsClosed = BRep_Tool::IsClosed( aWire );
508 anIsClosed = aNbWires == 1 && BRep_Tool::IsClosed( aWires.First() );
514 double HYDROData_PolylineXY::GetDistance( const int theSectionIndex,
515 const int thePointIndex ) const
517 double aResDistance = -1;
518 if ( theSectionIndex < 0 || theSectionIndex >= NbSections() )
521 if ( thePointIndex == 0 )
524 SectionType aSectionType = GetSectionType( theSectionIndex );
525 bool anIsSectionClosed = IsClosedSection( theSectionIndex );
526 PointsList aSectPointsList = GetPoints( theSectionIndex );
527 if ( thePointIndex < 0 || thePointIndex >= aSectPointsList.Size() )
530 if ( aSectionType == SECTION_POLYLINE )
534 Point aPrevPoint = aSectPointsList.Value( 1 );
535 for ( int i = 2, aNbPoints = aSectPointsList.Size(); i <= aNbPoints; ++i )
537 const Point& aSectPoint = aSectPointsList.Value( i );
538 aResDistance += gp_Pnt2d( aPrevPoint ).Distance( aSectPoint );
539 aPrevPoint = aSectPoint;
541 if ( thePointIndex == i - 1 )
549 int aSectNbPoints = aSectPointsList.Size();
550 NCollection_Sequence<gp_XYZ> aPoints;
551 for( int i = 1 ; i <= aSectNbPoints; ++i )
553 const Point& aSectPoint = aSectPointsList.Value( i );
555 gp_XYZ aPoint( aSectPoint.X(), aSectPoint.Y(), 0.0 );
556 aPoints.Append( aPoint );
558 if ( thePointIndex == i - 1 )
559 aPointToTest = aPoint;
562 HYDROData_BSplineOperation aBSpline( aPoints, anIsSectionClosed, LOCAL_SELECTION_TOLERANCE );
564 Quantity_Parameter aFirstParam = aBSpline.Curve()->FirstParameter();
565 Quantity_Parameter aSecondParam = aBSpline.Curve()->LastParameter();
567 if ( thePointIndex != aSectNbPoints - 1 )
569 GeomAPI_ProjectPointOnCurve aProject( aPointToTest, aBSpline.Curve() );
570 aSecondParam = aProject.LowerDistanceParameter();
573 GeomAdaptor_Curve anAdap( aBSpline.Curve() );
575 aResDistance = GCPnts_AbscissaPoint::Length( anAdap, aFirstParam, aSecondParam );
581 int HYDROData_PolylineXY::NbSections() const
583 Handle(TDataStd_ExtStringList) aNamesList;
584 Handle(TDataStd_IntegerList) aTypesList;
585 Handle(TDataStd_BooleanList) aClosuresList;
586 getSectionsLists( aNamesList, aTypesList, aClosuresList, false );
588 return !aClosuresList.IsNull() ? aClosuresList->Extent() : 0;
591 void HYDROData_PolylineXY::AddSection( const TCollection_AsciiString& theSectName,
592 const SectionType theSectionType,
593 const bool theIsClosed )
595 Handle(TDataStd_ExtStringList) aNamesList;
596 Handle(TDataStd_IntegerList) aTypesList;
597 Handle(TDataStd_BooleanList) aClosuresList;
598 getSectionsLists( aNamesList, aTypesList, aClosuresList );
600 TCollection_ExtendedString aSectName( theSectName );
601 if ( aSectName.Length() <= 0 )
602 aSectName = getUniqueSectionName( aNamesList );
604 aNamesList->Append( aSectName );
605 aTypesList->Append( theSectionType );
606 aClosuresList->Append( theIsClosed );
611 TCollection_AsciiString HYDROData_PolylineXY::GetSectionName( const int theSectionIndex ) const
613 TCollection_AsciiString aResName;
615 Handle(TDataStd_ExtStringList) aNamesList;
616 Handle(TDataStd_IntegerList) aTypesList;
617 Handle(TDataStd_BooleanList) aClosuresList;
618 getSectionsLists( aNamesList, aTypesList, aClosuresList, false );
619 if ( aNamesList.IsNull() || theSectionIndex >= aNamesList->Extent() )
622 TDataStd_ListIteratorOfListOfExtendedString aNamesIter( aNamesList->List() );
623 for ( int i = 0; aNamesIter.More() && i != theSectionIndex; aNamesIter.Next(), ++i );
625 if ( aNamesIter.More() )
626 aResName = aNamesIter.Value();
631 void HYDROData_PolylineXY::SetSectionName( const int theSectionIndex,
632 const TCollection_AsciiString& theSectionName )
634 Handle(TDataStd_ExtStringList) aNamesList;
635 Handle(TDataStd_IntegerList) aTypesList;
636 Handle(TDataStd_BooleanList) aClosuresList;
637 getSectionsLists( aNamesList, aTypesList, aClosuresList, false );
638 if ( aNamesList.IsNull() || theSectionIndex >= aNamesList->Extent() )
641 TDataStd_ListOfExtendedString anOldNamesList;
642 anOldNamesList = aNamesList->List();
644 // Refill the existing list
647 TCollection_ExtendedString aNewSectName = theSectionName;
649 TDataStd_ListIteratorOfListOfExtendedString aNamesIter( anOldNamesList );
650 for ( int i = 0; aNamesIter.More(); aNamesIter.Next(), ++i )
651 aNamesList->Append( i == theSectionIndex ? aNewSectName : aNamesIter.Value() );
656 HYDROData_PolylineXY::SectionType HYDROData_PolylineXY::GetSectionType( const int theSectionIndex ) const
658 Handle(TDataStd_ExtStringList) aNamesList;
659 Handle(TDataStd_IntegerList) aTypesList;
660 Handle(TDataStd_BooleanList) aClosuresList;
661 getSectionsLists( aNamesList, aTypesList, aClosuresList, false );
662 if ( aTypesList.IsNull() || theSectionIndex >= aTypesList->Extent() )
663 return SECTION_POLYLINE;
665 TColStd_ListIteratorOfListOfInteger aTypesIter( aTypesList->List() );
666 for ( int i = 0; aTypesIter.More() && i != theSectionIndex; aTypesIter.Next(), ++i );
668 return aTypesIter.More() ? (SectionType)aTypesIter.Value() : SECTION_POLYLINE;
671 void HYDROData_PolylineXY::SetSectionType( const int theSectionIndex,
672 const SectionType theSectionType )
674 Handle(TDataStd_ExtStringList) aNamesList;
675 Handle(TDataStd_IntegerList) aTypesList;
676 Handle(TDataStd_BooleanList) aClosuresList;
677 getSectionsLists( aNamesList, aTypesList, aClosuresList, false );
678 if ( aTypesList.IsNull() || theSectionIndex >= aTypesList->Extent() )
681 TColStd_ListOfInteger anOldTypesList;
682 anOldTypesList = aTypesList->List();
684 // Refill the existing list
687 TColStd_ListIteratorOfListOfInteger aTypesIter( anOldTypesList );
688 for ( int i = 0; aTypesIter.More(); aTypesIter.Next(), ++i )
689 aTypesList->Append( i == theSectionIndex ? theSectionType : aTypesIter.Value() );
694 bool HYDROData_PolylineXY::IsClosedSection( const int theSectionIndex ) const
696 Handle(TDataStd_ExtStringList) aNamesList;
697 Handle(TDataStd_IntegerList) aTypesList;
698 Handle(TDataStd_BooleanList) aClosuresList;
699 getSectionsLists( aNamesList, aTypesList, aClosuresList, false );
700 if ( aClosuresList.IsNull() || theSectionIndex >= aClosuresList->Extent() )
703 TDataStd_ListIteratorOfListOfByte aClosuresIter( aClosuresList->List() );
704 for ( int i = 0; aClosuresIter.More() && i != theSectionIndex; aClosuresIter.Next(), ++i );
706 return aClosuresIter.More() ? (bool)aClosuresIter.Value() : false;
709 void HYDROData_PolylineXY::SetSectionClosed( const int theSectionIndex,
710 const bool theIsClosed )
712 Handle(TDataStd_ExtStringList) aNamesList;
713 Handle(TDataStd_IntegerList) aTypesList;
714 Handle(TDataStd_BooleanList) aClosuresList;
715 getSectionsLists( aNamesList, aTypesList, aClosuresList, false );
716 if ( aClosuresList.IsNull() || theSectionIndex >= aClosuresList->Extent() )
719 TDataStd_ListOfByte anOldClosuresList;
720 anOldClosuresList = aClosuresList->List();
722 // Refill the existing list
723 aClosuresList->Clear();
725 TDataStd_ListIteratorOfListOfByte aClosuresIter( anOldClosuresList );
726 for ( int i = 0; aClosuresIter.More(); aClosuresIter.Next(), ++i )
727 aClosuresList->Append( i == theSectionIndex ? theIsClosed : (bool)aClosuresIter.Value() );
732 void HYDROData_PolylineXY::GetSections( NCollection_Sequence<TCollection_AsciiString>& theSectNames,
733 NCollection_Sequence<SectionType>& theSectTypes,
734 NCollection_Sequence<bool>& theSectClosures ) const
736 theSectNames.Clear();
737 theSectTypes.Clear();
738 theSectClosures.Clear();
740 Handle(TDataStd_ExtStringList) aNamesList;
741 Handle(TDataStd_IntegerList) aTypesList;
742 Handle(TDataStd_BooleanList) aClosuresList;
743 getSectionsLists( aNamesList, aTypesList, aClosuresList, false );
744 if ( aNamesList.IsNull() || aTypesList.IsNull() || aClosuresList.IsNull() )
747 TDataStd_ListIteratorOfListOfExtendedString aNamesIter( aNamesList->List() );
748 TColStd_ListIteratorOfListOfInteger aTypesIter( aTypesList->List() );
749 TDataStd_ListIteratorOfListOfByte aClosuresIter( aClosuresList->List() );
750 for ( ; aNamesIter.More() && aTypesIter.More() && aClosuresIter.More();
751 aNamesIter.Next(), aTypesIter.Next(), aClosuresIter.Next() )
753 const TCollection_ExtendedString& aSectName = aNamesIter.Value();
754 SectionType aSectType = (SectionType)aTypesIter.Value();
755 bool aSectClosures = aClosuresIter.Value();
757 theSectNames.Append( aSectName );
758 theSectTypes.Append( aSectType );
759 theSectClosures.Append( aSectClosures );
763 void HYDROData_PolylineXY::RemoveSection( const int theSectionIndex )
765 Handle(TDataStd_ExtStringList) aNamesList;
766 Handle(TDataStd_IntegerList) aTypesList;
767 Handle(TDataStd_BooleanList) aClosuresList;
768 getSectionsLists( aNamesList, aTypesList, aClosuresList, false );
769 if ( aNamesList.IsNull() || theSectionIndex >= aNamesList->Extent() )
772 if ( aNamesList->Extent() == 1 )
774 removeSectionsLists();
779 TDataStd_ListOfExtendedString anOldNamesList;
780 anOldNamesList = aNamesList->List();
782 TColStd_ListOfInteger anOldTypesList;
783 anOldTypesList = aTypesList->List();
785 TDataStd_ListOfByte anOldClosuresList;
786 anOldClosuresList = aClosuresList->List();
788 // Refill the existing lists
791 aClosuresList->Clear();
793 TDataStd_ListIteratorOfListOfExtendedString aNamesIter( anOldNamesList );
794 TColStd_ListIteratorOfListOfInteger aTypesIter( anOldTypesList );
795 TDataStd_ListIteratorOfListOfByte aClosuresIter( anOldClosuresList );
796 for ( int i = 0; aNamesIter.More() && aTypesIter.More() && aClosuresIter.More();
797 aNamesIter.Next(), aTypesIter.Next(), aClosuresIter.Next(), ++i )
799 if ( i == theSectionIndex )
800 continue; // skip index to remove
802 aNamesList->Append( aNamesIter.Value() );
803 aTypesList->Append( aTypesIter.Value() );
804 aClosuresList->Append( (bool)aClosuresIter.Value() );
807 // Remove points that belongs to removed section
808 removePointsLists( theSectionIndex );
814 void HYDROData_PolylineXY::RemoveSections()
816 removeSectionsLists();
821 void HYDROData_PolylineXY::AddPoint( const int theSectionIndex,
822 const Point& thePoint,
823 const int thePointIndex )
825 Handle(TDataStd_RealList) aListX, aListY;
826 getPointsLists( theSectionIndex, aListX, aListY );
828 if ( thePointIndex < 0 || thePointIndex >= aListX->Extent() )
830 aListX->Append( thePoint.X() );
831 aListY->Append( thePoint.Y() );
835 TColStd_ListOfReal anOldListX;
836 anOldListX = aListX->List();
838 TColStd_ListOfReal anOldListY;
839 anOldListY = aListY->List();
841 // Refill the existing lists
845 TColStd_ListIteratorOfListOfReal anIterX( anOldListX );
846 TColStd_ListIteratorOfListOfReal anIterY( anOldListY );
847 for ( int i = 0; anIterX.More() && anIterY.More(); anIterX.Next(), anIterY.Next(), ++i )
849 double aCoordX = anIterX.Value();
850 double aCoordY = anIterY.Value();
852 if ( i == thePointIndex )
854 // Insert our new point
855 aListX->Append( thePoint.X() );
856 aListY->Append( thePoint.Y() );
859 aListX->Append( aCoordX );
860 aListY->Append( aCoordY );
867 void HYDROData_PolylineXY::SetPoint( const int theSectionIndex,
868 const Point& thePoint,
869 const int thePointIndex )
871 Handle(TDataStd_RealList) aListX, aListY;
872 getPointsLists( theSectionIndex, aListX, aListY );
874 if ( thePointIndex < 0 )
876 aListX->Prepend( thePoint.X() );
877 aListY->Prepend( thePoint.Y() );
879 else if ( thePointIndex >= aListX->Extent() )
881 aListX->Append( thePoint.X() );
882 aListY->Append( thePoint.Y() );
886 TColStd_ListOfReal anOldListX;
887 anOldListX = aListX->List();
889 TColStd_ListOfReal anOldListY;
890 anOldListY = aListY->List();
892 // Refill the existing lists
896 TColStd_ListIteratorOfListOfReal anIterX( anOldListX );
897 TColStd_ListIteratorOfListOfReal anIterY( anOldListY );
898 for ( int i = 0; anIterX.More() && anIterY.More(); anIterX.Next(), anIterY.Next(), ++i )
900 double aCoordX = anIterX.Value();
901 double aCoordY = anIterY.Value();
903 if ( i == thePointIndex )
905 // Insert our new point instead of old one
906 aCoordX = thePoint.X();
907 aCoordY = thePoint.Y();
910 aListX->Append( aCoordX );
911 aListY->Append( aCoordY );
918 void HYDROData_PolylineXY::SetPoints( const int theSectionIndex,
919 const PointsList& thePoints )
921 Handle(TDataStd_RealList) aListX, aListY;
922 getPointsLists( theSectionIndex, aListX, aListY );
927 for ( int i = 1, n = thePoints.Length(); i <= n; ++i )
929 const Point& aPoint = thePoints.Value( i );
930 aListX->Append( aPoint.X() );
931 aListY->Append( aPoint.Y() );
935 void HYDROData_PolylineXY::RemovePoint( const int theSectionIndex,
936 const int thePointIndex )
938 Handle(TDataStd_RealList) aListX, aListY;
939 getPointsLists( theSectionIndex, aListX, aListY, false );
940 if ( aListX.IsNull() || aListY.IsNull() || aListX->IsEmpty() )
943 if ( aListX->Extent() == 1 )
945 removePointsLists( theSectionIndex );
949 TColStd_ListOfReal anOldListX;
950 anOldListX = aListX->List();
952 TColStd_ListOfReal anOldListY;
953 anOldListY = aListY->List();
955 // Refill the existing lists
959 TColStd_ListIteratorOfListOfReal anIterX( anOldListX );
960 TColStd_ListIteratorOfListOfReal anIterY( anOldListY );
961 for ( int i = 0; anIterX.More() && anIterY.More(); anIterX.Next(), anIterY.Next(), ++i )
963 if ( i == thePointIndex )
964 continue; // skip index to remove
966 aListX->Append( anIterX.Value() );
967 aListY->Append( anIterY.Value() );
974 HYDROData_PolylineXY::PointsList HYDROData_PolylineXY::GetPoints( const int theSectionIndex ) const
978 Handle(TDataStd_RealList) aListX, aListY;
979 getPointsLists( theSectionIndex, aListX, aListY, false );
980 if ( aListX.IsNull() || aListY.IsNull() || aListX->IsEmpty() )
983 TColStd_ListIteratorOfListOfReal anIterX( aListX->List() );
984 TColStd_ListIteratorOfListOfReal anIterY( aListY->List() );
985 for ( ; anIterX.More() && anIterY.More(); anIterX.Next(), anIterY.Next() )
987 Point aPoint( anIterX.Value(), anIterY.Value() );
988 aResList.Append( aPoint );
994 QPainterPath HYDROData_PolylineXY::GetPainterPath() const
998 NCollection_Sequence<TCollection_AsciiString> aSectNames;
999 NCollection_Sequence<HYDROData_PolylineXY::SectionType> aSectTypes;
1000 NCollection_Sequence<bool> aSectClosures;
1001 GetSections( aSectNames, aSectTypes, aSectClosures );
1003 for ( int aSectionId = 1, aNbSects = aSectNames.Size(); aSectionId <= aNbSects; aSectionId++ )
1005 TCollection_AsciiString aSectName = aSectNames.Value( aSectionId );
1006 SectionType aSectionType = aSectTypes.Value( aSectionId );
1007 bool anIsSectionClosed = aSectClosures.Value( aSectionId );
1009 PointsList aSectPointsList = GetPoints( aSectionId - 1 );
1010 if ( aSectPointsList.IsEmpty() )
1013 NCollection_Sequence<gp_XYZ> aPoints;
1014 for( int i = 1, n = aSectPointsList.Size(); i <= n; ++i )
1016 const Point& aSectPoint = aSectPointsList.Value( i );
1018 gp_XYZ aPoint( aSectPoint.X(), aSectPoint.Y(), 0.0 );
1019 aPoints.Append( aPoint );
1022 BuildPainterPath( aPath, aSectionType, anIsSectionClosed, aPoints );