Salome HOME
Merge branch 'master' of https://git.salome-platform.org/git/modules/hydro
[modules/hydro.git] / src / HYDROGUI / HYDROGUI_ExportFileOp.cxx
index 72915e5d7d2bd5bb15c6d035fa20e8dcfa2f86e2..b256ba4f28d70a4b9376bde57cff4aef3c63ecd7 100644 (file)
 #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>
 #include <HYDROGUI_DataObject.h>
 #include <HYDROData_Bathymetry.h>
 #include <HYDROData_LandCoverMap.h>
 
+#include <HYDROData_StricklerTable.h>
+
 #include <HYDROData_Profile.h>
 
 #include <SUIT_Desktop.h>
 #include <Handle_Geom_TrimmedCurve.hxx>
 #include <Geom_TrimmedCurve.hxx>
 #include <HYDROData_ShapeFile.h>
+#include <SUIT_Desktop.h>
+#include <SalomeApp_Study.h>
+#include <HYDROData_Iterator.h>
+
+#include <LightApp_Application.h>
+#include <QSet>
 
 HYDROGUI_ExportFileOp::HYDROGUI_ExportFileOp( HYDROGUI_Module* theModule )
 : HYDROGUI_Operation( theModule )
@@ -104,9 +113,77 @@ void HYDROGUI_ExportFileOp::startOperation()
       else
       {
         //Export polygons
-        //aSeq.Size() <= 1
+        //Extract all attribute names from all strickler tables
+        Handle_HYDROData_Document aDoc = HYDROData_Document::Document( application()->activeStudy()->id() );
+        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)
+        {
+          HYDROData_Iterator anIt( aDoc, KIND_STRICKLER_TABLE );
+          for( ; anIt.More(); anIt.Next() )
+          {
+            Handle(HYDROData_StricklerTable) aStricklerTableObj = Handle(HYDROData_StricklerTable)::DownCast( anIt.Current() );
+            if ( !aStricklerTableObj.IsNull())
+              anAttrNames << aStricklerTableObj->GetAttrName();
+          }
+        }
+        else
+          return; 
+
+        QStringList SortedListOfAttr = anAttrNames.toList();
+        SortedListOfAttr.sort();
+        //
         Handle_HYDROData_LandCoverMap aLCM = Handle(HYDROData_LandCoverMap)::DownCast( aSeq(1) );
-        anExporter.Export(aFileName, aLCM, aNonExpList);
+        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.
+          QString aCItem = aDlg.getCurrentItem();
+          Handle(HYDROData_StricklerTable) aStricklerTableObj;
+          {
+            HYDROData_Iterator anIt( aDoc, KIND_STRICKLER_TABLE );
+            for( ; anIt.More(); anIt.Next() )
+            {
+              aStricklerTableObj = Handle(HYDROData_StricklerTable)::DownCast( anIt.Current() );
+              if ( !aStricklerTableObj.IsNull() && aStricklerTableObj->GetAttrName() == aCItem)
+                break;
+            }
+          }
+
+          //export shape-data
+          anExporter.Export(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 (aDBFFileName.toStdString().c_str());
+          bool bToSaveAttrInfo = aDlg.getAttrCheckBoxState() && !aDlg.getCurrentItem().isEmpty();
+          if (bToSaveAttrInfo)
+          {
+            //export attribute info
+            QStringList anAttrValues;
+            QStringList aStricklerTypes;
+            if (aNonExpList.empty())
+            {
+              HYDROData_LandCoverMap::Explorer aLCMIt( aLCM );
+              for( ; aLCMIt.More(); aLCMIt.Next() )
+              {
+                QString aST = aLCMIt.StricklerType();
+                anAttrValues << aStricklerTableObj->GetAttrValue(aST);
+                aStricklerTypes << aST;
+              }
+            }
+            aLCM->ExportDBF(aDBFFileName, aCItem, anAttrValues, aStricklerTypes);
+          }
+        }
+        else
+        {
+          abort();
+          return;
+        }
+
       }
 
       if (!aNonExpList.empty())