1
2 """ Simple sources
3
4 Builds and displays simple sources. Grants easy access to the actual source
5 and the representation objects"""
6
7 from paraview import servermanager
8
9 from PyFoam.Paraview import proxyManager as pm
10 from PyFoam.Paraview import renderView as rv
11 from PyFoam.Paraview import characteristicLength as lc
12 from PyFoam.Paraview import getCenter as gc
13 from PyFoam.Paraview import transformsModule as tm
14
15 from SourceBase import SourceBase
16
17 import math
18
20 """Base class for the simple sources
21
22 The member src is the actual source object.
23 The member repr is the representation object"""
24
26 """@param name: The name under which the thing should be displayed
27 @param src: the actual source proxy"""
28 SourceBase.__init__(self,src)
29 self.name = name
30 pm.RegisterProxy("sources",self.name,self.src)
31 self.repr=servermanager.CreateRepresentation(self.src,rv())
32 pm.RegisterProxy("representations",self.name+"_repr",self.repr)
33
35 """Unregister the Proxies, but keept the objects"""
36 pm.UnRegisterProxy("sources",self.name,self.src)
37 pm.UnRegisterProxy("representations",self.name+"_repr",self.repr)
38
40 """Does not yet work properly"""
41 self.unregister()
42 del self.src
43 del self.repr
44
46 """Displays a sphere"""
47
48 - def __init__(self,name,center,relRadius=0.01,absRadius=None):
49 """@param name: name under which the sphere should be displayed
50 @param center: the center of the sphere
51 @param relRadius: radius relative to the characteristic length
52 @param absRadius: absolute radius. Overrides relRadius if set"""
53
54 try:
55 sphr=servermanager.sources.SphereSource()
56 except AttributeError:
57 sphr=servermanager.sources.Sphere()
58
59 sphr.Center=list(center)
60 if absRadius:
61 sphr.Radius=absRadius
62 else:
63 sphr.Radius=lc()*relRadius
64
65 SimpleSource.__init__(self,name,sphr)
66
67 -class Point(SimpleSource):
68 """Displays a point"""
69
71 """@param name: name under which the point should be displayed
72 @param center: the center of the point"""
73
74 pt=servermanager.sources.PointSource()
75 pt.Center = list(center)
76 SimpleSource.__init__(self,name,pt)
77
78 -class Line(SimpleSource):
79 """Displays a line"""
80
82 """@param name: name under which the line should be displayed
83 @param pt1: the start of the line
84 @param pt2: the end of the line"""
85
86 try:
87 ln=servermanager.sources.LineSource()
88 except AttributeError:
89 ln=servermanager.sources.Line()
90
91 ln.Point1 = list(pt1)
92 ln.Point2 = list(pt2)
93 SimpleSource.__init__(self,name,ln)
94
95 -class Plane(SimpleSource):
96 """Displays a plane"""
97
99 """@param name: name under which the plane should be displayed
100 @param origin: the origin of the plane
101 @param pt1: one point the plane spans to
102 @param pt2: the other point the plane spans to"""
103
104 try:
105 pl=servermanager.sources.PlaneSource()
106 except AttributeError:
107 pl=servermanager.sources.Plane()
108
109 pl.Origin = list(origin)
110 pl.Point1 = list(pt1)
111 pl.Point2 = list(pt2)
112 SimpleSource.__init__(self,name,pl)
113
114 -class Cube(SimpleSource):
115 """Displays a cube"""
116
118 """@param name: name under which the cube should be displayed
119 @param pt1: Point one that describes the box
120 @param pt2: Point two that describes the box"""
121
122 pt1=self.makeVector(pt1)
123 pt2=self.makeVector(pt2)
124 try:
125 box=servermanager.sources.CubeSource()
126 except AttributeError:
127 box=servermanager.sources.Box()
128 box.Center=list(0.5*(pt1+pt2))
129 diff=pt1-pt2
130 box.XLength=abs(diff[0])
131 box.YLength=abs(diff[1])
132 box.ZLength=abs(diff[2])
133
134 SimpleSource.__init__(self,name,box)
135
136 -class STL(SimpleSource):
137 """Displays a STL-File"""
138
140 """@param name: name under which the surface should be displayed
141 @param stlFile: the STL-file"""
142
143 try:
144 stl=servermanager.sources.stlreader()
145 except AttributeError:
146 stl=servermanager.sources.STLReader()
147
148 stl.FileNames=[stlFile]
149 stl.UpdatePipeline()
150
151 SimpleSource.__init__(self,name,stl)
152
153 -class Text(SimpleSource):
154 """Displays a Vector-Text"""
155
156 - def __init__(self,name,text,scale=1,position=None):
157 """@param name: name under which the sphere should be displayed
158 @param text: the text that will be displayed
159 @param scale: the scaling of the text (in terms ofcharacterist length of the geometry
160 @param position: the actual position at which the object should be centered"""
161
162 try:
163 txt=servermanager.sources.VectorText()
164 except AttributeError:
165 txt=servermanager.sources.a3DText()
166
167 txt.Text=text
168
169 SimpleSource.__init__(self,name,txt)
170
171 if not position:
172 position=gc()
173
174 try:
175 self.repr.Translate=list(position)
176 except AttributeError:
177 self.repr.Position=list(position)
178
179 self.repr.Origin=list(position)
180
181 scale*=lc()/self.characteristicLength()
182
183 self.repr.Scale=(scale,scale,scale)
184
186 """A Source that looks in a specific direction.
187 Assumes that the original base is located at (0 0 0)"""
188
190 """@param name: name under which the arrow will be displayed
191 @param src: The source objects
192 @param base: the base the arrow points away from
193 @param tip: the point the arrow points to"""
194 SimpleSource.__init__(self,name,src)
195 self.base=base
196 self.tip =tip
197 self.recalc()
198
199
200
201
202
203
204
205
207 """Recalculate the orientation of the object according to the tip and
208 the base"""
209 diff=self.tip-self.base
210 r=abs(diff)
211 phi=math.acos(diff[0]/(r+1e-15))*180/math.pi
212 theta=math.atan2(diff[1],-diff[2])*180/math.pi
213 self.repr.Scale=[r]*3
214 self.repr.Position=list(self.base)
215 self.repr.Orientation=[theta,phi,0]
216
218 """Reset the base point"""
219 self.base=base
220 self.recalc()
221
223 """Reset the tip point"""
224 self.tip=tip
225 self.recalc()
226
227 -class Arrow(DirectedSource):
228 """Displays a simple arrow"""
229
231 """@param name: name under which the arrow will be displayed
232 @param base: the base the arrow points away from
233 @param tip: the point the arrow points to"""
234
235 try:
236 DirectedSource.__init__(self,
237 name,
238 servermanager.sources.ArrowSource(),
239 base,
240 tip)
241 except AttributeError:
242 DirectedSource.__init__(self,
243 name,
244 servermanager.sources.Arrow(),
245 base,
246 tip)
247
248 -class Glyph(DirectedSource):
249 """Displays a simple glyph"""
250
252 """@param name: name under which the glyph will be displayed
253 @param base: the base the glyph points away from
254 @param tip: the point the glyph points to"""
255
256 try:
257 DirectedSource.__init__(self,
258 name,
259 servermanager.sources.GlyphSource2D(),
260 base,
261 tip)
262 except AttributeError:
263 DirectedSource.__init__(self,
264 name,
265 servermanager.sources.a2DGlyph(),
266 base,
267 tip)
268