Salome HOME
dd687177a0159f2625ae7da3aa11b6c9d4cdab51
[modules/shaper.git] / src / Model / Model_Update.h
1 // File:        Model_Update.hxx
2 // Created:     25 Jun 2014
3 // Author:      Mikhail PONIKAROV
4
5 #ifndef Model_Update_H_
6 #define Model_Update_H_
7
8 #include "Model.h"
9 #include <ModelAPI_Data.h>
10 #include "Events_Listener.h"
11 #include <memory>
12 #include <set>
13 #include <map>
14
15 class ModelAPI_Object;
16 class ModelAPI_Feature;
17
18 /**\class Model_Update
19  * \ingroup DataModel
20  * \brief Updates the results of features when it is needed.
21  */
22 class Model_Update : public Events_Listener
23 {
24   /// initial set of updated features that must be processed
25   std::set<std::shared_ptr<ModelAPI_Object> > myInitial;
26   /// already updated and processed features and modificated feature flag
27   std::map<std::shared_ptr<ModelAPI_Object>, bool> myUpdated;
28   /// to know that all next updates are caused by this execution
29   bool isExecuted;
30   /// to know execute or not automatically all update
31   bool isAutomatic;
32   /// just created features: they must be updated immideately even in not-automatic mode for 
33   /// preview; cleared on commit operations
34   std::set<std::shared_ptr<ModelAPI_Object> > myJustCreatedOrUpdated;
35
36  public:
37   /// Is called only once, on startup of the application
38   Model_Update();
39
40   /// Processes the feature argument update: executes the results
41   MODEL_EXPORT virtual void processEvent(const std::shared_ptr<Events_Message>& theMessage);
42
43 protected:
44   /// updates all features in the document and then - in sub-documents
45   void updateInDoc(std::shared_ptr<ModelAPI_Document> theDoc);
46   /// Recoursively checks and updates the feature if needed (calls the execute method)
47   /// Returns true if feature was updated.
48   bool updateFeature(std::shared_ptr<ModelAPI_Feature> theFeature);
49
50   /// Recoursively checks and updates the object (result or feature) if needed (calls updateFeature)
51   /// Returns true if object was updated.
52   bool updateObject(std::shared_ptr<ModelAPI_Object> theObject, const bool theCyclic = true);
53   /// Sends the redisplay events for feature and results, updates the updated status
54   void redisplayWithResults(std::shared_ptr<ModelAPI_Feature> theFeature, 
55     const ModelAPI_ExecState theState);
56 };
57
58 #endif