1 // File: SketchPlugin_Constraint.h
2 // Created: 08 May 2014
3 // Author: Artem ZHIDKOV
5 #ifndef SketchPlugin_Constraint_HeaderFile
6 #define SketchPlugin_Constraint_HeaderFile
8 #include "SketchPlugin.h"
9 #include "SketchPlugin_Feature.h"
10 #include <SketchPlugin_Sketch.h>
11 #include <ModelAPI_AttributeReference.h>
12 #include <ModelAPI_AttributeRefAttr.h>
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.
23 * The attributes below are named independent of the SolveSpace.
24 * Some of them may be unused.
26 * Also the list of possible attributes is provided to simplify assignment.
29 /// Size of the list of constraint attributes
30 const unsigned int CONSTRAINT_ATTR_SIZE = 4;
32 /** \class SketchPlugin_Constraint
34 * \brief Feature for creation of a new constraint between other features.
35 * Base class for all constraints.
37 class SketchPlugin_Constraint: public SketchPlugin_Feature
40 /// The value parameter for the constraint
41 inline static const std::string& VALUE()
43 static const std::string MY_CONSTRAINT_VALUE("ConstraintValue");
44 return MY_CONSTRAINT_VALUE;
46 /// The 2D value parameter for the constraint
47 inline static const std::string& FLYOUT_VALUE_PNT()
49 static const std::string MY_FLYOUT_VALUE_PNT("ConstraintFlyoutValuePnt");
50 return MY_FLYOUT_VALUE_PNT;
52 /// First entity for the constraint
53 inline static const std::string& ENTITY_A()
55 static const std::string MY_ENTITY_A("ConstraintEntityA");
58 /// Second entity for the constraint
59 inline static const std::string& ENTITY_B()
61 static const std::string MY_ENTITY_B("ConstraintEntityB");
64 /// Third entity for the constraint
65 inline static const std::string& ENTITY_C()
67 static const std::string MY_ENTITY_C("ConstraintEntityC");
70 /// Fourth entity for the constraint
71 inline static const std::string& ENTITY_D()
73 static const std::string MY_ENTITY_D("ConstraintEntityD");
77 /// List of constraint attributes
78 inline static const std::string& ATTRIBUTE(const int 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();
86 static const std::string EMPTY_STRING("");
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;}
94 /** \brief Adds sub-feature of the higher level feature (sub-element of the sketch)
95 * \param theFeature sub-feature
97 SKETCHPLUGIN_EXPORT virtual const void addSub(
98 const FeaturePtr& theFeature) {}
100 /// Returns the AIS preview
101 SKETCHPLUGIN_EXPORT virtual boost::shared_ptr<GeomAPI_AISObject> getAISObject(
102 boost::shared_ptr<GeomAPI_AISObject> thePrevious);
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) {};
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; };
114 /// \brief Use plugin manager for features creation
115 SketchPlugin_Constraint() {}