Salome HOME
Copyright update 2020
[modules/shaper.git] / src / SketcherPrs / SketcherPrs_Tools.h
1 // Copyright (C) 2014-2020  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 SketcherPrs_Tools_H
21 #define SketcherPrs_Tools_H
22
23 #include "SketcherPrs.h"
24 #include <GeomAPI_Shape.h>
25 #include <GeomAPI_Pnt2d.h>
26 #include <GeomAPI_Ax3.h>
27 #include <ModelAPI_Object.h>
28 #include <ModelAPI_Attribute.h>
29 #include <ModelAPI_Feature.h>
30 #include <ModelAPI_CompositeFeature.h>
31 #include <ModelAPI_Result.h>
32 #include <string>
33
34 #include <Events_Loop.h>
35 #include <Events_Message.h>
36
37 class GeomDataAPI_Point2D;
38 class AIS_Dimension;
39
40 namespace SketcherPrs_Tools {
41
42   /// \enum ParameterStyle lists styles of parameter
43   enum ParameterStyle {
44     ParameterValue, ///< using symbol with the parameter value
45     ParameterText ///< using parameter text
46   };
47
48   /// Set dimensions parameters style
49   /// \param theStyle new style
50   SKETCHERPRS_EXPORT void setParameterStyle(ParameterStyle theStyle);
51
52   /// Return dimensions parameters style
53   SKETCHERPRS_EXPORT ParameterStyle parameterStyle();
54
55   /// Enumeration with modes for activation of selection custom presentations
56   enum SelectionModes {
57     /// Start of enumeration
58     Sel_Mode_First = 100,
59
60     /// Selection mode for all constraints exclude dimensions
61     Sel_Constraint,
62
63     /// Selection mode for whole dimension
64     Sel_Dimension_All,
65
66     /// Selection mode for line of dimension
67     Sel_Dimension_Line,
68
69     /// Selection mode for text of dimension
70     Sel_Dimension_Text,
71
72     /// Selectiom mode for faces selection on sketch
73     Sel_Sketch_Face,
74
75     /// Selectiom mode for wires selection on sketch
76     Sel_Sketch_Wire
77   };
78
79   /// Type of angle
80   enum AngleType{
81     ANGLE_DIRECT,   ///< Angle from the first line to the second line
82     ANGLE_COMPLEMENTARY,  ///< Additional angle to the angle from first to second line
83     ANGLE_BACKWARD ///< Angle from the second line to the first line
84   };
85
86   /// Type of dimension location
87   enum LocationType{
88     LOCATION_RIGHT,   ///< Position is marked by right arrow placed on the left
89     LOCATION_AUTOMATIC,  ///< Position is marked by two arrow placed on the both sides
90     LOCATION_LEFT ///< Position is marked by left arrow placed on the left
91   };
92
93   /// Event ID about expression visual state has been changed, the symbol with a digit
94   /// or parameter text is shown
95
96   /// Returns attribute object referenced by feature
97   /// \param theFeature a feature
98   /// \param theAttrName an attribute name
99   SKETCHERPRS_EXPORT AttributePtr getAttribute(ModelAPI_Feature* theFeature,
100                                                const std::string& theAttrName);
101
102   /// Returns result object referenced by feature
103   /// \param theFeature a feature
104   /// \param theAttrName an attribute name
105   SKETCHERPRS_EXPORT ObjectPtr getResult(ModelAPI_Feature* theFeature,
106                                          const std::string& theAttrName);
107
108   /// Returns shape from result object (or NULL)
109   /// \param theObject a result object
110   SKETCHERPRS_EXPORT std::shared_ptr<GeomAPI_Shape> getShape(ObjectPtr theObject);
111
112
113   /// Returns point from a line feature
114   /// \param theFeature a line feature
115   /// \param theAttrName an attribute of the point
116   SKETCHERPRS_EXPORT std::shared_ptr<GeomAPI_Pnt2d> getPoint(ModelAPI_Feature* theFeature,
117                                           const std::string& theAttrName);
118
119
120   /// Returns point projected on a line
121   /// \param theLine  a line
122   /// \param thePoint a projecting point
123   SKETCHERPRS_EXPORT std::shared_ptr<GeomAPI_Pnt2d> getProjectionPoint(
124                         const FeaturePtr theLine,
125                         const std::shared_ptr<GeomAPI_Pnt2d>& thePoint);
126
127   SKETCHERPRS_EXPORT FeaturePtr getFeatureLine(DataPtr theData,
128                                                const std::string& theAttribute);
129
130   /// Obtain the point object from specified constraint parameter
131   /// \param theData a data object
132   /// \param theAttribute an attribute name
133   /// \param thePlane a projection plane (sketcher plane)
134   SKETCHERPRS_EXPORT std::shared_ptr<GeomDataAPI_Point2D> getFeaturePoint(DataPtr theData,
135                                                const std::string& theAttribute,
136                                                const std::shared_ptr<GeomAPI_Ax3>& thePlane);
137
138   /// Collect all sketch points which are not connected with other entities.
139   /// \param theSketch sketch feature
140   /// \return list of results of SketchPlugin_Point features
141   SKETCHERPRS_EXPORT std::list<ResultPtr> getFreePoints(const CompositeFeaturePtr& theSketch);
142
143   /// Returns value of dimension arrows size
144   SKETCHERPRS_EXPORT double getArrowSize();
145
146   /// Set value of dimension arrows size
147   /// \param theSize a size value
148   SKETCHERPRS_EXPORT void setArrowSize(double theSize);
149
150   /// Returns default value of dimension arrows size
151   SKETCHERPRS_EXPORT int getDefaultArrowSize();
152
153   /// Returns value of dimension arrows size set in preferences
154   SKETCHERPRS_EXPORT int getConfigArrowSize();
155
156   /// Set value of dimension text height
157   /// \param theHeight a height value
158   SKETCHERPRS_EXPORT void setTextHeight(double theHeight);
159
160   /// Returns value of dimension text height
161   SKETCHERPRS_EXPORT double getTextHeight();
162
163   /// Returns default value of dimension text height
164   SKETCHERPRS_EXPORT double getDefaultTextHeight();
165
166   /// Returns value of dimension text height set in preferences
167   SKETCHERPRS_EXPORT double getConfigTextHeight();
168
169   /// Get flayout distance of the dimension constraint
170   /// \param theConstraint a dimension constraint object
171   SKETCHERPRS_EXPORT double getFlyoutDistance(const ModelAPI_Feature* theConstraint);
172
173   /// Compute anchor pint for radius dimension
174   SKETCHERPRS_EXPORT std::shared_ptr<GeomAPI_Pnt> getAnchorPoint(
175                                               const ModelAPI_Feature* theConstraint,
176                                               const std::shared_ptr<GeomAPI_Ax3>& thePlane);
177
178   /// Throws an exception(in debug mode) and sends a signal about necessity to hide the object
179   /// \param theFeature a feature where AIS presentation is empty
180   /// \param theError a debug error information
181   SKETCHERPRS_EXPORT void sendEmptyPresentationError(ModelAPI_Feature* theFeature,
182                                                      const std::string theError);
183
184   SKETCHERPRS_EXPORT void setPixelRatio(int theRatio);
185
186   SKETCHERPRS_EXPORT int pixelRatio();
187 };
188
189 #endif