From 53a95466cbe84e05377a265238b6af6a0c718981 Mon Sep 17 00:00:00 2001 From: mzn Date: Wed, 1 Apr 2015 19:16:26 +0300 Subject: [PATCH] refs #493: provide Python API --- src/HYDROData/CMakeLists.txt | 16 +- src/HYDROData/HYDROData_Document.cxx | 26 ++++ src/HYDROData/HYDROData_Document.h | 7 + .../HYDROData_IProfilesInterpolator.cxx | 83 +++++++++- .../HYDROData_IProfilesInterpolator.h | 66 ++++++-- .../HYDROData_InterpolatorsFactory.cxx | 10 +- .../HYDROData_InterpolatorsFactory.h | 22 ++- .../HYDROData_LinearInterpolator.cxx | 8 +- src/HYDROData/HYDROData_LinearInterpolator.h | 2 +- src/HYDROData/HYDROData_Stream.cxx | 21 +-- .../HYDROGUI_ProfileInterpolateOp.cxx | 39 +++-- src/HYDROGUI/HYDROGUI_ProfileInterpolateOp.h | 2 +- src/HYDROPy/CMakeLists.txt | 1 + src/HYDROPy/HYDROData.sip | 1 + src/HYDROPy/HYDROData_Document.sip | 6 + .../HYDROData_IProfilesInterpolator.sip | 142 ++++++++++++++++++ src/HYDROPy/HYDROData_Stream.sip | 7 + 17 files changed, 375 insertions(+), 84 deletions(-) create mode 100644 src/HYDROPy/HYDROData_IProfilesInterpolator.sip diff --git a/src/HYDROData/CMakeLists.txt b/src/HYDROData/CMakeLists.txt index b1a830e4..188d4d2b 100644 --- a/src/HYDROData/CMakeLists.txt +++ b/src/HYDROData/CMakeLists.txt @@ -46,10 +46,10 @@ set(PROJECT_HEADERS HYDROData_VisualState.h HYDROData_Warning.h HYDROData_Zone.h - HYDROData_GeomTool.h - HYDROData_IProfilesInterpolator.h - HYDROData_LinearInterpolator.h - HYDROData_InterpolatorsFactory.h + HYDROData_GeomTool.h + HYDROData_IProfilesInterpolator.h + HYDROData_LinearInterpolator.h + HYDROData_InterpolatorsFactory.h ) set(PROJECT_SOURCES @@ -96,10 +96,10 @@ set(PROJECT_SOURCES HYDROData_Transform.cxx HYDROData_VisualState.cxx HYDROData_Zone.cxx - HYDROData_GeomTool.cxx - HYDROData_IProfilesInterpolator.cxx - HYDROData_LinearInterpolator.cxx - HYDROData_InterpolatorsFactory.cxx + HYDROData_GeomTool.cxx + HYDROData_IProfilesInterpolator.cxx + HYDROData_LinearInterpolator.cxx + HYDROData_InterpolatorsFactory.cxx ) add_definitions( diff --git a/src/HYDROData/HYDROData_Document.cxx b/src/HYDROData/HYDROData_Document.cxx index a032f025..7c9773ba 100644 --- a/src/HYDROData/HYDROData_Document.cxx +++ b/src/HYDROData/HYDROData_Document.cxx @@ -815,4 +815,30 @@ HYDROData_InterpolatorsFactory* HYDROData_Document::GetInterpolatorsFactory() } return myInterpolatorsFactory; +} + +HYDROData_IProfilesInterpolator* HYDROData_Document::GetInterpolator( const TCollection_AsciiString& theName ) const +{ + HYDROData_IProfilesInterpolator* anInterpolator = NULL; + + HYDROData_Document* aThat = const_cast( this ); + HYDROData_InterpolatorsFactory* aFactory = aThat->GetInterpolatorsFactory(); + if ( aFactory ) { + anInterpolator = aFactory->GetInterpolator( theName ); + } + + return anInterpolator; +} + +NCollection_Sequence HYDROData_Document::GetInterpolatorNames() const +{ + NCollection_Sequence aNames; + + HYDROData_Document* aThat = const_cast( this ); + HYDROData_InterpolatorsFactory* aFactory = aThat->GetInterpolatorsFactory(); + if ( aFactory ) { + aNames = aFactory->GetInterpolatorNames(); + } + + return aNames; } \ No newline at end of file diff --git a/src/HYDROData/HYDROData_Document.h b/src/HYDROData/HYDROData_Document.h index ae33d54e..009eda2f 100644 --- a/src/HYDROData/HYDROData_Document.h +++ b/src/HYDROData/HYDROData_Document.h @@ -29,6 +29,7 @@ #include class HYDROData_InterpolatorsFactory; +class HYDROData_IProfilesInterpolator; class QFile; class gp_Pnt2d; @@ -215,6 +216,12 @@ public: //! Returns interpolator factory instance HYDRODATA_EXPORT HYDROData_InterpolatorsFactory* GetInterpolatorsFactory(); + //! Get the appropriate interpolator by the name. + HYDRODATA_EXPORT HYDROData_IProfilesInterpolator* GetInterpolator( const TCollection_AsciiString& theName ) const; + + //! Get list of registered interpolator names. + HYDRODATA_EXPORT NCollection_Sequence GetInterpolatorNames() const; + protected: friend class HYDROData_Iterator; diff --git a/src/HYDROData/HYDROData_IProfilesInterpolator.cxx b/src/HYDROData/HYDROData_IProfilesInterpolator.cxx index 2af03fd7..264de971 100644 --- a/src/HYDROData/HYDROData_IProfilesInterpolator.cxx +++ b/src/HYDROData/HYDROData_IProfilesInterpolator.cxx @@ -22,6 +22,7 @@ #include "HYDROData_IProfilesInterpolator.h" +#include const int DEFAULT_RESULT_PROFILES_NB = 1; ///< default number of results profiles @@ -35,15 +36,37 @@ HYDROData_IProfilesInterpolator::~HYDROData_IProfilesInterpolator() { } -void HYDROData_IProfilesInterpolator::SetProfiles( const std::vector theProfile1, const std::vector theProfile2 ) +void HYDROData_IProfilesInterpolator::SetProfiles( const std::vector theProfile1, + const std::vector theProfile2 ) { myProfile1 = theProfile1; myProfile2 = theProfile2; } -void HYDROData_IProfilesInterpolator::SetParameter( const std::string& theName, const std::string& theValue ) +void HYDROData_IProfilesInterpolator::SetProfiles( const NCollection_Sequence& theProfile1, + const NCollection_Sequence& theProfile2 ) { - myParameters[theName] = theValue; + // The first profile + for ( int i = theProfile1.Lower(); i <= theProfile1.Upper(); i++ ) { + const gp_XYZ& aPnt = theProfile1.Value( i ); + myProfile1.push_back( aPnt.X() ); + myProfile1.push_back( aPnt.Y() ); + myProfile1.push_back( aPnt.Z() ); + } + + // The second profile + for ( int i = theProfile2.Lower(); i <= theProfile2.Upper(); i++ ) { + const gp_XYZ& aPnt = theProfile2.Value( i ); + myProfile2.push_back( aPnt.X() ); + myProfile2.push_back( aPnt.Y() ); + myProfile2.push_back( aPnt.Z() ); + } +} + +void HYDROData_IProfilesInterpolator::SetParameter( const TCollection_AsciiString& theName, + const TCollection_AsciiString& theValue ) +{ + myParameters[theName.ToCString()] = theValue.ToCString(); } InterpolationError HYDROData_IProfilesInterpolator::GetErrorCode() const @@ -56,9 +79,9 @@ void HYDROData_IProfilesInterpolator::SetErrorCode( const InterpolationError& th myErrorCode = theError; } -std::string HYDROData_IProfilesInterpolator::GetErrorMessage() const +TCollection_AsciiString HYDROData_IProfilesInterpolator::GetErrorMessage() const { - return myErrorMessage; + return TCollection_AsciiString(myErrorMessage.c_str()); } void HYDROData_IProfilesInterpolator::SetErrorMessage( const std::string& theMessage ) @@ -76,7 +99,7 @@ int HYDROData_IProfilesInterpolator::GetCalculatedProfilesNumber() const return myResultProfiles.size(); } -std::vector HYDROData_IProfilesInterpolator::GetResultProfile( const int theProfileIndex ) const +std::vector HYDROData_IProfilesInterpolator::GetResultProfileCoords( const int theProfileIndex ) const { std::vector aResultProfile; @@ -87,6 +110,11 @@ std::vector HYDROData_IProfilesInterpolator::GetResultProfile( const int return aResultProfile; } +NCollection_Sequence HYDROData_IProfilesInterpolator::GetResultProfilePoints( const int theProfileIndex ) const +{ + return GetPoints( GetResultProfileCoords( theProfileIndex ) ); +} + void HYDROData_IProfilesInterpolator::Reset() { // Reset input parameters @@ -100,12 +128,12 @@ void HYDROData_IProfilesInterpolator::Reset() ClearResults(); } -std::vector HYDROData_IProfilesInterpolator::GetFirstProfile() const +std::vector HYDROData_IProfilesInterpolator::GetFirstProfileCoords() const { return myProfile1; } -std::vector HYDROData_IProfilesInterpolator::GetSecondProfile() const +std::vector HYDROData_IProfilesInterpolator::GetSecondProfileCoords() const { return myProfile2; } @@ -128,4 +156,43 @@ int HYDROData_IProfilesInterpolator::GetNbProfilesToCompute() const void HYDROData_IProfilesInterpolator::InsertResultProfile( const std::vector& theProfile ) { myResultProfiles.push_back( theProfile ); +} + +void HYDROData_IProfilesInterpolator::InsertResultProfile( const NCollection_Sequence& theProfile ) +{ + std::vector aCoords; + + for ( int i = theProfile.Lower(); i <= theProfile.Upper(); i++ ) { + const gp_XYZ& aPnt = theProfile.Value( i ); + aCoords.push_back( aPnt.X() ); + aCoords.push_back( aPnt.Y() ); + aCoords.push_back( aPnt.Z() ); + } + + myResultProfiles.push_back( aCoords ); +} + +NCollection_Sequence HYDROData_IProfilesInterpolator::GetFirstProfilePoints() const +{ + return GetPoints( GetFirstProfileCoords() ); +} + +NCollection_Sequence HYDROData_IProfilesInterpolator::GetSecondProfilePoints() const +{ + return GetPoints( GetSecondProfileCoords() ); +} + +NCollection_Sequence HYDROData_IProfilesInterpolator::GetPoints( const std::vector& theCoords ) const +{ + NCollection_Sequence aProfilePoints; + + int aNbCoords = (int) theCoords.size(); + div_t aDiv = std::div( aNbCoords, 3 ); + if ( aDiv.rem == 0 ) { + for ( int i = 0; i < aNbCoords; i += 3 ) { + aProfilePoints.Append( gp_XYZ( theCoords[i], theCoords[i+1], theCoords[i+2] ) ); + } + } + + return aProfilePoints; } \ No newline at end of file diff --git a/src/HYDROData/HYDROData_IProfilesInterpolator.h b/src/HYDROData/HYDROData_IProfilesInterpolator.h index 09695727..2ec6c902 100644 --- a/src/HYDROData/HYDROData_IProfilesInterpolator.h +++ b/src/HYDROData/HYDROData_IProfilesInterpolator.h @@ -25,10 +25,15 @@ #include "HYDROData.h" +#include +#include + #include #include #include +class gp_XYZ; + /** * Errors that could appear on interpolation calculations. @@ -63,7 +68,7 @@ public: * Get description of the interpolation algorithm. * \return the description string */ - HYDRODATA_EXPORT virtual std::string GetDescription() const = 0; + HYDRODATA_EXPORT virtual TCollection_AsciiString GetDescription() const = 0; /** * Set profiles as vectors of point coordinates [x1, y1, z1, x2, y2, z2, ...]. @@ -72,6 +77,14 @@ public: */ HYDRODATA_EXPORT virtual void SetProfiles( const std::vector theProfile1, const std::vector theProfile2 ); + /** + * Set profiles as sequences of gp_XYZ points. + * \param theProfile1 the first profile points + * \param theProfile1 the second profile points + */ + HYDRODATA_EXPORT virtual void SetProfiles( const NCollection_Sequence& theProfile1, + const NCollection_Sequence& theProfile2 ); + /** * Set number of profiles to compute. * \param theNumber the number of profiles to be computed @@ -83,7 +96,8 @@ public: * \param the parameter name * \param the parameter value */ - HYDRODATA_EXPORT virtual void SetParameter( const std::string& theName, const std::string& theValue ); + HYDRODATA_EXPORT virtual void SetParameter( const TCollection_AsciiString& theName, + const TCollection_AsciiString& theValue ); /** * Get the last error code. @@ -95,7 +109,7 @@ public: * Get string description of the last error. * \return the string description */ - HYDRODATA_EXPORT virtual std::string GetErrorMessage() const; + HYDRODATA_EXPORT virtual TCollection_AsciiString GetErrorMessage() const; /** * Reset interpolator state: both input and output data are reset. @@ -110,16 +124,23 @@ public: /** * Get number of calculated profiles ( could be less than the number of profiles to be computed set as a parameter ). - * @return the number of really calculated profiles + * \return the number of really calculated profiles */ HYDRODATA_EXPORT virtual int GetCalculatedProfilesNumber() const; /** - * Get result profile by index. + * Get result profile by index as a vector of point coordinates [x1, y1, z1, x2, y2, z2, ...]. * \param theProfileIndex the profile index [0, ] * \return the profile with the given index or empty vector if the index is out of range */ - HYDRODATA_EXPORT std::vector GetResultProfile( const int theProfileIndex ) const; + HYDRODATA_EXPORT std::vector GetResultProfileCoords( const int theProfileIndex ) const; + + /** + * Get result profile by index as a sequence of gp_XYZ points. + * \param theProfileIndex the profile index [0, ] + * \return the profile with the given index or empty sequence if the index is out of range + */ + HYDRODATA_EXPORT NCollection_Sequence GetResultProfilePoints( const int theProfileIndex ) const; protected: /** @@ -135,16 +156,28 @@ protected: HYDRODATA_EXPORT virtual void SetErrorMessage( const std::string& theMessage ); /** - * Get the first profile. + * Get the first profile coordinates. + * \return the first profile points + */ + HYDRODATA_EXPORT std::vector GetFirstProfileCoords() const; + + /** + * Get the second profile coordinates. + * \return the second profile points + */ + HYDRODATA_EXPORT std::vector GetSecondProfileCoords() const; + + /** + * Get the first profile points. * \return the first profile points */ - HYDRODATA_EXPORT std::vector GetFirstProfile() const; + HYDRODATA_EXPORT NCollection_Sequence GetFirstProfilePoints() const; /** - * Get the second profile. + * Get the second profile points. * \return the second profile points */ - HYDRODATA_EXPORT std::vector GetSecondProfile() const; + HYDRODATA_EXPORT NCollection_Sequence GetSecondProfilePoints() const; /** * Get number of profiles to compute. @@ -158,11 +191,20 @@ protected: HYDRODATA_EXPORT void ClearResults(); /** - * Insert the calculated profile to the resuls. - * \param theProfile the profile to insert + * Insert the calculated profile to the resuls as a list of coordinates. + * \param theProfile the list of coordinates [x1, y1, z1, x2, y2, z2, ...] */ HYDRODATA_EXPORT void InsertResultProfile( const std::vector& theProfile ); + /** + * Insert the calculated profile to the resuls as a list of points. + * \param theProfile the list of points gp_XYZ + */ + HYDRODATA_EXPORT void InsertResultProfile( const NCollection_Sequence& theProfile ); + +private: + NCollection_Sequence GetPoints( const std::vector& theCoords ) const; + private: std::vector myProfile1, myProfile2; ///< the two input profiles int myResultProfilesNumber; ///< the number of profiles to compute diff --git a/src/HYDROData/HYDROData_InterpolatorsFactory.cxx b/src/HYDROData/HYDROData_InterpolatorsFactory.cxx index 8b11eda0..0a130c8a 100644 --- a/src/HYDROData/HYDROData_InterpolatorsFactory.cxx +++ b/src/HYDROData/HYDROData_InterpolatorsFactory.cxx @@ -33,11 +33,11 @@ HYDROData_InterpolatorsFactory::~HYDROData_InterpolatorsFactory() { } -HYDROData_IProfilesInterpolator* HYDROData_InterpolatorsFactory::GetInterpolator( const std::string& theName ) const +HYDROData_IProfilesInterpolator* HYDROData_InterpolatorsFactory::GetInterpolator( const TCollection_AsciiString& theName ) const { HYDROData_IProfilesInterpolator* anInterpolator = NULL; - FactoryInterpolators::const_iterator anIt = myInterpolators.find(theName); + FactoryInterpolators::const_iterator anIt = myInterpolators.find(theName.ToCString()); if ( anIt != myInterpolators.end() ) { anInterpolator = anIt->second; } @@ -45,13 +45,13 @@ HYDROData_IProfilesInterpolator* HYDROData_InterpolatorsFactory::GetInterpolator return anInterpolator; } -std::vector HYDROData_InterpolatorsFactory::GetInterpolatorNames() const +NCollection_Sequence HYDROData_InterpolatorsFactory::GetInterpolatorNames() const { - std::vector aNames; + NCollection_Sequence aNames; FactoryInterpolators::const_iterator anIt = myInterpolators.begin(); for ( ; anIt != myInterpolators.end(); anIt++ ) { - aNames.push_back( anIt->first ); + aNames.Append( anIt->first.c_str() ); } return aNames; diff --git a/src/HYDROData/HYDROData_InterpolatorsFactory.h b/src/HYDROData/HYDROData_InterpolatorsFactory.h index 84cdd995..0a258afd 100644 --- a/src/HYDROData/HYDROData_InterpolatorsFactory.h +++ b/src/HYDROData/HYDROData_InterpolatorsFactory.h @@ -25,13 +25,16 @@ #include +#include +#include + #include -#include #include class HYDROData_IProfilesInterpolator; -/**\class HYDROData_InterpolatorsFactory +/** + * \class HYDROData_InterpolatorsFactory * * \brief Profile interpolators factory. * @@ -43,16 +46,23 @@ class HYDROData_InterpolatorsFactory { public: + /** + * Public constructor. + */ HYDROData_InterpolatorsFactory(); + + /** + * Public virtual destructor. + */ virtual ~HYDROData_InterpolatorsFactory(); /** * Registers the interpolator of a certain type with the given name. * \param theName the interpolator name used as identifier */ - template /*HYDRODATA_EXPORT */void Register( const std::string& theName ) + template /*HYDRODATA_EXPORT */void Register( const TCollection_AsciiString& theName ) { - myInterpolators[theName] = new T(); + myInterpolators[theName.ToCString()] = new T(); } /** @@ -60,13 +70,13 @@ public: * \param theName name of the interpolator * \returns the appropriate interpolator or NULL if interpolator with such name is not registered */ - HYDRODATA_EXPORT HYDROData_IProfilesInterpolator* GetInterpolator( const std::string& theName ) const; + HYDRODATA_EXPORT HYDROData_IProfilesInterpolator* GetInterpolator( const TCollection_AsciiString& theName ) const; /** * Get list of registered interpolator names. * \return the list of unique names */ - HYDRODATA_EXPORT std::vector GetInterpolatorNames() const; + HYDRODATA_EXPORT NCollection_Sequence GetInterpolatorNames() const; private: //! Map that stores all interpolators, identified by interpolator name (string) diff --git a/src/HYDROData/HYDROData_LinearInterpolator.cxx b/src/HYDROData/HYDROData_LinearInterpolator.cxx index fedb3f12..6112500a 100644 --- a/src/HYDROData/HYDROData_LinearInterpolator.cxx +++ b/src/HYDROData/HYDROData_LinearInterpolator.cxx @@ -31,9 +31,9 @@ HYDROData_LinearInterpolator::~HYDROData_LinearInterpolator() { } -std::string HYDROData_LinearInterpolator::GetDescription() const +TCollection_AsciiString HYDROData_LinearInterpolator::GetDescription() const { - std::string aDescription( "Simple linear interpolator" ); + TCollection_AsciiString aDescription( "Simple linear interpolator" ); return aDescription; } @@ -44,8 +44,8 @@ void HYDROData_LinearInterpolator::Calculate() ClearResults(); // Check input data - std::vector aProfile1 = GetFirstProfile(); - std::vector aProfile2 = GetSecondProfile(); + std::vector aProfile1 = GetFirstProfileCoords(); + std::vector aProfile2 = GetSecondProfileCoords(); int aNbProfilesToCompute = GetNbProfilesToCompute(); int aSize1 = aProfile1.size(); diff --git a/src/HYDROData/HYDROData_LinearInterpolator.h b/src/HYDROData/HYDROData_LinearInterpolator.h index 4cd4e8e7..a46bbca6 100644 --- a/src/HYDROData/HYDROData_LinearInterpolator.h +++ b/src/HYDROData/HYDROData_LinearInterpolator.h @@ -48,7 +48,7 @@ public: /** * */ - HYDRODATA_EXPORT virtual std::string GetDescription() const; + HYDRODATA_EXPORT virtual TCollection_AsciiString GetDescription() const; /** * diff --git a/src/HYDROData/HYDROData_Stream.cxx b/src/HYDROData/HYDROData_Stream.cxx index bf9480c9..8e3cb8ee 100644 --- a/src/HYDROData/HYDROData_Stream.cxx +++ b/src/HYDROData/HYDROData_Stream.cxx @@ -1154,13 +1154,12 @@ bool HYDROData_Stream::Interpolate( HYDROData_IProfilesInterpolator* theInterpol for ( int aProfileInd = 0; aProfileInd < theInterpolator->GetCalculatedProfilesNumber(); aProfileInd++ ) { // Get calculated point coordinates - std::vector aResultCoords = theInterpolator->GetResultProfile( aProfileInd ); - div_t aDiv = std::div( aResultCoords.size(), 3 ); - if ( aDiv.rem != 0 ) { + HYDROData_Profile::ProfilePoints aResultPoints = theInterpolator->GetResultProfilePoints( aProfileInd ); + if ( aResultPoints.IsEmpty() ) { isOK = false; continue; } - + // Create profile object Handle(HYDROData_Profile) aProfile = Handle(HYDROData_Profile)::DownCast( aDocument->CreateObject( KIND_PROFILE ) ); @@ -1169,19 +1168,7 @@ bool HYDROData_Stream::Interpolate( HYDROData_IProfilesInterpolator* theInterpol aProfile->SetName( aName ); // Fill the profile with points - HYDROData_Profile::ProfilePoints aProfilePoints; - - int aPointsNb = aDiv.quot; - for ( int aPointInd = 0; aPointInd <= aPointsNb - 1; aPointInd++ ) { - int anXindex = aPointInd * 3; - double anX = aResultCoords[ anXindex ]; - double anY = aResultCoords[ anXindex + 1 ]; - double aZ = aResultCoords[ anXindex + 2 ]; - - aProfilePoints.Append( gp_XYZ( anX, anY, aZ ) ); - } - - aProfile->SetProfilePoints( aProfilePoints ); + aProfile->SetProfilePoints( aResultPoints ); // Add profile to the stream bool isAdded = AddProfile( aProfile ); diff --git a/src/HYDROGUI/HYDROGUI_ProfileInterpolateOp.cxx b/src/HYDROGUI/HYDROGUI_ProfileInterpolateOp.cxx index 4f328628..0f8d398f 100644 --- a/src/HYDROGUI/HYDROGUI_ProfileInterpolateOp.cxx +++ b/src/HYDROGUI/HYDROGUI_ProfileInterpolateOp.cxx @@ -142,7 +142,7 @@ bool HYDROGUI_ProfileInterpolateOp::processApply( int& theUpdateFlags, QString& commitDocOperation(); else { - errMessage = tr( "CALCULATE_ERROR" ), QString( anIterp->GetErrorMessage().c_str() ); + errMessage = tr( "CALCULATE_ERROR" ), QString( HYDROGUI_Tool::ToQString( anIterp->GetErrorMessage() ) ); abortDocOperation(); } } @@ -208,24 +208,19 @@ void HYDROGUI_ProfileInterpolateOp::updateInterpolator( HYDROData_IProfilesInter theInt->SetResultProfilesNumber( aDlg->profileNumber() ); theInt->SetProfiles( profile( aDlg->profileStart() ), profile( aDlg->profileFinish() ) ); ParamsList aParams = parameters( aDlg->interpolatorParameters() ); - for ( ParamsList::Iterator it = aParams.begin(); it != aParams.end(); ++it ) - theInt->SetParameter( (*it).first.toStdString(), (*it).second.toStdString() ); + for ( ParamsList::Iterator it = aParams.begin(); it != aParams.end(); ++it ) { + theInt->SetParameter( HYDROGUI_Tool::ToAsciiString( (*it).first ), + HYDROGUI_Tool::ToAsciiString( (*it).second ) ); + } } -std::vector HYDROGUI_ProfileInterpolateOp::profile( const QString& theName ) const +HYDROData_Profile::ProfilePoints HYDROGUI_ProfileInterpolateOp::profile( const QString& theName ) const { - std::vector aPoints; + HYDROData_Profile::ProfilePoints aPoints; Handle(HYDROData_Profile) aProf = Handle(HYDROData_Profile)::DownCast( HYDROGUI_Tool::FindObjectByName( module(), theName, KIND_PROFILE ) ); if ( !aProf.IsNull() ) { - HYDROData_Profile::ProfilePoints aPntList = aProf->GetProfilePoints(); - for ( int i = aPntList.Lower(); i <= aPntList.Upper(); i++ ) - { - HYDROData_Profile::ProfilePoint aPnt = aPntList.Value( i ); - aPoints.push_back( aPnt.X() ); - aPoints.push_back( aPnt.Y() ); - aPoints.push_back( aPnt.Z() ); - } + aPoints = aProf->GetProfilePoints(); } return aPoints; } @@ -270,9 +265,11 @@ QStringList HYDROGUI_ProfileInterpolateOp::interpolators() const QStringList aNames; if ( anIFactory ) { - std::vector iNames = anIFactory->GetInterpolatorNames(); - for ( std::vector::iterator it = iNames.begin(); it != iNames.end(); ++it ) - aNames.append( (*it).c_str() ); + NCollection_Sequence iNames = anIFactory->GetInterpolatorNames(); + for ( int i = 1, n = iNames.Size(); i <= n; ++i ) { + const TCollection_AsciiString& anInterpName = iNames.Value( i ); + aNames.append( HYDROGUI_Tool::ToQString( anInterpName ) ); + } } return aNames; @@ -287,7 +284,7 @@ HYDROData_IProfilesInterpolator* HYDROGUI_ProfileInterpolateOp::interpolator( co HYDROData_IProfilesInterpolator* aRes = 0; if ( anIFactory ) - aRes = anIFactory->GetInterpolator( theName.toStdString() ); + aRes = anIFactory->GetInterpolator( HYDROGUI_Tool::ToAsciiString( theName ) ); return aRes; } @@ -300,10 +297,8 @@ TopoDS_Shape HYDROGUI_ProfileInterpolateOp::previewShape( HYDROData_IProfilesInt aBuilder.MakeCompound( aPreviewShape ); for ( int i = 0; i < theInterp->GetCalculatedProfilesNumber(); i++ ) { - NCollection_Sequence pointSeq; - std::vector aPoints = theInterp->GetResultProfile( i ); - for ( int i = 0; i < (int) aPoints.size(); i += 3 ) - pointSeq.Append( gp_XYZ( aPoints[i], aPoints[i+1], aPoints[i+2] ) ); + NCollection_Sequence pointSeq = theInterp->GetResultProfilePoints( i ); + TopoDS_Shape aWire = HYDROData_PolylineXY::BuildWire( HYDROData_IPolyline::SECTION_SPLINE, false, pointSeq ); if ( !aWire.IsNull() ) aBuilder.Add( aPreviewShape, aWire ); @@ -320,7 +315,7 @@ void HYDROGUI_ProfileInterpolateOp::onInterpolatorChanged( const QString& theInt if ( !aPanel || !anInterp ) return; - aPanel->setInterpolatorDescription( QString( anInterp->GetDescription().c_str() ) ); + aPanel->setInterpolatorDescription( HYDROGUI_Tool::ToQString( anInterp->GetDescription() ) ); updatePreview(); } diff --git a/src/HYDROGUI/HYDROGUI_ProfileInterpolateOp.h b/src/HYDROGUI/HYDROGUI_ProfileInterpolateOp.h index e593acf5..946c3b1b 100644 --- a/src/HYDROGUI/HYDROGUI_ProfileInterpolateOp.h +++ b/src/HYDROGUI/HYDROGUI_ProfileInterpolateOp.h @@ -58,7 +58,7 @@ protected: QStringList interpolators() const; HYDROData_IProfilesInterpolator* interpolator( const QString& ) const; void updateInterpolator( HYDROData_IProfilesInterpolator* ); - std::vector profile( const QString& ) const; + HYDROData_Profile::ProfilePoints profile( const QString& ) const; ParamsList parameters( const QString& ) const; QString parameters( const ParamsList& ) const; diff --git a/src/HYDROPy/CMakeLists.txt b/src/HYDROPy/CMakeLists.txt index 233dd17b..9353e093 100644 --- a/src/HYDROPy/CMakeLists.txt +++ b/src/HYDROPy/CMakeLists.txt @@ -89,6 +89,7 @@ SET(_sip_files2 HYDROData_CalculationCase.sip HYDROData_Document.sip HYDROData_Application.sip + HYDROData_IProfilesInterpolator.sip ) # --- sources --- diff --git a/src/HYDROPy/HYDROData.sip b/src/HYDROPy/HYDROData.sip index 4eeee24d..82875342 100644 --- a/src/HYDROPy/HYDROData.sip +++ b/src/HYDROPy/HYDROData.sip @@ -106,6 +106,7 @@ %Include HYDROData_Zone.sip %Include HYDROData_Region.sip %Include HYDROData_CalculationCase.sip +%Include HYDROData_IProfilesInterpolator.sip %Include HYDROData_Document.sip %Include HYDROData_Application.sip diff --git a/src/HYDROPy/HYDROData_Document.sip b/src/HYDROPy/HYDROData_Document.sip index cda806f5..9d0a9cc0 100644 --- a/src/HYDROPy/HYDROData_Document.sip +++ b/src/HYDROPy/HYDROData_Document.sip @@ -300,6 +300,12 @@ public: void SetLocalCS( double, double ); + //! Get the appropriate interpolator by the name. + HYDROData_IProfilesInterpolator* GetInterpolator( const TCollection_AsciiString& theName ) const; + + //! Get list of registered interpolator names. + NCollection_Sequence GetInterpolatorNames() const; + protected: //! Creates new document: private because "Document" method must be used instead of direct creation. diff --git a/src/HYDROPy/HYDROData_IProfilesInterpolator.sip b/src/HYDROPy/HYDROData_IProfilesInterpolator.sip new file mode 100644 index 00000000..e1ccff00 --- /dev/null +++ b/src/HYDROPy/HYDROData_IProfilesInterpolator.sip @@ -0,0 +1,142 @@ +// Copyright (C) 2007-2015 CEA/DEN, EDF R&D, OPEN CASCADE +// +// Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, +// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// + +%ExportedHeaderCode +#include +%End + +/** + * Errors that could appear on interpolation calculations. + * If there is no error, it is "OK". + */ +enum InterpolationError { + OK = 0, ///< success + InvalidParametersError, ///< input parameters are invalid + UnknownError ///< problem has unknown nature +}; + +/**\class HYDROData_IProfilesInterpolator + * \brief The base class to provide interface for profiles interpolation. + */ +class HYDROData_IProfilesInterpolator +{ +%TypeHeaderCode +#include +%End + +public: + + /** + * Public constructor. + */ + HYDROData_IProfilesInterpolator(); + + /** + * Public virtual destructor. + */ + virtual ~HYDROData_IProfilesInterpolator(); + +public: + + /** + * Get description of the interpolation algorithm. + * \return the description string + */ + virtual TCollection_AsciiString GetDescription() const = 0; + + /** + * Set profiles as sequences of gp_XYZ points. + * \param theProfile1 the first profile points + * \param theProfile1 the second profile points + */ + virtual void SetProfiles( const NCollection_Sequence& theProfile1, + const NCollection_Sequence& theProfile2 ); + + /** + * Set number of profiles to compute. + * \param theNumber the number of profiles to be computed + */ + virtual void SetResultProfilesNumber( const int theNumber ); + + /** + * Set the additional parameter. + * \param the parameter name + * \param the parameter value + */ + virtual void SetParameter( const TCollection_AsciiString& theName, const TCollection_AsciiString& theValue ); + + /** + * Get the last error code. + * \return the error code from InterpolationError enumeration + */ + virtual InterpolationError GetErrorCode() const; + + /** + * Get string description of the last error. + * \return the string description + */ + virtual TCollection_AsciiString GetErrorMessage() const; + + /** + * Reset interpolator state: both input and output data are reset. + */ + virtual void Reset(); + +public: + /** + * Perform interpolation calculations. + */ + virtual void Calculate() = 0; + + /** + * Get number of calculated profiles ( could be less than the number of profiles to be computed set as a parameter ). + * \return the number of really calculated profiles + */ + virtual int GetCalculatedProfilesNumber() const; + + /** + * Get result profile by index. + * \param theProfileIndex the profile index [0, ] + * \return the profile with the given index or empty vector if the index is out of range + */ + NCollection_Sequence GetResultProfilePoints( const int theProfileIndex ) const; + +protected: + + /** + * Get the first profile points. + * \return the first profile points + */ + NCollection_Sequence GetFirstProfilePoints() const; + + /** + * Get the second profile points. + * \return the second profile points + */ + NCollection_Sequence GetSecondProfilePoints() const; + + /** + * Insert the calculated profile to the resuls as a list of points. + * \param theProfile the list of points gp_XYZ + */ + void InsertResultProfile( const NCollection_Sequence& theProfile ); +}; diff --git a/src/HYDROPy/HYDROData_Stream.sip b/src/HYDROPy/HYDROData_Stream.sip index 8b17eff4..4f07084d 100644 --- a/src/HYDROPy/HYDROData_Stream.sip +++ b/src/HYDROPy/HYDROData_Stream.sip @@ -185,6 +185,13 @@ public: } %End + /** + * Add interpolated profiles into the stream. + * \param theInterpolator the interpolator + * \return true in case of success + */ + virtual bool Interpolate( HYDROData_IProfilesInterpolator* theInterpolator ); + protected: /** * Creates new object in the internal data structure. Use higher level objects -- 2.39.2