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 Create or change SlveSpace entity according to the given attribute
80 /// \param[in] theAttribute reference to the entity to be changed
81 /// \param[out] theType type of created entity
82 /// \return identifier of created/updated entity
83 Slvs_hEntity changeEntity(AttributeRefAttrPtr theAttribute, int& theType);
84 /// \brief Create or change SlveSpace entity according to the given attribute
85 Slvs_hEntity changeEntity(AttributePtr theAttribute, int& theType);
86 /// \brief Create or change SlveSpace entity according to the given feature
87 Slvs_hEntity changeEntity(FeaturePtr theFeature, int& theType);
89 /// \brief Removes the links to unused entities
90 void cleanRemovedEntities();
92 /// \brief Removes last error
94 { myErrorMsg.clear(); }
97 SketchSolver_Group* myGroup; ///< the group which contains current constraint
98 ConstraintPtr myBaseConstraint; ///< SketchPlugin constraint
99 std::vector<Slvs_hConstraint> mySlvsConstraints; ///< list of indices of SolveSpace constraints, together which equivalent to SketchPlugin constraint
100 std::map<FeaturePtr, Slvs_hEntity> myFeatureMap; ///< map feature to the entity it represents
101 std::map<AttributePtr, Slvs_hEntity> myAttributeMap; ///< map attribute to the corresponding entity
102 std::map<AttributePtr, Slvs_hParam> myValueMap; ///< list of attributes, which represents single value (e.g. distance) used in constraint
103 StoragePtr myStorage; ///< storage, which contains all information about entities and constraints in current group
105 std::string myErrorMsg; ///< error message
108 typedef std::shared_ptr<SketchSolver_Constraint> SolverConstraintPtr;
112 /** \class SketchSolver_ConstraintDistance
114 * \brief Convert distance constraint to SolveSpace structure
116 class SketchSolver_ConstraintDistance : public SketchSolver_Constraint
119 SketchSolver_ConstraintDistance(ConstraintPtr theConstraint) :
120 SketchSolver_Constraint(theConstraint)
123 virtual int getType() const
124 { return SLVS_C_PT_PT_DISTANCE; }
128 /** \class SketchSolver_ConstraintParallel
130 * \brief Convert Parallel constraint to SolveSpace structure
132 class SketchSolver_ConstraintParallel : public SketchSolver_Constraint
135 SketchSolver_ConstraintParallel(ConstraintPtr theConstraint) :
136 SketchSolver_Constraint(theConstraint)
139 virtual int getType() const
140 { return SLVS_C_PARALLEL; }
144 /** \class SketchSolver_ConstraintPerpendicular
146 * \brief Convert Perpendicular constraint to SolveSpace structure
148 class SketchSolver_ConstraintPerpendicular : public SketchSolver_Constraint
151 SketchSolver_ConstraintPerpendicular(ConstraintPtr theConstraint) :
152 SketchSolver_Constraint(theConstraint)
155 virtual int getType() const
156 { return SLVS_C_PERPENDICULAR; }
160 /** \class SketchSolver_ConstraintHorizontal
162 * \brief Convert Horizontal constraint to SolveSpace structure
164 class SketchSolver_ConstraintHorizontal : public SketchSolver_Constraint
167 SketchSolver_ConstraintHorizontal(ConstraintPtr theConstraint) :
168 SketchSolver_Constraint(theConstraint)
171 virtual int getType() const
172 { return SLVS_C_HORIZONTAL; }
176 /** \class SketchSolver_ConstraintVertical
178 * \brief Convert Vertical constraint to SolveSpace structure
180 class SketchSolver_ConstraintVertical : public SketchSolver_Constraint
183 SketchSolver_ConstraintVertical(ConstraintPtr theConstraint) :
184 SketchSolver_Constraint(theConstraint)
187 virtual int getType() const
188 { return SLVS_C_VERTICAL; }