Salome HOME
#refs 522 (very draft) //import only
[modules/hydro.git] / src / HYDROData / HYDROData_Stream.cxx
index bf517b24aaff52ad5f92fe495056e6122d597043..6ffdd0ee43ec1d1110e89b351d5c97bcb11b6e30 100644 (file)
@@ -29,6 +29,7 @@
 #include "HYDROData_ShapesGroup.h"
 #include "HYDROData_ShapesTool.h"
 #include "HYDROData_IAltitudeObject.h"
+#include "HYDROData_IProfilesInterpolator.h"
 #include "HYDROData_Tool.h"
 
 #include <TDataStd_RealArray.hxx>
@@ -121,10 +122,10 @@ QStringList HYDROData_Stream::DumpToPython( MapOfTreatedObjects& theTreatedObjec
     setPythonReferenceObject( theTreatedObjects, aResList, aProfile, "AddProfile" );
   }
 
-  // Create bottom polyline if exists
+  // Set bottom polyline if exists
   const Handle(HYDROData_Polyline3D) aBottomPolyline = GetBottomPolyline();
   if ( !aBottomPolyline.IsNull() ) {
-    aResList << QString( "%1.GenerateBottomPolyline();" ).arg( aName );
+    setPythonReferenceObject( theTreatedObjects, aResList, aBottomPolyline, "SetBottomPolyline" );
   }
 
   aResList << QString( "" );
@@ -1122,8 +1123,93 @@ Handle(HYDROData_Polyline3D) HYDROData_Stream::GetBottomPolyline() const
            GetReferenceObject( DataTag_BottomPolyline ) );
 }
 
-bool HYDROData_Stream::Interpolate( const HYDROData_IProfilesInterpolator* theInterpolator )
+bool HYDROData_Stream::SetBottomPolyline( const Handle(HYDROData_Polyline3D)& theBottom )
 {
-  ///< \todo this is just a stub
+  if ( theBottom.IsNull() ) {
+    return false;
+  }
+
+  SetReferenceObject( theBottom, DataTag_BottomPolyline );
+
   return true;
+}
+
+bool HYDROData_Stream::Interpolate( HYDROData_IProfilesInterpolator* theInterpolator )
+{
+  // Get the document
+  Handle(HYDROData_Document) aDocument = HYDROData_Document::Document( myLab );
+  if ( aDocument.IsNull() ) {
+    return false;
+  }
+  
+  if ( theInterpolator->GetCalculatedProfilesNumber() < 1 ) {
+    theInterpolator->Calculate();
+  }
+
+  if ( theInterpolator->GetErrorCode() != OK ) {
+    return false;
+  }
+
+  bool isOK = true;
+
+  for ( int aProfileInd = 0; aProfileInd < theInterpolator->GetCalculatedProfilesNumber(); aProfileInd++ ) {
+    // Get calculated point coordinates
+    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 ) );
+    QString aBaseName = GetName() + "_interp_profile";
+    QString aName = HYDROData_Tool::GenerateObjectName( aDocument, aBaseName );
+    aProfile->SetName( aName );
+
+    // Fill the profile with points
+    aProfile->SetProfilePoints( aResultPoints );
+
+    // Add profile to the stream
+    bool isAdded = AddProfile( aProfile );
+    if ( !isAdded ) {
+      aProfile->Remove();
+    }
+    else
+      aProfile->Update();
+  }
+
+  if ( isOK )
+    Update();
+
+  return isOK;
+}
+
+void HYDROData_Stream::CopyTo( const Handle(HYDROData_Entity)& theDestination ) const
+{
+  // Get the document
+  Handle(HYDROData_Document) aDocument = HYDROData_Document::Document( myLab );
+  if ( aDocument.IsNull() ) {
+    return;
+  }
+
+  // Call base method
+  HYDROData_Entity::CopyTo( theDestination );
+
+  Handle(HYDROData_Stream) aStreamCopy = 
+    Handle(HYDROData_Stream)::DownCast( theDestination );
+
+  // Copy bottom polyline if exists
+  if ( !aStreamCopy.IsNull() ) {
+    const Handle(HYDROData_Polyline3D) aBottom = GetBottomPolyline();
+    if ( !aBottom.IsNull() ) {
+      aStreamCopy->ClearReferenceObjects( DataTag_BottomPolyline );
+      aStreamCopy->GenerateBottomPolyline();
+      const Handle(HYDROData_Polyline3D) aBottomCopy = aStreamCopy->GetBottomPolyline();
+      if ( !aBottomCopy.IsNull() && !aBottomCopy->GetPolylineXY().IsNull() ) {
+        aBottomCopy->GetPolylineXY()->Update();
+        aBottomCopy->Update();
+      }
+    }
+  }
 }
\ No newline at end of file