]> SALOME platform Git repositories - modules/hydro.git/commitdiff
Salome HOME
export of landcovers to shp-polygons (draft)
authorisn <isn@opencascade.com>
Thu, 25 Jun 2015 10:43:14 +0000 (13:43 +0300)
committerisn <isn@opencascade.com>
Thu, 25 Jun 2015 12:16:02 +0000 (15:16 +0300)
src/HYDROGUI/HYDROGUI_ExportFileOp.cxx
src/HYDROGUI/HYDROGUI_ExportFileOp.h
src/HYDROGUI/HYDROGUI_ImportLandcoverOp.cxx
src/HYDROGUI/HYDROGUI_Module.cxx
src/HYDROGUI/HYDROGUI_Operations.cxx
src/HYDROGUI/HYDROGUI_Operations.h
src/HYDROGUI/resources/HYDROGUI_images.ts
src/HYDROGUI/resources/HYDROGUI_msg_en.ts
src/HYDROGUI/resources/icon_export_polyline.png [deleted file]
src/HYDROGUI/resources/icon_export_shp.png [new file with mode: 0644]

index 02483407f1cd784252eed68dca1c19b7e87ec0ed..17d24d16cff9e6e7352c55133dfa06cf9b7876db 100644 (file)
@@ -30,6 +30,7 @@
 #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()
@@ -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<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++ )
@@ -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<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;
+}
index abab9c298f46841f28da1cba6491089826748347..ed9baa99d37f9b711cfda1a276d645e077cdaf80 100644 (file)
@@ -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<SHPObject*> mySHPObjects;
index 79179eb31500dd7aa075eb3954f6ec2ea83bb4ed..5151349cb6d608d0cdc1fbd428b8f9154069add2 100644 (file)
@@ -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<SalomeApp_Study*>( module()->getApp()->activeStudy() );
index 77aecedec32b355f6ba39745ce9d1507bdb22943..60d109b32a0d713e5232d2d6cf969879f1aa4567 100644 (file)
@@ -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 );
index 8858974a1039c9aea1daf4309bf7485828750096..98e3ee3c6c8a59610ecd179d474a8f6d2330b3ad 100644 (file)
@@ -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:
index eef042d9e8709782ff7b77bd0252c91f141641d9..fc1908471cdb0f02706eae33be88150ebe904609 100644 (file)
@@ -113,7 +113,7 @@ enum OperationId
   ImportSinusXId,
   ExportSinusXId,
     
-  ExportPolylineId,
+  ExportToShapeFileID,
   ImportLandcoverId,
 
   ImportStricklerTableFromFileId,
index 613d7f574266a1e4e90aed3d7fc88f0176995470..475bbaba59020b943d02d948b365629747f60dab 100644 (file)
     </message>
 
     <message>
-      <source>EXPORT_POLYLINE_ICO</source>
-      <translation>icon_export_polyline.png</translation>
+      <source>EXPORT_TO_SHAPE_FILE_ICO</source>
+      <translation>icon_export_shp.png</translation>
     </message>
 
     <message>
index 381bc4c857fd855deecf5506252ccd513903d501..5c331d7ac2e6b08fea33489bd7e489d55fccdb0d 100644 (file)
@@ -1043,8 +1043,8 @@ Would you like to remove all references from the image?</translation>
       <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>
@@ -1355,8 +1355,8 @@ Would you like to remove all references from the image?</translation>
       <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>
@@ -1649,8 +1649,8 @@ Would you like to remove all references from the image?</translation>
       <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>
 
 
@@ -2311,8 +2311,12 @@ file cannot be correctly imported for an Obstacle definition.</translation>
   <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>
   
diff --git a/src/HYDROGUI/resources/icon_export_polyline.png b/src/HYDROGUI/resources/icon_export_polyline.png
deleted file mode 100644 (file)
index 3e28616..0000000
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 (file)
index 0000000..3e28616
Binary files /dev/null and b/src/HYDROGUI/resources/icon_export_shp.png differ