+namespace {
+
+ //================================================================================
+ /*!
+ * \brief Widget: slider with left and right labels
+ */
+ //================================================================================
+
+ class TDoubleSliderWith2Labels: public QWidget
+ {
+ public:
+ TDoubleSliderWith2Labels( const QString& leftLabel, const QString& rightLabel,
+ const double initValue, const double bottom,
+ const double top , const double precision,
+ QWidget * parent=0 , const char * name=0 )
+ :QWidget(parent), _bottom(bottom), _precision(precision)
+ {
+ setObjectName(name);
+
+ QHBoxLayout* aHBoxL = new QHBoxLayout(this);
+
+ if ( !leftLabel.isEmpty() ) {
+ QLabel* aLeftLabel = new QLabel( this );
+ aLeftLabel->setText( leftLabel );
+ aHBoxL->addWidget( aLeftLabel );
+ }
+
+ _slider = new QSlider( Qt::Horizontal, this );
+ _slider->setRange( 0, toInt( top ));
+ _slider->setValue( toInt( initValue ));
+ aHBoxL->addWidget( _slider );
+
+ if ( !rightLabel.isEmpty() ) {
+ QLabel* aRightLabel = new QLabel( this );
+ aRightLabel->setText( rightLabel );
+ aHBoxL->addWidget( aRightLabel );
+ }
+
+ setLayout( aHBoxL );
+ }
+ double value() const { return _bottom + _slider->value() * _precision; }
+ QSlider * getSlider() const { return _slider; }
+ int toInt( double val ) const { return (int) ceil(( val - _bottom ) / _precision ); }
+ private:
+ double _bottom, _precision;
+ QSlider * _slider;
+ };
+
+ //================================================================================
+ /*!
+ * \brief Retrieve GEOM_Object held by widget
+ */
+ //================================================================================
+
+ inline GEOM::GEOM_Object_var geomFromWdg(const QWidget* wdg)
+ {
+ const StdMeshersGUI_ObjectReferenceParamWdg * objRefWdg =
+ dynamic_cast<const StdMeshersGUI_ObjectReferenceParamWdg*>( wdg );
+ if ( objRefWdg )
+ return objRefWdg->GetObject< GEOM::GEOM_Object >();
+
+ return GEOM::GEOM_Object::_nil();
+ }
+ //================================================================================
+ /*!
+ * \brief Retrieve SMESH_Mesh held by widget
+ */
+ //================================================================================
+
+ inline SMESH::SMESH_Mesh_var meshFromWdg(const QWidget* wdg)
+ {
+ const StdMeshersGUI_ObjectReferenceParamWdg * objRefWdg =
+ dynamic_cast<const StdMeshersGUI_ObjectReferenceParamWdg*>( wdg );
+ if ( objRefWdg )
+ return objRefWdg->GetObject< SMESH::SMESH_Mesh >();
+
+ return SMESH::SMESH_Mesh::_nil();
+ }
+ //================================================================================
+ /*!
+ * \brief Retrieve SMESH_Mesh held by widget
+ */
+ //================================================================================
+
+ inline SMESH::ListOfGroups_var groupsFromWdg(const QWidget* wdg)
+ {
+ SMESH::ListOfGroups_var groups = new SMESH::ListOfGroups;
+ const StdMeshersGUI_ObjectReferenceParamWdg * objRefWdg =
+ dynamic_cast<const StdMeshersGUI_ObjectReferenceParamWdg*>( wdg );
+ if ( objRefWdg )
+ {
+ groups->length( objRefWdg->NbObjects() );
+ for ( unsigned i = 0; i < groups->length(); ++i )
+ groups[i] = objRefWdg->GetObject< SMESH::SMESH_GroupBase >(i);
+ }
+ return groups;
+ }
+ //================================================================================
+ /*!
+ * \brief creates a filter for selection of shapes of given dimension
+ * \param dim - dimension
+ * \param subShapeType - required type of sub-shapes, number of which must be \a nbSubShapes
+ * \param nbSubShapes - number of sub-shapes of given type
+ * \param closed - required closeness flag of a shape
+ * \retval SUIT_SelectionFilter* - created filter
+ */
+ //================================================================================
+
+ SUIT_SelectionFilter* filterForShapeOfDim(const int dim,
+ TopAbs_ShapeEnum subShapeType = TopAbs_SHAPE,
+ const int nbSubShapes = 0,
+ bool closed = false)
+ {
+ TColStd_MapOfInteger shapeTypes;
+ switch ( dim ) {
+ case 0: shapeTypes.Add( TopAbs_VERTEX ); break;
+ case 1:
+ if ( subShapeType == TopAbs_SHAPE ) subShapeType = TopAbs_EDGE;
+ shapeTypes.Add( TopAbs_EDGE );
+ shapeTypes.Add( TopAbs_COMPOUND ); // for a group
+ break;
+ case 2:
+ if ( subShapeType == TopAbs_SHAPE ) subShapeType = TopAbs_FACE;
+ shapeTypes.Add( TopAbs_FACE );
+ shapeTypes.Add( TopAbs_COMPOUND ); // for a group
+ break;
+ case 3:
+ shapeTypes.Add( TopAbs_SHELL );
+ shapeTypes.Add( TopAbs_SOLID );
+ shapeTypes.Add( TopAbs_COMPSOLID );
+ shapeTypes.Add( TopAbs_COMPOUND );
+ break;
+ }
+ return new SMESH_NumberFilter("GEOM", subShapeType, nbSubShapes,
+ shapeTypes, GEOM::GEOM_Object::_nil(), closed);
+ }
+
+ //================================================================================
+ /*!
+ * \brief Create a widget for object selection
+ * \param object - initial object
+ * \param filter - selection filter
+ * \retval QWidget* - created widget
+ */
+ //================================================================================
+
+ QWidget* newObjRefParamWdg( SUIT_SelectionFilter* filter,
+ CORBA::Object_var object)
+ {
+ StdMeshersGUI_ObjectReferenceParamWdg* w =
+ new StdMeshersGUI_ObjectReferenceParamWdg( filter, 0);
+ w->SetObject( object.in() );
+ return w;
+ }
+ QWidget* newObjRefParamWdg( SUIT_SelectionFilter* filter,
+ SMESH::string_array_var& objEntries)
+ {
+ StdMeshersGUI_ObjectReferenceParamWdg* w =
+ new StdMeshersGUI_ObjectReferenceParamWdg( filter, 0, /*multiSel=*/true);
+ //RNV: Firstly, activate selection, then set objects
+ w->activateSelection();
+ w->SetObjects( objEntries );
+ return w;
+ }
+
+ //================================================================================
+ /*!
+ * \brief calls deactivateSelection() for StdMeshersGUI_ObjectReferenceParamWdg
+ * \param widgetList - list of widgets
+ */
+ //================================================================================
+
+ void deactivateObjRefParamWdg( QList<QWidget*>* widgetList )
+ {
+ StdMeshersGUI_ObjectReferenceParamWdg* w = 0;
+ QList<QWidget*>::iterator anIt = widgetList->begin();
+ QList<QWidget*>::iterator aLast = widgetList->end();
+ for ( ; anIt != aLast; anIt++ ) {
+ if ( (*anIt) && (*anIt)->inherits( "StdMeshersGUI_ObjectReferenceParamWdg" ))
+ {
+ w = (StdMeshersGUI_ObjectReferenceParamWdg* )( *anIt );
+ w->deactivateSelection();
+ }
+ }
+ }
+}
+
+//================================================================================
+/*!
+ * \brief Remove a group, whose name is stored by hypothesis, upon group name modification
+ * \param [in] oldName - old group name
+ * \param [in] newName - new group name
+ * \param [in] type - group type
+ */
+//================================================================================
+
+void StdMeshersGUI_StdHypothesisCreator::
+removeOldGroup(const char* oldName, const char* newName, SMESH::ElementType type) const
+{
+ if ( !oldName || !oldName[0] )
+ return; // old name undefined
+ if ( newName && strcmp( oldName, newName ) == 0 )
+ return; // same name
+
+ SMESH::SMESH_Hypothesis_var h = hypothesis();
+ SMESH::SObjectList listSOmesh = SMESH::GetMeshesUsingAlgoOrHypothesis( h );
+ for ( size_t i = 0; i < listSOmesh.size(); i++ )
+ {
+ _PTR(SObject) submSO = listSOmesh[i];
+ SMESH::SMESH_Mesh_var mesh = SMESH::SObjectToInterface<SMESH::SMESH_Mesh>( submSO );
+ SMESH::SMESH_subMesh_var subMesh = SMESH::SObjectToInterface<SMESH::SMESH_subMesh>( submSO );
+ if( !subMesh->_is_nil() )
+ mesh = subMesh->GetFather();
+ if ( mesh->_is_nil() )
+ continue;
+ SMESH::ListOfGroups_var groups = mesh->GetGroups();
+ for ( CORBA::ULong iG = 0; iG < groups->length(); iG++ )
+ {
+ if ( groups[iG]->GetType() != type )
+ continue;
+ CORBA::String_var name = groups[iG]->GetName();
+ if ( strcmp( name.in(), oldName ))
+ continue;
+ mesh->RemoveGroup( groups[iG] );
+ }
+ }
+}
+
+//================================================================================
+/*!
+ * \brief Check parameter values before accept()
+ * \retval bool - true if OK
+ */
+//================================================================================
+
+bool StdMeshersGUI_StdHypothesisCreator::checkParams( QString& msg ) const