1 // Copyright (c) 2019 OPEN CASCADE SAS
3 // This file is part of Open CASCADE Technology software library.
5 // This library is free software; you can redistribute it and/or modify it under
6 // the terms of the GNU Lesser General Public License version 2.1 as published
7 // by the Free Software Foundation, with special exception defined in the file
8 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
9 // distribution for complete text of the license and disclaimer of any warranty.
11 // Alternatively, this file may be used under the terms of Open CASCADE
12 // commercial license or contractual agreement.
14 #ifndef _Graphic3d_Text_HeaderFile
15 #define _Graphic3d_Text_HeaderFile
19 #include <Graphic3d_Vertex.hxx>
20 #include <Graphic3d_HorizontalTextAlignment.hxx>
21 #include <Graphic3d_VerticalTextAlignment.hxx>
22 #include <NCollection_String.hxx>
23 #include <Standard_Type.hxx>
24 #include <Standard_Transient.hxx>
25 #include <TCollection_AsciiString.hxx>
27 //! This class allows the definition of a text object for display.
28 //! The text might be defined in one of ways, using:
29 //! - text value and position,
30 //! - text value, orientation and the state whether the text uses position as point of attach.
31 //! - text formatter. Formatter contains text, height and alignment parameter.
33 //! This class also has parameters of the text height and H/V alignments.
34 class Graphic3d_Text : public Standard_Transient
36 DEFINE_STANDARD_RTTIEXT(Graphic3d_Text, Standard_Transient)
40 //! Creates default text parameters.
41 Standard_EXPORT Graphic3d_Text (const Standard_ShortReal theHeight);
44 virtual ~Graphic3d_Text() {}
46 //! Returns text value.
47 const NCollection_String& Text() const { return myText; }
50 void SetText (const NCollection_String& theText) { myText = theText; }
53 void SetText (const TCollection_AsciiString& theText) { myText = theText.ToCString(); }
56 void SetText (Standard_CString theText) { myText = theText; }
58 //! The 3D point of attachment is projected.
59 //! If the orientation is defined, the text is written in the plane of projection.
60 const gp_Pnt& Position() const { return myOrientation.Location(); }
63 void SetPosition (const gp_Pnt& thePoint) { myOrientation.SetLocation (thePoint); }
65 //! Returns text orientation in 3D space.
66 const gp_Ax2& Orientation() const { return myOrientation; }
68 //! Returns true if the text is filled by a point
69 Standard_Boolean HasPlane() const { return myHasPlane; }
71 //! Sets text orientation in 3D space.
72 Standard_EXPORT void SetOrientation (const gp_Ax2& theOrientation);
74 //! Reset text orientation in 3D space.
75 Standard_EXPORT void ResetOrientation();
77 //! Returns true if the text has an anchor point
78 Standard_Boolean HasOwnAnchorPoint() const { return myHasOwnAnchor; }
80 //! Returns true if the text has an anchor point
81 void SetOwnAnchorPoint (const Standard_Boolean theHasOwnAnchor) { myHasOwnAnchor = theHasOwnAnchor; }
83 //! Sets height of text. (Relative to the Normalized Projection Coordinates (NPC) Space).
84 Standard_ShortReal Height() const { return myHeight; }
86 //! Returns height of text
87 void SetHeight (const Standard_ShortReal theHeight) { myHeight = theHeight; }
89 //! Returns horizontal alignment of text.
90 Graphic3d_HorizontalTextAlignment HorizontalAlignment() const { return myHAlign; }
92 //! Sets horizontal alignment of text.
93 void SetHorizontalAlignment (const Graphic3d_HorizontalTextAlignment theJustification) { myHAlign = theJustification; }
95 //! Returns vertical alignment of text.
96 Graphic3d_VerticalTextAlignment VerticalAlignment() const { return myVAlign; }
98 //! Sets vertical alignment of text.
99 void SetVerticalAlignment (const Graphic3d_VerticalTextAlignment theJustification) { myVAlign = theJustification; }
102 NCollection_String myText; //!< text value
103 gp_Ax2 myOrientation; //!< Text orientation in 3D space.
105 Standard_ShortReal myHeight; //!< height of text
106 Graphic3d_HorizontalTextAlignment myHAlign; //!< horizontal alignment
107 Graphic3d_VerticalTextAlignment myVAlign; //!< vertical alignment
109 Standard_Boolean myHasPlane; //!< Check if text have orientation in 3D space.
110 Standard_Boolean myHasOwnAnchor; //!< flag if text uses position as point of attach
113 DEFINE_STANDARD_HANDLE(Graphic3d_Text, Standard_Transient)
115 #endif // _Graphic3d_Text_HeaderFile