]> SALOME platform Git repositories - plugins/hybridplugin.git/commitdiff
Salome HOME
21983: [CEA 714] Imposed mesh not taken into account after hdf reload
authoreap <eap@opencascade.com>
Mon, 19 Nov 2012 11:40:08 +0000 (11:40 +0000)
committereap <eap@opencascade.com>
Mon, 19 Nov 2012 11:40:08 +0000 (11:40 +0000)
+  virtual void SubmeshRestored(SMESH_subMesh* subMesh);

src/GHS3DPlugin/GHS3DPlugin_GHS3D.cxx
src/GHS3DPlugin/GHS3DPlugin_GHS3D.hxx

index 3e467d8d798d6f3091452211b4c8ef1db1f47707..257c774097d69006f79b126d381b9d53eb7545a9 100644 (file)
@@ -37,6 +37,8 @@
 #include "SMESH_MeshEditor.hxx"
 #include "SMESH_OctreeNode.hxx"
 #include "SMESH_Group.hxx"
+#include <SMESH_subMeshEventListener.hxx>
+#include <SMESH_HypoFilter.hxx>
 
 #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);
+      }
+    }
+  }
+}
index 7be3a9f490190d5f720713cfd8f2de9dc94fb7d6..776a1fa317eb33ac36cbf443004be976c11fb0e6 100644 (file)
@@ -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: