Salome HOME
Implement the Collinear constraint
[modules/shaper.git] / src / SketchSolver / SketchSolver_IConstraintWrapper.h
1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D
2
3 // File:    SketchSolver_IConstraintWrapper.h
4 // Created: 30 Nov 2015
5 // Author:  Artem ZHIDKOV
6
7 #ifndef SketchSolver_IConstraintWrapper_H_
8 #define SketchSolver_IConstraintWrapper_H_
9
10 #include <SketchSolver_IEntityWrapper.h>
11
12 #include <SketchPlugin_Constraint.h>
13
14 #include <list>
15 #include <memory>
16
17 /// Types of constraints
18 enum SketchSolver_ConstraintType {
19   CONSTRAINT_UNKNOWN = 0,
20   CONSTRAINT_COINCIDENCE,      // base coincidence if we don't know exact type yet
21   CONSTRAINT_PT_PT_COINCIDENT,
22   CONSTRAINT_PT_ON_LINE,
23   CONSTRAINT_PT_ON_CIRCLE,
24   CONSTRAINT_DISTANCE,         // base distance if we don't know the measured objects yet
25   CONSTRAINT_PT_PT_DISTANCE,
26   CONSTRAINT_PT_LINE_DISTANCE,
27   CONSTRAINT_RADIUS,
28   CONSTRAINT_ANGLE,
29   CONSTRAINT_FIXED,
30   CONSTRAINT_HORIZONTAL,
31   CONSTRAINT_VERTICAL,
32   CONSTRAINT_PARALLEL,
33   CONSTRAINT_PERPENDICULAR,
34   CONSTRAINT_SYMMETRIC,
35   CONSTRAINT_EQUAL,           // base equality if we don't know the measured objects yet
36   CONSTRAINT_EQUAL_LINES,
37   CONSTRAINT_EQUAL_LINE_ARC,
38   CONSTRAINT_EQUAL_RADIUS,
39   CONSTRAINT_TANGENT,         // base tangency if we don't know the measured objects yet
40   CONSTRAINT_TANGENT_ARC_LINE,
41   CONSTRAINT_TANGENT_CIRCLE_LINE,
42   CONSTRAINT_TANGENT_ARC_ARC,
43   CONSTRAINT_COLLINEAR,
44   CONSTRAINT_MULTI_TRANSLATION,
45   CONSTRAINT_MULTI_ROTATION
46 };
47
48 /**
49  *  Wrapper providing operations with constraints regardless the solver.
50  */
51 class SketchSolver_IConstraintWrapper
52 {
53 public:
54   virtual ~SketchSolver_IConstraintWrapper() {}
55
56   /// \brief Return base feature
57   const ConstraintPtr& baseConstraint() const
58   { return myBaseConstraint; }
59
60   /// \brief Return ID of current entity
61   virtual ConstraintID id() const = 0;
62
63   /// \brief Change group for the constraint
64   virtual void setGroup(const GroupID& theGroup) = 0;
65   /// \brief Return identifier of the group the constraint belongs to
66   virtual GroupID group() const = 0;
67
68   /// \brief Return type of current entity
69   virtual SketchSolver_ConstraintType type() const = 0;
70
71   /// \brief Assign list of constrained objects
72   void setEntities(const std::list<EntityWrapperPtr>& theEntities)
73   { myConstrained = theEntities; }
74   /// \brief Return list of constrained objects
75   const std::list<EntityWrapperPtr>& entities() const
76   { return myConstrained; }
77
78   /// \brief Assign numeric parameter of constraint
79   virtual void setValue(const double& theValue)
80   { myValue = theValue; }
81   /// \brief Return numeric parameter of constraint
82   const double& value() const
83   { return myValue; }
84
85   /// \brief Store a boolean flag for full value using
86   void setIsFullValue(const bool& theFullValue)
87   { myIsFullValue = theFullValue; }
88   /// \brief Return a flag of a full value using
89   const bool& isFullValue() const
90   { return myIsFullValue; }
91
92   /// \brief Verify the feature is used in the constraint
93   virtual bool isUsed(FeaturePtr theFeature) const = 0;
94   /// \brief Verify the attribute is used in the constraint
95   virtual bool isUsed(AttributePtr theAttribute) const = 0;
96
97   /// \brief Compare current constraint with other
98   virtual bool isEqual(const std::shared_ptr<SketchSolver_IConstraintWrapper>& theOther) = 0;
99
100   /// \brief Update values of parameters of this constraint by the parameters of given one
101   /// \return \c true if some parameters change their values
102   virtual bool update(const std::shared_ptr<SketchSolver_IConstraintWrapper>& theOther) = 0;
103
104 protected:
105   ConstraintPtr               myBaseConstraint;
106   std::list<EntityWrapperPtr> myConstrained;
107   double                      myValue;
108   bool                        myIsFullValue;
109 };
110
111 typedef std::shared_ptr<SketchSolver_IConstraintWrapper> ConstraintWrapperPtr;
112
113 #endif