1 // Copyright (C) 2014-2023 CEA, EDF
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.
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.
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
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
20 #ifndef SketchPlugin_ConstraintAngle_H_
21 #define SketchPlugin_ConstraintAngle_H_
23 #include "SketchPlugin.h"
24 #include "SketchPlugin_Sketch.h"
25 #include "SketchPlugin_ConstraintBase.h"
27 #include <ModelAPI_IReentrant.h>
29 /** \class SketchPlugin_ConstraintAngle
31 * \brief Feature for creation of a new constraint fix angle between two lines
33 * This constraint has two attributes:
34 * SketchPlugin_Constraint::ENTITY_A() and SketchPlugin_Constraint::ENTITY_B()
36 class SketchPlugin_ConstraintAngle : public SketchPlugin_ConstraintBase,
37 public ModelAPI_IReentrant
40 /// Angle constraint kind
41 inline static const std::string& ID()
43 static const std::string MY_CONSTRAINT_ANGLE_ID("SketchConstraintAngle");
44 return MY_CONSTRAINT_ANGLE_ID;
46 /// \brief Returns the kind of a feature
47 SKETCHPLUGIN_EXPORT virtual const std::string& getKind()
49 static std::string MY_KIND = SketchPlugin_ConstraintAngle::ID();
53 /// attribute name of operation type
54 inline static const std::string& TYPE_ID()
56 static const std::string MY_TYPE_ID("AngleType");
59 /// attribute name of previous value of operation type
60 inline static const std::string& PREV_TYPE_ID()
62 static const std::string MY_TYPE_ID("AngleTypePrevious");
66 /// attribute name of operation type
67 inline static const std::string& ANGLE_VALUE_ID()
69 static const std::string MY_ANGLE_VALUE_ID("AngleValue");
70 return MY_ANGLE_VALUE_ID;
73 /// attribute name indicating the first line is reversed
74 inline static const std::string& ANGLE_REVERSED_FIRST_LINE_ID()
76 static const std::string MY_ANGLE_REVERSED_ID("AngleReversedLine1");
77 return MY_ANGLE_REVERSED_ID;
79 /// attribute name indicating the second line is reversed
80 inline static const std::string& ANGLE_REVERSED_SECOND_LINE_ID()
82 static const std::string MY_ANGLE_REVERSED_ID("AngleReversedLine2");
83 return MY_ANGLE_REVERSED_ID;
86 /// attribute name of dimension location type
87 inline static const std::string& LOCATION_TYPE_ID()
89 static const std::string MY_LOCATION_TYPE_ID("LocationType");
90 return MY_LOCATION_TYPE_ID;
93 /// attribute name indicating the first point selected
94 inline static const std::string& SELECTED_FIRST_POINT_ID()
96 static const std::string MY_SELECTED_FIRST_POINT_ID("SelectedPointA");
97 return MY_SELECTED_FIRST_POINT_ID;
100 /// attribute name indicating the second point selected
101 inline static const std::string& SELECTED_SECOND_POINT_ID()
103 static const std::string MY_SELECTED_SECOND_POINT_ID("SelectedPointB");
104 return MY_SELECTED_SECOND_POINT_ID;
108 static const int THE_VERSION_0 = 0;
109 static const int THE_VERSION_1 = 20191210;
111 /// Attribute name of the version of Angle feature
112 inline static const std::string& VERSION_ID()
114 static const std::string MY_VERSION_ID("version");
115 return MY_VERSION_ID;
119 /// \brief Creates a new part document if needed
120 SKETCHPLUGIN_EXPORT virtual void execute();
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);
127 /// \brief Request for initialization of data model of the feature: adding all attributes
128 SKETCHPLUGIN_EXPORT virtual void initAttributes();
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);
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);
138 /// Returns the AIS preview
139 SKETCHPLUGIN_EXPORT virtual AISObjectPtr getAISObject(AISObjectPtr thePrevious);
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);
145 /// \brief Use plugin manager for features creation
146 SketchPlugin_ConstraintAngle();
149 /// Calculate current value of the angle
150 void calculateAngle();
152 /// Compute the position of the angle presentation (the quarter selected by the user)
153 void calculateAnglePosition();
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);
161 /// Update value of ANGLE_VALUE attribute according to the current type
162 void updateAngleValue();
164 /// Update parameters of the Angle to meet requirements for the latest version
165 void updateVersion();
168 bool myFlyoutUpdate; ///< to avoid cyclic dependencies on automatic updates of flyout point