Salome HOME
Refactoring: static constants are replaced by inline functions in:
[modules/shaper.git] / src / SketchPlugin / SketchPlugin_Sketch.h
1 // File:        SketchPlugin_Sketch.h
2 // Created:     27 Mar 2014
3 // Author:      Mikhail PONIKAROV
4
5 #ifndef SketchPlugin_Sketch_HeaderFile
6 #define SketchPlugin_Sketch_HeaderFile
7
8 #include "SketchPlugin.h"
9 #include <SketchPlugin_Feature.h>
10 #include <GeomAPI_Pnt.h>
11 #include <GeomAPI_Pln.h>
12 #include <list>
13
14 /**\class SketchPlugin_Sketch
15  * \ingroup DataModel
16  * \brief Feature for creation of the new part in PartSet.
17  */
18 class SketchPlugin_Sketch: public SketchPlugin_Feature
19 {
20 public:
21   /// Sketch feature kind
22   inline static const std::string& ID()
23   {
24     static const std::string MY_SKETCH_ID("Sketch");
25     return MY_SKETCH_ID;
26   }
27   /// Origin point of the sketcher in 3D space
28   inline static const std::string& ORIGIN_ID()
29   {
30     static const std::string MY_ORIGIN_ID("Origin");
31     return MY_ORIGIN_ID;
32   }
33   /// Vector X inside of the sketch plane
34   inline static const std::string& DIRX_ID()
35   {
36     static const std::string MY_DIRX_ID("DirX");
37     return MY_DIRX_ID;
38   }
39   /// Vector Y inside of the sketch plane
40   inline static const std::string& DIRY_ID()
41   {
42     static const std::string MY_DIRY_ID("DirY");
43     return MY_DIRY_ID;
44   }
45   /// Vector Z, normal to the sketch plane
46   inline static const std::string& NORM_ID()
47   {
48     static const std::string MY_NORM_ID("Norm");
49     return MY_NORM_ID;
50   }
51   /// All features of this sketch (list of references)
52   inline static const std::string& FEATURES_ID()
53   {
54     static const std::string MY_FEATURES_ID("Features");
55     return MY_FEATURES_ID;
56   }
57
58   /// Returns the kind of a feature
59   SKETCHPLUGIN_EXPORT virtual const std::string& getKind() 
60   {static std::string MY_KIND = SketchPlugin_Sketch::ID(); return MY_KIND;}
61
62   /// Returns to which group in the document must be added feature
63   SKETCHPLUGIN_EXPORT virtual const std::string& getGroup() 
64   {static std::string MY_GROUP = "Construction"; return MY_GROUP;}
65
66   /// Creates a new part document if needed
67   SKETCHPLUGIN_EXPORT virtual void execute();
68
69   /// Request for initialization of data model of the feature: adding all attributes
70   SKETCHPLUGIN_EXPORT virtual void initAttributes();
71
72   /// Returns the sketch preview
73   SKETCHPLUGIN_EXPORT virtual const boost::shared_ptr<GeomAPI_Shape>& preview();
74
75   /// Returns the AIS preview
76   SKETCHPLUGIN_EXPORT virtual boost::shared_ptr<GeomAPI_AISObject> getAISObject(
77                                 boost::shared_ptr<GeomAPI_AISObject> thePrevious);
78
79   /// Adds sub-feature of the higher level feature (sub-element of the sketch)
80   /// \param theFeature sub-feature
81   SKETCHPLUGIN_EXPORT virtual const void addSub(
82     const FeaturePtr& theFeature);
83
84   /// Moves the feature
85   /// \param theDeltaX the delta for X coordinate is moved
86   /// \param theDeltaY the delta for Y coordinate is moved
87   SKETCHPLUGIN_EXPORT virtual void move(const double theDeltaX, const double theDeltaY) {};
88
89   /// Return the distance between the feature and the point
90   /// \param thePoint the point
91   virtual double distanceToPoint(const boost::shared_ptr<GeomAPI_Pnt2d>& thePoint) { return 0; };
92
93   /// Converts a 2D sketch space point into point in 3D space
94   SKETCHPLUGIN_EXPORT boost::shared_ptr<GeomAPI_Pnt> to3D(
95     const double theX, const double theY);
96
97   /// Returns true if this feature must be displayed in the history (top level of Part tree)
98   SKETCHPLUGIN_EXPORT virtual bool isInHistory() {return true;}
99
100   /// Use plugin manager for features creation
101   SketchPlugin_Sketch();
102
103   /// Returns the basis plane for the sketch
104   boost::shared_ptr<GeomAPI_Pln> plane();
105 protected:
106   /// Creates a plane and append it to the list
107   /// \param theX the X normal value
108   /// \param theY the Y normal value
109   /// \param theZ the Z normal value
110   /// \param theShapes the list of result shapes
111   void addPlane(double theX, double theY, double theZ,
112                 std::list<boost::shared_ptr<GeomAPI_Shape> >& theShapes) const;
113
114   /// Checks whether the plane is set in the sketch.
115   /// \returns the boolean state
116   bool isPlaneSet();
117 };
118
119 #endif