1 // Copyright (C) 2003 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
2 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
4 // This library is free software; you can redistribute it and/or
5 // modify it under the terms of the GNU Lesser General Public
6 // License as published by the Free Software Foundation; either
7 // version 2.1 of the License.
9 // This library is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 // Lesser General Public License for more details.
14 // You should have received a copy of the GNU Lesser General Public
15 // License along with this library; if not, write to the Free Software
16 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
20 // File : StdMeshersGUI_StdHypothesisCreator.cxx
21 // Author : Alexander SOLOVYOV, Open CASCADE S.A.S.
25 #include "StdMeshersGUI_StdHypothesisCreator.h"
28 #include <SMESHGUI_SpinBox.h>
29 #include <SMESHGUI_HypothesesUtils.h>
30 #include <SMESHGUI_Utils.h>
31 #include <SMESH_TypeFilter.hxx>
32 #include <SMESH_NumberFilter.hxx>
33 #include <StdMeshersGUI_ObjectReferenceParamWdg.h>
34 #include <StdMeshersGUI_LayerDistributionParamWdg.h>
36 // SALOME GUI includes
37 #include <SUIT_ResourceMgr.h>
40 #include <SALOMEconfig.h>
41 #include CORBA_SERVER_HEADER(SMESH_BasicHypothesis)
42 #include CORBA_SERVER_HEADER(SMESH_Mesh)
45 #include <QHBoxLayout>
49 const double VALUE_MAX = 1.0e+15, // COORD_MAX
50 VALUE_MAX_2 = VALUE_MAX * VALUE_MAX,
51 VALUE_MAX_3 = VALUE_MAX_2 * VALUE_MAX,
52 VALUE_SMALL = 1.0e-15,
53 VALUE_SMALL_2 = VALUE_SMALL * VALUE_SMALL,
54 VALUE_SMALL_3 = VALUE_SMALL_2 * VALUE_SMALL;
56 //================================================================================
59 * \param type - hypothesis type
61 //================================================================================
63 StdMeshersGUI_StdHypothesisCreator::StdMeshersGUI_StdHypothesisCreator( const QString& type )
64 : SMESHGUI_GenericHypothesisCreator( type )
68 //================================================================================
72 //================================================================================
74 StdMeshersGUI_StdHypothesisCreator::~StdMeshersGUI_StdHypothesisCreator()
78 //================================================================================
80 * \brief Return widget for i-th hypothesis parameter (got from myParamWidgets)
81 * \param i - index of hypothesis parameter
82 * \retval QWidget* - found widget
84 //================================================================================
86 QWidget* StdMeshersGUI_StdHypothesisCreator::getWidgetForParam( int i ) const
89 if ( isCreation() ) ++i; // skip widget of 'name' parameter
91 if ( i < myCustomWidgets.count() ) {
92 QList<QWidget*>::const_iterator anIt = myCustomWidgets.begin();
93 QList<QWidget*>::const_iterator aLast = myCustomWidgets.end();
94 for ( int j = 0 ; !w && anIt != aLast; ++anIt )
99 // list has no at() const, so we iterate
100 QList<QWidget*>::const_iterator anIt = widgets().begin();
101 QList<QWidget*>::const_iterator aLast = widgets().end();
102 for( int j = 0; !w && anIt!=aLast; anIt++, ++j ) {
110 //================================================================================
112 * \brief Allow modifing myCustomWidgets in const methods
113 * \retval ListOfWidgets* - non-const pointer to myCustomWidgets
115 //================================================================================
117 StdMeshersGUI_StdHypothesisCreator::ListOfWidgets*
118 StdMeshersGUI_StdHypothesisCreator::customWidgets() const
120 return const_cast< ListOfWidgets* >( & myCustomWidgets );
123 //================================================================================
125 * \brief Builds dlg layout
126 * \retval QFrame* - the built widget
128 //================================================================================
130 QFrame* StdMeshersGUI_StdHypothesisCreator::buildFrame()
132 return buildStdFrame();
135 //================================================================================
137 * \brief Initialise parameter values in controls
139 //================================================================================
141 void StdMeshersGUI_StdHypothesisCreator::retrieveParams() const
143 // buildStdFrame() sets values itself calling stdParams()
145 if ( hypType().startsWith("ProjectionSource" ))
147 // we use this method to connect depending custom widgets
148 StdMeshersGUI_ObjectReferenceParamWdg* widgetToActivate = 0;
149 ListOfWidgets::const_iterator anIt = myCustomWidgets.begin();
150 for ( ; anIt != myCustomWidgets.end(); anIt++)
152 if ( *anIt && (*anIt)->inherits("StdMeshersGUI_ObjectReferenceParamWdg"))
154 StdMeshersGUI_ObjectReferenceParamWdg * w1 =
155 ( StdMeshersGUI_ObjectReferenceParamWdg* ) ( *anIt );
156 ListOfWidgets::const_iterator anIt2 = anIt;
157 for ( ++anIt2; anIt2 != myCustomWidgets.end(); anIt2++)
158 if ( *anIt2 && (*anIt2)->inherits("StdMeshersGUI_ObjectReferenceParamWdg"))
160 StdMeshersGUI_ObjectReferenceParamWdg * w2 =
161 ( StdMeshersGUI_ObjectReferenceParamWdg* ) ( *anIt2 );
162 w1->AvoidSimultaneousSelection( w2 );
164 if ( !widgetToActivate )
165 widgetToActivate = w1;
168 if ( widgetToActivate )
169 widgetToActivate->activateSelection();
173 dlg()->setMinimumSize( dlg()->minimumSizeHint().width(), dlg()->minimumSizeHint().height() );
178 //================================================================================
180 * \brief Widget: slider with left and right labels
182 //================================================================================
184 class TDoubleSliderWith2Lables: public QWidget
187 TDoubleSliderWith2Lables( const QString& leftLabel, const QString& rightLabel,
188 const double initValue, const double bottom,
189 const double top , const double precision,
190 QWidget * parent=0 , const char * name=0 )
191 :QWidget(parent), _bottom(bottom), _precision(precision)
195 QHBoxLayout* aHBoxL = new QHBoxLayout(this);
197 if ( !leftLabel.isEmpty() ) {
198 QLabel* aLeftLabel = new QLabel( this );
199 aLeftLabel->setText( leftLabel );
200 aHBoxL->addWidget( aLeftLabel );
203 _slider = new QSlider( Qt::Horizontal, this );
204 _slider->setRange( 0, toInt( top ));
205 _slider->setValue( toInt( initValue ));
206 aHBoxL->addWidget( _slider );
208 if ( !rightLabel.isEmpty() ) {
209 QLabel* aRightLabel = new QLabel( this );
210 aRightLabel->setText( rightLabel );
211 aHBoxL->addWidget( aRightLabel );
216 double value() const { return _bottom + _slider->value() * _precision; }
217 QSlider * getSlider() const { return _slider; }
218 int toInt( double val ) const { return (int) ceil(( val - _bottom ) / _precision ); }
220 double _bottom, _precision;
224 //================================================================================
226 * \brief Retrieve GEOM_Object held by widget
228 //================================================================================
230 inline GEOM::GEOM_Object_var geomFromWdg(const QWidget* wdg)
232 const StdMeshersGUI_ObjectReferenceParamWdg * objRefWdg =
233 dynamic_cast<const StdMeshersGUI_ObjectReferenceParamWdg*>( wdg );
235 return objRefWdg->GetObject< GEOM::GEOM_Object >();
237 return GEOM::GEOM_Object::_nil();
239 //================================================================================
241 * \brief Retrieve SMESH_Mesh held by widget
243 //================================================================================
245 inline SMESH::SMESH_Mesh_var meshFromWdg(const QWidget* wdg)
247 const StdMeshersGUI_ObjectReferenceParamWdg * objRefWdg =
248 dynamic_cast<const StdMeshersGUI_ObjectReferenceParamWdg*>( wdg );
250 return objRefWdg->GetObject< SMESH::SMESH_Mesh >();
252 return SMESH::SMESH_Mesh::_nil();
254 //================================================================================
256 * \brief creates a filter for selection of shapes of given dimension
257 * \param dim - dimension
258 * \param subShapeType - required type of subshapes, number of which must be \a nbSubShapes
259 * \param nbSubShapes - number of subshapes of given type
260 * \param closed - required closeness flag of a shape
261 * \retval SUIT_SelectionFilter* - created filter
263 //================================================================================
265 SUIT_SelectionFilter* filterForShapeOfDim(const int dim,
266 TopAbs_ShapeEnum subShapeType = TopAbs_SHAPE,
267 const int nbSubShapes = 0,
270 TColStd_MapOfInteger shapeTypes;
272 case 0: shapeTypes.Add( TopAbs_VERTEX ); break;
274 if ( subShapeType == TopAbs_SHAPE ) subShapeType = TopAbs_EDGE;
275 shapeTypes.Add( TopAbs_EDGE );
276 shapeTypes.Add( TopAbs_COMPOUND ); // for a group
279 if ( subShapeType == TopAbs_SHAPE ) subShapeType = TopAbs_FACE;
280 shapeTypes.Add( TopAbs_FACE );
281 shapeTypes.Add( TopAbs_COMPOUND ); // for a group
284 shapeTypes.Add( TopAbs_SHELL );
285 shapeTypes.Add( TopAbs_SOLID );
286 shapeTypes.Add( TopAbs_COMPSOLID );
287 shapeTypes.Add( TopAbs_COMPOUND );
290 return new SMESH_NumberFilter("GEOM", subShapeType, nbSubShapes,
291 shapeTypes, GEOM::GEOM_Object::_nil(), closed);
294 //================================================================================
296 * \brief Create a widget for object selection
297 * \param object - initial object
298 * \param filter - selection filter
299 * \retval QWidget* - created widget
301 //================================================================================
303 QWidget* newObjRefParamWdg( SUIT_SelectionFilter* filter,
304 CORBA::Object_var object)
306 StdMeshersGUI_ObjectReferenceParamWdg* w =
307 new StdMeshersGUI_ObjectReferenceParamWdg( filter, 0);
308 w->SetObject( object.in() );
312 //================================================================================
314 * \brief calls deactivateSelection() for StdMeshersGUI_ObjectReferenceParamWdg
315 * \param widgetList - list of widgets
317 //================================================================================
319 void deactivateObjRefParamWdg( QList<QWidget*>* widgetList )
321 StdMeshersGUI_ObjectReferenceParamWdg* w = 0;
322 QList<QWidget*>::iterator anIt = widgetList->begin();
323 QList<QWidget*>::iterator aLast = widgetList->end();
324 for ( ; anIt != aLast; anIt++ ) {
325 if ( (*anIt) && (*anIt)->inherits( "StdMeshersGUI_ObjectReferenceParamWdg" ))
327 w = (StdMeshersGUI_ObjectReferenceParamWdg* )( *anIt );
328 w->deactivateSelection();
334 //================================================================================
336 * \brief Check parameter values before accept()
337 * \retval bool - true if OK
339 //================================================================================
341 bool StdMeshersGUI_StdHypothesisCreator::checkParams() const
343 // check if object reference parameter is set, as it has no default value
345 if ( hypType().startsWith("ProjectionSource" ))
347 StdMeshersGUI_ObjectReferenceParamWdg* w =
348 widget< StdMeshersGUI_ObjectReferenceParamWdg >( 0 );
349 ok = ( w->IsObjectSelected() );
350 if ( !ok ) w->SetObject( CORBA::Object::_nil() );
351 int nbAssocVert = ( hypType() == "ProjectionSource1D" ? 1 : 2 );
352 for ( int i = 0; ok && i < nbAssocVert; i += 2)
355 StdMeshersGUI_ObjectReferenceParamWdg* w1 =
356 widget< StdMeshersGUI_ObjectReferenceParamWdg >( i+2 );
357 StdMeshersGUI_ObjectReferenceParamWdg* w2 =
358 widget< StdMeshersGUI_ObjectReferenceParamWdg >( i+3 );
359 srcV = w1->GetValue();
360 tgtV = w2->GetValue();
361 ok = (( srcV.isEmpty() && tgtV.isEmpty() ) ||
362 ( !srcV.isEmpty() && !tgtV.isEmpty() && srcV != tgtV ));
364 w1->SetObject( CORBA::Object::_nil() );
365 w2->SetObject( CORBA::Object::_nil() );
369 // Uninstall filters of StdMeshersGUI_ObjectReferenceParamWdg
371 deactivateObjRefParamWdg( customWidgets() );
373 else if ( hypType() == "LayerDistribution" )
375 StdMeshersGUI_LayerDistributionParamWdg* w =
376 widget< StdMeshersGUI_LayerDistributionParamWdg >( 0 );
377 ok = ( w && w->IsOk() );
382 //================================================================================
384 * \brief Store params from GUI controls to a hypothesis
385 * \retval QString - text representation of parameters
387 //================================================================================
389 QString StdMeshersGUI_StdHypothesisCreator::storeParams() const
391 ListOfStdParams params;
392 bool res = getStdParamFromDlg( params );
395 SMESH::SetName( SMESH::FindSObject( hypothesis() ), params[0].myValue.toString().toLatin1().data() );
396 params.erase( params.begin() );
399 QString valueStr = stdParamValues( params );
401 if( res && !params.isEmpty() )
403 if( hypType()=="LocalLength" )
405 StdMeshers::StdMeshers_LocalLength_var h =
406 StdMeshers::StdMeshers_LocalLength::_narrow( hypothesis() );
408 h->SetLength( params[0].myValue.toDouble() );
409 h->SetPrecision( params[1].myValue.toDouble() );
411 else if( hypType()=="SegmentLengthAroundVertex" )
413 StdMeshers::StdMeshers_SegmentLengthAroundVertex_var h =
414 StdMeshers::StdMeshers_SegmentLengthAroundVertex::_narrow( hypothesis() );
416 h->SetLength( params[0].myValue.toDouble() );
418 else if( hypType()=="Arithmetic1D" )
420 StdMeshers::StdMeshers_Arithmetic1D_var h =
421 StdMeshers::StdMeshers_Arithmetic1D::_narrow( hypothesis() );
423 h->SetLength( params[0].myValue.toDouble(), true );
424 h->SetLength( params[1].myValue.toDouble(), false );
426 else if( hypType()=="MaxElementArea" )
428 StdMeshers::StdMeshers_MaxElementArea_var h =
429 StdMeshers::StdMeshers_MaxElementArea::_narrow( hypothesis() );
431 h->SetMaxElementArea( params[0].myValue.toDouble() );
433 else if( hypType()=="MaxElementVolume" )
435 StdMeshers::StdMeshers_MaxElementVolume_var h =
436 StdMeshers::StdMeshers_MaxElementVolume::_narrow( hypothesis() );
438 h->SetMaxElementVolume( params[0].myValue.toDouble() );
440 else if( hypType()=="StartEndLength" )
442 StdMeshers::StdMeshers_StartEndLength_var h =
443 StdMeshers::StdMeshers_StartEndLength::_narrow( hypothesis() );
445 h->SetLength( params[0].myValue.toDouble(), true );
446 h->SetLength( params[1].myValue.toDouble(), false );
448 else if( hypType()=="Deflection1D" )
450 StdMeshers::StdMeshers_Deflection1D_var h =
451 StdMeshers::StdMeshers_Deflection1D::_narrow( hypothesis() );
453 h->SetDeflection( params[0].myValue.toDouble() );
455 else if( hypType()=="AutomaticLength" )
457 StdMeshers::StdMeshers_AutomaticLength_var h =
458 StdMeshers::StdMeshers_AutomaticLength::_narrow( hypothesis() );
460 h->SetFineness( params[0].myValue.toDouble() );
462 else if( hypType()=="NumberOfLayers" )
464 StdMeshers::StdMeshers_NumberOfLayers_var h =
465 StdMeshers::StdMeshers_NumberOfLayers::_narrow( hypothesis() );
467 h->SetNumberOfLayers( params[0].myValue.toInt() );
469 else if( hypType()=="LayerDistribution" )
471 StdMeshers::StdMeshers_LayerDistribution_var h =
472 StdMeshers::StdMeshers_LayerDistribution::_narrow( hypothesis() );
473 StdMeshersGUI_LayerDistributionParamWdg* w =
474 widget< StdMeshersGUI_LayerDistributionParamWdg >( 0 );
476 h->SetLayerDistribution( w->GetHypothesis() );
478 else if( hypType()=="ProjectionSource1D" )
480 StdMeshers::StdMeshers_ProjectionSource1D_var h =
481 StdMeshers::StdMeshers_ProjectionSource1D::_narrow( hypothesis() );
483 h->SetSourceEdge ( geomFromWdg ( getWidgetForParam( 0 )));
484 h->SetSourceMesh ( meshFromWdg ( getWidgetForParam( 1 )));
485 h->SetVertexAssociation( geomFromWdg ( getWidgetForParam( 2 )),
486 geomFromWdg ( getWidgetForParam( 3 )));
488 else if( hypType()=="ProjectionSource2D" )
490 StdMeshers::StdMeshers_ProjectionSource2D_var h =
491 StdMeshers::StdMeshers_ProjectionSource2D::_narrow( hypothesis() );
493 h->SetSourceFace ( geomFromWdg ( getWidgetForParam( 0 )));
494 h->SetSourceMesh ( meshFromWdg ( getWidgetForParam( 1 )));
495 h->SetVertexAssociation( geomFromWdg ( getWidgetForParam( 2 )), // src1
496 geomFromWdg ( getWidgetForParam( 4 )), // src2
497 geomFromWdg ( getWidgetForParam( 3 )), // tgt1
498 geomFromWdg ( getWidgetForParam( 5 ))); // tgt2
500 else if( hypType()=="ProjectionSource3D" )
502 StdMeshers::StdMeshers_ProjectionSource3D_var h =
503 StdMeshers::StdMeshers_ProjectionSource3D::_narrow( hypothesis() );
505 h->SetSource3DShape ( geomFromWdg ( getWidgetForParam( 0 )));
506 h->SetSourceMesh ( meshFromWdg ( getWidgetForParam( 1 )));
507 h->SetVertexAssociation( geomFromWdg ( getWidgetForParam( 2 )), // src1
508 geomFromWdg ( getWidgetForParam( 4 )), // src2
509 geomFromWdg ( getWidgetForParam( 3 )), // tgt1
510 geomFromWdg ( getWidgetForParam( 5 ))); // tgt2
516 //================================================================================
518 * \brief Return parameter values as SMESHGUI_GenericHypothesisCreator::StdParam
519 * \param p - list of parameters
520 * \retval bool - success flag
522 * Is called from SMESHGUI_GenericHypothesisCreator::buildStdFrame().
523 * Parameters will be shown using "standard" controls:
524 * Int by QtxIntSpinBox
525 * Double by SMESHGUI_SpinBox
526 * String by QLineEdit
527 * getCustomWidget() allows to redefine control for a parameter
529 //================================================================================
531 bool StdMeshersGUI_StdHypothesisCreator::stdParams( ListOfStdParams& p ) const
534 SMESHGUI_GenericHypothesisCreator::StdParam item;
537 customWidgets()->clear();
540 HypothesisData* data = SMESH::GetHypothesisData( hypType() );
541 item.myName = tr( "SMESH_NAME" );
542 item.myValue = data ? hypName() : QString();
544 customWidgets()->append(0);
547 SMESH::SMESH_Hypothesis_var hyp = initParamsHypothesis();
549 if( hypType()=="LocalLength" )
551 StdMeshers::StdMeshers_LocalLength_var h =
552 StdMeshers::StdMeshers_LocalLength::_narrow( hyp );
554 item.myName = tr("SMESH_LOCAL_LENGTH_PARAM");
555 item.myValue = h->GetLength();
557 item.myName = tr("SMESH_LOCAL_LENGTH_PRECISION");
558 item.myValue = h->GetPrecision();
561 else if( hypType()=="SegmentLengthAroundVertex" )
563 StdMeshers::StdMeshers_SegmentLengthAroundVertex_var h =
564 StdMeshers::StdMeshers_SegmentLengthAroundVertex::_narrow( hyp );
566 item.myName = tr("SMESH_LOCAL_LENGTH_PARAM");
567 item.myValue = h->GetLength();
570 else if( hypType()=="Arithmetic1D" )
572 StdMeshers::StdMeshers_Arithmetic1D_var h =
573 StdMeshers::StdMeshers_Arithmetic1D::_narrow( hyp );
575 item.myName = tr( "SMESH_START_LENGTH_PARAM" );
576 item.myValue = h->GetLength( true );
578 item.myName = tr( "SMESH_END_LENGTH_PARAM" );
579 item.myValue = h->GetLength( false );
582 else if( hypType()=="MaxElementArea" )
584 StdMeshers::StdMeshers_MaxElementArea_var h =
585 StdMeshers::StdMeshers_MaxElementArea::_narrow( hyp );
587 item.myName = tr( "SMESH_MAX_ELEMENT_AREA_PARAM" );
588 item.myValue = h->GetMaxElementArea();
591 else if( hypType()=="MaxElementVolume" )
593 StdMeshers::StdMeshers_MaxElementVolume_var h =
594 StdMeshers::StdMeshers_MaxElementVolume::_narrow( hyp );
596 item.myName = tr( "SMESH_MAX_ELEMENT_VOLUME_PARAM" );
597 item.myValue = h->GetMaxElementVolume();
600 else if( hypType()=="StartEndLength" )
602 StdMeshers::StdMeshers_StartEndLength_var h =
603 StdMeshers::StdMeshers_StartEndLength::_narrow( hyp );
605 item.myName = tr( "SMESH_START_LENGTH_PARAM" );
606 item.myValue = h->GetLength( true );
608 item.myName = tr( "SMESH_END_LENGTH_PARAM" );
609 item.myValue = h->GetLength( false );
612 else if( hypType()=="Deflection1D" )
614 StdMeshers::StdMeshers_Deflection1D_var h =
615 StdMeshers::StdMeshers_Deflection1D::_narrow( hyp );
617 item.myName = tr( "SMESH_DEFLECTION1D_PARAM" );
618 item.myValue = h->GetDeflection();
621 else if( hypType()=="AutomaticLength" )
623 StdMeshers::StdMeshers_AutomaticLength_var h =
624 StdMeshers::StdMeshers_AutomaticLength::_narrow( hyp );
626 item.myName = tr( "SMESH_FINENESS_PARAM" );
627 //item.myValue = h->GetFineness();
629 customWidgets()->append
630 ( new TDoubleSliderWith2Lables( "0 ", " 1", h->GetFineness(), 0, 1, 0.01, 0 ));
632 else if( hypType()=="NumberOfLayers" )
634 StdMeshers::StdMeshers_NumberOfLayers_var h =
635 StdMeshers::StdMeshers_NumberOfLayers::_narrow( hyp );
637 item.myName = tr( "SMESH_NUMBER_OF_LAYERS" );
638 item.myValue = (int) h->GetNumberOfLayers();
641 else if( hypType()=="LayerDistribution" )
643 StdMeshers::StdMeshers_LayerDistribution_var h =
644 StdMeshers::StdMeshers_LayerDistribution::_narrow( hyp );
646 item.myName = tr( "SMESH_LAYERS_DISTRIBUTION" ); p.append( item );
647 customWidgets()->append
648 ( new StdMeshersGUI_LayerDistributionParamWdg( h->GetLayerDistribution(), hypName(), dlg()));
650 else if( hypType()=="ProjectionSource1D" )
652 StdMeshers::StdMeshers_ProjectionSource1D_var h =
653 StdMeshers::StdMeshers_ProjectionSource1D::_narrow( hyp );
655 item.myName = tr( "SMESH_SOURCE_EDGE" ); p.append( item );
656 customWidgets()->append( newObjRefParamWdg( filterForShapeOfDim( 1 ),
657 h->GetSourceEdge()));
658 item.myName = tr( "SMESH_SOURCE_MESH" ); p.append( item );
659 customWidgets()->append( newObjRefParamWdg( new SMESH_TypeFilter( MESH ),
660 h->GetSourceMesh()));
661 item.myName = tr( "SMESH_SOURCE_VERTEX" ); p.append( item );
662 customWidgets()->append( newObjRefParamWdg( filterForShapeOfDim( 0 ),
663 h->GetSourceVertex()));
664 item.myName = tr( "SMESH_TARGET_VERTEX" ); p.append( item );
665 customWidgets()->append( newObjRefParamWdg( filterForShapeOfDim( 0 ),
666 h->GetTargetVertex()));
668 else if( hypType()=="ProjectionSource2D" )
670 StdMeshers::StdMeshers_ProjectionSource2D_var h =
671 StdMeshers::StdMeshers_ProjectionSource2D::_narrow( hyp );
673 item.myName = tr( "SMESH_SOURCE_FACE" ); p.append( item );
674 customWidgets()->append( newObjRefParamWdg( filterForShapeOfDim( 2 ),
675 h->GetSourceFace()));
676 item.myName = tr( "SMESH_SOURCE_MESH" ); p.append( item );
677 customWidgets()->append( newObjRefParamWdg( new SMESH_TypeFilter( MESH ),
678 h->GetSourceMesh()));
679 item.myName = tr( "SMESH_SOURCE_VERTEX1" ); p.append( item );
680 customWidgets()->append( newObjRefParamWdg( filterForShapeOfDim( 0 ),
681 h->GetSourceVertex( 1 )));
682 item.myName = tr( "SMESH_TARGET_VERTEX1" ); p.append( item );
683 customWidgets()->append( newObjRefParamWdg( filterForShapeOfDim( 0 ),
684 h->GetTargetVertex( 1 )));
685 item.myName = tr( "SMESH_SOURCE_VERTEX2" ); p.append( item );
686 customWidgets()->append( newObjRefParamWdg( filterForShapeOfDim( 0 ),
687 h->GetSourceVertex( 2 )));
688 item.myName = tr( "SMESH_TARGET_VERTEX2" ); p.append( item );
689 customWidgets()->append( newObjRefParamWdg( filterForShapeOfDim( 0 ),
690 h->GetTargetVertex( 2 )));
692 else if( hypType()=="ProjectionSource3D" )
694 StdMeshers::StdMeshers_ProjectionSource3D_var h =
695 StdMeshers::StdMeshers_ProjectionSource3D::_narrow( hyp );
697 item.myName = tr( "SMESH_SOURCE_3DSHAPE" ); p.append( item );
698 customWidgets()->append( newObjRefParamWdg( filterForShapeOfDim( 3, TopAbs_FACE, 6, true ),
699 h->GetSource3DShape()));
700 item.myName = tr( "SMESH_SOURCE_MESH" ); p.append( item );
701 customWidgets()->append( newObjRefParamWdg( new SMESH_TypeFilter( MESH ),
702 h->GetSourceMesh()));
703 item.myName = tr( "SMESH_SOURCE_VERTEX1" ); p.append( item );
704 customWidgets()->append( newObjRefParamWdg( filterForShapeOfDim( 0 ),
705 h->GetSourceVertex( 1 )));
706 item.myName = tr( "SMESH_TARGET_VERTEX1" ); p.append( item );
707 customWidgets()->append( newObjRefParamWdg( filterForShapeOfDim( 0 ),
708 h->GetTargetVertex( 1 )));
709 item.myName = tr( "SMESH_SOURCE_VERTEX2" ); p.append( item );
710 customWidgets()->append( newObjRefParamWdg( filterForShapeOfDim( 0 ),
711 h->GetSourceVertex( 2 )));
712 item.myName = tr( "SMESH_TARGET_VERTEX2" ); p.append( item );
713 customWidgets()->append( newObjRefParamWdg( filterForShapeOfDim( 0 ),
714 h->GetTargetVertex( 2 )));
721 //================================================================================
723 * \brief tune "standard" control
724 * \param w - control widget
725 * \param int - parameter index
727 //================================================================================
729 void StdMeshersGUI_StdHypothesisCreator::attuneStdWidget (QWidget* w, const int) const
731 SMESHGUI_SpinBox* sb = w->inherits( "SMESHGUI_SpinBox" ) ? ( SMESHGUI_SpinBox* )w : 0;
732 if( hypType()=="LocalLength" && sb )
734 if (sb->objectName() == tr("SMESH_LOCAL_LENGTH_PARAM"))
735 sb->RangeStepAndValidator( VALUE_SMALL, VALUE_MAX, 1.0, 6 );
736 else if (sb->objectName() == tr("SMESH_LOCAL_LENGTH_PRECISION"))
737 sb->RangeStepAndValidator( 0.0, 1.0, 0.05, 7 );
739 else if( hypType()=="Arithmetic1D" && sb )
741 sb->RangeStepAndValidator( VALUE_SMALL, VALUE_MAX, 1.0, 6 );
743 else if( hypType()=="MaxElementArea" && sb )
745 sb->RangeStepAndValidator( VALUE_SMALL_2, VALUE_MAX_2, 1.0, 6 );
747 else if( hypType()=="MaxElementVolume" && sb )
749 sb->RangeStepAndValidator( VALUE_SMALL_3, VALUE_MAX_3, 1.0, 6 );
751 else if( hypType()=="StartEndLength" && sb )
753 sb->RangeStepAndValidator( VALUE_SMALL, VALUE_MAX, 1.0, 6 );
755 else if( hypType()=="Deflection1D" && sb )
757 sb->RangeStepAndValidator( VALUE_SMALL, VALUE_MAX, 1.0, 6 );
759 else if ( sb ) // default validator for possible ancestors
761 sb->RangeStepAndValidator( VALUE_SMALL, VALUE_MAX, 1.0, 6 );
765 //================================================================================
767 * \brief Return dlg title
768 * \retval QString - title string
770 //================================================================================
772 QString StdMeshersGUI_StdHypothesisCreator::caption() const
774 return tr( QString( "SMESH_%1_TITLE" ).arg( hypTypeName( hypType() ) ).toLatin1().data() );
777 //================================================================================
779 * \brief return pixmap for dlg icon
782 //================================================================================
784 QPixmap StdMeshersGUI_StdHypothesisCreator::icon() const
786 QString hypIconName = tr( QString( "ICON_DLG_%1" ).arg( hypTypeName( hypType() ) ).toLatin1().data() );
787 return SMESHGUI::resourceMgr()->loadPixmap( "SMESH", hypIconName );
790 //================================================================================
792 * \brief Return hypothesis type name to show in dlg
795 //================================================================================
797 QString StdMeshersGUI_StdHypothesisCreator::type() const
799 return tr( QString( "SMESH_%1_HYPOTHESIS" ).arg( hypTypeName( hypType() ) ).toLatin1().data() );
802 //================================================================================
804 * \brief String to insert in "SMESH_%1_HYPOTHESIS" to get hypothesis type name
805 * from message resouce file
806 * \param t - hypothesis type
807 * \retval QString - result string
809 //================================================================================
811 QString StdMeshersGUI_StdHypothesisCreator::hypTypeName( const QString& t ) const
813 static QMap<QString,QString> types;
814 if( types.isEmpty() )
816 types.insert( "LocalLength", "LOCAL_LENGTH" );
817 types.insert( "NumberOfSegments", "NB_SEGMENTS" );
818 types.insert( "MaxElementArea", "MAX_ELEMENT_AREA" );
819 types.insert( "MaxElementVolume", "MAX_ELEMENT_VOLUME" );
820 types.insert( "StartEndLength", "START_END_LENGTH" );
821 types.insert( "Deflection1D", "DEFLECTION1D" );
822 types.insert( "Arithmetic1D", "ARITHMETIC_1D" );
823 types.insert( "AutomaticLength", "AUTOMATIC_LENGTH" );
824 types.insert( "ProjectionSource1D", "PROJECTION_SOURCE_1D" );
825 types.insert( "ProjectionSource2D", "PROJECTION_SOURCE_2D" );
826 types.insert( "ProjectionSource3D", "PROJECTION_SOURCE_3D" );
827 types.insert( "NumberOfLayers", "NUMBER_OF_LAYERS" );
828 types.insert( "LayerDistribution", "LAYER_DISTRIBUTION" );
829 types.insert( "SegmentLengthAroundVertex", "SEGMENT_LENGTH_AROUND_VERTEX" );
833 if( types.contains( t ) )
840 //=======================================================================
841 //function : getCustomWidget
842 //purpose : is called from buildStdFrame()
843 //=======================================================================
845 QWidget* StdMeshersGUI_StdHypothesisCreator::getCustomWidget( const StdParam & param,
847 const int index) const
850 if ( index < customWidgets()->count() ) {
851 w = customWidgets()->at( index );
853 w->setParent( parent );
854 w->move( QPoint( 0, 0 ) );
860 //================================================================================
862 * \brief Set param value taken from a custom widget
863 * \param param - SMESHGUI_GenericHypothesisCreator::StdParam structure
864 * \param widget - widget presenting param
865 * \retval bool - success flag
867 * this method is called from getStdParamFromDlg()
869 //================================================================================
871 bool StdMeshersGUI_StdHypothesisCreator::getParamFromCustomWidget( StdParam & param,
872 QWidget* widget) const
874 if ( hypType()=="AutomaticLength" ) {
875 TDoubleSliderWith2Lables* w = dynamic_cast<TDoubleSliderWith2Lables*>( widget );
877 param.myValue = w->value();
881 if ( widget->inherits( "StdMeshersGUI_ObjectReferenceParamWdg" ))
883 // show only 1st reference value
884 if ( true /*widget == getWidgetForParam( 0 )*/) {
885 const StdMeshersGUI_ObjectReferenceParamWdg * w =
886 static_cast<const StdMeshersGUI_ObjectReferenceParamWdg*>( widget );
887 param.myValue = w->GetValue();
891 if ( widget->inherits( "StdMeshersGUI_LayerDistributionParamWdg" ))
893 const StdMeshersGUI_LayerDistributionParamWdg * w =
894 static_cast<const StdMeshersGUI_LayerDistributionParamWdg*>( widget );
895 param.myValue = w->GetValue();
901 //================================================================================
903 * \brief called when operation cancelled
905 //================================================================================
907 void StdMeshersGUI_StdHypothesisCreator::onReject()
909 if ( hypType().startsWith("ProjectionSource" ))
911 // Uninstall filters of StdMeshersGUI_ObjectReferenceParamWdg
912 deactivateObjRefParamWdg( customWidgets() );