From: eap Date: Fri, 29 Jun 2012 13:43:18 +0000 (+0000) Subject: + CORBA::Long Reorient2D(SMESH::SMESH_IDSource_ptr the2Dgroup, X-Git-Tag: V6_6_0a1~291 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=95a77fcb020f1b1aebf6939093a446c8acbcf649;p=modules%2Fsmesh.git + CORBA::Long Reorient2D(SMESH::SMESH_IDSource_ptr the2Dgroup, + const SMESH::DirStruct& theDirection, + CORBA::Long theFace, + const SMESH::PointStruct& thePoint) throw (SALOME::SALOME_Exception); --- diff --git a/src/SMESH_I/SMESH_MeshEditor_i.cxx b/src/SMESH_I/SMESH_MeshEditor_i.cxx index 821a8a0a1..1518fdf1a 100644 --- a/src/SMESH_I/SMESH_MeshEditor_i.cxx +++ b/src/SMESH_I/SMESH_MeshEditor_i.cxx @@ -296,6 +296,7 @@ namespace { else { arrayToSet( anIDs, theMeshDS, theElemSet, theType); + return bool(anIDs->length()) == bool(theElemSet.size()); } return true; } @@ -378,6 +379,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; + } + } //============================================================================= @@ -1129,6 +1148,94 @@ 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); + + ::SMESH_MeshEditor anEditor( myMesh ); + + 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 = anEditor.GetElementSearcher(); + } + else + { + typedef SMDS_SetIterator TIter; + SMDS_ElemIteratorPtr elemsIt( new TIter( elements.begin(), elements.end() )); + + theElementSearcher = anEditor.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 = anEditor.Reorient2D( elements, dirVec, face ); + storeResult(anEditor); + + if ( nbReori ) { + myMesh->SetIsModified( true ); + myMesh->GetMeshDS()->Modified(); + } + TPythonDump() << this << ".Reorient2D( " + << the2Dgroup << ", " + << theDirection << ", " + << theFace << ", " + << thePoint << " )"; + + return nbReori; +} + //============================================================================= /*! * @@ -4466,15 +4573,9 @@ SMESH_MeshEditor_i::FindAmongElementsByPoint(SMESH::SMESH_IDSource_ptr elementID 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 diff --git a/src/SMESH_I/SMESH_MeshEditor_i.hxx b/src/SMESH_I/SMESH_MeshEditor_i.hxx index 4c2182498..1a2344835 100644 --- a/src/SMESH_I/SMESH_MeshEditor_i.hxx +++ b/src/SMESH_I/SMESH_MeshEditor_i.hxx @@ -122,6 +122,19 @@ public: CORBA::Boolean DeleteDiag(CORBA::Long NodeID1, CORBA::Long NodeID2); CORBA::Boolean Reorient(const SMESH::long_array & IDsOfElements); CORBA::Boolean ReorientObject(SMESH::SMESH_IDSource_ptr theObject); + /*! + * \brief Reorient faces contained in \a the2Dgroup. + * \param the2Dgroup - the mesh or its part to reorient + * \param theDirection - desired direction of normal of \a theFace + * \param theFace - ID of face whose orientation is checked. + * It can be < 1 then \a thePoint is used to find a face. + * \param thePoint - is used to find a face if \a theFace < 1. + * \return number of reoriented elements. + */ + CORBA::Long Reorient2D(SMESH::SMESH_IDSource_ptr the2Dgroup, + const SMESH::DirStruct& theDirection, + CORBA::Long theFace, + const SMESH::PointStruct& thePoint) throw (SALOME::SALOME_Exception); // Split/Join faces CORBA::Boolean TriToQuad (const SMESH::long_array & IDsOfElements,