1 // Copyright (C) 2007-2008 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.
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
22 // File : StdMeshersGUI_StdHypothesisCreator.cxx
23 // Author : Alexander SOLOVYOV, Open CASCADE S.A.S.
26 #include "StdMeshersGUI_StdHypothesisCreator.h"
29 #include <SMESHGUI_SpinBox.h>
30 #include <SMESHGUI_HypothesesUtils.h>
31 #include <SMESHGUI_Utils.h>
32 #include <SMESH_TypeFilter.hxx>
33 #include <SMESH_NumberFilter.hxx>
34 #include <StdMeshersGUI_ObjectReferenceParamWdg.h>
35 #include <StdMeshersGUI_LayerDistributionParamWdg.h>
37 // SALOME GUI includes
38 #include <SUIT_ResourceMgr.h>
41 #include <SALOMEconfig.h>
42 #include CORBA_SERVER_HEADER(SMESH_BasicHypothesis)
43 #include CORBA_SERVER_HEADER(SMESH_Mesh)
46 #include <QHBoxLayout>
51 const double VALUE_MAX = 1.0e+15, // COORD_MAX
52 VALUE_MAX_2 = VALUE_MAX * VALUE_MAX,
53 VALUE_MAX_3 = VALUE_MAX_2 * VALUE_MAX,
54 VALUE_SMALL = 1.0e-15,
55 VALUE_SMALL_2 = VALUE_SMALL * VALUE_SMALL,
56 VALUE_SMALL_3 = VALUE_SMALL_2 * VALUE_SMALL;
58 //================================================================================
61 * \param type - hypothesis type
63 //================================================================================
65 StdMeshersGUI_StdHypothesisCreator::StdMeshersGUI_StdHypothesisCreator( const QString& type )
66 : SMESHGUI_GenericHypothesisCreator( type )
70 //================================================================================
74 //================================================================================
76 StdMeshersGUI_StdHypothesisCreator::~StdMeshersGUI_StdHypothesisCreator()
80 //================================================================================
82 * \brief Return widget for i-th hypothesis parameter (got from myParamWidgets)
83 * \param i - index of hypothesis parameter
84 * \retval QWidget* - found widget
86 //================================================================================
88 QWidget* StdMeshersGUI_StdHypothesisCreator::getWidgetForParam( int i ) const
91 if ( isCreation() ) ++i; // skip widget of 'name' parameter
93 if ( i < myCustomWidgets.count() ) {
94 QList<QWidget*>::const_iterator anIt = myCustomWidgets.begin();
95 QList<QWidget*>::const_iterator aLast = myCustomWidgets.end();
96 for ( int j = 0 ; !w && anIt != aLast; ++anIt, ++j )
101 // list has no at() const, so we iterate
102 QList<QWidget*>::const_iterator anIt = widgets().begin();
103 QList<QWidget*>::const_iterator aLast = widgets().end();
104 for( int j = 0; !w && anIt!=aLast; anIt++, ++j ) {
112 //================================================================================
114 * \brief Allow modifing myCustomWidgets in const methods
115 * \retval ListOfWidgets* - non-const pointer to myCustomWidgets
117 //================================================================================
119 StdMeshersGUI_StdHypothesisCreator::ListOfWidgets*
120 StdMeshersGUI_StdHypothesisCreator::customWidgets() const
122 return const_cast< ListOfWidgets* >( & myCustomWidgets );
125 //================================================================================
127 * \brief Builds dlg layout
128 * \retval QFrame* - the built widget
130 //================================================================================
132 QFrame* StdMeshersGUI_StdHypothesisCreator::buildFrame()
134 return buildStdFrame();
137 //================================================================================
139 * \brief Initialise parameter values in controls
141 //================================================================================
143 void StdMeshersGUI_StdHypothesisCreator::retrieveParams() const
145 // buildStdFrame() sets values itself calling stdParams()
147 if ( hypType().startsWith("ProjectionSource" ))
149 // we use this method to connect depending custom widgets
150 StdMeshersGUI_ObjectReferenceParamWdg* widgetToActivate = 0;
151 ListOfWidgets::const_iterator anIt = myCustomWidgets.begin();
152 for ( ; anIt != myCustomWidgets.end(); anIt++)
154 if ( *anIt && (*anIt)->inherits("StdMeshersGUI_ObjectReferenceParamWdg"))
156 StdMeshersGUI_ObjectReferenceParamWdg * w1 =
157 ( StdMeshersGUI_ObjectReferenceParamWdg* ) ( *anIt );
158 ListOfWidgets::const_iterator anIt2 = anIt;
159 for ( ++anIt2; anIt2 != myCustomWidgets.end(); anIt2++)
160 if ( *anIt2 && (*anIt2)->inherits("StdMeshersGUI_ObjectReferenceParamWdg"))
162 StdMeshersGUI_ObjectReferenceParamWdg * w2 =
163 ( StdMeshersGUI_ObjectReferenceParamWdg* ) ( *anIt2 );
164 w1->AvoidSimultaneousSelection( w2 );
166 if ( !widgetToActivate )
167 widgetToActivate = w1;
170 if ( widgetToActivate )
171 widgetToActivate->activateSelection();
175 dlg()->setMinimumSize( dlg()->minimumSizeHint().width(), dlg()->minimumSizeHint().height() );
180 //================================================================================
182 * \brief Widget: slider with left and right labels
184 //================================================================================
186 class TDoubleSliderWith2Lables: public QWidget
189 TDoubleSliderWith2Lables( const QString& leftLabel, const QString& rightLabel,
190 const double initValue, const double bottom,
191 const double top , const double precision,
192 QWidget * parent=0 , const char * name=0 )
193 :QWidget(parent), _bottom(bottom), _precision(precision)
197 QHBoxLayout* aHBoxL = new QHBoxLayout(this);
199 if ( !leftLabel.isEmpty() ) {
200 QLabel* aLeftLabel = new QLabel( this );
201 aLeftLabel->setText( leftLabel );
202 aHBoxL->addWidget( aLeftLabel );
205 _slider = new QSlider( Qt::Horizontal, this );
206 _slider->setRange( 0, toInt( top ));
207 _slider->setValue( toInt( initValue ));
208 aHBoxL->addWidget( _slider );
210 if ( !rightLabel.isEmpty() ) {
211 QLabel* aRightLabel = new QLabel( this );
212 aRightLabel->setText( rightLabel );
213 aHBoxL->addWidget( aRightLabel );
218 double value() const { return _bottom + _slider->value() * _precision; }
219 QSlider * getSlider() const { return _slider; }
220 int toInt( double val ) const { return (int) ceil(( val - _bottom ) / _precision ); }
222 double _bottom, _precision;
226 //================================================================================
228 * \brief Retrieve GEOM_Object held by widget
230 //================================================================================
232 inline GEOM::GEOM_Object_var geomFromWdg(const QWidget* wdg)
234 const StdMeshersGUI_ObjectReferenceParamWdg * objRefWdg =
235 dynamic_cast<const StdMeshersGUI_ObjectReferenceParamWdg*>( wdg );
237 return objRefWdg->GetObject< GEOM::GEOM_Object >();
239 return GEOM::GEOM_Object::_nil();
241 //================================================================================
243 * \brief Retrieve SMESH_Mesh held by widget
245 //================================================================================
247 inline SMESH::SMESH_Mesh_var meshFromWdg(const QWidget* wdg)
249 const StdMeshersGUI_ObjectReferenceParamWdg * objRefWdg =
250 dynamic_cast<const StdMeshersGUI_ObjectReferenceParamWdg*>( wdg );
252 return objRefWdg->GetObject< SMESH::SMESH_Mesh >();
254 return SMESH::SMESH_Mesh::_nil();
256 //================================================================================
258 * \brief creates a filter for selection of shapes of given dimension
259 * \param dim - dimension
260 * \param subShapeType - required type of subshapes, number of which must be \a nbSubShapes
261 * \param nbSubShapes - number of subshapes of given type
262 * \param closed - required closeness flag of a shape
263 * \retval SUIT_SelectionFilter* - created filter
265 //================================================================================
267 SUIT_SelectionFilter* filterForShapeOfDim(const int dim,
268 TopAbs_ShapeEnum subShapeType = TopAbs_SHAPE,
269 const int nbSubShapes = 0,
272 TColStd_MapOfInteger shapeTypes;
274 case 0: shapeTypes.Add( TopAbs_VERTEX ); break;
276 if ( subShapeType == TopAbs_SHAPE ) subShapeType = TopAbs_EDGE;
277 shapeTypes.Add( TopAbs_EDGE );
278 shapeTypes.Add( TopAbs_COMPOUND ); // for a group
281 if ( subShapeType == TopAbs_SHAPE ) subShapeType = TopAbs_FACE;
282 shapeTypes.Add( TopAbs_FACE );
283 shapeTypes.Add( TopAbs_COMPOUND ); // for a group
286 shapeTypes.Add( TopAbs_SHELL );
287 shapeTypes.Add( TopAbs_SOLID );
288 shapeTypes.Add( TopAbs_COMPSOLID );
289 shapeTypes.Add( TopAbs_COMPOUND );
292 return new SMESH_NumberFilter("GEOM", subShapeType, nbSubShapes,
293 shapeTypes, GEOM::GEOM_Object::_nil(), closed);
296 //================================================================================
298 * \brief Create a widget for object selection
299 * \param object - initial object
300 * \param filter - selection filter
301 * \retval QWidget* - created widget
303 //================================================================================
305 QWidget* newObjRefParamWdg( SUIT_SelectionFilter* filter,
306 CORBA::Object_var object)
308 StdMeshersGUI_ObjectReferenceParamWdg* w =
309 new StdMeshersGUI_ObjectReferenceParamWdg( filter, 0);
310 w->SetObject( object.in() );
314 //================================================================================
316 * \brief calls deactivateSelection() for StdMeshersGUI_ObjectReferenceParamWdg
317 * \param widgetList - list of widgets
319 //================================================================================
321 void deactivateObjRefParamWdg( QList<QWidget*>* widgetList )
323 StdMeshersGUI_ObjectReferenceParamWdg* w = 0;
324 QList<QWidget*>::iterator anIt = widgetList->begin();
325 QList<QWidget*>::iterator aLast = widgetList->end();
326 for ( ; anIt != aLast; anIt++ ) {
327 if ( (*anIt) && (*anIt)->inherits( "StdMeshersGUI_ObjectReferenceParamWdg" ))
329 w = (StdMeshersGUI_ObjectReferenceParamWdg* )( *anIt );
330 w->deactivateSelection();
336 //================================================================================
338 * \brief Check parameter values before accept()
339 * \retval bool - true if OK
341 //================================================================================
343 bool StdMeshersGUI_StdHypothesisCreator::checkParams() const
345 // check if object reference parameter is set, as it has no default value
347 if ( hypType().startsWith("ProjectionSource" ))
349 StdMeshersGUI_ObjectReferenceParamWdg* w =
350 widget< StdMeshersGUI_ObjectReferenceParamWdg >( 0 );
351 ok = ( w->IsObjectSelected() );
352 if ( !ok ) w->SetObject( CORBA::Object::_nil() );
353 int nbAssocVert = ( hypType() == "ProjectionSource1D" ? 1 : 2 );
354 for ( int i = 0; ok && i < nbAssocVert; i += 2)
357 StdMeshersGUI_ObjectReferenceParamWdg* w1 =
358 widget< StdMeshersGUI_ObjectReferenceParamWdg >( i+2 );
359 StdMeshersGUI_ObjectReferenceParamWdg* w2 =
360 widget< StdMeshersGUI_ObjectReferenceParamWdg >( i+3 );
361 srcV = w1->GetValue();
362 tgtV = w2->GetValue();
363 ok = (( srcV.isEmpty() && tgtV.isEmpty() ) ||
364 ( !srcV.isEmpty() && !tgtV.isEmpty() && srcV != tgtV ));
366 w1->SetObject( CORBA::Object::_nil() );
367 w2->SetObject( CORBA::Object::_nil() );
371 // Uninstall filters of StdMeshersGUI_ObjectReferenceParamWdg
373 deactivateObjRefParamWdg( customWidgets() );
375 else if ( hypType() == "LayerDistribution" )
377 StdMeshersGUI_LayerDistributionParamWdg* w =
378 widget< StdMeshersGUI_LayerDistributionParamWdg >( 0 );
379 ok = ( w && w->IsOk() );
384 //================================================================================
386 * \brief Store params from GUI controls to a hypothesis
387 * \retval QString - text representation of parameters
389 //================================================================================
391 QString StdMeshersGUI_StdHypothesisCreator::storeParams() const
393 ListOfStdParams params;
394 bool res = getStdParamFromDlg( params );
397 SMESH::SetName( SMESH::FindSObject( hypothesis() ), params[0].myValue.toString().toLatin1().data() );
398 params.erase( params.begin() );
401 QString valueStr = stdParamValues( params );
403 if( res && !params.isEmpty() )
405 if( hypType()=="LocalLength" )
407 StdMeshers::StdMeshers_LocalLength_var h =
408 StdMeshers::StdMeshers_LocalLength::_narrow( hypothesis() );
410 h->SetLength( params[0].myValue.toDouble() );
411 h->SetPrecision( params[1].myValue.toDouble() );
413 else if( hypType()=="MaxLength" )
415 StdMeshers::StdMeshers_MaxLength_var h =
416 StdMeshers::StdMeshers_MaxLength::_narrow( hypothesis() );
418 h->SetLength( params[0].myValue.toDouble() );
419 h->SetUsePreestimatedLength( widget< QCheckBox >( 1 )->isChecked() );
420 if ( !h->HavePreestimatedLength() && !h->_is_equivalent( initParamsHypothesis() )) {
421 StdMeshers::StdMeshers_MaxLength_var hInit =
422 StdMeshers::StdMeshers_MaxLength::_narrow( initParamsHypothesis() );
423 h->SetPreestimatedLength( hInit->GetPreestimatedLength() );
426 else if( hypType()=="SegmentLengthAroundVertex" )
428 StdMeshers::StdMeshers_SegmentLengthAroundVertex_var h =
429 StdMeshers::StdMeshers_SegmentLengthAroundVertex::_narrow( hypothesis() );
431 h->SetLength( params[0].myValue.toDouble() );
433 else if( hypType()=="Arithmetic1D" )
435 StdMeshers::StdMeshers_Arithmetic1D_var h =
436 StdMeshers::StdMeshers_Arithmetic1D::_narrow( hypothesis() );
438 h->SetLength( params[0].myValue.toDouble(), true );
439 h->SetLength( params[1].myValue.toDouble(), false );
441 else if( hypType()=="MaxElementArea" )
443 StdMeshers::StdMeshers_MaxElementArea_var h =
444 StdMeshers::StdMeshers_MaxElementArea::_narrow( hypothesis() );
446 h->SetMaxElementArea( params[0].myValue.toDouble() );
448 else if( hypType()=="MaxElementVolume" )
450 StdMeshers::StdMeshers_MaxElementVolume_var h =
451 StdMeshers::StdMeshers_MaxElementVolume::_narrow( hypothesis() );
453 h->SetMaxElementVolume( params[0].myValue.toDouble() );
455 else if( hypType()=="StartEndLength" )
457 StdMeshers::StdMeshers_StartEndLength_var h =
458 StdMeshers::StdMeshers_StartEndLength::_narrow( hypothesis() );
460 h->SetLength( params[0].myValue.toDouble(), true );
461 h->SetLength( params[1].myValue.toDouble(), false );
463 else if( hypType()=="Deflection1D" )
465 StdMeshers::StdMeshers_Deflection1D_var h =
466 StdMeshers::StdMeshers_Deflection1D::_narrow( hypothesis() );
468 h->SetDeflection( params[0].myValue.toDouble() );
470 else if( hypType()=="AutomaticLength" )
472 StdMeshers::StdMeshers_AutomaticLength_var h =
473 StdMeshers::StdMeshers_AutomaticLength::_narrow( hypothesis() );
475 h->SetFineness( params[0].myValue.toDouble() );
477 else if( hypType()=="NumberOfLayers" )
479 StdMeshers::StdMeshers_NumberOfLayers_var h =
480 StdMeshers::StdMeshers_NumberOfLayers::_narrow( hypothesis() );
482 h->SetNumberOfLayers( params[0].myValue.toInt() );
484 else if( hypType()=="LayerDistribution" )
486 StdMeshers::StdMeshers_LayerDistribution_var h =
487 StdMeshers::StdMeshers_LayerDistribution::_narrow( hypothesis() );
488 StdMeshersGUI_LayerDistributionParamWdg* w =
489 widget< StdMeshersGUI_LayerDistributionParamWdg >( 0 );
491 h->SetLayerDistribution( w->GetHypothesis() );
493 else if( hypType()=="ProjectionSource1D" )
495 StdMeshers::StdMeshers_ProjectionSource1D_var h =
496 StdMeshers::StdMeshers_ProjectionSource1D::_narrow( hypothesis() );
498 h->SetSourceEdge ( geomFromWdg ( getWidgetForParam( 0 )));
499 h->SetSourceMesh ( meshFromWdg ( getWidgetForParam( 1 )));
500 h->SetVertexAssociation( geomFromWdg ( getWidgetForParam( 2 )),
501 geomFromWdg ( getWidgetForParam( 3 )));
503 else if( hypType()=="ProjectionSource2D" )
505 StdMeshers::StdMeshers_ProjectionSource2D_var h =
506 StdMeshers::StdMeshers_ProjectionSource2D::_narrow( hypothesis() );
508 h->SetSourceFace ( geomFromWdg ( getWidgetForParam( 0 )));
509 h->SetSourceMesh ( meshFromWdg ( getWidgetForParam( 1 )));
510 h->SetVertexAssociation( geomFromWdg ( getWidgetForParam( 2 )), // src1
511 geomFromWdg ( getWidgetForParam( 4 )), // src2
512 geomFromWdg ( getWidgetForParam( 3 )), // tgt1
513 geomFromWdg ( getWidgetForParam( 5 ))); // tgt2
515 else if( hypType()=="ProjectionSource3D" )
517 StdMeshers::StdMeshers_ProjectionSource3D_var h =
518 StdMeshers::StdMeshers_ProjectionSource3D::_narrow( hypothesis() );
520 h->SetSource3DShape ( geomFromWdg ( getWidgetForParam( 0 )));
521 h->SetSourceMesh ( meshFromWdg ( getWidgetForParam( 1 )));
522 h->SetVertexAssociation( geomFromWdg ( getWidgetForParam( 2 )), // src1
523 geomFromWdg ( getWidgetForParam( 4 )), // src2
524 geomFromWdg ( getWidgetForParam( 3 )), // tgt1
525 geomFromWdg ( getWidgetForParam( 5 ))); // tgt2
531 //================================================================================
533 * \brief Return parameter values as SMESHGUI_GenericHypothesisCreator::StdParam
534 * \param p - list of parameters
535 * \retval bool - success flag
537 * Is called from SMESHGUI_GenericHypothesisCreator::buildStdFrame().
538 * Parameters will be shown using "standard" controls:
539 * Int by QtxIntSpinBox
540 * Double by SMESHGUI_SpinBox
541 * String by QLineEdit
542 * getCustomWidget() allows to redefine control for a parameter
544 //================================================================================
546 bool StdMeshersGUI_StdHypothesisCreator::stdParams( ListOfStdParams& p ) const
549 SMESHGUI_GenericHypothesisCreator::StdParam item;
552 customWidgets()->clear();
555 HypothesisData* data = SMESH::GetHypothesisData( hypType() );
556 item.myName = tr( "SMESH_NAME" );
557 item.myValue = data ? hypName() : QString();
559 customWidgets()->append(0);
562 SMESH::SMESH_Hypothesis_var hyp = initParamsHypothesis();
564 if( hypType()=="LocalLength" )
566 StdMeshers::StdMeshers_LocalLength_var h =
567 StdMeshers::StdMeshers_LocalLength::_narrow( hyp );
569 item.myName = tr("SMESH_LOCAL_LENGTH_PARAM");
570 item.myValue = h->GetLength();
572 item.myName = tr("SMESH_LOCAL_LENGTH_PRECISION");
573 item.myValue = h->GetPrecision();
576 else if( hypType()=="MaxLength" )
578 StdMeshers::StdMeshers_MaxLength_var h =
579 StdMeshers::StdMeshers_MaxLength::_narrow( hyp );
580 // try to set a right preestimated length to edited hypothesis
581 bool noPreestimatedAtEdition = false;
582 if ( !isCreation() ) {
583 StdMeshers::StdMeshers_MaxLength_var initHyp =
584 StdMeshers::StdMeshers_MaxLength::_narrow( initParamsHypothesis(true) );
585 noPreestimatedAtEdition =
586 ( initHyp->_is_nil() || !initHyp->HavePreestimatedLength() );
587 if ( !noPreestimatedAtEdition )
588 h->SetPreestimatedLength( initHyp->GetPreestimatedLength() );
591 item.myName = tr("SMESH_LOCAL_LENGTH_PARAM");
592 item.myValue = h->GetLength();
594 customWidgets()->append(0);
596 item.myName = tr("SMESH_USE_PREESTIMATED_LENGTH");
598 QCheckBox* aQCheckBox = new QCheckBox(dlg());
599 if ( !noPreestimatedAtEdition && h->HavePreestimatedLength() ) {
600 aQCheckBox->setChecked( h->GetUsePreestimatedLength() );
601 connect( aQCheckBox, SIGNAL( stateChanged(int) ), this, SLOT( onValueChanged() ) );
604 aQCheckBox->setChecked( false );
605 aQCheckBox->setEnabled( false );
607 customWidgets()->append( aQCheckBox );
609 else if( hypType()=="SegmentLengthAroundVertex" )
611 StdMeshers::StdMeshers_SegmentLengthAroundVertex_var h =
612 StdMeshers::StdMeshers_SegmentLengthAroundVertex::_narrow( hyp );
614 item.myName = tr("SMESH_LOCAL_LENGTH_PARAM");
615 item.myValue = h->GetLength();
618 else if( hypType()=="Arithmetic1D" )
620 StdMeshers::StdMeshers_Arithmetic1D_var h =
621 StdMeshers::StdMeshers_Arithmetic1D::_narrow( hyp );
623 item.myName = tr( "SMESH_START_LENGTH_PARAM" );
624 item.myValue = h->GetLength( true );
626 item.myName = tr( "SMESH_END_LENGTH_PARAM" );
627 item.myValue = h->GetLength( false );
630 else if( hypType()=="MaxElementArea" )
632 StdMeshers::StdMeshers_MaxElementArea_var h =
633 StdMeshers::StdMeshers_MaxElementArea::_narrow( hyp );
635 item.myName = tr( "SMESH_MAX_ELEMENT_AREA_PARAM" );
636 item.myValue = h->GetMaxElementArea();
639 else if( hypType()=="MaxElementVolume" )
641 StdMeshers::StdMeshers_MaxElementVolume_var h =
642 StdMeshers::StdMeshers_MaxElementVolume::_narrow( hyp );
644 item.myName = tr( "SMESH_MAX_ELEMENT_VOLUME_PARAM" );
645 item.myValue = h->GetMaxElementVolume();
648 else if( hypType()=="StartEndLength" )
650 StdMeshers::StdMeshers_StartEndLength_var h =
651 StdMeshers::StdMeshers_StartEndLength::_narrow( hyp );
653 item.myName = tr( "SMESH_START_LENGTH_PARAM" );
654 item.myValue = h->GetLength( true );
656 item.myName = tr( "SMESH_END_LENGTH_PARAM" );
657 item.myValue = h->GetLength( false );
660 else if( hypType()=="Deflection1D" )
662 StdMeshers::StdMeshers_Deflection1D_var h =
663 StdMeshers::StdMeshers_Deflection1D::_narrow( hyp );
665 item.myName = tr( "SMESH_DEFLECTION1D_PARAM" );
666 item.myValue = h->GetDeflection();
669 else if( hypType()=="AutomaticLength" )
671 StdMeshers::StdMeshers_AutomaticLength_var h =
672 StdMeshers::StdMeshers_AutomaticLength::_narrow( hyp );
674 item.myName = tr( "SMESH_FINENESS_PARAM" );
675 //item.myValue = h->GetFineness();
677 customWidgets()->append
678 ( new TDoubleSliderWith2Lables( "0 ", " 1", h->GetFineness(), 0, 1, 0.01, 0 ));
680 else if( hypType()=="NumberOfLayers" )
682 StdMeshers::StdMeshers_NumberOfLayers_var h =
683 StdMeshers::StdMeshers_NumberOfLayers::_narrow( hyp );
685 item.myName = tr( "SMESH_NUMBER_OF_LAYERS" );
686 item.myValue = (int) h->GetNumberOfLayers();
689 else if( hypType()=="LayerDistribution" )
691 StdMeshers::StdMeshers_LayerDistribution_var h =
692 StdMeshers::StdMeshers_LayerDistribution::_narrow( hyp );
694 item.myName = tr( "SMESH_LAYERS_DISTRIBUTION" ); p.append( item );
695 customWidgets()->append
696 ( new StdMeshersGUI_LayerDistributionParamWdg( h->GetLayerDistribution(), hypName(), dlg()));
698 else if( hypType()=="ProjectionSource1D" )
700 StdMeshers::StdMeshers_ProjectionSource1D_var h =
701 StdMeshers::StdMeshers_ProjectionSource1D::_narrow( hyp );
703 item.myName = tr( "SMESH_SOURCE_EDGE" ); p.append( item );
704 customWidgets()->append( newObjRefParamWdg( filterForShapeOfDim( 1 ),
705 h->GetSourceEdge()));
706 item.myName = tr( "SMESH_SOURCE_MESH" ); p.append( item );
707 customWidgets()->append( newObjRefParamWdg( new SMESH_TypeFilter( MESH ),
708 h->GetSourceMesh()));
709 item.myName = tr( "SMESH_SOURCE_VERTEX" ); p.append( item );
710 customWidgets()->append( newObjRefParamWdg( filterForShapeOfDim( 0 ),
711 h->GetSourceVertex()));
712 item.myName = tr( "SMESH_TARGET_VERTEX" ); p.append( item );
713 customWidgets()->append( newObjRefParamWdg( filterForShapeOfDim( 0 ),
714 h->GetTargetVertex()));
716 else if( hypType()=="ProjectionSource2D" )
718 StdMeshers::StdMeshers_ProjectionSource2D_var h =
719 StdMeshers::StdMeshers_ProjectionSource2D::_narrow( hyp );
721 item.myName = tr( "SMESH_SOURCE_FACE" ); p.append( item );
722 customWidgets()->append( newObjRefParamWdg( filterForShapeOfDim( 2 ),
723 h->GetSourceFace()));
724 item.myName = tr( "SMESH_SOURCE_MESH" ); p.append( item );
725 customWidgets()->append( newObjRefParamWdg( new SMESH_TypeFilter( MESH ),
726 h->GetSourceMesh()));
727 item.myName = tr( "SMESH_SOURCE_VERTEX1" ); p.append( item );
728 customWidgets()->append( newObjRefParamWdg( filterForShapeOfDim( 0 ),
729 h->GetSourceVertex( 1 )));
730 item.myName = tr( "SMESH_TARGET_VERTEX1" ); p.append( item );
731 customWidgets()->append( newObjRefParamWdg( filterForShapeOfDim( 0 ),
732 h->GetTargetVertex( 1 )));
733 item.myName = tr( "SMESH_SOURCE_VERTEX2" ); p.append( item );
734 customWidgets()->append( newObjRefParamWdg( filterForShapeOfDim( 0 ),
735 h->GetSourceVertex( 2 )));
736 item.myName = tr( "SMESH_TARGET_VERTEX2" ); p.append( item );
737 customWidgets()->append( newObjRefParamWdg( filterForShapeOfDim( 0 ),
738 h->GetTargetVertex( 2 )));
740 else if( hypType()=="ProjectionSource3D" )
742 StdMeshers::StdMeshers_ProjectionSource3D_var h =
743 StdMeshers::StdMeshers_ProjectionSource3D::_narrow( hyp );
745 item.myName = tr( "SMESH_SOURCE_3DSHAPE" ); p.append( item );
746 customWidgets()->append( newObjRefParamWdg( filterForShapeOfDim( 3, TopAbs_FACE, 6, true ),
747 h->GetSource3DShape()));
748 item.myName = tr( "SMESH_SOURCE_MESH" ); p.append( item );
749 customWidgets()->append( newObjRefParamWdg( new SMESH_TypeFilter( MESH ),
750 h->GetSourceMesh()));
751 item.myName = tr( "SMESH_SOURCE_VERTEX1" ); p.append( item );
752 customWidgets()->append( newObjRefParamWdg( filterForShapeOfDim( 0 ),
753 h->GetSourceVertex( 1 )));
754 item.myName = tr( "SMESH_TARGET_VERTEX1" ); p.append( item );
755 customWidgets()->append( newObjRefParamWdg( filterForShapeOfDim( 0 ),
756 h->GetTargetVertex( 1 )));
757 item.myName = tr( "SMESH_SOURCE_VERTEX2" ); p.append( item );
758 customWidgets()->append( newObjRefParamWdg( filterForShapeOfDim( 0 ),
759 h->GetSourceVertex( 2 )));
760 item.myName = tr( "SMESH_TARGET_VERTEX2" ); p.append( item );
761 customWidgets()->append( newObjRefParamWdg( filterForShapeOfDim( 0 ),
762 h->GetTargetVertex( 2 )));
769 //================================================================================
771 * \brief tune "standard" control
772 * \param w - control widget
773 * \param int - parameter index
775 //================================================================================
777 void StdMeshersGUI_StdHypothesisCreator::attuneStdWidget (QWidget* w, const int) const
779 SMESHGUI_SpinBox* sb = w->inherits( "SMESHGUI_SpinBox" ) ? ( SMESHGUI_SpinBox* )w : 0;
780 if( hypType()=="LocalLength" && sb )
782 if (sb->objectName() == tr("SMESH_LOCAL_LENGTH_PARAM"))
783 sb->RangeStepAndValidator( VALUE_SMALL, VALUE_MAX, 1.0, 6 );
784 else if (sb->objectName() == tr("SMESH_LOCAL_LENGTH_PRECISION"))
785 sb->RangeStepAndValidator( 0.0, 1.0, 0.05, 7 );
787 else if( hypType()=="Arithmetic1D" && sb )
789 sb->RangeStepAndValidator( VALUE_SMALL, VALUE_MAX, 1.0, 6 );
791 else if( hypType()=="MaxLength" && sb )
793 sb->RangeStepAndValidator( VALUE_SMALL, VALUE_MAX, 1.0, 6 );
794 sb->setEnabled( !widget< QCheckBox >( 1 )->isChecked() );
796 else if( hypType()=="MaxElementArea" && sb )
798 sb->RangeStepAndValidator( VALUE_SMALL_2, VALUE_MAX_2, 1.0, 6 );
800 else if( hypType()=="MaxElementVolume" && sb )
802 sb->RangeStepAndValidator( VALUE_SMALL_3, VALUE_MAX_3, 1.0, 6 );
804 else if( hypType()=="StartEndLength" && sb )
806 sb->RangeStepAndValidator( VALUE_SMALL, VALUE_MAX, 1.0, 6 );
808 else if( hypType()=="Deflection1D" && sb )
810 sb->RangeStepAndValidator( VALUE_SMALL, VALUE_MAX, 1.0, 6 );
812 else if ( sb ) // default validator for possible ancestors
814 sb->RangeStepAndValidator( VALUE_SMALL, VALUE_MAX, 1.0, 6 );
818 //================================================================================
820 * \brief Return dlg title
821 * \retval QString - title string
823 //================================================================================
825 QString StdMeshersGUI_StdHypothesisCreator::caption() const
827 return tr( QString( "SMESH_%1_TITLE" ).arg( hypTypeName( hypType() ) ).toLatin1().data() );
830 //================================================================================
832 * \brief return pixmap for dlg icon
835 //================================================================================
837 QPixmap StdMeshersGUI_StdHypothesisCreator::icon() const
839 QString hypIconName = tr( QString( "ICON_DLG_%1" ).arg( hypTypeName( hypType() ) ).toLatin1().data() );
840 return SMESHGUI::resourceMgr()->loadPixmap( "SMESH", hypIconName );
843 //================================================================================
845 * \brief Return hypothesis type name to show in dlg
848 //================================================================================
850 QString StdMeshersGUI_StdHypothesisCreator::type() const
852 return tr( QString( "SMESH_%1_HYPOTHESIS" ).arg( hypTypeName( hypType() ) ).toLatin1().data() );
855 //================================================================================
857 * \brief String to insert in "SMESH_%1_HYPOTHESIS" to get hypothesis type name
858 * from message resouce file
859 * \param t - hypothesis type
860 * \retval QString - result string
862 //================================================================================
864 QString StdMeshersGUI_StdHypothesisCreator::hypTypeName( const QString& t ) const
866 static QMap<QString,QString> types;
867 if( types.isEmpty() )
869 types.insert( "LocalLength", "LOCAL_LENGTH" );
870 types.insert( "NumberOfSegments", "NB_SEGMENTS" );
871 types.insert( "MaxElementArea", "MAX_ELEMENT_AREA" );
872 types.insert( "MaxElementVolume", "MAX_ELEMENT_VOLUME" );
873 types.insert( "StartEndLength", "START_END_LENGTH" );
874 types.insert( "Deflection1D", "DEFLECTION1D" );
875 types.insert( "Arithmetic1D", "ARITHMETIC_1D" );
876 types.insert( "AutomaticLength", "AUTOMATIC_LENGTH" );
877 types.insert( "ProjectionSource1D", "PROJECTION_SOURCE_1D" );
878 types.insert( "ProjectionSource2D", "PROJECTION_SOURCE_2D" );
879 types.insert( "ProjectionSource3D", "PROJECTION_SOURCE_3D" );
880 types.insert( "NumberOfLayers", "NUMBER_OF_LAYERS" );
881 types.insert( "LayerDistribution", "LAYER_DISTRIBUTION" );
882 types.insert( "SegmentLengthAroundVertex", "SEGMENT_LENGTH_AROUND_VERTEX" );
883 types.insert( "MaxLength", "MAX_LENGTH" );
887 if( types.contains( t ) )
894 //=======================================================================
895 //function : getCustomWidget
896 //purpose : is called from buildStdFrame()
897 //=======================================================================
899 QWidget* StdMeshersGUI_StdHypothesisCreator::getCustomWidget( const StdParam & param,
901 const int index) const
904 if ( index < customWidgets()->count() ) {
905 w = customWidgets()->at( index );
907 w->setParent( parent );
908 w->move( QPoint( 0, 0 ) );
914 //================================================================================
916 * \brief Set param value taken from a custom widget
917 * \param param - SMESHGUI_GenericHypothesisCreator::StdParam structure
918 * \param widget - widget presenting param
919 * \retval bool - success flag
921 * this method is called from getStdParamFromDlg()
923 //================================================================================
925 bool StdMeshersGUI_StdHypothesisCreator::getParamFromCustomWidget( StdParam & param,
926 QWidget* widget) const
928 if ( hypType()=="AutomaticLength" ) {
929 TDoubleSliderWith2Lables* w = dynamic_cast<TDoubleSliderWith2Lables*>( widget );
931 param.myValue = w->value();
935 if ( hypType() == "MaxLength" ) {
939 if ( widget->inherits( "StdMeshersGUI_ObjectReferenceParamWdg" ))
941 // show only 1st reference value
942 if ( true /*widget == getWidgetForParam( 0 )*/) {
943 const StdMeshersGUI_ObjectReferenceParamWdg * w =
944 static_cast<const StdMeshersGUI_ObjectReferenceParamWdg*>( widget );
945 param.myValue = w->GetValue();
949 if ( widget->inherits( "StdMeshersGUI_LayerDistributionParamWdg" ))
951 const StdMeshersGUI_LayerDistributionParamWdg * w =
952 static_cast<const StdMeshersGUI_LayerDistributionParamWdg*>( widget );
953 param.myValue = w->GetValue();
959 //================================================================================
961 * \brief called when operation cancelled
963 //================================================================================
965 void StdMeshersGUI_StdHypothesisCreator::onReject()
967 if ( hypType().startsWith("ProjectionSource" ))
969 // Uninstall filters of StdMeshersGUI_ObjectReferenceParamWdg
970 deactivateObjRefParamWdg( customWidgets() );
974 //================================================================================
978 //================================================================================
980 void StdMeshersGUI_StdHypothesisCreator::valueChanged( QWidget* paramWidget)
982 if ( hypType() == "MaxLength" && paramWidget == getWidgetForParam(1) ) {
983 getWidgetForParam(0)->setEnabled( !widget< QCheckBox >( 1 )->isChecked() );
984 if ( !getWidgetForParam(0)->isEnabled() ) {
985 StdMeshers::StdMeshers_MaxLength_var h =
986 StdMeshers::StdMeshers_MaxLength::_narrow( initParamsHypothesis() );
987 widget< QtxDoubleSpinBox >( 0 )->setValue( h->GetPreestimatedLength() );