1 // Copyright (C) 2014-2017 CEA/DEN, EDF R&D
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License, or (at your option) any later version.
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 // Lesser General Public License for more details.
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 // See http://www.salome-platform.org/ or
18 // email : webmaster.salome@opencascade.com<mailto:webmaster.salome@opencascade.com>
21 #ifndef SolveSpaceSolver_Storage_H_
22 #define SolveSpaceSolver_Storage_H_
24 #include <SketchSolver_Storage.h>
25 #include <SolveSpaceSolver_Solver.h>
32 typedef std::list< std::set<ConstraintWrapperPtr> > SameConstraintMap;
34 /** \class SolveSpaceSolver_Storage
36 * \brief Contains all necessary data in SolveSpace format to solve a single
37 * group of constraints
39 class SolveSpaceSolver_Storage : public SketchSolver_Storage
42 SolveSpaceSolver_Storage(const GroupID& theGroup);
44 // ============= Inherited from SketchSolver_Storage =============
46 /// \brief Update constraint's data
47 /// \return \c true if any value is updated
48 virtual bool update(ConstraintWrapperPtr theConstraint);
49 /// \brief Update entity's data
50 /// \return \c true if any value is updated
51 virtual bool update(EntityWrapperPtr theEntity);
52 /// \brief Update parameter's data
53 /// \return \c true if the value of parameter is updated
54 virtual bool update(ParameterWrapperPtr theParameter);
56 /// \brief Update SketchPlugin features after resolving constraints
57 /// \param theFixedOnly [in] if \c true the fixed points will be updated only
58 virtual void refresh(bool theFixedOnly = false) const;
60 /// \brief Check if some parameters or entities are returned
61 /// to the current group after removing temporary constraints
62 virtual void verifyFixed();
64 /// \brief Mark two points as coincident
65 virtual void addCoincidentPoints(EntityWrapperPtr theMaster, EntityWrapperPtr theSlave);
67 /// \brief Calculate point on theBase entity. Value theCoeff is in [0.0 .. 1.0] and
68 /// shows the distance from the start point.
69 virtual EntityWrapperPtr calculateMiddlePoint(EntityWrapperPtr theBase, double theCoeff);
72 /// \brief Remove constraint
73 /// \return \c true if the constraint and all its parameters are removed successfully
74 virtual bool remove(ConstraintWrapperPtr theConstraint);
75 /// \brief Remove entity
76 /// \return \c true if the entity and all its parameters are removed successfully
77 virtual bool remove(EntityWrapperPtr theEntity);
78 /// \brief Remove parameter
79 /// \return \c true if the parameter has been removed
80 virtual bool remove(ParameterWrapperPtr theParameter);
82 /// \brief Update the group for the given entity, its sub-entities and parameters
83 virtual void changeGroup(EntityWrapperPtr theEntity, const GroupID& theGroup);
84 /// \brief Update the group for the given parameter
85 virtual void changeGroup(ParameterWrapperPtr theParam, const GroupID& theGroup);
88 // ============= Own methods =============
90 /// \brief Obtain and store identifier of sketch
91 void storeWorkplane(EntityWrapperPtr theSketch);
93 /** \brief Add new parameter to the current group
94 * \param[in] theParam SolveSpace parameter
95 * \return the ID of added parameter
97 Slvs_hParam addParameter(const Slvs_Param& theParam);
98 /** \brief Updates parameter in the current group. If the ID of parameter is zero, the new item will be added
99 * \param[in] theParam SolveSpace parameter
100 * \return the ID of updated/added parameter
102 Slvs_hParam updateParameter(const Slvs_Param& theParam);
103 /** \brief Removes the parameter by its ID
104 * \param[in] theParamID index of parameter to be removed
105 * \return \c true if the parameter was successfully removed
107 bool removeParameter(const Slvs_hParam& theParamID);
108 /// \brief Returns the parameter by its ID
109 const Slvs_Param& getParameter(const Slvs_hParam& theParamID) const;
111 /** \brief Add new entity to the current group
112 * \param[in] theEntity SolveSpace entity
113 * \return the ID of added entity
115 Slvs_hEntity addEntity(const Slvs_Entity& theEntity);
116 /** \brief Updates entity in the current group. If the ID of entity is zero, the new item will be added
117 * \param[in] theEntity SolveSpace entity
118 * \return the ID of updated/added entity
120 Slvs_hEntity updateEntity(const Slvs_Entity& theEntity);
121 /** \brief Removes the entity by its ID. All parameters used in this entity,
122 * and not used in other constraints, will be removed too.
123 * \param[in] theEntityID index of entity to be removed
124 * \return \c true if the entity was successfully removed
126 bool removeEntity(const Slvs_hEntity& theEntityID);
127 /// \brief Returns the entity by its ID
128 const Slvs_Entity& getEntity(const Slvs_hEntity& theEntityID) const;
129 /// \brief Returns maximal ID of entities in this storage
130 const Slvs_hEntity& entityMaxID() const
131 { return myEntityMaxID; }
133 /** \brief Add new constraint to the current group
134 * \param[in] theConstraint SolveSpace's constraint
135 * \return the ID of added constraint
137 Slvs_hConstraint addConstraint(const Slvs_Constraint& theConstraint);
138 /** \brief Updates constraint in the current group.
139 * If the ID of constraint is zero, the new item will be added
140 * \param[in] theConstraint SolveSpace constraint
141 * \return the ID of updated/added constraint
143 Slvs_hConstraint updateConstraint(const Slvs_Constraint& theConstraint);
144 /** \brief Removes the constraint by its ID. All entities and parameters depending on this
145 * constraint, which are not used in other constraints, will be removed too.
146 * \param[in] theConstraintID index of constraint to be removed
147 * \return \c true if the constraint was successfully removed
149 bool removeConstraint(const Slvs_hConstraint& theConstraintID);
150 /// \brief Returns the constraint by its ID
151 const Slvs_Constraint& getConstraint(const Slvs_hConstraint& theConstraintID) const;
152 /// \brief Returns quantity of constraints in this storage
153 size_t nbConstraints() const
154 { return myConstraints.size(); }
156 /// \brief Shows the storage has the same constraint twice
157 virtual bool hasDuplicatedConstraint() const
158 { return myDuplicatedConstraint; }
160 /// \brief Initialize constraint solver by the entities collected by current storage
161 virtual void initializeSolver(SolverPtr theSolver);
164 /// \brief Update arc points to be on circle sharp.
165 void adjustArc(const Slvs_Entity& theArc);
167 /// \brief Replace sub-entity theSource in all features by theDest
168 void replaceInFeatures(EntityWrapperPtr theSource, EntityWrapperPtr theDest);
169 /// \brief Replace constrained entity theSource by theDest in all constraints;
170 void replaceInConstraints(EntityWrapperPtr theSource, EntityWrapperPtr theDest);
172 /// \brief Add pair of constraints which have same representation in SolveSpace notation.
174 /// These constraints may be different and become the same after the substitution
175 /// of point coincidence.
176 void addSameConstraints(ConstraintWrapperPtr theConstraint1,
177 ConstraintWrapperPtr theConstraint2);
179 /// \brief Search constraint equal to the given in terms of SolveSpace notation
180 bool findSameConstraint(ConstraintWrapperPtr theConstraint);
183 Slvs_hEntity myWorkplaneID; ///< identifier of workplane
185 /// current parameter index (may differs with the number of parameters)
186 Slvs_hParam myParamMaxID;
188 /// list of parameters used in the current group of constraints (sorted by the identifier)
189 std::vector<Slvs_Param> myParameters;
190 Slvs_hEntity myEntityMaxID; ///< current entity index (may differs with the number of entities)
192 /// list of entities used in the current group of constraints (sorted by the identifier)
193 std::vector<Slvs_Entity> myEntities;
195 /// current constraint index (may differs with the number of constraints)
196 Slvs_hConstraint myConstrMaxID;
198 /// list of constraints used in the current group (sorted by the identifier)
199 std::vector<Slvs_Constraint> myConstraints;
201 bool myDuplicatedConstraint; ///< shows the storage has same constraint twice
203 SameConstraintMap myEqualConstraints; ///< list of groups of equal constraints