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;
63 /// \brief Makes a full copy of the given entity
64 Slvs_hEntity copyEntity(const Slvs_hEntity& theCopied);
65 /// \brief Copy one entity to another
66 void copyEntity(const Slvs_hEntity& theFrom, const Slvs_hEntity& theTo);
68 /// \brief Verifies the current point or another coincident one is fixed
69 /// \return the ID of the Fixed constraint or SLVS_E_UNKNOWN
70 Slvs_hConstraint isPointFixed(const Slvs_hEntity& thePointID) const;
72 /** \brief Add new constraint to the current group
73 * \param[in] theConstraint SolveSpace's constraint
74 * \return the ID of added constraint
76 Slvs_hConstraint addConstraint(const Slvs_Constraint& theConstraint);
77 /** \brief Updates constraint in the current group.
78 * If the ID of constraint is zero, the new item will be added
79 * \param[in] theConstraint SolveSpace constraint
80 * \return the ID of updated/added constraint
82 Slvs_hConstraint updateConstraint(const Slvs_Constraint& theConstraint);
83 /** \brief Removes the constraint by its ID. All entities and parameters depending on this
84 * constraint, which are not used in other constraints, will be removed too.
85 * \param[in] theConstraintID index of constraint to be removed
86 * \return \c true if the constraint was successfully removed
88 bool removeConstraint(const Slvs_hConstraint& theConstraintID);
89 /// \brief Returns the constraint by its ID
90 const Slvs_Constraint& getConstraint(const Slvs_hConstraint& theConstraintID) const;
91 /// \brief Returns list of constraints of specified type
92 std::list<Slvs_Constraint> getConstraintsByType(int theConstraintType) const;
94 /// \brief Attach constraint SLVS_C_WHERE_DRAGGED to this storage. It need to make precise calculations
95 void addConstraintWhereDragged(const Slvs_hConstraint& theConstraintID);
97 /// \brief Add transient constraint
98 void addTemporaryConstraint(const Slvs_hConstraint& theConstraintID);
99 /// \brief Remove all transient constraints
100 void removeTemporaryConstraints();
101 /// \brief Checks the constraint is temporary
102 bool isTemporary(const Slvs_hConstraint& theConstraintID) const;
104 /// \brief Shows the sketch should be resolved
105 bool isNeedToResolve() const
106 { return myNeedToResolve; }
108 /// \brief Changes the flag of group to be resolved
109 void setNeedToResolve(bool theFlag)
110 { myNeedToResolve = theFlag; }
112 /// \brief Returns lists of removed elements
113 void getRemoved(std::set<Slvs_hParam>& theParameters,
114 std::set<Slvs_hEntity>& theEntities,
115 std::set<Slvs_hConstraint>& theConstraints);
117 /// \brief Initialize constraint solver by the entities collected by current storage
118 void initializeSolver(SketchSolver_Solver& theSolver);
121 /// \brief Store coincident points
122 void addCoincidentPoints(const Slvs_hEntity& thePoint1, const Slvs_hEntity& thePoint2);
123 /// \brief Remove point from lists of coincidence
124 void removeCoincidentPoint(const Slvs_hEntity& thePoint);
127 /// \brief Check two points are coincident
128 bool isCoincident(const Slvs_hEntity& thePoint1, const Slvs_hEntity& thePoint2) const;
131 Slvs_hParam myParamMaxID; ///< current parameter index (may differs with the number of parameters)
132 std::vector<Slvs_Param> myParameters; ///< list of parameters used in the current group of constraints (sorted by the identifier)
133 Slvs_hEntity myEntityMaxID; ///< current entity index (may differs with the number of entities)
134 std::vector<Slvs_Entity> myEntities; ///< list of entities used in the current group of constraints (sorted by the identifier)
135 Slvs_hConstraint myConstrMaxID; ///< current constraint index (may differs with the number of constraints)
136 std::vector<Slvs_Constraint> myConstraints; ///< list of constraints used in the current group (sorted by the identifier)
138 std::vector< std::set<Slvs_hEntity> > myCoincidentPoints; ///< lists of coincident points
139 Slvs_hConstraint myFixed; ///< identifier of one of temporary constraints to fix separate point
141 bool myNeedToResolve; ///< parameters are changed and group needs to be resolved
143 std::set<Slvs_hConstraint> myTemporaryConstraints; ///< list of transient constraints
144 std::set<Slvs_hParam> myRemovedParameters; ///< list of just removed parameters (cleared when returning to applicant)
145 std::set<Slvs_hEntity> myRemovedEntities; ///< list of just removed entities (cleared when returning to applicant)
146 std::set<Slvs_hConstraint> myRemovedConstraints; ///< list of just removed constraints (cleared when returning to applicant)
149 typedef std::shared_ptr<SketchSolver_Storage> StoragePtr;