]> SALOME platform Git repositories - modules/hydro.git/commitdiff
Salome HOME
sinusX p.7 // Export of bathy
authorisn <isn@opencascade.com>
Thu, 18 Jun 2015 13:54:58 +0000 (16:54 +0300)
committerisn <isn@opencascade.com>
Thu, 18 Jun 2015 13:54:58 +0000 (16:54 +0300)
src/HYDROData/HYDROData_SinusX.cxx
src/HYDROData/HYDROData_SinusX.h
src/HYDROGUI/HYDROGUI_ExportSinusXOp.cxx

index bca60482b95a9df268d6c5cf60ce1cd079f3db24..c4645975d52ee1708e203ba56b5d993ec3d377b0 100644 (file)
@@ -36,6 +36,7 @@
 #include <QFileInfo>
 #include <QString>
 #include <QStringList>
+#include <QTextStream>
 
 HYDROData_SinusX::HYDROData_SinusX( ) 
 {
@@ -303,3 +304,53 @@ bool HYDROData_SinusX::Parse(QFile& theFile)
 
 }
 
+bool HYDROData_SinusX::Export(const QString& theFilePath, NCollection_Sequence<Handle_HYDROData_Entity>& theEntities)
+{
+  if ( theFilePath.isEmpty() )
+  { 
+    return false;
+  }
+
+  QString anExt = theFilePath.split('.', QString::SkipEmptyParts).back();
+
+  if (anExt == "sx")
+  {
+    QFile aFile (theFilePath);
+    
+    aFile.open(QIODevice::WriteOnly | QIODevice::Truncate | QIODevice::Text);
+
+    HydroToSX(aFile, theEntities);
+    
+    aFile.close();
+    
+    return true;
+  }
+  else
+    return false;
+
+}
+
+void HYDROData_SinusX::HydroToSX(QFile& theFile, NCollection_Sequence<Handle_HYDROData_Entity>& theEntities)
+{
+  QTextStream aTextStream(&theFile);
+  aTextStream << "C  Generated by HYDRO Module\n";
+  aTextStream << "C\n";
+
+  for (int i = 1; i <= theEntities.Size(); i++)
+  {
+    Handle_HYDROData_Entity anEnt = theEntities.Value(i);
+    if (anEnt->IsKind( STANDARD_TYPE(HYDROData_Bathymetry) ))
+    {
+       Handle(HYDROData_Bathymetry) aBathy = Handle(HYDROData_Bathymetry)::DownCast( anEnt );
+       HYDROData_Bathymetry::AltitudePoints anXYZPoints = aBathy->GetAltitudePoints();
+       aTextStream << "B S\n";
+       aTextStream << "CN " << aBathy->GetName() << "\n";
+       aTextStream << "CP 0 0\n";
+       aTextStream << "CP 0\n";
+       for (int j = 1; j <= anXYZPoints.Size(); j++)
+         aTextStream << " " << QString::number(anXYZPoints(j).X(), 'f', 3)  
+                     << " " << QString::number(anXYZPoints(j).Y(), 'f', 3)  
+                     << " " << QString::number(anXYZPoints(j).Z(), 'f', 3) << "\n"; 
+    }
+  }
+}
\ No newline at end of file
index cc743d71cfafd6f2eba2254cd0aecc71ab84d73f..3da6ff89098737fdd45b9684398610131428619a 100644 (file)
@@ -56,11 +56,15 @@ public:
   HYDROData_SinusX( );
   virtual ~HYDROData_SinusX();
   bool Import (const QString& theFilePath, Handle(HYDROData_Document) theDocument, NCollection_Sequence<Handle_HYDROData_Entity>& theEntities);
+  bool Export(const QString& theFilePath, NCollection_Sequence<Handle_HYDROData_Entity>& theEntities);
+  
 private:
   void SXToHydro(Handle(HYDROData_Document) theDocument, NCollection_Sequence<Handle_HYDROData_Entity>& theEntities);
   bool Parse( QFile& theFile );
   void CollectExistingNames(Handle_HYDROData_Document theDocument);
   QString GetName(const QString& theName);
+  void HydroToSX(QFile& theFile, NCollection_Sequence<Handle_HYDROData_Entity>& theEntities);
+
 private:
 
   std::vector<HYDROGUI_CurveBlock> myCurveBlocks;
index ef17ecdbbf53e91b8af34fce987920effd26e454..d43f1e8e19c02faeb7ac1d67bff105d280f4712b 100644 (file)
 #include <HYDROData_Profile.h>
 #include <HYDROData_Entity.h>
 #include <HYDROGUI_ObjListBox.h>
-#include <QMessageBox>
+#include <HYDROGUI_Operation.h>
+#include "HYDROGUI_Module.h"
+#include <HYDROData_SinusX.h>
 
+#include <SUIT_FileDlg.h>
+#include <SUIT_MessageBox.h>
+#include <SUIT_Desktop.h>
+
+#include <LightApp_Application.h>
+#include <QApplication>
 
 HYDROGUI_ExportSinusXOp::HYDROGUI_ExportSinusXOp( HYDROGUI_Module* theModule )
 : HYDROGUI_Operation( theModule )
@@ -57,8 +65,15 @@ HYDROGUI_InputPanel* HYDROGUI_ExportSinusXOp::createInputPanel() const
 
 void HYDROGUI_ExportSinusXOp::onExportItems()
 {
+  QString aFilter( "*.sx" ); //temp  ext-n; replace with filter; TODO
   HYDROGUI_ExportSinusXDlg* aPanel = ::qobject_cast<HYDROGUI_ExportSinusXDlg*>( inputPanel() );
   if ( !aPanel )
     return;
-  int T = aPanel->GetSelectedEntities().Size();
+  if (!aPanel->GetSelectedEntities().IsEmpty())
+  {
+    //Export selected items to SX file
+    QString aFileName = SUIT_FileDlg::getFileName( module()->getApp()->desktop(), "", aFilter, tr( "EXPORT_SINUSX" ), false );
+    HYDROData_SinusX anExporter;
+    anExporter.Export(aFileName, aPanel->GetSelectedEntities());
+  }
 }