X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FHYDROData%2FHYDROData_ProfileUZ.cxx;h=9e05e0a83fbe389129ecb72245064f9d6803a5f8;hb=13ef2433b28b41ed4d7338a31839a49c8b599ad7;hp=014288dc4b0140e151155222af403a5f43e5d2df;hpb=a23fa81dd76041264b4ddd65883ea9bfb7cc67bd;p=modules%2Fhydro.git diff --git a/src/HYDROData/HYDROData_ProfileUZ.cxx b/src/HYDROData/HYDROData_ProfileUZ.cxx index 014288dc..9e05e0a8 100755 --- a/src/HYDROData/HYDROData_ProfileUZ.cxx +++ b/src/HYDROData/HYDROData_ProfileUZ.cxx @@ -4,12 +4,16 @@ #include "HYDROData_Tool.h" #include +#include #include +#include +#include +#include #include -#include +#include IMPLEMENT_STANDARD_HANDLE(HYDROData_ProfileUZ, HYDROData_IPolyline) @@ -24,116 +28,121 @@ HYDROData_ProfileUZ::~HYDROData_ProfileUZ() { } -CurveCreator_ICurve::ListAISObjects HYDROData_ProfileUZ::constructWire() const +TopoDS_Shape HYDROData_ProfileUZ::GetShape() const { - // TODO - ListAISObjects aProfileObjects; - return aProfileObjects; + return TopoDS_Shape(); } -bool HYDROData_ProfileUZ::clear() +double HYDROData_ProfileUZ::GetDepthFromDistance( const PointsList& thePoints, + const double& theDistance ) { - removePointsLists(); - return true; -} + double aResDepth = 0.0; -bool HYDROData_ProfileUZ::join( const int theISectionTo, - const int theISectionFrom ) -{ - return false; + int aNbPoints = thePoints.Size(); + if ( aNbPoints < 2 ) + return aResDepth; + + double aCompDist = 0.0; + HYDROData_IPolyline::Point aPrevPoint = thePoints.First(); + for ( int i = 2; i <= aNbPoints; ++i ) + { + const Point& aCurPoint = thePoints.Value( i ); + + double aPntDist = gp_Pnt2d( aPrevPoint.X(), 0 ).Distance( gp_Pnt2d( aCurPoint.X(), 0 ) ); + + aCompDist += aPntDist; + + if ( theDistance < aCompDist ) + { + double aComPntDist = gp_Pnt2d( thePoints.First().X(), 0 ).Distance( gp_Pnt2d( aPrevPoint.X(), 0 ) ); + + double aFindDist = theDistance - aComPntDist; + double aRatio = aFindDist / ( aPntDist - aFindDist ); + + aResDepth = ( aPrevPoint.Y() + aRatio * aCurPoint.Y() ) / ( 1 + aRatio ); + break; + } + + aPrevPoint = aCurPoint; + } + + return aResDepth; } -int HYDROData_ProfileUZ::getNbSections() const +int HYDROData_ProfileUZ::NbSections() const { return 1; } -int HYDROData_ProfileUZ::addSection( const std::string& theName, - const CurveCreator::SectionType theType, - const bool theIsClosed ) +void HYDROData_ProfileUZ::AddSection( const TCollection_AsciiString& /*theSectName*/, + const SectionType /*theSectionType*/, + const bool /*theIsClosed*/ ) { - return 0; } -bool HYDROData_ProfileUZ::removeSection( const int theISection ) +TCollection_AsciiString HYDROData_ProfileUZ::GetSectionName( const int /*theSectionIndex*/ ) const { - return clear(); + return "Section_1"; } -bool HYDROData_ProfileUZ::isClosed( const int theISection ) const +void HYDROData_ProfileUZ::SetSectionName( const int /*theSectionIndex*/, + const TCollection_AsciiString& /*theSectionName*/ ) { - return false; } -bool HYDROData_ProfileUZ::setClosed( const int theISection, - const bool theIsClosed ) +HYDROData_ProfileUZ::SectionType HYDROData_ProfileUZ::GetSectionType( const int /*theSectionIndex*/ ) const { - return false; + Handle(TDataStd_ExtStringList) aNamesList; + Handle(TDataStd_IntegerList) aTypesList; + Handle(TDataStd_BooleanList) aClosuresList; + getSectionsLists( aNamesList, aTypesList, aClosuresList, false ); + if ( aTypesList.IsNull() || aTypesList->IsEmpty() ) + return SECTION_POLYLINE; + + return (SectionType)aTypesList->First(); } -std::string HYDROData_ProfileUZ::getSectionName( const int theISection ) const +void HYDROData_ProfileUZ::SetSectionType( const int /*theSectionIndex*/, + const SectionType theSectionType ) { - return "Section_1"; + Handle(TDataStd_ExtStringList) aNamesList; + Handle(TDataStd_IntegerList) aTypesList; + Handle(TDataStd_BooleanList) aClosuresList; + getSectionsLists( aNamesList, aTypesList, aClosuresList ); + if ( aTypesList.IsNull() ) + return; + + // Refill the existing list + aTypesList->Clear(); + aTypesList->Append( theSectionType ); } -bool HYDROData_ProfileUZ::setSectionName( const int theISection, - const std::string& theName ) +bool HYDROData_ProfileUZ::IsClosedSection( const int /*theSectionIndex*/ ) const { return false; } -CurveCreator::SectionType HYDROData_ProfileUZ::getSectionType( const int theISection ) const +void HYDROData_ProfileUZ::SetSectionClosed( const int /*theSectionIndex*/, + const bool /*theIsClosed*/ ) { - return CurveCreator::Polyline; } -bool HYDROData_ProfileUZ::setSectionType( const int theISection, - const CurveCreator::SectionType theType ) +void HYDROData_ProfileUZ::RemoveSection( const int /*theSectionIndex*/ ) { - return false; + RemoveSections(); } -bool HYDROData_ProfileUZ::addPoints( const CurveCreator::Coordinates& theCoords, - const int theISection, - const int theIPnt ) +void HYDROData_ProfileUZ::RemoveSections() { - bool anIsOperation = myIsOperation; - if ( !anIsOperation ) - startOperation(); - - bool aRes = true; - - int anAfterPnt = theIPnt; - - CurveCreator::Coordinates::const_iterator aBegIter = theCoords.begin(); - CurveCreator::Coordinates::const_iterator anEndIter = theCoords.end(); - while ( aBegIter != anEndIter ) - { - const CurveCreator::TypeCoord& aCoordX = *aBegIter++; - if ( aBegIter == anEndIter ) - break; - - const CurveCreator::TypeCoord& aCoordY = *aBegIter++; - - aRes = addPoint( aCoordX, aCoordY, theISection, anAfterPnt ) && aRes; - - if ( anAfterPnt != -1 ) - ++anAfterPnt; - } - - if ( !anIsOperation ) - commitOperation(); - - return aRes; + removePointsLists( 0 ); } -bool HYDROData_ProfileUZ::addPoint( const CurveCreator::TypeCoord& theCoordX, - const CurveCreator::TypeCoord& theCoordY, - const int theISection, - const int theIPnt ) +void HYDROData_ProfileUZ::AddPoint( const int /*theSectionIndex*/, + const Point& thePoint, + const int thePointIndex ) { - CurveCreator::TypeCoord aNewCoordU = theCoordX; - CurveCreator::TypeCoord aNewCoordZ = theCoordY; + double aNewCoordU = thePoint.X(); + double aNewCoordZ = thePoint.Y(); Handle(TDataStd_RealList) aListU, aListZ; getPointsLists( 0, aListU, aListZ ); @@ -142,69 +151,69 @@ bool HYDROData_ProfileUZ::addPoint( const CurveCreator::TypeCoord& theCoordX, { aListU->Append( aNewCoordU ); aListZ->Append( aNewCoordZ ); + return; } else if ( aNewCoordU < aListU->First() ) { aListU->Prepend( aNewCoordU ); aListZ->Prepend( aNewCoordZ ); + return; } - else - { - TColStd_ListOfReal anOldListU; - anOldListU = aListU->List(); - TColStd_ListOfReal anOldListZ; - anOldListZ = aListZ->List(); + TColStd_ListOfReal anOldListU; + anOldListU = aListU->List(); + + TColStd_ListOfReal anOldListZ; + anOldListZ = aListZ->List(); - // Refill the existing lists - aListU->Clear(); - aListZ->Clear(); + // Crsat new lists + removePointsLists( 0 ); + getPointsLists( 0, aListU, aListZ ); - bool anIsInserted = false; - TColStd_ListIteratorOfListOfReal anIterU( anOldListU ); - TColStd_ListIteratorOfListOfReal anIterZ( anOldListZ ); - for ( ; anIterU.More() && anIterZ.More(); anIterU.Next(), anIterZ.Next() ) - { - double aCoordU = anIterU.Value(); - double aCoordZ = anIterZ.Value(); + bool anIsInserted = false; + TColStd_ListIteratorOfListOfReal anIterU( anOldListU ); + TColStd_ListIteratorOfListOfReal anIterZ( anOldListZ ); + for ( ; anIterU.More() && anIterZ.More(); anIterU.Next(), anIterZ.Next() ) + { + double aCoordU = anIterU.Value(); + double aCoordZ = anIterZ.Value(); - if ( !anIsInserted ) + if ( !anIsInserted ) + { + if ( ValuesEquals( aNewCoordU, aCoordU ) ) { - if ( ValuesEquals( aNewCoordU, aCoordU ) ) - { - // Just update Z value - aCoordZ = aNewCoordZ; - anIsInserted = true; - } - else if ( aNewCoordU < aCoordU ) - { - // Insert new point - aListU->Append( aNewCoordU ); - aListZ->Append( aNewCoordZ ); - anIsInserted = true; - } + // Just update Z value + aCoordZ = aNewCoordZ; + anIsInserted = true; + } + else if ( aNewCoordU < aCoordU ) + { + // Insert new point + aListU->Append( aNewCoordU ); + aListZ->Append( aNewCoordZ ); + anIsInserted = true; } - - aListU->Append( aCoordU ); - aListZ->Append( aCoordZ ); } + + aListU->Append( aCoordU ); + aListZ->Append( aCoordZ ); } +} - return true; +void HYDROData_ProfileUZ::SetPoint( const int theSectionIndex, + const Point& thePoint, + const int /*thePointIndex*/ ) +{ + AddPoint( theSectionIndex, thePoint ); } -bool HYDROData_ProfileUZ::removePoint( const int /*theISection*/, - const int theIPnt ) +void HYDROData_ProfileUZ::RemovePoint( const int /*theSectionIndex*/, + const int thePointIndex ) { Handle(TDataStd_RealList) aListU, aListZ; getPointsLists( 0, aListU, aListZ, false ); - if ( aListU.IsNull() || aListZ.IsNull() || - theIPnt < 0 || theIPnt >= aListU->Extent() ) - return false; - - bool anIsOperation = myIsOperation; - if ( !anIsOperation ) - startOperation(); + if ( aListU.IsNull() || aListZ.IsNull() || aListU->IsEmpty() ) + return; TColStd_ListOfReal anOldListU; anOldListU = aListU->List(); @@ -212,62 +221,26 @@ bool HYDROData_ProfileUZ::removePoint( const int /*theISection*/, TColStd_ListOfReal anOldListZ; anOldListZ = aListZ->List(); - // Refill the existing lists - aListU->Clear(); - aListZ->Clear(); + // Creat new lists + removePointsLists( 0 ); + getPointsLists( 0, aListU, aListZ ); + bool anIsInserted = false; TColStd_ListIteratorOfListOfReal anIterU( anOldListU ); TColStd_ListIteratorOfListOfReal anIterZ( anOldListZ ); for ( int i = 0; anIterU.More() && anIterZ.More(); anIterU.Next(), anIterZ.Next(), ++i ) { - if ( i == theIPnt ) + if ( i == thePointIndex ) continue; // skip index to remove aListU->Append( anIterU.Value() ); aListZ->Append( anIterZ.Value() ); } - - if ( !anIsOperation ) - commitOperation(); - - return true; -} - -//! Remove several points from different sections with given ids -bool HYDROData_ProfileUZ::removeSeveralPoints( const SectionToPointList &theSectionToPntIDs) -{ - return false; } -bool HYDROData_ProfileUZ::setPoint( const int /*theISection*/, - const int theIPoint, - const CurveCreator::Coordinates& theNewCoords ) +HYDROData_ProfileUZ::PointsList HYDROData_ProfileUZ::GetPoints( const int /*theSectionIndex*/ ) const { - bool anIsOperation = myIsOperation; - if ( !anIsOperation ) - startOperation(); - - // At first we remove point - removePoint( 0, theIPoint ); - - // And then we insert it to correct place - bool aRes = addPoints( theNewCoords, 0 ); - - if ( !anIsOperation ) - commitOperation(); - - return aRes; -} - -//! Set coordinates of specified points from different sections -bool HYDROData_ProfileUZ::setSeveralPoints( const SectionToPointCoordsList &theSectionToPntCoords) -{ - return false; -} - -CurveCreator::Coordinates HYDROData_ProfileUZ::getPoints( const int /*theISection*/ ) const -{ - CurveCreator::Coordinates aResList; + PointsList aResList; Handle(TDataStd_RealList) aListU, aListZ; getPointsLists( 0, aListU, aListZ, false ); @@ -278,11 +251,8 @@ CurveCreator::Coordinates HYDROData_ProfileUZ::getPoints( const int /*theISectio TColStd_ListIteratorOfListOfReal anIterZ( aListZ->List() ); for ( ; anIterU.More() && anIterZ.More(); anIterU.Next(), anIterZ.Next() ) { - const double& aCoordU = anIterU.Value(); - const double& aCoordZ = anIterZ.Value(); - - aResList.push_back( aCoordU ); - aResList.push_back( aCoordZ ); + Point aPoint( anIterU.Value(), anIterZ.Value() ); + aResList.Append( aPoint ); } return aResList;