From c0c3555b372f1035f30af53cb06c49aaec374e08 Mon Sep 17 00:00:00 2001 From: isn Date: Wed, 19 Oct 2016 17:37:04 +0300 Subject: [PATCH] #1004-1008. + as well as some other improvements. --- src/HYDROGUI/HYDROGUI_ImportBathymetryDlg.cxx | 71 ++++++++++++++++--- src/HYDROGUI/HYDROGUI_ImportBathymetryDlg.h | 14 +++- src/HYDROGUI/HYDROGUI_ImportBathymetryOp.cxx | 46 +++--------- src/HYDROGUI/resources/HYDROGUI_msg_en.ts | 8 +-- 4 files changed, 87 insertions(+), 52 deletions(-) diff --git a/src/HYDROGUI/HYDROGUI_ImportBathymetryDlg.cxx b/src/HYDROGUI/HYDROGUI_ImportBathymetryDlg.cxx index 68cdbead..ee73bd2e 100644 --- a/src/HYDROGUI/HYDROGUI_ImportBathymetryDlg.cxx +++ b/src/HYDROGUI/HYDROGUI_ImportBathymetryDlg.cxx @@ -34,33 +34,38 @@ #include HYDROGUI_ImportBathymetryDlg::HYDROGUI_ImportBathymetryDlg( HYDROGUI_Module* theModule, const QString& theTitle ) -: HYDROGUI_InputPanel( theModule, theTitle ) +: HYDROGUI_InputPanel( theModule, theTitle ), myIsEdit ( false ) { SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr(); // Import bathymetry from file myFileNameGroup = new QGroupBox( tr( "IMPORT_BATHYMETRY_FROM_FILE" ) ); - QLabel* aFileNameLabel = new QLabel( tr( "FILE_NAME" ), myFileNameGroup ); + QLabel* aFileNameLabel = new QLabel( tr( "FILE_NAMES" ), myFileNameGroup ); myFileNames = new QListWidget( myFileNameGroup ); + myFileNames->setSelectionMode( QAbstractItemView::ExtendedSelection); //myFileNames->viewport()->setAttribute( Qt::WA_TransparentForMouseEvents ); //myFileNames->setFocusPolicy(Qt::FocusPolicy::NoFocus); QPushButton* aBrowseBtn = new QPushButton( myFileNameGroup ); - aBrowseBtn->setText("Load files(s)"); + aBrowseBtn->setText("Add files(s)"); aBrowseBtn->setIcon( aResMgr->loadPixmap( "HYDRO", tr( "BROWSE_ICO" ) ) ); + QPushButton* aRemoveBtn = new QPushButton( myFileNameGroup ); + aRemoveBtn->setText("Remove selected file(s)"); + QBoxLayout* aFileNameLayout = new QVBoxLayout( myFileNameGroup ); myFuseIntoOne = new QCheckBox(); - myFuseIntoOne->setText("Import as one bathemetry object (fuse the geometry data)"); + myFuseIntoOne->setText("Import as one bathymetry object (fuse the geometry data)"); myFuseIntoOne->setEnabled( false ); aFileNameLayout->setMargin( 5 ); aFileNameLayout->setSpacing( 5 ); aFileNameLayout->addWidget( aFileNameLabel ); aFileNameLayout->addWidget( aBrowseBtn ); + aFileNameLayout->addWidget( aRemoveBtn ); aFileNameLayout->addWidget( myFileNames ); aFileNameLayout->addWidget( myFuseIntoOne ); @@ -86,6 +91,7 @@ HYDROGUI_ImportBathymetryDlg::HYDROGUI_ImportBathymetryDlg( HYDROGUI_Module* the addStretch(); connect( aBrowseBtn, SIGNAL( clicked() ), this, SLOT( onBrowse() ) ); + connect( aRemoveBtn, SIGNAL( clicked() ), this, SLOT( onRemove() ) ); connect( myFuseIntoOne, SIGNAL( stateChanged(int) ), this, SLOT( onStateChanged(int) ) ); } @@ -101,6 +107,11 @@ void HYDROGUI_ImportBathymetryDlg::reset() myFuseIntoOne->setEnabled( false ); } +void HYDROGUI_ImportBathymetryDlg::SetEditMode(bool isEdit) +{ + myIsEdit = isEdit; +} + void HYDROGUI_ImportBathymetryDlg::setObjectName( const QString& theName ) { myObjectName->setText( theName ); @@ -115,12 +126,29 @@ QString HYDROGUI_ImportBathymetryDlg::getObjectName() const return myObjectName->text(); } -void HYDROGUI_ImportBathymetryDlg::setFileNames( const QStringList& theFileNames ) +void HYDROGUI_ImportBathymetryDlg::addFileNames( const QStringList& theFileNames ) { - myFileNames->clear(); - myFileNames->addItems( theFileNames ); + //myFileNames->clear(); + QSet exfilenames = getFileNames().toSet(); + QStringList newFileNames; + foreach (QString str, theFileNames) + if (!exfilenames.contains(str)) + newFileNames.append(str); + myFileNames->addItems( newFileNames ); + UpdateCheckBoxStates(); +} - if (myFuseIntoOne->isChecked() || theFileNames.count() == 1 ) +void HYDROGUI_ImportBathymetryDlg::removeFileNames( const QList& theFileNamesToRem ) +{ + foreach (QListWidgetItem* item, theFileNamesToRem) + delete myFileNames->takeItem(myFileNames->row(item)); + UpdateCheckBoxStates(); +} + + +void HYDROGUI_ImportBathymetryDlg::UpdateCheckBoxStates() +{ + if (myFuseIntoOne->isChecked() || myFileNames->count() == 1 ) { myObjectNameGroup->setEnabled( true ); myObjectName->setEnabled( true ); @@ -131,11 +159,25 @@ void HYDROGUI_ImportBathymetryDlg::setFileNames( const QStringList& theFileNames myObjectName->setEnabled( false ); } // - if (theFileNames.count() == 1) + if (myFileNames->count() <= 1 || myIsEdit) myFuseIntoOne->setEnabled( false ); - else if (theFileNames.count() > 1) + else myFuseIntoOne->setEnabled( true ); + QString anObjectName = getObjectName().simplified(); + + QStringList aFileNames = getFileNames(); + if ( anObjectName.isEmpty() ) + { + if (!aFileNames.empty()) + { + anObjectName = aFileNames[0]; + if ( !anObjectName.isEmpty() ) + anObjectName = QFileInfo( anObjectName ).baseName(); + } + setObjectName( anObjectName ); + } + } QStringList HYDROGUI_ImportBathymetryDlg::getFileNames() const @@ -186,11 +228,18 @@ void HYDROGUI_ImportBathymetryDlg::onBrowse() if( !aFileNames.isEmpty() ) { - setFileNames( aFileNames ); + addFileNames( aFileNames ); emit FileSelected( aFileNames ); } } +void HYDROGUI_ImportBathymetryDlg::onRemove() +{ + QList selected = myFileNames->selectedItems(); + + removeFileNames(selected); +} + void HYDROGUI_ImportBathymetryDlg::onStateChanged (int state) { if (getFileNames().count() > 1) diff --git a/src/HYDROGUI/HYDROGUI_ImportBathymetryDlg.h b/src/HYDROGUI/HYDROGUI_ImportBathymetryDlg.h index 438bddb4..d8443438 100644 --- a/src/HYDROGUI/HYDROGUI_ImportBathymetryDlg.h +++ b/src/HYDROGUI/HYDROGUI_ImportBathymetryDlg.h @@ -22,12 +22,14 @@ #include "HYDROGUI_InputPanel.h" #include +#include class QGroupBox; class QLineEdit; class QCheckBox; class QListWidget; class QStringList; +class QListWidgetItem; class HYDROGUI_ImportBathymetryDlg : public HYDROGUI_InputPanel { @@ -42,8 +44,11 @@ public: void setObjectName( const QString& theName ); QString getObjectName() const; - void setFileNames( const QStringList& theFileName ); + //void setFileNames( const QStringList& theFileName ); QStringList getFileNames() const; + void addFileNames( const QStringList& theFileNames ); + void removeFileNames( const QList& theFileNamesToRem ); + void UpdateCheckBoxStates(); void setInvertAltitudes( const bool theIsInvert ); bool isInvertAltitudes() const; @@ -52,13 +57,16 @@ public: bool isFuseIntoOneOptionChecked() const; void setFuseIntoOneOptionEnabled(bool enabled); bool isFuseIntoOneOptionEnabled() const; - + + void SetEditMode(bool isEdit); + signals: void FileSelected( const QStringList& theFileName ); protected slots: void onBrowse(); + void onRemove(); void onStateChanged (int state); private: @@ -71,6 +79,8 @@ private: QGroupBox* myObjectNameGroup; QLineEdit* myObjectName; + + bool myIsEdit; }; #endif diff --git a/src/HYDROGUI/HYDROGUI_ImportBathymetryOp.cxx b/src/HYDROGUI/HYDROGUI_ImportBathymetryOp.cxx index 02ea51ac..71fd99e0 100644 --- a/src/HYDROGUI/HYDROGUI_ImportBathymetryOp.cxx +++ b/src/HYDROGUI/HYDROGUI_ImportBathymetryOp.cxx @@ -61,6 +61,7 @@ void HYDROGUI_ImportBathymetryOp::startOperation() return; aPanel->reset(); + aPanel->SetEditMode(myIsEdit); if( myIsEdit ) { @@ -75,7 +76,7 @@ void HYDROGUI_ImportBathymetryOp::startOperation() aPanel->setFuseIntoOneOptionChecked( true ); aPanel->setObjectName( aName ); - aPanel->setFileNames( aFileNames ); + aPanel->addFileNames( aFileNames ); aPanel->setInvertAltitudes( anIsAltitudesInverted ); aPanel->setFuseIntoOneOptionEnabled( false ); } @@ -147,7 +148,7 @@ bool HYDROGUI_ImportBathymetryOp::processApply( int& theUpdateFlags, if (!inexistWarn.isNull()) SUIT_MessageBox::warning( module()->getApp()->desktop(), - tr( "BATHEMETRY_IMPORT_WARNING" ), "Can't read the next files:" + inexistWarn ); + tr( "BATHYMETRY_IMPORT_WARNING" ), "Can't read the next files:" + inexistWarn ); aFileNames = DummyFileList; @@ -163,11 +164,11 @@ bool HYDROGUI_ImportBathymetryOp::processApply( int& theUpdateFlags, if (myEditedObject.IsNull()) return false; QStringList anOldFileNames = myEditedObject->GetFilePaths(); - bool anIsInvertAltitudes = aPanel->isInvertAltitudes(); - myEditedObject->SetAltitudesInverted( anIsInvertAltitudes, false ); + //bool anIsInvertAltitudes = aPanel->isInvertAltitudes(); + //myEditedObject->SetAltitudesInverted( anIsInvertAltitudes, false ); if ( aFileNames.toSet() != anOldFileNames.toSet() ) { - myEditedObject->SetAltitudesInverted( anIsInvertAltitudes, false ); + myEditedObject->SetAltitudesInverted( anIsInvertAltitudes, true ); if ( !myEditedObject->ImportFromFiles( aFileNames ) ) { theErrorMsg = tr( "BAD_IMPORTED_BATHYMETRY_FILE" ).arg( aFileNames.join("\n") ); @@ -175,16 +176,9 @@ bool HYDROGUI_ImportBathymetryOp::processApply( int& theUpdateFlags, } } else if ( anIsInvertAltitudes != myEditedObject->IsAltitudesInverted() ) - myEditedObject->SetAltitudesInverted( anIsInvertAltitudes ); + myEditedObject->SetAltitudesInverted( anIsInvertAltitudes, true ); - QString aNewObjName; - if (CheckNameExistingBathy(anObjectName, aNewObjName)) - { - myEditedObject->SetName( aNewObjName ); - replacemWarn += "\n'" + anObjectName + "' => '" + aNewObjName + "'"; - } - else - myEditedObject->SetName( anObjectName ); + myEditedObject->SetName( anObjectName ); myEditedObject->Update(); } else @@ -256,12 +250,12 @@ bool HYDROGUI_ImportBathymetryOp::processApply( int& theUpdateFlags, if (!UnreadFilesWarn.isNull()) SUIT_MessageBox::warning( module()->getApp()->desktop(), - tr( "BATHEMETRY_IMPORT_WARNING" ), "The next files cannot be imported:" + UnreadFilesWarn ); + tr( "BATHYMETRY_IMPORT_WARNING" ), "The next files cannot be imported:" + UnreadFilesWarn ); if (!replacemWarn.isNull()) SUIT_MessageBox::warning( module()->getApp()->desktop(), - tr( "BATHEMETRY_IMPORT_WARNING" ), "The next objects names are already exist in the document; so the new objects was renamed:" + replacemWarn ); + tr( "BATHYMETRY_IMPORT_WARNING" ), "The next objects names are already exist in the document; so the new objects was renamed:" + replacemWarn ); // Activate VTK viewer and show the bathymetry SUIT_ViewManager* aVTKMgr = 0; @@ -292,25 +286,7 @@ void HYDROGUI_ImportBathymetryOp::onFileSelected() if ( !aPanel ) return; - QStringList aFileNames = aPanel->getFileNames(); - if ( !aPanel->isFuseIntoOneOptionEnabled() ) - aPanel->setFuseIntoOneOptionEnabled( !myIsEdit && aFileNames.count() > 1 ); - - QString anObjectName = aPanel->getObjectName().simplified(); - if ( anObjectName.isEmpty() ) - { - if (aFileNames.count() == 1) - { - anObjectName = aFileNames[0]; - if ( !anObjectName.isEmpty() ) - anObjectName = QFileInfo( anObjectName ).baseName(); - } - - if ( anObjectName.isEmpty() ) { - anObjectName = HYDROGUI_Tool::GenerateObjectName( module(), tr( "DEFAULT_BATHYMETRY_NAME" ) ); - } - aPanel->setObjectName( anObjectName ); - } + aPanel->UpdateCheckBoxStates(); } bool HYDROGUI_ImportBathymetryOp::CheckNameExistingBathy(const QString& InpName, QString& OutputName) diff --git a/src/HYDROGUI/resources/HYDROGUI_msg_en.ts b/src/HYDROGUI/resources/HYDROGUI_msg_en.ts index 49500afd..94f9b019 100644 --- a/src/HYDROGUI/resources/HYDROGUI_msg_en.ts +++ b/src/HYDROGUI/resources/HYDROGUI_msg_en.ts @@ -145,8 +145,8 @@ does not exist or you have not enough permissions to open it. Files list is empty - BATHEMETRY_IMPORT_WARNING - Imort of bahemetry - warning + BATHYMETRY_IMPORT_WARNING + Import of bahemetry - warning @@ -592,8 +592,8 @@ Do you want to continue? Bathymetry name - FILE_NAME - File name + FILE_NAMES + File names IMPORT_BATHYMETRY_FROM_FILE -- 2.39.2