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