Salome HOME
First phase of SketchSolver refactoring
[modules/shaper.git] / src / SketchSolver / SketchSolver_Constraint.h
1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D
2
3 // File:    SketchSolver_Constraint.h
4 // Created: 27 May 2014
5 // Author:  Artem ZHIDKOV
6
7 #ifndef SketchSolver_Constraint_H_
8 #define SketchSolver_Constraint_H_
9
10 #include "SketchSolver.h"
11 #include <SketchSolver_Storage.h>
12
13 #include <SketchPlugin_Constraint.h>
14
15 #include <ModelAPI_AttributeDouble.h>
16 #include <ModelAPI_AttributeRefAttr.h>
17
18 #include <string>
19 #include <vector>
20
21 /** \class   SketchSolver_Constraint
22  *  \ingroup Plugins
23  *  \brief   Converts SketchPlugin constraint to the constraint applicable for solver
24  */
25 class SketchSolver_Constraint
26 {
27 protected:
28   /// Default constructor
29   SketchSolver_Constraint()
30     : myGroupID(GID_UNKNOWN),
31       myType(CONSTRAINT_UNKNOWN)
32   {}
33
34 public:
35   /// Constructor based on SketchPlugin constraint
36   SKETCHSOLVER_EXPORT SketchSolver_Constraint(ConstraintPtr theConstraint);
37
38   virtual ~SketchSolver_Constraint() {}
39
40   /// \brief Initializes parameters and start constraint creation
41   /// \param theStorage  [in]  storage where to place new constraint
42   /// \param theGroupID  [in]  group for constraint
43   /// \param theSketchID [in] sketch for constraint
44   void process(StoragePtr theStorage, const GroupID& theGroupID, const EntityID& theSketchID);
45
46   /// \brief Update constraint
47   SKETCHSOLVER_EXPORT virtual void update();
48
49   /// \brief Tries to remove constraint
50   /// \return \c false, if current constraint contains another SketchPlugin constraints (like for multiple coincidence)
51   SKETCHSOLVER_EXPORT virtual bool remove();
52
53   /// \brief Obtain a type of SketchPlugin constraint
54   SKETCHSOLVER_EXPORT static SketchSolver_ConstraintType TYPE(ConstraintPtr theConstraint);
55
56   /// \brief Returns the type of constraint
57   virtual SketchSolver_ConstraintType getType() const
58   { return myType; }
59
60   /// \brief The constraint is made temporary
61   void makeTemporary() const;
62
63   /// \brief Verify the feature or any its attribute is used by constraint
64   bool isUsed(FeaturePtr theFeature) const;
65   /// \brief Verify the attribute is used by constraint
66   bool isUsed(AttributePtr theAttribute) const;
67
68   /// \brief Shows error message
69   const std::string& error() const
70   { return myErrorMsg; }
71
72 protected:
73   /// \brief Converts SketchPlugin constraint to a list of solver's constraints
74   virtual void process();
75
76   /// \brief Generate list of attributes of constraint in order useful for constraints
77   /// \param[out] theValue      numerical characteristic of constraint (e.g. distance)
78   /// \param[out] theAttributes list of attributes to be filled
79   virtual void getAttributes(double& theValue, std::vector<EntityWrapperPtr>& theAttributes);
80
81   /// \brief This method is used in derived objects to check consistency of constraint.
82   ///        E.g. the distance between line and point may be signed.
83   virtual void adjustConstraint()
84   {}
85
86   /// \brief Removes last error
87   void cleanErrorMsg()
88   { myErrorMsg.clear(); }
89
90 protected:
91   GroupID       myGroupID;  ///< identifier of the group, the constraint belongs to
92   EntityID      mySketchID; ///< identifier of the sketch, the constraint belongs to
93   ConstraintPtr myBaseConstraint; ///< base SketchPlugin constraint
94   StoragePtr    myStorage; ///< storage, which contains all information about entities and constraints
95   SketchSolver_ConstraintType myType; ///< type of constraint
96
97   std::string   myErrorMsg; ///< error message
98 };
99
100 typedef std::shared_ptr<SketchSolver_Constraint> SolverConstraintPtr;
101
102 #endif