HYDROData_LinearInterpolator.h
HYDROData_InterpolatorsFactory.h
HYDROData_SinusX.h
+ HYDROData_ShapeFile.h
)
set(PROJECT_SOURCES
HYDROData_LinearInterpolator.cxx
HYDROData_InterpolatorsFactory.cxx
HYDROData_SinusX.cxx
+ HYDROData_ShapeFile.cxx
)
add_definitions(
)
add_library(HYDROData SHARED ${PROJECT_SOURCES} ${PROJECT_HEADERS})
-target_link_libraries(HYDROData ${GEOM_GEOMUtils} ${CAS_OCAF} ${CAS_OCAFVIS} ${CAS_TKG3d} ${CAS_TKGeomBase} ${CAS_TKGeomAlgo}
+target_link_libraries(HYDROData shapelib ${GEOM_GEOMUtils} ${CAS_OCAF} ${CAS_OCAFVIS} ${CAS_TKG3d} ${CAS_TKGeomBase} ${CAS_TKGeomAlgo}
${CAS_TKBrep} ${CAS_TKIGES} ${CAS_TKSTEP} ${CAS_TKTopAlgo} ${CAS_TKBO} ${CAS_TKBool} ${CAS_TKOffset}
${QT_LIBRARIES} ${GUI_ImageComposer} ${CAS_TKHLR} ${GEOM_GEOM} ${GEOM_GEOMBase} ${GEOM_CurveCreator} )
INSTALL(TARGETS HYDROData EXPORT ${PROJECT_NAME}TargetGroup DESTINATION ${SALOME_INSTALL_LIBS})
--- /dev/null
+// Copyright (C) 2007-2015 CEA/DEN, EDF R&D, OPEN CASCADE
+//
+// Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
+// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
+//
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License as published by the Free Software Foundation; either
+// version 2.1 of the License, or (at your option) any later version.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+//
+// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
+//
+
+#include <HYDROData_ShapeFile.h>
+#include <HYDROData_PolylineXY.h>
+#include <HYDROData_Polyline3D.h>
+#include <HYDROData_Bathymetry.h>
+#include <HYDROData_LandCover.h>
+#include <HYDROData_Profile.h>
+
+#include <QFile>
+#include <QFileInfo>
+#include <TopoDS.hxx>
+#include <TopExp_Explorer.hxx>
+#include <TopoDS_Wire.hxx>
+#include <TopoDS_Vertex.hxx>
+#include <TopoDS_Edge.hxx>
+#include <TopoDS_Face.hxx>
+#include <BRep_Tool.hxx>
+#include <Precision.hxx>
+#include <Handle_Geom_Curve.hxx>
+#include <Handle_Geom_Line.hxx>
+#include <Handle_Geom_TrimmedCurve.hxx>
+#include <Geom_TrimmedCurve.hxx>
+#include <BRepBuilderAPI_MakeEdge.hxx>
+#include <BRepBuilderAPI_MakeWire.hxx>
+#include <BRepBuilderAPI_MakeFace.hxx>
+#include <gp_Pln.hxx>
+#include <BRepLib.hxx>
+#include <ShapeFix_Shape.hxx>
+#include <TopTools_SequenceOfShape.hxx>
+
+HYDROData_ShapeFile::HYDROData_ShapeFile() : myHSHP(NULL)
+{
+}
+
+HYDROData_ShapeFile::~HYDROData_ShapeFile()
+{
+ Free();
+}
+
+void HYDROData_ShapeFile::Export(const QString& aFileName,
+ NCollection_Sequence<Handle_HYDROData_PolylineXY> aPolyXYSeq,
+ NCollection_Sequence<Handle_HYDROData_Polyline3D> aPoly3DSeq,
+ NCollection_Sequence<Handle_HYDROData_LandCover> aLCSeq,
+ QStringList& aNonExpList)
+{
+ SHPHandle hSHPHandle;
+ 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 );
+
+}
+
+int HYDROData_ShapeFile::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 HYDROData_ShapeFile::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 HYDROData_ShapeFile::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 HYDROData_ShapeFile::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;
+}
+
+void HYDROData_ShapeFile::Parse(SHPHandle theHandle)
+{
+ int aShapeType;
+ mySHPObjects.clear();
+ SHPGetInfo( theHandle, NULL, &aShapeType, NULL, NULL );
+ if (aShapeType == 5)
+ {
+ for (int i = 0; i < theHandle->nRecords; i++)
+ mySHPObjects.push_back(SHPReadObject(theHandle, i));
+ }
+}
+
+void HYDROData_ShapeFile::ProcessSHP(SHPObject* anObj, int i, TopoDS_Face& F)
+{
+ TopoDS_Wire W;
+ TopoDS_Edge E;
+ int nParts = anObj->nParts;
+ gp_Pln pln(gp_Pnt(0,0,0), gp_Dir(0,0,1));
+ BRepBuilderAPI_MakeFace aFBuilder(pln);
+
+ //Handle(ShapeFix_Shape) sfs = new ShapeFix_Shape;
+ //sfs->FixFaceTool()->FixOrientationMode() = 1;
+
+ for ( int i = 0 ; i < nParts ; i++ )
+ {
+ BRepBuilderAPI_MakeWire aBuilder;
+ int StartIndex = anObj->panPartStart[i];
+ int EndIndex;
+ if (i != nParts - 1)
+ EndIndex = anObj->panPartStart[i + 1];
+ else
+ EndIndex = anObj->nVertices;
+
+ for ( int k = StartIndex; k < EndIndex - 1 ; k++ )
+ {
+ gp_Pnt P1 (anObj->padfX[k], anObj->padfY[k], 0);
+ gp_Pnt P2 (anObj->padfX[k+1], anObj->padfY[k+1], 0);
+ if (P1.Distance(P2) < Precision::Confusion())
+ continue;
+ BRepBuilderAPI_MakeEdge aMakeEdge(P1, P2);
+ aBuilder.Add(TopoDS::Edge(aMakeEdge.Shape()));
+ }
+
+ aBuilder.Build();
+ W = TopoDS::Wire(aBuilder.Shape());
+ W.Reverse();
+ aFBuilder.Add(W);
+ }
+
+ aFBuilder.Build();
+ TopoDS_Face DF = aFBuilder.Face();
+ BRepLib::BuildCurves3d(DF);
+ bool IsInf = DF.Infinite();
+ if(!DF.IsNull())
+ {
+ //sfs->Init ( DF );
+ //sfs->Perform();
+ F = DF; //TopoDS::Face(sfs->Shape());
+ }
+}
+
+bool HYDROData_ShapeFile::ImportLandCovers(const QString theFileName, QStringList& thePolygonsList, TopTools_SequenceOfShape& theFaces)
+{
+ Free();
+ myHSHP = SHPOpen( theFileName.toAscii().data(), "rb" );
+ Parse(myHSHP);
+ for (int i = 0; i < mySHPObjects.size(); i++)
+ thePolygonsList.append("polygon_" + QString::number(i + 1));
+
+ TopoDS_Face aF;
+ if (myHSHP->nShapeType == 5)
+ {
+ for (int i = 0; i < mySHPObjects.size(); i++)
+ {
+ ProcessSHP(mySHPObjects[i], i, aF);
+ theFaces.Append(aF);
+ }
+ return true;
+ }
+ else
+ return false;
+}
+
+void HYDROData_ShapeFile::Free()
+{
+ for (size_t i = 0; i < mySHPObjects.size(); i++ )
+ free (mySHPObjects[i]);
+
+ mySHPObjects.clear();
+ if (myHSHP != NULL)
+ {
+ SHPClose(myHSHP);
+ myHSHP = NULL;
+ }
+}
\ No newline at end of file
--- /dev/null
+// Copyright (C) 2007-2015 CEA/DEN, EDF R&D, OPEN CASCADE
+//
+// Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
+// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
+//
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License as published by the Free Software Foundation; either
+// version 2.1 of the License, or (at your option) any later version.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+//
+// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
+//
+
+#ifndef HYDRODATA_SHAPEFILE_H
+#define HYDRODATA_SHAPEFILE_H
+
+#include <vector>
+#include <NCollection_Sequence.hxx>
+#include <QStringList>
+#include "HYDROData.h"
+
+//extern "C" {
+#include <shapefil.h>
+//};
+
+class gp_XYZ;
+class Handle_HYDROData_PolylineXY;
+class Handle_HYDROData_Polyline3D;
+class Handle_HYDROData_LandCover;
+class TopTools_SequenceOfShape;
+class TopoDS_Face;
+
+class HYDROData_ShapeFile
+{
+
+public:
+ HYDRODATA_EXPORT HYDROData_ShapeFile( );
+ virtual HYDRODATA_EXPORT ~HYDROData_ShapeFile();
+
+public:
+ //Export operation
+ HYDRODATA_EXPORT void Export(const QString& aFileName,
+ NCollection_Sequence<Handle_HYDROData_PolylineXY> aPolyXYSeq,
+ NCollection_Sequence<Handle_HYDROData_Polyline3D> aPoly3DSeq,
+ NCollection_Sequence<Handle_HYDROData_LandCover> aLCSeq,
+ QStringList& aNonExpList);
+ int WriteObjectPolyXY(SHPHandle theShpHandle, Handle_HYDROData_PolylineXY thePoly );
+ int WriteObjectPoly3D(SHPHandle theShpHandle, Handle_HYDROData_Polyline3D thePoly );
+ int WriteObjectLC(SHPHandle theShpHandle, Handle_HYDROData_LandCover theLC );
+ //Import Landcover
+ void Parse(SHPHandle theHandle);
+ void ProcessSHP(SHPObject* anObj, int i, TopoDS_Face& F);
+ HYDRODATA_EXPORT bool ImportLandCovers(const QString theFileName, QStringList& thePolygonsList, TopTools_SequenceOfShape& theFaces);
+ HYDRODATA_EXPORT void Free();
+ ///
+private:
+ void ProcessFace(TopoDS_Face theFace, SHPHandle theShpHandle);
+private:
+ std::vector<SHPObject*> mySHPObjects;
+ SHPHandle myHSHP;
+};
+
+#endif
INSTALL(TARGETS HYDROGUI EXPORT ${PROJECT_NAME}TargetGroup DESTINATION ${SALOME_INSTALL_LIBS})
-set(PROJECT_LIBRARIES HYDROGUI)
+set(PROJECT_LIBRARIES shapelib HYDROGUI)
set(GUITS_SOURCES
resources/HYDROGUI_images.ts
#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 )
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 = tr("CANNOT_BE_EXPORTED") + "\n";
}
-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;
-}
#include "HYDROGUI_Operation.h"
#include <vector>
-//extern "C" {
-#include <shapefil.h>
-//};
-
class SUIT_FileDlg;
class gp_XYZ;
class Handle_HYDROData_PolylineXY;
protected:
virtual void startOperation();
- int WriteObjectPolyXY(SHPHandle theShpHandle, Handle_HYDROData_PolylineXY thePoly );
- int WriteObjectPoly3D(SHPHandle theShpHandle, Handle_HYDROData_Polyline3D thePoly );
- int WriteObjectLC(SHPHandle theShpHandle, Handle_HYDROData_LandCover theLC );
-private:
- void ProcessFace(TopoDS_Face theFace, SHPHandle theShpHandle);
+
private:
SUIT_FileDlg* myFileDlg;
- std::vector<SHPObject*> mySHPObjects;
};
#endif
#include <HYDROGUI_DataObject.h>
#include <HYDROData_Iterator.h>
-
+#include <HYDROData_ShapeFile.h>
#include <HYDROData_Profile.h>
#include <SUIT_Desktop.h>
#include <TopoDS.hxx>
#include <TopoDS_Shape.hxx>
#include <TopoDS_Wire.hxx>
-#include <BRepBuilderAPI_MakeEdge.hxx>
-#include <BRepBuilderAPI_MakeWire.hxx>
-#include <BRepBuilderAPI_MakeFace.hxx>
-#include <gp_Pln.hxx>
-#include <BRepLib.hxx>
-#include <ShapeFix_Shape.hxx>
+
HYDROGUI_ImportLandCoverOp::HYDROGUI_ImportLandCoverOp( HYDROGUI_Module* theModule )
}
-void HYDROGUI_ImportLandCoverOp::Parse(SHPHandle theHandle)
-{
- int aShapeType;
- mySHPObjects.clear();
- SHPGetInfo( theHandle, NULL, &aShapeType, NULL, NULL );
- if (aShapeType == 5)
- {
- for (int i = 0; i < theHandle->nRecords; i++)
- mySHPObjects.push_back(SHPReadObject(theHandle, i));
- }
-}
-
-void HYDROGUI_ImportLandCoverOp::ProcessSHP(SHPObject* anObj, int i, TopoDS_Face& F)
-{
- TopoDS_Wire W;
- TopoDS_Edge E;
- int nParts = anObj->nParts;
- gp_Pln pln(gp_Pnt(0,0,0), gp_Dir(0,0,1));
- BRepBuilderAPI_MakeFace aFBuilder(pln);
-
- //Handle(ShapeFix_Shape) sfs = new ShapeFix_Shape;
- //sfs->FixFaceTool()->FixOrientationMode() = 1;
-
- for ( int i = 0 ; i < nParts ; i++ )
- {
- BRepBuilderAPI_MakeWire aBuilder;
- int StartIndex = anObj->panPartStart[i];
- int EndIndex;
- if (i != nParts - 1)
- EndIndex = anObj->panPartStart[i + 1];
- else
- EndIndex = anObj->nVertices;
-
- for ( int k = StartIndex; k < EndIndex - 1 ; k++ )
- {
- gp_Pnt P1 (anObj->padfX[k], anObj->padfY[k], 0);
- gp_Pnt P2 (anObj->padfX[k+1], anObj->padfY[k+1], 0);
- if (P1.Distance(P2) < Precision::Confusion())
- continue;
- BRepBuilderAPI_MakeEdge aMakeEdge(P1, P2);
- aBuilder.Add(TopoDS::Edge(aMakeEdge.Shape()));
- }
-
- aBuilder.Build();
- W = TopoDS::Wire(aBuilder.Shape());
- W.Reverse();
- aFBuilder.Add(W);
- }
-
- aFBuilder.Build();
- TopoDS_Face DF = aFBuilder.Face();
- BRepLib::BuildCurves3d(DF);
- bool IsInf = DF.Infinite();
- if(!DF.IsNull())
- {
- //sfs->Init ( DF );
- //sfs->Perform();
- F = DF; //TopoDS::Face(sfs->Shape());
- }
-}
-
void HYDROGUI_ImportLandCoverOp::onFileSelected()
{
HYDROGUI_ImportLandCoverDlg* aPanel = ::qobject_cast<HYDROGUI_ImportLandCoverDlg*>( inputPanel() );
QString anExt = aFileName.split('.', QString::SkipEmptyParts).back();
if (anExt == "shp")
- {
- SHPHandle aHSHP;
- aHSHP = SHPOpen( aFileName.toAscii().data(), "rb" );
- Parse(aHSHP);
+ {
+ startDocOperation();
+ QApplication::setOverrideCursor(Qt::WaitCursor);
- startDocOperation();
QStringList aPolygonsList;
- for (int i = 0; i < mySHPObjects.size(); i++)
- aPolygonsList.append("polygon_" + QString::number(i + 1));
+ TopTools_SequenceOfShape aFaces;
+ HYDROData_ShapeFile anImporter;
+
+ if (!anImporter.ImportLandCovers(aFileName, aPolygonsList, aFaces))
+ {
+ SUIT_MessageBox::warning( module()->getApp()->desktop(), tr( "IMPORT_LANDCOVER" ), "Cannot import land cover;\nThe shape type is not polygon" );
+ abort();
+ }
+
aPanel->setPolygonNames(aPolygonsList);
SalomeApp_Study* aStudy = dynamic_cast<SalomeApp_Study*>( module()->getApp()->activeStudy() );
}
}
- QApplication::setOverrideCursor(Qt::WaitCursor);
- TopTools_SequenceOfShape aFaces;
- TopoDS_Face aF;
- if (aHSHP->nShapeType == 5)
- {
- for (int i = 0; i < mySHPObjects.size(); i++)
- {
- ProcessSHP(mySHPObjects[i], i, aF);
- aFaces.Append(aF);
- }
- }
- else
- SUIT_MessageBox::warning( module()->getApp()->desktop(), tr( "IMPORT_LANDCOVER" ), "Cannot import land cover;\nThe shape type is not polygon" );
QApplication::restoreOverrideCursor();
Handle(HYDROData_LandCover) aLC = Handle(HYDROData_LandCover)::DownCast( doc()->CreateObject( KIND_LAND_COVER ) );
}
commitDocOperation();
-
- for (size_t i = 0; i < mySHPObjects.size(); i++ )
- free (mySHPObjects[i]);
- mySHPObjects.clear();
- SHPClose(aHSHP);
+ anImporter.Free();
+
}
}
#include <vector>
#include <QMap>
-//extern "C" {
-#include <shapefil.h>
-//};
-
class SUIT_FileDlg;
class HYDROGUI_Shape;
class TopoDS_Face;
virtual bool processApply( int& theUpdateFlags, QString& theErrorMsg, QStringList& theBrowseObjectsEntries );
HYDROGUI_InputPanel* createInputPanel() const;
- void Parse(SHPHandle theHandle);
- void ProcessSHP(SHPObject* anObj, int i, TopoDS_Face& F);
+
void erasePreview();
protected slots:
void onViewerSelectionChanged ();
private:
- std::vector<SHPObject*> mySHPObjects;
QMap<QString, HYDROGUI_Shape*> myPolygonName2PrsShape;
};