X-Git-Url: http://git.salome-platform.org/gitweb/?p=modules%2Fsmesh.git;a=blobdiff_plain;f=src%2FSMESH_I%2FSMESH_MeshEditor_i.cxx;h=70462b1151fe749312912bfb169225e41d7d8872;hp=4ce4b901e6f9b165c43980d96be18fc4b2d5f4f1;hb=2c607013a23bd4e7ba07e72e0c04dee2c1209cff;hpb=512a8923018c8a53648b6bc2dd02a29cd8e94eed diff --git a/src/SMESH_I/SMESH_MeshEditor_i.cxx b/src/SMESH_I/SMESH_MeshEditor_i.cxx index 4ce4b901e..70462b115 100644 --- a/src/SMESH_I/SMESH_MeshEditor_i.cxx +++ b/src/SMESH_I/SMESH_MeshEditor_i.cxx @@ -1,25 +1,24 @@ -// Copyright (C) 2007-2010 CEA/DEN, EDF R&D, OPEN CASCADE +// Copyright (C) 2007-2011 CEA/DEN, EDF R&D, OPEN CASCADE // -// Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, -// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS +// Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, +// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS // -// This library is free software; you can redistribute it and/or -// modify it under the terms of the GNU Lesser General Public -// License as published by the Free Software Foundation; either -// version 2.1 of the License. +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License. // -// This library is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -// Lesser General Public License for more details. +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. // -// You should have received a copy of the GNU Lesser General Public -// License along with this library; if not, write to the Free Software -// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // -// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com // -// SMESH SMESH_I : idl implementation based on 'SMESH' unit's calsses // File : SMESH_MeshEditor_i.cxx // Author : Nicolas REJNERI // Module : SMESH @@ -234,7 +233,7 @@ namespace { } //================================================================================ /*! - * \brief function for conversion long_array to TIDSortedElemSet + * \brief function for conversion of long_array to TIDSortedElemSet * \param IDs - array of IDs * \param aMesh - mesh * \param aMap - collection to fill @@ -311,12 +310,64 @@ namespace { if ( const SMDS_MeshNode * n = theMeshDS->FindNode( aElementsId[i] )) theNodeSet.insert( theNodeSet.end(), n); } - else { + else if ( SMESH::DownCast( theObject )) + { + SMDS_NodeIteratorPtr nIt = theMeshDS->nodesIterator(); + while ( nIt->more( )) + if( const SMDS_MeshElement * elem = nIt->next() ) + theNodeSet.insert( elem->begin_nodes(), elem->end_nodes()); + } + else + { for(int i = 0; i < aElementsId->length(); i++) if( const SMDS_MeshElement * elem = theMeshDS->FindElement( aElementsId[i] )) theNodeSet.insert( elem->begin_nodes(), elem->end_nodes()); } } + + //================================================================================ + /*! + * \brief Returns elements connected to the given elements + */ + //================================================================================ + + void getElementsAround(const TIDSortedElemSet& theElements, + const SMESHDS_Mesh* theMeshDS, + TIDSortedElemSet& theElementsAround) + { + if ( theElements.empty() ) return; + + SMDSAbs_ElementType elemType = (*theElements.begin())->GetType(); + bool sameElemType = ( elemType == (*theElements.rbegin())->GetType() ); + if ( sameElemType && + theMeshDS->GetMeshInfo().NbElements( elemType ) == theElements.size() ) + return; // all the elements are in theElements + + if ( !sameElemType ) + elemType = SMDSAbs_All; + + TIDSortedElemSet visitedNodes; + TIDSortedElemSet::const_iterator elemIt = theElements.begin(); + for ( ; elemIt != theElements.end(); ++elemIt ) + { + const SMDS_MeshElement* e = *elemIt; + int i = e->NbCornerNodes(); + while ( --i != -1 ) + { + const SMDS_MeshNode* n = e->GetNode( i ); + if ( visitedNodes.insert( n ).second ) + { + SMDS_ElemIteratorPtr invIt = n->GetInverseElementIterator(elemType); + while ( invIt->more() ) + { + const SMDS_MeshElement* elemAround = invIt->next(); + if ( !theElements.count( elemAround )) + theElementsAround.insert( elemAround ); + } + } + } + } + } } //============================================================================= @@ -1799,7 +1850,7 @@ SMESH::ListOfGroups* SMESH_MeshEditor_i::extrusionSweep(const SMESH::long_array & theIDsOfElements, const SMESH::DirStruct & theStepVector, CORBA::Long theNbOfSteps, - const bool theMakeGroups, + bool theMakeGroups, const SMDSAbs_ElementType theElementType) { initData(); @@ -1816,16 +1867,14 @@ SMESH_MeshEditor_i::extrusionSweep(const SMESH::long_array & theIDsOfElements, TIDSortedElemSet* workElements = & elements; TPreviewMesh tmpMesh( SMDSAbs_Face ); - SMESH_Mesh* mesh = 0; + SMESH_Mesh* mesh = myMesh; if ( myPreviewMode ) { SMDSAbs_ElementType select = SMDSAbs_All, avoid = SMDSAbs_Volume; tmpMesh.Copy( elements, copyElements, select, avoid ); mesh = &tmpMesh; workElements = & copyElements; - } - else { - mesh = myMesh; + theMakeGroups = false; } TElemOfElemListMap aHystory; @@ -2208,7 +2257,7 @@ SMESH_MeshEditor_i::extrusionAlongPathX(const SMESH::long_array & IDsOfElements CORBA::Boolean LinearVariation, CORBA::Boolean HasRefPoint, const SMESH::PointStruct& RefPoint, - const bool MakeGroups, + bool MakeGroups, const SMDSAbs_ElementType ElementType, SMESH::SMESH_MeshEditor::Extrusion_Error & Error) { @@ -2233,7 +2282,7 @@ SMESH_MeshEditor_i::extrusionAlongPathX(const SMESH::long_array & IDsOfElements TIDSortedElemSet* workElements = &elements; TPreviewMesh tmpMesh( SMDSAbs_Face ); - SMESH_Mesh* mesh = 0; + SMESH_Mesh* mesh = myMesh; if ( myPreviewMode ) { @@ -2241,17 +2290,14 @@ SMESH_MeshEditor_i::extrusionAlongPathX(const SMESH::long_array & IDsOfElements tmpMesh.Copy( elements, copyElements, select, avoid ); mesh = &tmpMesh; workElements = & copyElements; - } - else - { - mesh = myMesh; + MakeGroups = false; } ::SMESH_MeshEditor anEditor( mesh ); ::SMESH_MeshEditor::Extrusion_Error error; - SMESH_Mesh_i* aMeshImp = SMESH::DownCast( Path ); - if(aMeshImp) { + if ( SMESH_Mesh_i* aMeshImp = SMESH::DownCast( Path )) + { // path as mesh SMDS_MeshNode* aNodeStart = (SMDS_MeshNode*)aMeshImp->GetImpl().GetMeshDS()->FindNode(NodeStart); @@ -2264,36 +2310,34 @@ SMESH_MeshEditor_i::extrusionAlongPathX(const SMESH::long_array & IDsOfElements HasRefPoint, refPnt, MakeGroups ); myMesh->GetMeshDS()->Modified(); } - else { - SMESH_subMesh_i* aSubMeshImp = SMESH::DownCast( Path ); - if(aSubMeshImp) { - // path as submesh - SMESH::SMESH_Mesh_ptr aPathMesh = aSubMeshImp->GetFather(); - aMeshImp = SMESH::DownCast( aPathMesh ); - SMDS_MeshNode* aNodeStart = - (SMDS_MeshNode*)aMeshImp->GetImpl().GetMeshDS()->FindNode(NodeStart); - if ( !aNodeStart ) { - Error = SMESH::SMESH_MeshEditor::EXTR_BAD_STARTING_NODE; - return EmptyGr; - } - SMESH_subMesh* aSubMesh = - aMeshImp->GetImpl().GetSubMeshContaining(aSubMeshImp->GetId()); - error = anEditor.ExtrusionAlongTrack( *workElements, aSubMesh, aNodeStart, - HasAngles, angles, LinearVariation, - HasRefPoint, refPnt, MakeGroups ); - myMesh->GetMeshDS()->Modified(); - } - else { - SMESH_Group_i* aGroupImp = SMESH::DownCast( Path ); - if(aGroupImp) { - // path as group of 1D elements - } - else { - // invalid path - Error = SMESH::SMESH_MeshEditor::EXTR_BAD_PATH_SHAPE; - return EmptyGr; - } + else if ( SMESH_subMesh_i* aSubMeshImp = SMESH::DownCast( Path )) + { + // path as submesh + SMESH::SMESH_Mesh_ptr aPathMesh = aSubMeshImp->GetFather(); + aMeshImp = SMESH::DownCast( aPathMesh ); + SMDS_MeshNode* aNodeStart = + (SMDS_MeshNode*)aMeshImp->GetImpl().GetMeshDS()->FindNode(NodeStart); + if ( !aNodeStart ) { + Error = SMESH::SMESH_MeshEditor::EXTR_BAD_STARTING_NODE; + return EmptyGr; } + SMESH_subMesh* aSubMesh = + aMeshImp->GetImpl().GetSubMeshContaining(aSubMeshImp->GetId()); + error = anEditor.ExtrusionAlongTrack( *workElements, aSubMesh, aNodeStart, + HasAngles, angles, LinearVariation, + HasRefPoint, refPnt, MakeGroups ); + myMesh->GetMeshDS()->Modified(); + } + else if ( SMESH::DownCast( Path )) + { + // path as group of 1D elements + // ???????? + } + else + { + // invalid path + Error = SMESH::SMESH_MeshEditor::EXTR_BAD_PATH_SHAPE; + return EmptyGr; } storeResult(anEditor); @@ -2891,7 +2935,7 @@ SMESH_MeshEditor_i::mirror(TIDSortedElemSet & theElements, const SMESH::AxisStruct & theAxis, SMESH::SMESH_MeshEditor::MirrorType theMirrorType, CORBA::Boolean theCopy, - const bool theMakeGroups, + bool theMakeGroups, ::SMESH_Mesh* theTargetMesh) { initData(); @@ -2899,6 +2943,9 @@ SMESH_MeshEditor_i::mirror(TIDSortedElemSet & theElements, gp_Pnt P ( theAxis.x, theAxis.y, theAxis.z ); gp_Vec V ( theAxis.vx, theAxis.vy, theAxis.vz ); + if ( theTargetMesh ) + theCopy = false; + gp_Trsf aTrsf; switch ( theMirrorType ) { case SMESH::SMESH_MeshEditor::POINT: @@ -2911,21 +2958,23 @@ SMESH_MeshEditor_i::mirror(TIDSortedElemSet & theElements, aTrsf.SetMirror( gp_Ax2( P, V )); } - TIDSortedElemSet copyElements; + TIDSortedElemSet copyElements; TPreviewMesh tmpMesh; - TIDSortedElemSet* workElements = 0; - SMESH_Mesh* mesh = 0; + TIDSortedElemSet* workElements = & theElements; + SMESH_Mesh* mesh = myMesh; if ( myPreviewMode ) { tmpMesh.Copy( theElements, copyElements); + if ( !theCopy && !theTargetMesh ) + { + TIDSortedElemSet elemsAround, elemsAroundCopy; + getElementsAround( theElements, GetMeshDS(), elemsAround ); + tmpMesh.Copy( elemsAround, elemsAroundCopy); + } mesh = &tmpMesh; workElements = & copyElements; - } - else - { - mesh = myMesh; - workElements = & theElements; + theMakeGroups = false; } ::SMESH_MeshEditor anEditor( mesh ); @@ -2935,11 +2984,10 @@ SMESH_MeshEditor_i::mirror(TIDSortedElemSet & theElements, if(theCopy || myPreviewMode) storeResult(anEditor); else - { - myMesh->GetMeshDS()->Modified(); - myMesh->SetIsModified( true ); - } - + { + myMesh->SetIsModified( true ); + myMesh->GetMeshDS()->Modified(); + } return theMakeGroups ? getGroups(groupIds.get()) : 0; } @@ -3153,30 +3201,35 @@ SMESH::ListOfGroups* SMESH_MeshEditor_i::translate(TIDSortedElemSet & theElements, const SMESH::DirStruct & theVector, CORBA::Boolean theCopy, - const bool theMakeGroups, + bool theMakeGroups, ::SMESH_Mesh* theTargetMesh) { initData(); + if ( theTargetMesh ) + theCopy = false; + gp_Trsf aTrsf; const SMESH::PointStruct * P = &theVector.PS; aTrsf.SetTranslation( gp_Vec( P->x, P->y, P->z )); - TIDSortedElemSet copyElements; + TIDSortedElemSet copyElements; + TIDSortedElemSet* workElements = &theElements; TPreviewMesh tmpMesh; - TIDSortedElemSet* workElements = 0; - SMESH_Mesh* mesh = 0; + SMESH_Mesh* mesh = myMesh; if ( myPreviewMode ) { tmpMesh.Copy( theElements, copyElements); + if ( !theCopy && !theTargetMesh ) + { + TIDSortedElemSet elemsAround, elemsAroundCopy; + getElementsAround( theElements, GetMeshDS(), elemsAround ); + tmpMesh.Copy( elemsAround, elemsAroundCopy); + } mesh = &tmpMesh; workElements = & copyElements; - } - else - { - mesh = myMesh; - workElements = & theElements; + theMakeGroups = false; } ::SMESH_MeshEditor anEditor( mesh ); @@ -3186,10 +3239,10 @@ SMESH_MeshEditor_i::translate(TIDSortedElemSet & theElements, if(theCopy || myPreviewMode) storeResult(anEditor); else - { - myMesh->GetMeshDS()->Modified(); - myMesh->SetIsModified( true ); - } + { + myMesh->GetMeshDS()->Modified(); + myMesh->SetIsModified( true ); + } return theMakeGroups ? getGroups(groupIds.get()) : 0; } @@ -3389,31 +3442,36 @@ SMESH_MeshEditor_i::rotate(TIDSortedElemSet & theElements, const SMESH::AxisStruct & theAxis, CORBA::Double theAngle, CORBA::Boolean theCopy, - const bool theMakeGroups, + bool theMakeGroups, ::SMESH_Mesh* theTargetMesh) { initData(); + if ( theTargetMesh ) + theCopy = false; + gp_Pnt P ( theAxis.x, theAxis.y, theAxis.z ); gp_Vec V ( theAxis.vx, theAxis.vy, theAxis.vz ); gp_Trsf aTrsf; aTrsf.SetRotation( gp_Ax1( P, V ), theAngle); - TIDSortedElemSet copyElements; + TIDSortedElemSet copyElements; + TIDSortedElemSet* workElements = &theElements; TPreviewMesh tmpMesh; - TIDSortedElemSet* workElements = 0; - SMESH_Mesh* mesh = 0; + SMESH_Mesh* mesh = myMesh; if ( myPreviewMode ) { tmpMesh.Copy( theElements, copyElements ); + if ( !theCopy && !theTargetMesh ) + { + TIDSortedElemSet elemsAround, elemsAroundCopy; + getElementsAround( theElements, GetMeshDS(), elemsAround ); + tmpMesh.Copy( elemsAround, elemsAroundCopy); + } mesh = &tmpMesh; workElements = ©Elements; - } - else - { - mesh = myMesh; - workElements=&theElements; + theMakeGroups = false; } ::SMESH_MeshEditor anEditor( mesh ); @@ -3423,10 +3481,10 @@ SMESH_MeshEditor_i::rotate(TIDSortedElemSet & theElements, if(theCopy || myPreviewMode) storeResult(anEditor); else - { - myMesh->GetMeshDS()->Modified(); - myMesh->SetIsModified( true ); - } + { + myMesh->GetMeshDS()->Modified(); + myMesh->SetIsModified( true ); + } return theMakeGroups ? getGroups(groupIds.get()) : 0; } @@ -3640,7 +3698,7 @@ SMESH_MeshEditor_i::scale(SMESH::SMESH_IDSource_ptr theObject, const SMESH::PointStruct& thePoint, const SMESH::double_array& theScaleFact, CORBA::Boolean theCopy, - const bool theMakeGroups, + bool theMakeGroups, ::SMESH_Mesh* theTargetMesh) { initData(); @@ -3649,36 +3707,42 @@ SMESH_MeshEditor_i::scale(SMESH::SMESH_IDSource_ptr theObject, if ( theScaleFact.length() == 2 ) THROW_SALOME_CORBA_EXCEPTION("Invalid nb of scale factors : 2", SALOME::BAD_PARAM); + if ( theTargetMesh ) + theCopy = false; + TIDSortedElemSet elements; bool emptyIfIsMesh = myPreviewMode ? false : true; if ( !idSourceToSet(theObject, GetMeshDS(), elements, SMDSAbs_All, emptyIfIsMesh)) return 0; - vector S(3); - S[0] = theScaleFact[0]; - S[1] = (theScaleFact.length() == 1) ? theScaleFact[0] : theScaleFact[1]; - S[2] = (theScaleFact.length() == 1) ? theScaleFact[0] : theScaleFact[2]; + double S[3] = { + theScaleFact[0], + (theScaleFact.length() == 1) ? theScaleFact[0] : theScaleFact[1], + (theScaleFact.length() == 1) ? theScaleFact[0] : theScaleFact[2], + }; double tol = std::numeric_limits::max(); gp_Trsf aTrsf; aTrsf.SetValues( S[0], 0, 0, thePoint.x * (1-S[0]), 0, S[1], 0, thePoint.y * (1-S[1]), 0, 0, S[2], thePoint.z * (1-S[2]), tol, tol); - TIDSortedElemSet copyElements; + TIDSortedElemSet copyElements; TPreviewMesh tmpMesh; - TIDSortedElemSet* workElements = 0; - SMESH_Mesh* mesh = 0; + TIDSortedElemSet* workElements = &elements; + SMESH_Mesh* mesh = myMesh; if ( myPreviewMode ) { tmpMesh.Copy( elements, copyElements); + if ( !theCopy && !theTargetMesh ) + { + TIDSortedElemSet elemsAround, elemsAroundCopy; + getElementsAround( elements, GetMeshDS(), elemsAround ); + tmpMesh.Copy( elemsAround, elemsAroundCopy); + } mesh = &tmpMesh; workElements = & copyElements; - } - else - { - mesh = myMesh; - workElements = & elements; + theMakeGroups = false; } ::SMESH_MeshEditor anEditor( mesh ); @@ -3688,10 +3752,10 @@ SMESH_MeshEditor_i::scale(SMESH::SMESH_IDSource_ptr theObject, if(theCopy || myPreviewMode ) storeResult(anEditor); else - { - myMesh->GetMeshDS()->Modified(); - myMesh->SetIsModified( true ); - } + { + myMesh->GetMeshDS()->Modified(); + myMesh->SetIsModified( true ); + } return theMakeGroups ? getGroups(groupIds.get()) : 0; } @@ -4645,18 +4709,22 @@ void SMESH_MeshEditor_i::storeResult(::SMESH_MeshEditor& anEditor) } { - // add new nodes into myLastCreatedNodes + // append new nodes into myLastCreatedNodes const SMESH_SequenceOfElemPtr& aSeq = anEditor.GetLastCreatedNodes(); - myLastCreatedNodes->length(aSeq.Length()); - for(int i=0; iGetID(); + int j = myLastCreatedNodes->length(); + int newLen = j + aSeq.Length(); + myLastCreatedNodes->length( newLen ); + for(int i=0; jGetID(); } { - // add new elements into myLastCreatedElems + // append new elements into myLastCreatedElems const SMESH_SequenceOfElemPtr& aSeq = anEditor.GetLastCreatedElems(); - myLastCreatedElems->length(aSeq.Length()); - for(int i=0; iGetID(); + int j = myLastCreatedElems->length(); + int newLen = j + aSeq.Length(); + myLastCreatedElems->length( newLen ); + for(int i=0; jGetID(); } } @@ -4724,6 +4792,74 @@ CORBA::Boolean SMESH_MeshEditor_i::ConvertFromQuadratic() myMesh->SetIsModified( true ); return isDone; } +//================================================================================ +/*! + * \brief Makes a part of the mesh quadratic + */ +//================================================================================ + +void SMESH_MeshEditor_i::ConvertToQuadraticObject(CORBA::Boolean theForce3d, + SMESH::SMESH_IDSource_ptr theObject) + throw (SALOME::SALOME_Exception) +{ + Unexpect aCatch(SALOME_SalomeException); + TPythonDump pyDump; + TIDSortedElemSet elems; + if ( idSourceToSet( theObject, GetMeshDS(), elems, SMDSAbs_All, /*emptyIfIsMesh=*/true )) + { + if ( elems.empty() ) + { + ConvertToQuadratic( theForce3d ); + } + else if ( (*elems.begin())->GetType() == SMDSAbs_Node ) + { + THROW_SALOME_CORBA_EXCEPTION("Group of nodes is not allowed", SALOME::BAD_PARAM); + } + else + { + ::SMESH_MeshEditor anEditor( myMesh ); + anEditor.ConvertToQuadratic(theForce3d, elems); + } + } + myMesh->GetMeshDS()->Modified(); + myMesh->SetIsModified( true ); + + pyDump << this << ".ConvertToQuadraticObject( "<GetType() == SMDSAbs_Node ) + { + THROW_SALOME_CORBA_EXCEPTION("Group of nodes is not allowed", SALOME::BAD_PARAM); + } + else + { + ::SMESH_MeshEditor anEditor( myMesh ); + anEditor.ConvertFromQuadratic(elems); + } + } + myMesh->GetMeshDS()->Modified(); + myMesh->SetIsModified( true ); + + pyDump << this << ".ConvertFromQuadraticObject( "<GetMeshDS()->Modified(); @@ -5493,6 +5631,53 @@ CORBA::Boolean SMESH_MeshEditor_i::DoubleNodesOnGroupBoundaries( const SMESH::Li return aResult; } +//================================================================================ +/*! + * \brief Double nodes on some external faces and create flat elements. + * Flat elements are mainly used by some types of mechanic calculations. + * + * Each group of the list must be constituted of faces. + * Triangles are transformed in prisms, and quadrangles in hexahedrons. + * @param theGroupsOfFaces - list of groups of faces + * @return TRUE if operation has been completed successfully, FALSE otherwise + */ +//================================================================================ + +CORBA::Boolean SMESH_MeshEditor_i::CreateFlatElementsOnFacesGroups( const SMESH::ListOfGroups& theGroupsOfFaces ) +{ + initData(); + + ::SMESH_MeshEditor aMeshEditor( myMesh ); + + SMESHDS_Mesh* aMeshDS = GetMeshDS(); + + vector faceGroups; + faceGroups.clear(); + + for ( int i = 0, n = theGroupsOfFaces.length(); i < n; i++ ) + { + SMESH::SMESH_GroupBase_var aGrp = theGroupsOfFaces[ i ]; + if ( !CORBA::is_nil( aGrp ) && ( aGrp->GetType() != SMESH::NODE ) ) + { + TIDSortedElemSet faceGroup; + faceGroup.clear(); + faceGroups.push_back(faceGroup); + SMESH::long_array_var anIDs = aGrp->GetIDs(); + arrayToSet( anIDs, aMeshDS, faceGroups[ i ], SMDSAbs_All ); + } + } + + bool aResult = aMeshEditor.CreateFlatElementsOnFacesGroups( faceGroups ); + // TODO publish the groups of flat elements in study + + storeResult( aMeshEditor) ; + myMesh->GetMeshDS()->Modified(); + + // Update Python script + TPythonDump() << "isDone = " << this << ".CreateFlatElementsOnFacesGroups( " << &theGroupsOfFaces << " )"; + return aResult; +} + // issue 20749 =================================================================== /*! * \brief Creates missing boundary elements @@ -5524,7 +5709,6 @@ SMESH_MeshEditor_i::MakeBoundaryMesh(SMESH::SMESH_IDSource_ptr idSource, 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; @@ -5561,6 +5745,9 @@ SMESH_MeshEditor_i::MakeBoundaryMesh(SMESH::SMESH_IDSource_ptr idSource, toCopyElements, toCopyExistingBondary); storeResult( aMeshEditor ); + + if ( smesh_mesh ) + smesh_mesh->GetMeshDS()->Modified(); } const char* dimName[] = { "BND_2DFROM3D", "BND_1DFROM3D", "BND_1DFROM2D" }; @@ -5585,3 +5772,146 @@ SMESH_MeshEditor_i::MakeBoundaryMesh(SMESH::SMESH_IDSource_ptr idSource, 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); + + // check that groups belongs to to this mesh and is not this mesh + const int nbGroups = groups.length(); + for ( int i = 0; i < nbGroups; ++i ) + { + SMESH::SMESH_Mesh_var m = groups[i]->GetMesh(); + if ( myMesh_i != SMESH::DownCast( m )) + THROW_SALOME_CORBA_EXCEPTION("group does not belong to this mesh", SALOME::BAD_PARAM); + if ( SMESH::DownCast( groups[i] )) + THROW_SALOME_CORBA_EXCEPTION("expect a group but recieve a mesh", SALOME::BAD_PARAM); + } + + TPythonDump pyDump; + + int nbAdded = 0; + 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( 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( group_var )) + smesh_group = group_i->GetSmeshGroup(); + } + + TIDSortedElemSet elements; + + if ( nbGroups > 0 ) + { + for ( int i = 0; i < nbGroups; ++i ) + { + elements.clear(); + if ( idSourceToSet( groups[i], srcMeshDS, elements, elemType,/*emptyIfIsMesh=*/false )) + { + SMESH::Bnd_Dimension bdim = + ( elemType == SMDSAbs_Volume ) ? SMESH::BND_2DFROM3D : SMESH::BND_1DFROM2D; + ::SMESH_MeshEditor aMeshEditor( srcMesh ); + nbAdded += aMeshEditor.MakeBoundaryMesh( elements, + ::SMESH_MeshEditor::Bnd_Dimension(bdim), + smesh_group, + tgtMesh, + /*toCopyElements=*/false, + /*toCopyExistingBondary=*/srcMesh != tgtMesh, + /*toAddExistingBondary=*/true, + /*aroundElements=*/true); + storeResult( aMeshEditor ); + } + } + } + else + { + ::SMESH_MeshEditor aMeshEditor( srcMesh ); + nbAdded += aMeshEditor.MakeBoundaryMesh( elements, + ::SMESH_MeshEditor::Bnd_Dimension(dim), + smesh_group, + tgtMesh, + /*toCopyElements=*/false, + /*toCopyExistingBondary=*/srcMesh != tgtMesh, + /*toAddExistingBondary=*/true); + storeResult( aMeshEditor ); + } + 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; +}