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