1 // Copyright (C) 2014-2019 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 email : webmaster.salome@opencascade.com
20 #ifndef SketchSolver_Storage_H_
21 #define SketchSolver_Storage_H_
23 #include <PlaneGCSSolver_ConstraintWrapper.h>
24 #include <PlaneGCSSolver_EntityWrapper.h>
26 #include <PlaneGCSSolver_Solver.h>
27 #include <PlaneGCSSolver_UpdateFeature.h>
29 #include <ModelAPI_Attribute.h>
30 #include <ModelAPI_AttributeDouble.h>
31 #include <ModelAPI_Feature.h>
32 #include <SketchPlugin_Constraint.h>
34 class SketchSolver_ConstraintDistance;
35 class SketchSolver_ConstraintFixedArcRadius;
36 typedef std::map<EntityWrapperPtr, std::set<EntityWrapperPtr> > CoincidentPointsMap;
39 /** \class SketchSolver_Storage
41 * \brief Interface to map SketchPlugin features to the entities of corresponding solver.
43 class SketchSolver_Storage
46 SketchSolver_Storage(const SketchSolver_Storage&);
47 SketchSolver_Storage& operator=(const SketchSolver_Storage&);
50 SketchSolver_Storage(SolverPtr theSolver);
52 /// \brief Change mapping between constraint from SketchPlugin and
53 /// a constraint applicable for corresponding solver.
54 /// \param theConstraint [in] original SketchPlugin constraint
55 /// \param theSolverConstraint [in] solver's constraint
56 virtual void addConstraint(ConstraintPtr theConstraint,
57 ConstraintWrapperPtr theSolverConstraint);
59 /// \brief Add a movement constraint which will be destroyed
60 /// after the next solving of the set of constraints.
61 /// \param theSolverConstraint [in] solver's constraint
62 virtual void addMovementConstraint(const ConstraintWrapperPtr& theSolverConstraint) = 0;
64 /// \brief Change mapping feature from SketchPlugin and
65 /// the entity applicable for corresponding solver.
66 /// \param theFeature [in] original SketchPlugin feature
67 /// \param theSolverEntity [in] solver's entity, created outside
68 void addEntity(FeaturePtr theFeature,
69 EntityWrapperPtr theSolverEntity);
71 /// \brief Change mapping attribute of a feature and the entity
72 /// applicable for corresponding solver.
73 /// \param theAttribute [in] original attribute
74 /// \param theSolverEntity [in] solver's entity, created outside
75 void addEntity(AttributePtr theAttribute,
76 EntityWrapperPtr theSolverEntity);
78 /// \brief Convert feature to the form applicable for specific solver and map it
79 /// \param theFeature [in] feature to convert
80 /// \param theForce [in] forced feature creation
81 /// \return \c true if the feature has been created or updated
82 virtual bool update(FeaturePtr theFeature, bool theForce = false) = 0;
84 /// \brief Convert attribute to the form applicable for specific solver and map it
85 /// \param theAttribute [in] attribute to convert
86 /// \param theForce [in] forced feature creation
87 /// \return \c true if the attribute has been created or updated
88 virtual bool update(AttributePtr theAttribute, bool theForce = false) = 0;
90 /// \brief Returns constraint related to corresponding constraint
91 const ConstraintWrapperPtr& constraint(const ConstraintPtr& theConstraint) const;
93 /// \brief Returns entity related to corresponding feature
94 const EntityWrapperPtr& entity(const FeaturePtr& theFeature) const;
95 /// \brief Returns entity related to corresponding attribute
96 const EntityWrapperPtr& entity(const AttributePtr& theAttribute) const;
98 /// \brief Make entity external
99 virtual void makeExternal(const EntityWrapperPtr& theEntity) = 0;
100 /// \brief Make entity non-external
101 virtual void makeNonExternal(const EntityWrapperPtr& theEntity) = 0;
103 /// \brief Removes constraint from the storage
104 /// \return \c true if the constraint and all its parameters are removed successfully
105 virtual bool removeConstraint(ConstraintPtr theConstraint) = 0;
106 /// \brief Removes feature from the storage
107 void removeFeature(FeaturePtr theFeature);
108 /// \brief Removes attribute from the storage
109 void removeAttribute(AttributePtr theAttribute);
111 /// \brief Remove all features became invalid
112 virtual void removeInvalidEntities() = 0;
114 /// \brief Check the features have not been removed
115 bool areFeaturesValid() const;
117 /// \brief Check the storage has constraints
118 virtual bool isEmpty() const
119 { return myConstraintMap.empty(); }
121 /// \brief Shows the sketch should be resolved
122 virtual bool isNeedToResolve()
123 { return myNeedToResolve; }
124 /// \brief Changes the flag of group to be resolved
125 void setNeedToResolve(bool theFlag)
126 { myNeedToResolve = theFlag; }
128 /// \brief Return list of conflicting constraints
129 std::set<ObjectPtr> getConflictingConstraints(SolverPtr theSolver) const;
131 /// \brief Verify, the sketch contains degenerated geometry
132 /// after resolving the set of constraints
133 /// \return STATUS_OK if the geometry is valid, STATUS_DEGENERATED otherwise.
134 virtual PlaneGCSSolver_Solver::SolveStatus checkDegeneratedGeometry() const = 0;
136 /// \brief Update SketchPlugin features after resolving constraints
137 virtual void refresh() const = 0;
139 /// \brief Block or unblock events when refreshing features
140 void blockEvents(bool isBlocked);
142 /// \brief Subscribe for updates of features
143 /// \param theSubscriber [in] object which wants to revceive notifications
144 /// \param theGroup [in] group of updates features to be send
145 void subscribeUpdates(SketchSolver_Constraint* theSubscriber, const std::string& theGroup) const;
146 /// \brief Unsubscribe for updates of features
147 /// \param theSubscriber [in] object which does not want to revceive notifications anymore
148 void unsubscribeUpdates(SketchSolver_Constraint* theSubscriber) const;
150 /// \brief Notify all subscribers about update of the feature
151 void notify(const FeaturePtr& theFeature) const;
153 /// \brief Make parametrization of arcs consistent.
154 /// Forward arcs should have the last parameter greater than the first parameter.
155 /// Reversed arcs should have the last parameter lesser than the first parameter.
156 virtual void adjustParametrizationOfArcs() = 0;
159 /// \brief Convert result to feature or attribute if theResult is linked to center of circle/arc
160 static void resultToFeatureOrAttribute(const ObjectPtr& theResult,
161 FeaturePtr& theFeature,
162 AttributePtr& theAttribute);
165 SolverPtr mySketchSolver; ///< Sketch solver, prepared in corresponding group
166 bool myNeedToResolve; ///< parameters are changed and group needs to be resolved
167 bool myEventsBlocked; ///< indicates that features do not send events
169 /// map SketchPlugin constraint to a list of solver's constraints
170 std::map<ConstraintPtr, ConstraintWrapperPtr> myConstraintMap;
171 /// map SketchPlugin feature to solver's entity
172 std::map<FeaturePtr, EntityWrapperPtr> myFeatureMap;
173 /// map attribute to solver's entity
174 std::map<AttributePtr, EntityWrapperPtr> myAttributeMap;
176 UpdaterPtr myUpdaters;
179 typedef std::shared_ptr<SketchSolver_Storage> StoragePtr;