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