#include <HYDROData_Polyline3D.h>
#include <HYDROGUI_DataObject.h>
#include <HYDROData_Bathymetry.h>
+#include <HYDROData_LandCover.h>
#include <HYDROData_Profile.h>
#include <QFile>
#include <QFileInfo>
#include <SUIT_MessageBox.h>
+#include <TopoDS.hxx>
+#include <TopExp_Explorer.hxx>
+#include <TopoDS_Wire.hxx>
+#include <TopoDS_Vertex.hxx>
+#include <BRep_Tool.hxx>
+#include <Precision.hxx>
HYDROGUI_ExportFileOp::HYDROGUI_ExportFileOp( HYDROGUI_Module* theModule )
: HYDROGUI_Operation( theModule )
{
- setName( tr( "EXPORT_POLYLINE" ) );
+ setName( tr( "EXPORT_TO_SHAPE_FILE" ) );
}
HYDROGUI_ExportFileOp::~HYDROGUI_ExportFileOp()
{
HYDROGUI_Operation::startOperation();
- QString aFilter( "*.shp" ); //temp ext-n; replace with filter; TODO
+ QString aFilter( tr("SHP_FILTER") ); //temp ext-n; replace with filter; TODO
Handle(HYDROData_PolylineXY) aPolyXY;
Handle(HYDROData_Polyline3D) aPoly3D;
+ Handle(HYDROData_LandCover) aLC;
NCollection_Sequence<Handle_HYDROData_PolylineXY> aPolyXYSeq;
NCollection_Sequence<Handle_HYDROData_Polyline3D> aPoly3DSeq;
-
+ NCollection_Sequence<Handle_HYDROData_LandCover> aLCSeq;
HYDROData_SequenceOfObjects aSeq = HYDROGUI_Tool::GetSelectedObjects( module() );
for( int anIndex = 1, aLength = aSeq.Length(); anIndex <= aLength; anIndex++ )
aPoly3D = Handle(HYDROData_Polyline3D)::DownCast( aSeq.Value( anIndex ));
if (!aPoly3D.IsNull())
aPoly3DSeq.Append(aPoly3D);
+
+ aLC = Handle(HYDROData_LandCover)::DownCast( aSeq.Value( anIndex ));
+ if (!aLC.IsNull())
+ aLCSeq.Append(aLC);
}
if (!aPolyXYSeq.IsEmpty() && !aPoly3DSeq.IsEmpty())
SUIT_MessageBox::warning( module()->getApp()->desktop(), "Export Polyline", "Cannot export polylines of different kind");
else
{
- QString aFileName = SUIT_FileDlg::getFileName( module()->getApp()->desktop(), "", aFilter, tr( "EXPORT_POLYLINE" ), false );
+ QString aFileName = SUIT_FileDlg::getFileName( module()->getApp()->desktop(), "", aFilter, tr( "EXPORT_TO_SHAPE_FILE" ), false );
if (!aFileName.isEmpty())
{
SHPHandle hSHPHandle;
hSHPHandle = SHPCreate( aFileName.toAscii().data(), SHPT_ARCZ );
for (int i = 1; i <= aPoly3DSeq.Size(); i++)
WriteObjectPoly3D(hSHPHandle, aPoly3DSeq(i));
- }
+ }
+ else if (aPolyXYSeq.IsEmpty() && aPoly3DSeq.IsEmpty() && !aLCSeq.IsEmpty())
+ {
+ hSHPHandle = SHPCreate( aFileName.toAscii().data(), SHPT_POLYGON );
+ for (int i = 1; i <= aLCSeq.Size(); i++)
+ WriteObjectLC(hSHPHandle, aLCSeq(i));
+ }
SHPClose( hSHPHandle );
commit();
}
SHPDestroyObject( aSHPObj );
}
+void HYDROGUI_ExportFileOp::WriteObjectLC(SHPHandle theShpHandle, Handle_HYDROData_LandCover theLC )
+{
+
+ TopoDS_Shape aSh = theLC->GetShape();
+ if (aSh.IsNull())
+ return;
+ if (aSh.ShapeType() == TopAbs_FACE)
+ {
+ ProcessFace(TopoDS::Face(aSh), theShpHandle);
+ }
+ else if (aSh.ShapeType() == TopAbs_COMPOUND)
+ {
+ TopExp_Explorer Ex(aSh, TopAbs_FACE);
+ for (; Ex.More(); Ex.Next())
+ {
+ TopoDS_Face aF = TopoDS::Face(Ex.Current());
+ if (aF.IsNull())
+ continue;
+ ProcessFace(aF, theShpHandle);
+ }
+ }
+ else
+ return;
+
+}
+
+void HYDROGUI_ExportFileOp::ProcessFace(TopoDS_Face theFace, SHPHandle theShpHandle)
+{
+ SHPObject *aSHPObj;
+ std::vector<double> x, y;
+ std::vector<int> anPartStart;
+ if (theFace.ShapeType() == TopAbs_FACE)
+ {
+ TopExp_Explorer Ex(theFace, TopAbs_WIRE);
+ int NbWires = 0;
+ for (; Ex.More(); Ex.Next())
+ {
+ TopoDS_Wire aW = TopoDS::Wire(Ex.Current());
+ if (aW.IsNull())
+ continue;
+ NbWires++;
+ anPartStart.push_back(x.size());
+ TopExp_Explorer aVEx(aW, TopAbs_VERTEX);
+ NCollection_Sequence<gp_Pnt2d> aPnts;
+ for (; aVEx.More(); aVEx.Next())
+ {
+ TopoDS_Vertex aV = TopoDS::Vertex(aVEx.Current());
+ if (aV.IsNull())
+ continue;
+ gp_Pnt P = BRep_Tool::Pnt(aV);
+ aPnts.Append(gp_Pnt2d(P.X(), P.Y()));
+ }
+ NCollection_Sequence<gp_Pnt2d> aNPnts;
+ aNPnts.Append(aPnts.First());
+ for (int j = 1; j <= aPnts.Size() - 1; j++)
+ {
+ if (!aPnts(j).IsEqual(aPnts(j + 1), Precision::Confusion()))
+ aNPnts.Append(aPnts(j + 1));
+ }
+ for (int j = 1; j <= aNPnts.Size(); j++)
+ {
+ x.push_back( aNPnts(j).X());
+ y.push_back( aNPnts(j).Y());
+ }
+ //x.push_back( aNPnts(1).X());
+ //y.push_back( aNPnts(1).Y());
+ }
+
+ aSHPObj = SHPCreateObject( SHPT_POLYGON, -1, NbWires, &anPartStart[0], NULL, x.size(), &x[0], &y[0], NULL, NULL );
+ SHPWriteObject( theShpHandle, -1, aSHPObj );
+ SHPDestroyObject( aSHPObj );
+ }
+ else
+ return;
+}
<translation>Submersible</translation>
</message>
<message>
- <source>DSK_EXPORT_POLYLINE</source>
- <translation>Export Polyline</translation>
+ <source>DSK_EXPORT_TO_SHAPE_FILE</source>
+ <translation>Export to Shape file</translation>
</message>
<message>
<source>MEN_CREATE_CALCULATION</source>
<translation>Submersible</translation>
</message>
<message>
- <source>MEN_EXPORT_POLYLINE</source>
- <translation>Export Polyline</translation>
+ <source>MEN_EXPORT_TO_SHAPE_FILE</source>
+ <translation>Export to Shape file</translation>
</message>
<message>
<translation>If the object is submersible</translation>
</message>
<message>
- <source>STB_EXPORT_POLYLINE</source>
- <translation>Export Polyline</translation>
+ <source>STB_EXPORT_TO_SHAPE_FILE</source>
+ <translation>Export to Shape file</translation>
</message>
<context>
<name>HYDROGUI_ExportFileOp</name>
<message>
- <source>EXPORT_POLYLINE</source>
- <translation>Export polyline</translation>
+ <source>EXPORT_TO_SHAPE_FILE</source>
+ <translation>Export to Shape file</translation>
+ </message>
+ <message>
+ <source>SHP_FILTER</source>
+ <translation>Shape Files (*.shp)</translation>
</message>
</context>