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