1 |
""" |
2 |
This is the file for the base Renderer class |
3 |
|
4 |
@var __author__: name of author |
5 |
@var __license__: licence agreement |
6 |
@var __copyright__: copyrights |
7 |
@var __url__: url entry point on documentation |
8 |
@var __version__: version |
9 |
@var __date__: date of the version |
10 |
""" |
11 |
|
12 |
__copyright__=""" Copyright (c) 2006 by ACcESS MNRF |
13 |
http://www.access.edu.au |
14 |
Primary Business: Queensland, Australia""" |
15 |
__license__="""Licensed under the Open Software License version 3.0 |
16 |
http://www.opensource.org/licenses/osl-3.0.php""" |
17 |
__author__="Paul Cochrane" |
18 |
__url__="http://www.iservo.edu.au/esys" |
19 |
__version__="$Revision$" |
20 |
__date__="$Date$" |
21 |
|
22 |
from common import debugMsg |
23 |
|
24 |
class Renderer(object): |
25 |
""" |
26 |
A generic object holding a renderer of a Scene(). |
27 |
""" |
28 |
|
29 |
def __init__(self): |
30 |
""" |
31 |
Initialisation of Renderer() class |
32 |
""" |
33 |
object.__init__(self) |
34 |
debugMsg("Called Renderer.__init__()") |
35 |
|
36 |
# initialise some attributes |
37 |
self.renderWindowWidth = 640 |
38 |
self.renderWindowHeight = 480 |
39 |
|
40 |
# the namespace to run the exec code |
41 |
self.renderDict = {} |
42 |
|
43 |
# initialise the evalstack |
44 |
self._evalStack = "" |
45 |
|
46 |
# keep the initial setup of the module for later reuse |
47 |
self._initStack = "" |
48 |
|
49 |
# initialise the renderer module |
50 |
|
51 |
def setRenderWindowWidth(self, width): |
52 |
""" |
53 |
Sets the render window width |
54 |
|
55 |
@param width: The width of the render window |
56 |
@type width: int |
57 |
""" |
58 |
debugMsg("Called Renderer.setRenderWindowWidth()") |
59 |
# check that the argument makes sense |
60 |
if __debug__: |
61 |
assert isinstance(width, int), "Incorrect data type; expected int" |
62 |
|
63 |
self.renderWindowWidth = width |
64 |
return |
65 |
|
66 |
def setRenderWindowHeight(self, height): |
67 |
""" |
68 |
Sets the render window height |
69 |
|
70 |
@param height: The height of the render window |
71 |
@type height: int |
72 |
""" |
73 |
debugMsg("Called Renderer.setRenderWindowHeight()") |
74 |
# check that the argument makes sense |
75 |
if __debug__: |
76 |
assert isinstance(height, int), "Incorrect data type; expected int" |
77 |
|
78 |
self.renderWindowHeight = height |
79 |
return |
80 |
|
81 |
def getRenderWindowWidth(self): |
82 |
""" |
83 |
Gets the render window width |
84 |
""" |
85 |
debugMsg("Called Renderer.getRenderWindowWidth()") |
86 |
return self.renderWindowWidth |
87 |
|
88 |
def getRenderWindowHeight(self): |
89 |
""" |
90 |
Gets the render window height |
91 |
""" |
92 |
debugMsg("Called Renderer.getRenderWindowHeight()") |
93 |
return self.renderWindowHeight |
94 |
|
95 |
def setRenderWindowDimensions(self, width, height): |
96 |
""" |
97 |
Sets the render window dimensions |
98 |
|
99 |
@param width: the width of the render window |
100 |
@type width: int |
101 |
|
102 |
@param height: the height of the render window |
103 |
@type height: int |
104 |
""" |
105 |
debugMsg("Called Renderer.setRenderWindowDimensions()") |
106 |
# check that the argument makes sense |
107 |
if __debug__: |
108 |
assert isinstance(width, int), "Incorrect data type; expected int" |
109 |
assert isinstance(height, int), "Incorrect data type; expected int" |
110 |
|
111 |
self.renderWindowWidth = width |
112 |
self.renderWindowHeight = height |
113 |
|
114 |
return |
115 |
|
116 |
def getRenderWindowDimensions(self): |
117 |
""" |
118 |
Gets the render window dimensions |
119 |
|
120 |
@return: tuple of window width and window height, respectively |
121 |
""" |
122 |
debugMsg("Called Renderer.getRenderWindowDimensions()") |
123 |
return (self.renderWindowWidth, self.renderWindowHeight) |
124 |
|
125 |
def getEvalStack(self): |
126 |
""" |
127 |
Gets the evaluation stack as it currently stands |
128 |
""" |
129 |
debugMsg("Called Renderer.getEvalStack()") |
130 |
return self._evalStack |
131 |
|
132 |
def addToEvalStack(self, evalString): |
133 |
""" |
134 |
Method to add commands to the evaluation stack |
135 |
|
136 |
@param evalString: The string of commands to be added to the evalStack |
137 |
@type evalString: string |
138 |
""" |
139 |
debugMsg("Called Renderer.addToEvalStack()") |
140 |
# check that the argument is ok |
141 |
if __debug__: |
142 |
assert isinstance(evalString, str), \ |
143 |
"Incorrect data type; expected string" |
144 |
|
145 |
self._evalStack += evalString + '\n' |
146 |
return |
147 |
|
148 |
def runString(self, evalString): |
149 |
""" |
150 |
Method to run the given string in the renderer python interpreter |
151 |
|
152 |
@param evalString: The string of commands to be run |
153 |
@type evalString: string |
154 |
""" |
155 |
debugMsg("Called Renderer.runString()") |
156 |
# check that the argument is ok |
157 |
if __debug__: |
158 |
assert isinstance(evalString, str), \ |
159 |
"Incorrect data type; expected string" |
160 |
|
161 |
self._evalStack += evalString + '\n' |
162 |
return |
163 |
|
164 |
def getInitStack(self): |
165 |
""" |
166 |
Gets the initialisation stack as it currently stands |
167 |
""" |
168 |
debugMsg("called Renderer.getInitStack()") |
169 |
return self._initStack |
170 |
|
171 |
def addToInitStack(self, evalString): |
172 |
""" |
173 |
Method to add commands to the reusable part of the evaluation stack |
174 |
|
175 |
@param evalString: The string of commands to be added to the evalStack |
176 |
@type evalString: string |
177 |
""" |
178 |
debugMsg("Called Renderer.addToInitStack()") |
179 |
# check that the argument is ok |
180 |
if __debug__: |
181 |
assert isinstance(evalString, str) |
182 |
|
183 |
self._initStack += evalString + '\n' |
184 |
return |
185 |
|
186 |
def resetEvalStack(self): |
187 |
""" |
188 |
Reset/flush the evaluation stack |
189 |
""" |
190 |
debugMsg("Called Renderer.resetEvalStack()") |
191 |
self._evalStack = "" |
192 |
return |
193 |
|
194 |
def resetInitStack(self): |
195 |
""" |
196 |
Reset/flush the initialisation stack |
197 |
""" |
198 |
debugMsg("Called Renderer.resetInitStack()") |
199 |
self._initStack = "" |
200 |
return |
201 |
|
202 |
# vim: expandtab shiftwidth=4: |