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 /// 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
37 /// to know execute or not automatically all update
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
44 /// internal structure that contains the updating iteration information:
45 /// which object and subobject is iterated, t ocontinue iteration
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
53 /// If this flag is true, the virtual iteration is performed, unbreackable
55 /// For composite main contains the current index
57 /// For root object constains the reference to objects
58 Model_Objects* myObjects;
59 /// If it is true, the next "next" will be ignored
63 /// Constructs the iterator of subs
64 IterationItem(std::shared_ptr<ModelAPI_CompositeFeature> theFeature);
65 /// Increments the iteration if not-breaked
67 /// Returns true if current is not null
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
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;}
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;
89 /// Is called only once, on startup of the application
92 /// Processes the feature argument update: executes the results
93 MODEL_EXPORT virtual void processEvent(const std::shared_ptr<Events_Message>& theMessage);
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);
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);
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);
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 /// \param theFinish is true for start, close or abort transaction: all objects must be processed
111 void processOperation(const bool theTotalUpdate, const bool theFinish = false);
113 /// Performs the feature execution
114 /// \returns the status of execution
115 void executeFeature(std::shared_ptr<ModelAPI_Feature> theFeature);
117 /// Iterates and updates features from theFeature by managing myProcessIterator.
118 /// Returns only after the iteration is finished.
119 /// \param theFeature is null for iteration of root document (which is not composite)
120 /// \returns false if this feature should not be updated: iteration was moved much upper
121 bool iterateUpdate(std::shared_ptr<ModelAPI_CompositeFeature> theFeature);
122 /// Feature is updated during the execution, so in this case if feature was already executed,
123 /// make the iterate Update process breaked to re-start iteration from this feature.
124 void iterateUpdateBreak(std::shared_ptr<ModelAPI_Feature> theFeature);
125 /// Returns true if the feature is older that the argument and it must be updated
126 bool isOlder(std::shared_ptr<ModelAPI_Feature> theFeature,
127 std::shared_ptr<ModelAPI_Object> theArgument);
128 /// Updates the properties of object because of stability state changes
129 void updateStability(void* theSender);