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