1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D
3 // File: Model_Update.hxx
4 // Created: 25 Jun 2014
5 // Author: Mikhail PONIKAROV
7 #ifndef Model_Update_H_
8 #define Model_Update_H_
11 #include <ModelAPI_Data.h>
12 #include "Events_Listener.h"
17 class ModelAPI_Object;
18 class ModelAPI_Feature;
19 class ModelAPI_CompositeFeature;
22 /**\class Model_Update
24 * \brief Updates the results of features when it is needed.
26 class Model_Update : public Events_Listener
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
33 /// id of modification inside of the current transaction on start of processing
34 int myModificationInStartProcessing;
35 /// features that must be additionally processed after execution of finish operation
36 std::set<std::shared_ptr<ModelAPI_Object> > myWaitForFinish;
37 /// to know that all next updates are caused by this execution
39 /// to know execute or not automatically all update
41 /// to know that some parameter was changed during this operation
42 bool myIsParamUpdated;
43 /// to execute features of finish if perview is not needed
46 /// internal structure that contains the updating iteration information:
47 /// which object and subobject is iterated, t ocontinue iteration
49 /// The main object, subs of it are iterated
50 std::shared_ptr<ModelAPI_CompositeFeature> myMain;
51 /// The currently iterated sub-object of root document
52 std::shared_ptr<ModelAPI_Feature> mySub;
53 /// If this is true, this iteration must be breaked immideately
55 /// If this flag is true, the virtual iteration is performed, unbreackable
57 /// For composite main contains the current index
59 /// For root object constains the reference to objects
60 Model_Objects* myObjects;
61 /// If it is true, the next "next" will be ignored
65 /// Constructs the iterator of subs
66 IterationItem(std::shared_ptr<ModelAPI_CompositeFeature> theFeature);
67 /// Increments the iteration if not-breaked
69 /// Returns true if current is not null
71 /// Returns the current iterated sub-element
72 std::shared_ptr<ModelAPI_Feature> current();
73 /// Returns true if theFeature is in all iterated objects
74 bool isIterated(std::shared_ptr<ModelAPI_Feature> theFeature);
75 /// Returns true if theFeature is earlier than the current value
76 bool isEarlierThanCurrent(std::shared_ptr<ModelAPI_Feature> theFeature);
77 /// Make iteration breaked
79 /// Makes the iteration before the currently breaked (next "next" will be ignored)
80 void setCurrentBefore(std::shared_ptr<ModelAPI_Feature> theFeature);
81 /// Initializes iteration: virtual or real
82 void startIteration(const bool theVirtual);
83 /// Returns true if iteration was breaked
84 bool isBreaked() {return myBreaked;}
86 /// List of iterated features: composite feature to the currently iterated sub.
87 /// The first element in the list has no "main": the root document is not feature.
88 std::list<IterationItem> myProcessIterator;
91 /// Is called only once, on startup of the application
94 /// Processes the feature argument update: executes the results
95 MODEL_EXPORT virtual void processEvent(const std::shared_ptr<Events_Message>& theMessage);
98 /// Recoursively checks and updates the feature if needed (calls the execute method)
99 /// Returns true if feature was updated.
100 void updateFeature(std::shared_ptr<ModelAPI_Feature> theFeature);
102 /// Updates the selection and parametrical arguments before the later feature analysis
103 /// Returns true if something really was updated
104 void updateArguments(std::shared_ptr<ModelAPI_Feature> theFeature);
106 /// Sends the redisplay events for feature and results, updates the updated status
107 void redisplayWithResults(std::shared_ptr<ModelAPI_Feature> theFeature,
108 const ModelAPI_ExecState theState);
110 /// On operation start/end/abort the "Just" fileds must be cleared and processed in the right way
111 /// \param theTotalUpdate force to updates everything that has been changed in this operation
112 /// \param theFinish is true for start, close or abort transaction: all objects must be processed
113 void processOperation(const bool theTotalUpdate, const bool theFinish = false);
115 /// Performs the feature execution
116 /// \returns the status of execution
117 void executeFeature(std::shared_ptr<ModelAPI_Feature> theFeature);
119 /// Iterates and updates features from theFeature by managing myProcessIterator.
120 /// Returns only after the iteration is finished.
121 /// \param theFeature is null for iteration of root document (which is not composite)
122 /// \returns false if this feature should not be updated: iteration was moved much upper
123 bool iterateUpdate(std::shared_ptr<ModelAPI_CompositeFeature> theFeature);
124 /// Feature is updated during the execution, so in this case if feature was already executed,
125 /// make the iterate Update process breaked to re-start iteration from this feature.
126 void iterateUpdateBreak(std::shared_ptr<ModelAPI_Feature> theFeature);
127 /// Returns true if the feature is older that the argument and it must be updated
128 bool isOlder(std::shared_ptr<ModelAPI_Feature> theFeature,
129 std::shared_ptr<ModelAPI_Object> theArgument);
130 /// Updates the properties of object because of stability state changes
131 void updateStability(void* theSender);
132 /// Returns true if the feature is the given modification ID is processed in the current processOperation
133 bool isProcessed(const int theModificationID);