1 // Copyright (C) 2014-2015 EDF-R&D
2 // This library is free software; you can redistribute it and/or
3 // modify it under the terms of the GNU Lesser General Public
4 // License as published by the Free Software Foundation; either
5 // version 2.1 of the License, or (at your option) any later version.
7 // This library is distributed in the hope that it will be useful,
8 // but WITHOUT ANY WARRANTY; without even the implied warranty of
9 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
10 // Lesser General Public License for more details.
12 // You should have received a copy of the GNU Lesser General Public
13 // License along with this library; if not, write to the Free Software
14 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
19 #include "HYDROGUI_ImportBathymetryDlg.h"
21 #include "HYDROGUI_Tool.h"
23 #include <SUIT_FileDlg.h>
24 #include <SUIT_ResourceMgr.h>
25 #include <SUIT_Session.h>
27 #include <QListWidget>
33 #include <QPushButton>
36 HYDROGUI_ImportBathymetryDlg::HYDROGUI_ImportBathymetryDlg( HYDROGUI_Module* theModule, const QString& theTitle )
37 : HYDROGUI_InputPanel( theModule, theTitle ), myIsEdit ( false )
39 SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
41 // Import bathymetry from file
42 myFileNameGroup = new QGroupBox( tr( "IMPORT_BATHYMETRY_FROM_FILE" ) );
44 QLabel* aFileNameLabel = new QLabel( tr( "FILE_NAMES" ), myFileNameGroup );
46 myFileNames = new QListWidget( myFileNameGroup );
47 myFileNames->setSelectionMode( QAbstractItemView::ExtendedSelection);
48 //myFileNames->viewport()->setAttribute( Qt::WA_TransparentForMouseEvents );
49 //myFileNames->setFocusPolicy(Qt::FocusPolicy::NoFocus);
51 QPushButton* aBrowseBtn = new QPushButton( myFileNameGroup );
52 aBrowseBtn->setText("Add files(s)");
53 aBrowseBtn->setIcon( aResMgr->loadPixmap( "HYDRO", tr( "BROWSE_ICO" ) ) );
55 QPushButton* aRemoveBtn = new QPushButton( myFileNameGroup );
56 aRemoveBtn->setText("Remove selected file(s)");
58 QBoxLayout* aFileNameLayout = new QVBoxLayout( myFileNameGroup );
60 myFuseIntoOne = new QCheckBox();
61 myFuseIntoOne->setText("Import as one bathymetry object (fuse the geometry data)");
62 myFuseIntoOne->setEnabled( false );
64 aFileNameLayout->setMargin( 5 );
65 aFileNameLayout->setSpacing( 5 );
66 aFileNameLayout->addWidget( aFileNameLabel );
67 aFileNameLayout->addWidget( aBrowseBtn );
68 aFileNameLayout->addWidget( aRemoveBtn );
69 aFileNameLayout->addWidget( myFileNames );
70 aFileNameLayout->addWidget( myFuseIntoOne );
73 myObjectNameGroup = new QGroupBox( tr( "BATHYMETRY_NAME" ) );
75 QLabel* aBathymetryNameLabel = new QLabel( tr( "NAME" ), myObjectNameGroup );
76 myObjectName = new QLineEdit( myObjectNameGroup );
78 QBoxLayout* aBathymetryNameLayout = new QHBoxLayout( myObjectNameGroup );
79 aBathymetryNameLayout->setMargin( 5 );
80 aBathymetryNameLayout->setSpacing( 5 );
81 aBathymetryNameLayout->addWidget( aBathymetryNameLabel );
82 aBathymetryNameLayout->addWidget( myObjectName );
84 myInvertAltitudes = new QCheckBox( tr( "INVERT_BATHYMETRY_ALTITUDES" ), this );
87 addWidget( myFileNameGroup );
88 addWidget( myObjectNameGroup );
89 addWidget( myInvertAltitudes );
93 connect( aBrowseBtn, SIGNAL( clicked() ), this, SLOT( onBrowse() ) );
94 connect( aRemoveBtn, SIGNAL( clicked() ), this, SLOT( onRemove() ) );
95 connect( myFuseIntoOne, SIGNAL( stateChanged(int) ), this, SLOT( onStateChanged(int) ) );
98 HYDROGUI_ImportBathymetryDlg::~HYDROGUI_ImportBathymetryDlg()
102 void HYDROGUI_ImportBathymetryDlg::reset()
104 myFileNames->clear();
105 myObjectName->clear();
106 myObjectNameGroup->setEnabled( false );
107 myFuseIntoOne->setEnabled( false );
110 void HYDROGUI_ImportBathymetryDlg::SetEditMode(bool isEdit)
115 void HYDROGUI_ImportBathymetryDlg::setObjectName( const QString& theName )
117 myObjectName->setText( theName );
118 bool ObjNameState = myObjectName->isEnabled();
119 myObjectNameGroup->setEnabled( !theName.isEmpty() || myFileNames->count() > 0 );
120 myObjectName->setEnabled(ObjNameState);
121 myFuseIntoOne->setEnabled( myFileNames->count() > 1 );
124 QString HYDROGUI_ImportBathymetryDlg::getObjectName() const
126 return myObjectName->text();
129 void HYDROGUI_ImportBathymetryDlg::addFileNames( const QStringList& theFileNames )
131 //myFileNames->clear();
132 QSet<QString> exfilenames = getFileNames().toSet();
133 QStringList newFileNames;
134 foreach (QString str, theFileNames)
135 if (!exfilenames.contains(str))
136 newFileNames.append(str);
137 myFileNames->addItems( newFileNames );
138 UpdateCheckBoxStates();
141 void HYDROGUI_ImportBathymetryDlg::removeFileNames( const QList<QListWidgetItem*>& theFileNamesToRem )
143 foreach (QListWidgetItem* item, theFileNamesToRem)
144 delete myFileNames->takeItem(myFileNames->row(item));
145 UpdateCheckBoxStates();
149 void HYDROGUI_ImportBathymetryDlg::UpdateCheckBoxStates()
151 if (myFuseIntoOne->isChecked() || myFileNames->count() == 1 )
153 myObjectNameGroup->setEnabled( true );
154 myObjectName->setEnabled( true );
158 myObjectNameGroup->setEnabled( false );
159 myObjectName->setEnabled( false );
162 if (myFileNames->count() <= 1 || myIsEdit)
163 myFuseIntoOne->setEnabled( false );
165 myFuseIntoOne->setEnabled( true );
167 QString anObjectName = getObjectName().simplified();
169 QStringList aFileNames = getFileNames();
170 if ( anObjectName.isEmpty() )
172 if (!aFileNames.empty())
174 anObjectName = aFileNames[0];
175 if ( !anObjectName.isEmpty() )
176 anObjectName = QFileInfo( anObjectName ).baseName();
178 setObjectName( anObjectName );
183 QStringList HYDROGUI_ImportBathymetryDlg::getFileNames() const
185 QStringList stritems;
186 for(int i = 0; i < myFileNames->count(); ++i)
188 QListWidgetItem* item = myFileNames->item(i);
189 stritems << item->text();
194 void HYDROGUI_ImportBathymetryDlg::setInvertAltitudes( const bool theIsInvert )
196 myInvertAltitudes->setChecked( theIsInvert );
199 bool HYDROGUI_ImportBathymetryDlg::isInvertAltitudes() const
201 return myInvertAltitudes->isChecked();
204 void HYDROGUI_ImportBathymetryDlg::setFuseIntoOneOptionChecked( bool isFIO )
206 myFuseIntoOne->setChecked( isFIO );
209 bool HYDROGUI_ImportBathymetryDlg::isFuseIntoOneOptionChecked() const
211 return myFuseIntoOne->isChecked();
214 void HYDROGUI_ImportBathymetryDlg::setFuseIntoOneOptionEnabled(bool enabled)
216 myFuseIntoOne->setEnabled(enabled);
219 bool HYDROGUI_ImportBathymetryDlg::isFuseIntoOneOptionEnabled() const
221 return myFuseIntoOne->isEnabled();
224 void HYDROGUI_ImportBathymetryDlg::onBrowse()
226 QString aFilter( tr( "BATHYMETRY_FILTER" ) );
227 QStringList aFileNames = SUIT_FileDlg::getOpenFileNames( this, "", aFilter, tr( "IMPORT_BATHYMETRY_FROM_FILE" ), true );
229 if( !aFileNames.isEmpty() )
231 addFileNames( aFileNames );
232 emit FileSelected( aFileNames );
236 void HYDROGUI_ImportBathymetryDlg::onRemove()
238 QList<QListWidgetItem*> selected = myFileNames->selectedItems();
240 removeFileNames(selected);
243 void HYDROGUI_ImportBathymetryDlg::onStateChanged (int state)
245 if (getFileNames().count() > 1)
247 if (state == Qt::Checked)
249 myObjectName->setEnabled(true);
250 myObjectNameGroup->setEnabled(true);
252 else if (state == Qt::Unchecked)
254 myObjectName->setEnabled(false);
255 myObjectNameGroup->setEnabled(false);