1 // Copyright (c) 1995-1999 Matra Datavision 2 // Copyright (c) 1999-2013 OPEN CASCADE SAS 3 // 4 // This file is part of Open CASCADE Technology software library. 5 // 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. 11 // 12 // Alternatively, this file may be used under the terms of Open CASCADE 13 // commercial license or contractual agreement. 14 15 #ifndef _AIS_AngleDimension_HeaderFile 16 #define _AIS_AngleDimension_HeaderFile 17 18 #include <AIS_Dimension.hxx> 19 #include <AIS_TypeOfAngle.hxx> 20 #include <AIS_TypeOfAngleArrowVisibility.hxx> 21 22 #include <Geom_Plane.hxx> 23 #include <Geom_Line.hxx> 24 #include <Geom_Transformation.hxx> 25 #include <gp.hxx> 26 #include <gp_Ax1.hxx> 27 #include <gp_Dir.hxx> 28 #include <gp_Pnt.hxx> 29 #include <Prs3d_DimensionAspect.hxx> 30 #include <Prs3d_Projector.hxx> 31 #include <Prs3d_Presentation.hxx> 32 #include <Standard.hxx> 33 #include <Standard_Macro.hxx> 34 #include <Standard_Type.hxx> 35 #include <TopoDS.hxx> 36 #include <TopoDS_Edge.hxx> 37 #include <TopoDS_Face.hxx> 38 #include <TopoDS_Vertex.hxx> 39 40 class AIS_AngleDimension; 41 DEFINE_STANDARD_HANDLE (AIS_AngleDimension, AIS_Dimension) 42 43 //! Angle dimension. Can be constructed: 44 //! - on two intersected edges. 45 //! - on three points or vertices. 46 //! - on conical face. 47 //! - between two intersected faces. 48 //! 49 //! In case of three points or two intersected edges the dimension plane 50 //! (on which dimension presentation is built) can be computed uniquely 51 //! as through three defined points can be built only one plane. 52 //! Therefore, if user-defined plane differs from this one, the dimension can't be built. 53 //! 54 //! In cases of two planes automatic plane by default is built on point of the 55 //! origin of parametric space of the first face (the basis surface) so, that 56 //! the working plane and two faces intersection forms minimal angle between the faces. 57 //! User can define the other point which the dimension plane should pass through 58 //! using the appropriate constructor. This point can lay on the one of the faces or not. 59 //! Also user can define his own plane but it should pass through the three points 60 //! computed on the geometry initialization step (when the constructor or SetMeasuredGeometry() method 61 //! is called). 62 //! 63 //! In case of the conical face the center point of the angle is the apex of the conical surface. 64 //! The attachment points are points of the first and the last parameter of the basis circle of the cone. 65 //! 66 class AIS_AngleDimension : public AIS_Dimension 67 { 68 public: 69 70 //! Constructs minimum angle dimension between two linear edges (where possible). 71 //! These two edges should be intersected by each other. Otherwise the geometry is not valid. 72 //! @param theFirstEdge [in] the first edge. 73 //! @param theSecondEdge [in] the second edge. 74 Standard_EXPORT AIS_AngleDimension (const TopoDS_Edge& theFirstEdge, 75 const TopoDS_Edge& theSecondEdge); 76 77 //! Constructs the angle display object defined by three points. 78 //! @param theFirstPoint [in] the first point (point on first angle flyout). 79 //! @param theSecondPoint [in] the center point of angle dimension. 80 //! @param theThirdPoint [in] the second point (point on second angle flyout). 81 Standard_EXPORT AIS_AngleDimension (const gp_Pnt& theFirstPoint, 82 const gp_Pnt& theSecondPoint, 83 const gp_Pnt& theThirdPoint); 84 85 //! Constructs the angle display object defined by three vertices. 86 //! @param theFirstVertex [in] the first vertex (vertex for first angle flyout). 87 //! @param theSecondVertex [in] the center vertex of angle dimension. 88 //! @param theThirdPoint [in] the second vertex (vertex for second angle flyout). 89 Standard_EXPORT AIS_AngleDimension (const TopoDS_Vertex& theFirstVertex, 90 const TopoDS_Vertex& theSecondVertex, 91 const TopoDS_Vertex& theThirdVertex); 92 93 //! Constructs angle dimension for the cone face. 94 //! @param theCone [in] the conical face. 95 Standard_EXPORT AIS_AngleDimension (const TopoDS_Face& theCone); 96 97 //! Constructs angle dimension between two planar faces. 98 //! @param theFirstFace [in] the first face. 99 //! @param theSecondFace [in] the second face. 100 Standard_EXPORT AIS_AngleDimension (const TopoDS_Face& theFirstFace, 101 const TopoDS_Face& theSecondFace); 102 103 //! Constructs angle dimension between two planar faces. 104 //! @param theFirstFace [in] the first face. 105 //! @param theSecondFace [in] the second face. 106 //! @param thePoint [in] the point which the dimension plane should pass through. 107 //! This point can lay on the one of the faces or not. 108 Standard_EXPORT AIS_AngleDimension (const TopoDS_Face& theFirstFace, 109 const TopoDS_Face& theSecondFace, 110 const gp_Pnt& thePoint); 111 112 public: 113 114 //! @return first point forming the angle. FirstPoint() const115 const gp_Pnt& FirstPoint() const 116 { 117 return myFirstPoint; 118 } 119 120 //! @return second point forming the angle. SecondPoint() const121 const gp_Pnt& SecondPoint() const 122 { 123 return mySecondPoint; 124 } 125 126 //! @return center point forming the angle. CenterPoint() const127 const gp_Pnt& CenterPoint() const 128 { 129 return myCenterPoint; 130 } 131 132 //! @return first argument shape. FirstShape() const133 const TopoDS_Shape& FirstShape() const 134 { 135 return myFirstShape; 136 } 137 138 //! @return second argument shape. SecondShape() const139 const TopoDS_Shape& SecondShape() const 140 { 141 return mySecondShape; 142 } 143 144 //! @return third argument shape. ThirdShape() const145 const TopoDS_Shape& ThirdShape() const 146 { 147 return myThirdShape; 148 } 149 150 public: 151 152 //! Measures minimum angle dimension between two linear edges. 153 //! These two edges should be intersected by each other. Otherwise the geometry is not valid. 154 //! @param theFirstEdge [in] the first edge. 155 //! @param theSecondEdge [in] the second edge. 156 Standard_EXPORT void SetMeasuredGeometry (const TopoDS_Edge& theFirstEdge, 157 const TopoDS_Edge& theSecondEdge); 158 159 //! Measures angle defined by three points. 160 //! @param theFirstPoint [in] the first point (point on first angle flyout). 161 //! @param theSecondPoint [in] the center point of angle dimension. 162 //! @param theThirdPoint [in] the second point (point on second angle flyout). 163 Standard_EXPORT void SetMeasuredGeometry (const gp_Pnt& theFirstPoint, 164 const gp_Pnt& theSecondPoint, 165 const gp_Pnt& theThridPoint); 166 167 //! Measures angle defined by three vertices. 168 //! @param theFirstVertex [in] the first vertex (vertex for first angle flyout). 169 //! @param theSecondVertex [in] the center vertex of angle dimension. 170 //! @param theThirdPoint [in] the second vertex (vertex for second angle flyout). 171 Standard_EXPORT void SetMeasuredGeometry (const TopoDS_Vertex& theFirstVertex, 172 const TopoDS_Vertex& theSecondVertex, 173 const TopoDS_Vertex& theThirdVertex); 174 175 //! Measures angle of conical face. 176 //! @param theCone [in] the shape to measure. 177 Standard_EXPORT void SetMeasuredGeometry (const TopoDS_Face& theCone); 178 179 //! Measures angle between two planar faces. 180 //! @param theFirstFace [in] the first face. 181 //! @param theSecondFace [in] the second face.. 182 Standard_EXPORT void SetMeasuredGeometry (const TopoDS_Face& theFirstFace, 183 const TopoDS_Face& theSecondFace); 184 185 //! Measures angle between two planar faces. 186 //! @param theFirstFace [in] the first face. 187 //! @param theSecondFace [in] the second face. 188 //! @param thePoint [in] the point which the dimension plane should pass through. 189 //! This point can lay on the one of the faces or not. 190 Standard_EXPORT void SetMeasuredGeometry (const TopoDS_Face& theFirstFace, 191 const TopoDS_Face& theSecondFace, 192 const gp_Pnt& thePoint); 193 194 //! @return the display units string. 195 Standard_EXPORT virtual const TCollection_AsciiString& GetDisplayUnits() const Standard_OVERRIDE; 196 197 //! @return the model units string. 198 Standard_EXPORT virtual const TCollection_AsciiString& GetModelUnits() const Standard_OVERRIDE; 199 200 Standard_EXPORT virtual void SetDisplayUnits (const TCollection_AsciiString& theUnits) Standard_OVERRIDE; 201 202 Standard_EXPORT virtual void SetModelUnits (const TCollection_AsciiString& theUnits) Standard_OVERRIDE; 203 204 //! Principle of horizontal text alignment settings: 205 //! - divide circle into two halves according to attachment points 206 //! - if aTextPos is between attach points -> Center + positive flyout 207 //! - if aTextPos is not between attach points but in this half -> Left or Right + positive flyout 208 //! - if aTextPos is between reflections of attach points -> Center + negative flyout 209 //! - if aTextPos is not between reflections of attach points -> Left or Right + negative flyout 210 Standard_EXPORT virtual void SetTextPosition (const gp_Pnt& theTextPos) Standard_OVERRIDE; 211 212 Standard_EXPORT virtual const gp_Pnt GetTextPosition () const Standard_OVERRIDE; 213 214 //! Sets angle type. 215 //! @param theType [in] the type value. SetType(const AIS_TypeOfAngle theType)216 void SetType(const AIS_TypeOfAngle theType) 217 { 218 myType = theType; 219 } 220 221 //! @return the current angle type. GetType() const222 AIS_TypeOfAngle GetType() const 223 { 224 return myType; 225 } 226 227 //! Sets visible arrows type 228 //! @param theType [in] the type of visibility of arrows. SetArrowsVisibility(const AIS_TypeOfAngleArrowVisibility & theType)229 void SetArrowsVisibility(const AIS_TypeOfAngleArrowVisibility& theType) 230 { 231 myArrowsVisibility = theType; 232 } 233 234 //! @return the type of visibility of arrows. GetArrowsVisibility() const235 AIS_TypeOfAngleArrowVisibility GetArrowsVisibility() const 236 { 237 return myArrowsVisibility; 238 } 239 240 public: 241 242 DEFINE_STANDARD_RTTIEXT(AIS_AngleDimension,AIS_Dimension) 243 244 protected: 245 246 //! Initialization of fields that is common to all constructors. 247 Standard_EXPORT void Init(); 248 249 //! Gets plane normal for minimal angle. 250 //! Dimension computation is based on three attach points and plane normal. 251 //! Based on this normal angle arc, arrows and extensions are constructed. 252 gp_Dir GetNormalForMinAngle() const; 253 254 //! @param theFirstAttach [in] the first attachment point. 255 //! @param theSecondAttach [in] the second attachment point. 256 //! @param theCenter [in] the center point (center point of the angle). 257 //! @return the center of the dimension arc (the main dimension line in case of angle). 258 Standard_EXPORT gp_Pnt GetCenterOnArc (const gp_Pnt& theFirstAttach, 259 const gp_Pnt& theSecondAttach, 260 const gp_Pnt& theCenter) const; 261 262 //! Draws main dimension line (arc). 263 //! @param thePresentation [in] the dimension presentation. 264 //! @param theFirstAttach [in] the first attachment point. 265 //! @param theSecondAttach [in] the second attachment point. 266 //! @param theCenter [in] the center point (center point of the angle). 267 //! @param theRadius [in] the radius of the dimension arc. 268 //! @param theMode [in] the display mode. 269 Standard_EXPORT void DrawArc (const Handle(Prs3d_Presentation)& thePresentation, 270 const gp_Pnt& theFirstAttach, 271 const gp_Pnt& theSecondAttach, 272 const gp_Pnt& theCenter, 273 const Standard_Real theRadius, 274 const Standard_Integer theMode); 275 276 //! Draws main dimension line (arc) with text. 277 //! @param thePresentation [in] the dimension presentation. 278 //! @param theFirstAttach [in] the first attachment point. 279 //! @param theSecondAttach [in] the second attachment point. 280 //! @param theCenter [in] the center point (center point of the angle). 281 //! @param theText [in] the text label string. 282 //! @param theTextWidth [in] the text label width. 283 //! @param theMode [in] the display mode. 284 //! @param theLabelPosition [in] the text label vertical and horizontal positioning option 285 //! respectively to the main dimension line. 286 Standard_EXPORT void DrawArcWithText (const Handle(Prs3d_Presentation)& thePresentation, 287 const gp_Pnt& theFirstAttach, 288 const gp_Pnt& theSecondAttach, 289 const gp_Pnt& theCenter, 290 const TCollection_ExtendedString& theText, 291 const Standard_Real theTextWidth, 292 const Standard_Integer theMode, 293 const Standard_Integer theLabelPosition); 294 295 //! Fits text alignment relatively to the dimension line; 296 //! it computes the value of label position and arrow orientation 297 //! according set in the aspect and dimension properties. 298 //! @param theHorizontalTextPos [in] the horizontal alignment for text position. 299 //! @param theLabelPosition [out] the label position, contains bits that defines 300 //! vertical and horizontal alignment. (for internal usage in count text position). 301 //! @param theIsArrowExternal [out] is the arrows external, 302 //! if arrow orientation in the dimension aspect is Prs3d_DAO_Fit, it fits arrow 303 //! orientation automatically. 304 Standard_EXPORT void FitTextAlignment (const Prs3d_DimensionTextHorizontalPosition& theHorizontalTextPos, 305 Standard_Integer& theLabelPosition, 306 Standard_Boolean& theIsArrowsExternal) const; 307 308 //! Adjusts aspect parameters according the text position: 309 //! extension size, vertical text alignment and flyout. 310 //! @param theTextPos [in] the user defined 3d point of text position. 311 //! @param theExtensionSize [out] the adjusted extension size. 312 //! @param theAlignment [out] the horizontal label alignment. 313 //! @param theFlyout [out] the adjusted value of flyout. 314 Standard_EXPORT void AdjustParameters (const gp_Pnt& theTextPos, 315 Standard_Real& theExtensionSize, 316 Prs3d_DimensionTextHorizontalPosition& theAlignment, 317 Standard_Real& theFlyout) const; 318 319 protected: 320 321 Standard_EXPORT virtual void ComputePlane(); 322 323 //! Checks if the plane includes three angle points to build dimension. 324 Standard_EXPORT virtual Standard_Boolean CheckPlane (const gp_Pln& thePlane) const Standard_OVERRIDE; 325 326 Standard_EXPORT virtual Standard_Real ComputeValue() const Standard_OVERRIDE; 327 328 Standard_EXPORT virtual void Compute (const Handle(PrsMgr_PresentationManager3d)& thePM, 329 const Handle(Prs3d_Presentation)& thePresentation, 330 const Standard_Integer theMode = 0) Standard_OVERRIDE; 331 332 Standard_EXPORT virtual void ComputeFlyoutSelection (const Handle(SelectMgr_Selection)& theSelection, 333 const Handle(SelectMgr_EntityOwner)& theOwner) Standard_OVERRIDE; 334 335 protected: 336 337 //! Init angular dimension to measure angle between two linear edges. 338 //! @return TRUE if the angular dimension can be constructured 339 //! for the passed edges. 340 Standard_EXPORT Standard_Boolean InitTwoEdgesAngle (gp_Pln& theComputedPlane); 341 342 //! Init angular dimension to measure angle between two planar faces. 343 //! there is no user-defined poisitoning. So attach points are set 344 //! according to faces geometry (in origin of the first face basis surface). 345 //! @return TRUE if the angular dimension can be constructed 346 //! for the passed faces. 347 Standard_EXPORT Standard_Boolean InitTwoFacesAngle(); 348 349 //! Init angular dimension to measure angle between two planar faces. 350 //! @param thePointOnFirstFace [in] the point which the dimension plane should pass through. 351 //! This point can lay on the one of the faces or not. 352 //! It will be projected on the first face and this point will be set 353 //! as the first point attach point. 354 //! It defines some kind of dimension positioning over the faces. 355 //! @return TRUE if the angular dimension can be constructed 356 //! for the passed faces. 357 Standard_EXPORT Standard_Boolean InitTwoFacesAngle (const gp_Pnt thePointOnFirstFace); 358 359 //! Init angular dimension to measure cone face. 360 //! @return TRUE if the angular dimension can be constructed 361 //! for the passed cone. 362 Standard_EXPORT Standard_Boolean InitConeAngle(); 363 364 //! Check that the points forming angle are valid. 365 //! @return TRUE if the points met the following requirements: 366 //! The (P1, Center), (P2, Center) can be built. 367 //! The angle between the vectors > Precision::Angular(). 368 Standard_EXPORT Standard_Boolean IsValidPoints (const gp_Pnt& theFirstPoint, 369 const gp_Pnt& theCenterPoint, 370 const gp_Pnt& theSecondPoint) const; 371 372 373 //! Returns true if the arrow should be visible 374 //! @param theArrowType an arrow type 375 //! @return TRUE if the arrow should be visible 376 Standard_EXPORT Standard_Boolean isArrowVisible(const AIS_TypeOfAngleArrowVisibility& theArrowType) const; 377 378 private: 379 AIS_TypeOfAngle myType; //!< type of angle 380 AIS_TypeOfAngleArrowVisibility myArrowsVisibility; //!< type of arrows visibility 381 382 gp_Pnt myFirstPoint; 383 gp_Pnt mySecondPoint; 384 gp_Pnt myCenterPoint; 385 TopoDS_Shape myFirstShape; 386 TopoDS_Shape mySecondShape; 387 TopoDS_Shape myThirdShape; 388 }; 389 390 #endif // _AIS_AngleDimension_HeaderFile 391