Salome HOME
A new event Visual Attributes Changed is defined for performance sake.
[modules/shaper.git] / src / ModelAPI / ModelAPI_Events.h
index 656ec109aeddf4735c8351b0d597ca0ec761cbbb..0b250ebd53e24493c8f0b4b93e42841d71b53aa4 100644 (file)
@@ -1,8 +1,21 @@
-// Copyright (C) 2014-20xx CEA/DEN, EDF R&D
-
-// File:        ModelAPI_Events.h
-// Created:     10 Apr 2014
-// Author:      Mikhail PONIKAROV
+// Copyright (C) 2014-2019  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 MODELAPI_EVENTS_H_
 #define MODELAPI_EVENTS_H_
@@ -21,6 +34,8 @@
 
 
 class ModelAPI_Document;
+class ModelAPI_ResultParameter;
+class GeomAPI_Pnt2d;
 
 /// Event ID that feature is created (comes with ModelAPI_ObjectUpdatedMessage)
 static const char * EVENT_OBJECT_CREATED = "ObjectCreated";
@@ -34,34 +49,67 @@ static const char * EVENT_OBJECT_RENAMED = "ObjectRenamed";
 static const char * EVENT_OBJECT_MOVED = "ObjectsMoved";
 /// Event ID that visualization must be redisplayed (comes with ModelAPI_ObjectUpdatedMessage)
 static const char * EVENT_OBJECT_TO_REDISPLAY = "ObjectsToRedisplay";
-/// Event ID that visualization must be redisplayed (comes with ModelAPI_ObjectUpdatedMessage)
-static const char * EVENT_OPERATION_LAUNCHED = "OperationLaunched";
 /// Event ID that plugin is loaded (comes with ModelAPI_ObjectUpdatedMessage)
-static const char * EVENT_PLUGIN_LOADED = "PliginLoaded";
-//
+static const char * EVENT_PLUGIN_LOADED = "PluginLoaded";
+/// The active document becomes another one
 static const char * EVENT_DOCUMENT_CHANGED = "CurrentDocumentChanged";
 
+/// Event ID that order of objects in group is changed,
+/// so, tree must be fully recreated (movement of feature)
+static const char * EVENT_ORDER_UPDATED = "OrderUpdated";
+/// Event ID that the sketch is prepared and all grouped messages for the solver may be flushed
+static const char * EVENT_UPDATE_SELECTION = "UpdateSelection";
+
+/// Request for the enabled/disabled actions behavior for some specific features
 static const char * EVENT_FEATURE_STATE_REQUEST = "FeatureStateRequest";
+/// Reply for the enabled/disabled actions behavior for some specific features
 static const char * EVENT_FEATURE_STATE_RESPONSE = "FeatureStateResponse";
 
-
+/// To block the viewer updates
 static const char * EVENT_UPDATE_VIEWER_BLOCKED = "UpdateViewerBlocked";
+/// To unblock the viewer updates
 static const char * EVENT_UPDATE_VIEWER_UNBLOCKED = "UpdateViewerUnblocked";
 
+/// To inform that there is an empty presentation in the viewer
+static const char * EVENT_EMPTY_AIS_PRESENTATION = "EmptyAISPresentation";
+/// To inform that there is an empty operation for presentation in the viewer
+static const char * EVENT_EMPTY_OPERATION_PRESENTATION = "EmptyOperationPresentation";
+/// To block preview
 static const char * EVENT_PREVIEW_BLOCKED = "PreviewBlocked";
+/// To preview the current feature in the viewer (to compute the result)
 static const char * EVENT_PREVIEW_REQUESTED = "PreviewRequested";
+/// To block automatic recomputation of any feature (by the GUI button press)
+static const char * EVENT_AUTOMATIC_RECOMPUTATION_DISABLE = "DisableAutomaticRecomputation";
+/// To unblock block automatic recomputation (default state: the GUI button unpressed)
+static const char * EVENT_AUTOMATIC_RECOMPUTATION_ENABLE = "EnableAutomaticRecomputation";
 
 /// Event ID that solver has conflicting constraints (comes with ModelAPI_SolverFailedMessage)
 static const char * EVENT_SOLVER_FAILED = "SolverFailed";
 /// Event ID that the problem in solver disappeared
 static const char * EVENT_SOLVER_REPAIRED = "SolverRepaired";
 
-/// Event ID that order of objects in group is changed, so, tree must be fully rectreated (movement of feature)
-static const char * EVENT_ORDER_UPDATED = "OrderUpdated";
+/// Event Id that sketch has DoF = 0
+static const char * EVENT_SKETCH_FULLY_CONSTRAINED = "SketchFullyConstrainted";
+/// Event Id that sketch has DoF > 0
+static const char * EVENT_SKETCH_UNDER_CONSTRAINED = "SketchUnderConstrainted";
+/// Event Id that sketch has DoF < 0
+static const char * EVENT_SKETCH_OVER_CONSTRAINED  = "SketchOverConstrainted";
 
 /// Event ID that informs that some object has changed the stability
 static const char * EVENT_STABILITY_CHANGED = "StabilityChanged";
 
+/// Event ID that the sketch is prepared and all grouped messages for the solver may be flushed
+static const char * EVENT_SKETCH_PREPARED = "SketchPrepared";
+
+/// Event ID that provides a request for list of non-fixed objects necessary for DoF = 0
+static const char * EVENT_GET_DOF_OBJECTS = "GetDoFObjects";
+
+/// Event ID that provides a request for list of non-fixed objects necessary for DoF = 0
+static const char * EVENT_DOF_OBJECTS = "DoFObjects";
+
+/// Event ID that requests updates visual attributes for presentations
+static const char * EVENT_VISUAL_ATTRIBUTES = "UpdateVisualAttributes";
+
 /// Message that feature was changed (used for Object Browser update): moved, updated and deleted
 class MODELAPI_EXPORT ModelAPI_ObjectUpdatedMessage : public Events_MessageGroup
 {
@@ -92,11 +140,9 @@ protected:
   virtual ~ModelAPI_ObjectDeletedMessage();
 
 public:
-  /// Returns the document that has been updated
-  virtual std::shared_ptr<ModelAPI_Document> document() const = 0;
-
   /// Returns the groups where the objects were deleted
-  virtual const std::set<std::string>& groups() const = 0;
+  virtual const std::list<std::pair<std::shared_ptr<ModelAPI_Document>, std::string> >&
+    groups() const = 0;
 
   /// Creates the new empty message of this kind
   virtual std::shared_ptr<Events_MessageGroup> newEmpty() = 0;
@@ -104,7 +150,7 @@ public:
   /// Returns the identifier of the kind of a message
   virtual const Events_ID messageId() = 0;
 
-  /// Appenad to this message the given one.
+  /// Appends to this message the given one.
   virtual void Join(const std::shared_ptr<Events_MessageGroup>& theJoined) = 0;
 };
 
@@ -112,17 +158,14 @@ public:
 class MODELAPI_EXPORT ModelAPI_OrderUpdatedMessage : public Events_Message
 {
 protected:
-  /// Creates an empty message
+  /// Creates a message:
   ModelAPI_OrderUpdatedMessage(const Events_ID theID, const void* theSender = 0);
   /// The virtual destructor
   virtual ~ModelAPI_OrderUpdatedMessage();
 
 public:
   /// Returns the document that has been updated
-  virtual std::shared_ptr<ModelAPI_Document> document() const = 0;
-
-  /// Returns the groups where the objects were reordered
-  virtual const std::string& group() const = 0;
+  virtual std::shared_ptr<ModelAPI_Feature> reordered() = 0;
 
   /// Returns the identifier of the kind of a message
   virtual const Events_ID messageId() = 0;
@@ -135,12 +178,14 @@ 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 = 0;
+  /// 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 = 0;
   /// creates deleted message and sends to the loop
   virtual void sendDeleted(const std::shared_ptr<ModelAPI_Document>& theDoc,
                            const std::string& theGroup) const = 0;
   /// creates reordered message and sends to the loop
-  virtual void sendReordered(const std::shared_ptr<ModelAPI_Document>& theDoc,
-                             const std::string& theGroup) const = 0;
+  virtual void sendReordered(const std::shared_ptr<ModelAPI_Feature>& theReordered) const = 0;
 
   /// returns the creator instance
   static const ModelAPI_EventCreator* get();
@@ -149,7 +194,6 @@ public:
   static void set(const ModelAPI_EventCreator* theCreator);
 };
 
-// TODO(sbh): Move this message into a separate package, like "GuiAPI"
 /// Contains the state information about the feature: is it enabled or disabled.
 class ModelAPI_FeatureStateMessage : public Events_Message
 {
@@ -238,6 +282,109 @@ class ModelAPI_AttributeEvalMessage : public Events_Message
   MODELAPI_EXPORT void setAttribute(AttributePtr theAttribute);
 };
 
+/// Message that parameter feature expression should be evaluated: value and error producing
+class ModelAPI_ParameterEvalMessage : public Events_Message
+{
+  FeaturePtr myParam; ///< parameters that should be evaluated
+  bool myIsProcessed; ///< true if results were set
+  /// result of processing, list of parameters in expression found
+  std::list<std::shared_ptr<ModelAPI_ResultParameter> > myParamsList;
+  double myResult; ///< result of processing, the computed value of the expression
+  std::string myError; ///< error of processing, empty if there is no error
+
+ public:
+  /// Static. Returns EventID of the message.
+  MODELAPI_EXPORT static Events_ID& eventId()
+  {
+    static const char * MY_PARAMETER_EVALUATION_EVENT_ID("ParameterEvaluationRequest");
+    static Events_ID anId = Events_Loop::eventByName(MY_PARAMETER_EVALUATION_EVENT_ID);
+    return anId;
+  }
+
+  /// Useful method that creates and sends the event.
+  /// Returns the message, processed, with the resulting fields filled.
+  MODELAPI_EXPORT static std::shared_ptr<ModelAPI_ParameterEvalMessage>
+    send(FeaturePtr theParameter, const void* theSender)
+  {
+    std::shared_ptr<ModelAPI_ParameterEvalMessage> aMessage =
+      std::shared_ptr<ModelAPI_ParameterEvalMessage>(
+      new ModelAPI_ParameterEvalMessage(eventId(), theSender));
+    aMessage->setParameter(theParameter);
+    Events_Loop::loop()->send(aMessage);
+    return aMessage;
+  }
+
+  /// Creates an empty message
+  MODELAPI_EXPORT ModelAPI_ParameterEvalMessage(const Events_ID theID, const void* theSender = 0);
+  /// The virtual destructor
+  MODELAPI_EXPORT virtual ~ModelAPI_ParameterEvalMessage();
+
+  /// Returns a parameter stored in the message
+  MODELAPI_EXPORT FeaturePtr parameter() const;
+  /// Sets a parameter to the message
+  MODELAPI_EXPORT void setParameter(FeaturePtr theParam);
+  /// Sets the results of processing
+  MODELAPI_EXPORT void setResults(
+    const std::list<std::shared_ptr<ModelAPI_ResultParameter> >& theParamsList,
+    const double theResult, const std::string& theError);
+  /// Returns true if the expression is processed
+  MODELAPI_EXPORT bool isProcessed();
+  /// Returns the results of processing: list of parameters found in the expression
+  MODELAPI_EXPORT const std::list<std::shared_ptr<ModelAPI_ResultParameter> >& params() const;
+  /// Returns the expression result
+  MODELAPI_EXPORT const double& result() const;
+  /// Returns the interpreter error (empty if no error)
+  MODELAPI_EXPORT const std::string& error() const;
+};
+
+
+/// Message to ask compute the positions of parameters in the expression
+class ModelAPI_ComputePositionsMessage : public Events_Message
+{
+  std::string myExpression; ///< the expression string
+  std::string myParamName; ///< name of the parameter to be searched
+  std::list<std::pair<int, int> > myPositions; ///< computation result: start-end position indices
+
+public:
+  /// Static. Returns EventID of the message.
+  MODELAPI_EXPORT static Events_ID& eventId()
+  {
+    static const char * MY_COMPUTE_POSITIOND_EVENT_ID("ComputePositionsRequest");
+    static Events_ID anId = Events_Loop::eventByName(MY_COMPUTE_POSITIOND_EVENT_ID);
+    return anId;
+  }
+
+  /// Useful method that creates and sends the AttributeEvalMessage event
+  /// Returns the message, processed, with the resulting fields filled
+  MODELAPI_EXPORT static std::shared_ptr<ModelAPI_ComputePositionsMessage>
+    send(const std::string& theExpression, const std::string& theParameter, const void* theSender)
+  {
+    std::shared_ptr<ModelAPI_ComputePositionsMessage> aMessage =
+      std::shared_ptr<ModelAPI_ComputePositionsMessage>(
+      new ModelAPI_ComputePositionsMessage(eventId(), theSender));
+    aMessage->set(theExpression, theParameter);
+    Events_Loop::loop()->send(aMessage);
+    return aMessage;
+  }
+
+  /// Creates an empty message
+  MODELAPI_EXPORT ModelAPI_ComputePositionsMessage(
+    const Events_ID theID, const void* theSender = 0);
+  /// The virtual destructor
+  MODELAPI_EXPORT virtual ~ModelAPI_ComputePositionsMessage();
+
+  /// Returns an expression stored in the message
+  MODELAPI_EXPORT const std::string& expression() const;
+  /// Returns a parameter name stored in the message
+  MODELAPI_EXPORT const std::string& parameter() const;
+  /// Sets an expression and parameter needed for computation
+  MODELAPI_EXPORT void set(const std::string& theExpression, const std::string& theParameter);
+  /// Sets the results of processing
+  MODELAPI_EXPORT void setPositions(const std::list<std::pair<int, int> >& thePositions);
+  /// Returns the results of processing: position start and end indices
+  MODELAPI_EXPORT const std::list<std::pair<int, int> >& positions() const;
+};
+
 /// Message that the object is renamed
 class ModelAPI_ObjectRenamedMessage : public Events_Message
 {
@@ -298,7 +445,8 @@ class ModelAPI_ReplaceParameterMessage : public Events_Message
                                    const void* theSender);
 
   /// Creates an empty message
-  MODELAPI_EXPORT ModelAPI_ReplaceParameterMessage(const Events_ID theID, const void* theSender = 0);
+  MODELAPI_EXPORT
+    ModelAPI_ReplaceParameterMessage(const Events_ID theID, const void* theSender = 0);
   /// The virtual destructor
   MODELAPI_EXPORT virtual ~ModelAPI_ReplaceParameterMessage();
 
@@ -308,11 +456,13 @@ class ModelAPI_ReplaceParameterMessage : public Events_Message
   MODELAPI_EXPORT void setObject(ObjectPtr theObject);
 };
 
-
+/// Message that sends the sketch solver and sketcher GUI processes to show in the property panel
 class ModelAPI_SolverFailedMessage : public Events_Message
 {
 public:
+  /// Creates an message
   MODELAPI_EXPORT ModelAPI_SolverFailedMessage(const Events_ID theID, const void* theSender = 0);
+  /// Default destructor
   MODELAPI_EXPORT virtual ~ModelAPI_SolverFailedMessage();
 
   /// Sets list of conflicting constraints
@@ -330,4 +480,46 @@ private:
   int myDOF;
 };
 
+/// Message sent when feature or attribute has been moved.
+/// Stores the moving object/attribute, original and new positions of mouse.
+class ModelAPI_ObjectMovedMessage : public Events_Message
+{
+  ObjectPtr myMovedObject;
+  AttributePtr myMovedAttribute;
+
+  std::shared_ptr<GeomAPI_Pnt2d> myOriginalPosition;
+  std::shared_ptr<GeomAPI_Pnt2d> myCurrentPosition;
+
+public:
+  MODELAPI_EXPORT ModelAPI_ObjectMovedMessage(const void* theSender = 0);
+
+  /// Set object which is being moved (if the message already contains attribute it will be cleared)
+  MODELAPI_EXPORT void setMovedObject(const ObjectPtr& theMovedObject);
+  /// Set attribute which is being moved (if the message already contains object it will be cleared)
+  MODELAPI_EXPORT void setMovedAttribute(const AttributePtr& theMovedAttribute);
+
+  /// Return moved object
+  ObjectPtr movedObject() const
+  { return myMovedObject; }
+  /// Return moved attribute
+  AttributePtr movedAttribute() const
+  { return myMovedAttribute; }
+
+  /// Set original mouse position
+  MODELAPI_EXPORT void setOriginalPosition(double theX, double theY);
+  /// Set original mouse position
+  MODELAPI_EXPORT void setOriginalPosition(const std::shared_ptr<GeomAPI_Pnt2d>& thePoint);
+  /// Return original mouse position
+  const std::shared_ptr<GeomAPI_Pnt2d>& originalPosition() const
+  { return myOriginalPosition; }
+
+  /// Set current mouse position
+  MODELAPI_EXPORT void setCurrentPosition(double theX, double theY);
+  /// Set current mouse position
+  MODELAPI_EXPORT void setCurrentPosition(const std::shared_ptr<GeomAPI_Pnt2d>& thePoint);
+  /// Return current mouse position
+  const std::shared_ptr<GeomAPI_Pnt2d>& currentPosition() const
+  { return myCurrentPosition; }
+};
+
 #endif