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 const int nbSubShapes = 0,
249 const TopAbs_ShapeEnum subShapeType = TopAbs_SHAPE,
250 const bool closed = false)
252 TColStd_MapOfInteger shapeTypes;
254 case 0: shapeTypes.Add( TopAbs_VERTEX ); break;
255 case 1: shapeTypes.Add( TopAbs_EDGE ); break;
256 case 2: shapeTypes.Add( TopAbs_FACE ); break;
258 shapeTypes.Add( TopAbs_SHELL );
259 shapeTypes.Add( TopAbs_SOLID );
260 shapeTypes.Add( TopAbs_COMPSOLID );
261 shapeTypes.Add( TopAbs_COMPOUND );
264 return new SMESH_NumberFilter("GEOM", subShapeType, nbSubShapes,
265 shapeTypes, GEOM::GEOM_Object::_nil(), closed);
268 //================================================================================
270 * \brief Create a widget for object selection
271 * \param object - initial object
272 * \param filter - selection filter
273 * \retval QWidget* - created widget
275 //================================================================================
277 QWidget* newObjRefParamWdg( SUIT_SelectionFilter* filter,
278 CORBA::Object_var object)
280 StdMeshersGUI_ObjectReferenceParamWdg* w =
281 new StdMeshersGUI_ObjectReferenceParamWdg( filter, 0);
282 w->SetObject( object.in() );
286 //================================================================================
288 * \brief calls deactivateSelection() for StdMeshersGUI_ObjectReferenceParamWdg
289 * \param widgetList - list of widgets
291 //================================================================================
293 void deactivateObjRefParamWdg( QPtrList<QWidget>* widgetList )
295 StdMeshersGUI_ObjectReferenceParamWdg* w = 0;
296 QPtrList<QWidget>::iterator anIt = widgetList->begin();
297 QPtrList<QWidget>::iterator aLast = widgetList->end();
298 for ( ; anIt != aLast; anIt++ ) {
299 if ( (*anIt) && (*anIt)->inherits( "StdMeshersGUI_ObjectReferenceParamWdg" ))
301 w = (StdMeshersGUI_ObjectReferenceParamWdg* )( *anIt );
302 w->deactivateSelection();
308 //================================================================================
310 * \brief Check parameter values before accept()
311 * \retval bool - true if OK
313 //================================================================================
315 bool StdMeshersGUI_StdHypothesisCreator::checkParams() const
317 // check if object reference parameter is set, as it has no default value
319 if ( hypType().startsWith("ProjectionSource" ))
321 StdMeshersGUI_ObjectReferenceParamWdg* w =
322 widget< StdMeshersGUI_ObjectReferenceParamWdg >( 0 );
323 ok = ( w->IsObjectSelected() );
324 if ( !ok ) w->SetObject( CORBA::Object::_nil() );
325 int nbAssocVert = ( hypType() == "ProjectionSource1D" ? 1 : 2 );
326 for ( int i = 0; ok && i < nbAssocVert; i += 2)
329 StdMeshersGUI_ObjectReferenceParamWdg* w1 =
330 widget< StdMeshersGUI_ObjectReferenceParamWdg >( i+2 );
331 StdMeshersGUI_ObjectReferenceParamWdg* w2 =
332 widget< StdMeshersGUI_ObjectReferenceParamWdg >( i+3 );
333 srcV = w1->GetValue();
334 tgtV = w2->GetValue();
335 ok = (( srcV.isEmpty() && tgtV.isEmpty() ) ||
336 ( !srcV.isEmpty() && !tgtV.isEmpty() && srcV != tgtV ));
338 w1->SetObject( CORBA::Object::_nil() );
339 w2->SetObject( CORBA::Object::_nil() );
343 // Uninstall filters of StdMeshersGUI_ObjectReferenceParamWdg
345 deactivateObjRefParamWdg( customWidgets() );
347 else if ( hypType() == "LayerDistribution" )
349 StdMeshersGUI_LayerDistributionParamWdg* w =
350 widget< StdMeshersGUI_LayerDistributionParamWdg >( 0 );
351 ok = ( w && w->IsOk() );
356 //================================================================================
358 * \brief Store params from GUI controls to a hypothesis
359 * \retval QString - text representation of parameters
361 //================================================================================
363 QString StdMeshersGUI_StdHypothesisCreator::storeParams() const
365 ListOfStdParams params;
366 bool res = getStdParamFromDlg( params );
369 SMESH::SetName( SMESH::FindSObject( hypothesis() ), params[0].myValue.toString().latin1() );
370 params.remove( params.begin() );
373 QString valueStr = stdParamValues( params );
375 if( res && !params.isEmpty() )
377 if( hypType()=="LocalLength" )
379 StdMeshers::StdMeshers_LocalLength_var h =
380 StdMeshers::StdMeshers_LocalLength::_narrow( hypothesis() );
382 h->SetLength( params[0].myValue.toDouble() );
384 else if( hypType()=="SegmentLengthAroundVertex" )
386 StdMeshers::StdMeshers_SegmentLengthAroundVertex_var h =
387 StdMeshers::StdMeshers_SegmentLengthAroundVertex::_narrow( hypothesis() );
389 h->SetLength( params[0].myValue.toDouble() );
391 else if( hypType()=="Arithmetic1D" )
393 StdMeshers::StdMeshers_Arithmetic1D_var h =
394 StdMeshers::StdMeshers_Arithmetic1D::_narrow( hypothesis() );
396 h->SetLength( params[0].myValue.toDouble(), true );
397 h->SetLength( params[1].myValue.toDouble(), false );
399 else if( hypType()=="MaxElementArea" )
401 StdMeshers::StdMeshers_MaxElementArea_var h =
402 StdMeshers::StdMeshers_MaxElementArea::_narrow( hypothesis() );
404 h->SetMaxElementArea( params[0].myValue.toDouble() );
406 else if( hypType()=="MaxElementVolume" )
408 StdMeshers::StdMeshers_MaxElementVolume_var h =
409 StdMeshers::StdMeshers_MaxElementVolume::_narrow( hypothesis() );
411 h->SetMaxElementVolume( params[0].myValue.toDouble() );
413 else if( hypType()=="StartEndLength" )
415 StdMeshers::StdMeshers_StartEndLength_var h =
416 StdMeshers::StdMeshers_StartEndLength::_narrow( hypothesis() );
418 h->SetLength( params[0].myValue.toDouble(), true );
419 h->SetLength( params[1].myValue.toDouble(), false );
421 else if( hypType()=="Deflection1D" )
423 StdMeshers::StdMeshers_Deflection1D_var h =
424 StdMeshers::StdMeshers_Deflection1D::_narrow( hypothesis() );
426 h->SetDeflection( params[0].myValue.toDouble() );
428 else if( hypType()=="AutomaticLength" )
430 StdMeshers::StdMeshers_AutomaticLength_var h =
431 StdMeshers::StdMeshers_AutomaticLength::_narrow( hypothesis() );
433 h->SetFineness( params[0].myValue.toDouble() );
435 else if( hypType()=="NumberOfLayers" )
437 StdMeshers::StdMeshers_NumberOfLayers_var h =
438 StdMeshers::StdMeshers_NumberOfLayers::_narrow( hypothesis() );
440 h->SetNumberOfLayers( params[0].myValue.toInt() );
442 else if( hypType()=="LayerDistribution" )
444 StdMeshers::StdMeshers_LayerDistribution_var h =
445 StdMeshers::StdMeshers_LayerDistribution::_narrow( hypothesis() );
446 StdMeshersGUI_LayerDistributionParamWdg* w =
447 widget< StdMeshersGUI_LayerDistributionParamWdg >( 0 );
449 h->SetLayerDistribution( w->GetHypothesis() );
451 else if( hypType()=="ProjectionSource1D" )
453 StdMeshers::StdMeshers_ProjectionSource1D_var h =
454 StdMeshers::StdMeshers_ProjectionSource1D::_narrow( hypothesis() );
456 h->SetSourceEdge ( geomFromWdg ( getWidgetForParam( 0 )));
457 h->SetSourceMesh ( meshFromWdg ( getWidgetForParam( 1 )));
458 h->SetVertexAssociation( geomFromWdg ( getWidgetForParam( 2 )),
459 geomFromWdg ( getWidgetForParam( 3 )));
461 else if( hypType()=="ProjectionSource2D" )
463 StdMeshers::StdMeshers_ProjectionSource2D_var h =
464 StdMeshers::StdMeshers_ProjectionSource2D::_narrow( hypothesis() );
466 h->SetSourceFace ( geomFromWdg ( getWidgetForParam( 0 )));
467 h->SetSourceMesh ( meshFromWdg ( getWidgetForParam( 1 )));
468 h->SetVertexAssociation( geomFromWdg ( getWidgetForParam( 2 )), // src1
469 geomFromWdg ( getWidgetForParam( 4 )), // src2
470 geomFromWdg ( getWidgetForParam( 3 )), // tgt1
471 geomFromWdg ( getWidgetForParam( 5 ))); // tgt2
473 else if( hypType()=="ProjectionSource3D" )
475 StdMeshers::StdMeshers_ProjectionSource3D_var h =
476 StdMeshers::StdMeshers_ProjectionSource3D::_narrow( hypothesis() );
478 h->SetSource3DShape ( geomFromWdg ( getWidgetForParam( 0 )));
479 h->SetSourceMesh ( meshFromWdg ( getWidgetForParam( 1 )));
480 h->SetVertexAssociation( geomFromWdg ( getWidgetForParam( 2 )), // src1
481 geomFromWdg ( getWidgetForParam( 4 )), // src2
482 geomFromWdg ( getWidgetForParam( 3 )), // tgt1
483 geomFromWdg ( getWidgetForParam( 5 ))); // tgt2
489 //================================================================================
491 * \brief Return parameter values as SMESHGUI_GenericHypothesisCreator::StdParam
492 * \param p - list of parameters
493 * \retval bool - success flag
495 * Is called from SMESHGUI_GenericHypothesisCreator::buildStdFrame().
496 * Parameters will be shown using "standard" controls:
497 * Int by QtxIntSpinBox
498 * Double by SMESHGUI_SpinBox
499 * String by QLineEdit
500 * getCustomWidget() allows to redefine control for a parameter
502 //================================================================================
504 bool StdMeshersGUI_StdHypothesisCreator::stdParams( ListOfStdParams& p ) const
507 SMESHGUI_GenericHypothesisCreator::StdParam item;
510 customWidgets()->clear();
513 HypothesisData* data = SMESH::GetHypothesisData( hypType() );
514 item.myName = tr( "SMESH_NAME" );
515 item.myValue = data ? hypName() : QString();
517 customWidgets()->append(0);
520 SMESH::SMESH_Hypothesis_var hyp = initParamsHypothesis();
522 if( hypType()=="LocalLength" )
524 StdMeshers::StdMeshers_LocalLength_var h =
525 StdMeshers::StdMeshers_LocalLength::_narrow( hyp );
527 item.myName = tr("SMESH_LOCAL_LENGTH_PARAM");
528 item.myValue = h->GetLength();
531 else if( hypType()=="SegmentLengthAroundVertex" )
533 StdMeshers::StdMeshers_SegmentLengthAroundVertex_var h =
534 StdMeshers::StdMeshers_SegmentLengthAroundVertex::_narrow( hyp );
536 item.myName = tr("SMESH_LOCAL_LENGTH_PARAM");
537 item.myValue = h->GetLength();
540 else if( hypType()=="Arithmetic1D" )
542 StdMeshers::StdMeshers_Arithmetic1D_var h =
543 StdMeshers::StdMeshers_Arithmetic1D::_narrow( hyp );
545 item.myName = tr( "SMESH_START_LENGTH_PARAM" );
546 item.myValue = h->GetLength( true );
548 item.myName = tr( "SMESH_END_LENGTH_PARAM" );
549 item.myValue = h->GetLength( false );
552 else if( hypType()=="MaxElementArea" )
554 StdMeshers::StdMeshers_MaxElementArea_var h =
555 StdMeshers::StdMeshers_MaxElementArea::_narrow( hyp );
557 item.myName = tr( "SMESH_MAX_ELEMENT_AREA_PARAM" );
558 item.myValue = h->GetMaxElementArea();
561 else if( hypType()=="MaxElementVolume" )
563 StdMeshers::StdMeshers_MaxElementVolume_var h =
564 StdMeshers::StdMeshers_MaxElementVolume::_narrow( hyp );
566 item.myName = tr( "SMESH_MAX_ELEMENT_VOLUME_PARAM" );
567 item.myValue = h->GetMaxElementVolume();
570 else if( hypType()=="StartEndLength" )
572 StdMeshers::StdMeshers_StartEndLength_var h =
573 StdMeshers::StdMeshers_StartEndLength::_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()=="Deflection1D" )
584 StdMeshers::StdMeshers_Deflection1D_var h =
585 StdMeshers::StdMeshers_Deflection1D::_narrow( hyp );
587 item.myName = tr( "SMESH_DEFLECTION1D_PARAM" );
588 item.myValue = h->GetDeflection();
591 else if( hypType()=="AutomaticLength" )
593 StdMeshers::StdMeshers_AutomaticLength_var h =
594 StdMeshers::StdMeshers_AutomaticLength::_narrow( hyp );
596 item.myName = tr( "SMESH_FINENESS_PARAM" );
597 //item.myValue = h->GetFineness();
599 customWidgets()->append
600 ( new TDoubleSliderWith2Lables( "0 ", " 1", h->GetFineness(), 0, 1, 0.01, 0 ));
602 else if( hypType()=="NumberOfLayers" )
604 StdMeshers::StdMeshers_NumberOfLayers_var h =
605 StdMeshers::StdMeshers_NumberOfLayers::_narrow( hyp );
607 item.myName = tr( "SMESH_NUMBER_OF_LAYERS" );
608 item.myValue = (int) h->GetNumberOfLayers();
611 else if( hypType()=="LayerDistribution" )
613 StdMeshers::StdMeshers_LayerDistribution_var h =
614 StdMeshers::StdMeshers_LayerDistribution::_narrow( hyp );
616 item.myName = tr( "SMESH_LAYERS_DISTRIBUTION" ); p.append( item );
617 customWidgets()->append
618 ( new StdMeshersGUI_LayerDistributionParamWdg( h->GetLayerDistribution(), hypName(), dlg()));
620 else if( hypType()=="ProjectionSource1D" )
622 StdMeshers::StdMeshers_ProjectionSource1D_var h =
623 StdMeshers::StdMeshers_ProjectionSource1D::_narrow( hyp );
625 item.myName = tr( "SMESH_SOURCE_EDGE" ); p.append( item );
626 customWidgets()->append( newObjRefParamWdg( filterForShapeOfDim( 1 ),
627 h->GetSourceEdge()));
628 item.myName = tr( "SMESH_SOURCE_MESH" ); p.append( item );
629 customWidgets()->append( newObjRefParamWdg( new SMESH_TypeFilter( MESH ),
630 h->GetSourceMesh()));
631 item.myName = tr( "SMESH_SOURCE_VERTEX" ); p.append( item );
632 customWidgets()->append( newObjRefParamWdg( filterForShapeOfDim( 0 ),
633 h->GetSourceVertex()));
634 item.myName = tr( "SMESH_TARGET_VERTEX" ); p.append( item );
635 customWidgets()->append( newObjRefParamWdg( filterForShapeOfDim( 0 ),
636 h->GetTargetVertex()));
638 else if( hypType()=="ProjectionSource2D" )
640 StdMeshers::StdMeshers_ProjectionSource2D_var h =
641 StdMeshers::StdMeshers_ProjectionSource2D::_narrow( hyp );
643 item.myName = tr( "SMESH_SOURCE_FACE" ); p.append( item );
644 customWidgets()->append( newObjRefParamWdg( filterForShapeOfDim( 2 ),
645 h->GetSourceFace()));
646 item.myName = tr( "SMESH_SOURCE_MESH" ); p.append( item );
647 customWidgets()->append( newObjRefParamWdg( new SMESH_TypeFilter( MESH ),
648 h->GetSourceMesh()));
649 item.myName = tr( "SMESH_SOURCE_VERTEX1" ); p.append( item );
650 customWidgets()->append( newObjRefParamWdg( filterForShapeOfDim( 0 ),
651 h->GetSourceVertex( 1 )));
652 item.myName = tr( "SMESH_TARGET_VERTEX1" ); p.append( item );
653 customWidgets()->append( newObjRefParamWdg( filterForShapeOfDim( 0 ),
654 h->GetTargetVertex( 1 )));
655 item.myName = tr( "SMESH_SOURCE_VERTEX2" ); p.append( item );
656 customWidgets()->append( newObjRefParamWdg( filterForShapeOfDim( 0 ),
657 h->GetSourceVertex( 2 )));
658 item.myName = tr( "SMESH_TARGET_VERTEX2" ); p.append( item );
659 customWidgets()->append( newObjRefParamWdg( filterForShapeOfDim( 0 ),
660 h->GetTargetVertex( 2 )));
662 else if( hypType()=="ProjectionSource3D" )
664 StdMeshers::StdMeshers_ProjectionSource3D_var h =
665 StdMeshers::StdMeshers_ProjectionSource3D::_narrow( hyp );
667 item.myName = tr( "SMESH_SOURCE_3DSHAPE" ); p.append( item );
668 customWidgets()->append( newObjRefParamWdg( filterForShapeOfDim( 3 , 6, TopAbs_FACE, true ),
669 h->GetSource3DShape()));
670 item.myName = tr( "SMESH_SOURCE_MESH" ); p.append( item );
671 customWidgets()->append( newObjRefParamWdg( new SMESH_TypeFilter( MESH ),
672 h->GetSourceMesh()));
673 item.myName = tr( "SMESH_SOURCE_VERTEX1" ); p.append( item );
674 customWidgets()->append( newObjRefParamWdg( filterForShapeOfDim( 0 ),
675 h->GetSourceVertex( 1 )));
676 item.myName = tr( "SMESH_TARGET_VERTEX1" ); p.append( item );
677 customWidgets()->append( newObjRefParamWdg( filterForShapeOfDim( 0 ),
678 h->GetTargetVertex( 1 )));
679 item.myName = tr( "SMESH_SOURCE_VERTEX2" ); p.append( item );
680 customWidgets()->append( newObjRefParamWdg( filterForShapeOfDim( 0 ),
681 h->GetSourceVertex( 2 )));
682 item.myName = tr( "SMESH_TARGET_VERTEX2" ); p.append( item );
683 customWidgets()->append( newObjRefParamWdg( filterForShapeOfDim( 0 ),
684 h->GetTargetVertex( 2 )));
691 //================================================================================
693 * \brief tune "standard" control
694 * \param w - control widget
695 * \param int - parameter index
697 //================================================================================
699 void StdMeshersGUI_StdHypothesisCreator::attuneStdWidget( QWidget* w, const int ) const
701 SMESHGUI_SpinBox* sb = w->inherits( "SMESHGUI_SpinBox" ) ? ( SMESHGUI_SpinBox* )w : 0;
702 if( hypType()=="LocalLength" && sb )
704 sb->RangeStepAndValidator( VALUE_SMALL, VALUE_MAX, 1.0, 6 );
706 else if( hypType()=="Arithmetic1D" && sb )
708 sb->RangeStepAndValidator( VALUE_SMALL, VALUE_MAX, 1.0, 6 );
710 else if( hypType()=="MaxElementArea" && sb )
712 sb->RangeStepAndValidator( VALUE_SMALL_2, VALUE_MAX_2, 1.0, 6 );
714 else if( hypType()=="MaxElementVolume" && sb )
716 sb->RangeStepAndValidator( VALUE_SMALL_3, VALUE_MAX_3, 1.0, 6 );
718 else if( hypType()=="StartEndLength" && sb )
720 sb->RangeStepAndValidator( VALUE_SMALL, VALUE_MAX, 1.0, 6 );
722 else if( hypType()=="Deflection1D" && sb )
724 sb->RangeStepAndValidator( VALUE_SMALL, VALUE_MAX, 1.0, 6 );
726 else if ( sb ) // default validator for possible ancestors
728 sb->RangeStepAndValidator( VALUE_SMALL, VALUE_MAX, 1.0, 6 );
732 //================================================================================
734 * \brief Return dlg title
735 * \retval QString - title string
737 //================================================================================
739 QString StdMeshersGUI_StdHypothesisCreator::caption() const
741 return tr( QString( "SMESH_%1_TITLE" ).arg( hypTypeName( hypType() ) ) );
744 //================================================================================
746 * \brief return pixmap for dlg icon
749 //================================================================================
751 QPixmap StdMeshersGUI_StdHypothesisCreator::icon() const
753 QString hypIconName = tr( QString( "ICON_DLG_%1" ).arg( hypTypeName( hypType() ) ) );
754 return SMESHGUI::resourceMgr()->loadPixmap( "SMESH", hypIconName );
757 //================================================================================
759 * \brief Return hypothesis type name to show in dlg
762 //================================================================================
764 QString StdMeshersGUI_StdHypothesisCreator::type() const
766 return tr( QString( "SMESH_%1_HYPOTHESIS" ).arg( hypTypeName( hypType() ) ) );
769 //================================================================================
771 * \brief String to insert in "SMESH_%1_HYPOTHESIS" to get hypothesis type name
772 * from message resouce file
773 * \param t - hypothesis type
774 * \retval QString - result string
776 //================================================================================
778 QString StdMeshersGUI_StdHypothesisCreator::hypTypeName( const QString& t ) const
780 static QMap<QString,QString> types;
781 if( types.isEmpty() )
783 types.insert( "LocalLength", "LOCAL_LENGTH" );
784 types.insert( "NumberOfSegments", "NB_SEGMENTS" );
785 types.insert( "MaxElementArea", "MAX_ELEMENT_AREA" );
786 types.insert( "MaxElementVolume", "MAX_ELEMENT_VOLUME" );
787 types.insert( "StartEndLength", "START_END_LENGTH" );
788 types.insert( "Deflection1D", "DEFLECTION1D" );
789 types.insert( "Arithmetic1D", "ARITHMETIC_1D" );
790 types.insert( "AutomaticLength", "AUTOMATIC_LENGTH" );
791 types.insert( "ProjectionSource1D", "PROJECTION_SOURCE_1D" );
792 types.insert( "ProjectionSource2D", "PROJECTION_SOURCE_2D" );
793 types.insert( "ProjectionSource3D", "PROJECTION_SOURCE_3D" );
794 types.insert( "NumberOfLayers", "NUMBER_OF_LAYERS" );
795 types.insert( "LayerDistribution", "LAYER_DISTRIBUTION" );
796 types.insert( "SegmentLengthAroundVertex", "SEGMENT_LENGTH_AROUND_VERTEX" );
800 if( types.contains( t ) )
807 //=======================================================================
808 //function : getCustomWidget
809 //purpose : is called from buildStdFrame()
810 //=======================================================================
812 QWidget* StdMeshersGUI_StdHypothesisCreator::getCustomWidget( const StdParam & param,
814 const int index) const
817 if ( index < customWidgets()->count() ) {
818 w = customWidgets()->at( index );
820 w->reparent( parent, QPoint( 0, 0 ));
825 //================================================================================
827 * \brief Set param value taken from a custom widget
828 * \param param - SMESHGUI_GenericHypothesisCreator::StdParam structure
829 * \param widget - widget presenting param
830 * \retval bool - success flag
832 * this method is called from getStdParamFromDlg()
834 //================================================================================
836 bool StdMeshersGUI_StdHypothesisCreator::getParamFromCustomWidget( StdParam & param,
837 QWidget* widget) const
839 if ( hypType()=="AutomaticLength" ) {
840 TDoubleSliderWith2Lables* w = dynamic_cast<TDoubleSliderWith2Lables*>( widget );
842 param.myValue = w->value();
846 if ( widget->inherits( "StdMeshersGUI_ObjectReferenceParamWdg" ))
848 // show only 1st reference value
849 if ( true /*widget == getWidgetForParam( 0 )*/) {
850 const StdMeshersGUI_ObjectReferenceParamWdg * w =
851 static_cast<const StdMeshersGUI_ObjectReferenceParamWdg*>( widget );
852 param.myValue = w->GetValue();
856 if ( widget->inherits( "StdMeshersGUI_LayerDistributionParamWdg" ))
858 const StdMeshersGUI_LayerDistributionParamWdg * w =
859 static_cast<const StdMeshersGUI_LayerDistributionParamWdg*>( widget );
860 param.myValue = w->GetValue();
866 //================================================================================
868 * \brief called when operation cancelled
870 //================================================================================
872 void StdMeshersGUI_StdHypothesisCreator::onReject()
874 if ( hypType().startsWith("ProjectionSource" ))
876 // Uninstall filters of StdMeshersGUI_ObjectReferenceParamWdg
877 deactivateObjRefParamWdg( customWidgets() );