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();
175 //================================================================================
177 * \brief Widget: slider with left and right labels
179 //================================================================================
181 class TDoubleSliderWith2Lables: public QWidget
184 TDoubleSliderWith2Lables( const QString& leftLabel, const QString& rightLabel,
185 const double initValue, const double bottom,
186 const double top , const double precision,
187 QWidget * parent=0 , const char * name=0 )
188 :QWidget(parent), _bottom(bottom), _precision(precision)
192 QHBoxLayout* aHBoxL = new QHBoxLayout(this);
194 if ( !leftLabel.isEmpty() ) {
195 QLabel* aLeftLabel = new QLabel( this );
196 aLeftLabel->setText( leftLabel );
197 aHBoxL->addWidget( aLeftLabel );
200 _slider = new QSlider( Qt::Horizontal, this );
201 _slider->setRange( 0, toInt( top ));
202 _slider->setValue( toInt( initValue ));
203 aHBoxL->addWidget( _slider );
205 if ( !rightLabel.isEmpty() ) {
206 QLabel* aRightLabel = new QLabel( this );
207 aRightLabel->setText( rightLabel );
208 aHBoxL->addWidget( aRightLabel );
213 double value() const { return _bottom + _slider->value() * _precision; }
214 QSlider * getSlider() const { return _slider; }
215 int toInt( double val ) const { return (int) ceil(( val - _bottom ) / _precision ); }
217 double _bottom, _precision;
221 //================================================================================
223 * \brief Retrieve GEOM_Object held by widget
225 //================================================================================
227 inline GEOM::GEOM_Object_var geomFromWdg(const QWidget* wdg)
229 const StdMeshersGUI_ObjectReferenceParamWdg * objRefWdg =
230 dynamic_cast<const StdMeshersGUI_ObjectReferenceParamWdg*>( wdg );
232 return objRefWdg->GetObject< GEOM::GEOM_Object >();
234 return GEOM::GEOM_Object::_nil();
236 //================================================================================
238 * \brief Retrieve SMESH_Mesh held by widget
240 //================================================================================
242 inline SMESH::SMESH_Mesh_var meshFromWdg(const QWidget* wdg)
244 const StdMeshersGUI_ObjectReferenceParamWdg * objRefWdg =
245 dynamic_cast<const StdMeshersGUI_ObjectReferenceParamWdg*>( wdg );
247 return objRefWdg->GetObject< SMESH::SMESH_Mesh >();
249 return SMESH::SMESH_Mesh::_nil();
251 //================================================================================
253 * \brief creates a filter for selection of shapes of given dimension
254 * \param dim - dimension
255 * \param subShapeType - required type of subshapes, number of which must be \a nbSubShapes
256 * \param nbSubShapes - number of subshapes of given type
257 * \param closed - required closeness flag of a shape
258 * \retval SUIT_SelectionFilter* - created filter
260 //================================================================================
262 SUIT_SelectionFilter* filterForShapeOfDim(const int dim,
263 TopAbs_ShapeEnum subShapeType = TopAbs_SHAPE,
264 const int nbSubShapes = 0,
267 TColStd_MapOfInteger shapeTypes;
269 case 0: shapeTypes.Add( TopAbs_VERTEX ); break;
271 if ( subShapeType == TopAbs_SHAPE ) subShapeType = TopAbs_EDGE;
272 shapeTypes.Add( TopAbs_EDGE );
273 shapeTypes.Add( TopAbs_COMPOUND ); // for a group
276 if ( subShapeType == TopAbs_SHAPE ) subShapeType = TopAbs_FACE;
277 shapeTypes.Add( TopAbs_FACE );
278 shapeTypes.Add( TopAbs_COMPOUND ); // for a group
281 shapeTypes.Add( TopAbs_SHELL );
282 shapeTypes.Add( TopAbs_SOLID );
283 shapeTypes.Add( TopAbs_COMPSOLID );
284 shapeTypes.Add( TopAbs_COMPOUND );
287 return new SMESH_NumberFilter("GEOM", subShapeType, nbSubShapes,
288 shapeTypes, GEOM::GEOM_Object::_nil(), closed);
291 //================================================================================
293 * \brief Create a widget for object selection
294 * \param object - initial object
295 * \param filter - selection filter
296 * \retval QWidget* - created widget
298 //================================================================================
300 QWidget* newObjRefParamWdg( SUIT_SelectionFilter* filter,
301 CORBA::Object_var object)
303 StdMeshersGUI_ObjectReferenceParamWdg* w =
304 new StdMeshersGUI_ObjectReferenceParamWdg( filter, 0);
305 w->SetObject( object.in() );
309 //================================================================================
311 * \brief calls deactivateSelection() for StdMeshersGUI_ObjectReferenceParamWdg
312 * \param widgetList - list of widgets
314 //================================================================================
316 void deactivateObjRefParamWdg( QList<QWidget*>* widgetList )
318 StdMeshersGUI_ObjectReferenceParamWdg* w = 0;
319 QList<QWidget*>::iterator anIt = widgetList->begin();
320 QList<QWidget*>::iterator aLast = widgetList->end();
321 for ( ; anIt != aLast; anIt++ ) {
322 if ( (*anIt) && (*anIt)->inherits( "StdMeshersGUI_ObjectReferenceParamWdg" ))
324 w = (StdMeshersGUI_ObjectReferenceParamWdg* )( *anIt );
325 w->deactivateSelection();
331 //================================================================================
333 * \brief Check parameter values before accept()
334 * \retval bool - true if OK
336 //================================================================================
338 bool StdMeshersGUI_StdHypothesisCreator::checkParams() const
340 // check if object reference parameter is set, as it has no default value
342 if ( hypType().startsWith("ProjectionSource" ))
344 StdMeshersGUI_ObjectReferenceParamWdg* w =
345 widget< StdMeshersGUI_ObjectReferenceParamWdg >( 0 );
346 ok = ( w->IsObjectSelected() );
347 if ( !ok ) w->SetObject( CORBA::Object::_nil() );
348 int nbAssocVert = ( hypType() == "ProjectionSource1D" ? 1 : 2 );
349 for ( int i = 0; ok && i < nbAssocVert; i += 2)
352 StdMeshersGUI_ObjectReferenceParamWdg* w1 =
353 widget< StdMeshersGUI_ObjectReferenceParamWdg >( i+2 );
354 StdMeshersGUI_ObjectReferenceParamWdg* w2 =
355 widget< StdMeshersGUI_ObjectReferenceParamWdg >( i+3 );
356 srcV = w1->GetValue();
357 tgtV = w2->GetValue();
358 ok = (( srcV.isEmpty() && tgtV.isEmpty() ) ||
359 ( !srcV.isEmpty() && !tgtV.isEmpty() && srcV != tgtV ));
361 w1->SetObject( CORBA::Object::_nil() );
362 w2->SetObject( CORBA::Object::_nil() );
366 // Uninstall filters of StdMeshersGUI_ObjectReferenceParamWdg
368 deactivateObjRefParamWdg( customWidgets() );
370 else if ( hypType() == "LayerDistribution" )
372 StdMeshersGUI_LayerDistributionParamWdg* w =
373 widget< StdMeshersGUI_LayerDistributionParamWdg >( 0 );
374 ok = ( w && w->IsOk() );
379 //================================================================================
381 * \brief Store params from GUI controls to a hypothesis
382 * \retval QString - text representation of parameters
384 //================================================================================
386 QString StdMeshersGUI_StdHypothesisCreator::storeParams() const
388 ListOfStdParams params;
389 bool res = getStdParamFromDlg( params );
392 SMESH::SetName( SMESH::FindSObject( hypothesis() ), params[0].myValue.toString().toLatin1().data() );
393 params.erase( params.begin() );
396 QString valueStr = stdParamValues( params );
398 if( res && !params.isEmpty() )
400 if( hypType()=="LocalLength" )
402 StdMeshers::StdMeshers_LocalLength_var h =
403 StdMeshers::StdMeshers_LocalLength::_narrow( hypothesis() );
405 h->SetLength( params[0].myValue.toDouble() );
406 h->SetPrecision( params[1].myValue.toDouble() );
408 else if( hypType()=="SegmentLengthAroundVertex" )
410 StdMeshers::StdMeshers_SegmentLengthAroundVertex_var h =
411 StdMeshers::StdMeshers_SegmentLengthAroundVertex::_narrow( hypothesis() );
413 h->SetLength( params[0].myValue.toDouble() );
415 else if( hypType()=="Arithmetic1D" )
417 StdMeshers::StdMeshers_Arithmetic1D_var h =
418 StdMeshers::StdMeshers_Arithmetic1D::_narrow( hypothesis() );
420 h->SetLength( params[0].myValue.toDouble(), true );
421 h->SetLength( params[1].myValue.toDouble(), false );
423 else if( hypType()=="MaxElementArea" )
425 StdMeshers::StdMeshers_MaxElementArea_var h =
426 StdMeshers::StdMeshers_MaxElementArea::_narrow( hypothesis() );
428 h->SetMaxElementArea( params[0].myValue.toDouble() );
430 else if( hypType()=="MaxElementVolume" )
432 StdMeshers::StdMeshers_MaxElementVolume_var h =
433 StdMeshers::StdMeshers_MaxElementVolume::_narrow( hypothesis() );
435 h->SetMaxElementVolume( params[0].myValue.toDouble() );
437 else if( hypType()=="StartEndLength" )
439 StdMeshers::StdMeshers_StartEndLength_var h =
440 StdMeshers::StdMeshers_StartEndLength::_narrow( hypothesis() );
442 h->SetLength( params[0].myValue.toDouble(), true );
443 h->SetLength( params[1].myValue.toDouble(), false );
445 else if( hypType()=="Deflection1D" )
447 StdMeshers::StdMeshers_Deflection1D_var h =
448 StdMeshers::StdMeshers_Deflection1D::_narrow( hypothesis() );
450 h->SetDeflection( params[0].myValue.toDouble() );
452 else if( hypType()=="AutomaticLength" )
454 StdMeshers::StdMeshers_AutomaticLength_var h =
455 StdMeshers::StdMeshers_AutomaticLength::_narrow( hypothesis() );
457 h->SetFineness( params[0].myValue.toDouble() );
459 else if( hypType()=="NumberOfLayers" )
461 StdMeshers::StdMeshers_NumberOfLayers_var h =
462 StdMeshers::StdMeshers_NumberOfLayers::_narrow( hypothesis() );
464 h->SetNumberOfLayers( params[0].myValue.toInt() );
466 else if( hypType()=="LayerDistribution" )
468 StdMeshers::StdMeshers_LayerDistribution_var h =
469 StdMeshers::StdMeshers_LayerDistribution::_narrow( hypothesis() );
470 StdMeshersGUI_LayerDistributionParamWdg* w =
471 widget< StdMeshersGUI_LayerDistributionParamWdg >( 0 );
473 h->SetLayerDistribution( w->GetHypothesis() );
475 else if( hypType()=="ProjectionSource1D" )
477 StdMeshers::StdMeshers_ProjectionSource1D_var h =
478 StdMeshers::StdMeshers_ProjectionSource1D::_narrow( hypothesis() );
480 h->SetSourceEdge ( geomFromWdg ( getWidgetForParam( 0 )));
481 h->SetSourceMesh ( meshFromWdg ( getWidgetForParam( 1 )));
482 h->SetVertexAssociation( geomFromWdg ( getWidgetForParam( 2 )),
483 geomFromWdg ( getWidgetForParam( 3 )));
485 else if( hypType()=="ProjectionSource2D" )
487 StdMeshers::StdMeshers_ProjectionSource2D_var h =
488 StdMeshers::StdMeshers_ProjectionSource2D::_narrow( hypothesis() );
490 h->SetSourceFace ( geomFromWdg ( getWidgetForParam( 0 )));
491 h->SetSourceMesh ( meshFromWdg ( getWidgetForParam( 1 )));
492 h->SetVertexAssociation( geomFromWdg ( getWidgetForParam( 2 )), // src1
493 geomFromWdg ( getWidgetForParam( 4 )), // src2
494 geomFromWdg ( getWidgetForParam( 3 )), // tgt1
495 geomFromWdg ( getWidgetForParam( 5 ))); // tgt2
497 else if( hypType()=="ProjectionSource3D" )
499 StdMeshers::StdMeshers_ProjectionSource3D_var h =
500 StdMeshers::StdMeshers_ProjectionSource3D::_narrow( hypothesis() );
502 h->SetSource3DShape ( geomFromWdg ( getWidgetForParam( 0 )));
503 h->SetSourceMesh ( meshFromWdg ( getWidgetForParam( 1 )));
504 h->SetVertexAssociation( geomFromWdg ( getWidgetForParam( 2 )), // src1
505 geomFromWdg ( getWidgetForParam( 4 )), // src2
506 geomFromWdg ( getWidgetForParam( 3 )), // tgt1
507 geomFromWdg ( getWidgetForParam( 5 ))); // tgt2
513 //================================================================================
515 * \brief Return parameter values as SMESHGUI_GenericHypothesisCreator::StdParam
516 * \param p - list of parameters
517 * \retval bool - success flag
519 * Is called from SMESHGUI_GenericHypothesisCreator::buildStdFrame().
520 * Parameters will be shown using "standard" controls:
521 * Int by QtxIntSpinBox
522 * Double by SMESHGUI_SpinBox
523 * String by QLineEdit
524 * getCustomWidget() allows to redefine control for a parameter
526 //================================================================================
528 bool StdMeshersGUI_StdHypothesisCreator::stdParams( ListOfStdParams& p ) const
531 SMESHGUI_GenericHypothesisCreator::StdParam item;
534 customWidgets()->clear();
537 HypothesisData* data = SMESH::GetHypothesisData( hypType() );
538 item.myName = tr( "SMESH_NAME" );
539 item.myValue = data ? hypName() : QString();
541 customWidgets()->append(0);
544 SMESH::SMESH_Hypothesis_var hyp = initParamsHypothesis();
546 if( hypType()=="LocalLength" )
548 StdMeshers::StdMeshers_LocalLength_var h =
549 StdMeshers::StdMeshers_LocalLength::_narrow( hyp );
551 item.myName = tr("SMESH_LOCAL_LENGTH_PARAM");
552 item.myValue = h->GetLength();
554 item.myName = tr("SMESH_LOCAL_LENGTH_PRECISION");
555 item.myValue = h->GetPrecision();
558 else if( hypType()=="SegmentLengthAroundVertex" )
560 StdMeshers::StdMeshers_SegmentLengthAroundVertex_var h =
561 StdMeshers::StdMeshers_SegmentLengthAroundVertex::_narrow( hyp );
563 item.myName = tr("SMESH_LOCAL_LENGTH_PARAM");
564 item.myValue = h->GetLength();
567 else if( hypType()=="Arithmetic1D" )
569 StdMeshers::StdMeshers_Arithmetic1D_var h =
570 StdMeshers::StdMeshers_Arithmetic1D::_narrow( hyp );
572 item.myName = tr( "SMESH_START_LENGTH_PARAM" );
573 item.myValue = h->GetLength( true );
575 item.myName = tr( "SMESH_END_LENGTH_PARAM" );
576 item.myValue = h->GetLength( false );
579 else if( hypType()=="MaxElementArea" )
581 StdMeshers::StdMeshers_MaxElementArea_var h =
582 StdMeshers::StdMeshers_MaxElementArea::_narrow( hyp );
584 item.myName = tr( "SMESH_MAX_ELEMENT_AREA_PARAM" );
585 item.myValue = h->GetMaxElementArea();
588 else if( hypType()=="MaxElementVolume" )
590 StdMeshers::StdMeshers_MaxElementVolume_var h =
591 StdMeshers::StdMeshers_MaxElementVolume::_narrow( hyp );
593 item.myName = tr( "SMESH_MAX_ELEMENT_VOLUME_PARAM" );
594 item.myValue = h->GetMaxElementVolume();
597 else if( hypType()=="StartEndLength" )
599 StdMeshers::StdMeshers_StartEndLength_var h =
600 StdMeshers::StdMeshers_StartEndLength::_narrow( hyp );
602 item.myName = tr( "SMESH_START_LENGTH_PARAM" );
603 item.myValue = h->GetLength( true );
605 item.myName = tr( "SMESH_END_LENGTH_PARAM" );
606 item.myValue = h->GetLength( false );
609 else if( hypType()=="Deflection1D" )
611 StdMeshers::StdMeshers_Deflection1D_var h =
612 StdMeshers::StdMeshers_Deflection1D::_narrow( hyp );
614 item.myName = tr( "SMESH_DEFLECTION1D_PARAM" );
615 item.myValue = h->GetDeflection();
618 else if( hypType()=="AutomaticLength" )
620 StdMeshers::StdMeshers_AutomaticLength_var h =
621 StdMeshers::StdMeshers_AutomaticLength::_narrow( hyp );
623 item.myName = tr( "SMESH_FINENESS_PARAM" );
624 //item.myValue = h->GetFineness();
626 customWidgets()->append
627 ( new TDoubleSliderWith2Lables( "0 ", " 1", h->GetFineness(), 0, 1, 0.01, 0 ));
629 else if( hypType()=="NumberOfLayers" )
631 StdMeshers::StdMeshers_NumberOfLayers_var h =
632 StdMeshers::StdMeshers_NumberOfLayers::_narrow( hyp );
634 item.myName = tr( "SMESH_NUMBER_OF_LAYERS" );
635 item.myValue = (int) h->GetNumberOfLayers();
638 else if( hypType()=="LayerDistribution" )
640 StdMeshers::StdMeshers_LayerDistribution_var h =
641 StdMeshers::StdMeshers_LayerDistribution::_narrow( hyp );
643 item.myName = tr( "SMESH_LAYERS_DISTRIBUTION" ); p.append( item );
644 customWidgets()->append
645 ( new StdMeshersGUI_LayerDistributionParamWdg( h->GetLayerDistribution(), hypName(), dlg()));
647 else if( hypType()=="ProjectionSource1D" )
649 StdMeshers::StdMeshers_ProjectionSource1D_var h =
650 StdMeshers::StdMeshers_ProjectionSource1D::_narrow( hyp );
652 item.myName = tr( "SMESH_SOURCE_EDGE" ); p.append( item );
653 customWidgets()->append( newObjRefParamWdg( filterForShapeOfDim( 1 ),
654 h->GetSourceEdge()));
655 item.myName = tr( "SMESH_SOURCE_MESH" ); p.append( item );
656 customWidgets()->append( newObjRefParamWdg( new SMESH_TypeFilter( MESH ),
657 h->GetSourceMesh()));
658 item.myName = tr( "SMESH_SOURCE_VERTEX" ); p.append( item );
659 customWidgets()->append( newObjRefParamWdg( filterForShapeOfDim( 0 ),
660 h->GetSourceVertex()));
661 item.myName = tr( "SMESH_TARGET_VERTEX" ); p.append( item );
662 customWidgets()->append( newObjRefParamWdg( filterForShapeOfDim( 0 ),
663 h->GetTargetVertex()));
665 else if( hypType()=="ProjectionSource2D" )
667 StdMeshers::StdMeshers_ProjectionSource2D_var h =
668 StdMeshers::StdMeshers_ProjectionSource2D::_narrow( hyp );
670 item.myName = tr( "SMESH_SOURCE_FACE" ); p.append( item );
671 customWidgets()->append( newObjRefParamWdg( filterForShapeOfDim( 2 ),
672 h->GetSourceFace()));
673 item.myName = tr( "SMESH_SOURCE_MESH" ); p.append( item );
674 customWidgets()->append( newObjRefParamWdg( new SMESH_TypeFilter( MESH ),
675 h->GetSourceMesh()));
676 item.myName = tr( "SMESH_SOURCE_VERTEX1" ); p.append( item );
677 customWidgets()->append( newObjRefParamWdg( filterForShapeOfDim( 0 ),
678 h->GetSourceVertex( 1 )));
679 item.myName = tr( "SMESH_TARGET_VERTEX1" ); p.append( item );
680 customWidgets()->append( newObjRefParamWdg( filterForShapeOfDim( 0 ),
681 h->GetTargetVertex( 1 )));
682 item.myName = tr( "SMESH_SOURCE_VERTEX2" ); p.append( item );
683 customWidgets()->append( newObjRefParamWdg( filterForShapeOfDim( 0 ),
684 h->GetSourceVertex( 2 )));
685 item.myName = tr( "SMESH_TARGET_VERTEX2" ); p.append( item );
686 customWidgets()->append( newObjRefParamWdg( filterForShapeOfDim( 0 ),
687 h->GetTargetVertex( 2 )));
689 else if( hypType()=="ProjectionSource3D" )
691 StdMeshers::StdMeshers_ProjectionSource3D_var h =
692 StdMeshers::StdMeshers_ProjectionSource3D::_narrow( hyp );
694 item.myName = tr( "SMESH_SOURCE_3DSHAPE" ); p.append( item );
695 customWidgets()->append( newObjRefParamWdg( filterForShapeOfDim( 3, TopAbs_FACE, 6, true ),
696 h->GetSource3DShape()));
697 item.myName = tr( "SMESH_SOURCE_MESH" ); p.append( item );
698 customWidgets()->append( newObjRefParamWdg( new SMESH_TypeFilter( MESH ),
699 h->GetSourceMesh()));
700 item.myName = tr( "SMESH_SOURCE_VERTEX1" ); p.append( item );
701 customWidgets()->append( newObjRefParamWdg( filterForShapeOfDim( 0 ),
702 h->GetSourceVertex( 1 )));
703 item.myName = tr( "SMESH_TARGET_VERTEX1" ); p.append( item );
704 customWidgets()->append( newObjRefParamWdg( filterForShapeOfDim( 0 ),
705 h->GetTargetVertex( 1 )));
706 item.myName = tr( "SMESH_SOURCE_VERTEX2" ); p.append( item );
707 customWidgets()->append( newObjRefParamWdg( filterForShapeOfDim( 0 ),
708 h->GetSourceVertex( 2 )));
709 item.myName = tr( "SMESH_TARGET_VERTEX2" ); p.append( item );
710 customWidgets()->append( newObjRefParamWdg( filterForShapeOfDim( 0 ),
711 h->GetTargetVertex( 2 )));
718 //================================================================================
720 * \brief tune "standard" control
721 * \param w - control widget
722 * \param int - parameter index
724 //================================================================================
726 void StdMeshersGUI_StdHypothesisCreator::attuneStdWidget (QWidget* w, const int) const
728 SMESHGUI_SpinBox* sb = w->inherits( "SMESHGUI_SpinBox" ) ? ( SMESHGUI_SpinBox* )w : 0;
729 if( hypType()=="LocalLength" && sb )
731 if (sb->objectName() == tr("SMESH_LOCAL_LENGTH_PARAM"))
732 sb->RangeStepAndValidator( VALUE_SMALL, VALUE_MAX, 1.0, 6 );
733 else if (sb->objectName() == tr("SMESH_LOCAL_LENGTH_PRECISION"))
734 sb->RangeStepAndValidator( 0.0, 1.0, 0.05, 6 );
736 else if( hypType()=="Arithmetic1D" && sb )
738 sb->RangeStepAndValidator( VALUE_SMALL, VALUE_MAX, 1.0, 6 );
740 else if( hypType()=="MaxElementArea" && sb )
742 sb->RangeStepAndValidator( VALUE_SMALL_2, VALUE_MAX_2, 1.0, 6 );
744 else if( hypType()=="MaxElementVolume" && sb )
746 sb->RangeStepAndValidator( VALUE_SMALL_3, VALUE_MAX_3, 1.0, 6 );
748 else if( hypType()=="StartEndLength" && sb )
750 sb->RangeStepAndValidator( VALUE_SMALL, VALUE_MAX, 1.0, 6 );
752 else if( hypType()=="Deflection1D" && sb )
754 sb->RangeStepAndValidator( VALUE_SMALL, VALUE_MAX, 1.0, 6 );
756 else if ( sb ) // default validator for possible ancestors
758 sb->RangeStepAndValidator( VALUE_SMALL, VALUE_MAX, 1.0, 6 );
762 //================================================================================
764 * \brief Return dlg title
765 * \retval QString - title string
767 //================================================================================
769 QString StdMeshersGUI_StdHypothesisCreator::caption() const
771 return tr( QString( "SMESH_%1_TITLE" ).arg( hypTypeName( hypType() ) ).toLatin1().data() );
774 //================================================================================
776 * \brief return pixmap for dlg icon
779 //================================================================================
781 QPixmap StdMeshersGUI_StdHypothesisCreator::icon() const
783 QString hypIconName = tr( QString( "ICON_DLG_%1" ).arg( hypTypeName( hypType() ) ).toLatin1().data() );
784 return SMESHGUI::resourceMgr()->loadPixmap( "SMESH", hypIconName );
787 //================================================================================
789 * \brief Return hypothesis type name to show in dlg
792 //================================================================================
794 QString StdMeshersGUI_StdHypothesisCreator::type() const
796 return tr( QString( "SMESH_%1_HYPOTHESIS" ).arg( hypTypeName( hypType() ) ).toLatin1().data() );
799 //================================================================================
801 * \brief String to insert in "SMESH_%1_HYPOTHESIS" to get hypothesis type name
802 * from message resouce file
803 * \param t - hypothesis type
804 * \retval QString - result string
806 //================================================================================
808 QString StdMeshersGUI_StdHypothesisCreator::hypTypeName( const QString& t ) const
810 static QMap<QString,QString> types;
811 if( types.isEmpty() )
813 types.insert( "LocalLength", "LOCAL_LENGTH" );
814 types.insert( "NumberOfSegments", "NB_SEGMENTS" );
815 types.insert( "MaxElementArea", "MAX_ELEMENT_AREA" );
816 types.insert( "MaxElementVolume", "MAX_ELEMENT_VOLUME" );
817 types.insert( "StartEndLength", "START_END_LENGTH" );
818 types.insert( "Deflection1D", "DEFLECTION1D" );
819 types.insert( "Arithmetic1D", "ARITHMETIC_1D" );
820 types.insert( "AutomaticLength", "AUTOMATIC_LENGTH" );
821 types.insert( "ProjectionSource1D", "PROJECTION_SOURCE_1D" );
822 types.insert( "ProjectionSource2D", "PROJECTION_SOURCE_2D" );
823 types.insert( "ProjectionSource3D", "PROJECTION_SOURCE_3D" );
824 types.insert( "NumberOfLayers", "NUMBER_OF_LAYERS" );
825 types.insert( "LayerDistribution", "LAYER_DISTRIBUTION" );
826 types.insert( "SegmentLengthAroundVertex", "SEGMENT_LENGTH_AROUND_VERTEX" );
830 if( types.contains( t ) )
837 //=======================================================================
838 //function : getCustomWidget
839 //purpose : is called from buildStdFrame()
840 //=======================================================================
842 QWidget* StdMeshersGUI_StdHypothesisCreator::getCustomWidget( const StdParam & param,
844 const int index) const
847 if ( index < customWidgets()->count() ) {
848 w = customWidgets()->at( index );
850 w->setParent( parent );
851 w->move( QPoint( 0, 0 ) );
857 //================================================================================
859 * \brief Set param value taken from a custom widget
860 * \param param - SMESHGUI_GenericHypothesisCreator::StdParam structure
861 * \param widget - widget presenting param
862 * \retval bool - success flag
864 * this method is called from getStdParamFromDlg()
866 //================================================================================
868 bool StdMeshersGUI_StdHypothesisCreator::getParamFromCustomWidget( StdParam & param,
869 QWidget* widget) const
871 if ( hypType()=="AutomaticLength" ) {
872 TDoubleSliderWith2Lables* w = dynamic_cast<TDoubleSliderWith2Lables*>( widget );
874 param.myValue = w->value();
878 if ( widget->inherits( "StdMeshersGUI_ObjectReferenceParamWdg" ))
880 // show only 1st reference value
881 if ( true /*widget == getWidgetForParam( 0 )*/) {
882 const StdMeshersGUI_ObjectReferenceParamWdg * w =
883 static_cast<const StdMeshersGUI_ObjectReferenceParamWdg*>( widget );
884 param.myValue = w->GetValue();
888 if ( widget->inherits( "StdMeshersGUI_LayerDistributionParamWdg" ))
890 const StdMeshersGUI_LayerDistributionParamWdg * w =
891 static_cast<const StdMeshersGUI_LayerDistributionParamWdg*>( widget );
892 param.myValue = w->GetValue();
898 //================================================================================
900 * \brief called when operation cancelled
902 //================================================================================
904 void StdMeshersGUI_StdHypothesisCreator::onReject()
906 if ( hypType().startsWith("ProjectionSource" ))
908 // Uninstall filters of StdMeshersGUI_ObjectReferenceParamWdg
909 deactivateObjRefParamWdg( customWidgets() );