1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D
3 // File: SketchSolver_Storage.h
4 // Created: 18 Mar 2015
5 // Author: Artem ZHIDKOV
7 #ifndef SketchSolver_Storage_H_
8 #define SketchSolver_Storage_H_
10 #include "SketchSolver.h"
11 #include <SketchSolver_Solver.h>
18 /** \class SketchSolver_Storage
20 * \brief Contains all necessary data in SolveSpace format to solve a single group of constraints
22 class SketchSolver_Storage
25 SketchSolver_Storage();
27 /** \brief Add new parameter to the current group
28 * \param[in] theParam SolveSpace parameter
29 * \return the ID of added parameter
31 Slvs_hParam addParameter(const Slvs_Param& theParam);
32 /** \brief Updates parameter in the current group. If the ID of parameter is zero, the new item will be added
33 * \param[in] theParam SolveSpace parameter
34 * \return the ID of updated/added parameter
36 Slvs_hParam updateParameter(const Slvs_Param& theParam);
37 /** \brief Removes the parameter by its ID
38 * \param[in] theParamID index of parameter to be removed
39 * \return \c true if the parameter was successfully removed
41 bool removeParameter(const Slvs_hParam& theParamID);
42 /// \brief Returns the parameter by its ID
43 const Slvs_Param& getParameter(const Slvs_hParam& theParamID) const;
45 /** \brief Add new entity to the current group
46 * \param[in] theEntity SolveSpace entity
47 * \return the ID of added entity
49 Slvs_hEntity addEntity(const Slvs_Entity& theEntity);
50 /** \brief Updates entity in the current group. If the ID of entity is zero, the new item will be added
51 * \param[in] theEntity SolveSpace entity
52 * \return the ID of updated/added entity
54 Slvs_hEntity updateEntity(const Slvs_Entity& theEntity);
55 /** \brief Removes the entity by its ID. All parameters used in this entity,
56 * and not used in other constraints, will be removed too.
57 * \param[in] theEntityID index of entity to be removed
58 * \return \c true if the entity was successfully removed
60 bool removeEntity(const Slvs_hEntity& theEntityID);
61 /// \brief Returns the entity by its ID
62 const Slvs_Entity& getEntity(const Slvs_hEntity& theEntityID) const;
64 /// \brief Verifies the current point or another coincident one is fixed
65 /// \return the ID of the Fixed constraint or SLVS_E_UNKNOWN
66 Slvs_hConstraint isPointFixed(const Slvs_hEntity& thePointID) const;
68 /** \brief Add new constraint to the current group
69 * \param[in] theConstraint SolveSpace's constraint
70 * \return the ID of added constraint
72 Slvs_hConstraint addConstraint(const Slvs_Constraint& theConstraint);
73 /** \brief Updates constraint in the current group.
74 * If the ID of constraint is zero, the new item will be added
75 * \param[in] theConstraint SolveSpace constraint
76 * \return the ID of updated/added constraint
78 Slvs_hConstraint updateConstraint(const Slvs_Constraint& theConstraint);
79 /** \brief Removes the constraint by its ID. All entities and parameters depending on this
80 * constraint, which are not used in other constraints, will be removed too.
81 * \param[in] theConstraintID index of constraint to be removed
82 * \return \c true if the constraint was successfully removed
84 bool removeConstraint(const Slvs_hConstraint& theConstraintID);
85 /// \brief Returns the constraint by its ID
86 const Slvs_Constraint& getConstraint(const Slvs_hConstraint& theConstraintID) const;
87 /// \brief Returns list of constraints of specified type
88 std::list<Slvs_Constraint> getConstraintsByType(int theConstraintType) const;
90 /// \brief Attach temporary constraint to this storage. It need to make precise calculations
91 void addTemporaryConstraint(const Slvs_hConstraint& theConstraintID);
93 /// \brief Shows the sketch should be resolved
94 bool isNeedToResolve() const
95 { return myNeedToResolve; }
97 /// \brief Changes the flag of group to be resolved
98 void setNeedToResolve(bool theFlag)
99 { myNeedToResolve = theFlag; }
101 /// \brief Returns lists of removed elements
102 void getRemoved(std::set<Slvs_hParam>& theParameters,
103 std::set<Slvs_hEntity>& theEntities,
104 std::set<Slvs_hConstraint>& theConstraints);
106 /// \brief Initialize constraint solver by the entities collected by current storage
107 void initializeSolver(SketchSolver_Solver& theSolver);
110 /// \brief Store coincident points
111 void addCoincidentPoints(const Slvs_hEntity& thePoint1, const Slvs_hEntity& thePoint2);
112 /// \brief Remove point from lists of coincidence
113 void removeCoincidentPoint(const Slvs_hEntity& thePoint);
116 /// \brief Check two points are coincident
117 bool isCoincident(const Slvs_hEntity& thePoint1, const Slvs_hEntity& thePoint2) const;
120 Slvs_hParam myParamMaxID; ///< current parameter index (may differs with the number of parameters)
121 std::vector<Slvs_Param> myParameters; ///< list of parameters used in the current group of constraints (sorted by the identifier)
122 Slvs_hEntity myEntityMaxID; ///< current entity index (may differs with the number of entities)
123 std::vector<Slvs_Entity> myEntities; ///< list of entities used in the current group of constraints (sorted by the identifier)
124 Slvs_hConstraint myConstrMaxID; ///< current constraint index (may differs with the number of constraints)
125 std::vector<Slvs_Constraint> myConstraints; ///< list of constraints used in the current group (sorted by the identifier)
127 std::vector< std::set<Slvs_hEntity> > myCoincidentPoints; ///< lists of coincident points
128 Slvs_hConstraint myFixed; ///< identifier of one of temporary constraints to fix separate point
130 bool myNeedToResolve; ///< parameters are changed and group needs to be resolved
132 std::set<Slvs_hParam> myRemovedParameters; ///< list of just removed parameters (cleared when returning to applicant)
133 std::set<Slvs_hEntity> myRemovedEntities; ///< list of just removed entities (cleared when returning to applicant)
134 std::set<Slvs_hConstraint> myRemovedConstraints; ///< list of just removed constraints (cleared when returning to applicant)
137 typedef std::shared_ptr<SketchSolver_Storage> StoragePtr;