From 4e65ec6527cf1fe07243bac642a083a01b08f2b0 Mon Sep 17 00:00:00 2001 From: asl Date: Thu, 7 Jul 2005 09:01:32 +0000 Subject: [PATCH] new operation for SMESHGUI_InitMeshDlg --- src/SMESHGUI/Makefile.in | 2 + src/SMESHGUI/SMESHGUI.cxx | 19 +- src/SMESHGUI/SMESHGUI.h | 1 + src/SMESHGUI/SMESHGUI_InitMeshDlg.cxx | 464 +++----------------------- src/SMESHGUI/SMESHGUI_InitMeshDlg.h | 90 +---- src/SMESHGUI/SMESHGUI_InitMeshOp.cxx | 297 +++++++++++++++++ src/SMESHGUI/SMESHGUI_InitMeshOp.h | 74 ++++ 7 files changed, 443 insertions(+), 504 deletions(-) create mode 100644 src/SMESHGUI/SMESHGUI_InitMeshOp.cxx create mode 100644 src/SMESHGUI/SMESHGUI_InitMeshOp.h diff --git a/src/SMESHGUI/Makefile.in b/src/SMESHGUI/Makefile.in index 6b0f10e38..960180788 100644 --- a/src/SMESHGUI/Makefile.in +++ b/src/SMESHGUI/Makefile.in @@ -60,6 +60,7 @@ LIB_SRC = SMESHGUI.cxx \ SMESHGUI_SpinBox.cxx \ SMESHGUI_NodesDlg.cxx \ SMESHGUI_InitMeshDlg.cxx \ + SMESHGUI_InitMeshOp.cxx \ SMESHGUI_AddSubMeshDlg.cxx \ SMESHGUI_TransparencyDlg.cxx \ SMESHGUI_ClippingDlg.cxx \ @@ -118,6 +119,7 @@ LIB_MOC = \ SMESHGUI_NodesDlg.h \ SMESHGUI_SpinBox.h \ SMESHGUI_InitMeshDlg.h \ + SMESHGUI_InitMeshOp.h \ SMESHGUI_AddSubMeshDlg.h \ SMESHGUI_TransparencyDlg.h \ SMESHGUI_ClippingDlg.h \ diff --git a/src/SMESHGUI/SMESHGUI.cxx b/src/SMESHGUI/SMESHGUI.cxx index b2e72a8ad..dba718184 100644 --- a/src/SMESHGUI/SMESHGUI.cxx +++ b/src/SMESHGUI/SMESHGUI.cxx @@ -25,7 +25,7 @@ // $Header$ #include "SMESHGUI.h" -#include "SMESHGUI_InitMeshDlg.h" +#include "SMESHGUI_InitMeshOp.h" #include "SMESHGUI_AddSubMeshDlg.h" #include "SMESHGUI_NodesDlg.h" #include "SMESHGUI_TransparencyDlg.h" @@ -1384,8 +1384,9 @@ bool SMESHGUI::OnGUIEvent( int theCommandID ) case 703: // INIT MESH { if(checkLock(aStudy)) break; - EmitSignalDeactivateDialog(); - new SMESHGUI_InitMeshDlg( this ); + //EmitSignalDeactivateDialog(); + //new SMESHGUI_InitMeshDlg( this ); + startOperation( 703 ); break; } @@ -3299,7 +3300,17 @@ void SMESHGUI::updateControls() // to do } - +//======================================================================= +// function : updateControls +// purpose : Update state of controls +//======================================================================= +SalomeApp_Operation* SMESHGUI::createOperation( const int id ) const +{ + if( id==703 ) + return new SMESHGUI_InitMeshOp(); + else + return SalomeApp_Module::createOperation( id ); +} diff --git a/src/SMESHGUI/SMESHGUI.h b/src/SMESHGUI/SMESHGUI.h index eb04e5d74..eaf77cdb6 100644 --- a/src/SMESHGUI/SMESHGUI.h +++ b/src/SMESHGUI/SMESHGUI.h @@ -123,6 +123,7 @@ signals: void SignalCloseAllDialogs(); protected: + virtual SalomeApp_Operation* createOperation( const int ) const; void createSMESHAction( const int, const QString&, diff --git a/src/SMESHGUI/SMESHGUI_InitMeshDlg.cxx b/src/SMESHGUI/SMESHGUI_InitMeshDlg.cxx index 388409a8c..95545e4a2 100644 --- a/src/SMESHGUI/SMESHGUI_InitMeshDlg.cxx +++ b/src/SMESHGUI/SMESHGUI_InitMeshDlg.cxx @@ -27,63 +27,15 @@ // $Header$ #include "SMESHGUI_InitMeshDlg.h" +#include +#include -#include "SMESHGUI.h" -#include "SMESHGUI_Utils.h" -#include "SMESHGUI_HypothesesUtils.h" +#include -#include "SMESH_TypeFilter.hxx" -#include "SMESH_NumberFilter.hxx" - -#include "GEOMBase.h" - -#include "SUIT_Session.h" -#include "SUIT_MessageBox.h" -#include "SUIT_OverrideCursor.h" -#include "SUIT_Operation.h" -#include "SUIT_Desktop.h" - -#include "SALOMEDSClient_Study.hxx" -#include "SALOMEDS_SObject.hxx" -#include "SALOME_ListIO.hxx" -#include "SALOME_ListIteratorOfListIO.hxx" -#include "SalomeApp_Tools.h" - -#include "SVTK_ViewModel.h" - -#include "utilities.h" - -// QT Includes #include -#include -#include -#include #include -#include - -using namespace std; - -namespace SMESH { - SMESH::SMESH_Mesh_var InitMesh (GEOM::GEOM_Object_ptr theShapeObject, - const char* theMeshName) - { - SMESH::SMESH_Mesh_var aMesh; - try { - SMESH::SMESH_Gen_var aSMESHGen = SMESHGUI::GetSMESHGen(); - if (!aSMESHGen->_is_nil() && !theShapeObject->_is_nil()) { - aMesh = aSMESHGen->CreateMesh(theShapeObject); - if (!aMesh->_is_nil()) { - _PTR(SObject) aMeshSObject = SMESH::FindSObject(aMesh.in()); - SMESH::SetName(aMeshSObject, theMeshName); - } - } - } - catch (const SALOME::SALOME_Exception& S_ex) { - SalomeApp_Tools::QtCatchCorbaException(S_ex); - } - return aMesh._retn(); - } -} +#include +#include //================================================================================= // class : SMESHGUI_InitMeshDlg() @@ -92,97 +44,36 @@ namespace SMESH { // The dialog will by default be modeless, unless you set 'modal' to // TRUE to construct a modal dialog. //================================================================================= -SMESHGUI_InitMeshDlg::SMESHGUI_InitMeshDlg (SMESHGUI* theModule, const char* name, - bool modal, WFlags fl) - : QDialog( SMESH::GetDesktop( theModule ), name, modal, WStyle_Customize | WStyle_NormalBorder | - WStyle_Title | WStyle_SysMenu | WDestructiveClose), - mySMESHGUI( theModule ), - mySelectionMgr( SMESH::GetSelectionMgr( theModule ) ) +SMESHGUI_InitMeshDlg::SMESHGUI_InitMeshDlg( SMESHGUI* theModule ) +: SMESHGUI_Dialog( theModule, false, true ) { - QPixmap image0 (SMESH::GetResourceMgr( mySMESHGUI )->loadPixmap("SMESH", tr("ICON_SELECT"))); - if (!name) - setName("SMESHGUI_InitMeshDlg"); - setCaption(tr("SMESH_INIT_MESH")); - setSizeGripEnabled(TRUE); - QGridLayout* SMESHGUI_InitMeshDlgLayout = new QGridLayout (this); - SMESHGUI_InitMeshDlgLayout->setSpacing(6); - SMESHGUI_InitMeshDlgLayout->setMargin(11); + + QVBoxLayout* main = new QVBoxLayout( mainFrame() ); /***************************************************************/ - GroupC1 = new QGroupBox(tr("SMESH_ARGUMENTS"), this, "GroupC1"); - GroupC1->setColumnLayout(0, Qt::Vertical); - GroupC1->layout()->setSpacing(0); - GroupC1->layout()->setMargin(0); - QGridLayout* GroupC1Layout = new QGridLayout(GroupC1->layout()); - GroupC1Layout->setAlignment(Qt::AlignTop); - GroupC1Layout->setSpacing(6); - GroupC1Layout->setMargin(11); + QGroupBox* GroupC1 = new QGroupBox( tr( "SMESH_ARGUMENTS" ), mainFrame(), "GroupC1" ); + GroupC1->setColumnLayout(3, Qt::Horizontal); + GroupC1->layout()->setSpacing(6); + GroupC1->layout()->setMargin(11); + + myMeshNameLabel = new QLabel(tr("SMESH_NAME"), GroupC1, "TextLabel_NameMesh"); + GroupC1->addSpace(1); + myMeshName = new QLineEdit(GroupC1, "LineEdit_NameMesh"); + + createObject( tr("SMESH_OBJECT_GEOM"), GroupC1, GeomObj ); + createObject( tr("SMESH_OBJECT_HYPOTHESIS"), GroupC1, Hypo ); + createObject( tr("SMESH_OBJECT_ALGORITHM"), GroupC1, Algo ); - 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_GEOM"), GroupC1, "TextLabelC1A1"); - GroupC1Layout->addWidget(TextLabelC1A1, 1, 0); - SelectButtonC1A1 = new QPushButton(GroupC1, "SelectButtonC1A1"); - SelectButtonC1A1->setPixmap(image0); - SelectButtonC1A1->setToggleButton(FALSE); - GroupC1Layout->addWidget(SelectButtonC1A1, 1, 1); - LineEditC1A1 = new QLineEdit(GroupC1, "LineEditC1A1"); - LineEditC1A1->setReadOnly(true); - GroupC1Layout->addWidget(LineEditC1A1, 1, 2); - - TextLabelC1A1Hyp = new QLabel(tr("SMESH_OBJECT_HYPOTHESIS"), GroupC1, "TextLabelC1A1Hyp"); - GroupC1Layout->addWidget(TextLabelC1A1Hyp, 2, 0); - SelectButtonC1A1Hyp = new QPushButton(GroupC1, "SelectButtonC1A1Hyp"); - SelectButtonC1A1Hyp->setPixmap(image0); - GroupC1Layout->addWidget(SelectButtonC1A1Hyp, 2, 1); - LineEditC1A1Hyp = new QLineEdit(GroupC1, "LineEditC1A1Hyp"); - LineEditC1A1Hyp->setReadOnly(true); - GroupC1Layout->addWidget(LineEditC1A1Hyp, 2, 2); - - TextLabelC1A1Algo = new QLabel(tr("SMESH_OBJECT_ALGORITHM"), GroupC1, "TextLabelC1A1Algo"); - GroupC1Layout->addWidget(TextLabelC1A1Algo, 3, 0); - SelectButtonC1A1Algo = new QPushButton(GroupC1, "SelectButtonC1A1Algo"); - SelectButtonC1A1Algo->setPixmap(image0); - GroupC1Layout->addWidget(SelectButtonC1A1Algo, 3, 1); - LineEditC1A1Algo = new QLineEdit(GroupC1, "LineEditC1A1Algo"); - LineEditC1A1Algo->setReadOnly(true); - GroupC1Layout->addWidget(LineEditC1A1Algo, 3, 2); - - SMESHGUI_InitMeshDlgLayout->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); - - 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_InitMeshDlgLayout->addWidget(GroupButtons, 2, 0); - - /***************************************************************/ - Init(); + setNameIndication( GeomObj, OneName ); + + int _smesh = SMESHGUI_Operation::prefix( "SMESH" ); + setObjectType( Hypo, _smesh + HYPOTHESIS, -1 ); + setObjectType( Algo, _smesh + ALGORITHM, -1 ); + + main->addWidget( GroupC1 ); + + updateControlState(); } //================================================================================= @@ -195,304 +86,31 @@ SMESHGUI_InitMeshDlg::~SMESHGUI_InitMeshDlg() } //================================================================================= -// function : Init() +// function : updateControlState // purpose : //================================================================================= -void SMESHGUI_InitMeshDlg::Init () +void SMESHGUI_InitMeshDlg::updateControlState() { - mySMESHGUI->SetActiveDialogBox((QDialog*)this); - - //myGeomFilter = new SALOME_TypeFilter("GEOM"); - TColStd_MapOfInteger allTypesMap; - for (int i = 0; i < 10; i++) - allTypesMap.Add(i); - myGeomFilter = new SMESH_NumberFilter ("GEOM", TopAbs_SHAPE, 0, allTypesMap); - 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(mySelectionMgr, 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; - mySelectionMgr->clearFilters(); - mySelectionMgr->installFilter(myGeomFilter); - - SelectionIntoArgument(); - - UpdateControlState(); + bool isEnabled = !meshName().isEmpty() && + hasSelection( GeomObj ) && hasSelection( Hypo ) && hasSelection( Algo ); + setButtonEnabled( isEnabled, OK | Apply ); } //================================================================================= -// function : ClickOnOk() +// function : meshName // purpose : //================================================================================= -void SMESHGUI_InitMeshDlg::ClickOnOk() +QString SMESHGUI_InitMeshDlg::meshName() const { - if (this->ClickOnApply()) - this->ClickOnCancel(); + return myMeshName->text().stripWhiteSpace(); } //================================================================================= -// function : ClickOnApply() +// function : setMeshName // purpose : //================================================================================= -bool SMESHGUI_InitMeshDlg::ClickOnApply() +void SMESHGUI_InitMeshDlg::setMeshName( const QString& name ) { - if (mySMESHGUI->isActiveStudyLocked()) - return false; - - QString myNameMesh = LineEdit_NameMesh->text().stripWhiteSpace(); - if (myNameMesh.isEmpty()) { - SUIT_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; - - SUIT_OverrideCursor wc; - - SUIT_Operation* op = - new SUIT_Operation (SUIT_Session::session()->activeApplication()); - - // 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++) { - _PTR(SObject) aHypSOClient = - SMESH::GetActiveStudyDocument()->FindObjectID(HypoList[i].latin1()); - if (aHypSOClient) { - CORBA::Object_var anObject = _CAST(SObject,aHypSOClient)->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++) { - _PTR(SObject) aHypSOClient = - SMESH::GetActiveStudyDocument()->FindObjectID(AlgoList[i].latin1()); - if (aHypSOClient) { - CORBA::Object_var anObject = _CAST(SObject,aHypSOClient)->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->commit(); - mySMESHGUI->updateObjBrowser(); - LineEdit_NameMesh->setText(GetDefaultMeshName()); - return true; + myMeshName->setText( name.stripWhiteSpace() ); } -//================================================================================= -// 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 = ""; - - SALOME_ListIO aList; - mySelectionMgr->selectedObjects(aList,SVTK_Viewer::Type()); - - int nbSel = SMESH::GetNameOfSelectedIObjects(mySelectionMgr, aString); - - if (myEditCurrentArgument == LineEditC1A1) { - // geom shape - if (nbSel != 1) { - myGeomShape = GEOM::GEOM_Object::_nil(); - aString = ""; - } else { - Handle(SALOME_InteractiveObject) IO = aList.First(); - myGeomShape = SMESH::IObjectToInterface(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 (aList); - 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 (aList); - for (; Itinit.More(); Itinit.Next()) { - AlgoList.append(Itinit.Value()->getEntry()); - } - if (nbSel > 1) - aString = tr("%1 Algorithms").arg(nbSel); - } else { - aString = ""; - } - } else { - } - - myEditCurrentArgument->setText(aString); - - UpdateControlState(); -} - -//================================================================================= -// function : SetEditCurrentArgument() -// purpose : -//================================================================================= -void SMESHGUI_InitMeshDlg::SetEditCurrentArgument() -{ - QPushButton* send = (QPushButton*)sender(); - if (send == SelectButtonC1A1) { - LineEditC1A1->setFocus(); - myEditCurrentArgument = LineEditC1A1; - mySelectionMgr->clearFilters(); - mySelectionMgr->installFilter(myGeomFilter); - } else if (send == SelectButtonC1A1Hyp) { - LineEditC1A1Hyp->setFocus(); - myEditCurrentArgument = LineEditC1A1Hyp; - mySelectionMgr->clearFilters(); - mySelectionMgr->installFilter(myHypothesisFilter); - } else if (send == SelectButtonC1A1Algo) { - LineEditC1A1Algo->setFocus(); - myEditCurrentArgument = LineEditC1A1Algo; - mySelectionMgr->clearFilters(); - mySelectionMgr->installFilter(myAlgorithmFilter); - } - SelectionIntoArgument(); -} - -//================================================================================= -// function : DeactivateActiveDialog() -// purpose : -//================================================================================= -void SMESHGUI_InitMeshDlg::DeactivateActiveDialog() -{ - if (GroupC1->isEnabled()) { - disconnect(mySelectionMgr, 0, this, 0); - GroupC1->setEnabled(false); - GroupButtons->setEnabled(false); - } -} - -//================================================================================= -// function : ActivateThisDialog() -// purpose : -//================================================================================= -void SMESHGUI_InitMeshDlg::ActivateThisDialog() -{ - mySMESHGUI->EmitSignalDeactivateDialog(); - GroupC1->setEnabled(true); - GroupButtons->setEnabled(true); - connect (mySelectionMgr, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument())); -} - -//================================================================================= -// function : enterEvent() -// purpose : -//================================================================================= -void SMESHGUI_InitMeshDlg::enterEvent (QEvent* e) -{ - if (!GroupC1->isEnabled()) - ActivateThisDialog(); -} - -//================================================================================= -// function : closeEvent() -// purpose : -//================================================================================= -void SMESHGUI_InitMeshDlg::closeEvent (QCloseEvent* e) -{ - disconnect(mySelectionMgr, 0, this, 0); - mySMESHGUI->ResetState(); - mySelectionMgr->clearFilters(); - QDialog::closeEvent(e); -} - -//================================================================================= -// function : UpdateControlState() -// purpose : -//================================================================================= -void SMESHGUI_InitMeshDlg::UpdateControlState() -{ - bool isEnabled = (!myGeomShape->_is_nil() && HypoList.count() && AlgoList.count()); - - buttonOk ->setEnabled(isEnabled); - buttonApply->setEnabled(isEnabled); -} - -//================================================================================= -// function : GetDefaultMeshName() -// purpose : Generates default mesh name(Mesh_1, Mesh_2, etc.) -//================================================================================= -QString SMESHGUI_InitMeshDlg::GetDefaultMeshName() -{ - _PTR(Study) aStudy = SMESH::GetActiveStudyDocument(); - int aNumber = 0; - QString aMeshName; - _PTR(SObject) obj; - - do { - aMeshName = QString(tr("SMESH_OBJECT_MESH")) + "_" + QString::number(++aNumber); - obj = aStudy->FindObject(aMeshName.latin1()); - } while (obj); - - return aMeshName; -} diff --git a/src/SMESHGUI/SMESHGUI_InitMeshDlg.h b/src/SMESHGUI/SMESHGUI_InitMeshDlg.h index 1a6f4ed57..bf8cde064 100644 --- a/src/SMESHGUI/SMESHGUI_InitMeshDlg.h +++ b/src/SMESHGUI/SMESHGUI_InitMeshDlg.h @@ -29,96 +29,32 @@ #ifndef DIALOGBOX_INIT_MESH_H #define DIALOGBOX_INIT_MESH_H -//#include "SMESH_TypeFilter.hxx" - -#include "SUIT_SelectionFilter.h" -#include "SalomeApp_SelectionMgr.h" - -// QT Includes -#include -#include - -// IDL Headers -#include -#include CORBA_SERVER_HEADER(GEOM_Gen) -#include CORBA_SERVER_HEADER(SMESH_Gen) - -class QGroupBox; -class QLabel; -class QLineEdit; -class QPushButton; -class SMESHGUI; +#include //================================================================================= // class : SMESHGUI_InitMeshDlg // purpose : //================================================================================= -class SMESHGUI_InitMeshDlg : public QDialog +class SMESHGUI_InitMeshDlg : public SMESHGUI_Dialog { Q_OBJECT public: - SMESHGUI_InitMeshDlg ( SMESHGUI*, - const char* = 0, - bool modal = FALSE, - WFlags fl = 0 ); + enum { GeomObj, Hypo, Algo }; + +public: + SMESHGUI_InitMeshDlg( SMESHGUI* ); ~SMESHGUI_InitMeshDlg(); -protected: - void closeEvent( QCloseEvent* e ) ; - void enterEvent( QEvent * ) ; + void updateControlState(); + + void setMeshName( const QString& ); + QString meshName() const; private: - void Init(); - - void UpdateControlState(); - QString SMESHGUI_InitMeshDlg::GetDefaultMeshName(); - -private: - SMESHGUI* mySMESHGUI; - SalomeApp_SelectionMgr* mySelectionMgr; - - GEOM::GEOM_Object_var myGeomShape; - QLineEdit* myEditCurrentArgument; - - //Handle(SALOME_TypeFilter) myGeomFilter; - SUIT_SelectionFilter* myGeomFilter; - //SMESH_TypeFilter* myHypothesisFilter; - //SMESH_TypeFilter* myAlgorithmFilter; - SUIT_SelectionFilter* myHypothesisFilter; - SUIT_SelectionFilter* myAlgorithmFilter; - - QStringList HypoList; - QStringList AlgoList; - - QGroupBox* GroupButtons; - QPushButton* buttonOk; - QPushButton* buttonCancel; - QPushButton* buttonApply; - - QGroupBox* GroupC1; - QLabel* TextLabel_NameMesh; - QLineEdit* LineEdit_NameMesh; - QLabel* TextLabelC1A1; - QPushButton* SelectButtonC1A1; - QLineEdit* LineEditC1A1; - - QLabel* TextLabelC1A1Hyp; - QPushButton* SelectButtonC1A1Hyp; - QLineEdit* LineEditC1A1Hyp; - - QLabel* TextLabelC1A1Algo; - QPushButton* SelectButtonC1A1Algo; - QLineEdit* LineEditC1A1Algo; - -private slots: - void ClickOnOk(); - bool ClickOnApply(); - void ClickOnCancel(); - void SetEditCurrentArgument(); - void SelectionIntoArgument(); - void DeactivateActiveDialog(); - void ActivateThisDialog(); + QLabel* myMeshNameLabel; + QLineEdit* myMeshName; + }; #endif // DIALOGBOX_INIT_MESH_H diff --git a/src/SMESHGUI/SMESHGUI_InitMeshOp.cxx b/src/SMESHGUI/SMESHGUI_InitMeshOp.cxx new file mode 100644 index 000000000..7a062119b --- /dev/null +++ b/src/SMESHGUI/SMESHGUI_InitMeshOp.cxx @@ -0,0 +1,297 @@ +// 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_InitMeshDlg.cxx +// Author : Nicolas REJNERI +// Module : SMESH +// $Header$ + +#include "SMESHGUI_InitMeshOp.h" +#include +#include +#include +#include + +#include +#include + +#include + +#include +#include +#include + +#include +#include + +#include + +//================================================================================= +// function : Constructor +// purpose : +//================================================================================= +SMESHGUI_InitMeshOp::SMESHGUI_InitMeshOp() +: SMESHGUI_Operation(), + myDlg( 0 ), + myGeomFilter( 0 ), + myHypothesisFilter( 0 ), + myAlgorithmFilter( 0 ) +{ +} + +//================================================================================= +// function : Destructor +// purpose : +//================================================================================= +SMESHGUI_InitMeshOp::~SMESHGUI_InitMeshOp() +{ + if( myDlg ) + delete myDlg; + + if( myGeomFilter ) + delete myGeomFilter; + + if( myAlgorithmFilter ) + delete myAlgorithmFilter; + + if( myHypothesisFilter ) + delete myHypothesisFilter; +} + +//================================================================================= +// function : startOperation +// purpose : +//================================================================================= +void SMESHGUI_InitMeshOp::startOperation() +{ + if( !myDlg ) + { + myDlg = new SMESHGUI_InitMeshDlg( getSMESHGUI() ); + connect( myDlg, SIGNAL( objectActivated( int ) ), this, SLOT( onActivateObject( int ) ) ); + } + + SMESHGUI_Operation::startOperation(); + + if( !myGeomFilter ) + { + TColStd_MapOfInteger allTypesMap; + for (int i = 0; i < 10; i++) + allTypesMap.Add(i); + myGeomFilter = new SMESH_NumberFilter ("GEOM", TopAbs_SHAPE, 0, allTypesMap); + } + + if( !myAlgorithmFilter ) + myAlgorithmFilter = new SMESH_TypeFilter (ALGORITHM); + + if( !myHypothesisFilter ) + myHypothesisFilter = new SMESH_TypeFilter (HYPOTHESIS); + + init(); + myDlg->clearSelection(); + myDlg->show(); +} + +//================================================================================= +// function : dlg +// purpose : +//================================================================================= +SalomeApp_Dialog* SMESHGUI_InitMeshOp::dlg() const +{ + return myDlg; +} + +//================================================================================= +// function : selectionDone +// purpose : +//================================================================================= +void SMESHGUI_InitMeshOp::selectionDone() +{ + QStringList names, ids; + SMESHGUI_Dialog::TypesList types; + selected( names, types, ids ); + if( myDlg ) + { + myDlg->selectObject( names, types, ids ); + myDlg->updateControlState(); + } +} + +//================================================================================= +// function : onActivateObject +// purpose : +//================================================================================= +void SMESHGUI_InitMeshOp::onActivateObject( int obj ) +{ + SalomeApp_SelectionMgr* mgr = selectionMgr(); + + if( !mgr ) + return; + + mgr->clearFilters(); + if( obj==SMESHGUI_InitMeshDlg::GeomObj ) + mgr->installFilter( myGeomFilter ); + + else if( obj==SMESHGUI_InitMeshDlg::Hypo ) + mgr->installFilter( myHypothesisFilter ); + + else if( obj==SMESHGUI_InitMeshDlg::Algo ) + mgr->installFilter( myAlgorithmFilter ); +} + +//================================================================================= +// function : commitOperation +// purpose : +//================================================================================= +bool SMESHGUI_InitMeshOp::onApply() +{ + if( getSMESHGUI()->isActiveStudyLocked() ) + return false; + + QString myNameMesh = myDlg->meshName(); + if (myNameMesh.isEmpty()) + { + SUIT_MessageBox::warn1( dlg(), tr("SMESH_WRN_WARNING"), + tr("SMESH_WRN_EMPTY_NAME"), tr("SMESH_BUT_OK") ); + return false; + } + + SUIT_OverrideCursor wc; + + QStringList selGeom, selHypo, selAlgo; + myDlg->selectedObject( SMESHGUI_InitMeshDlg::GeomObj, selGeom ); + myDlg->selectedObject( SMESHGUI_InitMeshDlg::Hypo, selHypo ); + myDlg->selectedObject( SMESHGUI_InitMeshDlg::Algo, selAlgo ); + + _PTR(Study) study = studyDS(); + _PTR(SObject) aGeomSO = study->FindObjectID( selGeom.first() ); + GEOM::GEOM_Object_var myGeomShape = GEOM::GEOM_Object::_narrow( _CAST(SObject,aGeomSO)->GetObject() ); + + // create mesh + SMESH::SMESH_Mesh_var aMesh = initMesh(myGeomShape, myNameMesh); + + if (!aMesh->_is_nil()) + { + // assign hypotheses + for (int i = 0; i < selHypo.count(); i++) + { + _PTR(SObject) aHypSOClient = + study->FindObjectID(selHypo[i].latin1()); + if (aHypSOClient) + { + CORBA::Object_var anObject = _CAST(SObject,aHypSOClient)->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)) + return false; + } + } + } + } + // assign algorithms + for (int i = 0; i < selAlgo.count(); i++) + { + _PTR(SObject) aHypSOClient = + study->FindObjectID(selAlgo[i].latin1()); + if (aHypSOClient) + { + CORBA::Object_var anObject = _CAST(SObject,aHypSOClient)->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)) + return false; + } + } + } + } + } + // commit transaction + + //update( UF_Model | UF_ObjBrowser ); + module()->updateObjBrowser( true, 0 ); + init(); + return true; +} + +//================================================================================= +// function : defaultMeshName() +// purpose : +//================================================================================= +QString SMESHGUI_InitMeshOp::defaultMeshName() const +{ + _PTR(Study) aStudy = studyDS(); + int aNumber = 0; + QString aMeshName; + _PTR(SObject) obj; + + do { + aMeshName = QString(tr("SMESH_OBJECT_MESH")) + "_" + QString::number(++aNumber); + obj = aStudy->FindObject(aMeshName.latin1()); + } while (obj); + + return aMeshName; +} + +//================================================================================= +// function : init() +// purpose : +//================================================================================= +void SMESHGUI_InitMeshOp::init() +{ + if( myDlg ) + myDlg->setMeshName( defaultMeshName() ); +} + +//================================================================================= +// function : defaultMeshName() +// purpose : +//================================================================================= +SMESH::SMESH_Mesh_var SMESHGUI_InitMeshOp::initMesh ( GEOM::GEOM_Object_ptr theShapeObject, + const QString& theMeshName ) +{ + SMESH::SMESH_Mesh_var aMesh; + try + { + SMESH::SMESH_Gen_var aSMESHGen = SMESHGUI::GetSMESHGen(); + if (!aSMESHGen->_is_nil() && !theShapeObject->_is_nil()) + { + aMesh = aSMESHGen->CreateMesh(theShapeObject); + if (!aMesh->_is_nil()) + { + _PTR(SObject) aMeshSObject = SMESH::FindSObject(aMesh.in()); + SMESH::SetName(aMeshSObject, theMeshName); + } + } + } + catch( const SALOME::SALOME_Exception& S_ex ) + { + SalomeApp_Tools::QtCatchCorbaException(S_ex); + } + + return aMesh._retn(); +} diff --git a/src/SMESHGUI/SMESHGUI_InitMeshOp.h b/src/SMESHGUI/SMESHGUI_InitMeshOp.h new file mode 100644 index 000000000..ee4141cea --- /dev/null +++ b/src/SMESHGUI/SMESHGUI_InitMeshOp.h @@ -0,0 +1,74 @@ +// 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_InitMeshOp.h +// Author : Nicolas REJNERI +// Module : SMESH +// $Header$ + +#ifndef OPERATION_INIT_MESH_H +#define OPERATION_INIT_MESH_H + +#include + +#include +#include CORBA_SERVER_HEADER(GEOM_Gen) +#include CORBA_SERVER_HEADER(SMESH_Gen) + +class SMESHGUI_InitMeshDlg; +class SUIT_SelectionFilter; + +//================================================================================= +// class : SMESHGUI_InitMeshOp +// purpose : +//================================================================================= +class SMESHGUI_InitMeshOp : public SMESHGUI_Operation +{ + Q_OBJECT + +public: + SMESHGUI_InitMeshOp(); + ~SMESHGUI_InitMeshOp(); + + virtual SalomeApp_Dialog* dlg() const; + void init(); + QString defaultMeshName() const; + +protected: + virtual void startOperation(); + virtual void selectionDone(); + + SMESH::SMESH_Mesh_var initMesh( GEOM::GEOM_Object_ptr, const QString& ); + +protected slots: + virtual bool onApply(); + +private slots: + void onActivateObject( int ); + +private: + SMESHGUI_InitMeshDlg *myDlg; + SUIT_SelectionFilter *myGeomFilter, *myHypothesisFilter, *myAlgorithmFilter; +}; + +#endif // OPERATION_INIT_MESH_H