- // no need to delete child widgets, Qt does it all for us
-}
-
-
-//=================================================================================
-// function : Init()
-// purpose :
-//=================================================================================
-void SMESHGUI_InitMeshDlg::Init( SALOME_Selection* Sel )
-{
- mySelection = Sel;
- mySMESHGUI = SMESHGUI::GetSMESHGUI() ;
- mySMESHGUI->SetActiveDialogBox( (QDialog*)this ) ;
-
- myGeomFilter = new SALOME_TypeFilter( "GEOM" );
- myAlgorithmFilter = new SMESH_TypeFilter( ALGORITHM );
- myHypothesisFilter = new SMESH_TypeFilter( HYPOTHESIS );
-
- /* signals and slots connections */
- connect( buttonOk, SIGNAL( clicked() ), this, SLOT( ClickOnOk() ) );
- connect( buttonApply, SIGNAL( clicked() ), this, SLOT( ClickOnApply() ) );
- connect( buttonCancel, SIGNAL( clicked() ), this, SLOT( ClickOnCancel() ) ) ;
-
- connect( SelectButtonC1A1, SIGNAL (clicked() ), this, SLOT( SetEditCurrentArgument() ) ) ;
- connect( SelectButtonC1A1Hyp, SIGNAL (clicked() ), this, SLOT( SetEditCurrentArgument() ) ) ;
- connect( SelectButtonC1A1Algo, SIGNAL (clicked() ), this, SLOT( SetEditCurrentArgument() ) ) ;
-
- connect( mySelection, SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
- connect( mySMESHGUI, SIGNAL( SignalDeactivateActiveDialog() ), this, SLOT( DeactivateActiveDialog() ) ) ;
- connect( mySMESHGUI, SIGNAL( SignalCloseAllDialogs() ), this, SLOT( ClickOnCancel() ) ) ;
-
- int x, y ;
- mySMESHGUI->DefineDlgPosition( this, x, y ) ;
- this->move( x, y ) ;
- this->show() ;
-
- LineEdit_NameMesh->setText( GetDefaultMeshName() );
- LineEdit_NameMesh->setFocus() ;
- myEditCurrentArgument = LineEditC1A1 ;
- mySelection->ClearFilters() ;
- mySelection->AddFilter( myGeomFilter ) ;
-
- SelectionIntoArgument();
-
- UpdateControlState();
-}
-
-
-//=================================================================================
-// function : ClickOnOk()
-// purpose :
-//=================================================================================
-void SMESHGUI_InitMeshDlg::ClickOnOk()
-{
- if ( this->ClickOnApply() )
- this->ClickOnCancel() ;
-}
-
-//=================================================================================
-// function : ClickOnApply()
-// purpose :
-//=================================================================================
-bool SMESHGUI_InitMeshDlg::ClickOnApply()
-{
- if (mySMESHGUI->ActiveStudyLocked())
- return false;
-
- QString myNameMesh = LineEdit_NameMesh->text().stripWhiteSpace();
- if ( myNameMesh.isEmpty() ) {
- QAD_MessageBox::warn1( this, tr( "SMESH_WRN_WARNING" ), tr( "SMESH_WRN_EMPTY_NAME" ), tr( "SMESH_BUT_OK" ) );
- return false;
- }
-
- if ( myGeomShape->_is_nil() || !HypoList.count() || !AlgoList.count() )
- return false;
-
- QAD_WaitCursor wc;
-
- QAD_Operation* op = new QAD_Operation( mySMESHGUI->GetActiveStudy() );
-
- // start transaction
- op->start();
-
- // create mesh
- SMESH::SMESH_Mesh_var aMesh = SMESH::InitMesh( myGeomShape, myNameMesh ) ;
-
- if ( !aMesh->_is_nil() ) {
- // assign hypotheses
- for( int i = 0; i < HypoList.count(); i++ ) {
- SALOMEDS::SObject_var aHypSO = SMESH::GetActiveStudyDocument()->FindObjectID( HypoList[i] );
- if ( !aHypSO->_is_nil() ) {
- CORBA::Object_var anObject = aHypSO->GetObject();
- if ( !CORBA::is_nil( anObject ) ) {
- SMESH::SMESH_Hypothesis_var aHyp = SMESH::SMESH_Hypothesis::_narrow( anObject );
- if ( !aHyp->_is_nil() ) {
- if ( !SMESH::AddHypothesisOnMesh( aMesh, aHyp ) ) {
- // abort transaction
- op->abort();
- return false;
- }
- }
- }
- }
- }
- // assign algorithms
- for( int i = 0; i < AlgoList.count(); i++ ) {
- SALOMEDS::SObject_var aHypSO = SMESH::GetActiveStudyDocument()->FindObjectID( AlgoList[i] );
- if ( !aHypSO->_is_nil() ) {
- CORBA::Object_var anObject = aHypSO->GetObject();
- if ( !CORBA::is_nil( anObject ) ) {
- SMESH::SMESH_Hypothesis_var aHyp = SMESH::SMESH_Hypothesis::_narrow( anObject );
- if ( !aHyp->_is_nil() ) {
- if ( !SMESH::AddHypothesisOnMesh( aMesh, aHyp ) ) {
- // abort transaction
- op->abort();
- return false;
- }
- }
- }
- }
- }
- }
- // commit transaction
- op->finish();
- LineEdit_NameMesh->setText( GetDefaultMeshName() );
- return true;
-}
-
-
-//=================================================================================
-// function : ClickOnCancel()
-// purpose :
-//=================================================================================
-void SMESHGUI_InitMeshDlg::ClickOnCancel()
-{
- close();
-}
-
-
-//=================================================================================
-// function : SelectionIntoArgument()
-// purpose : Called when selection as changed or other case
-//=================================================================================
-void SMESHGUI_InitMeshDlg::SelectionIntoArgument()
-{
- QString aString = "";
-
- int nbSel = SMESH::GetNameOfSelectedIObjects( mySelection, aString );
-
- if ( myEditCurrentArgument == LineEditC1A1 )
- {
- // geom shape
- if ( nbSel != 1 )
- {
- myGeomShape = GEOM::GEOM_Object::_nil();
- aString = "";
- }
- else
- {
- Handle(SALOME_InteractiveObject) IO = mySelection->firstIObject() ;
- myGeomShape = SMESH::IObjectToInterface<GEOM::GEOM_Object>( IO ) ;
- if ( myGeomShape->_is_nil() || !GEOMBase::IsShape( myGeomShape ) )
- {
- myGeomShape = GEOM::GEOM_Object::_nil();
- aString = "";
- }
- }
- }
- else if ( myEditCurrentArgument == LineEditC1A1Hyp ) {
- // hypotheses
- HypoList.clear();
- if ( nbSel >= 1 ) {
- SALOME_ListIteratorOfListIO Itinit( mySelection->StoredIObjects() );
- for ( ; Itinit.More(); Itinit.Next() ) {
- HypoList.append( Itinit.Value()->getEntry() );
- }
- if ( nbSel > 1 )
- aString = tr( "%1 Hypothesis" ).arg( nbSel ) ;
- }
- else {
- aString = "";
- }
- }
- else if ( myEditCurrentArgument == LineEditC1A1Algo ) {
- // algorithms
- AlgoList.clear();
- if ( nbSel >= 1 ) {
- SALOME_ListIteratorOfListIO Itinit( mySelection->StoredIObjects() );
- for ( ; Itinit.More(); Itinit.Next() ) {
- AlgoList.append( Itinit.Value()->getEntry() );
- }
- if ( nbSel > 1 )
- aString = tr( "%1 Algorithms" ).arg( nbSel ) ;
- }
- else {
- aString = "";
- }
- }
-
- myEditCurrentArgument->setText(aString) ;
-
- UpdateControlState();
-}
-
-
-//=================================================================================
-// function : SetEditCurrentArgument()
-// purpose :
-//=================================================================================
-void SMESHGUI_InitMeshDlg::SetEditCurrentArgument()
-{
- QPushButton* send = (QPushButton*)sender();
- if(send == SelectButtonC1A1) {
- LineEditC1A1->setFocus() ;
- myEditCurrentArgument = LineEditC1A1;
- mySelection->ClearFilters() ;
- mySelection->AddFilter(myGeomFilter) ;
- } else if( send == SelectButtonC1A1Hyp ) {
- LineEditC1A1Hyp->setFocus() ;
- myEditCurrentArgument = LineEditC1A1Hyp ;
- mySelection->ClearFilters() ;
- mySelection->AddFilter(myHypothesisFilter) ;
- } else if( send == SelectButtonC1A1Algo ) {
- LineEditC1A1Algo->setFocus() ;
- myEditCurrentArgument = LineEditC1A1Algo ;
- mySelection->ClearFilters() ;
- mySelection->AddFilter(myAlgorithmFilter) ;
- }
- SelectionIntoArgument() ;
-}
-
-//=================================================================================
-// function : DeactivateActiveDialog()
-// purpose :
-//=================================================================================
-void SMESHGUI_InitMeshDlg::DeactivateActiveDialog()
-{
- if ( GroupC1->isEnabled() ) {
- disconnect( mySelection, 0, this, 0 );
- GroupC1->setEnabled(false) ;
- GroupButtons->setEnabled(false) ;
- }