1 |
gross |
792 |
""" |
2 |
jongui |
845 |
@author: John Ngui |
3 |
|
|
@author: Lutz Gross |
4 |
gross |
792 |
""" |
5 |
|
|
|
6 |
jongui |
846 |
import vtk |
7 |
jongui |
847 |
from style import Style |
8 |
gross |
792 |
|
9 |
jongui |
846 |
class Text: |
10 |
|
|
""" |
11 |
|
|
Class that displays text. |
12 |
|
|
""" |
13 |
jongui |
845 |
|
14 |
jongui |
846 |
def __init__(self, scene): |
15 |
|
|
""" |
16 |
|
|
@type scene: L{Scene <scene.Scene>} object |
17 |
|
|
@param scene: Scene in which components are to be added to |
18 |
|
|
""" |
19 |
|
|
|
20 |
|
|
self.scene = scene |
21 |
jongui |
852 |
self.vtk_text_mapper = vtk.vtkTextMapper() |
22 |
|
|
self.vtk_text_actor = vtk.vtkScaledTextActor() |
23 |
jongui |
846 |
|
24 |
|
|
def setText(self, text): |
25 |
|
|
""" |
26 |
jongui |
860 |
Set up the text mapper. |
27 |
jongui |
846 |
|
28 |
|
|
@type text: String |
29 |
|
|
@param text: Text to be displayed |
30 |
|
|
""" |
31 |
|
|
|
32 |
|
|
self.vtk_text_mapper.SetInput(text) |
33 |
|
|
|
34 |
|
|
self.setActor() |
35 |
|
|
self.addActor() |
36 |
|
|
|
37 |
|
|
def setActor(self): |
38 |
|
|
""" |
39 |
|
|
Set up the 2D text actor, its mapper and its display position. |
40 |
|
|
""" |
41 |
|
|
|
42 |
|
|
self.vtk_text_actor.SetMapper(self.vtk_text_mapper) |
43 |
jongui |
852 |
self.setPosition(50, 20) # Default text position |
44 |
jongui |
846 |
|
45 |
|
|
def addActor(self): |
46 |
|
|
""" |
47 |
|
|
Add the 2D text actor to the renderer. |
48 |
|
|
""" |
49 |
|
|
|
50 |
|
|
self.scene.getRenderer().AddActor2D(self.vtk_text_actor) |
51 |
jongui |
847 |
|
52 |
jongui |
852 |
def setPosition(self, x_coor, y_coor): |
53 |
jongui |
860 |
""" |
54 |
|
|
Set the display position of the text. |
55 |
|
|
@type x_coor: Number |
56 |
|
|
@param x_coor: Coordinate along the x-axis |
57 |
|
|
@type y_coor: Number |
58 |
|
|
@param y_coor: Coordinate along the y-axis |
59 |
|
|
""" |
60 |
|
|
|
61 |
jongui |
852 |
self.vtk_text_actor.SetDisplayPosition(x_coor, y_coor) |
62 |
jongui |
847 |
|
63 |
jongui |
852 |
def setStyle(self, style): |
64 |
jongui |
860 |
""" |
65 |
|
|
Set the style of the text. |
66 |
|
|
@type style: L{Style <style.Style>} object |
67 |
|
|
@param style: Style of the text |
68 |
|
|
""" |
69 |
|
|
|
70 |
jongui |
852 |
self.vtk_text_mapper.SetTextProperty(style.getStyle()) |
71 |
jongui |
847 |
|