Salome HOME
Merge branch 'master' into cgt/devCEA
[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   /// Event ID about expression visual state has been changed, the symbol with a digit
107   /// or parameter text is shown
108
109   /// Returns attribute object referenced by feature
110   /// \param theFeature a feature
111   /// \param theAttrName an attribute name
112   SKETCHERPRS_EXPORT AttributePtr getAttribute(ModelAPI_Feature* theFeature,
113                                                const std::string& theAttrName);
114
115   /// Returns result object referenced by feature
116   /// \param theFeature a feature
117   /// \param theAttrName an attribute name
118   SKETCHERPRS_EXPORT ObjectPtr getResult(ModelAPI_Feature* theFeature,
119                                          const std::string& theAttrName);
120
121   /// Returns shape from result object (or NULL)
122   /// \param theObject a result object
123   SKETCHERPRS_EXPORT std::shared_ptr<GeomAPI_Shape> getShape(ObjectPtr theObject);
124
125
126   /// Returns point from a line feature
127   /// \param theFeature a line feature
128   /// \param theAttrName an attribute of the point
129   SKETCHERPRS_EXPORT std::shared_ptr<GeomAPI_Pnt2d> getPoint(ModelAPI_Feature* theFeature,
130                                           const std::string& theAttrName);
131
132
133   /// Returns point projected on a line
134   /// \param theLine  a line
135   /// \param thePoint a projecting point
136   SKETCHERPRS_EXPORT std::shared_ptr<GeomAPI_Pnt2d> getProjectionPoint(
137                         const FeaturePtr theLine,
138                         const std::shared_ptr<GeomAPI_Pnt2d>& thePoint);
139
140   SKETCHERPRS_EXPORT FeaturePtr getFeatureLine(DataPtr theData,
141                                                const std::string& theAttribute);
142
143   /// Obtain the point object from specified constraint parameter
144   /// \param theData a data object
145   /// \param theAttribute an attribute name
146   /// \param thePlane a projection plane (sketcher plane)
147   SKETCHERPRS_EXPORT std::shared_ptr<GeomDataAPI_Point2D> getFeaturePoint(DataPtr theData,
148                                                const std::string& theAttribute,
149                                                const std::shared_ptr<GeomAPI_Ax3>& thePlane);
150
151   /// Returns value of dimension arrows size
152   SKETCHERPRS_EXPORT double getArrowSize();
153
154   /// Set value of dimension arrows size
155   /// \param theSize a size value
156   SKETCHERPRS_EXPORT void setArrowSize(double theSize);
157
158   /// Returns default value of dimension arrows size
159   SKETCHERPRS_EXPORT int getDefaultArrowSize();
160
161   /// Set value of dimension text height
162   /// \param theHeight a height value
163   SKETCHERPRS_EXPORT void setTextHeight(double theHeight);
164
165   /// Returns value of dimension text height
166   SKETCHERPRS_EXPORT double getTextHeight();
167
168   /// Returns default value of dimension text height
169   SKETCHERPRS_EXPORT double getDefaultTextHeight();
170
171   /// Get flayout distance of the dimension constraint
172   /// \param theConstraint a dimension constraint object
173   SKETCHERPRS_EXPORT double getFlyoutDistance(const ModelAPI_Feature* theConstraint);
174
175   /// Compute anchor pint for radius dimension
176   SKETCHERPRS_EXPORT std::shared_ptr<GeomAPI_Pnt> getAnchorPoint(
177                                               const ModelAPI_Feature* theConstraint,
178                                               const std::shared_ptr<GeomAPI_Ax3>& thePlane);
179
180   /// Sends event about expression visualization type is changed for dimension presentations
181   /// Sends event to redisplay all sub-features of composite feature
182   /// \param theState a new state
183   SKETCHERPRS_EXPORT void sendExpressionShownEvent(const bool& theState);
184
185   /// Throws an exception(in debug mode) and sends a signal about necessity to hide the object
186   /// \param theFeature a feature where AIS presentation is empty
187   /// \param theError a debug error information
188   SKETCHERPRS_EXPORT void sendEmptyPresentationError(ModelAPI_Feature* theFeature,
189                                                      const std::string theError);
190 };
191
192 #endif