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_Storage.h>
11 #include <PlaneGCSSolver_Update.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 : myType(CONSTRAINT_UNKNOWN)
34 /// Constructor based on SketchPlugin constraint
35 SketchSolver_Constraint(ConstraintPtr theConstraint);
37 virtual ~SketchSolver_Constraint() {}
39 /// \brief Initializes parameters and start constraint creation
40 /// \param theStorage [in] storage where to place new constraint
41 /// \param theEventsBlocked [in] all events from this constraint should be blocked
42 void process(StoragePtr theStorage, bool theEvensBlocked);
44 /// \brief Notify this object about the feature is changed somewhere
45 virtual void notify(const FeaturePtr& theFeature, PlaneGCSSolver_Update* theUpdater) {}
47 /// \brief Update constraint
48 virtual void update();
50 /// \brief Tries to remove constraint
51 /// \return \c false, if current constraint contains another SketchPlugin constraints
52 /// (like for multiple coincidence)
53 virtual bool remove();
55 /// \brief Block or unblock events from this constraint
56 virtual void blockEvents(bool isBlocked);
58 /// \brief Obtain a type of SketchPlugin constraint
59 static SketchSolver_ConstraintType TYPE(ConstraintPtr theConstraint);
61 /// \brief Returns the type of constraint
62 virtual SketchSolver_ConstraintType getType() const
65 /// \brief Shows error message
66 const std::string& error() const
67 { return myErrorMsg; }
70 /// \brief Converts SketchPlugin constraint to a list of solver's constraints
71 virtual void process();
73 /// \brief Generate list of attributes of constraint in order useful for constraints
74 /// \param[out] theValue numerical characteristic of constraint (e.g. distance)
75 /// \param[out] theAttributes list of attributes to be filled
76 virtual void getAttributes(EntityWrapperPtr& theValue,
77 std::vector<EntityWrapperPtr>& theAttributes);
79 /// \brief This method is used in derived objects to check consistency of constraint.
80 /// E.g. the distance between line and point may be signed.
81 virtual void adjustConstraint()
84 /// \brief Removes last error
86 { myErrorMsg.clear(); }
89 ConstraintPtr myBaseConstraint; ///< base SketchPlugin constraint
90 ConstraintWrapperPtr mySolverConstraint; ///< wrapper for PlaneGCS constraint
92 /// storage, which contains all information about entities and constraints
94 SketchSolver_ConstraintType myType; ///< type of constraint
95 std::list<EntityWrapperPtr> myAttributes; ///< attributes of constraint
97 std::string myErrorMsg; ///< error message
100 typedef std::shared_ptr<SketchSolver_Constraint> SolverConstraintPtr;