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 <Font_TextFormatter.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> 26 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. 32 //! 33 //! This class also has parameters of the text height and H/V alignments. 34 //! Custom formatting is available using Font_TextFormatter. 35 class Graphic3d_Text : public Standard_Transient 36 { 37 DEFINE_STANDARD_RTTIEXT(Graphic3d_Text, Standard_Transient) 38 39 public: 40 41 //! Creates default text parameters. 42 Standard_EXPORT Graphic3d_Text (const Standard_ShortReal theHeight); 43 44 //! Destructor. ~Graphic3d_Text()45 virtual ~Graphic3d_Text() {} 46 47 //! Returns text value. Text() const48 const NCollection_String& Text() const { return myText; } 49 50 //! Sets text value. SetText(const NCollection_String & theText)51 void SetText (const NCollection_String& theText) { myText = theText; } 52 53 //! Sets text value. SetText(const TCollection_AsciiString & theText)54 void SetText (const TCollection_AsciiString& theText) { myText = theText.ToCString(); } 55 56 //! Sets text value. SetText(Standard_CString theText)57 void SetText (Standard_CString theText) { myText = theText; } 58 59 //! @return text formatter; NULL by default, which means standard text formatter will be used. Handle(Font_TextFormatter)60 const Handle(Font_TextFormatter)& TextFormatter() const { return myFormatter; } 61 62 //! Setup text default formatter for text within this context. SetTextFormatter(const Handle (Font_TextFormatter)& theFormatter)63 void SetTextFormatter (const Handle(Font_TextFormatter)& theFormatter) { myFormatter = theFormatter; } 64 65 //! The 3D point of attachment is projected. 66 //! If the orientation is defined, the text is written in the plane of projection. Position() const67 const gp_Pnt& Position() const { return myOrientation.Location(); } 68 69 //! Sets text point. SetPosition(const gp_Pnt & thePoint)70 void SetPosition (const gp_Pnt& thePoint) { myOrientation.SetLocation (thePoint); } 71 72 //! Returns text orientation in 3D space. Orientation() const73 const gp_Ax2& Orientation() const { return myOrientation; } 74 75 //! Returns true if the text is filled by a point HasPlane() const76 Standard_Boolean HasPlane() const { return myHasPlane; } 77 78 //! Sets text orientation in 3D space. 79 Standard_EXPORT void SetOrientation (const gp_Ax2& theOrientation); 80 81 //! Reset text orientation in 3D space. 82 Standard_EXPORT void ResetOrientation(); 83 84 //! Returns true if the text has an anchor point HasOwnAnchorPoint() const85 Standard_Boolean HasOwnAnchorPoint() const { return myHasOwnAnchor; } 86 87 //! Returns true if the text has an anchor point SetOwnAnchorPoint(const Standard_Boolean theHasOwnAnchor)88 void SetOwnAnchorPoint (const Standard_Boolean theHasOwnAnchor) { myHasOwnAnchor = theHasOwnAnchor; } 89 90 //! Sets height of text. (Relative to the Normalized Projection Coordinates (NPC) Space). Height() const91 Standard_ShortReal Height() const { return myHeight; } 92 93 //! Returns height of text SetHeight(const Standard_ShortReal theHeight)94 void SetHeight (const Standard_ShortReal theHeight) { myHeight = theHeight; } 95 96 //! Returns horizontal alignment of text. HorizontalAlignment() const97 Graphic3d_HorizontalTextAlignment HorizontalAlignment() const { return myHAlign; } 98 99 //! Sets horizontal alignment of text. SetHorizontalAlignment(const Graphic3d_HorizontalTextAlignment theJustification)100 void SetHorizontalAlignment (const Graphic3d_HorizontalTextAlignment theJustification) { myHAlign = theJustification; } 101 102 //! Returns vertical alignment of text. VerticalAlignment() const103 Graphic3d_VerticalTextAlignment VerticalAlignment() const { return myVAlign; } 104 105 //! Sets vertical alignment of text. SetVerticalAlignment(const Graphic3d_VerticalTextAlignment theJustification)106 void SetVerticalAlignment (const Graphic3d_VerticalTextAlignment theJustification) { myVAlign = theJustification; } 107 108 protected: 109 Handle(Font_TextFormatter) myFormatter; //!< text formatter 110 111 NCollection_String myText; //!< text value 112 gp_Ax2 myOrientation; //!< Text orientation in 3D space. 113 114 Standard_ShortReal myHeight; //!< height of text 115 Graphic3d_HorizontalTextAlignment myHAlign; //!< horizontal alignment 116 Graphic3d_VerticalTextAlignment myVAlign; //!< vertical alignment 117 118 Standard_Boolean myHasPlane; //!< Check if text have orientation in 3D space. 119 Standard_Boolean myHasOwnAnchor; //!< flag if text uses position as point of attach 120 }; 121 122 DEFINE_STANDARD_HANDLE(Graphic3d_Text, Standard_Transient) 123 124 #endif // _Graphic3d_Text_HeaderFile 125