020749: EDF 1291 SMESH : Create 2D Mesh from 3D improvement

for note 0010000
This commit is contained in:
eap 2011-03-11 10:18:32 +00:00
parent d7491a9906
commit a619563bc7
6 changed files with 223 additions and 243 deletions

Binary file not shown.

Before

Width:  |  Height:  |  Size: 21 KiB

After

Width:  |  Height:  |  Size: 17 KiB

View File

@ -7,6 +7,7 @@ elements of a higher dimension.
<em>To generate border elements:</em> <em>To generate border elements:</em>
<ol> <ol>
<li>Select a mesh in the Object Browser or in the 3D Viewer</li>
<li>From the Modification menu choose "Create boundary elements" <li>From the Modification menu choose "Create boundary elements"
item, or click "Create boundary elements" button in the toolbar item, or click "Create boundary elements" button in the toolbar
@ -26,31 +27,27 @@ of three types.
<ul> <ul>
<li><b>2D from 3D</b> creates mesh faces on free facets of volume elements</li> <li><b>2D from 3D</b> creates mesh faces on free facets of volume elements</li>
<li><b>1D from 2D</b> creates mesh edges on free edges of mesh faces</li> <li><b>1D from 2D</b> creates mesh edges on free edges of mesh faces</li>
<li><b>1D from 3D</b> creates mesh edges on all borders of free facets of volume elements</li> <li><b>1D from 2D groups</b> creates mesh edges on borders of groups of faces</li>
</ul> </ul>
Here a <em>free facet</em> means a facet shared by only one volume, a <em>free edge</em> Here a <em>free facet</em> means a facet shared by only one volume, a <em>free edge</em>
means an edge shared by only one mesh face. means an edge shared by only one mesh face.
In this dialog: In this dialog:
<ul> <ul>
<li>specify the <b>Mesh, submesh or group</b>, the boundary which of <li>specify the <b>2D groups</b> on borders of which the edges will be
will be analyzed.</li> generated (if <b>1D from 2D groups</b> is selected).</li>
<li>specify the <b>Target</b> mesh, where the boundary elements will <li>specify the <b>Target</b> mesh, where the boundary elements will
be created. be created.
<ul> <ul>
<li><b>This mesh</b> adds elements in the selected mesh or the mesh <li><b>This mesh</b> adds elements in the selected mesh.</li>
the selected submesh or group belongs to.</li>
<li><b>New mesh</b> adds elements to a new mesh. The new mesh appears <li><b>New mesh</b> adds elements to a new mesh. The new mesh appears
in the Object Browser with the name that you can change in the adjacent box. </li> in the Object Browser with the name that you can change in the adjacent box. </li>
</ul></li> </ul></li>
<li>activate <b>Copy source mesh</b> checkbox to copy 2D or 3D <li>activate <b>Copy source mesh</b> checkbox to copy all elements of
elements (depending on the operation type), which belong to the analyzed the selected mesh to the new mesh, else the new mesh will contain only
<b>Mesh, submesh or group</b> field, to the new mesh.</li> boundary elements (old and created by this operation).</li>
<li>deactivate <b>Copy missing elements only</b> checkbox to copy <li>activate <b>Create group</b> checkbox to create a group to which
boundary elements already present in the analyzed mesh to the all the boundary elements (old and new) are added. The new group appears
new mesh.</li>
<li>activate <b>Create group</b> checkbox to create a group to which the
missing boundary elements are added. The new group appears
in the Object Browser with the name that you can change in the adjacent box. </li> in the Object Browser with the name that you can change in the adjacent box. </li>
</ul> </ul>
<br><b>See Also</b> a sample TUI Script of a \ref tui_make_2dmesh_from_3d "Create boundary elements" operation. <br><b>See Also</b> a sample TUI Script of a \ref tui_make_2dmesh_from_3d "Create boundary elements" operation.

View File

@ -426,162 +426,111 @@ if salome.sg.hasDesktop():
<h3>Create boundary elements</h3> <h3>Create boundary elements</h3>
\code \code
# The objective of these samples is to illustrate the following use cases:
# 1) The mesh MESH1 with 3D cells has no or only a part of its skin (2D cells):
# 1.1) Add the 2D skin (missing 2D cells) to MESH1 (what is done now by the algorithm).
# 1.2) Create a new 3D Mesh MESH2 that consists of MESH1 and added 2D skin cells.
# 1.3) Create a new 2D Mesh MESH3 that consists only of 2D skin cells.
# 2) The mesh MESH1 with 3D cells has all its skin (2D cells):
# Create a new 2D Mesh MESH3 that consists only of 2D skin cells.
#
# In all cases an option to create a group containing these 2D skin cells is available.
from smesh import * from smesh import *
SetCurrentStudy(salome.myStudy)
box = geompy.MakeBoxDXDYDZ(1,1,1) box = geompy.MakeBoxDXDYDZ(100, 100, 100)
gFaces = geompy.SubShapeAllSorted(box, geompy.ShapeType["FACE"])
f1,f2 = gFaces[0],gFaces[1]
geompy.addToStudy(box,"box") geompy.addToStudy(box,"box")
boxFace = geompy.SubShapeAll(box, geompy.ShapeType["FACE"])[0] geompy.addToStudyInFather(box,f1,"face1")
geompy.addToStudyInFather(box,boxFace,"boxFace") geompy.addToStudyInFather(box,f2,"face2")
MESH1 = Mesh(box,"MESH1") twoFaces = geompy.MakeCompound([f1,f2])
MESH1.AutomaticHexahedralization()
init_nb_edges = MESH1.NbEdges() ## -----------
init_nb_faces = MESH1.NbFaces() ##
init_nb_volumes = MESH1.NbVolumes() ## 2D from 3D
##
## -----------
dim = SMESH.BND_2DFROM3D
init_mesh = Mesh(box, "box")
init_mesh.AutomaticHexahedralization() # it makes 3 x 3 x 3 hexahedrons
# =========================================================================================
# 1) The mesh MESH1 with 3D cells has no or only a part of its skin (2D cells)
# =========================================================================================
# remove some faces # remove some faces
all_faces = MESH1.GetElementsByType(SMESH.FACE) faces = init_mesh.GetElementsByType( SMESH.FACE )
rm_faces = all_faces[:init_nb_faces/5] + all_faces[4*init_nb_faces/5:] nb_faces = len( faces )
MESH1.RemoveElements(rm_faces) rm_face = faces[ : nb_faces/2]
assert(MESH1.NbFaces() == init_nb_faces-len(rm_faces)) init_mesh.RemoveElements( rm_face )
# 1.1) Add the 2D skin (missing 2D cells) to MESH1 # restore boundary in this mesh
# ------------------------------------------------- mesh = CopyMesh( init_mesh, "2D from 3D")
# add missing faces groupName = "bnd 2D"
# 1.1.1) to the whole mesh nb, new_mesh, new_group = mesh.MakeBoundaryElements(dim, groupName)
m,g = MESH1.MakeBoundaryMesh(MESH1)
assert(init_nb_faces == MESH1.NbFaces())
assert(init_nb_edges == MESH1.NbEdges())
assert(m)
assert(not g)
# 1.1.2) to some elements # restore boundary (only) in other mesh
MESH1.RemoveElements(rm_faces) meshName = "2D boundary of " + init_mesh.GetName()
MESH1.MakeBoundaryMesh([]) nb, new_mesh, new_group = init_mesh.MakeBoundaryElements(dim, groupName, meshName)
assert(init_nb_faces != MESH1.NbFaces())
volumes = MESH1.GetElementsByType(SMESH.VOLUME)
for v in volumes:
MESH1.MakeBoundaryMesh([v])
assert(init_nb_faces == MESH1.NbFaces())
assert(init_nb_edges == MESH1.NbEdges())
# 1.1.3) to a group of elements # restore boundary in mesh copy
volGroup1 = MESH1.CreateEmptyGroup(SMESH.VOLUME, "volGroup1") meshName = init_mesh.GetName() + " + boundary"
volGroup1.Add( volumes[: init_nb_volumes/2]) nb, new_mesh, new_group = init_mesh.MakeBoundaryElements(dim, groupName, meshName, toCopyAll=True)
volGroup2 = MESH1.CreateEmptyGroup(SMESH.VOLUME, "volGroup2")
volGroup1.Add( volumes[init_nb_volumes/2:])
MESH1.RemoveElements(rm_faces)
MESH1.MakeBoundaryMesh(volGroup1)
MESH1.MakeBoundaryMesh(volGroup2)
assert(init_nb_faces == MESH1.NbFaces())
assert(init_nb_edges == MESH1.NbEdges())
# 1.1.4) to a submesh.
# The submesh has no volumes, so it is required to check if it passes without crash and does not create
# missing faces
faceSubmesh = MESH1.GetSubMesh( boxFace, "boxFace" )
MESH1.RemoveElements(rm_faces)
MESH1.MakeBoundaryMesh(faceSubmesh)
assert(init_nb_faces != MESH1.NbFaces())
# check group creation
MESH1.RemoveElements(rm_faces)
groupName = "added to mesh"
m,group = MESH1.MakeBoundaryMesh(MESH1,groupName=groupName)
assert(group)
assert(group.GetName() == groupName)
assert(group.Size() == len(rm_faces))
# 1.2) Create a new 3D Mesh MESH2 that consists of MESH1 and added 2D skin cells. ## -----------
# ------------------------------------------------------------------------------ ##
MESH1.RemoveElements(rm_faces) ## 1D from 2D
meshName = "MESH2" ##
MESH2,group = MESH1.MakeBoundaryMesh(MESH1,meshName=meshName,toCopyElements=True) ## -----------
assert(MESH2) dim = SMESH.BND_1DFROM2D
assert(MESH2.GetName() == meshName)
assert(MESH2.NbVolumes() == MESH1.NbVolumes())
assert(MESH2.NbFaces() == len(rm_faces))
# check group creation init_mesh = Mesh(f1, "2D mesh")
MESH1.RemoveElements(rm_faces) init_mesh.AutomaticHexahedralization()
MESH2,group = MESH1.MakeBoundaryMesh(MESH1,meshName="MESH2_0",
groupName=groupName,toCopyElements=True)
assert(group)
assert(group.GetName() == groupName)
assert(group.Size() == len(rm_faces))
assert(group.GetMesh()._is_equivalent(MESH2.GetMesh()))
# 1.3) Create a new 2D Mesh MESH3 that consists only of 2D skin cells. # remove some edges
# ----------------------------------------------------------------------- edges = init_mesh.GetElementsByType( SMESH.EDGE )
MESH1.RemoveElements(rm_faces) nb_edges = len( edges )
meshName = "MESH3" rm_edge = edges[ : nb_edges/2]
MESH3,group = MESH1.MakeBoundaryMesh(MESH1,meshName=meshName,toCopyExistingBondary=True) init_mesh.RemoveElements( rm_edge )
assert(MESH3)
assert(not group)
assert(MESH3.GetName() == meshName)
assert(MESH3.NbVolumes() == 0)
assert(MESH3.NbFaces() == init_nb_faces)
# check group creation
MESH1.RemoveElements(rm_faces)
MESH3,group = MESH1.MakeBoundaryMesh(MESH1,meshName=meshName,
groupName=groupName, toCopyExistingBondary=True)
assert(group)
assert(group.GetName() == groupName)
assert(group.Size() == len(rm_faces))
assert(group.GetMesh()._is_equivalent(MESH3.GetMesh()))
assert(MESH3.NbFaces() == init_nb_faces)
# ================================================================== # restore boundary edges in this mesh
# 2) The mesh MESH1 with 3D cells has all its skin (2D cells) mesh = CopyMesh( init_mesh, "1D from 2D")
# Create a new 2D Mesh MESH3 that consists only of 2D skin cells. groupName = "bnd 1D"
# ================================================================== nb, new_mesh, new_group = mesh.MakeBoundaryElements(dim, groupName)
MESH1.MakeBoundaryMesh(MESH1)
MESH3,group = MESH1.MakeBoundaryMesh(MESH1,meshName=meshName,toCopyExistingBondary=True)
assert(MESH3)
assert(not group)
assert(MESH3.NbVolumes() == 0)
assert(MESH3.NbFaces() == init_nb_faces)
# check group creation # restore boundary edges (only) in other mesh
MESH3,group = MESH1.MakeBoundaryMesh(MESH1,meshName=meshName, meshName = "1D boundary of " + init_mesh.GetName()
groupName=groupName, toCopyExistingBondary=True) nb, new_mesh, new_group = init_mesh.MakeBoundaryElements(dim, groupName, meshName)
assert(group)
assert(group.GetName() == groupName)
assert(group.Size() == 0)
assert(group.GetMesh()._is_equivalent(MESH3.GetMesh()))
assert(MESH3.NbFaces() == init_nb_faces)
# ================ # restore boundary edges in mesh copy
# Make 1D from 2D meshName = init_mesh.GetName() + " + boundary"
# ================ nb, new_mesh, new_group = init_mesh.MakeBoundaryElements(dim, groupName, meshName, toCopyAll=True)
MESH1.Clear()
MESH1.Compute()
MESH1.RemoveElements( MESH1.GetElementsByType(SMESH.EDGE))
rm_faces = faceSubmesh.GetIDs()[:2] # to remove few adjacent faces
nb_missing_edges = 2 + 2*len(rm_faces)
MESH1.RemoveElements(rm_faces) ## ------------------
mesh,group = MESH1.MakeBoundaryMesh(MESH1, BND_1DFROM2D) ##
assert( MESH1.NbEdges() == nb_missing_edges ) ## 1D from 2D GROUPS
##
## ------------------
dim = SMESH.BND_1DFROM3D
init_mesh = Mesh(box, "box")
init_mesh.AutomaticHexahedralization() # it makes 3 x 3 x 3 hexahedrons
# remove all edges
rm_edges = init_mesh.GetElementsByType( SMESH.EDGE )
init_mesh.RemoveElements( rm_edges )
# make groups of faces
fGroup1 = init_mesh.Group( f1, "f1" )
fGroup2 = init_mesh.Group( f2, "f2" )
# make 1D boundary around groups in this mesh
mesh = CopyMesh( init_mesh, "1D from 2D groups", toCopyGroups=True)
groups = mesh.GetGroups()
nb, new_mesh, new_group = mesh.MakeBoundaryElements(dim, groupName,groups=groups)
# make 1D boundary (only) in other mesh
meshName = "boundary from groups of " + init_mesh.GetName()
groups = init_mesh.GetGroups()
nb, new_mesh, new_group = init_mesh.MakeBoundaryElements(dim, groupName, meshName,groups=groups)
# make 1D boundary in mesh copy
meshName = init_mesh.GetName() + " + boundary from groups"
nb, new_mesh, new_group = init_mesh.MakeBoundaryElements(dim, groupName, meshName,
groups=groups, toCopyAll=True)
\endcode \endcode
*/ */

View File

@ -28,12 +28,15 @@
#include "SMESH_LogicalFilter.hxx" #include "SMESH_LogicalFilter.hxx"
// SALOME GUI includes // SALOME GUI includes
#include <LightApp_SelectionMgr.h>
#include <LightApp_UpdateFlags.h> #include <LightApp_UpdateFlags.h>
#include <SalomeApp_Tools.h> #include <SALOME_ListIO.hxx>
#include <SalomeApp_Study.h>
#include <SUIT_Desktop.h> #include <SUIT_Desktop.h>
#include <SUIT_MessageBox.h> #include <SUIT_MessageBox.h>
#include <SUIT_OverrideCursor.h> #include <SUIT_OverrideCursor.h>
#include <SVTK_ViewModel.h>
#include <SalomeApp_Study.h>
#include <SalomeApp_Tools.h>
// IDL includes // IDL includes
#include <SALOMEconfig.h> #include <SALOMEconfig.h>
@ -46,6 +49,7 @@
#include <QCheckBox> #include <QCheckBox>
#include <QHBoxLayout> #include <QHBoxLayout>
#include <QGridLayout> #include <QGridLayout>
#include <QToolButton>
#define SPACING 6 #define SPACING 6
#define MARGIN 11 #define MARGIN 11
@ -56,15 +60,11 @@
*/ */
SMESHGUI_Make2DFrom3DDlg::SMESHGUI_Make2DFrom3DDlg( QWidget* parent ) SMESHGUI_Make2DFrom3DDlg::SMESHGUI_Make2DFrom3DDlg( QWidget* parent )
: SMESHGUI_Dialog( parent, false, true, OK | Apply | Close | Help ) : SMESHGUI_Dialog( parent, false, true, OK | Apply | Close | Help )
{ {
// title // title
setWindowTitle( tr("CAPTION") ); setWindowTitle( tr("CAPTION") );
// mesh
setObjectPixmap( "SMESH", tr( "ICON_SELECT" ) );
createObject( tr( "MESH" ), mainFrame(), Mesh );
// mode // mode
QGroupBox* aModeGrp = new QGroupBox( tr( "MODE" ), mainFrame() ); QGroupBox* aModeGrp = new QGroupBox( tr( "MODE" ), mainFrame() );
QHBoxLayout* aModeGrpLayout = new QHBoxLayout( aModeGrp ); QHBoxLayout* aModeGrpLayout = new QHBoxLayout( aModeGrp );
@ -77,6 +77,12 @@ SMESHGUI_Make2DFrom3DDlg::SMESHGUI_Make2DFrom3DDlg( QWidget* parent )
aModeGrpLayout->addWidget( my1dFrom2dRB ); aModeGrpLayout->addWidget( my1dFrom2dRB );
aModeGrpLayout->addWidget( my1dFrom3dRB ); aModeGrpLayout->addWidget( my1dFrom3dRB );
// Groups of mesh faces
setObjectPixmap( "SMESH", tr( "ICON_SELECT" ) );
createObject( tr( "Groups" ), mainFrame(), Groups );
setNameIndication( Groups, ListOfNames );
objectWg( Groups, Btn )->hide();
// target // target
QGroupBox* aTargetGrp = new QGroupBox( tr( "TARGET" ), mainFrame() ); QGroupBox* aTargetGrp = new QGroupBox( tr( "TARGET" ), mainFrame() );
QGridLayout* aTargetGrpLayout = new QGridLayout( aTargetGrp ); QGridLayout* aTargetGrpLayout = new QGridLayout( aTargetGrp );
@ -86,12 +92,10 @@ SMESHGUI_Make2DFrom3DDlg::SMESHGUI_Make2DFrom3DDlg( QWidget* parent )
myNewMeshRB = new QRadioButton( tr( "NEW_MESH" ), aTargetGrp ); myNewMeshRB = new QRadioButton( tr( "NEW_MESH" ), aTargetGrp );
myMeshName = new QLineEdit( aTargetGrp ); myMeshName = new QLineEdit( aTargetGrp );
myCopyCheck = new QCheckBox( tr( "COPY_SRC" ), aTargetGrp ); myCopyCheck = new QCheckBox( tr( "COPY_SRC" ), aTargetGrp );
myMissingCheck = new QCheckBox( tr( "MISSING_ONLY" ), aTargetGrp );
aTargetGrpLayout->addWidget( myThisMeshRB, 0, 0 ); aTargetGrpLayout->addWidget( myThisMeshRB, 0, 0 );
aTargetGrpLayout->addWidget( myNewMeshRB, 1, 0 ); aTargetGrpLayout->addWidget( myNewMeshRB, 1, 0 );
aTargetGrpLayout->addWidget( myMeshName, 1, 1 ); aTargetGrpLayout->addWidget( myMeshName, 1, 1 );
aTargetGrpLayout->addWidget( myCopyCheck, 2, 0 ); aTargetGrpLayout->addWidget( myCopyCheck, 2, 0 );
aTargetGrpLayout->addWidget( myMissingCheck, 2, 1 );
myGroupCheck = new QCheckBox( tr( "CREATE_GROUP" ), mainFrame() ); myGroupCheck = new QCheckBox( tr( "CREATE_GROUP" ), mainFrame() );
myGroupName = new QLineEdit( mainFrame() ); myGroupName = new QLineEdit( mainFrame() );
@ -99,10 +103,9 @@ SMESHGUI_Make2DFrom3DDlg::SMESHGUI_Make2DFrom3DDlg( QWidget* parent )
QGridLayout* aDlgLay = new QGridLayout( mainFrame() ); QGridLayout* aDlgLay = new QGridLayout( mainFrame() );
aDlgLay->setMargin( 0 ); aDlgLay->setMargin( 0 );
aDlgLay->setSpacing( SPACING ); aDlgLay->setSpacing( SPACING );
aDlgLay->addWidget( objectWg( Mesh, Label ), 0, 0 ); aDlgLay->addWidget( aModeGrp, 0, 0, 1, 3 );
aDlgLay->addWidget( objectWg( Mesh, Btn ), 0, 1 ); aDlgLay->addWidget( objectWg( Groups, Label ), 1, 0 );
aDlgLay->addWidget( objectWg( Mesh, Control ), 0, 2 ); aDlgLay->addWidget( objectWg( Groups, Control ), 1, 1 );
aDlgLay->addWidget( aModeGrp, 1, 0, 1, 3 );
aDlgLay->addWidget( aTargetGrp, 2, 0, 1, 3 ); aDlgLay->addWidget( aTargetGrp, 2, 0, 1, 3 );
aDlgLay->addWidget( myGroupCheck, 3, 0 ); aDlgLay->addWidget( myGroupCheck, 3, 0 );
aDlgLay->addWidget( myGroupName, 3, 1, 1, 2 ); aDlgLay->addWidget( myGroupName, 3, 1, 1, 2 );
@ -115,7 +118,6 @@ SMESHGUI_Make2DFrom3DDlg::SMESHGUI_Make2DFrom3DDlg( QWidget* parent )
// init dlg // init dlg
my2dFrom3dRB->setChecked( true ); my2dFrom3dRB->setChecked( true );
myThisMeshRB->setChecked( true ); myThisMeshRB->setChecked( true );
myMissingCheck->setChecked( true );
onTargetChanged(); onTargetChanged();
onGroupChecked(); onGroupChecked();
} }
@ -169,16 +171,10 @@ bool SMESHGUI_Make2DFrom3DDlg::copySource() const
return myCopyCheck->isChecked(); return myCopyCheck->isChecked();
} }
bool SMESHGUI_Make2DFrom3DDlg::copyMissingOnly() const
{
return myMissingCheck->isChecked();
}
void SMESHGUI_Make2DFrom3DDlg::onTargetChanged() void SMESHGUI_Make2DFrom3DDlg::onTargetChanged()
{ {
myMeshName->setEnabled( myNewMeshRB->isChecked() ); myMeshName->setEnabled( myNewMeshRB->isChecked() );
myCopyCheck->setEnabled( myNewMeshRB->isChecked() ); myCopyCheck->setEnabled( myNewMeshRB->isChecked() );
myMissingCheck->setEnabled( myNewMeshRB->isChecked() );
} }
void SMESHGUI_Make2DFrom3DDlg::onGroupChecked() void SMESHGUI_Make2DFrom3DDlg::onGroupChecked()
@ -212,33 +208,61 @@ void SMESHGUI_Make2DFrom3DOp::startOperation()
if( !myDlg ) if( !myDlg )
myDlg = new SMESHGUI_Make2DFrom3DDlg( desktop() ); myDlg = new SMESHGUI_Make2DFrom3DDlg( desktop() );
mySrc = SMESH::SMESH_IDSource::_nil();
myHelpFileName = "make_2dmesh_from_3d_page.html"; myHelpFileName = "make_2dmesh_from_3d_page.html";
SMESHGUI_SelectionOp::startOperation(); SMESHGUI_SelectionOp::startOperation();
myDlg->activateObject( SMESHGUI_Make2DFrom3DDlg::Mesh );
myDlg->setNewMeshName( SMESH::UniqueName( "Mesh_1" ) ); myDlg->setNewMeshName( SMESH::UniqueName( "Mesh_1" ) );
myDlg->setGroupName( SMESH::UniqueName( "Group" ) ); myDlg->setGroupName( SMESH::UniqueName( "Group" ) );
myDlg->show(); myDlg->show();
selectionDone(); connect( myDlg->my2dFrom3dRB, SIGNAL( toggled(bool) ), this, SLOT( onModeChanged() ) );
connect( myDlg->my1dFrom2dRB, SIGNAL( toggled(bool) ), this, SLOT( onModeChanged() ) );
connect( myDlg->my1dFrom3dRB, SIGNAL( toggled(bool) ), this, SLOT( onModeChanged() ) );
onModeChanged();
}
void SMESHGUI_Make2DFrom3DOp::onModeChanged()
{
QRadioButton* b = dynamic_cast<QRadioButton*>( sender());
if ( b && !b->isChecked() )
return;
// enable "2D groups" field
bool enableGroups = ( myDlg->mode() == SMESH::BND_1DFROM3D );
myDlg->setObjectEnabled( SMESHGUI_Make2DFrom3DDlg::Groups, enableGroups );
((QToolButton*) myDlg->objectWg( SMESHGUI_Make2DFrom3DDlg::Groups,
SMESHGUI_Make2DFrom3DDlg::Btn ))->setChecked( enableGroups );
// install filter
int id = enableGroups ? SMESHGUI_Make2DFrom3DDlg::Groups : SMESHGUI_Make2DFrom3DDlg::Mesh;
onDeactivateObject( id );
onActivateObject( id );
} }
void SMESHGUI_Make2DFrom3DOp::selectionDone() void SMESHGUI_Make2DFrom3DOp::selectionDone()
{ {
mySrcMesh = SMESH::SMESH_Mesh::_nil();
myDlg->clearSelection( SMESHGUI_Make2DFrom3DDlg::Groups );
if ( !dlg() ) return; if ( !dlg() ) return;
if ( dlg()->isVisible() ) { if ( dlg()->isVisible() ) {
try { try {
QStringList names, ids; QStringList names, ids;
LightApp_Dialog::TypesList types; LightApp_Dialog::TypesList types;
selected( names, types, ids ); selected( names, types, ids );
if ( names.count() == 1 ) myDlg->selectObject( names, types, ids );
myDlg->selectObject( names, types, ids );
else SALOME_ListIO sel; selectionMgr()->selectedObjects( sel, SVTK_Viewer::Type() );
myDlg->clearSelection(); if ( !sel.IsEmpty() )
{
SMESH::SMESH_IDSource_var IS = SMESH::IObjectToInterface<SMESH::SMESH_IDSource>(sel.First());
if(!CORBA::is_nil(IS))
mySrcMesh = IS->GetMesh();
}
} }
catch ( const SALOME::SALOME_Exception& S_ex ) { catch ( const SALOME::SALOME_Exception& S_ex ) {
SalomeApp_Tools::QtCatchCorbaException( S_ex ); SalomeApp_Tools::QtCatchCorbaException( S_ex );
@ -250,13 +274,8 @@ void SMESHGUI_Make2DFrom3DOp::selectionDone()
SUIT_SelectionFilter* SMESHGUI_Make2DFrom3DOp::createFilter( const int theId ) const SUIT_SelectionFilter* SMESHGUI_Make2DFrom3DOp::createFilter( const int theId ) const
{ {
SUIT_SelectionFilter* f = 0; MeshObjectType type = ( theId == SMESHGUI_Make2DFrom3DDlg::Groups ? GROUP_FACE : MESH );
if ( theId == SMESHGUI_Make2DFrom3DDlg::Mesh ) { SUIT_SelectionFilter* f = new SMESH_TypeFilter( type );
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; return f;
} }
@ -264,36 +283,43 @@ bool SMESHGUI_Make2DFrom3DOp::isValid( QString& msg ) const
{ {
if ( !dlg() ) return false; if ( !dlg() ) return false;
// check if any source data is selected // check if a mesh is selected
QString entry = myDlg->selectedObject( SMESHGUI_Make2DFrom3DDlg::Mesh ); if ( mySrcMesh->_is_nil() )
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" ); msg = tr( "SMESH_ERR_NO_INPUT_MESH" );
return false; return false;
} }
// check if groups are selected
// check if source contains elements of required type
SMESH::Bnd_Dimension mode = myDlg->mode(); SMESH::Bnd_Dimension mode = myDlg->mode();
SMESH::array_of_ElementType_var types = obj->GetTypes(); if ( mode == SMESH::BND_1DFROM3D )
{
bool has3d = false; SMESH::SMESH_GroupBase_var grp;
bool has2d = false; QStringList entries;
for ( int i = 0; i < types->length(); i++ ) { dlg()->selectedObject( SMESHGUI_Make2DFrom3DDlg::Groups, entries );
if ( types[i] == SMESH::VOLUME ) has3d = true; if ( !entries.isEmpty() )
else if ( types[i] == SMESH::FACE ) has2d = true; {
_PTR(SObject) sobj = SMESHGUI::activeStudy()->studyDS()->FindObjectID( entries[0].toLatin1().constData() );
if ( sobj )
grp = SMESH::SObjectToInterface<SMESH::SMESH_GroupBase>( sobj );
}
if ( grp->_is_nil() ) {
msg = tr( "SMESH_ERR_NO_INPUT_GROUP" );
return false;
}
} }
else
{
// check if mesh contains elements of required type
SMESH::Bnd_Dimension mode = myDlg->mode();
if ( ( mode == SMESH::BND_2DFROM3D || mode == SMESH::BND_1DFROM3D ) && !has3d ) { if ( mode == SMESH::BND_2DFROM3D && mySrcMesh->NbVolumes() == 0 ) {
msg = tr( "SMESH_ERR_NO_3D_ELEMENTS" ); msg = tr( "SMESH_ERR_NO_3D_ELEMENTS" );
return false; return false;
} }
else if ( mode == SMESH::BND_1DFROM2D && !has2d ) { else if ( mode == SMESH::BND_1DFROM2D && mySrcMesh->NbFaces() == 0 ) {
msg = tr( "SMESH_ERR_NO_2D_ELEMENTS" ); msg = tr( "SMESH_ERR_NO_2D_ELEMENTS" );
return false; return false;
}
} }
// check if new mesh name is specified // check if new mesh name is specified
@ -317,41 +343,38 @@ bool SMESHGUI_Make2DFrom3DOp::compute2DMesh()
bool ok = false; bool ok = false;
try { try {
QString entry = myDlg->selectedObject( SMESHGUI_Make2DFrom3DDlg::Mesh ); QStringList entries;
_PTR(SObject) sobj = SMESHGUI::activeStudy()->studyDS()->FindObjectID( entry.toLatin1().constData() ); dlg()->selectedObject( SMESHGUI_Make2DFrom3DDlg::Groups, entries );
SMESH::SMESH_IDSource_var obj = SMESH::SObjectToInterface<SMESH::SMESH_IDSource>( sobj ); SMESH::ListOfIDSources_var groups = new SMESH::ListOfIDSources;
groups->length( entries.count() );
for ( int i = 0; i < entries.count(); ++i )
{
_PTR(SObject) sobj = SMESHGUI::activeStudy()->studyDS()->FindObjectID( entries[i].toLatin1().constData() );
SMESH::SMESH_IDSource_var grp = SMESH::SObjectToInterface<SMESH::SMESH_IDSource>( sobj );
groups[i] = grp;
}
SMESH::Bnd_Dimension mode = myDlg->mode(); SMESH::Bnd_Dimension mode = myDlg->mode();
QString meshName = myDlg->needNewMesh() ? myDlg->getNewMeshName() : QString(); QString meshName = myDlg->needNewMesh() ? myDlg->getNewMeshName() : QString();
QString groupName = myDlg->needGroup() ? myDlg->getGroupName() : QString(); QString groupName = myDlg->needGroup() ? myDlg->getGroupName() : QString();
bool copySrc = myDlg->copySource(); bool copyAll = myDlg->copySource();
bool copyAll = !myDlg->copyMissingOnly();
SMESH::SMESH_Mesh_var srcMesh = SMESH::SMESH_Mesh::_narrow( obj ); if ( !CORBA::is_nil( mySrcMesh ) ) {
if ( CORBA::is_nil( srcMesh ) ) { SMESH::SMESH_MeshEditor_var aMeshEditor = mySrcMesh->GetMeshEditor();
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_Group_var newGrp;
SMESH::SMESH_Mesh_var mesh = aMeshEditor->MakeBoundaryMesh( obj.in(), SMESH::SMESH_Mesh_var newMesh;
mode, CORBA::Long nbAdded = aMeshEditor->MakeBoundaryElements( mode,
groupName.toLatin1().constData(), groupName.toLatin1().constData(),
meshName.toLatin1().constData(), meshName.toLatin1().constData(),
copySrc, copyAll,
copyAll, groups,
newGrp.out() ); newMesh.out(),
if ( !mesh->_is_nil() ) { newGrp.out() );
SUIT_MessageBox::information( myDlg,
tr("SMESH_INFORMATION"),
tr("NB_ADDED").arg( nbAdded ));
if ( !newMesh->_is_nil() ) {
#ifdef WITHGENERICOBJ #ifdef WITHGENERICOBJ
mesh->UnRegister(); newMesh->UnRegister();
#endif #endif
} }
if ( !newGrp->_is_nil() ) { if ( !newGrp->_is_nil() ) {

View File

@ -29,10 +29,12 @@
#include <SALOMEconfig.h> #include <SALOMEconfig.h>
#include CORBA_SERVER_HEADER(SMESH_MeshEditor) #include CORBA_SERVER_HEADER(SMESH_MeshEditor)
#include CORBA_SERVER_HEADER(SMESH_Mesh)
class QCheckBox; class QCheckBox;
class QLineEdit; class QLineEdit;
class QRadioButton; class QRadioButton;
class SMESHGUI_Make2DFrom3DOp;
/*! /*!
* \brief Dialog to show result mesh statistic * \brief Dialog to show result mesh statistic
@ -43,7 +45,7 @@ class SMESHGUI_EXPORT SMESHGUI_Make2DFrom3DDlg : public SMESHGUI_Dialog
Q_OBJECT Q_OBJECT
public: public:
enum { Mesh }; enum { Mesh, Groups };
SMESHGUI_Make2DFrom3DDlg( QWidget* ); SMESHGUI_Make2DFrom3DDlg( QWidget* );
virtual ~SMESHGUI_Make2DFrom3DDlg(); virtual ~SMESHGUI_Make2DFrom3DDlg();
@ -59,7 +61,6 @@ public:
void setGroupName( const QString& ); void setGroupName( const QString& );
bool copySource() const; bool copySource() const;
bool copyMissingOnly() const;
private slots: private slots:
void onTargetChanged(); void onTargetChanged();
@ -73,9 +74,10 @@ private:
QRadioButton* myNewMeshRB; QRadioButton* myNewMeshRB;
QLineEdit* myMeshName; QLineEdit* myMeshName;
QCheckBox* myCopyCheck; QCheckBox* myCopyCheck;
QCheckBox* myMissingCheck;
QCheckBox* myGroupCheck; QCheckBox* myGroupCheck;
QLineEdit* myGroupName; QLineEdit* myGroupName;
friend class SMESHGUI_Make2DFrom3DOp;
}; };
/*! /*!
@ -100,12 +102,13 @@ protected:
protected slots: protected slots:
virtual bool onApply(); virtual bool onApply();
void onModeChanged();
private: private:
bool compute2DMesh(); bool compute2DMesh();
private: private:
SMESH::SMESH_IDSource_var mySrc; SMESH::SMESH_Mesh_var mySrcMesh;
QPointer<SMESHGUI_Make2DFrom3DDlg> myDlg; QPointer<SMESHGUI_Make2DFrom3DDlg> myDlg;
}; };

View File

@ -5589,8 +5589,8 @@ It is impossible to read point coordinates from file</translation>
<translation>Create boundary elements</translation> <translation>Create boundary elements</translation>
</message> </message>
<message> <message>
<source>MESH</source> <source>Groups</source>
<translation>Mesh, submesh or group</translation> <translation>2D groups</translation>
</message> </message>
<message> <message>
<source>MODE</source> <source>MODE</source>
@ -5602,7 +5602,7 @@ It is impossible to read point coordinates from file</translation>
</message> </message>
<message> <message>
<source>1D_FROM_3D</source> <source>1D_FROM_3D</source>
<translation>1D from 3D</translation> <translation>1D from 2D groups</translation>
</message> </message>
<message> <message>
<source>1D_FROM_2D</source> <source>1D_FROM_2D</source>
@ -5635,9 +5635,17 @@ It is impossible to read point coordinates from file</translation>
</context> </context>
<context> <context>
<name>SMESHGUI_Make2DFrom3DOp</name> <name>SMESHGUI_Make2DFrom3DOp</name>
<message>
<source>NB_ADDED</source>
<translation>%1 boundary elements have been added</translation>
</message>
<message> <message>
<source>SMESH_ERR_NO_INPUT_MESH</source> <source>SMESH_ERR_NO_INPUT_MESH</source>
<translation>Source mesh, sub-mesh or group is not specified</translation> <translation>Source mesh is not specified</translation>
</message>
<message>
<source>SMESH_ERR_NO_INPUT_GROUP</source>
<translation>2D group is not specified</translation>
</message> </message>
<message> <message>
<source>SMESH_ERR_NO_3D_ELEMENTS</source> <source>SMESH_ERR_NO_3D_ELEMENTS</source>