Salome HOME
Issue #1860: fix end lines with spaces
[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
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     : myGroupID(GID_UNKNOWN),
31       myType(CONSTRAINT_UNKNOWN)
32   {}
33
34 public:
35   /// Constructor based on SketchPlugin constraint
36   SKETCHSOLVER_EXPORT 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 theGroupID  [in]  group for constraint
43   /// \param theSketchID [in] sketch for constraint
44   void process(StoragePtr theStorage, const GroupID& theGroupID, const EntityID& theSketchID);
45
46   /// \brief Update constraint
47   SKETCHSOLVER_EXPORT virtual void update();
48
49   /// \brief Tries to remove constraint
50   /// \return \c false, if current constraint contains another SketchPlugin constraints
51   /// (like for multiple coincidence)
52   SKETCHSOLVER_EXPORT virtual bool remove();
53
54   /// \brief Obtain a type of SketchPlugin constraint
55   SKETCHSOLVER_EXPORT static SketchSolver_ConstraintType TYPE(ConstraintPtr theConstraint);
56
57   /// \brief Returns the type of constraint
58   virtual SketchSolver_ConstraintType getType() const
59   { return myType; }
60
61   /// \brief Returns list of attributes of constraint
62   const std::list<EntityWrapperPtr>& attributes() const
63   { return myAttributes; }
64
65   /// \brief Verify the feature or any its attribute is used by constraint
66   virtual bool isUsed(FeaturePtr theFeature) const;
67   /// \brief Verify the attribute is used by constraint
68   virtual bool isUsed(AttributePtr theAttribute) const;
69
70   /// \brief Notify constraint, that coincidence appears or removed
71   virtual void notifyCoincidenceChanged(EntityWrapperPtr theCoincAttr1,
72     EntityWrapperPtr theCoincAttr2) { /* implement in derived class */ }
73
74   /// \brief Shows error message
75   const std::string& error() const
76   { return myErrorMsg; }
77
78 protected:
79   /// \brief Converts SketchPlugin constraint to a list of solver's constraints
80   virtual void process();
81
82   /// \brief Generate list of attributes of constraint in order useful for constraints
83   /// \param[out] theValue      numerical characteristic of constraint (e.g. distance)
84   /// \param[out] theAttributes list of attributes to be filled
85   virtual void getAttributes(double& theValue, std::vector<EntityWrapperPtr>& theAttributes);
86
87   /// \brief This method is used in derived objects to check consistency of constraint.
88   ///        E.g. the distance between line and point may be signed.
89   virtual void adjustConstraint()
90   {}
91
92   /// \brief Removes last error
93   void cleanErrorMsg()
94   { myErrorMsg.clear(); }
95
96 protected:
97   GroupID       myGroupID;  ///< identifier of the group, the constraint belongs to
98   EntityID      mySketchID; ///< identifier of the sketch, the constraint belongs to
99   ConstraintPtr myBaseConstraint; ///< base SketchPlugin constraint
100
101   /// storage, which contains all information about entities and constraints
102   StoragePtr    myStorage;
103   SketchSolver_ConstraintType myType; ///< type of constraint
104   std::list<EntityWrapperPtr> myAttributes; ///< attributes of constraint
105
106   std::string   myErrorMsg; ///< error message
107 };
108
109 typedef std::shared_ptr<SketchSolver_Constraint> SolverConstraintPtr;
110
111 #endif