1 // File: SketchSolver_ConstraintManager.h
2 // Created: 08 May 2014
3 // Author: Artem ZHIDKOV
5 #ifndef SketchSolver_ConstraintManager_Headerfile
6 #define SketchSolver_ConstraintManager_Headerfile
8 #include "SketchSolver.h"
10 #include <SketchPlugin_Constraint.h>
12 // Need to be defined before including SolveSpace to avoid additional dependances on Windows platform
13 #if defined(WIN32) && !defined(HAVE_C99_INTEGER_TYPES)
14 typedef unsigned int UINT32;
23 // Unknown constraint (for error reporting)
24 #define SLVS_C_UNKNOWN 0
26 /** \class SketchSolver_ConstraintManager
28 * \brief Transforms the Constraint feature into the format understandable by SolveSpace library.
30 * Constraints created for SolveSpace library will be divided into the groups.
31 * The division order based on connectedness of the features by the constraints.
32 * The groups may be fused or separated according to the new constraints.
34 class SketchSolver_ConstraintManager
37 SketchSolver_ConstraintManager();
38 ~SketchSolver_ConstraintManager();
40 /** \brief Adds a constraint into the manager
41 * \param[in] theConstraint constraint to be added
42 * \return \c true if the constraint added successfully
44 SKETCHSOLVER_EXPORT bool addConstraint(boost::shared_ptr<SketchPlugin_Constraint> theConstraint);
46 /** \brief Removes a constraint from the manager
47 * \param[in] theConstraint constraint to be removed
48 * \return \c true if the constraint removed successfully
50 SKETCHSOLVER_EXPORT bool removeConstraint(boost::shared_ptr<SketchPlugin_Constraint> theConstraint);
53 class SketchSolver_ConstraintGroup;
55 /** \brief Searches list of groups which interact with specified constraint
56 * \param[in] theConstraint constraint to be found
57 * \param[out] theGroups list of group indexes interacted with constraint
59 void findGroups(boost::shared_ptr<SketchPlugin_Constraint> theConstraint,
60 std::vector<Slvs_hGroup>& theGroupIDs) const;
63 std::vector<SketchSolver_ConstraintGroup> myGroups; ///< groups of constraints
67 /** \class SketchSolver_ConstraintGroup
69 * \brief Keeps the group of constraints which based on the same entities
71 class SketchSolver_ConstraintManager::SketchSolver_ConstraintGroup
74 SketchSolver_ConstraintGroup();
75 ~SketchSolver_ConstraintGroup();
77 /// \brief Returns group's unique identifier
78 const Slvs_hGroup& getId() const
81 /** \brief Adds a constraint into the group
82 * \param[in] theConstraint constraint to be added
83 * \return \c true if the constraint added successfully
85 bool addConstraint(boost::shared_ptr<SketchPlugin_Constraint> theConstraint);
87 /** \brief Removes a constraint into the group
88 * \param[in] theConstraint constraint to be removed
89 * \return \c true if the constraint removed successfully
91 bool removeConstraint(boost::shared_ptr<SketchPlugin_Constraint> theConstraint);
93 /** \brief Verifies the constraint uses the objects from this group
94 * \param[in] theConstraint constraint for verification of interaction
95 * \return \c true if the constrained objects are used in current group
97 bool isInteract(boost::shared_ptr<SketchPlugin_Constraint> theConstraint) const;
100 /** \brief Creates a workplane from the sketch parameters
101 * \param[in] theParams list of the basic parameters of the workplane
102 * \return \c true if success
104 bool addWorkplane(std::list< boost::shared_ptr<ModelAPI_Attribute> >& theParams);
106 /** \brief Adds an entity into the group
107 * \param[in] theEntity the object of constraint
108 * \return identifier of created entity or 0 if entity was not added
110 Slvs_hEntity addEntity(boost::shared_ptr<ModelAPI_Attribute> theEntity);
112 /** \brief Adds a parameter into the group
113 * \param[in] theParam parameter to be added
114 * \return identifier of created parameter or 0 if it was not added
116 Slvs_hParam addParameter(double theParam);
118 /** \brief Compute constraint type according to SolveSpace identifiers
119 * \param[in] theConstraint constraint which type should be determined
120 * \return identifier of constraint type
122 int getConstraintType(const boost::shared_ptr<SketchPlugin_Constraint>& theConstraint) const;
125 Slvs_hGroup myID; ///< the index of the group
126 Slvs_Entity myWorkplane; ///< Workplane for the current group
127 std::vector<Slvs_Param> myParams; ///< List of parameters of the constraints
128 Slvs_hParam myParamMaxID; ///< Actual maximal ID of parameters
129 std::vector<Slvs_Entity> myEntities; ///< List of entities of the constaints
130 Slvs_hEntity myEntityMaxID; ///< Actual maximal ID of entities
131 std::vector<Slvs_Constraint> myConstraints; ///< List of constraints in SolveSpace format
132 Slvs_hConstraint myConstrMaxID; ///< Actual maximal ID of constraints
133 Slvs_System myConstrSet; ///< SolveSpace's set of equations obtained by constraints
134 std::map<boost::shared_ptr<SketchPlugin_Constraint>, Slvs_Constraint>
135 myConstraintMap; ///< The map between SketchPlugin and SolveSpace constraints