From 9ae572587c234edf74d9684ce2dd9c28669ab445 Mon Sep 17 00:00:00 2001 From: gdd Date: Tue, 18 Jan 2011 14:45:18 +0000 Subject: [PATCH] Add new method DoubleNodeElemGroupsNew which allows to have the group of newly created elements. --- idl/SMESH_MeshEditor.idl | 17 ++++++++- src/SMESH_I/SMESH_2smeshpy.cxx | 4 ++- src/SMESH_I/SMESH_MeshEditor_i.cxx | 56 +++++++++++++++++++++++++++++- src/SMESH_I/SMESH_MeshEditor_i.hxx | 18 ++++++++-- src/SMESH_SWIG/smeshDC.py | 10 ++++-- 5 files changed, 98 insertions(+), 7 deletions(-) diff --git a/idl/SMESH_MeshEditor.idl b/idl/SMESH_MeshEditor.idl index e4e504e1a..f001799cf 100644 --- a/idl/SMESH_MeshEditor.idl +++ b/idl/SMESH_MeshEditor.idl @@ -900,12 +900,27 @@ module SMESH * \param theAffectedElems - group of elements to which the replicated nodes * should be associated to. * \return TRUE if operation has been completed successfully, FALSE otherwise - * \sa DoubleNodeGroup(), DoubleNodes() + * \sa DoubleNodeGroup(), DoubleNodes(), DoubleNodeElemGroupsNew() */ boolean DoubleNodeElemGroups( in ListOfGroups theElems, in ListOfGroups theNodesNot, in ListOfGroups theAffectedElems ); + /*! + * \brief Creates a hole in a mesh by doubling the nodes of some particular elements. + * Works as DoubleNodeElemGroups() described above, but returns a new group with + * newly created elements. + * \param theElems - list of groups of elements (edges or faces) to be replicated + * \param theNodesNot - list of groups of nodes not to replicated + * \param theAffectedElems - group of elements to which the replicated nodes + * should be associated to. + * \return a new group with newly created elements + * \sa DoubleNodeElemGroups() + */ + SMESH_Group DoubleNodeElemGroupsNew( in ListOfGroups theElems, + in ListOfGroups theNodesNot, + in ListOfGroups theAffectedElems ); + /*! * \brief Creates a hole in a mesh by doubling the nodes of some particular elements * This method provided for convenience works as DoubleNodes() described above. diff --git a/src/SMESH_I/SMESH_2smeshpy.cxx b/src/SMESH_I/SMESH_2smeshpy.cxx index e62946601..3ffce11d3 100644 --- a/src/SMESH_I/SMESH_2smeshpy.cxx +++ b/src/SMESH_I/SMESH_2smeshpy.cxx @@ -1194,7 +1194,9 @@ void _pyMeshEditor::Process( const Handle(_pyCommand)& theCommand) theCommand->SetMethod("FindCoincidentNodesOnPart"); } // DoubleNodeElemGroupNew() -> DoubleNodeElemGroup() - if ( !isPyMeshMethod && ( method == "DoubleNodeElemGroupNew" || method == "DoubleNodeGroupNew")) + // DoubleNodeGroupNew() -> DoubleNodeGroup() + // DoubleNodeElemGroupsNew() -> DoubleNodeElemGroups() + if ( !isPyMeshMethod && ( method == "DoubleNodeElemGroupNew" || method == "DoubleNodeGroupNew" || method == "DoubleNodeElemGroupsNew")) { isPyMeshMethod=true; theCommand->SetMethod( method.SubString( 1, method.Length()-3)); diff --git a/src/SMESH_I/SMESH_MeshEditor_i.cxx b/src/SMESH_I/SMESH_MeshEditor_i.cxx index 1e732f922..9d1cf79dd 100644 --- a/src/SMESH_I/SMESH_MeshEditor_i.cxx +++ b/src/SMESH_I/SMESH_MeshEditor_i.cxx @@ -5134,7 +5134,7 @@ CORBA::Boolean SMESH_MeshEditor_i::DoubleNodeElemGroupInRegion(SMESH::SMESH_Grou \param theAffectedElems - group of elements to which the replicated nodes should be associated to. \return TRUE if operation has been completed successfully, FALSE otherwise - \sa DoubleNodeGroup(), DoubleNodes() + \sa DoubleNodeGroup(), DoubleNodes(), DoubleNodeElemGroupsNew() */ //================================================================================ @@ -5183,6 +5183,60 @@ CORBA::Boolean SMESH_MeshEditor_i::DoubleNodeElemGroups(const SMESH::ListOfGroup return aResult; } +//================================================================================ +/*! + * \brief Creates a hole in a mesh by doubling the nodes of some particular elements + * Works as DoubleNodeElemGroups(), but returns a new group with newly created elements. + \param theElems - list of groups of elements (edges or faces) to be replicated + \param theNodesNot - list of groups of nodes not to replicated + \param theAffectedElems - group of elements to which the replicated nodes + should be associated to. + * \return a new group with newly created elements + * \sa DoubleNodeElemGroups() + */ +//================================================================================ + +SMESH::SMESH_Group_ptr SMESH_MeshEditor_i::DoubleNodeElemGroupsNew(const SMESH::ListOfGroups& theElems, + const SMESH::ListOfGroups& theNodesNot, + const SMESH::ListOfGroups& theAffectedElems) +{ + SMESH::SMESH_Group_var aNewGroup; + + initData(); + + ::SMESH_MeshEditor aMeshEditor( myMesh ); + + SMESHDS_Mesh* aMeshDS = GetMeshDS(); + TIDSortedElemSet anElems, aNodes, anAffected; + listOfGroupToSet(theElems, aMeshDS, anElems, false ); + listOfGroupToSet(theNodesNot, aMeshDS, aNodes, true ); + listOfGroupToSet(theAffectedElems, aMeshDS, anAffected, false ); + + bool aResult = aMeshEditor.DoubleNodes( anElems, aNodes, anAffected ); + + storeResult( aMeshEditor) ; + + myMesh->GetMeshDS()->Modified(); + if ( aResult ) { + myMesh->SetIsModified( true ); + + // Create group with newly created elements + SMESH::long_array_var anIds = GetLastCreatedElems(); + if (anIds->length() > 0) { + SMESH::ElementType aGroupType = myMesh_i->GetElementType(anIds[0], true); + string anUnindexedName (theElems[0]->GetName()); + string aNewName = generateGroupName(anUnindexedName + "_double"); + aNewGroup = myMesh_i->CreateGroup(aGroupType, aNewName.c_str()); + aNewGroup->Add(anIds); + } + } + + // Update Python script + TPythonDump() << "createdElems = " << this << ".DoubleNodeElemGroupsNew( " << &theElems << ", " + << &theNodesNot << ", " << &theAffectedElems << " )"; + return aNewGroup._retn(); +} + //================================================================================ /*! \brief Creates a hole in a mesh by doubling the nodes of some particular elements diff --git a/src/SMESH_I/SMESH_MeshEditor_i.hxx b/src/SMESH_I/SMESH_MeshEditor_i.hxx index e90fe857e..ea8f30142 100644 --- a/src/SMESH_I/SMESH_MeshEditor_i.hxx +++ b/src/SMESH_I/SMESH_MeshEditor_i.hxx @@ -607,7 +607,7 @@ public: * \param theAffectedElems - group of elements to which the replicated nodes * should be associated to. * \return TRUE if operation has been completed successfully, FALSE otherwise - * \sa DoubleNodes(), DoubleNodeGroups() + * \sa DoubleNodes(), DoubleNodeGroups(), DoubleNodeElemGroupNew() */ CORBA::Boolean DoubleNodeElemGroup( SMESH::SMESH_GroupBase_ptr theElems, SMESH::SMESH_GroupBase_ptr theNodesNot, @@ -649,12 +649,26 @@ public: * \param theAffectedElems - group of elements to which the replicated nodes * should be associated to. * \return TRUE if operation has been completed successfully, FALSE otherwise - * \sa DoubleNodeGroup(), DoubleNodes() + * \sa DoubleNodeGroup(), DoubleNodes(), DoubleNodeElemGroupsNew() */ CORBA::Boolean DoubleNodeElemGroups( const SMESH::ListOfGroups& theElems, const SMESH::ListOfGroups& theNodesNot, const SMESH::ListOfGroups& theAffectedElems ); + /*! + * \brief Creates a hole in a mesh by doubling the nodes of some particular elements + * Works as DoubleNodeElemGroups(), but returns a new group with newly created elements. + * \param theElems - list of groups of elements (edges or faces) to be replicated + * \param theNodesNot - list of groups of nodes not to replicated + * \param theAffectedElems - group of elements to which the replicated nodes + * should be associated to. + * \return a new group with newly created elements + * \sa DoubleNodeElemGroups() + */ + SMESH::SMESH_Group_ptr DoubleNodeElemGroupsNew( const SMESH::ListOfGroups& theElems, + const SMESH::ListOfGroups& theNodesNot, + const SMESH::ListOfGroups& theAffectedElems ); + /*! * \brief Creates a hole in a mesh by doubling the nodes of some particular elements diff --git a/src/SMESH_SWIG/smeshDC.py b/src/SMESH_SWIG/smeshDC.py index de05f11d8..5fa6cc4b4 100644 --- a/src/SMESH_SWIG/smeshDC.py +++ b/src/SMESH_SWIG/smeshDC.py @@ -4064,6 +4064,8 @@ class Mesh: # @param theAffectedElems - group of elements to which the replicated nodes # should be associated to. # @param theMakeGroup forces the generation of a group containing new elements. + # @return TRUE or a created group if operation has been completed successfully, + # FALSE or None otherwise # @ingroup l2_modif_edit def DoubleNodeElemGroup(self, theElems, theNodesNot, theAffectedElems, theMakeGroup=False): if theMakeGroup: @@ -4087,9 +4089,13 @@ class Mesh: # @param theNodesNot - list of groups of nodes not to replicated # @param theAffectedElems - group of elements to which the replicated nodes # should be associated to. - # @return TRUE if operation has been completed successfully, FALSE otherwise + # @param theMakeGroup forces the generation of a group containing new elements. + # @return TRUE or a created group if operation has been completed successfully, + # FALSE or None otherwise # @ingroup l2_modif_edit - def DoubleNodeElemGroups(self, theElems, theNodesNot, theAffectedElems): + def DoubleNodeElemGroups(self, theElems, theNodesNot, theAffectedElems, theMakeGroup=False): + if theMakeGroup: + return self.editor.DoubleNodeElemGroupsNew(theElems, theNodesNot, theAffectedElems) return self.editor.DoubleNodeElemGroups(theElems, theNodesNot, theAffectedElems) ## Creates a hole in a mesh by doubling the nodes of some particular elements -- 2.39.2