Salome HOME
Bug #490: batch mode error.
[modules/hydro.git] / src / HYDROData / HYDROData_Bathymetry.cxx
index 44a61a11e65fbc396dc36c4dd60a3bab9323d8ca..58d3a11cfd7c2103011225dbf3914bc45d9e6f9d 100644 (file)
@@ -26,9 +26,6 @@
 #include <OSD_Timer.hxx>
 #endif
 
-#define PYTHON_BATHYMETRY_ID "KIND_BATHYMETRY"
-
-
 IMPLEMENT_STANDARD_HANDLE(HYDROData_Bathymetry, HYDROData_IAltitudeObject)
 IMPLEMENT_STANDARD_RTTIEXT(HYDROData_Bathymetry, HYDROData_IAltitudeObject)
 
@@ -43,33 +40,19 @@ HYDROData_Bathymetry::~HYDROData_Bathymetry()
 
 QStringList HYDROData_Bathymetry::DumpToPython( MapOfTreatedObjects& theTreatedObjects ) const
 {
-  QStringList aResList;
-
-  Handle(HYDROData_Document) aDocument = HYDROData_Document::Document( myLab );
-  if ( aDocument.IsNull() )
-    return aResList;
-                             
-  QString aDocName = aDocument->GetDocPyName();
-  QString aBathymetryName = GetName();
-
-  aResList << QString( "%1 = %2.CreateObject( %3 );" )
-              .arg( aBathymetryName ).arg( aDocName ).arg( PYTHON_BATHYMETRY_ID );
-  aResList << QString( "%1.SetName( \"%2\" );" )
-              .arg( aBathymetryName ).arg( aBathymetryName );
+  QStringList aResList = dumpObjectCreation( theTreatedObjects );
+  QString aBathymetryName = GetObjPyName();
 
   aResList << QString( "%1.SetAltitudesInverted( %2 );" )
               .arg( aBathymetryName ).arg( IsAltitudesInverted() );
 
-  QString aFilePath = GetFilePath();
-  if ( !aFilePath.isEmpty() )
-  {
-    aResList << QString( "%1.ImportFromFile( \"%2\" );" )
-                .arg( aBathymetryName ).arg( aFilePath );
-  }
-  else
-  {
-    // TODO : bathymetry is composed from other bathymetry(ies)
-  }
+  TCollection_AsciiString aFilePath = GetFilePath();
+  aResList << QString( "%1.ImportFromFile( \"%2\" );" )
+              .arg( aBathymetryName ).arg( aFilePath.ToCString() );
+
+  aResList << QString( "" );
+  aResList << QString( "%1.Update();" ).arg( aBathymetryName );
+  aResList << QString( "" );
 
   return aResList;
 }
@@ -325,22 +308,21 @@ double HYDROData_Bathymetry::GetAltitudeForPoint( const gp_XY& thePoint ) const
   return aResAltitude;
 }
 
-void HYDROData_Bathymetry::SetFilePath(const QString& theFilePath)
+void HYDROData_Bathymetry::SetFilePath( const TCollection_AsciiString& theFilePath )
 {
-  TCollection_AsciiString anAsciiStr( theFilePath.toStdString().c_str() );
-  TDataStd_AsciiString::Set( myLab.FindChild( DataTag_FilePath ), anAsciiStr );
+  TDataStd_AsciiString::Set( myLab.FindChild( DataTag_FilePath ), theFilePath );
 }
 
-QString HYDROData_Bathymetry::GetFilePath() const
+TCollection_AsciiString HYDROData_Bathymetry::GetFilePath() const
 {
-  QString aRes;
+  TCollection_AsciiString aRes;
 
   TDF_Label aLabel = myLab.FindChild( DataTag_FilePath, false );
   if ( !aLabel.IsNull() )
   {
     Handle(TDataStd_AsciiString) anAsciiStr;
     if ( aLabel.FindAttribute( TDataStd_AsciiString::GetID(), anAsciiStr ) )
-      aRes = QString( anAsciiStr->Get().ToCString() );
+      aRes = anAsciiStr->Get();
   }
 
   return aRes;
@@ -390,10 +372,10 @@ bool HYDROData_Bathymetry::IsAltitudesInverted() const
   return aRes;
 }
 
-bool HYDROData_Bathymetry::ImportFromFile( const QString& theFileName )
+bool HYDROData_Bathymetry::ImportFromFile( const TCollection_AsciiString& theFileName )
 {
   // Try to open the file
-  QFile aFile( theFileName );
+  QFile aFile( theFileName.ToCString() );
   if ( !aFile.exists() || !aFile.open( QIODevice::ReadOnly ) )
     return false;
 
@@ -406,9 +388,19 @@ bool HYDROData_Bathymetry::ImportFromFile( const QString& theFileName )
   // Try to import the file
   if ( aFileSuf == "xyz" )
     aRes = importFromXYZFile( aFile, aPoints );
-    
+
   // Close the file
   aFile.close();
+  
+
+  // Convert from global to local CS
+  Handle_HYDROData_Document aDoc = HYDROData_Document::Document( myLab );
+  AltitudePoints::Iterator anIter( aPoints );
+  for ( ; anIter.More(); anIter.Next() )
+  {
+    AltitudePoint& aPoint = anIter.ChangeValue();
+    aDoc->Transform( aPoint, true );
+  }
 
   if ( aRes )
   {
@@ -484,14 +476,14 @@ bool HYDROData_Bathymetry::importFromXYZFile( QFile&          theFile,
 }
 
 
-bool HYDROData_Bathymetry::CreateBoundaryPolyline() const
+Handle_HYDROData_PolylineXY HYDROData_Bathymetry::CreateBoundaryPolyline() const
 {
   Handle(HYDROData_Document) aDocument = HYDROData_Document::Document( myLab );
   Handle_HYDROData_PolylineXY aResult = 
     Handle_HYDROData_PolylineXY::DownCast( aDocument->CreateObject( KIND_POLYLINEXY ) );
 
   if( aResult.IsNull() )
-    return false;
+    return aResult;
 
   //search free name
   QString aPolylinePref = GetName() + "_Boundary";
@@ -526,5 +518,19 @@ bool HYDROData_Bathymetry::CreateBoundaryPolyline() const
   aResult->AddPoint( 0, HYDROData_IPolyline::Point( Xmax, Ymin ) );
   aResult->Update();
 
-  return true;
+  return aResult;
+}
+
+void HYDROData_Bathymetry::UpdateLocalCS( double theDx, double theDy )
+{
+  gp_XYZ aDelta( theDx, theDy, 0 );
+  AltitudePoints aPoints = GetAltitudePoints();
+  AltitudePoints::Iterator anIter( aPoints );
+  for ( int i = 0 ; anIter.More(); ++i, anIter.Next() )
+  {
+    AltitudePoint& aPoint = anIter.ChangeValue();
+    aPoint += aDelta;
+  }
+  SetAltitudePoints( aPoints );
 }
+