Salome HOME
d2c66807160120a18b793d532e8503823118ab7a
[modules/hydro.git] / src / HYDROGUI / HYDROGUI_ChannelDlg.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_ChannelDlg.h"
20
21 #include "HYDROGUI_Tool.h"
22
23 #include <QComboBox>
24 #include <QGroupBox>
25 #include <QLabel>
26 #include <QLayout>
27 #include <QLineEdit>
28 #include <QCheckBox>
29 #include <QtxDoubleSpinBox.h>
30
31 HYDROGUI_ChannelDlg::HYDROGUI_ChannelDlg( HYDROGUI_Module* theModule, const QString& theTitle )
32 : HYDROGUI_InputPanel( theModule, theTitle )
33 {
34   // Channel name
35   myObjectNameGroup = new QGroupBox( tr( "CHANNEL_NAME" ), mainFrame() );
36
37   myObjectName = new QLineEdit( myObjectNameGroup );
38
39   QBoxLayout* aNameLayout = new QHBoxLayout( myObjectNameGroup );
40   aNameLayout->setMargin( 5 );
41   aNameLayout->setSpacing( 5 );
42   aNameLayout->addWidget( new QLabel( tr( "NAME" ), myObjectNameGroup ) );
43   aNameLayout->addWidget( myObjectName );
44
45   // Channel parameters
46   QGroupBox* aParamGroup = new QGroupBox( tr( "CHANNEL_PARAMETERS" ), mainFrame() );
47
48   //myGuideLines = new HYDROGUI_ObjComboSelector( theModule, KIND_POLYLINE, aParamGroup );
49   myGuideLines = new QComboBox( aParamGroup );
50   myGuideLines->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
51
52   //myProfiles = new HYDROGUI_ObjComboSelector( theModule, KIND_PROFILE, aParamGroup );
53   myProfiles = new QComboBox( aParamGroup );
54   myProfiles->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
55
56   myEquiDistance = new QtxDoubleSpinBox( aParamGroup );
57   myEquiDistance->setRange( 0.01, 9999 );
58   myEquiDistance->setValue( 1.0 );
59   myEquiDistance->setSingleStep( 1.0 );
60
61   myInvertDirection = new QCheckBox(aParamGroup);
62   myInvertDirection->setChecked(false);
63
64   QGridLayout* aParamsLayout = new QGridLayout( aParamGroup );
65   aParamsLayout->setMargin( 5 );
66   aParamsLayout->setSpacing( 5 );
67   aParamsLayout->addWidget( new QLabel( tr( "CHANNEL_GUIDE_LINE" ), aParamGroup ), 0, 0 );
68   aParamsLayout->addWidget( myGuideLines, 0, 1 );
69   aParamsLayout->addWidget( new QLabel( tr( "CHANNEL_PROFILE" ), aParamGroup ), 1, 0 );
70   aParamsLayout->addWidget( myProfiles, 1, 1 );
71   aParamsLayout->addWidget( new QLabel( tr( "EQUI_DISTANCE" ), aParamGroup ), 2, 0 );
72   aParamsLayout->addWidget( myEquiDistance, 2, 1 );
73   aParamsLayout->addWidget( new QLabel( tr( "INVERT_DIRECTION" ), aParamGroup ), 3, 0 );
74   aParamsLayout->addWidget( myInvertDirection, 3, 1 );
75
76   // Common
77   addWidget( myObjectNameGroup );
78   addWidget( aParamGroup );
79
80   addStretch();
81
82   // Connect signals and slots
83   connect( myGuideLines, SIGNAL( currentIndexChanged( int ) ), this, SLOT( onChannelDefChanged() ) );
84   connect( myProfiles, SIGNAL(  currentIndexChanged( int ) ), this, SLOT( onChannelDefChanged() ) );
85 }
86
87 HYDROGUI_ChannelDlg::~HYDROGUI_ChannelDlg()
88 {
89 }
90
91 void HYDROGUI_ChannelDlg::reset()
92 {
93   bool isBlocked = blockSignals( true );
94
95   myObjectName->clear();
96
97   myGuideLines->clear();
98   myProfiles->clear();
99
100   blockSignals( isBlocked );
101
102   onChannelDefChanged();
103 }
104
105 void HYDROGUI_ChannelDlg::setObjectName( const QString& theName )
106 {
107   myObjectName->setText( theName );
108 }
109
110 QString HYDROGUI_ChannelDlg::getObjectName() const
111 {
112   return myObjectName->text();
113 }
114
115 void HYDROGUI_ChannelDlg::setGuideLineNames( const QStringList& theGuideLines )
116 {
117   bool isBlocked = blockSignals( true );
118
119   myGuideLines->clear();
120   myGuideLines->addItems( theGuideLines );
121
122   blockSignals( isBlocked );
123 }
124
125 void HYDROGUI_ChannelDlg::setGuideLineName( const QString& theGuideLine )
126 {
127   int aNewIdx = myGuideLines->findText( theGuideLine );
128   if ( aNewIdx != myGuideLines->currentIndex() )
129   {
130     myGuideLines->setCurrentIndex( aNewIdx );
131   }
132   else
133   {
134     onChannelDefChanged();
135   }
136 }
137
138 QString HYDROGUI_ChannelDlg::getGuideLineName() const
139 {
140   return myGuideLines->currentText();
141 }
142
143 void HYDROGUI_ChannelDlg::setProfileNames( const QStringList& theProfiles )
144 {
145   bool isBlocked = blockSignals( true );
146
147   myProfiles->clear();
148   myProfiles->addItems( theProfiles );
149
150   blockSignals( isBlocked );
151 }
152
153 void HYDROGUI_ChannelDlg::setProfileName( const QString& theProfile )
154 {
155   int aNewIdx = myProfiles->findText( theProfile );
156   if ( aNewIdx != myProfiles->currentIndex() )
157   {
158     myProfiles->setCurrentIndex( aNewIdx );
159   }
160   else
161   {
162     onChannelDefChanged();
163   }
164 }
165
166 QString HYDROGUI_ChannelDlg::getProfileName() const
167 {
168   return myProfiles->currentText();
169 }
170
171 void HYDROGUI_ChannelDlg::onChannelDefChanged()
172 {
173   if ( signalsBlocked() )
174     return;
175
176   emit CreatePreview();
177 }
178
179 double HYDROGUI_ChannelDlg::getEquiDistance() const
180 {
181   return myEquiDistance->value();
182 }
183
184 void HYDROGUI_ChannelDlg::setEquiDistance( double theValue )
185 {
186   myEquiDistance->setValue( theValue );
187 }
188
189 bool HYDROGUI_ChannelDlg::getInvertDirection() const
190 {
191   return myInvertDirection->isChecked();
192 }
193
194 void HYDROGUI_ChannelDlg::setInvertDirection( bool isChecked )
195 {
196   myInvertDirection->setChecked(isChecked);
197 }
198