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_AttributeRefAttr.h>
20 class SketchSolver_Group;
22 /** \class SketchSolver_Constraint
24 * \brief Stores mapping between SketchPlugin and SolveSpace constraints data
26 class SketchSolver_Constraint
29 /// Default constructor
30 SketchSolver_Constraint() {}
31 SketchSolver_Constraint(ConstraintPtr theConstraint);
34 virtual ~SketchSolver_Constraint();
36 /// \brief Initializes the storage of SolveSpace constraints
37 void setStorage(StoragePtr theStorage);
38 /// \brief Initializes group ID for this constraint
39 void setGroup(SketchSolver_Group* theGroup);
41 /// \brief Update constraint
42 virtual void update(ConstraintPtr theConstraint = ConstraintPtr());
44 /// \brief Tries to remove constraint
45 /// \return \c false, if current constraint contains another SketchPlugin constraints (like for multiple coincidence)
46 virtual bool remove(ConstraintPtr theConstraint = ConstraintPtr());
48 /// \brief Update SketchPlugin attributes using the data obtained from SolveSpace entities
51 /// \brief Returns the type of constraint
52 virtual int getType() const = 0;
54 /// \brief Checks the constraint is used by current object
55 virtual bool hasConstraint(ConstraintPtr theConstraint) const
56 { return theConstraint == myBaseConstraint; }
58 /// \brief Return list of SketchPlugin constraints attached to this object
59 virtual std::list<ConstraintPtr> constraints() const;
61 /// \brief Return identifier of SolveSpace entity relating to the feature
62 Slvs_hEntity getId(FeaturePtr theFeature) const;
63 /// \brief Return identifier of SolveSpace entity relating to the attribute
64 Slvs_hEntity getId(AttributePtr theAttribute) const;
66 /// \brief Shows error message
67 const std::string& error() const
68 { return myErrorMsg; }
71 /// \brief Converts SketchPlugin constraint to a list of SolveSpace constraints
72 virtual void process();
74 /// \brief Generate list of attributes of constraint in order useful for SolveSpace 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(double& theValue, std::vector<Slvs_hEntity>& theAttributes);
79 /// \brief This method is used in derived objects to check consistence of constraint.
80 /// E.g. the distance between line and point may be signed.
81 virtual void adjustConstraint()
84 /// \brief Create or change SlveSpace entity according to the given attribute
85 /// \param[in] theAttribute reference to the entity to be changed
86 /// \param[out] theType type of created entity
87 /// \return identifier of created/updated entity
88 Slvs_hEntity changeEntity(AttributeRefAttrPtr theAttribute, int& theType);
89 /// \brief Create or change SlveSpace entity according to the given attribute
90 Slvs_hEntity changeEntity(AttributePtr theAttribute, int& theType);
91 /// \brief Create or change SlveSpace entity according to the given feature
92 Slvs_hEntity changeEntity(FeaturePtr theFeature, int& theType);
94 /// \brief Removes the links to unused entities
95 void cleanRemovedEntities();
97 /// \brief Removes last error
99 { myErrorMsg.clear(); }
102 SketchSolver_Group* myGroup; ///< the group which contains current constraint
103 ConstraintPtr myBaseConstraint; ///< SketchPlugin constraint
104 std::vector<Slvs_hConstraint> mySlvsConstraints; ///< list of indices of SolveSpace constraints, together which equivalent to SketchPlugin constraint
105 std::map<FeaturePtr, Slvs_hEntity> myFeatureMap; ///< map feature to the entity it represents
106 std::map<AttributePtr, Slvs_hEntity> myAttributeMap; ///< map attribute to the corresponding entity
107 std::map<AttributePtr, Slvs_hParam> myValueMap; ///< list of attributes, which represents single value (e.g. distance) used in constraint
108 StoragePtr myStorage; ///< storage, which contains all information about entities and constraints in current group
110 std::string myErrorMsg; ///< error message
113 typedef std::shared_ptr<SketchSolver_Constraint> SolverConstraintPtr;
117 /** \class SketchSolver_ConstraintParallel
119 * \brief Convert Parallel constraint to SolveSpace structure
121 class SketchSolver_ConstraintParallel : public SketchSolver_Constraint
124 SketchSolver_ConstraintParallel(ConstraintPtr theConstraint) :
125 SketchSolver_Constraint(theConstraint)
128 virtual int getType() const
129 { return SLVS_C_PARALLEL; }
133 /** \class SketchSolver_ConstraintPerpendicular
135 * \brief Convert Perpendicular constraint to SolveSpace structure
137 class SketchSolver_ConstraintPerpendicular : public SketchSolver_Constraint
140 SketchSolver_ConstraintPerpendicular(ConstraintPtr theConstraint) :
141 SketchSolver_Constraint(theConstraint)
144 virtual int getType() const
145 { return SLVS_C_PERPENDICULAR; }
149 /** \class SketchSolver_ConstraintHorizontal
151 * \brief Convert Horizontal constraint to SolveSpace structure
153 class SketchSolver_ConstraintHorizontal : public SketchSolver_Constraint
156 SketchSolver_ConstraintHorizontal(ConstraintPtr theConstraint) :
157 SketchSolver_Constraint(theConstraint)
160 virtual int getType() const
161 { return SLVS_C_HORIZONTAL; }
165 /** \class SketchSolver_ConstraintVertical
167 * \brief Convert Vertical constraint to SolveSpace structure
169 class SketchSolver_ConstraintVertical : public SketchSolver_Constraint
172 SketchSolver_ConstraintVertical(ConstraintPtr theConstraint) :
173 SketchSolver_Constraint(theConstraint)
176 virtual int getType() const
177 { return SLVS_C_VERTICAL; }