Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-09-12 09:17:29

0001 // Copyright (c) 2019 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 _Graphic3d_Text_HeaderFile
0015 #define _Graphic3d_Text_HeaderFile
0016 
0017 #include <gp_Ax2.hxx>
0018 
0019 #include <Font_TextFormatter.hxx>
0020 #include <Graphic3d_HorizontalTextAlignment.hxx>
0021 #include <Graphic3d_VerticalTextAlignment.hxx>
0022 #include <NCollection_String.hxx>
0023 #include <Standard_Type.hxx>
0024 #include <Standard_Transient.hxx>
0025 #include <TCollection_AsciiString.hxx>
0026 
0027 //! This class allows the definition of a text object for display.
0028 //! The text might be defined in one of ways, using:
0029 //! - text value and position,
0030 //! - text value, orientation and the state whether the text uses position as point of attach.
0031 //! - text formatter. Formatter contains text, height and alignment parameter.
0032 //!
0033 //! This class also has parameters of the text height and H/V alignments.
0034 //! Custom formatting is available using Font_TextFormatter.
0035 class Graphic3d_Text : public Standard_Transient
0036 {
0037   DEFINE_STANDARD_RTTIEXT(Graphic3d_Text, Standard_Transient)
0038 
0039 public:
0040   //! Creates default text parameters.
0041   Standard_EXPORT Graphic3d_Text(const float theHeight);
0042 
0043   //! Destructor.
0044   ~Graphic3d_Text() override = default;
0045 
0046   //! Returns text value.
0047   const NCollection_String& Text() const { return myText; }
0048 
0049   //! Sets text value.
0050   void SetText(const NCollection_String& theText) { myText = theText; }
0051 
0052   //! Sets text value.
0053   void SetText(const TCollection_AsciiString& theText) { myText = theText.ToCString(); }
0054 
0055   //! Sets text value.
0056   void SetText(const char* theText) { myText = theText; }
0057 
0058   //! @return text formatter; NULL by default, which means standard text formatter will be used.
0059   const occ::handle<Font_TextFormatter>& TextFormatter() const { return myFormatter; }
0060 
0061   //! Setup text default formatter for text within this context.
0062   void SetTextFormatter(const occ::handle<Font_TextFormatter>& theFormatter)
0063   {
0064     myFormatter = theFormatter;
0065   }
0066 
0067   //! The 3D point of attachment is projected.
0068   //! If the orientation is defined, the text is written in the plane of projection.
0069   const gp_Pnt& Position() const { return myOrientation.Location(); }
0070 
0071   //! Sets text point.
0072   void SetPosition(const gp_Pnt& thePoint) { myOrientation.SetLocation(thePoint); }
0073 
0074   //! Returns text orientation in 3D space.
0075   const gp_Ax2& Orientation() const { return myOrientation; }
0076 
0077   //! Returns true if the text is filled by a point
0078   bool HasPlane() const { return myHasPlane; }
0079 
0080   //! Sets text orientation in 3D space.
0081   Standard_EXPORT void SetOrientation(const gp_Ax2& theOrientation);
0082 
0083   //! Reset text orientation in 3D space.
0084   Standard_EXPORT void ResetOrientation();
0085 
0086   //! Returns true if the text has an anchor point
0087   bool HasOwnAnchorPoint() const { return myHasOwnAnchor; }
0088 
0089   //! Returns true if the text has an anchor point
0090   void SetOwnAnchorPoint(const bool theHasOwnAnchor) { myHasOwnAnchor = theHasOwnAnchor; }
0091 
0092   //! Sets height of text. (Relative to the Normalized Projection Coordinates (NPC) Space).
0093   float Height() const { return myHeight; }
0094 
0095   //! Returns height of text
0096   void SetHeight(const float theHeight) { myHeight = theHeight; }
0097 
0098   //! Returns horizontal alignment of text.
0099   Graphic3d_HorizontalTextAlignment HorizontalAlignment() const { return myHAlign; }
0100 
0101   //! Sets horizontal alignment of text.
0102   void SetHorizontalAlignment(const Graphic3d_HorizontalTextAlignment theJustification)
0103   {
0104     myHAlign = theJustification;
0105   }
0106 
0107   //! Returns vertical alignment of text.
0108   Graphic3d_VerticalTextAlignment VerticalAlignment() const { return myVAlign; }
0109 
0110   //! Sets vertical alignment of text.
0111   void SetVerticalAlignment(const Graphic3d_VerticalTextAlignment theJustification)
0112   {
0113     myVAlign = theJustification;
0114   }
0115 
0116 protected:
0117   occ::handle<Font_TextFormatter> myFormatter; //!< text formatter
0118 
0119   NCollection_String myText;        //!< text value
0120   gp_Ax2             myOrientation; //!< Text orientation in 3D space.
0121 
0122   float                             myHeight; //!< height of text
0123   Graphic3d_HorizontalTextAlignment myHAlign; //!< horizontal alignment
0124   Graphic3d_VerticalTextAlignment   myVAlign; //!< vertical alignment
0125 
0126   bool myHasPlane;     //!< Check if text have orientation in 3D space.
0127   bool myHasOwnAnchor; //!< flag if text uses position as point of attach
0128 };
0129 
0130 #endif // _Graphic3d_Text_HeaderFile