Salome HOME
cfc15dbfc6c06cb1dcc2c4cc9be00870963739e6
[modules/shaper.git] / src / SketcherPrs / SketcherPrs_Tools.h
1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D
2
3 // File:        SketcherPrs_Tools.h
4 // Created:     10 March 2015
5 // Author:      Vitaly SMETANNIKOV
6
7 #ifndef SketcherPrs_Tools_H
8 #define SketcherPrs_Tools_H
9
10 #include "SketcherPrs.h"
11 #include <GeomAPI_Shape.h>
12 #include <GeomAPI_Pnt2d.h>
13 #include <GeomAPI_Ax3.h>
14 #include <ModelAPI_Object.h>
15 #include <ModelAPI_Attribute.h>
16 #include <ModelAPI_Feature.h>
17 #include <string>
18
19 #include <Events_Loop.h>
20 #include <Events_Message.h>
21
22 class GeomDataAPI_Point2D;
23 class AIS_Dimension;
24 class Handle_Prs3d_DimensionAspect;
25
26 //#define MyTextHeight 20
27
28 /// Message that document (Part, PartSet) was created
29 class SketcherPrs_ParameterStyleMessage : public Events_Message
30 {
31 public:
32   /// \enum ParameterStyle lists styles of parameter
33   enum ParameterStyle {
34     ParameterValue, ///< using symbol with the parameter value
35     ParameterText ///< using parameter text
36   };
37
38 public:
39   /// Creates an empty message
40   SKETCHERPRS_EXPORT SketcherPrs_ParameterStyleMessage(const Events_ID theID,
41                                                     const void* theSender = 0)
42   : Events_Message(theID, theSender) {}
43   /// The virtual destructor
44   SKETCHERPRS_EXPORT virtual ~SketcherPrs_ParameterStyleMessage() {}
45   /// Static. Returns EventID of the message.
46   SKETCHERPRS_EXPORT static Events_ID eventId()
47   {
48     static const char * MY_EVENT_PARAMETER_STYLE_ID("ParameterStyle");
49     return Events_Loop::eventByName(MY_EVENT_PARAMETER_STYLE_ID);
50   }
51   /// Returns a document stored in the message
52   SKETCHERPRS_EXPORT ParameterStyle style() const { return myStyle; }
53   /// Sets a document to the message
54   SKETCHERPRS_EXPORT void setStyle(ParameterStyle theStyle) { myStyle = theStyle; }
55 private:
56   ParameterStyle myStyle; /// style of the parameter visualization
57 };
58
59 namespace SketcherPrs_Tools {
60
61   /// Enumeration with modes for activation of selection custom presentations
62   enum SelectionModes {
63     /// Start of enumeration
64     Sel_Mode_First = 100, 
65   
66     /// Selection mode for all constraints exclude dimensions
67     Sel_Constraint,
68   
69     /// Selection mode for whole dimension
70     Sel_Dimension_All,
71   
72     /// Selection mode for line of dimension
73     Sel_Dimension_Line,
74
75     /// Selection mode for text of dimension
76     Sel_Dimension_Text,
77
78     /// Selectiom mode for faces selection on sketch
79     Sel_Sketch_Face,
80
81     /// Selectiom mode for wires selection on sketch
82     Sel_Sketch_Wire
83   };
84
85   /// Type of angle
86   enum AngleType{
87     ANGLE_DIRECT,   ///< Angle from the first line to the second line
88     ANGLE_COMPLEMENTARY,  ///< Additional angle to the angle from first to second line
89     ANGLE_BACKWARD ///< Angle from the second line to the first line
90   };
91
92   /// Event ID about expression visual state has been changed, the symbol with a digit
93   /// or parameter text is shown
94
95   /// Returns attribute object referenced by feature
96   /// \param theFeature a feature
97   /// \param theAttrName an attribute name
98   SKETCHERPRS_EXPORT AttributePtr getAttribute(ModelAPI_Feature* theFeature,
99                                                const std::string& theAttrName);
100
101   /// Returns result object referenced by feature
102   /// \param theFeature a feature
103   /// \param theAttrName an attribute name
104   SKETCHERPRS_EXPORT ObjectPtr getResult(ModelAPI_Feature* theFeature,
105                                          const std::string& theAttrName);
106
107   /// Returns shape from result object (or NULL)
108   /// \param theObject a result object
109   SKETCHERPRS_EXPORT std::shared_ptr<GeomAPI_Shape> getShape(ObjectPtr theObject);
110
111
112   /// Returns point from a line feature
113   /// \param theFeature a line feature
114   /// \param theAttrName an attribute of the point
115   SKETCHERPRS_EXPORT std::shared_ptr<GeomAPI_Pnt2d> getPoint(ModelAPI_Feature* theFeature,
116                                           const std::string& theAttrName);
117
118
119   /// Returns point projected on a line
120   /// \param theLine  a line
121   /// \param thePoint a projecting point
122   SKETCHERPRS_EXPORT std::shared_ptr<GeomAPI_Pnt2d> getProjectionPoint(
123                         const FeaturePtr theLine,
124                         const std::shared_ptr<GeomAPI_Pnt2d>& thePoint);
125
126   SKETCHERPRS_EXPORT FeaturePtr getFeatureLine(DataPtr theData,
127                                                const std::string& theAttribute);
128
129   /// Obtain the point object from specified constraint parameter
130   /// \param theData a data object
131   /// \param theAttribute an attribute name
132   /// \param thePlane a projection plane (sketcher plane)
133   SKETCHERPRS_EXPORT std::shared_ptr<GeomDataAPI_Point2D> getFeaturePoint(DataPtr theData,
134                                                        const std::string& theAttribute,
135                                                        const std::shared_ptr<GeomAPI_Ax3>& thePlane);
136
137   /// Returns value of dimension arrows size
138   SKETCHERPRS_EXPORT double getArrowSize();
139
140   /// Set value of dimension arrows size
141   /// \param theSize a size value
142   SKETCHERPRS_EXPORT void setArrowSize(double theSize);
143
144   /// Returns default value of dimension arrows size
145   SKETCHERPRS_EXPORT int getDefaultArrowSize();
146
147   /// Set value of dimension text height
148   /// \param theHeight a height value
149   SKETCHERPRS_EXPORT void setTextHeight(double theHeight);
150
151   /// Returns value of dimension text height
152   SKETCHERPRS_EXPORT double getTextHeight();
153
154   /// Returns default value of dimension text height
155   SKETCHERPRS_EXPORT double getDefaultTextHeight();
156
157   /// Get flayout distance of the dimension constraint
158   /// \param theConstraint a dimension constraint object
159   SKETCHERPRS_EXPORT double getFlyoutDistance(const ModelAPI_Feature* theConstraint);
160
161   /// Compute anchor pint for radius dimension
162   SKETCHERPRS_EXPORT std::shared_ptr<GeomAPI_Pnt> getAnchorPoint(
163                                               const ModelAPI_Feature* theConstraint,
164                                               const std::shared_ptr<GeomAPI_Ax3>& thePlane);
165
166   /// Display/hide sigma symbol in the dimension presentation
167   /// \param theDimension a dimension constraint
168   /// \param theToDisplay a boolean value
169   SKETCHERPRS_EXPORT void setDisplaySpecialSymbol(AIS_Dimension* theDimension,
170                                                   const bool& theToDisplay);
171
172   /// Display the parameter value instead of dimention digit
173   /// \param theDimension a dimension constraint
174   /// \param theParameter a parameter value
175   /// \param theToDisplay a boolean value
176   SKETCHERPRS_EXPORT void setDisplayParameter(AIS_Dimension* theDimension,
177                                               const std::string& theParameter,
178                                               const bool& theToDisplay);
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   /// Creates an aspect to be shown in length/radius dimension presentations
186   /// \return an instance of aspect
187   SKETCHERPRS_EXPORT Handle_Prs3d_DimensionAspect createDimensionAspect();
188
189   /// Update variable aspect parameters (depending on viewer scale)
190   /// \param theDimAspect an aspect to be changed
191   /// \param theDimValue an arrow value
192   /// \param theTextSize an arrow value
193   SKETCHERPRS_EXPORT void updateArrows(Handle_Prs3d_DimensionAspect theDimAspect,
194                                        double theDimValue, double theTextSize);
195
196   /// Throws an exception(in debug mode) and sends a signal about necessity to hide the object
197   /// \param theFeature a feature where AIS presentation is empty
198   /// \param theError a debug error information
199   SKETCHERPRS_EXPORT void sendEmptyPresentationError(ModelAPI_Feature* theFeature,
200                                                      const std::string theError);
201 };
202
203 #endif