Salome HOME
Add copyright header according to request of CEA from 06.06.2017
[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
18 // email : webmaster.salome@opencascade.com<mailto:webmaster.salome@opencascade.com>
19 //
20
21 #ifndef Model_Update_H_
22 #define Model_Update_H_
23
24 #include "Model.h"
25 #include <ModelAPI_Data.h>
26 #include "Events_Listener.h"
27 #include <memory>
28 #include <set>
29 #include <map>
30
31 class ModelAPI_Object;
32 class ModelAPI_Feature;
33 class ModelAPI_CompositeFeature;
34 class Model_Objects;
35
36 /**\class Model_Update
37  * \ingroup DataModel
38  * \brief Updates the results of features when it is needed.
39  */
40 class Model_Update : public Events_Listener
41 {
42   /// Features and results that were modified and not yet processed.
43   /// The second set is the objects that causes this object is modified
44   std::map<std::shared_ptr<ModelAPI_Feature>, std::set<std::shared_ptr<ModelAPI_Feature> > >
45     myModified;
46   /// Features which arguments were modified by not-persistent changes.
47   /// So, these referencing arguments must be updated
48   /// due to these features info also before execution).
49   std::map<std::shared_ptr<ModelAPI_Feature>, std::set<std::shared_ptr<ModelAPI_Feature> > >
50     myNotPersistentRefs;
51   /// features that must be additionally processed after execution of finish operation
52   std::set<std::shared_ptr<ModelAPI_Feature> > myWaitForFinish;
53   /// to know that some parameter was changed during this operation (to enable update expressions)
54   bool myIsParamUpdated;
55   /// to execute features on finish if preview is needed only on finish operation
56   bool myIsFinish;
57   /// try if processing is currently performed
58   bool myIsProcessed;
59   /// set that contains features that must be executed only on finish of the operation
60   std::set<std::shared_ptr<ModelAPI_Feature> > myProcessOnFinish;
61   /// to avoid infinitive cycling: feature -> count of the processing periods during this update
62   std::map<std::shared_ptr<ModelAPI_Feature>, int > myProcessed;
63   /// if preview in hte property panel is blocked and
64   /// any update is postponed until the end of operation
65   bool myIsPreviewBlocked;
66
67  public:
68   /// Is called only once, on startup of the application
69   Model_Update();
70
71   /// Processes the feature argument update: executes the results
72   MODEL_EXPORT virtual void processEvent(const std::shared_ptr<Events_Message>& theMessage);
73
74 protected:
75   /// Appends the new modified feature to the myModified, clears myProcessed if needed
76   /// Returns true if some feature really was marked as modified
77   /// theReason is the object that causes modification of this feature
78   /// returns true if something reallsy was added to the modified and must be processed
79   bool addModified(
80     std::shared_ptr<ModelAPI_Feature> theFeature, std::shared_ptr<ModelAPI_Feature> theReason);
81
82   /// Recoursively checks and updates features if needed (calls the execute method)
83   /// Returns true if feature was updated.
84   bool processFeature(std::shared_ptr<ModelAPI_Feature> theFeature);
85
86   /// Updates the selection and parametrical arguments before the later feature analysis
87   /// Returns true if something really was updated
88   void updateArguments(std::shared_ptr<ModelAPI_Feature> theFeature);
89
90   /// Sends the redisplay events for feature and results, updates the updated status
91   void redisplayWithResults(std::shared_ptr<ModelAPI_Feature> theFeature,
92     const ModelAPI_ExecState theState);
93
94   /// On operation start/end/abort the "Just" fileds must be cleared and processed in the right way
95   //! \param theFlushRedisplay a boolean value if the redisplay signal should be flushed
96   void processFeatures(const bool theFlushRedisplay = true);
97
98   /// Performs the feature execution
99   /// \returns the status of execution
100   void executeFeature(std::shared_ptr<ModelAPI_Feature> theFeature);
101
102   /// Updates the properties of object because of stability state changes
103   void updateStability(void* theSender);
104
105   /// Returns true if theFeature modification was caused by theReason
106   /// (may be feature of result of this feature)
107   bool isReason(
108     std::shared_ptr<ModelAPI_Feature>& theFeature, std::shared_ptr<ModelAPI_Object> theReason);
109
110   /// Updates a selection attributes for the features that possible were affected by creation
111   /// or reorder of features upper in the history line (issue #1757)
112   void updateSelection(const std::set<std::shared_ptr<ModelAPI_Object> >& theObjects);
113
114 };
115
116 #endif