1 |
""" |
2 |
@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 |
""" |
9 |
|
10 |
__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 |
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 |
annotate the rendered object (i.e. inserting titles, authors and labels). |
31 |
""" |
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 |
self.__setupText2D(scene) |
50 |
|
51 |
def __setupText2D(self, scene): |
52 |
""" |
53 |
Setup the 2D text. |
54 |
|
55 |
@type scene: L{Scene <scene.Scene>} object |
56 |
@param scene: Scene in which objects are to be rendered on |
57 |
""" |
58 |
|
59 |
self.__setInput() |
60 |
# Set the color of the 2D text to black by default. |
61 |
self.setColor(Color.BLACK) |
62 |
# Add the 2D text to the appropriate renderer. |
63 |
scene._addActor2D(self.__viewport, self._vtk_actor2D) |
64 |
|
65 |
def __setInput(self): |
66 |
""" |
67 |
Set the input for the 2D text. |
68 |
""" |
69 |
|
70 |
self._vtk_actor2D.SetInput(self.__text) |
71 |
|
72 |
def setFontSize(self, size): |
73 |
""" |
74 |
Set the 2D text size. |
75 |
|
76 |
@type size: Number |
77 |
@param size: Size of the 2D text |
78 |
""" |
79 |
|
80 |
self._vtk_actor2D.GetTextProperty().SetFontSize(size) |
81 |
|
82 |
def setFontToTimes(self): |
83 |
""" |
84 |
Set the 2D text font type to Times New Roman. |
85 |
""" |
86 |
|
87 |
self._vtk_actor2D.GetTextProperty().SetFontFamilyToTimes() |
88 |
|
89 |
def setFontToArial(self): |
90 |
""" |
91 |
Set the 2D text font type to Arial. |
92 |
""" |
93 |
|
94 |
self._vtk_actor2D.GetTextProperty().SetFontFamilyToArial() |
95 |
|
96 |
def setFontToCourier(self): |
97 |
""" |
98 |
Set the 2D text front type to Courier. |
99 |
""" |
100 |
|
101 |
self._vtk_actor2D.GetTextProperty().SetFontFamilyToCourier() |
102 |
|
103 |
def boldOn(self): |
104 |
""" |
105 |
Bold the 2D text. |
106 |
""" |
107 |
|
108 |
self._vtk_actor2D.GetTextProperty().BoldOn() |
109 |
|
110 |
def shadowOn(self): |
111 |
""" |
112 |
Apply shadow onto the 2D text to ease visibility. |
113 |
""" |
114 |
|
115 |
self._vtk_actor2D.GetTextProperty().ShadowOn() |
116 |
|
117 |
def setColor(self, color): |
118 |
""" |
119 |
Set the color of the 2D text. |
120 |
|
121 |
@type color: L{Color <constant.Color>} constant |
122 |
@param color: 2D text color |
123 |
""" |
124 |
|
125 |
self._vtk_actor2D.GetTextProperty().SetColor(color) |
126 |
|