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>
12 #include <PlaneGCSSolver_Update.h>
14 #include <SketchPlugin_Constraint.h>
16 #include <ModelAPI_AttributeDouble.h>
17 #include <ModelAPI_AttributeRefAttr.h>
22 /** \class SketchSolver_Constraint
24 * \brief Converts SketchPlugin constraint to the constraint applicable for solver
26 class SketchSolver_Constraint
29 /// Default constructor
30 SketchSolver_Constraint()
31 : myType(CONSTRAINT_UNKNOWN)
35 /// Constructor based on SketchPlugin constraint
36 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 theEventsBlocked [in] all events from this constraint should be blocked
43 void process(StoragePtr theStorage, bool theEvensBlocked);
45 /// \brief Notify this object about the feature is changed somewhere
46 virtual void notify(const FeaturePtr& theFeature, PlaneGCSSolver_Update* theUpdater) {}
48 /// \brief Update constraint
49 virtual void update();
51 /// \brief Tries to remove constraint
52 /// \return \c false, if current constraint contains another SketchPlugin constraints
53 /// (like for multiple coincidence)
54 virtual bool remove();
56 /// \brief Block or unblock events from this constraint
57 virtual void blockEvents(bool isBlocked);
59 /// \brief Obtain a type of SketchPlugin constraint
60 static SketchSolver_ConstraintType TYPE(ConstraintPtr theConstraint);
62 /// \brief Returns the type of constraint
63 virtual SketchSolver_ConstraintType getType() const
66 /// \brief Shows error message
67 const std::string& error() const
68 { return myErrorMsg; }
71 /// \brief Converts SketchPlugin constraint to a list of solver's constraints
72 virtual void process();
74 /// \brief Generate list of attributes of constraint in order useful for constraints
75 /// \param[out] theValue numerical characteristic of constraint (e.g. distance)
76 /// \param[out] theAttributes list of attributes to be filled
77 virtual void getAttributes(EntityWrapperPtr& theValue,
78 std::vector<EntityWrapperPtr>& theAttributes);
80 /// \brief This method is used in derived objects to check consistency of constraint.
81 /// E.g. the distance between line and point may be signed.
82 virtual void adjustConstraint()
85 /// \brief Removes last error
87 { myErrorMsg.clear(); }
90 ConstraintPtr myBaseConstraint; ///< base SketchPlugin constraint
91 ConstraintWrapperPtr mySolverConstraint; ///< wrapper for PlaneGCS constraint
93 /// storage, which contains all information about entities and constraints
95 SketchSolver_ConstraintType myType; ///< type of constraint
96 std::list<EntityWrapperPtr> myAttributes; ///< attributes of constraint
98 std::string myErrorMsg; ///< error message
101 typedef std::shared_ptr<SketchSolver_Constraint> SolverConstraintPtr;