Salome HOME
59485c65807a5167468e452d424c5c536dbabc60
[modules/shaper.git] / src / Model / Model_Update.h
1 // Copyright (C) 2014-2017  CEA/DEN, EDF R&D
2 //
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License, or (at your option) any later version.
7 //
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11 // Lesser General Public License for more details.
12 //
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16 //
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com<mailto:webmaster.salome@opencascade.com>
18 //
19
20 #ifndef Model_Update_H_
21 #define Model_Update_H_
22
23 #include "Model.h"
24 #include <ModelAPI_Data.h>
25 #include "Events_Listener.h"
26 #include <memory>
27 #include <set>
28 #include <map>
29
30 class ModelAPI_Object;
31 class ModelAPI_Feature;
32 class ModelAPI_CompositeFeature;
33 class Model_Objects;
34
35 /**\class Model_Update
36  * \ingroup DataModel
37  * \brief Updates the results of features when it is needed.
38  */
39 class Model_Update : public Events_Listener
40 {
41   /// Features and results that were modified and not yet processed.
42   /// The second set is the objects that causes this object is modified
43   std::map<std::shared_ptr<ModelAPI_Feature>, std::set<std::shared_ptr<ModelAPI_Feature> > >
44     myModified;
45   /// Features which arguments were modified by not-persistent changes.
46   /// So, these referencing arguments must be updated
47   /// due to these features info also before execution).
48   std::map<std::shared_ptr<ModelAPI_Feature>, std::set<std::shared_ptr<ModelAPI_Feature> > >
49     myNotPersistentRefs;
50   /// features that must be additionally processed after execution of finish operation
51   std::set<std::shared_ptr<ModelAPI_Feature> > myWaitForFinish;
52   /// to know that some parameter was changed during this operation (to enable update expressions)
53   bool myIsParamUpdated;
54   /// to execute features on finish if preview is needed only on finish operation
55   bool myIsFinish;
56   /// try if processing is currently performed
57   bool myIsProcessed;
58   /// set that contains features that must be executed only on finish of the operation
59   std::set<std::shared_ptr<ModelAPI_Feature> > myProcessOnFinish;
60   /// to avoid infinitive cycling: feature -> count of the processing periods during this update
61   std::map<std::shared_ptr<ModelAPI_Feature>, int > myProcessed;
62   /// if preview in hte property panel is blocked and
63   /// any update is postponed until the end of operation
64   bool myIsPreviewBlocked;
65
66  public:
67   /// Is called only once, on startup of the application
68   Model_Update();
69
70   /// Processes the feature argument update: executes the results
71   MODEL_EXPORT virtual void processEvent(const std::shared_ptr<Events_Message>& theMessage);
72
73 protected:
74   /// Appends the new modified feature to the myModified, clears myProcessed if needed
75   /// Returns true if some feature really was marked as modified
76   /// theReason is the object that causes modification of this feature
77   /// returns true if something reallsy was added to the modified and must be processed
78   bool addModified(
79     std::shared_ptr<ModelAPI_Feature> theFeature, std::shared_ptr<ModelAPI_Feature> theReason);
80
81   /// Recoursively checks and updates features if needed (calls the execute method)
82   /// Returns true if feature was updated.
83   bool processFeature(std::shared_ptr<ModelAPI_Feature> theFeature);
84
85   /// Updates the selection and parametrical arguments before the later feature analysis
86   /// Returns true if something really was updated
87   void updateArguments(std::shared_ptr<ModelAPI_Feature> theFeature);
88
89   /// Sends the redisplay events for feature and results, updates the updated status
90   void redisplayWithResults(std::shared_ptr<ModelAPI_Feature> theFeature,
91     const ModelAPI_ExecState theState);
92
93   /// On operation start/end/abort the "Just" fileds must be cleared and processed in the right way
94   //! \param theFlushRedisplay a boolean value if the redisplay signal should be flushed
95   void processFeatures(const bool theFlushRedisplay = true);
96
97   /// Performs the feature execution
98   /// \returns the status of execution
99   void executeFeature(std::shared_ptr<ModelAPI_Feature> theFeature);
100
101   /// Updates the properties of object because of stability state changes
102   void updateStability(void* theSender);
103
104   /// Returns true if theFeature modification was caused by theReason
105   /// (may be feature of result of this feature)
106   bool isReason(
107     std::shared_ptr<ModelAPI_Feature>& theFeature, std::shared_ptr<ModelAPI_Object> theReason);
108
109   /// Updates a selection attributes for the features that possible were affected by creation
110   /// or reorder of features upper in the history line (issue #1757)
111   void updateSelection(const std::set<std::shared_ptr<ModelAPI_Object> >& theObjects);
112
113 };
114
115 #endif