Ejemplo n.º 1
0
def bounds2(self, fast=1):
	"""Returns the Rect that this line fits in """
	if (fast):
		bound = LineUtils().fastBounds(self)
		return Rect(bound[0].x,bound[0].y, bound[1].x-bound[0].x, bound[1].y-bound[0].y)
	else:
		bb = self.toArea2().getBounds()
		return Rect(bb.x, bb.y, bb.width, bb.height)
Ejemplo n.º 2
0
    def drawBox(b):
        rr = rectForBox(b)

        outputTo, qq, qq2 = mergeGroup.create(
            b.get("box").get("id"), rr, VisualElement, PlainDraggableComponent,
            SplineComputingOverride)
        outputTo.name = b.get("box").get("id")
        if (mergeGroup.getLastWasNew()):
            outputTo.python_source_v = ""
        if (outputTo.where.python_autoExec_v != outputTo):
            outputTo.python_autoExec_v = ""

        outputTo.decoration_frame = ArrayList()

        if (b.get("box").has("varname")):
            tt = b.get("box").get("varname")
            text = PLine().moveTo(0, -9)
            text.containsText = 1
            text.text_v = tt
            text.font_v = Font("Gill Sans", 2, 10)
            text.derived = 1
            text.alignment_v = -1
            text(offsetFromSource=Vector2(1, 0))
            text(color=Vector4(0.25, 0, 0, 1))
            outputTo.decoration_frame.add(text)
            hasVarName = 1
            outputTo.maxBox = tt
            outputTo.needsMax = True
        else:
            hasVarName = 0

        outputTo.setFrame(rr)

        pp = PLine().roundRect(Rect(0, 0, rr.w, rr.h),
                               radius=15)(offsetFromSource=Vector2(0, 0))
        outputTo.noFrame = 1
        pp(derived=1,
           filled=1,
           color=Vector4([0, 0.25][hasVarName], 0, 0, 0.2))
        outputTo.decoration_frame.add(pp)
        pp = PLine().roundRect(Rect(0, 0, rr.w, rr.h),
                               radius=15)(offsetFromSource=Vector2(0, 0))
        outputTo.noFrame = 1
        pp(derived=1,
           filled=0,
           color=Vector4(0, 0, 0, 0.5),
           onSourceSelectedOnly=1)
        outputTo.decoration_frame.add(pp)

        if (b.get("box").has("text")):
            tt = b.get("box").get("text")
            text = PLine().moveTo(5, -3)
            text.containsText = 1
            text.text_v = tt
            text.font_v = Font("Gill Sans", 0, 12)
            text.derived = 1
            text(offsetFromSource=Vector2(0, 0.5))
            outputTo.decoration_frame.add(text)
Ejemplo n.º 3
0
def makeEmbeddedCanvas(name, x=None, y=None, w=500, h=500, background=Vector4()):
	"""Makes a self-enclosed drawing window and places it inside the main Field canvas. Like makeFullscreenCanvas and makeWindowedCanvas, but in this case the window is embedded inside Field"""
	if (x==None): x = getSelf().frame.x
	if (y==None): y = getSelf().frame.y+getSelf().frame.h+25
        print x,y,w,h
	a,b,c = VisualElement.createWithToken(name, getSelf(), Rect(x,y,w,h), VisualElement, PlainDraggableComponent, ThreedComputingOverride)
	a.name = "canvas: "+name
	if (a.where.python_source_v==getSelf()): a.python_source_v=""
	return a.canvas	
Ejemplo n.º 4
0
 def inletForBox(element, num, of):
     rr = element.getFrame(None)
     w = 10
     o = 4
     if (of == 1):
         alpha = 0
     else:
         alpha = (rr.w - w - o * 2) * num / (of - 1.0)
     return Rect(rr.x + alpha + o, rr.y - 2, w, 2)
Ejemplo n.º 5
0
def makePDF(geometry = None, bounds = None, background = None, scale=1, filename=None, is3d=0):
	"""
	makePDF exports PLines to a PDF file.

	Every parameter is actually optional. 
	X{geometry} specifies a list of PLines to draw, if it's
	missing, then everything on the canvas gets exported (you can set .notForExport on a line to
	make sure it doesn't get exported). 

	X{bounds} specifies a Rect or a PLine that encloses all of the geometry 
	that gets drawn. It becomes the "paper size" of the PDF that's exported. If it's ommitted then the 
	bounds of the geometry that's going to get exported is used instead. One trick is to make a PLine 
	with a rect, then pass that PLine into here as the parameter bounds.

	X{background} is an optional background color. 

	X{filename} is an optional filename (a temp file is used if this is omitted)

	X{scale} increases the "dpi" of the canvas, making the paper and the drawing bigger (while keeping the line thickness the same).
	
	"""

	if (not geometry):
		geometry = sum([x.lines for x in getSelf().all if hasattr(x, "lines") and x.lines], [])
	else:
		try:
			geometry = sum(geometry, [])
		except:
			pass

	something = geometry

	pdfContext = BasePDFGraphicsContext()
	
	if (not is3d):
		ld = SimplePDFLineDrawing()
		ld.installInto(pdfContext)
		SimplePDFImageDrawing().installInto(pdfContext, ld)
		ctx = SimplePDFLineDrawing
	else:
		ld = SimplePDFLineDrawing_3d()
		ld.installInto(pdfContext)		
		#SimplePDFImageDrawing().installInto(pdfContext, ld)
		ctx = SimplePDFLineDrawing_3d

	if (bounds==None):
		for n in something:
			b = LineUtils().fastBounds(n)
			if (b):
				b = Rect(b[0].x,b[0].y, b[1].x-b[0].x, b[1].y-b[0].y)
				if (b.w>0 or b.h>0):
					print b
					bounds = Rect.union(b, bounds)
		if (not bounds):
			print "makePDF error: no bounds specified"
			return None

		bounds.x-=2
		bounds.y-=2
		bounds.w+=4
		bounds.h+=4

	if (isinstance(bounds, PLine)):
		bounds = bounds.bounds()

	if (isinstance(bounds, CachedLine)):
		bounds = bounds.bounds2()

	print bounds
	pdfContext.paperWidth=bounds.w*scale
	pdfContext.paperHeight=bounds.h*scale
	
	if (background):
		pdfContext.getGlobalProperties().paperColor = background

	ctx.outputTransform.z=(-bounds.x)*pdfContext.paperWidth/bounds.w
	ctx.outputTransform.w=(bounds.y+bounds.h)*pdfContext.paperHeight/bounds.h
	ctx.outputTransform.x=pdfContext.paperWidth/bounds.w
	ctx.outputTransform.y=-pdfContext.paperHeight/bounds.h

	if (not filename):
		name = File.createTempFile("field", ".pdf", None)
	else:
		name = File(filename)

	pdfContext.drawTo = name

	pdfContext.windowDisplayEnter()
	for n in something:
		pdfContext.submitLine(n, n.getProperties())
	pdfContext.windowDisplayExit()

	return name.getPath()
Ejemplo n.º 6
0
 def bounds(self):
     """Returns the Rect that this line fits in """
     bound = LineUtils().fastBounds(self.__dict__["line"])
     return Rect(bound[0].x, bound[0].y, bound[1].x - bound[0].x,
                 bound[1].y - bound[0].y)
Ejemplo n.º 7
0
def makePDF(geometry=None,
            bounds=None,
            background=None,
            scale=1,
            filename=None,
            is3d=0):
    """
	makePDF exports PLines to a PDF file.

	Every parameter is actually optional. 
	X{geometry} specifies a list of PLines to draw, if it's
	missing, then everything on the canvas gets exported (you can set .notForExport on a line to
	make sure it doesn't get exported). 

	X{bounds} specifies a Rect or a PLine that encloses all of the geometry 
	that gets drawn. It becomes the "paper size" of the PDF that's exported. If it's ommitted then the 
	bounds of the geometry that's going to get exported is used instead. One trick is to make a PLine 
	with a rect, then pass that PLine into here as the parameter bounds.

	X{background} is an optional background color. 

	X{filename} is an optional filename (a temp file is used if this is omitted)

	X{scale} increases the "dpi" of the canvas, making the paper and the drawing bigger (while keeping the line thickness the same).
	
	"""

    if (not geometry):
        geometry = sum([
            x.lines for x in getSelf().all if hasattr(x, "lines") and x.lines
        ], [])
    else:
        try:
            geometry = sum(geometry, [])
        except:
            pass

    something = geometry

    pdfContext = BasePDFGraphicsContext()

    if (not is3d):
        ld = SimplePDFLineDrawing()
        ld.installInto(pdfContext)
        SimplePDFImageDrawing().installInto(pdfContext, ld)
        ctx = SimplePDFLineDrawing
    else:
        ld = SimplePDFLineDrawing_3d()
        ld.installInto(pdfContext)
        #SimplePDFImageDrawing().installInto(pdfContext, ld)
        ctx = SimplePDFLineDrawing_3d

    if (bounds == None):
        for n in something:
            b = LineUtils().fastBounds(n)
            if (b):
                b = Rect(b[0].x, b[0].y, b[1].x - b[0].x, b[1].y - b[0].y)
                if (b.w > 0 or b.h > 0):
                    print b
                    bounds = Rect.union(b, bounds)
        if (not bounds):
            print "makePDF error: no bounds specified"
            return None

        bounds.x -= 2
        bounds.y -= 2
        bounds.w += 4
        bounds.h += 4

    if (isinstance(bounds, PLine)):
        bounds = bounds.bounds()

    if (isinstance(bounds, CachedLine)):
        bounds = bounds.bounds2()

    print bounds
    pdfContext.paperWidth = bounds.w * scale
    pdfContext.paperHeight = bounds.h * scale

    if (background):
        pdfContext.getGlobalProperties().paperColor = background

    ctx.outputTransform.z = (-bounds.x) * pdfContext.paperWidth / bounds.w
    ctx.outputTransform.w = (bounds.y +
                             bounds.h) * pdfContext.paperHeight / bounds.h
    ctx.outputTransform.x = pdfContext.paperWidth / bounds.w
    ctx.outputTransform.y = -pdfContext.paperHeight / bounds.h

    if (not filename):
        name = File.createTempFile("field", ".pdf", None)
    else:
        name = File(filename)

    pdfContext.drawTo = name

    pdfContext.windowDisplayEnter()
    for n in something:
        pdfContext.submitLine(n, n.getProperties())
    pdfContext.windowDisplayExit()

    return name.getPath()
Ejemplo n.º 8
0
 def rectForBox(b):
     rr = b.get("box").get("patching_rect")
     return Rect(
         rr.get(0) + offsetx,
         rr.get(1) + offsety, rr.get(2), rr.get(3))