Salome HOME
Managing of several groups with conflicting constraints on the same sketch plane
[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_MIDDLE_POINT,
25   CONSTRAINT_DISTANCE,         // base distance if we don't know the measured objects yet
26   CONSTRAINT_PT_PT_DISTANCE,
27   CONSTRAINT_PT_LINE_DISTANCE,
28   CONSTRAINT_RADIUS,
29   CONSTRAINT_ANGLE,
30   CONSTRAINT_FIXED,
31   CONSTRAINT_HORIZONTAL,
32   CONSTRAINT_VERTICAL,
33   CONSTRAINT_PARALLEL,
34   CONSTRAINT_PERPENDICULAR,
35   CONSTRAINT_SYMMETRIC,
36   CONSTRAINT_EQUAL,           // base equality if we don't know the measured objects yet
37   CONSTRAINT_EQUAL_LINES,
38   CONSTRAINT_EQUAL_LINE_ARC,
39   CONSTRAINT_EQUAL_RADIUS,
40   CONSTRAINT_TANGENT,         // base tangency if we don't know the measured objects yet
41   CONSTRAINT_TANGENT_ARC_LINE,
42   CONSTRAINT_TANGENT_CIRCLE_LINE,
43   CONSTRAINT_TANGENT_ARC_ARC,
44   CONSTRAINT_COLLINEAR,
45   CONSTRAINT_MULTI_TRANSLATION,
46   CONSTRAINT_MULTI_ROTATION
47 };
48
49 /**
50  *  Wrapper providing operations with constraints regardless the solver.
51  */
52 class SketchSolver_IConstraintWrapper
53 {
54 public:
55   virtual ~SketchSolver_IConstraintWrapper() {}
56
57   /// \brief Return base feature
58   const ConstraintPtr& baseConstraint() const
59   { return myBaseConstraint; }
60
61   /// \brief Return ID of current entity
62   virtual ConstraintID id() const = 0;
63
64   /// \brief Change group for the constraint
65   virtual void setGroup(const GroupID& theGroup) = 0;
66   /// \brief Return identifier of the group the constraint belongs to
67   virtual GroupID group() const = 0;
68
69   /// \brief Return type of current entity
70   virtual SketchSolver_ConstraintType type() const = 0;
71
72   /// \brief Assign list of constrained objects
73   void setEntities(const std::list<EntityWrapperPtr>& theEntities)
74   { myConstrained = theEntities; }
75   /// \brief Return list of constrained objects
76   const std::list<EntityWrapperPtr>& entities() const
77   { return myConstrained; }
78
79   /// \brief Assign numeric parameter of constraint
80   virtual void setValue(const double& theValue)
81   { myValue = theValue; }
82   /// \brief Return numeric parameter of constraint
83   const double& value() const
84   { return myValue; }
85
86   /// \brief Store a boolean flag for full value using
87   void setIsFullValue(const bool& theFullValue)
88   { myIsFullValue = theFullValue; }
89   /// \brief Return a flag of a full value using
90   const bool& isFullValue() const
91   { return myIsFullValue; }
92
93   /// \brief Verify the feature is used in the constraint
94   virtual bool isUsed(FeaturePtr theFeature) const = 0;
95   /// \brief Verify the attribute is used in the constraint
96   virtual bool isUsed(AttributePtr theAttribute) const = 0;
97
98   /// \brief Compare current constraint with other
99   virtual bool isEqual(const std::shared_ptr<SketchSolver_IConstraintWrapper>& theOther) = 0;
100
101   /// \brief Update values of parameters of this constraint by the parameters of given one
102   /// \return \c true if some parameters change their values
103   virtual bool update(const std::shared_ptr<SketchSolver_IConstraintWrapper>& theOther) = 0;
104
105 protected:
106   ConstraintPtr               myBaseConstraint;
107   std::list<EntityWrapperPtr> myConstrained;
108   double                      myValue;
109   bool                        myIsFullValue;
110 };
111
112 typedef std::shared_ptr<SketchSolver_IConstraintWrapper> ConstraintWrapperPtr;
113
114 #endif