Salome HOME
PAL13639 (EDF PAL 317 : SMESH : Create "0D Hypothesis")
authoreap <eap@opencascade.com>
Tue, 20 Feb 2007 07:21:28 +0000 (07:21 +0000)
committereap <eap@opencascade.com>
Tue, 20 Feb 2007 07:21:28 +0000 (07:21 +0000)
   change EventListener implementation

src/StdMeshers/StdMeshers_ProjectionUtils.cxx
src/StdMeshers/StdMeshers_ProjectionUtils.hxx
src/StdMeshers/StdMeshers_Projection_1D.cxx
src/StdMeshers/StdMeshers_Projection_2D.cxx
src/StdMeshers/StdMeshers_Projection_3D.cxx

index b1d3500c673993fcdf758e138fc96ce73d11da07..d9c58e9d7aa42d3c1f0b5350fa192db7ef3e24b3 100644 (file)
@@ -40,6 +40,7 @@
 #include "SMESH_Mesh.hxx"
 #include "SMESH_MeshEditor.hxx"
 #include "SMESH_subMesh.hxx"
+#include "SMESH_subMeshEventListener.hxx"
 #include "SMDS_EdgePosition.hxx"
 
 #include "utilities.h"
@@ -1128,7 +1129,7 @@ TopoDS_Shape StdMeshers_ProjectionUtils::OuterShape( const TopoDS_Face& face,
 
 //================================================================================
   /*!
-   * \brief Check that submeshis is computed and try to compute it if is not
+   * \brief Check that submesh is computed and try to compute it if is not
     * \param sm - submesh to compute
     * \param iterationNb - int used to stop infinite recursive call
     * \retval bool - true if computed
@@ -1221,21 +1222,87 @@ int StdMeshers_ProjectionUtils::Count(const TopoDS_Shape&    shape,
   }
 }
 
-      // bull shit
-//       Standard_Real f1,l1, f2,l2;
-//       BRep_Tool::Range( edge1, f1,l1 );
-//       BRep_Tool::Range( edge2, f2,l2 );
-//       BRepAdaptor_Curve e1( edge1 ), e2( edge2 );
-//       gp_Pnt pf1, pf2;
-//       gp_Vec dirX1, dirX2; // 1st derivatives
-//       e1.D1( f1, pf1, dirX1 );
-//       e2.D1( f2, pf2, dirX2 );
-//       gp_Pnt pm1 = e1.Value( 0.5 * ( f1 + l1 ));
-//       gp_Pnt pm2 = e2.Value( 0.5 * ( f2 + l2 ));
-//       gp_Vec dirZ1( pf1, pm1 ), dirZ2( pf2, pm2 );
-//       gp_Trsf trsf;
-//       gp_Ax3 fromSys( pf1, dirZ1, dirX1 ), toSys( pf2, dirZ2, dirX2 );
-//       trsf.SetTransformation( fromSys, toSys );
-//       dirX1.Transform( trsf );
-//       bool reverse = ( dirX1 * dirX2 < 0 );
-//       if ( reverse ) edge2.Reverse();
+namespace {
+
+  SMESH_subMeshEventListener* GetSrcSubMeshListener();
+
+  //================================================================================
+  /*!
+   * \brief Listener that resets an event listener on source submesh when 
+   * "ProjectionSource*D" hypothesis is modified
+   */
+  //================================================================================
+
+  struct HypModifWaiter: SMESH_subMeshEventListener
+  {
+    HypModifWaiter():SMESH_subMeshEventListener(0){} // won't be deleted by submesh
+
+    void ProcessEvent(const int event, const int eventType, SMESH_subMesh* subMesh,
+                      EventListenerData*, SMESH_Hypothesis*)
+    {
+      if ( event     == SMESH_subMesh::MODIF_HYP &&
+           eventType == SMESH_subMesh::ALGO_EVENT)
+      {
+        // delete current source listener
+        subMesh->DeleteEventListener( GetSrcSubMeshListener() );
+        // let algo set a new one
+        SMESH_Gen* gen = subMesh->GetFather()->GetGen();
+        if ( SMESH_Algo* algo = gen->GetAlgo( *subMesh->GetFather(),
+                                              subMesh->GetSubShape() ))
+          algo->SetEventListener( subMesh );
+      }
+    }
+  };
+  //================================================================================
+  /*!
+   * \brief return static HypModifWaiter
+   */
+  //================================================================================
+
+  SMESH_subMeshEventListener* GetHypModifWaiter() {
+    static HypModifWaiter aHypModifWaiter;
+    return &aHypModifWaiter;
+  }
+  //================================================================================
+  /*!
+   * \brief return static listener for source shape submeshes
+   */
+  //================================================================================
+
+  SMESH_subMeshEventListener* GetSrcSubMeshListener() {
+    static SMESH_subMeshEventListener srcListener(0); // won't be deleted by submesh
+    return &srcListener;
+  }
+}
+
+//================================================================================
+/*!
+ * \brief Set event listeners to submesh with projection algo
+ * \param subMesh - submesh with projection algo
+ * \param srcShape - source shape
+ * \param srcMesh - source mesh
+ */
+//================================================================================
+
+void StdMeshers_ProjectionUtils::SetEventListener(SMESH_subMesh* subMesh,
+                                                  TopoDS_Shape   srcShape,
+                                                  SMESH_Mesh*    srcMesh)
+{
+  // Set listener that resets an event listener on source submesh when
+  // "ProjectionSource*D" hypothesis is modified
+  subMesh->SetEventListener( GetHypModifWaiter(),0,subMesh);
+
+  // Set an event listener to submesh of the source shape
+  if ( !srcShape.IsNull() )
+  {
+    if ( !srcMesh )
+      srcMesh = subMesh->GetFather();
+
+    SMESH_subMesh* srcShapeSM = srcMesh->GetSubMesh( srcShape );
+
+    if ( srcShapeSM != subMesh )
+      subMesh->SetEventListener( GetSrcSubMeshListener(),
+                                 SMESH_subMeshEventListenerData::MakeData( subMesh ),
+                                 srcShapeSM );
+  }
+}
index 52d11dc2c9b8ddf6b8261dcf8dc48dbb5737a3c3..5071209cd233f7cac8ba9798229a9c2a2cdbdae7 100644 (file)
@@ -193,6 +193,16 @@ class StdMeshers_ProjectionUtils
   static int Count(const TopoDS_Shape&    shape,
                    const TopAbs_ShapeEnum type,
                    const bool             ignoreSame);
+
+  /*!
+   * \brief Set event listeners to submesh with projection algo
+    * \param subMesh - submesh with projection algo
+    * \param srcShape - source shape
+    * \param srcMesh - source mesh
+   */
+  static void SetEventListener(SMESH_subMesh* subMesh,
+                               TopoDS_Shape   srcShape,
+                               SMESH_Mesh*    srcMesh);
 };
 
 #endif
index f487d83925d2e2a668e548eba35647bae3906c2e..571d3990abea306913a576210fe37055a52a5d3c 100644 (file)
@@ -357,19 +357,7 @@ bool StdMeshers_Projection_1D::Compute(SMESH_Mesh& theMesh, const TopoDS_Shape&
 
 void StdMeshers_Projection_1D::SetEventListener(SMESH_subMesh* subMesh)
 {
-  if ( _sourceHypo && ! _sourceHypo->GetSourceEdge().IsNull() )
-  {
-    SMESH_Mesh* srcMesh = _sourceHypo->GetSourceMesh();
-    if ( !srcMesh )
-      srcMesh = subMesh->GetFather();
-
-    SMESH_subMesh* srcEdgeSM =
-      srcMesh->GetSubMesh( _sourceHypo->GetSourceEdge() );
-
-    if ( srcEdgeSM != subMesh )
-      subMesh->SetEventListener( new SMESH_subMeshEventListener(true),
-                                 SMESH_subMeshEventListenerData::MakeData( subMesh ),
-                                 srcEdgeSM );
-  }
+  TAssocTool::SetEventListener( subMesh,
+                                _sourceHypo->GetSourceEdge(),
+                                _sourceHypo->GetSourceMesh() );
 }
-  
index b7b3ff3e61004ecf2fc68d354e14ee3d2cb644c1..510589f9005d6cebf5d6839e101d2b5ba8c5d198 100644 (file)
@@ -626,17 +626,7 @@ bool StdMeshers_Projection_2D::Compute(SMESH_Mesh& theMesh, const TopoDS_Shape&
 
 void StdMeshers_Projection_2D::SetEventListener(SMESH_subMesh* subMesh)
 {
-  if ( _sourceHypo && ! _sourceHypo->GetSourceFace().IsNull() )
-  {
-    SMESH_Mesh* srcMesh = _sourceHypo->GetSourceMesh();
-    if ( !srcMesh )
-      srcMesh = subMesh->GetFather();
-
-    SMESH_subMesh* srcFaceSM =
-      srcMesh->GetSubMesh( _sourceHypo->GetSourceFace() );
-
-    subMesh->SetEventListener( new SMESH_subMeshEventListener(true),
-                               SMESH_subMeshEventListenerData::MakeData( subMesh ),
-                               srcFaceSM );
-  }
+  TAssocTool::SetEventListener( subMesh,
+                                _sourceHypo->GetSourceFace(),
+                                _sourceHypo->GetSourceMesh() );
 }
index 241ff7670c79096f8431f5eb7d30106e923cf793..1d8bce6d82ec8402d72b856c7338d499e8e04d80 100644 (file)
@@ -420,19 +420,8 @@ bool StdMeshers_Projection_3D::Compute(SMESH_Mesh& aMesh, const TopoDS_Shape& aS
 
 void StdMeshers_Projection_3D::SetEventListener(SMESH_subMesh* subMesh)
 {
-  if ( _sourceHypo && ! _sourceHypo->GetSource3DShape().IsNull() )
-  {
-    SMESH_Mesh* srcMesh = _sourceHypo->GetSourceMesh();
-    if ( !srcMesh )
-      srcMesh = subMesh->GetFather();
-
-    SMESH_subMesh* srcShapeSM =
-      srcMesh->GetSubMesh( _sourceHypo->GetSource3DShape() );
-
-    if ( srcShapeSM != subMesh )
-      subMesh->SetEventListener( new SMESH_subMeshEventListener(true),
-                                 SMESH_subMeshEventListenerData::MakeData( subMesh ),
-                                 srcShapeSM );
-  }
+  TAssocTool::SetEventListener( subMesh,
+                                _sourceHypo->GetSource3DShape(),
+                                _sourceHypo->GetSourceMesh() );
 }