#include <Handle_Geom_Line.hxx>
#include <Handle_Geom_TrimmedCurve.hxx>
#include <Geom_TrimmedCurve.hxx>
+#include <HYDROData_ShapeFile.h>
HYDROGUI_ExportFileOp::HYDROGUI_ExportFileOp( HYDROGUI_Module* theModule )
: HYDROGUI_Operation( theModule )
}
if (!aPolyXYSeq.IsEmpty() && !aPoly3DSeq.IsEmpty())
- SUIT_MessageBox::warning( module()->getApp()->desktop(), "Export Polyline", "Cannot export polylines of different kind");
+ SUIT_MessageBox::warning( module()->getApp()->desktop(), tr( "EXPORT_TO_SHAPE_FILE" ), tr("ERROR_POLYLINES_OF_DIFF_KIND"));
else
{
QString aName = "";
QString aFileName = SUIT_FileDlg::getFileName( module()->getApp()->desktop(), aName, aFilter, tr( "EXPORT_TO_SHAPE_FILE" ), false );
if (!aFileName.isEmpty())
{
- SHPHandle hSHPHandle;
QStringList aNonExpList;
- if (!aPolyXYSeq.IsEmpty() && aPoly3DSeq.IsEmpty())
- {
- hSHPHandle = SHPCreate( aFileName.toAscii().data(), SHPT_ARC );
- for (int i = 1; i <= aPolyXYSeq.Size(); i++)
- if (WriteObjectPolyXY(hSHPHandle, aPolyXYSeq(i)) != 1)
- aNonExpList.append(aPolyXYSeq(i)->GetName());
-
- }
- else if (aPolyXYSeq.IsEmpty() && !aPoly3DSeq.IsEmpty())
- {
- hSHPHandle = SHPCreate( aFileName.toAscii().data(), SHPT_ARCZ );
- for (int i = 1; i <= aPoly3DSeq.Size(); i++)
- if (WriteObjectPoly3D(hSHPHandle, aPoly3DSeq(i)) != 1)
- aNonExpList.append(aPoly3DSeq(i)->GetName());
- }
- else if (aPolyXYSeq.IsEmpty() && aPoly3DSeq.IsEmpty() && !aLCSeq.IsEmpty())
- {
- hSHPHandle = SHPCreate( aFileName.toAscii().data(), SHPT_POLYGON );
- for (int i = 1; i <= aLCSeq.Size(); i++)
- if (WriteObjectLC(hSHPHandle, aLCSeq(i)) != 1)
- aNonExpList.append(aLCSeq(i)->GetName());
- }
- SHPClose( hSHPHandle );
+ HYDROData_ShapeFile anExporter;
+ anExporter.Export(aFileName, aPolyXYSeq, aPoly3DSeq, aLCSeq, aNonExpList);
if (!aNonExpList.empty())
{
- QString aMessage = "The next entities cannot be exported:\n";
+ QString aMessage = tr("CANNOT_BE_EXPORTED") + "\n";
foreach (QString anNonExpEntName, aNonExpList)
aMessage += anNonExpEntName + "\n";
- SUIT_MessageBox::warning( module()->getApp()->desktop(), "Export warning", aMessage);
+ SUIT_MessageBox::warning( module()->getApp()->desktop(), tr( "EXPORT_TO_SHAPE_FILE" ), aMessage);
}
- //TODO pint aNonExpList
commit();
}
else
}
-int HYDROGUI_ExportFileOp::WriteObjectPolyXY(SHPHandle theShpHandle, Handle_HYDROData_PolylineXY thePoly )
-{
- SHPObject *aSHPObj;
- std::vector<double> x, y;
- std::vector<int> anPartStart;
-
- for (int i = 0; i < thePoly->NbSections(); i++)
- if (thePoly->GetSectionType(i) == HYDROData_IPolyline::SECTION_SPLINE)
- return -1;
-
- for (int i = 0; i < thePoly->NbSections(); i++)
- {
- anPartStart.push_back(x.size());
- HYDROData_PolylineXY::PointsList aPointList = thePoly->GetPoints(i);
- for (int j = 1; j <= aPointList.Size(); j++)
- {
- x.push_back( aPointList(j).X());
- y.push_back( aPointList(j).Y());
- }
- if (thePoly->IsClosedSection(i))
- {
- x.push_back( aPointList(1).X());
- y.push_back( aPointList(1).Y());
- }
- }
-
- aSHPObj = SHPCreateObject( SHPT_ARC, -1, thePoly->NbSections(), &anPartStart[0], NULL, x.size(), &x[0], &y[0], NULL, NULL );
- SHPWriteObject( theShpHandle, -1, aSHPObj );
- SHPDestroyObject( aSHPObj );
- return 1;
-}
-
-int HYDROGUI_ExportFileOp::WriteObjectPoly3D(SHPHandle theShpHandle, Handle_HYDROData_Polyline3D thePoly )
-{
- SHPObject *aSHPObj;
- std::vector<double> x, y, z;
- std::vector<int> anPartStart;
-
- for (int i = 0; i < thePoly->GetPolylineXY()->NbSections(); i++)
- if (thePoly->GetPolylineXY()->GetSectionType(i) == HYDROData_IPolyline::SECTION_SPLINE)
- return -1;
-
- for (int i = 0; i < thePoly->GetPolylineXY()->NbSections(); i++)
- {
- anPartStart.push_back(x.size());
- HYDROData_PolylineXY::PointsList aPointList = thePoly->GetPolylineXY()->GetPoints(i);
- for (int j = 1; j <= aPointList.Size(); j++)
- {
- x.push_back( aPointList(j).X());
- y.push_back( aPointList(j).Y());
- z.push_back(thePoly->GetAltitudeObject()->GetAltitudeForPoint(gp_XY (aPointList(j).X(), aPointList(j).Y())));
- }
- if ( thePoly->GetPolylineXY()->IsClosedSection(i))
- {
- x.push_back( aPointList(1).X());
- y.push_back( aPointList(1).Y());
- z.push_back(thePoly->GetAltitudeObject()->GetAltitudeForPoint(gp_XY (aPointList(1).X(), aPointList(1).Y())));
-
- }
- }
-
- aSHPObj = SHPCreateObject( SHPT_ARCZ, -1, thePoly->GetPolylineXY()->NbSections(), &anPartStart[0], NULL, x.size(), &x[0], &y[0], &z[0], NULL );
- SHPWriteObject( theShpHandle, -1, aSHPObj );
- SHPDestroyObject( aSHPObj );
- return 1;
-}
-
-int HYDROGUI_ExportFileOp::WriteObjectLC(SHPHandle theShpHandle, Handle_HYDROData_LandCover theLC )
-{
- TopoDS_Shape aSh = theLC->GetShape();
- if (aSh.IsNull())
- return 0;
- TopExp_Explorer anEdgeEx(aSh, TopAbs_EDGE);
- for (; anEdgeEx.More(); anEdgeEx.Next())
- {
- TopoDS_Edge E = TopoDS::Edge(anEdgeEx.Current());
- double aFP, aLP;
- Handle_Geom_Curve aCur = BRep_Tool::Curve(E, aFP, aLP);
- Handle(Geom_Line) aLine = Handle(Geom_Line)::DownCast(aCur);
- if (aLine.IsNull())
- {
- Handle(Geom_TrimmedCurve) aTC = Handle(Geom_TrimmedCurve)::DownCast(aCur);
- if (!aTC.IsNull())
- {
- Handle(Geom_Line) aLine = Handle(Geom_Line)::DownCast(aTC->BasisCurve());
- if (aLine.IsNull())
- return -1;
- }
- else
- return -1;
- }
-
- }
- 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 0;
-
- return 1;
-
-}
-
-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;
-}