//
// 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 <LightApp_SelectionMgr.h>
-
+#include <LightApp_UpdateFlags.h>
+#include <SalomeApp_Tools.h>
+#include <SalomeApp_Study.h>
#include <SUIT_Desktop.h>
#include <SUIT_MessageBox.h>
-#include <SUIT_ResourceMgr.h>
#include <SUIT_OverrideCursor.h>
-#include <SALOME_ListIO.hxx>
-
-// SALOME KERNEL includes
-#include <SALOMEDS_SObject.hxx>
-#include <SALOMEDSClient_SObject.hxx>
-
-// Qt includes
// IDL includes
#include <SALOMEconfig.h>
-#include CORBA_SERVER_HEADER(SMESH_Gen)
-#include CORBA_SERVER_HEADER(SMESH_MeshEditor)
+#include CORBA_SERVER_HEADER(SMESH_Group)
-#include <QFrame>
-#include <QLabel>
-#include <QPixmap>
+// Qt includes
#include <QGroupBox>
-#include <QPushButton>
-#include <QVBoxLayout>
-
-// MESH includes
-#include "SMDSAbs_ElementType.hxx"
-#include "SMDSAbs_ElementType.hxx"
-
+#include <QRadioButton>
+#include <QLineEdit>
+#include <QCheckBox>
+#include <QHBoxLayout>
+#include <QGridLayout>
#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<SUIT_SelectionFilter*> 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<SMESH::SMESH_IDSource>( 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<SMESH::SMESH_IDSource>( 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;
}