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