Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-09-20 09:18:49

0001 // Created on: 2013-11-11
0002 // Created by: Anastasia BORISOVA
0003 // Copyright (c) 2013-2014 OPEN CASCADE SAS
0004 //
0005 // This file is part of Open CASCADE Technology software library.
0006 //
0007 // This library is free software; you can redistribute it and/or modify it under
0008 // the terms of the GNU Lesser General Public License version 2.1 as published
0009 // by the Free Software Foundation, with special exception defined in the file
0010 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
0011 // distribution for complete text of the license and disclaimer of any warranty.
0012 //
0013 // Alternatively, this file may be used under the terms of Open CASCADE
0014 // commercial license or contractual agreement.
0015 
0016 #ifndef _PrsDim_Dimension_HeaderFile
0017 #define _PrsDim_Dimension_HeaderFile
0018 
0019 #include <PrsDim_DimensionOwner.hxx>
0020 #include <PrsDim_DisplaySpecialSymbol.hxx>
0021 #include <AIS_InteractiveObject.hxx>
0022 #include <AIS_KindOfInteractive.hxx>
0023 #include <PrsDim_KindOfDimension.hxx>
0024 #include <Geom_Curve.hxx>
0025 #include <gp_Circ.hxx>
0026 #include <gp_Pln.hxx>
0027 #include <Prs3d_DimensionAspect.hxx>
0028 #include <Prs3d_Drawer.hxx>
0029 #include <Prs3d_LineAspect.hxx>
0030 #include <Prs3d_Presentation.hxx>
0031 #include <SelectMgr_EntityOwner.hxx>
0032 #include <Standard.hxx>
0033 #include <TCollection_ExtendedString.hxx>
0034 #include <TopoDS_Edge.hxx>
0035 #include <TopoDS_Face.hxx>
0036 #include <TopoDS_Shape.hxx>
0037 #include <NCollection_Sequence.hxx>
0038 #include <NCollection_Handle.hxx>
0039 
0040 //! PrsDim_Dimension is a base class for 2D presentations of linear (length, diameter, radius)
0041 //! and angular dimensions.
0042 //!
0043 //! The dimensions provide measurement of quantities, such as lengths or plane angles.
0044 //! The measurement of dimension "value" is done in model space "as is".
0045 //! These "value" are said to be represented in "model units", which can be specified by user.
0046 //! During the display the measured value converted from "model units" to "display units".
0047 //! The display and model units are stored in common Prs3d_Drawer (drawer of the context)
0048 //! to share it between all dimensions.
0049 //! The specified by user units are stored in the dimension's drawer.
0050 //!
0051 //! As a drawing, the dimension is composed from the following components:
0052 //! - Attachment (binding) points. The points where the dimension lines attaches to, for
0053 //!   length dimensions the distances are measured between these points.
0054 //! - Main dimension line. The which extends from the attachment points in "up" direction,
0055 //!   and which contains text label on it with value string.
0056 //! - Flyouts. The lines connecting the attachment points with main dimension line.
0057 //! - Extension. The lines used to extend the main dimension line in the cases when text
0058 //!   or arrows do not fit into the main dimension line due to their size.
0059 //! - Arrows.
0060 //!
0061 //! <pre>
0062 //!  Linear dimensions:
0063 //!
0064 //!  extension
0065 //!   line                                     arrow
0066 //!       -->|------- main dimension line -------|<--
0067 //!          |                                   |
0068 //!          |flyout                       flyout|
0069 //!          |                                   |
0070 //!          +-----------------------------------+
0071 //! attachment                                attachment
0072 //!  point                                       point
0073 //!
0074 //!  Angular dimensions:
0075 //!
0076 //!                  extension
0077 //!                     line
0078 //!                        -->|+++++
0079 //!                     arrow |     +++
0080 //!                           |        90(deg) - main dimension line
0081 //!                    flyout |         +++
0082 //!                           |           +
0083 //!                           o---flyout---
0084 //!                         center         ^
0085 //!                         point          | extension
0086 //!                                          line
0087 //! </pre>
0088 //!
0089 //! Being a 2D drawings, the dimensions are created on imaginary plane, called "dimension plane",
0090 //! which can be thought of as reference system of axes (X,Y,N) for constructing the presentation.
0091 //!
0092 //! The role of axes of the dimension plane is to guide you through the encapsulated automations
0093 //! of presentation building to help you understand how is the presentation will look and how it
0094 //! will be oriented in model space during construction.
0095 //!
0096 //! Orientation of dimension line in model space relatively to the base shapes is defined
0097 //! with the flyouts. Flyouts specify length of flyout lines and their orientation relatively
0098 //! to the attachment points on the working plane.
0099 //! For linear dimensions:
0100 //!   Direction of flyouts is specified with direction of main dimension line
0101 //!   (vector from the first attachment to the second attachment) and the normal of the dimension
0102 //!   plane. Positive direction of flyouts is defined by vector multiplication: AttachVector *
0103 //!   PlaneNormal.
0104 //! For angular dimensions:
0105 //!   Flyouts are defined by vectors from the center point to the attachment points.
0106 //!   These vectors directions are supposed to be the positive directions of flyouts.
0107 //!   Negative flyouts directions means that these vectors should be reversed
0108 //!   (and dimension will be built out of the angle constructed with center and two attach points).
0109 //!
0110 //! The dimension plane can be constructed automatically by application (where possible,
0111 //! it depends on the measured geometry).
0112 //! It can be also set by user. However, if the user-defined plane does not fit the
0113 //! geometry of the dimension (attach points do not belong to it), the dimension could not
0114 //! be built.
0115 //! If it is not possible to compute automatic plane (for example, in case of length between
0116 //! two points) the user is supposed to specify the custom plane.
0117 //!
0118 //! Since the dimensions feature automated construction procedures from an arbitrary shapes,
0119 //! the interfaces to check the validness are also implemented. Once the measured geometry is
0120 //! specified, the one can inquire the validness status by calling "IsValid()" method. If the result
0121 //! is TRUE, then all of public parameters should be pre-computed and ready. The presentation
0122 //! should be also computable. Otherwise, the parameters may return invalid values. In this case,
0123 //! the presentation will not be computed and displayed.
0124 //!
0125 //! The dimension support two local selection modes: main dimension line selection and text label
0126 //! selection. These modes can be used to develop interactive modification of dimension
0127 //! presentations. The component highlighting in these selection modes is provided by
0128 //! PrsDim_DimensionOwner class. Please note that selection is unavailable until the presentation is
0129 //! computed.
0130 //!
0131 //! The specific drawing attributes are controlled through Prs3d_DimensionAspect. The one can change
0132 //! color, arrows, text and arrow style and specify positioning of value label by setting
0133 //! corresponding values to the aspect.
0134 //!
0135 //! Such set of parameters that consists of:
0136 //! - flyout size and direction,
0137 //! - user-defined dimension plane,
0138 //! - horizontal and vertical text alignment
0139 //! can be uniquely replaced with text position in 3d space. Therefore, there are methods to convert
0140 //! this set of parameters to the text position and vice versa:
0141 //!
0142 //! - If the fixed text position is defined by user, called SetTextPosition (theTextPos) method
0143 //! converts this 3d point to the set of parameters including adjusting of the dimension plane (this
0144 //! plane will be automatic plane, NOT user-defined one). If the fixed text position is set, the
0145 //! flag myIsFixedTextPosition is set to TRUE. ATTENTION! myIsFixedTextPosition fixes all parameters
0146 //! of the set from recomputing inside SetMeasureGeometry() methods. Parameters in dimension aspect
0147 //! (they are horizontal text position and extension size) are adjusted on presentation computing
0148 //! step, user-defined values in dimension aspect are not changed. But plane and flyout as dimension
0149 //! position parameters are changed by SetTextPosition() method according with user-defined text
0150 //! position. If parameters from the set are changed by user with calls of setters, it leads to
0151 //! disabling of fixed text position (myIsFixedTextPosition is set to FALSE). If the fixed text
0152 //! position is set and geometry is changed by user (SetMeasureGeometry() method is called) and the
0153 //! geometry doesn't satisfy computed dimension plane, the dimension is not valid.
0154 //!
0155 //! - If the set of parameters was set by user (may be without the user-defined plane or with it),
0156 //! it can be converted to the text position by calling the method GetTextPosition(). In this case
0157 //! the text position is NOT fixed, and SetMeasureGeometry() without user-defined plane adjusts
0158 //! the automatic plane according input geometry (if it is possible).
0159 class PrsDim_Dimension : public AIS_InteractiveObject
0160 {
0161   DEFINE_STANDARD_RTTIEXT(PrsDim_Dimension, AIS_InteractiveObject)
0162 protected:
0163   //! Geometry type defines type of shapes on which the dimension is to be built.
0164   //! Some type of geometry allows automatic plane computing and
0165   //! can be built without user-defined plane
0166   //! Another types can't be built without user-defined plane.
0167   enum GeometryType
0168   {
0169     GeometryType_UndefShapes,
0170     GeometryType_Edge,
0171     GeometryType_Face,
0172     GeometryType_Points,
0173     GeometryType_Edges,
0174     GeometryType_Faces,
0175     GeometryType_EdgeFace,
0176     GeometryType_EdgeVertex
0177   };
0178 
0179   //! Specifies supported at base level horizontal and vertical
0180   //! label positions for drawing extension lines and centered text.
0181   enum LabelPosition
0182   {
0183     LabelPosition_None = 0x00,
0184 
0185     LabelPosition_Left    = 0x01,
0186     LabelPosition_Right   = 0x02,
0187     LabelPosition_HCenter = 0x04,
0188     LabelPosition_HMask   = LabelPosition_Left | LabelPosition_Right | LabelPosition_HCenter,
0189 
0190     LabelPosition_Above   = 0x10,
0191     LabelPosition_Below   = 0x20,
0192     LabelPosition_VCenter = 0x40,
0193     LabelPosition_VMask   = LabelPosition_Above | LabelPosition_Below | LabelPosition_VCenter
0194   };
0195 
0196   enum ValueType
0197   {
0198     ValueType_Computed,
0199     ValueType_CustomReal,
0200     ValueType_CustomText
0201   };
0202 
0203 public:
0204   //! Specifies supported presentation compute modes.
0205   //! Used to compute only parts of presentation for
0206   //! advanced highlighting.
0207   enum ComputeMode
0208   {
0209     ComputeMode_All  = 0, //!< "0" is reserved as neutral mode
0210     ComputeMode_Line = 1, //!< corresponds to selection mode
0211     ComputeMode_Text = 2  //!< corresponds to selection mode
0212   };
0213 
0214 public:
0215   //! Constructor with default parameters values.
0216   //! @param[in] theType  the type of dimension.
0217   Standard_EXPORT PrsDim_Dimension(const PrsDim_KindOfDimension theType);
0218 
0219   //! Gets dimension measurement value. If the value to display is not
0220   //! specified by user, then the dimension object is responsible to
0221   //! compute it on its own in model space coordinates.
0222   //! @return the dimension value (in model units) which is used
0223   //! during display of the presentation.
0224   double GetValue() const
0225   {
0226     return myValueType == ValueType_CustomReal ? myCustomValue : ComputeValue();
0227   }
0228 
0229   //! Sets computed dimension value. Resets custom value mode if it was set.
0230   void SetComputedValue() { myValueType = ValueType_Computed; }
0231 
0232   //! Sets user-defined dimension value.
0233   //! The user-defined dimension value is specified in model space,
0234   //! and affect by unit conversion during the display.
0235   //! @param[in] theValue  the user-defined value to display.
0236   Standard_EXPORT void SetCustomValue(const double theValue);
0237 
0238   //! Sets user-defined dimension value.
0239   //! Unit conversion during the display is not applied.
0240   //! @param[in] theValue  the user-defined value to display.
0241   Standard_EXPORT void SetCustomValue(const TCollection_ExtendedString& theValue);
0242 
0243   //! Gets user-defined dimension value.
0244   //! @return dimension value string.
0245   const TCollection_ExtendedString& GetCustomValue() const { return myCustomStringValue; }
0246 
0247   //! Get the dimension plane in which the 2D dimension presentation is computed.
0248   //! By default, if plane is not defined by user, it is computed automatically
0249   //! after dimension geometry is computed.
0250   //! If computed dimension geometry (points) can't be placed on the user-defined
0251   //! plane, dimension geometry was set as invalid (validity flag is set to false)
0252   //! and dimension presentation will not be computed.
0253   //! If user-defined plane allow geometry placement on it, it will be used for
0254   //! computing of the dimension presentation.
0255   //! @return dimension plane used for presentation computing.
0256   const gp_Pln& GetPlane() const { return myPlane; }
0257 
0258   //! Geometry type defines type of shapes on which the dimension is to be built.
0259   //! @return type of geometry on which the dimension will be built.
0260   int GetGeometryType() const { return myGeometryType; }
0261 
0262   //! Sets user-defined plane where the 2D dimension presentation will be placed.
0263   //! Checks validity of this plane if geometry has been set already.
0264   //! Validity of the plane is checked according to the geometry set
0265   //! and has different criteria for different kinds of dimensions.
0266   Standard_EXPORT virtual void SetCustomPlane(const gp_Pln& thePlane);
0267 
0268   //! Unsets user-defined plane. Therefore the plane for dimension will be
0269   //! computed automatically.
0270   void UnsetCustomPlane() { myIsPlaneCustom = false; }
0271 
0272   //! @return TRUE if text position is set by user with method SetTextPosition().
0273   bool IsTextPositionCustom() const { return myIsTextPositionFixed; }
0274 
0275   //! Fixes the absolute text position and adjusts flyout, plane and text alignment
0276   //! according to it. Updates presentation if the text position is valid.
0277   //! ATTENTION! It does not change vertical text alignment.
0278   //! @param[in] theTextPos  the point of text position.
0279   virtual void SetTextPosition(const gp_Pnt& /*theTextPos*/) {}
0280 
0281   //! Computes absolute text position from dimension parameters
0282   //! (flyout, plane and text alignment).
0283   virtual gp_Pnt GetTextPosition() const { return gp_Pnt(); }
0284 
0285 public:
0286   //! Gets the dimension aspect from AIS object drawer.
0287   //! Dimension aspect contains aspects of line, text and arrows for dimension presentation.
0288   occ::handle<Prs3d_DimensionAspect> DimensionAspect() const { return myDrawer->DimensionAspect(); }
0289 
0290   //! Sets new dimension aspect for the interactive object drawer.
0291   //! The dimension aspect provides dynamic properties which are generally
0292   //! used during computation of dimension presentations.
0293   Standard_EXPORT void SetDimensionAspect(
0294     const occ::handle<Prs3d_DimensionAspect>& theDimensionAspect);
0295 
0296   //! @return the kind of dimension.
0297   PrsDim_KindOfDimension KindOfDimension() const { return myKindOfDimension; }
0298 
0299   //! @return the kind of interactive.
0300   AIS_KindOfInteractive Type() const override { return AIS_KindOfInteractive_Dimension; }
0301 
0302   //! Returns true if the class of objects accepts the display mode theMode.
0303   //! The interactive context can have a default mode of representation for
0304   //! the set of Interactive Objects. This mode may not be accepted by object.
0305   bool AcceptDisplayMode(const int theMode) const override { return theMode == ComputeMode_All; }
0306 
0307 public:
0308   //! @return dimension special symbol display options.
0309   PrsDim_DisplaySpecialSymbol DisplaySpecialSymbol() const { return myDisplaySpecialSymbol; }
0310 
0311   //! Specifies whether to display special symbol or not.
0312   Standard_EXPORT void SetDisplaySpecialSymbol(
0313     const PrsDim_DisplaySpecialSymbol theDisplaySpecSymbol);
0314 
0315   //! @return special symbol.
0316   char16_t SpecialSymbol() const { return mySpecialSymbol; }
0317 
0318   //! Specifies special symbol.
0319   Standard_EXPORT void SetSpecialSymbol(const char16_t theSpecialSymbol);
0320 
0321   Standard_EXPORT virtual const TCollection_AsciiString& GetDisplayUnits() const;
0322 
0323   Standard_EXPORT virtual const TCollection_AsciiString& GetModelUnits() const;
0324 
0325   virtual void SetDisplayUnits(const TCollection_AsciiString& /*theUnits*/) {}
0326 
0327   virtual void SetModelUnits(const TCollection_AsciiString& /*theUnits*/) {}
0328 
0329   //! Unsets user defined text positioning and enables text positioning
0330   //!  by other parameters: text alignment, extension size, flyout and custom plane.
0331   Standard_EXPORT void UnsetFixedTextPosition();
0332 
0333 public:
0334   //! Returns selection tolerance for text2d:
0335   //! For 2d text selection detection sensitive point with tolerance is used
0336   //! Important! Only for 2d text.
0337   double SelToleranceForText2d() const { return mySelToleranceForText2d; }
0338 
0339   //! Sets selection tolerance for text2d:
0340   //! For 2d text selection detection sensitive point with tolerance is used
0341   //! to change this tolerance use this method
0342   //! Important! Only for 2d text.
0343   Standard_EXPORT void SetSelToleranceForText2d(const double theTol);
0344 
0345   //! @return flyout value for dimension.
0346   double GetFlyout() const { return myFlyout; }
0347 
0348   //! Sets flyout value for dimension.
0349   Standard_EXPORT void SetFlyout(const double theFlyout);
0350 
0351   //! Check that the input geometry for dimension is valid and the
0352   //! presentation can be successfully computed.
0353   //! @return TRUE if dimension geometry is ok.
0354   virtual bool IsValid() const { return myIsGeometryValid && CheckPlane(GetPlane()); }
0355 
0356 protected:
0357   Standard_EXPORT double ValueToDisplayUnits() const;
0358 
0359   //! Get formatted value string and its model space width.
0360   //! @param[out] theWidth  the model space with of the string.
0361   //! @return formatted dimension value string.
0362   Standard_EXPORT TCollection_ExtendedString GetValueString(double& theWidth) const;
0363 
0364   //! Performs drawing of 2d or 3d arrows on the working plane
0365   //! @param[in] theLocation  the location of the arrow tip.
0366   //! @param[in] theDirection  the direction from the tip to the bottom of the arrow.
0367   Standard_EXPORT void DrawArrow(const occ::handle<Prs3d_Presentation>& thePresentation,
0368                                  const gp_Pnt&                          theLocation,
0369                                  const gp_Dir&                          theDirection);
0370 
0371   //! Performs drawing of 2d or 3d text on the working plane
0372   //! @param[in] theTextPos  the position of the text label.
0373   //! @param[in] theTestDir  the direction of the text label.
0374   //! @param[in] theText  the text label string.
0375   //! @param[in] theLabelPosition  the text label vertical and horizontal positioning option
0376   //! respectively to the main dimension line.
0377   //! @return text width relative to the dimension working plane. For 2d text this value will be
0378   //! zero.
0379   Standard_EXPORT void drawText(const occ::handle<Prs3d_Presentation>& thePresentation,
0380                                 const gp_Pnt&                          theTextPos,
0381                                 const gp_Dir&                          theTextDir,
0382                                 const TCollection_ExtendedString&      theText,
0383                                 const int                              theLabelPosition);
0384 
0385   //! Performs computing of dimension linear extension with text
0386   //! @param[in] thePresentation  the presentation to fill with graphical primitives.
0387   //! @param[in] theExtensionSize  the size of extension line.
0388   //! @param[in] theExtensionStart  the point where extension line connects to dimension.
0389   //! @param[in] theExtensionDir  the direction of extension line.
0390   //! @param[in] theLabelString  the string with value.
0391   //! @param[in] theLabelWidth  the geometrical width computed for value string.
0392   //! @param[in] theMode  the display mode.
0393   //! @param[in] theLabelPosition  position flags for the text label.
0394   Standard_EXPORT void DrawExtension(const occ::handle<Prs3d_Presentation>& thePresentation,
0395                                      const double                           theExtensionSize,
0396                                      const gp_Pnt&                          theExtensionStart,
0397                                      const gp_Dir&                          theExtensionDir,
0398                                      const TCollection_ExtendedString&      theLabelString,
0399                                      const double                           theLabelWidth,
0400                                      const int                              theMode,
0401                                      const int                              theLabelPosition);
0402 
0403   //! Performs computing of linear dimension (for length, diameter, radius and so on).
0404   //! Please note that this method uses base dimension properties, like working plane
0405   //! flyout length, drawer attributes.
0406   //! @param[in] thePresentation  the presentation to fill with primitives.
0407   //! @param[in] theMode  the presentation compute mode.
0408   //! @param[in] theFirstPoint  the first attach point of linear dimension.
0409   //! @param[in] theSecondPoint  the second attach point of linear dimension.
0410   //! @param[in] theIsOneSide  specifies whether the dimension has only one flyout line.
0411   Standard_EXPORT void DrawLinearDimension(const occ::handle<Prs3d_Presentation>& thePresentation,
0412                                            const int                              theMode,
0413                                            const gp_Pnt&                          theFirstPoint,
0414                                            const gp_Pnt&                          theSecondPoint,
0415                                            const bool theIsOneSide = false);
0416 
0417   //! Computes points bounded the flyout line for linear dimension.
0418   //! @param[in] theFirstPoint  the first attach point of linear dimension.
0419   //! @param[in] theSecondPoint  the second attach point of linear dimension.
0420   //! @param[out] theLineBegPoint  the first attach point of linear dimension.
0421   //! @param[out] theLineEndPoint  the second attach point of linear dimension.
0422   Standard_EXPORT virtual void ComputeFlyoutLinePoints(const gp_Pnt& theFirstPoint,
0423                                                        const gp_Pnt& theSecondPoint,
0424                                                        gp_Pnt&       theLineBegPoint,
0425                                                        gp_Pnt&       theLineEndPoint);
0426 
0427   //! Compute selection sensitives for linear dimension flyout lines (length, diameter, radius).
0428   //! Please note that this method uses base dimension properties: working plane and flyout length.
0429   //! @param[in] theSelection  the selection structure to fill with selection primitives.
0430   //! @param[in] theOwner  the selection entity owner.
0431   //! @param[in] theFirstPoint  the first attach point of linear dimension.
0432   //! @param[in] theSecondPoint  the second attach point of linear dimension.
0433   Standard_EXPORT void ComputeLinearFlyouts(const occ::handle<SelectMgr_Selection>&   theSelection,
0434                                             const occ::handle<SelectMgr_EntityOwner>& theOwner,
0435                                             const gp_Pnt&                             theFirstPoint,
0436                                             const gp_Pnt& theSecondPoint);
0437 
0438   //! Performs initialization of circle and middle arc point from the passed
0439   //! shape which is assumed to contain circular geometry.
0440   //! @param[in] theShape  the shape to explore.
0441   //! @param[out] theCircle  the circle geometry.
0442   //! @param[out] theMiddleArcPoint  the middle point of the arc.
0443   //! @param[out] theIsClosed  returns TRUE if the geometry is closed circle.
0444   //! @return TRUE if the circle is successfully returned from the input shape.
0445   Standard_EXPORT bool InitCircularDimension(const TopoDS_Shape& theShape,
0446                                              gp_Circ&            theCircle,
0447                                              gp_Pnt&             theMiddleArcPoint,
0448                                              bool&               theIsClosed);
0449 
0450   //! Produce points for triangular arrow face.
0451   //! @param[in] thePeakPnt  the arrow peak position.
0452   //! @param[in] theDirection  the arrow direction.
0453   //! @param[in] thePlane  the face plane.
0454   //! @param[in] theArrowLength  the length of arrow.
0455   //! @param[in] theArrowAngle  the angle of arrow.
0456   //! @param[out] theSidePnt1  the first side point.
0457   //! @param[out] theSidePnt2  the second side point.
0458   Standard_EXPORT void PointsForArrow(const gp_Pnt& thePeakPnt,
0459                                       const gp_Dir& theDirection,
0460                                       const gp_Dir& thePlane,
0461                                       const double  theArrowLength,
0462                                       const double  theArrowAngle,
0463                                       gp_Pnt&       theSidePnt1,
0464                                       gp_Pnt&       theSidePnt2);
0465 
0466   //! Compute point of text position for dimension parameters
0467   //! for linear kinds of dimensions (length, radius, diameter).
0468   Standard_EXPORT gp_Pnt GetTextPositionForLinear(const gp_Pnt& theFirstPoint,
0469                                                   const gp_Pnt& theSecondPoint,
0470                                                   const bool    theIsOneSide = false) const;
0471 
0472   //! Fits text alignment relatively to the dimension line.
0473   //! @param[in] theFirstPoint  the first attachment point.
0474   //! @param[in] theSecondPoint  the second attachment point.
0475   //! @param[in] theIsOneSide  is the arrow displayed only on the one side of the dimension.
0476   //! @param[in] theHorizontalTextPos  the text horizontal position (alignment).
0477   //! @param[out] theLabelPosition  the label position, contains bits that defines
0478   //! vertical and horizontal alignment. (for internal usage in count text position)
0479   //! @param[out] theIsArrowExternal  is the arrows external,
0480   //! if arrow orientation in the dimension aspect is Prs3d_DAO_Fit, it fits arrow
0481   //! orientation automatically.
0482   Standard_EXPORT void FitTextAlignmentForLinear(
0483     const gp_Pnt&                                theFirstPoint,
0484     const gp_Pnt&                                theSecondPoint,
0485     const bool                                   theIsOneSide,
0486     const Prs3d_DimensionTextHorizontalPosition& theHorizontalTextPos,
0487     int&                                         theLabelPosition,
0488     bool&                                        theIsArrowsExternal) const;
0489 
0490   //! Adjusts aspect parameters according the text position:
0491   //! extension size, vertical text alignment and flyout.
0492   //! @param[in] theTextPos  the user defined 3d point of text position
0493   //! @param[in] theFirstPoint  the first point of linear measurement.
0494   //! @param[in] theSecondPoint  the second point of linear measurement.
0495   //! @param[out] theExtensionSize  the adjusted extension size
0496   //! @param[out] theAlignment  the horizontal label alignment.
0497   //! @param[out] theFlyout  the adjusted value of flyout.
0498   //! @param[out] thePlane  the new plane that contains theTextPos and attachment points.
0499   //! @param[out] theIsPlaneOld  shows if new plane is computed.
0500   Standard_EXPORT bool AdjustParametersForLinear(
0501     const gp_Pnt&                          theTextPos,
0502     const gp_Pnt&                          theFirstPoint,
0503     const gp_Pnt&                          theSecondPoint,
0504     double&                                theExtensionSize,
0505     Prs3d_DimensionTextHorizontalPosition& theAlignment,
0506     double&                                theFlyout,
0507     gp_Pln&                                thePlane,
0508     bool&                                  theIsPlaneOld) const;
0509 
0510 protected: //! @name Static auxiliary methods for geometry extraction
0511   //! If it is possible extracts circle from planar face.
0512   //! @param[in] theFace         the planar face
0513   //! @param[out] theCurve        the circular curve
0514   //! @param[out] theFirstPoint   the point of the first parameter of the circlular curve
0515   //! @param[out] theSecondPoint  the point of the last parameter of the circlular curve
0516   //! @return TRUE in case of successful circle extraction
0517   static bool CircleFromPlanarFace(const TopoDS_Face&       theFace,
0518                                    occ::handle<Geom_Curve>& theCurve,
0519                                    gp_Pnt&                  theFirstPoint,
0520                                    gp_Pnt&                  theLastPoint);
0521 
0522   //! If it is possible extracts circle from the edge.
0523   //! @param[in] theEdge         input edge to extract circle from
0524   //! @param[out] theCircle       circle
0525   //! @param[out] theFirstPoint   the point of the first parameter of the circlular curve
0526   //! @param[out] theSecondPoint  the point of the last parameter of the circlular curve
0527   //! @return TRUE in case of successful circle extraction.
0528   static bool CircleFromEdge(const TopoDS_Edge& theEdge,
0529                              gp_Circ&           theCircle,
0530                              gp_Pnt&            theFirstPoint,
0531                              gp_Pnt&            theLastPoint);
0532 
0533 protected: //! @name Behavior to implement
0534   //! Override this method to check if user-defined plane
0535   //! is valid for the dimension geometry.
0536   //! @param[in] thePlane  the working plane for positioning every
0537   //! dimension in the application.
0538   //! @return true is the plane is suitable for building dimension
0539   //! with computed dimension geometry.
0540   virtual bool CheckPlane(const gp_Pln& /*thePlane*/) const { return true; }
0541 
0542   //! Override this method to computed value of dimension.
0543   //! @return value from the measured geometry.
0544   virtual double ComputeValue() const { return 0.0; }
0545 
0546   //! Override this method to compute selection primitives for
0547   //! flyout lines (if the dimension provides it).
0548   //! This callback is a only a part of base selection
0549   //! computation routine.
0550   virtual void ComputeFlyoutSelection(const occ::handle<SelectMgr_Selection>&,
0551                                       const occ::handle<SelectMgr_EntityOwner>&)
0552   {
0553   }
0554 
0555   //! Base procedure of computing selection (based on selection geometry data).
0556   //! @param[in] theSelection  the selection structure to will with primitives.
0557   //! @param[in] theMode  the selection mode.
0558   Standard_EXPORT void ComputeSelection(const occ::handle<SelectMgr_Selection>& theSelection,
0559                                         const int                               theMode) override;
0560 
0561 protected: //! @name Selection geometry
0562   //! Selection geometry of dimension presentation. The structure is filled with data
0563   //! during compute of presentation, then this data is used to generate selection
0564   //! sensitives when computing selection.
0565   struct SelectionGeometry
0566   {
0567     //! Arrows are represented by directed triangles.
0568     struct Arrow
0569     {
0570       gp_Pnt Position;
0571       gp_Dir Direction;
0572     };
0573 
0574     typedef NCollection_Sequence<gp_Pnt> Curve;
0575     typedef NCollection_Handle<Curve>    HCurve;
0576     typedef NCollection_Handle<Arrow>    HArrow;
0577     typedef NCollection_Sequence<HCurve> SeqOfCurves;
0578     typedef NCollection_Sequence<HArrow> SeqOfArrows;
0579 
0580     gp_Pnt TextPos;           //!< Center of text label.
0581     gp_Dir TextDir;           //!< Direction of text label.
0582     double TextWidth;         //!< Width of text label.
0583     double TextHeight;        //!< Height of text label.
0584                               // clang-format off
0585     SeqOfCurves      DimensionLine;      //!< Sequence of points for composing the segments of dimension line.
0586                               // clang-format on
0587     SeqOfArrows Arrows;       //!< Sequence of arrow geometries.
0588     bool        IsComputed;   //!< Shows if the selection geometry was filled.
0589 
0590   public:
0591     //! Clear geometry of sensitives for the specified compute mode.
0592     //! @param[in] theMode  the compute mode to clear.
0593     void Clear(const int theMode)
0594     {
0595       if (theMode == ComputeMode_All || theMode == ComputeMode_Line)
0596       {
0597         DimensionLine.Clear();
0598         Arrows.Clear();
0599       }
0600 
0601       if (theMode == ComputeMode_All || theMode == ComputeMode_Text)
0602       {
0603         TextPos    = gp::Origin();
0604         TextDir    = gp::DX();
0605         TextWidth  = 0.0;
0606         TextHeight = 0.0;
0607       }
0608 
0609       IsComputed = false;
0610     }
0611 
0612     //! Add new curve entry and return the reference to populate it.
0613     Curve& NewCurve()
0614     {
0615       DimensionLine.Append(new Curve);
0616       HCurve& aLastCurve = DimensionLine.ChangeLast();
0617       return *aLastCurve;
0618     }
0619 
0620     //! Add new arrow entry and return the reference to populate it.
0621     Arrow& NewArrow()
0622     {
0623       Arrows.Append(new Arrow);
0624       HArrow& aLastArrow = Arrows.ChangeLast();
0625       return *aLastArrow;
0626     }
0627   } mySelectionGeom;
0628 
0629   double mySelToleranceForText2d; //!< Sensitive point tolerance for 2d text selection.
0630 
0631 protected:                 //! @name Value properties
0632   ValueType myValueType;   //! type of value (computed or user-defined)
0633   double    myCustomValue; //!< Value of the dimension (computed or user-defined).
0634 
0635   // clang-format off
0636   TCollection_ExtendedString myCustomStringValue; //!< Value of the dimension (computed or user-defined).
0637   // clang-format on
0638 
0639 protected:                      //! @name Fixed text position properties
0640   gp_Pnt myFixedTextPosition;   //!< Stores text position fixed by user.
0641   bool   myIsTextPositionFixed; //!< Is the text label position fixed by user.
0642 
0643 protected:                                            //! @name Units properties
0644   char16_t                    mySpecialSymbol;        //!< Special symbol.
0645   PrsDim_DisplaySpecialSymbol myDisplaySpecialSymbol; //!< Special symbol display options.
0646 
0647 protected:                  //! @name Geometrical properties
0648                             // clang-format off
0649   GeometryType myGeometryType;  //!< defines type of shapes on which the dimension is to be built. 
0650 
0651   gp_Pln           myPlane;           //!< Plane where dimension will be built (computed or user defined).
0652   bool myIsPlaneCustom;   //!< Is plane defined by user (otherwise it will be computed automatically).
0653                             // clang-format on
0654   double myFlyout;          //!< Flyout distance.
0655   bool   myIsGeometryValid; //!< Is dimension geometry properly defined.
0656 
0657 private:
0658   PrsDim_KindOfDimension myKindOfDimension;
0659 };
0660 
0661 #endif // _PrsDim_Dimension_HeaderFile