Salome HOME
Unit test for moving group after BuildPlugin_Face feature
[modules/shaper.git] / src / SketcherPrs / SketcherPrs_Tools.h
1 // Copyright (C) 2014-2017  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
18 // email : webmaster.salome@opencascade.com<mailto:webmaster.salome@opencascade.com>
19 //
20
21 #ifndef SketcherPrs_Tools_H
22 #define SketcherPrs_Tools_H
23
24 #include "SketcherPrs.h"
25 #include <GeomAPI_Shape.h>
26 #include <GeomAPI_Pnt2d.h>
27 #include <GeomAPI_Ax3.h>
28 #include <ModelAPI_Object.h>
29 #include <ModelAPI_Attribute.h>
30 #include <ModelAPI_Feature.h>
31 #include <string>
32
33 #include <Events_Loop.h>
34 #include <Events_Message.h>
35
36 class GeomDataAPI_Point2D;
37 class AIS_Dimension;
38
39 //#define MyTextHeight 20
40
41 /// Message that style of visualization of parameter is changed.
42 /// It will be shown as expression or value
43 class SketcherPrs_ParameterStyleMessage : public Events_Message
44 {
45 public:
46   /// \enum ParameterStyle lists styles of parameter
47   enum ParameterStyle {
48     ParameterValue, ///< using symbol with the parameter value
49     ParameterText ///< using parameter text
50   };
51
52 public:
53   /// Creates an empty message
54   SKETCHERPRS_EXPORT SketcherPrs_ParameterStyleMessage(const Events_ID theID,
55                                                     const void* theSender = 0)
56   : Events_Message(theID, theSender) {}
57   /// The virtual destructor
58   SKETCHERPRS_EXPORT virtual ~SketcherPrs_ParameterStyleMessage() {}
59   /// Static. Returns EventID of the message.
60   SKETCHERPRS_EXPORT static Events_ID eventId()
61   {
62     static const char * MY_EVENT_PARAMETER_STYLE_ID("ParameterStyle");
63     return Events_Loop::eventByName(MY_EVENT_PARAMETER_STYLE_ID);
64   }
65   /// Returns a document stored in the message
66   SKETCHERPRS_EXPORT ParameterStyle style() const { return myStyle; }
67   /// Sets a document to the message
68   SKETCHERPRS_EXPORT void setStyle(ParameterStyle theStyle) { myStyle = theStyle; }
69 private:
70   ParameterStyle myStyle; /// style of the parameter visualization
71 };
72
73 namespace SketcherPrs_Tools {
74
75   /// Enumeration with modes for activation of selection custom presentations
76   enum SelectionModes {
77     /// Start of enumeration
78     Sel_Mode_First = 100,
79
80     /// Selection mode for all constraints exclude dimensions
81     Sel_Constraint,
82
83     /// Selection mode for whole dimension
84     Sel_Dimension_All,
85
86     /// Selection mode for line of dimension
87     Sel_Dimension_Line,
88
89     /// Selection mode for text of dimension
90     Sel_Dimension_Text,
91
92     /// Selectiom mode for faces selection on sketch
93     Sel_Sketch_Face,
94
95     /// Selectiom mode for wires selection on sketch
96     Sel_Sketch_Wire
97   };
98
99   /// Type of angle
100   enum AngleType{
101     ANGLE_DIRECT,   ///< Angle from the first line to the second line
102     ANGLE_COMPLEMENTARY,  ///< Additional angle to the angle from first to second line
103     ANGLE_BACKWARD ///< Angle from the second line to the first line
104   };
105
106   /// Type of dimension location
107   enum LocationType{
108     LOCATION_RIGHT,   ///< Position is marked by right arrow placed on the left
109     LOCATION_AUTOMATIC,  ///< Position is marked by two arrow placed on the both sides
110     LOCATION_LEFT ///< Position is marked by left arrow placed on the left
111   };
112
113   /// Event ID about expression visual state has been changed, the symbol with a digit
114   /// or parameter text is shown
115
116   /// Returns attribute object referenced by feature
117   /// \param theFeature a feature
118   /// \param theAttrName an attribute name
119   SKETCHERPRS_EXPORT AttributePtr getAttribute(ModelAPI_Feature* theFeature,
120                                                const std::string& theAttrName);
121
122   /// Returns result object referenced by feature
123   /// \param theFeature a feature
124   /// \param theAttrName an attribute name
125   SKETCHERPRS_EXPORT ObjectPtr getResult(ModelAPI_Feature* theFeature,
126                                          const std::string& theAttrName);
127
128   /// Returns shape from result object (or NULL)
129   /// \param theObject a result object
130   SKETCHERPRS_EXPORT std::shared_ptr<GeomAPI_Shape> getShape(ObjectPtr theObject);
131
132
133   /// Returns point from a line feature
134   /// \param theFeature a line feature
135   /// \param theAttrName an attribute of the point
136   SKETCHERPRS_EXPORT std::shared_ptr<GeomAPI_Pnt2d> getPoint(ModelAPI_Feature* theFeature,
137                                           const std::string& theAttrName);
138
139
140   /// Returns point projected on a line
141   /// \param theLine  a line
142   /// \param thePoint a projecting point
143   SKETCHERPRS_EXPORT std::shared_ptr<GeomAPI_Pnt2d> getProjectionPoint(
144                         const FeaturePtr theLine,
145                         const std::shared_ptr<GeomAPI_Pnt2d>& thePoint);
146
147   SKETCHERPRS_EXPORT FeaturePtr getFeatureLine(DataPtr theData,
148                                                const std::string& theAttribute);
149
150   /// Obtain the point object from specified constraint parameter
151   /// \param theData a data object
152   /// \param theAttribute an attribute name
153   /// \param thePlane a projection plane (sketcher plane)
154   SKETCHERPRS_EXPORT std::shared_ptr<GeomDataAPI_Point2D> getFeaturePoint(DataPtr theData,
155                                                const std::string& theAttribute,
156                                                const std::shared_ptr<GeomAPI_Ax3>& thePlane);
157
158   /// Returns value of dimension arrows size
159   SKETCHERPRS_EXPORT double getArrowSize();
160
161   /// Set value of dimension arrows size
162   /// \param theSize a size value
163   SKETCHERPRS_EXPORT void setArrowSize(double theSize);
164
165   /// Returns default value of dimension arrows size
166   SKETCHERPRS_EXPORT int getDefaultArrowSize();
167
168   /// Returns value of dimension arrows size set in preferences
169   SKETCHERPRS_EXPORT int getConfigArrowSize();
170
171   /// Set value of dimension text height
172   /// \param theHeight a height value
173   SKETCHERPRS_EXPORT void setTextHeight(double theHeight);
174
175   /// Returns value of dimension text height
176   SKETCHERPRS_EXPORT double getTextHeight();
177
178   /// Returns default value of dimension text height
179   SKETCHERPRS_EXPORT double getDefaultTextHeight();
180
181   /// Returns value of dimension text height set in preferences
182   SKETCHERPRS_EXPORT double getConfigTextHeight();
183
184   /// Get flayout distance of the dimension constraint
185   /// \param theConstraint a dimension constraint object
186   SKETCHERPRS_EXPORT double getFlyoutDistance(const ModelAPI_Feature* theConstraint);
187
188   /// Compute anchor pint for radius dimension
189   SKETCHERPRS_EXPORT std::shared_ptr<GeomAPI_Pnt> getAnchorPoint(
190                                               const ModelAPI_Feature* theConstraint,
191                                               const std::shared_ptr<GeomAPI_Ax3>& thePlane);
192
193   /// Sends event about expression visualization type is changed for dimension presentations
194   /// Sends event to redisplay all sub-features of composite feature
195   /// \param theState a new state
196   SKETCHERPRS_EXPORT void sendExpressionShownEvent(const bool& theState);
197
198   /// Throws an exception(in debug mode) and sends a signal about necessity to hide the object
199   /// \param theFeature a feature where AIS presentation is empty
200   /// \param theError a debug error information
201   SKETCHERPRS_EXPORT void sendEmptyPresentationError(ModelAPI_Feature* theFeature,
202                                                      const std::string theError);
203 };
204
205 #endif