X-Git-Url: http://git.salome-platform.org/gitweb/?p=modules%2Fsmesh.git;a=blobdiff_plain;f=src%2FSMESHGUI%2FSMESHGUI_AddSubMeshDlg.cxx;h=250323da7b5d71775e2f93a2af34f12572f0652d;hp=ea806f0abb780b219ab89a46ebd10a53b017da6c;hb=c9be7f0ec93cabbfbbe9d958a2756e2335ae2e5e;hpb=3973ceea250d2a077cdb5a798eb7c6151fa9c568 diff --git a/src/SMESHGUI/SMESHGUI_AddSubMeshDlg.cxx b/src/SMESHGUI/SMESHGUI_AddSubMeshDlg.cxx index ea806f0ab..250323da7 100644 --- a/src/SMESHGUI/SMESHGUI_AddSubMeshDlg.cxx +++ b/src/SMESHGUI/SMESHGUI_AddSubMeshDlg.cxx @@ -1,35 +1,77 @@ -using namespace std; -// File : SMESHGUI_AddSubMeshDlg.cxx -// Created : Mon May 27 10:20:11 2002 -// Author : Nicolas REJNERI - -// Project : SALOME -// Module : SMESH -// Copyright : Open CASCADE 2002 +// SMESH SMESHGUI : GUI for SMESH component +// +// Copyright (C) 2003 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, +// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org +// +// +// +// File : SMESHGUI_AddSubMeshDlg.cxx +// Author : Nicolas REJNERI +// Module : SMESH // $Header$ #include "SMESHGUI_AddSubMeshDlg.h" + #include "SMESHGUI.h" -#include "SALOME_ListIteratorOfListIO.hxx" +#include "SMESHGUI_Utils.h" +#include "SMESHGUI_GEOMGenUtils.h" +#include "SMESHGUI_HypothesesUtils.h" + +#include "GEOMBase.h" #include "QAD_Application.h" #include "QAD_Desktop.h" +#include "QAD_MessageBox.h" +#include "QAD_WaitCursor.h" +#include "QAD_Operation.h" + +#include "SALOME_ListIteratorOfListIO.hxx" +#include "SALOMEGUI_QtCatchCorbaException.hxx" + #include "utilities.h" // QT Includes -#include #include #include #include #include -#include #include -#include -#include -#include -#include #include +using namespace std; + +namespace SMESH{ + SMESH::SMESH_subMesh_var AddSubMesh(SMESH::SMESH_Mesh_ptr theMesh, + GEOM::GEOM_Object_ptr theShapeObject, + const char* theMeshName ) + { + SMESH::SMESH_subMesh_var aSubMesh; + try { + if ( !theMesh->_is_nil() && !theShapeObject->_is_nil() ) + aSubMesh = theMesh->GetSubMesh( theShapeObject, theMeshName ); + } + catch( const SALOME::SALOME_Exception& S_ex ) { + QtCatchCorbaException( S_ex ); + } + return aSubMesh._retn(); + } +} //================================================================================= // class : SMESHGUI_AddSubMeshDlg() @@ -39,149 +81,101 @@ using namespace std; // TRUE to construct a modal dialog. //================================================================================= SMESHGUI_AddSubMeshDlg::SMESHGUI_AddSubMeshDlg( QWidget* parent, const char* name, SALOME_Selection* Sel, bool modal, WFlags fl ) - : QDialog( parent, name, modal, WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu ) + : QDialog( parent, name, modal, WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu | WDestructiveClose ) { - QPixmap image1(QAD_Desktop::getResourceManager()->loadPixmap( "SMESHGUI",tr("ICON_DLG_ADD_SUBMESH"))); - QPixmap image0(QAD_Desktop::getResourceManager()->loadPixmap( "SMESHGUI",tr("ICON_SELECT"))); + QPixmap image0(QAD_Desktop::getResourceManager()->loadPixmap( "SMESH",tr("ICON_SELECT"))); if ( !name ) setName( "SMESHGUI_AddSubMeshDlg" ); - resize( 303, 175 ); setCaption( tr( "SMESH_ADD_SUBMESH" ) ); setSizeGripEnabled( TRUE ); - SMESHGUI_AddSubMeshDlgLayout = new QGridLayout( this ); + QGridLayout* SMESHGUI_AddSubMeshDlgLayout = new QGridLayout( this ); SMESHGUI_AddSubMeshDlgLayout->setSpacing( 6 ); SMESHGUI_AddSubMeshDlgLayout->setMargin( 11 ); /***************************************************************/ - GroupConstructors = new QButtonGroup( this, "GroupConstructors" ); - GroupConstructors->setTitle( tr( "SMESH_SUBMESH" ) ); - GroupConstructors->setExclusive( TRUE ); - GroupConstructors->setColumnLayout(0, Qt::Vertical ); - GroupConstructors->layout()->setSpacing( 0 ); - GroupConstructors->layout()->setMargin( 0 ); - GroupConstructorsLayout = new QGridLayout( GroupConstructors->layout() ); - GroupConstructorsLayout->setAlignment( Qt::AlignTop ); - GroupConstructorsLayout->setSpacing( 6 ); - GroupConstructorsLayout->setMargin( 11 ); - Constructor1 = new QRadioButton( GroupConstructors, "Constructor1" ); - Constructor1->setText( tr( "" ) ); - Constructor1->setPixmap( image1 ); - Constructor1->setChecked( TRUE ); - Constructor1->setSizePolicy( QSizePolicy( (QSizePolicy::SizeType)1, (QSizePolicy::SizeType)0, Constructor1->sizePolicy().hasHeightForWidth() ) ); - Constructor1->setMinimumSize( QSize( 50, 0 ) ); - GroupConstructorsLayout->addWidget( Constructor1, 0, 0 ); - QSpacerItem* spacer = new QSpacerItem( 20, 20, QSizePolicy::Expanding, QSizePolicy::Minimum ); - GroupConstructorsLayout->addItem( spacer, 0, 1 ); - SMESHGUI_AddSubMeshDlgLayout->addWidget( GroupConstructors, 0, 0 ); - - /***************************************************************/ - GroupButtons = new QGroupBox( this, "GroupButtons" ); - GroupButtons->setGeometry( QRect( 10, 10, 281, 48 ) ); - GroupButtons->setTitle( tr( "" ) ); - GroupButtons->setColumnLayout(0, Qt::Vertical ); - GroupButtons->layout()->setSpacing( 0 ); - GroupButtons->layout()->setMargin( 0 ); - GroupButtonsLayout = new QGridLayout( GroupButtons->layout() ); - GroupButtonsLayout->setAlignment( Qt::AlignTop ); - GroupButtonsLayout->setSpacing( 6 ); - GroupButtonsLayout->setMargin( 11 ); - buttonCancel = new QPushButton( GroupButtons, "buttonCancel" ); - buttonCancel->setText( tr( "SMESH_BUT_CLOSE" ) ); - buttonCancel->setAutoDefault( TRUE ); - GroupButtonsLayout->addWidget( buttonCancel, 0, 3 ); - buttonApply = new QPushButton( GroupButtons, "buttonApply" ); - buttonApply->setText( tr( "SMESH_BUT_APPLY" ) ); - buttonApply->setAutoDefault( TRUE ); - GroupButtonsLayout->addWidget( buttonApply, 0, 1 ); - QSpacerItem* spacer_9 = new QSpacerItem( 20, 20, QSizePolicy::Expanding, QSizePolicy::Minimum ); - GroupButtonsLayout->addItem( spacer_9, 0, 2 ); - buttonOk = new QPushButton( GroupButtons, "buttonOk" ); - buttonOk->setText( tr( "SMESH_BUT_OK" ) ); - buttonOk->setAutoDefault( TRUE ); - buttonOk->setDefault( TRUE ); - GroupButtonsLayout->addWidget( buttonOk, 0, 0 ); - SMESHGUI_AddSubMeshDlgLayout->addWidget( GroupButtons, 2, 0 ); - - /***************************************************************/ - GroupC1 = new QGroupBox( this, "GroupC1" ); - GroupC1->setTitle( tr( "SMESH_ARGUMENTS" ) ); - GroupC1->setMinimumSize( QSize( 0, 0 ) ); - GroupC1->setFrameShape( QGroupBox::Box ); - GroupC1->setFrameShadow( QGroupBox::Sunken ); + GroupC1 = new QGroupBox( tr( "SMESH_ARGUMENTS" ), this, "GroupC1" ); GroupC1->setColumnLayout(0, Qt::Vertical ); GroupC1->layout()->setSpacing( 0 ); GroupC1->layout()->setMargin( 0 ); - GroupC1Layout = new QGridLayout( GroupC1->layout() ); + QGridLayout* GroupC1Layout = new QGridLayout( GroupC1->layout() ); GroupC1Layout->setAlignment( Qt::AlignTop ); GroupC1Layout->setSpacing( 6 ); GroupC1Layout->setMargin( 11 ); - TextLabelC1A1 = new QLabel( GroupC1, "TextLabelC1A1" ); - TextLabelC1A1->setText( tr( "SMESH_OBJECT_MESH" ) ); - TextLabelC1A1->setMinimumSize( QSize( 50, 0 ) ); - TextLabelC1A1->setFrameShape( QLabel::NoFrame ); - TextLabelC1A1->setFrameShadow( QLabel::Plain ); - GroupC1Layout->addWidget( TextLabelC1A1, 0, 0 ); + TextLabel_NameMesh = new QLabel( tr( "SMESH_NAME" ), GroupC1, "TextLabel_NameMesh" ); + GroupC1Layout->addWidget( TextLabel_NameMesh, 0, 0 ); + LineEdit_NameMesh = new QLineEdit( GroupC1, "LineEdit_NameMesh" ); + GroupC1Layout->addWidget( LineEdit_NameMesh, 0, 2 ); + + TextLabelC1A1 = new QLabel( tr( "SMESH_OBJECT_MESH" ), GroupC1, "TextLabelC1A1" ); + GroupC1Layout->addWidget( TextLabelC1A1, 1, 0 ); SelectButtonC1A1 = new QPushButton( GroupC1, "SelectButtonC1A1" ); - SelectButtonC1A1->setText( tr( "" ) ); SelectButtonC1A1->setPixmap( image0 ); SelectButtonC1A1->setToggleButton( FALSE ); - GroupC1Layout->addWidget( SelectButtonC1A1, 0, 1 ); + GroupC1Layout->addWidget( SelectButtonC1A1, 1, 1 ); LineEditC1A1 = new QLineEdit( GroupC1, "LineEditC1A1" ); - GroupC1Layout->addWidget( LineEditC1A1, 0, 2 ); - - TextLabelC1A2 = new QLabel( GroupC1, "TextLabelC1A2" ); - TextLabelC1A2->setText( tr( "SMESH_OBJECT_GEOM" ) ); - TextLabelC1A2->setMinimumSize( QSize( 50, 0 ) ); - TextLabelC1A2->setFrameShape( QLabel::NoFrame ); - TextLabelC1A2->setFrameShadow( QLabel::Plain ); - GroupC1Layout->addWidget( TextLabelC1A2, 1, 0 ); + LineEditC1A1->setReadOnly( true ); + GroupC1Layout->addWidget( LineEditC1A1, 1, 2 ); + + TextLabelC1A2 = new QLabel( tr( "SMESH_OBJECT_GEOM" ), GroupC1, "TextLabelC1A2" ); + GroupC1Layout->addWidget( TextLabelC1A2, 2, 0 ); SelectButtonC1A2 = new QPushButton( GroupC1, "SelectButtonC1A2" ); - SelectButtonC1A2->setText( tr( "" ) ); SelectButtonC1A2->setPixmap( image0 ); SelectButtonC1A2->setToggleButton( FALSE ); - GroupC1Layout->addWidget( SelectButtonC1A2, 1, 1 ); + GroupC1Layout->addWidget( SelectButtonC1A2, 2, 1 ); LineEditC1A2 = new QLineEdit( GroupC1, "LineEditC1A2" ); - GroupC1Layout->addWidget( LineEditC1A2, 1, 2 ); - - TextLabel_NameMesh = new QLabel( GroupC1, "TextLabel_NameMesh" ); - TextLabel_NameMesh->setText( tr( "SMESH_NAME" ) ); - GroupC1Layout->addWidget( TextLabel_NameMesh, 2, 0 ); - LineEdit_NameMesh = new QLineEdit( GroupC1, "LineEdit_NameMesh" ); - GroupC1Layout->addWidget( LineEdit_NameMesh, 2, 2 ); + LineEditC1A2->setReadOnly( true ); + GroupC1Layout->addWidget( LineEditC1A2, 2, 2 ); - TextLabelC1A1Hyp = new QLabel( GroupC1, "TextLabelC1A1Hyp" ); - TextLabelC1A1Hyp->setText( tr( "SMESH_OBJECT_HYPOTHESIS" ) ); - TextLabelC1A1Hyp->setMinimumSize( QSize( 50, 0 ) ); - TextLabelC1A1Hyp->setFrameShape( QLabel::NoFrame ); - TextLabelC1A1Hyp->setFrameShadow( QLabel::Plain ); + TextLabelC1A1Hyp = new QLabel( tr( "SMESH_OBJECT_HYPOTHESIS" ), GroupC1, "TextLabelC1A1Hyp" ); GroupC1Layout->addWidget( TextLabelC1A1Hyp, 3, 0 ); SelectButtonC1A1Hyp = new QPushButton( GroupC1, "SelectButtonC1A1Hyp" ); - SelectButtonC1A1Hyp->setText( tr( "" ) ); SelectButtonC1A1Hyp->setPixmap( image0 ); GroupC1Layout->addWidget( SelectButtonC1A1Hyp, 3, 1 ); LineEditC1A1Hyp = new QLineEdit( GroupC1, "LineEditC1A1Hyp" ); - LineEditC1A1Hyp->setSizePolicy( QSizePolicy( (QSizePolicy::SizeType)3, (QSizePolicy::SizeType)0, LineEditC1A1Hyp->sizePolicy().hasHeightForWidth() ) ); + LineEditC1A1Hyp->setReadOnly( true ); GroupC1Layout->addWidget( LineEditC1A1Hyp, 3, 2 ); - TextLabelC1A1Algo = new QLabel( GroupC1, "TextLabelC1A1Algo" ); - TextLabelC1A1Algo->setText( tr( "SMESH_OBJECT_ALGORITHM" ) ); - TextLabelC1A1Algo->setMinimumSize( QSize( 50, 0 ) ); - TextLabelC1A1Algo->setFrameShape( QLabel::NoFrame ); - TextLabelC1A1Algo->setFrameShadow( QLabel::Plain ); + TextLabelC1A1Algo = new QLabel( tr( "SMESH_OBJECT_ALGORITHM" ), GroupC1, "TextLabelC1A1Algo" ); GroupC1Layout->addWidget( TextLabelC1A1Algo, 4, 0 ); SelectButtonC1A1Algo = new QPushButton( GroupC1, "SelectButtonC1A1Algo" ); - SelectButtonC1A1Algo->setText( tr( "" ) ); SelectButtonC1A1Algo->setPixmap( image0 ); GroupC1Layout->addWidget( SelectButtonC1A1Algo, 4, 1 ); LineEditC1A1Algo = new QLineEdit( GroupC1, "LineEditC1A1Algo" ); - LineEditC1A1Algo->setSizePolicy( QSizePolicy( (QSizePolicy::SizeType)3, (QSizePolicy::SizeType)0, LineEditC1A1Algo->sizePolicy().hasHeightForWidth() ) ); + LineEditC1A1Algo->setReadOnly( true ); GroupC1Layout->addWidget( LineEditC1A1Algo, 4, 2 ); SMESHGUI_AddSubMeshDlgLayout->addWidget( GroupC1, 1, 0 ); + /***************************************************************/ + GroupButtons = new QGroupBox( this, "GroupButtons" ); + GroupButtons->setColumnLayout(0, Qt::Vertical ); + GroupButtons->layout()->setSpacing( 0 ); + GroupButtons->layout()->setMargin( 0 ); + QGridLayout* GroupButtonsLayout = new QGridLayout( GroupButtons->layout() ); + GroupButtonsLayout->setAlignment( Qt::AlignTop ); + GroupButtonsLayout->setSpacing( 6 ); + GroupButtonsLayout->setMargin( 11 ); + + buttonOk = new QPushButton( tr( "SMESH_BUT_OK" ), GroupButtons, "buttonOk" ); + buttonOk->setAutoDefault( TRUE ); + buttonOk->setDefault( TRUE ); + GroupButtonsLayout->addWidget( buttonOk, 0, 0 ); + + buttonApply = new QPushButton( tr( "SMESH_BUT_APPLY" ), GroupButtons, "buttonApply" ); + buttonApply->setAutoDefault( TRUE ); + GroupButtonsLayout->addWidget( buttonApply, 0, 1 ); - Init(Sel) ; + GroupButtonsLayout->addItem( new QSpacerItem( 20, 20, QSizePolicy::Expanding, QSizePolicy::Minimum ), 0, 2 ); + + buttonCancel = new QPushButton( tr( "SMESH_BUT_CLOSE" ), GroupButtons, "buttonCancel" ); + buttonCancel->setAutoDefault( TRUE ); + GroupButtonsLayout->addWidget( buttonCancel, 0, 3 ); + + SMESHGUI_AddSubMeshDlgLayout->addWidget( GroupButtons, 2, 0 ); + + /***************************************************************/ + Init( Sel ) ; } @@ -201,60 +195,41 @@ SMESHGUI_AddSubMeshDlg::~SMESHGUI_AddSubMeshDlg() //================================================================================= void SMESHGUI_AddSubMeshDlg::Init( SALOME_Selection* Sel ) { - GroupC1->show(); - myConstructorId = 0 ; - Constructor1->setChecked( TRUE ); - myEditCurrentArgument = LineEditC1A1 ; mySelection = Sel; mySMESHGUI = SMESHGUI::GetSMESHGUI() ; mySMESHGUI->SetActiveDialogBox( (QDialog*)this ) ; - myGeomFilter = new SALOME_TypeFilter( "GEOM" ); - myMeshFilter = new SMESH_TypeFilter( MESH ); - - myAlgorithmFilter = new SMESH_TypeFilter( ALGORITHM ); + myGeomFilter = new SALOME_TypeFilter( "GEOM" ); + myMeshFilter = new SMESH_TypeFilter( MESH ); + myAlgorithmFilter = new SMESH_TypeFilter( ALGORITHM ); myHypothesisFilter = new SMESH_TypeFilter( HYPOTHESIS ); - myNameSubMesh = "SubMesh"; - - myGeomShape = GEOM::GEOM_Shape::_nil(); - myMesh = SMESH::SMESH_Mesh::_nil(); - /* signals and slots connections */ - connect( buttonOk, SIGNAL( clicked() ), this, SLOT( ClickOnOk() ) ); - connect( buttonApply, SIGNAL( clicked() ), this, SLOT(ClickOnApply() ) ); + connect( buttonOk, SIGNAL( clicked() ), this, SLOT( ClickOnOk() ) ); + connect( buttonApply, SIGNAL( clicked() ), this, SLOT( ClickOnApply() ) ); connect( buttonCancel, SIGNAL( clicked() ), this, SLOT( ClickOnCancel() ) ) ; - connect( GroupConstructors, SIGNAL(clicked(int) ), SLOT( ConstructorsClicked(int) ) ); - connect( SelectButtonC1A1, SIGNAL (clicked() ), this, SLOT( SetEditCurrentArgument() ) ) ; - connect( SelectButtonC1A2, SIGNAL (clicked() ), this, SLOT( SetEditCurrentArgument() ) ) ; - connect( LineEdit_NameMesh, SIGNAL (textChanged(const QString&) ), this, SLOT( TextChangedInLineEdit(const QString&) ) ) ; - - connect( SelectButtonC1A1Hyp, SIGNAL (clicked() ), this, SLOT( SetEditCurrentArgument() ) ) ; + connect( SelectButtonC1A1, SIGNAL (clicked() ), this, SLOT( SetEditCurrentArgument() ) ) ; + connect( SelectButtonC1A2, 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() ) ) ; + 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() ; - SelectionIntoArgument(); - - return ; -} - + LineEdit_NameMesh->setText( tr( "SMESH_SUBMESH" ) ); + LineEdit_NameMesh->setFocus() ; + myEditCurrentArgument = LineEditC1A1 ; + mySelection->ClearFilters() ; + mySelection->AddFilter( myMeshFilter ) ; -//================================================================================= -// function : ConstructorsClicked() -// purpose : Radio button management -//================================================================================= -void SMESHGUI_AddSubMeshDlg::ConstructorsClicked(int constructorId) -{ - return ; + SelectionIntoArgument(); } //================================================================================= @@ -263,50 +238,75 @@ void SMESHGUI_AddSubMeshDlg::ConstructorsClicked(int constructorId) //================================================================================= void SMESHGUI_AddSubMeshDlg::ClickOnOk() { - this->ClickOnApply() ; - this->ClickOnCancel() ; + if ( this->ClickOnApply() ) + this->ClickOnCancel() ; } //================================================================================= // function : ClickOnApply() // purpose : //================================================================================= -void SMESHGUI_AddSubMeshDlg::ClickOnApply() +bool SMESHGUI_AddSubMeshDlg::ClickOnApply() { - switch(myConstructorId) - { - case 0 : - { - if ( !myNameSubMesh.isEmpty() && !myNameSubMesh.isNull() && - !myGeomShape->_is_nil() && !myMesh->_is_nil()) { - mySubMesh = mySMESHGUI->AddSubMesh( myMesh, myGeomShape, myNameSubMesh ) ; - } - - if( myOkHypothesis && !mySubMesh->_is_nil() ) { - SALOME_ListIteratorOfListIO It( HypoList ); - for(;It.More();It.Next()) { - Handle(SALOME_InteractiveObject) IObject = It.Value(); - Standard_Boolean testResult; - myHypothesis = mySMESHGUI->ConvertIOinSMESHHypothesis(IObject, testResult) ; - if( testResult ) - mySMESHGUI->AddHypothesisOnSubMesh(mySubMesh, myHypothesis) ; - } - } + if (mySMESHGUI->ActiveStudyLocked()) + return false; + + QString myNameSubMesh = LineEdit_NameMesh->text().stripWhiteSpace(); + if ( myNameSubMesh.isEmpty() ) { + QAD_MessageBox::warn1( this, tr( "SMESH_WRN_WARNING" ), tr( "SMESH_WRN_EMPTY_NAME" ), tr( "SMESH_BUT_OK" ) ); + return false; + } + + if ( myMesh->_is_nil() || myGeomShape->_is_nil() || ( !HypoList.count() && !AlgoList.count() ) ) + return false; - if( myOkAlgorithm && !mySubMesh->_is_nil() ) { - SALOME_ListIteratorOfListIO It( AlgoList ); - for(;It.More();It.Next()) { - Handle(SALOME_InteractiveObject) IObject = It.Value(); - Standard_Boolean testResult; - myAlgorithm = mySMESHGUI->ConvertIOinSMESHHypothesis(IObject, testResult) ; - if( testResult ) - mySMESHGUI->AddAlgorithmOnSubMesh(mySubMesh, myAlgorithm) ; - } + SALOMEDS::SObject_var aMeshSO = SMESH::FindSObject( myMesh ); + GEOM::GEOM_Object_var myMainShape = SMESH::GetShapeOnMeshOrSubMesh( aMeshSO ); + if ( myMainShape->_is_nil() ) + return false; + + QAD_WaitCursor wc; + + QAD_Operation* op = new QAD_Operation( mySMESHGUI->GetActiveStudy() ); + + // start transaction + op->start(); + + // create submesh + SMESH::SMESH_subMesh_var aSubMesh = SMESH::AddSubMesh( myMesh, myGeomShape, myNameSubMesh ) ; + int nbSuccess = 0; + + if ( !aSubMesh->_is_nil() ) { + // assign hypotheses + int nbAlgo = AlgoList.count(); + int nbHyps = HypoList.count() + nbAlgo; + for( int i = 0; i < nbHyps; i++ ) { + SALOMEDS::SObject_var aHypSO = SMESH::GetActiveStudyDocument()->FindObjectID + ( i < nbAlgo ? AlgoList[i] : HypoList[i-nbAlgo] ); + 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::AddHypothesisOnSubMesh( aSubMesh, aHyp ) ) + nbSuccess++; } - - break ; + else { + SCRUTE( CORBA::is_nil( anObject )); + } + } + else { + SCRUTE( aHypSO->_is_nil() ); } } + } + else { + SCRUTE( aSubMesh->_is_nil() ); + } + + // commit transaction + op->finish(); + return ( nbSuccess > 0 ); } @@ -316,13 +316,25 @@ void SMESHGUI_AddSubMeshDlg::ClickOnApply() //================================================================================= void SMESHGUI_AddSubMeshDlg::ClickOnCancel() { - disconnect( mySelection, 0, this, 0 ); - mySMESHGUI->ResetState() ; - mySelection->ClearFilters() ; - reject() ; - return ; + close(); } +//======================================================================= +//function : IsFatherOf +//purpose : +//======================================================================= + +static bool IsFatherOf( SALOMEDS::SObject_ptr SO, SALOMEDS::SObject_ptr fatherSO ) { + if ( !SO->_is_nil() && !fatherSO->_is_nil() ) { + SALOMEDS::SObject_var aSO = SO->GetFather(); + while( strlen( aSO->GetID() ) >= strlen( fatherSO->GetID() ) ) { + if ( QString( aSO->GetID() ) == QString( fatherSO->GetID() ) ) + return true; + aSO = aSO->GetFather(); + } + } + return false; +} //================================================================================= // function : SelectionIntoArgument() @@ -330,81 +342,84 @@ void SMESHGUI_AddSubMeshDlg::ClickOnCancel() //================================================================================= void SMESHGUI_AddSubMeshDlg::SelectionIntoArgument() { - myEditCurrentArgument->setText("") ; QString aString = ""; - - int nbSel = mySMESHGUI->GetNameOfSelectedIObjects(mySelection, aString) ; - - switch (myConstructorId) - { - case 0: + int nbSel = SMESH::GetNameOfSelectedIObjects(mySelection, aString) ; + + if ( myEditCurrentArgument == LineEditC1A1 ) { + // mesh + if ( nbSel != 1 ) { + myMesh = SMESH::SMESH_Mesh::_nil(); + aString = ""; + } + else { + Handle(SALOME_InteractiveObject) IO = mySelection->firstIObject() ; + myMesh = SMESH::IObjectToInterface(IO) ; + if( myMesh->_is_nil() ) { + aString = ""; + } + } + myGeomShape = GEOM::GEOM_Object::_nil(); + LineEditC1A2->setText( "" ); + } + else if ( myEditCurrentArgument == LineEditC1A2 ) { + // geom shape + if ( nbSel != 1 ) { + myGeomShape = GEOM::GEOM_Object::_nil(); + aString = ""; + } + else { + Handle(SALOME_InteractiveObject) IO = mySelection->firstIObject() ; + myGeomShape = SMESH::IObjectToInterface(IO) ; + if( myGeomShape->_is_nil() || !GEOMBase::IsShape( myGeomShape ) ) { - if ( myEditCurrentArgument == LineEditC1A1 ) { - if ( nbSel != 1 ) { - myOkHypothesis = false; - myOkAlgorithm = false; - return ; - } else { - Standard_Boolean testResult ; - Handle(SALOME_InteractiveObject) IO = mySelection->firstIObject() ; - myMesh = mySMESHGUI->ConvertIOinMesh(IO, testResult) ; - if( !testResult ) { - myMesh = SMESH::SMESH_Mesh::_nil(); - return ; - } - } - } else if ( myEditCurrentArgument == LineEditC1A2 ) { - if ( nbSel != 1 ) { - myOkHypothesis = false; - myOkAlgorithm = false; - return ; - } else { - Standard_Boolean testResult ; - Handle(SALOME_InteractiveObject) IO = mySelection->firstIObject() ; - myGeomShape = mySMESHGUI->ConvertIOinGEOMShape(IO, testResult) ; - if( !testResult ) { - myGeomShape = GEOM::GEOM_Shape::_nil(); - return ; - } - } - } else if ( myEditCurrentArgument == LineEditC1A1Hyp ) { - if ( nbSel >= 1 ) { - HypoList.Clear(); - SALOME_ListIteratorOfListIO Itinit( mySelection->StoredIObjects() ); - for (; Itinit.More(); Itinit.Next()) { - HypoList.Append(Itinit.Value()); - } - myOkHypothesis = true ; - if (nbSel > 1) - aString = tr("%1 Hypothesis").arg(nbSel) ; - LineEditC1A1Hyp->setText(aString) ; - } - else { - myOkHypothesis = false ; - return ; - } - } else if ( myEditCurrentArgument == LineEditC1A1Algo ) { - if ( nbSel >= 1 ) { - AlgoList.Clear(); - SALOME_ListIteratorOfListIO Itinit( mySelection->StoredIObjects() ); - for (; Itinit.More(); Itinit.Next()) { - AlgoList.Append(Itinit.Value()); - } - myOkAlgorithm = true ; - if (nbSel > 1) - aString = tr("%1 Algorithms").arg(nbSel) ; - LineEditC1A1Algo->setText(aString) ; - } - else { - myOkAlgorithm = false ; - return ; - } - } - break; + myGeomShape = GEOM::GEOM_Object::_nil(); + aString = ""; + } + if ( !myMesh->_is_nil() ) { + SALOMEDS::SObject_var aMeshSO = SMESH::FindSObject( myMesh ); + GEOM::GEOM_Object_var aMainGeomShape = SMESH::GetShapeOnMeshOrSubMesh( aMeshSO ); + SALOMEDS::SObject_var aMainGeomShapeSO = SMESH::FindSObject( aMainGeomShape ); + if ( aMainGeomShapeSO->_is_nil() || !IsFatherOf( SMESH::GetActiveStudyDocument()->FindObjectID( IO->getEntry() ), aMainGeomShapeSO ) ) { + 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(); } @@ -415,36 +430,28 @@ void SMESHGUI_AddSubMeshDlg::SelectionIntoArgument() void SMESHGUI_AddSubMeshDlg::SetEditCurrentArgument() { QPushButton* send = (QPushButton*)sender(); - switch (myConstructorId) - { - case 0: /* default constructor */ - { - if(send == SelectButtonC1A1) { - LineEditC1A1->setFocus() ; - myEditCurrentArgument = LineEditC1A1; - mySelection->ClearFilters() ; - mySelection->AddFilter(myMeshFilter) ; - } else if (send == SelectButtonC1A2) { - LineEditC1A2->setFocus() ; - myEditCurrentArgument = LineEditC1A2; - 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() ; - break; - } - } - return ; + if(send == SelectButtonC1A1) { + LineEditC1A1->setFocus() ; + myEditCurrentArgument = LineEditC1A1; + mySelection->ClearFilters() ; + mySelection->AddFilter(myMeshFilter) ; + } else if (send == SelectButtonC1A2) { + LineEditC1A2->setFocus() ; + myEditCurrentArgument = LineEditC1A2; + 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() ; } //================================================================================= @@ -453,9 +460,8 @@ void SMESHGUI_AddSubMeshDlg::SetEditCurrentArgument() //================================================================================= void SMESHGUI_AddSubMeshDlg::DeactivateActiveDialog() { - if ( GroupConstructors->isEnabled() ) { + if ( GroupC1->isEnabled() ) { disconnect( mySelection, 0, this, 0 ); - GroupConstructors->setEnabled(false) ; GroupC1->setEnabled(false) ; GroupButtons->setEnabled(false) ; } @@ -469,11 +475,9 @@ void SMESHGUI_AddSubMeshDlg::DeactivateActiveDialog() void SMESHGUI_AddSubMeshDlg::ActivateThisDialog() { mySMESHGUI->EmitSignalDeactivateDialog() ; - GroupConstructors->setEnabled(true) ; GroupC1->setEnabled(true) ; GroupButtons->setEnabled(true) ; connect ( mySelection, SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) ); - return ; } @@ -483,10 +487,8 @@ void SMESHGUI_AddSubMeshDlg::ActivateThisDialog() //================================================================================= void SMESHGUI_AddSubMeshDlg::enterEvent(QEvent* e) { - if ( GroupConstructors->isEnabled() ) - return ; - ActivateThisDialog() ; - return ; + if ( !GroupC1->isEnabled() ) + ActivateThisDialog() ; } @@ -496,21 +498,26 @@ void SMESHGUI_AddSubMeshDlg::enterEvent(QEvent* e) //================================================================================= void SMESHGUI_AddSubMeshDlg::closeEvent( QCloseEvent* e ) { - this->ClickOnCancel() ; - return ; + disconnect( mySelection, 0, this, 0 ); + mySMESHGUI->ResetState() ; + mySelection->ClearFilters() ; + QDialog::closeEvent( e ); } //================================================================================= -// function : TextChangedInLineEdit() +// function : UpdateControlState() // purpose : //================================================================================= -void SMESHGUI_AddSubMeshDlg::TextChangedInLineEdit(const QString& newText) -{ - QLineEdit* send = (QLineEdit*)sender(); - QString newT = strdup(newText) ; - - if (send == LineEdit_NameMesh) { - myNameSubMesh = newText; +void SMESHGUI_AddSubMeshDlg::UpdateControlState() +{ + bool isEnabled = ( !myMesh->_is_nil() && !myGeomShape->_is_nil() && ( HypoList.count() || AlgoList.count() ) ); + bool isImportedMesh = false; + if ( !myMesh->_is_nil() ) { + SALOMEDS::SObject_var aMeshSO = SMESH::FindSObject( myMesh ); + GEOM::GEOM_Object_var myGeomShape = SMESH::GetShapeOnMeshOrSubMesh( aMeshSO ); + isImportedMesh = myGeomShape->_is_nil(); } - return ; + + buttonOk ->setEnabled( isEnabled && !isImportedMesh ); + buttonApply->setEnabled( isEnabled && !isImportedMesh ); }