1 // SMESH StdMeshersGUI : GUI for plugged-in meshers
3 // Copyright (C) 2003 CEA
5 // This library is free software; you can redistribute it and/or
6 // modify it under the terms of the GNU Lesser General Public
7 // License as published by the Free Software Foundation; either
8 // version 2.1 of the License.
10 // This library is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 // Lesser General Public License for more details.
15 // You should have received a copy of the GNU Lesser General Public
16 // License along with this library; if not, write to the Free Software
17 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
23 // File : StdMeshersGUI_StdHypothesisCreator.cxx
24 // Author : Alexander SOLOVYOV
26 // $Header: /home/server/cvs/SMESH/SMESH_SRC/src/StdMeshersGUI/StdMeshersGUI_StdHypothesisCreator.cxx
28 #include "StdMeshersGUI_StdHypothesisCreator.h"
31 #include "SMESHGUI_SpinBox.h"
32 #include "SMESHGUI_HypothesesUtils.h"
33 #include "SMESHGUI_Utils.h"
34 #include "SMESH_TypeFilter.hxx"
35 #include "SMESH_NumberFilter.hxx"
36 #include "StdMeshersGUI_ObjectReferenceParamWdg.h"
37 #include "StdMeshersGUI_LayerDistributionParamWdg.h"
39 #include "SUIT_ResourceMgr.h"
41 #include <SALOMEconfig.h>
42 #include CORBA_SERVER_HEADER(SMESH_BasicHypothesis)
43 #include CORBA_SERVER_HEADER(SMESH_Mesh)
51 const double VALUE_MAX = 1.0e+15, // COORD_MAX
52 VALUE_MAX_2 = VALUE_MAX * VALUE_MAX,
53 VALUE_MAX_3 = VALUE_MAX_2 * VALUE_MAX,
54 VALUE_SMALL = 1.0e-15,
55 VALUE_SMALL_2 = VALUE_SMALL * VALUE_SMALL,
56 VALUE_SMALL_3 = VALUE_SMALL_2 * VALUE_SMALL;
58 //================================================================================
61 * \param type - hypothesis type
63 //================================================================================
65 StdMeshersGUI_StdHypothesisCreator::StdMeshersGUI_StdHypothesisCreator( const QString& type )
66 : SMESHGUI_GenericHypothesisCreator( type )
70 //================================================================================
74 //================================================================================
76 StdMeshersGUI_StdHypothesisCreator::~StdMeshersGUI_StdHypothesisCreator()
80 //================================================================================
82 * \brief Return widget for i-th hypothesis parameter (got from myParamWidgets)
83 * \param i - index of hypothesis parameter
84 * \retval QWidget* - found widget
86 //================================================================================
88 QWidget* StdMeshersGUI_StdHypothesisCreator::getWidgetForParam( int i ) const
91 if ( isCreation() ) ++i; // skip widget of 'name' parameter
93 if ( i < myCustomWidgets.count() ) {
94 QPtrList<QWidget>::const_iterator anIt = myCustomWidgets.begin();
95 QPtrList<QWidget>::const_iterator aLast = myCustomWidgets.end();
96 for ( int j = 0 ; !w && anIt != aLast; ++anIt )
101 // list has no at() const, so we iterate
102 QPtrList<QWidget>::const_iterator anIt = widgets().begin();
103 QPtrList<QWidget>::const_iterator aLast = widgets().end();
104 for( int j = 0; !w && anIt!=aLast; anIt++, ++j ) {
112 //================================================================================
114 * \brief Allow modifing myCustomWidgets in const methods
115 * \retval ListOfWidgets* - non-const pointer to myCustomWidgets
117 //================================================================================
119 StdMeshersGUI_StdHypothesisCreator::ListOfWidgets*
120 StdMeshersGUI_StdHypothesisCreator::customWidgets() const
122 return const_cast< ListOfWidgets* >( & myCustomWidgets );
125 //================================================================================
127 * \brief Builds dlg layout
128 * \retval QFrame* - the built widget
130 //================================================================================
132 QFrame* StdMeshersGUI_StdHypothesisCreator::buildFrame()
134 return buildStdFrame();
137 //================================================================================
139 * \brief Initialise parameter values in controls
141 //================================================================================
143 void StdMeshersGUI_StdHypothesisCreator::retrieveParams() const
145 // buildStdFrame() sets values itself calling stdParams()
147 if ( hypType().startsWith("ProjectionSource" ))
149 // we use this method to connect depending custom widgets
150 StdMeshersGUI_ObjectReferenceParamWdg* widgetToActivate = 0;
151 ListOfWidgets::const_iterator anIt = myCustomWidgets.begin();
152 for ( ; anIt != myCustomWidgets.end(); anIt++)
154 if ( *anIt && (*anIt)->inherits("StdMeshersGUI_ObjectReferenceParamWdg"))
156 StdMeshersGUI_ObjectReferenceParamWdg * w1 =
157 ( StdMeshersGUI_ObjectReferenceParamWdg* ) ( *anIt );
158 ListOfWidgets::const_iterator anIt2 = anIt;
159 for ( ++anIt2; anIt2 != myCustomWidgets.end(); anIt2++)
160 if ( *anIt2 && (*anIt2)->inherits("StdMeshersGUI_ObjectReferenceParamWdg"))
162 StdMeshersGUI_ObjectReferenceParamWdg * w2 =
163 ( StdMeshersGUI_ObjectReferenceParamWdg* ) ( *anIt2 );
164 w1->AvoidSimultaneousSelection( w2 );
166 if ( !widgetToActivate )
167 widgetToActivate = w1;
170 if ( widgetToActivate )
171 widgetToActivate->activateSelection();
177 //================================================================================
179 * \brief Widget: slider with left and right labels
181 //================================================================================
183 class TDoubleSliderWith2Lables: public QHBox
186 TDoubleSliderWith2Lables( const QString& leftLabel, const QString& rightLabel,
187 const double initValue, const double bottom,
188 const double top , const double precision,
189 QWidget * parent=0 , const char * name=0 )
190 :QHBox(parent,name), _bottom(bottom), _precision(precision)
192 if ( !leftLabel.isEmpty() ) (new QLabel( this ))->setText( leftLabel );
193 _slider = new QSlider( Horizontal, this );
194 _slider->setRange( 0, toInt( top ));
195 _slider->setValue( toInt( initValue ));
196 if ( !rightLabel.isEmpty() ) (new QLabel( this ))->setText( rightLabel );
198 double value() const { return _bottom + _slider->value() * _precision; }
199 QSlider * getSlider() const { return _slider; }
200 int toInt( double val ) const { return (int) ceil(( val - _bottom ) / _precision ); }
202 double _bottom, _precision;
206 //================================================================================
208 * \brief Retrieve GEOM_Object held by widget
210 //================================================================================
212 inline GEOM::GEOM_Object_var geomFromWdg(const QWidget* wdg)
214 const StdMeshersGUI_ObjectReferenceParamWdg * objRefWdg =
215 dynamic_cast<const StdMeshersGUI_ObjectReferenceParamWdg*>( wdg );
217 return objRefWdg->GetObject< GEOM::GEOM_Object >();
219 return GEOM::GEOM_Object::_nil();
221 //================================================================================
223 * \brief Retrieve SMESH_Mesh held by widget
225 //================================================================================
227 inline SMESH::SMESH_Mesh_var meshFromWdg(const QWidget* wdg)
229 const StdMeshersGUI_ObjectReferenceParamWdg * objRefWdg =
230 dynamic_cast<const StdMeshersGUI_ObjectReferenceParamWdg*>( wdg );
232 return objRefWdg->GetObject< SMESH::SMESH_Mesh >();
234 return SMESH::SMESH_Mesh::_nil();
236 //================================================================================
238 * \brief creates a filter for selection of shapes of given dimension
239 * \param dim - dimension
240 * \param subShapeType - required type of subshapes, number of which must be \a nbSubShapes
241 * \param nbSubShapes - number of subshapes of given type
242 * \param closed - required closeness flag of a shape
243 * \retval SUIT_SelectionFilter* - created filter
245 //================================================================================
247 SUIT_SelectionFilter* filterForShapeOfDim(const int dim,
248 TopAbs_ShapeEnum subShapeType = TopAbs_SHAPE,
249 const int nbSubShapes = 0,
252 TColStd_MapOfInteger shapeTypes;
254 case 0: shapeTypes.Add( TopAbs_VERTEX ); break;
256 if ( subShapeType == TopAbs_SHAPE ) subShapeType = TopAbs_EDGE;
257 shapeTypes.Add( TopAbs_EDGE );
258 shapeTypes.Add( TopAbs_COMPOUND ); // for a group
261 if ( subShapeType == TopAbs_SHAPE ) subShapeType = TopAbs_FACE;
262 shapeTypes.Add( TopAbs_FACE );
263 shapeTypes.Add( TopAbs_COMPOUND ); // for a group
266 shapeTypes.Add( TopAbs_SHELL );
267 shapeTypes.Add( TopAbs_SOLID );
268 shapeTypes.Add( TopAbs_COMPSOLID );
269 shapeTypes.Add( TopAbs_COMPOUND );
272 return new SMESH_NumberFilter("GEOM", subShapeType, nbSubShapes,
273 shapeTypes, GEOM::GEOM_Object::_nil(), closed);
276 //================================================================================
278 * \brief Create a widget for object selection
279 * \param object - initial object
280 * \param filter - selection filter
281 * \retval QWidget* - created widget
283 //================================================================================
285 QWidget* newObjRefParamWdg( SUIT_SelectionFilter* filter,
286 CORBA::Object_var object)
288 StdMeshersGUI_ObjectReferenceParamWdg* w =
289 new StdMeshersGUI_ObjectReferenceParamWdg( filter, 0);
290 w->SetObject( object.in() );
294 //================================================================================
296 * \brief calls deactivateSelection() for StdMeshersGUI_ObjectReferenceParamWdg
297 * \param widgetList - list of widgets
299 //================================================================================
301 void deactivateObjRefParamWdg( QPtrList<QWidget>* widgetList )
303 StdMeshersGUI_ObjectReferenceParamWdg* w = 0;
304 QPtrList<QWidget>::iterator anIt = widgetList->begin();
305 QPtrList<QWidget>::iterator aLast = widgetList->end();
306 for ( ; anIt != aLast; anIt++ ) {
307 if ( (*anIt) && (*anIt)->inherits( "StdMeshersGUI_ObjectReferenceParamWdg" ))
309 w = (StdMeshersGUI_ObjectReferenceParamWdg* )( *anIt );
310 w->deactivateSelection();
316 //================================================================================
318 * \brief Check parameter values before accept()
319 * \retval bool - true if OK
321 //================================================================================
323 bool StdMeshersGUI_StdHypothesisCreator::checkParams() const
325 // check if object reference parameter is set, as it has no default value
327 if ( hypType().startsWith("ProjectionSource" ))
329 StdMeshersGUI_ObjectReferenceParamWdg* w =
330 widget< StdMeshersGUI_ObjectReferenceParamWdg >( 0 );
331 ok = ( w->IsObjectSelected() );
332 if ( !ok ) w->SetObject( CORBA::Object::_nil() );
333 int nbAssocVert = ( hypType() == "ProjectionSource1D" ? 1 : 2 );
334 for ( int i = 0; ok && i < nbAssocVert; i += 2)
337 StdMeshersGUI_ObjectReferenceParamWdg* w1 =
338 widget< StdMeshersGUI_ObjectReferenceParamWdg >( i+2 );
339 StdMeshersGUI_ObjectReferenceParamWdg* w2 =
340 widget< StdMeshersGUI_ObjectReferenceParamWdg >( i+3 );
341 srcV = w1->GetValue();
342 tgtV = w2->GetValue();
343 ok = (( srcV.isEmpty() && tgtV.isEmpty() ) ||
344 ( !srcV.isEmpty() && !tgtV.isEmpty() && srcV != tgtV ));
346 w1->SetObject( CORBA::Object::_nil() );
347 w2->SetObject( CORBA::Object::_nil() );
351 // Uninstall filters of StdMeshersGUI_ObjectReferenceParamWdg
353 deactivateObjRefParamWdg( customWidgets() );
355 else if ( hypType() == "LayerDistribution" )
357 StdMeshersGUI_LayerDistributionParamWdg* w =
358 widget< StdMeshersGUI_LayerDistributionParamWdg >( 0 );
359 ok = ( w && w->IsOk() );
364 //================================================================================
366 * \brief Store params from GUI controls to a hypothesis
367 * \retval QString - text representation of parameters
369 //================================================================================
371 QString StdMeshersGUI_StdHypothesisCreator::storeParams() const
373 ListOfStdParams params;
374 bool res = getStdParamFromDlg( params );
377 SMESH::SetName( SMESH::FindSObject( hypothesis() ), params[0].myValue.toString().latin1() );
378 params.remove( params.begin() );
381 QString valueStr = stdParamValues( params );
383 if( res && !params.isEmpty() )
385 if( hypType()=="LocalLength" )
387 StdMeshers::StdMeshers_LocalLength_var h =
388 StdMeshers::StdMeshers_LocalLength::_narrow( hypothesis() );
390 h->SetLength( params[0].myValue.toDouble() );
392 else if( hypType()=="SegmentLengthAroundVertex" )
394 StdMeshers::StdMeshers_SegmentLengthAroundVertex_var h =
395 StdMeshers::StdMeshers_SegmentLengthAroundVertex::_narrow( hypothesis() );
397 h->SetLength( params[0].myValue.toDouble() );
399 else if( hypType()=="Arithmetic1D" )
401 StdMeshers::StdMeshers_Arithmetic1D_var h =
402 StdMeshers::StdMeshers_Arithmetic1D::_narrow( hypothesis() );
404 h->SetLength( params[0].myValue.toDouble(), true );
405 h->SetLength( params[1].myValue.toDouble(), false );
407 else if( hypType()=="MaxElementArea" )
409 StdMeshers::StdMeshers_MaxElementArea_var h =
410 StdMeshers::StdMeshers_MaxElementArea::_narrow( hypothesis() );
412 h->SetMaxElementArea( params[0].myValue.toDouble() );
414 else if( hypType()=="MaxElementVolume" )
416 StdMeshers::StdMeshers_MaxElementVolume_var h =
417 StdMeshers::StdMeshers_MaxElementVolume::_narrow( hypothesis() );
419 h->SetMaxElementVolume( params[0].myValue.toDouble() );
421 else if( hypType()=="StartEndLength" )
423 StdMeshers::StdMeshers_StartEndLength_var h =
424 StdMeshers::StdMeshers_StartEndLength::_narrow( hypothesis() );
426 h->SetLength( params[0].myValue.toDouble(), true );
427 h->SetLength( params[1].myValue.toDouble(), false );
429 else if( hypType()=="Deflection1D" )
431 StdMeshers::StdMeshers_Deflection1D_var h =
432 StdMeshers::StdMeshers_Deflection1D::_narrow( hypothesis() );
434 h->SetDeflection( params[0].myValue.toDouble() );
436 else if( hypType()=="AutomaticLength" )
438 StdMeshers::StdMeshers_AutomaticLength_var h =
439 StdMeshers::StdMeshers_AutomaticLength::_narrow( hypothesis() );
441 h->SetFineness( params[0].myValue.toDouble() );
443 else if( hypType()=="NumberOfLayers" )
445 StdMeshers::StdMeshers_NumberOfLayers_var h =
446 StdMeshers::StdMeshers_NumberOfLayers::_narrow( hypothesis() );
448 h->SetNumberOfLayers( params[0].myValue.toInt() );
450 else if( hypType()=="LayerDistribution" )
452 StdMeshers::StdMeshers_LayerDistribution_var h =
453 StdMeshers::StdMeshers_LayerDistribution::_narrow( hypothesis() );
454 StdMeshersGUI_LayerDistributionParamWdg* w =
455 widget< StdMeshersGUI_LayerDistributionParamWdg >( 0 );
457 h->SetLayerDistribution( w->GetHypothesis() );
459 else if( hypType()=="ProjectionSource1D" )
461 StdMeshers::StdMeshers_ProjectionSource1D_var h =
462 StdMeshers::StdMeshers_ProjectionSource1D::_narrow( hypothesis() );
464 h->SetSourceEdge ( geomFromWdg ( getWidgetForParam( 0 )));
465 h->SetSourceMesh ( meshFromWdg ( getWidgetForParam( 1 )));
466 h->SetVertexAssociation( geomFromWdg ( getWidgetForParam( 2 )),
467 geomFromWdg ( getWidgetForParam( 3 )));
469 else if( hypType()=="ProjectionSource2D" )
471 StdMeshers::StdMeshers_ProjectionSource2D_var h =
472 StdMeshers::StdMeshers_ProjectionSource2D::_narrow( hypothesis() );
474 h->SetSourceFace ( geomFromWdg ( getWidgetForParam( 0 )));
475 h->SetSourceMesh ( meshFromWdg ( getWidgetForParam( 1 )));
476 h->SetVertexAssociation( geomFromWdg ( getWidgetForParam( 2 )), // src1
477 geomFromWdg ( getWidgetForParam( 4 )), // src2
478 geomFromWdg ( getWidgetForParam( 3 )), // tgt1
479 geomFromWdg ( getWidgetForParam( 5 ))); // tgt2
481 else if( hypType()=="ProjectionSource3D" )
483 StdMeshers::StdMeshers_ProjectionSource3D_var h =
484 StdMeshers::StdMeshers_ProjectionSource3D::_narrow( hypothesis() );
486 h->SetSource3DShape ( geomFromWdg ( getWidgetForParam( 0 )));
487 h->SetSourceMesh ( meshFromWdg ( getWidgetForParam( 1 )));
488 h->SetVertexAssociation( geomFromWdg ( getWidgetForParam( 2 )), // src1
489 geomFromWdg ( getWidgetForParam( 4 )), // src2
490 geomFromWdg ( getWidgetForParam( 3 )), // tgt1
491 geomFromWdg ( getWidgetForParam( 5 ))); // tgt2
497 //================================================================================
499 * \brief Return parameter values as SMESHGUI_GenericHypothesisCreator::StdParam
500 * \param p - list of parameters
501 * \retval bool - success flag
503 * Is called from SMESHGUI_GenericHypothesisCreator::buildStdFrame().
504 * Parameters will be shown using "standard" controls:
505 * Int by QtxIntSpinBox
506 * Double by SMESHGUI_SpinBox
507 * String by QLineEdit
508 * getCustomWidget() allows to redefine control for a parameter
510 //================================================================================
512 bool StdMeshersGUI_StdHypothesisCreator::stdParams( ListOfStdParams& p ) const
515 SMESHGUI_GenericHypothesisCreator::StdParam item;
518 customWidgets()->clear();
521 HypothesisData* data = SMESH::GetHypothesisData( hypType() );
522 item.myName = tr( "SMESH_NAME" );
523 item.myValue = data ? hypName() : QString();
525 customWidgets()->append(0);
528 SMESH::SMESH_Hypothesis_var hyp = initParamsHypothesis();
530 if( hypType()=="LocalLength" )
532 StdMeshers::StdMeshers_LocalLength_var h =
533 StdMeshers::StdMeshers_LocalLength::_narrow( hyp );
535 item.myName = tr("SMESH_LOCAL_LENGTH_PARAM");
536 item.myValue = h->GetLength();
539 else if( hypType()=="SegmentLengthAroundVertex" )
541 StdMeshers::StdMeshers_SegmentLengthAroundVertex_var h =
542 StdMeshers::StdMeshers_SegmentLengthAroundVertex::_narrow( hyp );
544 item.myName = tr("SMESH_LOCAL_LENGTH_PARAM");
545 item.myValue = h->GetLength();
548 else if( hypType()=="Arithmetic1D" )
550 StdMeshers::StdMeshers_Arithmetic1D_var h =
551 StdMeshers::StdMeshers_Arithmetic1D::_narrow( hyp );
553 item.myName = tr( "SMESH_START_LENGTH_PARAM" );
554 item.myValue = h->GetLength( true );
556 item.myName = tr( "SMESH_END_LENGTH_PARAM" );
557 item.myValue = h->GetLength( false );
560 else if( hypType()=="MaxElementArea" )
562 StdMeshers::StdMeshers_MaxElementArea_var h =
563 StdMeshers::StdMeshers_MaxElementArea::_narrow( hyp );
565 item.myName = tr( "SMESH_MAX_ELEMENT_AREA_PARAM" );
566 item.myValue = h->GetMaxElementArea();
569 else if( hypType()=="MaxElementVolume" )
571 StdMeshers::StdMeshers_MaxElementVolume_var h =
572 StdMeshers::StdMeshers_MaxElementVolume::_narrow( hyp );
574 item.myName = tr( "SMESH_MAX_ELEMENT_VOLUME_PARAM" );
575 item.myValue = h->GetMaxElementVolume();
578 else if( hypType()=="StartEndLength" )
580 StdMeshers::StdMeshers_StartEndLength_var h =
581 StdMeshers::StdMeshers_StartEndLength::_narrow( hyp );
583 item.myName = tr( "SMESH_START_LENGTH_PARAM" );
584 item.myValue = h->GetLength( true );
586 item.myName = tr( "SMESH_END_LENGTH_PARAM" );
587 item.myValue = h->GetLength( false );
590 else if( hypType()=="Deflection1D" )
592 StdMeshers::StdMeshers_Deflection1D_var h =
593 StdMeshers::StdMeshers_Deflection1D::_narrow( hyp );
595 item.myName = tr( "SMESH_DEFLECTION1D_PARAM" );
596 item.myValue = h->GetDeflection();
599 else if( hypType()=="AutomaticLength" )
601 StdMeshers::StdMeshers_AutomaticLength_var h =
602 StdMeshers::StdMeshers_AutomaticLength::_narrow( hyp );
604 item.myName = tr( "SMESH_FINENESS_PARAM" );
605 //item.myValue = h->GetFineness();
607 customWidgets()->append
608 ( new TDoubleSliderWith2Lables( "0 ", " 1", h->GetFineness(), 0, 1, 0.01, 0 ));
610 else if( hypType()=="NumberOfLayers" )
612 StdMeshers::StdMeshers_NumberOfLayers_var h =
613 StdMeshers::StdMeshers_NumberOfLayers::_narrow( hyp );
615 item.myName = tr( "SMESH_NUMBER_OF_LAYERS" );
616 item.myValue = (int) h->GetNumberOfLayers();
619 else if( hypType()=="LayerDistribution" )
621 StdMeshers::StdMeshers_LayerDistribution_var h =
622 StdMeshers::StdMeshers_LayerDistribution::_narrow( hyp );
624 item.myName = tr( "SMESH_LAYERS_DISTRIBUTION" ); p.append( item );
625 customWidgets()->append
626 ( new StdMeshersGUI_LayerDistributionParamWdg( h->GetLayerDistribution(), hypName(), dlg()));
628 else if( hypType()=="ProjectionSource1D" )
630 StdMeshers::StdMeshers_ProjectionSource1D_var h =
631 StdMeshers::StdMeshers_ProjectionSource1D::_narrow( hyp );
633 item.myName = tr( "SMESH_SOURCE_EDGE" ); p.append( item );
634 customWidgets()->append( newObjRefParamWdg( filterForShapeOfDim( 1 ),
635 h->GetSourceEdge()));
636 item.myName = tr( "SMESH_SOURCE_MESH" ); p.append( item );
637 customWidgets()->append( newObjRefParamWdg( new SMESH_TypeFilter( MESH ),
638 h->GetSourceMesh()));
639 item.myName = tr( "SMESH_SOURCE_VERTEX" ); p.append( item );
640 customWidgets()->append( newObjRefParamWdg( filterForShapeOfDim( 0 ),
641 h->GetSourceVertex()));
642 item.myName = tr( "SMESH_TARGET_VERTEX" ); p.append( item );
643 customWidgets()->append( newObjRefParamWdg( filterForShapeOfDim( 0 ),
644 h->GetTargetVertex()));
646 else if( hypType()=="ProjectionSource2D" )
648 StdMeshers::StdMeshers_ProjectionSource2D_var h =
649 StdMeshers::StdMeshers_ProjectionSource2D::_narrow( hyp );
651 item.myName = tr( "SMESH_SOURCE_FACE" ); p.append( item );
652 customWidgets()->append( newObjRefParamWdg( filterForShapeOfDim( 2 ),
653 h->GetSourceFace()));
654 item.myName = tr( "SMESH_SOURCE_MESH" ); p.append( item );
655 customWidgets()->append( newObjRefParamWdg( new SMESH_TypeFilter( MESH ),
656 h->GetSourceMesh()));
657 item.myName = tr( "SMESH_SOURCE_VERTEX1" ); p.append( item );
658 customWidgets()->append( newObjRefParamWdg( filterForShapeOfDim( 0 ),
659 h->GetSourceVertex( 1 )));
660 item.myName = tr( "SMESH_TARGET_VERTEX1" ); p.append( item );
661 customWidgets()->append( newObjRefParamWdg( filterForShapeOfDim( 0 ),
662 h->GetTargetVertex( 1 )));
663 item.myName = tr( "SMESH_SOURCE_VERTEX2" ); p.append( item );
664 customWidgets()->append( newObjRefParamWdg( filterForShapeOfDim( 0 ),
665 h->GetSourceVertex( 2 )));
666 item.myName = tr( "SMESH_TARGET_VERTEX2" ); p.append( item );
667 customWidgets()->append( newObjRefParamWdg( filterForShapeOfDim( 0 ),
668 h->GetTargetVertex( 2 )));
670 else if( hypType()=="ProjectionSource3D" )
672 StdMeshers::StdMeshers_ProjectionSource3D_var h =
673 StdMeshers::StdMeshers_ProjectionSource3D::_narrow( hyp );
675 item.myName = tr( "SMESH_SOURCE_3DSHAPE" ); p.append( item );
676 customWidgets()->append( newObjRefParamWdg( filterForShapeOfDim( 3, TopAbs_FACE, 6, true ),
677 h->GetSource3DShape()));
678 item.myName = tr( "SMESH_SOURCE_MESH" ); p.append( item );
679 customWidgets()->append( newObjRefParamWdg( new SMESH_TypeFilter( MESH ),
680 h->GetSourceMesh()));
681 item.myName = tr( "SMESH_SOURCE_VERTEX1" ); p.append( item );
682 customWidgets()->append( newObjRefParamWdg( filterForShapeOfDim( 0 ),
683 h->GetSourceVertex( 1 )));
684 item.myName = tr( "SMESH_TARGET_VERTEX1" ); p.append( item );
685 customWidgets()->append( newObjRefParamWdg( filterForShapeOfDim( 0 ),
686 h->GetTargetVertex( 1 )));
687 item.myName = tr( "SMESH_SOURCE_VERTEX2" ); p.append( item );
688 customWidgets()->append( newObjRefParamWdg( filterForShapeOfDim( 0 ),
689 h->GetSourceVertex( 2 )));
690 item.myName = tr( "SMESH_TARGET_VERTEX2" ); p.append( item );
691 customWidgets()->append( newObjRefParamWdg( filterForShapeOfDim( 0 ),
692 h->GetTargetVertex( 2 )));
699 //================================================================================
701 * \brief tune "standard" control
702 * \param w - control widget
703 * \param int - parameter index
705 //================================================================================
707 void StdMeshersGUI_StdHypothesisCreator::attuneStdWidget( QWidget* w, const int ) const
709 SMESHGUI_SpinBox* sb = w->inherits( "SMESHGUI_SpinBox" ) ? ( SMESHGUI_SpinBox* )w : 0;
710 if( hypType()=="LocalLength" && sb )
712 sb->RangeStepAndValidator( VALUE_SMALL, VALUE_MAX, 1.0, 6 );
714 else if( hypType()=="Arithmetic1D" && sb )
716 sb->RangeStepAndValidator( VALUE_SMALL, VALUE_MAX, 1.0, 6 );
718 else if( hypType()=="MaxElementArea" && sb )
720 sb->RangeStepAndValidator( VALUE_SMALL_2, VALUE_MAX_2, 1.0, 6 );
722 else if( hypType()=="MaxElementVolume" && sb )
724 sb->RangeStepAndValidator( VALUE_SMALL_3, VALUE_MAX_3, 1.0, 6 );
726 else if( hypType()=="StartEndLength" && sb )
728 sb->RangeStepAndValidator( VALUE_SMALL, VALUE_MAX, 1.0, 6 );
730 else if( hypType()=="Deflection1D" && sb )
732 sb->RangeStepAndValidator( VALUE_SMALL, VALUE_MAX, 1.0, 6 );
734 else if ( sb ) // default validator for possible ancestors
736 sb->RangeStepAndValidator( VALUE_SMALL, VALUE_MAX, 1.0, 6 );
740 //================================================================================
742 * \brief Return dlg title
743 * \retval QString - title string
745 //================================================================================
747 QString StdMeshersGUI_StdHypothesisCreator::caption() const
749 return tr( QString( "SMESH_%1_TITLE" ).arg( hypTypeName( hypType() ) ) );
752 //================================================================================
754 * \brief return pixmap for dlg icon
757 //================================================================================
759 QPixmap StdMeshersGUI_StdHypothesisCreator::icon() const
761 QString hypIconName = tr( QString( "ICON_DLG_%1" ).arg( hypTypeName( hypType() ) ) );
762 return SMESHGUI::resourceMgr()->loadPixmap( "SMESH", hypIconName );
765 //================================================================================
767 * \brief Return hypothesis type name to show in dlg
770 //================================================================================
772 QString StdMeshersGUI_StdHypothesisCreator::type() const
774 return tr( QString( "SMESH_%1_HYPOTHESIS" ).arg( hypTypeName( hypType() ) ) );
777 //================================================================================
779 * \brief String to insert in "SMESH_%1_HYPOTHESIS" to get hypothesis type name
780 * from message resouce file
781 * \param t - hypothesis type
782 * \retval QString - result string
784 //================================================================================
786 QString StdMeshersGUI_StdHypothesisCreator::hypTypeName( const QString& t ) const
788 static QMap<QString,QString> types;
789 if( types.isEmpty() )
791 types.insert( "LocalLength", "LOCAL_LENGTH" );
792 types.insert( "NumberOfSegments", "NB_SEGMENTS" );
793 types.insert( "MaxElementArea", "MAX_ELEMENT_AREA" );
794 types.insert( "MaxElementVolume", "MAX_ELEMENT_VOLUME" );
795 types.insert( "StartEndLength", "START_END_LENGTH" );
796 types.insert( "Deflection1D", "DEFLECTION1D" );
797 types.insert( "Arithmetic1D", "ARITHMETIC_1D" );
798 types.insert( "AutomaticLength", "AUTOMATIC_LENGTH" );
799 types.insert( "ProjectionSource1D", "PROJECTION_SOURCE_1D" );
800 types.insert( "ProjectionSource2D", "PROJECTION_SOURCE_2D" );
801 types.insert( "ProjectionSource3D", "PROJECTION_SOURCE_3D" );
802 types.insert( "NumberOfLayers", "NUMBER_OF_LAYERS" );
803 types.insert( "LayerDistribution", "LAYER_DISTRIBUTION" );
804 types.insert( "SegmentLengthAroundVertex", "SEGMENT_LENGTH_AROUND_VERTEX" );
808 if( types.contains( t ) )
815 //=======================================================================
816 //function : getCustomWidget
817 //purpose : is called from buildStdFrame()
818 //=======================================================================
820 QWidget* StdMeshersGUI_StdHypothesisCreator::getCustomWidget( const StdParam & param,
822 const int index) const
825 if ( index < customWidgets()->count() ) {
826 w = customWidgets()->at( index );
828 w->reparent( parent, QPoint( 0, 0 ));
833 //================================================================================
835 * \brief Set param value taken from a custom widget
836 * \param param - SMESHGUI_GenericHypothesisCreator::StdParam structure
837 * \param widget - widget presenting param
838 * \retval bool - success flag
840 * this method is called from getStdParamFromDlg()
842 //================================================================================
844 bool StdMeshersGUI_StdHypothesisCreator::getParamFromCustomWidget( StdParam & param,
845 QWidget* widget) const
847 if ( hypType()=="AutomaticLength" ) {
848 TDoubleSliderWith2Lables* w = dynamic_cast<TDoubleSliderWith2Lables*>( widget );
850 param.myValue = w->value();
854 if ( widget->inherits( "StdMeshersGUI_ObjectReferenceParamWdg" ))
856 // show only 1st reference value
857 if ( true /*widget == getWidgetForParam( 0 )*/) {
858 const StdMeshersGUI_ObjectReferenceParamWdg * w =
859 static_cast<const StdMeshersGUI_ObjectReferenceParamWdg*>( widget );
860 param.myValue = w->GetValue();
864 if ( widget->inherits( "StdMeshersGUI_LayerDistributionParamWdg" ))
866 const StdMeshersGUI_LayerDistributionParamWdg * w =
867 static_cast<const StdMeshersGUI_LayerDistributionParamWdg*>( widget );
868 param.myValue = w->GetValue();
874 //================================================================================
876 * \brief called when operation cancelled
878 //================================================================================
880 void StdMeshersGUI_StdHypothesisCreator::onReject()
882 if ( hypType().startsWith("ProjectionSource" ))
884 // Uninstall filters of StdMeshersGUI_ObjectReferenceParamWdg
885 deactivateObjRefParamWdg( customWidgets() );