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