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"
36 #include <SALOMEDSClient_Study.hxx>
38 // SALOME GUI includes
39 #include <SUIT_ResourceMgr.h>
42 #include <SALOMEconfig.h>
43 #include CORBA_SERVER_HEADER(SMESH_BasicHypothesis)
44 #include CORBA_SERVER_HEADER(SMESH_Mesh)
47 #include <QHBoxLayout>
52 const double VALUE_MAX = 1.0e+15, // COORD_MAX
53 VALUE_MAX_2 = VALUE_MAX * VALUE_MAX,
54 VALUE_MAX_3 = VALUE_MAX_2 * VALUE_MAX,
55 VALUE_SMALL = 1.0e-15,
56 VALUE_SMALL_2 = VALUE_SMALL * VALUE_SMALL,
57 VALUE_SMALL_3 = VALUE_SMALL_2 * VALUE_SMALL;
59 //================================================================================
62 * \param type - hypothesis type
64 //================================================================================
66 StdMeshersGUI_StdHypothesisCreator::StdMeshersGUI_StdHypothesisCreator( const QString& type )
67 : SMESHGUI_GenericHypothesisCreator( type )
71 //================================================================================
75 //================================================================================
77 StdMeshersGUI_StdHypothesisCreator::~StdMeshersGUI_StdHypothesisCreator()
81 //================================================================================
83 * \brief Return widget for i-th hypothesis parameter (got from myParamWidgets)
84 * \param i - index of hypothesis parameter
85 * \retval QWidget* - found widget
87 //================================================================================
89 QWidget* StdMeshersGUI_StdHypothesisCreator::getWidgetForParam( int i ) const
92 if ( isCreation() ) ++i; // skip widget of 'name' parameter
94 if ( i < myCustomWidgets.count() ) {
95 QList<QWidget*>::const_iterator anIt = myCustomWidgets.begin();
96 QList<QWidget*>::const_iterator aLast = myCustomWidgets.end();
97 for ( int j = 0 ; !w && anIt != aLast; ++anIt, ++j )
102 // list has no at() const, so we iterate
103 QList<QWidget*>::const_iterator anIt = widgets().begin();
104 QList<QWidget*>::const_iterator aLast = widgets().end();
105 for( int j = 0; !w && anIt!=aLast; anIt++, ++j ) {
113 //================================================================================
115 * \brief Allow modifing myCustomWidgets in const methods
116 * \retval ListOfWidgets* - non-const pointer to myCustomWidgets
118 //================================================================================
120 StdMeshersGUI_StdHypothesisCreator::ListOfWidgets*
121 StdMeshersGUI_StdHypothesisCreator::customWidgets() const
123 return const_cast< ListOfWidgets* >( & myCustomWidgets );
126 //================================================================================
128 * \brief Builds dlg layout
129 * \retval QFrame* - the built widget
131 //================================================================================
133 QFrame* StdMeshersGUI_StdHypothesisCreator::buildFrame()
135 return buildStdFrame();
138 //================================================================================
140 * \brief Initialise parameter values in controls
142 //================================================================================
144 void StdMeshersGUI_StdHypothesisCreator::retrieveParams() const
146 // buildStdFrame() sets values itself calling stdParams()
148 if ( hypType().startsWith("ProjectionSource" ))
150 // we use this method to connect depending custom widgets
151 StdMeshersGUI_ObjectReferenceParamWdg* widgetToActivate = 0;
152 ListOfWidgets::const_iterator anIt = myCustomWidgets.begin();
153 for ( ; anIt != myCustomWidgets.end(); anIt++)
155 if ( *anIt && (*anIt)->inherits("StdMeshersGUI_ObjectReferenceParamWdg"))
157 StdMeshersGUI_ObjectReferenceParamWdg * w1 =
158 ( StdMeshersGUI_ObjectReferenceParamWdg* ) ( *anIt );
159 ListOfWidgets::const_iterator anIt2 = anIt;
160 for ( ++anIt2; anIt2 != myCustomWidgets.end(); anIt2++)
161 if ( *anIt2 && (*anIt2)->inherits("StdMeshersGUI_ObjectReferenceParamWdg"))
163 StdMeshersGUI_ObjectReferenceParamWdg * w2 =
164 ( StdMeshersGUI_ObjectReferenceParamWdg* ) ( *anIt2 );
165 w1->AvoidSimultaneousSelection( w2 );
167 if ( !widgetToActivate )
168 widgetToActivate = w1;
171 if ( widgetToActivate )
172 widgetToActivate->activateSelection();
176 dlg()->setMinimumSize( dlg()->minimumSizeHint().width(), dlg()->minimumSizeHint().height() );
181 //================================================================================
183 * \brief Widget: slider with left and right labels
185 //================================================================================
187 class TDoubleSliderWith2Lables: public QWidget
190 TDoubleSliderWith2Lables( const QString& leftLabel, const QString& rightLabel,
191 const double initValue, const double bottom,
192 const double top , const double precision,
193 QWidget * parent=0 , const char * name=0 )
194 :QWidget(parent), _bottom(bottom), _precision(precision)
198 QHBoxLayout* aHBoxL = new QHBoxLayout(this);
200 if ( !leftLabel.isEmpty() ) {
201 QLabel* aLeftLabel = new QLabel( this );
202 aLeftLabel->setText( leftLabel );
203 aHBoxL->addWidget( aLeftLabel );
206 _slider = new QSlider( Qt::Horizontal, this );
207 _slider->setRange( 0, toInt( top ));
208 _slider->setValue( toInt( initValue ));
209 aHBoxL->addWidget( _slider );
211 if ( !rightLabel.isEmpty() ) {
212 QLabel* aRightLabel = new QLabel( this );
213 aRightLabel->setText( rightLabel );
214 aHBoxL->addWidget( aRightLabel );
219 double value() const { return _bottom + _slider->value() * _precision; }
220 QSlider * getSlider() const { return _slider; }
221 int toInt( double val ) const { return (int) ceil(( val - _bottom ) / _precision ); }
223 double _bottom, _precision;
227 //================================================================================
229 * \brief Retrieve GEOM_Object held by widget
231 //================================================================================
233 inline GEOM::GEOM_Object_var geomFromWdg(const QWidget* wdg)
235 const StdMeshersGUI_ObjectReferenceParamWdg * objRefWdg =
236 dynamic_cast<const StdMeshersGUI_ObjectReferenceParamWdg*>( wdg );
238 return objRefWdg->GetObject< GEOM::GEOM_Object >();
240 return GEOM::GEOM_Object::_nil();
242 //================================================================================
244 * \brief Retrieve SMESH_Mesh held by widget
246 //================================================================================
248 inline SMESH::SMESH_Mesh_var meshFromWdg(const QWidget* wdg)
250 const StdMeshersGUI_ObjectReferenceParamWdg * objRefWdg =
251 dynamic_cast<const StdMeshersGUI_ObjectReferenceParamWdg*>( wdg );
253 return objRefWdg->GetObject< SMESH::SMESH_Mesh >();
255 return SMESH::SMESH_Mesh::_nil();
257 //================================================================================
259 * \brief creates a filter for selection of shapes of given dimension
260 * \param dim - dimension
261 * \param subShapeType - required type of subshapes, number of which must be \a nbSubShapes
262 * \param nbSubShapes - number of subshapes of given type
263 * \param closed - required closeness flag of a shape
264 * \retval SUIT_SelectionFilter* - created filter
266 //================================================================================
268 SUIT_SelectionFilter* filterForShapeOfDim(const int dim,
269 TopAbs_ShapeEnum subShapeType = TopAbs_SHAPE,
270 const int nbSubShapes = 0,
273 TColStd_MapOfInteger shapeTypes;
275 case 0: shapeTypes.Add( TopAbs_VERTEX ); break;
277 if ( subShapeType == TopAbs_SHAPE ) subShapeType = TopAbs_EDGE;
278 shapeTypes.Add( TopAbs_EDGE );
279 shapeTypes.Add( TopAbs_COMPOUND ); // for a group
282 if ( subShapeType == TopAbs_SHAPE ) subShapeType = TopAbs_FACE;
283 shapeTypes.Add( TopAbs_FACE );
284 shapeTypes.Add( TopAbs_COMPOUND ); // for a group
287 shapeTypes.Add( TopAbs_SHELL );
288 shapeTypes.Add( TopAbs_SOLID );
289 shapeTypes.Add( TopAbs_COMPSOLID );
290 shapeTypes.Add( TopAbs_COMPOUND );
293 return new SMESH_NumberFilter("GEOM", subShapeType, nbSubShapes,
294 shapeTypes, GEOM::GEOM_Object::_nil(), closed);
297 //================================================================================
299 * \brief Create a widget for object selection
300 * \param object - initial object
301 * \param filter - selection filter
302 * \retval QWidget* - created widget
304 //================================================================================
306 QWidget* newObjRefParamWdg( SUIT_SelectionFilter* filter,
307 CORBA::Object_var object)
309 StdMeshersGUI_ObjectReferenceParamWdg* w =
310 new StdMeshersGUI_ObjectReferenceParamWdg( filter, 0);
311 w->SetObject( object.in() );
315 //================================================================================
317 * \brief calls deactivateSelection() for StdMeshersGUI_ObjectReferenceParamWdg
318 * \param widgetList - list of widgets
320 //================================================================================
322 void deactivateObjRefParamWdg( QList<QWidget*>* widgetList )
324 StdMeshersGUI_ObjectReferenceParamWdg* w = 0;
325 QList<QWidget*>::iterator anIt = widgetList->begin();
326 QList<QWidget*>::iterator aLast = widgetList->end();
327 for ( ; anIt != aLast; anIt++ ) {
328 if ( (*anIt) && (*anIt)->inherits( "StdMeshersGUI_ObjectReferenceParamWdg" ))
330 w = (StdMeshersGUI_ObjectReferenceParamWdg* )( *anIt );
331 w->deactivateSelection();
337 //================================================================================
339 * \brief Check parameter values before accept()
340 * \retval bool - true if OK
342 //================================================================================
344 bool StdMeshersGUI_StdHypothesisCreator::checkParams( QString& msg ) const
346 if( !SMESHGUI_GenericHypothesisCreator::checkParams( msg ) )
349 // check if object reference parameter is set, as it has no default value
351 if ( hypType().startsWith("ProjectionSource" ))
353 StdMeshersGUI_ObjectReferenceParamWdg* w =
354 widget< StdMeshersGUI_ObjectReferenceParamWdg >( 0 );
355 ok = ( w->IsObjectSelected() );
356 if ( !ok ) w->SetObject( CORBA::Object::_nil() );
357 int nbAssocVert = ( hypType() == "ProjectionSource1D" ? 1 : 2 );
358 for ( int i = 0; ok && i < nbAssocVert; i += 2)
361 StdMeshersGUI_ObjectReferenceParamWdg* w1 =
362 widget< StdMeshersGUI_ObjectReferenceParamWdg >( i+2 );
363 StdMeshersGUI_ObjectReferenceParamWdg* w2 =
364 widget< StdMeshersGUI_ObjectReferenceParamWdg >( i+3 );
365 srcV = w1->GetValue();
366 tgtV = w2->GetValue();
367 ok = (( srcV.isEmpty() && tgtV.isEmpty() ) ||
368 ( !srcV.isEmpty() && !tgtV.isEmpty() && srcV != tgtV ));
370 w1->SetObject( CORBA::Object::_nil() );
371 w2->SetObject( CORBA::Object::_nil() );
375 // Uninstall filters of StdMeshersGUI_ObjectReferenceParamWdg
377 deactivateObjRefParamWdg( customWidgets() );
379 else if ( hypType() == "LayerDistribution" )
381 StdMeshersGUI_LayerDistributionParamWdg* w =
382 widget< StdMeshersGUI_LayerDistributionParamWdg >( 0 );
383 ok = ( w && w->IsOk() );
388 //================================================================================
390 * \brief Store params from GUI controls to a hypothesis
391 * \retval QString - text representation of parameters
393 //================================================================================
395 QString StdMeshersGUI_StdHypothesisCreator::storeParams() const
397 ListOfStdParams params;
398 bool res = getStdParamFromDlg( params );
401 SMESH::SetName( SMESH::FindSObject( hypothesis() ), params[0].myValue.toString().toLatin1().data() );
402 params.erase( params.begin() );
405 QString valueStr = stdParamValues( params );
406 QStringList aVariablesList = getVariablesFromDlg();
408 if( res && !params.isEmpty() )
410 if( hypType()=="LocalLength" )
412 StdMeshers::StdMeshers_LocalLength_var h =
413 StdMeshers::StdMeshers_LocalLength::_narrow( hypothesis() );
415 h->SetLength( params[0].myValue.toDouble() );
416 h->SetParameters(SMESHGUI::JoinObjectParameters(aVariablesList));
417 h->SetPrecision( params[1].myValue.toDouble() );
418 h->SetParameters(SMESHGUI::JoinObjectParameters(aVariablesList));
420 else if( hypType()=="MaxLength" )
422 StdMeshers::StdMeshers_MaxLength_var h =
423 StdMeshers::StdMeshers_MaxLength::_narrow( hypothesis() );
425 h->SetLength( params[0].myValue.toDouble() );
426 h->SetParameters(SMESHGUI::JoinObjectParameters(aVariablesList));
427 h->SetUsePreestimatedLength( widget< QCheckBox >( 1 )->isChecked() );
428 if ( !h->HavePreestimatedLength() && !h->_is_equivalent( initParamsHypothesis() )) {
429 StdMeshers::StdMeshers_MaxLength_var hInit =
430 StdMeshers::StdMeshers_MaxLength::_narrow( initParamsHypothesis() );
431 h->SetPreestimatedLength( hInit->GetPreestimatedLength() );
434 else if( hypType()=="SegmentLengthAroundVertex" )
436 StdMeshers::StdMeshers_SegmentLengthAroundVertex_var h =
437 StdMeshers::StdMeshers_SegmentLengthAroundVertex::_narrow( hypothesis() );
439 h->SetLength( params[0].myValue.toDouble() );
440 h->SetParameters(SMESHGUI::JoinObjectParameters(aVariablesList));
442 else if( hypType()=="Arithmetic1D" )
444 StdMeshers::StdMeshers_Arithmetic1D_var h =
445 StdMeshers::StdMeshers_Arithmetic1D::_narrow( hypothesis() );
447 h->SetLength( params[0].myValue.toDouble(), true );
448 h->SetParameters(SMESHGUI::JoinObjectParameters(aVariablesList));
449 h->SetLength( params[1].myValue.toDouble(), false );
450 h->SetParameters(SMESHGUI::JoinObjectParameters(aVariablesList));
452 else if( hypType()=="MaxElementArea" )
454 StdMeshers::StdMeshers_MaxElementArea_var h =
455 StdMeshers::StdMeshers_MaxElementArea::_narrow( hypothesis() );
456 h->SetParameters(SMESHGUI::JoinObjectParameters(aVariablesList));
457 h->SetMaxElementArea( params[0].myValue.toDouble() );
459 else if( hypType()=="MaxElementVolume" )
461 StdMeshers::StdMeshers_MaxElementVolume_var h =
462 StdMeshers::StdMeshers_MaxElementVolume::_narrow( hypothesis() );
464 h->SetMaxElementVolume( params[0].myValue.toDouble() );
465 h->SetParameters(SMESHGUI::JoinObjectParameters(aVariablesList));
467 else if( hypType()=="StartEndLength" )
469 StdMeshers::StdMeshers_StartEndLength_var h =
470 StdMeshers::StdMeshers_StartEndLength::_narrow( hypothesis() );
472 h->SetLength( params[0].myValue.toDouble(), true );
473 h->SetParameters(SMESHGUI::JoinObjectParameters(aVariablesList));
474 h->SetLength( params[1].myValue.toDouble(), false );
475 h->SetParameters(SMESHGUI::JoinObjectParameters(aVariablesList));
477 else if( hypType()=="Deflection1D" )
479 StdMeshers::StdMeshers_Deflection1D_var h =
480 StdMeshers::StdMeshers_Deflection1D::_narrow( hypothesis() );
481 h->SetParameters(SMESHGUI::JoinObjectParameters(aVariablesList));
482 h->SetDeflection( params[0].myValue.toDouble() );
484 else if( hypType()=="AutomaticLength" )
486 StdMeshers::StdMeshers_AutomaticLength_var h =
487 StdMeshers::StdMeshers_AutomaticLength::_narrow( hypothesis() );
489 h->SetFineness( params[0].myValue.toDouble() );
491 else if( hypType()=="NumberOfLayers" )
493 StdMeshers::StdMeshers_NumberOfLayers_var h =
494 StdMeshers::StdMeshers_NumberOfLayers::_narrow( hypothesis() );
496 h->SetNumberOfLayers( params[0].myValue.toInt() );
497 h->SetParameters(SMESHGUI::JoinObjectParameters(aVariablesList));
499 else if( hypType()=="LayerDistribution" )
501 StdMeshers::StdMeshers_LayerDistribution_var h =
502 StdMeshers::StdMeshers_LayerDistribution::_narrow( hypothesis() );
503 StdMeshersGUI_LayerDistributionParamWdg* w =
504 widget< StdMeshersGUI_LayerDistributionParamWdg >( 0 );
506 h->SetLayerDistribution( w->GetHypothesis() );
507 h->SetParameters(w->GetHypothesis()->GetParameters());
508 w->GetHypothesis()->ClearParameters();
510 else if( hypType()=="ProjectionSource1D" )
512 StdMeshers::StdMeshers_ProjectionSource1D_var h =
513 StdMeshers::StdMeshers_ProjectionSource1D::_narrow( hypothesis() );
515 h->SetSourceEdge ( geomFromWdg ( getWidgetForParam( 0 )));
516 h->SetSourceMesh ( meshFromWdg ( getWidgetForParam( 1 )));
517 h->SetVertexAssociation( geomFromWdg ( getWidgetForParam( 2 )),
518 geomFromWdg ( getWidgetForParam( 3 )));
520 else if( hypType()=="ProjectionSource2D" )
522 StdMeshers::StdMeshers_ProjectionSource2D_var h =
523 StdMeshers::StdMeshers_ProjectionSource2D::_narrow( hypothesis() );
525 h->SetSourceFace ( geomFromWdg ( getWidgetForParam( 0 )));
526 h->SetSourceMesh ( meshFromWdg ( getWidgetForParam( 1 )));
527 h->SetVertexAssociation( geomFromWdg ( getWidgetForParam( 2 )), // src1
528 geomFromWdg ( getWidgetForParam( 4 )), // src2
529 geomFromWdg ( getWidgetForParam( 3 )), // tgt1
530 geomFromWdg ( getWidgetForParam( 5 ))); // tgt2
532 else if( hypType()=="ProjectionSource3D" )
534 StdMeshers::StdMeshers_ProjectionSource3D_var h =
535 StdMeshers::StdMeshers_ProjectionSource3D::_narrow( hypothesis() );
537 h->SetSource3DShape ( geomFromWdg ( getWidgetForParam( 0 )));
538 h->SetSourceMesh ( meshFromWdg ( getWidgetForParam( 1 )));
539 h->SetVertexAssociation( geomFromWdg ( getWidgetForParam( 2 )), // src1
540 geomFromWdg ( getWidgetForParam( 4 )), // src2
541 geomFromWdg ( getWidgetForParam( 3 )), // tgt1
542 geomFromWdg ( getWidgetForParam( 5 ))); // tgt2
548 //================================================================================
550 * \brief Return parameter values as SMESHGUI_GenericHypothesisCreator::StdParam
551 * \param p - list of parameters
552 * \retval bool - success flag
554 * Is called from SMESHGUI_GenericHypothesisCreator::buildStdFrame().
555 * Parameters will be shown using "standard" controls:
556 * Int by QtxIntSpinBox
557 * Double by SMESHGUI_SpinBox
558 * String by QLineEdit
559 * getCustomWidget() allows to redefine control for a parameter
561 //================================================================================
563 bool StdMeshersGUI_StdHypothesisCreator::stdParams( ListOfStdParams& p ) const
566 SMESHGUI_GenericHypothesisCreator::StdParam item;
569 customWidgets()->clear();
572 HypothesisData* data = SMESH::GetHypothesisData( hypType() );
573 item.myName = tr( "SMESH_NAME" );
574 item.myValue = data ? hypName() : QString();
576 customWidgets()->append(0);
579 SMESH::SMESH_Hypothesis_var hyp = initParamsHypothesis();
580 SMESH::ListOfParameters_var aParameters = hyp->GetLastParameters();
582 if( hypType()=="LocalLength" )
584 StdMeshers::StdMeshers_LocalLength_var h =
585 StdMeshers::StdMeshers_LocalLength::_narrow( hyp );
587 item.myName = tr("SMESH_LOCAL_LENGTH_PARAM");
588 if(!initVariableName(aParameters,item,0))
589 item.myValue = h->GetLength();
592 item.myName = tr("SMESH_LOCAL_LENGTH_PRECISION");
593 if(!initVariableName(aParameters,item,1))
594 item.myValue = h->GetPrecision();
598 else if( hypType()=="MaxLength" )
600 StdMeshers::StdMeshers_MaxLength_var h =
601 StdMeshers::StdMeshers_MaxLength::_narrow( hyp );
602 // try to set a right preestimated length to edited hypothesis
603 bool noPreestimatedAtEdition = false;
604 if ( !isCreation() ) {
605 StdMeshers::StdMeshers_MaxLength_var initHyp =
606 StdMeshers::StdMeshers_MaxLength::_narrow( initParamsHypothesis(true) );
607 noPreestimatedAtEdition =
608 ( initHyp->_is_nil() || !initHyp->HavePreestimatedLength() );
609 if ( !noPreestimatedAtEdition )
610 h->SetPreestimatedLength( initHyp->GetPreestimatedLength() );
613 item.myName = tr("SMESH_LOCAL_LENGTH_PARAM");
614 if(!initVariableName(aParameters,item,0))
615 item.myValue = h->GetLength();
617 customWidgets()->append(0);
619 item.myName = tr("SMESH_USE_PREESTIMATED_LENGTH");
621 QCheckBox* aQCheckBox = new QCheckBox(dlg());
622 if ( !noPreestimatedAtEdition && h->HavePreestimatedLength() ) {
623 aQCheckBox->setChecked( h->GetUsePreestimatedLength() );
624 connect( aQCheckBox, SIGNAL( stateChanged(int) ), this, SLOT( onValueChanged() ) );
627 aQCheckBox->setChecked( false );
628 aQCheckBox->setEnabled( false );
630 customWidgets()->append( aQCheckBox );
632 else if( hypType()=="SegmentLengthAroundVertex" )
634 StdMeshers::StdMeshers_SegmentLengthAroundVertex_var h =
635 StdMeshers::StdMeshers_SegmentLengthAroundVertex::_narrow( hyp );
637 item.myName = tr("SMESH_LOCAL_LENGTH_PARAM");
638 if(!initVariableName(aParameters,item,0))
639 item.myValue = h->GetLength();
643 else if( hypType()=="Arithmetic1D" )
645 StdMeshers::StdMeshers_Arithmetic1D_var h =
646 StdMeshers::StdMeshers_Arithmetic1D::_narrow( hyp );
648 item.myName = tr( "SMESH_START_LENGTH_PARAM" );
649 if(!initVariableName(aParameters,item,0))
650 item.myValue = h->GetLength( true );
653 item.myName = tr( "SMESH_END_LENGTH_PARAM" );
654 if(!initVariableName(aParameters,item,1))
655 item.myValue = h->GetLength( false );
658 else if( hypType()=="MaxElementArea" )
660 StdMeshers::StdMeshers_MaxElementArea_var h =
661 StdMeshers::StdMeshers_MaxElementArea::_narrow( hyp );
663 item.myName = tr( "SMESH_MAX_ELEMENT_AREA_PARAM" );
664 if(!initVariableName(aParameters,item,0))
665 item.myValue = h->GetMaxElementArea();
669 else if( hypType()=="MaxElementVolume" )
671 StdMeshers::StdMeshers_MaxElementVolume_var h =
672 StdMeshers::StdMeshers_MaxElementVolume::_narrow( hyp );
674 item.myName = tr( "SMESH_MAX_ELEMENT_VOLUME_PARAM" );
675 if(!initVariableName(aParameters,item,0))
676 item.myValue = h->GetMaxElementVolume();
679 else if( hypType()=="StartEndLength" )
681 StdMeshers::StdMeshers_StartEndLength_var h =
682 StdMeshers::StdMeshers_StartEndLength::_narrow( hyp );
684 item.myName = tr( "SMESH_START_LENGTH_PARAM" );
686 if(!initVariableName(aParameters,item,0))
687 item.myValue = h->GetLength( true );
690 item.myName = tr( "SMESH_END_LENGTH_PARAM" );
691 if(!initVariableName(aParameters,item,1))
692 item.myValue = h->GetLength( false );
696 else if( hypType()=="Deflection1D" )
698 StdMeshers::StdMeshers_Deflection1D_var h =
699 StdMeshers::StdMeshers_Deflection1D::_narrow( hyp );
701 item.myName = tr( "SMESH_DEFLECTION1D_PARAM" );
702 if(!initVariableName(aParameters,item,0))
703 item.myValue = h->GetDeflection();
706 else if( hypType()=="AutomaticLength" )
708 StdMeshers::StdMeshers_AutomaticLength_var h =
709 StdMeshers::StdMeshers_AutomaticLength::_narrow( hyp );
711 item.myName = tr( "SMESH_FINENESS_PARAM" );
712 //item.myValue = h->GetFineness();
714 customWidgets()->append
715 ( new TDoubleSliderWith2Lables( "0 ", " 1", h->GetFineness(), 0, 1, 0.01, 0 ));
717 else if( hypType()=="NumberOfLayers" )
719 StdMeshers::StdMeshers_NumberOfLayers_var h =
720 StdMeshers::StdMeshers_NumberOfLayers::_narrow( hyp );
722 item.myName = tr( "SMESH_NUMBER_OF_LAYERS" );
723 if(!initVariableName(aParameters,item,0))
724 item.myValue = (int) h->GetNumberOfLayers();
727 else if( hypType()=="LayerDistribution" )
729 StdMeshers::StdMeshers_LayerDistribution_var h =
730 StdMeshers::StdMeshers_LayerDistribution::_narrow( hyp );
732 item.myName = tr( "SMESH_LAYERS_DISTRIBUTION" ); p.append( item );
734 //Set into not published hypo last variables
735 QStringList aLastVarsList;
736 for(int i = 0;i<aParameters->length();i++)
737 aLastVarsList.append(QString(aParameters[i].in()));
739 if(!aLastVarsList.isEmpty())
740 h->GetLayerDistribution()->SetLastParameters(SMESHGUI::JoinObjectParameters(aLastVarsList));
742 customWidgets()->append
743 ( new StdMeshersGUI_LayerDistributionParamWdg( h->GetLayerDistribution(), hypName(), dlg()));
745 else if( hypType()=="ProjectionSource1D" )
747 StdMeshers::StdMeshers_ProjectionSource1D_var h =
748 StdMeshers::StdMeshers_ProjectionSource1D::_narrow( hyp );
750 item.myName = tr( "SMESH_SOURCE_EDGE" ); p.append( item );
751 customWidgets()->append( newObjRefParamWdg( filterForShapeOfDim( 1 ),
752 h->GetSourceEdge()));
753 item.myName = tr( "SMESH_SOURCE_MESH" ); p.append( item );
754 customWidgets()->append( newObjRefParamWdg( new SMESH_TypeFilter( MESH ),
755 h->GetSourceMesh()));
756 item.myName = tr( "SMESH_SOURCE_VERTEX" ); p.append( item );
757 customWidgets()->append( newObjRefParamWdg( filterForShapeOfDim( 0 ),
758 h->GetSourceVertex()));
759 item.myName = tr( "SMESH_TARGET_VERTEX" ); p.append( item );
760 customWidgets()->append( newObjRefParamWdg( filterForShapeOfDim( 0 ),
761 h->GetTargetVertex()));
763 else if( hypType()=="ProjectionSource2D" )
765 StdMeshers::StdMeshers_ProjectionSource2D_var h =
766 StdMeshers::StdMeshers_ProjectionSource2D::_narrow( hyp );
768 item.myName = tr( "SMESH_SOURCE_FACE" ); p.append( item );
769 customWidgets()->append( newObjRefParamWdg( filterForShapeOfDim( 2 ),
770 h->GetSourceFace()));
771 item.myName = tr( "SMESH_SOURCE_MESH" ); p.append( item );
772 customWidgets()->append( newObjRefParamWdg( new SMESH_TypeFilter( MESH ),
773 h->GetSourceMesh()));
774 item.myName = tr( "SMESH_SOURCE_VERTEX1" ); p.append( item );
775 customWidgets()->append( newObjRefParamWdg( filterForShapeOfDim( 0 ),
776 h->GetSourceVertex( 1 )));
777 item.myName = tr( "SMESH_TARGET_VERTEX1" ); p.append( item );
778 customWidgets()->append( newObjRefParamWdg( filterForShapeOfDim( 0 ),
779 h->GetTargetVertex( 1 )));
780 item.myName = tr( "SMESH_SOURCE_VERTEX2" ); p.append( item );
781 customWidgets()->append( newObjRefParamWdg( filterForShapeOfDim( 0 ),
782 h->GetSourceVertex( 2 )));
783 item.myName = tr( "SMESH_TARGET_VERTEX2" ); p.append( item );
784 customWidgets()->append( newObjRefParamWdg( filterForShapeOfDim( 0 ),
785 h->GetTargetVertex( 2 )));
787 else if( hypType()=="ProjectionSource3D" )
789 StdMeshers::StdMeshers_ProjectionSource3D_var h =
790 StdMeshers::StdMeshers_ProjectionSource3D::_narrow( hyp );
792 item.myName = tr( "SMESH_SOURCE_3DSHAPE" ); p.append( item );
793 customWidgets()->append( newObjRefParamWdg( filterForShapeOfDim( 3, TopAbs_FACE, 6, true ),
794 h->GetSource3DShape()));
795 item.myName = tr( "SMESH_SOURCE_MESH" ); p.append( item );
796 customWidgets()->append( newObjRefParamWdg( new SMESH_TypeFilter( MESH ),
797 h->GetSourceMesh()));
798 item.myName = tr( "SMESH_SOURCE_VERTEX1" ); p.append( item );
799 customWidgets()->append( newObjRefParamWdg( filterForShapeOfDim( 0 ),
800 h->GetSourceVertex( 1 )));
801 item.myName = tr( "SMESH_TARGET_VERTEX1" ); p.append( item );
802 customWidgets()->append( newObjRefParamWdg( filterForShapeOfDim( 0 ),
803 h->GetTargetVertex( 1 )));
804 item.myName = tr( "SMESH_SOURCE_VERTEX2" ); p.append( item );
805 customWidgets()->append( newObjRefParamWdg( filterForShapeOfDim( 0 ),
806 h->GetSourceVertex( 2 )));
807 item.myName = tr( "SMESH_TARGET_VERTEX2" ); p.append( item );
808 customWidgets()->append( newObjRefParamWdg( filterForShapeOfDim( 0 ),
809 h->GetTargetVertex( 2 )));
816 //================================================================================
818 * \brief tune "standard" control
819 * \param w - control widget
820 * \param int - parameter index
822 //================================================================================
824 void StdMeshersGUI_StdHypothesisCreator::attuneStdWidget (QWidget* w, const int) const
826 SMESHGUI_SpinBox* sb = w->inherits( "SMESHGUI_SpinBox" ) ? ( SMESHGUI_SpinBox* )w : 0;
827 if( hypType()=="LocalLength" && sb )
829 if (sb->objectName() == tr("SMESH_LOCAL_LENGTH_PARAM"))
830 sb->RangeStepAndValidator( VALUE_SMALL, VALUE_MAX, 1.0, 6 );
831 else if (sb->objectName() == tr("SMESH_LOCAL_LENGTH_PRECISION"))
832 sb->RangeStepAndValidator( 0.0, 1.0, 0.05, 7 );
834 else if( hypType()=="Arithmetic1D" && sb )
836 sb->RangeStepAndValidator( VALUE_SMALL, VALUE_MAX, 1.0, 6 );
838 else if( hypType()=="MaxLength" && sb )
840 sb->RangeStepAndValidator( VALUE_SMALL, VALUE_MAX, 1.0, 6 );
841 sb->setEnabled( !widget< QCheckBox >( 1 )->isChecked() );
843 else if( hypType()=="MaxElementArea" && sb )
845 sb->RangeStepAndValidator( VALUE_SMALL_2, VALUE_MAX_2, 1.0, 6 );
847 else if( hypType()=="MaxElementVolume" && sb )
849 sb->RangeStepAndValidator( VALUE_SMALL_3, VALUE_MAX_3, 1.0, 6 );
851 else if( hypType()=="StartEndLength" && sb )
853 sb->RangeStepAndValidator( VALUE_SMALL, VALUE_MAX, 1.0, 6 );
855 else if( hypType()=="Deflection1D" && sb )
857 sb->RangeStepAndValidator( VALUE_SMALL, VALUE_MAX, 1.0, 6 );
859 else if ( sb ) // default validator for possible ancestors
861 sb->RangeStepAndValidator( VALUE_SMALL, VALUE_MAX, 1.0, 6 );
865 //================================================================================
867 * \brief Return dlg title
868 * \retval QString - title string
870 //================================================================================
872 QString StdMeshersGUI_StdHypothesisCreator::caption() const
874 return tr( QString( "SMESH_%1_TITLE" ).arg( hypTypeName( hypType() ) ).toLatin1().data() );
877 //================================================================================
879 * \brief return pixmap for dlg icon
882 //================================================================================
884 QPixmap StdMeshersGUI_StdHypothesisCreator::icon() const
886 QString hypIconName = tr( QString( "ICON_DLG_%1" ).arg( hypTypeName( hypType() ) ).toLatin1().data() );
887 return SMESHGUI::resourceMgr()->loadPixmap( "SMESH", hypIconName );
890 //================================================================================
892 * \brief Return hypothesis type name to show in dlg
895 //================================================================================
897 QString StdMeshersGUI_StdHypothesisCreator::type() const
899 return tr( QString( "SMESH_%1_HYPOTHESIS" ).arg( hypTypeName( hypType() ) ).toLatin1().data() );
902 //================================================================================
904 * \brief String to insert in "SMESH_%1_HYPOTHESIS" to get hypothesis type name
905 * from message resouce file
906 * \param t - hypothesis type
907 * \retval QString - result string
909 //================================================================================
911 QString StdMeshersGUI_StdHypothesisCreator::hypTypeName( const QString& t ) const
913 static QMap<QString,QString> types;
914 if( types.isEmpty() )
916 types.insert( "LocalLength", "LOCAL_LENGTH" );
917 types.insert( "NumberOfSegments", "NB_SEGMENTS" );
918 types.insert( "MaxElementArea", "MAX_ELEMENT_AREA" );
919 types.insert( "MaxElementVolume", "MAX_ELEMENT_VOLUME" );
920 types.insert( "StartEndLength", "START_END_LENGTH" );
921 types.insert( "Deflection1D", "DEFLECTION1D" );
922 types.insert( "Arithmetic1D", "ARITHMETIC_1D" );
923 types.insert( "AutomaticLength", "AUTOMATIC_LENGTH" );
924 types.insert( "ProjectionSource1D", "PROJECTION_SOURCE_1D" );
925 types.insert( "ProjectionSource2D", "PROJECTION_SOURCE_2D" );
926 types.insert( "ProjectionSource3D", "PROJECTION_SOURCE_3D" );
927 types.insert( "NumberOfLayers", "NUMBER_OF_LAYERS" );
928 types.insert( "LayerDistribution", "LAYER_DISTRIBUTION" );
929 types.insert( "SegmentLengthAroundVertex", "SEGMENT_LENGTH_AROUND_VERTEX" );
930 types.insert( "MaxLength", "MAX_LENGTH" );
934 if( types.contains( t ) )
941 //=======================================================================
942 //function : getCustomWidget
943 //purpose : is called from buildStdFrame()
944 //=======================================================================
946 QWidget* StdMeshersGUI_StdHypothesisCreator::getCustomWidget( const StdParam & param,
948 const int index) const
951 if ( index < customWidgets()->count() ) {
952 w = customWidgets()->at( index );
954 w->setParent( parent );
955 w->move( QPoint( 0, 0 ) );
961 //================================================================================
963 * \brief Set param value taken from a custom widget
964 * \param param - SMESHGUI_GenericHypothesisCreator::StdParam structure
965 * \param widget - widget presenting param
966 * \retval bool - success flag
968 * this method is called from getStdParamFromDlg()
970 //================================================================================
972 bool StdMeshersGUI_StdHypothesisCreator::getParamFromCustomWidget( StdParam & param,
973 QWidget* widget) const
975 if ( hypType()=="AutomaticLength" ) {
976 TDoubleSliderWith2Lables* w = dynamic_cast<TDoubleSliderWith2Lables*>( widget );
978 param.myValue = w->value();
982 if ( hypType() == "MaxLength" ) {
986 if ( widget->inherits( "StdMeshersGUI_ObjectReferenceParamWdg" ))
988 // show only 1st reference value
989 if ( true /*widget == getWidgetForParam( 0 )*/) {
990 const StdMeshersGUI_ObjectReferenceParamWdg * w =
991 static_cast<const StdMeshersGUI_ObjectReferenceParamWdg*>( widget );
992 param.myValue = w->GetValue();
996 if ( widget->inherits( "StdMeshersGUI_LayerDistributionParamWdg" ))
998 const StdMeshersGUI_LayerDistributionParamWdg * w =
999 static_cast<const StdMeshersGUI_LayerDistributionParamWdg*>( widget );
1000 param.myValue = w->GetValue();
1006 //================================================================================
1008 * \brief called when operation cancelled
1010 //================================================================================
1012 void StdMeshersGUI_StdHypothesisCreator::onReject()
1014 if ( hypType().startsWith("ProjectionSource" ))
1016 // Uninstall filters of StdMeshersGUI_ObjectReferenceParamWdg
1017 deactivateObjRefParamWdg( customWidgets() );
1021 //================================================================================
1025 //================================================================================
1027 void StdMeshersGUI_StdHypothesisCreator::valueChanged( QWidget* paramWidget)
1029 if ( hypType() == "MaxLength" && paramWidget == getWidgetForParam(1) ) {
1030 getWidgetForParam(0)->setEnabled( !widget< QCheckBox >( 1 )->isChecked() );
1031 if ( !getWidgetForParam(0)->isEnabled() ) {
1032 StdMeshers::StdMeshers_MaxLength_var h =
1033 StdMeshers::StdMeshers_MaxLength::_narrow( initParamsHypothesis() );
1034 widget< QtxDoubleSpinBox >( 0 )->setValue( h->GetPreestimatedLength() );
1039 //================================================================================
1043 //================================================================================
1045 bool StdMeshersGUI_StdHypothesisCreator::initVariableName(SMESH::ListOfParameters_var theParameters,
1046 StdParam &theParams,
1049 QString aVaribaleName = (theParameters->length() > order) ? QString(theParameters[order].in()) : QString("");
1050 theParams.isVariable = !aVaribaleName.isEmpty();
1051 if(theParams.isVariable)
1052 theParams.myValue = aVaribaleName;
1054 return theParams.isVariable;