From 425b15bf0a9b041a69e1a1400c85d290d2bae51e Mon Sep 17 00:00:00 2001 From: asl Date: Fri, 22 Sep 2017 09:34:59 +0300 Subject: [PATCH] refs #1331: first implementation of the new sorting for profiles --- src/HYDROGUI/HYDROGUI_CurveCreatorProfile.cxx | 27 ++++++++++++++++++- src/HYDROGUI/HYDROGUI_CurveCreatorProfile.h | 2 ++ src/HYDROGUI/HYDROGUI_PolylineOp.cxx | 4 +-- src/HYDROGUI/HYDROGUI_ProfileOp.cxx | 11 ++++---- 4 files changed, 35 insertions(+), 9 deletions(-) diff --git a/src/HYDROGUI/HYDROGUI_CurveCreatorProfile.cxx b/src/HYDROGUI/HYDROGUI_CurveCreatorProfile.cxx index 072567cf..8ea04259 100644 --- a/src/HYDROGUI/HYDROGUI_CurveCreatorProfile.cxx +++ b/src/HYDROGUI/HYDROGUI_CurveCreatorProfile.cxx @@ -19,6 +19,7 @@ #include #include #include +#include HYDROGUI_CurveCreatorProfile::HYDROGUI_CurveCreatorProfile() : CurveCreator_Curve( CurveCreator::Dim2d ) @@ -29,6 +30,7 @@ HYDROGUI_CurveCreatorProfile::HYDROGUI_CurveCreatorProfile() aSection->myIsClosed = false; mySections.push_back( aSection ); + mySkipSorting = true; } HYDROGUI_CurveCreatorProfile::~HYDROGUI_CurveCreatorProfile() @@ -229,7 +231,7 @@ void HYDROGUI_CurveCreatorProfile::convert( const CurveCreator::PosPointsList& t bool HYDROGUI_CurveCreatorProfile::canPointsBeSorted() { - return true; + return false; } /** @@ -259,3 +261,26 @@ bool HYDROGUI_CurveCreatorProfile::addPoints( const CurveCreator::Coordinates& t return CurveCreator_Curve::addPoints( theCoords, theISection, anIPnt ); } + +bool ULess( const gp_Pnt& p1, const gp_Pnt& p2 ) +{ + return p1.X() < p2.X(); +} + +Handle(TColgp_HArray1OfPnt) HYDROGUI_CurveCreatorProfile::GetDifferentPoints( int theISection ) const +{ + Handle(TColgp_HArray1OfPnt) points = CurveCreator_Curve::GetDifferentPoints( theISection ); + if( points.IsNull() ) + return points; + + QVector vpoints( points->Size() ); + for( int i=points->Lower(), j=0, n=points->Upper(); i<=n; i++, j++ ) + vpoints[j] = points->Value( i ); + + qSort( vpoints.begin(), vpoints.end(), ULess ); + + for( int i=points->Lower(), j=0, n=points->Upper(); i<=n; i++, j++ ) + points->SetValue( i, vpoints[j] ); + + return points; +} diff --git a/src/HYDROGUI/HYDROGUI_CurveCreatorProfile.h b/src/HYDROGUI/HYDROGUI_CurveCreatorProfile.h index c70dd7f0..58fd7152 100644 --- a/src/HYDROGUI/HYDROGUI_CurveCreatorProfile.h +++ b/src/HYDROGUI/HYDROGUI_CurveCreatorProfile.h @@ -121,6 +121,8 @@ public: */ virtual bool canPointsBeSorted(); + virtual Handle(TColgp_HArray1OfPnt) GetDifferentPoints( int theISection = -1 ) const; + protected: /** * Converts the list of custom point position objects into a list of point indices diff --git a/src/HYDROGUI/HYDROGUI_PolylineOp.cxx b/src/HYDROGUI/HYDROGUI_PolylineOp.cxx index da94fccf..a59af02d 100755 --- a/src/HYDROGUI/HYDROGUI_PolylineOp.cxx +++ b/src/HYDROGUI/HYDROGUI_PolylineOp.cxx @@ -353,8 +353,8 @@ bool HYDROGUI_PolylineOp::processApply( int& theUpdateFlags, aPolylineObj->AddSection( aSectName, aSectType, aSectClosure ); - // Add the points fro section - CurveCreator::Coordinates aCurveCoords = myCurve->getPoints( i ); + // Add the points from section + CurveCreator::Coordinates aCurveCoords = myCurve->getCoords( i ); if ( aCurveCoords.size() <= 2 ) { diff --git a/src/HYDROGUI/HYDROGUI_ProfileOp.cxx b/src/HYDROGUI/HYDROGUI_ProfileOp.cxx index ab8f669b..732637ac 100644 --- a/src/HYDROGUI/HYDROGUI_ProfileOp.cxx +++ b/src/HYDROGUI/HYDROGUI_ProfileOp.cxx @@ -202,20 +202,19 @@ bool HYDROGUI_ProfileOp::processApply( int& theUpdateFlags, HYDROData_ProfileUZ::PointsList aProfileParamPoints; - CurveCreator::Coordinates aCurveCoords = myProfile->getPoints( 0 ); - if ( aCurveCoords.size() <= 2 ) + Handle(TColgp_HArray1OfPnt) aCurveCoords = myProfile->GetDifferentPoints( 0 ); + if ( aCurveCoords.IsNull() || aCurveCoords->Size() <= 2 ) { theErrorMsg = tr( "NUMBER_OF_PROFILE_POINTS_INCORRECT" ); return false; } - for ( int k = 0 ; k + 1 < aCurveCoords.size() ; k++ ) + for ( int k = aCurveCoords->Lower(); k <= aCurveCoords->Upper() ; k++ ) { HYDROData_ProfileUZ::Point aProfileParamPoint; - aProfileParamPoint.SetX( aCurveCoords.at( k ) ); - k++; - aProfileParamPoint.SetY( aCurveCoords.at( k ) ); + aProfileParamPoint.SetX( aCurveCoords->Value( k ).X() ); + aProfileParamPoint.SetY( aCurveCoords->Value( k ).Y() ); aProfileParamPoints.Append( aProfileParamPoint ); } -- 2.39.2