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