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=a983a13c3298599e2a7230aeb435134097d7248b;hp=d157a2c49105dd754c293a3847405ee08b1d62be;hb=c94d606fe399faeb356151a1a9754e5f21754082;hpb=5cc99bd09d23235cc26f67d7b9e49fb3f42e3c88 diff --git a/src/SMESH_I/SMESH_MeshEditor_i.cxx b/src/SMESH_I/SMESH_MeshEditor_i.cxx index d157a2c49..a983a13c3 100644 --- a/src/SMESH_I/SMESH_MeshEditor_i.cxx +++ b/src/SMESH_I/SMESH_MeshEditor_i.cxx @@ -23,7 +23,7 @@ // Author : Nicolas REJNERI // Module : SMESH -#ifdef WNT +#ifdef WIN32 #define NOMINMAX #endif @@ -63,6 +63,7 @@ #include #include #include +#include #include #include @@ -176,6 +177,10 @@ namespace MeshEditor_I { return _myMeshDS->AddNodeWithID(anElemNode->X(), anElemNode->Y(), anElemNode->Z(), anElemNode->GetID()); } + void RemoveAll() + { + GetMeshDS()->ClearMesh(); + } };// struct TPreviewMesh static SMESH_NodeSearcher * theNodeSearcher = 0; @@ -222,22 +227,22 @@ namespace MeshEditor_I { } myMesh = mesh; myMeshPartIOR = meshPartIOR; - if ( SMESH_subMesh* myMainSubMesh = mesh->GetSubMeshContaining(1) ) { - const TDependsOnMap & subMeshes = myMainSubMesh->DependsOn(); - TDependsOnMap::const_iterator sm; - for (sm = subMeshes.begin(); sm != subMeshes.end(); sm++) - sm->second->SetEventListener( this, 0, sm->second ); + SMESH_subMesh* sm = mesh->GetSubMesh( mesh->GetShapeToMesh() ); + SMESH_subMeshIteratorPtr smIt = sm->getDependsOnIterator( /*includeSelf=*/true ); + while ( smIt->more() ) + { + sm = smIt->next(); + sm->SetEventListener( this, 0, sm ); } } } //!< delete self from all submeshes void Unset(SMESH_Mesh* mesh) { - if ( SMESH_subMesh* myMainSubMesh = mesh->GetSubMeshContaining(1) ) { - const TDependsOnMap & subMeshes = myMainSubMesh->DependsOn(); - TDependsOnMap::const_iterator sm; - for (sm = subMeshes.begin(); sm != subMeshes.end(); sm++) - sm->second->DeleteEventListener( this ); + if ( SMESH_subMesh* sm = mesh->GetSubMeshContaining(1) ) { + SMESH_subMeshIteratorPtr smIt = sm->getDependsOnIterator( /*includeSelf=*/true ); + while ( smIt->more() ) + smIt->next()->DeleteEventListener( this ); } myMesh = 0; } @@ -272,12 +277,16 @@ namespace MeshEditor_I { void arrayToSet(const SMESH::long_array & IDs, const SMESHDS_Mesh* aMesh, TIDSortedElemSet& aMap, - const SMDSAbs_ElementType aType = SMDSAbs_All ) + const SMDSAbs_ElementType aType = SMDSAbs_All, + SMDS_MeshElement::Filter* aFilter = NULL) { SMDS_MeshElement::NonNullFilter filter1; SMDS_MeshElement::TypeFilter filter2( aType ); - SMDS_MeshElement::Filter & filter = - ( aType == SMDSAbs_All ) ? (SMDS_MeshElement::Filter&) filter1 : filter2; + + if ( aFilter == NULL ) + aFilter = ( aType == SMDSAbs_All ) ? (SMDS_MeshElement::Filter*) &filter1 : (SMDS_MeshElement::Filter*) &filter2; + + SMDS_MeshElement::Filter & filter = *aFilter; if ( aType == SMDSAbs_Node ) for (int i=0; iservant_to_id(this); + poa->deactivate_object(anObjectId.in()); + + //deleteAuxIDSources(); delete myPreviewMesh; myPreviewMesh = 0; delete myPreviewEditor; myPreviewEditor = 0; } @@ -467,7 +480,7 @@ SMESH_MeshEditor_i::~SMESH_MeshEditor_i() void SMESH_MeshEditor_i::initData(bool deleteSearchers) { if ( myIsPreviewMode ) { - if ( myPreviewMesh ) myPreviewMesh->Clear(); + if ( myPreviewMesh ) myPreviewMesh->RemoveAll(); } else { if ( deleteSearchers ) @@ -711,16 +724,26 @@ SMESH::ComputeError* SMESH_MeshEditor_i::GetLastError() //======================================================================= //function : MakeIDSource -//purpose : Wrap a sequence of ids in a SMESH_IDSource +//purpose : Wrap a sequence of ids in a SMESH_IDSource. +// Call UnRegister() as you fininsh using it!! //======================================================================= -struct SMESH_MeshEditor_i::_IDSource : public POA_SMESH::SMESH_IDSource +struct SMESH_MeshEditor_i::_IDSource : public virtual POA_SMESH::SMESH_IDSource, + public virtual SALOME::GenericObj_i { SMESH::long_array _ids; SMESH::ElementType _type; SMESH::SMESH_Mesh_ptr _mesh; SMESH::long_array* GetIDs() { return new SMESH::long_array( _ids ); } SMESH::long_array* GetMeshInfo() { return 0; } + SMESH::long_array* GetNbElementsByType() + { + SMESH::long_array_var aRes = new SMESH::long_array(); + aRes->length(SMESH::NB_ELEMENT_TYPES); + for (int i = 0; i < SMESH::NB_ELEMENT_TYPES; i++) + aRes[ i ] = ( i == _type ) ? _ids.length() : 0; + return aRes._retn(); + } SMESH::SMESH_Mesh_ptr GetMesh() { return SMESH::SMESH_Mesh::_duplicate( _mesh ); } bool IsMeshInfoCorrect() { return true; } SMESH::array_of_ElementType* GetTypes() @@ -737,14 +760,16 @@ struct SMESH_MeshEditor_i::_IDSource : public POA_SMESH::SMESH_IDSource SMESH::SMESH_IDSource_ptr SMESH_MeshEditor_i::MakeIDSource(const SMESH::long_array& ids, SMESH::ElementType type) { - if ( myAuxIDSources.size() > 10 ) - deleteAuxIDSources(); + // if ( myAuxIDSources.size() > 10 ) { + // delete myAuxIDSources.front(); + // myAuxIDSources.pop_front(); + // } _IDSource* idSrc = new _IDSource; idSrc->_mesh = myMesh_i->_this(); idSrc->_ids = ids; idSrc->_type = type; - myAuxIDSources.push_back( idSrc ); + //myAuxIDSources.push_back( idSrc ); SMESH::SMESH_IDSource_var anIDSourceVar = idSrc->_this(); @@ -756,14 +781,26 @@ bool SMESH_MeshEditor_i::IsTemporaryIDSource( SMESH::SMESH_IDSource_ptr& idSourc return SMESH::DownCast( idSource ); } -void SMESH_MeshEditor_i::deleteAuxIDSources() +CORBA::Long* SMESH_MeshEditor_i::GetTemporaryIDs( SMESH::SMESH_IDSource_ptr& idSource, + int& nbIds) { - std::list< _IDSource* >::iterator idSrcIt = myAuxIDSources.begin(); - for ( ; idSrcIt != myAuxIDSources.end(); ++idSrcIt ) - delete *idSrcIt; - myAuxIDSources.clear(); + if ( _IDSource* tmpIdSource = SMESH::DownCast( idSource )) + { + nbIds = (int) tmpIdSource->_ids.length(); + return & tmpIdSource->_ids[0]; + } + nbIds = 0; + return 0; } +// void SMESH_MeshEditor_i::deleteAuxIDSources() +// { +// std::list< _IDSource* >::iterator idSrcIt = myAuxIDSources.begin(); +// for ( ; idSrcIt != myAuxIDSources.end(); ++idSrcIt ) +// delete *idSrcIt; +// myAuxIDSources.clear(); +// } + //============================================================================= /*! * @@ -1688,8 +1725,16 @@ CORBA::Boolean SMESH_MeshEditor_i::TriToQuad (const SMESH::long_array & IDsOfE initData(); SMESHDS_Mesh* aMesh = getMeshDS(); - TIDSortedElemSet faces; - arrayToSet(IDsOfElements, aMesh, faces, SMDSAbs_Face); + TIDSortedElemSet faces,copyFaces; + SMDS_MeshElement::GeomFilter triaFilter(SMDSGeom_TRIANGLE); + arrayToSet(IDsOfElements, aMesh, faces, SMDSAbs_Face, & triaFilter); + TIDSortedElemSet* workElements = & faces; + + if ( myIsPreviewMode ) { + SMDSAbs_ElementType select = SMDSAbs_Face; + getPreviewMesh( SMDSAbs_Face )->Copy( faces, copyFaces, select ); + workElements = & copyFaces; + } SMESH::NumericalFunctor_i* aNumericalFunctor = dynamic_cast( SMESH_Gen_i::GetServant( Criterion ).in() ); @@ -1699,12 +1744,13 @@ CORBA::Boolean SMESH_MeshEditor_i::TriToQuad (const SMESH::long_array & IDsOfE else aCrit = aNumericalFunctor->GetNumericalFunctor(); - // Update Python script - TPythonDump() << "isDone = " << this << ".TriToQuad( " - << IDsOfElements << ", " << aNumericalFunctor << ", " << TVar( MaxAngle ) << " )"; - + if ( !myIsPreviewMode ) { + // Update Python script + TPythonDump() << "isDone = " << this << ".TriToQuad( " + << IDsOfElements << ", " << aNumericalFunctor << ", " << TVar( MaxAngle ) << " )"; + } - bool stat = getEditor().TriToQuad( faces, aCrit, MaxAngle ); + bool stat = getEditor().TriToQuad( *workElements, aCrit, MaxAngle ); declareMeshModified( /*isReComputeSafe=*/!stat ); return stat; @@ -1733,12 +1779,14 @@ CORBA::Boolean SMESH_MeshEditor_i::TriToQuadObject (SMESH::SMESH_IDSource_ptr SMESH::long_array_var anElementsId = theObject->GetIDs(); CORBA::Boolean isDone = TriToQuad(anElementsId, Criterion, MaxAngle); - SMESH::NumericalFunctor_i* aNumericalFunctor = - SMESH::DownCast( Criterion ); + if ( !myIsPreviewMode ) { + SMESH::NumericalFunctor_i* aNumericalFunctor = + SMESH::DownCast( Criterion ); - // Update Python script - aTPythonDump << "isDone = " << this << ".TriToQuadObject(" - << theObject << ", " << aNumericalFunctor << ", " << TVar( MaxAngle ) << " )"; + // Update Python script + aTPythonDump << "isDone = " << this << ".TriToQuadObject(" + << theObject << ", " << aNumericalFunctor << ", " << TVar( MaxAngle ) << " )"; + } return isDone; @@ -1932,6 +1980,7 @@ CORBA::Long SMESH_MeshEditor_i::BestSplit (CORBA::Long IDOfQuad, int id = getEditor().BestSplit(quad, aCrit); declareMeshModified( /*isReComputeSafe=*/ id < 1 ); + return id; } SMESH_CATCH( SMESH::throwCorbaException ); @@ -1950,13 +1999,15 @@ void SMESH_MeshEditor_i::SplitVolumesIntoTetra (SMESH::SMESH_IDSource_ptr elems, { SMESH_TRY; initData(); - prepareIdSource( elems ); - SMESH::long_array_var anElementsId = elems->GetIDs(); - TIDSortedElemSet elemSet; - arrayToSet( anElementsId, getMeshDS(), elemSet, SMDSAbs_Volume ); - getEditor().SplitVolumesIntoTetra( elemSet, int( methodFlags )); + ::SMESH_MeshEditor::TFacetOfElem elemSet; + const int noneFacet = -1; + SMDS_ElemIteratorPtr volIt = myMesh_i->GetElements( elems, SMESH::VOLUME ); + while( volIt->more() ) + elemSet.insert( elemSet.end(), make_pair( volIt->next(), noneFacet )); + + getEditor().SplitVolumes( elemSet, int( methodFlags )); declareMeshModified( /*isReComputeSafe=*/true ); // it does not influence Compute() TPythonDump() << this << ".SplitVolumesIntoTetra( " @@ -1965,6 +2016,70 @@ void SMESH_MeshEditor_i::SplitVolumesIntoTetra (SMESH::SMESH_IDSource_ptr elems, SMESH_CATCH( SMESH::throwCorbaException ); } +//================================================================================ +/*! + * \brief Split hexahedra into triangular prisms + * \param elems - elements to split + * \param facetToSplitNormal - normal used to find a facet of hexahedron + * to split into triangles + * \param methodFlags - flags passing splitting method: + * 1 - split the hexahedron into 2 prisms + * 2 - split the hexahedron into 4 prisms + */ +//================================================================================ + +void SMESH_MeshEditor_i::SplitHexahedraIntoPrisms (SMESH::SMESH_IDSource_ptr elems, + const SMESH::PointStruct & startHexPoint, + const SMESH::DirStruct& facetToSplitNormal, + CORBA::Short methodFlags, + CORBA::Boolean allDomains) + throw (SALOME::SALOME_Exception) +{ + SMESH_TRY; + initData(); + prepareIdSource( elems ); + + gp_Ax1 facetNorm( gp_Pnt( startHexPoint.x, + startHexPoint.y, + startHexPoint.z ), + gp_Dir( facetToSplitNormal.PS.x, + facetToSplitNormal.PS.y, + facetToSplitNormal.PS.z )); + TIDSortedElemSet elemSet; + SMESH::long_array_var anElementsId = elems->GetIDs(); + SMDS_MeshElement::GeomFilter filter( SMDSGeom_HEXA ); + arrayToSet( anElementsId, getMeshDS(), elemSet, SMDSAbs_Volume, &filter ); + + ::SMESH_MeshEditor::TFacetOfElem elemFacets; + while ( !elemSet.empty() ) + { + getEditor().GetHexaFacetsToSplit( elemSet, facetNorm, elemFacets ); + if ( !allDomains ) + break; + + ::SMESH_MeshEditor::TFacetOfElem::iterator ef = elemFacets.begin(); + for ( ; ef != elemFacets.end(); ++ef ) + elemSet.erase( ef->first ); + } + + if ( methodFlags == 2 ) + methodFlags = int( ::SMESH_MeshEditor::HEXA_TO_4_PRISMS ); + else + methodFlags = int( ::SMESH_MeshEditor::HEXA_TO_2_PRISMS ); + + getEditor().SplitVolumes( elemFacets, int( methodFlags )); + declareMeshModified( /*isReComputeSafe=*/true ); // it does not influence Compute() + + TPythonDump() << this << ".SplitHexahedraIntoPrisms( " + << elems << ", " + << startHexPoint << ", " + << facetToSplitNormal<< ", " + << methodFlags<< ", " + << allDomains << " )"; + + SMESH_CATCH( SMESH::throwCorbaException ); +} + //======================================================================= //function : Smooth //purpose : @@ -2529,7 +2644,7 @@ SMESH_MeshEditor_i::extrusionSweep(const SMESH::long_array & theIDsOfElements, theMakeGroups = false; } - TElemOfElemListMap aHystory; + ::SMESH_MeshEditor::TTElemOfElemListMap aHystory; ::SMESH_MeshEditor::PGroupIDs groupIds = getEditor().ExtrusionSweep (*workElements, stepVec, theNbOfSteps, aHystory, theMakeGroups); @@ -2821,7 +2936,7 @@ SMESH_MeshEditor_i::advancedExtrusion(const SMESH::long_array & theIDsOfElements const SMESH::PointStruct * P = &theStepVector.PS; gp_Vec stepVec( P->x, P->y, P->z ); - TElemOfElemListMap aHystory; + ::SMESH_MeshEditor::TTElemOfElemListMap aHystory; ::SMESH_MeshEditor::PGroupIDs groupIds = getEditor().ExtrusionSweep (elements, stepVec, theNbOfSteps, aHystory, theMakeGroups, theExtrFlags, theSewTolerance);