Salome HOME
debug of local CS
[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 #include <QPushButton>
34
35 HYDROGUI_StreamDlg::HYDROGUI_StreamDlg( HYDROGUI_Module* theModule, const QString& theTitle )
36 : HYDROGUI_InputPanel( theModule, theTitle )
37 {
38   // Stream name
39   myObjectNameGroup = new QGroupBox( tr( "STREAM_NAME" ), mainFrame() );
40
41   myObjectName = new QLineEdit( myObjectNameGroup );
42
43   QBoxLayout* aNameLayout = new QHBoxLayout( myObjectNameGroup );
44   aNameLayout->setMargin( 5 );
45   aNameLayout->setSpacing( 5 );
46   aNameLayout->addWidget( new QLabel( tr( "NAME" ), myObjectNameGroup ) );
47   aNameLayout->addWidget( myObjectName );
48
49   // Stream parameters
50   QGroupBox* aParamGroup = new QGroupBox( tr( "STREAM_PARAMETERS" ), mainFrame() );
51
52   myAxes = new QComboBox( aParamGroup );
53   myAxes->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
54   QBoxLayout* anAxisLayout = new QHBoxLayout();
55   anAxisLayout->addWidget( new QLabel( tr( "STREAM_HYDRAULIC_AXIS" ) ) );
56   anAxisLayout->addWidget( myAxes );
57
58   myProfiles = new QListWidget( aParamGroup );
59   myProfiles->setSelectionMode( QListWidget::ExtendedSelection );
60   myProfiles->setEditTriggers( QListWidget::NoEditTriggers );
61   myProfiles->setViewMode( QListWidget::ListMode );
62   myProfiles->setSortingEnabled( false );
63
64   myAddButton = new QPushButton( aParamGroup );
65   myAddButton->setText( tr("ADD") );
66   myRemoveButton = new QPushButton( aParamGroup );
67   myRemoveButton->setText( tr("REMOVE") );
68   QBoxLayout* aButtonsLayout = new QHBoxLayout();
69   aButtonsLayout->addWidget( myAddButton );
70   aButtonsLayout->addWidget( myRemoveButton );
71   aButtonsLayout->addStretch();
72  
73   QBoxLayout* aParamLayout = new QVBoxLayout();
74   aParamLayout->setMargin( 5 );
75   aParamLayout->setSpacing( 5 );
76   aParamLayout->addLayout( anAxisLayout );
77   aParamLayout->addWidget( myProfiles );
78   aParamLayout->addLayout( aButtonsLayout );
79
80   aParamGroup->setLayout( aParamLayout );
81
82   // Common
83   addWidget( myObjectNameGroup );
84   addWidget( aParamGroup );
85   addStretch();
86
87   // Connect signals and slots
88   connect( myAxes, SIGNAL( currentIndexChanged( const QString & ) ), 
89            this, SIGNAL( AxisChanged( const QString& ) ) );
90   connect( myAddButton, SIGNAL( clicked() ), this, SIGNAL( AddProfiles() ) );
91   connect( myRemoveButton, SIGNAL( clicked() ), this, SLOT( onRemoveProfiles() ) );
92 }
93
94 HYDROGUI_StreamDlg::~HYDROGUI_StreamDlg()
95 {
96 }
97
98 void HYDROGUI_StreamDlg::reset()
99 {
100   bool isBlocked = blockSignals( true );
101
102   myObjectName->clear();
103
104   myAxes->clear();
105   myProfiles->clear();
106   myAddButton->setEnabled( false );
107   myRemoveButton->setEnabled( false );
108
109   blockSignals( isBlocked );
110 }
111
112 void HYDROGUI_StreamDlg::setObjectName( const QString& theName )
113 {
114   myObjectName->setText( theName );
115 }
116
117 QString HYDROGUI_StreamDlg::getObjectName() const
118 {
119   return myObjectName->text();
120 }
121
122 void HYDROGUI_StreamDlg::setAxisNames( const QStringList& theAxises )
123 {
124   bool isBlocked = blockSignals( true );
125
126   myAxes->clear();
127   myAxes->addItems( theAxises );
128
129   blockSignals( isBlocked );
130 }
131
132 void HYDROGUI_StreamDlg::setAxisName( const QString& theName )
133 {
134   bool isBlocked = blockSignals( true );
135
136   int aNewId = myAxes->findText( theName );
137   if ( aNewId != myAxes->currentIndex() ) {
138     myAxes->setCurrentIndex( aNewId );
139   }
140   myAddButton->setEnabled( myAxes->currentIndex() > -1 );
141
142   blockSignals( isBlocked );
143 }
144
145 QString HYDROGUI_StreamDlg::getAxisName() const
146 {
147   return myAxes->currentText();
148 }
149
150 void HYDROGUI_StreamDlg::setProfiles( const QStringList& theProfiles )
151 {
152   bool isBlocked = blockSignals( true );
153
154   myProfiles->setUpdatesEnabled( false );
155   
156   myProfiles->clear();
157   foreach ( const QString& aProfileName, theProfiles ) {
158     QListWidgetItem* aListItem = new QListWidgetItem( aProfileName, myProfiles );
159     aListItem->setFlags( Qt::ItemIsEnabled | Qt::ItemIsSelectable );
160   }
161
162   myRemoveButton->setEnabled( myProfiles->count() > 0 );
163
164   myProfiles->setUpdatesEnabled( true );
165
166   blockSignals( isBlocked );
167 }
168
169 void HYDROGUI_StreamDlg::onRemoveProfiles()
170 {
171   QStringList aSelectedProfiles;
172
173   QList<QListWidgetItem*> aSelectedItems = myProfiles->selectedItems();
174   foreach( const QListWidgetItem* anItem, aSelectedItems ) {
175     QString aProfileName = anItem->text();
176     if ( !aProfileName.isEmpty() ) {
177       aSelectedProfiles << aProfileName;
178     }
179   }
180
181   emit RemoveProfiles( aSelectedProfiles );
182 }