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