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>
35 #include <SALOMEDSClient_Study.hxx>
37 // SALOME GUI includes
38 #include <SUIT_ResourceMgr.h>
41 #include <SALOMEconfig.h>
42 #include CORBA_SERVER_HEADER(SMESH_BasicHypothesis)
43 #include CORBA_SERVER_HEADER(SMESH_Mesh)
46 #include <QHBoxLayout>
50 const double VALUE_MAX = 1.0e+15, // COORD_MAX
51 VALUE_MAX_2 = VALUE_MAX * VALUE_MAX,
52 VALUE_MAX_3 = VALUE_MAX_2 * VALUE_MAX,
53 VALUE_SMALL = 1.0e-15,
54 VALUE_SMALL_2 = VALUE_SMALL * VALUE_SMALL,
55 VALUE_SMALL_3 = VALUE_SMALL_2 * VALUE_SMALL;
57 //================================================================================
60 * \param type - hypothesis type
62 //================================================================================
64 StdMeshersGUI_StdHypothesisCreator::StdMeshersGUI_StdHypothesisCreator( const QString& type )
65 : SMESHGUI_GenericHypothesisCreator( type )
69 //================================================================================
73 //================================================================================
75 StdMeshersGUI_StdHypothesisCreator::~StdMeshersGUI_StdHypothesisCreator()
79 //================================================================================
81 * \brief Return widget for i-th hypothesis parameter (got from myParamWidgets)
82 * \param i - index of hypothesis parameter
83 * \retval QWidget* - found widget
85 //================================================================================
87 QWidget* StdMeshersGUI_StdHypothesisCreator::getWidgetForParam( int i ) const
90 if ( isCreation() ) ++i; // skip widget of 'name' parameter
92 if ( i < myCustomWidgets.count() ) {
93 QList<QWidget*>::const_iterator anIt = myCustomWidgets.begin();
94 QList<QWidget*>::const_iterator aLast = myCustomWidgets.end();
95 for ( int j = 0 ; !w && anIt != aLast; ++anIt )
100 // list has no at() const, so we iterate
101 QList<QWidget*>::const_iterator anIt = widgets().begin();
102 QList<QWidget*>::const_iterator aLast = widgets().end();
103 for( int j = 0; !w && anIt!=aLast; anIt++, ++j ) {
111 //================================================================================
113 * \brief Allow modifing myCustomWidgets in const methods
114 * \retval ListOfWidgets* - non-const pointer to myCustomWidgets
116 //================================================================================
118 StdMeshersGUI_StdHypothesisCreator::ListOfWidgets*
119 StdMeshersGUI_StdHypothesisCreator::customWidgets() const
121 return const_cast< ListOfWidgets* >( & myCustomWidgets );
124 //================================================================================
126 * \brief Builds dlg layout
127 * \retval QFrame* - the built widget
129 //================================================================================
131 QFrame* StdMeshersGUI_StdHypothesisCreator::buildFrame()
133 return buildStdFrame();
136 //================================================================================
138 * \brief Initialise parameter values in controls
140 //================================================================================
142 void StdMeshersGUI_StdHypothesisCreator::retrieveParams() const
144 // buildStdFrame() sets values itself calling stdParams()
146 if ( hypType().startsWith("ProjectionSource" ))
148 // we use this method to connect depending custom widgets
149 StdMeshersGUI_ObjectReferenceParamWdg* widgetToActivate = 0;
150 ListOfWidgets::const_iterator anIt = myCustomWidgets.begin();
151 for ( ; anIt != myCustomWidgets.end(); anIt++)
153 if ( *anIt && (*anIt)->inherits("StdMeshersGUI_ObjectReferenceParamWdg"))
155 StdMeshersGUI_ObjectReferenceParamWdg * w1 =
156 ( StdMeshersGUI_ObjectReferenceParamWdg* ) ( *anIt );
157 ListOfWidgets::const_iterator anIt2 = anIt;
158 for ( ++anIt2; anIt2 != myCustomWidgets.end(); anIt2++)
159 if ( *anIt2 && (*anIt2)->inherits("StdMeshersGUI_ObjectReferenceParamWdg"))
161 StdMeshersGUI_ObjectReferenceParamWdg * w2 =
162 ( StdMeshersGUI_ObjectReferenceParamWdg* ) ( *anIt2 );
163 w1->AvoidSimultaneousSelection( w2 );
165 if ( !widgetToActivate )
166 widgetToActivate = w1;
169 if ( widgetToActivate )
170 widgetToActivate->activateSelection();
174 dlg()->setMinimumSize( dlg()->minimumSizeHint().width(), dlg()->minimumSizeHint().height() );
179 //================================================================================
181 * \brief Widget: slider with left and right labels
183 //================================================================================
185 class TDoubleSliderWith2Lables: public QWidget
188 TDoubleSliderWith2Lables( const QString& leftLabel, const QString& rightLabel,
189 const double initValue, const double bottom,
190 const double top , const double precision,
191 QWidget * parent=0 , const char * name=0 )
192 :QWidget(parent), _bottom(bottom), _precision(precision)
196 QHBoxLayout* aHBoxL = new QHBoxLayout(this);
198 if ( !leftLabel.isEmpty() ) {
199 QLabel* aLeftLabel = new QLabel( this );
200 aLeftLabel->setText( leftLabel );
201 aHBoxL->addWidget( aLeftLabel );
204 _slider = new QSlider( Qt::Horizontal, this );
205 _slider->setRange( 0, toInt( top ));
206 _slider->setValue( toInt( initValue ));
207 aHBoxL->addWidget( _slider );
209 if ( !rightLabel.isEmpty() ) {
210 QLabel* aRightLabel = new QLabel( this );
211 aRightLabel->setText( rightLabel );
212 aHBoxL->addWidget( aRightLabel );
217 double value() const { return _bottom + _slider->value() * _precision; }
218 QSlider * getSlider() const { return _slider; }
219 int toInt( double val ) const { return (int) ceil(( val - _bottom ) / _precision ); }
221 double _bottom, _precision;
225 //================================================================================
227 * \brief Retrieve GEOM_Object held by widget
229 //================================================================================
231 inline GEOM::GEOM_Object_var geomFromWdg(const QWidget* wdg)
233 const StdMeshersGUI_ObjectReferenceParamWdg * objRefWdg =
234 dynamic_cast<const StdMeshersGUI_ObjectReferenceParamWdg*>( wdg );
236 return objRefWdg->GetObject< GEOM::GEOM_Object >();
238 return GEOM::GEOM_Object::_nil();
240 //================================================================================
242 * \brief Retrieve SMESH_Mesh held by widget
244 //================================================================================
246 inline SMESH::SMESH_Mesh_var meshFromWdg(const QWidget* wdg)
248 const StdMeshersGUI_ObjectReferenceParamWdg * objRefWdg =
249 dynamic_cast<const StdMeshersGUI_ObjectReferenceParamWdg*>( wdg );
251 return objRefWdg->GetObject< SMESH::SMESH_Mesh >();
253 return SMESH::SMESH_Mesh::_nil();
255 //================================================================================
257 * \brief creates a filter for selection of shapes of given dimension
258 * \param dim - dimension
259 * \param subShapeType - required type of subshapes, number of which must be \a nbSubShapes
260 * \param nbSubShapes - number of subshapes of given type
261 * \param closed - required closeness flag of a shape
262 * \retval SUIT_SelectionFilter* - created filter
264 //================================================================================
266 SUIT_SelectionFilter* filterForShapeOfDim(const int dim,
267 TopAbs_ShapeEnum subShapeType = TopAbs_SHAPE,
268 const int nbSubShapes = 0,
271 TColStd_MapOfInteger shapeTypes;
273 case 0: shapeTypes.Add( TopAbs_VERTEX ); break;
275 if ( subShapeType == TopAbs_SHAPE ) subShapeType = TopAbs_EDGE;
276 shapeTypes.Add( TopAbs_EDGE );
277 shapeTypes.Add( TopAbs_COMPOUND ); // for a group
280 if ( subShapeType == TopAbs_SHAPE ) subShapeType = TopAbs_FACE;
281 shapeTypes.Add( TopAbs_FACE );
282 shapeTypes.Add( TopAbs_COMPOUND ); // for a group
285 shapeTypes.Add( TopAbs_SHELL );
286 shapeTypes.Add( TopAbs_SOLID );
287 shapeTypes.Add( TopAbs_COMPSOLID );
288 shapeTypes.Add( TopAbs_COMPOUND );
291 return new SMESH_NumberFilter("GEOM", subShapeType, nbSubShapes,
292 shapeTypes, GEOM::GEOM_Object::_nil(), closed);
295 //================================================================================
297 * \brief Create a widget for object selection
298 * \param object - initial object
299 * \param filter - selection filter
300 * \retval QWidget* - created widget
302 //================================================================================
304 QWidget* newObjRefParamWdg( SUIT_SelectionFilter* filter,
305 CORBA::Object_var object)
307 StdMeshersGUI_ObjectReferenceParamWdg* w =
308 new StdMeshersGUI_ObjectReferenceParamWdg( filter, 0);
309 w->SetObject( object.in() );
313 //================================================================================
315 * \brief calls deactivateSelection() for StdMeshersGUI_ObjectReferenceParamWdg
316 * \param widgetList - list of widgets
318 //================================================================================
320 void deactivateObjRefParamWdg( QList<QWidget*>* widgetList )
322 StdMeshersGUI_ObjectReferenceParamWdg* w = 0;
323 QList<QWidget*>::iterator anIt = widgetList->begin();
324 QList<QWidget*>::iterator aLast = widgetList->end();
325 for ( ; anIt != aLast; anIt++ ) {
326 if ( (*anIt) && (*anIt)->inherits( "StdMeshersGUI_ObjectReferenceParamWdg" ))
328 w = (StdMeshersGUI_ObjectReferenceParamWdg* )( *anIt );
329 w->deactivateSelection();
335 //================================================================================
337 * \brief Check parameter values before accept()
338 * \retval bool - true if OK
340 //================================================================================
342 bool StdMeshersGUI_StdHypothesisCreator::checkParams( QString& msg ) const
344 if( !SMESHGUI_GenericHypothesisCreator::checkParams( msg ) )
347 // check if object reference parameter is set, as it has no default value
349 if ( hypType().startsWith("ProjectionSource" ))
351 StdMeshersGUI_ObjectReferenceParamWdg* w =
352 widget< StdMeshersGUI_ObjectReferenceParamWdg >( 0 );
353 ok = ( w->IsObjectSelected() );
354 if ( !ok ) w->SetObject( CORBA::Object::_nil() );
355 int nbAssocVert = ( hypType() == "ProjectionSource1D" ? 1 : 2 );
356 for ( int i = 0; ok && i < nbAssocVert; i += 2)
359 StdMeshersGUI_ObjectReferenceParamWdg* w1 =
360 widget< StdMeshersGUI_ObjectReferenceParamWdg >( i+2 );
361 StdMeshersGUI_ObjectReferenceParamWdg* w2 =
362 widget< StdMeshersGUI_ObjectReferenceParamWdg >( i+3 );
363 srcV = w1->GetValue();
364 tgtV = w2->GetValue();
365 ok = (( srcV.isEmpty() && tgtV.isEmpty() ) ||
366 ( !srcV.isEmpty() && !tgtV.isEmpty() && srcV != tgtV ));
368 w1->SetObject( CORBA::Object::_nil() );
369 w2->SetObject( CORBA::Object::_nil() );
373 // Uninstall filters of StdMeshersGUI_ObjectReferenceParamWdg
375 deactivateObjRefParamWdg( customWidgets() );
377 else if ( hypType() == "LayerDistribution" )
379 StdMeshersGUI_LayerDistributionParamWdg* w =
380 widget< StdMeshersGUI_LayerDistributionParamWdg >( 0 );
381 ok = ( w && w->IsOk() );
386 //================================================================================
388 * \brief Store params from GUI controls to a hypothesis
389 * \retval QString - text representation of parameters
391 //================================================================================
393 QString StdMeshersGUI_StdHypothesisCreator::storeParams() const
395 ListOfStdParams params;
396 bool res = getStdParamFromDlg( params );
399 SMESH::SetName( SMESH::FindSObject( hypothesis() ), params[0].myValue.toString().toLatin1().data() );
400 params.erase( params.begin() );
403 QString valueStr = stdParamValues( params );
404 QStringList aVariablesList = getVariablesFromDlg();
406 if( res && !params.isEmpty() )
408 if( hypType()=="LocalLength" )
410 StdMeshers::StdMeshers_LocalLength_var h =
411 StdMeshers::StdMeshers_LocalLength::_narrow( hypothesis() );
413 h->SetLength( params[0].myValue.toDouble() );
414 h->SetParameters(SMESHGUI::JoinObjectParameters(aVariablesList));
415 h->SetPrecision( params[1].myValue.toDouble() );
416 h->SetParameters(SMESHGUI::JoinObjectParameters(aVariablesList));
418 else if( hypType()=="SegmentLengthAroundVertex" )
420 StdMeshers::StdMeshers_SegmentLengthAroundVertex_var h =
421 StdMeshers::StdMeshers_SegmentLengthAroundVertex::_narrow( hypothesis() );
423 h->SetLength( params[0].myValue.toDouble() );
424 h->SetParameters(SMESHGUI::JoinObjectParameters(aVariablesList));
426 else if( hypType()=="Arithmetic1D" )
428 StdMeshers::StdMeshers_Arithmetic1D_var h =
429 StdMeshers::StdMeshers_Arithmetic1D::_narrow( hypothesis() );
431 h->SetLength( params[0].myValue.toDouble(), true );
432 h->SetParameters(SMESHGUI::JoinObjectParameters(aVariablesList));
433 h->SetLength( params[1].myValue.toDouble(), false );
434 h->SetParameters(SMESHGUI::JoinObjectParameters(aVariablesList));
436 else if( hypType()=="MaxElementArea" )
438 StdMeshers::StdMeshers_MaxElementArea_var h =
439 StdMeshers::StdMeshers_MaxElementArea::_narrow( hypothesis() );
441 h->SetMaxElementArea( params[0].myValue.toDouble() );
443 else if( hypType()=="MaxElementVolume" )
445 StdMeshers::StdMeshers_MaxElementVolume_var h =
446 StdMeshers::StdMeshers_MaxElementVolume::_narrow( hypothesis() );
448 h->SetMaxElementVolume( params[0].myValue.toDouble() );
450 else if( hypType()=="StartEndLength" )
452 StdMeshers::StdMeshers_StartEndLength_var h =
453 StdMeshers::StdMeshers_StartEndLength::_narrow( hypothesis() );
455 h->SetLength( params[0].myValue.toDouble(), true );
456 h->SetParameters(SMESHGUI::JoinObjectParameters(aVariablesList));
457 h->SetLength( params[1].myValue.toDouble(), false );
458 h->SetParameters(SMESHGUI::JoinObjectParameters(aVariablesList));
460 else if( hypType()=="Deflection1D" )
462 StdMeshers::StdMeshers_Deflection1D_var h =
463 StdMeshers::StdMeshers_Deflection1D::_narrow( hypothesis() );
464 h->SetParameters(SMESHGUI::JoinObjectParameters(aVariablesList));
465 h->SetDeflection( params[0].myValue.toDouble() );
467 else if( hypType()=="AutomaticLength" )
469 StdMeshers::StdMeshers_AutomaticLength_var h =
470 StdMeshers::StdMeshers_AutomaticLength::_narrow( hypothesis() );
472 h->SetFineness( params[0].myValue.toDouble() );
474 else if( hypType()=="NumberOfLayers" )
476 StdMeshers::StdMeshers_NumberOfLayers_var h =
477 StdMeshers::StdMeshers_NumberOfLayers::_narrow( hypothesis() );
479 h->SetNumberOfLayers( params[0].myValue.toInt() );
481 else if( hypType()=="LayerDistribution" )
483 StdMeshers::StdMeshers_LayerDistribution_var h =
484 StdMeshers::StdMeshers_LayerDistribution::_narrow( hypothesis() );
485 StdMeshersGUI_LayerDistributionParamWdg* w =
486 widget< StdMeshersGUI_LayerDistributionParamWdg >( 0 );
488 h->SetLayerDistribution( w->GetHypothesis() );
489 /* h->SetParameters(w->GetHypothesis()->GetParameters());
490 if(QString(w->GetHypothesis()->GetName()) == "LocalLength")
491 h->SetParameters(w->GetHypothesis()->GetParameters());
494 else if( hypType()=="ProjectionSource1D" )
496 StdMeshers::StdMeshers_ProjectionSource1D_var h =
497 StdMeshers::StdMeshers_ProjectionSource1D::_narrow( hypothesis() );
499 h->SetSourceEdge ( geomFromWdg ( getWidgetForParam( 0 )));
500 h->SetSourceMesh ( meshFromWdg ( getWidgetForParam( 1 )));
501 h->SetVertexAssociation( geomFromWdg ( getWidgetForParam( 2 )),
502 geomFromWdg ( getWidgetForParam( 3 )));
504 else if( hypType()=="ProjectionSource2D" )
506 StdMeshers::StdMeshers_ProjectionSource2D_var h =
507 StdMeshers::StdMeshers_ProjectionSource2D::_narrow( hypothesis() );
509 h->SetSourceFace ( geomFromWdg ( getWidgetForParam( 0 )));
510 h->SetSourceMesh ( meshFromWdg ( getWidgetForParam( 1 )));
511 h->SetVertexAssociation( geomFromWdg ( getWidgetForParam( 2 )), // src1
512 geomFromWdg ( getWidgetForParam( 4 )), // src2
513 geomFromWdg ( getWidgetForParam( 3 )), // tgt1
514 geomFromWdg ( getWidgetForParam( 5 ))); // tgt2
516 else if( hypType()=="ProjectionSource3D" )
518 StdMeshers::StdMeshers_ProjectionSource3D_var h =
519 StdMeshers::StdMeshers_ProjectionSource3D::_narrow( hypothesis() );
521 h->SetSource3DShape ( geomFromWdg ( getWidgetForParam( 0 )));
522 h->SetSourceMesh ( meshFromWdg ( getWidgetForParam( 1 )));
523 h->SetVertexAssociation( geomFromWdg ( getWidgetForParam( 2 )), // src1
524 geomFromWdg ( getWidgetForParam( 4 )), // src2
525 geomFromWdg ( getWidgetForParam( 3 )), // tgt1
526 geomFromWdg ( getWidgetForParam( 5 ))); // tgt2
532 //================================================================================
534 * \brief Return parameter values as SMESHGUI_GenericHypothesisCreator::StdParam
535 * \param p - list of parameters
536 * \retval bool - success flag
538 * Is called from SMESHGUI_GenericHypothesisCreator::buildStdFrame().
539 * Parameters will be shown using "standard" controls:
540 * Int by QtxIntSpinBox
541 * Double by SMESHGUI_SpinBox
542 * String by QLineEdit
543 * getCustomWidget() allows to redefine control for a parameter
545 //================================================================================
547 bool StdMeshersGUI_StdHypothesisCreator::stdParams( ListOfStdParams& p ) const
550 SMESHGUI_GenericHypothesisCreator::StdParam item;
553 customWidgets()->clear();
556 HypothesisData* data = SMESH::GetHypothesisData( hypType() );
557 item.myName = tr( "SMESH_NAME" );
558 item.myValue = data ? hypName() : QString();
560 customWidgets()->append(0);
563 SMESH::SMESH_Hypothesis_var hyp = initParamsHypothesis();
564 SMESH::ListOfParameters_var aParameters = hyp->GetLastParameters();
565 QString aVaribaleName;
567 if( hypType()=="LocalLength" )
569 StdMeshers::StdMeshers_LocalLength_var h =
570 StdMeshers::StdMeshers_LocalLength::_narrow( hyp );
572 item.myName = tr("SMESH_LOCAL_LENGTH_PARAM");
574 aVaribaleName = (aParameters->length() > 0) ? QString(aParameters[0].in()) : QString("");
575 item.isVariable = !aVaribaleName.isEmpty();
577 item.myValue = aVaribaleName;
579 item.myValue = h->GetLength();
582 item.myName = tr("SMESH_LOCAL_LENGTH_PRECISION");
583 aVaribaleName = (aParameters->length() > 1) ? QString(aParameters[1].in()) : QString("");
584 item.isVariable = !aVaribaleName.isEmpty();
586 item.myValue = aVaribaleName;
588 item.myValue = h->GetPrecision();
592 else if( hypType()=="SegmentLengthAroundVertex" )
594 StdMeshers::StdMeshers_SegmentLengthAroundVertex_var h =
595 StdMeshers::StdMeshers_SegmentLengthAroundVertex::_narrow( hyp );
596 item.myName = tr("SMESH_LOCAL_LENGTH_PARAM");
598 aVaribaleName = (aParameters->length() > 0) ? QString(aParameters[0].in()) : QString("");
599 item.isVariable = !aVaribaleName.isEmpty();
602 item.myValue = aVaribaleName;
604 item.myValue = h->GetLength();
607 else if( hypType()=="Arithmetic1D" )
609 StdMeshers::StdMeshers_Arithmetic1D_var h =
610 StdMeshers::StdMeshers_Arithmetic1D::_narrow( hyp );
612 aVaribaleName = (aParameters->length() > 0) ? QString(aParameters[0].in()) : QString("");
614 item.isVariable = !aVaribaleName.isEmpty();
616 item.myName = tr( "SMESH_START_LENGTH_PARAM" );
618 item.myValue = aVaribaleName;
620 item.myValue = h->GetLength( true );
623 aVaribaleName = (aParameters->length() > 1) ? QString(aParameters[1].in()) : QString("");
625 item.myName = tr( "SMESH_END_LENGTH_PARAM" );
628 item.myValue = aVaribaleName;
630 item.myValue = h->GetLength( false );
633 else if( hypType()=="MaxElementArea" )
635 StdMeshers::StdMeshers_MaxElementArea_var h =
636 StdMeshers::StdMeshers_MaxElementArea::_narrow( hyp );
638 item.myName = tr( "SMESH_MAX_ELEMENT_AREA_PARAM" );
639 item.myValue = h->GetMaxElementArea();
642 else if( hypType()=="MaxElementVolume" )
644 StdMeshers::StdMeshers_MaxElementVolume_var h =
645 StdMeshers::StdMeshers_MaxElementVolume::_narrow( hyp );
647 item.myName = tr( "SMESH_MAX_ELEMENT_VOLUME_PARAM" );
648 item.myValue = h->GetMaxElementVolume();
651 else if( hypType()=="StartEndLength" )
653 StdMeshers::StdMeshers_StartEndLength_var h =
654 StdMeshers::StdMeshers_StartEndLength::_narrow( hyp );
656 item.myName = tr( "SMESH_START_LENGTH_PARAM" );
658 aVaribaleName = (aParameters->length() > 0) ? QString(aParameters[0].in()) : QString("");
659 item.isVariable = !aVaribaleName.isEmpty();
661 item.myValue = aVaribaleName;
663 item.myValue = h->GetLength( true );
666 item.myName = tr( "SMESH_END_LENGTH_PARAM" );
667 aVaribaleName = (aParameters->length() > 1) ? QString(aParameters[1].in()) : QString("");
668 item.isVariable = !aVaribaleName.isEmpty();
670 item.myValue = aVaribaleName;
672 item.myValue = h->GetLength( false );
676 else if( hypType()=="Deflection1D" )
678 StdMeshers::StdMeshers_Deflection1D_var h =
679 StdMeshers::StdMeshers_Deflection1D::_narrow( hyp );
681 item.myName = tr( "SMESH_DEFLECTION1D_PARAM" );
682 aVaribaleName = (aParameters->length() > 0) ? QString(aParameters[0].in()) : QString("");
683 item.isVariable = !aVaribaleName.isEmpty();
685 item.myValue = aVaribaleName;
687 item.myValue = h->GetDeflection();
690 else if( hypType()=="AutomaticLength" )
692 StdMeshers::StdMeshers_AutomaticLength_var h =
693 StdMeshers::StdMeshers_AutomaticLength::_narrow( hyp );
695 item.myName = tr( "SMESH_FINENESS_PARAM" );
696 //item.myValue = h->GetFineness();
698 customWidgets()->append
699 ( new TDoubleSliderWith2Lables( "0 ", " 1", h->GetFineness(), 0, 1, 0.01, 0 ));
701 else if( hypType()=="NumberOfLayers" )
703 StdMeshers::StdMeshers_NumberOfLayers_var h =
704 StdMeshers::StdMeshers_NumberOfLayers::_narrow( hyp );
706 item.myName = tr( "SMESH_NUMBER_OF_LAYERS" );
707 item.myValue = (int) h->GetNumberOfLayers();
710 else if( hypType()=="LayerDistribution" )
712 StdMeshers::StdMeshers_LayerDistribution_var h =
713 StdMeshers::StdMeshers_LayerDistribution::_narrow( hyp );
715 item.myName = tr( "SMESH_LAYERS_DISTRIBUTION" ); p.append( item );
717 //Set into not published hypo last variables
718 /* QStringList aLastVarsList;
719 for(int i = 0;i<aParameters->length();i++)
720 aLastVarsList.append(QString(aParameters[i].in()));
722 if(!aLastVarsList.isEmpty())
723 h->GetLayerDistribution()->SetParameters(SMESHGUI::JoinObjectParameters(aLastVarsList));
725 customWidgets()->append
726 ( new StdMeshersGUI_LayerDistributionParamWdg( h->GetLayerDistribution(), hypName(), dlg()));
728 else if( hypType()=="ProjectionSource1D" )
730 StdMeshers::StdMeshers_ProjectionSource1D_var h =
731 StdMeshers::StdMeshers_ProjectionSource1D::_narrow( hyp );
733 item.myName = tr( "SMESH_SOURCE_EDGE" ); p.append( item );
734 customWidgets()->append( newObjRefParamWdg( filterForShapeOfDim( 1 ),
735 h->GetSourceEdge()));
736 item.myName = tr( "SMESH_SOURCE_MESH" ); p.append( item );
737 customWidgets()->append( newObjRefParamWdg( new SMESH_TypeFilter( MESH ),
738 h->GetSourceMesh()));
739 item.myName = tr( "SMESH_SOURCE_VERTEX" ); p.append( item );
740 customWidgets()->append( newObjRefParamWdg( filterForShapeOfDim( 0 ),
741 h->GetSourceVertex()));
742 item.myName = tr( "SMESH_TARGET_VERTEX" ); p.append( item );
743 customWidgets()->append( newObjRefParamWdg( filterForShapeOfDim( 0 ),
744 h->GetTargetVertex()));
746 else if( hypType()=="ProjectionSource2D" )
748 StdMeshers::StdMeshers_ProjectionSource2D_var h =
749 StdMeshers::StdMeshers_ProjectionSource2D::_narrow( hyp );
751 item.myName = tr( "SMESH_SOURCE_FACE" ); p.append( item );
752 customWidgets()->append( newObjRefParamWdg( filterForShapeOfDim( 2 ),
753 h->GetSourceFace()));
754 item.myName = tr( "SMESH_SOURCE_MESH" ); p.append( item );
755 customWidgets()->append( newObjRefParamWdg( new SMESH_TypeFilter( MESH ),
756 h->GetSourceMesh()));
757 item.myName = tr( "SMESH_SOURCE_VERTEX1" ); p.append( item );
758 customWidgets()->append( newObjRefParamWdg( filterForShapeOfDim( 0 ),
759 h->GetSourceVertex( 1 )));
760 item.myName = tr( "SMESH_TARGET_VERTEX1" ); p.append( item );
761 customWidgets()->append( newObjRefParamWdg( filterForShapeOfDim( 0 ),
762 h->GetTargetVertex( 1 )));
763 item.myName = tr( "SMESH_SOURCE_VERTEX2" ); p.append( item );
764 customWidgets()->append( newObjRefParamWdg( filterForShapeOfDim( 0 ),
765 h->GetSourceVertex( 2 )));
766 item.myName = tr( "SMESH_TARGET_VERTEX2" ); p.append( item );
767 customWidgets()->append( newObjRefParamWdg( filterForShapeOfDim( 0 ),
768 h->GetTargetVertex( 2 )));
770 else if( hypType()=="ProjectionSource3D" )
772 StdMeshers::StdMeshers_ProjectionSource3D_var h =
773 StdMeshers::StdMeshers_ProjectionSource3D::_narrow( hyp );
775 item.myName = tr( "SMESH_SOURCE_3DSHAPE" ); p.append( item );
776 customWidgets()->append( newObjRefParamWdg( filterForShapeOfDim( 3, TopAbs_FACE, 6, true ),
777 h->GetSource3DShape()));
778 item.myName = tr( "SMESH_SOURCE_MESH" ); p.append( item );
779 customWidgets()->append( newObjRefParamWdg( new SMESH_TypeFilter( MESH ),
780 h->GetSourceMesh()));
781 item.myName = tr( "SMESH_SOURCE_VERTEX1" ); p.append( item );
782 customWidgets()->append( newObjRefParamWdg( filterForShapeOfDim( 0 ),
783 h->GetSourceVertex( 1 )));
784 item.myName = tr( "SMESH_TARGET_VERTEX1" ); p.append( item );
785 customWidgets()->append( newObjRefParamWdg( filterForShapeOfDim( 0 ),
786 h->GetTargetVertex( 1 )));
787 item.myName = tr( "SMESH_SOURCE_VERTEX2" ); p.append( item );
788 customWidgets()->append( newObjRefParamWdg( filterForShapeOfDim( 0 ),
789 h->GetSourceVertex( 2 )));
790 item.myName = tr( "SMESH_TARGET_VERTEX2" ); p.append( item );
791 customWidgets()->append( newObjRefParamWdg( filterForShapeOfDim( 0 ),
792 h->GetTargetVertex( 2 )));
799 //================================================================================
801 * \brief tune "standard" control
802 * \param w - control widget
803 * \param int - parameter index
805 //================================================================================
807 void StdMeshersGUI_StdHypothesisCreator::attuneStdWidget (QWidget* w, const int) const
809 SMESHGUI_SpinBox* sb = w->inherits( "SMESHGUI_SpinBox" ) ? ( SMESHGUI_SpinBox* )w : 0;
810 if( hypType()=="LocalLength" && sb )
812 if (sb->objectName() == tr("SMESH_LOCAL_LENGTH_PARAM"))
813 sb->RangeStepAndValidator( VALUE_SMALL, VALUE_MAX, 1.0, 6 );
814 else if (sb->objectName() == tr("SMESH_LOCAL_LENGTH_PRECISION"))
815 sb->RangeStepAndValidator( 0.0, 1.0, 0.05, 7 );
817 else if( hypType()=="Arithmetic1D" && sb )
819 sb->RangeStepAndValidator( VALUE_SMALL, VALUE_MAX, 1.0, 6 );
821 else if( hypType()=="MaxElementArea" && sb )
823 sb->RangeStepAndValidator( VALUE_SMALL_2, VALUE_MAX_2, 1.0, 6 );
825 else if( hypType()=="MaxElementVolume" && sb )
827 sb->RangeStepAndValidator( VALUE_SMALL_3, VALUE_MAX_3, 1.0, 6 );
829 else if( hypType()=="StartEndLength" && sb )
831 sb->RangeStepAndValidator( VALUE_SMALL, VALUE_MAX, 1.0, 6 );
833 else if( hypType()=="Deflection1D" && sb )
835 sb->RangeStepAndValidator( VALUE_SMALL, VALUE_MAX, 1.0, 6 );
837 else if ( sb ) // default validator for possible ancestors
839 sb->RangeStepAndValidator( VALUE_SMALL, VALUE_MAX, 1.0, 6 );
843 //================================================================================
845 * \brief Return dlg title
846 * \retval QString - title string
848 //================================================================================
850 QString StdMeshersGUI_StdHypothesisCreator::caption() const
852 return tr( QString( "SMESH_%1_TITLE" ).arg( hypTypeName( hypType() ) ).toLatin1().data() );
855 //================================================================================
857 * \brief return pixmap for dlg icon
860 //================================================================================
862 QPixmap StdMeshersGUI_StdHypothesisCreator::icon() const
864 QString hypIconName = tr( QString( "ICON_DLG_%1" ).arg( hypTypeName( hypType() ) ).toLatin1().data() );
865 return SMESHGUI::resourceMgr()->loadPixmap( "SMESH", hypIconName );
868 //================================================================================
870 * \brief Return hypothesis type name to show in dlg
873 //================================================================================
875 QString StdMeshersGUI_StdHypothesisCreator::type() const
877 return tr( QString( "SMESH_%1_HYPOTHESIS" ).arg( hypTypeName( hypType() ) ).toLatin1().data() );
880 //================================================================================
882 * \brief String to insert in "SMESH_%1_HYPOTHESIS" to get hypothesis type name
883 * from message resouce file
884 * \param t - hypothesis type
885 * \retval QString - result string
887 //================================================================================
889 QString StdMeshersGUI_StdHypothesisCreator::hypTypeName( const QString& t ) const
891 static QMap<QString,QString> types;
892 if( types.isEmpty() )
894 types.insert( "LocalLength", "LOCAL_LENGTH" );
895 types.insert( "NumberOfSegments", "NB_SEGMENTS" );
896 types.insert( "MaxElementArea", "MAX_ELEMENT_AREA" );
897 types.insert( "MaxElementVolume", "MAX_ELEMENT_VOLUME" );
898 types.insert( "StartEndLength", "START_END_LENGTH" );
899 types.insert( "Deflection1D", "DEFLECTION1D" );
900 types.insert( "Arithmetic1D", "ARITHMETIC_1D" );
901 types.insert( "AutomaticLength", "AUTOMATIC_LENGTH" );
902 types.insert( "ProjectionSource1D", "PROJECTION_SOURCE_1D" );
903 types.insert( "ProjectionSource2D", "PROJECTION_SOURCE_2D" );
904 types.insert( "ProjectionSource3D", "PROJECTION_SOURCE_3D" );
905 types.insert( "NumberOfLayers", "NUMBER_OF_LAYERS" );
906 types.insert( "LayerDistribution", "LAYER_DISTRIBUTION" );
907 types.insert( "SegmentLengthAroundVertex", "SEGMENT_LENGTH_AROUND_VERTEX" );
911 if( types.contains( t ) )
918 //=======================================================================
919 //function : getCustomWidget
920 //purpose : is called from buildStdFrame()
921 //=======================================================================
923 QWidget* StdMeshersGUI_StdHypothesisCreator::getCustomWidget( const StdParam & param,
925 const int index) const
928 if ( index < customWidgets()->count() ) {
929 w = customWidgets()->at( index );
931 w->setParent( parent );
932 w->move( QPoint( 0, 0 ) );
938 //================================================================================
940 * \brief Set param value taken from a custom widget
941 * \param param - SMESHGUI_GenericHypothesisCreator::StdParam structure
942 * \param widget - widget presenting param
943 * \retval bool - success flag
945 * this method is called from getStdParamFromDlg()
947 //================================================================================
949 bool StdMeshersGUI_StdHypothesisCreator::getParamFromCustomWidget( StdParam & param,
950 QWidget* widget) const
952 if ( hypType()=="AutomaticLength" ) {
953 TDoubleSliderWith2Lables* w = dynamic_cast<TDoubleSliderWith2Lables*>( widget );
955 param.myValue = w->value();
959 if ( widget->inherits( "StdMeshersGUI_ObjectReferenceParamWdg" ))
961 // show only 1st reference value
962 if ( true /*widget == getWidgetForParam( 0 )*/) {
963 const StdMeshersGUI_ObjectReferenceParamWdg * w =
964 static_cast<const StdMeshersGUI_ObjectReferenceParamWdg*>( widget );
965 param.myValue = w->GetValue();
969 if ( widget->inherits( "StdMeshersGUI_LayerDistributionParamWdg" ))
971 const StdMeshersGUI_LayerDistributionParamWdg * w =
972 static_cast<const StdMeshersGUI_LayerDistributionParamWdg*>( widget );
973 param.myValue = w->GetValue();
979 //================================================================================
981 * \brief called when operation cancelled
983 //================================================================================
985 void StdMeshersGUI_StdHypothesisCreator::onReject()
987 if ( hypType().startsWith("ProjectionSource" ))
989 // Uninstall filters of StdMeshersGUI_ObjectReferenceParamWdg
990 deactivateObjRefParamWdg( customWidgets() );
994 //================================================================================
998 //================================================================================
999 /*QVariant StdMeshersGUI_StdHypothesisCreator::
1000 parseParameter(const QStringList& theList, int theNbParam) const
1002 _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
1004 if(theList.size() > theNbParam) {
1005 QString aParameter = theList[theNbParam];
1006 if(QString::compare(QString(""),aParameter) !=0 ) {
1007 if(aStudy->IsVariable(aParameter.toLatin1().constData())) {
1011 bool aResult = false;
1012 int anIResult = aParameter.toInt(&aResult);
1014 aResult = anIResult;
1016 double aDResult = aParameter.toDouble(&aResult);