workaround pyside bug #671
This commit is contained in:
parent
66dcfc7c67
commit
ebc805a45f
@ -110,7 +110,11 @@ class ParamObj(object):
|
|||||||
|
|
||||||
def __getitem__(self, item):
|
def __getitem__(self, item):
|
||||||
# bug in pyside 1.2.2 causes getitem to be called inside QGraphicsObject.parentItem:
|
# bug in pyside 1.2.2 causes getitem to be called inside QGraphicsObject.parentItem:
|
||||||
return self.getParam(item) # PySide bug: https://bugreports.qt.io/browse/PYSIDE-441
|
return self.getParam(item) # PySide bug: https://bugreports.qt.io/browse/PYSIDE-671
|
||||||
|
|
||||||
|
def __len__(self):
|
||||||
|
# Workaround for PySide bug: https://bugreports.qt.io/browse/PYSIDE-671
|
||||||
|
return 0
|
||||||
|
|
||||||
def getParam(self, param):
|
def getParam(self, param):
|
||||||
return self.__params[param]
|
return self.__params[param]
|
||||||
@ -235,35 +239,21 @@ class Lens(Optic):
|
|||||||
N must already be normalized in order to achieve the
|
N must already be normalized in order to achieve the
|
||||||
desired result.
|
desired result.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
iors = [self.ior(ray['wl']), 1.0]
|
iors = [self.ior(ray['wl']), 1.0]
|
||||||
for i in [0,1]:
|
for i in [0,1]:
|
||||||
surface = self.surfaces[i]
|
surface = self.surfaces[i]
|
||||||
ior = iors[i]
|
ior = iors[i]
|
||||||
p1, ai = surface.intersectRay(ray)
|
p1, ai = surface.intersectRay(ray)
|
||||||
#print "surface intersection:", p1, ai*180/3.14159
|
|
||||||
#trans = self.sceneTransform().inverted()[0] * surface.sceneTransform()
|
|
||||||
#p1 = trans.map(p1)
|
|
||||||
if p1 is None:
|
if p1 is None:
|
||||||
ray.setEnd(None)
|
ray.setEnd(None)
|
||||||
break
|
break
|
||||||
p1 = surface.mapToItem(ray, p1)
|
p1 = surface.mapToItem(ray, p1)
|
||||||
|
|
||||||
#print "adjusted position:", p1
|
|
||||||
#ior = self.ior(ray['wl'])
|
|
||||||
rd = ray['dir']
|
rd = ray['dir']
|
||||||
a1 = np.arctan2(rd[1], rd[0])
|
a1 = np.arctan2(rd[1], rd[0])
|
||||||
ar = a1 - ai + np.arcsin((np.sin(ai) * ray['ior'] / ior))
|
ar = a1 - ai + np.arcsin((np.sin(ai) * ray['ior'] / ior))
|
||||||
#print [x for x in [a1, ai, (np.sin(ai) * ray['ior'] / ior), ar]]
|
|
||||||
#print ai, np.sin(ai), ray['ior'], ior
|
|
||||||
ray.setEnd(p1)
|
ray.setEnd(p1)
|
||||||
dp = Point(np.cos(ar), np.sin(ar))
|
dp = Point(np.cos(ar), np.sin(ar))
|
||||||
#p2 = p1+dp
|
|
||||||
#p1p = self.mapToScene(p1)
|
|
||||||
#p2p = self.mapToScene(p2)
|
|
||||||
#dpp = Point(p2p-p1p)
|
|
||||||
ray = Ray(parent=ray, ior=ior, dir=dp)
|
ray = Ray(parent=ray, ior=ior, dir=dp)
|
||||||
return [ray]
|
return [ray]
|
||||||
|
|
||||||
@ -384,20 +374,12 @@ class CircleSurface(pg.GraphicsObject):
|
|||||||
else:
|
else:
|
||||||
## half-height of surface can't be larger than radius
|
## half-height of surface can't be larger than radius
|
||||||
h2 = min(h2, abs(r))
|
h2 = min(h2, abs(r))
|
||||||
|
|
||||||
#dx = abs(r) - (abs(r)**2 - abs(h2)**2)**0.5
|
|
||||||
#p.moveTo(-d*w/2.+ d*dx, d*h2)
|
|
||||||
arc = QtCore.QRectF(0, -r, r*2, r*2)
|
arc = QtCore.QRectF(0, -r, r*2, r*2)
|
||||||
#self.surfaces.append((arc.center(), r, h2))
|
|
||||||
a1 = np.arcsin(h2/r) * 180. / np.pi
|
a1 = np.arcsin(h2/r) * 180. / np.pi
|
||||||
a2 = -2*a1
|
a2 = -2*a1
|
||||||
a1 += 180.
|
a1 += 180.
|
||||||
self.path.arcMoveTo(arc, a1)
|
self.path.arcMoveTo(arc, a1)
|
||||||
self.path.arcTo(arc, a1, a2)
|
self.path.arcTo(arc, a1, a2)
|
||||||
#if d == -1:
|
|
||||||
#p1 = QtGui.QPainterPath()
|
|
||||||
#p1.addRect(arc)
|
|
||||||
#self.paths.append(p1)
|
|
||||||
self.h2 = h2
|
self.h2 = h2
|
||||||
|
|
||||||
def boundingRect(self):
|
def boundingRect(self):
|
||||||
@ -405,8 +387,6 @@ class CircleSurface(pg.GraphicsObject):
|
|||||||
|
|
||||||
def paint(self, p, *args):
|
def paint(self, p, *args):
|
||||||
return ## usually we let the optic draw.
|
return ## usually we let the optic draw.
|
||||||
#p.setPen(pg.mkPen('r'))
|
|
||||||
#p.drawPath(self.path)
|
|
||||||
|
|
||||||
def intersectRay(self, ray):
|
def intersectRay(self, ray):
|
||||||
## return the point of intersection and the angle of incidence
|
## return the point of intersection and the angle of incidence
|
||||||
@ -527,7 +507,6 @@ class Ray(pg.GraphicsObject, ParamObj):
|
|||||||
p2 = trans.map(pos + dir)
|
p2 = trans.map(pos + dir)
|
||||||
return Point(p1), Point(p2-p1)
|
return Point(p1), Point(p2-p1)
|
||||||
|
|
||||||
|
|
||||||
def setEnd(self, end):
|
def setEnd(self, end):
|
||||||
self['end'] = end
|
self['end'] = end
|
||||||
self.mkPath()
|
self.mkPath()
|
||||||
@ -561,6 +540,7 @@ def trace(rays, optics):
|
|||||||
r2 = o.propagateRay(r)
|
r2 = o.propagateRay(r)
|
||||||
trace(r2, optics[1:])
|
trace(r2, optics[1:])
|
||||||
|
|
||||||
|
|
||||||
class Tracer(QtCore.QObject):
|
class Tracer(QtCore.QObject):
|
||||||
"""
|
"""
|
||||||
Simple ray tracer.
|
Simple ray tracer.
|
||||||
|
Loading…
Reference in New Issue
Block a user