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