Salome HOME
ImportFromFile()
[modules/hydro.git] / src / HYDROGUI / HYDROGUI_ImportBathymetryDlg.cxx
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.
6 //
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.
11 //
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
15 //
16 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
17 //
18
19 #include "HYDROGUI_ImportBathymetryDlg.h"
20
21 #include "HYDROGUI_Tool.h"
22
23 #include <SUIT_FileDlg.h>
24 #include <SUIT_ResourceMgr.h>
25 #include <SUIT_Session.h>
26
27 #include <QListWidget>
28 #include <QGroupBox>
29 #include <QLabel>
30 #include <QLayout>
31 #include <QLineEdit>
32 #include <QPicture>
33 #include <QPushButton>
34 #include <QCheckBox>
35
36 HYDROGUI_ImportBathymetryDlg::HYDROGUI_ImportBathymetryDlg( HYDROGUI_Module* theModule, const QString& theTitle )
37 : HYDROGUI_InputPanel( theModule, theTitle )
38 {
39   SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
40
41   // Import bathymetry from file
42   myFileNameGroup = new QGroupBox( tr( "IMPORT_BATHYMETRY_FROM_FILE" ) );
43
44   QLabel* aFileNameLabel = new QLabel( tr( "FILE_NAME" ), myFileNameGroup );
45
46   myFileNames = new QListWidget( myFileNameGroup );
47   //myFileNames->viewport()->setAttribute( Qt::WA_TransparentForMouseEvents );
48   //myFileNames->setFocusPolicy(Qt::FocusPolicy::NoFocus);
49
50   QPushButton* aBrowseBtn = new QPushButton( myFileNameGroup );
51   aBrowseBtn->setText("Load files(s)");
52   aBrowseBtn->setIcon( aResMgr->loadPixmap( "HYDRO", tr( "BROWSE_ICO" ) ) );
53
54   QBoxLayout* aFileNameLayout = new QVBoxLayout( myFileNameGroup );
55
56   myFuseIntoOne = new QCheckBox();
57   myFuseIntoOne->setText("Import as one bathemetry object (fuse the geometry data)");
58   myFuseIntoOne->setEnabled( false );
59
60   aFileNameLayout->setMargin( 5 );
61   aFileNameLayout->setSpacing( 5 );
62   aFileNameLayout->addWidget( aFileNameLabel );  
63   aFileNameLayout->addWidget( aBrowseBtn );
64   aFileNameLayout->addWidget( myFileNames );
65   aFileNameLayout->addWidget( myFuseIntoOne );
66
67   // Bathymetry name
68   myObjectNameGroup = new QGroupBox( tr( "BATHYMETRY_NAME" ) );
69
70   QLabel* aBathymetryNameLabel = new QLabel( tr( "NAME" ), myObjectNameGroup );
71   myObjectName = new QLineEdit( myObjectNameGroup );
72
73   QBoxLayout* aBathymetryNameLayout = new QHBoxLayout( myObjectNameGroup );
74   aBathymetryNameLayout->setMargin( 5 );
75   aBathymetryNameLayout->setSpacing( 5 );
76   aBathymetryNameLayout->addWidget( aBathymetryNameLabel );
77   aBathymetryNameLayout->addWidget( myObjectName );
78
79   myInvertAltitudes = new QCheckBox( tr( "INVERT_BATHYMETRY_ALTITUDES" ), this );
80
81   // Common
82   addWidget( myFileNameGroup );
83   addWidget( myObjectNameGroup );
84   addWidget( myInvertAltitudes );
85
86   addStretch();
87
88   connect( aBrowseBtn, SIGNAL( clicked() ), this, SLOT( onBrowse() ) );
89   connect( myFuseIntoOne, SIGNAL( stateChanged(int) ), this, SLOT( onStateChanged(int) ) );
90 }
91
92 HYDROGUI_ImportBathymetryDlg::~HYDROGUI_ImportBathymetryDlg()
93 {
94 }
95
96 void HYDROGUI_ImportBathymetryDlg::reset()
97 {
98   myFileNames->clear();
99   myObjectName->clear();
100   myObjectNameGroup->setEnabled( false );
101   myFuseIntoOne->setEnabled( false );
102 }
103
104 void HYDROGUI_ImportBathymetryDlg::setObjectName( const QString& theName )
105 {
106   myObjectName->setText( theName );
107   bool ObjNameState = myObjectName->isEnabled();
108   myObjectNameGroup->setEnabled( !theName.isEmpty() || myFileNames->count() > 0 );
109   myObjectName->setEnabled(ObjNameState);
110   myFuseIntoOne->setEnabled( myFileNames->count() > 1 );
111 }
112
113 QString HYDROGUI_ImportBathymetryDlg::getObjectName() const
114 {
115   return myObjectName->text();
116 }
117
118 void HYDROGUI_ImportBathymetryDlg::setFileNames( const QStringList& theFileNames )
119 {
120   myFileNames->clear();
121   myFileNames->addItems( theFileNames );
122
123   if (myFuseIntoOne->isChecked() || theFileNames.count() == 1 )
124   {
125     myObjectNameGroup->setEnabled( true );
126     myObjectName->setEnabled( true );
127   }
128   else
129   {
130     myObjectNameGroup->setEnabled( false );
131     myObjectName->setEnabled( false );
132   }
133   //
134   if (theFileNames.count() == 1)
135     myFuseIntoOne->setEnabled( false );
136   else if (theFileNames.count() > 1)
137     myFuseIntoOne->setEnabled( true );
138
139 }
140
141 QStringList HYDROGUI_ImportBathymetryDlg::getFileNames() const
142 {
143   QStringList stritems;
144   for(int i = 0; i < myFileNames->count(); ++i)
145   {
146     QListWidgetItem* item = myFileNames->item(i);
147     stritems << item->text();
148   }
149   return stritems;
150 }
151
152 void HYDROGUI_ImportBathymetryDlg::setInvertAltitudes( const bool theIsInvert )
153 {
154   myInvertAltitudes->setChecked( theIsInvert );
155 }
156
157 bool HYDROGUI_ImportBathymetryDlg::isInvertAltitudes() const
158 {
159   return myInvertAltitudes->isChecked();
160 }
161
162 void HYDROGUI_ImportBathymetryDlg::setFuseIntoOneOptionChecked( bool isFIO )
163 {
164   myFuseIntoOne->setChecked( isFIO );
165 }
166
167 bool HYDROGUI_ImportBathymetryDlg::isFuseIntoOneOptionChecked() const
168 {
169   return myFuseIntoOne->isChecked();
170 }
171
172 void HYDROGUI_ImportBathymetryDlg::setFuseIntoOneOptionEnabled(bool enabled)
173 {
174   myFuseIntoOne->setEnabled(enabled);
175 }
176
177 bool HYDROGUI_ImportBathymetryDlg::isFuseIntoOneOptionEnabled() const
178 {
179   return myFuseIntoOne->isEnabled();
180 }
181
182 void HYDROGUI_ImportBathymetryDlg::onBrowse()
183 {
184   QString aFilter( tr( "BATHYMETRY_FILTER" ) );
185   QStringList aFileNames = SUIT_FileDlg::getOpenFileNames( this, "", aFilter, tr( "IMPORT_BATHYMETRY_FROM_FILE" ), true );
186
187   if( !aFileNames.isEmpty() )
188   {
189     setFileNames( aFileNames );
190     emit FileSelected( aFileNames );
191   }
192 }
193
194 void HYDROGUI_ImportBathymetryDlg::onStateChanged (int state)
195 {
196   if (getFileNames().count() > 1)
197   {
198     if (state == Qt::Checked)
199     {
200       myObjectName->setEnabled(true);
201       myObjectNameGroup->setEnabled(true);
202     }
203     else if (state == Qt::Unchecked)
204     {
205       myObjectName->setEnabled(false);
206       myObjectNameGroup->setEnabled(false);
207     }
208   }
209 }
210
211