Salome HOME
SketchSolver Refactoring: Eliminate SolveSpace as a sketch solver.
[modules/shaper.git] / src / SketchSolver / SketchSolver_Constraint.h
index e194c2571cf48619bd2530d00415884b3a50d5d3..5c06e0aa5434f268cfd35570011e0375cb26e696 100644 (file)
@@ -8,46 +8,96 @@
 #define SketchSolver_Constraint_H_
 
 #include "SketchSolver.h"
+#include <SketchSolver_Storage.h>
+#include <PlaneGCSSolver_Update.h>
 
 #include <SketchPlugin_Constraint.h>
 
+#include <ModelAPI_AttributeDouble.h>
+#include <ModelAPI_AttributeRefAttr.h>
+
 #include <string>
 #include <vector>
 
 /** \class   SketchSolver_Constraint
- *  \ingroup DataModel
- *  \brief   Obtain information about SketchPlugin's constraint
+ *  \ingroup Plugins
+ *  \brief   Converts SketchPlugin constraint to the constraint applicable for solver
  */
 class SketchSolver_Constraint
 {
-public:
+protected:
   /// Default constructor
-  SketchSolver_Constraint();
-  /// Creates constraint to manage the given constraint from plugin
-  SketchSolver_Constraint(std::shared_ptr<SketchPlugin_Constraint> theConstraint);
-
-  /** \brief Compute constraint type according to SolveSpace identifiers
-   *         and verify that constraint parameters are correct
-   *  \param[in]  theConstraint constraint which type should be determined
-   *  \return identifier of constraint type or SLVS_C_UNKNOWN if the type is wrong
-   */
-  const int& getType(std::shared_ptr<SketchPlugin_Constraint> theConstraint);
-  /// \brief Returns the type of myConstraint member
-  inline const int& getType() const
-  {
-    return myType;
-  }
-
-  /// \brief Returns list of attributes names in the correct order required by SolveSpace
-  inline const std::vector<std::string>& getAttributes() const
-  {
-    return myAttributesList;
-  }
-
- private:
-  std::shared_ptr<SketchPlugin_Constraint> myConstraint;
-  int myType;
-  std::vector<std::string> myAttributesList;
+  SketchSolver_Constraint()
+    : myType(CONSTRAINT_UNKNOWN)
+  {}
+
+public:
+  /// Constructor based on SketchPlugin constraint
+  SketchSolver_Constraint(ConstraintPtr theConstraint);
+
+  virtual ~SketchSolver_Constraint() {}
+
+  /// \brief Initializes parameters and start constraint creation
+  /// \param theStorage       [in]  storage where to place new constraint
+  /// \param theEventsBlocked [in]  all events from this constraint should be blocked
+  void process(StoragePtr theStorage, bool theEvensBlocked);
+
+  /// \brief Notify this object about the feature is changed somewhere
+  virtual void notify(const FeaturePtr& theFeature, PlaneGCSSolver_Update* theUpdater) {}
+
+  /// \brief Update constraint
+  virtual void update();
+
+  /// \brief Tries to remove constraint
+  /// \return \c false, if current constraint contains another SketchPlugin constraints
+  /// (like for multiple coincidence)
+  virtual bool remove();
+
+  /// \brief Block or unblock events from this constraint
+  virtual void blockEvents(bool isBlocked);
+
+  /// \brief Obtain a type of SketchPlugin constraint
+  static SketchSolver_ConstraintType TYPE(ConstraintPtr theConstraint);
+
+  /// \brief Returns the type of constraint
+  virtual SketchSolver_ConstraintType getType() const
+  { return myType; }
+
+  /// \brief Shows error message
+  const std::string& error() const
+  { return myErrorMsg; }
+
+protected:
+  /// \brief Converts SketchPlugin constraint to a list of solver's constraints
+  virtual void process();
+
+  /// \brief Generate list of attributes of constraint in order useful for constraints
+  /// \param[out] theValue      numerical characteristic of constraint (e.g. distance)
+  /// \param[out] theAttributes list of attributes to be filled
+  virtual void getAttributes(EntityWrapperPtr&              theValue,
+                             std::vector<EntityWrapperPtr>& theAttributes);
+
+  /// \brief This method is used in derived objects to check consistency of constraint.
+  ///        E.g. the distance between line and point may be signed.
+  virtual void adjustConstraint()
+  {}
+
+  /// \brief Removes last error
+  void cleanErrorMsg()
+  { myErrorMsg.clear(); }
+
+protected:
+  ConstraintPtr myBaseConstraint; ///< base SketchPlugin constraint
+  ConstraintWrapperPtr mySolverConstraint; ///< wrapper for PlaneGCS constraint
+
+  /// storage, which contains all information about entities and constraints
+  StoragePtr    myStorage;
+  SketchSolver_ConstraintType myType; ///< type of constraint
+  std::list<EntityWrapperPtr> myAttributes; ///< attributes of constraint
+
+  std::string   myErrorMsg; ///< error message
 };
 
+typedef std::shared_ptr<SketchSolver_Constraint> SolverConstraintPtr;
+
 #endif