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 #include "StdMeshersGUI_DistrPreview.h"
29 #include "StdMeshersGUI_DistrTable.h"
30 #include "StdMeshersGUI_PropagationHelperWdg.h"
31 #include "StdMeshersGUI_SubShapeSelectorWdg.h"
34 #include <SMESHGUI_Utils.h>
35 #include <SMESHGUI_HypothesesUtils.h>
36 #include <SMESHGUI_SpinBox.h>
39 #include CORBA_SERVER_HEADER(SMESH_BasicHypothesis)
41 // SALOME GUI includes
42 #include <SalomeApp_Tools.h>
43 #include <SalomeApp_IntSpinBox.h>
44 #include <QtxComboBox.h>
51 #include <QButtonGroup>
52 #include <QRadioButton>
53 #include <QGridLayout>
54 #include <QVBoxLayout>
55 #include <QHBoxLayout>
56 #include <QApplication>
61 StdMeshersGUI_NbSegmentsCreator::StdMeshersGUI_NbSegmentsCreator()
62 : StdMeshersGUI_StdHypothesisCreator( "NumberOfSegments" ),
81 StdMeshersGUI_NbSegmentsCreator::~StdMeshersGUI_NbSegmentsCreator()
85 bool StdMeshersGUI_NbSegmentsCreator::checkParams( QString& msg ) const
87 if( !SMESHGUI_GenericHypothesisCreator::checkParams( msg ) )
89 NbSegmentsHypothesisData data_old, data_new;
90 readParamsFromHypo( data_old );
91 readParamsFromWidgets( data_new );
92 bool res = storeParamsToHypo( data_new );
93 storeParamsToHypo( data_old );
94 res = myNbSeg->isValid( msg, true ) && res;
95 res = myScale->isValid( msg, true ) && res;
99 QFrame* StdMeshersGUI_NbSegmentsCreator::buildFrame()
101 QFrame* fr = new QFrame();
102 fr->setMinimumWidth(460);
104 QVBoxLayout* lay = new QVBoxLayout( fr );
106 lay->setSpacing( SPACING );
108 QGroupBox* GroupC1 = new QGroupBox( tr( "SMESH_ARGUMENTS" ), fr );
109 lay->addWidget( GroupC1 );
111 StdMeshers::StdMeshers_NumberOfSegments_var h =
112 StdMeshers::StdMeshers_NumberOfSegments::_narrow( hypothesis() );
114 myGroupLayout = new QGridLayout( GroupC1 );
115 myGroupLayout->setSpacing( SPACING );
116 myGroupLayout->setMargin( MARGIN );
117 myGroupLayout->setColumnStretch( 0, 0 );
118 myGroupLayout->setColumnStretch( 1, 1 );
125 myName = new QLineEdit( GroupC1 );
126 myGroupLayout->addWidget( new QLabel( tr( "SMESH_NAME" ), GroupC1 ), row, 0 );
127 myGroupLayout->addWidget( myName, row, 1 );
132 // 1) number of segments
133 myGroupLayout->addWidget( new QLabel( tr( "SMESH_NB_SEGMENTS_PARAM" ), GroupC1 ), row, 0 );
134 myNbSeg = new SalomeApp_IntSpinBox( GroupC1 );
135 myNbSeg->setMinimum( 1 );
136 myNbSeg->setMaximum( 9999 );
137 myGroupLayout->addWidget( myNbSeg, row, 1 );
141 // 2) type of distribution
142 myGroupLayout->addWidget( new QLabel( tr( "SMESH_DISTR_TYPE" ), GroupC1 ), row, 0 );
143 myDistr = new QtxComboBox( GroupC1 );
145 types.append( tr( "SMESH_DISTR_REGULAR" ) );
146 types.append( tr( "SMESH_DISTR_SCALE" ) );
147 types.append( tr( "SMESH_DISTR_TAB" ) );
148 types.append( tr( "SMESH_DISTR_EXPR" ) );
149 myDistr->addItems( types );
150 myGroupLayout->addWidget( myDistr, row, 1 );
155 myGroupLayout->addWidget( myLScale = new QLabel( tr( "SMESH_NB_SEGMENTS_SCALE_PARAM" ), GroupC1 ), row, 0 );
156 myScale = new SMESHGUI_SpinBox( GroupC1 );
157 myScale->RangeStepAndValidator( 1E-5, 1E+5, 0.1, "parametric_precision" );
158 myGroupLayout->addWidget( myScale, row, 1 );
162 // 4) Distribution definition
163 QGridLayout* myDistLayout = new QGridLayout(GroupC1);
164 myGroupLayout->addLayout( myDistLayout, row, 0, 1, 2 );
165 myGroupLayout->setRowStretch( row, 1 );
169 QHBoxLayout* myExprLayout = new QHBoxLayout(GroupC1);
170 myExprLayout->addWidget( myLExpr = new QLabel( "f(t)=", GroupC1 ), 0);
171 myExpr = new QLineEdit( GroupC1 );
172 myExprLayout->addWidget( myExpr,1);
173 myDistLayout->addLayout(myExprLayout,1 ,0);
174 myDistLayout->setRowStretch(2, 1);
177 myInfo = new QLabel( tr( "SMESH_FUNC_DOMAIN" ), GroupC1 );
178 myDistLayout->addWidget( myInfo, 0, 0, 1, 2);
181 myTable = new StdMeshersGUI_DistrTableFrame( GroupC1 );
182 myDistLayout->addWidget( myTable, 1, 0, 2, 1 );
185 myPreview = new StdMeshersGUI_DistrPreview( GroupC1, h.in() );
186 myPreview->setMinimumHeight(220);
187 myDistLayout->addWidget( myPreview, 1, 1, 2, 1 );
189 // 5) conversion (radiogroup)
190 myConvBox = new QGroupBox( tr( "SMESH_CONV_MODE" ), GroupC1 );
191 myConv = new QButtonGroup( GroupC1 );
193 QHBoxLayout* convLay = new QHBoxLayout( myConvBox );
194 convLay->setMargin( MARGIN );
195 convLay->setSpacing( SPACING );
197 QRadioButton* rbExp = new QRadioButton( tr( "SMESH_EXP_MODE" ), myConvBox );
198 QRadioButton* myCutNeg = new QRadioButton( tr( "SMESH_CUT_NEG_MODE" ), myConvBox );
200 convLay->addWidget( rbExp );
201 convLay->addWidget( myCutNeg );
202 myConv->addButton( rbExp, 0 );
203 myConv->addButton( myCutNeg, 1 );
205 myGroupLayout->addWidget( myConvBox, row, 0, 1, 2 );
209 // 6) reverse edge parameters
210 myReversedEdgesBox = new QGroupBox(tr( "SMESH_REVERSED_EDGES" ), fr);
211 QHBoxLayout* edgeLay = new QHBoxLayout( myReversedEdgesBox );
213 myDirectionWidget = new StdMeshersGUI_SubShapeSelectorWdg( myReversedEdgesBox );
214 QString aGeomEntry = getShapeEntry();
215 QString aMainEntry = getMainShapeEntry();
216 if ( aGeomEntry == "" )
217 aGeomEntry = h->GetObjectEntry();
218 myDirectionWidget->SetGeomShapeEntry( aGeomEntry, aMainEntry );
219 myDirectionWidget->SetListOfIDs( h->GetReversedEdges() );
220 edgeLay->addWidget( myDirectionWidget );
222 lay->addWidget( myReversedEdgesBox );
223 lay->setStretchFactor( GroupC1, 1);
224 lay->setStretchFactor( myReversedEdgesBox, 1);
226 myReversedEdgesHelper = 0;
227 if ( !aGeomEntry.isEmpty() || !aMainEntry.isEmpty() )
229 myReversedEdgesHelper = new StdMeshersGUI_PropagationHelperWdg( myDirectionWidget, fr, false );
230 lay->addWidget( myReversedEdgesHelper );
231 lay->setStretchFactor( myReversedEdgesHelper, 1 );
234 connect( myNbSeg, SIGNAL( valueChanged( const QString& ) ), this, SLOT( onValueChanged() ) );
235 connect( myDistr, SIGNAL( activated( int ) ), this, SLOT( onValueChanged() ) );
236 connect( myTable, SIGNAL( valueChanged( int, int ) ), this, SLOT( onValueChanged() ) );
237 connect( myExpr, SIGNAL( textChanged( const QString& ) ), this, SLOT( onValueChanged() ) );
238 connect( myConv, SIGNAL( buttonClicked( int ) ), this, SLOT( onValueChanged() ) );
245 void StdMeshersGUI_NbSegmentsCreator::retrieveParams() const
247 NbSegmentsHypothesisData data;
248 readParamsFromHypo( data );
251 myName->setText( data.myName );
252 if(data.myNbSegVarName.isEmpty())
253 myNbSeg->setValue( data.myNbSeg );
255 myNbSeg->setText( data.myNbSegVarName );
257 myDistr->setCurrentIndex( data.myDistrType );
258 if(data.myScaleVarName.isEmpty())
259 myScale->setValue( data.myScale );
261 myScale->setText( data.myScaleVarName );
262 myConv->button( data.myConv )->setChecked( true );
263 myTable->setFuncMinValue(myConv->checkedId()==0 ? -1E20 : 0);
264 myTable->setData( data.myTable );
265 myExpr->setText( data.myExpr );
268 dlg()->setMinimumSize( dlg()->minimumSizeHint().width(), dlg()->minimumSizeHint().height() );
271 QString StdMeshersGUI_NbSegmentsCreator::storeParams() const
273 NbSegmentsHypothesisData data;
274 readParamsFromWidgets( data );
275 storeParamsToHypo( data );
277 QString valStr = QString::number( data.myNbSeg ) += "; ";
281 Regular, //!< equidistant distribution
282 Scale, //!< scale distribution
283 TabFunc, //!< distribution with density function presented by table
284 ExprFunc //!< distribution with density function presented by expression
286 bool hasConv = false;
287 switch ( data.myDistrType ) {
289 valStr += tr("SMESH_DISTR_REGULAR");
292 valStr += tr("SMESH_NB_SEGMENTS_SCALE_PARAM") + " = " + QString::number( data.myScale );\
295 //valStr += tr("SMESH_TAB_FUNC");
297 for( int i=0; i < data.myTable.length(); i++, param = !param ) {
300 valStr += QString::number( data.myTable[ i ]);
301 valStr += ( param ? "," : "]" );
307 valStr += data.myExpr;
314 valStr += "; " + tr("SMESH_CUT_NEG_MODE");
316 valStr += "; " + tr("SMESH_EXP_MODE");
322 bool StdMeshersGUI_NbSegmentsCreator::readParamsFromHypo( NbSegmentsHypothesisData& h_data ) const
324 StdMeshers::StdMeshers_NumberOfSegments_var h =
325 StdMeshers::StdMeshers_NumberOfSegments::_narrow( initParamsHypothesis() );
327 h_data.myName = hypName();
329 h_data.myNbSeg = (int) h->GetNumberOfSegments();
331 CORBA::String_var aVaribaleName = h->GetVarParameter( "SetNumberOfSegments" );
332 h_data.myNbSegVarName = aVaribaleName.in();
334 int distr = (int) h->GetDistrType();
335 h_data.myDistrType = distr;
336 h_data.myScale = distr==1 ? h->GetScaleFactor() : 1.0;
339 aVaribaleName = h->GetVarParameter( "SetScaleFactor" );
340 h_data.myScaleVarName = aVaribaleName.in();
343 h_data.myScaleVarName = QString("");
347 SMESH::double_array* a = h->GetTableFunction();
353 SMESH::double_array& a = h_data.myTable;
354 // by default, constant table function f(t)=1
356 a[0] = 0.0; a[1] = 1.0;
357 a[2] = 1.0; a[3] = 1.0;
360 h_data.myExpr = distr==3 ? h->GetExpressionFunction() : "1";
361 h_data.myConv = distr==2 || distr==3 ? h->ConversionMode() : 1; /*cut negative by default*/
366 bool StdMeshersGUI_NbSegmentsCreator::storeParamsToHypo( const NbSegmentsHypothesisData& h_data ) const
368 StdMeshers::StdMeshers_NumberOfSegments_var h =
369 StdMeshers::StdMeshers_NumberOfSegments::_narrow( hypothesis() );
375 SMESH::SetName( SMESH::FindSObject( h ), h_data.myName.toLatin1().data() );
377 h->SetVarParameter( h_data.myNbSegVarName.toLatin1().constData(), "SetNumberOfSegments" );
378 h->SetNumberOfSegments( h_data.myNbSeg );
379 int distr = h_data.myDistrType;
380 h->SetDistrType( distr );
383 h->SetVarParameter( h_data.myScaleVarName.toLatin1().constData(), "SetScaleFactor" );
384 h->SetScaleFactor( h_data.myScale );
386 if( distr==2 || distr==3 )
387 h->SetConversionMode( h_data.myConv );
389 if( distr==1 || distr==2 || distr==3 ) {
390 h->SetReversedEdges( myDirectionWidget->GetListOfIDs() );
391 h->SetObjectEntry( myDirectionWidget->GetMainShapeEntry() );
395 h->SetTableFunction( h_data.myTable );
398 h->SetExpressionFunction( h_data.myExpr.toLatin1().data() );
399 //setting of function must follow after setConversionMode, because otherwise
400 //the function will be checked with old conversion mode, so that it may occurs
401 //unexpected errors for user
403 catch(const SALOME::SALOME_Exception& ex)
405 SalomeApp_Tools::QtCatchCorbaException(ex);
411 bool StdMeshersGUI_NbSegmentsCreator::readParamsFromWidgets( NbSegmentsHypothesisData& h_data ) const
413 h_data.myName = myName ? myName->text() : "";
414 h_data.myNbSeg = myNbSeg->value();
415 h_data.myNbSegVarName = myNbSeg->text();
416 h_data.myScaleVarName = myScale->text();
417 h_data.myDistrType = myDistr->currentIndex();
418 h_data.myConv = myConv->checkedId();
419 h_data.myScale = myScale->value();
420 myTable->data( h_data.myTable );
421 h_data.myExpr = myExpr->text();
425 void StdMeshersGUI_NbSegmentsCreator::onValueChanged()
427 int distr = myDistr->currentIndex();
429 /* if( distr==2 ) //table func
430 myCutNeg->setText( tr( "SMESH_NO_CONV" ) );
432 myCutNeg->setText( tr( "SMESH_CUT_NEG_MODE" ) );*/
434 if( distr==2 && sender()==myConv ) //table func
436 myTable->setFuncMinValue( myConv->checkedId()==0 ? -1E20 : 0 );
437 SMESH::double_array arr;
438 myTable->data( arr );
439 myTable->setData( arr ); //update data in table
442 myScale->setShown( distr==1 );
443 myLScale->setShown( distr==1 );
444 myReversedEdgesBox->setShown( distr!=0 );
445 if ( myReversedEdgesHelper ) {
446 myReversedEdgesHelper->Clear();
447 myReversedEdgesHelper->setShown( distr!=0 );
449 myDirectionWidget->ShowPreview( distr!=0 );
451 bool isFunc = distr==2 || distr==3;
452 myPreview->setShown( isFunc );
453 myConvBox->setShown( isFunc );
455 myTable->setShown( distr==2 );
456 myExpr->setShown( distr==3 );
457 myLExpr->setShown( distr==3 );
458 myInfo->setShown( distr==3);
461 int nbSeg = myNbSeg->value();
462 if( distr==2 ) //preview for table-described function
464 SMESH::double_array a;
466 myPreview->setParams( a, nbSeg, false );
468 else if( distr==3 ) //preview for analytic-described function
469 myPreview->setParams( myExpr->text(), nbSeg, 100, false );
472 myPreview->setConversion( StdMeshersGUI_DistrPreview::Conversion( myConv->checkedId() ) );
474 if ( (QtxComboBox*)sender() == myDistr && dlg() ) {
475 QApplication::instance()->processEvents();
476 myGroupLayout->invalidate();
477 dlg()->layout()->invalidate();
478 dlg()->updateGeometry();
479 dlg()->setMinimumSize( dlg()->minimumSizeHint() );
480 dlg()->resize( dlg()->minimumSize() );
481 QApplication::instance()->processEvents();