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>
55 StdMeshersGUI_NbSegmentsCreator::StdMeshersGUI_NbSegmentsCreator()
56 : StdMeshersGUI_StdHypothesisCreator( "NumberOfSegments" ),
75 StdMeshersGUI_NbSegmentsCreator::~StdMeshersGUI_NbSegmentsCreator()
79 bool StdMeshersGUI_NbSegmentsCreator::checkParams() const
81 NbSegmentsHypothesisData data_old, data_new;
82 readParamsFromHypo( data_old );
83 readParamsFromWidgets( data_new );
84 bool res = storeParamsToHypo( data_new );
85 storeParamsToHypo( data_old );
89 QFrame* StdMeshersGUI_NbSegmentsCreator::buildFrame()
91 QFrame* fr = new QFrame();
93 QVBoxLayout* lay = new QVBoxLayout( fr );
97 QGroupBox* GroupC1 = new QGroupBox( tr( "SMESH_ARGUMENTS" ), fr );
98 lay->addWidget( GroupC1 );
100 StdMeshers::StdMeshers_NumberOfSegments_var h =
101 StdMeshers::StdMeshers_NumberOfSegments::_narrow( hypothesis() );
102 myPreview = new StdMeshersGUI_DistrPreview( GroupC1, h.in() );
104 myGroupLayout = new QGridLayout( GroupC1 );
105 myGroupLayout->setSpacing( SPACING );
106 myGroupLayout->setMargin( MARGIN );
107 myGroupLayout->setColumnStretch( 0, 0 );
108 myGroupLayout->setColumnStretch( 1, 1 );
115 myName = new QLineEdit( GroupC1 );
116 myGroupLayout->addWidget( new QLabel( tr( "SMESH_NAME" ), GroupC1 ), row, 0 );
117 myGroupLayout->addWidget( myName, row, 1 );
121 // 1) number of segments
122 myGroupLayout->addWidget( new QLabel( tr( "SMESH_NB_SEGMENTS_PARAM" ), GroupC1 ), row, 0 );
123 myNbSeg = new QtxIntSpinBox( GroupC1 );
124 myNbSeg->setMinimum( 1 );
125 myNbSeg->setMaximum( 9999 );
126 myGroupLayout->addWidget( myNbSeg, row, 1 );
129 // 2) type of distribution
130 myGroupLayout->addWidget( new QLabel( tr( "SMESH_DISTR_TYPE" ), GroupC1 ), row, 0 );
131 myDistr = new QtxComboBox( GroupC1 );
133 types.append( tr( "SMESH_DISTR_REGULAR" ) );
134 types.append( tr( "SMESH_DISTR_SCALE" ) );
135 types.append( tr( "SMESH_DISTR_TAB" ) );
136 types.append( tr( "SMESH_DISTR_EXPR" ) );
137 myDistr->addItems( types );
138 myGroupLayout->addWidget( myDistr, row, 1 );
142 myGroupLayout->addWidget( myLScale = new QLabel( tr( "SMESH_NB_SEGMENTS_SCALE_PARAM" ), GroupC1 ), row, 0 );
143 myScale = new SMESHGUI_SpinBox( GroupC1 );
144 myScale->RangeStepAndValidator( 1E-5, 1E+5, 0.1, 6 );
145 myGroupLayout->addWidget( myScale, row, 1 );
148 myInfo = new QLabel( tr( "SMESH_FUNC_DOMAIN" ), GroupC1 );
149 myGroupLayout->addWidget( myInfo, row, 0, 1, 2 );
153 myGroupLayout->addWidget( myLTable = new QLabel( tr( "SMESH_TAB_FUNC" ), GroupC1 ), row, 0 );
154 myTable = new StdMeshersGUI_DistrTableFrame( GroupC1 );
155 myGroupLayout->addWidget( myTable, row, 1 );
156 myGroupLayout->setRowStretch( row, 1 );
161 myGroupLayout->addWidget( myLExpr = new QLabel( tr( "SMESH_EXPR_FUNC" ), GroupC1 ), row, 0 );
162 myExpr = new QLineEdit( GroupC1 );
163 myGroupLayout->addWidget( myExpr, row, 1 );
166 // 6) conversion (radiogroup)
167 myConvBox = new QGroupBox( tr( "SMESH_CONV_MODE" ), GroupC1 );
168 myConv = new QButtonGroup( GroupC1 );
170 QHBoxLayout* convLay = new QHBoxLayout( myConvBox );
171 convLay->setMargin( MARGIN );
172 convLay->setSpacing( SPACING );
174 QRadioButton* rbExp = new QRadioButton( tr( "SMESH_EXP_MODE" ), myConvBox );
175 QRadioButton* myCutNeg = new QRadioButton( tr( "SMESH_CUT_NEG_MODE" ), myConvBox );
177 convLay->addWidget( rbExp );
178 convLay->addWidget( myCutNeg );
179 myConv->addButton( rbExp, 0 );
180 myConv->addButton( myCutNeg, 1 );
182 myGroupLayout->addWidget( myConvBox, row, 0, 1, 2 );
185 // 7) distribution preview
186 myGroupLayout->addWidget( myPreview, row, 0, 1, 2 );
187 myGroupLayout->setRowStretch( row, 1 );
191 connect( myNbSeg, SIGNAL( valueChanged( const QString& ) ), this, SLOT( onValueChanged() ) );
192 connect( myDistr, SIGNAL( activated( int ) ), this, SLOT( onValueChanged() ) );
193 connect( myTable, SIGNAL( valueChanged( int, int ) ), this, SLOT( onValueChanged() ) );
194 connect( myExpr, SIGNAL( textChanged( const QString& ) ), this, SLOT( onValueChanged() ) );
195 connect( myConv, SIGNAL( cuttonClicked( int ) ), this, SLOT( onValueChanged() ) );
200 void StdMeshersGUI_NbSegmentsCreator::retrieveParams() const
202 NbSegmentsHypothesisData data;
203 readParamsFromHypo( data );
206 myName->setText( data.myName );
207 myNbSeg->setValue( data.myNbSeg );
208 myDistr->setCurrentIndex( data.myDistrType );
209 myScale->setValue( data.myScale );
210 myConv->button( data.myConv )->setChecked( true );
211 myTable->setFuncMinValue(myConv->checkedId()==0 ? -1E20 : 0);
212 myTable->setData( data.myTable );
213 myExpr->setText( data.myExpr );
216 QString StdMeshersGUI_NbSegmentsCreator::storeParams() const
218 NbSegmentsHypothesisData data;
219 readParamsFromWidgets( data );
220 storeParamsToHypo( data );
222 QString valStr = QString::number( data.myNbSeg ) += "; ";
226 Regular, //!< equidistant distribution
227 Scale, //!< scale distribution
228 TabFunc, //!< distribution with density function presented by table
229 ExprFunc //!< distribution with density function presented by expression
231 bool hasConv = false;
232 switch ( data.myDistrType ) {
234 valStr += tr("SMESH_DISTR_REGULAR");
237 valStr += tr("SMESH_NB_SEGMENTS_SCALE_PARAM") + " = " + QString::number( data.myScale );
240 //valStr += tr("SMESH_TAB_FUNC");
242 for( int i=0; i < data.myTable.length(); i++, param = !param ) {
245 valStr += QString::number( data.myTable[ i ]);
246 valStr += ( param ? "," : "]" );
252 valStr += data.myExpr;
258 valStr += "; " + tr("SMESH_CUT_NEG_MODE");
260 valStr += "; " + tr("SMESH_EXP_MODE");
265 bool StdMeshersGUI_NbSegmentsCreator::readParamsFromHypo( NbSegmentsHypothesisData& h_data ) const
267 StdMeshers::StdMeshers_NumberOfSegments_var h =
268 StdMeshers::StdMeshers_NumberOfSegments::_narrow( initParamsHypothesis() );
270 h_data.myName = hypName();
272 h_data.myNbSeg = (int) h->GetNumberOfSegments();
273 int distr = (int) h->GetDistrType();
274 h_data.myDistrType = distr;
275 h_data.myScale = distr==1 ? h->GetScaleFactor() : 1.0;
278 SMESH::double_array* a = h->GetTableFunction();
284 SMESH::double_array& a = h_data.myTable;
285 // by default, constant table function f(t)=1
287 a[0] = 0.0; a[1] = 1.0;
288 a[2] = 1.0; a[3] = 1.0;
291 h_data.myExpr = distr==3 ? h->GetExpressionFunction() : "1";
292 h_data.myConv = distr==2 || distr==3 ? h->ConversionMode() : 1; /*cut negative by default*/
297 bool StdMeshersGUI_NbSegmentsCreator::storeParamsToHypo( const NbSegmentsHypothesisData& h_data ) const
299 StdMeshers::StdMeshers_NumberOfSegments_var h =
300 StdMeshers::StdMeshers_NumberOfSegments::_narrow( hypothesis() );
306 SMESH::SetName( SMESH::FindSObject( h ), h_data.myName.toLatin1().data() );
308 h->SetNumberOfSegments( h_data.myNbSeg );
309 int distr = h_data.myDistrType;
310 h->SetDistrType( distr );
313 h->SetScaleFactor( h_data.myScale );
315 if( distr==2 || distr==3 )
316 h->SetConversionMode( h_data.myConv );
319 h->SetTableFunction( h_data.myTable );
322 h->SetExpressionFunction( h_data.myExpr.toLatin1().data() );
323 //setting of function must follow after setConversionMode, because otherwise
324 //the function will be checked with old conversion mode, so that it may occurs
325 //unexpected errors for user
327 catch(const SALOME::SALOME_Exception& ex)
329 SalomeApp_Tools::QtCatchCorbaException(ex);
335 bool StdMeshersGUI_NbSegmentsCreator::readParamsFromWidgets( NbSegmentsHypothesisData& h_data ) const
337 h_data.myName = myName ? myName->text() : "";
338 h_data.myNbSeg = myNbSeg->value();
339 h_data.myDistrType = myDistr->currentIndex();
340 h_data.myConv = myConv->checkedId();
341 h_data.myScale = myScale->value();
342 myTable->data( h_data.myTable );
343 h_data.myExpr = myExpr->text();
347 void StdMeshersGUI_NbSegmentsCreator::onValueChanged()
349 int distr = myDistr->currentIndex();
351 /* if( distr==2 ) //table func
352 myCutNeg->setText( tr( "SMESH_NO_CONV" ) );
354 myCutNeg->setText( tr( "SMESH_CUT_NEG_MODE" ) );*/
356 if( distr==2 && sender()==myConv ) //table func
358 myTable->setFuncMinValue( myConv->checkedId()==0 ? -1E20 : 0 );
359 SMESH::double_array arr;
360 myTable->data( arr );
361 myTable->setData( arr ); //update data in table
364 myScale->setShown( distr==1 );
365 myLScale->setShown( distr==1 );
367 bool isFunc = distr==2 || distr==3;
368 myPreview->setShown( isFunc );
369 myGroupLayout->setRowStretch( myPreviewRow, isFunc ? 1 : 0 );
371 myConvBox->setShown( isFunc );
377 myLTable->setShown( distr==2 );
378 myGroupLayout->setRowStretch( myTableRow, distr==2 ? 1 : 0 );
380 myExpr->setShown( distr==3 );
381 myLExpr->setShown( distr==3 );
382 myInfo->setShown( isFunc );
385 int nbSeg = myNbSeg->value();
386 if( distr==2 ) //preview for table-described function
388 SMESH::double_array a;
390 myPreview->setParams( a, nbSeg, false );
392 else if( distr==3 ) //preview for analytic-described function
393 myPreview->setParams( myExpr->text(), nbSeg, 100, false );
396 myPreview->setConversion( StdMeshersGUI_DistrPreview::Conversion( myConv->checkedId() ) );