Salome HOME
Image positioning by two points.
[modules/hydro.git] / src / HYDROGUI / HYDROGUI_ImportBathymetryDlg.cxx
1 // Copyright (C) 2007-2013  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 // Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
5 //
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License.
10 //
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14 // Lesser General Public License for more details.
15 //
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
19 //
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 //
22
23 #include "HYDROGUI_ImportBathymetryDlg.h"
24
25 #include "HYDROGUI_Tool.h"
26
27 #include <SUIT_FileDlg.h>
28 #include <SUIT_ResourceMgr.h>
29 #include <SUIT_Session.h>
30
31 #include <QGroupBox>
32 #include <QLabel>
33 #include <QLayout>
34 #include <QLineEdit>
35 #include <QPicture>
36 #include <QToolButton>
37
38 HYDROGUI_ImportBathymetryDlg::HYDROGUI_ImportBathymetryDlg( HYDROGUI_Module* theModule, const QString& theTitle )
39 : HYDROGUI_InputPanel( theModule, theTitle )
40 {
41   SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
42
43   // Import bathymetry from file
44   myFileNameGroup = new QGroupBox( tr( "IMPORT_BATHYMETRY_FROM_FILE" ) );
45
46   QLabel* aFileNameLabel = new QLabel( tr( "FILE_NAME" ), myFileNameGroup );
47
48   myFileName = new QLineEdit( myFileNameGroup );
49   myFileName->setReadOnly( true );
50
51   QToolButton* aBrowseBtn = new QToolButton( myFileNameGroup );
52   aBrowseBtn->setIcon( aResMgr->loadPixmap( "HYDRO", tr( "BROWSE_ICO" ) ) );
53
54   QBoxLayout* aFileNameLayout = new QHBoxLayout( myFileNameGroup );
55   aFileNameLayout->setMargin( 5 );
56   aFileNameLayout->setSpacing( 5 );
57   aFileNameLayout->addWidget( aFileNameLabel );
58   aFileNameLayout->addWidget( myFileName );
59   aFileNameLayout->addWidget( aBrowseBtn );
60
61   // Bathymetry name
62   myObjectNameGroup = new QGroupBox( tr( "BATHYMETRY_NAME" ) );
63
64   QLabel* aBathymetryNameLabel = new QLabel( tr( "NAME" ), myObjectNameGroup );
65   myObjectName = new QLineEdit( myObjectNameGroup );
66
67   QBoxLayout* aBathymetryNameLayout = new QHBoxLayout( myObjectNameGroup );
68   aBathymetryNameLayout->setMargin( 5 );
69   aBathymetryNameLayout->setSpacing( 5 );
70   aBathymetryNameLayout->addWidget( aBathymetryNameLabel );
71   aBathymetryNameLayout->addWidget( myObjectName );
72
73   // Common
74   addWidget( myFileNameGroup );
75   addWidget( myObjectNameGroup );
76   addStretch();
77
78   connect( aBrowseBtn, SIGNAL( clicked() ), this, SLOT( onBrowse() ) );
79 }
80
81 HYDROGUI_ImportBathymetryDlg::~HYDROGUI_ImportBathymetryDlg()
82 {
83 }
84
85 void HYDROGUI_ImportBathymetryDlg::reset()
86 {
87   myFileName->clear();
88   myObjectName->clear();
89   myObjectNameGroup->setEnabled( false );
90 }
91
92 void HYDROGUI_ImportBathymetryDlg::setObjectName( const QString& theName )
93 {
94   myObjectName->setText( theName );
95   myObjectNameGroup->setEnabled( !theName.isEmpty() || !myFileName->text().isEmpty() );
96 }
97
98 QString HYDROGUI_ImportBathymetryDlg::getObjectName() const
99 {
100   return myObjectName->text();
101 }
102
103 void HYDROGUI_ImportBathymetryDlg::setFileName( const QString& theFileName )
104 {
105   myFileName->setText( theFileName );
106
107   if ( !myObjectNameGroup->isEnabled() )
108     myObjectNameGroup->setEnabled( !theFileName.isEmpty() );
109 }
110
111 QString HYDROGUI_ImportBathymetryDlg::getFileName() const
112 {
113   return myFileName->text();
114 }
115
116 void HYDROGUI_ImportBathymetryDlg::onBrowse()
117 {
118   QString aFilter( tr( "BATHYMETRY_FILTER" ) );
119   QString aFileName = SUIT_FileDlg::getFileName( this, "", aFilter, tr( "IMPORT_BATHYMETRY_FROM_FILE" ), true );
120
121   if( !aFileName.isEmpty() )
122   {
123     setFileName( aFileName );
124     emit FileSelected( aFileName );
125   }
126 }
127
128
129
130