X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FHYDROData%2FHYDROData_PolylineXY.cxx;h=0d79dd238678eeb86abac756dc34ea566189eda2;hb=84ec5b92ea05194a9d4d413b9bc896cf68d2e3ca;hp=04039c96a9f4a9591437404d3247bae5f60824f4;hpb=d84fadb6fba0d9ef3926995eab878175cc24e291;p=modules%2Fhydro.git diff --git a/src/HYDROData/HYDROData_PolylineXY.cxx b/src/HYDROData/HYDROData_PolylineXY.cxx index 04039c96..0d79dd23 100755 --- a/src/HYDROData/HYDROData_PolylineXY.cxx +++ b/src/HYDROData/HYDROData_PolylineXY.cxx @@ -9,6 +9,11 @@ #include #include +#include +#include + +#include + #include #include @@ -80,7 +85,7 @@ QStringList HYDROData_PolylineXY::DumpToPython( MapOfTreatedObjects& theTreatedO HYDROData_PolylineXY::PointsList aSectPointsList = GetPoints( i ); for ( int k = 1, aNbPoints = aSectPointsList.Size(); k <= aNbPoints; ++k ) { - const HYDROData_PolylineXY::Point& aSectPoint = aSectPointsList.Value( k ); + const Point& aSectPoint = aSectPointsList.Value( k ); aResList << QString( "%1.AddPoint( %2, QPointF( %3, %4 ) );" ).arg( aPolylineName ) .arg( i - 1 ).arg( aSectPoint.X() ).arg( aSectPoint.Y() ); @@ -105,6 +110,85 @@ TopoDS_Shape HYDROData_PolylineXY::GetShape() return getPolylineShape(); } +TopoDS_Wire HYDROData_PolylineXY::BuildWire( const SectionType& theType, + const bool& theIsClosed, + const NCollection_Sequence& thePoints ) +{ + BRepBuilderAPI_MakeWire aMakeWire; + + if( theType == SECTION_POLYLINE ) + { + for( int i = 1, n = thePoints.Size(); i <= n; ++i ) + { + const gp_XYZ& aFirstPoint = thePoints.Value( i ); + + gp_XYZ aLastPoint; + if ( i == n ) + { + if( theIsClosed ) + aLastPoint = thePoints.Value( 1 ); + else + break; + } + else + { + aLastPoint = thePoints.Value( i + 1 ); + } + + gp_Pnt aPnt1( aFirstPoint.X(), aFirstPoint.Y(), aFirstPoint.Z() ); + gp_Pnt aPnt2( aLastPoint.X(), aLastPoint.Y(), aLastPoint.Z() ); + + TopoDS_Edge anEdge = BRepBuilderAPI_MakeEdge( aPnt1, aPnt2 ).Edge(); + aMakeWire.Add( anEdge ); + } + } + else //if( theType == PolylineSection::SECTION_SPLINE ) + { + HYDROData_BSplineOperation aBSpline( thePoints, theIsClosed ); + + TopoDS_Edge anEdge = BRepBuilderAPI_MakeEdge( aBSpline.Curve() ).Edge(); + aMakeWire.Add( anEdge ); + } + + TopoDS_Wire aWire; + aMakeWire.Build(); + if ( aMakeWire.IsDone() ) + aWire = aMakeWire; + + return aWire; +} + +QPainterPath HYDROData_PolylineXY::BuildPainterPath( const SectionType& theType, + const bool& theIsClosed, + const NCollection_Sequence& thePoints ) +{ + QPainterPath aPath; + if ( thePoints.IsEmpty() ) + return aPath; + + if ( theType == SECTION_POLYLINE ) + { + aPath.moveTo( thePoints.Value( 1 ).X(), thePoints.Value( 1 ).Y() ); + + for( int i = 2, n = thePoints.Size(); i <= n; ++i ) + { + const gp_XYZ& aSectPoint = thePoints.Value( i ); + + aPath.lineTo( aSectPoint.X(), aSectPoint.Y() ); + } + + if( theIsClosed ) + aPath.closeSubpath(); + } + else + { + HYDROData_BSplineOperation aBSpline( thePoints, theIsClosed ); + aPath = aBSpline.ComputePath(); + } + + return aPath; +} + void HYDROData_PolylineXY::Update() { NCollection_Sequence aSectNames; @@ -125,50 +209,17 @@ void HYDROData_PolylineXY::Update() PointsList aSectPointsList = GetPoints( aSectionId - 1 ); if ( aSectPointsList.IsEmpty() ) continue; - - BRepBuilderAPI_MakeWire aMakeSectionWire; - if( aSectionType == SECTION_POLYLINE ) + + NCollection_Sequence aPoints; + for( int i = 1, n = aSectPointsList.Size(); i <= n; ++i ) { - for( int i = 1, n = aSectPointsList.Size(); i <= n; ++i ) - { - const Point& aFirstPoint = aSectPointsList.Value( i ); - - Point aLastPoint; - if ( i == n ) - { - if( anIsSectionClosed ) - aLastPoint = aSectPointsList.Value( 1 ); - else - break; - } - else - { - aLastPoint = aSectPointsList.Value( i + 1 ); - } - - gp_Pnt aPnt1( aFirstPoint.X(), aFirstPoint.Y(), 0.0 ); - gp_Pnt aPnt2( aLastPoint.X(), aLastPoint.Y(), 0.0 ); + const Point& aSectPoint = aSectPointsList.Value( i ); - TopoDS_Edge anEdge = BRepBuilderAPI_MakeEdge( aPnt1, aPnt2 ).Edge(); - aMakeSectionWire.Add( anEdge ); - } + gp_XYZ aPoint( aSectPoint.X(), aSectPoint.Y(), 0.0 ); + aPoints.Append( aPoint ); } - else //if( aSectionType == PolylineSection::SECTION_SPLINE ) - { - QList aPoints; - for( int i = 1, n = aSectPointsList.Size(); i <= n; ++i ) - { - const Point& aSectPoint = aSectPointsList.Value( i ); - aPoints << aSectPoint.X() << aSectPoint.Y(); - } - - HYDROData_BSplineOperation aBSpline( aPoints, 0.0, anIsSectionClosed ); - TopoDS_Edge anEdge = BRepBuilderAPI_MakeEdge( aBSpline.Curve() ).Edge(); - aMakeSectionWire.Add( anEdge ); - } - - TopoDS_Wire aSectionWire = aMakeSectionWire.Wire(); + TopoDS_Wire aSectionWire = BuildWire( aSectionType, anIsSectionClosed, aPoints ); aSectionWiresList.Append( aSectionWire ); aMakeWire.Add( aSectionWire ); } @@ -218,6 +269,70 @@ bool HYDROData_PolylineXY::IsClosed() const return anIsClosed; } +double HYDROData_PolylineXY::GetDistance( const int theSectionIndex, + const int thePointIndex ) const +{ + double aResDistance = -1; + if ( theSectionIndex < 0 || theSectionIndex >= NbSections() ) + return aResDistance; + + if ( thePointIndex == 0 ) + return 0.0; + + SectionType aSectionType = GetSectionType( theSectionIndex ); + bool anIsSectionClosed = IsClosedSection( theSectionIndex ); + PointsList aSectPointsList = GetPoints( theSectionIndex ); + if ( thePointIndex < 0 || thePointIndex >= aSectPointsList.Size() ) + return aResDistance; + + if ( aSectionType == SECTION_POLYLINE ) + { + aResDistance = 0.0; + + Point aPrevPoint = aSectPointsList.Value( 1 ); + for ( int i = 2, aNbPoints = aSectPointsList.Size(); i <= aNbPoints; ++i ) + { + const Point& aSectPoint = aSectPointsList.Value( i ); + aResDistance += gp_Pnt2d( aPrevPoint ).Distance( aSectPoint ); + aPrevPoint = aSectPoint; + } + } + else + { + gp_XYZ aPointToTest; + + int aSectNbPoints = aSectPointsList.Size(); + NCollection_Sequence aPoints; + for( int i = 1 ; i <= aSectNbPoints; ++i ) + { + const Point& aSectPoint = aSectPointsList.Value( i ); + + gp_XYZ aPoint( aSectPoint.X(), aSectPoint.Y(), 0.0 ); + aPoints.Append( aPoint ); + + if ( thePointIndex == i - 1 ) + aPointToTest = aPoint; + } + + HYDROData_BSplineOperation aBSpline( aPoints, anIsSectionClosed ); + + Quantity_Parameter aFirstParam = aBSpline.Curve()->FirstParameter(); + Quantity_Parameter aSecondParam = aBSpline.Curve()->LastParameter(); + + if ( thePointIndex != aSectNbPoints - 1 ) + { + GeomAPI_ProjectPointOnCurve aProject( aPointToTest, aBSpline.Curve() ); + aSecondParam = aProject.LowerDistanceParameter(); + } + + GeomAdaptor_Curve anAdap( aBSpline.Curve() ); + + aResDistance = GCPnts_AbscissaPoint::Length( anAdap, aFirstParam, aSecondParam ); + } + + return aResDistance; +} + int HYDROData_PolylineXY::NbSections() const { Handle(TDataStd_ExtStringList) aNamesList; @@ -303,9 +418,11 @@ void HYDROData_PolylineXY::SetSectionName( const int theSec // Refill the existing list aNamesList->Clear(); - TDataStd_ListIteratorOfListOfExtendedString aNamesIter( aNamesList->List() ); + TCollection_ExtendedString aNewSectName = theSectionName; + + TDataStd_ListIteratorOfListOfExtendedString aNamesIter( anOldNamesList ); for ( int i = 0; aNamesIter.More(); aNamesIter.Next(), ++i ) - aNamesList->Append( i == theSectionIndex ? theSectionName : aNamesIter.Value() ); + aNamesList->Append( i == theSectionIndex ? aNewSectName : aNamesIter.Value() ); } HYDROData_PolylineXY::SectionType HYDROData_PolylineXY::GetSectionType( const int theSectionIndex ) const @@ -634,34 +751,19 @@ QPainterPath HYDROData_PolylineXY::GetPainterPath() const SectionType aSectionType = aSectTypes.Value( 1 ); bool anIsSectionClosed = aSectClosures.Value( 1 ); - if ( aSectionType == SECTION_POLYLINE ) + NCollection_Sequence aPoints; + for( int i = 1, n = aSectPointsList.Size(); i <= n; ++i ) { - aPath.moveTo( aSectPointsList.Value( 1 ).X(), aSectPointsList.Value( 1 ).Y() ); - - for( int i = 2, n = aSectPointsList.Size(); i <= n; ++i ) - { - const Point& aSectPoint = aSectPointsList.Value( i ); + const Point& aSectPoint = aSectPointsList.Value( i ); - aPath.lineTo( aSectPoint.X(), aSectPoint.Y() ); - } - - if( anIsSectionClosed ) - aPath.closeSubpath(); + gp_XYZ aPoint( aSectPoint.X(), aSectPoint.Y(), 0.0 ); + aPoints.Append( aPoint ); } - else - { - QList aPoints; - for( int i = 1, n = aSectPointsList.Size(); i <= n; ++i ) - { - const Point& aSectPoint = aSectPointsList.Value( i ); - aPoints << aSectPoint.X() << aSectPoint.Y(); - } - HYDROData_BSplineOperation aBSpline( aPoints, 0, anIsSectionClosed ); - aPath = aBSpline.ComputePath(); - } + aPath = BuildPainterPath( aSectionType, anIsSectionClosed, aPoints ); return aPath; + }