]> SALOME platform Git repositories - modules/shaper.git/blob - src/SketchPlugin/SketchPlugin_ConstraintLength.h
Salome HOME
Issue #394 Undo-ing a Sketch element
[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 #define LENGTH_COLOR "#ff00ff"
18
19 /** \class SketchPlugin_ConstraintLength
20  *  \ingroup Plugins
21  *  \brief Feature for creation of a new constraint which defines a length of a line segment
22  *
23  *  This constraint has two attributes:
24  *  SketchPlugin_Constraint::VALUE() (length) and SketchPlugin_Constraint::ENTITY_A() (segment),
25  *  SketchPlugin_Constraint::FLYOUT_VALUE_PNT() (distance of a constraints handle)
26  */
27 class SketchPlugin_ConstraintLength : public SketchPlugin_ConstraintBase
28 {
29  public:
30   /// Length constraint kind
31   inline static const std::string& ID()
32   {
33     static const std::string MY_CONSTRAINT_LENGTH_ID("SketchConstraintLength");
34     return MY_CONSTRAINT_LENGTH_ID;
35   }
36   /// \brief Returns the kind of a feature
37   SKETCHPLUGIN_EXPORT virtual const std::string& getKind()
38   {
39     static std::string MY_KIND = SketchPlugin_ConstraintLength::ID();
40     return MY_KIND;
41   }
42
43   /// \brief Creates a new part document if needed
44   SKETCHPLUGIN_EXPORT virtual void execute();
45
46   /// Computes the attribute value on the base of other attributes if the value can be computed
47   /// \param theAttributeId an attribute index to be computed
48   /// \return a boolean value about it is computed
49   SKETCHPLUGIN_EXPORT virtual bool compute(const std::string& theAttributeId);
50
51   /// \brief Request for initialization of data model of the feature: adding all attributes
52   SKETCHPLUGIN_EXPORT virtual void initAttributes();
53
54   /// Returns the AIS preview
55   SKETCHPLUGIN_EXPORT virtual AISObjectPtr getAISObject(AISObjectPtr thePrevious);
56
57   /// Moves the feature
58   /// \param theDeltaX the delta for X coordinate is moved
59   /// \param theDeltaY the delta for Y coordinate is moved
60   SKETCHPLUGIN_EXPORT virtual void move(const double theDeltaX, const double theDeltaY);
61
62   /// Called on change of any argument-attribute of this object
63   /// \param theID identifier of changed attribute
64   SKETCHPLUGIN_EXPORT virtual void attributeChanged(const std::string& theID);
65
66   /// \brief Use plugin manager for features creation
67   SketchPlugin_ConstraintLength();
68
69 private:
70   // retrns the points-base of length, returns false if it is not possible
71   bool getPoints(
72     std::shared_ptr<GeomAPI_Pnt>& thePoint1, std::shared_ptr<GeomAPI_Pnt>& thePoint2,
73     std::shared_ptr<GeomDataAPI_Point2D>& theStartPoint,
74     std::shared_ptr<GeomDataAPI_Point2D>& theEndPoint);
75 };
76
77 #endif