Salome HOME
Reanud's patch for modern Cpp11 compilers applied
[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 #include <GeomAPI_ICustomPrs.h>
17
18 class SketchPlugin_Sketch;
19 class GeomAPI_Pnt2d;
20 class Handle_AIS_InteractiveObject;
21
22 /**\class SketchPlugin_Feature
23  * \ingroup DataModel
24  * \brief Feature for creation of the new feature in PartSet. This is an abstract class to give
25  * an interface to create the sketch feature preview.
26  */
27 class SketchPlugin_Feature : public ModelAPI_Feature, public GeomAPI_ICustomPrs
28 {
29  public:
30   /// Reference to the external edge or vertex as a AttributeSelection
31   inline static const std::string& EXTERNAL_ID()
32   {
33     static const std::string MY_EXTERNAL_ID("External");
34     return MY_EXTERNAL_ID;
35   }
36
37   /// Returns true if this feature must be displayed in the history (top level of Part tree)
38   SKETCHPLUGIN_EXPORT virtual bool isInHistory()
39   {
40     return false;
41   }
42
43   /// Moves the feature
44   /// \param theDeltaX the delta for X coordinate is moved
45   /// \param theDeltaY the delta for Y coordinate is moved
46   SKETCHPLUGIN_EXPORT virtual void move(const double theDeltaX, const double theDeltaY) = 0;
47
48   /// Return the distance between the feature and the point
49   /// \param thePoint the point
50   virtual double distanceToPoint(const std::shared_ptr<GeomAPI_Pnt2d>& thePoint) = 0;
51
52   /// Construction result is allways recomuted on the fly
53   SKETCHPLUGIN_EXPORT virtual bool isPersistentResult() {return false;}
54
55   /// Returns true is sketch element is under the rigid constraint
56   SKETCHPLUGIN_EXPORT virtual bool isFixed() {return false;}
57
58   inline bool isExternal() const
59   {
60     AttributeSelectionPtr aAttr = data()->selection(EXTERNAL_ID());
61     if (aAttr)
62       return aAttr->context().get();
63     return false;
64   }
65
66   /// Customize presentation of the feature
67   virtual void customisePresentation(AISObjectPtr thePrs)
68   {
69     // if this is an edge
70     if (thePrs->getShapeType() == 6)
71       thePrs->setWidth(3);
72     // if this is a vertex
73     //else if (thePrs->getShapeType() == 7)
74     //  thePrs->setPointMarker(6, 2.);
75   }
76
77   /// Returns the sketch of this feature
78   SketchPlugin_Sketch* sketch();
79 protected:
80   /// Sets the higher-level feature for the sub-feature (sketch for line)
81   void setSketch(SketchPlugin_Sketch* theSketch)
82   {
83     mySketch = theSketch;
84   }
85   /// initializes mySketch
86   SketchPlugin_Feature();
87
88   friend class SketchPlugin_Sketch;
89
90  private:
91   std::shared_ptr<GeomAPI_Shape> myPreview;  ///< the preview shape
92   SketchPlugin_Sketch* mySketch;  /// sketch that contains this feature
93 };
94
95 #endif