0022634: Cut operation on closed solids returns opened one
[occt.git] / src / OpenGl / OpenGl_Text.hxx
CommitLineData
b311480e 1// Created on: 2011-07-13
2// Created by: Sergey ZERCHANINOV
a174a3c5 3// Copyright (c) 2011-2013 OPEN CASCADE SAS
b311480e 4//
973c2be1 5// This file is part of Open CASCADE Technology software library.
b311480e 6//
d5f74e42 7// This library is free software; you can redistribute it and/or modify it under
8// the terms of the GNU Lesser General Public License version 2.1 as published
973c2be1 9// by the Free Software Foundation, with special exception defined in the file
10// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
11// distribution for complete text of the license and disclaimer of any warranty.
b311480e 12//
973c2be1 13// Alternatively, this file may be used under the terms of Open CASCADE
14// commercial license or contractual agreement.
b311480e 15
2166f0fa
SK
16#ifndef OpenGl_Text_Header
17#define OpenGl_Text_Header
18
19#include <OpenGl_Element.hxx>
20
a174a3c5 21#include <OpenGl_AspectText.hxx>
2166f0fa 22#include <OpenGl_TextParam.hxx>
317d68c9 23#include <OpenGl_TextBuilder.hxx>
2166f0fa
SK
24
25#include <TCollection_ExtendedString.hxx>
26#include <Graphic3d_Vertex.hxx>
27#include <Graphic3d_HorizontalTextAlignment.hxx>
4b1c8733 28#include <Graphic3d_RenderingParams.hxx>
2166f0fa
SK
29#include <Graphic3d_VerticalTextAlignment.hxx>
30
ce01ec26 31#include <gp_Ax2.hxx>
32
c04c30b3 33class OpenGl_PrinterContext;
a174a3c5 34
35//! Text rendering
2166f0fa
SK
36class OpenGl_Text : public OpenGl_Element
37{
5e27df78 38
39public:
2166f0fa 40
a174a3c5 41 //! Main constructor
b64d84be 42 Standard_EXPORT OpenGl_Text (const Standard_Utf8Char* theText,
43 const OpenGl_Vec3& thePoint,
44 const OpenGl_TextParam& theParams);
a174a3c5 45
ce01ec26 46 //! Creates new text in 3D space.
47 Standard_EXPORT OpenGl_Text (const Standard_Utf8Char* theText,
48 const gp_Ax2& theOrientation,
3f1eb0ab 49 const OpenGl_TextParam& theParams,
50 const bool theHasOwnAnchor = true);
ce01ec26 51
a174a3c5 52 //! Setup new string and position
53 Standard_EXPORT void Init (const Handle(OpenGl_Context)& theCtx,
54 const Standard_Utf8Char* theText,
55 const OpenGl_Vec3& thePoint);
56
57 //! Setup new string and parameters
58 Standard_EXPORT void Init (const Handle(OpenGl_Context)& theCtx,
59 const Standard_Utf8Char* theText,
60 const OpenGl_Vec3& thePoint,
61 const OpenGl_TextParam& theParams);
62
63 //! Setup new position
64 Standard_EXPORT void SetPosition (const OpenGl_Vec3& thePoint);
65
66 //! Setup new font size
67 Standard_EXPORT void SetFontSize (const Handle(OpenGl_Context)& theContext,
68 const Standard_Integer theFontSize);
69
70 Standard_EXPORT virtual void Render (const Handle(OpenGl_Workspace)& theWorkspace) const;
10b9c7df 71 Standard_EXPORT virtual void Release (OpenGl_Context* theContext);
a174a3c5 72
73public: //! @name methods for compatibility with layers
74
75 //! Empty constructor
6a240ff8 76 Standard_EXPORT OpenGl_Text();
a174a3c5 77
78 //! Create key for shared resource
6a240ff8 79 Standard_EXPORT static TCollection_AsciiString FontKey (const OpenGl_AspectText& theAspect,
4b1c8733 80 const Standard_Integer theHeight,
81 const unsigned int theResolution);
a174a3c5 82
83 //! Find shared resource for specified font or initialize new one
6a240ff8 84 Standard_EXPORT static Handle(OpenGl_Font) FindFont (const Handle(OpenGl_Context)& theCtx,
85 const OpenGl_AspectText& theAspect,
86 const Standard_Integer theHeight,
4b1c8733 87 const unsigned int theResolution,
6a240ff8 88 const TCollection_AsciiString theKey);
a174a3c5 89
90 //! Compute text width
6a240ff8 91 Standard_EXPORT static void StringSize (const Handle(OpenGl_Context)& theCtx,
92 const NCollection_String& theText,
93 const OpenGl_AspectText& theTextAspect,
94 const OpenGl_TextParam& theParams,
4b1c8733 95 const unsigned int theResolution,
6a240ff8 96 Standard_ShortReal& theWidth,
97 Standard_ShortReal& theAscent,
98 Standard_ShortReal& theDescent);
a174a3c5 99
100 //! Setup new string and parameters
6a240ff8 101 Standard_EXPORT void Init (const Handle(OpenGl_Context)& theCtx,
102 const TCollection_ExtendedString& theText,
103 const OpenGl_Vec2& thePoint,
104 const OpenGl_TextParam& theParams);
a174a3c5 105
106 //! Perform rendering
6a240ff8 107 Standard_EXPORT void Render (const Handle(OpenGl_PrinterContext)& thePrintCtx,
108 const Handle(OpenGl_Context)& theCtx,
4b1c8733 109 const OpenGl_AspectText& theTextAspect,
110 const unsigned int theResolution = Graphic3d_RenderingParams::THE_DEFAULT_RESOLUTION) const;
a174a3c5 111
112protected:
113
114 //! Destructor
115 Standard_EXPORT virtual ~OpenGl_Text();
116
117 friend class OpenGl_Trihedron;
118 friend class OpenGl_GraduatedTrihedron;
119
120private:
121
122 //! Release cached VBO resources
10b9c7df 123 void releaseVbos (OpenGl_Context* theCtx);
a174a3c5 124
125 //! Setup matrix.
126 void setupMatrix (const Handle(OpenGl_PrinterContext)& thePrintCtx,
127 const Handle(OpenGl_Context)& theCtx,
128 const OpenGl_AspectText& theTextAspect,
129 const OpenGl_Vec3 theDVec) const;
130
131 //! Draw arrays of vertices.
132 void drawText (const Handle(OpenGl_PrinterContext)& thePrintCtx,
133 const Handle(OpenGl_Context)& theCtx,
134 const OpenGl_AspectText& theTextAspect) const;
135
136 //! Main rendering code
137 void render (const Handle(OpenGl_PrinterContext)& thePrintCtx,
138 const Handle(OpenGl_Context)& theCtx,
139 const OpenGl_AspectText& theTextAspect,
b6472664 140 const OpenGl_Vec4& theColorText,
141 const OpenGl_Vec4& theColorSubs,
4b1c8733 142 const unsigned int theResolution) const;
a174a3c5 143
144protected:
2166f0fa 145
a174a3c5 146 mutable Handle(OpenGl_Font) myFont;
147 mutable NCollection_Vector<GLuint> myTextures; //!< textures' IDs
148 mutable NCollection_Vector<Handle(OpenGl_VertexBuffer)> myVertsVbo; //!< VBOs of vertices
149 mutable NCollection_Vector<Handle(OpenGl_VertexBuffer)> myTCrdsVbo; //!< VBOs of texture coordinates
d2eddacc 150 mutable Font_Rect myBndBox;
5e27df78 151
152protected:
153
c827ea3a 154 mutable OpenGl_Mat4d myProjMatrix;
155 mutable OpenGl_Mat4d myModelMatrix;
ce01ec26 156 mutable OpenGl_Mat4d myOrientationMatrix;
a174a3c5 157 mutable GLint myViewport[4];
158 mutable GLdouble myWinX;
159 mutable GLdouble myWinY;
160 mutable GLdouble myWinZ;
161 mutable GLdouble myScaleHeight;
162 mutable GLdouble myExportHeight;
2166f0fa 163
5e27df78 164protected:
2166f0fa 165
a174a3c5 166 OpenGl_TextParam myParams;
167 NCollection_String myString;
168 OpenGl_Vec3 myPoint;
169 bool myIs2d;
ce01ec26 170 gp_Ax2 myOrientation; //!< Text orientation in 3D space.
171 bool myHasPlane; //!< Check if text have orientation in 3D space.
3f1eb0ab 172 bool myHasAnchorPoint; //!< Shows if it has own attach point
2166f0fa 173
5e27df78 174public:
175
1c35b92f 176 DEFINE_STANDARD_ALLOC
5e27df78 177
2166f0fa
SK
178};
179
180#endif //OpenGl_Text_Header