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