+
+/*!
+ * \brief identify all the elements around a geom shape, get the faces delimiting the hole
+ * Build groups of volume to remove, groups of faces to replace on the skin of the object,
+ * groups of faces to remove inside the object, (idem edges).
+ * Build ordered list of nodes at the border of each group of faces to replace (to be used to build a geom subshape)
+ */
+void SMESH_MeshEditor_i::CreateHoleSkin(CORBA::Double radius,
+ GEOM::GEOM_Object_ptr theShape,
+ const char* groupName,
+ const SMESH::double_array& theNodesCoords,
+ SMESH::array_of_long_array_out GroupsOfNodes)
+throw (SALOME::SALOME_Exception)
+{
+ initData();
+ std::vector<std::vector<int> > aListOfListOfNodes;
+ ::SMESH_MeshEditor aMeshEditor( myMesh );
+
+ theSearchersDeleter.Set( myMesh ); // remove theNodeSearcher if mesh is other
+ if ( !theNodeSearcher )
+ theNodeSearcher = aMeshEditor.GetNodeSearcher();
+
+ vector<double> nodesCoords;
+ for (int i = 0; i < theNodesCoords.length(); i++)
+ {
+ nodesCoords.push_back( theNodesCoords[i] );
+ }
+
+ TopoDS_Shape aShape = SMESH_Gen_i::GetSMESHGen()->GeomObjectToShape( theShape );
+ aMeshEditor.CreateHoleSkin(radius, aShape, theNodeSearcher, groupName, nodesCoords, aListOfListOfNodes);
+
+ GroupsOfNodes = new SMESH::array_of_long_array;
+ GroupsOfNodes->length( aListOfListOfNodes.size() );
+ std::vector<std::vector<int> >::iterator llIt = aListOfListOfNodes.begin();
+ for ( CORBA::Long i = 0; llIt != aListOfListOfNodes.end(); llIt++, i++ )
+ {
+ vector<int>& aListOfNodes = *llIt;
+ vector<int>::iterator lIt = aListOfNodes.begin();;
+ SMESH::long_array& aGroup = (*GroupsOfNodes)[ i ];
+ aGroup.length( aListOfNodes.size() );
+ for ( int j = 0; lIt != aListOfNodes.end(); lIt++, j++ )
+ aGroup[ j ] = (*lIt);
+ }
+ TPythonDump() << "lists_nodes = " << this << ".CreateHoleSkin( "
+ << radius << ", " << theShape << ", " << ", " << groupName << ", " << theNodesCoords << " )";
+}
+
+
+// issue 20749 ===================================================================
+/*!
+ * \brief Creates missing boundary elements
+ * \param elements - elements whose boundary is to be checked
+ * \param dimension - defines type of boundary elements to create
+ * \param groupName - a name of group to store created boundary elements in,
+ * "" means not to create the group
+ * \param meshName - a name of new mesh to store created boundary elements in,
+ * "" means not to create the new mesh
+ * \param toCopyElements - if true, the checked elements will be copied into the new mesh
+ * \param toCopyExistingBondary - if true, not only new but also pre-existing
+ * boundary elements will be copied into the new mesh
+ * \param group - returns the create group, if any
+ * \retval SMESH::SMESH_Mesh - the mesh where elements were added to
+ */
+// ================================================================================
+
+SMESH::SMESH_Mesh_ptr
+SMESH_MeshEditor_i::MakeBoundaryMesh(SMESH::SMESH_IDSource_ptr idSource,
+ SMESH::Bnd_Dimension dim,
+ const char* groupName,
+ const char* meshName,
+ CORBA::Boolean toCopyElements,
+ CORBA::Boolean toCopyExistingBondary,
+ SMESH::SMESH_Group_out group)
+{
+ initData();
+
+ if ( dim > SMESH::BND_1DFROM2D )
+ THROW_SALOME_CORBA_EXCEPTION("Invalid boundary dimension", SALOME::BAD_PARAM);
+
+ SMESHDS_Mesh* aMeshDS = GetMeshDS();
+
+ SMESH::SMESH_Mesh_var mesh_var;
+ SMESH::SMESH_Group_var group_var;
+
+ TPythonDump pyDump;
+
+ TIDSortedElemSet elements;
+ SMDSAbs_ElementType elemType = (dim == SMESH::BND_1DFROM2D) ? SMDSAbs_Face : SMDSAbs_Volume;
+ if ( idSourceToSet( idSource, aMeshDS, elements, elemType,/*emptyIfIsMesh=*/true ))
+ {
+ // mesh to fill in
+ mesh_var =
+ strlen(meshName) ? makeMesh(meshName) : SMESH::SMESH_Mesh::_duplicate(myMesh_i->_this());
+ SMESH_Mesh_i* mesh_i = SMESH::DownCast<SMESH_Mesh_i*>( mesh_var );
+ // other mesh
+ SMESH_Mesh* smesh_mesh = (mesh_i==myMesh_i) ? (SMESH_Mesh*)0 : &mesh_i->GetImpl();
+
+ // group of new boundary elements
+ SMESH_Group* smesh_group = 0;
+ if ( strlen(groupName) )
+ {
+ group_var = mesh_i->CreateGroup( SMESH::ElementType(int(elemType)-1),groupName);
+ if ( SMESH_GroupBase_i* group_i = SMESH::DownCast<SMESH_GroupBase_i*>( group_var ))
+ smesh_group = group_i->GetSmeshGroup();
+ }
+
+ // do it
+ myEditor.MakeBoundaryMesh( elements,
+ ::SMESH_MeshEditor::Bnd_Dimension(dim),
+ smesh_group,
+ smesh_mesh,
+ toCopyElements,
+ toCopyExistingBondary);
+ storeResult( myEditor );
+
+ if ( smesh_mesh )
+ smesh_mesh->GetMeshDS()->Modified();
+ }
+
+ const char* dimName[] = { "BND_2DFROM3D", "BND_1DFROM3D", "BND_1DFROM2D" };
+
+ // result of MakeBoundaryMesh() is a tuple (mesh, group)
+ if ( mesh_var->_is_nil() )
+ pyDump << myMesh_i->_this() << ", ";
+ else
+ pyDump << mesh_var << ", ";
+ if ( group_var->_is_nil() )
+ pyDump << "_NoneGroup = "; // assignment to None is forbiden
+ else
+ pyDump << group_var << " = ";
+ pyDump << this << ".MakeBoundaryMesh( "
+ << idSource << ", "
+ << "SMESH." << dimName[int(dim)] << ", "
+ << "'" << groupName << "', "
+ << "'" << meshName<< "', "
+ << toCopyElements << ", "
+ << toCopyExistingBondary << ")";
+
+ group = group_var._retn();
+ return mesh_var._retn();
+}
+
+//================================================================================
+/*!
+ * \brief Creates missing boundary elements
+ * \param dimension - defines type of boundary elements to create
+ * \param groupName - a name of group to store all boundary elements in,
+ * "" means not to create the group
+ * \param meshName - a name of a new mesh, which is a copy of the initial
+ * mesh + created boundary elements; "" means not to create the new mesh
+ * \param toCopyAll - if true, the whole initial mesh will be copied into
+ * the new mesh else only boundary elements will be copied into the new mesh
+ * \param groups - optional groups of elements to make boundary around
+ * \param mesh - returns the mesh where elements were added to
+ * \param group - returns the created group, if any
+ * \retval long - number of added boundary elements
+ */
+//================================================================================
+
+CORBA::Long SMESH_MeshEditor_i::MakeBoundaryElements(SMESH::Bnd_Dimension dim,
+ const char* groupName,
+ const char* meshName,
+ CORBA::Boolean toCopyAll,
+ const SMESH::ListOfIDSources& groups,
+ SMESH::SMESH_Mesh_out mesh,
+ SMESH::SMESH_Group_out group)
+ throw (SALOME::SALOME_Exception)
+{
+ Unexpect aCatch(SALOME_SalomeException);
+
+ initData();
+
+ if ( dim > SMESH::BND_1DFROM2D )
+ THROW_SALOME_CORBA_EXCEPTION("Invalid boundary dimension", SALOME::BAD_PARAM);
+
+ // separate groups belonging to this and other mesh
+ SMESH::ListOfIDSources_var groupsOfThisMesh = new SMESH::ListOfIDSources;
+ SMESH::ListOfIDSources_var groupsOfOtherMesh = new SMESH::ListOfIDSources;
+ groupsOfThisMesh->length( groups.length() );
+ groupsOfOtherMesh->length( groups.length() );
+ int nbGroups = 0, nbGroupsOfOtherMesh = 0;
+ for ( int i = 0; i < groups.length(); ++i )
+ {
+ SMESH::SMESH_Mesh_var m = groups[i]->GetMesh();
+ if ( myMesh_i != SMESH::DownCast<SMESH_Mesh_i*>( m ))
+ groupsOfOtherMesh[ nbGroupsOfOtherMesh++ ] = groups[i];
+ else
+ groupsOfThisMesh[ nbGroups++ ] = groups[i];
+ if ( SMESH::DownCast<SMESH_Mesh_i*>( groups[i] ))
+ THROW_SALOME_CORBA_EXCEPTION("expect a group but recieve a mesh", SALOME::BAD_PARAM);
+ }
+ groupsOfThisMesh->length( nbGroups );
+ groupsOfOtherMesh->length( nbGroupsOfOtherMesh );
+
+ int nbAdded = 0;
+ TPythonDump pyDump;
+
+ if ( nbGroupsOfOtherMesh > 0 )
+ {
+ // process groups belonging to another mesh
+ SMESH::SMESH_Mesh_var otherMesh = groupsOfOtherMesh[0]->GetMesh();
+ SMESH::SMESH_MeshEditor_var editor = otherMesh->GetMeshEditor();
+ nbAdded += editor->MakeBoundaryElements( dim, groupName, meshName, toCopyAll,
+ groupsOfOtherMesh, mesh, group );
+ }
+
+ SMESH::SMESH_Mesh_var mesh_var;
+ SMESH::SMESH_Group_var group_var;
+
+ // get mesh to fill
+ mesh_var = SMESH::SMESH_Mesh::_duplicate( myMesh_i->_this() );
+ const bool toCopyMesh = ( strlen( meshName ) > 0 );
+ if ( toCopyMesh )
+ {
+ if ( toCopyAll )
+ mesh_var = SMESH_Gen_i::GetSMESHGen()->CopyMesh(mesh_var,
+ meshName,
+ /*toCopyGroups=*/false,
+ /*toKeepIDs=*/true);
+ else
+ mesh_var = makeMesh(meshName);
+ }
+ SMESH_Mesh_i* mesh_i = SMESH::DownCast<SMESH_Mesh_i*>( mesh_var );
+ SMESH_Mesh* tgtMesh = &mesh_i->GetImpl();
+
+ // source mesh
+ SMESH_Mesh* srcMesh = ( toCopyMesh && !toCopyAll ) ? myMesh : tgtMesh;
+ SMESHDS_Mesh* srcMeshDS = srcMesh->GetMeshDS();
+
+ // group of boundary elements
+ SMESH_Group* smesh_group = 0;
+ SMDSAbs_ElementType elemType = (dim == SMESH::BND_2DFROM3D) ? SMDSAbs_Volume : SMDSAbs_Face;
+ if ( strlen(groupName) )
+ {
+ SMESH::ElementType groupType = SMESH::ElementType( int(elemType)-1 );
+ group_var = mesh_i->CreateGroup( groupType, groupName );
+ if ( SMESH_GroupBase_i* group_i = SMESH::DownCast<SMESH_GroupBase_i*>( group_var ))
+ smesh_group = group_i->GetSmeshGroup();
+ }
+
+ TIDSortedElemSet elements;
+
+ if ( groups.length() > 0 )
+ {
+ for ( int i = 0; i < nbGroups; ++i )
+ {
+ elements.clear();
+ if ( idSourceToSet( groupsOfThisMesh[i], srcMeshDS, elements, elemType,/*emptyIfIsMesh=*/0 ))
+ {
+ SMESH::Bnd_Dimension bdim =
+ ( elemType == SMDSAbs_Volume ) ? SMESH::BND_2DFROM3D : SMESH::BND_1DFROM2D;
+ nbAdded += myEditor.MakeBoundaryMesh( elements,
+ ::SMESH_MeshEditor::Bnd_Dimension(bdim),
+ smesh_group,
+ tgtMesh,
+ /*toCopyElements=*/false,
+ /*toCopyExistingBondary=*/srcMesh != tgtMesh,
+ /*toAddExistingBondary=*/true,
+ /*aroundElements=*/true);
+ storeResult( myEditor );
+ }
+ }
+ }
+ else
+ {
+ nbAdded += myEditor.MakeBoundaryMesh( elements,
+ ::SMESH_MeshEditor::Bnd_Dimension(dim),
+ smesh_group,
+ tgtMesh,
+ /*toCopyElements=*/false,
+ /*toCopyExistingBondary=*/srcMesh != tgtMesh,
+ /*toAddExistingBondary=*/true);
+ storeResult( myEditor );
+ }
+ tgtMesh->GetMeshDS()->Modified();
+
+ const char* dimName[] = { "BND_2DFROM3D", "BND_1DFROM3D", "BND_1DFROM2D" };
+
+ // result of MakeBoundaryElements() is a tuple (nb, mesh, group)
+ pyDump << "nbAdded, ";
+ if ( mesh_var->_is_nil() )
+ pyDump << myMesh_i->_this() << ", ";
+ else
+ pyDump << mesh_var << ", ";
+ if ( group_var->_is_nil() )
+ pyDump << "_NoneGroup = "; // assignment to None is forbiden
+ else
+ pyDump << group_var << " = ";
+ pyDump << this << ".MakeBoundaryElements( "
+ << "SMESH." << dimName[int(dim)] << ", "
+ << "'" << groupName << "', "
+ << "'" << meshName<< "', "
+ << toCopyAll << ", "
+ << groups << ")";
+
+ mesh = mesh_var._retn();
+ group = group_var._retn();
+ return nbAdded;
+}