1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D
3 // File: SketchSolver_Constraint.h
4 // Created: 27 May 2014
5 // Author: Artem ZHIDKOV
7 #ifndef SketchSolver_Constraint_H_
8 #define SketchSolver_Constraint_H_
10 #include "SketchSolver.h"
11 #include <SketchSolver_Storage.h>
13 #include <SketchPlugin_Constraint.h>
15 #include <ModelAPI_AttributeDouble.h>
16 #include <ModelAPI_AttributeRefAttr.h>
21 /** \class SketchSolver_Constraint
23 * \brief Converts SketchPlugin constraint to the constraint applicable for solver
25 class SketchSolver_Constraint
28 /// Default constructor
29 SketchSolver_Constraint()
30 : myGroupID(GID_UNKNOWN),
31 myType(CONSTRAINT_UNKNOWN)
35 /// Constructor based on SketchPlugin constraint
36 SKETCHSOLVER_EXPORT SketchSolver_Constraint(ConstraintPtr theConstraint);
38 virtual ~SketchSolver_Constraint() {}
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);
46 /// \brief Update constraint
47 SKETCHSOLVER_EXPORT virtual void update();
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();
53 /// \brief Obtain a type of SketchPlugin constraint
54 SKETCHSOLVER_EXPORT static SketchSolver_ConstraintType TYPE(ConstraintPtr theConstraint);
56 /// \brief Returns the type of constraint
57 //// virtual SketchSolver_ConstraintType getType() const = 0;
58 virtual SketchSolver_ConstraintType getType() const
61 /// \brief The constraint is made temporary
62 void makeTemporary() const;
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;
69 //// /// \brief Checks the constraint is used by current object
70 //// SKETCHSOLVER_EXPORT virtual bool hasConstraint(ConstraintPtr theConstraint) const;
72 //// /// \brief Return list of SketchPlugin constraints attached to this object
73 //// virtual const std::list<ConstraintPtr>& constraints() const
74 //// { return myConstraints; }
76 /// \brief Shows error message
77 const std::string& error() const
78 { return myErrorMsg; }
81 /// \brief Converts SketchPlugin constraint to a list of solver's constraints
82 virtual void process();
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);
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);
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()
99 /// \brief Removes last error
101 { myErrorMsg.clear(); }
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
110 std::string myErrorMsg; ///< error message
113 typedef std::shared_ptr<SketchSolver_Constraint> SolverConstraintPtr;
117 /////** \class SketchSolver_ConstraintParallel
118 //// * \ingroup Plugins
119 //// * \brief Convert Parallel constraint to SolveSpace structure
121 ////class SketchSolver_ConstraintParallel : public SketchSolver_Constraint
124 //// /// Constructor based on SketchPlugin constraint
125 //// SketchSolver_ConstraintParallel(ConstraintPtr theConstraint) :
126 //// SketchSolver_Constraint(theConstraint)
129 //// virtual int getType() const
130 //// { return SLVS_C_PARALLEL; }
134 /////** \class SketchSolver_ConstraintPerpendicular
135 //// * \ingroup Plugins
136 //// * \brief Convert Perpendicular constraint to SolveSpace structure
138 ////class SketchSolver_ConstraintPerpendicular : public SketchSolver_Constraint
141 //// /// Constructor based on SketchPlugin constraint
142 //// SketchSolver_ConstraintPerpendicular(ConstraintPtr theConstraint) :
143 //// SketchSolver_Constraint(theConstraint)
146 //// virtual int getType() const
147 //// { return SLVS_C_PERPENDICULAR; }
151 /////** \class SketchSolver_ConstraintHorizontal
152 //// * \ingroup Plugins
153 //// * \brief Convert Horizontal constraint to SolveSpace structure
155 ////class SketchSolver_ConstraintHorizontal : public SketchSolver_Constraint
158 //// /// Constructor based on SketchPlugin constraint
159 //// SketchSolver_ConstraintHorizontal(ConstraintPtr theConstraint) :
160 //// SketchSolver_Constraint(theConstraint)
163 //// virtual int getType() const
164 //// { return SLVS_C_HORIZONTAL; }
168 /////** \class SketchSolver_ConstraintVertical
169 //// * \ingroup Plugins
170 //// * \brief Convert Vertical constraint to SolveSpace structure
172 ////class SketchSolver_ConstraintVertical : public SketchSolver_Constraint
175 //// /// Constructor based on SketchPlugin constraint
176 //// SketchSolver_ConstraintVertical(ConstraintPtr theConstraint) :
177 //// SketchSolver_Constraint(theConstraint)
180 //// virtual int getType() const
181 //// { return SLVS_C_VERTICAL; }
185 /////** \class SketchSolver_ConstraintRadius
186 //// * \ingroup Plugins
187 //// * \brief Convert Radius constraint to SolveSpace structure
189 ////class SketchSolver_ConstraintRadius : public SketchSolver_Constraint
192 //// /// Constructor based on SketchPlugin constraint
193 //// SketchSolver_ConstraintRadius(ConstraintPtr theConstraint) :
194 //// SketchSolver_Constraint(theConstraint)
197 //// virtual int getType() const
198 //// { return SLVS_C_DIAMETER; }
200 //// virtual void adjustConstraint()
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);