From 8e58160b632a7b7d4507f68628f0b31c5ad56ce1 Mon Sep 17 00:00:00 2001 From: isn Date: Fri, 30 Oct 2015 21:46:40 +0300 Subject: [PATCH] LCM // Import/Export of SHP p.3 --- src/HYDROData/HYDROData_LandCoverMap.cxx | 5 - src/HYDROData/HYDROData_LandCoverMap.h | 10 +- .../HYDROGUI_ImportLandCoverMapDlg.cxx | 70 ++++++- src/HYDROGUI/HYDROGUI_ImportLandCoverMapDlg.h | 75 ++++---- .../HYDROGUI_ImportLandCoverMapOp.cxx | 171 +++++++++++------- src/HYDROGUI/HYDROGUI_ImportLandCoverMapOp.h | 3 + 6 files changed, 221 insertions(+), 113 deletions(-) diff --git a/src/HYDROData/HYDROData_LandCoverMap.cxx b/src/HYDROData/HYDROData_LandCoverMap.cxx index 00592dd7..bad3d009 100644 --- a/src/HYDROData/HYDROData_LandCoverMap.cxx +++ b/src/HYDROData/HYDROData_LandCoverMap.cxx @@ -31,7 +31,6 @@ #include #include #include -#include #include #include #include @@ -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 -{ -}; - /** Constructor @param theMap the land cover map to iterate through diff --git a/src/HYDROData/HYDROData_LandCoverMap.h b/src/HYDROData/HYDROData_LandCoverMap.h index 75c2182e..8fa16c22 100644 --- a/src/HYDROData/HYDROData_LandCoverMap.h +++ b/src/HYDROData/HYDROData_LandCoverMap.h @@ -21,16 +21,19 @@ #include #include +#include +#include +#include + +typedef NCollection_IndexedDataMap 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 ); diff --git a/src/HYDROGUI/HYDROGUI_ImportLandCoverMapDlg.cxx b/src/HYDROGUI/HYDROGUI_ImportLandCoverMapDlg.cxx index cf4de87a..40add2d8 100644 --- a/src/HYDROGUI/HYDROGUI_ImportLandCoverMapDlg.cxx +++ b/src/HYDROGUI/HYDROGUI_ImportLandCoverMapDlg.cxx @@ -28,10 +28,13 @@ #include #include #include - +#include +#include +#include #include #include #include +#include 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 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 (aW); + ST.push_back(aCB->currentText()); + } +} + + +QVector HYDROGUI_ImportLandCoverMapDlg::getSelectedPolygonIndices() const +{ + QVector aSelectedIndices; + + QModelIndexList aSelectedItems = myPolygons->selectionModel()->selectedIndexes(); + foreach( QModelIndex index, aSelectedItems ) { + aSelectedIndices << index.row(); + } + + return aSelectedIndices; +} \ No newline at end of file diff --git a/src/HYDROGUI/HYDROGUI_ImportLandCoverMapDlg.h b/src/HYDROGUI/HYDROGUI_ImportLandCoverMapDlg.h index c0ec3de8..6030b8ad 100644 --- a/src/HYDROGUI/HYDROGUI_ImportLandCoverMapDlg.h +++ b/src/HYDROGUI/HYDROGUI_ImportLandCoverMapDlg.h @@ -21,6 +21,7 @@ #define HYDROGUI_ImportLandCoverMapDlg_H #include "HYDROGUI_Wizard.h" +#include 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 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; }; diff --git a/src/HYDROGUI/HYDROGUI_ImportLandCoverMapOp.cxx b/src/HYDROGUI/HYDROGUI_ImportLandCoverMapOp.cxx index 5490f57f..e8303bac 100644 --- a/src/HYDROGUI/HYDROGUI_ImportLandCoverMapOp.cxx +++ b/src/HYDROGUI/HYDROGUI_ImportLandCoverMapOp.cxx @@ -63,7 +63,13 @@ #include #include #include -#include +#include + +#include + + +//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( 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( 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 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 theAttrV; + //std::vector 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(); + } +} + diff --git a/src/HYDROGUI/HYDROGUI_ImportLandCoverMapOp.h b/src/HYDROGUI/HYDROGUI_ImportLandCoverMapOp.h index 7276fae2..1a525fc9 100644 --- a/src/HYDROGUI/HYDROGUI_ImportLandCoverMapOp.h +++ b/src/HYDROGUI/HYDROGUI_ImportLandCoverMapOp.h @@ -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 myPolygonName2PrsShape; TopTools_SequenceOfShape myPolygonFaces; @@ -66,6 +68,7 @@ private: HYDROData_ShapeFile myImporter; QString myFileName; QStringList myFieldList; + std::vector myAttrV;; }; #endif -- 2.39.2