Salome HOME
Copyright update 2022
[modules/shaper.git] / src / Model / Model_Events.h
index 68b277b94c03f9084f0dc79d3add800be884319c..937ca6f7d61e6d23150f2feacae856c0f71e188c 100644 (file)
-// File:        Model_Events.h
-// Created:     10 Apr 2014
-// Author:      Mikhail PONIKAROV
-
-#ifndef Model_Events_HeaderFile
-#define Model_Events_HeaderFile
+// 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_Events_H_
+#define Model_Events_H_
 
 #include <Model.h>
-#include <Events_MessageGroup.h>
-#include <Events_Loop.h>
-#include <boost/shared_ptr.hpp>
-#include <string>
-#include <set>
-
-#include "ModelAPI_Feature.h"
+#include <ModelAPI_Events.h>
+
+#include <memory>
+
+/// Allows to create ModelAPI messages
+class Model_EventCreator : public ModelAPI_EventCreator
+{
+ public:
+  /// creates created, updated or moved messages and sends to the loop
+  virtual void sendUpdated(const ObjectPtr& theObject, const Events_ID& theEvent,
+                           const bool isGroupped = true) const;
+
+  /// creates created, updated or moved messages with the objects collection and sends to the loop
+  virtual void sendUpdated(const std::list<ObjectPtr>& theObjects, const Events_ID& theEvent,
+    const bool isGroupped = true) const;
+  /// creates deleted message and sends to the loop
+  virtual void sendDeleted(const std::shared_ptr<ModelAPI_Document>& theDoc,
+                           const std::string& theGroup) const;
+
+  /// creates reordered message and sends to the loop
+  virtual void sendReordered(const std::shared_ptr<ModelAPI_Feature>& theReordered) const;
+
+  /// must be one per application, the constructor for internal usage only
+  Model_EventCreator();
+};
 
-class ModelAPI_Document;
+/// Message that feature was changed (used for Object Browser update): moved, updated and deleted
+class Model_ObjectUpdatedMessage : public ModelAPI_ObjectUpdatedMessage
+{
+  std::set<ObjectPtr> myObjects;  ///< which feature is changed
 
-/// Event ID that feature is created (comes with Model_FeatureUpdatedMessage)
-static const char * EVENT_FEATURE_CREATED = "FeatureCreated";
-/// Event ID that data of feature is updated (comes with Model_FeatureUpdatedMessage)
-static const char * EVENT_FEATURE_UPDATED = "FeatureUpdated";
-/// Event ID that data of feature is deleted (comes with Model_FeatureDeletedMessage)
-static const char * EVENT_FEATURE_DELETED = "FeatureDeleted";
-/// Event ID that data of feature is updated (comes with Model_FeaturesMovedMessage)
-static const char * EVENT_FEATURE_MOVED = "FeaturesMoved";
+  /// Sender is not important, all information is located in the feature.
+  /// Use ModelAPI for creation of this event. Used for creation, movement and edition events.
+  Model_ObjectUpdatedMessage(const ObjectPtr& theObject, const Events_ID& theEvent);
 
-/// Message that feature was changed (used for Object Browser update): moved, updated and deleted
-class Model_FeatureUpdatedMessage : public Events_MessageGroup {
-  std::set<FeaturePtr > myFeatures; ///< which feature is changed
-public:
-  /// sender is not important, all information is located in the feature
-  Model_FeatureUpdatedMessage(
-    const FeaturePtr& theFeature,
-    const Events_ID& theEvent) : Events_MessageGroup(theEvent, 0)
-  {if (theFeature) myFeatures.insert(theFeature);}
+  friend class Model_EventCreator;
+ public:
 
   /// Returns the feature that has been updated
-  std::set<FeaturePtr> features() const {return myFeatures;}
+  virtual const std::set<ObjectPtr>& objects() const;
 
   //! Creates a new empty group (to store it in the loop before flush)
-  virtual Events_MessageGroup* newEmpty() {
-    FeaturePtr anEmptyFeature;
-    return new Model_FeatureUpdatedMessage(anEmptyFeature, eventID());
-  }
+  virtual std::shared_ptr<Events_MessageGroup> newEmpty();
 
   //! Allows to join the given message with the current one
-  virtual void Join(Events_MessageGroup& theJoined) {
-    Model_FeatureUpdatedMessage* aJoined = dynamic_cast<Model_FeatureUpdatedMessage*>(&theJoined);
-    std::set<FeaturePtr >::iterator aFIter = aJoined->myFeatures.begin();
-    for(; aFIter != aJoined->myFeatures.end(); aFIter++) {
-      myFeatures.insert(*aFIter);
-    }
-  }
+  virtual void Join(const std::shared_ptr<Events_MessageGroup>& theJoined);
 };
 
 /// Message that feature was deleted (used for Object Browser update)
-class Model_FeatureDeletedMessage : public Events_MessageGroup {
-  boost::shared_ptr<ModelAPI_Document> myDoc; ///< document owner of the feature
-  std::set<std::string> myGroups; ///< group identifiers that contained the deleted feature
-public:
-  /// creates a message by initialization of fields
-//  Model_FeatureDeletedMessage(const boost::shared_ptr<ModelAPI_Document>& theDoc,
-//    const std::string& theGroup);
-
-  /// Returns the ID of this message (EVENT_FEATURE_DELETED)
-//  static const Events_ID messageId();
-
-  /// Returns the feature that has been updated
-  boost::shared_ptr<ModelAPI_Document> document() const {return myDoc;}
-
-  /// Returns the group where the feature was deleted
-  const std::set<std::string >& groups() const {return myGroups;}
-
-  //! Creates a new empty group (to store it in the loop before flush)
-//  virtual Events_MessageGroup* newEmpty();
-
-  //! Allows to join the given message with the current one
-//  virtual void Join(Events_MessageGroup& theJoined);
-
-  Events_MessageGroup* newEmpty() {
-    return new Model_FeatureDeletedMessage(myDoc, "");
+class Model_ObjectDeletedMessage : public ModelAPI_ObjectDeletedMessage
+{
+  ///< group identifiers that contained the deleted feature and document where they are deleted
+  std::list<std::pair<std::shared_ptr<ModelAPI_Document>, std::string> > myGroups;
+
+  /// Use ModelAPI for creation of this event.
+  Model_ObjectDeletedMessage(const std::shared_ptr<ModelAPI_Document>& theDoc,
+                             const std::string& theGroup);
+
+  friend class Model_EventCreator;
+ public:
+  /// Returns the group where the objects were deleted
+  virtual const std::list<std::pair<std::shared_ptr<ModelAPI_Document>, std::string> >&
+    groups() const
+  {
+    return myGroups;
   }
 
-  Model_FeatureDeletedMessage(
-    const boost::shared_ptr<ModelAPI_Document>& theDoc, const std::string& theGroup)
-    : Events_MessageGroup(messageId(), 0), myDoc(theDoc)
+  /// Returns the new empty message of this type
+  virtual std::shared_ptr<Events_MessageGroup> newEmpty();
 
-  {
-    if (!theGroup.empty())
-      myGroups.insert(theGroup);
-  }
+  /// Returns the identifier of this message
+  virtual const Events_ID messageId();
 
-  const Events_ID messageId()
-  {
-    static Events_ID MY_ID = Events_Loop::eventByName(EVENT_FEATURE_DELETED);
-    return MY_ID;
-  }
+  /// Appends to this message the given one
+  virtual void Join(const std::shared_ptr<Events_MessageGroup>& theJoined);
+};
 
-  void Join(Events_MessageGroup& theJoined)
+/// Message that feature was deleted (used for Object Browser update)
+class Model_OrderUpdatedMessage : public ModelAPI_OrderUpdatedMessage
+{
+  std::shared_ptr<ModelAPI_Feature> myReordered;  ///< the feature that was moved
+
+  /// Use ModelAPI for creation of this event.
+  Model_OrderUpdatedMessage(FeaturePtr theReordered,
+                            const void* theSender = 0);
+
+  friend class Model_EventCreator;
+ public:
+  /// Returns the document that has been updated
+  virtual std::shared_ptr<ModelAPI_Feature> reordered()
   {
-    Model_FeatureDeletedMessage* aJoined = dynamic_cast<Model_FeatureDeletedMessage*>(&theJoined);
-    std::set<std::string>::iterator aGIter = aJoined->myGroups.begin();
-    for(; aGIter != aJoined->myGroups.end(); aGIter++) {
-      myGroups.insert(*aGIter);
-    }
+    return myReordered;
   }
+
+  /// Returns the identifier of this message
+  virtual const Events_ID messageId();
 };
 
 #endif