Salome HOME
LCM // Import/Export of SHP p.3
authorisn <isn@opencascade.com>
Fri, 30 Oct 2015 18:46:40 +0000 (21:46 +0300)
committerisn <isn@opencascade.com>
Fri, 30 Oct 2015 18:46:40 +0000 (21:46 +0300)
src/HYDROData/HYDROData_LandCoverMap.cxx
src/HYDROData/HYDROData_LandCoverMap.h
src/HYDROGUI/HYDROGUI_ImportLandCoverMapDlg.cxx
src/HYDROGUI/HYDROGUI_ImportLandCoverMapDlg.h
src/HYDROGUI/HYDROGUI_ImportLandCoverMapOp.cxx
src/HYDROGUI/HYDROGUI_ImportLandCoverMapOp.h

index 00592dd777c174076c2ee9fb40c2bbe6aabeafbd..bad3d009d434f55a4b79bdbbfb1c17cd06bfd96b 100644 (file)
@@ -31,7 +31,6 @@
 #include <BRepAlgoAPI_Fuse.hxx>
 #include <BRepBuilderAPI_MakeFace.hxx>
 #include <GCPnts_QuasiUniformDeflection.hxx>
-#include <NCollection_IndexedMap.hxx>
 #include <TopoDS.hxx>
 #include <TopoDS_Compound.hxx>
 #include <TopoDS_Edge.hxx>
@@ -56,10 +55,6 @@ const int TELEMAC_PRECISION = 3;
 IMPLEMENT_STANDARD_HANDLE(HYDROData_LandCoverMap, HYDROData_Entity)
 IMPLEMENT_STANDARD_RTTIEXT(HYDROData_LandCoverMap, HYDROData_Entity)
 
-class HYDROData_MapOfFaceToStricklerType : public NCollection_IndexedDataMap<TopoDS_Face, QString>
-{
-};
-
 /**
   Constructor
   @param theMap the land cover map to iterate through
index 75c2182ebf0a6816c305873f8382c7d505de7ec7..8fa16c225fd83b5569791a719fb4c1b9e59e2fc5 100644 (file)
 
 #include <HYDROData_Entity.h>
 #include <TDataStd_ExtStringArray.hxx>
+#include <NCollection_IndexedDataMap.hxx>
+#include <QString>
+#include <TopoDS_Face.hxx>
+
+typedef NCollection_IndexedDataMap<TopoDS_Face, QString> HYDROData_MapOfFaceToStricklerType;
 
 DEFINE_STANDARD_HANDLE( HYDROData_LandCoverMap, HYDROData_Entity )
 
-class TopoDS_Face;
 class TopoDS_Shape;
 class TopoDS_Iterator;
 class TopTools_ListOfShape;
 class Handle( HYDROData_PolylineXY );
 class Handle( HYDROData_Object );
-class HYDROData_MapOfFaceToStricklerType;
 class gp_Pnt2d;
 
 class HYDROData_LandCoverMap : public HYDROData_Entity
@@ -113,13 +116,14 @@ public:
   HYDRODATA_EXPORT int GetLCCount() const;
   HYDRODATA_EXPORT bool IsEmpty() const;
 
+  HYDRODATA_EXPORT void StoreLandCovers( const HYDROData_MapOfFaceToStricklerType& );
+
 protected:
   void SetShape( const TopoDS_Shape& );
 
   bool LocalPartition( const TopoDS_Shape&, const QString& theNewType );
   static TopoDS_Shape MergeFaces(const TopTools_ListOfShape& theFaces,
                       bool IsToUnify, double theTolerance = 1E-3 );
-  void StoreLandCovers( const HYDROData_MapOfFaceToStricklerType& );
 
 public:
   DEFINE_STANDARD_RTTI( HYDROData_LandCoverMap );
index cf4de87aab6b083e6a3e47e30a7cc84af58b3417..40add2d825d6d226635243fc0383b7eda33f5c56 100644 (file)
 #include <SUIT_ResourceMgr.h>
 #include <SUIT_Session.h>
 #include <SUIT_FileDlg.h>
-
+#include <HYDROGUI_Module.h>
+#include <SUIT_MessageBox.h>
+#include <LightApp_Application.h>
 #include <QTableWidget>
 #include <QHeaderView>
 #include <QComboBox>
+#include <QStackedWidget>
 
 HYDROGUI_ImportLandCoverMapDlg::HYDROGUI_ImportLandCoverMapDlg( HYDROGUI_Module* theModule, const QString& theTitle )
 : HYDROGUI_Wizard( theModule, theTitle )
@@ -39,6 +42,7 @@ HYDROGUI_ImportLandCoverMapDlg::HYDROGUI_ImportLandCoverMapDlg( HYDROGUI_Module*
   addPage( createPage1() );
   addPage( createPage2() );
   addPage( createPage3() );
+  myFirstPageState = false;
 }
 
 QWizardPage* HYDROGUI_ImportLandCoverMapDlg::createPage1() {
@@ -174,7 +178,7 @@ void HYDROGUI_ImportLandCoverMapDlg::setAttributeNames( const QStringList& theAt
   myDBFAttr->addItems( theAttrNames );
 }
 
-void HYDROGUI_ImportLandCoverMapDlg::removePolygonNames( const QStringList& theNames )
+/*void HYDROGUI_ImportLandCoverMapDlg::removePolygonNames( const QStringList& theNames )
 {
   QList<QListWidgetItem*> aFoundItems;
 
@@ -185,7 +189,7 @@ void HYDROGUI_ImportLandCoverMapDlg::removePolygonNames( const QStringList& theN
       delete anItem;
     }
   }
-}
+}*/
 
 void HYDROGUI_ImportLandCoverMapDlg::setSelectedPolygonNames( const QStringList& theNames )
 {
@@ -283,3 +287,63 @@ QString HYDROGUI_ImportLandCoverMapDlg::getSelectedFieldName() const
 {
   return myDBFAttr->selectedItems().first()->text();
 }
+
+void HYDROGUI_ImportLandCoverMapDlg::setFirstPageState(bool bState)
+{
+  myFirstPageState = bState;
+}
+
+bool HYDROGUI_ImportLandCoverMapDlg::acceptCurrent() const
+{
+  //Check the state of curent page
+  int CurrPage = wizard()->currentIndex();
+  switch ( CurrPage )
+  {
+    case 0:
+    {
+      if (!myFirstPageState)
+        return false;
+      break;
+    }
+    case 1:
+    {
+      if (this->myDBFAttr->selectedItems().empty())
+        return false;
+      break;
+    }
+    default:
+     return false;
+  }
+  return true;
+
+}
+
+void HYDROGUI_ImportLandCoverMapDlg::GetAttribute2StricklerCorr(QStringList& AttrValues, QStringList& ST)
+{
+  int aRowCount = myTableW->rowCount();
+  for (int i = 0; i < aRowCount; i++)
+  {
+    QTableWidgetItem* aTWI = myTableW->item(i, 0);
+    AttrValues.push_back(aTWI->text());
+  }
+
+  for (int i = 0; i < aRowCount; i++)
+  {
+    QWidget* aW = myTableW->cellWidget(i, 1);
+    QComboBox* aCB = dynamic_cast<QComboBox*> (aW);
+    ST.push_back(aCB->currentText());
+  }
+}
+
+
+QVector<int> HYDROGUI_ImportLandCoverMapDlg::getSelectedPolygonIndices() const
+{
+  QVector<int> aSelectedIndices;
+
+  QModelIndexList aSelectedItems = myPolygons->selectionModel()->selectedIndexes();
+  foreach( QModelIndex index, aSelectedItems ) {
+    aSelectedIndices << index.row();
+  }
+
+  return aSelectedIndices;
+}
\ No newline at end of file
index c0ec3de86890d2be27c0cf38251e8833c2d3acbf..6030b8adf3765603bf661c743fa9f3dc11359cc1 100644 (file)
@@ -21,6 +21,7 @@
 #define HYDROGUI_ImportLandCoverMapDlg_H
 
 #include "HYDROGUI_Wizard.h"
+#include <qvector.h>
 
 class QListWidget;
 class QLineEdit;
@@ -29,6 +30,7 @@ class QComboBox;
 class QLabel;
 class QTableWidget;
 
+
 class HYDROGUI_ImportLandCoverMapDlg : public HYDROGUI_Wizard
 {
   Q_OBJECT
@@ -37,61 +39,68 @@ public:
   HYDROGUI_ImportLandCoverMapDlg( HYDROGUI_Module* theModule, const QString& theTitle );
   virtual ~HYDROGUI_ImportLandCoverMapDlg();
 
-  void reset();
+  void                  reset();
+
+  void                  setPolygonNames( const QStringList& theNames );
+  //void                  removePolygonNames( const QStringList& theNames );
 
-  void setPolygonNames( const QStringList& theNames );
-  void removePolygonNames( const QStringList& theNames );
+  void                  setSelectedPolygonNames( const QStringList& theNames );
 
-  void setSelectedPolygonNames( const QStringList& theNames );
+  void                  setAttributeNames( const QStringList& theAttrNames );
 
-  void setAttributeNames( const QStringList& theAttrNames );
+  void                  FillCorrTable(const QStringList& theFirstColumn, const QStringList& theSecondColumn);
 
-  void FillCorrTable(const QStringList& theFirstColumn, const QStringList& theSecondColumn);
+  QStringList           getSelectedPolygonNames() const;
+  QString               getSelectedFieldName() const;
 
-  QStringList getSelectedPolygonNames() const;
-  QString getSelectedFieldName() const;
+  void                  setObjectName( const QString& theName );
+  QString               getObjectName() const;
 
-  void                       setObjectName( const QString& theName );
-  QString                    getObjectName() const;
+  void                  setFileName( const QString& theFileName );
+  QString               getFileName() const;
 
-  void                       setFileName( const QString& theFileName );
-  QString                    getFileName() const;
+  void                  setFirstPageState(bool bState);
+  //void                  setThirdPageState(bool bState);
+  void                  GetAttribute2StricklerCorr(QStringList& AttrValues, QStringList& ST);
+  QVector<int>          getSelectedPolygonIndices() const;
 
 signals:
-  void                       FileSelected( const QString& theFileName );
+  void                  FileSelected( const QString& theFileName );
+  void                  selectionChanged( const QStringList& );
 
 protected slots:
-  void                       onBrowse();
-
-  
-signals:
-  void selectionChanged( const QStringList& );
+  void                  onBrowse();
+  void                  onItemSelectionChanged();
 
-public slots:
-  void onItemSelectionChanged();
+protected:
+  bool                  acceptCurrent() const;
 
 private:
 
-  QWizardPage*               createPage1();
-  QWizardPage*               createPage2();
-  QWizardPage*               createPage3();
+  QWizardPage*          createPage1();
+  QWizardPage*          createPage2();
+  QWizardPage*          createPage3();
 
-  QLineEdit*                 myFileName; 
-  QGroupBox*                 myFileNameGroup;
-  QListWidget*               myPolygons;       
+  //First page
+  QLineEdit*            myFileName; 
+  QGroupBox*            myFileNameGroup;
+  QListWidget*          myPolygons;    
 
-  QGroupBox*                 myObjectNameGroup;
-  QLineEdit*                 myObjectName;
+  QGroupBox*            myObjectNameGroup;
+  QLineEdit*            myObjectName;
 
   //second page
-  QGroupBox*                 myAttrNameGroup;
-  QListWidget*               myDBFAttr; 
-  QGroupBox*                 myCorrNameGroup;
+  QGroupBox*            myAttrNameGroup;
+  QListWidget*          myDBFAttr; 
+  QGroupBox*            myCorrNameGroup;
 
   //third page
-  QLabel*                    myCLabel;
-  QTableWidget*              myTableW;
+  QLabel*               myCLabel;
+  QTableWidget*         myTableW;
 
+  //State of pages
+  bool                  myFirstPageState;
+  //bool                  myThirdPageState;
 
 };
 
index 5490f57fd530b1866b24c009303ce17fa0064d15..e8303bac36a5df471c005c7fa7e9918e55f1ef38 100644 (file)
 #include <TopoDS.hxx>
 #include <TopoDS_Shape.hxx>
 #include <TopoDS_Wire.hxx>
-#include <qset.h>
+#include <QSet>
+
+#include <HYDROData_LandCoverMap.h>
+
+
+//TODO deny to create null-LCM (selected poltgons on the first page = 0)
+//TODO erase onBack/onFinish if not needed...
 
 HYDROGUI_ImportLandCoverMapOp::HYDROGUI_ImportLandCoverMapOp( HYDROGUI_Module* theModule )
 : HYDROGUI_Operation( theModule )
@@ -74,6 +80,8 @@ HYDROGUI_ImportLandCoverMapOp::HYDROGUI_ImportLandCoverMapOp( HYDROGUI_Module* t
 HYDROGUI_ImportLandCoverMapOp::~HYDROGUI_ImportLandCoverMapOp()
 {
   erasePreview();
+  myImporter.Free();
+  myAttrV.clear();
 }
 
 void HYDROGUI_ImportLandCoverMapOp::startOperation()
@@ -85,10 +93,6 @@ void HYDROGUI_ImportLandCoverMapOp::startOperation()
                        module()->getApp()->getViewManager( OCCViewer_Viewer::Type(), true ) ) );
   }
 
-  if ( !isApplyAndClose() ) {
-    return;
-  }
-
   HYDROGUI_ImportLandCoverMapDlg* aPanel = 
     ::qobject_cast<HYDROGUI_ImportLandCoverMapDlg*>( inputPanel() );
   if ( !aPanel ) {
@@ -184,7 +188,7 @@ void HYDROGUI_ImportLandCoverMapOp::onFileSelected()
       }
       //
       QApplication::restoreOverrideCursor();
-      commitDocOperation();
+      aPanel->setFirstPageState(true); 
     }
     else
     {
@@ -203,6 +207,7 @@ void HYDROGUI_ImportLandCoverMapOp::onFileSelected()
       commitDocOperation();
       myImporter.Free();
       //abort();
+      aPanel->setFirstPageState(false);
     }
     
   }
@@ -228,72 +233,63 @@ bool HYDROGUI_ImportLandCoverMapOp::processApply( int& theUpdateFlags,
                                                 QString& theErrorMsg,
                                                 QStringList& theBrowseObjectsEntries )
 {
-
+  //TODO rewrite this!
   HYDROGUI_ImportLandCoverMapDlg* aPanel = ::qobject_cast<HYDROGUI_ImportLandCoverMapDlg*>( inputPanel() );
   if ( !aPanel ) {
     return false;
   }
-  
-  QStringList aSelectedtPolygons = aPanel->getSelectedPolygonNames();
-  aPanel->removePolygonNames( aSelectedtPolygons );
+
+  Handle(HYDROData_LandCoverMap) aLCM =  Handle(HYDROData_LandCoverMap)::DownCast( doc()->CreateObject( KIND_LAND_COVER_MAP ) );
+   
+  HYDROData_MapOfFaceToStricklerType aMapFace2ST;
+
+  /*QStringList aSelectedPolygons = aPanel->getSelectedPolygonNames();
+  aPanel->removePolygonNames( aSelectedPolygons );
     
-  if (!aSelectedtPolygons.empty())
+  foreach ( QString aName, aSelectedPolygons )
   {
-    Handle(HYDROData_LandCoverMap) aLCM =  Handle(HYDROData_LandCoverMap)::DownCast( doc()->CreateObject( KIND_LAND_COVER_MAP ) );
-    TopoDS_Shape aResShape;
-    if (aSelectedtPolygons.size() > 1) 
-    {
-      TopoDS_Compound cmp;
-      BRep_Builder BB;
-      BB.MakeCompound(cmp);
-
-      foreach ( QString aName, aSelectedtPolygons ) {
-        TopoDS_Shape aShape = myPolygonName2PrsShape.value( aName )->getTopoShape();
-        if ( aShape.IsNull() ) 
-          continue;
-        BB.Add(cmp, aShape);
-        HYDROGUI_Shape* aShapeToDelete = myPolygonName2PrsShape.take( aName );
-        delete aShapeToDelete;
-      }
-      aResShape = cmp;
-    }
-    else
-    {         
-      TopoDS_Shape aShape = myPolygonName2PrsShape.value( aSelectedtPolygons.first() )->getTopoShape();
-      if ( !aShape.IsNull() ) 
-      {
-        HYDROGUI_Shape* aShapeToDelete = myPolygonName2PrsShape.take( aSelectedtPolygons.first() );
-        delete aShapeToDelete;
-        aResShape = aShape;
-      }
-    }
-    if( !aLCM.IsNull() ) 
-    {
-      QString aLCName = aPanel->getObjectName() + "_polygon";
-      int i = 0;
-      for( ;HYDROGUI_Tool::FindObjectByName(module(), aLCName); i++)
-        aLCName = aPanel->getObjectName() + "_polygon_" + QString::number(i);
-      aLCM->SetName( aLCName );
-      //TODO add color
-      //aLCM->SetFillingColor( aLCM->DefaultFillingColor() );
-      //aLCM->SetBorderColor( aLCM->DefaultBorderColor() );
-      
-      //aLCM->SetShape(aResShape);
-      aLCM->Show();
-            
-      //erasePreview();
-      
-      module()->setIsToUpdate( aLCM );
-      
-    }
+    TopoDS_Shape aShape = myPolygonName2PrsShape.value( aName )->getTopoShape();
+    if ( aShape.IsNull() ) 
+      continue;
+    aMapFace2ST.Add( TopoDS::Face( aShape ), "TODO temp" ); //TODO get from tableW
+    HYDROGUI_Shape* aShapeToDelete = myPolygonName2PrsShape.take( aName );
+    delete aShapeToDelete;
+  }*/
+  QStringList aAttrV_T;
+  QStringList aSTL;
+  aPanel->GetAttribute2StricklerCorr(aAttrV_T, aSTL);
+
+  QVector<int> aSelIndices = aPanel->getSelectedPolygonIndices();
+  foreach ( int Ind, aSelIndices ) //check i-base.
+  {
+    TopoDS_Shape aShape = myPolygonFaces(Ind + 1);
+    if ( aShape.IsNull() ) 
+      continue;
+    HYDROData_ShapeFile::DBF_AttrValue aV = myAttrV[Ind];
+    int StricklerTypesInd = aAttrV_T.indexOf(QString(aV.myStrVal));
+      QString aST = aSTL.at(StricklerTypesInd);
+    aMapFace2ST.Add( TopoDS::Face( aShape ), aST ); //TODO get from tableW
+    //HYDROGUI_Shape* aShapeToDelete = myPolygonName2PrsShape.take( aName );
+    //delete aShapeToDelete;
   }
-  module()->update( UF_Model | UF_VTKViewer | UF_VTK_Forced | UF_VTK_Init );
 
-  if ( isApplyAndClose() )
-    erasePreview();
+  //
+  aLCM->StoreLandCovers(aMapFace2ST);
 
+  if( !aLCM.IsNull() ) 
+  {
+    aLCM->SetName( "temp_name" );
+    aLCM->SetColor( QColor(0,100,100) );
+    aLCM->Show();
+    module()->setIsToUpdate( aLCM );
+    
+  }
+  
+  module()->update( UF_Model | UF_VTKViewer | UF_VTK_Forced | UF_VTK_Init );
+
+  erasePreview();
   myImporter.Free();
+  myAttrV.clear();
 
   return true;
 }
@@ -378,11 +374,11 @@ void HYDROGUI_ImportLandCoverMapOp::abortOperation()
   }
 
   erasePreview();
-
+  myImporter.Free();
   HYDROGUI_Operation::abortOperation();
 }
 
-
+//TODO take "Use dbf attrs as ST.." into account
 void HYDROGUI_ImportLandCoverMapOp::onNext( const int theIndex )
 {  
   //TODO add acceptor
@@ -404,16 +400,20 @@ void HYDROGUI_ImportLandCoverMapOp::onNext( const int theIndex )
 
   if (theIndex == 2)
   {
-    std::vector<HYDROData_ShapeFile::DBF_AttrValue> theAttrV;
+    //std::vector<HYDROData_ShapeFile::DBF_AttrValue> myAttrV;
     int Ind = myFieldList.indexOf(aPanel->getSelectedFieldName());
     if (Ind == -1)
-      return; //TODO add acceptor here!!
-    myImporter.DBF_GetAttributeList(Ind, theAttrV ); 
+    {
+      return;
+    }
+    //aPanel->setSecondPageState(true);
+    myAttrV.clear();
+    myImporter.DBF_GetAttributeList(Ind, myAttrV ); 
 
     mySetOfAttrValues.clear();
-    for (size_t i = 0; i < theAttrV.size(); i++)
+    for (size_t i = 0; i < myAttrV.size(); i++)
     {
-      HYDROData_ShapeFile::DBF_AttrValue aV = theAttrV[i];
+      HYDROData_ShapeFile::DBF_AttrValue aV = myAttrV[i];
       mySetOfAttrValues << QString(aV.myStrVal);  //take myStrVal by now..
     }
 
@@ -443,3 +443,36 @@ void HYDROGUI_ImportLandCoverMapOp::onBack( const int theIndex )
 {
 
 }
+
+void HYDROGUI_ImportLandCoverMapOp::onApply()
+{
+
+  QApplication::setOverrideCursor( Qt::WaitCursor );
+  int anUpdateFlags = 0;
+  QString anErrorMsg;
+  QStringList aBrowseObjectsEntries;
+
+  bool aResult = false;
+  try
+  {
+    aResult = processApply( anUpdateFlags, anErrorMsg, aBrowseObjectsEntries );
+  }
+  catch (...)
+  {
+    aResult = false;
+  }
+  
+  QApplication::restoreOverrideCursor();
+
+  if ( aResult )
+  {
+    module()->update( anUpdateFlags );
+    commit();
+    browseObjects( aBrowseObjectsEntries );
+  }
+  else
+  {
+    abort();
+  }
+}
+
index 7276fae2220f0f148802d521f0296fcd366b2a4e..1a525fc9b61cc6e5c4613b759c2e4d2da2944a37 100644 (file)
@@ -49,6 +49,7 @@ protected:
 
   virtual bool processApply( int& theUpdateFlags, QString& theErrorMsg, QStringList& theBrowseObjectsEntries );
   HYDROGUI_InputPanel* createInputPanel() const;
+  virtual void onApply();
 
   void erasePreview();
  
@@ -59,6 +60,7 @@ protected slots:
   void onNext( const int theIndex );
   void onBack( const int theIndex );
 
+
 private:
   QMap<QString, HYDROGUI_Shape*> myPolygonName2PrsShape;
   TopTools_SequenceOfShape myPolygonFaces;
@@ -66,6 +68,7 @@ private:
   HYDROData_ShapeFile myImporter;
   QString myFileName;
   QStringList myFieldList;
+  std::vector<HYDROData_ShapeFile::DBF_AttrValue> myAttrV;;
 };
 
 #endif