1 // Copyright (C) 2014-2023 CEA, EDF
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 email : webmaster.salome@opencascade.com
20 #ifndef PlaneGCSSolver_Storage_H_
21 #define PlaneGCSSolver_Storage_H_
23 #include <PlaneGCSSolver_Defs.h>
24 #include <SketchSolver_Storage.h>
26 class PlaneGCSSolver_EntityBuilder;
28 /** \class PlaneGCSSolver_Storage
30 * \brief Contains all necessary data in PlaneGCS format to solve a single group of constraints
32 class PlaneGCSSolver_Storage : public SketchSolver_Storage
35 PlaneGCSSolver_Storage(const SolverPtr& theSolver);
37 // ============= Inherited from SketchSolver_Storage =============
39 /// \brief Change mapping between constraint from SketchPlugin and
40 /// a constraint applicable for corresponding solver.
41 /// \param theConstraint [in] original SketchPlugin constraint
42 /// \param theSolverConstraint [in] solver's constraint
43 virtual void addConstraint(ConstraintPtr theConstraint,
44 ConstraintWrapperPtr theSolverConstraint);
46 /// \brief Add a movement constraint which will be destroyed
47 /// after the next solving of the set of constraints.
48 /// \param theSolverConstraint [in] solver's constraint
49 virtual void addMovementConstraint(const ConstraintWrapperPtr& theSolverConstraint);
52 /// \brief Convert feature to the form applicable for specific solver and map it
53 /// \param theFeature [in] feature to convert
54 /// \param theForce [in] forced feature creation
55 /// \return \c true if the feature has been created or updated
56 virtual bool update(FeaturePtr theFeature, bool theForce = false);
58 /// \brief Convert attribute to the form applicable for specific solver and map it
59 /// \param theAttribute [in] attribute to convert
60 /// \param theForce [in] forced feature creation
61 /// \return \c true if the attribute has been created or updated
62 virtual bool update(AttributePtr theAttribute, bool theForce = false);
64 /// \brief Make entity external
65 virtual void makeExternal(const EntityWrapperPtr& theEntity);
66 /// \brief Make entity non-external
67 virtual void makeNonExternal(const EntityWrapperPtr& theEntity);
69 /// \brief Removes constraint from the storage
70 /// \return \c true if the constraint and all its parameters are removed successfully
71 virtual bool removeConstraint(ConstraintPtr theConstraint);
73 /// \brief Verify, the sketch contains degenerated geometry
74 /// after resolving the set of constraints
75 /// \return STATUS_OK if the geometry is valid, STATUS_DEGENERATED otherwise.
76 virtual PlaneGCSSolver_Solver::SolveStatus checkDegeneratedGeometry() const;
78 /// \brief Update SketchPlugin features after resolving constraints
79 virtual void refresh() const;
81 /// \brief Initialize memory for new solver's parameter
82 double* createParameter();
83 /// \brief Release memory occupied by parameters
84 void removeParameters(const GCS::SET_pD& theParams);
86 /// \brief Remove all features became invalid
87 virtual void removeInvalidEntities();
89 /// \brief Check the storage has constraints
90 virtual bool isEmpty() const
91 { return SketchSolver_Storage::isEmpty() && myAuxConstraintMap.empty(); }
93 /// \brief Make parametrization of arcs consistent.
94 /// Forward arcs should have the last parameter greater than the first parameter.
95 /// Reversed arcs should have the last parameter lesser than the first parameter.
96 virtual void adjustParametrizationOfArcs();
98 /// \brief Return list of features which are not fully constrained
99 virtual void getUnderconstrainedGeometry(std::set<ObjectPtr>& theFeatures) const;
102 /// \brief Convert feature using specified builder.
103 EntityWrapperPtr createFeature(const FeaturePtr& theFeature,
104 PlaneGCSSolver_EntityBuilder* theBuilder);
106 /// \brief Convert attribute using specified builder.
107 EntityWrapperPtr createAttribute(const AttributePtr& theAttribute,
108 PlaneGCSSolver_EntityBuilder* theBuilder);
110 /// \brief Create additional constaints:
111 /// * for arc to fix extra parameters;
112 /// * for ellipse to keep auxiliary points on their places
113 void createAuxiliaryConstraints(const EntityWrapperPtr& theEntity);
114 void removeAuxiliaryConstraints(const EntityWrapperPtr& theEntity);
117 ConstraintID myConstraintLastID; ///< identifier of last added constraint
119 /// additional constraints for correct processing of the arcs, ellipses, elliptic arcs
120 std::map<EntityWrapperPtr, ConstraintWrapperPtr> myAuxConstraintMap;
122 /// list of removed constraints to notify solver
123 std::list<GCSConstraintPtr> myRemovedConstraints;