1 // File: SketchPlugin_Sketch.h
2 // Created: 27 Mar 2014
3 // Author: Mikhail PONIKAROV
5 #ifndef SketchPlugin_Sketch_H_
6 #define SketchPlugin_Sketch_H_
8 #include "SketchPlugin.h"
9 #include <SketchPlugin_Feature.h>
10 #include <GeomAPI_Pnt.h>
11 #include <GeomAPI_Pln.h>
12 #include <GeomAPI_IPresentable.h>
15 /// the plane edge color
16 #define SKETCH_PLANE_COLOR "#700000"
18 /// the plane edge width
19 #define SKETCH_WIDTH "4"
21 /// face of the square-face displayed for selection of general plane
22 #define PLANE_SIZE "200"
24 /**\class SketchPlugin_Sketch
26 * \brief Feature for creation of the new part in PartSet.
28 class SketchPlugin_Sketch : public ModelAPI_CompositeFeature//, public GeomAPI_IPresentable
31 /// Sketch feature kind
32 inline static const std::string& ID()
34 static const std::string MY_SKETCH_ID("Sketch");
37 /// Origin point of the sketcher in 3D space
38 inline static const std::string& ORIGIN_ID()
40 static const std::string MY_ORIGIN_ID("Origin");
43 /// Vector X inside of the sketch plane
44 inline static const std::string& DIRX_ID()
46 static const std::string MY_DIRX_ID("DirX");
49 /// Vector Y inside of the sketch plane
50 inline static const std::string& DIRY_ID()
52 static const std::string MY_DIRY_ID("DirY");
55 /// Vector Z, normal to the sketch plane
56 inline static const std::string& NORM_ID()
58 static const std::string MY_NORM_ID("Norm");
61 /// All features of this sketch (list of references)
62 inline static const std::string& FEATURES_ID()
64 static const std::string MY_FEATURES_ID("Features");
65 return MY_FEATURES_ID;
68 /// Returns the kind of a feature
69 SKETCHPLUGIN_EXPORT virtual const std::string& getKind()
71 static std::string MY_KIND = SketchPlugin_Sketch::ID();
75 /// Creates a new part document if needed
76 SKETCHPLUGIN_EXPORT virtual void execute();
78 /// Request for initialization of data model of the feature: adding all attributes
79 SKETCHPLUGIN_EXPORT virtual void initAttributes();
82 /// \param theDeltaX the delta for X coordinate is moved
83 /// \param theDeltaY the delta for Y coordinate is moved
84 SKETCHPLUGIN_EXPORT virtual void move(const double theDeltaX, const double theDeltaY)
89 /// Return the distance between the feature and the point
90 /// \param thePoint the point
91 virtual double distanceToPoint(const std::shared_ptr<GeomAPI_Pnt2d>& thePoint)
97 /// Converts a 2D sketch space point into point in 3D space
98 SKETCHPLUGIN_EXPORT std::shared_ptr<GeomAPI_Pnt> to3D(const double theX, const double theY);
100 /// Returns true if this feature must be displayed in the history (top level of Part tree)
101 SKETCHPLUGIN_EXPORT virtual bool isInHistory()
106 /// Use plugin manager for features creation
107 SketchPlugin_Sketch();
109 /// Returns the basis plane for the sketch
110 std::shared_ptr<GeomAPI_Pln> plane();
112 //virtual AISObjectPtr getAISObject(AISObjectPtr thePrevious);
114 /// removes also all sub-sketch elements
115 SKETCHPLUGIN_EXPORT virtual void erase();
117 SKETCHPLUGIN_EXPORT virtual std::shared_ptr<ModelAPI_Feature> addFeature(std::string theID);
119 /// Returns the number of sub-elements
120 SKETCHPLUGIN_EXPORT virtual int numberOfSubs() const;
122 /// Returns the sub-feature by zero-base index
123 SKETCHPLUGIN_EXPORT virtual std::shared_ptr<ModelAPI_Feature>
124 subFeature(const int theIndex) const;
126 /// Returns the sub-feature unique identifier in this composite feature by zero-base index
127 SKETCHPLUGIN_EXPORT virtual int subFeatureId(const int theIndex) const;
129 /// Returns true if feature or reuslt belong to this composite feature as subs
130 SKETCHPLUGIN_EXPORT virtual bool isSub(ObjectPtr theObject) const;
132 /// Construction result is allways recomuted on the fly
133 SKETCHPLUGIN_EXPORT virtual bool isPersistentResult() {return false;}
135 /// Returns the point projected into the sketch plane
136 std::shared_ptr<GeomAPI_Pnt2d> to2D(const std::shared_ptr<GeomAPI_Pnt>& thePnt);
138 SKETCHPLUGIN_EXPORT virtual void attributeChanged(const std::string& theID);
140 /// Creates a plane and append it to the list
141 /// \param theX the X normal value
142 /// \param theY the Y normal value
143 /// \param theZ the Z normal value
144 /// \param theShapes the list of result shapes
145 //void addPlane(double theX, double theY, double theZ,
146 // std::list<std::shared_ptr<GeomAPI_Shape> >& theShapes) const;
148 /// Checks whether the plane is set in the sketch.
149 /// \returns the boolean state