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