Salome HOME
Fix the problem moving arc with radius constraint (issue #1375)
[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 Returns list of attributes of constraint
61   const std::list<EntityWrapperPtr>& attributes() const
62   { return myAttributes; }
63
64   /// \brief Verify the feature or any its attribute is used by constraint
65   virtual bool isUsed(FeaturePtr theFeature) const;
66   /// \brief Verify the attribute is used by constraint
67   virtual bool isUsed(AttributePtr theAttribute) const;
68
69   /// \brief Notify constraint, that coincidence appears or removed
70   virtual void notifyCoincidenceChanged(EntityWrapperPtr theCoincAttr1, EntityWrapperPtr theCoincAttr2)
71   { /* implement in derived class */ }
72
73   /// \brief Shows error message
74   const std::string& error() const
75   { return myErrorMsg; }
76
77 protected:
78   /// \brief Converts SketchPlugin constraint to a list of solver's constraints
79   virtual void process();
80
81   /// \brief Generate list of attributes of constraint in order useful for constraints
82   /// \param[out] theValue      numerical characteristic of constraint (e.g. distance)
83   /// \param[out] theAttributes list of attributes to be filled
84   virtual void getAttributes(double& theValue, std::vector<EntityWrapperPtr>& theAttributes);
85
86   /// \brief This method is used in derived objects to check consistency of constraint.
87   ///        E.g. the distance between line and point may be signed.
88   virtual void adjustConstraint()
89   {}
90
91   /// \brief Removes last error
92   void cleanErrorMsg()
93   { myErrorMsg.clear(); }
94
95 protected:
96   GroupID       myGroupID;  ///< identifier of the group, the constraint belongs to
97   EntityID      mySketchID; ///< identifier of the sketch, the constraint belongs to
98   ConstraintPtr myBaseConstraint; ///< base SketchPlugin constraint
99   StoragePtr    myStorage; ///< storage, which contains all information about entities and constraints
100   SketchSolver_ConstraintType myType; ///< type of constraint
101   std::list<EntityWrapperPtr> myAttributes; ///< attributes of constraint
102
103   std::string   myErrorMsg; ///< error message
104 };
105
106 typedef std::shared_ptr<SketchSolver_Constraint> SolverConstraintPtr;
107
108 #endif