1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D
3 // File: SketcherPrs_Tools.h
4 // Created: 10 March 2015
5 // Author: Vitaly SMETANNIKOV
7 #ifndef SketcherPrs_Tools_H
8 #define SketcherPrs_Tools_H
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>
19 #include <Events_Loop.h>
20 #include <Events_Message.h>
22 class GeomDataAPI_Point2D;
24 class Handle_Prs3d_DimensionAspect;
26 //#define MyTextHeight 20
28 /// Message that document (Part, PartSet) was created
29 class SketcherPrs_ParameterStyleMessage : public Events_Message
32 /// \enum ParameterStyle lists styles of parameter
34 ParameterValue, ///< using symbol with the parameter value
35 ParameterText ///< using parameter text
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()
48 static const char * MY_EVENT_PARAMETER_STYLE_ID("ParameterStyle");
49 return Events_Loop::eventByName(MY_EVENT_PARAMETER_STYLE_ID);
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; }
56 ParameterStyle myStyle; /// style of the parameter visualization
59 namespace SketcherPrs_Tools {
61 /// Enumeration with modes for activation of selection custom presentations
63 /// Start of enumeration
66 /// Selection mode for all constraints exclude dimensions
69 /// Selection mode for whole dimension
72 /// Selection mode for line of dimension
75 /// Selection mode foe text of dimension
81 ANGLE_DIRECT, ///< Angle from the first line to the second line
82 ANGLE_COMPLEMENTARY, ///< Additional angle to the angle from first to second line
83 ANGLE_BACKWARD ///< Angle from the second line to the first line
86 /// Event ID about expression visual state has been changed, the symbol with a digit
87 /// or parameter text is shown
89 /// Returns attribute object referenced by feature
90 /// \param theFeature a feature
91 /// \param theAttrName an attribute name
92 SKETCHERPRS_EXPORT AttributePtr getAttribute(ModelAPI_Feature* theFeature,
93 const std::string& theAttrName);
95 /// Returns result object referenced by feature
96 /// \param theFeature a feature
97 /// \param theAttrName an attribute name
98 SKETCHERPRS_EXPORT ObjectPtr getResult(ModelAPI_Feature* theFeature,
99 const std::string& theAttrName);
101 /// Returns shape from result object (or NULL)
102 /// \param theObject a result object
103 SKETCHERPRS_EXPORT std::shared_ptr<GeomAPI_Shape> getShape(ObjectPtr theObject);
106 /// Returns point from a line feature
107 /// \param theFeature a line feature
108 /// \param theAttrName an attribute of the point
109 SKETCHERPRS_EXPORT std::shared_ptr<GeomAPI_Pnt2d> getPoint(ModelAPI_Feature* theFeature,
110 const std::string& theAttrName);
113 /// Returns point projected on a line
114 /// \param theLine a line
115 /// \param thePoint a projecting point
116 SKETCHERPRS_EXPORT std::shared_ptr<GeomAPI_Pnt2d> getProjectionPoint(
117 const FeaturePtr theLine,
118 const std::shared_ptr<GeomAPI_Pnt2d>& thePoint);
120 SKETCHERPRS_EXPORT FeaturePtr getFeatureLine(DataPtr theData,
121 const std::string& theAttribute);
123 /// Obtain the point object from specified constraint parameter
124 /// \param theData a data object
125 /// \param theAttribute an attribute name
126 /// \param thePlane a projection plane (sketcher plane)
127 SKETCHERPRS_EXPORT std::shared_ptr<GeomDataAPI_Point2D> getFeaturePoint(DataPtr theData,
128 const std::string& theAttribute,
129 const std::shared_ptr<GeomAPI_Ax3>& thePlane);
131 /// Returns value of dimension arrows size
132 SKETCHERPRS_EXPORT double getArrowSize();
134 /// Set value of dimension arrows size
135 /// \param theSize a size value
136 SKETCHERPRS_EXPORT void setArrowSize(double theSize);
138 /// Returns default value of dimension arrows size
139 SKETCHERPRS_EXPORT int getDefaultArrowSize();
141 /// Set value of dimension text height
142 /// \param theHeight a height value
143 SKETCHERPRS_EXPORT void setTextHeight(double theHeight);
145 /// Returns value of dimension text height
146 SKETCHERPRS_EXPORT double getTextHeight();
148 /// Returns default value of dimension text height
149 SKETCHERPRS_EXPORT double getDefaultTextHeight();
151 /// Get flayout distance of the dimension constraint
152 /// \param theConstraint a dimension constraint object
153 SKETCHERPRS_EXPORT double getFlyoutDistance(const ModelAPI_Feature* theConstraint);
155 /// Compute anchor pint for radius dimension
156 SKETCHERPRS_EXPORT std::shared_ptr<GeomAPI_Pnt> getAnchorPoint(
157 const ModelAPI_Feature* theConstraint,
158 const std::shared_ptr<GeomAPI_Ax3>& thePlane);
160 /// Display/hide sigma symbol in the dimension presentation
161 /// \param theDimension a dimension constraint
162 /// \param theToDisplay a boolean value
163 SKETCHERPRS_EXPORT void setDisplaySpecialSymbol(AIS_Dimension* theDimension,
164 const bool& theToDisplay);
166 /// Display the parameter value instead of dimention digit
167 /// \param theDimension a dimension constraint
168 /// \param theParameter a parameter value
169 /// \param theToDisplay a boolean value
170 SKETCHERPRS_EXPORT void setDisplayParameter(AIS_Dimension* theDimension,
171 const std::string& theParameter,
172 const bool& theToDisplay);
174 /// Sends event about expression visualization type is changed for dimension presentations
175 /// Sends event to redisplay all sub-features of composite feature
176 /// \param theState a new state
177 SKETCHERPRS_EXPORT void sendExpressionShownEvent(const bool& theState);
179 /// Creates an aspect to be shown in length/radius dimension presentations
180 /// \return an instance of aspect
181 SKETCHERPRS_EXPORT Handle_Prs3d_DimensionAspect createDimensionAspect();
183 /// Update variable aspect parameters (depending on viewer scale)
184 /// \param theDimAspect an aspect to be changed
185 /// \param theDimValue an arrow value
186 /// \param theTextSize an arrow value
187 SKETCHERPRS_EXPORT void updateArrows(Handle_Prs3d_DimensionAspect theDimAspect,
188 double theDimValue, double theTextSize);
190 /// Throws an exception(in debug mode) and sends a signal about necessity to hide the object
191 /// \param theFeature a feature where AIS presentation is empty
192 /// \param theError a debug error information
193 SKETCHERPRS_EXPORT void sendEmptyPresentationError(ModelAPI_Feature* theFeature,
194 const std::string theError);