Salome HOME
2.17. Improved management of overconstraint situation: dimension constraints are...
[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
14 #include <GeomAPI_ICustomPrs.h>
15
16 #include <list>
17
18 class GeomDataAPI_Point2D;
19
20 /** \class SketchPlugin_ConstraintLength
21  *  \ingroup Plugins
22  *  \brief Feature for creation of a new constraint which defines a length of a line segment
23  *
24  *  This constraint has two attributes:
25  *  SketchPlugin_Constraint::VALUE() (length) and SketchPlugin_Constraint::ENTITY_A() (segment),
26  *  SketchPlugin_Constraint::FLYOUT_VALUE_PNT() (distance of a constraints handle)
27  */
28 class SketchPlugin_ConstraintLength : public SketchPlugin_ConstraintBase
29 {
30  public:
31   /// Length constraint kind
32   inline static const std::string& ID()
33   {
34     static const std::string MY_CONSTRAINT_LENGTH_ID("SketchConstraintLength");
35     return MY_CONSTRAINT_LENGTH_ID;
36   }
37   /// \brief Returns the kind of a feature
38   SKETCHPLUGIN_EXPORT virtual const std::string& getKind()
39   {
40     static std::string MY_KIND = SketchPlugin_ConstraintLength::ID();
41     return MY_KIND;
42   }
43
44   /// \brief Creates a new part document if needed
45   SKETCHPLUGIN_EXPORT virtual void execute();
46
47   /// Computes the attribute value on the base of other attributes if the value can be computed
48   /// \param theAttributeId an attribute index to be computed
49   /// \return a boolean value about it is computed
50   SKETCHPLUGIN_EXPORT virtual bool compute(const std::string& theAttributeId);
51
52   /// \brief Request for initialization of data model of the feature: adding all attributes
53   SKETCHPLUGIN_EXPORT virtual void initAttributes();
54
55   /// Retuns the parameters of color definition in the resources config manager
56   SKETCHPLUGIN_EXPORT virtual void colorConfigInfo(std::string& theSection, std::string& theName,
57                                                    std::string& theDefault);
58
59   /// Returns the AIS preview
60   SKETCHPLUGIN_EXPORT virtual AISObjectPtr getAISObject(AISObjectPtr thePrevious);
61
62   /// Moves the feature
63   /// \param theDeltaX the delta for X coordinate is moved
64   /// \param theDeltaY the delta for Y coordinate is moved
65   SKETCHPLUGIN_EXPORT virtual void move(const double theDeltaX, const double theDeltaY);
66
67   /// Called on change of any argument-attribute of this object
68   /// \param theID identifier of changed attribute
69   SKETCHPLUGIN_EXPORT virtual void attributeChanged(const std::string& theID);
70
71   /// \brief Use plugin manager for features creation
72   SketchPlugin_ConstraintLength();
73
74 private:
75   // retrns the points-base of length, returns false if it is not possible
76   bool getPoints(
77     std::shared_ptr<GeomAPI_Pnt>& thePoint1, std::shared_ptr<GeomAPI_Pnt>& thePoint2,
78     std::shared_ptr<GeomDataAPI_Point2D>& theStartPoint,
79     std::shared_ptr<GeomDataAPI_Point2D>& theEndPoint);
80
81 private:
82   bool myFlyoutUpdate; ///< to avoid cyclic dependencies on automatic updates of flyout point
83 };
84
85 #endif