Salome HOME
lot 10 - warnings for DTM - untested
[modules/hydro.git] / src / HYDROGUI / HYDROGUI_ExportFileOp.cxx
index 9baba92b180b6dd1195a3352ae807b0985c61d7c..cf1565cfff4ba533c3a6ba2b6b764feaaa316b4c 100644 (file)
@@ -21,7 +21,7 @@
 #include "HYDROGUI_DataModel.h"
 #include "HYDROGUI_Module.h"
 #include "HYDROGUI_UpdateFlags.h"
-#include "HYDROGUI_Tool.h"
+#include "HYDROGUI_Tool2.h"
 #include "HYDROGUI_ExportLandCoverMapDlg.h"
 #include <HYDROData_PolylineXY.h>
 #include <HYDROData_Polyline3D.h>
@@ -48,9 +48,9 @@
 #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_Curve.hxx>
+#include <Geom_Line.hxx>
+#include <Geom_TrimmedCurve.hxx>
 #include <Geom_TrimmedCurve.hxx>
 #include <HYDROData_ShapeFile.h>
 #include <SUIT_Desktop.h>
@@ -78,8 +78,8 @@ void HYDROGUI_ExportFileOp::startOperation()
   
   Handle(HYDROData_PolylineXY) aPolyXY;
   Handle(HYDROData_Polyline3D) aPoly3D;
-  NCollection_Sequence<Handle_HYDROData_PolylineXY> aPolyXYSeq;
-  NCollection_Sequence<Handle_HYDROData_Polyline3D> aPoly3DSeq;
+  NCollection_Sequence<Handle(HYDROData_PolylineXY)> aPolyXYSeq;
+  NCollection_Sequence<Handle(HYDROData_Polyline3D)> aPoly3DSeq;
   //
   HYDROData_SequenceOfObjects aSeq = HYDROGUI_Tool::GetSelectedObjects( module() );
   for( int anIndex = 1, aLength = aSeq.Length(); anIndex <= aLength; anIndex++ )
@@ -107,72 +107,75 @@ void HYDROGUI_ExportFileOp::startOperation()
     {
       QStringList aNonExpList;
       HYDROData_ShapeFile anExporter;
+      Handle(HYDROData_Document) aDoc = HYDROData_Document::Document( application()->activeStudy()->id() );
       if (!aPolyXYSeq.IsEmpty() || !aPolyXYSeq.IsEmpty())
         //Export polylines
-        anExporter.Export(aFileName, aPolyXYSeq, aPoly3DSeq, aNonExpList);
+        anExporter.Export(aDoc, aFileName, aPolyXYSeq, aPoly3DSeq, aNonExpList);
       else
       {
         //Export polygons
         //Extract all attribute names from all strickler tables
-        Handle_HYDROData_Document aDoc = HYDROData_Document::Document( application()->activeStudy()->id() );
-        QSet<QString> AttrNames;
+        QSet<QString> anAttrNames;
         //use QSet to store attribute names. Yet it's not so good if the document contains two strickler types
         //with the same name
-        if ( aDoc )
+        if (aDoc)
         {
-          HYDROData_Iterator It( aDoc, KIND_STRICKLER_TABLE );
-          for( ; It.More(); It.Next() )
+          HYDROData_Iterator anIt( aDoc, KIND_STRICKLER_TABLE );
+          for( ; anIt.More(); anIt.Next() )
           {
-            Handle(HYDROData_StricklerTable) aStricklerTableObj = Handle(HYDROData_StricklerTable)::DownCast( It.Current() );
+            Handle(HYDROData_StricklerTable) aStricklerTableObj = Handle(HYDROData_StricklerTable)::DownCast( anIt.Current() );
             if ( !aStricklerTableObj.IsNull())
-              AttrNames << aStricklerTableObj->GetAttrName();
+              anAttrNames << aStricklerTableObj->GetAttrName();
           }
         }
         else
           return; 
 
+        QStringList SortedListOfAttr = anAttrNames.toList();
+        SortedListOfAttr.sort();
         //
-        HYDROGUI_ExportLandCoverMapDlg aDlg( module()->getApp()->desktop(), AttrNames.toList());
+        Handle(HYDROData_LandCoverMap) aLCM = Handle(HYDROData_LandCoverMap)::DownCast( aSeq(1) );
+        bool IsLinear = aLCM->CheckLinear();
+        HYDROGUI_ExportLandCoverMapDlg aDlg( module()->getApp()->desktop(), IsLinear, SortedListOfAttr);
         if ( aDlg.exec() == HYDROGUI_ExportLandCoverMapDlg::Accepted )
         { 
           //In our case :  aSeq.Size() == 1
           //Export of multiple landcover maps into the one shp-file is disallowed.
-          Handle_HYDROData_LandCoverMap aLCM = Handle(HYDROData_LandCoverMap)::DownCast( aSeq(1) );
-          QString CItem = aDlg.getCurrentItem();
-          Handle(HYDROData_StricklerTable) StricklerTableObj;
+          QString aCItem = aDlg.getCurrentItem();
+          Handle(HYDROData_StricklerTable) aStricklerTableObj;
           {
-            HYDROData_Iterator It( aDoc, KIND_STRICKLER_TABLE );
-            for( ; It.More(); It.Next() )
+            HYDROData_Iterator anIt( aDoc, KIND_STRICKLER_TABLE );
+            for( ; anIt.More(); anIt.Next() )
             {
-              StricklerTableObj = Handle(HYDROData_StricklerTable)::DownCast( It.Current() );
-              if ( !StricklerTableObj.IsNull() && StricklerTableObj->GetAttrName() == CItem)
+              aStricklerTableObj = Handle(HYDROData_StricklerTable)::DownCast( anIt.Current() );
+              if ( !aStricklerTableObj.IsNull() && aStricklerTableObj->GetAttrName() == aCItem)
                 break;
             }
           }
 
           //export shape-data
-          anExporter.Export(aFileName, aLCM, aNonExpList);
-          QString DBFFileName = aFileName.replace( ".shp", ".dbf", Qt::CaseInsensitive);
+          anExporter.Export(aDoc, aFileName, aLCM, aNonExpList, false, !IsLinear, aDlg.getDeflValue());
+          QString aDBFFileName = aFileName.replace( ".shp", ".dbf", Qt::CaseInsensitive);
           //Even if attribute-checkbox is unchecked, the .dbf-file should be removed. 
           //otherwise it may be used with wrong .shp-file. This is an incorrect behaivor.
-          remove (DBFFileName.toStdString().c_str());
-          bool ToSaveAttrInfo = aDlg.getAttrCheckBoxState();
-          if (ToSaveAttrInfo)
+          remove (aDBFFileName.toStdString().c_str());
+          bool bToSaveAttrInfo = aDlg.getAttrCheckBoxState() && !aDlg.getCurrentItem().isEmpty();
+          if (bToSaveAttrInfo)
           {
             //export attribute info
-            QStringList AttrValues;
-            QStringList StricklerTypes;
+            QStringList anAttrValues;
+            QStringList aStricklerTypes;
             if (aNonExpList.empty())
             {
-              HYDROData_LandCoverMap::Iterator It( aLCM );
-              for( ; It.More(); It.Next() )
+              HYDROData_LandCoverMap::Explorer aLCMIt( aLCM );
+              for( ; aLCMIt.More(); aLCMIt.Next() )
               {
-                QString ST = It.StricklerType();
-                AttrValues << StricklerTableObj->GetAttrValue(ST);
-                StricklerTypes << ST;
+                QString aST = aLCMIt.StricklerType();
+                anAttrValues << aStricklerTableObj->GetAttrValue(aST);
+                aStricklerTypes << aST;
               }
             }
-            aLCM->ExportDBF(DBFFileName, CItem, AttrValues, StricklerTypes);
+            aLCM->ExportDBF(aDBFFileName, aCItem, anAttrValues, aStricklerTypes);
           }
         }
         else