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