Salome HOME
487200dd39e2aa3b3a9b1335669740bf3e9b150d
[modules/shaper.git] / src / SketchSolver / SketchSolver_Constraint.h
1 // Copyright (C) 2014-2023  CEA, EDF
2 //
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.
7 //
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.
12 //
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
16 //
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 //
19
20 #ifndef SketchSolver_Constraint_H_
21 #define SketchSolver_Constraint_H_
22
23 #include <SketchSolver_Storage.h>
24 #include <PlaneGCSSolver_Update.h>
25
26 #include <SketchPlugin_Constraint.h>
27
28 #include <ModelAPI_AttributeDouble.h>
29 #include <ModelAPI_AttributeRefAttr.h>
30
31 #include <string>
32 #include <vector>
33
34 /** \class   SketchSolver_Constraint
35  *  \ingroup Plugins
36  *  \brief   Converts SketchPlugin constraint to the constraint applicable for solver
37  */
38 class SketchSolver_Constraint
39 {
40 protected:
41   /// Default constructor
42   SketchSolver_Constraint()
43     : myType(CONSTRAINT_UNKNOWN)
44   {}
45
46 public:
47   /// Constructor based on SketchPlugin constraint
48   SketchSolver_Constraint(ConstraintPtr theConstraint);
49
50   virtual ~SketchSolver_Constraint() {}
51
52   /// \brief Initializes parameters and start constraint creation
53   /// \param theStorage       [in]  storage where to place new constraint
54   /// \param theEventsBlocked [in]  all events from this constraint should be blocked
55   void process(StoragePtr theStorage, bool theEvensBlocked);
56
57   /// \brief Notify this object about the feature is changed somewhere
58   virtual void notify(const FeaturePtr& theFeature, PlaneGCSSolver_Update* theUpdater) {}
59
60   /// \brief Update constraint
61   virtual void update();
62
63   /// \brief Tries to remove constraint
64   /// \return \c false, if current constraint contains another SketchPlugin constraints
65   /// (like for multiple coincidence)
66   virtual bool remove();
67
68   /// \brief Block or unblock events from this constraint
69   virtual void blockEvents(bool isBlocked);
70
71   /// \brief Obtain a type of SketchPlugin constraint
72   static SketchSolver_ConstraintType TYPE(ConstraintPtr theConstraint);
73
74   /// \brief Returns the type of constraint
75   virtual SketchSolver_ConstraintType getType() const
76   { return myType; }
77
78   /// \brief Shows error message
79   const std::string& error() const
80   { return myErrorMsg; }
81
82 protected:
83   /// \brief Converts SketchPlugin constraint to a list of solver's constraints
84   virtual void process();
85
86   /// \brief Generate list of attributes of constraint in order useful for constraints
87   /// \param[out] theValue      numerical characteristic of constraint (e.g. distance)
88   /// \param[out] theAttributes list of attributes to be filled
89   virtual void getAttributes(EntityWrapperPtr&              theValue,
90                              std::vector<EntityWrapperPtr>& theAttributes);
91
92   /// \brief This method is used in derived objects to check consistency of constraint.
93   ///        E.g. the distance between line and point may be signed.
94   virtual void adjustConstraint()
95   {}
96
97   /// \brief Removes last error
98   void cleanErrorMsg()
99   { myErrorMsg.clear(); }
100
101 protected:
102   ConstraintPtr myBaseConstraint; ///< base SketchPlugin constraint
103   ConstraintWrapperPtr mySolverConstraint; ///< wrapper for PlaneGCS constraint
104
105   /// storage, which contains all information about entities and constraints
106   StoragePtr    myStorage;
107   SketchSolver_ConstraintType myType; ///< type of constraint
108   std::list<EntityWrapperPtr> myAttributes; ///< attributes of constraint
109
110   std::string   myErrorMsg; ///< error message
111 };
112
113 typedef std::shared_ptr<SketchSolver_Constraint> SolverConstraintPtr;
114
115 #endif