Salome HOME
Make the expressions in double attributes and points updated after the parameter...
[modules/shaper.git] / src / SketchSolver / SketchSolver_ConstraintManager.h
index 376fd2029d8cce46a72d9dba936cfb378ec944ae..a2d7ffaffe580a08ca944a71938b56dfae64092d 100644 (file)
+// Copyright (C) 2014-20xx CEA/DEN, EDF R&D
+
 // File:    SketchSolver_ConstraintManager.h
 // Created: 08 May 2014
 // Author:  Artem ZHIDKOV
 
-#ifndef SketchSolver_ConstraintManager_Headerfile
-#define SketchSolver_ConstraintManager_Headerfile
+#ifndef SketchSolver_ConstraintManager_H_
+#define SketchSolver_ConstraintManager_H_
 
 #include "SketchSolver.h"
+#include <SketchSolver_Solver.h>
+#include <SketchSolver_Group.h>
+
+#include <Events_Listener.h>
+#include <SketchPlugin_Constraint.h>
+
+#include <string.h>
+#include <slvs.h>
+
+#include <list>
+#include <map>
+#include <vector>
+#include <set>
 
 /** \class   SketchSolver_ConstraintManager
- *  \ingroup DataModel
- *  \brief   Transforms the Constraint feature into the format understandable by SolveSpace library.
+ *  \ingroup Plugins
+ *  \brief   Listens the changes of SketchPlugin features and transforms the Constraint
+ *           feature into the format understandable by SolveSpace library.
  *
- *  Constraints created for SolveSpace library will be divided into the groups.
+ *  Constraints created for SolveSpace library are divided into the groups.
  *  The division order based on connectedness of the features by the constraints.
  *  The groups may be fused or separated according to the new constraints.
+ *
+ *  \remark This is a singleton.
  */
-class SketchSolver_ConstraintManager
+class SketchSolver_ConstraintManager : public Events_Listener
 {
-private:
-  class SketchSolver_ConstraintGroup;
-};
+ public:
+  /** \brief Main method to create constraint manager
+   *  \return pointer to the singleton
+   */
+  static SketchSolver_ConstraintManager* Instance();
 
-class SketchSolver_ConstraintManager::SketchSolver_ConstraintGroup
-{
+  /** \brief Implementation of Event Listener method
+   *  \param[in] theMessage the data of the event
+   */
+  virtual void processEvent(const std::shared_ptr<Events_Message>& theMessage);
+
+ protected:
+  SketchSolver_ConstraintManager();
+  ~SketchSolver_ConstraintManager();
+
+  /** \brief Adds or updates a constraint or an entity in the suitable group
+   *  \param[in] theFeature sketch feature to be changed
+   *  \return \c true if the feature changed successfully
+   */
+  bool changeConstraintOrEntity(std::shared_ptr<SketchPlugin_Feature> theFeature);
+
+  /** \brief Removes a constraint from the manager
+   *  \param[in] theConstraint constraint to be removed
+   *  \return \c true if the constraint removed successfully
+   */
+  bool removeConstraint(std::shared_ptr<SketchPlugin_Constraint> theConstraint);
+
+  /** \brief Adds or updates a workplane in the manager
+   *  \param[in] theSketch the feature to create or update workplane
+   *  \return \c true if the workplane changed successfully
+   *  \remark Type of theSketch is not verified inside
+   */
+  bool changeWorkplane(CompositeFeaturePtr theSketch);
+
+  /** \brief Removes a workplane from the manager.
+   *         All groups based on such workplane will be removed too.
+   *  \param[in] theSketch the feature to be removed
+   *  \return \c true if the workplane removed successfully
+   */
+  bool removeWorkplane(std::shared_ptr<SketchPlugin_Sketch> theSketch);
+
+  /** \brief Updates entity which is moved in GUI
+   *  \param[in] theFeature entity to be updated
+   */
+  void moveEntity(std::shared_ptr<SketchPlugin_Feature> theFeature);
+
+  /** \brief Goes through the list of groups and solve the constraints
+   *  \param theForceUpdate flushes the update event in any case: something changed or not
+   */
+  void resolveConstraints(const bool theForceUpdate);
+
+ private:
+  /** \brief Searches list of groups which interact with specified feature
+   *  \param[in]  theFeature  object to be found
+   *  \param[out] theGroups   list of group indexes interacted with the feature
+   */
+  void findGroups(std::shared_ptr<SketchPlugin_Feature> theFeature,
+                  std::set<Slvs_hGroup>& theGroupIDs) const;
+
+  /** \brief Searches in the list of groups the workplane which constains specified feature
+   *  \param[in] theFeature object to be found
+   *  \return workplane containing the feature
+   */
+  std::shared_ptr<ModelAPI_CompositeFeature> findWorkplane(
+      std::shared_ptr<SketchPlugin_Feature> theFeature) const;
+
+ private:
+  static SketchSolver_ConstraintManager* _self;  ///< Self pointer to implement singleton functionality
+  std::vector<SketchSolver_Group*> myGroups;  ///< Groups of constraints
+  /// true if computation is performed and all "updates" are generated by this algo
+  /// and needs no recomputation
+  bool myIsComputed;
 };
 
 #endif