1 // Copyright (c) 1995-1999 Matra Datavision
2 // Copyright (c) 1999-2013 OPEN CASCADE SAS
4 // This file is part of Open CASCADE Technology software library.
6 // This library is free software; you can redistribute it and/or modify it under
7 // the terms of the GNU Lesser General Public License version 2.1 as published
8 // by the Free Software Foundation, with special exception defined in the file
9 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
10 // distribution for complete text of the license and disclaimer of any warranty.
12 // Alternatively, this file may be used under the terms of Open CASCADE
13 // commercial license or contractual agreement.
15 #ifndef _PrsDim_AngleDimension_HeaderFile
16 #define _PrsDim_AngleDimension_HeaderFile
18 #include <PrsDim_Dimension.hxx>
19 #include <PrsDim_TypeOfAngle.hxx>
20 #include <PrsDim_TypeOfAngleArrowVisibility.hxx>
22 #include <Geom_Plane.hxx>
23 #include <Geom_Line.hxx>
26 #include <Prs3d_DimensionAspect.hxx>
27 #include <Prs3d_Presentation.hxx>
28 #include <Standard.hxx>
29 #include <Standard_Macro.hxx>
30 #include <Standard_Type.hxx>
32 #include <TopoDS_Edge.hxx>
33 #include <TopoDS_Face.hxx>
34 #include <TopoDS_Vertex.hxx>
36 DEFINE_STANDARD_HANDLE(PrsDim_AngleDimension, PrsDim_Dimension)
38 //! Angle dimension. Can be constructed:
39 //! - on two intersected edges.
40 //! - on three points or vertices.
41 //! - on conical face.
42 //! - between two intersected faces.
44 //! In case of three points or two intersected edges the dimension plane
45 //! (on which dimension presentation is built) can be computed uniquely
46 //! as through three defined points can be built only one plane.
47 //! Therefore, if user-defined plane differs from this one, the dimension can't be built.
49 //! In cases of two planes automatic plane by default is built on point of the
50 //! origin of parametric space of the first face (the basis surface) so, that
51 //! the working plane and two faces intersection forms minimal angle between the faces.
52 //! User can define the other point which the dimension plane should pass through
53 //! using the appropriate constructor. This point can lay on the one of the faces or not.
54 //! Also user can define his own plane but it should pass through the three points
55 //! computed on the geometry initialization step (when the constructor or SetMeasuredGeometry() method
58 //! In case of the conical face the center point of the angle is the apex of the conical surface.
59 //! The attachment points are points of the first and the last parameter of the basis circle of the cone.
60 class PrsDim_AngleDimension : public PrsDim_Dimension
62 DEFINE_STANDARD_RTTIEXT(PrsDim_AngleDimension, PrsDim_Dimension)
65 //! Constructs minimum angle dimension between two linear edges (where possible).
66 //! These two edges should be intersected by each other. Otherwise the geometry is not valid.
67 //! @param theFirstEdge [in] the first edge.
68 //! @param theSecondEdge [in] the second edge.
69 Standard_EXPORT PrsDim_AngleDimension (const TopoDS_Edge& theFirstEdge,
70 const TopoDS_Edge& theSecondEdge);
72 //! Constructs the angle display object defined by three points.
73 //! @param theFirstPoint [in] the first point (point on first angle flyout).
74 //! @param theSecondPoint [in] the center point of angle dimension.
75 //! @param theThirdPoint [in] the second point (point on second angle flyout).
76 Standard_EXPORT PrsDim_AngleDimension (const gp_Pnt& theFirstPoint,
77 const gp_Pnt& theSecondPoint,
78 const gp_Pnt& theThirdPoint);
80 //! Constructs the angle display object defined by three vertices.
81 //! @param theFirstVertex [in] the first vertex (vertex for first angle flyout).
82 //! @param theSecondVertex [in] the center vertex of angle dimension.
83 //! @param theThirdPoint [in] the second vertex (vertex for second angle flyout).
84 Standard_EXPORT PrsDim_AngleDimension (const TopoDS_Vertex& theFirstVertex,
85 const TopoDS_Vertex& theSecondVertex,
86 const TopoDS_Vertex& theThirdVertex);
88 //! Constructs angle dimension for the cone face.
89 //! @param theCone [in] the conical face.
90 Standard_EXPORT PrsDim_AngleDimension (const TopoDS_Face& theCone);
92 //! Constructs angle dimension between two planar faces.
93 //! @param theFirstFace [in] the first face.
94 //! @param theSecondFace [in] the second face.
95 Standard_EXPORT PrsDim_AngleDimension (const TopoDS_Face& theFirstFace,
96 const TopoDS_Face& theSecondFace);
98 //! Constructs angle dimension between two planar faces.
99 //! @param theFirstFace [in] the first face.
100 //! @param theSecondFace [in] the second face.
101 //! @param thePoint [in] the point which the dimension plane should pass through.
102 //! This point can lay on the one of the faces or not.
103 Standard_EXPORT PrsDim_AngleDimension (const TopoDS_Face& theFirstFace,
104 const TopoDS_Face& theSecondFace,
105 const gp_Pnt& thePoint);
109 //! @return first point forming the angle.
110 const gp_Pnt& FirstPoint() const { return myFirstPoint; }
112 //! @return second point forming the angle.
113 const gp_Pnt& SecondPoint() const { return mySecondPoint; }
115 //! @return center point forming the angle.
116 const gp_Pnt& CenterPoint() const { return myCenterPoint; }
118 //! @return first argument shape.
119 const TopoDS_Shape& FirstShape() const { return myFirstShape; }
121 //! @return second argument shape.
122 const TopoDS_Shape& SecondShape() const { return mySecondShape; }
124 //! @return third argument shape.
125 const TopoDS_Shape& ThirdShape() const { return myThirdShape; }
129 //! Measures minimum angle dimension between two linear edges.
130 //! These two edges should be intersected by each other. Otherwise the geometry is not valid.
131 //! @param theFirstEdge [in] the first edge.
132 //! @param theSecondEdge [in] the second edge.
133 Standard_EXPORT void SetMeasuredGeometry (const TopoDS_Edge& theFirstEdge,
134 const TopoDS_Edge& theSecondEdge);
136 //! Measures angle defined by three points.
137 //! @param theFirstPoint [in] the first point (point on first angle flyout).
138 //! @param theSecondPoint [in] the center point of angle dimension.
139 //! @param theThirdPoint [in] the second point (point on second angle flyout).
140 Standard_EXPORT void SetMeasuredGeometry (const gp_Pnt& theFirstPoint,
141 const gp_Pnt& theSecondPoint,
142 const gp_Pnt& theThridPoint);
144 //! Measures angle defined by three vertices.
145 //! @param theFirstVertex [in] the first vertex (vertex for first angle flyout).
146 //! @param theSecondVertex [in] the center vertex of angle dimension.
147 //! @param theThirdPoint [in] the second vertex (vertex for second angle flyout).
148 Standard_EXPORT void SetMeasuredGeometry (const TopoDS_Vertex& theFirstVertex,
149 const TopoDS_Vertex& theSecondVertex,
150 const TopoDS_Vertex& theThirdVertex);
152 //! Measures angle of conical face.
153 //! @param theCone [in] the shape to measure.
154 Standard_EXPORT void SetMeasuredGeometry (const TopoDS_Face& theCone);
156 //! Measures angle between two planar faces.
157 //! @param theFirstFace [in] the first face.
158 //! @param theSecondFace [in] the second face..
159 Standard_EXPORT void SetMeasuredGeometry (const TopoDS_Face& theFirstFace,
160 const TopoDS_Face& theSecondFace);
162 //! Measures angle between two planar faces.
163 //! @param theFirstFace [in] the first face.
164 //! @param theSecondFace [in] the second face.
165 //! @param thePoint [in] the point which the dimension plane should pass through.
166 //! This point can lay on the one of the faces or not.
167 Standard_EXPORT void SetMeasuredGeometry (const TopoDS_Face& theFirstFace,
168 const TopoDS_Face& theSecondFace,
169 const gp_Pnt& thePoint);
171 //! @return the display units string.
172 Standard_EXPORT virtual const TCollection_AsciiString& GetDisplayUnits() const Standard_OVERRIDE;
174 //! @return the model units string.
175 Standard_EXPORT virtual const TCollection_AsciiString& GetModelUnits() const Standard_OVERRIDE;
177 Standard_EXPORT virtual void SetDisplayUnits (const TCollection_AsciiString& theUnits) Standard_OVERRIDE;
179 Standard_EXPORT virtual void SetModelUnits (const TCollection_AsciiString& theUnits) Standard_OVERRIDE;
181 //! Principle of horizontal text alignment settings:
182 //! - divide circle into two halves according to attachment points
183 //! - if aTextPos is between attach points -> Center + positive flyout
184 //! - if aTextPos is not between attach points but in this half -> Left or Right + positive flyout
185 //! - if aTextPos is between reflections of attach points -> Center + negative flyout
186 //! - if aTextPos is not between reflections of attach points -> Left or Right + negative flyout
187 Standard_EXPORT virtual void SetTextPosition (const gp_Pnt& theTextPos) Standard_OVERRIDE;
189 Standard_EXPORT virtual gp_Pnt GetTextPosition () const Standard_OVERRIDE;
192 //! @param theType [in] the type value.
193 void SetType (const PrsDim_TypeOfAngle theType) { myType = theType; }
195 //! @return the current angle type.
196 PrsDim_TypeOfAngle GetType() const { return myType; }
198 //! Sets visible arrows type
199 //! @param theType [in] the type of visibility of arrows.
200 void SetArrowsVisibility (const PrsDim_TypeOfAngleArrowVisibility& theType) { myArrowsVisibility = theType; }
202 //! @return the type of visibility of arrows.
203 PrsDim_TypeOfAngleArrowVisibility GetArrowsVisibility() const { return myArrowsVisibility; }
207 //! Initialization of fields that is common to all constructors.
208 Standard_EXPORT void Init();
210 //! Gets plane normal for minimal angle.
211 //! Dimension computation is based on three attach points and plane normal.
212 //! Based on this normal angle arc, arrows and extensions are constructed.
213 gp_Dir GetNormalForMinAngle() const;
215 //! @param theFirstAttach [in] the first attachment point.
216 //! @param theSecondAttach [in] the second attachment point.
217 //! @param theCenter [in] the center point (center point of the angle).
218 //! @return the center of the dimension arc (the main dimension line in case of angle).
219 Standard_EXPORT gp_Pnt GetCenterOnArc (const gp_Pnt& theFirstAttach,
220 const gp_Pnt& theSecondAttach,
221 const gp_Pnt& theCenter) const;
223 //! Draws main dimension line (arc).
224 //! @param thePresentation [in] the dimension presentation.
225 //! @param theFirstAttach [in] the first attachment point.
226 //! @param theSecondAttach [in] the second attachment point.
227 //! @param theCenter [in] the center point (center point of the angle).
228 //! @param theRadius [in] the radius of the dimension arc.
229 //! @param theMode [in] the display mode.
230 Standard_EXPORT void DrawArc (const Handle(Prs3d_Presentation)& thePresentation,
231 const gp_Pnt& theFirstAttach,
232 const gp_Pnt& theSecondAttach,
233 const gp_Pnt& theCenter,
234 const Standard_Real theRadius,
235 const Standard_Integer theMode);
237 //! Draws main dimension line (arc) with text.
238 //! @param thePresentation [in] the dimension presentation.
239 //! @param theFirstAttach [in] the first attachment point.
240 //! @param theSecondAttach [in] the second attachment point.
241 //! @param theCenter [in] the center point (center point of the angle).
242 //! @param theText [in] the text label string.
243 //! @param theTextWidth [in] the text label width.
244 //! @param theMode [in] the display mode.
245 //! @param theLabelPosition [in] the text label vertical and horizontal positioning option
246 //! respectively to the main dimension line.
247 Standard_EXPORT void DrawArcWithText (const Handle(Prs3d_Presentation)& thePresentation,
248 const gp_Pnt& theFirstAttach,
249 const gp_Pnt& theSecondAttach,
250 const gp_Pnt& theCenter,
251 const TCollection_ExtendedString& theText,
252 const Standard_Real theTextWidth,
253 const Standard_Integer theMode,
254 const Standard_Integer theLabelPosition);
256 //! Fits text alignment relatively to the dimension line;
257 //! it computes the value of label position and arrow orientation
258 //! according set in the aspect and dimension properties.
259 //! @param theHorizontalTextPos [in] the horizontal alignment for text position.
260 //! @param theLabelPosition [out] the label position, contains bits that defines
261 //! vertical and horizontal alignment. (for internal usage in count text position).
262 //! @param theIsArrowExternal [out] is the arrows external,
263 //! if arrow orientation in the dimension aspect is Prs3d_DAO_Fit, it fits arrow
264 //! orientation automatically.
265 Standard_EXPORT void FitTextAlignment (const Prs3d_DimensionTextHorizontalPosition& theHorizontalTextPos,
266 Standard_Integer& theLabelPosition,
267 Standard_Boolean& theIsArrowsExternal) const;
269 //! Adjusts aspect parameters according the text position:
270 //! extension size, vertical text alignment and flyout.
271 //! @param theTextPos [in] the user defined 3d point of text position.
272 //! @param theExtensionSize [out] the adjusted extension size.
273 //! @param theAlignment [out] the horizontal label alignment.
274 //! @param theFlyout [out] the adjusted value of flyout.
275 Standard_EXPORT void AdjustParameters (const gp_Pnt& theTextPos,
276 Standard_Real& theExtensionSize,
277 Prs3d_DimensionTextHorizontalPosition& theAlignment,
278 Standard_Real& theFlyout) const;
282 Standard_EXPORT virtual void ComputePlane();
284 //! Checks if the plane includes three angle points to build dimension.
285 Standard_EXPORT virtual Standard_Boolean CheckPlane (const gp_Pln& thePlane) const Standard_OVERRIDE;
287 Standard_EXPORT virtual Standard_Real ComputeValue() const Standard_OVERRIDE;
289 Standard_EXPORT virtual void Compute (const Handle(PrsMgr_PresentationManager)& thePM,
290 const Handle(Prs3d_Presentation)& thePresentation,
291 const Standard_Integer theMode = 0) Standard_OVERRIDE;
293 Standard_EXPORT virtual void ComputeFlyoutSelection (const Handle(SelectMgr_Selection)& theSelection,
294 const Handle(SelectMgr_EntityOwner)& theOwner) Standard_OVERRIDE;
298 //! Init angular dimension to measure angle between two linear edges.
299 //! @return TRUE if the angular dimension can be constructured
300 //! for the passed edges.
301 Standard_EXPORT Standard_Boolean InitTwoEdgesAngle (gp_Pln& theComputedPlane);
303 //! Init angular dimension to measure angle between two planar faces.
304 //! there is no user-defined poisitoning. So attach points are set
305 //! according to faces geometry (in origin of the first face basis surface).
306 //! @return TRUE if the angular dimension can be constructed
307 //! for the passed faces.
308 Standard_EXPORT Standard_Boolean InitTwoFacesAngle();
310 //! Init angular dimension to measure angle between two planar faces.
311 //! @param thePointOnFirstFace [in] the point which the dimension plane should pass through.
312 //! This point can lay on the one of the faces or not.
313 //! It will be projected on the first face and this point will be set
314 //! as the first point attach point.
315 //! It defines some kind of dimension positioning over the faces.
316 //! @return TRUE if the angular dimension can be constructed
317 //! for the passed faces.
318 Standard_EXPORT Standard_Boolean InitTwoFacesAngle (const gp_Pnt& thePointOnFirstFace);
320 //! Init angular dimension to measure cone face.
321 //! @return TRUE if the angular dimension can be constructed
322 //! for the passed cone.
323 Standard_EXPORT Standard_Boolean InitConeAngle();
325 //! Check that the points forming angle are valid.
326 //! @return TRUE if the points met the following requirements:
327 //! The (P1, Center), (P2, Center) can be built.
328 //! The angle between the vectors > Precision::Angular().
329 Standard_EXPORT Standard_Boolean IsValidPoints (const gp_Pnt& theFirstPoint,
330 const gp_Pnt& theCenterPoint,
331 const gp_Pnt& theSecondPoint) const;
334 //! Returns true if the arrow should be visible
335 //! @param theArrowType an arrow type
336 //! @return TRUE if the arrow should be visible
337 Standard_EXPORT Standard_Boolean isArrowVisible (const PrsDim_TypeOfAngleArrowVisibility theArrowType) const;
340 PrsDim_TypeOfAngle myType; //!< type of angle
341 PrsDim_TypeOfAngleArrowVisibility myArrowsVisibility; //!< type of arrows visibility
344 gp_Pnt mySecondPoint;
345 gp_Pnt myCenterPoint;
346 TopoDS_Shape myFirstShape;
347 TopoDS_Shape mySecondShape;
348 TopoDS_Shape myThirdShape;
351 #endif // _PrsDim_AngleDimension_HeaderFile