From e62fe64c08065602fcfd2817422faee1eb113116 Mon Sep 17 00:00:00 2001 From: vsr Date: Fri, 8 Oct 2010 13:21:03 +0000 Subject: [PATCH] 0020749: EDF 1291 SMESH : Create 2D Mesh from 2D improvement --- src/SMESHGUI/SMESHGUI_Make2DFrom3DOp.cxx | 466 +++++++++++++++-------- src/SMESHGUI/SMESHGUI_Make2DFrom3DOp.h | 85 +++-- src/SMESHGUI/SMESHGUI_MeshUtils.cxx | 40 ++ src/SMESHGUI/SMESHGUI_MeshUtils.h | 7 + src/SMESHGUI/SMESH_msg_en.ts | 74 ++++ 5 files changed, 487 insertions(+), 185 deletions(-) diff --git a/src/SMESHGUI/SMESHGUI_Make2DFrom3DOp.cxx b/src/SMESHGUI/SMESHGUI_Make2DFrom3DOp.cxx index ffbc3b80d..579345f57 100644 --- a/src/SMESHGUI/SMESHGUI_Make2DFrom3DOp.cxx +++ b/src/SMESHGUI/SMESHGUI_Make2DFrom3DOp.cxx @@ -16,235 +16,389 @@ // // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com // +// File : SMESHGUI_Make2DFrom3D.cxx +// Author : Vadim SANDLER, Open CASCADE S.A.S. (vadim.sandler@opencascade.com) -// File : SMESHGUI_Make2DFrom3DOp.cxx -// Author : Open CASCADE S.A.S. -// SMESH includes -// #include "SMESHGUI_Make2DFrom3DOp.h" #include "SMESHGUI.h" #include "SMESHGUI_Utils.h" -#include "SMESHGUI_VTKUtils.h" #include "SMESHGUI_MeshUtils.h" -#include "SMESHGUI_MeshInfosBox.h" +#include "SMESH_TypeFilter.hxx" +#include "SMESH_LogicalFilter.hxx" // SALOME GUI includes -#include - +#include +#include +#include #include #include -#include #include -#include - -// SALOME KERNEL includes -#include -#include - -// Qt includes // IDL includes #include -#include CORBA_SERVER_HEADER(SMESH_Gen) -#include CORBA_SERVER_HEADER(SMESH_MeshEditor) +#include CORBA_SERVER_HEADER(SMESH_Group) -#include -#include -#include +// Qt includes #include -#include -#include - -// MESH includes -#include "SMDSAbs_ElementType.hxx" -#include "SMDSAbs_ElementType.hxx" - +#include +#include +#include +#include +#include #define SPACING 6 #define MARGIN 11 -// ========================================================================================= /*! - * \brief Dialog to show creted mesh statistic - */ -//======================================================================= + \class SMESHGUI_CopyMeshDlg + \brief Copy Mesh dialog box +*/ -SMESHGUI_Make2DFrom3DDlg::SMESHGUI_Make2DFrom3DDlg( QWidget* parent ) - : SMESHGUI_Dialog( parent, false, true, Close/* | Help*/ ) +SMESHGUI_CopyMeshDlg::SMESHGUI_CopyMeshDlg( QWidget* parent ) + : SMESHGUI_Dialog( parent, false, true, OK | Apply | Close | Help ) { + // title setWindowTitle( tr("CAPTION") ); - QVBoxLayout* aDlgLay = new QVBoxLayout (mainFrame()); + + // mesh + setObjectPixmap( "SMESH", tr( "ICON_SELECT" ) ); + createObject( tr( "MESH" ), mainFrame(), Mesh ); + + // mode + QGroupBox* aModeGrp = new QGroupBox( tr( "MODE" ), mainFrame() ); + QHBoxLayout* aModeGrpLayout = new QHBoxLayout( aModeGrp ); + aModeGrpLayout->setMargin( MARGIN ); + aModeGrpLayout->setSpacing( SPACING ); + my2dFrom3dRB = new QRadioButton( tr( "2D_FROM_3D" ), aModeGrp ); + my1dFrom2dRB = new QRadioButton( tr( "1D_FROM_2D" ), aModeGrp ); + my1dFrom3dRB = new QRadioButton( tr( "1D_FROM_3D" ), aModeGrp ); + aModeGrpLayout->addWidget( my2dFrom3dRB ); + aModeGrpLayout->addWidget( my1dFrom2dRB ); + aModeGrpLayout->addWidget( my1dFrom3dRB ); + + // target + QGroupBox* aTargetGrp = new QGroupBox( tr( "TARGET" ), mainFrame() ); + QGridLayout* aTargetGrpLayout = new QGridLayout( aTargetGrp ); + aTargetGrpLayout->setMargin( MARGIN ); + aTargetGrpLayout->setSpacing( SPACING ); + myThisMeshRB = new QRadioButton( tr( "THIS_MESH" ), aTargetGrp ); + myNewMeshRB = new QRadioButton( tr( "NEW_MESH" ), aTargetGrp ); + myMeshName = new QLineEdit( aTargetGrp ); + myCopyCheck = new QCheckBox( tr( "COPY_SRC" ), aTargetGrp ); + myMissingCheck = new QCheckBox( tr( "MISSING_ONLY" ), aTargetGrp ); + aTargetGrpLayout->addWidget( myThisMeshRB, 0, 0 ); + aTargetGrpLayout->addWidget( myNewMeshRB, 1, 0 ); + aTargetGrpLayout->addWidget( myMeshName, 1, 1 ); + aTargetGrpLayout->addWidget( myCopyCheck, 2, 0 ); + aTargetGrpLayout->addWidget( myMissingCheck, 2, 1 ); + myGroupCheck = new QCheckBox( tr( "CREATE_GROUP" ), mainFrame() ); + myGroupName = new QLineEdit( mainFrame() ); + + // layout + QGridLayout* aDlgLay = new QGridLayout( mainFrame() ); aDlgLay->setMargin( 0 ); aDlgLay->setSpacing( SPACING ); - QFrame* aMainFrame = createMainFrame(mainFrame()); - aDlgLay->addWidget(aMainFrame); - aDlgLay->setStretchFactor(aMainFrame, 1); + aDlgLay->addWidget( objectWg( Mesh, Label ), 0, 0 ); + aDlgLay->addWidget( objectWg( Mesh, Btn ), 0, 1 ); + aDlgLay->addWidget( objectWg( Mesh, Control ), 0, 2 ); + aDlgLay->addWidget( aModeGrp, 1, 0, 1, 3 ); + aDlgLay->addWidget( aTargetGrp, 2, 0, 1, 3 ); + aDlgLay->addWidget( myGroupCheck, 3, 0 ); + aDlgLay->addWidget( myGroupName, 3, 1, 1, 2 ); + + // connect signals + connect( myThisMeshRB, SIGNAL( clicked() ), this, SLOT( onTargetChanged() ) ); + connect( myNewMeshRB, SIGNAL( clicked() ), this, SLOT( onTargetChanged() ) ); + connect( myGroupCheck, SIGNAL( clicked() ), this, SLOT( onGroupChecked() ) ); + + // init dlg + my2dFrom3dRB->setChecked( true ); + myThisMeshRB->setChecked( true ); + myMissingCheck->setChecked( true ); + onTargetChanged(); + onGroupChecked(); } -// ========================================================================================= -/*! - * \brief Dialog destructor - */ -//======================================================================= - -SMESHGUI_Make2DFrom3DDlg::~SMESHGUI_Make2DFrom3DDlg() +SMESHGUI_CopyMeshDlg::~SMESHGUI_CopyMeshDlg() { } -//======================================================================= -// function : createMainFrame() -// purpose : Create frame containing dialog's fields -//======================================================================= - -QFrame* SMESHGUI_Make2DFrom3DDlg::createMainFrame (QWidget* theParent) +SMESH::Bnd_Dimension SMESHGUI_CopyMeshDlg::mode() const { - QFrame* aFrame = new QFrame(theParent); + if ( my2dFrom3dRB->isChecked() ) + return SMESH::BND_2DFROM3D; + else if ( my1dFrom2dRB->isChecked() ) + return SMESH::BND_1DFROM2D; + else + return SMESH::BND_1DFROM3D; +} - SUIT_ResourceMgr* rm = resourceMgr(); - QPixmap iconCompute (rm->loadPixmap("SMESH", tr("ICON_2D_FROM_3D"))); +bool SMESHGUI_CopyMeshDlg::needNewMesh() const +{ + return myNewMeshRB->isChecked(); +} - // Mesh name - QGroupBox* nameBox = new QGroupBox(tr("SMESH_MESHINFO_NAME"), aFrame ); - QHBoxLayout* nameBoxLayout = new QHBoxLayout(nameBox); - nameBoxLayout->setMargin(MARGIN); nameBoxLayout->setSpacing(SPACING); - myMeshName = new QLabel(nameBox); - nameBoxLayout->addWidget(myMeshName); +QString SMESHGUI_CopyMeshDlg::getNewMeshName() const +{ + return myMeshName->text().trimmed(); +} - // Mesh Info +void SMESHGUI_CopyMeshDlg::setNewMeshName( const QString& name ) +{ + myMeshName->setText( name ); +} - myFullInfo = new SMESHGUI_MeshInfosBox(true, aFrame); +bool SMESHGUI_CopyMeshDlg::needGroup() const +{ + return myGroupCheck->isChecked(); +} - // add all widgets to aFrame - QVBoxLayout* aLay = new QVBoxLayout(aFrame); - aLay->setMargin( 0 ); - aLay->setSpacing( 0 ); - aLay->addWidget( nameBox ); - aLay->addWidget( myFullInfo ); +QString SMESHGUI_CopyMeshDlg::getGroupName() const +{ + return myGroupName->text().trimmed(); +} - ((QPushButton*) button( OK ))->setDefault( true ); - return aFrame; +void SMESHGUI_CopyMeshDlg::setGroupName( const QString& name ) +{ + myGroupName->setText( name ); } -//================================================================================ -/*! - * \brief set name of the mesh -*/ -//================================================================================ +bool SMESHGUI_CopyMeshDlg::copySource() const +{ + return myCopyCheck->isChecked(); +} -void SMESHGUI_Make2DFrom3DDlg::SetMeshName(const QString& theName) +bool SMESHGUI_CopyMeshDlg::copyMissingOnly() const { - myMeshName->setText( theName ); + return myMissingCheck->isChecked(); } -//================================================================================ -/*! - * \brief set mesh info -*/ -//================================================================================ +void SMESHGUI_CopyMeshDlg::onTargetChanged() +{ + myMeshName->setEnabled( myNewMeshRB->isChecked() ); + myCopyCheck->setEnabled( myNewMeshRB->isChecked() ); + myMissingCheck->setEnabled( myNewMeshRB->isChecked() ); +} -void SMESHGUI_Make2DFrom3DDlg::SetMeshInfo(const SMESH::long_array& theInfo) +void SMESHGUI_CopyMeshDlg::onGroupChecked() { - myFullInfo->SetMeshInfo( theInfo ); + myGroupName->setEnabled( myGroupCheck->isChecked() ); } -//================================================================================ /*! - * \brief Constructor + \class SMESHGUI_Make2DFrom3DOp + \brief Copy Mesh operation class */ -//================================================================================ SMESHGUI_Make2DFrom3DOp::SMESHGUI_Make2DFrom3DOp() - : SMESHGUI_Operation() + : SMESHGUI_SelectionOp() { - myDlg = new SMESHGUI_Make2DFrom3DDlg(desktop()); } -//================================================================================ -/*! - * \brief Desctructor -*/ -//================================================================================ - SMESHGUI_Make2DFrom3DOp::~SMESHGUI_Make2DFrom3DOp() { + if ( myDlg ) + delete myDlg; } -//================================================================================ -/*! - * \brief perform it's intention action: compute 2D mesh on 3D - */ -//================================================================================ +LightApp_Dialog* SMESHGUI_Make2DFrom3DOp::dlg() const +{ + return myDlg; +} void SMESHGUI_Make2DFrom3DOp::startOperation() { - myMesh = SMESH::SMESH_Mesh::_nil(); + if( !myDlg ) + myDlg = new SMESHGUI_CopyMeshDlg( desktop() ); + + mySrc = SMESH::SMESH_IDSource::_nil(); - // check selection - LightApp_SelectionMgr *Sel = selectionMgr(); - SALOME_ListIO selected; Sel->selectedObjects( selected ); + myHelpFileName = "copy_mesh_page.html"; - int nbSel = selected.Extent(); - if (nbSel != 1) { - SUIT_MessageBox::warning(desktop(), - tr("SMESH_WRN_WARNING"), - tr("SMESH_WRN_NO_AVAILABLE_DATA")); - onCancel(); - return; - } + SMESHGUI_SelectionOp::startOperation(); + + myDlg->activateObject( SMESHGUI_CopyMeshDlg::Mesh ); + myDlg->setNewMeshName( SMESH::UniqueName( "Mesh_1" ) ); + myDlg->setGroupName( SMESH::UniqueName( "Group" ) ); + myDlg->show(); + + selectionDone(); +} - Handle(SALOME_InteractiveObject) anIO = selected.First(); - myMesh = SMESH::GetMeshByIO(anIO); - if (myMesh->_is_nil()) { - SUIT_MessageBox::warning(desktop(), - tr("SMESH_WRN_WARNING"), - tr("SMESH_WRN_NO_AVAILABLE_DATA")); - onCancel(); - return; +void SMESHGUI_Make2DFrom3DOp::selectionDone() +{ + if ( !dlg() ) return; + + if ( dlg()->isVisible() ) { + try { + QStringList names, ids; + LightApp_Dialog::TypesList types; + selected( names, types, ids ); + if ( names.count() == 1 ) + myDlg->selectObject( names, types, ids ); + else + myDlg->clearSelection(); + } + catch ( const SALOME::SALOME_Exception& S_ex ) { + SalomeApp_Tools::QtCatchCorbaException( S_ex ); + } + catch ( ... ) { + } } +} - SMESHGUI_Operation::startOperation(); +SUIT_SelectionFilter* SMESHGUI_Make2DFrom3DOp::createFilter( const int theId ) const +{ + SUIT_SelectionFilter* f = 0; + if ( theId == SMESHGUI_CopyMeshDlg::Mesh ) { + QList filters; + filters.append( new SMESH_TypeFilter( MESHorSUBMESH ) ); + filters.append( new SMESH_TypeFilter( GROUP ) ); + f = new SMESH_LogicalFilter( filters, SMESH_LogicalFilter::LO_OR ); + } + return f; +} +bool SMESHGUI_Make2DFrom3DOp::isValid( QString& msg ) const +{ + if ( !dlg() ) return false; + + // check if any source data is selected + QString entry = myDlg->selectedObject( SMESHGUI_CopyMeshDlg::Mesh ); + SMESH::SMESH_IDSource_var obj; + _PTR(SObject) sobj = SMESHGUI::activeStudy()->studyDS()->FindObjectID( entry.toLatin1().constData() ); + if ( sobj ) + obj = SMESH::SObjectToInterface( sobj ); + + if ( obj->_is_nil() ) { + msg = tr( "SMESH_ERR_NO_INPUT_MESH" ); + return false; + } - // backup mesh info before 2D mesh computation - SMESH::long_array_var anOldInfo = myMesh->GetMeshInfo(); + // check if source contains elements of required type + SMESH::Bnd_Dimension mode = myDlg->mode(); + SMESH::array_of_ElementType_var types = obj->GetTypes(); + bool has3d = false; + bool has2d = false; + for ( int i = 0; i < types->length(); i++ ) { + if ( types[i] == SMESH::VOLUME ) has3d = true; + else if ( types[i] == SMESH::FACE ) has2d = true; + } - if (!compute2DMesh()) { - SUIT_MessageBox::warning(desktop(), - tr("SMESH_WRN_WARNING"), - tr("SMESH_WRN_COMPUTE_FAILED")); - onCancel(); - return; - } - // get new mesh statistic - SMESH::long_array_var aNewInfo = myMesh->GetMeshInfo(); - // get difference in mesh statistic from old to new - for ( int i = SMDSEntity_Node; i < SMDSEntity_Last; i++ ) - aNewInfo[i] -= anOldInfo[i]; - - // update presentation - SMESH::Update(anIO, SMESH::eDisplay); - - // show computated result - _PTR(SObject) aMeshSObj = SMESH::FindSObject(myMesh); - if ( aMeshSObj ) - myDlg->SetMeshName( aMeshSObj->GetName().c_str() ); - myDlg->SetMeshInfo( aNewInfo ); - myDlg->show(); /*exec();*/ - commit(); - SMESHGUI::Modified(); -} - -//================================================================================ -/*! - * \brief compute 2D mesh on initial 3D - */ -//================================================================================ + if ( ( mode == SMESH::BND_2DFROM3D || mode == SMESH::BND_1DFROM3D ) && !has3d ) { + msg = tr( "SMESH_ERR_NO_3D_ELEMENTS" ); + return false; + } + else if ( mode == SMESH::BND_1DFROM2D && !has2d ) { + msg = tr( "SMESH_ERR_NO_2D_ELEMENTS" ); + return false; + } + + // check if new mesh name is specified + if ( myDlg->needNewMesh() && myDlg->getNewMeshName().isEmpty() ) { + msg = tr( "SMESH_ERR_MESH_NAME_NOT_SPECIFIED" ); + return false; + } + + // check if group name is specified + if ( myDlg->needGroup() && myDlg->getGroupName().isEmpty() ) { + msg = tr( "SMESH_ERR_GRP_NAME_NOT_SPECIFIED" ); + return false; + } + + return true; +} bool SMESHGUI_Make2DFrom3DOp::compute2DMesh() { SUIT_OverrideCursor wc; - SMESH::SMESH_MeshEditor_var aMeshEditor = myMesh->GetMeshEditor(); - return aMeshEditor->Make2DMeshFrom3D(); + + bool ok = false; + try { + QString entry = myDlg->selectedObject( SMESHGUI_CopyMeshDlg::Mesh ); + _PTR(SObject) sobj = SMESHGUI::activeStudy()->studyDS()->FindObjectID( entry.toLatin1().constData() ); + SMESH::SMESH_IDSource_var obj = SMESH::SObjectToInterface( sobj ); + + SMESH::Bnd_Dimension mode = myDlg->mode(); + QString meshName = myDlg->needNewMesh() ? myDlg->getNewMeshName() : QString(); + QString groupName = myDlg->needGroup() ? myDlg->getGroupName() : QString(); + bool copySrc = myDlg->copySource(); + bool copyAll = !myDlg->copyMissingOnly(); + + SMESH::SMESH_Mesh_var srcMesh = SMESH::SMESH_Mesh::_narrow( obj ); + if ( CORBA::is_nil( srcMesh ) ) { + SMESH::SMESH_subMesh_var subMesh = SMESH::SMESH_subMesh::_narrow( obj ); + if ( !CORBA::is_nil( subMesh ) ) + srcMesh = subMesh->GetFather(); + } + if ( CORBA::is_nil( srcMesh ) ) { + SMESH::SMESH_GroupBase_var grp = SMESH::SMESH_GroupBase::_narrow( obj ); + if ( !CORBA::is_nil( grp ) ) + srcMesh = grp->GetMesh(); + } + + if ( !CORBA::is_nil( srcMesh ) ) { + SMESH::SMESH_MeshEditor_var aMeshEditor = srcMesh->GetMeshEditor(); + SMESH::SMESH_Group_var newGrp; + SMESH::SMESH_Mesh_var mesh = aMeshEditor->MakeBoundaryMesh( obj.in(), + mode, + meshName.toLatin1().constData(), + groupName.toLatin1().constData(), + copySrc, + copyAll, + newGrp.out() ); + if ( !mesh->_is_nil() ) { +#ifdef WITHGENERICOBJ + mesh->Destroy(); +#endif + } + if ( !newGrp->_is_nil() ) { +#ifdef WITHGENERICOBJ + newGrp->Destroy(); +#endif + } + ok = true; + } + } + catch ( ... ) { + } + return ok; +} + +bool SMESHGUI_Make2DFrom3DOp::onApply() +{ + if ( isStudyLocked() ) + return false; + + QString msg; + if ( !isValid( msg ) ) { + dlg()->show(); + if ( msg != "" ) + SUIT_MessageBox::warning( myDlg, tr( "SMESH_ERROR" ), msg ); + return false; + } + + bool res = false; + try { + res = compute2DMesh(); + } + catch ( const SALOME::SALOME_Exception& S_ex ) { + SalomeApp_Tools::QtCatchCorbaException( S_ex ); + } + catch ( ... ) { + } + + if ( res ) { + SMESHGUI::Modified(); + update( UF_ObjBrowser | UF_Model ); + myDlg->setNewMeshName( SMESH::UniqueName( "Mesh_1" ) ); + myDlg->setGroupName( SMESH::UniqueName( "Group" ) ); + } + else { + SUIT_MessageBox::warning( myDlg, tr( "SMESH_ERROR" ), tr( "SMESH_OPERATION_FAILED" ) ); + } + + return res; } diff --git a/src/SMESHGUI/SMESHGUI_Make2DFrom3DOp.h b/src/SMESHGUI/SMESHGUI_Make2DFrom3DOp.h index f2ef2d9fd..871c3725c 100644 --- a/src/SMESHGUI/SMESHGUI_Make2DFrom3DOp.h +++ b/src/SMESHGUI/SMESHGUI_Make2DFrom3DOp.h @@ -16,70 +16,97 @@ // // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com // - -// SMESH SMESHGUI : GUI for SMESH component // File : SMESHGUI_Make2DFrom3D.h -// Author : Open CASCADE S.A.S. -// +// Author : Vadim SANDLER, Open CASCADE S.A.S. (vadim.sandler@opencascade.com) + #ifndef SMESHGUI_Make2DFrom3DOp_H #define SMESHGUI_Make2DFrom3DOp_H // SMESH includes #include "SMESH_SMESHGUI.hxx" - #include "SMESHGUI_Dialog.h" -#include "SMESHGUI_Operation.h" +#include "SMESHGUI_SelectionOp.h" -// IDL includes #include -#include CORBA_SERVER_HEADER(SMESH_Mesh) +#include CORBA_SERVER_HEADER(SMESH_MeshEditor) -class QFrame; -class SMESHGUI_MeshInfosBox; +class QCheckBox; +class QLineEdit; +class QRadioButton; /*! * \brief Dialog to show result mesh statistic */ -class SMESHGUI_Make2DFrom3DDlg : public SMESHGUI_Dialog +class SMESHGUI_EXPORT SMESHGUI_CopyMeshDlg : public SMESHGUI_Dialog { Q_OBJECT - public: - SMESHGUI_Make2DFrom3DDlg( QWidget* ); - virtual ~SMESHGUI_Make2DFrom3DDlg(); +public: + enum { Mesh }; - void SetMeshName(const QString& theName); - void SetMeshInfo(const SMESH::long_array& theInfo); + SMESHGUI_CopyMeshDlg( QWidget* ); + virtual ~SMESHGUI_CopyMeshDlg(); - private: - QFrame* createMainFrame( QWidget* ); + SMESH::Bnd_Dimension mode() const; - private: - QLabel* myMeshName; - SMESHGUI_MeshInfosBox* myFullInfo; -}; + bool needNewMesh() const; + QString getNewMeshName() const; + void setNewMeshName( const QString& ); + + bool needGroup() const; + QString getGroupName() const; + void setGroupName( const QString& ); + + bool copySource() const; + bool copyMissingOnly() const; +private slots: + void onTargetChanged(); + void onGroupChecked(); + +private: + QRadioButton* my2dFrom3dRB; + QRadioButton* my1dFrom2dRB; + QRadioButton* my1dFrom3dRB; + QRadioButton* myThisMeshRB; + QRadioButton* myNewMeshRB; + QLineEdit* myMeshName; + QCheckBox* myCopyCheck; + QCheckBox* myMissingCheck; + QCheckBox* myGroupCheck; + QLineEdit* myGroupName; +}; /*! * \brief Operation to compute 2D mesh on 3D */ -class SMESHGUI_Make2DFrom3DOp : public SMESHGUI_Operation +class SMESHGUI_EXPORT SMESHGUI_Make2DFrom3DOp : public SMESHGUI_SelectionOp { - public: + Q_OBJECT + +public: SMESHGUI_Make2DFrom3DOp(); virtual ~SMESHGUI_Make2DFrom3DOp(); - protected: + virtual LightApp_Dialog* dlg() const; + +protected: virtual void startOperation(); + virtual void selectionDone(); + virtual SUIT_SelectionFilter* createFilter( const int ) const; + bool isValid( QString& ) const; + +protected slots: + virtual bool onApply(); - private: +private: bool compute2DMesh(); - private: - SMESH::SMESH_Mesh_var myMesh; - QPointer myDlg; +private: + SMESH::SMESH_IDSource_var mySrc; + QPointer myDlg; }; #endif // SMESHGUI_Make2DFrom3DOp_H diff --git a/src/SMESHGUI/SMESHGUI_MeshUtils.cxx b/src/SMESHGUI/SMESHGUI_MeshUtils.cxx index 0763be3ed..bf53ecd7f 100644 --- a/src/SMESHGUI/SMESHGUI_MeshUtils.cxx +++ b/src/SMESHGUI/SMESHGUI_MeshUtils.cxx @@ -82,4 +82,44 @@ namespace SMESH } return baseName; } + + QString UniqueName(const QString& theBaseName, _PTR(SObject) theParent, const QString& thePostfix) + { + QString baseName = thePostfix.isEmpty() ? + theBaseName : theBaseName + "_" + thePostfix; + QString name = baseName; + if ( _PTR(Study) aStudy = GetActiveStudyDocument() ) { + _PTR(SObject) p = theParent; + if ( !p ) p = aStudy->FindComponent( "SMESH" ); + if ( p ) { + _PTR(ChildIterator) iter = aStudy->NewChildIterator( p ); + int idx = 0; + while( true ) { + bool found = false; + for ( ; iter->More(); iter->Next() ) { + _PTR(SObject) so = iter->Value(); + if ( !so ) continue; // skip bad objects + _PTR(SObject) ref; + if ( so->ReferencedObject( ref ) ) continue; // skip references + QString n = so->GetName().c_str(); + if ( !n.isEmpty() && n == name ) { + QStringList names = name.split("_", QString::KeepEmptyParts); + if ( names.count() > 0 ) { + bool ok; + names.last().toInt( &ok ); + if ( ok ) + names.removeLast(); + } + names.append( QString::number( ++idx ) ); + name = names.join( "_" ); + found = true; + break; + } + } + if ( !found ) break; + } + } + } + return name; + } } // end of namespace SMESH diff --git a/src/SMESHGUI/SMESHGUI_MeshUtils.h b/src/SMESHGUI/SMESHGUI_MeshUtils.h index 5edffe9f3..5a959cb39 100644 --- a/src/SMESHGUI/SMESHGUI_MeshUtils.h +++ b/src/SMESHGUI/SMESHGUI_MeshUtils.h @@ -36,10 +36,15 @@ // SALOME GUI includes #include +// SALOME KERNEL includes +#include + // IDL includes #include #include CORBA_SERVER_HEADER(SMESH_Mesh) +class SALOMEDSClient_SObject; + namespace SMESH { SMESHGUI_EXPORT @@ -47,6 +52,8 @@ namespace SMESH SMESHGUI_EXPORT QString UniqueMeshName( const QString&, const QString& = QString() ); + SMESHGUI_EXPORT + QString UniqueName( const QString&, _PTR(SObject) = _PTR(SObject)(), const QString& = QString() ); } #endif // SMESHGUI_MESHUTILS_H diff --git a/src/SMESHGUI/SMESH_msg_en.ts b/src/SMESHGUI/SMESH_msg_en.ts index d3482c48b..68e5b8a55 100644 --- a/src/SMESHGUI/SMESH_msg_en.ts +++ b/src/SMESHGUI/SMESH_msg_en.ts @@ -5257,4 +5257,78 @@ It is impossible to read point coordinates from file Construct group with newly created elements + + SMESHGUI_CopyMeshDlg + + CAPTION + Copy mesh elements + + + MESH + Mesh, submesh or group + + + MODE + Mode + + + 2D_FROM_3D + 2D from 3D + + + 1D_FROM_3D + 1D from 3D + + + 1D_FROM_2D + 1D from 2D + + + TARGET + Target + + + THIS_MESH + This mesh + + + NEW_MESH + New mesh + + + COPY_SRC + Copy source mesh + + + MISSING_ONLY + Copy missing elements only + + + CREATE_GROUP + Create group + + + + SMESHGUI_Make2DFrom3DOp + + SMESH_ERR_NO_INPUT_MESH + Source mesh, sub-mesh or group is not specified + + + SMESH_ERR_NO_3D_ELEMENTS + The source object does not contain 3D elements + + + SMESH_ERR_NO_2D_ELEMENTS + The source object does not contain 2D elements + + + SMESH_ERR_MESH_NAME_NOT_SPECIFIED + New mesh name is not specified + + + SMESH_ERR_GRP_NAME_NOT_SPECIFIED + Group name is not specified + + -- 2.39.2