Salome HOME
Copyright update 2022
[modules/shaper.git] / src / Model / Model_Update.h
index 2e44ea32122c6dc542084da15b9ea81126696179..b0b30f9226244c43e0f78328419aff219156e986 100644 (file)
@@ -1,8 +1,21 @@
-// Copyright (C) 2014-20xx CEA/DEN, EDF R&D
-
-// File:        Model_Update.hxx
-// Created:     25 Jun 2014
-// Author:      Mikhail PONIKAROV
+// Copyright (C) 2014-2022  CEA/DEN, EDF R&D
+//
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License as published by the Free Software Foundation; either
+// version 2.1 of the License, or (at your option) any later version.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
+//
+// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
+//
 
 #ifndef Model_Update_H_
 #define Model_Update_H_
@@ -25,67 +38,33 @@ class Model_Objects;
  */
 class Model_Update : public Events_Listener
 {
-  /// updated features during this transaction with IDs of iterations of modifications
-  /// (to reexecute the object twice if needed: for correct preview, etc.)
-  std::map<std::shared_ptr<ModelAPI_Object>, int > myUpdated;
-  /// current id of modification inside of the current transaction
-  int myModification;
-  /// id of modification inside of the current transaction on start of processing
-  int myModificationInStartProcessing;
+  /// Features and results that were modified and not yet processed.
+  /// The second set is the objects that causes this object is modified
+  std::map<std::shared_ptr<ModelAPI_Feature>, std::set<std::shared_ptr<ModelAPI_Feature> > >
+    myModified;
+  /// Features which arguments were modified by not-persistent changes.
+  /// So, these referencing arguments must be updated
+  /// due to these features info also before execution).
+  std::map<std::shared_ptr<ModelAPI_Feature>, std::set<std::shared_ptr<ModelAPI_Feature> > >
+    myNotPersistentRefs;
   /// features that must be additionally processed after execution of finish operation
-  std::set<std::shared_ptr<ModelAPI_Object> > myWaitForFinish;
-  /// to know that all next updates are caused by this execution
-  bool myIsExecuted;
-  /// to know execute or not automatically all update
-  bool myIsAutomatic;
-  /// to know that some parameter was changed during this operation
+  std::set<std::shared_ptr<ModelAPI_Feature> > myWaitForFinish;
+  /// to know that some parameter was changed during this operation (to enable update expressions)
   bool myIsParamUpdated;
-  /// to execute features of finish if perview is not needed
+  /// to execute features on finish if preview is needed only on finish operation
   bool myIsFinish;
-
-  /// internal structure that contains the updating iteration information:
-  /// which object and subobject is iterated, t ocontinue iteration
-  class IterationItem {
-    /// The main object, subs of it are iterated
-    std::shared_ptr<ModelAPI_CompositeFeature> myMain;
-    /// The currently iterated sub-object of root document
-    std::shared_ptr<ModelAPI_Feature> mySub;
-    /// If this is true, this iteration must be breaked immideately
-    bool myBreaked;
-    /// If this flag is true, the virtual iteration is performed, unbreackable
-    bool myIsVirtual;
-    /// For composite main contains the current index
-    int myIndex;
-    /// For root object constains the reference to objects
-    Model_Objects* myObjects;
-    /// If it is true, the next "next" will be ignored
-    bool mySkipNext;
-
-  public:
-    /// Constructs the iterator of subs
-    IterationItem(std::shared_ptr<ModelAPI_CompositeFeature> theFeature);
-    /// Increments the iteration if not-breaked
-    void next();
-    /// Returns true if current is not null
-    bool more();
-    /// Returns the current iterated sub-element
-    std::shared_ptr<ModelAPI_Feature> current();
-    /// Returns true if theFeature is in all iterated objects 
-    bool isIterated(std::shared_ptr<ModelAPI_Feature> theFeature);
-    /// Returns true if theFeature is earlier than the current value 
-    bool isEarlierThanCurrent(std::shared_ptr<ModelAPI_Feature> theFeature);
-    /// Make iteration breaked
-    void setBreaked();
-    /// Makes the iteration before the currently breaked (next "next" will be ignored)
-    void setCurrentBefore(std::shared_ptr<ModelAPI_Feature> theFeature);
-    /// Initializes iteration: virtual or real
-    void startIteration(const bool theVirtual);
-    /// Returns true if iteration was breaked
-    bool isBreaked() {return myBreaked;}
-  };
-  /// List of iterated features: composite feature to the currently iterated sub.
-  /// The first element in the list has no "main": the root document is not feature.
-  std::list<IterationItem> myProcessIterator;
+  /// try if processing is currently performed
+  bool myIsProcessed;
+  /// map that contains features that must be executed only on finish of the operation
+  /// the value in map is the set of reasons
+  std::map<std::shared_ptr<ModelAPI_Feature>, std::set<std::shared_ptr<ModelAPI_Feature> > >
+    myProcessOnFinish;
+  /// to avoid infinitive cycling: feature -> count of the processing periods during this update
+  std::map<std::shared_ptr<ModelAPI_Feature>, int > myProcessed;
+  /// if preview in the property panel is blocked any update is postponed until end of operation
+  bool myIsPreviewBlocked;
+  /// disables any update if it is true, even on start/finish operation, undo, etc.
+  bool myUpdateBlocked;
 
  public:
   /// Is called only once, on startup of the application
@@ -95,42 +74,45 @@ class Model_Update : public Events_Listener
   MODEL_EXPORT virtual void processEvent(const std::shared_ptr<Events_Message>& theMessage);
 
 protected:
-  /// Recoursively checks and updates the feature if needed (calls the execute method)
+  /// Appends the new modified feature to the myModified, clears myProcessed if needed
+  /// Returns true if some feature really was marked as modified
+  /// theReason is the object that causes modification of this feature
+  /// returns true if something reallsy was added to the modified and must be processed
+  bool addModified(
+    std::shared_ptr<ModelAPI_Feature> theFeature, std::shared_ptr<ModelAPI_Feature> theReason);
+
+  /// Recoursively checks and updates features if needed (calls the execute method)
   /// Returns true if feature was updated.
-  void updateFeature(std::shared_ptr<ModelAPI_Feature> theFeature);
+  bool processFeature(std::shared_ptr<ModelAPI_Feature> theFeature);
 
   /// Updates the selection and parametrical arguments before the later feature analysis
   /// Returns true if something really was updated
   void updateArguments(std::shared_ptr<ModelAPI_Feature> theFeature);
 
   /// Sends the redisplay events for feature and results, updates the updated status
-  void redisplayWithResults(std::shared_ptr<ModelAPI_Feature> theFeature, 
-    const ModelAPI_ExecState theState);
+  void redisplayWithResults(std::shared_ptr<ModelAPI_Feature> theFeature,
+    const ModelAPI_ExecState theState, bool theUpdateState = true);
 
   /// On operation start/end/abort the "Just" fileds must be cleared and processed in the right way
-  /// \param theTotalUpdate force to updates everything that has been changed in this operation
-  /// \param theFinish is true for start, close or abort transaction: all objects must be processed
-  void processOperation(const bool theTotalUpdate, const bool theFinish = false);
+  //! \param theFlushRedisplay a boolean value if the redisplay signal should be flushed
+  void processFeatures(const bool theFlushRedisplay = true);
 
   /// Performs the feature execution
   /// \returns the status of execution
   void executeFeature(std::shared_ptr<ModelAPI_Feature> theFeature);
 
-  /// Iterates and updates features from theFeature by managing myProcessIterator.
-  /// Returns only after the iteration is finished.
-  /// \param theFeature is null for iteration of root document (which is not composite)
-  /// \returns false if this feature should not be updated: iteration was moved much upper
-  bool iterateUpdate(std::shared_ptr<ModelAPI_CompositeFeature> theFeature);
-  /// Feature is updated during the execution, so in this case if feature was already executed,
-  /// make the iterate Update process breaked to re-start iteration from this feature.
-  void iterateUpdateBreak(std::shared_ptr<ModelAPI_Feature> theFeature);
-  /// Returns true if the feature is older that the argument and it must be updated
-  bool isOlder(std::shared_ptr<ModelAPI_Feature> theFeature, 
-               std::shared_ptr<ModelAPI_Object> theArgument);
   /// Updates the properties of object because of stability state changes
   void updateStability(void* theSender);
-  /// Returns true if the feature is the given modification ID is processed in the current processOperation
-  bool isProcessed(const int theModificationID);
+
+  /// Returns true if theFeature modification was caused by theReason
+  /// (may be feature of result of this feature)
+  bool isReason(
+    std::shared_ptr<ModelAPI_Feature>& theFeature, std::shared_ptr<ModelAPI_Object> theReason);
+
+  /// Updates a selection attributes for the features that possible were affected by creation
+  /// or reorder of features upper in the history line (issue #1757)
+  void updateSelection(const std::set<std::shared_ptr<ModelAPI_Object> >& theObjects);
+
 };
 
 #endif