[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

Re: gEDA-user: gerbv export to png



Stephan Boettcher <boettcher@xxxxxxxxxxxxxxxxxx> writes:

> Julian <thepurlieu@xxxxxxxxx> writes:
>
>> Stephan,
>>     Yes, you can do it, however you can't use the project file for the
>> process.  Here's how:
>>
>> gerbv --export=png --dpi=600 --foreground=#ff0000ff
>> --foreground=#00ff0088 file1.gbx file2.gbx .......and so on
>>
>> Hope this helps.  Cheers--
>
> Absolutely, thanks!  Now I need to write a script to transform the
> project file into a Makefile rule :-)

Here is is.

#!/usr/bin/python
# coding=utf-8

# $Id: gvp2make.py 16 2010-02-24 12:38:06Z stephan $
# This script is free software (c) 2010 Stephan I. BÃttcher
# Distributed under GNU GPL Version 2 or later.

"""
Julian <thepurlieu@xxxxxxxxx> writes:

> Stephan,
>     Yes, you can do it, however you can't use the project file for the
> process.  Here's how:
>
> gerbv --export=png --dpi=600 --foreground=#ff0000ff
> --foreground=#00ff0088 file1.gbx file2.gbx .......and so on
>
> Hope this helps.  Cheers--
"""


usage="""
Prints a gerbv commandline to export a project to png,
with adjusted layer opacities.
Options:
        -h		print this help
        -g gerbv 	path of the gerbv executable
        -x png		export format
        -o layout.png~  output file
        -D 600		dpi resolution
        -w <option>	gerbv option
        -A layer=alpha	alpha between 0 and 1.0
        -X		execute the command
        -M		print Makefile to stdout
"""

options=[
    "gerbv",
    "--export=png",
    "--output=layout.png~",
    "--dpi=600",
    ]

"""
The layer names are the second dot-separated part of the filename.
Digits are stripped from the layer name and tried again.
"""

opacities = {
    "DEFAULT": 0.7,
    "frontsilk": 1.0,
    "backsilk": 1.0,
    "outline": 1.0,
    "plated-drill": 1.0,
    "frontpaste": 0.7,
    "backpaste": 0.7,
    "front": 0.5,
    "back": 0.5,
    "group": 0.4,
    }
    
execcmd=False
makefile=False

import sys, os
from getopt import gnu_getopt as getopt
oo,ifile = getopt(sys.argv[1:], "hg:x:o:w:D:XMA:")
for o,v in oo:
    if o=="-h":
        print "Synopsis:", sys.argv[0], "<options> gerbv-project-file", usage
        sys.exit()
    if o=="-g":
        options[0]=v
    if o=="-x":
        options[1]="--export=%s" % v
    if o=="-o":
        options[2]="--output=%s" % v
    if o=="-D":
        options[3]="--dpi=%s" % v
    if o=="-w":
        options.append(v)
    if o=="-X":
        execcmd=True
    if o=="-M":
        makefile=True
    if o=="-A":
        vv=v.split("=")
        opacities[vv[0]]=float(vv[1])
  
layers = {}
from fileinput import input
for l in input(ifile):
    ll = l.split()
    if ll[0]=="(define-layer!":
        ll=[llll.strip("\"')(#") for lll in ll for llll in lll.split(")(")]
        layers[int(ll[1])] = {
            "number" : int(ll[1]),
            "filename": ll[4],
            "visible": ll[7]=="t",
            "color": [int(lll)/65536.0 for lll in ll[10:13]],
            }
        
files=[]
lnumbers = [n for n in layers]
lnumbers.sort()
for n in lnumbers:
    l = layers[n]
    if l["visible"]:
        fn = l["filename"]
        files.append(fn)
        try:
            ltype = fn.split(".")[1]
            try:
                opacity = opacities[ltype]
            except KeyError:
                opacity = opacities[ltype.strip("0123456789")]
        except:
            opacity = opacities["DEFAULT"]
        l["color"].append(opacity)
        options.append("--foreground=#%02x%02x%02x%02x" % tuple(
            [int(c*255) for c in l["color"]]))

if makefile:
    target = options[2].split("=")[1]
    print "GERBV="+options[0]
    print "FORMAT="+options[1].split("=")[1]
    print "DPI="+options[3].split("=")[1]
    print target+": \\\n\t  "+" \\\n\t  ".join(files)
    print "\t$(GERBV) --output=$@ --export=$(FORMAT) --dpi=$(DPI) \\"
    print "\t  "+" \\\n\t  ".join(options[4:])+" \\\n\t $<"
else:
    cmd = " ".join(options+files)
    print cmd
    if execcmd:
        os.system(cmd)

-- 
Stephan BÃttcher                     FAX: +49-431-880-3968
Extraterrestrische Physik            Tel: +49-431-880-2508
I.f.Exp.u.Angew.Physik               mailto:boettcher@xxxxxxxxxxxxxxxxxx
Leibnizstr. 11, 24118 Kiel, Germany

_______________________________________________
geda-user mailing list
geda-user@xxxxxxxxxxxxxx
http://www.seul.org/cgi-bin/mailman/listinfo/geda-user