Salome HOME
bd69891b7b2f55961df02f5d4451f464c810a710
[modules/shaper.git] / src / Model / Model_Update.h
1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D
2
3 // File:        Model_Update.hxx
4 // Created:     25 Jun 2014
5 // Author:      Mikhail PONIKAROV
6
7 #ifndef Model_Update_H_
8 #define Model_Update_H_
9
10 #include "Model.h"
11 #include <ModelAPI_Data.h>
12 #include "Events_Listener.h"
13 #include <memory>
14 #include <set>
15 #include <map>
16
17 class ModelAPI_Object;
18 class ModelAPI_Feature;
19 class ModelAPI_CompositeFeature;
20 class Model_Objects;
21
22 /**\class Model_Update
23  * \ingroup DataModel
24  * \brief Updates the results of features when it is needed.
25  */
26 class Model_Update : public Events_Listener
27 {
28   /// updated features during this transaction with IDs of iterations of modifications
29   /// (to reexecute the object twice if needed: for correct preview, etc.)
30   std::map<std::shared_ptr<ModelAPI_Object>, int > myUpdated;
31   /// current id of modification inside of the current transaction
32   int myModification;
33   /// features that must be additionally processed after execution of finish operation
34   std::set<std::shared_ptr<ModelAPI_Object> > myWaitForFinish;
35   /// to know that all next updates are caused by this execution
36   bool myIsExecuted;
37   /// to know execute or not automatically all update
38   bool myIsAutomatic;
39   /// to know that some parameter was changed during this operation
40   bool myIsParamUpdated;
41   /// to execute features of finish if perview is not needed
42   bool myIsFinish;
43
44   /// internal structure that contains the updating iteration information:
45   /// which object and subobject is iterated, t ocontinue iteration
46   class IterationItem {
47     /// The main object, subs of it are iterated
48     std::shared_ptr<ModelAPI_CompositeFeature> myMain;
49     /// The currently iterated sub-object of root document
50     std::shared_ptr<ModelAPI_Feature> mySub;
51     /// If this is true, this iteration must be breaked immideately
52     bool myBreaked;
53     /// If this flag is true, the virtual iteration is performed, unbreackable
54     bool myIsVirtual;
55     /// For composite main contains the current index
56     int myIndex;
57     /// For root object constains the reference to objects
58     Model_Objects* myObjects;
59     /// If it is true, the next "next" will be ignored
60     bool mySkipNext;
61
62   public:
63     /// Constructs the iterator of subs
64     IterationItem(std::shared_ptr<ModelAPI_CompositeFeature> theFeature);
65     /// Increments the iteration if not-breaked
66     void next();
67     /// Returns true if current is not null
68     bool more();
69     /// Returns the current iterated sub-element
70     std::shared_ptr<ModelAPI_Feature> current();
71     /// Returns true if theFeature is in all iterated objects 
72     bool isIterated(std::shared_ptr<ModelAPI_Feature> theFeature);
73     /// Returns true if theFeature is earlier than the current value 
74     bool isEarlierThanCurrent(std::shared_ptr<ModelAPI_Feature> theFeature);
75     /// Make iteration breaked
76     void setBreaked();
77     /// Makes the iteration before the currently breaked (next "next" will be ignored)
78     void setCurrentBefore(std::shared_ptr<ModelAPI_Feature> theFeature);
79     /// Initializes iteration: virtual or real
80     void startIteration(const bool theVirtual);
81     /// Returns true if iteration was breaked
82     bool isBreaked() {return myBreaked;}
83   };
84   /// List of iterated features: composite feature to the currently iterated sub.
85   /// The first element in the list has no "main": the root document is not feature.
86   std::list<IterationItem> myProcessIterator;
87
88  public:
89   /// Is called only once, on startup of the application
90   Model_Update();
91
92   /// Processes the feature argument update: executes the results
93   MODEL_EXPORT virtual void processEvent(const std::shared_ptr<Events_Message>& theMessage);
94
95 protected:
96   /// Recoursively checks and updates the feature if needed (calls the execute method)
97   /// Returns true if feature was updated.
98   void updateFeature(std::shared_ptr<ModelAPI_Feature> theFeature);
99
100   /// Updates the selection and parametrical arguments before the later feature analysis
101   /// Returns true if something really was updated
102   void updateArguments(std::shared_ptr<ModelAPI_Feature> theFeature);
103
104   /// Sends the redisplay events for feature and results, updates the updated status
105   void redisplayWithResults(std::shared_ptr<ModelAPI_Feature> theFeature, 
106     const ModelAPI_ExecState theState);
107
108   /// On operation start/end/abort the "Just" fileds must be cleared and processed in the right way
109   /// \param theTotalUpdate force to updates everything that has been changed in this operation
110   void processOperation(const bool theTotalUpdate, const bool theFinish = false);
111
112   /// Performs the feature execution
113   /// \returns the status of execution
114   void executeFeature(std::shared_ptr<ModelAPI_Feature> theFeature);
115
116   /// Iterates and updates features from theFeature by managing myProcessIterator.
117   /// Returns only after the iteration is finished.
118   /// \param theFeature is null for iteration of root document (which is not composite)
119   /// \returns false if this feature should not be updated: iteration was moved much upper
120   bool iterateUpdate(std::shared_ptr<ModelAPI_CompositeFeature> theFeature);
121   /// Feature is updated during the execution, so in this case if feature was already executed,
122   /// make the iterate Update process breaked to re-start iteration from this feature.
123   void iterateUpdateBreak(std::shared_ptr<ModelAPI_Feature> theFeature);
124   /// Returns true if the feature is older that the argument and it must be updated
125   bool isOlder(std::shared_ptr<ModelAPI_Feature> theFeature, 
126                std::shared_ptr<ModelAPI_Object> theArgument);
127 };
128
129 #endif