1 // Copyright (C) 2003 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
2 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
4 // This library is free software; you can redistribute it and/or
5 // modify it under the terms of the GNU Lesser General Public
6 // License as published by the Free Software Foundation; either
7 // version 2.1 of the License.
9 // This library is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 // Lesser General Public License for more details.
14 // You should have received a copy of the GNU Lesser General Public
15 // License along with this library; if not, write to the Free Software
16 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
20 // File : StdMeshersGUI_NbSegmentsCreator.cxx
21 // Author : Open CASCADE S.A.S.
25 #include "StdMeshersGUI_NbSegmentsCreator.h"
26 #include "StdMeshersGUI_DistrTable.h"
27 #include "StdMeshersGUI_DistrPreview.h"
29 #include <SMESHGUI_Utils.h>
30 #include <SMESHGUI_HypothesesUtils.h>
31 #include <SMESHGUI_SpinBox.h>
34 #include CORBA_SERVER_HEADER(SMESH_BasicHypothesis)
36 // SALOME GUI includes
37 #include <SalomeApp_Tools.h>
38 #include <QtxIntSpinBox.h>
39 #include <QtxComboBox.h>
46 #include <QButtonGroup>
47 #include <QRadioButton>
48 #include <QGridLayout>
49 #include <QVBoxLayout>
50 #include <QHBoxLayout>
51 #include <QApplication>
56 StdMeshersGUI_NbSegmentsCreator::StdMeshersGUI_NbSegmentsCreator()
57 : StdMeshersGUI_StdHypothesisCreator( "NumberOfSegments" ),
76 StdMeshersGUI_NbSegmentsCreator::~StdMeshersGUI_NbSegmentsCreator()
80 bool StdMeshersGUI_NbSegmentsCreator::checkParams() const
82 NbSegmentsHypothesisData data_old, data_new;
83 readParamsFromHypo( data_old );
84 readParamsFromWidgets( data_new );
85 bool res = storeParamsToHypo( data_new );
86 storeParamsToHypo( data_old );
90 QFrame* StdMeshersGUI_NbSegmentsCreator::buildFrame()
92 QFrame* fr = new QFrame();
94 QVBoxLayout* lay = new QVBoxLayout( fr );
98 QGroupBox* GroupC1 = new QGroupBox( tr( "SMESH_ARGUMENTS" ), fr );
99 lay->addWidget( GroupC1 );
101 StdMeshers::StdMeshers_NumberOfSegments_var h =
102 StdMeshers::StdMeshers_NumberOfSegments::_narrow( hypothesis() );
103 myPreview = new StdMeshersGUI_DistrPreview( GroupC1, h.in() );
105 myGroupLayout = new QGridLayout( GroupC1 );
106 myGroupLayout->setSpacing( SPACING );
107 myGroupLayout->setMargin( MARGIN );
108 myGroupLayout->setColumnStretch( 0, 0 );
109 myGroupLayout->setColumnStretch( 1, 1 );
116 myName = new QLineEdit( GroupC1 );
117 myGroupLayout->addWidget( new QLabel( tr( "SMESH_NAME" ), GroupC1 ), row, 0 );
118 myGroupLayout->addWidget( myName, row, 1 );
122 // 1) number of segments
123 myGroupLayout->addWidget( new QLabel( tr( "SMESH_NB_SEGMENTS_PARAM" ), GroupC1 ), row, 0 );
124 myNbSeg = new QtxIntSpinBox( GroupC1 );
125 myNbSeg->setMinimum( 1 );
126 myNbSeg->setMaximum( 9999 );
127 myGroupLayout->addWidget( myNbSeg, row, 1 );
130 // 2) type of distribution
131 myGroupLayout->addWidget( new QLabel( tr( "SMESH_DISTR_TYPE" ), GroupC1 ), row, 0 );
132 myDistr = new QtxComboBox( GroupC1 );
134 types.append( tr( "SMESH_DISTR_REGULAR" ) );
135 types.append( tr( "SMESH_DISTR_SCALE" ) );
136 types.append( tr( "SMESH_DISTR_TAB" ) );
137 types.append( tr( "SMESH_DISTR_EXPR" ) );
138 myDistr->addItems( types );
139 myGroupLayout->addWidget( myDistr, row, 1 );
143 myGroupLayout->addWidget( myLScale = new QLabel( tr( "SMESH_NB_SEGMENTS_SCALE_PARAM" ), GroupC1 ), row, 0 );
144 myScale = new SMESHGUI_SpinBox( GroupC1 );
145 myScale->RangeStepAndValidator( 1E-5, 1E+5, 0.1, 6 );
146 myGroupLayout->addWidget( myScale, row, 1 );
149 myInfo = new QLabel( tr( "SMESH_FUNC_DOMAIN" ), GroupC1 );
150 myGroupLayout->addWidget( myInfo, row, 0, 1, 2 );
154 myGroupLayout->addWidget( myLTable = new QLabel( tr( "SMESH_TAB_FUNC" ), GroupC1 ), row, 0 );
155 myTable = new StdMeshersGUI_DistrTableFrame( GroupC1 );
156 myGroupLayout->addWidget( myTable, row, 1 );
157 myGroupLayout->setRowStretch( row, 1 );
162 myGroupLayout->addWidget( myLExpr = new QLabel( tr( "SMESH_EXPR_FUNC" ), GroupC1 ), row, 0 );
163 myExpr = new QLineEdit( GroupC1 );
164 myGroupLayout->addWidget( myExpr, row, 1 );
167 // 6) conversion (radiogroup)
168 myConvBox = new QGroupBox( tr( "SMESH_CONV_MODE" ), GroupC1 );
169 myConv = new QButtonGroup( GroupC1 );
171 QHBoxLayout* convLay = new QHBoxLayout( myConvBox );
172 convLay->setMargin( MARGIN );
173 convLay->setSpacing( SPACING );
175 QRadioButton* rbExp = new QRadioButton( tr( "SMESH_EXP_MODE" ), myConvBox );
176 QRadioButton* myCutNeg = new QRadioButton( tr( "SMESH_CUT_NEG_MODE" ), myConvBox );
178 convLay->addWidget( rbExp );
179 convLay->addWidget( myCutNeg );
180 myConv->addButton( rbExp, 0 );
181 myConv->addButton( myCutNeg, 1 );
183 myGroupLayout->addWidget( myConvBox, row, 0, 1, 2 );
186 // 7) distribution preview
187 myGroupLayout->addWidget( myPreview, row, 0, 1, 2 );
188 myGroupLayout->setRowStretch( row, 1 );
192 connect( myNbSeg, SIGNAL( valueChanged( const QString& ) ), this, SLOT( onValueChanged() ) );
193 connect( myDistr, SIGNAL( activated( int ) ), this, SLOT( onValueChanged() ) );
194 connect( myTable, SIGNAL( valueChanged( int, int ) ), this, SLOT( onValueChanged() ) );
195 connect( myExpr, SIGNAL( textChanged( const QString& ) ), this, SLOT( onValueChanged() ) );
196 connect( myConv, SIGNAL( cuttonClicked( int ) ), this, SLOT( onValueChanged() ) );
201 void StdMeshersGUI_NbSegmentsCreator::retrieveParams() const
203 NbSegmentsHypothesisData data;
204 readParamsFromHypo( data );
207 myName->setText( data.myName );
208 myNbSeg->setValue( data.myNbSeg );
209 myDistr->setCurrentIndex( data.myDistrType );
210 myScale->setValue( data.myScale );
211 myConv->button( data.myConv )->setChecked( true );
212 myTable->setFuncMinValue(myConv->checkedId()==0 ? -1E20 : 0);
213 myTable->setData( data.myTable );
214 myExpr->setText( data.myExpr );
217 dlg()->setMinimumSize( dlg()->minimumSizeHint().width(), dlg()->minimumSizeHint().height() );
220 QString StdMeshersGUI_NbSegmentsCreator::storeParams() const
222 NbSegmentsHypothesisData data;
223 readParamsFromWidgets( data );
224 storeParamsToHypo( data );
226 QString valStr = QString::number( data.myNbSeg ) += "; ";
230 Regular, //!< equidistant distribution
231 Scale, //!< scale distribution
232 TabFunc, //!< distribution with density function presented by table
233 ExprFunc //!< distribution with density function presented by expression
235 bool hasConv = false;
236 switch ( data.myDistrType ) {
238 valStr += tr("SMESH_DISTR_REGULAR");
241 valStr += tr("SMESH_NB_SEGMENTS_SCALE_PARAM") + " = " + QString::number( data.myScale );
244 //valStr += tr("SMESH_TAB_FUNC");
246 for( int i=0; i < data.myTable.length(); i++, param = !param ) {
249 valStr += QString::number( data.myTable[ i ]);
250 valStr += ( param ? "," : "]" );
256 valStr += data.myExpr;
262 valStr += "; " + tr("SMESH_CUT_NEG_MODE");
264 valStr += "; " + tr("SMESH_EXP_MODE");
269 bool StdMeshersGUI_NbSegmentsCreator::readParamsFromHypo( NbSegmentsHypothesisData& h_data ) const
271 StdMeshers::StdMeshers_NumberOfSegments_var h =
272 StdMeshers::StdMeshers_NumberOfSegments::_narrow( initParamsHypothesis() );
274 h_data.myName = hypName();
276 h_data.myNbSeg = (int) h->GetNumberOfSegments();
277 int distr = (int) h->GetDistrType();
278 h_data.myDistrType = distr;
279 h_data.myScale = distr==1 ? h->GetScaleFactor() : 1.0;
282 SMESH::double_array* a = h->GetTableFunction();
288 SMESH::double_array& a = h_data.myTable;
289 // by default, constant table function f(t)=1
291 a[0] = 0.0; a[1] = 1.0;
292 a[2] = 1.0; a[3] = 1.0;
295 h_data.myExpr = distr==3 ? h->GetExpressionFunction() : "1";
296 h_data.myConv = distr==2 || distr==3 ? h->ConversionMode() : 1; /*cut negative by default*/
301 bool StdMeshersGUI_NbSegmentsCreator::storeParamsToHypo( const NbSegmentsHypothesisData& h_data ) const
303 StdMeshers::StdMeshers_NumberOfSegments_var h =
304 StdMeshers::StdMeshers_NumberOfSegments::_narrow( hypothesis() );
310 SMESH::SetName( SMESH::FindSObject( h ), h_data.myName.toLatin1().data() );
312 h->SetNumberOfSegments( h_data.myNbSeg );
313 int distr = h_data.myDistrType;
314 h->SetDistrType( distr );
317 h->SetScaleFactor( h_data.myScale );
319 if( distr==2 || distr==3 )
320 h->SetConversionMode( h_data.myConv );
323 h->SetTableFunction( h_data.myTable );
326 h->SetExpressionFunction( h_data.myExpr.toLatin1().data() );
327 //setting of function must follow after setConversionMode, because otherwise
328 //the function will be checked with old conversion mode, so that it may occurs
329 //unexpected errors for user
331 catch(const SALOME::SALOME_Exception& ex)
333 SalomeApp_Tools::QtCatchCorbaException(ex);
339 bool StdMeshersGUI_NbSegmentsCreator::readParamsFromWidgets( NbSegmentsHypothesisData& h_data ) const
341 h_data.myName = myName ? myName->text() : "";
342 h_data.myNbSeg = myNbSeg->value();
343 h_data.myDistrType = myDistr->currentIndex();
344 h_data.myConv = myConv->checkedId();
345 h_data.myScale = myScale->value();
346 myTable->data( h_data.myTable );
347 h_data.myExpr = myExpr->text();
351 void StdMeshersGUI_NbSegmentsCreator::onValueChanged()
353 int distr = myDistr->currentIndex();
355 /* if( distr==2 ) //table func
356 myCutNeg->setText( tr( "SMESH_NO_CONV" ) );
358 myCutNeg->setText( tr( "SMESH_CUT_NEG_MODE" ) );*/
360 if( distr==2 && sender()==myConv ) //table func
362 myTable->setFuncMinValue( myConv->checkedId()==0 ? -1E20 : 0 );
363 SMESH::double_array arr;
364 myTable->data( arr );
365 myTable->setData( arr ); //update data in table
368 myScale->setShown( distr==1 );
369 myLScale->setShown( distr==1 );
371 bool isFunc = distr==2 || distr==3;
372 myPreview->setShown( isFunc );
373 myGroupLayout->setRowStretch( myPreviewRow, isFunc ? 1 : 0 );
375 myConvBox->setShown( isFunc );
381 myLTable->setShown( distr==2 );
382 myGroupLayout->setRowStretch( myTableRow, distr==2 ? 1 : 0 );
384 myExpr->setShown( distr==3 );
385 myLExpr->setShown( distr==3 );
386 myInfo->setShown( isFunc );
389 int nbSeg = myNbSeg->value();
390 if( distr==2 ) //preview for table-described function
392 SMESH::double_array a;
394 myPreview->setParams( a, nbSeg, false );
396 else if( distr==3 ) //preview for analytic-described function
397 myPreview->setParams( myExpr->text(), nbSeg, 100, false );
400 myPreview->setConversion( StdMeshersGUI_DistrPreview::Conversion( myConv->checkedId() ) );
402 if ( (QtxComboBox*)sender() == myDistr && dlg() ) {
403 QApplication::instance()->processEvents();
404 dlg()->updateGeometry();
405 dlg()->setMinimumSize( dlg()->minimumSizeHint().width(), dlg()->minimumSizeHint().height() );
406 dlg()->resize( dlg()->minimumSize() );