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_Manager_H_
21 #define SketchSolver_Manager_H_
23 #include <SketchSolver_Group.h>
25 #include <Events_Listener.h>
31 class GeomDataAPI_Point2D;
32 class ModelAPI_CompositeFeature;
33 class SketchPlugin_Constraint;
35 /** \class SketchSolver_Manager
37 * \brief Listens the changes of SketchPlugin features and transforms the Constraint
38 * feature into the format understandable by sketch solver.
40 * \remark This is a singleton.
42 class SketchSolver_Manager : public Events_Listener
45 /** \brief Main method to create constraint manager
46 * \return pointer to the singleton
48 static SketchSolver_Manager* instance();
50 /** \brief Implementation of Event Listener method
51 * \param[in] theMessage the data of the event
53 virtual void processEvent(const std::shared_ptr<Events_Message>& theMessage);
56 * The solver needs all the updated objects are transfered in one group, not one by one.
57 * This iscreases performance and avoids problems in resolve of only part of the made updates.
59 virtual bool groupMessages();
62 SketchSolver_Manager();
63 ~SketchSolver_Manager();
65 /** \brief Adds or updates a constraint or an entity in the suitable group
66 * \param[in] theFeature sketch feature to be changed
67 * \return \c true if the feature changed successfully
69 bool updateFeature(const std::shared_ptr<SketchPlugin_Feature>& theFeature);
71 /** \brief Updates the sketch and related constraints, if the sketch plane is changed
72 * \param[in] theSketch sketch to be updated
73 * \return \c true if the sketch plane is changed
75 bool updateSketch(const std::shared_ptr<ModelAPI_CompositeFeature>& theSketch);
77 /** \brief Move feature
78 * \param[in] theMovedFeature dragged sketch feature
79 * \param[in] theFromPoint original position of the feature
80 * \param[in] theToPoint prefereble position of the feature (current position of the mouse)
81 * \return \c true if the feature has been changed successfully
83 bool moveFeature(const std::shared_ptr<SketchPlugin_Feature>& theMovedFeature,
84 const std::shared_ptr<GeomAPI_Pnt2d>& theFromPoint,
85 const std::shared_ptr<GeomAPI_Pnt2d>& theToPoint);
87 /** \brief Move feature using its moved attribute
88 * \param[in] theMovedAttribute dragged point attribute of sketch feature
89 * \param[in] theFromPoint original position of the moved point
90 * \param[in] theToPoint prefereble position (current position of the mouse)
91 * \return \c true if the attribute owner has been changed successfully
93 bool moveAttribute(const std::shared_ptr<GeomDataAPI_Point2D>& theMovedAttribute,
94 const std::shared_ptr<GeomAPI_Pnt2d>& theFromPoint,
95 const std::shared_ptr<GeomAPI_Pnt2d>& theToPoint);
97 /** \brief Removes a constraint from the manager
98 * \param[in] theConstraint constraint to be removed
99 * \return \c true if the constraint removed successfully
101 bool removeConstraint(std::shared_ptr<SketchPlugin_Constraint> theConstraint);
103 /** \brief Goes through the list of groups and solve the constraints
104 * \return \c true, if groups are resolved, and features should be updated
105 * (send the Update event)
107 bool resolveConstraints();
110 /** \brief Searches group which interact with specified feature
111 * \param[in] theFeature object to be found
112 * \return Pointer to corresponding group or NULL if the group cannot be created.
114 SketchGroupPtr findGroup(std::shared_ptr<SketchPlugin_Feature> theFeature);
116 /// \brief Stop sending the Update event until all features updated
117 /// \return \c true, if the last flushed event is Update
118 bool stopSendUpdate() const;
119 /// \brief Allow to send the Update event
120 void allowSendUpdate() const;
122 /// \brief Allow send events about changing features in groups
123 void releaseFeaturesIfEventsBlocked() const;
126 std::list<SketchGroupPtr> myGroups; ///< Groups of constraints
127 /// true if computation is performed and all "updates" are generated by this algo
128 /// and needs no recomputation