From: isn Date: Mon, 9 Nov 2015 09:27:28 +0000 (+0300) Subject: LCM // Import/Export of SHP p.8 X-Git-Tag: v1.5~58^2~2 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=fdea7d8aa9dbccf58a9bf0d96a215498d0d2528b;p=modules%2Fhydro.git LCM // Import/Export of SHP p.8 --- diff --git a/src/HYDROGUI/HYDROGUI_ExportFileOp.cxx b/src/HYDROGUI/HYDROGUI_ExportFileOp.cxx index 9baba92b..02f6b2df 100644 --- a/src/HYDROGUI/HYDROGUI_ExportFileOp.cxx +++ b/src/HYDROGUI/HYDROGUI_ExportFileOp.cxx @@ -115,64 +115,64 @@ void HYDROGUI_ExportFileOp::startOperation() //Export polygons //Extract all attribute names from all strickler tables Handle_HYDROData_Document aDoc = HYDROData_Document::Document( application()->activeStudy()->id() ); - QSet AttrNames; + QSet anAttrNames; //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 ) + if (aDoc) { - HYDROData_Iterator It( aDoc, KIND_STRICKLER_TABLE ); - for( ; It.More(); It.Next() ) + HYDROData_Iterator anIt( aDoc, KIND_STRICKLER_TABLE ); + for( ; anIt.More(); anIt.Next() ) { - Handle(HYDROData_StricklerTable) aStricklerTableObj = Handle(HYDROData_StricklerTable)::DownCast( It.Current() ); + Handle(HYDROData_StricklerTable) aStricklerTableObj = Handle(HYDROData_StricklerTable)::DownCast( anIt.Current() ); if ( !aStricklerTableObj.IsNull()) - AttrNames << aStricklerTableObj->GetAttrName(); + anAttrNames << aStricklerTableObj->GetAttrName(); } } else return; // - HYDROGUI_ExportLandCoverMapDlg aDlg( module()->getApp()->desktop(), AttrNames.toList()); + HYDROGUI_ExportLandCoverMapDlg aDlg( module()->getApp()->desktop(), anAttrNames.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; + QString aCItem = aDlg.getCurrentItem(); + Handle(HYDROData_StricklerTable) aStricklerTableObj; { - HYDROData_Iterator It( aDoc, KIND_STRICKLER_TABLE ); - for( ; It.More(); It.Next() ) + HYDROData_Iterator anIt( aDoc, KIND_STRICKLER_TABLE ); + for( ; anIt.More(); anIt.Next() ) { - StricklerTableObj = Handle(HYDROData_StricklerTable)::DownCast( It.Current() ); - if ( !StricklerTableObj.IsNull() && StricklerTableObj->GetAttrName() == CItem) + aStricklerTableObj = Handle(HYDROData_StricklerTable)::DownCast( anIt.Current() ); + if ( !aStricklerTableObj.IsNull() && aStricklerTableObj->GetAttrName() == aCItem) break; } } //export shape-data anExporter.Export(aFileName, aLCM, aNonExpList); - QString DBFFileName = aFileName.replace( ".shp", ".dbf", Qt::CaseInsensitive); + QString aDBFFileName = 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) + remove (aDBFFileName.toStdString().c_str()); + bool bToSaveAttrInfo = aDlg.getAttrCheckBoxState(); + if (bToSaveAttrInfo) { //export attribute info - QStringList AttrValues; - QStringList StricklerTypes; + QStringList anAttrValues; + QStringList aStricklerTypes; if (aNonExpList.empty()) { - HYDROData_LandCoverMap::Iterator It( aLCM ); - for( ; It.More(); It.Next() ) + HYDROData_LandCoverMap::Iterator aLCMIt( aLCM ); + for( ; aLCMIt.More(); aLCMIt.Next() ) { - QString ST = It.StricklerType(); - AttrValues << StricklerTableObj->GetAttrValue(ST); - StricklerTypes << ST; + QString aST = aLCMIt.StricklerType(); + anAttrValues << aStricklerTableObj->GetAttrValue(aST); + aStricklerTypes << aST; } } - aLCM->ExportDBF(DBFFileName, CItem, AttrValues, StricklerTypes); + aLCM->ExportDBF(aDBFFileName, aCItem, anAttrValues, aStricklerTypes); } } else diff --git a/src/HYDROGUI/HYDROGUI_ExportLandCoverMapDlg.cxx b/src/HYDROGUI/HYDROGUI_ExportLandCoverMapDlg.cxx index 71063efc..9da8db36 100644 --- a/src/HYDROGUI/HYDROGUI_ExportLandCoverMapDlg.cxx +++ b/src/HYDROGUI/HYDROGUI_ExportLandCoverMapDlg.cxx @@ -24,18 +24,18 @@ #include #include -HYDROGUI_ExportLandCoverMapDlg::HYDROGUI_ExportLandCoverMapDlg( QWidget* theParent, const QStringList& AttrItems ) +HYDROGUI_ExportLandCoverMapDlg::HYDROGUI_ExportLandCoverMapDlg( QWidget* theParent, const QStringList& theAttrItems ) : 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 = new QCheckBox( tr( "WRITE_ST_AS_ATTRS_TO_DBF" ), mainFrame() ); myAttrCheckBox->setChecked(false); myAvFields = new QComboBox( mainFrame() ); myAvFields->setEnabled(false); - myAvFields->addItems( AttrItems ); + myAvFields->addItems( theAttrItems ); QGridLayout* aLayout = new QGridLayout( mainFrame() ); aLayout->setMargin( 5 ); diff --git a/src/HYDROGUI/HYDROGUI_ExportLandCoverMapDlg.h b/src/HYDROGUI/HYDROGUI_ExportLandCoverMapDlg.h index a4b5bdcb..eda646f5 100644 --- a/src/HYDROGUI/HYDROGUI_ExportLandCoverMapDlg.h +++ b/src/HYDROGUI/HYDROGUI_ExportLandCoverMapDlg.h @@ -30,7 +30,7 @@ class HYDROGUI_ExportLandCoverMapDlg : public QtxDialog Q_OBJECT public: - HYDROGUI_ExportLandCoverMapDlg( QWidget* = 0, const QStringList& AttrItems = QStringList()); + HYDROGUI_ExportLandCoverMapDlg( QWidget* theParent = 0, const QStringList& theAttrItems = QStringList()); virtual ~HYDROGUI_ExportLandCoverMapDlg(); protected slots: diff --git a/src/HYDROGUI/HYDROGUI_ImportLandCoverMapDlg.cxx b/src/HYDROGUI/HYDROGUI_ImportLandCoverMapDlg.cxx index e2032638..bebfe82e 100644 --- a/src/HYDROGUI/HYDROGUI_ImportLandCoverMapDlg.cxx +++ b/src/HYDROGUI/HYDROGUI_ImportLandCoverMapDlg.cxx @@ -84,18 +84,18 @@ QWizardPage* HYDROGUI_ImportLandCoverMapDlg::createPage1() { aLandcoverNameLayout->addWidget( myObjectName ); QGroupBox* aPolygonsGroup = new QGroupBox( tr( "FOUNDED_POLYGONS" ) ); - myPolygons = new QListWidget( aPolygonsGroup ); - myPolygons->setSelectionMode( QListWidget::ExtendedSelection ); - myPolygons->setEditTriggers( QListWidget::NoEditTriggers ); - myPolygons->setViewMode( QListWidget::ListMode ); - myPolygons->setSortingEnabled( false ); + myPolygonsListWidget = new QListWidget( aPolygonsGroup ); + myPolygonsListWidget->setSelectionMode( QListWidget::ExtendedSelection ); + myPolygonsListWidget->setEditTriggers( QListWidget::NoEditTriggers ); + myPolygonsListWidget->setViewMode( QListWidget::ListMode ); + myPolygonsListWidget->setSortingEnabled( false ); QBoxLayout* aPolygonsLayout = new QVBoxLayout; - aPolygonsLayout->addWidget( myPolygons ); + aPolygonsLayout->addWidget( myPolygonsListWidget ); aPolygonsGroup->setLayout( aPolygonsLayout ); QVBoxLayout* aPageLayout = new QVBoxLayout; - myAttrCheckBox = new QCheckBox( "Use dBase attributes as a Strickler Types" ); //TODO replace with tr() + myAttrCheckBox = new QCheckBox( tr("USE_DBF_AS_ST") ); //TODO replace with tr() myAttrCheckBox->setChecked(true); // Layout @@ -108,7 +108,7 @@ QWizardPage* HYDROGUI_ImportLandCoverMapDlg::createPage1() { aPage->setLayout( aPageLayout ); // Conections - connect( myPolygons, SIGNAL( itemSelectionChanged() ), this, SLOT( onItemSelectionChanged() ) ); + connect( myPolygonsListWidget, SIGNAL( itemSelectionChanged() ), this, SLOT( onItemSelectionChanged() ) ); connect( aBrowseBtn, SIGNAL( clicked() ), this, SLOT( onBrowse() ) ); connect( myAttrCheckBox, SIGNAL(clicked(bool)), this, SLOT(onAttrCBChecked(bool))); @@ -120,20 +120,20 @@ QWizardPage* HYDROGUI_ImportLandCoverMapDlg::createPage2() { QFrame* aFrame = new QFrame( aPage ); myAvAttrLabel = new QLabel(); - myAvAttrLabel->setText("Available attributes"); + myAvAttrLabel->setText(tr("AV_ATTRS")); - myDBFAttr = new QListWidget( ); - myDBFAttr->setSelectionMode( QListWidget::SingleSelection ); - myDBFAttr->setEditTriggers( QListWidget::NoEditTriggers ); - myDBFAttr->setViewMode( QListWidget::ListMode ); - myDBFAttr->setSortingEnabled( false ); + myDBFAttrListWidget = new QListWidget( ); + myDBFAttrListWidget->setSelectionMode( QListWidget::SingleSelection ); + myDBFAttrListWidget->setEditTriggers( QListWidget::NoEditTriggers ); + myDBFAttrListWidget->setViewMode( QListWidget::ListMode ); + myDBFAttrListWidget->setSortingEnabled( false ); // Layout QVBoxLayout* aPageLayout = new QVBoxLayout; aPageLayout->setMargin( 5 ); aPageLayout->setSpacing( 5 ); aPageLayout->addWidget( myAvAttrLabel ); - aPageLayout->addWidget( myDBFAttr ); + aPageLayout->addWidget( myDBFAttrListWidget ); aPage->setLayout( aPageLayout ); return aPage; @@ -143,17 +143,17 @@ QWizardPage* HYDROGUI_ImportLandCoverMapDlg::createPage3() { QWizardPage* aPage = new QWizardPage( mainFrame() ); QFrame* aFrame = new QFrame( aPage ); - myCLabel = new QLabel(); - myCLabel->setText("Correspondence"); + myCorrLabel = new QLabel(); + myCorrLabel->setText(tr ("CORR")); - myTableW = new QTableWidget(); + myCorrTableWidget = new QTableWidget(); // Layout QVBoxLayout* aPageLayout = new QVBoxLayout; aPageLayout->setMargin( 5 ); aPageLayout->setSpacing( 5 ); - aPageLayout->addWidget( myCLabel ); - aPageLayout->addWidget( myTableW ); + aPageLayout->addWidget( myCorrLabel ); + aPageLayout->addWidget( myCorrTableWidget ); aPage->setLayout( aPageLayout ); return aPage; } @@ -161,47 +161,34 @@ QWizardPage* HYDROGUI_ImportLandCoverMapDlg::createPage3() { HYDROGUI_ImportLandCoverMapDlg::~HYDROGUI_ImportLandCoverMapDlg() { - myPolygons->clear(); - myDBFAttr->clear(); + myPolygonsListWidget->clear(); + myDBFAttrListWidget->clear(); } void HYDROGUI_ImportLandCoverMapDlg::reset() { - myPolygons->clear(); - myDBFAttr->clear(); + myPolygonsListWidget->clear(); + myDBFAttrListWidget->clear(); } void HYDROGUI_ImportLandCoverMapDlg::setPolygonNames( const QStringList& theNames ) { - myPolygons->clear(); - myPolygons->addItems( theNames ); + myPolygonsListWidget->clear(); + myPolygonsListWidget->addItems( theNames ); } void HYDROGUI_ImportLandCoverMapDlg::setAttributeNames( const QStringList& theAttrNames ) { - myDBFAttr->clear(); - myDBFAttr->addItems( theAttrNames ); + myDBFAttrListWidget->clear(); + myDBFAttrListWidget->addItems( theAttrNames ); } -/*void HYDROGUI_ImportLandCoverMapDlg::removePolygonNames( const QStringList& theNames ) -{ - QList aFoundItems; - - foreach ( const QString& aName, theNames ) { - aFoundItems = myPolygons->findItems( aName, Qt::MatchExactly ); - foreach ( QListWidgetItem* anItem, aFoundItems ) { - anItem = myPolygons->takeItem( myPolygons->row( anItem ) ); - delete anItem; - } - } -}*/ - void HYDROGUI_ImportLandCoverMapDlg::setSelectedPolygonNames( const QStringList& theNames ) { - myPolygons->clearSelection(); + myPolygonsListWidget->clearSelection(); foreach( const QString aName, theNames ) { - QList anItems = myPolygons->findItems( aName, Qt::MatchExactly ); + QList anItems = myPolygonsListWidget->findItems( aName, Qt::MatchExactly ); if ( anItems.count() == 1 ) { anItems.first()->setSelected( true ); } @@ -217,15 +204,13 @@ QStringList HYDROGUI_ImportLandCoverMapDlg::getSelectedPolygonNames() const { QStringList aSelectedNames; - QList aSelectedItems = myPolygons->selectedItems(); + QList aSelectedItems = myPolygonsListWidget->selectedItems(); foreach( const QListWidgetItem* anItem, aSelectedItems ) aSelectedNames << anItem->text(); return aSelectedNames; } - - void HYDROGUI_ImportLandCoverMapDlg::onBrowse() { QString aFilter( tr( "LANDCOVERMAP_FILTER" ) ); @@ -263,94 +248,94 @@ QString HYDROGUI_ImportLandCoverMapDlg::getFileName() const } -void HYDROGUI_ImportLandCoverMapDlg::FillCorrTable(const QStringList& theFirstColumn, +void HYDROGUI_ImportLandCoverMapDlg::FillCorrespondenceTable(const QStringList& theFirstColumn, const QStringList& theSecondColumn, const QVector theDefCBIndices, const QVector theColors) { - int FCSize = theFirstColumn.size(); // == theDefCBIndices.size() ! - int SCSize = theSecondColumn.size(); + int aFCSize = theFirstColumn.size(); // == theDefCBIndices.size() ! + int aSCSize = theSecondColumn.size(); myStrColors = theColors; - myTableW->setRowCount(FCSize); - myTableW->setColumnCount(3); - QTableWidgetItem* Header_1 = new QTableWidgetItem(QString("Attribute"), QTableWidgetItem::Type); - QTableWidgetItem* Header_2 = new QTableWidgetItem(QString("Strickler Type"), QTableWidgetItem::Type); - QTableWidgetItem* Header_3 = new QTableWidgetItem(QString("Color"), QTableWidgetItem::Type); - myTableW->setHorizontalHeaderItem(0, Header_1); - myTableW->setHorizontalHeaderItem(1, Header_2); - myTableW->setHorizontalHeaderItem(2, Header_3); - myTableW->horizontalHeader()->setResizeMode(QHeaderView::ResizeMode::ResizeToContents); + myCorrTableWidget->setRowCount(aFCSize); + myCorrTableWidget->setColumnCount(3); + QTableWidgetItem* aHeader_1 = new QTableWidgetItem(QString(tr("TABLE_H1")), QTableWidgetItem::Type); + QTableWidgetItem* aHeader_2 = new QTableWidgetItem(QString(tr("TABLE_H2")), QTableWidgetItem::Type); + QTableWidgetItem* aHeader_3 = new QTableWidgetItem(QString(tr("TABLE_H3")), QTableWidgetItem::Type); + myCorrTableWidget->setHorizontalHeaderItem(0, aHeader_1); + myCorrTableWidget->setHorizontalHeaderItem(1, aHeader_2); + myCorrTableWidget->setHorizontalHeaderItem(2, aHeader_3); + myCorrTableWidget->horizontalHeader()->setResizeMode(QHeaderView::ResizeMode::ResizeToContents); // - for (int i = 0; i < FCSize; i++) + for (int i = 0; i < aFCSize; i++) { QTableWidgetItem* aTWI = new QTableWidgetItem(); aTWI->setText(theFirstColumn.at(i)); aTWI->setFlags(Qt::ItemIsUserCheckable); - myTableW->setItem(i, 0, aTWI); + myCorrTableWidget->setItem(i, 0, aTWI); } // QSignalMapper* signalMap = new QSignalMapper(); - for (int i = 0; i < FCSize; i++) + for (int i = 0; i < aFCSize; i++) { QComboBox* aCB = new QComboBox(); connect(aCB, SIGNAL(currentIndexChanged(int)), signalMap, SLOT(map())); signalMap->setMapping(aCB, i); aCB->addItems(theSecondColumn); aCB->setCurrentIndex(theDefCBIndices[i]); - myTableW->setCellWidget(i, 1, aCB); + myCorrTableWidget->setCellWidget(i, 1, aCB); } - connect(signalMap, SIGNAL(mapped(int)), this, SLOT(OnComboBoxColorChanged(int))); + connect(signalMap, SIGNAL(mapped(int)), this, SLOT(onComboBoxColorChanged(int))); // - for (int i = 0; i < FCSize; i++) + for (int i = 0; i < aFCSize; i++) { - myTableW->setItem(i, 2, new QTableWidgetItem); + myCorrTableWidget->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[theDefCBIndices[i]]); + myCorrTableWidget->item(i, 2)->setBackground(myStrColors[theDefCBIndices[i]]); } } QString HYDROGUI_ImportLandCoverMapDlg::getSelectedFieldName() const { - return myDBFAttr->selectedItems().first()->text(); + return myDBFAttrListWidget->selectedItems().first()->text(); } -void HYDROGUI_ImportLandCoverMapDlg::setFirstPageState(bool bState) +void HYDROGUI_ImportLandCoverMapDlg::setFirstPageState(bool theState) { - myFirstPageState = bState; + myFirstPageState = theState; } bool HYDROGUI_ImportLandCoverMapDlg::acceptCurrent() const { //Check the state of the current page - int CurrPage = wizard()->currentIndex(); - switch ( CurrPage ) + int aCurrPage = wizard()->currentIndex(); + switch ( aCurrPage ) { case 0: { if (!myFirstPageState) { - SUIT_MessageBox::warning( module()->getApp()->desktop(), tr( "LCM_IMPORT_WARNING" ), "File isn't chosen"); + SUIT_MessageBox::warning( module()->getApp()->desktop(), tr( "LCM_IMPORT_WARNING" ), tr("FILE_ISNT_CHOSEN")); return false; } - if (myPolygons->selectedItems().empty()) + if (myPolygonsListWidget->selectedItems().empty()) { - SUIT_MessageBox::warning( module()->getApp()->desktop(), tr( "LCM_IMPORT_WARNING" ), "Polygons isn't selected"); + SUIT_MessageBox::warning( module()->getApp()->desktop(), tr( "LCM_IMPORT_WARNING" ), tr("POLYGONS_ISNT_SELECTED")); return false; } if (getAttrCheckBoxState() && !getDbfState()) { - SUIT_MessageBox::critical( module()->getApp()->desktop(), tr( "DBF_LOAD_ERROR" ), "Cant open DBF file or it's corrupted"); + SUIT_MessageBox::critical( module()->getApp()->desktop(), tr( "DBF_LOAD_ERROR" ), tr("DBF_LOAD_ERR_MESS")); return false; } break; } case 1: { - if (myDBFAttr->selectedItems().empty()) + if (myDBFAttrListWidget->selectedItems().empty()) { SUIT_MessageBox::warning( module()->getApp()->desktop(), tr( "LCM_IMPORT_WARNING" ), "Attribute isn't selected"); return false; @@ -363,20 +348,20 @@ bool HYDROGUI_ImportLandCoverMapDlg::acceptCurrent() const return true; } -void HYDROGUI_ImportLandCoverMapDlg::GetAttribute2StricklerCorr(QStringList& AttrValues, QStringList& ST) +void HYDROGUI_ImportLandCoverMapDlg::getValAttr2StricklerTypeCorr(QStringList& theAttrValues, QStringList& theST) { - int aRowCount = myTableW->rowCount(); + int aRowCount = myCorrTableWidget->rowCount(); for (int i = 0; i < aRowCount; i++) { - QTableWidgetItem* aTWI = myTableW->item(i, 0); - AttrValues.push_back(aTWI->text()); + QTableWidgetItem* aTWI = myCorrTableWidget->item(i, 0); + theAttrValues.push_back(aTWI->text()); } for (int i = 0; i < aRowCount; i++) { - QWidget* aW = myTableW->cellWidget(i, 1); + QWidget* aW = myCorrTableWidget->cellWidget(i, 1); QComboBox* aCB = dynamic_cast (aW); - ST.push_back(aCB->currentText()); + theST.push_back(aCB->currentText()); } } @@ -385,7 +370,7 @@ QVector HYDROGUI_ImportLandCoverMapDlg::getSelectedPolygonIndices() const { QVector aSelectedIndices; - QModelIndexList aSelectedItems = myPolygons->selectionModel()->selectedIndexes(); + QModelIndexList aSelectedItems = myPolygonsListWidget->selectionModel()->selectedIndexes(); foreach( QModelIndex index, aSelectedItems ) { aSelectedIndices << index.row(); } @@ -406,16 +391,16 @@ bool HYDROGUI_ImportLandCoverMapDlg::getAttrCheckBoxState() const return myAttrCheckBox->isChecked(); } -void HYDROGUI_ImportLandCoverMapDlg::OnComboBoxColorChanged(int theInd) +void HYDROGUI_ImportLandCoverMapDlg::onComboBoxColorChanged(int theInd) { - QComboBox* CB = qobject_cast (myTableW->cellWidget(theInd, 1)); - int CurIndOfCB = CB->currentIndex(); - myTableW->item(theInd, 2)->setBackground(myStrColors[CurIndOfCB]); + QComboBox* CB = qobject_cast (myCorrTableWidget->cellWidget(theInd, 1)); + int aCurIndOfCB = CB->currentIndex(); + myCorrTableWidget->item(theInd, 2)->setBackground(myStrColors[aCurIndOfCB]); } -void HYDROGUI_ImportLandCoverMapDlg::setDbfState(bool _state) +void HYDROGUI_ImportLandCoverMapDlg::setDbfState(bool theState) { - myDbfState = _state; + myDbfState = theState; } bool HYDROGUI_ImportLandCoverMapDlg::getDbfState() const diff --git a/src/HYDROGUI/HYDROGUI_ImportLandCoverMapDlg.h b/src/HYDROGUI/HYDROGUI_ImportLandCoverMapDlg.h index ac5503f9..e7992563 100644 --- a/src/HYDROGUI/HYDROGUI_ImportLandCoverMapDlg.h +++ b/src/HYDROGUI/HYDROGUI_ImportLandCoverMapDlg.h @@ -45,10 +45,6 @@ public: void setPolygonNames( const QStringList& theNames ); void setSelectedPolygonNames( const QStringList& theNames ); void setAttributeNames( const QStringList& theAttrNames ); - void FillCorrTable(const QStringList& theFirstColumn, - const QStringList& theSecondColumn, - const QVector theDefCBIndices, - const QVector theColors); QStringList getSelectedPolygonNames() const; QString getSelectedFieldName() const; @@ -59,14 +55,18 @@ public: void setFileName( const QString& theFileName ); QString getFileName() const; - void setFirstPageState(bool bState); + void setFirstPageState(bool theState); bool getAttrCheckBoxState() const; - void GetAttribute2StricklerCorr(QStringList& AttrValues, QStringList& ST); + void getValAttr2StricklerTypeCorr(QStringList& theAttrValues, QStringList& theST); QVector getSelectedPolygonIndices() const; - void setDbfState(bool _state); + void setDbfState(bool theState); bool getDbfState() const; + void FillCorrespondenceTable(const QStringList& theFirstColumn, + const QStringList& theSecondColumn, + const QVector theDefCBIndices, + const QVector theColors); signals: void FileSelected( const QString& theFileName ); void selectionChanged( const QStringList& ); @@ -75,7 +75,7 @@ protected slots: void onBrowse(); void onItemSelectionChanged(); void onAttrCBChecked(bool theState); - void OnComboBoxColorChanged(int theInd); + void onComboBoxColorChanged(int theInd); protected: bool acceptCurrent() const; @@ -89,18 +89,18 @@ private: //First page QLineEdit* myFileName; QGroupBox* myFileNameGroup; - QListWidget* myPolygons; + QListWidget* myPolygonsListWidget; QGroupBox* myObjectNameGroup; QLineEdit* myObjectName; QCheckBox* myAttrCheckBox; //Second page - QListWidget* myDBFAttr; + QListWidget* myDBFAttrListWidget; QLabel* myAvAttrLabel; //Third page - QLabel* myCLabel; - QTableWidget* myTableW; + QLabel* myCorrLabel; + QTableWidget* myCorrTableWidget; //State of the first page bool myFirstPageState; diff --git a/src/HYDROGUI/HYDROGUI_ImportLandCoverMapOp.cxx b/src/HYDROGUI/HYDROGUI_ImportLandCoverMapOp.cxx index 6274879f..993ac81d 100644 --- a/src/HYDROGUI/HYDROGUI_ImportLandCoverMapOp.cxx +++ b/src/HYDROGUI/HYDROGUI_ImportLandCoverMapOp.cxx @@ -64,7 +64,6 @@ #define MAX_LCM_NAME_INDEX 1000 -//TODO add definitions into TS file HYDROGUI_ImportLandCoverMapOp::HYDROGUI_ImportLandCoverMapOp( HYDROGUI_Module* theModule ) : HYDROGUI_Operation( theModule ) { @@ -75,23 +74,19 @@ HYDROGUI_ImportLandCoverMapOp::~HYDROGUI_ImportLandCoverMapOp() { erasePreview(); myImporter.Free(); - myAttrV.clear(); + myAttrValue.clear(); } void HYDROGUI_ImportLandCoverMapOp::startOperation() { HYDROGUI_Operation::startOperation(); - if ( !getPreviewManager() ) { - setPreviewManager( ::qobject_cast( - module()->getApp()->getViewManager( OCCViewer_Viewer::Type(), true ) ) ); - } + if ( !getPreviewManager() ) + setPreviewManager( ::qobject_cast( module()->getApp()->getViewManager( OCCViewer_Viewer::Type(), true ) ) ); - HYDROGUI_ImportLandCoverMapDlg* aPanel = - ::qobject_cast( inputPanel() ); - if ( !aPanel ) { + HYDROGUI_ImportLandCoverMapDlg* aPanel = ::qobject_cast( inputPanel() ); + if ( !aPanel ) return; - } aPanel->reset(); } @@ -166,13 +161,13 @@ void HYDROGUI_ImportLandCoverMapOp::onFileSelected() if ( aViewManager && !aCtx.IsNull() ) { HYDROGUI_Shape* aShape = new HYDROGUI_Shape( aCtx, NULL, getPreviewZLayer() ); - //Green color for now.. - aShape->setFillingColor(QColor(0,255,0), false, false); - aShape->setBorderColor(QColor(0,255,0), false, false); + //Preview color is grey + aShape->setFillingColor(QColor(50,50,50), false, false); + aShape->setBorderColor(QColor(50,50,50), false, false); if( !aFace.IsNull() ) aShape->setShape( aFace); - myPolygonName2PrsShape.insert( "polygon_" + QString::number(i), aShape); + myPolygonName2PrsShape.insert( tr( "DEF_POLYGON_NAME" ) + "_" + QString::number(i), aShape); } } @@ -186,9 +181,9 @@ void HYDROGUI_ImportLandCoverMapOp::onFileSelected() aPanel->setFirstPageState(true); // //Try to load DBF-database... - QString theDBFFileName; - theDBFFileName = myFileName.simplified().replace( ".shp", ".dbf", Qt::CaseInsensitive); - bool DBF_Stat = myImporter.DBF_OpenDBF(theDBFFileName); + QString aDBFFileName; + aDBFFileName = myFileName.simplified().replace( ".shp", ".dbf", Qt::CaseInsensitive); + bool DBF_Stat = myImporter.DBF_OpenDBF(aDBFFileName); // TODO: // add MSG BOX if stat is bad if (DBF_Stat) @@ -204,22 +199,20 @@ void HYDROGUI_ImportLandCoverMapOp::onFileSelected() aPanel->setPolygonNames(QStringList()); aPanel->setObjectName(""); QApplication::restoreOverrideCursor(); - QString aMess = "Cannot import land cover;\n"; + QString aMess = tr( "CANNT_IMPORT_LCM" ) + "\n"; if (aStat == -1) - aMess += "Cannot open SHP file"; + aMess += tr( "CANNT_OPEN_SHP" ); else if (aStat == -2) - aMess += "Cannot open SHX file"; + aMess += tr( "CANNT_OPEN_SHX" ); else - aMess += "The shape type of file is " + myImporter.GetShapeTypeName(aShapeTypeOfFile); + aMess += tr ("SHP_TYPEFORMAT_MESS") + myImporter.GetShapeTypeName(aShapeTypeOfFile); SUIT_MessageBox::warning( module()->getApp()->desktop(), tr( "IMPORT_LANDCOVER" ), aMess); commitDocOperation(); myImporter.Free(); //abort(); aPanel->setFirstPageState(false); } - } - } HYDROGUI_InputPanel* HYDROGUI_ImportLandCoverMapOp::createInputPanel() const @@ -247,10 +240,10 @@ bool HYDROGUI_ImportLandCoverMapOp::processApply( int& theUpdateFlags, QStringList aAttrV_T; QStringList aSTL; - aPanel->GetAttribute2StricklerCorr(aAttrV_T, aSTL); + aPanel->getValAttr2StricklerTypeCorr(aAttrV_T, aSTL); QVector aSelIndices = aPanel->getSelectedPolygonIndices(); - foreach ( int Ind, aSelIndices ) //check i-base. + foreach ( int Ind, aSelIndices ) { TopoDS_Shape aShape = myPolygonFaces(Ind + 1); if ( aShape.IsNull() ) @@ -258,9 +251,9 @@ bool HYDROGUI_ImportLandCoverMapOp::processApply( int& theUpdateFlags, QString aST = ""; if (aPanel->getAttrCheckBoxState()) { - HYDROData_ShapeFile::DBF_AttrValue aV = myAttrV[Ind]; - int StricklerTypesInd = aAttrV_T.indexOf(QString(aV.myStrVal)); - aST = aSTL.at(StricklerTypesInd); + HYDROData_ShapeFile::DBF_AttrValue aDataVal = myAttrValue[Ind]; + int aStricklerTypesInd = aAttrV_T.indexOf(QString(aDataVal.myStrVal)); + aST = aSTL.at(aStricklerTypesInd); } // else => ST is empty aMapFace2ST.Add( TopoDS::Face( aShape ), aST ); @@ -269,9 +262,9 @@ bool HYDROGUI_ImportLandCoverMapOp::processApply( int& theUpdateFlags, // myLCM->StoreLandCovers(aMapFace2ST); - QString ObjName; + QString anObjName; if ( !aPanel->getFileName().isEmpty() ) - ObjName = aPanel->getObjectName(); + anObjName = aPanel->getObjectName(); Handle_HYDROData_Document aDoc = HYDROData_Document::Document( application()->activeStudy()->id() ); @@ -284,13 +277,13 @@ bool HYDROGUI_ImportLandCoverMapOp::processApply( int& theUpdateFlags, 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); + QString aNewName = anObjName; + for ( int i = 1; i < MAX_LCM_NAME_INDEX && aNameList.contains(aNewName); i++) + aNewName = anObjName + "_" + QString::number(i); if( !myLCM.IsNull() ) { - myLCM->SetName( NewName ); + myLCM->SetName( aNewName ); myLCM->SetColor( Qt::gray ); myLCM->Show(); module()->setIsToUpdate( myLCM ); @@ -300,7 +293,7 @@ bool HYDROGUI_ImportLandCoverMapOp::processApply( int& theUpdateFlags, erasePreview(); myImporter.Free(); - myAttrV.clear(); + myAttrValue.clear(); return true; } @@ -334,9 +327,8 @@ void HYDROGUI_ImportLandCoverMapOp::onSelectionChanged( const QStringList& theSe void HYDROGUI_ImportLandCoverMapOp::onViewerSelectionChanged() { HYDROGUI_ImportLandCoverMapDlg* aPanel = ::qobject_cast( inputPanel() ); - if ( !aPanel ) { + if ( !aPanel ) return; - } OCCViewer_ViewManager* aViewManager = getPreviewManager(); Handle(AIS_InteractiveContext) aCtx = NULL; @@ -361,9 +353,8 @@ void HYDROGUI_ImportLandCoverMapOp::onViewerSelectionChanged() void HYDROGUI_ImportLandCoverMapOp::erasePreview() { - foreach ( HYDROGUI_Shape* aShape, myPolygonName2PrsShape ) { + foreach ( HYDROGUI_Shape* aShape, myPolygonName2PrsShape ) delete aShape; - } myPolygonName2PrsShape.clear(); } @@ -388,19 +379,19 @@ void HYDROGUI_ImportLandCoverMapOp::onNext( const int theIndex ) if (theIndex == 2) { - //std::vector myAttrV; - int Ind = myFieldList.indexOf(aPanel->getSelectedFieldName()); - if (Ind == -1) + //std::vector myAttrValue; + int anIndOfSelField = myFieldList.indexOf(aPanel->getSelectedFieldName()); + if (anIndOfSelField == -1) return; //aPanel->setSecondPageState(true); - myAttrV.clear(); - myImporter.DBF_GetAttributeList(Ind, myAttrV ); + myAttrValue.clear(); + myImporter.DBF_GetAttributeList(anIndOfSelField, myAttrValue ); mySetOfAttrValues.clear(); - for (size_t i = 0; i < myAttrV.size(); i++) + for (size_t i = 0; i < myAttrValue.size(); i++) { - HYDROData_ShapeFile::DBF_AttrValue aV = myAttrV[i]; - mySetOfAttrValues << QString(aV.myStrVal); //take myStrVal by now.. + HYDROData_ShapeFile::DBF_AttrValue aV = myAttrValue[i]; + mySetOfAttrValues << QString(aV.myStrVal); //take myStrVal for now.. } //Collect all strickler_types @@ -423,38 +414,35 @@ void HYDROGUI_ImportLandCoverMapOp::onNext( const int theIndex ) } } } - QList SetOfAttrValuesList = mySetOfAttrValues.toList(); + + QList aSetOfAttrValuesList = mySetOfAttrValues.toList(); QList aSTSetList = aSTSet.toList(); - QVector STColors; - STColors.reserve(aSTSetList.size()); + QVector aSTColors; + aSTColors.reserve(aSTSetList.size()); foreach (QString str, aSTSetList) { QColor col = aDoc->GetAssociatedColor(str, NULL); - STColors.append (col); + aSTColors.append (col); } //add an empty Strickler type aSTSetList.prepend(""); - STColors.prepend(QColor(Qt::gray)); + aSTColors.prepend(QColor(Qt::gray)); - QVector aCurCBIndices(SetOfAttrValuesList.size()); + QVector aCurCBIndices(aSetOfAttrValuesList.size()); if (DefStricklerTableObj->GetAttrName() == aPanel->getSelectedFieldName()) - { - for (int i = 0; i < SetOfAttrValuesList.size(); i++) + for (int i = 0; i < aSetOfAttrValuesList.size(); i++) { - QString ST = DefStricklerTableObj->GetType(SetOfAttrValuesList[i]); - int IndofSt = aSTSetList.indexOf(ST); - aCurCBIndices[i] = IndofSt; + QString aST = DefStricklerTableObj->GetType(aSetOfAttrValuesList[i]); + int anIndOfSt = aSTSetList.indexOf(aST); + aCurCBIndices[i] = anIndOfSt; } - } else - { //TODO add warning ??? - for (int i = 0; i < SetOfAttrValuesList.size(); i++) + for (int i = 0; i < aSetOfAttrValuesList.size(); i++) aCurCBIndices[i] = 0; - } - aPanel->FillCorrTable(SetOfAttrValuesList, aSTSetList, aCurCBIndices, STColors); + aPanel->FillCorrespondenceTable(aSetOfAttrValuesList, aSTSetList, aCurCBIndices, aSTColors); } } @@ -474,7 +462,7 @@ void HYDROGUI_ImportLandCoverMapOp::onApply() } catch (...) { - SUIT_MessageBox::critical( module()->getApp()->desktop(), tr( "LCM_IMPORT_ERROR" ), "Cant import choosed polygons"); + SUIT_MessageBox::critical( module()->getApp()->desktop(), tr( "LCM_IMPORT_ERROR" ), tr ("CANNT_IMPORT_POLYGONS_FROM_SHP")); aResult = false; } diff --git a/src/HYDROGUI/HYDROGUI_ImportLandCoverMapOp.h b/src/HYDROGUI/HYDROGUI_ImportLandCoverMapOp.h index b8cfad97..1c84c04f 100644 --- a/src/HYDROGUI/HYDROGUI_ImportLandCoverMapOp.h +++ b/src/HYDROGUI/HYDROGUI_ImportLandCoverMapOp.h @@ -34,7 +34,6 @@ class SUIT_FileDlg; class HYDROGUI_Shape; class TopoDS_Face; -//class HYDROData_LandCoverMap; #include class HYDROGUI_ImportLandCoverMapOp : public HYDROGUI_Operation @@ -64,11 +63,11 @@ protected slots: private: QMap myPolygonName2PrsShape; TopTools_SequenceOfShape myPolygonFaces; - QSet mySetOfAttrValues; HYDROData_ShapeFile myImporter; QString myFileName; QStringList myFieldList; - std::vector myAttrV; + std::vector myAttrValue; + QSet mySetOfAttrValues; Handle(HYDROData_LandCoverMap) myLCM; }; diff --git a/src/HYDROGUI/resources/HYDROGUI_msg_en.ts b/src/HYDROGUI/resources/HYDROGUI_msg_en.ts index 4ce8f6d6..3605689b 100644 --- a/src/HYDROGUI/resources/HYDROGUI_msg_en.ts +++ b/src/HYDROGUI/resources/HYDROGUI_msg_en.ts @@ -2322,13 +2322,52 @@ file cannot be correctly imported for an Obstacle definition. Founded polygons: - BAD_IMPORTED_LANDCOVERMAP_FILES - Land cover map import error + USE_DBF_AS_ST + Use dBase attributes as a Strickler Types - NO_ONE_LANDCOVERMAP_IMPORTED - Land cover map cannot be read from seleted file + AV_ATTRS + Available attributes + + CORR + Correspondence + + + + TABLE_H1 + Attribute + + + TABLE_H2 + Strickler Type + + + TABLE_H3 + Color + + + + LCM_IMPORT_WARNING + Import of Land cover map + + + DBF_LOAD_ERROR + Cannot load DBF file + + + FILE_ISNT_CHOSEN + File isn't chosen + + + POLYGONS_ISNT_SELECTED + Polygons isn't selected + + + DBF_LOAD_ERR_MESS + Cant open DBF file or it's corrupted + + @@ -2341,7 +2380,45 @@ file cannot be correctly imported for an Obstacle definition. DEFAULT_LANDCOVER_MAP_NAME Landcovermap_0 + + DEF_POLYGON_NAME + polygon + + + + CANNT_IMPORT_LCM + Cannot import land cover map; + + + CANNT_OPEN_SHP + Cannot open SHP file + + + CANNT_OPEN_SHX + Cannot open SHX file + + + SHP_TYPEFORMAT_MESS + The shape type of file is + + + CANNT_IMPORT_POLYGONS_FROM_SHP + Cant import choosed polygons + + + + + HYDROGUI_ExportLandCoverMapDlg + + EXPORT_LANDCOVERMAP + Export land cover map to SHP file + + + WRITE_ST_AS_ATTRS_TO_DBF + Write Strickler Types as attributes values to DBF file + + HYDROGUI_ImportSinusXOp