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