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>
15 const int CONSTRAINT_TEXT_HEIGHT = 28; /// the text height of the constraint
16 const int CONSTRAINT_TEXT_SELECTION_TOLERANCE = 20; /// the text selection tolerance
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.
31 /// The value parameter for the constraint
32 const std::string CONSTRAINT_ATTR_VALUE("ConstraintValue");
33 /// The 2D value parameter for the constraint
34 const std::string CONSTRAINT_ATTR_FLYOUT_VALUE_PNT("ConstraintFlyoutValuePnt");
35 /// The value parameter for the constraint
36 const std::string CONSTRAINT_ATTR_FLYOUT_VALUE("ConstraintFlyoutValue");
37 /// First entity for the constraint
38 const std::string CONSTRAINT_ATTR_ENTITY_A("ConstraintEntityA");
39 /// Second entity for the constraint
40 const std::string CONSTRAINT_ATTR_ENTITY_B("ConstraintEntityB");
41 /// Third entity for the constraint
42 const std::string CONSTRAINT_ATTR_ENTITY_C("ConstraintEntityC");
43 /// Fourth entity for the constraint
44 const std::string CONSTRAINT_ATTR_ENTITY_D("ConstraintEntityD");
45 /// List of constraint attributes
46 const unsigned int CONSTRAINT_ATTR_SIZE = 4;
47 const std::string CONSTRAINT_ATTRIBUTES[CONSTRAINT_ATTR_SIZE] =
48 {CONSTRAINT_ATTR_ENTITY_A, CONSTRAINT_ATTR_ENTITY_B,
49 CONSTRAINT_ATTR_ENTITY_C, CONSTRAINT_ATTR_ENTITY_D};
52 /** \class SketchPlugin_Constraint
54 * \brief Feature for creation of a new constraint between other features.
55 * Base class for all constraints.
57 class SketchPlugin_Constraint: public SketchPlugin_Feature
60 /// \brief Returns to which group in the document must be added feature
61 SKETCHPLUGIN_EXPORT virtual const std::string& getGroup()
62 {static std::string MY_GROUP = SKETCH_KIND; return MY_GROUP;}
64 /** \brief Adds sub-feature of the higher level feature (sub-element of the sketch)
65 * \param theFeature sub-feature
67 SKETCHPLUGIN_EXPORT virtual const void addSub(
68 const FeaturePtr& theFeature) {}
70 /// \brief Returns the sketch preview
71 SKETCHPLUGIN_EXPORT virtual const boost::shared_ptr<GeomAPI_Shape>& preview();
73 /// Returns the AIS preview
74 SKETCHPLUGIN_EXPORT virtual Handle_AIS_InteractiveObject getAISShape(Handle_AIS_InteractiveObject thePrevious);
77 /// \param theDeltaX the delta for X coordinate is moved
78 /// \param theDeltaY the delta for Y coordinate is moved
79 SKETCHPLUGIN_EXPORT virtual void move(const double theDeltaX, const double theDeltaY) {};
81 /// Return the distance between the feature and the point
82 /// \param thePoint the point
83 virtual double distanceToPoint(const boost::shared_ptr<GeomAPI_Pnt2d>& thePoint) { return 0; };
86 /// \brief Use plugin manager for features creation
87 SketchPlugin_Constraint() {}