Salome HOME
22877: EDF 10054 SMESH: Add a new filter "BelongToSmeshGroup" for Create Group
[modules/smesh.git] / src / SMESH_I / SMESH_Filter_i.hxx
index 1b70ae38836b0d6751326ab20c99cb4d9c9bd9a2..92b1235b42b20837edeaeb36e50a30fe114510a3 100644 (file)
 
 #include <list>
 
+class SMESH_GroupBase_i;
+
+
 namespace SMESH
 {
+  /*!
+   * \brief Object notified on change of base objects and
+   *        notifying dependent objects in its turn.
+   *        This interface is used to track the following dependencies:
+   *        - GroupOnFiler depending on Filter predicates
+   *        - Filter depending on a Group via FT_BelongToMeshGroup predicate 
+   */
+  struct NotifyerAndWaiter
+  {
+    virtual void OnBaseObjModified(NotifyerAndWaiter* obj, bool removed) {};
+    // specific reaction on modification of a base object
+
+    void Modified( bool removed=false, NotifyerAndWaiter* who = 0);
+    // calls OnBaseObjModified(), if who != 0, and myWaiters[i]->Modified(who)
+
+    void AddModifWaiter    ( NotifyerAndWaiter* waiter ); // adds a dependent object to notify
+    void RemoveModifWaiter ( NotifyerAndWaiter* waiter ); // CALL IT when a waiter dies!!!
+    bool ContainModifWaiter( NotifyerAndWaiter* waiter );
+    std::list<NotifyerAndWaiter*> myWaiters;
+  };
   // ================================================================================
   /*
     FUNCTORS
@@ -370,6 +393,28 @@ namespace SMESH
     FunctorType                     GetFunctorType();
   };
 
+  /*
+    Class       : BelongToMeshGroup_i
+    Description : Verify whether a mesh element is included into a mesh group
+  */
+  class SMESH_I_EXPORT BelongToMeshGroup_i: public virtual POA_SMESH::BelongToMeshGroup,
+                                            public virtual Predicate_i
+  {
+    std::string                    myID; // IOR or StoreName
+    SMESH::SMESH_GroupBase_var     myGroup;
+    Controls::BelongToMeshGroupPtr myBelongToMeshGroup;
+  public:
+    BelongToMeshGroup_i();
+    ~BelongToMeshGroup_i();
+    void                       SetGroup( SMESH::SMESH_GroupBase_ptr theGroup );
+    void                       SetGroupID( const char* theID ); // IOR or StoreName
+    SMESH::SMESH_GroupBase_ptr GetGroup();
+
+    std::string                GetGroupID();
+    FunctorType                GetFunctorType();
+    //virtual void               SetMesh( SMESH_Mesh_ptr theMesh );
+  };
+
   /*
     Class       : BelongToGeom_i
     Description : Predicate for selection on geometrical support
@@ -896,7 +941,8 @@ namespace SMESH
     FILTER
   */
   class SMESH_I_EXPORT Filter_i: public virtual POA_SMESH::Filter,
-                                 public virtual SALOME::GenericObj_i
+                                 public virtual SALOME::GenericObj_i,
+                                 public NotifyerAndWaiter
   {
   public:
     Filter_i();
@@ -943,6 +989,12 @@ namespace SMESH
 
     Predicate_i*     GetPredicate_i();
 
+    void FindBaseObjects();
+    // finds groups it depends on
+
+    virtual void OnBaseObjModified(NotifyerAndWaiter* group, bool removed);
+    // notified on change of myBaseGroups[i]
+
     // =========================
     // SMESH_IDSource interface
     // =========================
@@ -953,22 +1005,13 @@ namespace SMESH
     virtual SMESH::SMESH_Mesh_ptr        GetMesh();
     virtual bool                         IsMeshInfoCorrect() { return true; }
     virtual SALOMEDS::TMPFile*           GetVtkUgStream();
-    /*!
-     * \brief Object notified on change of predicate
-     */
-    struct TPredicateChangeWaiter
-    {
-      virtual void PredicateChanged() = 0;
-    };
-    void AddWaiter( TPredicateChangeWaiter* waiter );
-    void RemoveWaiter( TPredicateChangeWaiter* waiter );
 
   private:
     Controls::Filter myFilter;
     Predicate_i*     myPredicate;
     SMESH_Mesh_var   myMesh;
 
-    std::list<TPredicateChangeWaiter*> myWaiters;
+    std::vector< SMESH_GroupBase_i* > myBaseGroups;
   };
   
   
@@ -1036,6 +1079,7 @@ namespace SMESH
     MultiConnection2D_ptr     CreateMultiConnection2D();
     BallDiameter_ptr          CreateBallDiameter();
     
+    BelongToMeshGroup_ptr     CreateBelongToMeshGroup();
     BelongToGeom_ptr          CreateBelongToGeom();
     BelongToPlane_ptr         CreateBelongToPlane();
     BelongToCylinder_ptr      CreateBelongToCylinder();