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 position import LocalPosition |
35 |
from constant import Color |
36 |
from esys.escript import getMPISizeWorld |
37 |
if getMPISizeWorld()==1: import vtk |
38 |
|
39 |
class ScalarBar: |
40 |
""" |
41 |
Class that defines a scalar bar. |
42 |
""" |
43 |
|
44 |
def __init__(self): |
45 |
""" |
46 |
Initialise the scalar bar. |
47 |
""" |
48 |
if getMPISizeWorld()>1: |
49 |
raise ValueError,"pyvisi.ScalarBar is not running on more than one processor." |
50 |
self.__vtk_scalar_bar = vtk.vtkScalarBarActor() |
51 |
self.__setupScalarBar() |
52 |
|
53 |
def __setupScalarBar(self): |
54 |
""" |
55 |
Setup the scalar bar. |
56 |
""" |
57 |
|
58 |
self.__vtk_scalar_bar.GetPositionCoordinate().SetCoordinateSystemToViewport() |
59 |
# Set the default number of labels on the scalar bar to 8. |
60 |
self.setNumberOfLabels(8) |
61 |
# Set the default color of the scalar bar's title and label to black. |
62 |
self.setTitleColor(Color.BLACK) |
63 |
self.setLabelColor(Color.BLACK) |
64 |
self.titleBoldOff() |
65 |
self.labelBoldOff() |
66 |
|
67 |
def _setScalarBarLookupTable(self, lookup_table): |
68 |
""" |
69 |
Set the scalar bar's lookup table. |
70 |
|
71 |
:type lookup_table: vtkScalarsToColors |
72 |
:param lookup_table: Converts scalar data to colors |
73 |
""" |
74 |
|
75 |
self.__vtk_scalar_bar.SetLookupTable(lookup_table) |
76 |
|
77 |
def setNumberOfLabels(self, labels): |
78 |
""" |
79 |
Set the number of labels on the scalar bar. |
80 |
|
81 |
:type labels: Number |
82 |
:param labels: Number of labels on the scalar bar |
83 |
""" |
84 |
|
85 |
self.__vtk_scalar_bar.SetNumberOfLabels(labels) |
86 |
|
87 |
def setTitle(self, title): |
88 |
""" |
89 |
Set the title on the scalar bar. |
90 |
|
91 |
:type title: String |
92 |
:param title: Title on the scalar bar |
93 |
""" |
94 |
|
95 |
self.__vtk_scalar_bar.SetTitle(title) |
96 |
|
97 |
def setPosition(self, position): |
98 |
""" |
99 |
Set the local position of the scalar bar. |
100 |
|
101 |
:type position: `LocalPosition` object |
102 |
:param position: Position of the scalar bar |
103 |
""" |
104 |
|
105 |
self.__vtk_scalar_bar.SetPosition(position._getXCoor(), \ |
106 |
position._getYCoor()) |
107 |
|
108 |
def setOrientationToHorizontal(self): |
109 |
""" |
110 |
Set the orientation of the scalar bar to horizontal. |
111 |
""" |
112 |
|
113 |
self.__vtk_scalar_bar.SetOrientationToHorizontal() |
114 |
# Default width, height and position for a horizontal scalar bar. |
115 |
self.setWidth(0.8) |
116 |
self.setHeight(0.10) |
117 |
self.setPosition(LocalPosition(130,5)) |
118 |
|
119 |
def setOrientationToVertical(self): |
120 |
""" |
121 |
Set the orientation of the scalar bar to vertical. |
122 |
""" |
123 |
|
124 |
self.__vtk_scalar_bar.SetOrientationToVertical() |
125 |
# Default width, height and position for a vertical scalar bar. |
126 |
self.setWidth(0.14) |
127 |
self.setHeight(0.85) |
128 |
self.setPosition(LocalPosition(5,150)) |
129 |
|
130 |
def setHeight(self, height): |
131 |
""" |
132 |
Set the height of the scalar bar. |
133 |
|
134 |
:type height: Number |
135 |
:param height: Height of the scalar bar |
136 |
""" |
137 |
|
138 |
self.__vtk_scalar_bar.SetHeight(height) |
139 |
|
140 |
def setWidth(self, width): |
141 |
""" |
142 |
Set the width of the scalar bar. |
143 |
|
144 |
:type width: Number |
145 |
:param width: Width of the scalar bar. |
146 |
""" |
147 |
|
148 |
self.__vtk_scalar_bar.SetWidth(width) |
149 |
|
150 |
def setLabelColor(self, color): |
151 |
""" |
152 |
Set the color of the scalar bar's label. |
153 |
|
154 |
:type color: `Color` constant |
155 |
:param color: Color of the scalar bar label |
156 |
""" |
157 |
|
158 |
self.__getLabelProperty().SetColor(color) |
159 |
|
160 |
def labelBoldOn(self): |
161 |
""" |
162 |
Enable the bold on the scalar bar's label. |
163 |
""" |
164 |
|
165 |
self.__getLabelProperty().BoldOn() |
166 |
|
167 |
def labelBoldOff(self): |
168 |
""" |
169 |
Disable the bold on the scalar bar's label. |
170 |
""" |
171 |
|
172 |
self.__getLabelProperty().BoldOff() |
173 |
|
174 |
def setTitleColor(self, color): |
175 |
""" |
176 |
Set the color of the scalar bar's title. |
177 |
|
178 |
:type color: `Color` constant |
179 |
:param color: Color of the scalar bar title |
180 |
""" |
181 |
|
182 |
self.__getTitleProperty().SetColor(color) |
183 |
|
184 |
def titleBoldOn(self): |
185 |
""" |
186 |
Enable the bold on the scalar bar's title. |
187 |
""" |
188 |
|
189 |
self.__getTitleProperty().BoldOn() |
190 |
|
191 |
def titleBoldOff(self): |
192 |
""" |
193 |
Disable the bold on the scalar bar's title. |
194 |
""" |
195 |
|
196 |
self.__getTitleProperty().BoldOff() |
197 |
|
198 |
def __getLabelProperty(self): |
199 |
""" |
200 |
Return the scalar bar's label property. |
201 |
|
202 |
:rtype: vtkTextPorperty |
203 |
:return: Scalar bar's label property |
204 |
""" |
205 |
|
206 |
return self.__vtk_scalar_bar.GetLabelTextProperty() |
207 |
|
208 |
def __getTitleProperty(self): |
209 |
""" |
210 |
Return the scalar bar's title property. |
211 |
|
212 |
:rtype: vtkTextPorperty |
213 |
:return: Scalar bar's title property |
214 |
""" |
215 |
|
216 |
return self.__vtk_scalar_bar.GetTitleTextProperty() |
217 |
|
218 |
def _getScalarBar(self): |
219 |
""" |
220 |
Return the scalar bar. |
221 |
|
222 |
:rtype: vtkScalarBarActor |
223 |
:return: Scalar bar actor |
224 |
""" |
225 |
|
226 |
return self.__vtk_scalar_bar |
227 |
|