From: isn Date: Thu, 25 Jun 2015 10:43:14 +0000 (+0300) Subject: export of landcovers to shp-polygons (draft) X-Git-Tag: v1.4.2~33 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=dacea3a67f71fc820f2351d4ac2f7e2566837429;p=modules%2Fhydro.git export of landcovers to shp-polygons (draft) --- diff --git a/src/HYDROGUI/HYDROGUI_ExportFileOp.cxx b/src/HYDROGUI/HYDROGUI_ExportFileOp.cxx index 02483407..17d24d16 100644 --- a/src/HYDROGUI/HYDROGUI_ExportFileOp.cxx +++ b/src/HYDROGUI/HYDROGUI_ExportFileOp.cxx @@ -30,6 +30,7 @@ #include #include #include +#include #include @@ -41,12 +42,18 @@ #include #include #include +#include +#include +#include +#include +#include +#include HYDROGUI_ExportFileOp::HYDROGUI_ExportFileOp( HYDROGUI_Module* theModule ) : HYDROGUI_Operation( theModule ) { - setName( tr( "EXPORT_POLYLINE" ) ); + setName( tr( "EXPORT_TO_SHAPE_FILE" ) ); } HYDROGUI_ExportFileOp::~HYDROGUI_ExportFileOp() @@ -57,13 +64,14 @@ void HYDROGUI_ExportFileOp::startOperation() { 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 aPolyXYSeq; NCollection_Sequence aPoly3DSeq; - + NCollection_Sequence aLCSeq; HYDROData_SequenceOfObjects aSeq = HYDROGUI_Tool::GetSelectedObjects( module() ); for( int anIndex = 1, aLength = aSeq.Length(); anIndex <= aLength; anIndex++ ) @@ -75,13 +83,17 @@ void HYDROGUI_ExportFileOp::startOperation() 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; @@ -96,7 +108,13 @@ void HYDROGUI_ExportFileOp::startOperation() 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(); } @@ -163,5 +181,80 @@ void HYDROGUI_ExportFileOp::WriteObjectPoly3D(SHPHandle theShpHandle, Handle_HYD 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 x, y; + std::vector 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 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 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; +} diff --git a/src/HYDROGUI/HYDROGUI_ExportFileOp.h b/src/HYDROGUI/HYDROGUI_ExportFileOp.h index abab9c29..ed9baa99 100644 --- a/src/HYDROGUI/HYDROGUI_ExportFileOp.h +++ b/src/HYDROGUI/HYDROGUI_ExportFileOp.h @@ -34,6 +34,8 @@ class SUIT_FileDlg; class gp_XYZ; class Handle_HYDROData_PolylineXY; class Handle_HYDROData_Polyline3D; +class Handle_HYDROData_LandCover; +class TopoDS_Face; class HYDROGUI_ExportFileOp : public HYDROGUI_Operation { @@ -47,6 +49,9 @@ protected: virtual void startOperation(); void WriteObjectPolyXY(SHPHandle theShpHandle, Handle_HYDROData_PolylineXY thePoly ); void WriteObjectPoly3D(SHPHandle theShpHandle, Handle_HYDROData_Polyline3D thePoly ); + void WriteObjectLC(SHPHandle theShpHandle, Handle_HYDROData_LandCover theLC ); +private: + void ProcessFace(TopoDS_Face theFace, SHPHandle theShpHandle); private: SUIT_FileDlg* myFileDlg; std::vector mySHPObjects; diff --git a/src/HYDROGUI/HYDROGUI_ImportLandcoverOp.cxx b/src/HYDROGUI/HYDROGUI_ImportLandcoverOp.cxx index 79179eb3..5151349c 100644 --- a/src/HYDROGUI/HYDROGUI_ImportLandcoverOp.cxx +++ b/src/HYDROGUI/HYDROGUI_ImportLandcoverOp.cxx @@ -224,6 +224,8 @@ void HYDROGUI_ImportLandCoverOp::ProcessSHP(SHPObject* anObj, int i, TopoDS_Face { 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())); } @@ -236,7 +238,8 @@ void HYDROGUI_ImportLandCoverOp::ProcessSHP(SHPObject* anObj, int i, TopoDS_Face aFBuilder.Build(); TopoDS_Face DF = aFBuilder.Face(); - BRepLib::BuildCurves3d(DF); + BRepLib::BuildCurves3d(DF); + bool IsInf = DF.Infinite(); if(!DF.IsNull()) { //sfs->Init ( DF ); @@ -277,8 +280,8 @@ void HYDROGUI_ImportLandCoverOp::onFileSelected() startDocOperation(); QStringList aPolygonsList; - for (int i = 1; i < mySHPObjects.size(); i++) - aPolygonsList.append("polygon_" + QString::number(i)); + for (int i = 0; i < mySHPObjects.size(); i++) + aPolygonsList.append("polygon_" + QString::number(i + 1)); aPanel->setPolygonNames(aPolygonsList); SalomeApp_Study* aStudy = dynamic_cast( module()->getApp()->activeStudy() ); diff --git a/src/HYDROGUI/HYDROGUI_Module.cxx b/src/HYDROGUI/HYDROGUI_Module.cxx index 77aecede..60d109b3 100644 --- a/src/HYDROGUI/HYDROGUI_Module.cxx +++ b/src/HYDROGUI/HYDROGUI_Module.cxx @@ -684,8 +684,9 @@ void HYDROGUI_Module::contextMenuPopup( const QString& theClient, theMenu->addSeparator(); } - if (anIsPolyline || anIsPolyline3D) - theMenu->addAction( action( ExportPolylineId ) ); + bool anIsPoly = anIsPolyline || anIsPolyline3D; + if ((anIsPoly && !anIsLandCover) || (!anIsPoly && anIsLandCover)) + theMenu->addAction( action( ExportToShapeFileID ) ); // Add copy action QAction* aCopyAction = action( CopyId ); diff --git a/src/HYDROGUI/HYDROGUI_Operations.cxx b/src/HYDROGUI/HYDROGUI_Operations.cxx index 8858974a..98e3ee3c 100644 --- a/src/HYDROGUI/HYDROGUI_Operations.cxx +++ b/src/HYDROGUI/HYDROGUI_Operations.cxx @@ -212,7 +212,7 @@ void HYDROGUI_Module::createActions() createAction( ProfileInterpolateId, "PROFILE_INTERPOLATE", "PROFILE_INTERPOLATE_ICO" ); createAction( SubmersibleId, "SUBMERSIBLE", "SUBMERSIBLE_ICO" ); - createAction( ExportPolylineId, "EXPORT_POLYLINE", "EXPORT_POLYLINE_ICO" ); + createAction( ExportToShapeFileID, "EXPORT_TO_SHAPE_FILE", "EXPORT_TO_SHAPE_FILE_ICO" ); createAction( SplitPolylinesId, "SPLIT_POLYLINES", "SPLIT_POLYLINES_ICO" ); createAction( MergePolylinesId, "MERGE_POLYLINES", "MERGE_POLYLINES_ICO" ); @@ -473,7 +473,7 @@ LightApp_Operation* HYDROGUI_Module::createOperation( const int theId ) const case ForcedUpdateObjectId: anOp = new HYDROGUI_UpdateObjectOp( aModule, theId == ForcedUpdateObjectId ); break; - case ExportPolylineId: + case ExportToShapeFileID: anOp = new HYDROGUI_ExportFileOp( aModule ); break; case ImportLandcoverId: diff --git a/src/HYDROGUI/HYDROGUI_Operations.h b/src/HYDROGUI/HYDROGUI_Operations.h index eef042d9..fc190847 100644 --- a/src/HYDROGUI/HYDROGUI_Operations.h +++ b/src/HYDROGUI/HYDROGUI_Operations.h @@ -113,7 +113,7 @@ enum OperationId ImportSinusXId, ExportSinusXId, - ExportPolylineId, + ExportToShapeFileID, ImportLandcoverId, ImportStricklerTableFromFileId, diff --git a/src/HYDROGUI/resources/HYDROGUI_images.ts b/src/HYDROGUI/resources/HYDROGUI_images.ts index 613d7f57..475bbaba 100644 --- a/src/HYDROGUI/resources/HYDROGUI_images.ts +++ b/src/HYDROGUI/resources/HYDROGUI_images.ts @@ -418,8 +418,8 @@ - EXPORT_POLYLINE_ICO - icon_export_polyline.png + EXPORT_TO_SHAPE_FILE_ICO + icon_export_shp.png diff --git a/src/HYDROGUI/resources/HYDROGUI_msg_en.ts b/src/HYDROGUI/resources/HYDROGUI_msg_en.ts index 381bc4c8..5c331d7a 100644 --- a/src/HYDROGUI/resources/HYDROGUI_msg_en.ts +++ b/src/HYDROGUI/resources/HYDROGUI_msg_en.ts @@ -1043,8 +1043,8 @@ Would you like to remove all references from the image? Submersible - DSK_EXPORT_POLYLINE - Export Polyline + DSK_EXPORT_TO_SHAPE_FILE + Export to Shape file MEN_CREATE_CALCULATION @@ -1355,8 +1355,8 @@ Would you like to remove all references from the image? Submersible - MEN_EXPORT_POLYLINE - Export Polyline + MEN_EXPORT_TO_SHAPE_FILE + Export to Shape file @@ -1649,8 +1649,8 @@ Would you like to remove all references from the image? If the object is submersible - STB_EXPORT_POLYLINE - Export Polyline + STB_EXPORT_TO_SHAPE_FILE + Export to Shape file @@ -2311,8 +2311,12 @@ file cannot be correctly imported for an Obstacle definition. HYDROGUI_ExportFileOp - EXPORT_POLYLINE - Export polyline + EXPORT_TO_SHAPE_FILE + Export to Shape file + + + SHP_FILTER + Shape Files (*.shp) diff --git a/src/HYDROGUI/resources/icon_export_polyline.png b/src/HYDROGUI/resources/icon_export_polyline.png deleted file mode 100644 index 3e28616d..00000000 Binary files a/src/HYDROGUI/resources/icon_export_polyline.png and /dev/null differ diff --git a/src/HYDROGUI/resources/icon_export_shp.png b/src/HYDROGUI/resources/icon_export_shp.png new file mode 100644 index 00000000..3e28616d Binary files /dev/null and b/src/HYDROGUI/resources/icon_export_shp.png differ