Salome HOME
Redesign of operations architecture
[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_H_
6 #define SketchPlugin_Sketch_H_
7
8 #include "SketchPlugin.h"
9 #include <SketchPlugin_Feature.h>
10 #include <GeomAPI_Pnt.h>
11 #include <GeomAPI_Pln.h>
12 #include <GeomAPI_IPresentable.h>
13 #include <list>
14
15 /// the plane edge color
16 #define SKETCH_PLANE_COLOR "#700000" 
17
18 /// the plane edge width
19 #define SKETCH_WIDTH        "4"
20
21 /// face of the square-face displayed for selection of general plane
22 #define PLANE_SIZE          "200"     
23
24 /**\class SketchPlugin_Sketch
25  * \ingroup DataModel
26  * \brief Feature for creation of the new part in PartSet.
27  */
28 class SketchPlugin_Sketch : public ModelAPI_CompositeFeature//, public GeomAPI_IPresentable
29 {
30  public:
31   /// Sketch feature kind
32   inline static const std::string& ID()
33   {
34     static const std::string MY_SKETCH_ID("Sketch");
35     return MY_SKETCH_ID;
36   }
37   /// Origin point of the sketcher in 3D space
38   inline static const std::string& ORIGIN_ID()
39   {
40     static const std::string MY_ORIGIN_ID("Origin");
41     return MY_ORIGIN_ID;
42   }
43   /// Vector X inside of the sketch plane
44   inline static const std::string& DIRX_ID()
45   {
46     static const std::string MY_DIRX_ID("DirX");
47     return MY_DIRX_ID;
48   }
49   /// Vector Y inside of the sketch plane
50   inline static const std::string& DIRY_ID()
51   {
52     static const std::string MY_DIRY_ID("DirY");
53     return MY_DIRY_ID;
54   }
55   /// Vector Z, normal to the sketch plane
56   inline static const std::string& NORM_ID()
57   {
58     static const std::string MY_NORM_ID("Norm");
59     return MY_NORM_ID;
60   }
61   /// All features of this sketch (list of references)
62   inline static const std::string& FEATURES_ID()
63   {
64     static const std::string MY_FEATURES_ID("Features");
65     return MY_FEATURES_ID;
66   }
67
68   /// Returns the kind of a feature
69   SKETCHPLUGIN_EXPORT virtual const std::string& getKind()
70   {
71     static std::string MY_KIND = SketchPlugin_Sketch::ID();
72     return MY_KIND;
73   }
74
75   /// Creates a new part document if needed
76   SKETCHPLUGIN_EXPORT virtual void execute();
77
78   /// Request for initialization of data model of the feature: adding all attributes
79   SKETCHPLUGIN_EXPORT virtual void initAttributes();
80
81   /// Moves the feature
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)
85   {
86   }
87   ;
88
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)
92   {
93     return 0;
94   }
95   ;
96
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);
99
100   /// Returns true if this feature must be displayed in the history (top level of Part tree)
101   SKETCHPLUGIN_EXPORT virtual bool isInHistory()
102   {
103     return true;
104   }
105
106   /// Use plugin manager for features creation
107   SketchPlugin_Sketch();
108
109   /// Returns the basis plane for the sketch
110   std::shared_ptr<GeomAPI_Pln> plane();
111
112   //virtual AISObjectPtr getAISObject(AISObjectPtr thePrevious);
113
114   /// removes also all sub-sketch elements
115   SKETCHPLUGIN_EXPORT virtual void erase();
116
117   SKETCHPLUGIN_EXPORT virtual std::shared_ptr<ModelAPI_Feature> addFeature(std::string theID);
118
119   /// Returns the number of sub-elements
120   SKETCHPLUGIN_EXPORT virtual int numberOfSubs() const;
121
122   /// Returns the sub-feature by zero-base index
123   SKETCHPLUGIN_EXPORT virtual std::shared_ptr<ModelAPI_Feature> 
124     subFeature(const int theIndex) const;
125
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;
128
129   /// Returns true if feature or reuslt belong to this composite feature as subs
130   SKETCHPLUGIN_EXPORT virtual bool isSub(ObjectPtr theObject) const;
131
132   /// Construction result is allways recomuted on the fly
133   SKETCHPLUGIN_EXPORT virtual bool isPersistentResult() {return false;}
134
135   /// Returns the point projected into the sketch plane
136   std::shared_ptr<GeomAPI_Pnt2d> to2D(const std::shared_ptr<GeomAPI_Pnt>& thePnt);
137
138   SKETCHPLUGIN_EXPORT virtual void attributeChanged();
139 protected:
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;
147
148   /// Checks whether the plane is set in the sketch.
149   /// \returns the boolean state
150   bool isPlaneSet();
151 };
152
153 #endif