Salome HOME
Adjust validator of tangent constraint attributes for arc-arc tangency
[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 <GeomAPI_Ax3.h>
16 #include <list>
17
18 #define YZ_PLANE_COLOR "#ff0000"
19 #define XZ_PLANE_COLOR "#00ff00"
20 #define XY_PLANE_COLOR "#0000ff"
21
22 /**\class SketchPlugin_Sketch
23  * \ingroup Plugins
24  * \brief Feature for creation of the new part in PartSet.
25  */
26 class SketchPlugin_Sketch : public ModelAPI_CompositeFeature//, public GeomAPI_IPresentable
27 {
28  public:
29   /// Sketch feature kind
30   inline static const std::string& ID()
31   {
32     static const std::string MY_SKETCH_ID("Sketch");
33     return MY_SKETCH_ID;
34   }
35   /// Origin point of the sketcher in 3D space
36   inline static const std::string& ORIGIN_ID()
37   {
38     static const std::string MY_ORIGIN_ID("Origin");
39     return MY_ORIGIN_ID;
40   }
41   /// Vector X inside of the sketch plane
42   inline static const std::string& DIRX_ID()
43   {
44     static const std::string MY_DIRX_ID("DirX");
45     return MY_DIRX_ID;
46   }
47   /// Vector Z, normal to the sketch plane
48   inline static const std::string& NORM_ID()
49   {
50     static const std::string MY_NORM_ID("Norm");
51     return MY_NORM_ID;
52   }
53   /// All features of this sketch (list of references)
54   inline static const std::string& FEATURES_ID()
55   {
56     static const std::string MY_FEATURES_ID("Features");
57     return MY_FEATURES_ID;
58   }
59
60   /// Returns the kind of a feature
61   SKETCHPLUGIN_EXPORT virtual const std::string& getKind()
62   {
63     static std::string MY_KIND = SketchPlugin_Sketch::ID();
64     return MY_KIND;
65   }
66
67   /// Creates a new part document if needed
68   SKETCHPLUGIN_EXPORT virtual void execute();
69
70   /// Request for initialization of data model of the feature: adding all attributes
71   SKETCHPLUGIN_EXPORT virtual void initAttributes();
72
73   /// Moves the feature
74   /// \param theDeltaX the delta for X coordinate is moved
75   /// \param theDeltaY the delta for Y coordinate is moved
76   SKETCHPLUGIN_EXPORT virtual void move(const double theDeltaX, const double theDeltaY)
77   {
78   }
79
80   /// Return the distance between the feature and the point
81   /// \param thePoint the point
82   virtual double distanceToPoint(const std::shared_ptr<GeomAPI_Pnt2d>& thePoint)
83   {
84     return 0;
85   }
86
87   /// Converts a 2D sketch space point into point in 3D space
88   SKETCHPLUGIN_EXPORT std::shared_ptr<GeomAPI_Pnt> to3D(const double theX, const double theY);
89
90   /// Returns true if this feature must be displayed in the history (top level of Part tree)
91   SKETCHPLUGIN_EXPORT virtual bool isInHistory()
92   {
93     return true;
94   }
95
96   /// Use plugin manager for features creation
97   SketchPlugin_Sketch();
98
99   /// Returns the basis plane for the sketch
100   std::shared_ptr<GeomAPI_Pln> plane();
101
102   SKETCHPLUGIN_EXPORT std::shared_ptr<GeomAPI_Ax3> coordinatePlane() const;
103
104   //virtual AISObjectPtr getAISObject(AISObjectPtr thePrevious);
105
106   /// removes also all sub-sketch elements
107   SKETCHPLUGIN_EXPORT virtual void erase();
108
109   /// appends a feature to the sketch sub-elements container
110   SKETCHPLUGIN_EXPORT virtual std::shared_ptr<ModelAPI_Feature> addFeature(std::string theID);
111
112   /// Just to synchronise the container of sub-features
113   virtual void removeFeature(std::shared_ptr<ModelAPI_Feature> theFeature);
114
115   /// Returns the number of sub-elements
116   SKETCHPLUGIN_EXPORT virtual int numberOfSubs() const;
117
118   /// Returns the sub-feature by zero-base index
119   SKETCHPLUGIN_EXPORT virtual std::shared_ptr<ModelAPI_Feature> 
120     subFeature(const int theIndex) const;
121
122   /// Returns the sub-feature unique identifier in this composite feature by zero-base index
123   SKETCHPLUGIN_EXPORT virtual int subFeatureId(const int theIndex) const;
124
125   /// Returns true if feature or reuslt belong to this composite feature as subs
126   SKETCHPLUGIN_EXPORT virtual bool isSub(ObjectPtr theObject) const;
127
128   /// Construction result is allways recomuted on the fly
129   SKETCHPLUGIN_EXPORT virtual bool isPersistentResult() {return false;}
130
131   /// Returns the point projected into the sketch plane
132   std::shared_ptr<GeomAPI_Pnt2d> to2D(const std::shared_ptr<GeomAPI_Pnt>& thePnt);
133
134   SKETCHPLUGIN_EXPORT virtual void attributeChanged(const std::string& theID);
135 protected:
136   /// Checks whether the plane is set in the sketch.
137   /// \returns the boolean state
138   bool isPlaneSet();
139 };
140
141 #endif