Salome HOME
ae0c78a8bcd70945819693965648dc4a3e1eb7c7
[modules/shaper.git] / src / SketchPlugin / SketchPlugin_ConstraintAngle.h
1 // Copyright (C) 2014-2023  CEA/DEN, EDF R&D
2 //
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License, or (at your option) any later version.
7 //
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11 // Lesser General Public License for more details.
12 //
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
16 //
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 //
19
20 #ifndef SketchPlugin_ConstraintAngle_H_
21 #define SketchPlugin_ConstraintAngle_H_
22
23 #include "SketchPlugin.h"
24 #include "SketchPlugin_Sketch.h"
25 #include "SketchPlugin_ConstraintBase.h"
26
27 #include <ModelAPI_IReentrant.h>
28
29 /** \class SketchPlugin_ConstraintAngle
30  *  \ingroup Plugins
31  *  \brief Feature for creation of a new constraint fix angle between two lines
32  *
33  *  This constraint has two attributes:
34  *  SketchPlugin_Constraint::ENTITY_A() and SketchPlugin_Constraint::ENTITY_B()
35  */
36 class SketchPlugin_ConstraintAngle : public SketchPlugin_ConstraintBase,
37                                      public ModelAPI_IReentrant
38 {
39 public:
40   /// Angle constraint kind
41   inline static const std::string& ID()
42   {
43     static const std::string MY_CONSTRAINT_ANGLE_ID("SketchConstraintAngle");
44     return MY_CONSTRAINT_ANGLE_ID;
45   }
46   /// \brief Returns the kind of a feature
47   SKETCHPLUGIN_EXPORT virtual const std::string& getKind()
48   {
49     static std::string MY_KIND = SketchPlugin_ConstraintAngle::ID();
50     return MY_KIND;
51   }
52
53   /// attribute name of operation type
54   inline static const std::string& TYPE_ID()
55   {
56     static const std::string MY_TYPE_ID("AngleType");
57     return MY_TYPE_ID;
58   }
59   /// attribute name of previous value of operation type
60   inline static const std::string& PREV_TYPE_ID()
61   {
62     static const std::string MY_TYPE_ID("AngleTypePrevious");
63     return MY_TYPE_ID;
64   }
65
66   /// attribute name of operation type
67   inline static const std::string& ANGLE_VALUE_ID()
68   {
69     static const std::string MY_ANGLE_VALUE_ID("AngleValue");
70     return MY_ANGLE_VALUE_ID;
71   }
72
73   /// attribute name indicating the first line is reversed
74   inline static const std::string& ANGLE_REVERSED_FIRST_LINE_ID()
75   {
76     static const std::string MY_ANGLE_REVERSED_ID("AngleReversedLine1");
77     return MY_ANGLE_REVERSED_ID;
78   }
79   /// attribute name indicating the second line is reversed
80   inline static const std::string& ANGLE_REVERSED_SECOND_LINE_ID()
81   {
82     static const std::string MY_ANGLE_REVERSED_ID("AngleReversedLine2");
83     return MY_ANGLE_REVERSED_ID;
84   }
85
86   /// attribute name of dimension location type
87   inline static const std::string& LOCATION_TYPE_ID()
88   {
89     static const std::string MY_LOCATION_TYPE_ID("LocationType");
90     return MY_LOCATION_TYPE_ID;
91   }
92
93   /// attribute name indicating the first point selected
94   inline static const std::string& SELECTED_FIRST_POINT_ID()
95   {
96     static const std::string MY_SELECTED_FIRST_POINT_ID("SelectedPointA");
97     return MY_SELECTED_FIRST_POINT_ID;
98   }
99
100   /// attribute name indicating the second point selected
101   inline static const std::string& SELECTED_SECOND_POINT_ID()
102   {
103     static const std::string MY_SELECTED_SECOND_POINT_ID("SelectedPointB");
104     return MY_SELECTED_SECOND_POINT_ID;
105   }
106
107 public:
108   static const int THE_VERSION_0 = 0;
109   static const int THE_VERSION_1 = 20191210;
110
111   /// Attribute name of the version of Angle feature
112   inline static const std::string& VERSION_ID()
113   {
114     static const std::string MY_VERSION_ID("version");
115     return MY_VERSION_ID;
116   }
117
118 public:
119   /// \brief Creates a new part document if needed
120   SKETCHPLUGIN_EXPORT virtual void execute();
121
122   /// Computes the attribute value on the base of other attributes if the value can be computed
123   /// \param theAttributeId an attribute index to be computed
124   /// \return a boolean value about it is computed
125   SKETCHPLUGIN_EXPORT virtual bool compute(const std::string& theAttributeId);
126
127   /// \brief Request for initialization of data model of the feature: adding all attributes
128   SKETCHPLUGIN_EXPORT virtual void initAttributes();
129
130   /// Retuns the parameters of color definition in the resources config manager
131   SKETCHPLUGIN_EXPORT virtual void colorConfigInfo(std::string& theSection, std::string& theName,
132                                                    std::string& theDefault);
133
134   /// Called on change of any argument-attribute of this object
135   /// \param theID identifier of changed attribute
136   SKETCHPLUGIN_EXPORT virtual void attributeChanged(const std::string& theID);
137
138   /// Returns the AIS preview
139   SKETCHPLUGIN_EXPORT virtual AISObjectPtr getAISObject(AISObjectPtr thePrevious);
140
141   /// Apply information of the message to current object.
142   /// It fills selected point and the first object.
143   virtual std::string processEvent(const std::shared_ptr<Events_Message>& theMessage);
144
145   /// \brief Use plugin manager for features creation
146   SketchPlugin_ConstraintAngle();
147
148 protected:
149   /// Calculate current value of the angle
150   void calculateAngle();
151
152   /// Compute the position of the angle presentation (the quarter selected by the user)
153   void calculateAnglePosition();
154
155   /// Converts the angle value according to the current angle type and sketch plane normal.
156   /// The in/out angle is in degree.
157   /// \param theAngle a source for the calculated angle
158   /// \param a double angle value
159   double getAngleForType(double theAngle, bool isReversed1 = false, bool isReversed2 = false);
160
161   /// Update value of ANGLE_VALUE attribute according to the current type
162   void updateAngleValue();
163
164   /// Update parameters of the Angle to meet requirements for the latest version
165   void updateVersion();
166
167 private:
168   bool myFlyoutUpdate; ///< to avoid cyclic dependencies on automatic updates of flyout point
169 };
170
171 #endif