1 |
ksteube |
1147 |
""" |
2 |
jongui |
1197 |
@var __author__: name of author |
3 |
|
|
@var __copyright__: copyrights |
4 |
|
|
@var __license__: licence agreement |
5 |
|
|
@var __url__: url entry point on documentation |
6 |
|
|
@var __version__: version |
7 |
|
|
@var __date__: date of the version |
8 |
ksteube |
1147 |
""" |
9 |
|
|
|
10 |
jongui |
1197 |
__author__="John Ngui, john.ngui@uq.edu.au" |
11 |
|
|
__copyright__=""" Copyright (c) 2006 by ACcESS MNRF |
12 |
|
|
http://www.access.edu.au |
13 |
|
|
Primary Business: Queensland, Australia""" |
14 |
|
|
__license__="""Licensed under the Open Software License version 3.0 |
15 |
|
|
http://www.opensource.org/licenses/osl-3.0.php""" |
16 |
|
|
__url__="http://www.iservo.edu.au/esys" |
17 |
|
|
__version__="$Revision$" |
18 |
|
|
__date__="$Date$" |
19 |
|
|
|
20 |
|
|
|
21 |
ksteube |
1147 |
import vtk |
22 |
|
|
from actor import Actor2D |
23 |
|
|
from constant import Viewport, Color |
24 |
|
|
|
25 |
|
|
# NOTE: Actor2D was inherited to allow access to its public methods from |
26 |
|
|
# the driver. |
27 |
|
|
class Text2D(Actor2D): |
28 |
|
|
""" |
29 |
|
|
Class that defines a 2D text actor. A two-dimensional text is used to |
30 |
jongui |
1154 |
annotate the rendered object (i.e. inserting titles, authors and labels). |
31 |
ksteube |
1147 |
""" |
32 |
|
|
|
33 |
|
|
def __init__(self, scene, text, viewport = Viewport.SOUTH_WEST): |
34 |
|
|
""" |
35 |
|
|
Initialise the 2D text actor. |
36 |
|
|
|
37 |
|
|
@type scene: L{Scene <scene.Scene>} object |
38 |
|
|
@param scene: Scene in which objects are to be rendered on |
39 |
|
|
@type text: String |
40 |
|
|
@param text: 2D text to be displayed |
41 |
|
|
@type viewport: L{Viewport <constant.Viewport>} constant |
42 |
|
|
@param viewport: Viewport in which objects are to be rendered on |
43 |
|
|
""" |
44 |
|
|
|
45 |
|
|
self.__text = text |
46 |
|
|
self.__viewport = viewport |
47 |
|
|
self._vtk_actor2D = vtk.vtkTextActor() |
48 |
|
|
|
49 |
jongui |
1158 |
self.__setupText2D(scene) |
50 |
ksteube |
1147 |
|
51 |
jongui |
1158 |
def __setupText2D(self, scene): |
52 |
ksteube |
1147 |
""" |
53 |
|
|
Setup the 2D text. |
54 |
jongui |
1158 |
|
55 |
|
|
@type scene: L{Scene <scene.Scene>} object |
56 |
|
|
@param scene: Scene in which objects are to be rendered on |
57 |
ksteube |
1147 |
""" |
58 |
|
|
|
59 |
|
|
self.__setInput() |
60 |
jongui |
1189 |
self.setColor(Color.BLACK) |
61 |
ksteube |
1147 |
# Add the 2D text to the appropriate renderer. |
62 |
jongui |
1158 |
scene._addActor2D(self.__viewport, self._vtk_actor2D) |
63 |
ksteube |
1147 |
|
64 |
|
|
def __setInput(self): |
65 |
|
|
""" |
66 |
|
|
Set the input for the 2D text. |
67 |
|
|
""" |
68 |
|
|
|
69 |
|
|
self._vtk_actor2D.SetInput(self.__text) |
70 |
|
|
|
71 |
|
|
def setFontSize(self, size): |
72 |
|
|
""" |
73 |
|
|
Set the 2D text size. |
74 |
|
|
|
75 |
|
|
@type size: Number |
76 |
|
|
@param size: Size of the 2D text |
77 |
|
|
""" |
78 |
|
|
|
79 |
|
|
self._vtk_actor2D.GetTextProperty().SetFontSize(size) |
80 |
|
|
|
81 |
|
|
def setFontToTimes(self): |
82 |
|
|
""" |
83 |
|
|
Set the 2D text font type to Times New Roman. |
84 |
|
|
""" |
85 |
|
|
|
86 |
|
|
self._vtk_actor2D.GetTextProperty().SetFontFamilyToTimes() |
87 |
|
|
|
88 |
|
|
def setFontToArial(self): |
89 |
|
|
""" |
90 |
|
|
Set the 2D text font type to Arial. |
91 |
|
|
""" |
92 |
|
|
|
93 |
|
|
self._vtk_actor2D.GetTextProperty().SetFontFamilyToArial() |
94 |
|
|
|
95 |
|
|
def setFontToCourier(self): |
96 |
|
|
""" |
97 |
|
|
Set the 2D text front type to Courier. |
98 |
|
|
""" |
99 |
|
|
|
100 |
|
|
self._vtk_actor2D.GetTextProperty().SetFontFamilyToCourier() |
101 |
|
|
|
102 |
|
|
def boldOn(self): |
103 |
|
|
""" |
104 |
|
|
Bold the 2D text. |
105 |
|
|
""" |
106 |
|
|
|
107 |
|
|
self._vtk_actor2D.GetTextProperty().BoldOn() |
108 |
|
|
|
109 |
|
|
def shadowOn(self): |
110 |
|
|
""" |
111 |
|
|
Apply shadow onto the 2D text to ease visibility. |
112 |
|
|
""" |
113 |
|
|
|
114 |
|
|
self._vtk_actor2D.GetTextProperty().ShadowOn() |
115 |
|
|
|
116 |
|
|
def setColor(self, color): |
117 |
|
|
""" |
118 |
|
|
Set the color of the 2D text. |
119 |
|
|
|
120 |
|
|
@type color: L{Color <constant.Color>} constant |
121 |
|
|
@param color: 2D text color |
122 |
|
|
""" |
123 |
|
|
|
124 |
|
|
self._vtk_actor2D.GetTextProperty().SetColor(color) |
125 |
|
|
|