Salome HOME
Added class for the distance constraint
[modules/shaper.git] / src / SketchPlugin / SketchPlugin_ConstraintDistance.h
1 // File:    SketchPlugin_ConstraintDistance.h
2 // Created: 08 May 2014
3 // Author:  Artem ZHIDKOV
4
5 #ifndef SketchPlugin_ConstraintDistance_HeaderFile
6 #define SketchPlugin_ConstraintDistance_HeaderFile
7
8 #include "SketchPlugin.h"
9 #include "SketchPlugin_Constraint.h"
10 #include <list>
11
12 /// The distance value
13 const std::string CONSTRAINT_ATTR_DISTANCE(CONSTRAINT_ATTR_VALUE);
14
15
16 /** \class SketchPlugin_ConstraintDistance
17  *  \ingroup DataModel
18  *  \brief Feature for creation of a new constraint which fixes the distance 
19  *         between two other features.
20  *
21  *  There are allowed several kinds of distances:
22  *    \li The next constraints use "valA", "ptA" and "entityA" parameters:
23  *        point-point, point-line, point-plane, point-face;
24  *    \li The distance between two points projected on a line (or vector) 
25  *        uses "valA", "ptA", "ptB", "entityA";
26  *    \li The diameter of a circle is defined by "valA" and "entityA";
27  *    \li The angle between two lines (or vectors) uses "valA", "entityA", "entityB".
28  *
29  *  The default list of attributes contains only CONSTRAINT_ATTR_DISTANCE.
30  *
31  *  \remark As far as the constraint may have different attributes, 
32  *          it is strongly recommended to use setAttibutes() methods 
33  *          instead of direct intialization of the attributes
34  */
35 class SketchPlugin_ConstraintDistance: public SketchPlugin_Constraint
36 {
37 public:
38   /// \brief Returns the kind of a feature
39   SKETCHPLUGIN_EXPORT virtual const std::string& getKind() 
40   {static std::string MY_KIND = "SketchConstraintDistance"; return MY_KIND;}
41
42   /// \brief Returns to which group in the document must be added feature
43   SKETCHPLUGIN_EXPORT virtual const std::string& getGroup() 
44   {static std::string MY_GROUP = "Sketch"; return MY_GROUP;}
45
46   /// \brief Creates a new part document if needed
47   SKETCHPLUGIN_EXPORT virtual void execute();
48
49   /** \brief Request for initialization of data model of the feature: adding all attributes
50    *
51    *  The setAttributes() methods should be used instead.
52    */
53   SKETCHPLUGIN_EXPORT virtual void initAttributes() 
54   { /* do nothing */ }
55
56   /// \brief Use plugin manager for features creation
57   SketchPlugin_ConstraintDistance();
58
59   /** \brief Initializes the attributes of the constraint
60    *
61    *  Defines the distance between a point and another entity, 
62    *  or defines the angle between two vectors.
63    *
64    *  \param[in] theDistance distance (or angle) between two entities
65    *  \param[in] theEntityA  first parameter of the constraint
66    *  \param[in] theEntityB  second parameter of the constraint
67    */
68   SKETCHPLUGIN_EXPORT void setAttributes(
69           const double                                  theDistance, 
70           const boost::shared_ptr<SketchPlugin_Feature> theEntityA, 
71           const boost::shared_ptr<SketchPlugin_Feature> theEntityB);
72   /** \brief Initializes the attributes of the constraint
73    *
74    *  Defines the distance between a point defined by reference and another entity.
75    *
76    *  \param[in] theDistance distance between the point and other entity
77    *  \param[in] thePoint    reference to the point attribute
78    *  \param[in] theEntity   other parameter of the constraint
79    */
80   SKETCHPLUGIN_EXPORT void setAttributes(
81           const double                                  theDistance, 
82           const boost::shared_ptr<ModelAPI_Attribute>   thePoint, 
83           const boost::shared_ptr<SketchPlugin_Feature> theEntity);
84   /** \brief Initializes the attributes of the constraint
85    *
86    *  Defines the distance between two points which defined by references.
87    *
88    *  \param[in] theDistance distance between the points
89    *  \param[in] thePointA   reference to the first point attribute
90    *  \param[in] thePointB   reference to the second point attribute
91    */
92   SKETCHPLUGIN_EXPORT void setAttributes(
93           const double                                  theDistance, 
94           const boost::shared_ptr<ModelAPI_Attribute>   thePointA, 
95           const boost::shared_ptr<ModelAPI_Attribute>   thePointB);
96   /** \brief Initializes the attributes of the constraint
97    *
98    *  Defines radius of a circle.
99    *
100    *  \param[in] theRadius radius of the circle
101    *  \param[in] theCircle the circle which has specified radius
102    */
103   SKETCHPLUGIN_EXPORT void setAttributes(
104           const double                                  theRadius, 
105           const boost::shared_ptr<SketchPlugin_Feature> theCircle);
106   /** \brief Initializes the attributes of the constraint
107    *
108    *  Defines the distance between two points projected on specified vector (or line).
109    *
110    *  \param[in] theDistance distance between projected points
111    *  \param[in] thePointA   first point for the projection
112    *  \param[in] thePointB   second point for the projection
113    *  \param[in] theEntity   direction of the line which the points projected on
114    */
115   SKETCHPLUGIN_EXPORT void setAttributes(
116           const double                                  theDistance, 
117           const boost::shared_ptr<SketchPlugin_Feature> thePointA, 
118           const boost::shared_ptr<SketchPlugin_Feature> thePointB, 
119           const boost::shared_ptr<SketchPlugin_Feature> theEntity);
120
121 private:
122   /** \brief Returns the list of attributes for the certain type of constraint.
123    *  \return names of attributes
124    */
125   const std::list<std::string>& getAttributesList() const
126   { return myAttrList; }
127
128 private:
129   std::list<std::string> myAttrList; ///< List of attributes for current constraint
130 };
131
132 #endif