#include <ShapeAnalysis.hxx>
#include <ShapeAnalysis_FreeBounds.hxx>
+#include <HYDROData_PolylineXY.h>
+#include <HYDROData_Polyline3D.h>
+#include <HYDROData_Bathymetry.h>
+
+#include <QFileInfo>
+#define BLOCK_SIZE 10000
HYDROData_Tool::ExecStatus HYDROData_Tool::myTriangulationStatus = ExecStatus::None;
return myTriangulationStatus;
}
+static bool AddXYZ(bool bImportXY,
+ double x,
+ double y,
+ double z,
+ std::vector<gp_XYZ>& thePointsXYZ,
+ std::vector<gp_XY>& thePointsXY)
+{
+ if (!bImportXY)
+ {
+ if ( HYDROData_Tool::IsNan( x ) || HYDROData_Tool::IsInf( x ) ||
+ HYDROData_Tool::IsNan( y ) || HYDROData_Tool::IsInf( y ) ||
+ HYDROData_Tool::IsNan( z ) || HYDROData_Tool::IsInf( z ) )
+ return false;
+
+ if( thePointsXYZ.size()>=thePointsXYZ.capacity() )
+ thePointsXYZ.reserve( thePointsXYZ.size()+BLOCK_SIZE );
+
+ thePointsXYZ.push_back(gp_XYZ(x,y,z));
+ }
+ else
+ {
+ if ( HYDROData_Tool::IsNan( x ) || HYDROData_Tool::IsInf( x ) ||
+ HYDROData_Tool::IsNan( y ) || HYDROData_Tool::IsInf( y ) )
+ return false;
+
+ if( thePointsXY.size()>=thePointsXY.capacity() )
+ thePointsXY.reserve( thePointsXY.size()+BLOCK_SIZE );
+
+ thePointsXY.push_back(gp_XY(x,y));
+ }
+ return true;
+}
+
+bool HYDROData_Tool::importFromXYZ( QString& theFileName,
+ bool bImportXY,
+ std::vector<gp_XYZ>& thePointsXYZ,
+ std::vector<gp_XY>& thePointsXY)
+{
+ QFile aFile( theFileName );
+ if ( !aFile.exists() || !aFile.open( QIODevice::ReadOnly ) )
+ return false;
+
+ QString aFileSuf = QFileInfo( aFile ).suffix().toLower();
+
+ double x,y;
+ if ( aFileSuf == "xyz" )
+ {
+ double z;
+ while ( !aFile.atEnd() )
+ {
+ std::string aLine = aFile.readLine().simplified().toStdString();
+ if ( aLine.empty() )
+ continue;
+
+ x = 0;
+ y = 0;
+ z = 0;
+
+ if( sscanf( aLine.c_str(), "%lf %lf %lf", &x, &y, &z )!=3 )
+ return false;
+
+ if (!AddXYZ(bImportXY, x, y, z, thePointsXYZ, thePointsXY ))
+ return false;
+ }
+ }
+ else if (aFileSuf == "xy" )
+ {
+ while ( !aFile.atEnd() )
+ {
+ std::string aLine = aFile.readLine().simplified().toStdString();
+ if ( aLine.empty() )
+ continue;
+
+ x = 0;
+ y = 0;
+
+ if( sscanf( aLine.c_str(), "%lf %lf", &x, &y )!=2 )
+ return false;
+
+ if (!AddXYZ(true, x, y, 0, thePointsXYZ, thePointsXY ))
+ return false;
+ }
+ }
+
+ aFile.close();
+
+ return true;
+}
+
+bool HYDROData_Tool::importPolylineFromXYZ(QString aFileName, Handle(HYDROData_Document) theDocument,
+ bool importXY, NCollection_Sequence<Handle(HYDROData_Entity)>& importedEntities)
+{
+ if (importXY)
+ {
+ std::vector<gp_XY> aPoints2d;
+ std::vector<gp_XYZ> aDPoints3d;
+
+ if (HYDROData_Tool::importFromXYZ(aFileName, importXY, aDPoints3d, aPoints2d))
+ {
+ QString basename = QFileInfo( aFileName ).baseName();
+
+ Handle(HYDROData_PolylineXY) aPolylineXY = Handle(HYDROData_PolylineXY)::DownCast( theDocument->CreateObject( KIND_POLYLINEXY ) );
+ HYDROData_PolylineXY::SectionType aSectType = HYDROData_PolylineXY::SECTION_POLYLINE;
+ bool IsClosed = false;
+ if ((aPoints2d.front()-aPoints2d.back()).Modulus()<Precision::Confusion())
+ {
+ IsClosed = true;
+ aPolylineXY->AddSection( TCollection_AsciiString("poly_section"), aSectType, true);
+ }
+ else
+ aPolylineXY->AddSection( TCollection_AsciiString("poly_section"), aSectType, false);
+
+ int n = aPoints2d.size();
+ if (IsClosed)
+ n--;
+
+ for ( int i = 0; i < n; i++ )
+ {
+ gp_XY aSectPoint = aPoints2d[i];
+ theDocument->Transform(aSectPoint, true);
+ aPolylineXY->AddPoint( 0, aSectPoint );
+ }
+
+ aPolylineXY->SetWireColor( HYDROData_PolylineXY::DefaultWireColor() );
+ aPolylineXY->SetName( basename + "_PolyXY_" );
+ aPolylineXY->Update();
+ importedEntities.Append(aPolylineXY);
+ return true;
+ }
+ else
+ return false;
+ }
+ else //xyz
+ {
+ std::vector<gp_XY> aDPoints2d;
+ std::vector<gp_XYZ> aPoints3d;
+ if (HYDROData_Tool::importFromXYZ(aFileName, false, aPoints3d, aDPoints2d))
+ {
+ QString basename = QFileInfo( aFileName ).baseName();
+ Handle(HYDROData_PolylineXY) aPolylineXY = Handle(HYDROData_PolylineXY)::DownCast( theDocument->CreateObject( KIND_POLYLINEXY ) );
+ Handle(HYDROData_Polyline3D) aPolylineObj = Handle(HYDROData_Polyline3D)::DownCast( theDocument->CreateObject( KIND_POLYLINE ) );
+ Handle(HYDROData_Bathymetry) aBath = Handle(HYDROData_Bathymetry)::DownCast( theDocument->CreateObject( KIND_BATHYMETRY ) );
+ HYDROData_Bathymetry::AltitudePoints aAPoints;
+ HYDROData_PolylineXY::SectionType aSectType = HYDROData_PolylineXY::SECTION_POLYLINE;
+ bool IsClosed = false;
+ if ((aPoints3d.front()-aPoints3d.back()).Modulus()<Precision::Confusion())
+ {
+ IsClosed = true;
+ aPolylineXY->AddSection( TCollection_AsciiString("poly_section"), aSectType, true);
+ }
+ else
+ aPolylineXY->AddSection( TCollection_AsciiString("poly_section"), aSectType, false);
+
+ int n = aPoints3d.size();
+ if (IsClosed)
+ n--;
+
+ for ( int i = 0; i < n; i++ )
+ {
+ gp_XY aSectPoint(aPoints3d[i].X(), aPoints3d[i].Y());
+ theDocument->Transform(aSectPoint, true);
+ aPolylineXY->AddPoint( 0, aSectPoint );
+ HYDROData_Bathymetry::AltitudePoint p;
+ p.X = aSectPoint.X();
+ p.Y = aSectPoint.Y();
+ p.Z = aPoints3d[i].Z();
+ aAPoints.push_back(p);
+ }
+
+ QString aBathName = basename + "_bath_";
+ QString aPolyXYName = basename + "_polyXY_";
+ QString aPoly3DName = basename + "_poly3D_";
+
+ aPolylineXY->SetName( aPolyXYName );
+ aPolylineXY->SetWireColor(HYDROData_PolylineXY::DefaultWireColor());
+ aPolylineXY->Update();
+
+ aBath->SetAltitudePoints(aAPoints);
+ aBath->SetName( aBathName );
+
+ aPolylineObj->SetPolylineXY (aPolylineXY, false);
+ aPolylineObj->SetAltitudeObject(aBath);
+
+ aPolylineObj->SetBorderColor( aPolylineObj->DefaultBorderColor() );
+ aPolylineObj->SetName( aPoly3DName );
+
+ aPolylineObj->Update();
+ importedEntities.Append(aPolylineXY);
+ importedEntities.Append(aPolylineObj);
+ return true;
+ }
+ else
+ return false;
+ }
+}
+
+
std::ostream& operator<<( std::ostream& theStream, const QString& theText )
{
theStream << theText.toStdString();
#include <HYDROData_Bathymetry.h>
#include <HYDROData_Iterator.h>
#include <HYDROData_ShapeFile.h>
+#include <HYDROData_Tool.h>
#include <HYDROData_Profile.h>
#include <QFile>
#include <QFileInfo>
#include <SUIT_MessageBox.h>
+#include <gp_XY.hxx>
HYDROGUI_ImportPolylineOp::HYDROGUI_ImportPolylineOp( HYDROGUI_Module* theModule )
continue;
QString anExt = aFileName.split('.', QString::SkipEmptyParts).back();
-
+ anExt.toLower();
+ bool importXY = false;
+ if (anExt == "xyz")
+ {
+ importXY = SUIT_MessageBox::question( module->getApp()->desktop(),
+ tr( "IMPORT_POLYLINE" ),
+ tr( "IMPORT_POLYLINE_XY_PART_ONLY" ),
+ QMessageBox::Yes | QMessageBox::No,
+ SUIT_MessageBox::Yes) == SUIT_MessageBox::Yes;
+ }
if (anExt == "shp")
{
HYDROData_ShapeFile anImporter;
}
importedEntities.Append(theEntities);
}
+ else if ( anExt == "xy" || (importXY && anExt == "xyz"))
+ {
+ HYDROData_Tool::importPolylineFromXYZ(aFileName, theDocument, true, importedEntities);
+ }
+ else if (anExt == "xyz")
+ {
+ HYDROData_Tool::importPolylineFromXYZ(aFileName, theDocument, false, importedEntities);
+ }
}
return importedEntities;
}
#include <TopoDS_Vertex.hxx>
#include <TopoDS_Wire.hxx>
#include <gp_XY.hxx>
+#include <HYDROData_Tool.h>
+
+extern QString REF_DATA_PATH;
void test_HYDROData_PolylineXY::test_polyline()
{
aDoc->Close();
}
+
+void test_HYDROData_PolylineXY::test_import_from_xyz()
+{
+ NCollection_Sequence<Handle(HYDROData_Entity)> ents;
+ Handle(HYDROData_Document) aDoc = HYDROData_Document::Document( 1 );
+ TCollection_AsciiString fname = REF_DATA_PATH.toLatin1().data();
+ fname += "/profiles1.xyz";
+
+ NCollection_Sequence<Handle(HYDROData_Entity)> importedEntities;
+ bool stat = HYDROData_Tool::importPolylineFromXYZ(QString(fname.ToCString()), aDoc, true, importedEntities);
+ CPPUNIT_ASSERT (stat);
+ Handle(HYDROData_PolylineXY) aPolyXY = Handle(HYDROData_PolylineXY)::DownCast(importedEntities.First());
+ CPPUNIT_ASSERT_EQUAL (importedEntities.Size(), 1);
+ CPPUNIT_ASSERT (!aPolyXY.IsNull());
+ TestViewer::show( aPolyXY->GetShape(), 0, true, "Polyline_import_XY" );
+ CPPUNIT_ASSERT_IMAGES
+ importedEntities.Clear();
+
+ stat = HYDROData_Tool::importPolylineFromXYZ(QString(fname.ToCString()), aDoc, false, importedEntities);
+ CPPUNIT_ASSERT (stat);
+ CPPUNIT_ASSERT_EQUAL (importedEntities.Size(), 2);
+ Handle(HYDROData_Polyline3D) aPoly3D;
+ aPolyXY = Handle(HYDROData_PolylineXY)::DownCast(importedEntities.First());
+ aPoly3D = Handle(HYDROData_Polyline3D)::DownCast(importedEntities.Last());
+ CPPUNIT_ASSERT (!aPolyXY.IsNull());
+ CPPUNIT_ASSERT (!aPoly3D.IsNull());
+ TestViewer::show( aPolyXY->GetShape(), 0, false, "Polyline_import_XYZ" );
+ TestViewer::show( aPoly3D->GetShape3D(), 0, false, "Polyline_import_XYZ_3D" );
+ CPPUNIT_ASSERT_IMAGES
+}
\ No newline at end of file