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 = 0;
58   virtual SketchSolver_ConstraintType getType() const
59   { return myType; }
60
61   /// \brief The constraint is made temporary
62   void makeTemporary() const;
63
64   /// \brief Verify the feature or any its attribute is used by constraint
65   bool isUsed(FeaturePtr theFeature) const;
66   /// \brief Verify the attribute is used by constraint
67   bool isUsed(AttributePtr theAttribute) const;
68
69 ////  /// \brief Checks the constraint is used by current object
70 ////  SKETCHSOLVER_EXPORT virtual bool hasConstraint(ConstraintPtr theConstraint) const;
71 ////
72 ////  /// \brief Return list of SketchPlugin constraints attached to this object
73 ////  virtual const std::list<ConstraintPtr>& constraints() const
74 ////  { return myConstraints; }
75
76   /// \brief Shows error message
77   const std::string& error() const
78   { return myErrorMsg; }
79
80 protected:
81   /// \brief Converts SketchPlugin constraint to a list of solver's constraints
82   virtual void process();
83
84   /// \brief Generate list of attributes of constraint in order useful for constraints
85   /// \param[out] theValue      numerical characteristic of constraint (e.g. distance)
86   /// \param[out] theAttributes list of attributes to be filled
87   virtual void getAttributes(double& theValue, std::vector<EntityWrapperPtr>& theAttributes);
88
89 ////  /// \brief Verify the attributes of constraint are changed (and constraint need to rebuild)
90 ////  /// \param[in] theConstraint constraint, which attributes should be checked (if NULL, the myBaseConstraint is used)
91 ////  /// \return \c true if some attributes are changed
92 ////  virtual bool checkAttributesChanged(ConstraintPtr theConstraint);
93
94   /// \brief This method is used in derived objects to check consistency of constraint.
95   ///        E.g. the distance between line and point may be signed.
96   virtual void adjustConstraint()
97   {}
98
99   /// \brief Removes last error
100   void cleanErrorMsg()
101   { myErrorMsg.clear(); }
102
103 protected:
104   GroupID       myGroupID;  ///< identifier of the group, the constraint belongs to
105   EntityID      mySketchID; ///< identifier of the sketch, the constraint belongs to
106   ConstraintPtr myBaseConstraint; ///< base SketchPlugin constraint
107   StoragePtr    myStorage; ///< storage, which contains all information about entities and constraints
108   SketchSolver_ConstraintType myType; ///< type of constraint
109
110   std::string   myErrorMsg; ///< error message
111 };
112
113 typedef std::shared_ptr<SketchSolver_Constraint> SolverConstraintPtr;
114
115
116
117 /////** \class   SketchSolver_ConstraintParallel
118 //// *  \ingroup Plugins
119 //// *  \brief   Convert Parallel constraint to SolveSpace structure
120 //// */
121 ////class SketchSolver_ConstraintParallel : public SketchSolver_Constraint
122 ////{
123 ////public:
124 ////  /// Constructor based on SketchPlugin constraint
125 ////  SketchSolver_ConstraintParallel(ConstraintPtr theConstraint) :
126 ////      SketchSolver_Constraint(theConstraint)
127 ////  {}
128 ////
129 ////  virtual int getType() const
130 ////  { return SLVS_C_PARALLEL; }
131 ////};
132 ////
133 ////
134 /////** \class   SketchSolver_ConstraintPerpendicular
135 //// *  \ingroup Plugins
136 //// *  \brief   Convert Perpendicular constraint to SolveSpace structure
137 //// */
138 ////class SketchSolver_ConstraintPerpendicular : public SketchSolver_Constraint
139 ////{
140 ////public:
141 ////  /// Constructor based on SketchPlugin constraint
142 ////  SketchSolver_ConstraintPerpendicular(ConstraintPtr theConstraint) :
143 ////      SketchSolver_Constraint(theConstraint)
144 ////  {}
145 ////
146 ////  virtual int getType() const
147 ////  { return SLVS_C_PERPENDICULAR; }
148 ////};
149 ////
150 ////
151 /////** \class   SketchSolver_ConstraintHorizontal
152 //// *  \ingroup Plugins
153 //// *  \brief   Convert Horizontal constraint to SolveSpace structure
154 //// */
155 ////class SketchSolver_ConstraintHorizontal : public SketchSolver_Constraint
156 ////{
157 ////public:
158 ////  /// Constructor based on SketchPlugin constraint
159 ////  SketchSolver_ConstraintHorizontal(ConstraintPtr theConstraint) :
160 ////      SketchSolver_Constraint(theConstraint)
161 ////  {}
162 ////
163 ////  virtual int getType() const
164 ////  { return SLVS_C_HORIZONTAL; }
165 ////};
166 ////
167 ////
168 /////** \class   SketchSolver_ConstraintVertical
169 //// *  \ingroup Plugins
170 //// *  \brief   Convert Vertical constraint to SolveSpace structure
171 //// */
172 ////class SketchSolver_ConstraintVertical : public SketchSolver_Constraint
173 ////{
174 ////public:
175 ////  /// Constructor based on SketchPlugin constraint
176 ////  SketchSolver_ConstraintVertical(ConstraintPtr theConstraint) :
177 ////      SketchSolver_Constraint(theConstraint)
178 ////  {}
179 ////
180 ////  virtual int getType() const
181 ////  { return SLVS_C_VERTICAL; }
182 ////};
183 ////
184 ////
185 /////** \class   SketchSolver_ConstraintRadius
186 //// *  \ingroup Plugins
187 //// *  \brief   Convert Radius constraint to SolveSpace structure
188 //// */
189 ////class SketchSolver_ConstraintRadius : public SketchSolver_Constraint
190 ////{
191 ////public:
192 ////  /// Constructor based on SketchPlugin constraint
193 ////  SketchSolver_ConstraintRadius(ConstraintPtr theConstraint) :
194 ////      SketchSolver_Constraint(theConstraint)
195 ////  {}
196 ////
197 ////  virtual int getType() const
198 ////  { return SLVS_C_DIAMETER; }
199 ////
200 ////  virtual void adjustConstraint()
201 ////  {
202 ////    AttributeDoublePtr aValueAttr = std::dynamic_pointer_cast<ModelAPI_AttributeDouble>(
203 ////        myBaseConstraint->attribute(SketchPlugin_Constraint::VALUE()));
204 ////    Slvs_Constraint aConstraint = myStorage->getConstraint(mySlvsConstraints.front());
205 ////    aConstraint.valA = 2.0 * aValueAttr->value();
206 ////    myStorage->updateConstraint(aConstraint);
207 ////  }
208 ////};
209
210 #endif