]> SALOME platform Git repositories - modules/hydro.git/commitdiff
Salome HOME
Import/Export new corrections
authorisn <isn@opencascade.com>
Thu, 25 Jun 2015 14:45:28 +0000 (17:45 +0300)
committerisn <isn@opencascade.com>
Thu, 25 Jun 2015 14:45:28 +0000 (17:45 +0300)
src/HYDROGUI/HYDROGUI_ExportFileOp.cxx
src/HYDROGUI/HYDROGUI_ExportFileOp.h

index b52e18b030b71a5ed8ee813e60beab4de588545e..e5dcd7ffa6aff785a0e1859de2ca611b2d869e96 100644 (file)
 #include <TopExp_Explorer.hxx>
 #include <TopoDS_Wire.hxx>
 #include <TopoDS_Vertex.hxx>
+#include <TopoDS_Edge.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>
 
 HYDROGUI_ExportFileOp::HYDROGUI_ExportFileOp( HYDROGUI_Module* theModule )
 : HYDROGUI_Operation( theModule )
@@ -93,34 +97,49 @@ void HYDROGUI_ExportFileOp::startOperation()
     SUIT_MessageBox::warning( module()->getApp()->desktop(), "Export Polyline", "Cannot export polylines of different kind");
   else
   {
-    QString aPolyName = "";
+    QString aName = "";
     if (aPolyXYSeq.Size() == 1 && aPoly3DSeq.IsEmpty())
-      aPolyName = aPolyXYSeq(1)->GetName();
+      aName = aPolyXYSeq(1)->GetName();
     if (aPoly3DSeq.Size() == 1 && aPolyXYSeq.IsEmpty())
-      aPolyName = aPoly3DSeq(1)->GetName();
-    QString aFileName = SUIT_FileDlg::getFileName( module()->getApp()->desktop(), aPolyName, aFilter, tr( "EXPORT_TO_SHAPE_FILE" ), false );
+      aName = aPoly3DSeq(1)->GetName();
+    if (aLCSeq.Size() == 1 && aPolyXYSeq.IsEmpty() && aPoly3DSeq.IsEmpty())
+      aName = aLCSeq(1)->GetName();
+    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 );
+        hSHPHandle = SHPCreate( aFileName.toAscii().data(), SHPT_ARC );        
         for (int i = 1; i <= aPolyXYSeq.Size(); i++)
-          WriteObjectPolyXY(hSHPHandle, aPolyXYSeq(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++)
-          WriteObjectPoly3D(hSHPHandle, aPoly3DSeq(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++)
-          WriteObjectLC(hSHPHandle, aLCSeq(i));
+          if (WriteObjectLC(hSHPHandle, aLCSeq(i)) != 1)
+            aNonExpList.append(aLCSeq(i)->GetName());
       }
       SHPClose( hSHPHandle );
+      if (!aNonExpList.empty())
+      {
+        QString aMessage = "The next entities cannot be exported:\n";
+        foreach (QString anNonExpEntName, aNonExpList)
+          aMessage += anNonExpEntName + "\n"; 
+        SUIT_MessageBox::warning( module()->getApp()->desktop(), "Export warning", aMessage);
+      }
+      //TODO  pint aNonExpList
       commit();
     }
     else
@@ -129,12 +148,16 @@ void HYDROGUI_ExportFileOp::startOperation()
 
 }
 
-void HYDROGUI_ExportFileOp::WriteObjectPolyXY(SHPHandle theShpHandle, Handle_HYDROData_PolylineXY thePoly )
+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());
@@ -154,13 +177,18 @@ void HYDROGUI_ExportFileOp::WriteObjectPolyXY(SHPHandle theShpHandle, Handle_HYD
   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;
 }
 
-void HYDROGUI_ExportFileOp::WriteObjectPoly3D(SHPHandle theShpHandle, Handle_HYDROData_Polyline3D thePoly )
+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++)
   {
@@ -184,14 +212,35 @@ void HYDROGUI_ExportFileOp::WriteObjectPoly3D(SHPHandle theShpHandle, Handle_HYD
   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;
 }
 
-void HYDROGUI_ExportFileOp::WriteObjectLC(SHPHandle theShpHandle, Handle_HYDROData_LandCover theLC )
+int HYDROGUI_ExportFileOp::WriteObjectLC(SHPHandle theShpHandle, Handle_HYDROData_LandCover theLC )
 {
-
   TopoDS_Shape aSh = theLC->GetShape();
   if (aSh.IsNull())
-    return;
+    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);
@@ -208,7 +257,9 @@ void HYDROGUI_ExportFileOp::WriteObjectLC(SHPHandle theShpHandle, Handle_HYDRODa
     }
   }
   else
-    return;
+    return 0;
+
+  return 1;
  
 }
 
index ed9baa99d37f9b711cfda1a276d645e077cdaf80..886424df1b8fccb415d5ac2041b2334de872ab5f 100644 (file)
@@ -47,9 +47,9 @@ public:
 
 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 );
+  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: