Salome HOME
code revision
[modules/hydro.git] / src / HYDROGUI / HYDROGUI_StreamDlg.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_StreamDlg.h"
20
21 #include "HYDROGUI_ListSelector.h"
22 #include "HYDROGUI_Module.h"
23 #include "HYDROGUI_OrderedListWidget.h"
24 #include "HYDROGUI_Tool.h"
25
26 #include <HYDROData_Profile.h>
27
28 #include <LightApp_Application.h>
29 #include <LightApp_SelectionMgr.h>
30
31 #include <QComboBox>
32 #include <QGroupBox>
33 #include <QLabel>
34 #include <QLayout>
35 #include <QLineEdit>
36 #include <QListWidget>
37 #include <QPushButton>
38
39 HYDROGUI_StreamDlg::HYDROGUI_StreamDlg( HYDROGUI_Module* theModule, const QString& theTitle )
40 : HYDROGUI_InputPanel( theModule, theTitle )
41 {
42   // Stream name
43   myObjectNameGroup = new QGroupBox( tr( "STREAM_NAME" ), mainFrame() );
44
45   myObjectName = new QLineEdit( myObjectNameGroup );
46
47   QBoxLayout* aNameLayout = new QHBoxLayout( myObjectNameGroup );
48   aNameLayout->setMargin( 5 );
49   aNameLayout->setSpacing( 5 );
50   aNameLayout->addWidget( new QLabel( tr( "NAME" ), myObjectNameGroup ) );
51   aNameLayout->addWidget( myObjectName );
52
53   // Stream parameters
54   QGroupBox* aParamGroup = new QGroupBox( tr( "STREAM_PARAMETERS" ), mainFrame() );
55
56   myAxes = new QComboBox( aParamGroup );
57   myAxes->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
58   QBoxLayout* anAxisLayout = new QHBoxLayout();
59   anAxisLayout->addWidget( new QLabel( tr( "STREAM_HYDRAULIC_AXIS" ) ) );
60   anAxisLayout->addWidget( myAxes );
61
62   myProfiles = new HYDROGUI_OrderedListWidget( aParamGroup, 0 );
63   myProfiles->setHiddenObjectsShown(true);
64   myProfiles->setVisibilityIconShown(false);
65   myProfiles->setContentsMargins(QMargins());
66   myProfiles->setOrderingEnabled( false );
67  
68   myAddButton = new QPushButton( aParamGroup );
69   myAddButton->setText( tr("ADD") );
70   myRemoveButton = new QPushButton( aParamGroup );
71   myRemoveButton->setText( tr("REMOVE") );
72   QBoxLayout* aButtonsLayout = new QHBoxLayout();
73   aButtonsLayout->addWidget( myAddButton );
74   aButtonsLayout->addWidget( myRemoveButton );
75   aButtonsLayout->addStretch();
76  
77   QBoxLayout* aParamLayout = new QVBoxLayout();
78   aParamLayout->setMargin( 5 );
79   aParamLayout->setSpacing( 5 );
80   aParamLayout->addLayout( anAxisLayout );
81   aParamLayout->addWidget( myProfiles );
82   aParamLayout->addLayout( aButtonsLayout );
83
84   aParamGroup->setLayout( aParamLayout );
85
86   // Common
87   addWidget( myObjectNameGroup );
88   addWidget( aParamGroup );
89   addStretch();
90
91   // Create selector
92   if ( module() ) {
93     HYDROGUI_ListSelector* aListSelector = 
94       new HYDROGUI_ListSelector( myProfiles, module()->getApp()->selectionMgr() );
95     aListSelector->setAutoBlock( true );
96   }
97
98   // Connect signals and slots
99   connect( myAxes, SIGNAL( currentIndexChanged( const QString & ) ), 
100            this, SIGNAL( AxisChanged( const QString& ) ) );
101   connect( myAddButton, SIGNAL( clicked() ), this, SIGNAL( AddProfiles() ) );
102   connect( myRemoveButton, SIGNAL( clicked() ), this, SLOT( onRemoveProfiles() ) );
103 }
104
105 HYDROGUI_StreamDlg::~HYDROGUI_StreamDlg()
106 {
107 }
108
109 void HYDROGUI_StreamDlg::reset()
110 {
111   bool isBlocked = blockSignals( true );
112
113   myObjectName->clear();
114
115   myAxes->clear();
116   myProfiles->setObjects( HYDROGUI_ListModel::Object2VisibleList() );
117   myAddButton->setEnabled( false );
118   myRemoveButton->setEnabled( false );
119
120   blockSignals( isBlocked );
121 }
122
123 void HYDROGUI_StreamDlg::setObjectName( const QString& theName )
124 {
125   myObjectName->setText( theName );
126 }
127
128 QString HYDROGUI_StreamDlg::getObjectName() const
129 {
130   return myObjectName->text();
131 }
132
133 void HYDROGUI_StreamDlg::setAxisNames( const QStringList& theAxises )
134 {
135   bool isBlocked = blockSignals( true );
136
137   myAxes->clear();
138   myAxes->addItems( theAxises );
139
140   blockSignals( isBlocked );
141 }
142
143 void HYDROGUI_StreamDlg::setAxisName( const QString& theName )
144 {
145   bool isBlocked = blockSignals( true );
146
147   int aNewId = myAxes->findText( theName );
148   if ( aNewId != myAxes->currentIndex() ) {
149     myAxes->setCurrentIndex( aNewId );
150   }
151   myAddButton->setEnabled( myAxes->currentIndex() > -1 );
152
153   blockSignals( isBlocked );
154 }
155
156 QString HYDROGUI_StreamDlg::getAxisName() const
157 {
158   return myAxes->currentText();
159 }
160
161 void HYDROGUI_StreamDlg::setProfiles( const QStringList& theProfiles )
162 {
163   bool isBlocked = blockSignals( true );
164
165   myProfiles->setUpdatesEnabled( false );
166   
167   HYDROGUI_ListModel::Object2VisibleList aProfiles;
168   foreach ( const QString& aProfileName, theProfiles ) {
169     Handle(HYDROData_Profile) anObject = Handle(HYDROData_Profile)::DownCast( 
170       HYDROGUI_Tool::FindObjectByName( module(), aProfileName ) );
171     if ( !anObject.IsNull() ) {
172       aProfiles.append( HYDROGUI_ListModel::Object2Visible( anObject, true ) );
173     }
174   }
175
176   myProfiles->setObjects( aProfiles );
177
178   myRemoveButton->setEnabled( myProfiles->getObjects().count() > 0 );
179
180   myProfiles->setUpdatesEnabled( true );
181
182   blockSignals( isBlocked );
183 }
184
185 void HYDROGUI_StreamDlg::onRemoveProfiles()
186 {
187   QStringList aSelectedProfiles = myProfiles->getSelectedNames();
188
189   emit RemoveProfiles( aSelectedProfiles );
190 }