Salome HOME
020749: EDF 1291 SMESH : Create 2D Mesh from 3D improvement
authoreap <eap@opencascade.com>
Fri, 11 Mar 2011 10:18:32 +0000 (10:18 +0000)
committereap <eap@opencascade.com>
Fri, 11 Mar 2011 10:18:32 +0000 (10:18 +0000)
   for note 0010000

doc/salome/gui/SMESH/images/2d_from_3d_dlg.png
doc/salome/gui/SMESH/input/make_2dmesh_from_3d.doc
doc/salome/gui/SMESH/input/tui_transforming_meshes.doc
src/SMESHGUI/SMESHGUI_Make2DFrom3DOp.cxx
src/SMESHGUI/SMESHGUI_Make2DFrom3DOp.h
src/SMESHGUI/SMESH_msg_en.ts

index a03530978f29caa18e64729480aa02cde20066c0..4a839e89e23143881a7dd6eb1ed0137add1b8459 100644 (file)
Binary files a/doc/salome/gui/SMESH/images/2d_from_3d_dlg.png and b/doc/salome/gui/SMESH/images/2d_from_3d_dlg.png differ
index e520786296df0d79c4db9389dc38949abc82afb1..fe8f31b665b0a0a18365b5c0c3ad8e72f2cb64cc 100644 (file)
@@ -7,6 +7,7 @@ elements of a higher dimension.
 
 <em>To generate border elements:</em>
 <ol>
+<li>Select a mesh in the Object Browser or in the 3D Viewer</li>
 <li>From the Modification menu choose "Create boundary elements"
 item, or click "Create boundary elements" button in the toolbar
 
@@ -26,31 +27,27 @@ of three types.
 <ul>
 <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 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>
 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.
 
 In this dialog:
 <ul>
-<li>specify the <b>Mesh, submesh or group</b>, the boundary which of
-will be analyzed.</li>
+<li>specify the <b>2D groups</b> on borders of which the edges will be
+generated (if <b>1D from 2D groups</b> is selected).</li>
 <li>specify the <b>Target</b> mesh, where the boundary elements will
   be created.
   <ul>
-  <li><b>This mesh</b> adds elements in the selected mesh or the mesh
-  the selected submesh or group belongs to.</li>
+  <li><b>This mesh</b> adds elements in the selected mesh.</li>
   <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>
   </ul></li>
-<li>activate <b>Copy source mesh</b> checkbox to copy 2D or 3D
-  elements (depending on the operation type), which belong to the analyzed 
-<b>Mesh, submesh or group</b> field, to the new mesh.</li>
-<li>deactivate <b>Copy missing elements only</b> checkbox to copy
-  boundary elements already present in the analyzed mesh to the
-  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
+<li>activate <b>Copy source mesh</b> checkbox to copy all elements of
+the selected mesh to the new mesh, else the new mesh will contain only
+boundary elements (old and created by this operation).</li>
+<li>activate <b>Create group</b> checkbox to create a group to which
+  all the boundary elements (old and new) are added. The new group appears
   in the Object Browser with the name that you can change in the adjacent box. </li>
 </ul>
 <br><b>See Also</b> a sample TUI Script of a \ref tui_make_2dmesh_from_3d "Create boundary elements" operation.  
index 22f11886f64f4cca29148358908f035cb43bbb45..2f2f10d4cdbf6337e80a4e9bc7164c43e71399a9 100644 (file)
@@ -426,162 +426,111 @@ if salome.sg.hasDesktop():
 <h3>Create boundary elements</h3>
 
 \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 *
+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")
-boxFace = geompy.SubShapeAll(box, geompy.ShapeType["FACE"])[0]
-geompy.addToStudyInFather(box,boxFace,"boxFace")
+geompy.addToStudyInFather(box,f1,"face1")
+geompy.addToStudyInFather(box,f2,"face2")
 
-MESH1 = Mesh(box,"MESH1")
-MESH1.AutomaticHexahedralization()
+twoFaces = geompy.MakeCompound([f1,f2])
 
-init_nb_edges = MESH1.NbEdges()
-init_nb_faces = MESH1.NbFaces()
-init_nb_volumes = MESH1.NbVolumes()
+## -----------
+##
+## 2D from 3D
+##
+## -----------
+dim = SMESH.BND_2DFROM3D
 
-# =========================================================================================
-# 1) The mesh MESH1 with 3D cells has no or only a part of its skin (2D cells)
-# =========================================================================================
-# remove some faces
-all_faces = MESH1.GetElementsByType(SMESH.FACE)
-rm_faces = all_faces[:init_nb_faces/5] + all_faces[4*init_nb_faces/5:]
-MESH1.RemoveElements(rm_faces)
-assert(MESH1.NbFaces() == init_nb_faces-len(rm_faces))
-
-# 1.1) Add the 2D skin (missing 2D cells) to MESH1
-# -------------------------------------------------
-# add missing faces
-# 1.1.1) to the whole mesh
-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
-MESH1.RemoveElements(rm_faces)
-MESH1.MakeBoundaryMesh([])
-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
-volGroup1 = MESH1.CreateEmptyGroup(SMESH.VOLUME, "volGroup1")
-volGroup1.Add( volumes[: init_nb_volumes/2])
-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)
-meshName = "MESH2"
-MESH2,group = MESH1.MakeBoundaryMesh(MESH1,meshName=meshName,toCopyElements=True)
-assert(MESH2)
-assert(MESH2.GetName() == meshName)
-assert(MESH2.NbVolumes() == MESH1.NbVolumes())
-assert(MESH2.NbFaces() == len(rm_faces))
-
-# check group creation
-MESH1.RemoveElements(rm_faces)
-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.
-# -----------------------------------------------------------------------
-MESH1.RemoveElements(rm_faces)
-meshName = "MESH3"
-MESH3,group = MESH1.MakeBoundaryMesh(MESH1,meshName=meshName,toCopyExistingBondary=True)
-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)
-
-# ==================================================================
-# 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.
-# ==================================================================
-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
-MESH3,group = MESH1.MakeBoundaryMesh(MESH1,meshName=meshName,
-                                     groupName=groupName, toCopyExistingBondary=True)
-assert(group)
-assert(group.GetName() == groupName)
-assert(group.Size() == 0)
-assert(group.GetMesh()._is_equivalent(MESH3.GetMesh()))
-assert(MESH3.NbFaces() == init_nb_faces)
-
-# ================
-# Make 1D from 2D
-# ================
-
-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 )
+init_mesh = Mesh(box, "box")
+init_mesh.AutomaticHexahedralization() # it makes 3 x 3 x 3 hexahedrons
 
+# remove some faces
+faces = init_mesh.GetElementsByType( SMESH.FACE )
+nb_faces = len( faces )
+rm_face = faces[ : nb_faces/2]
+init_mesh.RemoveElements( rm_face )
+
+# restore boundary in this mesh
+mesh = CopyMesh( init_mesh, "2D from 3D")
+groupName = "bnd 2D"
+nb, new_mesh, new_group = mesh.MakeBoundaryElements(dim, groupName)
+
+# restore boundary (only) in other mesh
+meshName = "2D boundary of " + init_mesh.GetName()
+nb, new_mesh, new_group = init_mesh.MakeBoundaryElements(dim, groupName, meshName)
+
+# restore boundary in mesh copy
+meshName = init_mesh.GetName() + " + boundary"
+nb, new_mesh, new_group = init_mesh.MakeBoundaryElements(dim, groupName, meshName, toCopyAll=True)
+
+
+## -----------
+##
+## 1D from 2D
+##
+## -----------
+dim = SMESH.BND_1DFROM2D
+
+init_mesh = Mesh(f1, "2D mesh")
+init_mesh.AutomaticHexahedralization()
+
+# remove some edges
+edges = init_mesh.GetElementsByType( SMESH.EDGE )
+nb_edges = len( edges )
+rm_edge = edges[ : nb_edges/2]
+init_mesh.RemoveElements( rm_edge )
+
+
+# restore boundary edges in this mesh
+mesh = CopyMesh( init_mesh, "1D from 2D")
+groupName = "bnd 1D"
+nb, new_mesh, new_group = mesh.MakeBoundaryElements(dim, groupName)
+
+# restore boundary edges (only) in other mesh
+meshName = "1D boundary of " + init_mesh.GetName()
+nb, new_mesh, new_group = init_mesh.MakeBoundaryElements(dim, groupName, meshName)
+
+# restore boundary edges in mesh copy
+meshName = init_mesh.GetName() + " + boundary"
+nb, new_mesh, new_group = init_mesh.MakeBoundaryElements(dim, groupName, meshName, toCopyAll=True)
+
+
+
+## ------------------
+##
+## 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
 */
index eb8a49ba0151e4663860b6891ae1a7134b6d1240..b11f4bdf76648c6176ee82c5da930a5f0c360f94 100644 (file)
 #include "SMESH_LogicalFilter.hxx"
 
 // SALOME GUI includes
+#include <LightApp_SelectionMgr.h>
 #include <LightApp_UpdateFlags.h>
-#include <SalomeApp_Tools.h>
-#include <SalomeApp_Study.h>
+#include <SALOME_ListIO.hxx>
 #include <SUIT_Desktop.h>
 #include <SUIT_MessageBox.h>
 #include <SUIT_OverrideCursor.h>
+#include <SVTK_ViewModel.h>
+#include <SalomeApp_Study.h>
+#include <SalomeApp_Tools.h>
 
 // IDL includes
 #include <SALOMEconfig.h>
@@ -46,6 +49,7 @@
 #include <QCheckBox>
 #include <QHBoxLayout>
 #include <QGridLayout>
+#include <QToolButton>
 
 #define SPACING 6
 #define MARGIN  11
 */
 
 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
   setWindowTitle( tr("CAPTION") );
 
-  // mesh
-  setObjectPixmap( "SMESH", tr( "ICON_SELECT" ) );
-  createObject( tr( "MESH" ), mainFrame(), Mesh );
-
   // mode
   QGroupBox* aModeGrp = new QGroupBox( tr( "MODE" ), mainFrame() );
   QHBoxLayout* aModeGrpLayout = new QHBoxLayout( aModeGrp );
@@ -77,6 +77,12 @@ SMESHGUI_Make2DFrom3DDlg::SMESHGUI_Make2DFrom3DDlg( QWidget* parent )
   aModeGrpLayout->addWidget( my1dFrom2dRB );
   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
   QGroupBox* aTargetGrp = new QGroupBox( tr( "TARGET" ), mainFrame() );
   QGridLayout* aTargetGrpLayout = new QGridLayout( aTargetGrp );
@@ -86,12 +92,10 @@ SMESHGUI_Make2DFrom3DDlg::SMESHGUI_Make2DFrom3DDlg( QWidget* parent )
   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() );
 
@@ -99,10 +103,9 @@ SMESHGUI_Make2DFrom3DDlg::SMESHGUI_Make2DFrom3DDlg( QWidget* parent )
   QGridLayout* aDlgLay = new QGridLayout( mainFrame() );
   aDlgLay->setMargin( 0 );
   aDlgLay->setSpacing( SPACING );
-  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( aModeGrp,     0, 0, 1, 3 );
+  aDlgLay->addWidget( objectWg( Groups,  Label ),   1, 0 );
+  aDlgLay->addWidget( objectWg( Groups,  Control ), 1, 1 );
   aDlgLay->addWidget( aTargetGrp,   2, 0, 1, 3 );
   aDlgLay->addWidget( myGroupCheck, 3, 0 );
   aDlgLay->addWidget( myGroupName,  3, 1, 1, 2 );
@@ -115,7 +118,6 @@ SMESHGUI_Make2DFrom3DDlg::SMESHGUI_Make2DFrom3DDlg( QWidget* parent )
   // init dlg
   my2dFrom3dRB->setChecked( true );
   myThisMeshRB->setChecked( true );
-  myMissingCheck->setChecked( true );
   onTargetChanged();
   onGroupChecked();
 }
@@ -169,16 +171,10 @@ bool SMESHGUI_Make2DFrom3DDlg::copySource() const
   return myCopyCheck->isChecked();
 }
 
-bool SMESHGUI_Make2DFrom3DDlg::copyMissingOnly() const
-{
-  return myMissingCheck->isChecked();
-}
-
 void SMESHGUI_Make2DFrom3DDlg::onTargetChanged()
 {
   myMeshName->setEnabled( myNewMeshRB->isChecked() );
   myCopyCheck->setEnabled( myNewMeshRB->isChecked() );
-  myMissingCheck->setEnabled( myNewMeshRB->isChecked() );
 }
 
 void SMESHGUI_Make2DFrom3DDlg::onGroupChecked()
@@ -212,33 +208,61 @@ void SMESHGUI_Make2DFrom3DOp::startOperation()
   if( !myDlg )
     myDlg = new SMESHGUI_Make2DFrom3DDlg( desktop() );
 
-  mySrc = SMESH::SMESH_IDSource::_nil();
-  
   myHelpFileName = "make_2dmesh_from_3d_page.html";
 
   SMESHGUI_SelectionOp::startOperation();
 
-  myDlg->activateObject( SMESHGUI_Make2DFrom3DDlg::Mesh );
   myDlg->setNewMeshName( SMESH::UniqueName( "Mesh_1" ) );
   myDlg->setGroupName( SMESH::UniqueName( "Group" ) );
   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()
 {
+  mySrcMesh = SMESH::SMESH_Mesh::_nil();
+  myDlg->clearSelection( SMESHGUI_Make2DFrom3DDlg::Groups );
+
   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();
+      myDlg->selectObject( names, types, ids );
+
+      SALOME_ListIO sel; selectionMgr()->selectedObjects( sel, SVTK_Viewer::Type() );
+      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 ) {
       SalomeApp_Tools::QtCatchCorbaException( S_ex );
@@ -250,13 +274,8 @@ void SMESHGUI_Make2DFrom3DOp::selectionDone()
 
 SUIT_SelectionFilter* SMESHGUI_Make2DFrom3DOp::createFilter( const int theId ) const
 {
-  SUIT_SelectionFilter* f = 0;
-  if ( theId == SMESHGUI_Make2DFrom3DDlg::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 );
-  }
+  MeshObjectType type = ( theId == SMESHGUI_Make2DFrom3DDlg::Groups ? GROUP_FACE : MESH );
+  SUIT_SelectionFilter* f = new SMESH_TypeFilter( type );
   return f;
 }
 
@@ -264,36 +283,43 @@ bool SMESHGUI_Make2DFrom3DOp::isValid( QString& msg ) const
 {
   if ( !dlg() ) return false;
 
-  // check if any source data is selected
-  QString entry = myDlg->selectedObject( SMESHGUI_Make2DFrom3DDlg::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() ) {
+  // check if a mesh is selected
+  if ( mySrcMesh->_is_nil() )
+  {
     msg = tr( "SMESH_ERR_NO_INPUT_MESH" );
     return false;
   }
-
-  // check if source contains elements of required type
+  // check if groups are selected
   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 ( mode == SMESH::BND_1DFROM3D )
+  {
+    SMESH::SMESH_GroupBase_var grp;
+    QStringList entries;
+    dlg()->selectedObject( SMESHGUI_Make2DFrom3DDlg::Groups, entries );
+    if ( !entries.isEmpty() )
+    {
+      _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 ) {
-    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;
+    if ( mode == SMESH::BND_2DFROM3D && mySrcMesh->NbVolumes() == 0 ) {
+      msg = tr( "SMESH_ERR_NO_3D_ELEMENTS" );
+      return false;
+    }
+    else if ( mode == SMESH::BND_1DFROM2D && mySrcMesh->NbFaces() == 0  ) {
+      msg = tr( "SMESH_ERR_NO_2D_ELEMENTS" );
+      return false;
+    }
   }
 
   // check if new mesh name is specified
@@ -317,41 +343,38 @@ bool SMESHGUI_Make2DFrom3DOp::compute2DMesh()
 
   bool ok = false;
   try {
-    QString entry = myDlg->selectedObject( SMESHGUI_Make2DFrom3DDlg::Mesh );
-    _PTR(SObject) sobj = SMESHGUI::activeStudy()->studyDS()->FindObjectID( entry.toLatin1().constData() );
-    SMESH::SMESH_IDSource_var obj = SMESH::SObjectToInterface<SMESH::SMESH_IDSource>( sobj );  
-    
+    QStringList entries;
+    dlg()->selectedObject( SMESHGUI_Make2DFrom3DDlg::Groups, entries );
+    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();
     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();
-    }
+    bool copyAll = myDlg->copySource();
 
-    if ( !CORBA::is_nil( srcMesh ) ) {
-      SMESH::SMESH_MeshEditor_var aMeshEditor = srcMesh->GetMeshEditor();
+    if ( !CORBA::is_nil( mySrcMesh ) ) {
+      SMESH::SMESH_MeshEditor_var aMeshEditor = mySrcMesh->GetMeshEditor();
       SMESH::SMESH_Group_var newGrp;
-      SMESH::SMESH_Mesh_var mesh = aMeshEditor->MakeBoundaryMesh( obj.in(), 
-                                                                  mode,
-                                                                  groupName.toLatin1().constData(),
-                                                                  meshName.toLatin1().constData(),
-                                                                  copySrc,
-                                                                  copyAll,
-                                                                  newGrp.out() );
-      if ( !mesh->_is_nil() ) {
+      SMESH::SMESH_Mesh_var newMesh;
+      CORBA::Long nbAdded = aMeshEditor->MakeBoundaryElements( mode,
+                                                               groupName.toLatin1().constData(),
+                                                               meshName.toLatin1().constData(),
+                                                               copyAll,
+                                                               groups,
+                                                               newMesh.out(),
+                                                               newGrp.out() );
+      SUIT_MessageBox::information( myDlg,
+                                    tr("SMESH_INFORMATION"),
+                                    tr("NB_ADDED").arg( nbAdded ));
+      if ( !newMesh->_is_nil() ) {
 #ifdef WITHGENERICOBJ
-        mesh->UnRegister();
+        newMesh->UnRegister();
 #endif
       }
       if ( !newGrp->_is_nil() ) {
index 23bab5e615cc0e362b42d684c5128558cc7613a4..69cc946556f28d94af45a75cd79db49c1689a221 100644 (file)
 
 #include <SALOMEconfig.h>
 #include CORBA_SERVER_HEADER(SMESH_MeshEditor)
+#include CORBA_SERVER_HEADER(SMESH_Mesh)
 
 class QCheckBox;
 class QLineEdit;
 class QRadioButton;
+class SMESHGUI_Make2DFrom3DOp;
 
 /*!
  * \brief Dialog to show result mesh statistic
@@ -43,7 +45,7 @@ class SMESHGUI_EXPORT SMESHGUI_Make2DFrom3DDlg :  public SMESHGUI_Dialog
   Q_OBJECT
 
 public:
-  enum { Mesh };
+  enum { Mesh, Groups };
 
   SMESHGUI_Make2DFrom3DDlg( QWidget* );
   virtual ~SMESHGUI_Make2DFrom3DDlg();
@@ -59,7 +61,6 @@ public:
   void                 setGroupName( const QString& );
 
   bool                 copySource() const;
-  bool                 copyMissingOnly() const;
 
 private slots:
   void                 onTargetChanged();
@@ -73,9 +74,10 @@ private:
   QRadioButton* myNewMeshRB;
   QLineEdit*    myMeshName;
   QCheckBox*    myCopyCheck;
-  QCheckBox*    myMissingCheck;
   QCheckBox*    myGroupCheck;
   QLineEdit*    myGroupName;
+
+  friend class SMESHGUI_Make2DFrom3DOp;
 };
 
 /*!
@@ -100,12 +102,13 @@ protected:
 
 protected slots:
   virtual bool                       onApply();
+  void                               onModeChanged();
 
 private:
   bool                               compute2DMesh();
 
 private:
-  SMESH::SMESH_IDSource_var          mySrc;
+  SMESH::SMESH_Mesh_var              mySrcMesh;
   QPointer<SMESHGUI_Make2DFrom3DDlg> myDlg;
 };
 
index d615804e7646978ed7c0c2ec341339bd6e1b4654..d6e8ce582313aeaa43b0750eb30684dc8d5760c2 100644 (file)
@@ -5589,8 +5589,8 @@ It is impossible to read point coordinates from file</translation>
         <translation>Create boundary elements</translation>
     </message>
     <message>
-        <source>MESH</source>
-        <translation>Mesh, submesh or group</translation>
+        <source>Groups</source>
+        <translation>2D groups</translation>
     </message>
     <message>
         <source>MODE</source>
@@ -5602,7 +5602,7 @@ It is impossible to read point coordinates from file</translation>
     </message>
     <message>
         <source>1D_FROM_3D</source>
-        <translation>1D from 3D</translation>
+        <translation>1D from 2D groups</translation>
     </message>
     <message>
         <source>1D_FROM_2D</source>
@@ -5635,9 +5635,17 @@ It is impossible to read point coordinates from file</translation>
 </context>
 <context>
     <name>SMESHGUI_Make2DFrom3DOp</name>
+    <message>
+        <source>NB_ADDED</source>
+        <translation>%1 boundary elements have been added</translation>
+    </message>
     <message>
         <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>
         <source>SMESH_ERR_NO_3D_ELEMENTS</source>