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 /// \param[in] thePointID entity to be checked fixed
70 /// \param[out] theFixed ID of constraint
71 /// \param[in] theAccurate if \c true, the calculation will be made for all type of constraints,
72 /// if \c false, only the point is verified
73 /// \return \c true if the point is fixed
74 bool isPointFixed(const Slvs_hEntity& thePointID, Slvs_hConstraint& theFixed, bool theAccurate = false) const;
75 /// \brief Verifies the current entity is fully fixed (may not be changed by constraints)
76 /// \param[in] theEntityID entity to be checked fixed
77 /// \param[in] theAccurate if \c true, the calculation will be made for all type of constraints,
78 /// if \c false, only points are verified
79 /// \return \c true if the entity is fixed
80 bool isEntityFixed(const Slvs_hEntity& theEntityID, bool theAccurate = false) const;
82 /** \brief Add new constraint to the current group
83 * \param[in] theConstraint SolveSpace's constraint
84 * \return the ID of added constraint
86 Slvs_hConstraint addConstraint(const Slvs_Constraint& theConstraint);
87 /** \brief Updates constraint in the current group.
88 * If the ID of constraint is zero, the new item will be added
89 * \param[in] theConstraint SolveSpace constraint
90 * \return the ID of updated/added constraint
92 Slvs_hConstraint updateConstraint(const Slvs_Constraint& theConstraint);
93 /** \brief Removes the constraint by its ID. All entities and parameters depending on this
94 * constraint, which are not used in other constraints, will be removed too.
95 * \param[in] theConstraintID index of constraint to be removed
96 * \return \c true if the constraint was successfully removed
98 bool removeConstraint(const Slvs_hConstraint& theConstraintID);
99 /// \brief Returns the constraint by its ID
100 const Slvs_Constraint& getConstraint(const Slvs_hConstraint& theConstraintID) const;
101 /// \brief Returns list of constraints of specified type
102 std::list<Slvs_Constraint> getConstraintsByType(int theConstraintType) const;
104 /// \brief Attach constraint SLVS_C_WHERE_DRAGGED to this storage. It need to make precise calculations
105 void addConstraintWhereDragged(const Slvs_hConstraint& theConstraintID);
107 /// \brief Add transient constraint
108 void addTemporaryConstraint(const Slvs_hConstraint& theConstraintID);
109 /// \brief Remove all transient constraints
110 void removeTemporaryConstraints();
111 /// \brief Remove one temporary constraint. Preferable to remove the points under Point-on-Line constraint
112 /// \return Number of remaining temporary constraints
113 int deleteTemporaryConstraint();
114 /// \brief Checks the constraint is temporary
115 bool isTemporary(const Slvs_hConstraint& theConstraintID) const;
117 /// \brief Shows the sketch should be resolved
118 bool isNeedToResolve() const
119 { return myNeedToResolve && !myConstraints.empty(); }
121 /// \brief Shows the storage has the same constraint twice
122 bool hasDuplicatedConstraint() const
123 { return myDuplicatedConstraint; }
125 /// \brief Changes the flag of group to be resolved
126 void setNeedToResolve(bool theFlag)
127 { myNeedToResolve = theFlag; }
129 /// \brief Returns lists of removed elements
130 void getRemoved(std::set<Slvs_hParam>& theParameters,
131 std::set<Slvs_hEntity>& theEntities,
132 std::set<Slvs_hConstraint>& theConstraints);
134 /// \brief Initialize constraint solver by the entities collected by current storage
135 void initializeSolver(SketchSolver_Solver& theSolver);
138 /// \brief Store coincident points
139 void addCoincidentPoints(const Slvs_hEntity& thePoint1, const Slvs_hEntity& thePoint2);
140 /// \brief Remove point from lists of coincidence
141 void removeCoincidentPoint(const Slvs_hEntity& thePoint);
144 /// \brief Check two points are coincident
145 bool isCoincident(const Slvs_hEntity& thePoint1, const Slvs_hEntity& thePoint2) const;
148 Slvs_hParam myParamMaxID; ///< current parameter index (may differs with the number of parameters)
149 std::vector<Slvs_Param> myParameters; ///< list of parameters used in the current group of constraints (sorted by the identifier)
150 Slvs_hEntity myEntityMaxID; ///< current entity index (may differs with the number of entities)
151 std::vector<Slvs_Entity> myEntities; ///< list of entities used in the current group of constraints (sorted by the identifier)
152 Slvs_hConstraint myConstrMaxID; ///< current constraint index (may differs with the number of constraints)
153 std::vector<Slvs_Constraint> myConstraints; ///< list of constraints used in the current group (sorted by the identifier)
155 std::vector< std::set<Slvs_hEntity> > myCoincidentPoints; ///< lists of coincident points
156 Slvs_hConstraint myFixed; ///< identifier of one of temporary constraints to fix separate point
158 bool myNeedToResolve; ///< parameters are changed and group needs to be resolved
159 bool myDuplicatedConstraint; ///< shows the storage has same constraint twice
161 std::set<Slvs_hConstraint> myTemporaryConstraints; ///< list of transient constraints
162 std::set<Slvs_hParam> myRemovedParameters; ///< list of just removed parameters (cleared when returning to applicant)
163 std::set<Slvs_hEntity> myRemovedEntities; ///< list of just removed entities (cleared when returning to applicant)
164 std::set<Slvs_hConstraint> myRemovedConstraints; ///< list of just removed constraints (cleared when returning to applicant)
167 typedef std::shared_ptr<SketchSolver_Storage> StoragePtr;