1 // Copyright (C) 2007-2015 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
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, or (at your option) any later version.
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.
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
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
23 // File : StdMeshersGUI_NbSegmentsCreator.cxx
24 // Author : Open CASCADE S.A.S.
27 #include "StdMeshersGUI_NbSegmentsCreator.h"
28 #ifndef DISABLE_PLOT2DVIEWER
29 #include "StdMeshersGUI_DistrPreview.h"
31 #include "StdMeshersGUI_DistrTable.h"
32 #include "StdMeshersGUI_PropagationHelperWdg.h"
33 #include "StdMeshersGUI_SubShapeSelectorWdg.h"
36 #include <SMESHGUI_Utils.h>
37 #include <SMESHGUI_HypothesesUtils.h>
38 #include <SMESHGUI_SpinBox.h>
41 #include CORBA_SERVER_HEADER(SMESH_BasicHypothesis)
43 // SALOME GUI includes
44 #include <SalomeApp_Tools.h>
45 #include <SalomeApp_IntSpinBox.h>
46 #include <QtxComboBox.h>
53 #include <QButtonGroup>
54 #include <QRadioButton>
55 #include <QGridLayout>
56 #include <QVBoxLayout>
57 #include <QHBoxLayout>
58 #include <QApplication>
63 StdMeshersGUI_NbSegmentsCreator::StdMeshersGUI_NbSegmentsCreator()
64 : StdMeshersGUI_StdHypothesisCreator( "NumberOfSegments" ),
69 #ifndef DISABLE_PLOT2DVIEWER
85 StdMeshersGUI_NbSegmentsCreator::~StdMeshersGUI_NbSegmentsCreator()
89 bool StdMeshersGUI_NbSegmentsCreator::checkParams( QString& msg ) const
91 if( !SMESHGUI_GenericHypothesisCreator::checkParams( msg ) )
93 NbSegmentsHypothesisData data_old, data_new;
94 readParamsFromHypo( data_old );
95 readParamsFromWidgets( data_new );
96 bool res = storeParamsToHypo( data_new );
97 storeParamsToHypo( data_old );
98 res = myNbSeg->isValid( msg, true ) && res;
99 res = myScale->isValid( msg, true ) && res;
103 QFrame* StdMeshersGUI_NbSegmentsCreator::buildFrame()
105 QFrame* fr = new QFrame();
106 fr->setMinimumWidth(460);
108 QVBoxLayout* lay = new QVBoxLayout( fr );
110 lay->setSpacing( SPACING );
112 QGroupBox* GroupC1 = new QGroupBox( tr( "SMESH_ARGUMENTS" ), fr );
113 lay->addWidget( GroupC1 );
115 StdMeshers::StdMeshers_NumberOfSegments_var h =
116 StdMeshers::StdMeshers_NumberOfSegments::_narrow( hypothesis() );
118 myGroupLayout = new QGridLayout( GroupC1 );
119 myGroupLayout->setSpacing( SPACING );
120 myGroupLayout->setMargin( MARGIN );
121 myGroupLayout->setColumnStretch( 0, 0 );
122 myGroupLayout->setColumnStretch( 1, 1 );
129 myName = new QLineEdit( GroupC1 );
130 myGroupLayout->addWidget( new QLabel( tr( "SMESH_NAME" ), GroupC1 ), row, 0 );
131 myGroupLayout->addWidget( myName, row, 1 );
136 // 1) number of segments
137 myGroupLayout->addWidget( new QLabel( tr( "SMESH_NB_SEGMENTS_PARAM" ), GroupC1 ), row, 0 );
138 myNbSeg = new SalomeApp_IntSpinBox( GroupC1 );
139 myNbSeg->setMinimum( 1 );
140 myNbSeg->setMaximum( 9999 );
141 myGroupLayout->addWidget( myNbSeg, row, 1 );
145 // 2) type of distribution
146 myGroupLayout->addWidget( new QLabel( tr( "SMESH_DISTR_TYPE" ), GroupC1 ), row, 0 );
147 myDistr = new QtxComboBox( GroupC1 );
149 types.append( tr( "SMESH_DISTR_REGULAR" ) );
150 types.append( tr( "SMESH_DISTR_SCALE" ) );
151 types.append( tr( "SMESH_DISTR_TAB" ) );
152 types.append( tr( "SMESH_DISTR_EXPR" ) );
153 myDistr->addItems( types );
154 myGroupLayout->addWidget( myDistr, row, 1 );
159 myGroupLayout->addWidget( myLScale = new QLabel( tr( "SMESH_NB_SEGMENTS_SCALE_PARAM" ), GroupC1 ), row, 0 );
160 myScale = new SMESHGUI_SpinBox( GroupC1 );
161 myScale->RangeStepAndValidator( 1E-5, 1E+5, 0.1, "parametric_precision" );
162 myGroupLayout->addWidget( myScale, row, 1 );
166 // 4) Distribution definition
167 QGridLayout* myDistLayout = new QGridLayout(GroupC1);
168 myGroupLayout->addLayout( myDistLayout, row, 0, 1, 2 );
169 myGroupLayout->setRowStretch( row, 1 );
173 QHBoxLayout* myExprLayout = new QHBoxLayout(GroupC1);
174 myExprLayout->addWidget( myLExpr = new QLabel( "f(t)=", GroupC1 ), 0);
175 myExpr = new QLineEdit( GroupC1 );
176 myExprLayout->addWidget( myExpr,1);
177 myDistLayout->addLayout(myExprLayout,1 ,0);
178 myDistLayout->setRowStretch(2, 1);
181 myInfo = new QLabel( tr( "SMESH_FUNC_DOMAIN" ), GroupC1 );
182 myDistLayout->addWidget( myInfo, 0, 0, 1, 2);
185 myTable = new StdMeshersGUI_DistrTableFrame( GroupC1 );
186 myTable->setMinimumHeight(220);
187 myDistLayout->addWidget( myTable, 1, 0, 2, 1 );
189 #ifndef DISABLE_PLOT2DVIEWER
191 myPreview = new StdMeshersGUI_DistrPreview( GroupC1, h.in() );
192 myDistLayout->addWidget( myPreview, 1, 1, 2, 1 );
195 // 5) conversion (radiogroup)
196 myConvBox = new QGroupBox( tr( "SMESH_CONV_MODE" ), GroupC1 );
197 myConv = new QButtonGroup( GroupC1 );
199 QHBoxLayout* convLay = new QHBoxLayout( myConvBox );
200 convLay->setMargin( MARGIN );
201 convLay->setSpacing( SPACING );
203 QRadioButton* rbExp = new QRadioButton( tr( "SMESH_EXP_MODE" ), myConvBox );
204 QRadioButton* myCutNeg = new QRadioButton( tr( "SMESH_CUT_NEG_MODE" ), myConvBox );
206 convLay->addWidget( rbExp );
207 convLay->addWidget( myCutNeg );
208 myConv->addButton( rbExp, 0 );
209 myConv->addButton( myCutNeg, 1 );
211 myGroupLayout->addWidget( myConvBox, row, 0, 1, 2 );
215 // 6) reverse edge parameters
216 myReversedEdgesBox = new QGroupBox(tr( "SMESH_REVERSED_EDGES" ), fr);
217 QHBoxLayout* edgeLay = new QHBoxLayout( myReversedEdgesBox );
219 myDirectionWidget = new StdMeshersGUI_SubShapeSelectorWdg( myReversedEdgesBox );
220 QString aGeomEntry = getShapeEntry();
221 QString aMainEntry = getMainShapeEntry();
222 if ( aGeomEntry == "" )
223 aGeomEntry = h->GetObjectEntry();
224 myDirectionWidget->SetGeomShapeEntry( aGeomEntry, aMainEntry );
225 myDirectionWidget->SetListOfIDs( h->GetReversedEdges() );
226 edgeLay->addWidget( myDirectionWidget );
228 lay->addWidget( myReversedEdgesBox );
229 lay->setStretchFactor( GroupC1, 1);
230 lay->setStretchFactor( myReversedEdgesBox, 1);
232 myReversedEdgesHelper = 0;
233 if ( !aGeomEntry.isEmpty() || !aMainEntry.isEmpty() )
235 myReversedEdgesHelper = new StdMeshersGUI_PropagationHelperWdg( myDirectionWidget, fr, false );
236 lay->addWidget( myReversedEdgesHelper );
237 lay->setStretchFactor( myReversedEdgesHelper, 1 );
240 connect( myNbSeg, SIGNAL( valueChanged( const QString& ) ), this, SLOT( onValueChanged() ) );
241 connect( myDistr, SIGNAL( activated( int ) ), this, SLOT( onValueChanged() ) );
242 connect( myTable, SIGNAL( valueChanged( int, int ) ), this, SLOT( onValueChanged() ) );
243 connect( myExpr, SIGNAL( textChanged( const QString& ) ), this, SLOT( onValueChanged() ) );
244 connect( myConv, SIGNAL( buttonClicked( int ) ), this, SLOT( onValueChanged() ) );
251 void StdMeshersGUI_NbSegmentsCreator::retrieveParams() const
253 NbSegmentsHypothesisData data;
254 readParamsFromHypo( data );
257 myName->setText( data.myName );
258 if(data.myNbSegVarName.isEmpty())
259 myNbSeg->setValue( data.myNbSeg );
261 myNbSeg->setText( data.myNbSegVarName );
263 myDistr->setCurrentIndex( data.myDistrType );
264 if(data.myScaleVarName.isEmpty())
265 myScale->setValue( data.myScale );
267 myScale->setText( data.myScaleVarName );
268 myConv->button( data.myConv )->setChecked( true );
269 myTable->setFuncMinValue(myConv->checkedId()==0 ? -1E20 : 0);
270 myTable->setData( data.myTable );
271 myExpr->setText( data.myExpr );
274 dlg()->setMinimumSize( dlg()->minimumSizeHint().width(), dlg()->minimumSizeHint().height() );
277 QString StdMeshersGUI_NbSegmentsCreator::storeParams() const
279 NbSegmentsHypothesisData data;
280 readParamsFromWidgets( data );
281 storeParamsToHypo( data );
283 QString valStr = QString::number( data.myNbSeg ) += "; ";
287 Regular, //!< equidistant distribution
288 Scale, //!< scale distribution
289 TabFunc, //!< distribution with density function presented by table
290 ExprFunc //!< distribution with density function presented by expression
292 bool hasConv = false;
293 switch ( data.myDistrType ) {
295 valStr += tr("SMESH_DISTR_REGULAR");
298 valStr += tr("SMESH_NB_SEGMENTS_SCALE_PARAM") + " = " + QString::number( data.myScale );\
301 //valStr += tr("SMESH_TAB_FUNC");
303 for( int i=0; i < data.myTable.length(); i++, param = !param ) {
306 valStr += QString::number( data.myTable[ i ]);
307 valStr += ( param ? "," : "]" );
313 valStr += data.myExpr;
320 valStr += "; " + tr("SMESH_CUT_NEG_MODE");
322 valStr += "; " + tr("SMESH_EXP_MODE");
328 bool StdMeshersGUI_NbSegmentsCreator::readParamsFromHypo( NbSegmentsHypothesisData& h_data ) const
330 StdMeshers::StdMeshers_NumberOfSegments_var h =
331 StdMeshers::StdMeshers_NumberOfSegments::_narrow( initParamsHypothesis() );
333 h_data.myName = hypName();
335 h_data.myNbSeg = (int) h->GetNumberOfSegments();
337 CORBA::String_var aVaribaleName = h->GetVarParameter( "SetNumberOfSegments" );
338 h_data.myNbSegVarName = aVaribaleName.in();
340 int distr = (int) h->GetDistrType();
341 h_data.myDistrType = distr;
342 h_data.myScale = distr==1 ? h->GetScaleFactor() : 1.0;
345 aVaribaleName = h->GetVarParameter( "SetScaleFactor" );
346 h_data.myScaleVarName = aVaribaleName.in();
349 h_data.myScaleVarName = QString("");
353 SMESH::double_array* a = h->GetTableFunction();
359 SMESH::double_array& a = h_data.myTable;
360 // by default, constant table function f(t)=1
362 a[0] = 0.0; a[1] = 1.0;
363 a[2] = 1.0; a[3] = 1.0;
366 h_data.myExpr = distr==3 ? h->GetExpressionFunction() : "1";
367 h_data.myConv = distr==2 || distr==3 ? h->ConversionMode() : 1; /*cut negative by default*/
372 bool StdMeshersGUI_NbSegmentsCreator::storeParamsToHypo( const NbSegmentsHypothesisData& h_data ) const
374 StdMeshers::StdMeshers_NumberOfSegments_var h =
375 StdMeshers::StdMeshers_NumberOfSegments::_narrow( hypothesis() );
381 SMESH::SetName( SMESH::FindSObject( h ), h_data.myName.toLatin1().data() );
383 h->SetVarParameter( h_data.myNbSegVarName.toLatin1().constData(), "SetNumberOfSegments" );
384 h->SetNumberOfSegments( h_data.myNbSeg );
385 int distr = h_data.myDistrType;
386 h->SetDistrType( distr );
389 h->SetVarParameter( h_data.myScaleVarName.toLatin1().constData(), "SetScaleFactor" );
390 h->SetScaleFactor( h_data.myScale );
392 if( distr==2 || distr==3 )
393 h->SetConversionMode( h_data.myConv );
395 if( distr==1 || distr==2 || distr==3 ) {
396 h->SetReversedEdges( myDirectionWidget->GetListOfIDs() );
397 h->SetObjectEntry( myDirectionWidget->GetMainShapeEntry() );
401 h->SetTableFunction( h_data.myTable );
404 h->SetExpressionFunction( h_data.myExpr.toLatin1().data() );
405 //setting of function must follow after setConversionMode, because otherwise
406 //the function will be checked with old conversion mode, so that it may occurs
407 //unexpected errors for user
409 catch(const SALOME::SALOME_Exception& ex)
411 SalomeApp_Tools::QtCatchCorbaException(ex);
417 bool StdMeshersGUI_NbSegmentsCreator::readParamsFromWidgets( NbSegmentsHypothesisData& h_data ) const
419 h_data.myName = myName ? myName->text() : "";
420 h_data.myNbSeg = myNbSeg->value();
421 h_data.myNbSegVarName = myNbSeg->text();
422 h_data.myScaleVarName = myScale->text();
423 h_data.myDistrType = myDistr->currentIndex();
424 h_data.myConv = myConv->checkedId();
425 h_data.myScale = myScale->value();
426 myTable->data( h_data.myTable );
427 h_data.myExpr = myExpr->text();
431 void StdMeshersGUI_NbSegmentsCreator::onValueChanged()
433 int distr = myDistr->currentIndex();
435 /* if( distr==2 ) //table func
436 myCutNeg->setText( tr( "SMESH_NO_CONV" ) );
438 myCutNeg->setText( tr( "SMESH_CUT_NEG_MODE" ) );*/
440 if( distr==2 && sender()==myConv ) //table func
442 myTable->setFuncMinValue( myConv->checkedId()==0 ? -1E20 : 0 );
443 SMESH::double_array arr;
444 myTable->data( arr );
445 myTable->setData( arr ); //update data in table
448 myScale->setShown( distr==1 );
449 myLScale->setShown( distr==1 );
450 myReversedEdgesBox->setShown( distr!=0 );
451 if ( myReversedEdgesHelper ) {
452 myReversedEdgesHelper->Clear();
453 myReversedEdgesHelper->setShown( distr!=0 );
455 myDirectionWidget->ShowPreview( distr!=0 );
457 bool isFunc = distr==2 || distr==3;
458 #ifndef DISABLE_PLOT2DVIEWER
459 myPreview->setShown( isFunc );
461 myConvBox->setShown( isFunc );
463 myTable->setShown( distr==2 );
464 myExpr->setShown( distr==3 );
465 myLExpr->setShown( distr==3 );
466 myInfo->setShown( distr==3);
468 #ifndef DISABLE_PLOT2DVIEWER
470 int nbSeg = myNbSeg->value();
471 if( distr==2 ) //preview for table-described function
473 SMESH::double_array a;
475 myPreview->setParams( a, nbSeg, false );
477 else if( distr==3 ) //preview for analytic-described function
478 myPreview->setParams( myExpr->text(), nbSeg, 100, false );
481 myPreview->setConversion( StdMeshersGUI_DistrPreview::Conversion( myConv->checkedId() ) );
484 if ( (QtxComboBox*)sender() == myDistr && dlg() ) {
485 QApplication::instance()->processEvents();
486 myGroupLayout->invalidate();
487 dlg()->layout()->invalidate();
488 dlg()->updateGeometry();
489 dlg()->setMinimumSize( dlg()->minimumSizeHint() );
490 dlg()->resize( dlg()->minimumSize() );
491 QApplication::instance()->processEvents();