]> SALOME platform Git repositories - modules/hydro.git/commitdiff
Salome HOME
LCM // Import/Export of SHP p.7
authorisn <isn@opencascade.com>
Thu, 5 Nov 2015 11:31:22 +0000 (14:31 +0300)
committerisn <isn@opencascade.com>
Fri, 6 Nov 2015 16:27:31 +0000 (19:27 +0300)
src/HYDROData/HYDROData_LandCoverMap.cxx
src/HYDROData/HYDROData_ShapeFile.cxx
src/HYDROGUI/CMakeLists.txt
src/HYDROGUI/HYDROGUI_ExportFileOp.cxx
src/HYDROGUI/HYDROGUI_ExportLandCoverMapDlg.cxx [new file with mode: 0644]
src/HYDROGUI/HYDROGUI_ExportLandCoverMapDlg.h [new file with mode: 0644]
src/HYDROGUI/HYDROGUI_ImportLandCoverMapDlg.cxx
src/HYDROGUI/HYDROGUI_ImportLandCoverMapDlg.h
src/HYDROGUI/HYDROGUI_ImportLandCoverMapOp.cxx

index e2ff679f256708204588327a8cb500f2229dfa17..5487b6ad255d8e0c459d667e235f5415a53f6e25 100644 (file)
@@ -264,6 +264,8 @@ void HYDROData_LandCoverMap::ExportDBF( const QString& theDBFFileName,
                                         const QStringList& theDBFValues,
                                         const QStringList& theStricklerTypes) const
 {
+  if (theDBFValues.size() != theStricklerTypes.size())
+    return;
   HYDROData_ShapeFile anExporter; 
   std::vector<HYDROData_ShapeFile::DBF_AttrValue> theAttrV;
   Iterator anIt( *this );
@@ -282,8 +284,8 @@ void HYDROData_LandCoverMap::ExportDBF( const QString& theDBFFileName,
     else
       aCurAttrV.myIsNull = true;
   }
-
-  anExporter.DBF_WriteFieldAndValues(theDBFFileName, theFieldName, HYDROData_ShapeFile::DBF_FieldType_String, theAttrV, true);
+  //use actual str value; not the raw value
+  anExporter.DBF_WriteFieldAndValues(theDBFFileName, theFieldName, HYDROData_ShapeFile::DBF_FieldType_String, theAttrV, false);
 
 }
 
index b8b3effd5bf74d6a2af4ed318e95c6400d448e3b..629de51bf30d10a74d5862d00f1cf350bd0a7421 100644 (file)
@@ -33,6 +33,7 @@
 #include <TopoDS_Edge.hxx>
 #include <TopoDS_Face.hxx>
 #include <BRep_Tool.hxx>
+#include <BRepTools.hxx>
 #include <Precision.hxx>
 #include <Handle_Geom_Curve.hxx>
 #include <Handle_Geom_Line.hxx>
@@ -47,6 +48,7 @@
 #include <TopTools_SequenceOfShape.hxx>
 #include <QColor>
 #include <BRepTopAdaptor_FClass2d.hxx>
+#include <TopExp.hxx>
 
 #ifdef WIN32
   #pragma warning( disable: 4996 )
@@ -235,53 +237,88 @@ int HYDROData_ShapeFile::WriteObjectPolygon(SHPHandle theShpHandle, const TopoDS
 
 void HYDROData_ShapeFile::ProcessFace(TopoDS_Face theFace, SHPHandle theShpHandle)
 {
+  if (theFace.ShapeType() != TopAbs_FACE)
+     return;
   SHPObject    *aSHPObj;
   std::vector<double> x, y;
   std::vector<int> anPartStart;
-  if (theFace.ShapeType() == TopAbs_FACE)
+  TopoDS_Wire OuterW = BRepTools::OuterWire(theFace);
+  NCollection_Sequence<TopoDS_Wire> aWires;
+
+  //write an outer wire first
+  aWires.Append(OuterW); 
+  TopExp_Explorer Ex(theFace, TopAbs_WIRE);  
+  for (; Ex.More(); Ex.Next()) 
   {
-    TopExp_Explorer Ex(theFace, TopAbs_WIRE);
-    int NbWires = 0;
-    for (; Ex.More(); Ex.Next()) 
+    TopoDS_Wire aW = TopoDS::Wire(Ex.Current());
+    if (aW.IsEqual(OuterW))
+      continue;
+    aWires.Append(aW); 
+  }
+
+  //TopExp_Explorer Ex(theFace, TopAbs_WIRE);
+  int NbWires = 0;
+  for (int k = 1; k <= aWires.Length(); k++) 
+  {
+    TopoDS_Wire aW = aWires(k);   
+    if (aW.IsNull())
+      continue;
+    NbWires++;
+    // Try to reorder edges
+    Handle(ShapeFix_Wire) aSFW = new ShapeFix_Wire( aW, theFace, Precision::Confusion() );
+    aSFW->FixReorder();
+    Handle(ShapeExtend_WireData) aSEWD = aSFW->WireData();
+    Standard_Integer nbE = aSEWD->NbEdges();
+    //
+    anPartStart.push_back(x.size());
+    NCollection_Sequence<gp_Pnt2d> aPnts;
+    for (Standard_Integer i = 1; i <= nbE; i++)
     {
-      TopoDS_Wire aW = TopoDS::Wire(Ex.Current());   
-      if (aW.IsNull())
+      TopoDS_Edge E = aSEWD->Edge(i);
+      TopoDS_Vertex aV = TopExp::LastVertex(E, 1);
+      if (aV.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));
-      }
+      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));
+    }
 
+    if (k == 1)
+    {
+      //an outer wire
+      //clockwise direction
       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()); 
+      x.push_back( aNPnts(1).X());
+      y.push_back( aNPnts(1).Y()); 
+    }
+    else
+    {
+      //holes
+      //counter-clockwise direction
+      for (int j = aNPnts.Size(); j > 0; j--)
+      { 
+        x.push_back( aNPnts(j).X());
+        y.push_back( aNPnts(j).Y()); 
+      }
+      x.push_back( aNPnts(aNPnts.Size()).X());
+      y.push_back( aNPnts(aNPnts.Size()).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;
+  
+  aSHPObj = SHPCreateObject( SHPT_POLYGON, -1, NbWires, &anPartStart[0], NULL, x.size(), &x[0], &y[0], NULL, NULL );
+  SHPWriteObject( theShpHandle, -1, aSHPObj );
+  SHPDestroyObject( aSHPObj );
+
 }
 
 bool HYDROData_ShapeFile::Parse(SHPHandle theHandle, ShapeType theType, int& theShapeTypeOfFile)
index 6c670c1d79e86aab28a8b086f366e5abb3ac827a..061a7632643e1b94780b48af8ef8073f1678931b 100644 (file)
@@ -42,6 +42,7 @@ set(PROJECT_HEADERS
     HYDROGUI_ImportSinusXOp.h
     HYDROGUI_ExportSinusXOp.h
     HYDROGUI_ExportSinusXDlg.h
+    HYDROGUI_ExportLandCoverMapDlg.h
     HYDROGUI_InputPanel.h
     HYDROGUI_LandCoverMapDlg.h
     HYDROGUI_LandCoverMapOp.h
@@ -175,12 +176,13 @@ set(PROJECT_SOURCES
     HYDROGUI_ImportBathymetryOp.cxx
     HYDROGUI_ImportImageDlg.cxx
     HYDROGUI_ImportImageOp.cxx
-       HYDROGUI_ImportLandCoverMapOp.cxx
-       HYDROGUI_ImportLandCoverMapDlg.cxx
+    HYDROGUI_ImportLandCoverMapOp.cxx
+    HYDROGUI_ImportLandCoverMapDlg.cxx
     HYDROGUI_ImportPolylineOp.cxx
     HYDROGUI_ImportSinusXOp.cxx
     HYDROGUI_ExportSinusXOp.cxx
     HYDROGUI_ExportSinusXDlg.cxx
+    HYDROGUI_ExportLandCoverMapDlg.cxx
     HYDROGUI_InputPanel.cxx
     HYDROGUI_LandCoverMapDlg.cxx
     HYDROGUI_LandCoverMapOp.cxx
index 72915e5d7d2bd5bb15c6d035fa20e8dcfa2f86e2..9baba92b180b6dd1195a3352ae807b0985c61d7c 100644 (file)
 #include "HYDROGUI_Module.h"
 #include "HYDROGUI_UpdateFlags.h"
 #include "HYDROGUI_Tool.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,74 @@ void HYDROGUI_ExportFileOp::startOperation()
       else
       {
         //Export polygons
-        //aSeq.Size() <= 1
-        Handle_HYDROData_LandCoverMap aLCM = Handle(HYDROData_LandCoverMap)::DownCast( aSeq(1) );
-        anExporter.Export(aFileName, aLCM, aNonExpList);
+        //Extract all attribute names from all strickler tables
+        Handle_HYDROData_Document aDoc = HYDROData_Document::Document( application()->activeStudy()->id() );
+        QSet<QString> AttrNames;
+        //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 It( aDoc, KIND_STRICKLER_TABLE );
+          for( ; It.More(); It.Next() )
+          {
+            Handle(HYDROData_StricklerTable) aStricklerTableObj = Handle(HYDROData_StricklerTable)::DownCast( It.Current() );
+            if ( !aStricklerTableObj.IsNull())
+              AttrNames << aStricklerTableObj->GetAttrName();
+          }
+        }
+        else
+          return; 
+
+        //
+        HYDROGUI_ExportLandCoverMapDlg aDlg( module()->getApp()->desktop(), AttrNames.toList());
+        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;
+          {
+            HYDROData_Iterator It( aDoc, KIND_STRICKLER_TABLE );
+            for( ; It.More(); It.Next() )
+            {
+              StricklerTableObj = Handle(HYDROData_StricklerTable)::DownCast( It.Current() );
+              if ( !StricklerTableObj.IsNull() && StricklerTableObj->GetAttrName() == CItem)
+                break;
+            }
+          }
+
+          //export shape-data
+          anExporter.Export(aFileName, aLCM, aNonExpList);
+          QString DBFFileName = 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)
+          {
+            //export attribute info
+            QStringList AttrValues;
+            QStringList StricklerTypes;
+            if (aNonExpList.empty())
+            {
+              HYDROData_LandCoverMap::Iterator It( aLCM );
+              for( ; It.More(); It.Next() )
+              {
+                QString ST = It.StricklerType();
+                AttrValues << StricklerTableObj->GetAttrValue(ST);
+                StricklerTypes << ST;
+              }
+            }
+            aLCM->ExportDBF(DBFFileName, CItem, AttrValues, StricklerTypes);
+          }
+        }
+        else
+        {
+          abort();
+          return;
+        }
+
       }
 
       if (!aNonExpList.empty())
diff --git a/src/HYDROGUI/HYDROGUI_ExportLandCoverMapDlg.cxx b/src/HYDROGUI/HYDROGUI_ExportLandCoverMapDlg.cxx
new file mode 100644 (file)
index 0000000..71063ef
--- /dev/null
@@ -0,0 +1,72 @@
+// Copyright (C) 2014-2015  EDF-R&D
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License as published by the Free Software Foundation; either
+// version 2.1 of the License, or (at your option) any later version.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
+//
+// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
+//
+
+#include "HYDROGUI_ExportLandCoverMapDlg.h"
+
+#include <SUIT_MessageBox.h>
+
+#include <QCheckBox>
+#include <QVBoxLayout>
+#include <QComboBox>
+
+HYDROGUI_ExportLandCoverMapDlg::HYDROGUI_ExportLandCoverMapDlg( QWidget* theParent, const QStringList& AttrItems )
+  : QtxDialog( theParent, false, true, QtxDialog::OKCancel )
+{
+  setWindowTitle( tr( "EXPORT_LANDCOVERMAP" ) );
+  setButtonPosition( Left, OK );
+  setButtonPosition( Right, Cancel );
+
+  myAttrCheckBox = new QCheckBox( tr( "Write Strickler Types as attributes values to DBF file" ), mainFrame() );
+  myAttrCheckBox->setChecked(false);
+  myAvFields = new QComboBox( mainFrame() );
+  myAvFields->setEnabled(false);
+  myAvFields->addItems( AttrItems );
+
+  QGridLayout* aLayout = new QGridLayout( mainFrame() );
+  aLayout->setMargin( 5 );
+  aLayout->setSpacing( 5 );
+  aLayout->addWidget( myAttrCheckBox, 0, 0 );
+  aLayout->addWidget( myAvFields, 1, 0, 1, 2 );
+
+  setMinimumSize( 300, 100 );
+
+  connect( myAttrCheckBox, SIGNAL(clicked(bool)), this, SLOT(onAttrCBChecked(bool)));
+
+}
+
+HYDROGUI_ExportLandCoverMapDlg::~HYDROGUI_ExportLandCoverMapDlg()
+{
+}
+
+void HYDROGUI_ExportLandCoverMapDlg::onAttrCBChecked( bool theState )
+{
+  if (theState)
+    myAvFields->setEnabled(true);
+  else
+    myAvFields->setEnabled(false);
+}
+
+QString HYDROGUI_ExportLandCoverMapDlg::getCurrentItem() const
+{
+  return myAvFields->currentText();
+}
+
+bool HYDROGUI_ExportLandCoverMapDlg::getAttrCheckBoxState()
+{
+  return myAttrCheckBox->isChecked();
+}
diff --git a/src/HYDROGUI/HYDROGUI_ExportLandCoverMapDlg.h b/src/HYDROGUI/HYDROGUI_ExportLandCoverMapDlg.h
new file mode 100644 (file)
index 0000000..a4b5bdc
--- /dev/null
@@ -0,0 +1,48 @@
+// Copyright (C) 2014-2015  EDF-R&D
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License as published by the Free Software Foundation; either
+// version 2.1 of the License, or (at your option) any later version.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
+//
+// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
+//
+
+
+#ifndef HYDROGUI_ExportLandCoverMapDlg_H
+#define HYDROGUI_ExportLandCoverMapDlg_H
+
+#include <QtxDialog.h>
+
+class QCheckBox;
+class QComboBox;
+
+class HYDROGUI_ExportLandCoverMapDlg : public QtxDialog
+{
+  Q_OBJECT
+
+public:
+  HYDROGUI_ExportLandCoverMapDlg( QWidget* = 0, const QStringList& AttrItems = QStringList());
+  virtual ~HYDROGUI_ExportLandCoverMapDlg();
+
+protected slots:
+  void             onAttrCBChecked(bool theState);
+
+public:
+  QString          getCurrentItem() const; 
+  bool             getAttrCheckBoxState();
+
+private:
+  QCheckBox*       myAttrCheckBox;
+  QComboBox*       myAvFields;
+};
+
+#endif
index 7fd79557c4c827b2032a45c13dcea70c17cc8e2d..e203263883d114959bcdbc3aed3cee9cb1cd66ef 100644 (file)
@@ -265,10 +265,11 @@ QString HYDROGUI_ImportLandCoverMapDlg::getFileName() const
 
 void HYDROGUI_ImportLandCoverMapDlg::FillCorrTable(const QStringList& theFirstColumn, 
                                                    const QStringList& theSecondColumn,
+                                                   const QVector<int> theDefCBIndices,
                                                    const QVector<QColor> theColors)
 {
-  int FCSize = theFirstColumn.size();
-  int SCSize = theSecondColumn.size();
+  int FCSize = theFirstColumn.size();  // == theDefCBIndices.size() !
+  int SCSize = theSecondColumn.size(); 
 
   myStrColors = theColors;
 
@@ -280,6 +281,7 @@ void HYDROGUI_ImportLandCoverMapDlg::FillCorrTable(const QStringList& theFirstCo
   myTableW->setHorizontalHeaderItem(0, Header_1);
   myTableW->setHorizontalHeaderItem(1, Header_2);
   myTableW->setHorizontalHeaderItem(2, Header_3);
+  myTableW->horizontalHeader()->setResizeMode(QHeaderView::ResizeMode::ResizeToContents);
   //
   for (int i = 0; i < FCSize; i++)
   {
@@ -296,15 +298,17 @@ void HYDROGUI_ImportLandCoverMapDlg::FillCorrTable(const QStringList& theFirstCo
     connect(aCB, SIGNAL(currentIndexChanged(int)), signalMap, SLOT(map()));
     signalMap->setMapping(aCB, i);
     aCB->addItems(theSecondColumn);
+    aCB->setCurrentIndex(theDefCBIndices[i]);
     myTableW->setCellWidget(i, 1, aCB);
   }
   connect(signalMap, SIGNAL(mapped(int)), this, SLOT(OnComboBoxColorChanged(int)));
+
   //
   for (int i = 0; i < FCSize; i++)
   {
     myTableW->setItem(i, 2, new QTableWidgetItem);
     //take the first color from array; this color corresponds to the first item in the combo box
-    myTableW->item(i, 2)->setBackground(myStrColors[0]);
+    myTableW->item(i, 2)->setBackground(myStrColors[theDefCBIndices[i]]);
   }
 
 }
@@ -347,7 +351,10 @@ bool HYDROGUI_ImportLandCoverMapDlg::acceptCurrent() const
     case 1:
     {
       if (myDBFAttr->selectedItems().empty())
+      {
+        SUIT_MessageBox::warning( module()->getApp()->desktop(), tr( "LCM_IMPORT_WARNING" ), "Attribute isn't selected");
         return false;
+      }
       break;
     }
     default:
index 22c3dea38c085cc5fee4178c09d3617d75487753..ac5503f92d598eb0366f264ca6d420512cb8cc5f 100644 (file)
@@ -47,6 +47,7 @@ public:
   void                  setAttributeNames( const QStringList& theAttrNames );
   void                  FillCorrTable(const QStringList& theFirstColumn, 
                                       const QStringList& theSecondColumn,
+                                      const QVector<int> theDefCBIndices,
                                       const QVector<QColor> theColors);
 
   QStringList           getSelectedPolygonNames() const;
index 45f345fbb955864a9112126134a9c82d651fea43..6274879f8cbb4d2dfb39f67d841399f43633195e 100644 (file)
 #include "HYDROGUI_Tool.h"
 #include "HYDROGUI_ImportLandCoverMapDlg.h"
 #include "HYDROGUI_Shape.h"
-#include <HYDROData_LandCoverMap.h>
 #include <HYDROGUI_ZLayers.h>
-
 #include <HYDROGUI_DataObject.h>
 #include <HYDROData_Iterator.h>
 #include <HYDROData_ShapeFile.h>
 #include <HYDROData_Profile.h>
+#include <HYDROData_LandCoverMap.h>
+#include <HYDROData_StricklerTable.h>
 
 #include <SUIT_Desktop.h>
 #include <SUIT_FileDlg.h>
-#include <LightApp_Application.h>
-
-#include <QApplication>
-#include <QFile>
-#include <QFileInfo>
 #include <SUIT_MessageBox.h>
+#include <SUIT_Desktop.h>
+#include <SUIT_ViewManager.h>
 
 #include <OCCViewer_ViewManager.h>
 #include <OCCViewer_ViewModel.h>
 
 #include <SalomeApp_Study.h>
-
 #include <LightApp_Application.h>
 #include <LightApp_DataOwner.h>
 #include <LightApp_Displayer.h>
 #include <LightApp_SelectionMgr.h>
-#include <HYDROData_StricklerTable.h>
-
-#include <SUIT_Desktop.h>
-#include <SUIT_ViewManager.h>
 
 #include <BRep_Builder.hxx>
 #include <TopoDS.hxx>
 #include <TopoDS_Shape.hxx>
 #include <TopoDS_Wire.hxx>
+
 #include <QSet>
+#include <QFile>
+#include <QFileInfo>
 
-#include <HYDROData_LandCoverMap.h>
+#include <QApplication>
+
+#define MAX_LCM_NAME_INDEX 1000
 
 //TODO add definitions into TS file
-//TODO check if LCM name is already exists..
-//rename it
 HYDROGUI_ImportLandCoverMapOp::HYDROGUI_ImportLandCoverMapOp( HYDROGUI_Module* theModule )
 : HYDROGUI_Operation( theModule )
 {
@@ -247,7 +242,7 @@ bool HYDROGUI_ImportLandCoverMapOp::processApply( int& theUpdateFlags,
   if ( !aPanel ) 
     return false;
 
-  myLCM =  Handle(HYDROData_LandCoverMap)::DownCast( doc()->CreateObject( KIND_LAND_COVER_MAP ) );
+  myLCM = Handle(HYDROData_LandCoverMap)::DownCast( doc()->CreateObject( KIND_LAND_COVER_MAP ) );
   HYDROData_MapOfFaceToStricklerType aMapFace2ST;
 
   QStringList aAttrV_T;
@@ -268,7 +263,7 @@ bool HYDROGUI_ImportLandCoverMapOp::processApply( int& theUpdateFlags,
       aST = aSTL.at(StricklerTypesInd);
     }
     // else => ST is empty
-    aMapFace2ST.Add( TopoDS::Face( aShape ), aST ); //TODO get from tableW
+    aMapFace2ST.Add( TopoDS::Face( aShape ), aST );
   }
 
   //
@@ -277,10 +272,25 @@ bool HYDROGUI_ImportLandCoverMapOp::processApply( int& theUpdateFlags,
   QString ObjName;
   if ( !aPanel->getFileName().isEmpty() )
     ObjName = aPanel->getObjectName();
+  
+  Handle_HYDROData_Document aDoc = HYDROData_Document::Document( application()->activeStudy()->id() );
+
+  //check if name of LCM is already exists
+  QSet<QString> aNameList;
+  if (aDoc)
+  {
+    HYDROData_Iterator It( aDoc, KIND_LAND_COVER_MAP );
+    for( ; It.More(); It.Next() )
+      aNameList << It.Current()->GetName();
+  }
+
+  QString NewName = ObjName;
+  for ( int i = 1; i < MAX_LCM_NAME_INDEX && aNameList.contains(NewName); i++)
+    NewName = ObjName + "_" + QString::number(i);
 
   if( !myLCM.IsNull() ) 
   {
-    myLCM->SetName( ObjName );
+    myLCM->SetName( NewName );
     myLCM->SetColor( Qt::gray );
     myLCM->Show();
     module()->setIsToUpdate( myLCM );
@@ -362,9 +372,8 @@ void HYDROGUI_ImportLandCoverMapOp::erasePreview()
 void HYDROGUI_ImportLandCoverMapOp::abortOperation()
 {
   LightApp_Application* anApp = module()->getApp();
-  if ( anApp ) {
+  if ( anApp )
     anApp->disconnect( this );
-  }
 
   erasePreview();
   myImporter.Free();
@@ -397,21 +406,20 @@ void HYDROGUI_ImportLandCoverMapOp::onNext( const int theIndex )
     //Collect all strickler_types
     QSet<QString> aSTSet;
     Handle_HYDROData_Document aDoc = HYDROData_Document::Document( application()->activeStudy()->id() );
+    Handle(HYDROData_StricklerTable) DefStricklerTableObj;
     if ( aDoc )
     {
       HYDROData_Iterator It( aDoc, KIND_STRICKLER_TABLE );
       for( ; It.More(); It.Next() )
       {
         Handle(HYDROData_StricklerTable) aStricklerTableObj = Handle(HYDROData_StricklerTable)::DownCast( It.Current() );
-        QString TT  = aStricklerTableObj->GetAttrName();
+        if (DefStricklerTableObj.IsNull())
+          DefStricklerTableObj = aStricklerTableObj;
         if ( !aStricklerTableObj.IsNull())
         {
           const QStringList& aStricklerList = aStricklerTableObj->GetTypes();
           foreach (QString aStr, aStricklerList)
-          {
-            QString AttVal = aStricklerTableObj->GetAttrValue(aStr);
             aSTSet << aStr;
-          }
         }
       }
     }
@@ -425,7 +433,28 @@ void HYDROGUI_ImportLandCoverMapOp::onNext( const int theIndex )
       STColors.append (col);
     }
 
-    aPanel->FillCorrTable(SetOfAttrValuesList, aSTSetList, STColors);
+    //add an empty Strickler type
+    aSTSetList.prepend(""); 
+    STColors.prepend(QColor(Qt::gray));
+    
+    QVector<int> aCurCBIndices(SetOfAttrValuesList.size());
+    if (DefStricklerTableObj->GetAttrName() == aPanel->getSelectedFieldName())
+    {
+      for (int i = 0; i < SetOfAttrValuesList.size(); i++)
+      {
+        QString ST = DefStricklerTableObj->GetType(SetOfAttrValuesList[i]);
+        int IndofSt = aSTSetList.indexOf(ST);
+        aCurCBIndices[i] = IndofSt;
+      }
+    }
+    else
+    {
+      //TODO add warning ???
+      for (int i = 0; i < SetOfAttrValuesList.size(); i++)
+        aCurCBIndices[i] = 0;
+    }
+
+    aPanel->FillCorrTable(SetOfAttrValuesList, aSTSetList, aCurCBIndices, STColors);    
   }
 
 }