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 setPolylineShape( theShape );
293 setEditable( anIsCanBeImported );
298 TopoDS_Wire HYDROData_PolylineXY::BuildWire( const SectionType& theType,
299 const bool& theIsClosed,
300 const NCollection_Sequence<gp_XYZ>& thePoints )
302 BRepBuilderAPI_MakeWire aMakeWire;
304 if( theType == SECTION_POLYLINE )
306 for( int i = 1, n = thePoints.Size(); i <= n; ++i )
308 const gp_XYZ& aFirstPoint = thePoints.Value( i );
314 aLastPoint = thePoints.Value( 1 );
320 aLastPoint = thePoints.Value( i + 1 );
323 gp_Pnt aPnt1( aFirstPoint.X(), aFirstPoint.Y(), aFirstPoint.Z() );
324 gp_Pnt aPnt2( aLastPoint.X(), aLastPoint.Y(), aLastPoint.Z() );
326 if ( aPnt1.IsEqual( aPnt2, LOCAL_SELECTION_TOLERANCE ) )
329 TopoDS_Edge anEdge = BRepBuilderAPI_MakeEdge( aPnt1, aPnt2 ).Edge();
330 aMakeWire.Add( anEdge );
333 else //if( theType == PolylineSection::SECTION_SPLINE )
335 HYDROData_BSplineOperation aBSpline( thePoints, theIsClosed, LOCAL_SELECTION_TOLERANCE );
337 TopoDS_Edge anEdge = BRepBuilderAPI_MakeEdge( aBSpline.Curve() ).Edge();
338 aMakeWire.Add( anEdge );
343 if ( aMakeWire.IsDone() )
349 void HYDROData_PolylineXY::BuildPainterPath( QPainterPath& thePath,
350 const SectionType& theType,
351 const bool& theIsClosed,
352 const NCollection_Sequence<gp_XYZ>& thePoints )
354 if ( thePoints.IsEmpty() )
357 if ( theType == SECTION_POLYLINE )
359 const gp_XYZ& aFirstPoint = thePoints.Value( 1 );
360 thePath.moveTo( aFirstPoint.X(), aFirstPoint.Y() );
362 for( int i = 2, n = thePoints.Size(); i <= n; ++i )
364 const gp_XYZ& aSectPoint = thePoints.Value( i );
366 thePath.lineTo( aSectPoint.X(), aSectPoint.Y() );
370 thePath.closeSubpath();
374 HYDROData_BSplineOperation aBSpline( thePoints, theIsClosed, LOCAL_SELECTION_TOLERANCE );
375 aBSpline.ComputePath( thePath );
379 void HYDROData_PolylineXY::Update()
383 // If polyline is not editable we no need to update it wire
384 SetToUpdate( false );
388 HYDROData_IPolyline::Update();
390 NCollection_Sequence<TCollection_AsciiString> aSectNames;
391 NCollection_Sequence<HYDROData_PolylineXY::SectionType> aSectTypes;
392 NCollection_Sequence<bool> aSectClosures;
393 GetSections( aSectNames, aSectTypes, aSectClosures );
395 BRepBuilderAPI_MakeWire aMakeWire;
397 TopTools_ListOfShape aSectionWiresList;
399 for ( int aSectionId = 1, aNbSects = aSectNames.Size(); aSectionId <= aNbSects; aSectionId++ )
401 TCollection_AsciiString aSectName = aSectNames.Value( aSectionId );
402 SectionType aSectionType = aSectTypes.Value( aSectionId );
403 bool anIsSectionClosed = aSectClosures.Value( aSectionId );
405 PointsList aSectPointsList = GetPoints( aSectionId - 1 );
406 if ( aSectPointsList.IsEmpty() )
409 NCollection_Sequence<gp_XYZ> aPoints;
410 for( int i = 1, n = aSectPointsList.Size(); i <= n; ++i )
412 const Point& aSectPoint = aSectPointsList.Value( i );
414 gp_XYZ aPoint( aSectPoint.X(), aSectPoint.Y(), 0.0 );
415 aPoints.Append( aPoint );
418 TopoDS_Wire aSectionWire = BuildWire( aSectionType, anIsSectionClosed, aPoints );
419 if ( !aSectionWire.IsNull() ) {
420 aSectionWiresList.Append( aSectionWire );
421 aMakeWire.Add( aSectionWire );
424 // all input wires in the <aSectionWiresList>
425 Handle(TopTools_HSequenceOfShape) aSeqWires = new TopTools_HSequenceOfShape;
426 Handle(TopTools_HSequenceOfShape) aSeqEdges = new TopTools_HSequenceOfShape;
427 TopTools_ListIteratorOfListOfShape it(aSectionWiresList);
428 for(;it.More();it.Next())
430 TopExp_Explorer it2(it.Value(), TopAbs_EDGE);
431 for(;it2.More();it2.Next())
432 aSeqEdges->Append(it2.Current());
436 TopoDS_Compound aCmp;
437 TopoDS_Shape aResult;
438 aBB.MakeCompound(aCmp);
439 if(aSeqEdges->Length() >1)
441 ShapeAnalysis_FreeBounds::ConnectEdgesToWires(aSeqEdges,1E-5,Standard_False,aSeqWires);
443 if( aSeqWires->Length()==1 )
444 aResult = aSeqWires->Value( 1 );
447 for (Standard_Integer i = 1; i <= aSeqWires->Length();i++)
449 const TopoDS_Shape& aS1 = aSeqWires->Value(i);
455 else if (aSeqEdges->Length() == 1)
457 BRepBuilderAPI_MakeWire mkWire (TopoDS::Edge(aSeqEdges->Value(1)));
459 aResult = mkWire.Wire();
462 setPolylineShape( aResult );
465 bool HYDROData_PolylineXY::IsEditable() const
467 return !myLab.IsAttribute( GUID_IS_UNEDITABLE );
470 void HYDROData_PolylineXY::setEditable( const bool theIsEditable )
472 if ( !theIsEditable )
473 TDataStd_UAttribute::Set( myLab, GUID_IS_UNEDITABLE );
475 myLab.ForgetAttribute( GUID_IS_UNEDITABLE );
479 * Returns true if polyline is closed
481 bool HYDROData_PolylineXY::IsClosed( const bool theIsSimpleCheck ) const
483 bool anIsClosed = false;
485 TopoDS_Shape aShape = GetShape();
486 if ( aShape.IsNull() )
489 if ( aShape.ShapeType() == TopAbs_EDGE )
491 //For unrecognized curves from GEOM module
492 anIsClosed = BRep_Tool::IsClosed( aShape );
496 TopTools_SequenceOfShape aWires;
497 HYDROData_ShapesTool::ExploreShapeToShapes( aShape, TopAbs_WIRE, aWires );
499 int aNbWires = aWires.Length();
500 if ( theIsSimpleCheck )
502 anIsClosed = aNbWires > 0;
503 for ( int i = 1; i <= aNbWires && anIsClosed; ++i )
505 const TopoDS_Shape& aWire = aWires.Value( i );
506 anIsClosed = BRep_Tool::IsClosed( aWire );
511 anIsClosed = aNbWires == 1 && BRep_Tool::IsClosed( aWires.First() );
517 double HYDROData_PolylineXY::GetDistance( const int theSectionIndex,
518 const int thePointIndex ) const
520 double aResDistance = -1;
521 if ( theSectionIndex < 0 || theSectionIndex >= NbSections() )
524 if ( thePointIndex == 0 )
527 SectionType aSectionType = GetSectionType( theSectionIndex );
528 bool anIsSectionClosed = IsClosedSection( theSectionIndex );
529 PointsList aSectPointsList = GetPoints( theSectionIndex );
530 if ( thePointIndex < 0 || thePointIndex >= aSectPointsList.Size() )
533 if ( aSectionType == SECTION_POLYLINE )
537 Point aPrevPoint = aSectPointsList.Value( 1 );
538 for ( int i = 2, aNbPoints = aSectPointsList.Size(); i <= aNbPoints; ++i )
540 const Point& aSectPoint = aSectPointsList.Value( i );
541 aResDistance += gp_Pnt2d( aPrevPoint ).Distance( aSectPoint );
542 aPrevPoint = aSectPoint;
544 if ( thePointIndex == i - 1 )
552 int aSectNbPoints = aSectPointsList.Size();
553 NCollection_Sequence<gp_XYZ> aPoints;
554 for( int i = 1 ; i <= aSectNbPoints; ++i )
556 const Point& aSectPoint = aSectPointsList.Value( i );
558 gp_XYZ aPoint( aSectPoint.X(), aSectPoint.Y(), 0.0 );
559 aPoints.Append( aPoint );
561 if ( thePointIndex == i - 1 )
562 aPointToTest = aPoint;
565 HYDROData_BSplineOperation aBSpline( aPoints, anIsSectionClosed, LOCAL_SELECTION_TOLERANCE );
567 Quantity_Parameter aFirstParam = aBSpline.Curve()->FirstParameter();
568 Quantity_Parameter aSecondParam = aBSpline.Curve()->LastParameter();
570 if ( thePointIndex != aSectNbPoints - 1 )
572 GeomAPI_ProjectPointOnCurve aProject( aPointToTest, aBSpline.Curve() );
573 aSecondParam = aProject.LowerDistanceParameter();
576 GeomAdaptor_Curve anAdap( aBSpline.Curve() );
578 aResDistance = GCPnts_AbscissaPoint::Length( anAdap, aFirstParam, aSecondParam );
584 int HYDROData_PolylineXY::NbSections() const
586 Handle(TDataStd_ExtStringList) aNamesList;
587 Handle(TDataStd_IntegerList) aTypesList;
588 Handle(TDataStd_BooleanList) aClosuresList;
589 getSectionsLists( aNamesList, aTypesList, aClosuresList, false );
591 return !aClosuresList.IsNull() ? aClosuresList->Extent() : 0;
594 void HYDROData_PolylineXY::AddSection( const TCollection_AsciiString& theSectName,
595 const SectionType theSectionType,
596 const bool theIsClosed )
598 Handle(TDataStd_ExtStringList) aNamesList;
599 Handle(TDataStd_IntegerList) aTypesList;
600 Handle(TDataStd_BooleanList) aClosuresList;
601 getSectionsLists( aNamesList, aTypesList, aClosuresList );
603 TCollection_ExtendedString aSectName( theSectName );
604 if ( aSectName.Length() <= 0 )
605 aSectName = getUniqueSectionName( aNamesList );
607 aNamesList->Append( aSectName );
608 aTypesList->Append( theSectionType );
609 aClosuresList->Append( theIsClosed );
614 TCollection_AsciiString HYDROData_PolylineXY::GetSectionName( const int theSectionIndex ) const
616 TCollection_AsciiString aResName;
618 Handle(TDataStd_ExtStringList) aNamesList;
619 Handle(TDataStd_IntegerList) aTypesList;
620 Handle(TDataStd_BooleanList) aClosuresList;
621 getSectionsLists( aNamesList, aTypesList, aClosuresList, false );
622 if ( aNamesList.IsNull() || theSectionIndex >= aNamesList->Extent() )
625 TDataStd_ListIteratorOfListOfExtendedString aNamesIter( aNamesList->List() );
626 for ( int i = 0; aNamesIter.More() && i != theSectionIndex; aNamesIter.Next(), ++i );
628 if ( aNamesIter.More() )
629 aResName = aNamesIter.Value();
634 void HYDROData_PolylineXY::SetSectionName( const int theSectionIndex,
635 const TCollection_AsciiString& theSectionName )
637 Handle(TDataStd_ExtStringList) aNamesList;
638 Handle(TDataStd_IntegerList) aTypesList;
639 Handle(TDataStd_BooleanList) aClosuresList;
640 getSectionsLists( aNamesList, aTypesList, aClosuresList, false );
641 if ( aNamesList.IsNull() || theSectionIndex >= aNamesList->Extent() )
644 TDataStd_ListOfExtendedString anOldNamesList;
645 anOldNamesList = aNamesList->List();
647 // Refill the existing list
650 TCollection_ExtendedString aNewSectName = theSectionName;
652 TDataStd_ListIteratorOfListOfExtendedString aNamesIter( anOldNamesList );
653 for ( int i = 0; aNamesIter.More(); aNamesIter.Next(), ++i )
654 aNamesList->Append( i == theSectionIndex ? aNewSectName : aNamesIter.Value() );
659 HYDROData_PolylineXY::SectionType HYDROData_PolylineXY::GetSectionType( const int theSectionIndex ) const
661 Handle(TDataStd_ExtStringList) aNamesList;
662 Handle(TDataStd_IntegerList) aTypesList;
663 Handle(TDataStd_BooleanList) aClosuresList;
664 getSectionsLists( aNamesList, aTypesList, aClosuresList, false );
665 if ( aTypesList.IsNull() || theSectionIndex >= aTypesList->Extent() )
666 return SECTION_POLYLINE;
668 TColStd_ListIteratorOfListOfInteger aTypesIter( aTypesList->List() );
669 for ( int i = 0; aTypesIter.More() && i != theSectionIndex; aTypesIter.Next(), ++i );
671 return aTypesIter.More() ? (SectionType)aTypesIter.Value() : SECTION_POLYLINE;
674 void HYDROData_PolylineXY::SetSectionType( const int theSectionIndex,
675 const SectionType theSectionType )
677 Handle(TDataStd_ExtStringList) aNamesList;
678 Handle(TDataStd_IntegerList) aTypesList;
679 Handle(TDataStd_BooleanList) aClosuresList;
680 getSectionsLists( aNamesList, aTypesList, aClosuresList, false );
681 if ( aTypesList.IsNull() || theSectionIndex >= aTypesList->Extent() )
684 TColStd_ListOfInteger anOldTypesList;
685 anOldTypesList = aTypesList->List();
687 // Refill the existing list
690 TColStd_ListIteratorOfListOfInteger aTypesIter( anOldTypesList );
691 for ( int i = 0; aTypesIter.More(); aTypesIter.Next(), ++i )
692 aTypesList->Append( i == theSectionIndex ? theSectionType : aTypesIter.Value() );
697 bool HYDROData_PolylineXY::IsClosedSection( const int theSectionIndex ) const
699 Handle(TDataStd_ExtStringList) aNamesList;
700 Handle(TDataStd_IntegerList) aTypesList;
701 Handle(TDataStd_BooleanList) aClosuresList;
702 getSectionsLists( aNamesList, aTypesList, aClosuresList, false );
703 if ( aClosuresList.IsNull() || theSectionIndex >= aClosuresList->Extent() )
706 TDataStd_ListIteratorOfListOfByte aClosuresIter( aClosuresList->List() );
707 for ( int i = 0; aClosuresIter.More() && i != theSectionIndex; aClosuresIter.Next(), ++i );
709 return aClosuresIter.More() ? (bool)aClosuresIter.Value() : false;
712 void HYDROData_PolylineXY::SetSectionClosed( const int theSectionIndex,
713 const bool theIsClosed )
715 Handle(TDataStd_ExtStringList) aNamesList;
716 Handle(TDataStd_IntegerList) aTypesList;
717 Handle(TDataStd_BooleanList) aClosuresList;
718 getSectionsLists( aNamesList, aTypesList, aClosuresList, false );
719 if ( aClosuresList.IsNull() || theSectionIndex >= aClosuresList->Extent() )
722 TDataStd_ListOfByte anOldClosuresList;
723 anOldClosuresList = aClosuresList->List();
725 // Refill the existing list
726 aClosuresList->Clear();
728 TDataStd_ListIteratorOfListOfByte aClosuresIter( anOldClosuresList );
729 for ( int i = 0; aClosuresIter.More(); aClosuresIter.Next(), ++i )
730 aClosuresList->Append( i == theSectionIndex ? theIsClosed : (bool)aClosuresIter.Value() );
735 void HYDROData_PolylineXY::GetSections( NCollection_Sequence<TCollection_AsciiString>& theSectNames,
736 NCollection_Sequence<SectionType>& theSectTypes,
737 NCollection_Sequence<bool>& theSectClosures ) const
739 theSectNames.Clear();
740 theSectTypes.Clear();
741 theSectClosures.Clear();
743 Handle(TDataStd_ExtStringList) aNamesList;
744 Handle(TDataStd_IntegerList) aTypesList;
745 Handle(TDataStd_BooleanList) aClosuresList;
746 getSectionsLists( aNamesList, aTypesList, aClosuresList, false );
747 if ( aNamesList.IsNull() || aTypesList.IsNull() || aClosuresList.IsNull() )
750 TDataStd_ListIteratorOfListOfExtendedString aNamesIter( aNamesList->List() );
751 TColStd_ListIteratorOfListOfInteger aTypesIter( aTypesList->List() );
752 TDataStd_ListIteratorOfListOfByte aClosuresIter( aClosuresList->List() );
753 for ( ; aNamesIter.More() && aTypesIter.More() && aClosuresIter.More();
754 aNamesIter.Next(), aTypesIter.Next(), aClosuresIter.Next() )
756 const TCollection_ExtendedString& aSectName = aNamesIter.Value();
757 SectionType aSectType = (SectionType)aTypesIter.Value();
758 bool aSectClosures = aClosuresIter.Value();
760 theSectNames.Append( aSectName );
761 theSectTypes.Append( aSectType );
762 theSectClosures.Append( aSectClosures );
766 void HYDROData_PolylineXY::RemoveSection( const int theSectionIndex )
768 Handle(TDataStd_ExtStringList) aNamesList;
769 Handle(TDataStd_IntegerList) aTypesList;
770 Handle(TDataStd_BooleanList) aClosuresList;
771 getSectionsLists( aNamesList, aTypesList, aClosuresList, false );
772 if ( aNamesList.IsNull() || theSectionIndex >= aNamesList->Extent() )
775 if ( aNamesList->Extent() == 1 )
777 removeSectionsLists();
782 TDataStd_ListOfExtendedString anOldNamesList;
783 anOldNamesList = aNamesList->List();
785 TColStd_ListOfInteger anOldTypesList;
786 anOldTypesList = aTypesList->List();
788 TDataStd_ListOfByte anOldClosuresList;
789 anOldClosuresList = aClosuresList->List();
791 // Refill the existing lists
794 aClosuresList->Clear();
796 TDataStd_ListIteratorOfListOfExtendedString aNamesIter( anOldNamesList );
797 TColStd_ListIteratorOfListOfInteger aTypesIter( anOldTypesList );
798 TDataStd_ListIteratorOfListOfByte aClosuresIter( anOldClosuresList );
799 for ( int i = 0; aNamesIter.More() && aTypesIter.More() && aClosuresIter.More();
800 aNamesIter.Next(), aTypesIter.Next(), aClosuresIter.Next(), ++i )
802 if ( i == theSectionIndex )
803 continue; // skip index to remove
805 aNamesList->Append( aNamesIter.Value() );
806 aTypesList->Append( aTypesIter.Value() );
807 aClosuresList->Append( (bool)aClosuresIter.Value() );
810 // Remove points that belongs to removed section
811 removePointsLists( theSectionIndex );
817 void HYDROData_PolylineXY::RemoveSections()
819 removeSectionsLists();
824 void HYDROData_PolylineXY::AddPoint( const int theSectionIndex,
825 const Point& thePoint,
826 const int thePointIndex )
828 Handle(TDataStd_RealList) aListX, aListY;
829 getPointsLists( theSectionIndex, aListX, aListY );
831 if ( thePointIndex < 0 || thePointIndex >= aListX->Extent() )
833 aListX->Append( thePoint.X() );
834 aListY->Append( thePoint.Y() );
838 TColStd_ListOfReal anOldListX;
839 anOldListX = aListX->List();
841 TColStd_ListOfReal anOldListY;
842 anOldListY = aListY->List();
844 // Refill the existing lists
848 TColStd_ListIteratorOfListOfReal anIterX( anOldListX );
849 TColStd_ListIteratorOfListOfReal anIterY( anOldListY );
850 for ( int i = 0; anIterX.More() && anIterY.More(); anIterX.Next(), anIterY.Next(), ++i )
852 double aCoordX = anIterX.Value();
853 double aCoordY = anIterY.Value();
855 if ( i == thePointIndex )
857 // Insert our new point
858 aListX->Append( thePoint.X() );
859 aListY->Append( thePoint.Y() );
862 aListX->Append( aCoordX );
863 aListY->Append( aCoordY );
870 void HYDROData_PolylineXY::SetPoint( const int theSectionIndex,
871 const Point& thePoint,
872 const int thePointIndex )
874 Handle(TDataStd_RealList) aListX, aListY;
875 getPointsLists( theSectionIndex, aListX, aListY );
877 if ( thePointIndex < 0 )
879 aListX->Prepend( thePoint.X() );
880 aListY->Prepend( thePoint.Y() );
882 else if ( thePointIndex >= aListX->Extent() )
884 aListX->Append( thePoint.X() );
885 aListY->Append( thePoint.Y() );
889 TColStd_ListOfReal anOldListX;
890 anOldListX = aListX->List();
892 TColStd_ListOfReal anOldListY;
893 anOldListY = aListY->List();
895 // Refill the existing lists
899 TColStd_ListIteratorOfListOfReal anIterX( anOldListX );
900 TColStd_ListIteratorOfListOfReal anIterY( anOldListY );
901 for ( int i = 0; anIterX.More() && anIterY.More(); anIterX.Next(), anIterY.Next(), ++i )
903 double aCoordX = anIterX.Value();
904 double aCoordY = anIterY.Value();
906 if ( i == thePointIndex )
908 // Insert our new point instead of old one
909 aCoordX = thePoint.X();
910 aCoordY = thePoint.Y();
913 aListX->Append( aCoordX );
914 aListY->Append( aCoordY );
921 void HYDROData_PolylineXY::SetPoints( const int theSectionIndex,
922 const PointsList& thePoints )
924 Handle(TDataStd_RealList) aListX, aListY;
925 getPointsLists( theSectionIndex, aListX, aListY );
930 for ( int i = 1, n = thePoints.Length(); i <= n; ++i )
932 const Point& aPoint = thePoints.Value( i );
933 aListX->Append( aPoint.X() );
934 aListY->Append( aPoint.Y() );
938 void HYDROData_PolylineXY::RemovePoint( const int theSectionIndex,
939 const int thePointIndex )
941 Handle(TDataStd_RealList) aListX, aListY;
942 getPointsLists( theSectionIndex, aListX, aListY, false );
943 if ( aListX.IsNull() || aListY.IsNull() || aListX->IsEmpty() )
946 if ( aListX->Extent() == 1 )
948 removePointsLists( theSectionIndex );
952 TColStd_ListOfReal anOldListX;
953 anOldListX = aListX->List();
955 TColStd_ListOfReal anOldListY;
956 anOldListY = aListY->List();
958 // Refill the existing lists
962 TColStd_ListIteratorOfListOfReal anIterX( anOldListX );
963 TColStd_ListIteratorOfListOfReal anIterY( anOldListY );
964 for ( int i = 0; anIterX.More() && anIterY.More(); anIterX.Next(), anIterY.Next(), ++i )
966 if ( i == thePointIndex )
967 continue; // skip index to remove
969 aListX->Append( anIterX.Value() );
970 aListY->Append( anIterY.Value() );
977 HYDROData_PolylineXY::PointsList HYDROData_PolylineXY::GetPoints( const int theSectionIndex ) const
981 Handle(TDataStd_RealList) aListX, aListY;
982 getPointsLists( theSectionIndex, aListX, aListY, false );
983 if ( aListX.IsNull() || aListY.IsNull() || aListX->IsEmpty() )
986 TColStd_ListIteratorOfListOfReal anIterX( aListX->List() );
987 TColStd_ListIteratorOfListOfReal anIterY( aListY->List() );
988 for ( ; anIterX.More() && anIterY.More(); anIterX.Next(), anIterY.Next() )
990 Point aPoint( anIterX.Value(), anIterY.Value() );
991 aResList.Append( aPoint );
997 QPainterPath HYDROData_PolylineXY::GetPainterPath() const
1001 NCollection_Sequence<TCollection_AsciiString> aSectNames;
1002 NCollection_Sequence<HYDROData_PolylineXY::SectionType> aSectTypes;
1003 NCollection_Sequence<bool> aSectClosures;
1004 GetSections( aSectNames, aSectTypes, aSectClosures );
1006 for ( int aSectionId = 1, aNbSects = aSectNames.Size(); aSectionId <= aNbSects; aSectionId++ )
1008 TCollection_AsciiString aSectName = aSectNames.Value( aSectionId );
1009 SectionType aSectionType = aSectTypes.Value( aSectionId );
1010 bool anIsSectionClosed = aSectClosures.Value( aSectionId );
1012 PointsList aSectPointsList = GetPoints( aSectionId - 1 );
1013 if ( aSectPointsList.IsEmpty() )
1016 NCollection_Sequence<gp_XYZ> aPoints;
1017 for( int i = 1, n = aSectPointsList.Size(); i <= n; ++i )
1019 const Point& aSectPoint = aSectPointsList.Value( i );
1021 gp_XYZ aPoint( aSectPoint.X(), aSectPoint.Y(), 0.0 );
1022 aPoints.Append( aPoint );
1025 BuildPainterPath( aPath, aSectionType, anIsSectionClosed, aPoints );