Salome HOME
Merge branch 'master' of newgeom:newgeom.git
[modules/shaper.git] / src / SketchPlugin / SketchPlugin_Constraint.h
1 // File:    SketchPlugin_Constraint.h
2 // Created: 08 May 2014
3 // Author:  Artem ZHIDKOV
4
5 #ifndef SketchPlugin_Constraint_HeaderFile
6 #define SketchPlugin_Constraint_HeaderFile
7
8 #include "SketchPlugin.h"
9 #include "SketchPlugin_Feature.h"
10 #include <SketchPlugin_Sketch.h>
11 #include <ModelAPI_AttributeReference.h>
12 #include <ModelAPI_AttributeRefAttr.h>
13 #include <list>
14
15
16 /*  Description: 
17  *    Each constraint uses a set of parameters. In the SolveSpace library 
18  *    these parameters are named "valA", "ptA", "ptB", "entityA", "entityB". 
19  *    The "ptA" and "ptB" parameters represents a point in the constraint.
20  *    The "entityA" and "entityB" represents any other object (and a point too).
21  *    And the "valA" represents a real value.
22  *
23  *    The attributes below are named independent of the SolveSpace.
24  *    Some of them may be unused. 
25  *
26  *    Also the list of possible attributes is provided to simplify assignment.
27  */
28
29 /// Size of the list of constraint attributes
30 const unsigned int CONSTRAINT_ATTR_SIZE = 4;
31
32 /** \class SketchPlugin_Constraint
33  *  \ingroup DataModel
34  *  \brief Feature for creation of a new constraint between other features.
35  *         Base class for all constraints.
36  */
37 class SketchPlugin_Constraint: public SketchPlugin_Feature
38 {
39 public:
40   /// The value parameter for the constraint
41   inline static const std::string& VALUE()
42   {
43     static const std::string MY_CONSTRAINT_VALUE("ConstraintValue");
44     return MY_CONSTRAINT_VALUE;
45   }
46   /// The 2D value parameter for the constraint
47   inline static const std::string& FLYOUT_VALUE_PNT()
48   {
49     static const std::string MY_FLYOUT_VALUE_PNT("ConstraintFlyoutValuePnt");
50     return MY_FLYOUT_VALUE_PNT;
51   }
52   /// First entity for the constraint
53   inline static const std::string& ENTITY_A()
54   {
55     static const std::string MY_ENTITY_A("ConstraintEntityA");
56     return MY_ENTITY_A;
57   }
58   /// Second entity for the constraint
59   inline static const std::string& ENTITY_B()
60   {
61     static const std::string MY_ENTITY_B("ConstraintEntityB");
62     return MY_ENTITY_B;
63   }
64   /// Third entity for the constraint
65   inline static const std::string& ENTITY_C()
66   {
67     static const std::string MY_ENTITY_C("ConstraintEntityC");
68     return MY_ENTITY_C;
69   }
70   /// Fourth entity for the constraint
71   inline static const std::string& ENTITY_D()
72   {
73     static const std::string MY_ENTITY_D("ConstraintEntityD");
74     return MY_ENTITY_D;
75   }
76
77   /// List of constraint attributes
78   inline static const std::string& ATTRIBUTE(const int theNumber) {
79     switch (theNumber) {
80       case 0: return ENTITY_A();
81       case 1: return ENTITY_B();
82       case 2: return ENTITY_C();
83       case 3: return ENTITY_D();
84       default: break;
85     }
86     static const std::string EMPTY_STRING("");
87     return EMPTY_STRING;
88   }
89
90   /// \brief Returns to which group in the document must be added feature
91   SKETCHPLUGIN_EXPORT virtual const std::string& getGroup()
92   {static std::string MY_GROUP = SketchPlugin_Sketch::ID(); return MY_GROUP;}
93
94   /** \brief Adds sub-feature of the higher level feature (sub-element of the sketch)
95    *  \param theFeature sub-feature
96    */
97   SKETCHPLUGIN_EXPORT virtual const void addSub(
98     const FeaturePtr& theFeature) {}
99
100   /// Returns the AIS preview
101   SKETCHPLUGIN_EXPORT virtual boost::shared_ptr<GeomAPI_AISObject> getAISObject(
102                                 boost::shared_ptr<GeomAPI_AISObject> thePrevious);
103
104   /// Moves the feature
105   /// \param theDeltaX the delta for X coordinate is moved
106   /// \param theDeltaY the delta for Y coordinate is moved
107   SKETCHPLUGIN_EXPORT virtual void move(const double theDeltaX, const double theDeltaY) {};
108
109   /// Return the distance between the feature and the point
110   /// \param thePoint the point
111   virtual double distanceToPoint(const boost::shared_ptr<GeomAPI_Pnt2d>& thePoint) { return 0; };
112
113 protected:
114   /// \brief Use plugin manager for features creation
115   SketchPlugin_Constraint() {}
116 };
117
118 #endif