Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-09-24 09:17:01

0001 // Copyright (c) 1999-2013 OPEN CASCADE SAS
0002 //
0003 // This file is part of Open CASCADE Technology software library.
0004 //
0005 // This library is free software; you can redistribute it and/or modify it under
0006 // the terms of the GNU Lesser General Public License version 2.1 as published
0007 // by the Free Software Foundation, with special exception defined in the file
0008 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
0009 // distribution for complete text of the license and disclaimer of any warranty.
0010 //
0011 // Alternatively, this file may be used under the terms of Open CASCADE
0012 // commercial license or contractual agreement.
0013 
0014 #ifndef _PrsDim_LengthDimension_HeaderFile
0015 #define _PrsDim_LengthDimension_HeaderFile
0016 
0017 #include <PrsDim_Dimension.hxx>
0018 #include <Geom_Plane.hxx>
0019 #include <gp_Pnt.hxx>
0020 #include <gp_Dir.hxx>
0021 #include <Prs3d_DimensionAspect.hxx>
0022 #include <TopoDS.hxx>
0023 
0024 //! Length dimension. Can be constructed:
0025 //! - Between two generic points.
0026 //! - Between two vertices.
0027 //! - Between two faces.
0028 //! - Between two parallel edges.
0029 //! - Between face and edge.
0030 //!
0031 //! In case of two points (vertices) or one linear edge the user-defined plane
0032 //! that includes this geometry is necessary to be set.
0033 //!
0034 //! In case of face-edge, edge-vertex or face-face lengths the automatic plane
0035 //! computing is allowed. For this plane the third point is found on the
0036 //! edge or on the face.
0037 //!
0038 //! Please note that if the inappropriate geometry is defined
0039 //! or the distance between measured points is less than
0040 //! Precision::Confusion(), the dimension is invalid and its
0041 //! presentation can not be computed.
0042 class PrsDim_LengthDimension : public PrsDim_Dimension
0043 {
0044   DEFINE_STANDARD_RTTIEXT(PrsDim_LengthDimension, PrsDim_Dimension)
0045 public:
0046   //! Construct an empty length dimension.
0047   //! @sa SetMeasuredGeometry(), SetMeasuredShapes() for initialization.
0048   Standard_EXPORT PrsDim_LengthDimension();
0049 
0050   //! Construct length dimension between face and edge.
0051   //! Here dimension can be built without user-defined plane.
0052   //! @param[in] theFace  the face (first shape).
0053   //! @param[in] theEdge  the edge (second shape).
0054   Standard_EXPORT PrsDim_LengthDimension(const TopoDS_Face& theFace, const TopoDS_Edge& theEdge);
0055 
0056   //! Construct length dimension between two faces.
0057   //! @param[in] theFirstFace  the first face (first shape).
0058   //! @param[in] theSecondFace  the second face (second shape).
0059   Standard_EXPORT PrsDim_LengthDimension(const TopoDS_Face& theFirstFace,
0060                                          const TopoDS_Face& theSecondFace);
0061 
0062   //! Construct length dimension between two points in
0063   //! the specified plane.
0064   //! @param[in] theFirstPoint  the first point.
0065   //! @param[in] theSecondPoint  the second point.
0066   //! @param[in] thePlane  the plane to orient dimension.
0067   Standard_EXPORT PrsDim_LengthDimension(const gp_Pnt& theFirstPoint,
0068                                          const gp_Pnt& theSecondPoint,
0069                                          const gp_Pln& thePlane);
0070 
0071   //! Construct length dimension between two arbitrary shapes in
0072   //! the specified plane.
0073   //! @param[in] theFirstShape  the first shape.
0074   //! @param[in] theSecondShape  the second shape.
0075   //! @param[in] thePlane  the plane to orient dimension.
0076   Standard_EXPORT PrsDim_LengthDimension(const TopoDS_Shape& theFirstShape,
0077                                          const TopoDS_Shape& theSecondShape,
0078                                          const gp_Pln&       thePlane);
0079 
0080   //! Construct length dimension of linear edge.
0081   //! @param[in] theEdge  the edge to measure.
0082   //! @param[in] thePlane  the plane to orient dimension.
0083   Standard_EXPORT PrsDim_LengthDimension(const TopoDS_Edge& theEdge, const gp_Pln& thePlane);
0084 
0085 public:
0086   //! @return first attachment point.
0087   const gp_Pnt& FirstPoint() const { return myFirstPoint; }
0088 
0089   //! @return second attachment point.
0090   const gp_Pnt& SecondPoint() const { return mySecondPoint; }
0091 
0092   //! @return first attachment shape.
0093   const TopoDS_Shape& FirstShape() const { return myFirstShape; }
0094 
0095   //! @return second attachment shape.
0096   const TopoDS_Shape& SecondShape() const { return mySecondShape; }
0097 
0098 public:
0099   //! Measure distance between two points.
0100   //! The dimension will become invalid if the new distance between
0101   //! attachment points is less than Precision::Confusion().
0102   //! @param[in] theFirstPoint  the first point.
0103   //! @param[in] theSecondPoint  the second point.
0104   //! @param[in] thePlane  the user-defined plane
0105   Standard_EXPORT void SetMeasuredGeometry(const gp_Pnt& theFirstPoint,
0106                                            const gp_Pnt& theSecondPoint,
0107                                            const gp_Pln& thePlane);
0108 
0109   //! Measure length of edge.
0110   //! The dimension will become invalid if the new length of edge
0111   //! is less than Precision::Confusion().
0112   //! @param[in] theEdge  the edge to measure.
0113   //! @param[in] thePlane  the user-defined plane
0114   Standard_EXPORT void SetMeasuredGeometry(const TopoDS_Edge& theEdge, const gp_Pln& thePlane);
0115 
0116   //! Measure distance between two faces.
0117   //! The dimension will become invalid if the distance can not
0118   //! be measured or it is less than Precision::Confusion().
0119   //! @param[in] theFirstFace  the first face (first shape).
0120   //! @param[in] theSecondFace  the second face (second shape).
0121   Standard_EXPORT void SetMeasuredGeometry(const TopoDS_Face& theFirstFace,
0122                                            const TopoDS_Face& theSecondFace);
0123 
0124   //! Measure distance between face and edge.
0125   //! The dimension will become invalid if the distance can not
0126   //! be measured or it is less than Precision::Confusion().
0127   //! @param[in] theFace  the face (first shape).
0128   //! @param[in] theEdge  the edge (second shape).
0129   Standard_EXPORT void SetMeasuredGeometry(const TopoDS_Face& theFace, const TopoDS_Edge& theEdge);
0130 
0131   //! Measure distance between generic pair of shapes (edges, vertices, length),
0132   //! where measuring is applicable.
0133   //! @param[in] theFirstShape  the first shape.
0134   //! @param[in] theSecondShape  the second shape.
0135   Standard_EXPORT void SetMeasuredShapes(const TopoDS_Shape& theFirstShape,
0136                                          const TopoDS_Shape& theSecondShape);
0137 
0138   //! @return the display units string.
0139   Standard_EXPORT const TCollection_AsciiString& GetDisplayUnits() const override;
0140 
0141   //! @return the model units string.
0142   Standard_EXPORT const TCollection_AsciiString& GetModelUnits() const override;
0143 
0144   Standard_EXPORT void SetDisplayUnits(const TCollection_AsciiString& theUnits) override;
0145 
0146   Standard_EXPORT void SetModelUnits(const TCollection_AsciiString& theUnits) override;
0147 
0148   Standard_EXPORT void SetTextPosition(const gp_Pnt& theTextPos) override;
0149 
0150   Standard_EXPORT gp_Pnt GetTextPosition() const override;
0151 
0152   //! Set custom direction for dimension. If it is not set, the direction is obtained
0153   //! from the measured geometry (e.g. line between points of dimension)
0154   //! The direction does not change flyout direction of dimension.
0155   //! @param[in] theDirection  the dimension direction.
0156   //! @param[in] theUseDirection  boolean value if custom direction should be used.
0157   Standard_EXPORT void SetDirection(const gp_Dir& theDirection, const bool theUseDirection = true);
0158 
0159 protected:
0160   //! Checks if the plane includes first and second points to build dimension.
0161   Standard_EXPORT bool CheckPlane(const gp_Pln& thePlane) const override;
0162 
0163   Standard_EXPORT virtual gp_Pln ComputePlane(const gp_Dir& theAttachDir) const;
0164 
0165   //! Computes distance between dimension points. If custom direction is defined, the distance
0166   //! is a projection value of the distance between points to this direction
0167   //! @return dimension value
0168   Standard_EXPORT double ComputeValue() const override;
0169 
0170   Standard_EXPORT void Compute(
0171     const occ::handle<PrsMgr_PresentationManager>& thePresentationManager,
0172     const occ::handle<Prs3d_Presentation>&         thePresentation,
0173     const int                                      theMode = 0) override;
0174 
0175   //! Computes points bounded the flyout line for linear dimension.
0176   //! Direction of flyout line equal to the custom direction of dimension if defined or
0177   //! parallel to the main direction line
0178   //! @param[in] theFirstPoint  the first attach point of linear dimension.
0179   //! @param[in] theSecondPoint  the second attach point of linear dimension.
0180   //! @param[out] theLineBegPoint  the first attach point of linear dimension.
0181   //! @param[out] theLineEndPoint  the second attach point of linear dimension.
0182   Standard_EXPORT void ComputeFlyoutLinePoints(const gp_Pnt& theFirstPoint,
0183                                                const gp_Pnt& theSecondPoint,
0184                                                gp_Pnt&       theLineBegPoint,
0185                                                gp_Pnt&       theLineEndPoint) override;
0186 
0187   Standard_EXPORT void ComputeFlyoutSelection(
0188     const occ::handle<SelectMgr_Selection>&   theSelection,
0189     const occ::handle<SelectMgr_EntityOwner>& theEntityOwner) override;
0190 
0191 protected:
0192   //! Checks that distance between two points is valid.
0193   //! @param[in] theFirstPoint  the first point.
0194   //! @param[in] theSecondPoint  the second point.
0195   Standard_EXPORT bool IsValidPoints(const gp_Pnt& theFirstPoint,
0196                                      const gp_Pnt& theSecondPoint) const;
0197 
0198   Standard_EXPORT bool InitTwoEdgesLength(const TopoDS_Edge& theFirstEdge,
0199                                           const TopoDS_Edge& theSecondEdge,
0200                                           gp_Dir&            theEdgeDir);
0201 
0202   //! Auxiliary method for InitTwoShapesPoints()
0203   //! in case of the distance between edge and vertex.
0204   //! Finds the point on the edge that is the closest one to <theVertex>.
0205   //! @param[out] theEdgeDir  is the direction on the edge to build automatic plane.
0206   Standard_EXPORT bool InitEdgeVertexLength(const TopoDS_Edge&   theEdge,
0207                                             const TopoDS_Vertex& theVertex,
0208                                             gp_Dir&              theEdgeDir,
0209                                             bool                 isInfinite);
0210 
0211   //! Auxiliary method for InitTwoShapesPoints()
0212   //! in case of the distance between face and edge.
0213   //! The first attachment point is first parameter point from <theEdge>.
0214   //! Find the second attachment point which belongs to <theFace>
0215   //! Iterate over the edges of the face and find the closest point according
0216   //! to found point on edge.
0217   //! @param[out] theEdgeDir  is the direction on the edge to build automatic plane.
0218   Standard_EXPORT bool InitEdgeFaceLength(const TopoDS_Edge& theEdge,
0219                                           const TopoDS_Face& theFace,
0220                                           gp_Dir&            theEdgeDir);
0221 
0222   //! Initialization of two attach points in case of two owner shapes.
0223   Standard_EXPORT bool InitTwoShapesPoints(const TopoDS_Shape& theFirstShape,
0224                                            const TopoDS_Shape& theSecondShape,
0225                                            gp_Pln&             theComputedPlane,
0226                                            bool&               theIsPlaneComputed);
0227 
0228   //! Initialization of two attach points in case of one owner shape.
0229   Standard_EXPORT bool InitOneShapePoints(const TopoDS_Shape& theShape);
0230 
0231 protected:
0232   gp_Pnt       myFirstPoint;
0233   gp_Pnt       mySecondPoint;
0234   TopoDS_Shape myFirstShape;
0235   TopoDS_Shape mySecondShape;
0236   gp_Dir       myDirection;
0237   bool         myHasCustomDirection;
0238 };
0239 
0240 #endif // _PrsDim_LengthDimension_HeaderFile