Salome HOME
2f1fddb0005274842d0abac94e232c9a25a9e5d6
[modules/shaper.git] / src / SketchSolver / PlaneGCSSolver / PlaneGCSSolver_Update.h
1 // Copyright (C) 2017-20xx CEA/DEN, EDF R&D
2
3 // File:    PlaneGCSSolver_Update.h
4 // Created: 17 Feb 2017
5 // Author:  Artem ZHIDKOV
6
7 #ifndef PlaneGCSSolver_Update_H_
8 #define PlaneGCSSolver_Update_H_
9
10 #include <ModelAPI_Feature.h>
11
12 #include <list>
13 #include <memory>
14 #include <string>
15
16 class SketchSolver_Constraint;
17 class PlaneGCSSolver_Update;
18 typedef std::shared_ptr<PlaneGCSSolver_Update> UpdaterPtr;
19
20 /** \class   PlaneGCSSolver_Update
21  *  \ingroup Plugins
22  *  \brief   Send events to listeners about changing a feature
23  */
24 class PlaneGCSSolver_Update
25 {
26 public:
27   PlaneGCSSolver_Update(UpdaterPtr theNext = UpdaterPtr())
28     : myNext(theNext)
29   {}
30
31   virtual ~PlaneGCSSolver_Update() {}
32
33   /// \brief Attach listener
34   /// \param theObserver [in]  object which want to receive notifications
35   /// \param theType     [in]  receive notifications about changing objects
36   ///                          of theType and their derivatives
37   virtual void attach(SketchSolver_Constraint* theObserver, const std::string& theType) = 0;
38
39   /// \brief Detach listener
40   void detach(SketchSolver_Constraint* theObserver) {
41     std::list<SketchSolver_Constraint*>::iterator anIt = myObservers.begin();
42     for (; anIt != myObservers.end(); ++anIt)
43       if (*anIt == theObserver) {
44         myObservers.erase(anIt);
45         break;
46       }
47     // detach listener from all senders
48     if (myNext)
49       myNext->detach(theObserver);
50   }
51
52   /// \brief Send notification about update of the feature to all interested
53   virtual void update(const FeaturePtr& theFeature) = 0;
54
55 protected:
56   UpdaterPtr myNext; ///< next updater, access if current one unable to process request
57   std::list<SketchSolver_Constraint*> myObservers; ///< list of observers
58 };
59
60 #endif