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
51 /// (like for multiple coincidence)
52 SKETCHSOLVER_EXPORT virtual bool remove();
54 /// \brief Obtain a type of SketchPlugin constraint
55 SKETCHSOLVER_EXPORT static SketchSolver_ConstraintType TYPE(ConstraintPtr theConstraint);
57 /// \brief Returns the type of constraint
58 virtual SketchSolver_ConstraintType getType() const
61 /// \brief Returns list of attributes of constraint
62 const std::list<EntityWrapperPtr>& attributes() const
63 { return myAttributes; }
65 /// \brief Verify the feature or any its attribute is used by constraint
66 virtual bool isUsed(FeaturePtr theFeature) const;
67 /// \brief Verify the attribute is used by constraint
68 virtual bool isUsed(AttributePtr theAttribute) const;
70 /// \brief Notify constraint, that coincidence appears or removed
71 virtual void notifyCoincidenceChanged(EntityWrapperPtr theCoincAttr1,
72 EntityWrapperPtr theCoincAttr2) { /* implement in derived class */ }
74 /// \brief Shows error message
75 const std::string& error() const
76 { return myErrorMsg; }
79 /// \brief Converts SketchPlugin constraint to a list of solver's constraints
80 virtual void process();
82 /// \brief Generate list of attributes of constraint in order useful for constraints
83 /// \param[out] theValue numerical characteristic of constraint (e.g. distance)
84 /// \param[out] theAttributes list of attributes to be filled
85 virtual void getAttributes(double& theValue, std::vector<EntityWrapperPtr>& theAttributes);
87 /// \brief This method is used in derived objects to check consistency of constraint.
88 /// E.g. the distance between line and point may be signed.
89 virtual void adjustConstraint()
92 /// \brief Removes last error
94 { myErrorMsg.clear(); }
97 GroupID myGroupID; ///< identifier of the group, the constraint belongs to
98 EntityID mySketchID; ///< identifier of the sketch, the constraint belongs to
99 ConstraintPtr myBaseConstraint; ///< base SketchPlugin constraint
101 /// storage, which contains all information about entities and constraints
102 StoragePtr myStorage;
103 SketchSolver_ConstraintType myType; ///< type of constraint
104 std::list<EntityWrapperPtr> myAttributes; ///< attributes of constraint
106 std::string myErrorMsg; ///< error message
109 typedef std::shared_ptr<SketchSolver_Constraint> SolverConstraintPtr;