0030537: Visualization - wrapping text in font text formatter
[occt.git] / src / Graphic3d / Graphic3d_Text.hxx
CommitLineData
8ed07085 1// Copyright (c) 2019 OPEN CASCADE SAS
2//
3// This file is part of Open CASCADE Technology software library.
4//
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.
10//
11// Alternatively, this file may be used under the terms of Open CASCADE
12// commercial license or contractual agreement.
13
14#ifndef _Graphic3d_Text_HeaderFile
15#define _Graphic3d_Text_HeaderFile
16
17#include <gp_Ax2.hxx>
18
19#include <Graphic3d_Vertex.hxx>
60f7b225 20#include <Font_TextFormatter.hxx>
8ed07085 21#include <Graphic3d_HorizontalTextAlignment.hxx>
22#include <Graphic3d_VerticalTextAlignment.hxx>
23#include <NCollection_String.hxx>
24#include <Standard_Type.hxx>
25#include <Standard_Transient.hxx>
26#include <TCollection_AsciiString.hxx>
27
28//! This class allows the definition of a text object for display.
29//! The text might be defined in one of ways, using:
30//! - text value and position,
31//! - text value, orientation and the state whether the text uses position as point of attach.
32//! - text formatter. Formatter contains text, height and alignment parameter.
33//!
34//! This class also has parameters of the text height and H/V alignments.
60f7b225 35//! Custom formatting is available using Font_TextFormatter.
8ed07085 36class Graphic3d_Text : public Standard_Transient
37{
38 DEFINE_STANDARD_RTTIEXT(Graphic3d_Text, Standard_Transient)
39
40public:
41
42 //! Creates default text parameters.
43 Standard_EXPORT Graphic3d_Text (const Standard_ShortReal theHeight);
44
45 //! Destructor.
46 virtual ~Graphic3d_Text() {}
47
48 //! Returns text value.
49 const NCollection_String& Text() const { return myText; }
50
51 //! Sets text value.
52 void SetText (const NCollection_String& theText) { myText = theText; }
53
54 //! Sets text value.
55 void SetText (const TCollection_AsciiString& theText) { myText = theText.ToCString(); }
56
57 //! Sets text value.
58 void SetText (Standard_CString theText) { myText = theText; }
59
60f7b225 60 //! @return text formatter; NULL by default, which means standard text formatter will be used.
61 const Handle(Font_TextFormatter)& TextFormatter() const { return myFormatter; }
62
63 //! Setup text default formatter for text within this context.
64 void SetTextFormatter (const Handle(Font_TextFormatter)& theFormatter) { myFormatter = theFormatter; }
65
8ed07085 66 //! The 3D point of attachment is projected.
67 //! If the orientation is defined, the text is written in the plane of projection.
68 const gp_Pnt& Position() const { return myOrientation.Location(); }
69
70 //! Sets text point.
71 void SetPosition (const gp_Pnt& thePoint) { myOrientation.SetLocation (thePoint); }
72
73 //! Returns text orientation in 3D space.
74 const gp_Ax2& Orientation() const { return myOrientation; }
75
76 //! Returns true if the text is filled by a point
77 Standard_Boolean HasPlane() const { return myHasPlane; }
78
79 //! Sets text orientation in 3D space.
80 Standard_EXPORT void SetOrientation (const gp_Ax2& theOrientation);
81
82 //! Reset text orientation in 3D space.
83 Standard_EXPORT void ResetOrientation();
84
85 //! Returns true if the text has an anchor point
86 Standard_Boolean HasOwnAnchorPoint() const { return myHasOwnAnchor; }
87
88 //! Returns true if the text has an anchor point
89 void SetOwnAnchorPoint (const Standard_Boolean theHasOwnAnchor) { myHasOwnAnchor = theHasOwnAnchor; }
90
91 //! Sets height of text. (Relative to the Normalized Projection Coordinates (NPC) Space).
92 Standard_ShortReal Height() const { return myHeight; }
93
94 //! Returns height of text
95 void SetHeight (const Standard_ShortReal theHeight) { myHeight = theHeight; }
96
97 //! Returns horizontal alignment of text.
98 Graphic3d_HorizontalTextAlignment HorizontalAlignment() const { return myHAlign; }
99
100 //! Sets horizontal alignment of text.
101 void SetHorizontalAlignment (const Graphic3d_HorizontalTextAlignment theJustification) { myHAlign = theJustification; }
102
103 //! Returns vertical alignment of text.
104 Graphic3d_VerticalTextAlignment VerticalAlignment() const { return myVAlign; }
105
106 //! Sets vertical alignment of text.
107 void SetVerticalAlignment (const Graphic3d_VerticalTextAlignment theJustification) { myVAlign = theJustification; }
108
109protected:
60f7b225 110 Handle(Font_TextFormatter) myFormatter; //!< text formatter
111
8ed07085 112 NCollection_String myText; //!< text value
113 gp_Ax2 myOrientation; //!< Text orientation in 3D space.
114
115 Standard_ShortReal myHeight; //!< height of text
116 Graphic3d_HorizontalTextAlignment myHAlign; //!< horizontal alignment
117 Graphic3d_VerticalTextAlignment myVAlign; //!< vertical alignment
118
119 Standard_Boolean myHasPlane; //!< Check if text have orientation in 3D space.
120 Standard_Boolean myHasOwnAnchor; //!< flag if text uses position as point of attach
121};
122
123DEFINE_STANDARD_HANDLE(Graphic3d_Text, Standard_Transient)
124
125#endif // _Graphic3d_Text_HeaderFile