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