Index: ChangeLog =================================================================== --- ChangeLog (revision 1956) +++ ChangeLog (working copy) @@ -1,3 +1,8 @@ +2010-07-29 Georg von Hippel + + * Fixed bug reported by Jesse Dunietz; each diagram now gets its + own canvas, which can be set in the constructor. + 2010-01-22 Georg von Hippel * Added support for helicity-style (=>) arrows. This still needs work. Index: pyfeyn/deco.py =================================================================== --- pyfeyn/deco.py (revision 1956) +++ pyfeyn/deco.py (working copy) @@ -117,7 +117,7 @@ normal = normal.transformed(pyx.trafo.rotate(180, x, y)) nx, ny = normal.atend() if config.getOptions().VDEBUG: - FeynDiagram.currentCanvas.stroke(normal) + FeynDiagram.currentDiagram.currentCanvas.stroke(normal) ## Displace the arrow by this normal vector endx, endy = endx + (nx-x), endy + (ny-y) @@ -290,7 +290,7 @@ normal = normal.transformed(pyx.trafo.rotate(180, x, y)) nx, ny = normal.atend() if config.getOptions().VDEBUG: - FeynDiagram.currentCanvas.stroke(normal) + FeynDiagram.currentDiagram.currentCanvas.stroke(normal) ## Displace the label by this normal vector x, y = nx, ny Index: pyfeyn/lines.py =================================================================== --- pyfeyn/lines.py (revision 1956) +++ pyfeyn/lines.py (working copy) @@ -130,14 +130,14 @@ ny *= -1 arcpoint = Point(middle.x() + amount * nx, middle.y() + amount * ny) if config.getOptions().VDEBUG: - FeynDiagram.currentCanvas.stroke( + FeynDiagram.currenDiagram.currentCanvas.stroke( pyx.path.line(middle.x(), middle.y(), arcpoint.x(), arcpoint.y()), [color.rgb.blue] ) self.arcThru(arcpoint) if config.getOptions().DEBUG: print self.getVisiblePath() if config.getOptions().VDEBUG: - FeynDiagram.currentCanvas.stroke(self.getVisiblePath(), [color.rgb.blue]) + FeynDiagram.currenDiagram.currentCanvas.stroke(self.getVisiblePath(), [color.rgb.blue]) return self @@ -188,7 +188,7 @@ circle = pyx.path.circle(*cargs) line = pyx.path.line( self.p1.x(), self.p1.y(), arccenter.x(), arccenter.y()) if config.getOptions().VDEBUG: - FeynDiagram.currentCanvas.stroke(line, [color.rgb.green]) + FeynDiagram.currenDiagram.currentCanvas.stroke(line, [color.rgb.green]) ass, bs = circle.intersect(line) subpaths = circle.split(ass[0]) cpath = subpaths[0] @@ -274,7 +274,7 @@ p2path = self.p2.getPath() vispath = self.getPath() if config.getOptions().VDEBUG: - FeynDiagram.currentCanvas.stroke(vispath, [color.rgb.green]) + FeynDiagram.currenDiagram.currentCanvas.stroke(vispath, [color.rgb.green]) if p1path: ass, bs = p1path.intersect(vispath) for b in bs: @@ -288,11 +288,11 @@ math.fabs(pyx.unit.tocm(x.arclen() - y.arclen()))) ) vispath = subpaths[-1] if config.getOptions().VDEBUG: - FeynDiagram.currentCanvas.stroke(subpaths[0], [color.rgb.blue]) + FeynDiagram.currenDiagram.currentCanvas.stroke(subpaths[0], [color.rgb.blue]) if config.getOptions().VDEBUG: for a in ass: ix, iy = p1path.at(a) - FeynDiagram.currentCanvas.fill(pyx.path.circle(ix, iy, 0.05), + FeynDiagram.currenDiagram.currentCanvas.fill(pyx.path.circle(ix, iy, 0.05), [color.rgb.green]) if p2path: ass, bs = p2path.intersect(vispath) @@ -307,14 +307,14 @@ math.fabs(pyx.unit.tocm(x.arclen() - y.arclen()))) ) vispath = subpaths[-1] if config.getOptions().VDEBUG: - FeynDiagram.currentCanvas.stroke(subpaths[0], [color.rgb.red]) + FeynDiagram.currenDiagram.currentCanvas.stroke(subpaths[0], [color.rgb.red]) if config.getOptions().VDEBUG: for a in ass: ix, iy = p2path.at(a) - FeynDiagram.currentCanvas.fill(pyx.path.circle(ix, iy, 0.05), + FeynDiagram.currenDiagram.currentCanvas.fill(pyx.path.circle(ix, iy, 0.05), [color.rgb.blue]) if config.getOptions().VDEBUG: - FeynDiagram.currentCanvas.stroke(vispath, [color.rgb.red]) + FeynDiagram.currenDiagram.currentCanvas.stroke(vispath, [color.rgb.red]) #return pyx.path.circle(-2,-1,0.2) return vispath Index: pyfeyn/diagrams.py =================================================================== --- pyfeyn/diagrams.py (revision 1956) +++ pyfeyn/diagrams.py (working copy) @@ -8,15 +8,17 @@ class FeynDiagram: """The main PyFeyn diagram class.""" currentDiagram = None - currentCanvas = pyx.canvas.canvas() - def __init__(self, objects=None): + def __init__(self, objects=None, canvas=None): """Objects for holding a set of Feynman diagram components.""" self.__objs = objects if self.__objs is None: self.__objs = [] self.highestautolayer = 0 - FeynDiagram.currentCanvas = pyx.canvas.canvas() + if canvas is None: + self.currentCanvas = pyx.canvas.canvas() + else: + self.currentCanvas = canvas FeynDiagram.currentDiagram = self @@ -56,9 +58,9 @@ for obj in drawingobjs: if config.getOptions().DEBUG: print "Depth = ", obj.getDepth() - obj.draw(FeynDiagram.currentCanvas) + obj.draw(self.currentCanvas) - return FeynDiagram.currentCanvas + return self.currentCanvas def draw(self, outfile):