From 07bddf62431ea9878a4446a96fb35760587317e3 Mon Sep 17 00:00:00 2001 From: isn Date: Thu, 18 Jun 2015 16:54:58 +0300 Subject: [PATCH] sinusX p.7 // Export of bathy --- src/HYDROData/HYDROData_SinusX.cxx | 51 ++++++++++++++++++++++++ src/HYDROData/HYDROData_SinusX.h | 4 ++ src/HYDROGUI/HYDROGUI_ExportSinusXOp.cxx | 19 ++++++++- 3 files changed, 72 insertions(+), 2 deletions(-) diff --git a/src/HYDROData/HYDROData_SinusX.cxx b/src/HYDROData/HYDROData_SinusX.cxx index bca60482..c4645975 100644 --- a/src/HYDROData/HYDROData_SinusX.cxx +++ b/src/HYDROData/HYDROData_SinusX.cxx @@ -36,6 +36,7 @@ #include #include #include +#include HYDROData_SinusX::HYDROData_SinusX( ) { @@ -303,3 +304,53 @@ bool HYDROData_SinusX::Parse(QFile& theFile) } +bool HYDROData_SinusX::Export(const QString& theFilePath, NCollection_Sequence& 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& 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 diff --git a/src/HYDROData/HYDROData_SinusX.h b/src/HYDROData/HYDROData_SinusX.h index cc743d71..3da6ff89 100644 --- a/src/HYDROData/HYDROData_SinusX.h +++ b/src/HYDROData/HYDROData_SinusX.h @@ -56,11 +56,15 @@ public: HYDROData_SinusX( ); virtual ~HYDROData_SinusX(); bool Import (const QString& theFilePath, Handle(HYDROData_Document) theDocument, NCollection_Sequence& theEntities); + bool Export(const QString& theFilePath, NCollection_Sequence& theEntities); + private: void SXToHydro(Handle(HYDROData_Document) theDocument, NCollection_Sequence& theEntities); bool Parse( QFile& theFile ); void CollectExistingNames(Handle_HYDROData_Document theDocument); QString GetName(const QString& theName); + void HydroToSX(QFile& theFile, NCollection_Sequence& theEntities); + private: std::vector myCurveBlocks; diff --git a/src/HYDROGUI/HYDROGUI_ExportSinusXOp.cxx b/src/HYDROGUI/HYDROGUI_ExportSinusXOp.cxx index ef17ecdb..d43f1e8e 100644 --- a/src/HYDROGUI/HYDROGUI_ExportSinusXOp.cxx +++ b/src/HYDROGUI/HYDROGUI_ExportSinusXOp.cxx @@ -26,8 +26,16 @@ #include #include #include -#include +#include +#include "HYDROGUI_Module.h" +#include +#include +#include +#include + +#include +#include 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( 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()); + } } -- 2.39.2