1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D
3 // File: SolveSpaceSolver_Storage.h
4 // Created: 18 Mar 2015
5 // Author: Artem ZHIDKOV
7 #ifndef SolveSpaceSolver_Storage_H_
8 #define SolveSpaceSolver_Storage_H_
10 #include <SketchSolver_Storage.h>
11 #include <SolveSpaceSolver_Solver.h>
18 typedef std::list< std::set<ConstraintWrapperPtr> > SameConstraintMap;
20 /** \class SolveSpaceSolver_Storage
22 * \brief Contains all necessary data in SolveSpace format to solve a single
23 * group of constraints
25 class SolveSpaceSolver_Storage : public SketchSolver_Storage
28 SolveSpaceSolver_Storage(const GroupID& theGroup);
30 // ============= Inherited from SketchSolver_Storage =============
32 /// \brief Update constraint's data
33 /// \return \c true if any value is updated
34 virtual bool update(ConstraintWrapperPtr theConstraint);
35 /// \brief Update entity's data
36 /// \return \c true if any value is updated
37 virtual bool update(EntityWrapperPtr theEntity);
38 /// \brief Update parameter's data
39 /// \return \c true if the value of parameter is updated
40 virtual bool update(ParameterWrapperPtr theParameter);
42 /// \brief Update SketchPlugin features after resolving constraints
43 /// \param theFixedOnly [in] if \c true the fixed points will be updated only
44 virtual void refresh(bool theFixedOnly = false) const;
46 /// \brief Check if some parameters or entities are returned
47 /// to the current group after removing temporary constraints
48 virtual void verifyFixed();
50 /// \brief Mark two points as coincident
51 virtual void addCoincidentPoints(EntityWrapperPtr theMaster, EntityWrapperPtr theSlave);
53 /// \brief Calculate point on theBase entity. Value theCoeff is in [0.0 .. 1.0] and
54 /// shows the distance from the start point.
55 virtual EntityWrapperPtr calculateMiddlePoint(EntityWrapperPtr theBase, double theCoeff);
58 /// \brief Remove constraint
59 /// \return \c true if the constraint and all its parameters are removed successfully
60 virtual bool remove(ConstraintWrapperPtr theConstraint);
61 /// \brief Remove entity
62 /// \return \c true if the entity and all its parameters are removed successfully
63 virtual bool remove(EntityWrapperPtr theEntity);
64 /// \brief Remove parameter
65 /// \return \c true if the parameter has been removed
66 virtual bool remove(ParameterWrapperPtr theParameter);
68 /// \brief Update the group for the given entity, its sub-entities and parameters
69 virtual void changeGroup(EntityWrapperPtr theEntity, const GroupID& theGroup);
70 /// \brief Update the group for the given parameter
71 virtual void changeGroup(ParameterWrapperPtr theParam, const GroupID& theGroup);
74 // ============= Own methods =============
76 /// \brief Obtain and store identifier of sketch
77 void storeWorkplane(EntityWrapperPtr theSketch);
79 /** \brief Add new parameter to the current group
80 * \param[in] theParam SolveSpace parameter
81 * \return the ID of added parameter
83 Slvs_hParam addParameter(const Slvs_Param& theParam);
84 /** \brief Updates parameter in the current group. If the ID of parameter is zero, the new item will be added
85 * \param[in] theParam SolveSpace parameter
86 * \return the ID of updated/added parameter
88 Slvs_hParam updateParameter(const Slvs_Param& theParam);
89 /** \brief Removes the parameter by its ID
90 * \param[in] theParamID index of parameter to be removed
91 * \return \c true if the parameter was successfully removed
93 bool removeParameter(const Slvs_hParam& theParamID);
94 /// \brief Returns the parameter by its ID
95 const Slvs_Param& getParameter(const Slvs_hParam& theParamID) const;
97 /** \brief Add new entity to the current group
98 * \param[in] theEntity SolveSpace entity
99 * \return the ID of added entity
101 Slvs_hEntity addEntity(const Slvs_Entity& theEntity);
102 /** \brief Updates entity in the current group. If the ID of entity is zero, the new item will be added
103 * \param[in] theEntity SolveSpace entity
104 * \return the ID of updated/added entity
106 Slvs_hEntity updateEntity(const Slvs_Entity& theEntity);
107 /** \brief Removes the entity by its ID. All parameters used in this entity,
108 * and not used in other constraints, will be removed too.
109 * \param[in] theEntityID index of entity to be removed
110 * \return \c true if the entity was successfully removed
112 bool removeEntity(const Slvs_hEntity& theEntityID);
113 /// \brief Returns the entity by its ID
114 const Slvs_Entity& getEntity(const Slvs_hEntity& theEntityID) const;
115 /// \brief Returns maximal ID of entities in this storage
116 const Slvs_hEntity& entityMaxID() const
117 { return myEntityMaxID; }
119 /** \brief Add new constraint to the current group
120 * \param[in] theConstraint SolveSpace's constraint
121 * \return the ID of added constraint
123 Slvs_hConstraint addConstraint(const Slvs_Constraint& theConstraint);
124 /** \brief Updates constraint in the current group.
125 * If the ID of constraint is zero, the new item will be added
126 * \param[in] theConstraint SolveSpace constraint
127 * \return the ID of updated/added constraint
129 Slvs_hConstraint updateConstraint(const Slvs_Constraint& theConstraint);
130 /** \brief Removes the constraint by its ID. All entities and parameters depending on this
131 * constraint, which are not used in other constraints, will be removed too.
132 * \param[in] theConstraintID index of constraint to be removed
133 * \return \c true if the constraint was successfully removed
135 bool removeConstraint(const Slvs_hConstraint& theConstraintID);
136 /// \brief Returns the constraint by its ID
137 const Slvs_Constraint& getConstraint(const Slvs_hConstraint& theConstraintID) const;
138 /// \brief Returns quantity of constraints in this storage
139 size_t nbConstraints() const
140 { return myConstraints.size(); }
142 /// \brief Shows the storage has the same constraint twice
143 virtual bool hasDuplicatedConstraint() const
144 { return myDuplicatedConstraint; }
146 /// \brief Initialize constraint solver by the entities collected by current storage
147 virtual void initializeSolver(SolverPtr theSolver);
150 /// \brief Update arc points to be on circle sharp.
151 void adjustArc(const Slvs_Entity& theArc);
153 /// \brief Replace sub-entity theSource in all features by theDest
154 void replaceInFeatures(EntityWrapperPtr theSource, EntityWrapperPtr theDest);
155 /// \brief Replace constrained entity theSource by theDest in all constraints;
156 void replaceInConstraints(EntityWrapperPtr theSource, EntityWrapperPtr theDest);
158 /// \brief Add pair of constraints which have same representation in SolveSpace notation.
160 /// These constraints may be different and become the same after the substitution
161 /// of point coincidence.
162 void addSameConstraints(ConstraintWrapperPtr theConstraint1,
163 ConstraintWrapperPtr theConstraint2);
165 /// \brief Search constraint equal to the given in terms of SolveSpace notation
166 bool findSameConstraint(ConstraintWrapperPtr theConstraint);
169 Slvs_hEntity myWorkplaneID; ///< identifier of workplane
171 /// current parameter index (may differs with the number of parameters)
172 Slvs_hParam myParamMaxID;
174 /// list of parameters used in the current group of constraints (sorted by the identifier)
175 std::vector<Slvs_Param> myParameters;
176 Slvs_hEntity myEntityMaxID; ///< current entity index (may differs with the number of entities)
178 /// list of entities used in the current group of constraints (sorted by the identifier)
179 std::vector<Slvs_Entity> myEntities;
181 /// current constraint index (may differs with the number of constraints)
182 Slvs_hConstraint myConstrMaxID;
184 /// list of constraints used in the current group (sorted by the identifier)
185 std::vector<Slvs_Constraint> myConstraints;
187 bool myDuplicatedConstraint; ///< shows the storage has same constraint twice
189 SameConstraintMap myEqualConstraints; ///< list of groups of equal constraints