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