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 group of constraints
24 class SolveSpaceSolver_Storage : public SketchSolver_Storage
27 SolveSpaceSolver_Storage(const GroupID& theGroup);
29 // ============= Inherited from SketchSolver_Storage =============
31 /// \brief Update constraint's data
32 /// \return \c true if any value is updated
33 virtual bool update(ConstraintWrapperPtr theConstraint);
34 /// \brief Update entity's data
35 /// \return \c true if any value is updated
36 virtual bool update(EntityWrapperPtr theEntity);
37 /// \brief Update parameter's data
38 /// \return \c true if the value of parameter is updated
39 virtual bool update(ParameterWrapperPtr theParameter);
41 /// \brief Update SketchPlugin features after resolving constraints
42 /// \param theFixedOnly [in] if \c true the fixed points will be updated only
43 virtual void refresh(bool theFixedOnly = false) const;
45 /// \brief Check if some parameters or entities are returned
46 /// to the current group after removing temporary constraints
47 virtual void verifyFixed();
49 /// \brief Mark two points as coincident
50 virtual void addCoincidentPoints(EntityWrapperPtr theMaster, EntityWrapperPtr theSlave);
52 /// \brief Calculate point on theBase entity. Value theCoeff is in [0.0 .. 1.0] and
53 /// shows the distance from the start point.
54 virtual EntityWrapperPtr calculateMiddlePoint(EntityWrapperPtr theBase, double theCoeff);
57 /// \brief Remove constraint
58 /// \return \c true if the constraint and all its parameters are removed successfully
59 virtual bool remove(ConstraintWrapperPtr theConstraint);
60 /// \brief Remove entity
61 /// \return \c true if the entity and all its parameters are removed successfully
62 virtual bool remove(EntityWrapperPtr theEntity);
63 /// \brief Remove parameter
64 /// \return \c true if the parameter has been removed
65 virtual bool remove(ParameterWrapperPtr theParameter);
67 /// \brief Update the group for the given entity, its sub-entities and parameters
68 virtual void changeGroup(EntityWrapperPtr theEntity, const GroupID& theGroup);
69 /// \brief Update the group for the given parameter
70 virtual void changeGroup(ParameterWrapperPtr theParam, const GroupID& theGroup);
73 // ============= Own methods =============
75 /// \brief Obtain and store identifier of sketch
76 void storeWorkplane(EntityWrapperPtr theSketch);
78 /** \brief Add new parameter to the current group
79 * \param[in] theParam SolveSpace parameter
80 * \return the ID of added parameter
82 Slvs_hParam addParameter(const Slvs_Param& theParam);
83 /** \brief Updates parameter in the current group. If the ID of parameter is zero, the new item will be added
84 * \param[in] theParam SolveSpace parameter
85 * \return the ID of updated/added parameter
87 Slvs_hParam updateParameter(const Slvs_Param& theParam);
88 /** \brief Removes the parameter by its ID
89 * \param[in] theParamID index of parameter to be removed
90 * \return \c true if the parameter was successfully removed
92 bool removeParameter(const Slvs_hParam& theParamID);
93 /// \brief Returns the parameter by its ID
94 const Slvs_Param& getParameter(const Slvs_hParam& theParamID) const;
96 /** \brief Add new entity to the current group
97 * \param[in] theEntity SolveSpace entity
98 * \return the ID of added entity
100 Slvs_hEntity addEntity(const Slvs_Entity& theEntity);
101 /** \brief Updates entity in the current group. If the ID of entity is zero, the new item will be added
102 * \param[in] theEntity SolveSpace entity
103 * \return the ID of updated/added entity
105 Slvs_hEntity updateEntity(const Slvs_Entity& theEntity);
106 /** \brief Removes the entity by its ID. All parameters used in this entity,
107 * and not used in other constraints, will be removed too.
108 * \param[in] theEntityID index of entity to be removed
109 * \return \c true if the entity was successfully removed
111 bool removeEntity(const Slvs_hEntity& theEntityID);
112 /// \brief Returns the entity by its ID
113 const Slvs_Entity& getEntity(const Slvs_hEntity& theEntityID) const;
114 /// \brief Returns maximal ID of entities in this storage
115 const Slvs_hEntity& entityMaxID() const
116 { return myEntityMaxID; }
118 /** \brief Add new constraint to the current group
119 * \param[in] theConstraint SolveSpace's constraint
120 * \return the ID of added constraint
122 Slvs_hConstraint addConstraint(const Slvs_Constraint& theConstraint);
123 /** \brief Updates constraint in the current group.
124 * If the ID of constraint is zero, the new item will be added
125 * \param[in] theConstraint SolveSpace constraint
126 * \return the ID of updated/added constraint
128 Slvs_hConstraint updateConstraint(const Slvs_Constraint& theConstraint);
129 /** \brief Removes the constraint by its ID. All entities and parameters depending on this
130 * constraint, which are not used in other constraints, will be removed too.
131 * \param[in] theConstraintID index of constraint to be removed
132 * \return \c true if the constraint was successfully removed
134 bool removeConstraint(const Slvs_hConstraint& theConstraintID);
135 /// \brief Returns the constraint by its ID
136 const Slvs_Constraint& getConstraint(const Slvs_hConstraint& theConstraintID) const;
137 /// \brief Returns quantity of constraints in this storage
138 size_t nbConstraints() const
139 { return myConstraints.size(); }
141 /// \brief Shows the storage has the same constraint twice
142 virtual bool hasDuplicatedConstraint() const
143 { return myDuplicatedConstraint; }
145 /// \brief Initialize constraint solver by the entities collected by current storage
146 virtual void initializeSolver(SolverPtr theSolver);
149 /// \brief Update arc points to be on circle sharp.
150 void adjustArc(const Slvs_Entity& theArc);
152 /// \brief Replace sub-entity theSource in all features by theDest
153 void replaceInFeatures(EntityWrapperPtr theSource, EntityWrapperPtr theDest);
154 /// \brief Replace constrained entity theSource by theDest in all constraints;
155 void replaceInConstraints(EntityWrapperPtr theSource, EntityWrapperPtr theDest);
157 /// \brief Add pair of constraints which have same representation in SolveSpace notation.
159 /// These constraints may be different and become the same after the substitution
160 /// of point coincidence.
161 void addSameConstraints(ConstraintWrapperPtr theConstraint1, ConstraintWrapperPtr theConstraint2);
163 /// \brief Search constraint equal to the given in terms of SolveSpace notation
164 bool findSameConstraint(ConstraintWrapperPtr theConstraint);
167 Slvs_hEntity myWorkplaneID; ///< identifier of workplane
169 Slvs_hParam myParamMaxID; ///< current parameter index (may differs with the number of parameters)
170 std::vector<Slvs_Param> myParameters; ///< list of parameters used in the current group of constraints (sorted by the identifier)
171 Slvs_hEntity myEntityMaxID; ///< current entity index (may differs with the number of entities)
172 std::vector<Slvs_Entity> myEntities; ///< list of entities used in the current group of constraints (sorted by the identifier)
173 Slvs_hConstraint myConstrMaxID; ///< current constraint index (may differs with the number of constraints)
174 std::vector<Slvs_Constraint> myConstraints; ///< list of constraints used in the current group (sorted by the identifier)
176 bool myDuplicatedConstraint; ///< shows the storage has same constraint twice
178 SameConstraintMap myEqualConstraints; ///< list of groups of equal constraints