Salome HOME
LCM // Import/Export of SHP p.2
[modules/hydro.git] / src / HYDROGUI / HYDROGUI_ImportLandCoverMapOp.cxx
index 540a159242b6a4d657190abfc228e5d27351f75f..5490f57fd530b1866b24c009303ce17fa0064d15 100644 (file)
@@ -54,6 +54,7 @@
 #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 <TopoDS.hxx>
 #include <TopoDS_Shape.hxx>
 #include <TopoDS_Wire.hxx>
-
-
-#include <BRepTools.hxx>
-
+#include <qset.h>
 
 HYDROGUI_ImportLandCoverMapOp::HYDROGUI_ImportLandCoverMapOp( HYDROGUI_Module* theModule )
 : HYDROGUI_Operation( theModule )
 {
-  setName( tr( "IMPORT_LANDCOVER" ) );
+  setName( tr( "IMPORT_LANDCOVERMAP" ) );
 }
 
 HYDROGUI_ImportLandCoverMapOp::~HYDROGUI_ImportLandCoverMapOp()
@@ -115,14 +113,14 @@ void HYDROGUI_ImportLandCoverMapOp::onFileSelected()
     anObjectName = HYDROGUI_Tool::GenerateObjectName( module(), tr( "DEFAULT_LANDCOVERMAP_NAME" ) );
   aPanel->setObjectName( anObjectName );
 
-  QString aFileName = aPanel->getFileName();
-  if ( aFileName.isEmpty() )
+  myFileName = aPanel->getFileName();
+  if ( myFileName.isEmpty() )
   {
     abort();
     return;
   }
 
-  QString anExt = aFileName.split('.', QString::SkipEmptyParts).back();
+  QString anExt = myFileName.split('.', QString::SkipEmptyParts).back();
 
   if (anExt == "shp")
   {     
@@ -130,8 +128,8 @@ void HYDROGUI_ImportLandCoverMapOp::onFileSelected()
     QApplication::setOverrideCursor(Qt::WaitCursor);
     
     QStringList aPolygonsList;
-    TopTools_SequenceOfShape aFaces;
-    HYDROData_ShapeFile anImporter;
+    myPolygonFaces.Clear();
+    myImporter.Free();
 
     SalomeApp_Study* aStudy = dynamic_cast<SalomeApp_Study*>( module()->getApp()->activeStudy() );
     if ( !aStudy )
@@ -141,7 +139,11 @@ void HYDROGUI_ImportLandCoverMapOp::onFileSelected()
 
     Handle(AIS_InteractiveContext) aCtx = NULL;
     int aShapeTypeOfFile = -1;
-    int aStat = anImporter.ImportLandCovers(aFileName, aPolygonsList, aFaces, aShapeTypeOfFile);
+
+    //Import polygons from SHP file as faces
+    //This faces should be added to the new LCM object
+
+    int aStat = myImporter.ImportPolygons(myFileName, aPolygonsList, myPolygonFaces, aShapeTypeOfFile);
     if (aStat == 1)
     {
       aPanel->setPolygonNames(aPolygonsList);
@@ -160,9 +162,9 @@ void HYDROGUI_ImportLandCoverMapOp::onFileSelected()
         }
       }
 
-      for ( int i = 1; i <= aFaces.Length(); i++ ) 
+      for ( int i = 1; i <= myPolygonFaces.Length(); i++ ) 
       {
-        TopoDS_Face aFace = TopoDS::Face(aFaces.Value( i ));
+        TopoDS_Face aFace = TopoDS::Face(myPolygonFaces.Value( i ));
         if ( aViewManager && !aCtx.IsNull() )
         {
           HYDROGUI_Shape* aShape = new HYDROGUI_Shape( aCtx, NULL, getPreviewZLayer() );
@@ -180,7 +182,7 @@ void HYDROGUI_ImportLandCoverMapOp::onFileSelected()
         UpdateZLayersOfHilightPresentationsOfDisplayedObjects( aCtx, Graphic3d_ZLayerId_TopOSD );
         aCtx->UpdateCurrentViewer();
       }
-      
+      //
       QApplication::restoreOverrideCursor();
       commitDocOperation();
     }
@@ -196,13 +198,13 @@ void HYDROGUI_ImportLandCoverMapOp::onFileSelected()
       else if (aStat == -2)
         aMess += "Cannot open SHX file";
       else 
-        aMess += "The shape type of file is " + anImporter.GetShapeTypeName(aShapeTypeOfFile);
+        aMess += "The shape type of file is " + myImporter.GetShapeTypeName(aShapeTypeOfFile);
       SUIT_MessageBox::warning( module()->getApp()->desktop(), tr( "IMPORT_LANDCOVER" ), aMess);
       commitDocOperation();
+      myImporter.Free();
       //abort();
     }
-    anImporter.Free();
-
+    
   }
   
 }
@@ -291,6 +293,8 @@ bool HYDROGUI_ImportLandCoverMapOp::processApply( int& theUpdateFlags,
   if ( isApplyAndClose() )
     erasePreview();
 
+  myImporter.Free();
+
   return true;
 }
 
@@ -380,7 +384,58 @@ void HYDROGUI_ImportLandCoverMapOp::abortOperation()
 
 
 void HYDROGUI_ImportLandCoverMapOp::onNext( const int theIndex )
-{
+{  
+  //TODO add acceptor
+  HYDROGUI_ImportLandCoverMapDlg* aPanel = ::qobject_cast<HYDROGUI_ImportLandCoverMapDlg*>( inputPanel() );
+  if ( !aPanel )
+    return;
+
+  if (theIndex == 1)
+  {
+      //Try to load DBF-database...
+      QString theDBFFileName;
+      theDBFFileName = myFileName.simplified().replace( ".shp", ".dbf", Qt::CaseInsensitive);
+      bool DBF_Stat = myImporter.DBF_OpenDBF(theDBFFileName);
+      // TODO:
+      // add MSG BOX if stat is bad
+      myFieldList = myImporter.DBF_GetFieldList();
+      aPanel->setAttributeNames(myFieldList);
+  }
+
+  if (theIndex == 2)
+  {
+    std::vector<HYDROData_ShapeFile::DBF_AttrValue> theAttrV;
+    int Ind = myFieldList.indexOf(aPanel->getSelectedFieldName());
+    if (Ind == -1)
+      return; //TODO add acceptor here!!
+    myImporter.DBF_GetAttributeList(Ind, theAttrV ); 
+
+    mySetOfAttrValues.clear();
+    for (size_t i = 0; i < theAttrV.size(); i++)
+    {
+      HYDROData_ShapeFile::DBF_AttrValue aV = theAttrV[i];
+      mySetOfAttrValues << QString(aV.myStrVal);  //take myStrVal by now..
+    }
+
+    //Collect all strickler_types
+    QSet<QString> aSTSet;
+    Handle_HYDROData_Document aDoc = HYDROData_Document::Document( application()->activeStudy()->id() );
+    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())
+        {
+          const QStringList& aStricklerList = aStricklerTableObj->GetTypes();
+          foreach (QString aStr, aStricklerList)
+            aSTSet << aStr;
+        }
+      }
+    }
+    aPanel->FillCorrTable(mySetOfAttrValues.toList(), aSTSet.toList());
+  }
 
 }