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 //TODO add new checkbox ('FUSE INTO THE ONE')!!!
37 HYDROGUI_ImportBathymetryDlg::HYDROGUI_ImportBathymetryDlg( HYDROGUI_Module* theModule, const QString& theTitle )
38 : HYDROGUI_InputPanel( theModule, theTitle )
40 SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
42 // Import bathymetry from file
43 myFileNameGroup = new QGroupBox( tr( "IMPORT_BATHYMETRY_FROM_FILE" ) );
45 QLabel* aFileNameLabel = new QLabel( tr( "FILE_NAME" ), myFileNameGroup );
47 myFileNames = new QListWidget( myFileNameGroup );
48 myFileNames->viewport()->setAttribute( Qt::WA_TransparentForMouseEvents );
49 //myFileNames->setFocusPolicy(Qt::FocusPolicy::NoFocus); //TODO
50 //myFileNames->setReadOnly( true );
52 QPushButton* aBrowseBtn = new QPushButton( myFileNameGroup );
53 // aBrowseBtn->setIcon( aResMgr->loadPixmap( "HYDRO", tr( "BROWSE_ICO" ) ) );
54 aBrowseBtn->setText("Load files(s)");
55 aBrowseBtn->setIcon( aResMgr->loadPixmap( "HYDRO", tr( "BROWSE_ICO" ) ) );
57 QBoxLayout* aFileNameLayout = new QVBoxLayout( myFileNameGroup );
58 aFileNameLayout->setMargin( 5 );
59 aFileNameLayout->setSpacing( 5 );
60 aFileNameLayout->addWidget( aFileNameLabel );
61 aFileNameLayout->addWidget( aBrowseBtn );
62 aFileNameLayout->addWidget( myFileNames );
65 myObjectNameGroup = new QGroupBox( tr( "BATHYMETRY_NAME" ) );
67 QLabel* aBathymetryNameLabel = new QLabel( tr( "NAME" ), myObjectNameGroup );
68 myObjectName = new QLineEdit( myObjectNameGroup );
70 QBoxLayout* aBathymetryNameLayout = new QHBoxLayout( myObjectNameGroup );
71 aBathymetryNameLayout->setMargin( 5 );
72 aBathymetryNameLayout->setSpacing( 5 );
73 aBathymetryNameLayout->addWidget( aBathymetryNameLabel );
74 aBathymetryNameLayout->addWidget( myObjectName );
76 myInvertAltitudes = new QCheckBox( tr( "INVERT_BATHYMETRY_ALTITUDES" ), this );
79 addWidget( myFileNameGroup );
80 addWidget( myObjectNameGroup );
81 addWidget( myInvertAltitudes );
85 connect( aBrowseBtn, SIGNAL( clicked() ), this, SLOT( onBrowse() ) );
88 HYDROGUI_ImportBathymetryDlg::~HYDROGUI_ImportBathymetryDlg()
92 void HYDROGUI_ImportBathymetryDlg::reset()
95 myObjectName->clear();
96 myObjectNameGroup->setEnabled( false );
99 void HYDROGUI_ImportBathymetryDlg::setObjectName( const QString& theName )
101 myObjectName->setText( theName );
102 myObjectNameGroup->setEnabled( !theName.isEmpty() || !myFileNames->count() );
105 QString HYDROGUI_ImportBathymetryDlg::getObjectName() const
107 return myObjectName->text();
110 void HYDROGUI_ImportBathymetryDlg::setFileNames( const QStringList& theFileNames )
113 myFileNames->addItems( theFileNames );
115 if ( !myObjectNameGroup->isEnabled() )
116 myObjectNameGroup->setEnabled( !theFileNames.isEmpty() );
119 QStringList HYDROGUI_ImportBathymetryDlg::getFileNames() const
121 QStringList stritems;
122 for(int i = 0; i < myFileNames->count(); ++i)
124 QListWidgetItem* item = myFileNames->item(i);
125 stritems << item->text();
130 void HYDROGUI_ImportBathymetryDlg::setInvertAltitudes( const bool theIsInvert )
132 myInvertAltitudes->setChecked( theIsInvert );
135 bool HYDROGUI_ImportBathymetryDlg::isInvertAltitudes() const
137 return myInvertAltitudes->isChecked();
140 void HYDROGUI_ImportBathymetryDlg::onBrowse()
142 QString aFilter( tr( "BATHYMETRY_FILTER" ) );
143 QStringList aFileNames = SUIT_FileDlg::getOpenFileNames( this, "", aFilter, tr( "IMPORT_BATHYMETRY_FROM_FILE" ), true );
145 if( !aFileNames.isEmpty() )
147 setFileNames( aFileNames );
148 emit FileSelected( aFileNames );