Salome HOME
Merge branch 'master' into Dev_1.1.0
[modules/shaper.git] / src / SketchPlugin / SketchPlugin_ConstraintDistance.h
1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D -->
2
3 // File:    SketchPlugin_ConstraintDistance.h
4 // Created: 23 May 2014
5 // Author:  Artem ZHIDKOV
6
7 #ifndef SketchPlugin_ConstraintDistance_H_
8 #define SketchPlugin_ConstraintDistance_H_
9
10 #include "SketchPlugin.h"
11 #include "SketchPlugin_ConstraintBase.h"
12 #include "SketchPlugin_Sketch.h"
13 #include "ModelAPI_Data.h"
14
15 #include <list>
16
17 class SketchPlugin_Line;
18 class GeomDataAPI_Point2D;
19
20 /** \class SketchPlugin_ConstraintDistance
21  *  \ingroup Plugins
22  *  \brief Feature for creation of a new constraint which defines a distance
23  *         between a point and another feature (point, line, plane or face)
24  *
25  *  This constraint has three attributes:
26  *  SketchPlugin_Constraint::VALUE(), SketchPlugin_Constraint::ENTITY_A() and SketchPlugin_Constraint::ENTITY_B()
27  */
28 class SketchPlugin_ConstraintDistance : public SketchPlugin_ConstraintBase
29 {
30  public:
31   /// Distance constraint kind
32   inline static const std::string& ID()
33   {
34     static const std::string MY_CONSTRAINT_DISTANCE_ID("SketchConstraintDistance");
35     return MY_CONSTRAINT_DISTANCE_ID;
36   }
37
38   /// \brief Returns the kind of a feature
39   SKETCHPLUGIN_EXPORT virtual const std::string& getKind()
40   {
41     static std::string MY_KIND = SketchPlugin_ConstraintDistance::ID();
42     return MY_KIND;
43   }
44
45   /// \brief Creates a new part document if needed
46   SKETCHPLUGIN_EXPORT virtual void execute();
47
48   /// Computes the attribute value on the base of other attributes if the value can be computed
49   /// \param theAttributeId an attribute index to be computed
50   /// \return a boolean value about it is computed
51   SKETCHPLUGIN_EXPORT virtual bool compute(const std::string& theAttributeId);
52
53   /// \brief Request for initialization of data model of the feature: adding all attributes
54   SKETCHPLUGIN_EXPORT virtual void initAttributes();
55
56   /// Returns the AIS preview
57   SKETCHPLUGIN_EXPORT virtual AISObjectPtr getAISObject(AISObjectPtr thePrevious);
58
59   /// Moves the feature
60   /// \param theDeltaX the delta for X coordinate is moved
61   /// \param theDeltaY the delta for Y coordinate is moved
62   SKETCHPLUGIN_EXPORT virtual void move(const double theDeltaX, const double theDeltaY);
63
64   /// Called on change of any argument-attribute of this object
65   /// \param theID identifier of changed attribute
66   SKETCHPLUGIN_EXPORT virtual void attributeChanged(const std::string& theID);
67
68   /// Returns the current distance between the feature attributes
69   double calculateCurrentDistance() const;
70
71   /// \brief Use plugin manager for features creation
72   SketchPlugin_ConstraintDistance();
73 };
74
75 /// Obtain the point object from specified constraint parameter
76 std::shared_ptr<GeomDataAPI_Point2D> getFeaturePoint(DataPtr theData,
77                                                        const std::string& theAttribute);
78
79 std::shared_ptr<SketchPlugin_Line> getFeatureLine(DataPtr theData,
80                                                     const std::string& theAttribute);
81
82 std::shared_ptr<GeomAPI_Pnt2d> getProjectionPoint(
83     const std::shared_ptr<SketchPlugin_Line>& theLine,
84     const std::shared_ptr<GeomAPI_Pnt2d>& thePoint);
85
86 #endif