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