Salome HOME
Merge branch 'Dev_0.6.1' of newgeom:newgeom into Dev_0.6.1
[modules/shaper.git] / src / SketchPlugin / SketchPlugin_Feature.h
1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D -->
2
3 // File:        SketchPlugin_Feature.h
4 // Created:     27 Mar 2014
5 // Author:      Mikhail PONIKAROV
6
7 #ifndef SketchPlugin_Feature_H_
8 #define SketchPlugin_Feature_H_
9
10 #include "SketchPlugin.h"
11 #include <ModelAPI_CompositeFeature.h>
12 #include <GeomAPI_Shape.h>
13 #include <GeomAPI_AISObject.h>
14 #include <ModelAPI_Document.h>
15 #include <ModelAPI_AttributeSelection.h>
16
17 class SketchPlugin_Sketch;
18 class GeomAPI_Pnt2d;
19 class Handle_AIS_InteractiveObject;
20
21 /**\class SketchPlugin_Feature
22  * \ingroup DataModel
23  * \brief Feature for creation of the new feature in PartSet. This is an abstract class to give
24  * an interface to create the sketch feature preview.
25  */
26 class SketchPlugin_Feature : public ModelAPI_Feature
27 {
28  public:
29   /// Simple creation of interactive object by the result of the object
30   static AISObjectPtr simpleAISObject(std::shared_ptr<ModelAPI_Result> theRes,
31                                       AISObjectPtr thePrevious);
32
33   /// Reference to the external edge or vertex as a AttributeSelection
34   inline static const std::string& EXTERNAL_ID()
35   {
36     static const std::string MY_EXTERNAL_ID("External");
37     return MY_EXTERNAL_ID;
38   }
39
40   /// Returns true if this feature must be displayed in the history (top level of Part tree)
41   SKETCHPLUGIN_EXPORT virtual bool isInHistory()
42   {
43     return false;
44   }
45
46   /// Moves the feature
47   /// \param theDeltaX the delta for X coordinate is moved
48   /// \param theDeltaY the delta for Y coordinate is moved
49   SKETCHPLUGIN_EXPORT virtual void move(const double theDeltaX, const double theDeltaY) = 0;
50
51   /// Return the distance between the feature and the point
52   /// \param thePoint the point
53   virtual double distanceToPoint(const std::shared_ptr<GeomAPI_Pnt2d>& thePoint) = 0;
54
55   /// Construction result is allways recomuted on the fly
56   SKETCHPLUGIN_EXPORT virtual bool isPersistentResult() {return false;}
57
58   /// Returns true is sketch element is under the rigid constraint
59   SKETCHPLUGIN_EXPORT virtual bool isFixed() {return false;}
60
61   inline bool isExternal() const
62   {
63     AttributeSelectionPtr aAttr = data()->selection(EXTERNAL_ID());
64     if (aAttr)
65       return aAttr->context();
66     return false;
67   }
68
69   /// Returns the sketch of this feature
70   SketchPlugin_Sketch* sketch();
71 protected:
72   /// Sets the higher-level feature for the sub-feature (sketch for line)
73   void setSketch(SketchPlugin_Sketch* theSketch)
74   {
75     mySketch = theSketch;
76   }
77   /// initializes mySketch
78   SketchPlugin_Feature();
79
80   friend class SketchPlugin_Sketch;
81
82  private:
83   std::shared_ptr<GeomAPI_Shape> myPreview;  ///< the preview shape
84   SketchPlugin_Sketch* mySketch;  /// sketch that contains this feature
85 };
86
87 #endif