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->SetUsePreestimatedLength( widget< QCheckBox >( 1 )->isChecked() );
427 if ( !h->HavePreestimatedLength() && !h->_is_equivalent( initParamsHypothesis() )) {
428 StdMeshers::StdMeshers_MaxLength_var hInit =
429 StdMeshers::StdMeshers_MaxLength::_narrow( initParamsHypothesis() );
430 h->SetPreestimatedLength( hInit->GetPreestimatedLength() );
433 else if( hypType()=="SegmentLengthAroundVertex" )
435 StdMeshers::StdMeshers_SegmentLengthAroundVertex_var h =
436 StdMeshers::StdMeshers_SegmentLengthAroundVertex::_narrow( hypothesis() );
438 h->SetLength( params[0].myValue.toDouble() );
439 h->SetParameters(SMESHGUI::JoinObjectParameters(aVariablesList));
441 else if( hypType()=="Arithmetic1D" )
443 StdMeshers::StdMeshers_Arithmetic1D_var h =
444 StdMeshers::StdMeshers_Arithmetic1D::_narrow( hypothesis() );
446 h->SetLength( params[0].myValue.toDouble(), true );
447 h->SetParameters(SMESHGUI::JoinObjectParameters(aVariablesList));
448 h->SetLength( params[1].myValue.toDouble(), false );
449 h->SetParameters(SMESHGUI::JoinObjectParameters(aVariablesList));
451 else if( hypType()=="MaxElementArea" )
453 StdMeshers::StdMeshers_MaxElementArea_var h =
454 StdMeshers::StdMeshers_MaxElementArea::_narrow( hypothesis() );
455 h->SetParameters(SMESHGUI::JoinObjectParameters(aVariablesList));
456 h->SetMaxElementArea( params[0].myValue.toDouble() );
458 else if( hypType()=="MaxElementVolume" )
460 StdMeshers::StdMeshers_MaxElementVolume_var h =
461 StdMeshers::StdMeshers_MaxElementVolume::_narrow( hypothesis() );
463 h->SetMaxElementVolume( params[0].myValue.toDouble() );
464 h->SetParameters(SMESHGUI::JoinObjectParameters(aVariablesList));
466 else if( hypType()=="StartEndLength" )
468 StdMeshers::StdMeshers_StartEndLength_var h =
469 StdMeshers::StdMeshers_StartEndLength::_narrow( hypothesis() );
471 h->SetLength( params[0].myValue.toDouble(), true );
472 h->SetParameters(SMESHGUI::JoinObjectParameters(aVariablesList));
473 h->SetLength( params[1].myValue.toDouble(), false );
474 h->SetParameters(SMESHGUI::JoinObjectParameters(aVariablesList));
476 else if( hypType()=="Deflection1D" )
478 StdMeshers::StdMeshers_Deflection1D_var h =
479 StdMeshers::StdMeshers_Deflection1D::_narrow( hypothesis() );
480 h->SetParameters(SMESHGUI::JoinObjectParameters(aVariablesList));
481 h->SetDeflection( params[0].myValue.toDouble() );
483 else if( hypType()=="AutomaticLength" )
485 StdMeshers::StdMeshers_AutomaticLength_var h =
486 StdMeshers::StdMeshers_AutomaticLength::_narrow( hypothesis() );
488 h->SetFineness( params[0].myValue.toDouble() );
490 else if( hypType()=="NumberOfLayers" )
492 StdMeshers::StdMeshers_NumberOfLayers_var h =
493 StdMeshers::StdMeshers_NumberOfLayers::_narrow( hypothesis() );
495 h->SetNumberOfLayers( params[0].myValue.toInt() );
496 h->SetParameters(SMESHGUI::JoinObjectParameters(aVariablesList));
498 else if( hypType()=="LayerDistribution" )
500 StdMeshers::StdMeshers_LayerDistribution_var h =
501 StdMeshers::StdMeshers_LayerDistribution::_narrow( hypothesis() );
502 StdMeshersGUI_LayerDistributionParamWdg* w =
503 widget< StdMeshersGUI_LayerDistributionParamWdg >( 0 );
505 h->SetLayerDistribution( w->GetHypothesis() );
506 h->SetParameters(w->GetHypothesis()->GetParameters());
507 w->GetHypothesis()->ClearParameters();
509 else if( hypType()=="ProjectionSource1D" )
511 StdMeshers::StdMeshers_ProjectionSource1D_var h =
512 StdMeshers::StdMeshers_ProjectionSource1D::_narrow( hypothesis() );
514 h->SetSourceEdge ( geomFromWdg ( getWidgetForParam( 0 )));
515 h->SetSourceMesh ( meshFromWdg ( getWidgetForParam( 1 )));
516 h->SetVertexAssociation( geomFromWdg ( getWidgetForParam( 2 )),
517 geomFromWdg ( getWidgetForParam( 3 )));
519 else if( hypType()=="ProjectionSource2D" )
521 StdMeshers::StdMeshers_ProjectionSource2D_var h =
522 StdMeshers::StdMeshers_ProjectionSource2D::_narrow( hypothesis() );
524 h->SetSourceFace ( geomFromWdg ( getWidgetForParam( 0 )));
525 h->SetSourceMesh ( meshFromWdg ( getWidgetForParam( 1 )));
526 h->SetVertexAssociation( geomFromWdg ( getWidgetForParam( 2 )), // src1
527 geomFromWdg ( getWidgetForParam( 4 )), // src2
528 geomFromWdg ( getWidgetForParam( 3 )), // tgt1
529 geomFromWdg ( getWidgetForParam( 5 ))); // tgt2
531 else if( hypType()=="ProjectionSource3D" )
533 StdMeshers::StdMeshers_ProjectionSource3D_var h =
534 StdMeshers::StdMeshers_ProjectionSource3D::_narrow( hypothesis() );
536 h->SetSource3DShape ( geomFromWdg ( getWidgetForParam( 0 )));
537 h->SetSourceMesh ( meshFromWdg ( getWidgetForParam( 1 )));
538 h->SetVertexAssociation( geomFromWdg ( getWidgetForParam( 2 )), // src1
539 geomFromWdg ( getWidgetForParam( 4 )), // src2
540 geomFromWdg ( getWidgetForParam( 3 )), // tgt1
541 geomFromWdg ( getWidgetForParam( 5 ))); // tgt2
547 //================================================================================
549 * \brief Return parameter values as SMESHGUI_GenericHypothesisCreator::StdParam
550 * \param p - list of parameters
551 * \retval bool - success flag
553 * Is called from SMESHGUI_GenericHypothesisCreator::buildStdFrame().
554 * Parameters will be shown using "standard" controls:
555 * Int by QtxIntSpinBox
556 * Double by SMESHGUI_SpinBox
557 * String by QLineEdit
558 * getCustomWidget() allows to redefine control for a parameter
560 //================================================================================
562 bool StdMeshersGUI_StdHypothesisCreator::stdParams( ListOfStdParams& p ) const
565 SMESHGUI_GenericHypothesisCreator::StdParam item;
568 customWidgets()->clear();
571 HypothesisData* data = SMESH::GetHypothesisData( hypType() );
572 item.myName = tr( "SMESH_NAME" );
573 item.myValue = data ? hypName() : QString();
575 customWidgets()->append(0);
578 SMESH::SMESH_Hypothesis_var hyp = initParamsHypothesis();
579 SMESH::ListOfParameters_var aParameters = hyp->GetLastParameters();
581 if( hypType()=="LocalLength" )
583 StdMeshers::StdMeshers_LocalLength_var h =
584 StdMeshers::StdMeshers_LocalLength::_narrow( hyp );
586 item.myName = tr("SMESH_LOCAL_LENGTH_PARAM");
587 if(!initVariableName(aParameters,item,0))
588 item.myValue = h->GetLength();
591 item.myName = tr("SMESH_LOCAL_LENGTH_PRECISION");
592 if(!initVariableName(aParameters,item,1))
593 item.myValue = h->GetPrecision();
597 else if( hypType()=="MaxLength" )
599 StdMeshers::StdMeshers_MaxLength_var h =
600 StdMeshers::StdMeshers_MaxLength::_narrow( hyp );
601 // try to set a right preestimated length to edited hypothesis
602 bool noPreestimatedAtEdition = false;
603 if ( !isCreation() ) {
604 StdMeshers::StdMeshers_MaxLength_var initHyp =
605 StdMeshers::StdMeshers_MaxLength::_narrow( initParamsHypothesis(true) );
606 noPreestimatedAtEdition =
607 ( initHyp->_is_nil() || !initHyp->HavePreestimatedLength() );
608 if ( !noPreestimatedAtEdition )
609 h->SetPreestimatedLength( initHyp->GetPreestimatedLength() );
612 item.myName = tr("SMESH_LOCAL_LENGTH_PARAM");
613 item.myValue = h->GetLength();
615 customWidgets()->append(0);
617 item.myName = tr("SMESH_USE_PREESTIMATED_LENGTH");
619 QCheckBox* aQCheckBox = new QCheckBox(dlg());
620 if ( !noPreestimatedAtEdition && h->HavePreestimatedLength() ) {
621 aQCheckBox->setChecked( h->GetUsePreestimatedLength() );
622 connect( aQCheckBox, SIGNAL( stateChanged(int) ), this, SLOT( onValueChanged() ) );
625 aQCheckBox->setChecked( false );
626 aQCheckBox->setEnabled( false );
628 customWidgets()->append( aQCheckBox );
630 else if( hypType()=="SegmentLengthAroundVertex" )
632 StdMeshers::StdMeshers_SegmentLengthAroundVertex_var h =
633 StdMeshers::StdMeshers_SegmentLengthAroundVertex::_narrow( hyp );
635 item.myName = tr("SMESH_LOCAL_LENGTH_PARAM");
636 if(!initVariableName(aParameters,item,0))
637 item.myValue = h->GetLength();
641 else if( hypType()=="Arithmetic1D" )
643 StdMeshers::StdMeshers_Arithmetic1D_var h =
644 StdMeshers::StdMeshers_Arithmetic1D::_narrow( hyp );
646 item.myName = tr( "SMESH_START_LENGTH_PARAM" );
647 if(!initVariableName(aParameters,item,0))
648 item.myValue = h->GetLength( true );
651 item.myName = tr( "SMESH_END_LENGTH_PARAM" );
652 if(!initVariableName(aParameters,item,1))
653 item.myValue = h->GetLength( false );
656 else if( hypType()=="MaxElementArea" )
658 StdMeshers::StdMeshers_MaxElementArea_var h =
659 StdMeshers::StdMeshers_MaxElementArea::_narrow( hyp );
661 item.myName = tr( "SMESH_MAX_ELEMENT_AREA_PARAM" );
662 if(!initVariableName(aParameters,item,0))
663 item.myValue = h->GetMaxElementArea();
667 else if( hypType()=="MaxElementVolume" )
669 StdMeshers::StdMeshers_MaxElementVolume_var h =
670 StdMeshers::StdMeshers_MaxElementVolume::_narrow( hyp );
672 item.myName = tr( "SMESH_MAX_ELEMENT_VOLUME_PARAM" );
673 if(!initVariableName(aParameters,item,0))
674 item.myValue = h->GetMaxElementVolume();
677 else if( hypType()=="StartEndLength" )
679 StdMeshers::StdMeshers_StartEndLength_var h =
680 StdMeshers::StdMeshers_StartEndLength::_narrow( hyp );
682 item.myName = tr( "SMESH_START_LENGTH_PARAM" );
684 if(!initVariableName(aParameters,item,0))
685 item.myValue = h->GetLength( true );
688 item.myName = tr( "SMESH_END_LENGTH_PARAM" );
689 if(!initVariableName(aParameters,item,1))
690 item.myValue = h->GetLength( false );
694 else if( hypType()=="Deflection1D" )
696 StdMeshers::StdMeshers_Deflection1D_var h =
697 StdMeshers::StdMeshers_Deflection1D::_narrow( hyp );
699 item.myName = tr( "SMESH_DEFLECTION1D_PARAM" );
700 if(!initVariableName(aParameters,item,0))
701 item.myValue = h->GetDeflection();
704 else if( hypType()=="AutomaticLength" )
706 StdMeshers::StdMeshers_AutomaticLength_var h =
707 StdMeshers::StdMeshers_AutomaticLength::_narrow( hyp );
709 item.myName = tr( "SMESH_FINENESS_PARAM" );
710 //item.myValue = h->GetFineness();
712 customWidgets()->append
713 ( new TDoubleSliderWith2Lables( "0 ", " 1", h->GetFineness(), 0, 1, 0.01, 0 ));
715 else if( hypType()=="NumberOfLayers" )
717 StdMeshers::StdMeshers_NumberOfLayers_var h =
718 StdMeshers::StdMeshers_NumberOfLayers::_narrow( hyp );
720 item.myName = tr( "SMESH_NUMBER_OF_LAYERS" );
721 if(!initVariableName(aParameters,item,0))
722 item.myValue = (int) h->GetNumberOfLayers();
725 else if( hypType()=="LayerDistribution" )
727 StdMeshers::StdMeshers_LayerDistribution_var h =
728 StdMeshers::StdMeshers_LayerDistribution::_narrow( hyp );
730 item.myName = tr( "SMESH_LAYERS_DISTRIBUTION" ); p.append( item );
732 //Set into not published hypo last variables
733 QStringList aLastVarsList;
734 for(int i = 0;i<aParameters->length();i++)
735 aLastVarsList.append(QString(aParameters[i].in()));
737 if(!aLastVarsList.isEmpty())
738 h->GetLayerDistribution()->SetLastParameters(SMESHGUI::JoinObjectParameters(aLastVarsList));
740 customWidgets()->append
741 ( new StdMeshersGUI_LayerDistributionParamWdg( h->GetLayerDistribution(), hypName(), dlg()));
743 else if( hypType()=="ProjectionSource1D" )
745 StdMeshers::StdMeshers_ProjectionSource1D_var h =
746 StdMeshers::StdMeshers_ProjectionSource1D::_narrow( hyp );
748 item.myName = tr( "SMESH_SOURCE_EDGE" ); p.append( item );
749 customWidgets()->append( newObjRefParamWdg( filterForShapeOfDim( 1 ),
750 h->GetSourceEdge()));
751 item.myName = tr( "SMESH_SOURCE_MESH" ); p.append( item );
752 customWidgets()->append( newObjRefParamWdg( new SMESH_TypeFilter( MESH ),
753 h->GetSourceMesh()));
754 item.myName = tr( "SMESH_SOURCE_VERTEX" ); p.append( item );
755 customWidgets()->append( newObjRefParamWdg( filterForShapeOfDim( 0 ),
756 h->GetSourceVertex()));
757 item.myName = tr( "SMESH_TARGET_VERTEX" ); p.append( item );
758 customWidgets()->append( newObjRefParamWdg( filterForShapeOfDim( 0 ),
759 h->GetTargetVertex()));
761 else if( hypType()=="ProjectionSource2D" )
763 StdMeshers::StdMeshers_ProjectionSource2D_var h =
764 StdMeshers::StdMeshers_ProjectionSource2D::_narrow( hyp );
766 item.myName = tr( "SMESH_SOURCE_FACE" ); p.append( item );
767 customWidgets()->append( newObjRefParamWdg( filterForShapeOfDim( 2 ),
768 h->GetSourceFace()));
769 item.myName = tr( "SMESH_SOURCE_MESH" ); p.append( item );
770 customWidgets()->append( newObjRefParamWdg( new SMESH_TypeFilter( MESH ),
771 h->GetSourceMesh()));
772 item.myName = tr( "SMESH_SOURCE_VERTEX1" ); p.append( item );
773 customWidgets()->append( newObjRefParamWdg( filterForShapeOfDim( 0 ),
774 h->GetSourceVertex( 1 )));
775 item.myName = tr( "SMESH_TARGET_VERTEX1" ); p.append( item );
776 customWidgets()->append( newObjRefParamWdg( filterForShapeOfDim( 0 ),
777 h->GetTargetVertex( 1 )));
778 item.myName = tr( "SMESH_SOURCE_VERTEX2" ); p.append( item );
779 customWidgets()->append( newObjRefParamWdg( filterForShapeOfDim( 0 ),
780 h->GetSourceVertex( 2 )));
781 item.myName = tr( "SMESH_TARGET_VERTEX2" ); p.append( item );
782 customWidgets()->append( newObjRefParamWdg( filterForShapeOfDim( 0 ),
783 h->GetTargetVertex( 2 )));
785 else if( hypType()=="ProjectionSource3D" )
787 StdMeshers::StdMeshers_ProjectionSource3D_var h =
788 StdMeshers::StdMeshers_ProjectionSource3D::_narrow( hyp );
790 item.myName = tr( "SMESH_SOURCE_3DSHAPE" ); p.append( item );
791 customWidgets()->append( newObjRefParamWdg( filterForShapeOfDim( 3, TopAbs_FACE, 6, true ),
792 h->GetSource3DShape()));
793 item.myName = tr( "SMESH_SOURCE_MESH" ); p.append( item );
794 customWidgets()->append( newObjRefParamWdg( new SMESH_TypeFilter( MESH ),
795 h->GetSourceMesh()));
796 item.myName = tr( "SMESH_SOURCE_VERTEX1" ); p.append( item );
797 customWidgets()->append( newObjRefParamWdg( filterForShapeOfDim( 0 ),
798 h->GetSourceVertex( 1 )));
799 item.myName = tr( "SMESH_TARGET_VERTEX1" ); p.append( item );
800 customWidgets()->append( newObjRefParamWdg( filterForShapeOfDim( 0 ),
801 h->GetTargetVertex( 1 )));
802 item.myName = tr( "SMESH_SOURCE_VERTEX2" ); p.append( item );
803 customWidgets()->append( newObjRefParamWdg( filterForShapeOfDim( 0 ),
804 h->GetSourceVertex( 2 )));
805 item.myName = tr( "SMESH_TARGET_VERTEX2" ); p.append( item );
806 customWidgets()->append( newObjRefParamWdg( filterForShapeOfDim( 0 ),
807 h->GetTargetVertex( 2 )));
814 //================================================================================
816 * \brief tune "standard" control
817 * \param w - control widget
818 * \param int - parameter index
820 //================================================================================
822 void StdMeshersGUI_StdHypothesisCreator::attuneStdWidget (QWidget* w, const int) const
824 SMESHGUI_SpinBox* sb = w->inherits( "SMESHGUI_SpinBox" ) ? ( SMESHGUI_SpinBox* )w : 0;
825 if( hypType()=="LocalLength" && sb )
827 if (sb->objectName() == tr("SMESH_LOCAL_LENGTH_PARAM"))
828 sb->RangeStepAndValidator( VALUE_SMALL, VALUE_MAX, 1.0, 6 );
829 else if (sb->objectName() == tr("SMESH_LOCAL_LENGTH_PRECISION"))
830 sb->RangeStepAndValidator( 0.0, 1.0, 0.05, 7 );
832 else if( hypType()=="Arithmetic1D" && sb )
834 sb->RangeStepAndValidator( VALUE_SMALL, VALUE_MAX, 1.0, 6 );
836 else if( hypType()=="MaxLength" && sb )
838 sb->RangeStepAndValidator( VALUE_SMALL, VALUE_MAX, 1.0, 6 );
839 sb->setEnabled( !widget< QCheckBox >( 1 )->isChecked() );
841 else if( hypType()=="MaxElementArea" && sb )
843 sb->RangeStepAndValidator( VALUE_SMALL_2, VALUE_MAX_2, 1.0, 6 );
845 else if( hypType()=="MaxElementVolume" && sb )
847 sb->RangeStepAndValidator( VALUE_SMALL_3, VALUE_MAX_3, 1.0, 6 );
849 else if( hypType()=="StartEndLength" && sb )
851 sb->RangeStepAndValidator( VALUE_SMALL, VALUE_MAX, 1.0, 6 );
853 else if( hypType()=="Deflection1D" && sb )
855 sb->RangeStepAndValidator( VALUE_SMALL, VALUE_MAX, 1.0, 6 );
857 else if ( sb ) // default validator for possible ancestors
859 sb->RangeStepAndValidator( VALUE_SMALL, VALUE_MAX, 1.0, 6 );
863 //================================================================================
865 * \brief Return dlg title
866 * \retval QString - title string
868 //================================================================================
870 QString StdMeshersGUI_StdHypothesisCreator::caption() const
872 return tr( QString( "SMESH_%1_TITLE" ).arg( hypTypeName( hypType() ) ).toLatin1().data() );
875 //================================================================================
877 * \brief return pixmap for dlg icon
880 //================================================================================
882 QPixmap StdMeshersGUI_StdHypothesisCreator::icon() const
884 QString hypIconName = tr( QString( "ICON_DLG_%1" ).arg( hypTypeName( hypType() ) ).toLatin1().data() );
885 return SMESHGUI::resourceMgr()->loadPixmap( "SMESH", hypIconName );
888 //================================================================================
890 * \brief Return hypothesis type name to show in dlg
893 //================================================================================
895 QString StdMeshersGUI_StdHypothesisCreator::type() const
897 return tr( QString( "SMESH_%1_HYPOTHESIS" ).arg( hypTypeName( hypType() ) ).toLatin1().data() );
900 //================================================================================
902 * \brief String to insert in "SMESH_%1_HYPOTHESIS" to get hypothesis type name
903 * from message resouce file
904 * \param t - hypothesis type
905 * \retval QString - result string
907 //================================================================================
909 QString StdMeshersGUI_StdHypothesisCreator::hypTypeName( const QString& t ) const
911 static QMap<QString,QString> types;
912 if( types.isEmpty() )
914 types.insert( "LocalLength", "LOCAL_LENGTH" );
915 types.insert( "NumberOfSegments", "NB_SEGMENTS" );
916 types.insert( "MaxElementArea", "MAX_ELEMENT_AREA" );
917 types.insert( "MaxElementVolume", "MAX_ELEMENT_VOLUME" );
918 types.insert( "StartEndLength", "START_END_LENGTH" );
919 types.insert( "Deflection1D", "DEFLECTION1D" );
920 types.insert( "Arithmetic1D", "ARITHMETIC_1D" );
921 types.insert( "AutomaticLength", "AUTOMATIC_LENGTH" );
922 types.insert( "ProjectionSource1D", "PROJECTION_SOURCE_1D" );
923 types.insert( "ProjectionSource2D", "PROJECTION_SOURCE_2D" );
924 types.insert( "ProjectionSource3D", "PROJECTION_SOURCE_3D" );
925 types.insert( "NumberOfLayers", "NUMBER_OF_LAYERS" );
926 types.insert( "LayerDistribution", "LAYER_DISTRIBUTION" );
927 types.insert( "SegmentLengthAroundVertex", "SEGMENT_LENGTH_AROUND_VERTEX" );
928 types.insert( "MaxLength", "MAX_LENGTH" );
932 if( types.contains( t ) )
939 //=======================================================================
940 //function : getCustomWidget
941 //purpose : is called from buildStdFrame()
942 //=======================================================================
944 QWidget* StdMeshersGUI_StdHypothesisCreator::getCustomWidget( const StdParam & param,
946 const int index) const
949 if ( index < customWidgets()->count() ) {
950 w = customWidgets()->at( index );
952 w->setParent( parent );
953 w->move( QPoint( 0, 0 ) );
959 //================================================================================
961 * \brief Set param value taken from a custom widget
962 * \param param - SMESHGUI_GenericHypothesisCreator::StdParam structure
963 * \param widget - widget presenting param
964 * \retval bool - success flag
966 * this method is called from getStdParamFromDlg()
968 //================================================================================
970 bool StdMeshersGUI_StdHypothesisCreator::getParamFromCustomWidget( StdParam & param,
971 QWidget* widget) const
973 if ( hypType()=="AutomaticLength" ) {
974 TDoubleSliderWith2Lables* w = dynamic_cast<TDoubleSliderWith2Lables*>( widget );
976 param.myValue = w->value();
980 if ( hypType() == "MaxLength" ) {
984 if ( widget->inherits( "StdMeshersGUI_ObjectReferenceParamWdg" ))
986 // show only 1st reference value
987 if ( true /*widget == getWidgetForParam( 0 )*/) {
988 const StdMeshersGUI_ObjectReferenceParamWdg * w =
989 static_cast<const StdMeshersGUI_ObjectReferenceParamWdg*>( widget );
990 param.myValue = w->GetValue();
994 if ( widget->inherits( "StdMeshersGUI_LayerDistributionParamWdg" ))
996 const StdMeshersGUI_LayerDistributionParamWdg * w =
997 static_cast<const StdMeshersGUI_LayerDistributionParamWdg*>( widget );
998 param.myValue = w->GetValue();
1004 //================================================================================
1006 * \brief called when operation cancelled
1008 //================================================================================
1010 void StdMeshersGUI_StdHypothesisCreator::onReject()
1012 if ( hypType().startsWith("ProjectionSource" ))
1014 // Uninstall filters of StdMeshersGUI_ObjectReferenceParamWdg
1015 deactivateObjRefParamWdg( customWidgets() );
1019 //================================================================================
1023 //================================================================================
1025 void StdMeshersGUI_StdHypothesisCreator::valueChanged( QWidget* paramWidget)
1027 if ( hypType() == "MaxLength" && paramWidget == getWidgetForParam(1) ) {
1028 getWidgetForParam(0)->setEnabled( !widget< QCheckBox >( 1 )->isChecked() );
1029 if ( !getWidgetForParam(0)->isEnabled() ) {
1030 StdMeshers::StdMeshers_MaxLength_var h =
1031 StdMeshers::StdMeshers_MaxLength::_narrow( initParamsHypothesis() );
1032 widget< QtxDoubleSpinBox >( 0 )->setValue( h->GetPreestimatedLength() );
1037 //================================================================================
1041 //================================================================================
1043 bool StdMeshersGUI_StdHypothesisCreator::initVariableName(SMESH::ListOfParameters_var theParameters,
1044 StdParam &theParams,
1047 QString aVaribaleName = (theParameters->length() > order) ? QString(theParameters[order].in()) : QString("");
1048 theParams.isVariable = !aVaribaleName.isEmpty();
1049 if(theParams.isVariable)
1050 theParams.myValue = aVaribaleName;
1052 return theParams.isVariable;