Salome HOME
import of multi baths (draft; always fused)
[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 //TODO add new checkbox ('FUSE INTO THE ONE')!!!
37 HYDROGUI_ImportBathymetryDlg::HYDROGUI_ImportBathymetryDlg( HYDROGUI_Module* theModule, const QString& theTitle )
38 : HYDROGUI_InputPanel( theModule, theTitle )
39 {
40   SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
41
42   // Import bathymetry from file
43   myFileNameGroup = new QGroupBox( tr( "IMPORT_BATHYMETRY_FROM_FILE" ) );
44
45   QLabel* aFileNameLabel = new QLabel( tr( "FILE_NAME" ), myFileNameGroup );
46
47   myFileNames = new QListWidget( myFileNameGroup );
48   myFileNames->viewport()->setAttribute( Qt::WA_TransparentForMouseEvents );
49   //myFileNames->setFocusPolicy(Qt::FocusPolicy::NoFocus); //TODO
50   //myFileNames->setReadOnly( true );
51
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" ) ) );
56
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 );
63
64   // Bathymetry name
65   myObjectNameGroup = new QGroupBox( tr( "BATHYMETRY_NAME" ) );
66
67   QLabel* aBathymetryNameLabel = new QLabel( tr( "NAME" ), myObjectNameGroup );
68   myObjectName = new QLineEdit( myObjectNameGroup );
69
70   QBoxLayout* aBathymetryNameLayout = new QHBoxLayout( myObjectNameGroup );
71   aBathymetryNameLayout->setMargin( 5 );
72   aBathymetryNameLayout->setSpacing( 5 );
73   aBathymetryNameLayout->addWidget( aBathymetryNameLabel );
74   aBathymetryNameLayout->addWidget( myObjectName );
75
76   myInvertAltitudes = new QCheckBox( tr( "INVERT_BATHYMETRY_ALTITUDES" ), this );
77
78   // Common
79   addWidget( myFileNameGroup );
80   addWidget( myObjectNameGroup );
81   addWidget( myInvertAltitudes );
82
83   addStretch();
84
85   connect( aBrowseBtn, SIGNAL( clicked() ), this, SLOT( onBrowse() ) );
86 }
87
88 HYDROGUI_ImportBathymetryDlg::~HYDROGUI_ImportBathymetryDlg()
89 {
90 }
91
92 void HYDROGUI_ImportBathymetryDlg::reset()
93 {
94   myFileNames->clear();
95   myObjectName->clear();
96   myObjectNameGroup->setEnabled( false );
97 }
98
99 void HYDROGUI_ImportBathymetryDlg::setObjectName( const QString& theName )
100 {
101   myObjectName->setText( theName );
102   myObjectNameGroup->setEnabled( !theName.isEmpty() || !myFileNames->count() );
103 }
104
105 QString HYDROGUI_ImportBathymetryDlg::getObjectName() const
106 {
107   return myObjectName->text();
108 }
109
110 void HYDROGUI_ImportBathymetryDlg::setFileNames( const QStringList& theFileNames )
111 {
112
113   myFileNames->addItems( theFileNames );
114
115   if ( !myObjectNameGroup->isEnabled() )
116     myObjectNameGroup->setEnabled( !theFileNames.isEmpty() );
117 }
118
119 QStringList HYDROGUI_ImportBathymetryDlg::getFileNames() const
120 {
121   QStringList stritems;
122   for(int i = 0; i < myFileNames->count(); ++i)
123   {
124     QListWidgetItem* item = myFileNames->item(i);
125     stritems << item->text();
126   }
127   return stritems;
128 }
129
130 void HYDROGUI_ImportBathymetryDlg::setInvertAltitudes( const bool theIsInvert )
131 {
132   myInvertAltitudes->setChecked( theIsInvert );
133 }
134
135 bool HYDROGUI_ImportBathymetryDlg::isInvertAltitudes() const
136 {
137   return myInvertAltitudes->isChecked();
138 }
139
140 void HYDROGUI_ImportBathymetryDlg::onBrowse()
141 {
142   QString aFilter( tr( "BATHYMETRY_FILTER" ) );
143   QStringList aFileNames = SUIT_FileDlg::getOpenFileNames( this, "", aFilter, tr( "IMPORT_BATHYMETRY_FROM_FILE" ), true );
144
145   if( !aFileNames.isEmpty() )
146   {
147     setFileNames( aFileNames );
148     emit FileSelected( aFileNames );
149   }
150 }
151
152
153
154