]> SALOME platform Git repositories - modules/hydro.git/commitdiff
Salome HOME
refs #493: provide Python API
authormzn <mzn@opencascade.com>
Wed, 1 Apr 2015 16:16:26 +0000 (19:16 +0300)
committermzn <mzn@opencascade.com>
Wed, 1 Apr 2015 16:16:26 +0000 (19:16 +0300)
17 files changed:
src/HYDROData/CMakeLists.txt
src/HYDROData/HYDROData_Document.cxx
src/HYDROData/HYDROData_Document.h
src/HYDROData/HYDROData_IProfilesInterpolator.cxx
src/HYDROData/HYDROData_IProfilesInterpolator.h
src/HYDROData/HYDROData_InterpolatorsFactory.cxx
src/HYDROData/HYDROData_InterpolatorsFactory.h
src/HYDROData/HYDROData_LinearInterpolator.cxx
src/HYDROData/HYDROData_LinearInterpolator.h
src/HYDROData/HYDROData_Stream.cxx
src/HYDROGUI/HYDROGUI_ProfileInterpolateOp.cxx
src/HYDROGUI/HYDROGUI_ProfileInterpolateOp.h
src/HYDROPy/CMakeLists.txt
src/HYDROPy/HYDROData.sip
src/HYDROPy/HYDROData_Document.sip
src/HYDROPy/HYDROData_IProfilesInterpolator.sip [new file with mode: 0644]
src/HYDROPy/HYDROData_Stream.sip

index b1a830e4e73f25c8b67d5f3c3d69fd4e672d9bfa..188d4d2beeddcaecb9119d4eccf8bfca877b6abb 100644 (file)
@@ -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(
index a032f025aec0be4f4f3446c401b76e80f953065f..7c9773ba065bbda794f090dc6bd689c2ba954a04 100644 (file)
@@ -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<HYDROData_Document*>( this );
+  HYDROData_InterpolatorsFactory* aFactory = aThat->GetInterpolatorsFactory();
+  if ( aFactory ) {
+    anInterpolator = aFactory->GetInterpolator( theName );
+  }
+
+  return anInterpolator;
+}
+NCollection_Sequence<TCollection_AsciiString> HYDROData_Document::GetInterpolatorNames() const
+{
+  NCollection_Sequence<TCollection_AsciiString> aNames;
+
+  HYDROData_Document* aThat = const_cast<HYDROData_Document*>( this );
+  HYDROData_InterpolatorsFactory* aFactory = aThat->GetInterpolatorsFactory();
+  if ( aFactory ) {
+    aNames = aFactory->GetInterpolatorNames();
+  }
+
+  return aNames;
 }
\ No newline at end of file
index ae33d54e79dc378669854559529702b2772e7c31..009eda2f5e9794b4a5e054ee88d3df7e01d6e266 100644 (file)
@@ -29,6 +29,7 @@
 #include <TDocStd_Document.hxx>
 
 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<TCollection_AsciiString> GetInterpolatorNames() const;
+
 protected:
 
   friend class HYDROData_Iterator;
index 2af03fd7e29179a4c18451328fb8b3217c3e8556..264de9715f169a0d967f34622a8a23ae31d96170 100644 (file)
@@ -22,6 +22,7 @@
 
 #include "HYDROData_IProfilesInterpolator.h"
 
+#include <gp_XYZ.hxx>
 
 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<double> theProfile1, const std::vector<double> theProfile2 )
+void HYDROData_IProfilesInterpolator::SetProfiles( const std::vector<double> theProfile1, 
+                                                   const std::vector<double> theProfile2 )
 {
   myProfile1 = theProfile1;
   myProfile2 = theProfile2;
 }
 
-void HYDROData_IProfilesInterpolator::SetParameter( const std::string& theName, const std::string& theValue )
+void HYDROData_IProfilesInterpolator::SetProfiles( const NCollection_Sequence<gp_XYZ>& theProfile1, 
+                                                   const NCollection_Sequence<gp_XYZ>& 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<double> HYDROData_IProfilesInterpolator::GetResultProfile( const int theProfileIndex ) const
+std::vector<double> HYDROData_IProfilesInterpolator::GetResultProfileCoords( const int theProfileIndex ) const
 {
   std::vector<double> aResultProfile;
 
@@ -87,6 +110,11 @@ std::vector<double> HYDROData_IProfilesInterpolator::GetResultProfile( const int
   return aResultProfile;
 }
 
+NCollection_Sequence<gp_XYZ> 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<double> HYDROData_IProfilesInterpolator::GetFirstProfile() const
+std::vector<double> HYDROData_IProfilesInterpolator::GetFirstProfileCoords() const
 {
   return myProfile1;
 }
 
-std::vector<double> HYDROData_IProfilesInterpolator::GetSecondProfile() const
+std::vector<double> HYDROData_IProfilesInterpolator::GetSecondProfileCoords() const
 {
   return myProfile2;
 }
@@ -128,4 +156,43 @@ int HYDROData_IProfilesInterpolator::GetNbProfilesToCompute() const
 void HYDROData_IProfilesInterpolator::InsertResultProfile( const std::vector<double>& theProfile )
 {
   myResultProfiles.push_back( theProfile );
+}
+
+void HYDROData_IProfilesInterpolator::InsertResultProfile( const NCollection_Sequence<gp_XYZ>& theProfile )
+{
+  std::vector<double> 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<gp_XYZ> HYDROData_IProfilesInterpolator::GetFirstProfilePoints() const
+{
+  return GetPoints( GetFirstProfileCoords() );
+}
+
+NCollection_Sequence<gp_XYZ> HYDROData_IProfilesInterpolator::GetSecondProfilePoints() const
+{
+  return GetPoints( GetSecondProfileCoords() );
+}
+
+NCollection_Sequence<gp_XYZ> HYDROData_IProfilesInterpolator::GetPoints( const std::vector<double>& theCoords ) const
+{
+  NCollection_Sequence<gp_XYZ> 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
index 096957270b5a64e2c4111582d21764c81c5f1730..2ec6c9020be23a29f5c72058ad8a583442ce472c 100644 (file)
 
 #include "HYDROData.h"
 
+#include <TCollection_AsciiString.hxx>
+#include <NCollection_Sequence.hxx>
+
 #include <string>
 #include <vector>
 #include <map>
 
+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<double> theProfile1, const std::vector<double> 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<gp_XYZ>& theProfile1, 
+                                             const NCollection_Sequence<gp_XYZ>& 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, <number of profiles to compute>]
    * \return the profile with the given index or empty vector if the index is out of range
    */
-  HYDRODATA_EXPORT std::vector<double> GetResultProfile( const int theProfileIndex ) const;
+  HYDRODATA_EXPORT std::vector<double> GetResultProfileCoords( const int theProfileIndex ) const;
+
+  /**
+   * Get result profile by index as a sequence of gp_XYZ points.
+   * \param theProfileIndex the profile index [0, <number of profiles to compute>]
+   * \return the profile with the given index or empty sequence if the index is out of range
+   */
+  HYDRODATA_EXPORT NCollection_Sequence<gp_XYZ> 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<double> GetFirstProfileCoords() const;
+
+  /**
+   * Get the second profile coordinates.
+   * \return the second profile points
+   */
+  HYDRODATA_EXPORT std::vector<double> GetSecondProfileCoords() const;
+
+  /**
+   * Get the first profile points.
    * \return the first profile points
    */
-  HYDRODATA_EXPORT std::vector<double> GetFirstProfile() const;
+  HYDRODATA_EXPORT NCollection_Sequence<gp_XYZ> GetFirstProfilePoints() const;
 
   /**
-   * Get the second profile.
+   * Get the second profile points.
    * \return the second profile points
    */
-  HYDRODATA_EXPORT std::vector<double> GetSecondProfile() const;
+  HYDRODATA_EXPORT NCollection_Sequence<gp_XYZ> 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<double>& 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<gp_XYZ>& theProfile );
+
+private:
+  NCollection_Sequence<gp_XYZ> GetPoints( const std::vector<double>& theCoords ) const;
+
 private:
   std::vector<double> myProfile1, myProfile2; ///< the two input profiles
   int myResultProfilesNumber; ///< the number of profiles to compute
index 8b11eda00ee94168699e19705a9bbe8571e1ffa5..0a130c8acbc5d387e940e0e0e1dd110cc7736a96 100644 (file)
@@ -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<std::string> HYDROData_InterpolatorsFactory::GetInterpolatorNames() const
+NCollection_Sequence<TCollection_AsciiString> HYDROData_InterpolatorsFactory::GetInterpolatorNames() const
 {
-  std::vector<std::string> aNames;
+  NCollection_Sequence<TCollection_AsciiString> 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;
index 84cdd995b0fcabdd3b48c0218ffa0f69f783e116..0a258afdd39b0f768aadd7dcb2ddff4609800f14 100644 (file)
 
 #include <HYDROData.h>
 
+#include <TCollection_AsciiString.hxx>
+#include <NCollection_Sequence.hxx>
+
 #include <string>
-#include <vector>
 #include <map>
 
 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 <class T> /*HYDRODATA_EXPORT */void Register( const std::string& theName )
+  template <class T> /*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<std::string> GetInterpolatorNames() const;
+  HYDRODATA_EXPORT NCollection_Sequence<TCollection_AsciiString> GetInterpolatorNames() const;
   
 private:
   //! Map that stores all interpolators, identified by interpolator name (string)
index fedb3f12b8b9066f03c68817876060a042fa9167..6112500a53e65eadc94315a7a781a513d6030bef 100644 (file)
@@ -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<double> aProfile1 = GetFirstProfile();
-  std::vector<double> aProfile2 = GetSecondProfile();
+  std::vector<double> aProfile1 = GetFirstProfileCoords();
+  std::vector<double> aProfile2 = GetSecondProfileCoords();
   int aNbProfilesToCompute = GetNbProfilesToCompute();
 
   int aSize1 = aProfile1.size();
index 4cd4e8e712a5902780fb7aa06143cc71791f9aa7..a46bbca6bd91d3adf4cf70bb448347c7c353c907 100644 (file)
@@ -48,7 +48,7 @@ public:
   /**
    *
    */
-  HYDRODATA_EXPORT virtual std::string GetDescription() const;
+  HYDRODATA_EXPORT virtual TCollection_AsciiString GetDescription() const;
 
   /**
    *
index bf9480c9d0655c6f214d6d3a1539d3c8f4130e4e..8e3cb8eed347522748e753b58bb417ed690b817d 100644 (file)
@@ -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<double> 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 );
index 4f3286288aeecfa7e0c1cb1d5791e368bc3be441..0f8d398ff9e142a7c62f1b6cf5d1da76ec359a9e 100644 (file)
@@ -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<double> HYDROGUI_ProfileInterpolateOp::profile( const QString& theName ) const
+HYDROData_Profile::ProfilePoints HYDROGUI_ProfileInterpolateOp::profile( const QString& theName ) const
 {
-    std::vector<double> 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<std::string> iNames = anIFactory->GetInterpolatorNames();
-        for ( std::vector<std::string>::iterator it = iNames.begin(); it != iNames.end(); ++it )
-            aNames.append( (*it).c_str() );
+      NCollection_Sequence<TCollection_AsciiString> 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<gp_XYZ> pointSeq;
-            std::vector<double> 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<gp_XYZ> 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();
 }
index e593acf51f9e037122a4defaa0040fc3d8a9ed49..946c3b1bdd53011d301738f724b295f92f3e4e19 100644 (file)
@@ -58,7 +58,7 @@ protected:
   QStringList                interpolators() const;
   HYDROData_IProfilesInterpolator* interpolator( const QString& ) const;
   void                       updateInterpolator( HYDROData_IProfilesInterpolator* );
-  std::vector<double>        profile( const QString& ) const;
+  HYDROData_Profile::ProfilePoints profile( const QString& ) const;
   ParamsList                 parameters( const QString& ) const;
   QString                    parameters( const ParamsList& ) const;
 
index 233dd17b808cd6424125622aa29d06753c143c15..9353e093bac8cd998cbd5f26e2e2441ebb0e15c0 100644 (file)
@@ -89,6 +89,7 @@ SET(_sip_files2
   HYDROData_CalculationCase.sip
   HYDROData_Document.sip
   HYDROData_Application.sip
+  HYDROData_IProfilesInterpolator.sip
 )
 
 # --- sources ---
index 4eeee24d1b77b20af1d906f1333eef30ea0c8a0c..828753421ed02e0e7d66d24159d39909c24f2f2c 100644 (file)
 %Include HYDROData_Zone.sip
 %Include HYDROData_Region.sip
 %Include HYDROData_CalculationCase.sip
+%Include HYDROData_IProfilesInterpolator.sip
 
 %Include HYDROData_Document.sip
 %Include HYDROData_Application.sip
index cda806f5f7a7ed544d450a330f606e8bd23ed5b5..9d0a9cc0c7d08c922d759b5979040b82ff7bbd06 100644 (file)
@@ -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<TCollection_AsciiString> 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 (file)
index 0000000..e1ccff0
--- /dev/null
@@ -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 <HYDROData_IProfilesInterpolator.h>
+%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 <HYDROData_IProfilesInterpolator.h>
+%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<gp_XYZ>& theProfile1, 
+                            const NCollection_Sequence<gp_XYZ>& 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, <number of profiles to compute>]
+   * \return the profile with the given index or empty vector if the index is out of range
+   */
+   NCollection_Sequence<gp_XYZ> GetResultProfilePoints( const int theProfileIndex ) const; 
+
+protected:
+
+  /**
+   * Get the first profile points.
+   * \return the first profile points
+   */
+  NCollection_Sequence<gp_XYZ> GetFirstProfilePoints() const;
+
+  /**
+   * Get the second profile points.
+   * \return the second profile points
+   */
+  NCollection_Sequence<gp_XYZ> 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<gp_XYZ>& theProfile );
+};
index 8b17eff4253652e4cf7264bed98e5a6bf1122f09..4f07084d8003bc2397a03e34207fa1c8dca05013 100644 (file)
@@ -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