Salome HOME
Creat\Edit stream operation.
[modules/hydro.git] / src / HYDROGUI / HYDROGUI_StreamDlg.cxx
1 // Copyright (C) 2007-2013  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.
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_StreamDlg.h"
24
25 #include "HYDROGUI_Tool.h"
26
27 #include <QComboBox>
28 #include <QGroupBox>
29 #include <QLabel>
30 #include <QLayout>
31 #include <QLineEdit>
32 #include <QListWidget>
33
34 HYDROGUI_StreamDlg::HYDROGUI_StreamDlg( HYDROGUI_Module* theModule, const QString& theTitle )
35 : HYDROGUI_InputPanel( theModule, theTitle )
36 {
37   // Stream name
38   myObjectNameGroup = new QGroupBox( tr( "STREAM_NAME" ), mainFrame() );
39
40   myObjectName = new QLineEdit( myObjectNameGroup );
41
42   QBoxLayout* aNameLayout = new QHBoxLayout( myObjectNameGroup );
43   aNameLayout->setMargin( 5 );
44   aNameLayout->setSpacing( 5 );
45   aNameLayout->addWidget( new QLabel( tr( "NAME" ), myObjectNameGroup ) );
46   aNameLayout->addWidget( myObjectName );
47
48   // Stream parameters
49   QGroupBox* aParamGroup = new QGroupBox( tr( "STREAM_PARAMETERS" ), mainFrame() );
50
51   myAxises = new QComboBox( aParamGroup );
52   myAxises->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
53
54   myProfiles = new QListWidget( aParamGroup );
55   myProfiles->setSelectionMode( QListWidget::SingleSelection );
56   myProfiles->setEditTriggers( QListWidget::NoEditTriggers );
57   myProfiles->setViewMode( QListWidget::ListMode );
58   myProfiles->setSortingEnabled( false );
59  
60   QGridLayout* aParamLayout = new QGridLayout( aParamGroup );
61   aParamLayout->setMargin( 5 );
62   aParamLayout->setSpacing( 5 );
63   aParamLayout->addWidget( new QLabel( tr( "STREAM_HYDRAULIC_AXIS" ), aParamGroup ), 0, 0 );
64   aParamLayout->addWidget( myAxises, 0, 1 );
65   aParamLayout->addWidget( myProfiles, 1, 0, 1, 2 );
66
67   // Common
68   addWidget( myObjectNameGroup );
69   addWidget( aParamGroup );
70
71   addStretch();
72
73   // Connect signals and slots
74   connect( myAxises, SIGNAL( currentIndexChanged( int ) ), this, SLOT( onStreamDefChanged() ) );
75 }
76
77 HYDROGUI_StreamDlg::~HYDROGUI_StreamDlg()
78 {
79 }
80
81 void HYDROGUI_StreamDlg::reset()
82 {
83   bool isBlocked = blockSignals( true );
84
85   myObjectName->clear();
86
87   myAxises->clear();
88   myProfiles->clear();
89
90   blockSignals( isBlocked );
91
92   onStreamDefChanged();
93 }
94
95 void HYDROGUI_StreamDlg::setObjectName( const QString& theName )
96 {
97   myObjectName->setText( theName );
98 }
99
100 QString HYDROGUI_StreamDlg::getObjectName() const
101 {
102   return myObjectName->text();
103 }
104
105 void HYDROGUI_StreamDlg::setAxisNames( const QStringList& theAxises )
106 {
107   bool isBlocked = blockSignals( true );
108
109   myAxises->clear();
110   myAxises->addItems( theAxises );
111
112   blockSignals( isBlocked );
113 }
114
115 void HYDROGUI_StreamDlg::setAxisName( const QString& theName )
116 {
117   int aNewIdx = myAxises->findText( theName );
118   if ( aNewIdx != myAxises->currentIndex() )
119   {
120     myAxises->setCurrentIndex( aNewIdx );
121   }
122   else
123   {
124     onStreamDefChanged();
125   }
126 }
127
128 QString HYDROGUI_StreamDlg::getAxisName() const
129 {
130   return myAxises->currentText();
131 }
132
133 void HYDROGUI_StreamDlg::setSelectedProfiles( const QStringList& theProfiles )
134 {
135   bool isBlocked = blockSignals( true );
136
137   myProfiles->setUpdatesEnabled( false );
138   
139   myProfiles->clear();
140   for ( int i = 0, n = theProfiles.length(); i < n; ++i )
141   {
142     const QString& aProfileName = theProfiles.at( i );
143     QListWidgetItem* aListItem = new QListWidgetItem( aProfileName, myProfiles );
144     aListItem->setFlags( Qt::ItemIsEnabled | Qt::ItemIsSelectable );
145   }
146
147   myProfiles->setUpdatesEnabled( true );
148
149   blockSignals( isBlocked );
150
151   onStreamDefChanged();
152 }
153
154 QStringList HYDROGUI_StreamDlg::getSelectedProfiles() const
155 {
156   QStringList aProfiles;
157
158   for ( int i = 0, n = myProfiles->count(); i < n; ++i )
159   {
160     QListWidgetItem* aListItem = myProfiles->item( i );
161     if ( !aListItem )
162       continue;
163
164     QString aProfileName = aListItem->text();
165     aProfiles << aProfileName;
166   }
167
168   return aProfiles;
169 }
170
171 void HYDROGUI_StreamDlg::onStreamDefChanged()
172 {
173   if ( signalsBlocked() )
174     return;
175
176   emit CreatePreview();
177 }