Salome HOME
refs #567: add "POLYLINES" partition and modified icon for Land Cover object.
[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 <QGroupBox>
28 #include <QLabel>
29 #include <QLayout>
30 #include <QLineEdit>
31 #include <QPicture>
32 #include <QToolButton>
33 #include <QCheckBox>
34
35 HYDROGUI_ImportBathymetryDlg::HYDROGUI_ImportBathymetryDlg( HYDROGUI_Module* theModule, const QString& theTitle )
36 : HYDROGUI_InputPanel( theModule, theTitle )
37 {
38   SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
39
40   // Import bathymetry from file
41   myFileNameGroup = new QGroupBox( tr( "IMPORT_BATHYMETRY_FROM_FILE" ) );
42
43   QLabel* aFileNameLabel = new QLabel( tr( "FILE_NAME" ), myFileNameGroup );
44
45   myFileName = new QLineEdit( myFileNameGroup );
46   myFileName->setReadOnly( true );
47
48   QToolButton* aBrowseBtn = new QToolButton( myFileNameGroup );
49   aBrowseBtn->setIcon( aResMgr->loadPixmap( "HYDRO", tr( "BROWSE_ICO" ) ) );
50
51   QBoxLayout* aFileNameLayout = new QHBoxLayout( myFileNameGroup );
52   aFileNameLayout->setMargin( 5 );
53   aFileNameLayout->setSpacing( 5 );
54   aFileNameLayout->addWidget( aFileNameLabel );
55   aFileNameLayout->addWidget( myFileName );
56   aFileNameLayout->addWidget( aBrowseBtn );
57
58   // Bathymetry name
59   myObjectNameGroup = new QGroupBox( tr( "BATHYMETRY_NAME" ) );
60
61   QLabel* aBathymetryNameLabel = new QLabel( tr( "NAME" ), myObjectNameGroup );
62   myObjectName = new QLineEdit( myObjectNameGroup );
63
64   QBoxLayout* aBathymetryNameLayout = new QHBoxLayout( myObjectNameGroup );
65   aBathymetryNameLayout->setMargin( 5 );
66   aBathymetryNameLayout->setSpacing( 5 );
67   aBathymetryNameLayout->addWidget( aBathymetryNameLabel );
68   aBathymetryNameLayout->addWidget( myObjectName );
69
70   myInvertAltitudes = new QCheckBox( tr( "INVERT_BATHYMETRY_ALTITUDES" ), this );
71
72   // Common
73   addWidget( myFileNameGroup );
74   addWidget( myObjectNameGroup );
75   addWidget( myInvertAltitudes );
76
77   addStretch();
78
79   connect( aBrowseBtn, SIGNAL( clicked() ), this, SLOT( onBrowse() ) );
80 }
81
82 HYDROGUI_ImportBathymetryDlg::~HYDROGUI_ImportBathymetryDlg()
83 {
84 }
85
86 void HYDROGUI_ImportBathymetryDlg::reset()
87 {
88   myFileName->clear();
89   myObjectName->clear();
90   myObjectNameGroup->setEnabled( false );
91 }
92
93 void HYDROGUI_ImportBathymetryDlg::setObjectName( const QString& theName )
94 {
95   myObjectName->setText( theName );
96   myObjectNameGroup->setEnabled( !theName.isEmpty() || !myFileName->text().isEmpty() );
97 }
98
99 QString HYDROGUI_ImportBathymetryDlg::getObjectName() const
100 {
101   return myObjectName->text();
102 }
103
104 void HYDROGUI_ImportBathymetryDlg::setFileName( const QString& theFileName )
105 {
106   myFileName->setText( theFileName );
107
108   if ( !myObjectNameGroup->isEnabled() )
109     myObjectNameGroup->setEnabled( !theFileName.isEmpty() );
110 }
111
112 QString HYDROGUI_ImportBathymetryDlg::getFileName() const
113 {
114   return myFileName->text();
115 }
116
117 void HYDROGUI_ImportBathymetryDlg::setInvertAltitudes( const bool theIsInvert )
118 {
119   myInvertAltitudes->setChecked( theIsInvert );
120 }
121
122 bool HYDROGUI_ImportBathymetryDlg::isInvertAltitudes() const
123 {
124   return myInvertAltitudes->isChecked();
125 }
126
127 void HYDROGUI_ImportBathymetryDlg::onBrowse()
128 {
129   QString aFilter( tr( "BATHYMETRY_FILTER" ) );
130   QString aFileName = SUIT_FileDlg::getFileName( this, "", aFilter, tr( "IMPORT_BATHYMETRY_FROM_FILE" ), true );
131
132   if( !aFileName.isEmpty() )
133   {
134     setFileName( aFileName );
135     emit FileSelected( aFileName );
136   }
137 }
138
139
140
141