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>
14 #include <GeomAPI_IPresentable.h>
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.
26 * The attributes below are named independent of the SolveSpace.
27 * Some of them may be unused.
29 * Also the list of possible attributes is provided to simplify assignment.
32 /// Size of the list of constraint attributes
33 const unsigned int CONSTRAINT_ATTR_SIZE = 4;
35 /** \class SketchPlugin_Constraint
37 * \brief Feature for creation of a new constraint between other features.
38 * Base class for all constraints.
40 class SketchPlugin_Constraint: public SketchPlugin_Feature,
41 public GeomAPI_IPresentable
44 /// The value parameter for the constraint
45 inline static const std::string& VALUE()
47 static const std::string MY_CONSTRAINT_VALUE("ConstraintValue");
48 return MY_CONSTRAINT_VALUE;
50 /// The 2D value parameter for the constraint
51 inline static const std::string& FLYOUT_VALUE_PNT()
53 static const std::string MY_FLYOUT_VALUE_PNT("ConstraintFlyoutValuePnt");
54 return MY_FLYOUT_VALUE_PNT;
56 /// First entity for the constraint
57 inline static const std::string& ENTITY_A()
59 static const std::string MY_ENTITY_A("ConstraintEntityA");
62 /// Second entity for the constraint
63 inline static const std::string& ENTITY_B()
65 static const std::string MY_ENTITY_B("ConstraintEntityB");
68 /// Third entity for the constraint
69 inline static const std::string& ENTITY_C()
71 static const std::string MY_ENTITY_C("ConstraintEntityC");
74 /// Fourth entity for the constraint
75 inline static const std::string& ENTITY_D()
77 static const std::string MY_ENTITY_D("ConstraintEntityD");
81 /// List of constraint attributes
82 inline static const std::string& ATTRIBUTE(const int 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();
90 static const std::string EMPTY_STRING("");
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;}
98 /** \brief Adds sub-feature of the higher level feature (sub-element of the sketch)
99 * \param theFeature sub-feature
101 SKETCHPLUGIN_EXPORT virtual const void addSub(
102 const FeaturePtr& theFeature) {}
104 /// Returns the AIS preview
105 SKETCHPLUGIN_EXPORT virtual boost::shared_ptr<GeomAPI_AISObject> getAISObject(
106 boost::shared_ptr<GeomAPI_AISObject> thePrevious);
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) {};
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; };
118 /// \brief Use plugin manager for features creation
119 SketchPlugin_Constraint() {}