1 // Copyright (C) 2007-2008 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
22 // File : StdMeshersGUI_StdHypothesisCreator.cxx
23 // Author : Alexander SOLOVYOV, Open CASCADE S.A.S.
26 #include "StdMeshersGUI_StdHypothesisCreator.h"
29 #include <SMESHGUI_SpinBox.h>
30 #include <SMESHGUI_HypothesesUtils.h>
31 #include <SMESHGUI_Utils.h>
32 #include <SMESH_TypeFilter.hxx>
33 #include <SMESH_NumberFilter.hxx>
34 #include "StdMeshersGUI_ObjectReferenceParamWdg.h"
35 #include "StdMeshersGUI_LayerDistributionParamWdg.h"
36 #include "StdMeshersGUI_EdgeDirectionParamWdg.h"
37 #include <SALOMEDSClient_Study.hxx>
39 // SALOME GUI includes
40 #include <SUIT_ResourceMgr.h>
43 #include <SALOMEconfig.h>
44 #include CORBA_SERVER_HEADER(SMESH_BasicHypothesis)
45 #include CORBA_SERVER_HEADER(SMESH_Mesh)
48 #include <QHBoxLayout>
53 const double VALUE_MAX = 1.0e+15, // COORD_MAX
54 VALUE_MAX_2 = VALUE_MAX * VALUE_MAX,
55 VALUE_MAX_3 = VALUE_MAX_2 * VALUE_MAX,
56 VALUE_SMALL = 1.0e-15,
57 VALUE_SMALL_2 = VALUE_SMALL * VALUE_SMALL,
58 VALUE_SMALL_3 = VALUE_SMALL_2 * VALUE_SMALL;
60 //================================================================================
63 * \param type - hypothesis type
65 //================================================================================
67 StdMeshersGUI_StdHypothesisCreator::StdMeshersGUI_StdHypothesisCreator( const QString& type )
68 : SMESHGUI_GenericHypothesisCreator( type )
72 //================================================================================
76 //================================================================================
78 StdMeshersGUI_StdHypothesisCreator::~StdMeshersGUI_StdHypothesisCreator()
82 //================================================================================
84 * \brief Return widget for i-th hypothesis parameter (got from myParamWidgets)
85 * \param i - index of hypothesis parameter
86 * \retval QWidget* - found widget
88 //================================================================================
90 QWidget* StdMeshersGUI_StdHypothesisCreator::getWidgetForParam( int i ) const
93 if ( isCreation() ) ++i; // skip widget of 'name' parameter
95 if ( i < myCustomWidgets.count() ) {
96 QList<QWidget*>::const_iterator anIt = myCustomWidgets.begin();
97 QList<QWidget*>::const_iterator aLast = myCustomWidgets.end();
98 for ( int j = 0 ; !w && anIt != aLast; ++anIt, ++j )
103 // list has no at() const, so we iterate
104 QList<QWidget*>::const_iterator anIt = widgets().begin();
105 QList<QWidget*>::const_iterator aLast = widgets().end();
106 for( int j = 0; !w && anIt!=aLast; anIt++, ++j ) {
114 //================================================================================
116 * \brief Allow modifing myCustomWidgets in const methods
117 * \retval ListOfWidgets* - non-const pointer to myCustomWidgets
119 //================================================================================
121 StdMeshersGUI_StdHypothesisCreator::ListOfWidgets*
122 StdMeshersGUI_StdHypothesisCreator::customWidgets() const
124 return const_cast< ListOfWidgets* >( & myCustomWidgets );
127 //================================================================================
129 * \brief Builds dlg layout
130 * \retval QFrame* - the built widget
132 //================================================================================
134 QFrame* StdMeshersGUI_StdHypothesisCreator::buildFrame()
136 return buildStdFrame();
139 //================================================================================
141 * \brief Initialise parameter values in controls
143 //================================================================================
145 void StdMeshersGUI_StdHypothesisCreator::retrieveParams() const
147 // buildStdFrame() sets values itself calling stdParams()
149 if ( hypType().startsWith("ProjectionSource" ))
151 // we use this method to connect depending custom widgets
152 StdMeshersGUI_ObjectReferenceParamWdg* widgetToActivate = 0;
153 ListOfWidgets::const_iterator anIt = myCustomWidgets.begin();
154 for ( ; anIt != myCustomWidgets.end(); anIt++)
156 if ( *anIt && (*anIt)->inherits("StdMeshersGUI_ObjectReferenceParamWdg"))
158 StdMeshersGUI_ObjectReferenceParamWdg * w1 =
159 ( StdMeshersGUI_ObjectReferenceParamWdg* ) ( *anIt );
160 ListOfWidgets::const_iterator anIt2 = anIt;
161 for ( ++anIt2; anIt2 != myCustomWidgets.end(); anIt2++)
162 if ( *anIt2 && (*anIt2)->inherits("StdMeshersGUI_ObjectReferenceParamWdg"))
164 StdMeshersGUI_ObjectReferenceParamWdg * w2 =
165 ( StdMeshersGUI_ObjectReferenceParamWdg* ) ( *anIt2 );
166 w1->AvoidSimultaneousSelection( w2 );
168 if ( !widgetToActivate )
169 widgetToActivate = w1;
172 if ( widgetToActivate )
173 widgetToActivate->activateSelection();
177 dlg()->setMinimumSize( dlg()->minimumSizeHint().width(), dlg()->minimumSizeHint().height() );
182 //================================================================================
184 * \brief Widget: slider with left and right labels
186 //================================================================================
188 class TDoubleSliderWith2Lables: public QWidget
191 TDoubleSliderWith2Lables( const QString& leftLabel, const QString& rightLabel,
192 const double initValue, const double bottom,
193 const double top , const double precision,
194 QWidget * parent=0 , const char * name=0 )
195 :QWidget(parent), _bottom(bottom), _precision(precision)
199 QHBoxLayout* aHBoxL = new QHBoxLayout(this);
201 if ( !leftLabel.isEmpty() ) {
202 QLabel* aLeftLabel = new QLabel( this );
203 aLeftLabel->setText( leftLabel );
204 aHBoxL->addWidget( aLeftLabel );
207 _slider = new QSlider( Qt::Horizontal, this );
208 _slider->setRange( 0, toInt( top ));
209 _slider->setValue( toInt( initValue ));
210 aHBoxL->addWidget( _slider );
212 if ( !rightLabel.isEmpty() ) {
213 QLabel* aRightLabel = new QLabel( this );
214 aRightLabel->setText( rightLabel );
215 aHBoxL->addWidget( aRightLabel );
220 double value() const { return _bottom + _slider->value() * _precision; }
221 QSlider * getSlider() const { return _slider; }
222 int toInt( double val ) const { return (int) ceil(( val - _bottom ) / _precision ); }
224 double _bottom, _precision;
228 //================================================================================
230 * \brief Retrieve GEOM_Object held by widget
232 //================================================================================
234 inline GEOM::GEOM_Object_var geomFromWdg(const QWidget* wdg)
236 const StdMeshersGUI_ObjectReferenceParamWdg * objRefWdg =
237 dynamic_cast<const StdMeshersGUI_ObjectReferenceParamWdg*>( wdg );
239 return objRefWdg->GetObject< GEOM::GEOM_Object >();
241 return GEOM::GEOM_Object::_nil();
243 //================================================================================
245 * \brief Retrieve SMESH_Mesh held by widget
247 //================================================================================
249 inline SMESH::SMESH_Mesh_var meshFromWdg(const QWidget* wdg)
251 const StdMeshersGUI_ObjectReferenceParamWdg * objRefWdg =
252 dynamic_cast<const StdMeshersGUI_ObjectReferenceParamWdg*>( wdg );
254 return objRefWdg->GetObject< SMESH::SMESH_Mesh >();
256 return SMESH::SMESH_Mesh::_nil();
258 //================================================================================
260 * \brief creates a filter for selection of shapes of given dimension
261 * \param dim - dimension
262 * \param subShapeType - required type of subshapes, number of which must be \a nbSubShapes
263 * \param nbSubShapes - number of subshapes of given type
264 * \param closed - required closeness flag of a shape
265 * \retval SUIT_SelectionFilter* - created filter
267 //================================================================================
269 SUIT_SelectionFilter* filterForShapeOfDim(const int dim,
270 TopAbs_ShapeEnum subShapeType = TopAbs_SHAPE,
271 const int nbSubShapes = 0,
274 TColStd_MapOfInteger shapeTypes;
276 case 0: shapeTypes.Add( TopAbs_VERTEX ); break;
278 if ( subShapeType == TopAbs_SHAPE ) subShapeType = TopAbs_EDGE;
279 shapeTypes.Add( TopAbs_EDGE );
280 shapeTypes.Add( TopAbs_COMPOUND ); // for a group
283 if ( subShapeType == TopAbs_SHAPE ) subShapeType = TopAbs_FACE;
284 shapeTypes.Add( TopAbs_FACE );
285 shapeTypes.Add( TopAbs_COMPOUND ); // for a group
288 shapeTypes.Add( TopAbs_SHELL );
289 shapeTypes.Add( TopAbs_SOLID );
290 shapeTypes.Add( TopAbs_COMPSOLID );
291 shapeTypes.Add( TopAbs_COMPOUND );
294 return new SMESH_NumberFilter("GEOM", subShapeType, nbSubShapes,
295 shapeTypes, GEOM::GEOM_Object::_nil(), closed);
298 //================================================================================
300 * \brief Create a widget for object selection
301 * \param object - initial object
302 * \param filter - selection filter
303 * \retval QWidget* - created widget
305 //================================================================================
307 QWidget* newObjRefParamWdg( SUIT_SelectionFilter* filter,
308 CORBA::Object_var object)
310 StdMeshersGUI_ObjectReferenceParamWdg* w =
311 new StdMeshersGUI_ObjectReferenceParamWdg( filter, 0);
312 w->SetObject( object.in() );
316 //================================================================================
318 * \brief calls deactivateSelection() for StdMeshersGUI_ObjectReferenceParamWdg
319 * \param widgetList - list of widgets
321 //================================================================================
323 void deactivateObjRefParamWdg( QList<QWidget*>* widgetList )
325 StdMeshersGUI_ObjectReferenceParamWdg* w = 0;
326 QList<QWidget*>::iterator anIt = widgetList->begin();
327 QList<QWidget*>::iterator aLast = widgetList->end();
328 for ( ; anIt != aLast; anIt++ ) {
329 if ( (*anIt) && (*anIt)->inherits( "StdMeshersGUI_ObjectReferenceParamWdg" ))
331 w = (StdMeshersGUI_ObjectReferenceParamWdg* )( *anIt );
332 w->deactivateSelection();
338 //================================================================================
340 * \brief Check parameter values before accept()
341 * \retval bool - true if OK
343 //================================================================================
345 bool StdMeshersGUI_StdHypothesisCreator::checkParams( QString& msg ) const
347 if( !SMESHGUI_GenericHypothesisCreator::checkParams( msg ) )
350 // check if object reference parameter is set, as it has no default value
352 if ( hypType().startsWith("ProjectionSource" ))
354 StdMeshersGUI_ObjectReferenceParamWdg* w =
355 widget< StdMeshersGUI_ObjectReferenceParamWdg >( 0 );
356 ok = ( w->IsObjectSelected() );
357 if ( !ok ) w->SetObject( CORBA::Object::_nil() );
358 int nbAssocVert = ( hypType() == "ProjectionSource1D" ? 1 : 2 );
359 for ( int i = 0; ok && i < nbAssocVert; i += 2)
362 StdMeshersGUI_ObjectReferenceParamWdg* w1 =
363 widget< StdMeshersGUI_ObjectReferenceParamWdg >( i+2 );
364 StdMeshersGUI_ObjectReferenceParamWdg* w2 =
365 widget< StdMeshersGUI_ObjectReferenceParamWdg >( i+3 );
366 srcV = w1->GetValue();
367 tgtV = w2->GetValue();
368 ok = (( srcV.isEmpty() && tgtV.isEmpty() ) ||
369 ( !srcV.isEmpty() && !tgtV.isEmpty() && srcV != tgtV ));
371 w1->SetObject( CORBA::Object::_nil() );
372 w2->SetObject( CORBA::Object::_nil() );
376 // Uninstall filters of StdMeshersGUI_ObjectReferenceParamWdg
378 deactivateObjRefParamWdg( customWidgets() );
380 else if ( hypType() == "LayerDistribution" )
382 StdMeshersGUI_LayerDistributionParamWdg* w =
383 widget< StdMeshersGUI_LayerDistributionParamWdg >( 0 );
384 ok = ( w && w->IsOk() );
389 //================================================================================
391 * \brief Store params from GUI controls to a hypothesis
392 * \retval QString - text representation of parameters
394 //================================================================================
396 QString StdMeshersGUI_StdHypothesisCreator::storeParams() const
398 ListOfStdParams params;
399 bool res = getStdParamFromDlg( params );
402 SMESH::SetName( SMESH::FindSObject( hypothesis() ), params[0].myValue.toString().toLatin1().data() );
403 params.erase( params.begin() );
406 QString valueStr = stdParamValues( params );
407 QStringList aVariablesList = getVariablesFromDlg();
409 if( res && !params.isEmpty() )
411 if( hypType()=="LocalLength" )
413 StdMeshers::StdMeshers_LocalLength_var h =
414 StdMeshers::StdMeshers_LocalLength::_narrow( hypothesis() );
416 h->SetLength( params[0].myValue.toDouble() );
417 h->SetParameters(SMESHGUI::JoinObjectParameters(aVariablesList));
418 h->SetPrecision( params[1].myValue.toDouble() );
419 h->SetParameters(SMESHGUI::JoinObjectParameters(aVariablesList));
421 else if( hypType()=="MaxLength" )
423 StdMeshers::StdMeshers_MaxLength_var h =
424 StdMeshers::StdMeshers_MaxLength::_narrow( hypothesis() );
426 h->SetLength( params[0].myValue.toDouble() );
427 h->SetParameters(SMESHGUI::JoinObjectParameters(aVariablesList));
428 h->SetUsePreestimatedLength( widget< QCheckBox >( 1 )->isChecked() );
429 if ( !h->HavePreestimatedLength() && !h->_is_equivalent( initParamsHypothesis() )) {
430 StdMeshers::StdMeshers_MaxLength_var hInit =
431 StdMeshers::StdMeshers_MaxLength::_narrow( initParamsHypothesis() );
432 h->SetPreestimatedLength( hInit->GetPreestimatedLength() );
435 else if( hypType()=="SegmentLengthAroundVertex" )
437 StdMeshers::StdMeshers_SegmentLengthAroundVertex_var h =
438 StdMeshers::StdMeshers_SegmentLengthAroundVertex::_narrow( hypothesis() );
440 h->SetLength( params[0].myValue.toDouble() );
441 h->SetParameters(SMESHGUI::JoinObjectParameters(aVariablesList));
443 else if( hypType()=="Arithmetic1D" )
445 StdMeshers::StdMeshers_Arithmetic1D_var h =
446 StdMeshers::StdMeshers_Arithmetic1D::_narrow( hypothesis() );
448 StdMeshersGUI_EdgeDirectionParamWdg* w =
449 widget< StdMeshersGUI_EdgeDirectionParamWdg >( 2 );
451 h->SetStartLength( params[0].myValue.toDouble() );
452 h->SetParameters(SMESHGUI::JoinObjectParameters(aVariablesList));
453 h->SetEndLength( params[1].myValue.toDouble() );
454 h->SetParameters(SMESHGUI::JoinObjectParameters(aVariablesList));
456 h->SetReversedEdges( w->GetListOfIDs() );
457 const char * entry = w->GetMainShapeEntry();
458 h->SetObjectEntry( entry );
461 else if( hypType()=="MaxElementArea" )
463 StdMeshers::StdMeshers_MaxElementArea_var h =
464 StdMeshers::StdMeshers_MaxElementArea::_narrow( hypothesis() );
465 h->SetParameters(SMESHGUI::JoinObjectParameters(aVariablesList));
466 h->SetMaxElementArea( params[0].myValue.toDouble() );
468 else if( hypType()=="MaxElementVolume" )
470 StdMeshers::StdMeshers_MaxElementVolume_var h =
471 StdMeshers::StdMeshers_MaxElementVolume::_narrow( hypothesis() );
473 h->SetMaxElementVolume( params[0].myValue.toDouble() );
474 h->SetParameters(SMESHGUI::JoinObjectParameters(aVariablesList));
476 else if( hypType()=="StartEndLength" )
478 StdMeshers::StdMeshers_StartEndLength_var h =
479 StdMeshers::StdMeshers_StartEndLength::_narrow( hypothesis() );
481 StdMeshersGUI_EdgeDirectionParamWdg* w =
482 widget< StdMeshersGUI_EdgeDirectionParamWdg >( 2 );
484 h->SetStartLength( params[0].myValue.toDouble() );
485 h->SetParameters(SMESHGUI::JoinObjectParameters(aVariablesList));
486 h->SetEndLength( params[1].myValue.toDouble() );
487 h->SetParameters(SMESHGUI::JoinObjectParameters(aVariablesList));
489 h->SetReversedEdges( w->GetListOfIDs() );
490 h->SetObjectEntry( w->GetMainShapeEntry() );
493 else if( hypType()=="Deflection1D" )
495 StdMeshers::StdMeshers_Deflection1D_var h =
496 StdMeshers::StdMeshers_Deflection1D::_narrow( hypothesis() );
497 h->SetParameters(SMESHGUI::JoinObjectParameters(aVariablesList));
498 h->SetDeflection( params[0].myValue.toDouble() );
500 else if( hypType()=="AutomaticLength" )
502 StdMeshers::StdMeshers_AutomaticLength_var h =
503 StdMeshers::StdMeshers_AutomaticLength::_narrow( hypothesis() );
505 h->SetFineness( params[0].myValue.toDouble() );
507 else if( hypType()=="NumberOfLayers" )
509 StdMeshers::StdMeshers_NumberOfLayers_var h =
510 StdMeshers::StdMeshers_NumberOfLayers::_narrow( hypothesis() );
512 h->SetNumberOfLayers( params[0].myValue.toInt() );
513 h->SetParameters(SMESHGUI::JoinObjectParameters(aVariablesList));
515 else if( hypType()=="LayerDistribution" )
517 StdMeshers::StdMeshers_LayerDistribution_var h =
518 StdMeshers::StdMeshers_LayerDistribution::_narrow( hypothesis() );
519 StdMeshersGUI_LayerDistributionParamWdg* w =
520 widget< StdMeshersGUI_LayerDistributionParamWdg >( 0 );
522 h->SetLayerDistribution( w->GetHypothesis() );
523 h->SetParameters(w->GetHypothesis()->GetParameters());
524 w->GetHypothesis()->ClearParameters();
526 else if( hypType()=="ProjectionSource1D" )
528 StdMeshers::StdMeshers_ProjectionSource1D_var h =
529 StdMeshers::StdMeshers_ProjectionSource1D::_narrow( hypothesis() );
531 h->SetSourceEdge ( geomFromWdg ( getWidgetForParam( 0 )));
532 h->SetSourceMesh ( meshFromWdg ( getWidgetForParam( 1 )));
533 h->SetVertexAssociation( geomFromWdg ( getWidgetForParam( 2 )),
534 geomFromWdg ( getWidgetForParam( 3 )));
536 else if( hypType()=="ProjectionSource2D" )
538 StdMeshers::StdMeshers_ProjectionSource2D_var h =
539 StdMeshers::StdMeshers_ProjectionSource2D::_narrow( hypothesis() );
541 h->SetSourceFace ( geomFromWdg ( getWidgetForParam( 0 )));
542 h->SetSourceMesh ( meshFromWdg ( getWidgetForParam( 1 )));
543 h->SetVertexAssociation( geomFromWdg ( getWidgetForParam( 2 )), // src1
544 geomFromWdg ( getWidgetForParam( 4 )), // src2
545 geomFromWdg ( getWidgetForParam( 3 )), // tgt1
546 geomFromWdg ( getWidgetForParam( 5 ))); // tgt2
548 else if( hypType()=="ProjectionSource3D" )
550 StdMeshers::StdMeshers_ProjectionSource3D_var h =
551 StdMeshers::StdMeshers_ProjectionSource3D::_narrow( hypothesis() );
553 h->SetSource3DShape ( geomFromWdg ( getWidgetForParam( 0 )));
554 h->SetSourceMesh ( meshFromWdg ( getWidgetForParam( 1 )));
555 h->SetVertexAssociation( geomFromWdg ( getWidgetForParam( 2 )), // src1
556 geomFromWdg ( getWidgetForParam( 4 )), // src2
557 geomFromWdg ( getWidgetForParam( 3 )), // tgt1
558 geomFromWdg ( getWidgetForParam( 5 ))); // tgt2
564 //================================================================================
566 * \brief Return parameter values as SMESHGUI_GenericHypothesisCreator::StdParam
567 * \param p - list of parameters
568 * \retval bool - success flag
570 * Is called from SMESHGUI_GenericHypothesisCreator::buildStdFrame().
571 * Parameters will be shown using "standard" controls:
572 * Int by QtxIntSpinBox
573 * Double by SMESHGUI_SpinBox
574 * String by QLineEdit
575 * getCustomWidget() allows to redefine control for a parameter
577 //================================================================================
579 bool StdMeshersGUI_StdHypothesisCreator::stdParams( ListOfStdParams& p ) const
582 SMESHGUI_GenericHypothesisCreator::StdParam item;
585 customWidgets()->clear();
588 HypothesisData* data = SMESH::GetHypothesisData( hypType() );
589 item.myName = tr( "SMESH_NAME" );
590 item.myValue = data ? hypName() : QString();
592 customWidgets()->append(0);
595 SMESH::SMESH_Hypothesis_var hyp = initParamsHypothesis();
596 SMESH::ListOfParameters_var aParameters = hyp->GetLastParameters();
598 if( hypType()=="LocalLength" )
600 StdMeshers::StdMeshers_LocalLength_var h =
601 StdMeshers::StdMeshers_LocalLength::_narrow( hyp );
603 item.myName = tr("SMESH_LOCAL_LENGTH_PARAM");
604 if(!initVariableName(aParameters,item,0))
605 item.myValue = h->GetLength();
608 item.myName = tr("SMESH_LOCAL_LENGTH_PRECISION");
609 if(!initVariableName(aParameters,item,1))
610 item.myValue = h->GetPrecision();
614 else if( hypType()=="MaxLength" )
616 StdMeshers::StdMeshers_MaxLength_var h =
617 StdMeshers::StdMeshers_MaxLength::_narrow( hyp );
618 // try to set a right preestimated length to edited hypothesis
619 bool noPreestimatedAtEdition = false;
620 if ( !isCreation() ) {
621 StdMeshers::StdMeshers_MaxLength_var initHyp =
622 StdMeshers::StdMeshers_MaxLength::_narrow( initParamsHypothesis(true) );
623 noPreestimatedAtEdition =
624 ( initHyp->_is_nil() || !initHyp->HavePreestimatedLength() );
625 if ( !noPreestimatedAtEdition )
626 h->SetPreestimatedLength( initHyp->GetPreestimatedLength() );
629 item.myName = tr("SMESH_LOCAL_LENGTH_PARAM");
630 if(!initVariableName(aParameters,item,0))
631 item.myValue = h->GetLength();
633 customWidgets()->append(0);
635 item.myName = tr("SMESH_USE_PREESTIMATED_LENGTH");
637 QCheckBox* aQCheckBox = new QCheckBox(dlg());
638 if ( !noPreestimatedAtEdition && h->HavePreestimatedLength() ) {
639 aQCheckBox->setChecked( h->GetUsePreestimatedLength() );
640 connect( aQCheckBox, SIGNAL( stateChanged(int) ), this, SLOT( onValueChanged() ) );
643 aQCheckBox->setChecked( false );
644 aQCheckBox->setEnabled( false );
646 customWidgets()->append( aQCheckBox );
648 else if( hypType()=="SegmentLengthAroundVertex" )
650 StdMeshers::StdMeshers_SegmentLengthAroundVertex_var h =
651 StdMeshers::StdMeshers_SegmentLengthAroundVertex::_narrow( hyp );
653 item.myName = tr("SMESH_LOCAL_LENGTH_PARAM");
654 if(!initVariableName(aParameters,item,0))
655 item.myValue = h->GetLength();
659 else if( hypType()=="Arithmetic1D" )
661 StdMeshers::StdMeshers_Arithmetic1D_var h =
662 StdMeshers::StdMeshers_Arithmetic1D::_narrow( hyp );
664 item.myName = tr( "SMESH_START_LENGTH_PARAM" );
665 if(!initVariableName(aParameters,item,0))
666 item.myValue = h->GetLength( true );
669 customWidgets()->append (0);
671 item.myName = tr( "SMESH_END_LENGTH_PARAM" );
672 if(!initVariableName(aParameters,item,1))
673 item.myValue = h->GetLength( false );
676 customWidgets()->append (0);
678 item.myName = tr( "SMESH_REVERCE_EDGES" );
681 StdMeshersGUI_EdgeDirectionParamWdg* aDirectionWidget = new StdMeshersGUI_EdgeDirectionParamWdg();
682 QString anEntry = SMESHGUI_GenericHypothesisCreator::getShapeEntry();
684 anEntry = h->GetObjectEntry();
685 aDirectionWidget->SetMainShapeEntry( anEntry );
686 aDirectionWidget->SetListOfIDs( h->GetReversedEdges() );
687 aDirectionWidget->showPreview( true );
688 customWidgets()->append ( aDirectionWidget );
690 else if( hypType()=="MaxElementArea" )
692 StdMeshers::StdMeshers_MaxElementArea_var h =
693 StdMeshers::StdMeshers_MaxElementArea::_narrow( hyp );
695 item.myName = tr( "SMESH_MAX_ELEMENT_AREA_PARAM" );
696 if(!initVariableName(aParameters,item,0))
697 item.myValue = h->GetMaxElementArea();
701 else if( hypType()=="MaxElementVolume" )
703 StdMeshers::StdMeshers_MaxElementVolume_var h =
704 StdMeshers::StdMeshers_MaxElementVolume::_narrow( hyp );
706 item.myName = tr( "SMESH_MAX_ELEMENT_VOLUME_PARAM" );
707 if(!initVariableName(aParameters,item,0))
708 item.myValue = h->GetMaxElementVolume();
711 else if( hypType()=="StartEndLength" )
713 StdMeshers::StdMeshers_StartEndLength_var h =
714 StdMeshers::StdMeshers_StartEndLength::_narrow( hyp );
716 item.myName = tr( "SMESH_START_LENGTH_PARAM" );
718 if(!initVariableName(aParameters,item,0))
719 item.myValue = h->GetLength( true );
721 customWidgets()->append(0);
723 item.myName = tr( "SMESH_END_LENGTH_PARAM" );
724 if(!initVariableName(aParameters,item,1))
725 item.myValue = h->GetLength( false );
727 customWidgets()->append(0);
729 item.myName = tr( "SMESH_REVERCE_EDGES" );
732 StdMeshersGUI_EdgeDirectionParamWdg* aDirectionWidget = new StdMeshersGUI_EdgeDirectionParamWdg();
733 QString anEntry = SMESHGUI_GenericHypothesisCreator::getShapeEntry();
735 anEntry = h->GetObjectEntry();
736 aDirectionWidget->SetMainShapeEntry( anEntry );
737 aDirectionWidget->SetListOfIDs( h->GetReversedEdges() );
738 aDirectionWidget->SetMainShapeEntry( h->GetObjectEntry() );
739 aDirectionWidget->showPreview( true );
740 customWidgets()->append ( aDirectionWidget );
742 else if( hypType()=="Deflection1D" )
744 StdMeshers::StdMeshers_Deflection1D_var h =
745 StdMeshers::StdMeshers_Deflection1D::_narrow( hyp );
747 item.myName = tr( "SMESH_DEFLECTION1D_PARAM" );
748 if(!initVariableName(aParameters,item,0))
749 item.myValue = h->GetDeflection();
752 else if( hypType()=="AutomaticLength" )
754 StdMeshers::StdMeshers_AutomaticLength_var h =
755 StdMeshers::StdMeshers_AutomaticLength::_narrow( hyp );
757 item.myName = tr( "SMESH_FINENESS_PARAM" );
758 //item.myValue = h->GetFineness();
760 customWidgets()->append
761 ( new TDoubleSliderWith2Lables( "0 ", " 1", h->GetFineness(), 0, 1, 0.01, 0 ));
763 else if( hypType()=="NumberOfLayers" )
765 StdMeshers::StdMeshers_NumberOfLayers_var h =
766 StdMeshers::StdMeshers_NumberOfLayers::_narrow( hyp );
768 item.myName = tr( "SMESH_NUMBER_OF_LAYERS" );
769 if(!initVariableName(aParameters,item,0))
770 item.myValue = (int) h->GetNumberOfLayers();
773 else if( hypType()=="LayerDistribution" )
775 StdMeshers::StdMeshers_LayerDistribution_var h =
776 StdMeshers::StdMeshers_LayerDistribution::_narrow( hyp );
778 item.myName = tr( "SMESH_LAYERS_DISTRIBUTION" ); p.append( item );
780 //Set into not published hypo last variables
781 QStringList aLastVarsList;
782 for(int i = 0;i<aParameters->length();i++)
783 aLastVarsList.append(QString(aParameters[i].in()));
785 if(!aLastVarsList.isEmpty())
786 h->GetLayerDistribution()->SetLastParameters(SMESHGUI::JoinObjectParameters(aLastVarsList));
788 customWidgets()->append
789 ( new StdMeshersGUI_LayerDistributionParamWdg( h->GetLayerDistribution(), hypName(), dlg()));
791 else if( hypType()=="ProjectionSource1D" )
793 StdMeshers::StdMeshers_ProjectionSource1D_var h =
794 StdMeshers::StdMeshers_ProjectionSource1D::_narrow( hyp );
796 item.myName = tr( "SMESH_SOURCE_EDGE" ); p.append( item );
797 customWidgets()->append( newObjRefParamWdg( filterForShapeOfDim( 1 ),
798 h->GetSourceEdge()));
799 item.myName = tr( "SMESH_SOURCE_MESH" ); p.append( item );
800 customWidgets()->append( newObjRefParamWdg( new SMESH_TypeFilter( MESH ),
801 h->GetSourceMesh()));
802 item.myName = tr( "SMESH_SOURCE_VERTEX" ); p.append( item );
803 customWidgets()->append( newObjRefParamWdg( filterForShapeOfDim( 0 ),
804 h->GetSourceVertex()));
805 item.myName = tr( "SMESH_TARGET_VERTEX" ); p.append( item );
806 customWidgets()->append( newObjRefParamWdg( filterForShapeOfDim( 0 ),
807 h->GetTargetVertex()));
809 else if( hypType()=="ProjectionSource2D" )
811 StdMeshers::StdMeshers_ProjectionSource2D_var h =
812 StdMeshers::StdMeshers_ProjectionSource2D::_narrow( hyp );
814 item.myName = tr( "SMESH_SOURCE_FACE" ); p.append( item );
815 customWidgets()->append( newObjRefParamWdg( filterForShapeOfDim( 2 ),
816 h->GetSourceFace()));
817 item.myName = tr( "SMESH_SOURCE_MESH" ); p.append( item );
818 customWidgets()->append( newObjRefParamWdg( new SMESH_TypeFilter( MESH ),
819 h->GetSourceMesh()));
820 item.myName = tr( "SMESH_SOURCE_VERTEX1" ); p.append( item );
821 customWidgets()->append( newObjRefParamWdg( filterForShapeOfDim( 0 ),
822 h->GetSourceVertex( 1 )));
823 item.myName = tr( "SMESH_TARGET_VERTEX1" ); p.append( item );
824 customWidgets()->append( newObjRefParamWdg( filterForShapeOfDim( 0 ),
825 h->GetTargetVertex( 1 )));
826 item.myName = tr( "SMESH_SOURCE_VERTEX2" ); p.append( item );
827 customWidgets()->append( newObjRefParamWdg( filterForShapeOfDim( 0 ),
828 h->GetSourceVertex( 2 )));
829 item.myName = tr( "SMESH_TARGET_VERTEX2" ); p.append( item );
830 customWidgets()->append( newObjRefParamWdg( filterForShapeOfDim( 0 ),
831 h->GetTargetVertex( 2 )));
833 else if( hypType()=="ProjectionSource3D" )
835 StdMeshers::StdMeshers_ProjectionSource3D_var h =
836 StdMeshers::StdMeshers_ProjectionSource3D::_narrow( hyp );
838 item.myName = tr( "SMESH_SOURCE_3DSHAPE" ); p.append( item );
839 customWidgets()->append( newObjRefParamWdg( filterForShapeOfDim( 3, TopAbs_FACE, 6, true ),
840 h->GetSource3DShape()));
841 item.myName = tr( "SMESH_SOURCE_MESH" ); p.append( item );
842 customWidgets()->append( newObjRefParamWdg( new SMESH_TypeFilter( MESH ),
843 h->GetSourceMesh()));
844 item.myName = tr( "SMESH_SOURCE_VERTEX1" ); p.append( item );
845 customWidgets()->append( newObjRefParamWdg( filterForShapeOfDim( 0 ),
846 h->GetSourceVertex( 1 )));
847 item.myName = tr( "SMESH_TARGET_VERTEX1" ); p.append( item );
848 customWidgets()->append( newObjRefParamWdg( filterForShapeOfDim( 0 ),
849 h->GetTargetVertex( 1 )));
850 item.myName = tr( "SMESH_SOURCE_VERTEX2" ); p.append( item );
851 customWidgets()->append( newObjRefParamWdg( filterForShapeOfDim( 0 ),
852 h->GetSourceVertex( 2 )));
853 item.myName = tr( "SMESH_TARGET_VERTEX2" ); p.append( item );
854 customWidgets()->append( newObjRefParamWdg( filterForShapeOfDim( 0 ),
855 h->GetTargetVertex( 2 )));
862 //================================================================================
864 * \brief tune "standard" control
865 * \param w - control widget
866 * \param int - parameter index
868 //================================================================================
870 void StdMeshersGUI_StdHypothesisCreator::attuneStdWidget (QWidget* w, const int) const
872 SMESHGUI_SpinBox* sb = w->inherits( "SMESHGUI_SpinBox" ) ? ( SMESHGUI_SpinBox* )w : 0;
873 if( hypType()=="LocalLength" && sb )
875 if (sb->objectName() == tr("SMESH_LOCAL_LENGTH_PARAM"))
876 sb->RangeStepAndValidator( VALUE_SMALL, VALUE_MAX, 1.0, 6 );
877 else if (sb->objectName() == tr("SMESH_LOCAL_LENGTH_PRECISION"))
878 sb->RangeStepAndValidator( 0.0, 1.0, 0.05, 7 );
880 else if( hypType()=="Arithmetic1D" && sb )
882 sb->RangeStepAndValidator( VALUE_SMALL, VALUE_MAX, 1.0, 6 );
884 else if( hypType()=="MaxLength" && sb )
886 sb->RangeStepAndValidator( VALUE_SMALL, VALUE_MAX, 1.0, 6 );
887 sb->setEnabled( !widget< QCheckBox >( 1 )->isChecked() );
889 else if( hypType()=="MaxElementArea" && sb )
891 sb->RangeStepAndValidator( VALUE_SMALL_2, VALUE_MAX_2, 1.0, 6 );
893 else if( hypType()=="MaxElementVolume" && sb )
895 sb->RangeStepAndValidator( VALUE_SMALL_3, VALUE_MAX_3, 1.0, 6 );
897 else if( hypType()=="StartEndLength" && sb )
899 sb->RangeStepAndValidator( VALUE_SMALL, VALUE_MAX, 1.0, 6 );
901 else if( hypType()=="Deflection1D" && sb )
903 sb->RangeStepAndValidator( VALUE_SMALL, VALUE_MAX, 1.0, 6 );
905 else if ( sb ) // default validator for possible ancestors
907 sb->RangeStepAndValidator( VALUE_SMALL, VALUE_MAX, 1.0, 6 );
911 //================================================================================
913 * \brief Return dlg title
914 * \retval QString - title string
916 //================================================================================
918 QString StdMeshersGUI_StdHypothesisCreator::caption() const
920 return tr( QString( "SMESH_%1_TITLE" ).arg( hypTypeName( hypType() ) ).toLatin1().data() );
923 //================================================================================
925 * \brief return pixmap for dlg icon
928 //================================================================================
930 QPixmap StdMeshersGUI_StdHypothesisCreator::icon() const
932 QString hypIconName = tr( QString( "ICON_DLG_%1" ).arg( hypTypeName( hypType() ) ).toLatin1().data() );
933 return SMESHGUI::resourceMgr()->loadPixmap( "SMESH", hypIconName );
936 //================================================================================
938 * \brief Return hypothesis type name to show in dlg
941 //================================================================================
943 QString StdMeshersGUI_StdHypothesisCreator::type() const
945 return tr( QString( "SMESH_%1_HYPOTHESIS" ).arg( hypTypeName( hypType() ) ).toLatin1().data() );
948 //================================================================================
950 * \brief String to insert in "SMESH_%1_HYPOTHESIS" to get hypothesis type name
951 * from message resouce file
952 * \param t - hypothesis type
953 * \retval QString - result string
955 //================================================================================
957 QString StdMeshersGUI_StdHypothesisCreator::hypTypeName( const QString& t ) const
959 static QMap<QString,QString> types;
960 if( types.isEmpty() )
962 types.insert( "LocalLength", "LOCAL_LENGTH" );
963 types.insert( "NumberOfSegments", "NB_SEGMENTS" );
964 types.insert( "MaxElementArea", "MAX_ELEMENT_AREA" );
965 types.insert( "MaxElementVolume", "MAX_ELEMENT_VOLUME" );
966 types.insert( "StartEndLength", "START_END_LENGTH" );
967 types.insert( "Deflection1D", "DEFLECTION1D" );
968 types.insert( "Arithmetic1D", "ARITHMETIC_1D" );
969 types.insert( "AutomaticLength", "AUTOMATIC_LENGTH" );
970 types.insert( "ProjectionSource1D", "PROJECTION_SOURCE_1D" );
971 types.insert( "ProjectionSource2D", "PROJECTION_SOURCE_2D" );
972 types.insert( "ProjectionSource3D", "PROJECTION_SOURCE_3D" );
973 types.insert( "NumberOfLayers", "NUMBER_OF_LAYERS" );
974 types.insert( "LayerDistribution", "LAYER_DISTRIBUTION" );
975 types.insert( "SegmentLengthAroundVertex", "SEGMENT_LENGTH_AROUND_VERTEX" );
976 types.insert( "MaxLength", "MAX_LENGTH" );
980 if( types.contains( t ) )
987 //=======================================================================
988 //function : getCustomWidget
989 //purpose : is called from buildStdFrame()
990 //=======================================================================
992 QWidget* StdMeshersGUI_StdHypothesisCreator::getCustomWidget( const StdParam & param,
994 const int index) const
997 if ( index < customWidgets()->count() ) {
998 w = customWidgets()->at( index );
1000 w->setParent( parent );
1001 w->move( QPoint( 0, 0 ) );
1007 //================================================================================
1009 * \brief Set param value taken from a custom widget
1010 * \param param - SMESHGUI_GenericHypothesisCreator::StdParam structure
1011 * \param widget - widget presenting param
1012 * \retval bool - success flag
1014 * this method is called from getStdParamFromDlg()
1016 //================================================================================
1018 bool StdMeshersGUI_StdHypothesisCreator::getParamFromCustomWidget( StdParam & param,
1019 QWidget* widget) const
1021 if ( hypType()=="AutomaticLength" ) {
1022 TDoubleSliderWith2Lables* w = dynamic_cast<TDoubleSliderWith2Lables*>( widget );
1024 param.myValue = w->value();
1028 if ( hypType() == "MaxLength" ) {
1032 if ( widget->inherits( "StdMeshersGUI_ObjectReferenceParamWdg" ))
1034 // show only 1st reference value
1035 if ( true /*widget == getWidgetForParam( 0 )*/) {
1036 const StdMeshersGUI_ObjectReferenceParamWdg * w =
1037 static_cast<const StdMeshersGUI_ObjectReferenceParamWdg*>( widget );
1038 param.myValue = w->GetValue();
1042 if ( widget->inherits( "StdMeshersGUI_LayerDistributionParamWdg" ))
1044 const StdMeshersGUI_LayerDistributionParamWdg * w =
1045 static_cast<const StdMeshersGUI_LayerDistributionParamWdg*>( widget );
1046 param.myValue = w->GetValue();
1049 if ( widget->inherits( "StdMeshersGUI_EdgeDirectionParamWdg" ))
1051 const StdMeshersGUI_EdgeDirectionParamWdg * w =
1052 static_cast<const StdMeshersGUI_EdgeDirectionParamWdg*>( widget );
1053 param.myValue = w->GetValue();
1059 //================================================================================
1061 * \brief called when operation cancelled
1063 //================================================================================
1065 void StdMeshersGUI_StdHypothesisCreator::onReject()
1067 if ( hypType().startsWith("ProjectionSource" ))
1069 // Uninstall filters of StdMeshersGUI_ObjectReferenceParamWdg
1070 deactivateObjRefParamWdg( customWidgets() );
1074 //================================================================================
1078 //================================================================================
1080 void StdMeshersGUI_StdHypothesisCreator::valueChanged( QWidget* paramWidget)
1082 if ( hypType() == "MaxLength" && paramWidget == getWidgetForParam(1) ) {
1083 getWidgetForParam(0)->setEnabled( !widget< QCheckBox >( 1 )->isChecked() );
1084 if ( !getWidgetForParam(0)->isEnabled() ) {
1085 StdMeshers::StdMeshers_MaxLength_var h =
1086 StdMeshers::StdMeshers_MaxLength::_narrow( initParamsHypothesis() );
1087 widget< QtxDoubleSpinBox >( 0 )->setValue( h->GetPreestimatedLength() );
1092 //================================================================================
1096 //================================================================================
1098 bool StdMeshersGUI_StdHypothesisCreator::initVariableName(SMESH::ListOfParameters_var theParameters,
1099 StdParam &theParams,
1102 QString aVaribaleName = (theParameters->length() > order) ? QString(theParameters[order].in()) : QString("");
1103 theParams.isVariable = !aVaribaleName.isEmpty();
1104 if(theParams.isVariable)
1105 theParams.myValue = aVaribaleName;
1107 return theParams.isVariable;