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