From: eap Date: Mon, 19 Nov 2012 11:40:08 +0000 (+0000) Subject: 21983: [CEA 714] Imposed mesh not taken into account after hdf reload X-Git-Tag: V6_6_0~1 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=dee0b93fe072e918a2bed99664341fcee59dfd37;p=plugins%2Fghs3dplugin.git 21983: [CEA 714] Imposed mesh not taken into account after hdf reload + virtual void SubmeshRestored(SMESH_subMesh* subMesh); --- diff --git a/src/GHS3DPlugin/GHS3DPlugin_GHS3D.cxx b/src/GHS3DPlugin/GHS3DPlugin_GHS3D.cxx index 3e467d8..257c774 100644 --- a/src/GHS3DPlugin/GHS3DPlugin_GHS3D.cxx +++ b/src/GHS3DPlugin/GHS3DPlugin_GHS3D.cxx @@ -37,6 +37,8 @@ #include "SMESH_MeshEditor.hxx" #include "SMESH_OctreeNode.hxx" #include "SMESH_Group.hxx" +#include +#include #include "SMDS_MeshElement.hxx" #include "SMDS_MeshNode.hxx" @@ -4310,3 +4312,84 @@ bool GHS3DPlugin_GHS3D::importGMFMesh(const char* theGMFFileName, SMESH_Mesh& th theMesh.GetMeshDS()->Modified(); return ok; } + +namespace +{ + //================================================================================ + /*! + * \brief Sub-mesh event listener setting enforced elements as soon as an enforced + * mesh is loaded + */ + struct _EnforcedMeshRestorer : public SMESH_subMeshEventListener + { + _EnforcedMeshRestorer(): + SMESH_subMeshEventListener( /*isDeletable = */true, Name() ) + {} + + //================================================================================ + /*! + * \brief Returns an ID of listener + */ + static const char* Name() { return "GHS3DPlugin_GHS3D::_EnforcedMeshRestorer"; } + + //================================================================================ + /*! + * \brief Treat events of the subMesh + */ + void ProcessEvent(const int event, + const int eventType, + SMESH_subMesh* subMesh, + SMESH_subMeshEventListenerData* data, + const SMESH_Hypothesis* hyp) + { + if ( SMESH_subMesh::SUBMESH_LOADED == event && + SMESH_subMesh::COMPUTE_EVENT == eventType && + data && + !data->mySubMeshes.empty() ) + { + // An enforced mesh (subMesh->_father) has been loaded from hdf file + if ( GHS3DPlugin_Hypothesis* hyp = GetGHSHypothesis( data->mySubMeshes.front() )) + hyp->RestoreEnfElemsByMeshes(); + } + } + //================================================================================ + /*! + * \brief Returns GHS3DPlugin_Hypothesis used to compute a subMesh + */ + static GHS3DPlugin_Hypothesis* GetGHSHypothesis( SMESH_subMesh* subMesh ) + { + SMESH_HypoFilter ghsHypFilter( SMESH_HypoFilter::HasName( "GHS3D_Parameters" )); + return (GHS3DPlugin_Hypothesis* ) + subMesh->GetFather()->GetHypothesis( subMesh->GetSubShape(), + ghsHypFilter, + /*visitAncestors=*/true); + } + }; +} + +//================================================================================ +/*! + * \brief Set an event listener to set enforced elements as soon as an enforced + * mesh is loaded + */ +//================================================================================ + +void GHS3DPlugin_GHS3D::SubmeshRestored(SMESH_subMesh* subMesh) +{ + if ( GHS3DPlugin_Hypothesis* hyp = _EnforcedMeshRestorer::GetGHSHypothesis( subMesh )) + { + GHS3DPlugin_Hypothesis::TGHS3DEnforcedMeshList enfMeshes = hyp->_GetEnforcedMeshes(); + GHS3DPlugin_Hypothesis::TGHS3DEnforcedMeshList::iterator it = enfMeshes.begin(); + for(;it != enfMeshes.end();++it) { + GHS3DPlugin_Hypothesis::TGHS3DEnforcedMesh* enfMesh = *it; + if ( SMESH_Mesh* mesh = GetMeshByPersistentID( enfMesh->persistID )) + { + SMESH_subMesh* smToListen = mesh->GetSubMesh( mesh->GetShapeToMesh() ); + // a listener set to smToListen will care of hypothesis stored in SMESH_EventListenerData + subMesh->SetEventListener( new _EnforcedMeshRestorer(), + SMESH_subMeshEventListenerData::MakeData( subMesh ), + smToListen); + } + } + } +} diff --git a/src/GHS3DPlugin/GHS3DPlugin_GHS3D.hxx b/src/GHS3DPlugin/GHS3DPlugin_GHS3D.hxx index 7be3a9f..776a1fa 100644 --- a/src/GHS3DPlugin/GHS3DPlugin_GHS3D.hxx +++ b/src/GHS3DPlugin/GHS3DPlugin_GHS3D.hxx @@ -75,6 +75,8 @@ public: virtual bool Compute(SMESH_Mesh& theMesh, SMESH_MesherHelper* aHelper); + virtual void SubmeshRestored(SMESH_subMesh* subMesh); + bool importGMFMesh(const char* aGMFFileName, SMESH_Mesh& aMesh); private: