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 = dumpObjectCreation( theTreatedObjects );
110 QString aPolylineName = GetObjPyName();
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_IPolyline::PointsList aSectPointsList = GetPoints( i - 1 );
128 for ( int k = 1, aNbPoints = aSectPointsList.Size(); k <= aNbPoints; ++k )
130 const Point& aSectPoint = aSectPointsList.Value( k );
132 aResList << QString( "%1.AddPoint( %2, gp_XY( %3, %4 ) );" ).arg( aPolylineName )
133 .arg( i - 1 ).arg( aSectPoint.X() ).arg( aSectPoint.Y() );
137 aResList << QString( "" );
138 aResList << QString( "%1.Update();" ).arg( aPolylineName );
139 aResList << QString( "" );
144 QVariant HYDROData_PolylineXY::GetDataVariant()
146 QPainterPath aPath = GetPainterPath();
149 aVarData.setValue<QPainterPath>( aPath );
154 QColor HYDROData_PolylineXY::DefaultWireColor()
156 return QColor( Qt::red );
159 TopoDS_Shape HYDROData_PolylineXY::GetShape() const
161 return getPolylineShape();
164 bool convertEdgeToSection( const TopoDS_Edge& theEdge,
165 NCollection_Sequence<TCollection_AsciiString>& theSectNames,
166 NCollection_Sequence<HYDROData_PolylineXY::SectionType>& theSectTypes,
167 NCollection_Sequence<bool>& theSectClosures,
168 NCollection_Sequence<HYDROData_PolylineXY::PointsList>& theSectPoints,
169 const bool theIsCanBeClosed )
171 Standard_Real aFirst = 0.0, aLast = 0.0;
172 Handle(Geom_Curve) anEdgeGeomCurve = BRep_Tool::Curve( theEdge, aFirst, aLast );
173 if ( anEdgeGeomCurve.IsNull() )
176 TCollection_AsciiString aSectName = getUniqueSectionName( theSectNames );
177 bool anIsEdgeClosed = anEdgeGeomCurve->IsClosed();
179 HYDROData_PolylineXY::SectionType aSectionType = HYDROData_PolylineXY::SECTION_POLYLINE;
180 HYDROData_PolylineXY::PointsList aPointsList;
182 if ( anEdgeGeomCurve->IsKind( STANDARD_TYPE(Geom_Line) ) )
184 Handle(Geom_Line) aGeomLine = Handle(Geom_Line)::DownCast( anEdgeGeomCurve );
186 gp_Pnt aFirstPoint, aLastPoint;
187 aGeomLine->D0( aFirst, aFirstPoint );
188 aGeomLine->D0( aLast, aLastPoint );
190 HYDROData_PolylineXY::Point aSectFirstPoint( aFirstPoint.X(), aFirstPoint.Y() );
191 aPointsList.Append( aSectFirstPoint );
193 HYDROData_PolylineXY::Point aSectLastPoint( aLastPoint.X(), aLastPoint.Y() );
194 aPointsList.Append( aSectLastPoint );
196 else if ( anEdgeGeomCurve->IsKind( STANDARD_TYPE(Geom_BSplineCurve) ) )
198 aSectionType = HYDROData_PolylineXY::SECTION_SPLINE;
200 Handle(Geom_BSplineCurve) aGeomSpline =
201 Handle(Geom_BSplineCurve)::DownCast( anEdgeGeomCurve );
203 int aNbKnots = aGeomSpline->NbKnots();
205 TColStd_Array1OfReal aSplineKnots( 1, aNbKnots );
206 aGeomSpline->Knots( aSplineKnots );
208 // Decrease the number of imported knots because of last one
209 // knot is the closing point which are the start point
210 if ( anIsEdgeClosed ) aNbKnots--;
212 for ( int i = 1; i <= aNbKnots; ++i )
214 const Standard_Real& aKnot = aSplineKnots.Value( i );
217 aGeomSpline->D0( aKnot, aPoint );
219 HYDROData_PolylineXY::Point aSectPoint( aPoint.X(), aPoint.Y() );
220 aPointsList.Append( aSectPoint );
225 // Other curve types are not supported
229 if ( aPointsList.IsEmpty() )
232 theSectNames.Append( aSectName );
233 theSectTypes.Append( aSectionType );
234 theSectClosures.Append( anIsEdgeClosed );
235 theSectPoints.Append( aPointsList );
240 bool HYDROData_PolylineXY::ImportShape( const TopoDS_Shape& theShape )
242 if ( theShape.IsNull() )
247 bool anIsCanBeImported = false;
249 NCollection_Sequence<TCollection_AsciiString> aSectNames;
250 NCollection_Sequence<SectionType> aSectTypes;
251 NCollection_Sequence<bool> aSectClosures;
252 NCollection_Sequence<PointsList> aSectPoints;
254 if ( theShape.ShapeType() == TopAbs_EDGE )
256 TopoDS_Edge anEdge = TopoDS::Edge( theShape );
257 anIsCanBeImported = convertEdgeToSection( anEdge, aSectNames, aSectTypes, aSectClosures, aSectPoints, true );
259 else if ( theShape.ShapeType() == TopAbs_WIRE )
261 TopTools_SequenceOfShape anEdges;
262 HYDROData_ShapesTool::ExploreShapeToShapes( theShape, TopAbs_EDGE, anEdges );
264 anIsCanBeImported = !anEdges.IsEmpty();
265 for ( int i = 1, n = anEdges.Length(); i <= n && anIsCanBeImported; ++i )
267 TopoDS_Edge aWireEdge = TopoDS::Edge( anEdges.Value( i ) );
268 anIsCanBeImported = convertEdgeToSection( aWireEdge, aSectNames, aSectTypes, aSectClosures, aSectPoints, false );
272 if ( anIsCanBeImported )
274 for ( int i = 1, n = aSectNames.Length(); i <= n; ++i )
276 const TCollection_AsciiString& aSectName = aSectNames.Value( i );
277 const SectionType& aSectType = aSectTypes.Value( i );
278 bool anIsSectionClosed = aSectClosures.Value( i );
279 const PointsList& aSectPointsList = aSectPoints( i );
281 AddSection( aSectName, aSectType, anIsSectionClosed );
282 SetPoints( i - 1, aSectPointsList );
287 TopoDS_Shape aShape = theShape;
289 if ( theShape.ShapeType() == TopAbs_EDGE )
291 // We make the wire from incoming edge because of other algorithms
292 // are waiting at least the wire from polyline
293 TopoDS_Edge anEdge = TopoDS::Edge( theShape );
294 BRepBuilderAPI_MakeWire aMakeWire( anEdge );
296 if ( aMakeWire.IsDone() )
297 aShape = aMakeWire.Wire();
300 gp_Pln aPlane( gp_Pnt( 0, 0, 0 ), gp_Dir( 0, 0, 1 ) );
301 BRepBuilderAPI_MakeFace aMakeFace( aPlane );
303 BRepOffsetAPI_NormalProjection aProj( aMakeFace.Face() );
306 TopoDS_Shape aResult;
308 aResult = aProj.Shape();
310 setPolylineShape( aResult );
313 setEditable( anIsCanBeImported );
318 TopoDS_Wire HYDROData_PolylineXY::BuildWire( const SectionType& theType,
319 const bool& theIsClosed,
320 const NCollection_Sequence<gp_XYZ>& thePoints )
323 if( theType == SECTION_POLYLINE )
325 BRepBuilderAPI_MakePolygon aMakeWire;
326 for ( int i = 1, n = thePoints.Length(); i <= n ; ++i )
328 gp_XYZ aPoint = thePoints.Value( i );
329 gp_Pnt aPnt( aPoint.X(), aPoint.Y(), aPoint.Z() );
330 aMakeWire.Add( aPnt );
335 if ( aMakeWire.IsDone() )
336 aWire = aMakeWire.Wire();
338 else //if( theType == PolylineSection::SECTION_SPLINE )
340 BRepBuilderAPI_MakeWire aMakeWire;
342 if ( thePoints.Size() > 1 )
344 HYDROData_BSplineOperation aBSpline( thePoints, theIsClosed, LOCAL_SELECTION_TOLERANCE );
346 TopoDS_Edge anEdge = BRepBuilderAPI_MakeEdge( aBSpline.Curve() ).Edge();
347 aMakeWire.Add( anEdge );
350 if ( aMakeWire.IsDone() )
357 void HYDROData_PolylineXY::BuildPainterPath( QPainterPath& thePath,
358 const SectionType& theType,
359 const bool& theIsClosed,
360 const NCollection_Sequence<gp_XYZ>& thePoints )
362 if ( thePoints.IsEmpty() )
365 if ( theType == SECTION_POLYLINE )
367 const gp_XYZ& aFirstPoint = thePoints.Value( 1 );
368 thePath.moveTo( aFirstPoint.X(), aFirstPoint.Y() );
370 for( int i = 2, n = thePoints.Size(); i <= n; ++i )
372 const gp_XYZ& aSectPoint = thePoints.Value( i );
374 thePath.lineTo( aSectPoint.X(), aSectPoint.Y() );
378 thePath.closeSubpath();
382 HYDROData_BSplineOperation aBSpline( thePoints, theIsClosed, LOCAL_SELECTION_TOLERANCE );
383 aBSpline.ComputePath( thePath );
387 void HYDROData_PolylineXY::Update()
391 // If polyline is not editable we no need to update it wire
392 SetToUpdate( false );
396 HYDROData_IPolyline::Update();
398 NCollection_Sequence<TCollection_AsciiString> aSectNames;
399 NCollection_Sequence<HYDROData_PolylineXY::SectionType> aSectTypes;
400 NCollection_Sequence<bool> aSectClosures;
401 GetSections( aSectNames, aSectTypes, aSectClosures );
403 BRepBuilderAPI_MakeWire aMakeWire;
405 TopTools_ListOfShape aSectionWiresList;
407 for ( int aSectionId = 1, aNbSects = aSectNames.Size(); aSectionId <= aNbSects; aSectionId++ )
409 TCollection_AsciiString aSectName = aSectNames.Value( aSectionId );
410 SectionType aSectionType = aSectTypes.Value( aSectionId );
411 bool anIsSectionClosed = aSectClosures.Value( aSectionId );
413 PointsList aSectPointsList = GetPoints( aSectionId - 1 );
414 if ( aSectPointsList.IsEmpty() )
417 NCollection_Sequence<gp_XYZ> aPoints;
418 for( int i = 1, n = aSectPointsList.Size(); i <= n; ++i )
420 const Point& aSectPoint = aSectPointsList.Value( i );
422 gp_XYZ aPoint( aSectPoint.X(), aSectPoint.Y(), 0.0 );
423 aPoints.Append( aPoint );
426 TopoDS_Wire aSectionWire = BuildWire( aSectionType, anIsSectionClosed, aPoints );
427 if ( !aSectionWire.IsNull() ) {
428 aSectionWiresList.Append( aSectionWire );
429 aMakeWire.Add( aSectionWire );
432 // all input wires in the <aSectionWiresList>
433 Handle(TopTools_HSequenceOfShape) aSeqWires = new TopTools_HSequenceOfShape;
434 Handle(TopTools_HSequenceOfShape) aSeqEdges = new TopTools_HSequenceOfShape;
435 TopTools_ListIteratorOfListOfShape it(aSectionWiresList);
436 for(;it.More();it.Next())
438 TopExp_Explorer it2(it.Value(), TopAbs_EDGE);
439 for(;it2.More();it2.Next())
440 aSeqEdges->Append(it2.Current());
444 TopoDS_Compound aCmp;
445 TopoDS_Shape aResult;
446 aBB.MakeCompound(aCmp);
447 if(aSeqEdges->Length() >1)
449 ShapeAnalysis_FreeBounds::ConnectEdgesToWires(aSeqEdges,1E-5,Standard_False,aSeqWires);
451 if( aSeqWires->Length()==1 )
452 aResult = aSeqWires->Value( 1 );
455 for (Standard_Integer i = 1; i <= aSeqWires->Length();i++)
457 const TopoDS_Shape& aS1 = aSeqWires->Value(i);
463 else if (aSeqEdges->Length() == 1)
465 BRepBuilderAPI_MakeWire mkWire (TopoDS::Edge(aSeqEdges->Value(1)));
467 aResult = mkWire.Wire();
470 setPolylineShape( aResult );
473 bool HYDROData_PolylineXY::IsEditable() const
475 return !myLab.IsAttribute( GUID_IS_UNEDITABLE );
478 void HYDROData_PolylineXY::setEditable( const bool theIsEditable )
480 if ( !theIsEditable )
481 TDataStd_UAttribute::Set( myLab, GUID_IS_UNEDITABLE );
483 myLab.ForgetAttribute( GUID_IS_UNEDITABLE );
487 * Returns true if polyline is closed
489 bool HYDROData_PolylineXY::IsClosed( const bool theIsSimpleCheck ) const
491 bool anIsClosed = false;
493 TopoDS_Shape aShape = GetShape();
494 if ( aShape.IsNull() )
497 TopTools_SequenceOfShape aWires;
498 HYDROData_ShapesTool::ExploreShapeToShapes( aShape, TopAbs_WIRE, aWires );
500 int aNbWires = aWires.Length();
501 if ( theIsSimpleCheck )
503 anIsClosed = aNbWires > 0;
504 for ( int i = 1; i <= aNbWires && anIsClosed; ++i )
506 const TopoDS_Shape& aWire = aWires.Value( i );
507 anIsClosed = BRep_Tool::IsClosed( aWire );
512 anIsClosed = aNbWires == 1 && BRep_Tool::IsClosed( aWires.First() );
518 double HYDROData_PolylineXY::GetDistance( const int theSectionIndex,
519 const int thePointIndex ) const
521 double aResDistance = -1;
522 if ( theSectionIndex < 0 || theSectionIndex >= NbSections() )
525 if ( thePointIndex == 0 )
528 SectionType aSectionType = GetSectionType( theSectionIndex );
529 bool anIsSectionClosed = IsClosedSection( theSectionIndex );
530 PointsList aSectPointsList = GetPoints( theSectionIndex );
531 if ( thePointIndex < 0 || thePointIndex >= aSectPointsList.Size() )
534 if ( aSectionType == SECTION_POLYLINE )
538 Point aPrevPoint = aSectPointsList.Value( 1 );
539 for ( int i = 2, aNbPoints = aSectPointsList.Size(); i <= aNbPoints; ++i )
541 const Point& aSectPoint = aSectPointsList.Value( i );
542 aResDistance += gp_Pnt2d( aPrevPoint ).Distance( aSectPoint );
543 aPrevPoint = aSectPoint;
545 if ( thePointIndex == i - 1 )
553 int aSectNbPoints = aSectPointsList.Size();
554 NCollection_Sequence<gp_XYZ> aPoints;
555 for( int i = 1 ; i <= aSectNbPoints; ++i )
557 const Point& aSectPoint = aSectPointsList.Value( i );
559 gp_XYZ aPoint( aSectPoint.X(), aSectPoint.Y(), 0.0 );
560 aPoints.Append( aPoint );
562 if ( thePointIndex == i - 1 )
563 aPointToTest = aPoint;
566 HYDROData_BSplineOperation aBSpline( aPoints, anIsSectionClosed, LOCAL_SELECTION_TOLERANCE );
568 Quantity_Parameter aFirstParam = aBSpline.Curve()->FirstParameter();
569 Quantity_Parameter aSecondParam = aBSpline.Curve()->LastParameter();
571 if ( thePointIndex != aSectNbPoints - 1 )
573 GeomAPI_ProjectPointOnCurve aProject( aPointToTest, aBSpline.Curve() );
574 aSecondParam = aProject.LowerDistanceParameter();
577 GeomAdaptor_Curve anAdap( aBSpline.Curve() );
579 aResDistance = GCPnts_AbscissaPoint::Length( anAdap, aFirstParam, aSecondParam );
585 int HYDROData_PolylineXY::NbSections() const
587 Handle(TDataStd_ExtStringList) aNamesList;
588 Handle(TDataStd_IntegerList) aTypesList;
589 Handle(TDataStd_BooleanList) aClosuresList;
590 getSectionsLists( aNamesList, aTypesList, aClosuresList, false );
592 return !aClosuresList.IsNull() ? aClosuresList->Extent() : 0;
595 void HYDROData_PolylineXY::AddSection( const TCollection_AsciiString& theSectName,
596 const SectionType theSectionType,
597 const bool theIsClosed )
599 Handle(TDataStd_ExtStringList) aNamesList;
600 Handle(TDataStd_IntegerList) aTypesList;
601 Handle(TDataStd_BooleanList) aClosuresList;
602 getSectionsLists( aNamesList, aTypesList, aClosuresList );
604 TCollection_ExtendedString aSectName( theSectName );
605 if ( aSectName.Length() <= 0 )
606 aSectName = getUniqueSectionName( aNamesList );
608 aNamesList->Append( aSectName );
609 aTypesList->Append( theSectionType );
610 aClosuresList->Append( theIsClosed );
615 TCollection_AsciiString HYDROData_PolylineXY::GetSectionName( const int theSectionIndex ) const
617 TCollection_AsciiString aResName;
619 Handle(TDataStd_ExtStringList) aNamesList;
620 Handle(TDataStd_IntegerList) aTypesList;
621 Handle(TDataStd_BooleanList) aClosuresList;
622 getSectionsLists( aNamesList, aTypesList, aClosuresList, false );
623 if ( aNamesList.IsNull() || theSectionIndex >= aNamesList->Extent() )
626 TDataStd_ListIteratorOfListOfExtendedString aNamesIter( aNamesList->List() );
627 for ( int i = 0; aNamesIter.More() && i != theSectionIndex; aNamesIter.Next(), ++i );
629 if ( aNamesIter.More() )
630 aResName = aNamesIter.Value();
635 void HYDROData_PolylineXY::SetSectionName( const int theSectionIndex,
636 const TCollection_AsciiString& theSectionName )
638 Handle(TDataStd_ExtStringList) aNamesList;
639 Handle(TDataStd_IntegerList) aTypesList;
640 Handle(TDataStd_BooleanList) aClosuresList;
641 getSectionsLists( aNamesList, aTypesList, aClosuresList, false );
642 if ( aNamesList.IsNull() || theSectionIndex >= aNamesList->Extent() )
645 TDataStd_ListOfExtendedString anOldNamesList;
646 anOldNamesList = aNamesList->List();
648 // Refill the existing list
651 TCollection_ExtendedString aNewSectName = theSectionName;
653 TDataStd_ListIteratorOfListOfExtendedString aNamesIter( anOldNamesList );
654 for ( int i = 0; aNamesIter.More(); aNamesIter.Next(), ++i )
655 aNamesList->Append( i == theSectionIndex ? aNewSectName : aNamesIter.Value() );
660 HYDROData_PolylineXY::SectionType HYDROData_PolylineXY::GetSectionType( const int theSectionIndex ) const
662 Handle(TDataStd_ExtStringList) aNamesList;
663 Handle(TDataStd_IntegerList) aTypesList;
664 Handle(TDataStd_BooleanList) aClosuresList;
665 getSectionsLists( aNamesList, aTypesList, aClosuresList, false );
666 if ( aTypesList.IsNull() || theSectionIndex >= aTypesList->Extent() )
667 return SECTION_POLYLINE;
669 TColStd_ListIteratorOfListOfInteger aTypesIter( aTypesList->List() );
670 for ( int i = 0; aTypesIter.More() && i != theSectionIndex; aTypesIter.Next(), ++i );
672 return aTypesIter.More() ? (SectionType)aTypesIter.Value() : SECTION_POLYLINE;
675 void HYDROData_PolylineXY::SetSectionType( const int theSectionIndex,
676 const SectionType theSectionType )
678 Handle(TDataStd_ExtStringList) aNamesList;
679 Handle(TDataStd_IntegerList) aTypesList;
680 Handle(TDataStd_BooleanList) aClosuresList;
681 getSectionsLists( aNamesList, aTypesList, aClosuresList, false );
682 if ( aTypesList.IsNull() || theSectionIndex >= aTypesList->Extent() )
685 TColStd_ListOfInteger anOldTypesList;
686 anOldTypesList = aTypesList->List();
688 // Refill the existing list
691 TColStd_ListIteratorOfListOfInteger aTypesIter( anOldTypesList );
692 for ( int i = 0; aTypesIter.More(); aTypesIter.Next(), ++i )
693 aTypesList->Append( i == theSectionIndex ? theSectionType : aTypesIter.Value() );
698 bool HYDROData_PolylineXY::IsClosedSection( const int theSectionIndex ) const
700 Handle(TDataStd_ExtStringList) aNamesList;
701 Handle(TDataStd_IntegerList) aTypesList;
702 Handle(TDataStd_BooleanList) aClosuresList;
703 getSectionsLists( aNamesList, aTypesList, aClosuresList, false );
704 if ( aClosuresList.IsNull() || theSectionIndex >= aClosuresList->Extent() )
707 TDataStd_ListIteratorOfListOfByte aClosuresIter( aClosuresList->List() );
708 for ( int i = 0; aClosuresIter.More() && i != theSectionIndex; aClosuresIter.Next(), ++i );
710 return aClosuresIter.More() ? (bool)aClosuresIter.Value() : false;
713 void HYDROData_PolylineXY::SetSectionClosed( const int theSectionIndex,
714 const bool theIsClosed )
716 Handle(TDataStd_ExtStringList) aNamesList;
717 Handle(TDataStd_IntegerList) aTypesList;
718 Handle(TDataStd_BooleanList) aClosuresList;
719 getSectionsLists( aNamesList, aTypesList, aClosuresList, false );
720 if ( aClosuresList.IsNull() || theSectionIndex >= aClosuresList->Extent() )
723 TDataStd_ListOfByte anOldClosuresList;
724 anOldClosuresList = aClosuresList->List();
726 // Refill the existing list
727 aClosuresList->Clear();
729 TDataStd_ListIteratorOfListOfByte aClosuresIter( anOldClosuresList );
730 for ( int i = 0; aClosuresIter.More(); aClosuresIter.Next(), ++i )
731 aClosuresList->Append( i == theSectionIndex ? theIsClosed : (bool)aClosuresIter.Value() );
736 void HYDROData_PolylineXY::GetSections( NCollection_Sequence<TCollection_AsciiString>& theSectNames,
737 NCollection_Sequence<SectionType>& theSectTypes,
738 NCollection_Sequence<bool>& theSectClosures ) const
740 theSectNames.Clear();
741 theSectTypes.Clear();
742 theSectClosures.Clear();
744 Handle(TDataStd_ExtStringList) aNamesList;
745 Handle(TDataStd_IntegerList) aTypesList;
746 Handle(TDataStd_BooleanList) aClosuresList;
747 getSectionsLists( aNamesList, aTypesList, aClosuresList, false );
748 if ( aNamesList.IsNull() || aTypesList.IsNull() || aClosuresList.IsNull() )
751 TDataStd_ListIteratorOfListOfExtendedString aNamesIter( aNamesList->List() );
752 TColStd_ListIteratorOfListOfInteger aTypesIter( aTypesList->List() );
753 TDataStd_ListIteratorOfListOfByte aClosuresIter( aClosuresList->List() );
754 for ( ; aNamesIter.More() && aTypesIter.More() && aClosuresIter.More();
755 aNamesIter.Next(), aTypesIter.Next(), aClosuresIter.Next() )
757 const TCollection_ExtendedString& aSectName = aNamesIter.Value();
758 SectionType aSectType = (SectionType)aTypesIter.Value();
759 bool aSectClosures = aClosuresIter.Value();
761 theSectNames.Append( aSectName );
762 theSectTypes.Append( aSectType );
763 theSectClosures.Append( aSectClosures );
767 void HYDROData_PolylineXY::RemoveSection( const int theSectionIndex )
769 Handle(TDataStd_ExtStringList) aNamesList;
770 Handle(TDataStd_IntegerList) aTypesList;
771 Handle(TDataStd_BooleanList) aClosuresList;
772 getSectionsLists( aNamesList, aTypesList, aClosuresList, false );
773 if ( aNamesList.IsNull() || theSectionIndex >= aNamesList->Extent() )
776 if ( aNamesList->Extent() == 1 )
778 removeSectionsLists();
783 TDataStd_ListOfExtendedString anOldNamesList;
784 anOldNamesList = aNamesList->List();
786 TColStd_ListOfInteger anOldTypesList;
787 anOldTypesList = aTypesList->List();
789 TDataStd_ListOfByte anOldClosuresList;
790 anOldClosuresList = aClosuresList->List();
792 // Refill the existing lists
795 aClosuresList->Clear();
797 TDataStd_ListIteratorOfListOfExtendedString aNamesIter( anOldNamesList );
798 TColStd_ListIteratorOfListOfInteger aTypesIter( anOldTypesList );
799 TDataStd_ListIteratorOfListOfByte aClosuresIter( anOldClosuresList );
800 for ( int i = 0; aNamesIter.More() && aTypesIter.More() && aClosuresIter.More();
801 aNamesIter.Next(), aTypesIter.Next(), aClosuresIter.Next(), ++i )
803 if ( i == theSectionIndex )
804 continue; // skip index to remove
806 aNamesList->Append( aNamesIter.Value() );
807 aTypesList->Append( aTypesIter.Value() );
808 aClosuresList->Append( (bool)aClosuresIter.Value() );
811 // Remove points that belongs to removed section
812 removePointsLists( theSectionIndex );
818 void HYDROData_PolylineXY::RemoveSections()
820 removeSectionsLists();
825 void HYDROData_PolylineXY::AddPoint( const int theSectionIndex,
826 const Point& thePoint,
827 const int thePointIndex )
829 Handle(TDataStd_RealList) aListX, aListY;
830 getPointsLists( theSectionIndex, aListX, aListY );
832 if ( thePointIndex < 0 || thePointIndex >= aListX->Extent() )
834 aListX->Append( thePoint.X() );
835 aListY->Append( thePoint.Y() );
839 TColStd_ListOfReal anOldListX;
840 anOldListX = aListX->List();
842 TColStd_ListOfReal anOldListY;
843 anOldListY = aListY->List();
845 // Refill the existing lists
849 TColStd_ListIteratorOfListOfReal anIterX( anOldListX );
850 TColStd_ListIteratorOfListOfReal anIterY( anOldListY );
851 for ( int i = 0; anIterX.More() && anIterY.More(); anIterX.Next(), anIterY.Next(), ++i )
853 double aCoordX = anIterX.Value();
854 double aCoordY = anIterY.Value();
856 if ( i == thePointIndex )
858 // Insert our new point
859 aListX->Append( thePoint.X() );
860 aListY->Append( thePoint.Y() );
863 aListX->Append( aCoordX );
864 aListY->Append( aCoordY );
871 void HYDROData_PolylineXY::SetPoint( const int theSectionIndex,
872 const Point& thePoint,
873 const int thePointIndex )
875 Handle(TDataStd_RealList) aListX, aListY;
876 getPointsLists( theSectionIndex, aListX, aListY );
878 if ( thePointIndex < 0 )
880 aListX->Prepend( thePoint.X() );
881 aListY->Prepend( thePoint.Y() );
883 else if ( thePointIndex >= aListX->Extent() )
885 aListX->Append( thePoint.X() );
886 aListY->Append( thePoint.Y() );
890 TColStd_ListOfReal anOldListX;
891 anOldListX = aListX->List();
893 TColStd_ListOfReal anOldListY;
894 anOldListY = aListY->List();
896 // Refill the existing lists
900 TColStd_ListIteratorOfListOfReal anIterX( anOldListX );
901 TColStd_ListIteratorOfListOfReal anIterY( anOldListY );
902 for ( int i = 0; anIterX.More() && anIterY.More(); anIterX.Next(), anIterY.Next(), ++i )
904 double aCoordX = anIterX.Value();
905 double aCoordY = anIterY.Value();
907 if ( i == thePointIndex )
909 // Insert our new point instead of old one
910 aCoordX = thePoint.X();
911 aCoordY = thePoint.Y();
914 aListX->Append( aCoordX );
915 aListY->Append( aCoordY );
922 void HYDROData_PolylineXY::SetPoints( const int theSectionIndex,
923 const PointsList& thePoints )
925 Handle(TDataStd_RealList) aListX, aListY;
926 getPointsLists( theSectionIndex, aListX, aListY );
931 for ( int i = 1, n = thePoints.Length(); i <= n; ++i )
933 const Point& aPoint = thePoints.Value( i );
934 aListX->Append( aPoint.X() );
935 aListY->Append( aPoint.Y() );
939 void HYDROData_PolylineXY::RemovePoint( const int theSectionIndex,
940 const int thePointIndex )
942 Handle(TDataStd_RealList) aListX, aListY;
943 getPointsLists( theSectionIndex, aListX, aListY, false );
944 if ( aListX.IsNull() || aListY.IsNull() || aListX->IsEmpty() )
947 if ( aListX->Extent() == 1 )
949 removePointsLists( theSectionIndex );
953 TColStd_ListOfReal anOldListX;
954 anOldListX = aListX->List();
956 TColStd_ListOfReal anOldListY;
957 anOldListY = aListY->List();
959 // Refill the existing lists
963 TColStd_ListIteratorOfListOfReal anIterX( anOldListX );
964 TColStd_ListIteratorOfListOfReal anIterY( anOldListY );
965 for ( int i = 0; anIterX.More() && anIterY.More(); anIterX.Next(), anIterY.Next(), ++i )
967 if ( i == thePointIndex )
968 continue; // skip index to remove
970 aListX->Append( anIterX.Value() );
971 aListY->Append( anIterY.Value() );
978 HYDROData_PolylineXY::PointsList HYDROData_PolylineXY::GetPoints( const int theSectionIndex ) const
982 Handle(TDataStd_RealList) aListX, aListY;
983 getPointsLists( theSectionIndex, aListX, aListY, false );
984 if ( aListX.IsNull() || aListY.IsNull() || aListX->IsEmpty() )
987 TColStd_ListIteratorOfListOfReal anIterX( aListX->List() );
988 TColStd_ListIteratorOfListOfReal anIterY( aListY->List() );
989 for ( ; anIterX.More() && anIterY.More(); anIterX.Next(), anIterY.Next() )
991 Point aPoint( anIterX.Value(), anIterY.Value() );
992 aResList.Append( aPoint );
998 QPainterPath HYDROData_PolylineXY::GetPainterPath() const
1002 NCollection_Sequence<TCollection_AsciiString> aSectNames;
1003 NCollection_Sequence<HYDROData_PolylineXY::SectionType> aSectTypes;
1004 NCollection_Sequence<bool> aSectClosures;
1005 GetSections( aSectNames, aSectTypes, aSectClosures );
1007 for ( int aSectionId = 1, aNbSects = aSectNames.Size(); aSectionId <= aNbSects; aSectionId++ )
1009 TCollection_AsciiString aSectName = aSectNames.Value( aSectionId );
1010 SectionType aSectionType = aSectTypes.Value( aSectionId );
1011 bool anIsSectionClosed = aSectClosures.Value( aSectionId );
1013 PointsList aSectPointsList = GetPoints( aSectionId - 1 );
1014 if ( aSectPointsList.IsEmpty() )
1017 NCollection_Sequence<gp_XYZ> aPoints;
1018 for( int i = 1, n = aSectPointsList.Size(); i <= n; ++i )
1020 const Point& aSectPoint = aSectPointsList.Value( i );
1022 gp_XYZ aPoint( aSectPoint.X(), aSectPoint.Y(), 0.0 );
1023 aPoints.Append( aPoint );
1026 BuildPainterPath( aPath, aSectionType, anIsSectionClosed, aPoints );