From: isn Date: Fri, 30 Oct 2015 13:10:59 +0000 (+0300) Subject: LCM // Import/Export of SHP p.2 X-Git-Tag: v1.5~58^2~8 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=0f2cb979c8d6ea008efeb10454f30da10b0daa8a;p=modules%2Fhydro.git LCM // Import/Export of SHP p.2 --- diff --git a/src/HYDROData/HYDROData_ShapeFile.cxx b/src/HYDROData/HYDROData_ShapeFile.cxx index ef50acef..969bba9c 100644 --- a/src/HYDROData/HYDROData_ShapeFile.cxx +++ b/src/HYDROData/HYDROData_ShapeFile.cxx @@ -343,7 +343,7 @@ void HYDROData_ShapeFile::ReadSHPPolygon(SHPObject* anObj, int i, TopoDS_Face& F BRepLib::BuildCurves3d(F); } -int HYDROData_ShapeFile::ImportLandCovers(const QString theFileName, QStringList& thePolygonsList, TopTools_SequenceOfShape& theFaces, int& theShapeTypeOfFile) +int HYDROData_ShapeFile::ImportPolygons(const QString theFileName, QStringList& thePolygonsList, TopTools_SequenceOfShape& theFaces, int& theShapeTypeOfFile) { Free(); int Stat = TryOpenShapeFile(theFileName); diff --git a/src/HYDROData/HYDROData_ShapeFile.h b/src/HYDROData/HYDROData_ShapeFile.h index bd33a735..4704d91a 100644 --- a/src/HYDROData/HYDROData_ShapeFile.h +++ b/src/HYDROData/HYDROData_ShapeFile.h @@ -93,7 +93,7 @@ public: bool Parse(SHPHandle theHandle, ShapeType theType, int& theShapeTypeOfFile); //Import Landcover void ReadSHPPolygon(SHPObject* anObj, int i, TopoDS_Face& F); - HYDRODATA_EXPORT int ImportLandCovers(const QString theFileName, QStringList& thePolygonsList, TopTools_SequenceOfShape& theFaces, int& theShapeTypeOfFile); + HYDRODATA_EXPORT int ImportPolygons(const QString theFileName, QStringList& thePolygonsList, TopTools_SequenceOfShape& theFaces, int& theShapeTypeOfFile); HYDRODATA_EXPORT void Free(); //Import Polyline void ReadSHPPolyXY(Handle(HYDROData_Document) theDocument, SHPObject* anObj, QString theFileName, @@ -105,15 +105,15 @@ public: HYDRODATA_EXPORT QString GetShapeTypeName(int theType); //DBF I/O Methods - bool CheckDBFFileExisting(const QString& theSHPFilePath, QString& thePathToDBFFile); - bool DBF_OpenDBF(const QString& thePathToDBFFile); - int DBF_GetNbFields(); - QStringList DBF_GetFieldList(); - void DBF_GetFieldTypeList(std::vector& FTVect); - int DBF_GetNbRecords(); - void DBF_CloseDBF(); - void DBF_GetAttributeList(int theIndexOfField, std::vector& theAttrV); - bool DBF_WriteFieldAndValues(const QString& theFileName, const QString& theFieldName, DBF_FieldType theType, const std::vector& theAttrV, bool bUseStrValue); + HYDRODATA_EXPORT bool CheckDBFFileExisting(const QString& theSHPFilePath, QString& thePathToDBFFile); + HYDRODATA_EXPORT bool DBF_OpenDBF(const QString& thePathToDBFFile); + HYDRODATA_EXPORT int DBF_GetNbFields(); + HYDRODATA_EXPORT QStringList DBF_GetFieldList(); + HYDRODATA_EXPORT void DBF_GetFieldTypeList(std::vector& FTVect); + HYDRODATA_EXPORT int DBF_GetNbRecords(); + HYDRODATA_EXPORT void DBF_CloseDBF(); + HYDRODATA_EXPORT void DBF_GetAttributeList(int theIndexOfField, std::vector& theAttrV); + HYDRODATA_EXPORT bool DBF_WriteFieldAndValues(const QString& theFileName, const QString& theFieldName, DBF_FieldType theType, const std::vector& theAttrV, bool bUseStrValue); private: void ProcessFace(TopoDS_Face theFace, SHPHandle theShpHandle); diff --git a/src/HYDROGUI/HYDROGUI_ImportLandCoverMapDlg.cxx b/src/HYDROGUI/HYDROGUI_ImportLandCoverMapDlg.cxx index 5c7c5ccd..cf4de87a 100644 --- a/src/HYDROGUI/HYDROGUI_ImportLandCoverMapDlg.cxx +++ b/src/HYDROGUI/HYDROGUI_ImportLandCoverMapDlg.cxx @@ -117,7 +117,7 @@ QWizardPage* HYDROGUI_ImportLandCoverMapDlg::createPage2() { myDBFAttr = new QListWidget( aPage ); - myDBFAttr->setSelectionMode( QListWidget::ExtendedSelection ); + myDBFAttr->setSelectionMode( QListWidget::SingleSelection ); myDBFAttr->setEditTriggers( QListWidget::NoEditTriggers ); myDBFAttr->setViewMode( QListWidget::ListMode ); myDBFAttr->setSortingEnabled( false ); @@ -141,20 +141,6 @@ QWizardPage* HYDROGUI_ImportLandCoverMapDlg::createPage3() { myTableW = new QTableWidget(); - myTableW->setRowCount(5); - myTableW->setColumnCount(2); - - QStringList list; - list << "1" << "2" << "3"; - - for (int i = 0; i < 5; i++) - for (int j = 0; j < 2; j++) - { - QComboBox* CB = new QComboBox(); - CB->addItems(list); - myTableW->setCellWidget(i,j,CB); - } - // Layout QVBoxLayout* aPageLayout = new QVBoxLayout; aPageLayout->setMargin( 5 ); @@ -173,6 +159,7 @@ HYDROGUI_ImportLandCoverMapDlg::~HYDROGUI_ImportLandCoverMapDlg() void HYDROGUI_ImportLandCoverMapDlg::reset() { myPolygons->clear(); + myDBFAttr->clear(); } void HYDROGUI_ImportLandCoverMapDlg::setPolygonNames( const QStringList& theNames ) @@ -181,6 +168,12 @@ void HYDROGUI_ImportLandCoverMapDlg::setPolygonNames( const QStringList& theName myPolygons->addItems( theNames ); } +void HYDROGUI_ImportLandCoverMapDlg::setAttributeNames( const QStringList& theAttrNames ) +{ + myDBFAttr->clear(); + myDBFAttr->addItems( theAttrNames ); +} + void HYDROGUI_ImportLandCoverMapDlg::removePolygonNames( const QStringList& theNames ) { QList aFoundItems; @@ -224,6 +217,7 @@ QStringList HYDROGUI_ImportLandCoverMapDlg::getSelectedPolygonNames() const } + void HYDROGUI_ImportLandCoverMapDlg::onBrowse() { QString aFilter( tr( "LANDCOVERMAP_FILTER" ) ); @@ -260,3 +254,32 @@ QString HYDROGUI_ImportLandCoverMapDlg::getFileName() const return myFileName->text(); } + +void HYDROGUI_ImportLandCoverMapDlg::FillCorrTable(const QStringList& theFirstColumn, const QStringList& theSecondColumn) +{ + int FCSize = theFirstColumn.size(); + int SCSize = theSecondColumn.size(); + + myTableW->setRowCount(FCSize); + myTableW->setColumnCount(2); + + for (int i = 0; i < FCSize; i++) + { + QTableWidgetItem* aTWI = new QTableWidgetItem(); + aTWI->setText(theFirstColumn.at(i)); + aTWI->setFlags(Qt::ItemIsUserCheckable); + myTableW->setItem(i, 0, aTWI); + } + + for (int i = 0; i < FCSize; i++) + { + QComboBox* aCB = new QComboBox(); + aCB->addItems(theSecondColumn); + myTableW->setCellWidget(i, 1, aCB); + } +} + +QString HYDROGUI_ImportLandCoverMapDlg::getSelectedFieldName() const +{ + return myDBFAttr->selectedItems().first()->text(); +} diff --git a/src/HYDROGUI/HYDROGUI_ImportLandCoverMapDlg.h b/src/HYDROGUI/HYDROGUI_ImportLandCoverMapDlg.h index 864c2258..c0ec3de8 100644 --- a/src/HYDROGUI/HYDROGUI_ImportLandCoverMapDlg.h +++ b/src/HYDROGUI/HYDROGUI_ImportLandCoverMapDlg.h @@ -44,7 +44,12 @@ public: void setSelectedPolygonNames( const QStringList& theNames ); + void setAttributeNames( const QStringList& theAttrNames ); + + void FillCorrTable(const QStringList& theFirstColumn, const QStringList& theSecondColumn); + QStringList getSelectedPolygonNames() const; + QString getSelectedFieldName() const; void setObjectName( const QString& theName ); QString getObjectName() const; @@ -84,8 +89,8 @@ private: QGroupBox* myCorrNameGroup; //third page - QLabel* myCLabel; - QTableWidget* myTableW; + QLabel* myCLabel; + QTableWidget* myTableW; }; diff --git a/src/HYDROGUI/HYDROGUI_ImportLandCoverMapOp.cxx b/src/HYDROGUI/HYDROGUI_ImportLandCoverMapOp.cxx index 540a1592..5490f57f 100644 --- a/src/HYDROGUI/HYDROGUI_ImportLandCoverMapOp.cxx +++ b/src/HYDROGUI/HYDROGUI_ImportLandCoverMapOp.cxx @@ -54,6 +54,7 @@ #include #include #include +#include #include #include @@ -62,15 +63,12 @@ #include #include #include - - -#include - +#include 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( 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( 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 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 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()); + } } diff --git a/src/HYDROGUI/HYDROGUI_ImportLandCoverMapOp.h b/src/HYDROGUI/HYDROGUI_ImportLandCoverMapOp.h index 7582f667..7276fae2 100644 --- a/src/HYDROGUI/HYDROGUI_ImportLandCoverMapOp.h +++ b/src/HYDROGUI/HYDROGUI_ImportLandCoverMapOp.h @@ -26,12 +26,15 @@ #include "HYDROGUI_Operation.h" #include #include +#include + +#include +#include class SUIT_FileDlg; class HYDROGUI_Shape; class TopoDS_Face; - class HYDROGUI_ImportLandCoverMapOp : public HYDROGUI_Operation { Q_OBJECT @@ -58,6 +61,11 @@ protected slots: private: QMap myPolygonName2PrsShape; + TopTools_SequenceOfShape myPolygonFaces; + QSet mySetOfAttrValues; + HYDROData_ShapeFile myImporter; + QString myFileName; + QStringList myFieldList; }; #endif