Salome HOME
Merge branch 'Dev_1.1.0' of newgeom:newgeom.git into Dev_1.1.0
[modules/shaper.git] / src / SketchPlugin / SketchPlugin_ConstraintLength.h
1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D -->
2
3 // File:    SketchPlugin_ConstraintLength.h
4 // Created: 30 May 2014
5 // Author:  Artem ZHIDKOV
6
7 #ifndef SketchPlugin_ConstraintLength_H_
8 #define SketchPlugin_ConstraintLength_H_
9
10 #include "SketchPlugin.h"
11 #include "SketchPlugin_ConstraintBase.h"
12 #include <SketchPlugin_Sketch.h>
13 #include <list>
14
15 class GeomDataAPI_Point2D;
16
17 /** \class SketchPlugin_ConstraintLength
18  *  \ingroup Plugins
19  *  \brief Feature for creation of a new constraint which defines a length of a line segment
20  *
21  *  This constraint has two attributes:
22  *  SketchPlugin_Constraint::VALUE() (length) and SketchPlugin_Constraint::ENTITY_A() (segment),
23  *  SketchPlugin_Constraint::FLYOUT_VALUE_PNT() (distance of a constraints handle)
24  */
25 class SketchPlugin_ConstraintLength : public SketchPlugin_ConstraintBase
26 {
27  public:
28   /// Length constraint kind
29   inline static const std::string& ID()
30   {
31     static const std::string MY_CONSTRAINT_LENGTH_ID("SketchConstraintLength");
32     return MY_CONSTRAINT_LENGTH_ID;
33   }
34   /// \brief Returns the kind of a feature
35   SKETCHPLUGIN_EXPORT virtual const std::string& getKind()
36   {
37     static std::string MY_KIND = SketchPlugin_ConstraintLength::ID();
38     return MY_KIND;
39   }
40
41   /// \brief Creates a new part document if needed
42   SKETCHPLUGIN_EXPORT virtual void execute();
43
44   /// Computes the attribute value on the base of other attributes if the value can be computed
45   /// \param theAttributeId an attribute index to be computed
46   /// \return a boolean value about it is computed
47   SKETCHPLUGIN_EXPORT virtual bool compute(const std::string& theAttributeId);
48
49   /// \brief Request for initialization of data model of the feature: adding all attributes
50   SKETCHPLUGIN_EXPORT virtual void initAttributes();
51
52   /// Returns the AIS preview
53   SKETCHPLUGIN_EXPORT virtual AISObjectPtr getAISObject(AISObjectPtr thePrevious);
54
55   /// Moves the feature
56   /// \param theDeltaX the delta for X coordinate is moved
57   /// \param theDeltaY the delta for Y coordinate is moved
58   SKETCHPLUGIN_EXPORT virtual void move(const double theDeltaX, const double theDeltaY);
59
60   /// Called on change of any argument-attribute of this object
61   /// \param theID identifier of changed attribute
62   SKETCHPLUGIN_EXPORT virtual void attributeChanged(const std::string& theID);
63
64   /// \brief Use plugin manager for features creation
65   SketchPlugin_ConstraintLength();
66
67 private:
68   // retrns the points-base of length, returns false if it is not possible
69   bool getPoints(
70     std::shared_ptr<GeomAPI_Pnt>& thePoint1, std::shared_ptr<GeomAPI_Pnt>& thePoint2,
71     std::shared_ptr<GeomDataAPI_Point2D>& theStartPoint,
72     std::shared_ptr<GeomDataAPI_Point2D>& theEndPoint);
73
74 private:
75   bool myFlyoutUpdate; ///< to avoid cyclic dependencies on automatic updates of flyout point
76 };
77
78 #endif