X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FSMESH_I%2FSMESH_MeshEditor_i.cxx;h=2d3f5b88831641f040fa6a505dfba9ea990e6738;hb=f0bf265fc0ea849ad1a359e10ad0c9cf6b0b9bb8;hp=0ae64289ecc79bc4a9677a2ad6fe940a4462718a;hpb=93e79bb6c3a7c6e695af77feabbf5bb17c41ab42;p=modules%2Fsmesh.git diff --git a/src/SMESH_I/SMESH_MeshEditor_i.cxx b/src/SMESH_I/SMESH_MeshEditor_i.cxx index 0ae64289e..2d3f5b888 100644 --- a/src/SMESH_I/SMESH_MeshEditor_i.cxx +++ b/src/SMESH_I/SMESH_MeshEditor_i.cxx @@ -1,4 +1,4 @@ -// Copyright (C) 2007-2011 CEA/DEN, EDF R&D, OPEN CASCADE +// Copyright (C) 2007-2012 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 @@ -29,20 +29,42 @@ #include "SMESH_MeshEditor_i.hxx" +#include "DriverMED_R_SMESHDS_Mesh.h" +#include "DriverMED_W_SMESHDS_Mesh.h" +#include "SMDS_EdgePosition.hxx" +#include "SMDS_ElemIterator.hxx" +#include "SMDS_FacePosition.hxx" +#include "SMDS_IteratorOnIterators.hxx" #include "SMDS_LinearEdge.hxx" #include "SMDS_Mesh0DElement.hxx" #include "SMDS_MeshFace.hxx" #include "SMDS_MeshVolume.hxx" #include "SMDS_PolyhedralVolumeOfNodes.hxx" #include "SMDS_SetIterator.hxx" +#include "SMDS_SetIterator.hxx" +#include "SMDS_VolumeTool.hxx" +#include "SMESHDS_Command.hxx" +#include "SMESHDS_CommandType.hxx" #include "SMESHDS_Group.hxx" +#include "SMESHDS_GroupOnGeom.hxx" #include "SMESH_ControlsDef.hxx" #include "SMESH_Filter_i.hxx" +#include "SMESH_Filter_i.hxx" #include "SMESH_Gen_i.hxx" +#include "SMESH_Gen_i.hxx" +#include "SMESH_Group.hxx" +#include "SMESH_Group_i.hxx" #include "SMESH_Group_i.hxx" +#include "SMESH_MEDMesh_i.hxx" +#include "SMESH_MeshEditor.hxx" +#include "SMESH_MeshPartDS.hxx" +#include "SMESH_MesherHelper.hxx" +#include "SMESH_PreMeshInfo.hxx" +#include "SMESH_PythonDump.hxx" #include "SMESH_PythonDump.hxx" #include "SMESH_subMeshEventListener.hxx" #include "SMESH_subMesh_i.hxx" +#include "SMESH_subMesh_i.hxx" #include "utilities.h" #include "Utils_ExceptHandlers.hxx" @@ -261,7 +283,7 @@ namespace { const SMDS_MeshElement * elem = (aType == SMDSAbs_Node ? aMesh->FindNode(ind) : aMesh->FindElement(ind)); if ( elem && ( aType == SMDSAbs_All || elem->GetType() == aType )) - aMap.insert( elem ); + aMap.insert( aMap.end(), elem ); } } //================================================================================ @@ -296,6 +318,7 @@ namespace { else { arrayToSet( anIDs, theMeshDS, theElemSet, theType); + return bool(anIDs->length()) == bool(theElemSet.size()); } return true; } @@ -378,6 +401,24 @@ namespace { } } } + + //================================================================================ + /*! + * \brief Return a string used to detect change of mesh part on which theElementSearcher + * is going to be used + */ + //================================================================================ + + string getPartIOR( SMESH::SMESH_IDSource_ptr theMeshPart, SMESH::ElementType type) + { + string partIOR = SMESH_Gen_i::GetORB()->object_to_string( theMeshPart ); + if ( SMESH_Group_i* group_i = SMESH::DownCast( theMeshPart )) + // take into account passible group modification + partIOR += SMESH_Comment( ((SMESHDS_Group*)group_i->GetGroupDS())->SMDSGroup().Tic() ); + partIOR += SMESH_Comment( type ); + return partIOR; + } + } //============================================================================= @@ -386,11 +427,12 @@ namespace { */ //============================================================================= -SMESH_MeshEditor_i::SMESH_MeshEditor_i(SMESH_Mesh_i* theMesh, bool isPreview) +SMESH_MeshEditor_i::SMESH_MeshEditor_i(SMESH_Mesh_i* theMesh, bool isPreview): + myMesh_i( theMesh ), + myMesh( &theMesh->GetImpl() ), + myEditor( myMesh ), + myPreviewMode ( isPreview ) { - myMesh_i = theMesh; - myMesh = & theMesh->GetImpl(); - myPreviewMode = isPreview; } //================================================================================ @@ -401,6 +443,7 @@ SMESH_MeshEditor_i::SMESH_MeshEditor_i(SMESH_Mesh_i* theMesh, bool isPreview) SMESH_MeshEditor_i::~SMESH_MeshEditor_i() { + deleteAuxIDSources(); } //================================================================================ @@ -412,14 +455,170 @@ SMESH_MeshEditor_i::~SMESH_MeshEditor_i() void SMESH_MeshEditor_i::initData(bool deleteSearchers) { if ( myPreviewMode ) { - myPreviewData = new SMESH::MeshPreviewStruct(); + //myPreviewData = new SMESH::MeshPreviewStruct(); } else { - myLastCreatedElems = new SMESH::long_array(); - myLastCreatedNodes = new SMESH::long_array(); if ( deleteSearchers ) TSearchersDeleter::Delete(); } + myEditor.GetError().reset(); + myEditor.CrearLastCreated(); +} + +//================================================================================ +/*! + * \brief Now does nothing + */ +//================================================================================ + +void SMESH_MeshEditor_i::storeResult(::SMESH_MeshEditor& ) +{ +} + +//================================================================================ +/*! + * Return data of mesh edition preview + */ +//================================================================================ + +SMESH::MeshPreviewStruct* SMESH_MeshEditor_i::GetPreviewData() +{ + const bool hasBadElems = ( myEditor.GetError() && myEditor.GetError()->HasBadElems() ); + + if ( myPreviewMode || hasBadElems ) { // --- MeshPreviewStruct filling --- + + list aNodesConnectivity; + typedef map TNodesMap; + TNodesMap nodesMap; + + SMESHDS_Mesh* aMeshDS; + std::auto_ptr< SMESH_MeshPartDS > aMeshPartDS; + if ( hasBadElems ) { + aMeshPartDS.reset( new SMESH_MeshPartDS( myEditor.GetError()->myBadElements )); + aMeshDS = aMeshPartDS.get(); + } + else { + aMeshDS = myEditor.GetMeshDS(); + } + int nbEdges = aMeshDS->NbEdges(); + int nbFaces = aMeshDS->NbFaces(); + int nbVolum = aMeshDS->NbVolumes(); + myPreviewData = new SMESH::MeshPreviewStruct(); + myPreviewData->nodesXYZ.length(aMeshDS->NbNodes()); + + + SMDSAbs_ElementType previewType = SMDSAbs_All; + if ( !hasBadElems ) + if (TPreviewMesh * aPreviewMesh = dynamic_cast< TPreviewMesh* >( myEditor.GetMesh() )) { + previewType = aPreviewMesh->myPreviewType; + switch ( previewType ) { + case SMDSAbs_Edge : nbFaces = nbVolum = 0; break; + case SMDSAbs_Face : nbEdges = nbVolum = 0; break; + case SMDSAbs_Volume: nbEdges = nbFaces = 0; break; + default:; + } + } + + myPreviewData->elementTypes.length(nbEdges + nbFaces + nbVolum); + int i = 0, j = 0; + SMDS_ElemIteratorPtr itMeshElems = aMeshDS->elementsIterator(); + + while ( itMeshElems->more() ) { + const SMDS_MeshElement* aMeshElem = itMeshElems->next(); + if ( previewType != SMDSAbs_All && aMeshElem->GetType() != previewType ) + continue; + + SMDS_ElemIteratorPtr itElemNodes = aMeshElem->nodesIterator(); + while ( itElemNodes->more() ) { + const SMDS_MeshNode* aMeshNode = + static_cast( itElemNodes->next() ); + int aNodeID = aMeshNode->GetID(); + TNodesMap::iterator anIter = nodesMap.find(aNodeID); + if ( anIter == nodesMap.end() ) { + // filling the nodes coordinates + myPreviewData->nodesXYZ[j].x = aMeshNode->X(); + myPreviewData->nodesXYZ[j].y = aMeshNode->Y(); + myPreviewData->nodesXYZ[j].z = aMeshNode->Z(); + anIter = nodesMap.insert( make_pair(aNodeID, j) ).first; + j++; + } + aNodesConnectivity.push_back(anIter->second); + } + + // filling the elements types + SMDSAbs_ElementType aType = aMeshElem->GetType(); + bool isPoly = aMeshElem->IsPoly(); + + myPreviewData->elementTypes[i].SMDS_ElementType = (SMESH::ElementType) aType; + myPreviewData->elementTypes[i].isPoly = isPoly; + myPreviewData->elementTypes[i].nbNodesInElement = aMeshElem->NbNodes(); + i++; + + } + myPreviewData->nodesXYZ.length( j ); + + // filling the elements connectivities + list::iterator aConnIter = aNodesConnectivity.begin(); + myPreviewData->elementConnectivities.length(aNodesConnectivity.size()); + for( int i = 0; aConnIter != aNodesConnectivity.end(); aConnIter++, i++ ) + myPreviewData->elementConnectivities[i] = *aConnIter; + } + + return myPreviewData._retn(); +} + +//================================================================================ +/*! + * \brief Returns list of it's IDs of created nodes + * \retval SMESH::long_array* - list of node ID + */ +//================================================================================ + +SMESH::long_array* SMESH_MeshEditor_i::GetLastCreatedNodes() +{ + SMESH::long_array_var myLastCreatedNodes = new SMESH::long_array(); + const SMESH_SequenceOfElemPtr& aSeq = myEditor.GetLastCreatedNodes(); + myLastCreatedNodes->length( aSeq.Length() ); + for (int i = 1; i <= aSeq.Length(); i++) + myLastCreatedNodes[i-1] = aSeq.Value(i)->GetID(); + return myLastCreatedNodes._retn(); +} + +//================================================================================ +/*! + * \brief Returns list of it's IDs of created elements + * \retval SMESH::long_array* - list of elements' ID + */ +//================================================================================ + +SMESH::long_array* SMESH_MeshEditor_i::GetLastCreatedElems() +{ + SMESH::long_array_var myLastCreatedElems = new SMESH::long_array(); + const SMESH_SequenceOfElemPtr& aSeq = myEditor.GetLastCreatedElems(); + myLastCreatedElems->length( aSeq.Length() ); + for ( int i = 1; i <= aSeq.Length(); i++ ) + myLastCreatedElems[i-1] = aSeq.Value(i)->GetID(); + return myLastCreatedElems._retn(); +} + +//======================================================================= +/* + * Returns description of an error/warning occured during the last operation + */ +//======================================================================= + +SMESH::ComputeError* SMESH_MeshEditor_i::GetLastError() +{ + SMESH::ComputeError* errOut = new SMESH::ComputeError; + SMESH_ComputeErrorPtr& errIn = myEditor.GetError(); + if ( errIn && !errIn->IsOK() ) + { + errOut->code = -( errIn->myName < 0 ? errIn->myName + 1: errIn->myName ); // -1 -> 0 + errOut->comment = errIn->myComment.c_str(); + errOut->subShapeID = -1; + errOut->hasBadMesh = !errIn->myBadElements.empty(); + } + return errOut; } //======================================================================= @@ -427,7 +626,7 @@ void SMESH_MeshEditor_i::initData(bool deleteSearchers) //purpose : Wrap a sequence of ids in a SMESH_IDSource //======================================================================= -struct _IDSource : public POA_SMESH::SMESH_IDSource +struct SMESH_MeshEditor_i::_IDSource : public POA_SMESH::SMESH_IDSource { SMESH::long_array _ids; SMESH::ElementType _type; @@ -450,15 +649,28 @@ struct _IDSource : public POA_SMESH::SMESH_IDSource SMESH::SMESH_IDSource_ptr SMESH_MeshEditor_i::MakeIDSource(const SMESH::long_array& ids, SMESH::ElementType type) { - _IDSource* anIDSource = new _IDSource; - anIDSource->_ids = ids; - anIDSource->_type = type; - anIDSource->_mesh = myMesh_i->_this(); - SMESH::SMESH_IDSource_var anIDSourceVar = anIDSource->_this(); + if ( myAuxIDSources.size() > 10 ) + deleteAuxIDSources(); + + _IDSource* idSrc = new _IDSource; + idSrc->_mesh = myMesh_i->_this(); + idSrc->_ids = ids; + idSrc->_type = type; + myAuxIDSources.push_back( idSrc ); + + SMESH::SMESH_IDSource_var anIDSourceVar = idSrc->_this(); return anIDSourceVar._retn(); } +void SMESH_MeshEditor_i::deleteAuxIDSources() +{ + std::list< _IDSource* >::iterator idSrcIt = myAuxIDSources.begin(); + for ( ; idSrcIt != myAuxIDSources.end(); ++idSrcIt ) + delete *idSrcIt; + myAuxIDSources.clear(); +} + //============================================================================= /*! * @@ -470,7 +682,6 @@ SMESH_MeshEditor_i::RemoveElements(const SMESH::long_array & IDsOfElements) { initData(); - ::SMESH_MeshEditor anEditor( myMesh ); list< int > IdList; for (int i = 0; i < IDsOfElements.length(); i++) @@ -480,7 +691,7 @@ SMESH_MeshEditor_i::RemoveElements(const SMESH::long_array & IDsOfElements) TPythonDump() << "isDone = " << this << ".RemoveElements( " << IDsOfElements << " )"; // Remove Elements - bool ret = anEditor.Remove( IdList, false ); + bool ret = myEditor.Remove( IdList, false ); myMesh->GetMeshDS()->Modified(); if ( IDsOfElements.length() ) myMesh->SetIsModified( true ); // issue 0020693 @@ -497,7 +708,6 @@ CORBA::Boolean SMESH_MeshEditor_i::RemoveNodes(const SMESH::long_array & IDsOfNo { initData(); - ::SMESH_MeshEditor anEditor( myMesh ); list< int > IdList; for (int i = 0; i < IDsOfNodes.length(); i++) IdList.push_back( IDsOfNodes[i] ); @@ -505,7 +715,7 @@ CORBA::Boolean SMESH_MeshEditor_i::RemoveNodes(const SMESH::long_array & IDsOfNo // Update Python script TPythonDump() << "isDone = " << this << ".RemoveNodes( " << IDsOfNodes << " )"; - bool ret = anEditor.Remove( IdList, true ); + bool ret = myEditor.Remove( IdList, true ); myMesh->GetMeshDS()->Modified(); if ( IDsOfNodes.length() ) myMesh->SetIsModified( true ); // issue 0020693 @@ -522,7 +732,6 @@ CORBA::Long SMESH_MeshEditor_i::RemoveOrphanNodes() { initData(); - ::SMESH_MeshEditor anEditor( myMesh ); // Update Python script TPythonDump() << "nbRemoved = " << this << ".RemoveOrphanNodes()"; @@ -538,7 +747,7 @@ CORBA::Long SMESH_MeshEditor_i::RemoveOrphanNodes() IdList.push_back( seq[i] ); int nbNodesBefore = myMesh->NbNodes(); - anEditor.Remove( IdList, true ); + myEditor.Remove( IdList, true ); myMesh->GetMeshDS()->Modified(); if ( IdList.size() ) myMesh->SetIsModified( true ); @@ -549,7 +758,7 @@ CORBA::Long SMESH_MeshEditor_i::RemoveOrphanNodes() //============================================================================= /*! - * + * Add a new node. */ //============================================================================= @@ -571,9 +780,10 @@ CORBA::Long SMESH_MeshEditor_i::AddNode(CORBA::Double x, //============================================================================= /*! - * + * Create 0D element on the given node. */ //============================================================================= + CORBA::Long SMESH_MeshEditor_i::Add0DElement(CORBA::Long IDOfNode) { initData(); @@ -595,7 +805,38 @@ CORBA::Long SMESH_MeshEditor_i::Add0DElement(CORBA::Long IDOfNode) //============================================================================= /*! - * + * Create a ball element on the given node. + */ +//============================================================================= + +CORBA::Long SMESH_MeshEditor_i::AddBall(CORBA::Long IDOfNode, CORBA::Double diameter) + throw (SALOME::SALOME_Exception) +{ + initData(); + + if ( diameter < std::numeric_limits::min() ) + THROW_SALOME_CORBA_EXCEPTION("Invalid diameter", SALOME::BAD_PARAM); + + const SMDS_MeshNode* aNode = GetMeshDS()->FindNode(IDOfNode); + SMDS_MeshElement* elem = GetMeshDS()->AddBall(aNode, diameter); + + // Update Python script + TPythonDump() << "ballElem = " + << this << ".AddBall( " << IDOfNode << ", " << diameter <<" )"; + + myMesh->GetMeshDS()->Modified(); + myMesh->SetIsModified( true ); // issue 0020693 + + if (elem) + return elem->GetID(); + + return 0; +} + +//============================================================================= +/*! + * Create an edge, either linear and quadratic (this is determed + * by number of given nodes, two or three) */ //============================================================================= @@ -712,7 +953,8 @@ CORBA::Long SMESH_MeshEditor_i::AddPolygonalFace (const SMESH::long_array & IDsO //============================================================================= /*! - * + * Create volume, either linear and quadratic (this is determed + * by number of given nodes) */ //============================================================================= @@ -804,6 +1046,7 @@ CORBA::Long SMESH_MeshEditor_i::AddPolyhedralVolume (const SMESH::long_array & I * AddPolyhedralVolumeByFaces */ //============================================================================= + CORBA::Long SMESH_MeshEditor_i::AddPolyhedralVolumeByFaces (const SMESH::long_array & IdsOfFaces) { initData(); @@ -832,6 +1075,77 @@ CORBA::Long SMESH_MeshEditor_i::AddPolyhedralVolumeByFaces (const SMESH::long_ar return elem ? ( myMesh->SetIsModified( true ), elem->GetID()) : 0; } +//============================================================================= +// +// \brief Create 0D elements on all nodes of the given object except those +// nodes on which a 0D element already exists. +// \param theObject object on whose nodes 0D elements will be created. +// \param theGroupName optional name of a group to add 0D elements created +// and/or found on nodes of \a theObject. +// \return an object (a new group or a temporary SMESH_IDSource) holding +// ids of new and/or found 0D elements. +// +//============================================================================= + +SMESH::SMESH_IDSource_ptr +SMESH_MeshEditor_i::Create0DElementsOnAllNodes(SMESH::SMESH_IDSource_ptr theObject, + const char* theGroupName) + throw (SALOME::SALOME_Exception) +{ + initData(); + + SMESH::SMESH_IDSource_var result; + TPythonDump pyDump; + + TIDSortedElemSet elements, elems0D; + if ( idSourceToSet( theObject, GetMeshDS(), elements, SMDSAbs_All, /*emptyIfIsMesh=*/1)) + myEditor.Create0DElementsOnAllNodes( elements, elems0D ); + + SMESH::long_array_var newElems = new SMESH::long_array; + newElems->length( elems0D.size() ); + TIDSortedElemSet::iterator eIt = elems0D.begin(); + for ( size_t i = 0; i < elems0D.size(); ++i, ++eIt ) + newElems[ i ] = (*eIt)->GetID(); + + SMESH::SMESH_GroupBase_var groupToFill; + if ( theGroupName && strlen( theGroupName )) + { + // Get existing group named theGroupName + SMESH::ListOfGroups_var groups = myMesh_i->GetGroups(); + for (int i = 0, nbGroups = groups->length(); i < nbGroups; i++ ) { + SMESH::SMESH_GroupBase_var group = groups[i]; + if ( !group->_is_nil() ) { + CORBA::String_var name = group->GetName(); + if ( strcmp( name.in(), theGroupName ) == 0 && group->GetType() == SMESH::ELEM0D ) { + groupToFill = group; + break; + } + } + } + if ( groupToFill->_is_nil() ) + groupToFill = myMesh_i->CreateGroup( SMESH::ELEM0D, theGroupName ); + else if ( !SMESH::DownCast< SMESH_Group_i* > ( groupToFill )) + groupToFill = myMesh_i->ConvertToStandalone( groupToFill ); + } + + if ( SMESH_Group_i* group_i = SMESH::DownCast< SMESH_Group_i* > ( groupToFill )) + { + group_i->Add( newElems ); + result = SMESH::SMESH_IDSource::_narrow( groupToFill ); + pyDump << groupToFill; + } + else + { + result = MakeIDSource( newElems, SMESH::ELEM0D ); + pyDump << "elem0DIDs"; + } + + pyDump << " = " << this << ".Create0DElementsOnAllNodes( " + << theObject << ", '" << theGroupName << "' )"; + + return result._retn(); +} + //============================================================================= /*! * \brief Bind a node to a vertex @@ -1039,8 +1353,7 @@ CORBA::Boolean SMESH_MeshEditor_i::InverseDiag(CORBA::Long NodeID1, << NodeID1 << ", " << NodeID2 << " )"; - ::SMESH_MeshEditor aMeshEditor( myMesh ); - int ret = aMeshEditor.InverseDiag ( n1, n2 ); + int ret = myEditor.InverseDiag ( n1, n2 ); myMesh->GetMeshDS()->Modified(); myMesh->SetIsModified( true ); return ret; @@ -1066,15 +1379,14 @@ CORBA::Boolean SMESH_MeshEditor_i::DeleteDiag(CORBA::Long NodeID1, TPythonDump() << "isDone = " << this << ".DeleteDiag( " << NodeID1 << ", " << NodeID2 << " )"; - ::SMESH_MeshEditor aMeshEditor( myMesh ); - bool stat = aMeshEditor.DeleteDiag ( n1, n2 ); + bool stat = myEditor.DeleteDiag ( n1, n2 ); myMesh->GetMeshDS()->Modified(); if ( stat ) myMesh->SetIsModified( true ); // issue 0020693 - storeResult(aMeshEditor); + storeResult(myEditor); return stat; } @@ -1089,13 +1401,12 @@ CORBA::Boolean SMESH_MeshEditor_i::Reorient(const SMESH::long_array & IDsOfEleme { initData(); - ::SMESH_MeshEditor anEditor( myMesh ); for (int i = 0; i < IDsOfElements.length(); i++) { CORBA::Long index = IDsOfElements[i]; const SMDS_MeshElement * elem = GetMeshDS()->FindElement(index); if ( elem ) - anEditor.Reorient( elem ); + myEditor.Reorient( elem ); } // Update Python script TPythonDump() << "isDone = " << this << ".Reorient( " << IDsOfElements << " )"; @@ -1129,6 +1440,93 @@ CORBA::Boolean SMESH_MeshEditor_i::ReorientObject(SMESH::SMESH_IDSource_ptr theO return isDone; } +//======================================================================= +//function : Reorient2D +//purpose : Reorient faces contained in \a the2Dgroup. +// the2Dgroup - the mesh or its part to reorient +// theDirection - desired direction of normal of \a theFace +// theFace - ID of face whose orientation is checked. +// It can be < 1 then \a thePoint is used to find a face. +// thePoint - is used to find a face if \a theFace < 1. +// return number of reoriented elements. +//======================================================================= + +CORBA::Long SMESH_MeshEditor_i::Reorient2D(SMESH::SMESH_IDSource_ptr the2Dgroup, + const SMESH::DirStruct& theDirection, + CORBA::Long theFace, + const SMESH::PointStruct& thePoint) + throw (SALOME::SALOME_Exception) +{ + Unexpect aCatch(SALOME_SalomeException); + + initData(/*deleteSearchers=*/false); + + TIDSortedElemSet elements; + if ( !idSourceToSet( the2Dgroup, GetMeshDS(), elements, SMDSAbs_Face, /*emptyIfIsMesh=*/1)) + THROW_SALOME_CORBA_EXCEPTION("No faces in given group", SALOME::BAD_PARAM); + + + const SMDS_MeshElement* face = 0; + if ( theFace > 0 ) + { + face = GetMeshDS()->FindElement( theFace ); + if ( !face ) + THROW_SALOME_CORBA_EXCEPTION("Inexistent face given", SALOME::BAD_PARAM); + if ( face->GetType() != SMDSAbs_Face ) + THROW_SALOME_CORBA_EXCEPTION("Wrong element type", SALOME::BAD_PARAM); + } + else + { + // create theElementSearcher if needed + theSearchersDeleter.Set( myMesh, getPartIOR( the2Dgroup, SMESH::FACE )); + if ( !theElementSearcher ) + { + if ( elements.empty() ) // search in the whole mesh + { + if ( myMesh->NbFaces() == 0 ) + THROW_SALOME_CORBA_EXCEPTION("No faces in the mesh", SALOME::BAD_PARAM); + + theElementSearcher = myEditor.GetElementSearcher(); + } + else + { + typedef SMDS_SetIterator TIter; + SMDS_ElemIteratorPtr elemsIt( new TIter( elements.begin(), elements.end() )); + + theElementSearcher = myEditor.GetElementSearcher(elemsIt); + } + } + // find a face + gp_Pnt p( thePoint.x, thePoint.y, thePoint.z ); + face = theElementSearcher->FindClosestTo( p, SMDSAbs_Face ); + + if ( !face ) + THROW_SALOME_CORBA_EXCEPTION("No face found by point", SALOME::INTERNAL_ERROR ); + if ( !elements.empty() && !elements.count( face )) + THROW_SALOME_CORBA_EXCEPTION("Found face is not in the group", SALOME::BAD_PARAM ); + } + + const SMESH::PointStruct * P = &theDirection.PS; + gp_Vec dirVec( P->x, P->y, P->z ); + if ( dirVec.Magnitude() < std::numeric_limits< double >::min() ) + THROW_SALOME_CORBA_EXCEPTION("Zero size vector", SALOME::BAD_PARAM); + + int nbReori = myEditor.Reorient2D( elements, dirVec, face ); + storeResult(myEditor); + + if ( nbReori ) { + myMesh->SetIsModified( true ); + myMesh->GetMeshDS()->Modified(); + } + TPythonDump() << this << ".Reorient2D( " + << the2Dgroup << ", " + << theDirection << ", " + << theFace << ", " + << thePoint << " )"; + + return nbReori; +} + //============================================================================= /*! * @@ -1148,7 +1546,7 @@ CORBA::Boolean SMESH_MeshEditor_i::TriToQuad (const SMESH::long_array & IDsOfE dynamic_cast( SMESH_Gen_i::GetServant( Criterion ).in() ); SMESH::Controls::NumericalFunctorPtr aCrit; if ( !aNumericalFunctor ) - aCrit.reset( new SMESH::Controls::AspectRatio() ); + aCrit.reset( new SMESH::Controls::MaxElementLength2D() ); else aCrit = aNumericalFunctor->GetNumericalFunctor(); @@ -1156,14 +1554,13 @@ CORBA::Boolean SMESH_MeshEditor_i::TriToQuad (const SMESH::long_array & IDsOfE TPythonDump() << "isDone = " << this << ".TriToQuad( " << IDsOfElements << ", " << aNumericalFunctor << ", " << TVar( MaxAngle ) << " )"; - ::SMESH_MeshEditor anEditor( myMesh ); - bool stat = anEditor.TriToQuad( faces, aCrit, MaxAngle ); + bool stat = myEditor.TriToQuad( faces, aCrit, MaxAngle ); myMesh->GetMeshDS()->Modified(); if ( stat ) myMesh->SetIsModified( true ); // issue 0020693 - storeResult(anEditor); + storeResult(myEditor); return stat; } @@ -1221,13 +1618,12 @@ CORBA::Boolean SMESH_MeshEditor_i::QuadToTri (const SMESH::long_array & IDsOfE // Update Python script TPythonDump() << "isDone = " << this << ".QuadToTri( " << IDsOfElements << ", " << aNumericalFunctor << " )"; - ::SMESH_MeshEditor anEditor( myMesh ); - CORBA::Boolean stat = anEditor.QuadToTri( faces, aCrit ); + CORBA::Boolean stat = myEditor.QuadToTri( faces, aCrit ); myMesh->GetMeshDS()->Modified(); if ( stat ) myMesh->SetIsModified( true ); // issue 0020693 - storeResult(anEditor); + storeResult(myEditor); return stat; } @@ -1276,14 +1672,13 @@ CORBA::Boolean SMESH_MeshEditor_i::SplitQuad (const SMESH::long_array & IDsOfEle TPythonDump() << "isDone = " << this << ".SplitQuad( " << IDsOfElements << ", " << Diag13 << " )"; - ::SMESH_MeshEditor anEditor( myMesh ); - CORBA::Boolean stat = anEditor.QuadToTri( faces, Diag13 ); + CORBA::Boolean stat = myEditor.QuadToTri( faces, Diag13 ); myMesh->GetMeshDS()->Modified(); if ( stat ) myMesh->SetIsModified( true ); // issue 0020693 - storeResult(anEditor); + storeResult(myEditor); return stat; } @@ -1333,8 +1728,7 @@ CORBA::Long SMESH_MeshEditor_i::BestSplit (CORBA::Long IDOfQuad, else aCrit.reset(new SMESH::Controls::AspectRatio()); - ::SMESH_MeshEditor anEditor (myMesh); - return anEditor.BestSplit(quad, aCrit); + return myEditor.BestSplit(quad, aCrit); } return -1; } @@ -1357,11 +1751,10 @@ void SMESH_MeshEditor_i::SplitVolumesIntoTetra (SMESH::SMESH_IDSource_ptr elems, TIDSortedElemSet elemSet; arrayToSet( anElementsId, GetMeshDS(), elemSet, SMDSAbs_Volume ); - ::SMESH_MeshEditor anEditor (myMesh); - anEditor.SplitVolumesIntoTetra( elemSet, int( methodFlags )); + myEditor.SplitVolumesIntoTetra( elemSet, int( methodFlags )); myMesh->GetMeshDS()->Modified(); - storeResult(anEditor); + storeResult(myEditor); // if ( myLastCreatedElems.length() ) - it does not influence Compute() // myMesh->SetIsModified( true ); // issue 0020693 @@ -1470,14 +1863,13 @@ SMESH_MeshEditor_i::smooth(const SMESH::long_array & IDsOfElements, if ( Method != SMESH::SMESH_MeshEditor::LAPLACIAN_SMOOTH ) method = ::SMESH_MeshEditor::CENTROIDAL; - ::SMESH_MeshEditor anEditor( myMesh ); - anEditor.Smooth(elements, fixedNodes, method, + myEditor.Smooth(elements, fixedNodes, method, MaxNbOfIterations, MaxAspectRatio, IsParametric ); myMesh->GetMeshDS()->Modified(); myMesh->SetIsModified( true ); // issue 0020693 - storeResult(anEditor); + storeResult(myEditor); // Update Python script TPythonDump() << "isDone = " << this << "." @@ -1609,11 +2001,10 @@ SMESH_MeshEditor_i::rotationSweep(const SMESH::long_array & theIDsOfElements, gp_Ax1 Ax1 (gp_Pnt( theAxis.x, theAxis.y, theAxis.z ), gp_Vec( theAxis.vx, theAxis.vy, theAxis.vz )); - ::SMESH_MeshEditor anEditor( mesh ); ::SMESH_MeshEditor::PGroupIDs groupIds = - anEditor.RotationSweep (*workElements, Ax1, theAngleInRadians, + myEditor.RotationSweep (*workElements, Ax1, theAngleInRadians, theNbOfSteps, theTolerance, theMakeGroups, makeWalls); - storeResult(anEditor); + storeResult(myEditor); myMesh->GetMeshDS()->Modified(); // myMesh->SetIsModified( true ); -- it does not influence Compute() @@ -1913,12 +2304,11 @@ SMESH_MeshEditor_i::extrusionSweep(const SMESH::long_array & theIDsOfElements, } TElemOfElemListMap aHystory; - ::SMESH_MeshEditor anEditor( mesh ); ::SMESH_MeshEditor::PGroupIDs groupIds = - anEditor.ExtrusionSweep (*workElements, stepVec, theNbOfSteps, aHystory, theMakeGroups); + myEditor.ExtrusionSweep (*workElements, stepVec, theNbOfSteps, aHystory, theMakeGroups); myMesh->GetMeshDS()->Modified(); - storeResult(anEditor); + storeResult(myEditor); return theMakeGroups ? getGroups(groupIds.get()) : 0; @@ -2187,12 +2577,11 @@ SMESH_MeshEditor_i::advancedExtrusion(const SMESH::long_array & theIDsOfElements const SMESH::PointStruct * P = &theStepVector.PS; gp_Vec stepVec( P->x, P->y, P->z ); - ::SMESH_MeshEditor anEditor( myMesh ); TElemOfElemListMap aHystory; ::SMESH_MeshEditor::PGroupIDs groupIds = - anEditor.ExtrusionSweep (elements, stepVec, theNbOfSteps, aHystory, + myEditor.ExtrusionSweep (elements, stepVec, theNbOfSteps, aHystory, theMakeGroups, theExtrFlags, theSewTolerance); - storeResult(anEditor); + storeResult(myEditor); return theMakeGroups ? getGroups(groupIds.get()) : 0; } @@ -2336,13 +2725,12 @@ SMESH_MeshEditor_i::extrusionAlongPath(const SMESH::long_array & theIDsOfEleme int nbOldGroups = myMesh->NbGroup(); - ::SMESH_MeshEditor anEditor( myMesh ); ::SMESH_MeshEditor::Extrusion_Error error = - anEditor.ExtrusionAlongTrack( elements, aSubMesh, nodeStart, + myEditor.ExtrusionAlongTrack( elements, aSubMesh, nodeStart, theHasAngles, angles, false, theHasRefPoint, refPnt, theMakeGroups ); myMesh->GetMeshDS()->Modified(); - storeResult(anEditor); + storeResult(myEditor); theError = convExtrError( error ); if ( theMakeGroups ) { @@ -2405,7 +2793,6 @@ SMESH_MeshEditor_i::extrusionAlongPathX(const SMESH::long_array & IDsOfElements MakeGroups = false; } - ::SMESH_MeshEditor anEditor( mesh ); ::SMESH_MeshEditor::Extrusion_Error error; if ( SMESH_Mesh_i* aMeshImp = SMESH::DownCast( Path )) @@ -2417,7 +2804,7 @@ SMESH_MeshEditor_i::extrusionAlongPathX(const SMESH::long_array & IDsOfElements Error = SMESH::SMESH_MeshEditor::EXTR_BAD_STARTING_NODE; return EmptyGr; } - error = anEditor.ExtrusionAlongTrack( *workElements, &(aMeshImp->GetImpl()), aNodeStart, + error = myEditor.ExtrusionAlongTrack( *workElements, &(aMeshImp->GetImpl()), aNodeStart, HasAngles, angles, LinearVariation, HasRefPoint, refPnt, MakeGroups ); myMesh->GetMeshDS()->Modified(); @@ -2435,7 +2822,7 @@ SMESH_MeshEditor_i::extrusionAlongPathX(const SMESH::long_array & IDsOfElements } SMESH_subMesh* aSubMesh = aMeshImp->GetImpl().GetSubMeshContaining(aSubMeshImp->GetId()); - error = anEditor.ExtrusionAlongTrack( *workElements, aSubMesh, aNodeStart, + error = myEditor.ExtrusionAlongTrack( *workElements, aSubMesh, aNodeStart, HasAngles, angles, LinearVariation, HasRefPoint, refPnt, MakeGroups ); myMesh->GetMeshDS()->Modified(); @@ -2452,7 +2839,7 @@ SMESH_MeshEditor_i::extrusionAlongPathX(const SMESH::long_array & IDsOfElements return EmptyGr; } - storeResult(anEditor); + storeResult(myEditor); Error = convExtrError( error ); if ( MakeGroups ) { @@ -3089,12 +3476,11 @@ SMESH_MeshEditor_i::mirror(TIDSortedElemSet & theElements, theMakeGroups = false; } - ::SMESH_MeshEditor anEditor( mesh ); ::SMESH_MeshEditor::PGroupIDs groupIds = - anEditor.Transform (*workElements, aTrsf, theCopy, theMakeGroups, theTargetMesh); + myEditor.Transform (*workElements, aTrsf, theCopy, theMakeGroups, theTargetMesh); if(theCopy || myPreviewMode) - storeResult(anEditor); // store preview data or new elements + storeResult(myEditor); // store preview data or new elements if ( !myPreviewMode ) { @@ -3352,12 +3738,11 @@ SMESH_MeshEditor_i::translate(TIDSortedElemSet & theElements, theMakeGroups = false; } - ::SMESH_MeshEditor anEditor( mesh ); ::SMESH_MeshEditor::PGroupIDs groupIds = - anEditor.Transform (*workElements, aTrsf, theCopy, theMakeGroups, theTargetMesh); + myEditor.Transform (*workElements, aTrsf, theCopy, theMakeGroups, theTargetMesh); if(theCopy || myPreviewMode) - storeResult(anEditor); + storeResult(myEditor); if ( !myPreviewMode ) { @@ -3602,12 +3987,11 @@ SMESH_MeshEditor_i::rotate(TIDSortedElemSet & theElements, theMakeGroups = false; } - ::SMESH_MeshEditor anEditor( mesh ); ::SMESH_MeshEditor::PGroupIDs groupIds = - anEditor.Transform (*workElements, aTrsf, theCopy, theMakeGroups, theTargetMesh); + myEditor.Transform (*workElements, aTrsf, theCopy, theMakeGroups, theTargetMesh); if(theCopy || myPreviewMode) - storeResult(anEditor); + storeResult(myEditor); if ( !myPreviewMode ) { @@ -3881,12 +4265,11 @@ SMESH_MeshEditor_i::scale(SMESH::SMESH_IDSource_ptr theObject, theMakeGroups = false; } - ::SMESH_MeshEditor anEditor( mesh ); ::SMESH_MeshEditor::PGroupIDs groupIds = - anEditor.Transform (*workElements, aTrsf, theCopy, theMakeGroups, theTargetMesh); + myEditor.Transform (*workElements, aTrsf, theCopy, theMakeGroups, theTargetMesh); if(theCopy || myPreviewMode ) - storeResult(anEditor); + storeResult(myEditor); if ( !myPreviewMode ) { @@ -4003,9 +4386,8 @@ void SMESH_MeshEditor_i::FindCoincidentNodes (CORBA::Double Tol initData(); ::SMESH_MeshEditor::TListOfListOfNodes aListOfListOfNodes; - ::SMESH_MeshEditor anEditor( myMesh ); TIDSortedNodeSet nodes; // no input nodes - anEditor.FindCoincidentNodes( nodes, Tolerance, aListOfListOfNodes ); + myEditor.FindCoincidentNodes( nodes, Tolerance, aListOfListOfNodes ); GroupsOfNodes = new SMESH::array_of_long_array; GroupsOfNodes->length( aListOfListOfNodes.size() ); @@ -4036,9 +4418,8 @@ void SMESH_MeshEditor_i::FindCoincidentNodesOnPart(SMESH::SMESH_IDSource_ptr idSourceToNodeSet( theObject, GetMeshDS(), nodes ); ::SMESH_MeshEditor::TListOfListOfNodes aListOfListOfNodes; - ::SMESH_MeshEditor anEditor( myMesh ); if(!nodes.empty()) - anEditor.FindCoincidentNodes( nodes, Tolerance, aListOfListOfNodes ); + myEditor.FindCoincidentNodes( nodes, Tolerance, aListOfListOfNodes ); GroupsOfNodes = new SMESH::array_of_long_array; GroupsOfNodes->length( aListOfListOfNodes.size() ); @@ -4084,9 +4465,8 @@ FindCoincidentNodesOnPartBut(SMESH::SMESH_IDSource_ptr theObject, nodes.erase( *avoidNode ); } ::SMESH_MeshEditor::TListOfListOfNodes aListOfListOfNodes; - ::SMESH_MeshEditor anEditor( myMesh ); if(!nodes.empty()) - anEditor.FindCoincidentNodes( nodes, theTolerance, aListOfListOfNodes ); + myEditor.FindCoincidentNodes( nodes, theTolerance, aListOfListOfNodes ); theGroupsOfNodes = new SMESH::array_of_long_array; theGroupsOfNodes->length( aListOfListOfNodes.size() ); @@ -4138,8 +4518,7 @@ void SMESH_MeshEditor_i::MergeNodes (const SMESH::array_of_long_array& GroupsOfN if ( i > 0 ) aTPythonDump << ", "; aTPythonDump << aNodeGroup; } - ::SMESH_MeshEditor anEditor( myMesh ); - anEditor.MergeNodes( aListOfListOfNodes ); + myEditor.MergeNodes( aListOfListOfNodes ); aTPythonDump << "])"; myMesh->GetMeshDS()->Modified(); @@ -4158,35 +4537,25 @@ void SMESH_MeshEditor_i::FindEqualElements(SMESH::SMESH_IDSource_ptr theObj SMESH::SMESH_GroupBase_var group = SMESH::SMESH_GroupBase::_narrow(theObject); if ( !(!group->_is_nil() && group->GetType() == SMESH::NODE) ) { - typedef list TListOfIDs; - set elems; - SMESH::long_array_var aElementsId = theObject->GetIDs(); - SMESHDS_Mesh* aMesh = GetMeshDS(); - - for(int i = 0; i < aElementsId->length(); i++) { - CORBA::Long anID = aElementsId[i]; - const SMDS_MeshElement * elem = aMesh->FindElement(anID); - if (elem) { - elems.insert(elem); - } - } + TIDSortedElemSet elems; + idSourceToSet( theObject, GetMeshDS(), elems, SMDSAbs_All, /*emptyIfIsMesh=*/true); ::SMESH_MeshEditor::TListOfListOfElementsID aListOfListOfElementsID; - ::SMESH_MeshEditor anEditor( myMesh ); - anEditor.FindEqualElements( elems, aListOfListOfElementsID ); + myEditor.FindEqualElements( elems, aListOfListOfElementsID ); GroupsOfElementsID = new SMESH::array_of_long_array; GroupsOfElementsID->length( aListOfListOfElementsID.size() ); - ::SMESH_MeshEditor::TListOfListOfElementsID::iterator arraysIt = aListOfListOfElementsID.begin(); - for (CORBA::Long j = 0; arraysIt != aListOfListOfElementsID.end(); ++arraysIt, ++j) { + ::SMESH_MeshEditor::TListOfListOfElementsID::iterator arraysIt = + aListOfListOfElementsID.begin(); + for (CORBA::Long j = 0; arraysIt != aListOfListOfElementsID.end(); ++arraysIt, ++j) + { SMESH::long_array& aGroup = (*GroupsOfElementsID)[ j ]; - TListOfIDs& listOfIDs = *arraysIt; + list& listOfIDs = *arraysIt; aGroup.length( listOfIDs.size() ); - TListOfIDs::iterator idIt = listOfIDs.begin(); - for (int k = 0; idIt != listOfIDs.end(); ++idIt, ++k ) { + list::iterator idIt = listOfIDs.begin(); + for (int k = 0; idIt != listOfIDs.end(); ++idIt, ++k ) aGroup[ k ] = *idIt; - } } TPythonDump() << "equal_elements = " << this << ".FindEqualElements( " @@ -4222,8 +4591,7 @@ void SMESH_MeshEditor_i::MergeElements(const SMESH::array_of_long_array& GroupsO aTPythonDump << anElemsIDGroup; } - ::SMESH_MeshEditor anEditor( myMesh ); - anEditor.MergeElements(aListOfListOfElementsID); + myEditor.MergeElements(aListOfListOfElementsID); myMesh->GetMeshDS()->Modified(); myMesh->SetIsModified( true ); @@ -4239,8 +4607,7 @@ void SMESH_MeshEditor_i::MergeEqualElements() { initData(); - ::SMESH_MeshEditor anEditor( myMesh ); - anEditor.MergeEqualElements(); + myEditor.MergeEqualElements(); myMesh->GetMeshDS()->Modified(); @@ -4284,8 +4651,7 @@ CORBA::Boolean SMESH_MeshEditor_i::MoveNode(CORBA::Long NodeID, if ( nodeCpy1 ) tmpMesh.GetMeshDS()->MoveNode(nodeCpy1, x, y, z); // fill preview data - ::SMESH_MeshEditor anEditor( & tmpMesh ); - storeResult( anEditor ); + storeResult( myEditor ); } else if ( theNodeSearcher ) // move node and update theNodeSearcher data accordingly theNodeSearcher->MoveNode(node, gp_Pnt( x,y,z )); @@ -4317,8 +4683,7 @@ CORBA::Long SMESH_MeshEditor_i::FindNodeClosestTo(CORBA::Double x, theSearchersDeleter.Set( myMesh ); // remove theNodeSearcher if mesh is other if ( !theNodeSearcher ) { - ::SMESH_MeshEditor anEditor( myMesh ); - theNodeSearcher = anEditor.GetNodeSearcher(); + theNodeSearcher = myEditor.GetNodeSearcher(); } gp_Pnt p( x,y,z ); if ( const SMDS_MeshNode* node = theNodeSearcher->FindClosestTo( p )) @@ -4352,8 +4717,7 @@ CORBA::Long SMESH_MeshEditor_i::MoveClosestNodeToPoint(CORBA::Double x, if ( !node ) // preview moving node { if ( !theNodeSearcher ) { - ::SMESH_MeshEditor anEditor( myMesh ); - theNodeSearcher = anEditor.GetNodeSearcher(); + theNodeSearcher = myEditor.GetNodeSearcher(); } gp_Pnt p( x,y,z ); node = theNodeSearcher->FindClosestTo( p ); @@ -4377,8 +4741,7 @@ CORBA::Long SMESH_MeshEditor_i::MoveClosestNodeToPoint(CORBA::Double x, if ( node ) tmpMesh.GetMeshDS()->MoveNode(node, x, y, z); // fill preview data - ::SMESH_MeshEditor anEditor( & tmpMesh ); - storeResult( anEditor ); + storeResult( myEditor ); } else if ( theNodeSearcher ) // move node and update theNodeSearcher data accordingly { @@ -4421,8 +4784,7 @@ SMESH::long_array* SMESH_MeshEditor_i::FindElementsByPoint(CORBA::Double x, theSearchersDeleter.Set( myMesh ); if ( !theElementSearcher ) { - ::SMESH_MeshEditor anEditor( myMesh ); - theElementSearcher = anEditor.GetElementSearcher(); + theElementSearcher = myEditor.GetElementSearcher(); } theElementSearcher->FindElementsByPoint( gp_Pnt( x,y,z ), SMDSAbs_ElementType( type ), @@ -4459,22 +4821,16 @@ SMESH_MeshEditor_i::FindAmongElementsByPoint(SMESH::SMESH_IDSource_ptr elementID SMESH::array_of_ElementType_var types = elementIDs->GetTypes(); if ( types->length() == 1 && // a part contains only nodes or 0D elements - ( types[0] == SMESH::NODE || types[0] == SMESH::ELEM0D ) && + ( types[0] == SMESH::NODE || types[0] == SMESH::ELEM0D || types[0] == SMESH::BALL) && type != types[0] ) // but search of elements of dim > 0 return res._retn(); if ( SMESH::DownCast( elementIDs )) // elementIDs is the whole mesh return FindElementsByPoint( x,y,z, type ); - string partIOR = SMESH_Gen_i::GetORB()->object_to_string( elementIDs ); - if ( SMESH_Group_i* group_i = SMESH::DownCast( elementIDs )) - // take into account passible group modification - partIOR += SMESH_Comment( ((SMESHDS_Group*)group_i->GetGroupDS())->SMDSGroup().Tic() ); - partIOR += SMESH_Comment( type ); - TIDSortedElemSet elements; // elems should live until FindElementsByPoint() finishes - theSearchersDeleter.Set( myMesh, partIOR ); + theSearchersDeleter.Set( myMesh, getPartIOR( elementIDs, type )); if ( !theElementSearcher ) { // create a searcher from elementIDs @@ -4488,8 +4844,7 @@ SMESH_MeshEditor_i::FindAmongElementsByPoint(SMESH::SMESH_IDSource_ptr elementID typedef SMDS_SetIterator TIter; SMDS_ElemIteratorPtr elemsIt( new TIter( elements.begin(), elements.end() )); - ::SMESH_MeshEditor anEditor( myMesh ); - theElementSearcher = anEditor.GetElementSearcher(elemsIt); + theElementSearcher = myEditor.GetElementSearcher(elemsIt); } vector< const SMDS_MeshElement* > foundElems; @@ -4524,8 +4879,7 @@ CORBA::Short SMESH_MeshEditor_i::GetPointState(CORBA::Double x, { theSearchersDeleter.Set( myMesh ); if ( !theElementSearcher ) { - ::SMESH_MeshEditor anEditor( myMesh ); - theElementSearcher = anEditor.GetElementSearcher(); + theElementSearcher = myEditor.GetElementSearcher(); } return CORBA::Short( theElementSearcher->GetPointState( gp_Pnt( x,y,z ))); } @@ -4599,9 +4953,8 @@ SMESH_MeshEditor_i::SewFreeBorders(CORBA::Long FirstNodeID1, << CreatePolygons<< ", " << CreatePolyedrs<< " )"; - ::SMESH_MeshEditor anEditor( myMesh ); SMESH::SMESH_MeshEditor::Sew_Error error = - convError( anEditor.SewFreeBorder (aBorderFirstNode, + convError( myEditor.SewFreeBorder (aBorderFirstNode, aBorderSecondNode, aBorderLastNode, aSide2FirstNode, @@ -4611,7 +4964,7 @@ SMESH_MeshEditor_i::SewFreeBorders(CORBA::Long FirstNodeID1, CreatePolygons, CreatePolyedrs) ); - storeResult(anEditor); + storeResult(myEditor); myMesh->GetMeshDS()->Modified(); myMesh->SetIsModified( true ); @@ -4658,9 +5011,8 @@ SMESH_MeshEditor_i::SewConformFreeBorders(CORBA::Long FirstNodeID1, << FirstNodeID2 << ", " << SecondNodeID2 << " )"; - ::SMESH_MeshEditor anEditor( myMesh ); SMESH::SMESH_MeshEditor::Sew_Error error = - convError( anEditor.SewFreeBorder (aBorderFirstNode, + convError( myEditor.SewFreeBorder (aBorderFirstNode, aBorderSecondNode, aBorderLastNode, aSide2FirstNode, @@ -4669,7 +5021,7 @@ SMESH_MeshEditor_i::SewConformFreeBorders(CORBA::Long FirstNodeID1, true, false, false) ); - storeResult(anEditor); + storeResult(myEditor); myMesh->GetMeshDS()->Modified(); myMesh->SetIsModified( true ); @@ -4720,9 +5072,8 @@ SMESH_MeshEditor_i::SewBorderToSide(CORBA::Long FirstNodeIDOnFreeBorder, << CreatePolygons << ", " << CreatePolyedrs << ") "; - ::SMESH_MeshEditor anEditor( myMesh ); SMESH::SMESH_MeshEditor::Sew_Error error = - convError( anEditor.SewFreeBorder (aBorderFirstNode, + convError( myEditor.SewFreeBorder (aBorderFirstNode, aBorderSecondNode, aBorderLastNode, aSide2FirstNode, @@ -4732,7 +5083,7 @@ SMESH_MeshEditor_i::SewBorderToSide(CORBA::Long FirstNodeIDOnFreeBorder, CreatePolygons, CreatePolyedrs) ); - storeResult(anEditor); + storeResult(myEditor); myMesh->GetMeshDS()->Modified(); myMesh->SetIsModified( true ); @@ -4782,15 +5133,14 @@ SMESH_MeshEditor_i::SewSideElements(const SMESH::long_array& IDsOfSide1Elements, << NodeID2OfSide1ToMerge << ", " << NodeID2OfSide2ToMerge << ")"; - ::SMESH_MeshEditor anEditor( myMesh ); SMESH::SMESH_MeshEditor::Sew_Error error = - convError( anEditor.SewSideElements (aSide1Elems, aSide2Elems, + convError( myEditor.SewSideElements (aSide1Elems, aSide2Elems, aFirstNode1ToMerge, aFirstNode2ToMerge, aSecondNode1ToMerge, aSecondNode2ToMerge)); - storeResult(anEditor); + storeResult(myEditor); myMesh->GetMeshDS()->Modified(); myMesh->SetIsModified( true ); @@ -4839,145 +5189,6 @@ CORBA::Boolean SMESH_MeshEditor_i::ChangeElemNodes(CORBA::Long ide, return res; } -//================================================================================ -/*! - * \brief Update myLastCreated* or myPreviewData - * \param anEditor - it contains last modification results - */ -//================================================================================ - -void SMESH_MeshEditor_i::storeResult(::SMESH_MeshEditor& anEditor) -{ - if ( myPreviewMode ) { // --- MeshPreviewStruct filling --- - - list aNodesConnectivity; - typedef map TNodesMap; - TNodesMap nodesMap; - - TPreviewMesh * aPreviewMesh = dynamic_cast< TPreviewMesh* >( anEditor.GetMesh() ); - SMDSAbs_ElementType previewType = aPreviewMesh->myPreviewType; - - SMESHDS_Mesh* aMeshDS = anEditor.GetMeshDS(); - int nbEdges = aMeshDS->NbEdges(); - int nbFaces = aMeshDS->NbFaces(); - int nbVolum = aMeshDS->NbVolumes(); - switch ( previewType ) { - case SMDSAbs_Edge : nbFaces = nbVolum = 0; break; - case SMDSAbs_Face : nbEdges = nbVolum = 0; break; - case SMDSAbs_Volume: nbEdges = nbFaces = 0; break; - default:; - } - myPreviewData->nodesXYZ.length(aMeshDS->NbNodes()); - myPreviewData->elementTypes.length(nbEdges + nbFaces + nbVolum); - int i = 0, j = 0; - SMDS_ElemIteratorPtr itMeshElems = aMeshDS->elementsIterator(); - - while ( itMeshElems->more() ) { - const SMDS_MeshElement* aMeshElem = itMeshElems->next(); - if ( previewType != SMDSAbs_All && aMeshElem->GetType() != previewType ) - continue; - - SMDS_ElemIteratorPtr itElemNodes = aMeshElem->nodesIterator(); - while ( itElemNodes->more() ) { - const SMDS_MeshNode* aMeshNode = - static_cast( itElemNodes->next() ); - int aNodeID = aMeshNode->GetID(); - TNodesMap::iterator anIter = nodesMap.find(aNodeID); - if ( anIter == nodesMap.end() ) { - // filling the nodes coordinates - myPreviewData->nodesXYZ[j].x = aMeshNode->X(); - myPreviewData->nodesXYZ[j].y = aMeshNode->Y(); - myPreviewData->nodesXYZ[j].z = aMeshNode->Z(); - anIter = nodesMap.insert( make_pair(aNodeID, j) ).first; - j++; - } - aNodesConnectivity.push_back(anIter->second); - } - - // filling the elements types - SMDSAbs_ElementType aType; - bool isPoly; - /*if (aMeshElem->GetType() == SMDSAbs_Volume) { - aType = SMDSAbs_Node; - isPoly = false; - } - else*/ { - aType = aMeshElem->GetType(); - isPoly = aMeshElem->IsPoly(); - } - - myPreviewData->elementTypes[i].SMDS_ElementType = (SMESH::ElementType) aType; - myPreviewData->elementTypes[i].isPoly = isPoly; - myPreviewData->elementTypes[i].nbNodesInElement = aMeshElem->NbNodes(); - i++; - - } - myPreviewData->nodesXYZ.length( j ); - - // filling the elements connectivities - list::iterator aConnIter = aNodesConnectivity.begin(); - myPreviewData->elementConnectivities.length(aNodesConnectivity.size()); - for( int i = 0; aConnIter != aNodesConnectivity.end(); aConnIter++, i++ ) - myPreviewData->elementConnectivities[i] = *aConnIter; - - return; - } - - { - // append new nodes into myLastCreatedNodes - const SMESH_SequenceOfElemPtr& aSeq = anEditor.GetLastCreatedNodes(); - int j = myLastCreatedNodes->length(); - int newLen = j + aSeq.Length(); - myLastCreatedNodes->length( newLen ); - for(int i=0; jGetID(); - } - { - // append new elements into myLastCreatedElems - const SMESH_SequenceOfElemPtr& aSeq = anEditor.GetLastCreatedElems(); - int j = myLastCreatedElems->length(); - int newLen = j + aSeq.Length(); - myLastCreatedElems->length( newLen ); - for(int i=0; jGetID(); - } -} - -//================================================================================ -/*! - * Return data of mesh edition preview - */ -//================================================================================ - -SMESH::MeshPreviewStruct* SMESH_MeshEditor_i::GetPreviewData() -{ - return myPreviewData._retn(); -} - -//================================================================================ -/*! - * \brief Returns list of it's IDs of created nodes - * \retval SMESH::long_array* - list of node ID - */ -//================================================================================ - -SMESH::long_array* SMESH_MeshEditor_i::GetLastCreatedNodes() -{ - return myLastCreatedNodes._retn(); -} - -//================================================================================ -/*! - * \brief Returns list of it's IDs of created elements - * \retval SMESH::long_array* - list of elements' ID - */ -//================================================================================ - -SMESH::long_array* SMESH_MeshEditor_i::GetLastCreatedElems() -{ - return myLastCreatedElems._retn(); -} - //======================================================================= //function : ConvertToQuadratic //purpose : @@ -4985,8 +5196,7 @@ SMESH::long_array* SMESH_MeshEditor_i::GetLastCreatedElems() void SMESH_MeshEditor_i::ConvertToQuadratic(CORBA::Boolean theForce3d) { - ::SMESH_MeshEditor anEditor( myMesh ); - anEditor.ConvertToQuadratic(theForce3d); + myEditor.ConvertToQuadratic(theForce3d); TPythonDump() << this << ".ConvertToQuadratic( " << theForce3d << " )"; myMesh->GetMeshDS()->Modified(); myMesh->SetIsModified( true ); @@ -4999,8 +5209,7 @@ void SMESH_MeshEditor_i::ConvertToQuadratic(CORBA::Boolean theForce3d) CORBA::Boolean SMESH_MeshEditor_i::ConvertFromQuadratic() { - ::SMESH_MeshEditor anEditor( myMesh ); - CORBA::Boolean isDone = anEditor.ConvertFromQuadratic(); + CORBA::Boolean isDone = myEditor.ConvertFromQuadratic(); TPythonDump() << this << ".ConvertFromQuadratic()"; myMesh->GetMeshDS()->Modified(); if ( isDone ) @@ -5032,8 +5241,7 @@ void SMESH_MeshEditor_i::ConvertToQuadraticObject(CORBA::Boolean theF } else { - ::SMESH_MeshEditor anEditor( myMesh ); - anEditor.ConvertToQuadratic(theForce3d, elems); + myEditor.ConvertToQuadratic(theForce3d, elems); } } myMesh->GetMeshDS()->Modified(); @@ -5066,8 +5274,7 @@ void SMESH_MeshEditor_i::ConvertFromQuadraticObject(SMESH::SMESH_IDSource_ptr th } else { - ::SMESH_MeshEditor anEditor( myMesh ); - anEditor.ConvertFromQuadratic(elems); + myEditor.ConvertFromQuadratic(elems); } } myMesh->GetMeshDS()->Modified(); @@ -5124,24 +5331,16 @@ string SMESH_MeshEditor_i::generateGroupName(const string& thePrefix) if (CORBA::is_nil(aGroup)) continue; - groupNames.insert(aGroup->GetName()); + CORBA::String_var name = aGroup->GetName(); + groupNames.insert( name.in() ); } // Find new name string name = thePrefix; int index = 0; - while (!groupNames.insert(name).second) { - if (index == 0) { - name += "_1"; - } - else { - TCollection_AsciiString nbStr(index+1); - name.resize( name.rfind('_')+1 ); - name += nbStr.ToCString(); - } - ++index; - } + while (!groupNames.insert(name).second) + name = SMESH_Comment( thePrefix ) << "_" << index; return name; } @@ -5163,7 +5362,6 @@ CORBA::Boolean SMESH_MeshEditor_i::DoubleNodes( const SMESH::long_array& theNode { initData(); - ::SMESH_MeshEditor aMeshEditor( myMesh ); list< int > aListOfNodes; int i, n; for ( i = 0, n = theNodes.length(); i < n; i++ ) @@ -5173,10 +5371,10 @@ CORBA::Boolean SMESH_MeshEditor_i::DoubleNodes( const SMESH::long_array& theNode for ( i = 0, n = theModifiedElems.length(); i < n; i++ ) aListOfElems.push_back( theModifiedElems[ i ] ); - bool aResult = aMeshEditor.DoubleNodes( aListOfNodes, aListOfElems ); + bool aResult = myEditor.DoubleNodes( aListOfNodes, aListOfElems ); myMesh->GetMeshDS()->Modified(); - storeResult( aMeshEditor) ; + storeResult( myEditor) ; if ( aResult ) myMesh->SetIsModified( true ); @@ -5257,14 +5455,15 @@ CORBA::Boolean SMESH_MeshEditor_i::DoubleNodeGroup(SMESH::SMESH_GroupBase_ptr th * \return a new group with newly created nodes * \sa DoubleNodeGroup() */ -SMESH::SMESH_Group_ptr SMESH_MeshEditor_i::DoubleNodeGroupNew( SMESH::SMESH_GroupBase_ptr theNodes, - SMESH::SMESH_GroupBase_ptr theModifiedElems ) +SMESH::SMESH_Group_ptr +SMESH_MeshEditor_i::DoubleNodeGroupNew( SMESH::SMESH_GroupBase_ptr theNodes, + SMESH::SMESH_GroupBase_ptr theModifiedElems ) { - if ( CORBA::is_nil( theNodes ) && theNodes->GetType() != SMESH::NODE ) - return false; - SMESH::SMESH_Group_var aNewGroup; + if ( CORBA::is_nil( theNodes ) && theNodes->GetType() != SMESH::NODE ) + return aNewGroup._retn(); + // Duplicate nodes SMESH::long_array_var aNodes = theNodes->GetListOfID(); SMESH::long_array_var aModifiedElems; @@ -5278,7 +5477,6 @@ SMESH::SMESH_Group_ptr SMESH_MeshEditor_i::DoubleNodeGroupNew( SMESH::SMESH_Grou TPythonDump pyDump; // suppress dump by the next line bool aResult = DoubleNodes( aNodes, aModifiedElems ); - if ( aResult ) { // Create group with newly created nodes @@ -5288,11 +5486,12 @@ SMESH::SMESH_Group_ptr SMESH_MeshEditor_i::DoubleNodeGroupNew( SMESH::SMESH_Grou string aNewName = generateGroupName(anUnindexedName + "_double"); aNewGroup = myMesh_i->CreateGroup(SMESH::NODE, aNewName.c_str()); aNewGroup->Add(anIds); + pyDump << aNewGroup << " = "; } } - pyDump << "createdNodes = " << this << ".DoubleNodeGroupNew( " << theNodes << ", " - << theModifiedElems << " )"; + pyDump << this << ".DoubleNodeGroupNew( " << theNodes << ", " + << theModifiedElems << " )"; return aNewGroup._retn(); } @@ -5313,7 +5512,6 @@ CORBA::Boolean SMESH_MeshEditor_i::DoubleNodeGroups(const SMESH::ListOfGroups& t { initData(); - ::SMESH_MeshEditor aMeshEditor( myMesh ); std::list< int > aNodes; int i, n, j, m; @@ -5340,9 +5538,9 @@ CORBA::Boolean SMESH_MeshEditor_i::DoubleNodeGroups(const SMESH::ListOfGroups& t } } - bool aResult = aMeshEditor.DoubleNodes( aNodes, anElems ); + bool aResult = myEditor.DoubleNodes( aNodes, anElems ); - storeResult( aMeshEditor) ; + storeResult( myEditor) ; myMesh->GetMeshDS()->Modified(); if ( aResult ) @@ -5365,8 +5563,9 @@ CORBA::Boolean SMESH_MeshEditor_i::DoubleNodeGroups(const SMESH::ListOfGroups& t */ //================================================================================ -SMESH::SMESH_Group_ptr SMESH_MeshEditor_i::DoubleNodeGroupsNew( const SMESH::ListOfGroups& theNodes, - const SMESH::ListOfGroups& theModifiedElems ) +SMESH::SMESH_Group_ptr +SMESH_MeshEditor_i::DoubleNodeGroupsNew( const SMESH::ListOfGroups& theNodes, + const SMESH::ListOfGroups& theModifiedElems ) { SMESH::SMESH_Group_var aNewGroup; @@ -5383,11 +5582,12 @@ SMESH::SMESH_Group_ptr SMESH_MeshEditor_i::DoubleNodeGroupsNew( const SMESH::Lis string aNewName = generateGroupName(anUnindexedName + "_double"); aNewGroup = myMesh_i->CreateGroup(SMESH::NODE, aNewName.c_str()); aNewGroup->Add(anIds); + pyDump << aNewGroup << " = "; } } - pyDump << "createdNodes = " << this << ".DoubleNodeGroupsNew( " << theNodes << ", " - << theModifiedElems << " )"; + pyDump << this << ".DoubleNodeGroupsNew( " << theNodes << ", " + << theModifiedElems << " )"; return aNewGroup._retn(); } @@ -5413,7 +5613,6 @@ CORBA::Boolean SMESH_MeshEditor_i::DoubleNodeElem( const SMESH::long_array& theE { initData(); - ::SMESH_MeshEditor aMeshEditor( myMesh ); SMESHDS_Mesh* aMeshDS = GetMeshDS(); TIDSortedElemSet anElems, aNodes, anAffected; @@ -5421,9 +5620,9 @@ CORBA::Boolean SMESH_MeshEditor_i::DoubleNodeElem( const SMESH::long_array& theE arrayToSet(theNodesNot, aMeshDS, aNodes, SMDSAbs_Node); arrayToSet(theAffectedElems, aMeshDS, anAffected, SMDSAbs_All); - bool aResult = aMeshEditor.DoubleNodes( anElems, aNodes, anAffected ); + bool aResult = myEditor.DoubleNodes( anElems, aNodes, anAffected ); - storeResult( aMeshEditor) ; + storeResult( myEditor) ; myMesh->GetMeshDS()->Modified(); if ( aResult ) @@ -5456,7 +5655,6 @@ CORBA::Boolean SMESH_MeshEditor_i::DoubleNodeElemInRegion ( const SMESH::long_ar { initData(); - ::SMESH_MeshEditor aMeshEditor( myMesh ); SMESHDS_Mesh* aMeshDS = GetMeshDS(); TIDSortedElemSet anElems, aNodes; @@ -5464,9 +5662,9 @@ CORBA::Boolean SMESH_MeshEditor_i::DoubleNodeElemInRegion ( const SMESH::long_ar arrayToSet(theNodesNot, aMeshDS, aNodes, SMDSAbs_Node); TopoDS_Shape aShape = SMESH_Gen_i::GetSMESHGen()->GeomObjectToShape( theShape ); - bool aResult = aMeshEditor.DoubleNodesInRegion( anElems, aNodes, aShape ); + bool aResult = myEditor.DoubleNodesInRegion( anElems, aNodes, aShape ); - storeResult( aMeshEditor) ; + storeResult( myEditor) ; myMesh->GetMeshDS()->Modified(); if ( aResult ) @@ -5499,7 +5697,6 @@ CORBA::Boolean SMESH_MeshEditor_i::DoubleNodeElemGroup(SMESH::SMESH_GroupBase_pt initData(); - ::SMESH_MeshEditor aMeshEditor( myMesh ); SMESHDS_Mesh* aMeshDS = GetMeshDS(); TIDSortedElemSet anElems, aNodes, anAffected; @@ -5507,9 +5704,9 @@ CORBA::Boolean SMESH_MeshEditor_i::DoubleNodeElemGroup(SMESH::SMESH_GroupBase_pt idSourceToSet( theNodesNot, aMeshDS, aNodes, SMDSAbs_Node ); idSourceToSet( theAffectedElems, aMeshDS, anAffected, SMDSAbs_All ); - bool aResult = aMeshEditor.DoubleNodes( anElems, aNodes, anAffected ); + bool aResult = myEditor.DoubleNodes( anElems, aNodes, anAffected ); - storeResult( aMeshEditor) ; + storeResult( myEditor) ; myMesh->GetMeshDS()->Modified(); if ( aResult ) @@ -5531,18 +5728,43 @@ CORBA::Boolean SMESH_MeshEditor_i::DoubleNodeElemGroup(SMESH::SMESH_GroupBase_pt * \return a new group with newly created elements * \sa DoubleNodeElemGroup() */ -SMESH::SMESH_Group_ptr SMESH_MeshEditor_i::DoubleNodeElemGroupNew(SMESH::SMESH_GroupBase_ptr theElems, - SMESH::SMESH_GroupBase_ptr theNodesNot, - SMESH::SMESH_GroupBase_ptr theAffectedElems) +SMESH::SMESH_Group_ptr +SMESH_MeshEditor_i::DoubleNodeElemGroupNew(SMESH::SMESH_GroupBase_ptr theElems, + SMESH::SMESH_GroupBase_ptr theNodesNot, + SMESH::SMESH_GroupBase_ptr theAffectedElems) { - if ( CORBA::is_nil( theElems ) && theElems->GetType() == SMESH::NODE ) - return false; + TPythonDump pyDump; + SMESH::ListOfGroups_var twoGroups = DoubleNodeElemGroup2New( theElems, + theNodesNot, + theAffectedElems, + true, false ); + SMESH::SMESH_GroupBase_var baseGroup = twoGroups[0].in(); + SMESH::SMESH_Group_var elemGroup = SMESH::SMESH_Group::_narrow( baseGroup ); - SMESH::SMESH_Group_var aNewGroup; + pyDump << elemGroup << " = " << this << ".DoubleNodeElemGroupNew( " + << theElems << ", " + << theNodesNot << ", " + << theAffectedElems << " )"; + + return elemGroup._retn(); +} + +SMESH::ListOfGroups* +SMESH_MeshEditor_i::DoubleNodeElemGroup2New(SMESH::SMESH_GroupBase_ptr theElems, + SMESH::SMESH_GroupBase_ptr theNodesNot, + SMESH::SMESH_GroupBase_ptr theAffectedElems, + CORBA::Boolean theElemGroupNeeded, + CORBA::Boolean theNodeGroupNeeded) +{ + SMESH::SMESH_Group_var aNewElemGroup, aNewNodeGroup; + SMESH::ListOfGroups_var aTwoGroups = new SMESH::ListOfGroups(); + aTwoGroups->length( 2 ); + + if ( CORBA::is_nil( theElems ) && theElems->GetType() == SMESH::NODE ) + return aTwoGroups._retn(); initData(); - ::SMESH_MeshEditor aMeshEditor( myMesh ); SMESHDS_Mesh* aMeshDS = GetMeshDS(); TIDSortedElemSet anElems, aNodes, anAffected; @@ -5551,28 +5773,52 @@ SMESH::SMESH_Group_ptr SMESH_MeshEditor_i::DoubleNodeElemGroupNew(SMESH::SMESH_G idSourceToSet( theAffectedElems, aMeshDS, anAffected, SMDSAbs_All ); - bool aResult = aMeshEditor.DoubleNodes( anElems, aNodes, anAffected ); + bool aResult = myEditor.DoubleNodes( anElems, aNodes, anAffected ); + + storeResult( myEditor) ; + myMesh->GetMeshDS()->Modified(); - storeResult( aMeshEditor) ; + TPythonDump pyDump; - if ( aResult ) { + if ( aResult ) + { myMesh->SetIsModified( true ); // Create group with newly created elements - SMESH::long_array_var anIds = GetLastCreatedElems(); - if (anIds->length() > 0) { + CORBA::String_var elemGroupName = theElems->GetName(); + string aNewName = generateGroupName( string(elemGroupName.in()) + "_double"); + if ( !myEditor.GetLastCreatedElems().IsEmpty() && theElemGroupNeeded ) + { + SMESH::long_array_var anIds = GetLastCreatedElems(); SMESH::ElementType aGroupType = myMesh_i->GetElementType(anIds[0], true); - string anUnindexedName (theElems->GetName()); - string aNewName = generateGroupName(anUnindexedName + "_double"); - aNewGroup = myMesh_i->CreateGroup(aGroupType, aNewName.c_str()); - aNewGroup->Add(anIds); + aNewElemGroup = myMesh_i->CreateGroup(aGroupType, aNewName.c_str()); + aNewElemGroup->Add(anIds); + } + if ( !myEditor.GetLastCreatedNodes().IsEmpty() && theNodeGroupNeeded ) + { + SMESH::long_array_var anIds = GetLastCreatedNodes(); + aNewNodeGroup = myMesh_i->CreateGroup(SMESH::NODE, aNewName.c_str()); + aNewNodeGroup->Add(anIds); } } // Update Python script - TPythonDump() << "createdElems = " << this << ".DoubleNodeElemGroupNew( " << theElems << ", " - << theNodesNot << ", " << theAffectedElems << " )"; - return aNewGroup._retn(); + + pyDump << "[ "; + if ( aNewElemGroup->_is_nil() ) pyDump << "nothing, "; + else pyDump << aNewElemGroup << ", "; + if ( aNewNodeGroup->_is_nil() ) pyDump << "nothing ] = "; + else pyDump << aNewNodeGroup << " ] = "; + + pyDump << this << ".DoubleNodeElemGroup2New( " << theElems << ", " + << theNodesNot << ", " + << theAffectedElems << ", " + << theElemGroupNeeded << ", " + << theNodeGroupNeeded <<" )"; + + aTwoGroups[0] = aNewElemGroup._retn(); + aTwoGroups[1] = aNewNodeGroup._retn(); + return aTwoGroups._retn(); } //================================================================================ @@ -5598,7 +5844,6 @@ CORBA::Boolean SMESH_MeshEditor_i::DoubleNodeElemGroupInRegion(SMESH::SMESH_Grou initData(); - ::SMESH_MeshEditor aMeshEditor( myMesh ); SMESHDS_Mesh* aMeshDS = GetMeshDS(); TIDSortedElemSet anElems, aNodes, anAffected; @@ -5606,9 +5851,9 @@ CORBA::Boolean SMESH_MeshEditor_i::DoubleNodeElemGroupInRegion(SMESH::SMESH_Grou idSourceToSet( theNodesNot, aMeshDS, aNodes, SMDSAbs_Node ); TopoDS_Shape aShape = SMESH_Gen_i::GetSMESHGen()->GeomObjectToShape( theShape ); - bool aResult = aMeshEditor.DoubleNodesInRegion( anElems, aNodes, aShape ); + bool aResult = myEditor.DoubleNodesInRegion( anElems, aNodes, aShape ); - storeResult( aMeshEditor) ; + storeResult( myEditor) ; myMesh->GetMeshDS()->Modified(); if ( aResult ) @@ -5656,7 +5901,6 @@ CORBA::Boolean SMESH_MeshEditor_i::DoubleNodeElemGroups(const SMESH::ListOfGroup { initData(); - ::SMESH_MeshEditor aMeshEditor( myMesh ); SMESHDS_Mesh* aMeshDS = GetMeshDS(); TIDSortedElemSet anElems, aNodes, anAffected; @@ -5664,9 +5908,9 @@ CORBA::Boolean SMESH_MeshEditor_i::DoubleNodeElemGroups(const SMESH::ListOfGroup listOfGroupToSet(theNodesNot, aMeshDS, aNodes, true ); listOfGroupToSet(theAffectedElems, aMeshDS, anAffected, false ); - bool aResult = aMeshEditor.DoubleNodes( anElems, aNodes, anAffected ); + bool aResult = myEditor.DoubleNodes( anElems, aNodes, anAffected ); - storeResult( aMeshEditor) ; + storeResult( myEditor) ; myMesh->GetMeshDS()->Modified(); if ( aResult ) @@ -5691,15 +5935,40 @@ CORBA::Boolean SMESH_MeshEditor_i::DoubleNodeElemGroups(const SMESH::ListOfGroup */ //================================================================================ -SMESH::SMESH_Group_ptr SMESH_MeshEditor_i::DoubleNodeElemGroupsNew(const SMESH::ListOfGroups& theElems, - const SMESH::ListOfGroups& theNodesNot, - const SMESH::ListOfGroups& theAffectedElems) +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; + TPythonDump pyDump; + SMESH::ListOfGroups_var twoGroups = DoubleNodeElemGroups2New( theElems, + theNodesNot, + theAffectedElems, + true, false ); + SMESH::SMESH_GroupBase_var baseGroup = twoGroups[0].in(); + SMESH::SMESH_Group_var elemGroup = SMESH::SMESH_Group::_narrow( baseGroup ); + + pyDump << elemGroup << " = " << this << ".DoubleNodeElemGroupsNew( " + << theElems << ", " + << theNodesNot << ", " + << theAffectedElems << " )"; + + return elemGroup._retn(); +} + +SMESH::ListOfGroups* +SMESH_MeshEditor_i::DoubleNodeElemGroups2New(const SMESH::ListOfGroups& theElems, + const SMESH::ListOfGroups& theNodesNot, + const SMESH::ListOfGroups& theAffectedElems, + CORBA::Boolean theElemGroupNeeded, + CORBA::Boolean theNodeGroupNeeded) +{ + SMESH::SMESH_Group_var aNewElemGroup, aNewNodeGroup; + SMESH::ListOfGroups_var aTwoGroups = new SMESH::ListOfGroups(); + aTwoGroups->length( 2 ); initData(); - ::SMESH_MeshEditor aMeshEditor( myMesh ); SMESHDS_Mesh* aMeshDS = GetMeshDS(); TIDSortedElemSet anElems, aNodes, anAffected; @@ -5707,29 +5976,51 @@ SMESH::SMESH_Group_ptr SMESH_MeshEditor_i::DoubleNodeElemGroupsNew(const SMESH:: listOfGroupToSet(theNodesNot, aMeshDS, aNodes, true ); listOfGroupToSet(theAffectedElems, aMeshDS, anAffected, false ); - bool aResult = aMeshEditor.DoubleNodes( anElems, aNodes, anAffected ); + bool aResult = myEditor.DoubleNodes( anElems, aNodes, anAffected ); - storeResult( aMeshEditor) ; + storeResult( myEditor) ; myMesh->GetMeshDS()->Modified(); - if ( aResult ) { + TPythonDump pyDump; + if ( aResult ) + { myMesh->SetIsModified( true ); // Create group with newly created elements - SMESH::long_array_var anIds = GetLastCreatedElems(); - if (anIds->length() > 0) { + CORBA::String_var elemGroupName = theElems[0]->GetName(); + string aNewName = generateGroupName( string(elemGroupName.in()) + "_double"); + if ( !myEditor.GetLastCreatedElems().IsEmpty() && theElemGroupNeeded ) + { + SMESH::long_array_var anIds = GetLastCreatedElems(); 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); + aNewElemGroup = myMesh_i->CreateGroup(aGroupType, aNewName.c_str()); + aNewElemGroup->Add(anIds); + } + if ( !myEditor.GetLastCreatedNodes().IsEmpty() && theNodeGroupNeeded ) + { + SMESH::long_array_var anIds = GetLastCreatedNodes(); + aNewNodeGroup = myMesh_i->CreateGroup(SMESH::NODE, aNewName.c_str()); + aNewNodeGroup->Add(anIds); } } // Update Python script - TPythonDump() << "createdElems = " << this << ".DoubleNodeElemGroupsNew( " << &theElems << ", " - << &theNodesNot << ", " << &theAffectedElems << " )"; - return aNewGroup._retn(); + + pyDump << "[ "; + if ( aNewElemGroup->_is_nil() ) pyDump << "nothing, "; + else pyDump << aNewElemGroup << ", "; + if ( aNewNodeGroup->_is_nil() ) pyDump << "nothing ] = "; + else pyDump << aNewNodeGroup << " ] = "; + + pyDump << this << ".DoubleNodeElemGroups2New( " << &theElems << ", " + << &theNodesNot << ", " + << &theAffectedElems << ", " + << theElemGroupNeeded << ", " + << theNodeGroupNeeded << " )"; + + aTwoGroups[0] = aNewElemGroup._retn(); + aTwoGroups[1] = aNewNodeGroup._retn(); + return aTwoGroups._retn(); } //================================================================================ @@ -5753,7 +6044,6 @@ SMESH_MeshEditor_i::DoubleNodeElemGroupsInRegion(const SMESH::ListOfGroups& theE { initData(); - ::SMESH_MeshEditor aMeshEditor( myMesh ); SMESHDS_Mesh* aMeshDS = GetMeshDS(); TIDSortedElemSet anElems, aNodes; @@ -5761,9 +6051,9 @@ SMESH_MeshEditor_i::DoubleNodeElemGroupsInRegion(const SMESH::ListOfGroups& theE listOfGroupToSet(theNodesNot, aMeshDS, aNodes, true ); TopoDS_Shape aShape = SMESH_Gen_i::GetSMESHGen()->GeomObjectToShape( theShape ); - bool aResult = aMeshEditor.DoubleNodesInRegion( anElems, aNodes, aShape ); + bool aResult = myEditor.DoubleNodesInRegion( anElems, aNodes, aShape ); - storeResult( aMeshEditor) ; + storeResult( myEditor) ; myMesh->GetMeshDS()->Modified(); if ( aResult ) @@ -5775,6 +6065,124 @@ SMESH_MeshEditor_i::DoubleNodeElemGroupsInRegion(const SMESH::ListOfGroups& theE return aResult; } +//================================================================================ +/*! + \brief Identify the elements that will be affected by node duplication (actual duplication is not performed. + This method is the first step of DoubleNodeElemGroupsInRegion. + \param theElems - list of groups of elements (edges or faces) to be replicated + \param theNodesNot - list of groups of nodes not to replicated + \param theShape - shape to detect affected elements (element which geometric center + located on or inside shape). + The replicated nodes should be associated to affected elements. + \return groups of affected elements + \sa DoubleNodeElemGroupsInRegion() + */ +//================================================================================ +SMESH::ListOfGroups* +SMESH_MeshEditor_i::AffectedElemGroupsInRegion( const SMESH::ListOfGroups& theElems, + const SMESH::ListOfGroups& theNodesNot, + GEOM::GEOM_Object_ptr theShape ) +{ + MESSAGE("AffectedElemGroupsInRegion"); + SMESH::ListOfGroups_var aListOfGroups = new SMESH::ListOfGroups(); + bool isEdgeGroup = false; + bool isFaceGroup = false; + bool isVolumeGroup = false; + SMESH::SMESH_Group_var aNewEdgeGroup = myMesh_i->CreateGroup(SMESH::EDGE, "affectedEdges"); + SMESH::SMESH_Group_var aNewFaceGroup = myMesh_i->CreateGroup(SMESH::FACE, "affectedFaces"); + SMESH::SMESH_Group_var aNewVolumeGroup = myMesh_i->CreateGroup(SMESH::VOLUME, "affectedVolumes"); + + initData(); + + ::SMESH_MeshEditor aMeshEditor(myMesh); + + SMESHDS_Mesh* aMeshDS = GetMeshDS(); + TIDSortedElemSet anElems, aNodes; + listOfGroupToSet(theElems, aMeshDS, anElems, false); + listOfGroupToSet(theNodesNot, aMeshDS, aNodes, true); + + TopoDS_Shape aShape = SMESH_Gen_i::GetSMESHGen()->GeomObjectToShape(theShape); + TIDSortedElemSet anAffected; + bool aResult = aMeshEditor.AffectedElemGroupsInRegion(anElems, aNodes, aShape, anAffected); + + storeResult(aMeshEditor); + + myMesh->GetMeshDS()->Modified(); + TPythonDump pyDump; + if (aResult) + { + myMesh->SetIsModified(true); + + int lg = anAffected.size(); + MESSAGE("lg="<< lg); + SMESH::long_array_var volumeIds = new SMESH::long_array; + volumeIds->length(lg); + SMESH::long_array_var faceIds = new SMESH::long_array; + faceIds->length(lg); + SMESH::long_array_var edgeIds = new SMESH::long_array; + edgeIds->length(lg); + int ivol = 0; + int iface = 0; + int iedge = 0; + + TIDSortedElemSet::const_iterator eIt = anAffected.begin(); + for (; eIt != anAffected.end(); ++eIt) + { + const SMDS_MeshElement* anElem = *eIt; + if (!anElem) + continue; + int elemId = anElem->GetID(); + if (myMesh->GetElementType(elemId, true) == SMDSAbs_Volume) + volumeIds[ivol++] = elemId; + else if (myMesh->GetElementType(elemId, true) == SMDSAbs_Face) + faceIds[iface++] = elemId; + else if (myMesh->GetElementType(elemId, true) == SMDSAbs_Edge) + edgeIds[iedge++] = elemId; + } + volumeIds->length(ivol); + faceIds->length(iface); + edgeIds->length(iedge); + + aNewVolumeGroup->Add(volumeIds); + aNewFaceGroup->Add(faceIds); + aNewEdgeGroup->Add(edgeIds); + isVolumeGroup = (aNewVolumeGroup->Size() > 0); + isFaceGroup = (aNewFaceGroup->Size() > 0); + isEdgeGroup = (aNewEdgeGroup->Size() > 0); + } + + int nbGroups = 0; + if (isEdgeGroup) + nbGroups++; + if (isFaceGroup) + nbGroups++; + if (isVolumeGroup) + nbGroups++; + aListOfGroups->length(nbGroups); + + int i = 0; + if (isEdgeGroup) + aListOfGroups[i++] = aNewEdgeGroup._retn(); + if (isFaceGroup) + aListOfGroups[i++] = aNewFaceGroup._retn(); + if (isVolumeGroup) + aListOfGroups[i++] = aNewVolumeGroup._retn(); + + // Update Python script + + pyDump << "[ "; + if (isEdgeGroup) + pyDump << aNewEdgeGroup << ", "; + if (isFaceGroup) + pyDump << aNewFaceGroup << ", "; + if (isVolumeGroup) + pyDump << aNewVolumeGroup << ", "; + pyDump << "] = "; + pyDump << this << ".AffectedElemGroupsInRegion( " << &theElems << ", " << &theNodesNot << ", " << theShape << " )"; + + return aListOfGroups._retn(); +} + //================================================================================ /*! \brief Generated skin mesh (containing 2D cells) from 3D mesh @@ -5787,9 +6195,8 @@ CORBA::Boolean SMESH_MeshEditor_i::Make2DMeshFrom3D() { initData(); - ::SMESH_MeshEditor aMeshEditor( myMesh ); - bool aResult = aMeshEditor.Make2DMeshFrom3D(); - storeResult( aMeshEditor) ; + bool aResult = myEditor.Make2DMeshFrom3D(); + storeResult( myEditor) ; myMesh->GetMeshDS()->Modified(); TPythonDump() << "isDone = " << this << ".Make2DMeshFrom3D()"; return aResult; @@ -5815,7 +6222,6 @@ CORBA::Boolean SMESH_MeshEditor_i::DoubleNodesOnGroupBoundaries( const SMESH::Li { initData(); - ::SMESH_MeshEditor aMeshEditor( myMesh ); SMESHDS_Mesh* aMeshDS = GetMeshDS(); @@ -5837,10 +6243,10 @@ CORBA::Boolean SMESH_MeshEditor_i::DoubleNodesOnGroupBoundaries( const SMESH::Li } } - bool aResult = aMeshEditor.DoubleNodesOnGroupBoundaries( domains, createJointElems ); + bool aResult = myEditor.DoubleNodesOnGroupBoundaries( domains, createJointElems ); // TODO publish the groups of flat elements in study - storeResult( aMeshEditor) ; + storeResult( myEditor) ; myMesh->GetMeshDS()->Modified(); // Update Python script @@ -5865,7 +6271,6 @@ CORBA::Boolean SMESH_MeshEditor_i::CreateFlatElementsOnFacesGroups( const SMESH: { initData(); - ::SMESH_MeshEditor aMeshEditor( myMesh ); SMESHDS_Mesh* aMeshDS = GetMeshDS(); @@ -5885,10 +6290,10 @@ CORBA::Boolean SMESH_MeshEditor_i::CreateFlatElementsOnFacesGroups( const SMESH: } } - bool aResult = aMeshEditor.CreateFlatElementsOnFacesGroups( faceGroups ); + bool aResult = myEditor.CreateFlatElementsOnFacesGroups( faceGroups ); // TODO publish the groups of flat elements in study - storeResult( aMeshEditor) ; + storeResult( myEditor) ; myMesh->GetMeshDS()->Modified(); // Update Python script @@ -5896,6 +6301,53 @@ CORBA::Boolean SMESH_MeshEditor_i::CreateFlatElementsOnFacesGroups( const SMESH: return aResult; } +/*! + * \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 > aListOfListOfNodes; + ::SMESH_MeshEditor aMeshEditor( myMesh ); + + theSearchersDeleter.Set( myMesh ); // remove theNodeSearcher if mesh is other + if ( !theNodeSearcher ) + theNodeSearcher = aMeshEditor.GetNodeSearcher(); + + vector 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 >::iterator llIt = aListOfListOfNodes.begin(); + for ( CORBA::Long i = 0; llIt != aListOfListOfNodes.end(); llIt++, i++ ) + { + vector& aListOfNodes = *llIt; + vector::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 @@ -5955,14 +6407,13 @@ SMESH_MeshEditor_i::MakeBoundaryMesh(SMESH::SMESH_IDSource_ptr idSource, } // do it - ::SMESH_MeshEditor aMeshEditor( myMesh ); - aMeshEditor.MakeBoundaryMesh( elements, + myEditor.MakeBoundaryMesh( elements, ::SMESH_MeshEditor::Bnd_Dimension(dim), smesh_group, smesh_mesh, toCopyElements, toCopyExistingBondary); - storeResult( aMeshEditor ); + storeResult( myEditor ); if ( smesh_mesh ) smesh_mesh->GetMeshDS()->Modified(); @@ -6100,8 +6551,7 @@ CORBA::Long SMESH_MeshEditor_i::MakeBoundaryElements(SMESH::Bnd_Dimension dim, { SMESH::Bnd_Dimension bdim = ( elemType == SMDSAbs_Volume ) ? SMESH::BND_2DFROM3D : SMESH::BND_1DFROM2D; - ::SMESH_MeshEditor aMeshEditor( srcMesh ); - nbAdded += aMeshEditor.MakeBoundaryMesh( elements, + nbAdded += myEditor.MakeBoundaryMesh( elements, ::SMESH_MeshEditor::Bnd_Dimension(bdim), smesh_group, tgtMesh, @@ -6109,21 +6559,20 @@ CORBA::Long SMESH_MeshEditor_i::MakeBoundaryElements(SMESH::Bnd_Dimension dim, /*toCopyExistingBondary=*/srcMesh != tgtMesh, /*toAddExistingBondary=*/true, /*aroundElements=*/true); - storeResult( aMeshEditor ); + storeResult( myEditor ); } } } else { - ::SMESH_MeshEditor aMeshEditor( srcMesh ); - nbAdded += aMeshEditor.MakeBoundaryMesh( elements, + nbAdded += myEditor.MakeBoundaryMesh( elements, ::SMESH_MeshEditor::Bnd_Dimension(dim), smesh_group, tgtMesh, /*toCopyElements=*/false, /*toCopyExistingBondary=*/srcMesh != tgtMesh, /*toAddExistingBondary=*/true); - storeResult( aMeshEditor ); + storeResult( myEditor ); } tgtMesh->GetMeshDS()->Modified();