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>
17 /** \class SketchSolver_Storage
19 * \brief Contains all necessary data in SolveSpace format to solve a single group of constraints
21 class SketchSolver_Storage
24 SketchSolver_Storage();
26 /** \brief Add new parameter to the current group
27 * \param[in] theParam SolveSpace parameter
28 * \return the ID of added parameter
30 Slvs_hParam addParameter(const Slvs_Param& theParam);
31 /** \brief Updates parameter in the current group. If the ID of parameter is zero, the new item will be added
32 * \param[in] theParam SolveSpace parameter
33 * \return the ID of updated/added parameter
35 Slvs_hParam updateParameter(const Slvs_Param& theParam);
36 /** \brief Removes the parameter by its ID
37 * \param[in] theParamID index of parameter to be removed
38 * \return \c true if the parameter was successfully removed
40 bool removeParameter(const Slvs_hParam& theParamID);
41 /// \brief Returns the parameter by its ID
42 const Slvs_Param& getParameter(const Slvs_hParam& theParamID) const;
44 /** \brief Add new entity to the current group
45 * \param[in] theEntity SolveSpace entity
46 * \return the ID of added entity
48 Slvs_hEntity addEntity(const Slvs_Entity& theEntity);
49 /** \brief Updates entity in the current group. If the ID of entity is zero, the new item will be added
50 * \param[in] theEntity SolveSpace entity
51 * \return the ID of updated/added entity
53 Slvs_hEntity updateEntity(const Slvs_Entity& theEntity);
54 /** \brief Removes the entity by its ID. All parameters used in this entity,
55 * and not used in other constraints, will be removed too.
56 * \param[in] theEntityID index of entity to be removed
57 * \return \c true if the entity was successfully removed
59 bool removeEntity(const Slvs_hEntity& theEntityID);
60 /// \brief Returns the entity by its ID
61 const Slvs_Entity& getEntity(const Slvs_hEntity& theEntityID) const;
63 /** \brief Add new constraint to the current group
64 * \param[in] theConstraint SolveSpace constraint
65 * \return the ID of added constraint
67 Slvs_hConstraint addConstraint(const Slvs_Constraint& theConstraint);
68 /** \brief Updates constraint in the current group.
69 * If the ID of constraint is zero, the new item will be added
70 * \param[in] theConstraint SolveSpace constraint
71 * \return the ID of updated/added constraint
73 Slvs_hConstraint updateConstraint(const Slvs_Constraint& theConstraint);
74 /** \brief Removes the constraint by its ID. All entities and parameters depending on this
75 * constraint, which are not used in other constraints, will be removed too.
76 * \param[in] theConstraintID index of constraint to be removed
77 * \return \c true if the constraint was successfully removed
79 bool removeConstraint(const Slvs_hConstraint& theConstraintID);
80 /// \brief Returns the constraint by its ID
81 const Slvs_Constraint& getConstraint(const Slvs_hConstraint& theConstraintID) const;
83 /// \brief Attach temporary constraint to this storage. It need to make precise calculations
84 void addTemporaryConstraint(const Slvs_hConstraint& theConstraintID);
86 /// \brief Shows the sketch should be resolved
87 bool isNeedToResolve() const
88 { return myNeedToResolve; }
90 /// \brief Changes the flag of group to be resolved
91 void setNeedToResolve(bool theFlag)
92 { myNeedToResolve = theFlag; }
94 /// \brief Returns lists of removed elements
95 void getRemoved(std::set<Slvs_hParam>& theParameters,
96 std::set<Slvs_hEntity>& theEntities,
97 std::set<Slvs_hConstraint>& theConstraints);
99 /// \brief Initialize constraint solver by the entities collected by current storage
100 void initializeSolver(SketchSolver_Solver& theSolver);
103 Slvs_hParam myParamMaxID; ///< current parameter index (may differs with the number of parameters)
104 std::vector<Slvs_Param> myParameters; ///< list of parameters used in the current group of constraints
105 Slvs_hEntity myEntityMaxID; ///< current entity index (may differs with the number of entities)
106 std::vector<Slvs_Entity> myEntities; ///< list of entities used in the current group of constraints
107 Slvs_hConstraint myConstrMaxID; ///< current constraint index (may differs with the number of constraints)
108 std::vector<Slvs_Constraint> myConstraints; ///< list of constraints used in the current group
110 std::vector<Slvs_hEntity> myFixedPoints; ///< identifiers of entities which relate to temporary constraints
112 bool myNeedToResolve; ///< parameters are changed and group needs to be resolved
114 std::set<Slvs_hParam> myRemovedParameters; ///< list of just removed parameters (cleared when returning to applicant)
115 std::set<Slvs_hEntity> myRemovedEntities; ///< list of just removed entities (cleared when returning to applicant)
116 std::set<Slvs_hConstraint> myRemovedConstraints; ///< list of just removed constraints (cleared when returning to applicant)
119 typedef std::shared_ptr<SketchSolver_Storage> StoragePtr;