Exemple #1
0
def main():
    oparser = initOptions()
    (opts, args) = oparser.parse_args()
    fn = opts.macrosch
    outfn = opts.schout
    xcopies = opts.xclones
    ycopies = opts.yclones
    xsize = opts.xsize
    ysize = opts.ysize

    if (fn == None) or (outfn == None):
        oparser.exit('File names must be specified, --help for help')

    if xcopies + ycopies == 0:
        oparser.exit('Specify more than zero copies in X and/or Y dimensions')

    if (xcopies > 0) and (xsize == 0):
        oparser.exit(
            'Specify xsize of a clone in magic KiCad units, e.g. 8000; --help for help'
        )
    if (ycopies > 0) and (ysize == 0):
        oparser.exit(
            'Specify ysize of a clone in magic KiCad units, e.g. 2000; --help for help'
        )

    print 'Going to make %s copies along X axis with spacing of %s' % (xcopies,
                                                                       xsize)
    print 'Going to make %s copies along Y axis with spacing of %s' % (ycopies,
                                                                       ysize)

    fn = FileAccess(fn)
    sch = SchFile(fn)

    newitems = []
    for item in sch.items:
        clown = -1
        for y in xrange(ycopies + 1):
            if y == ycopies: continue
            for x in xrange(xcopies + 1):
                clown = clown + 1
                ii = CloneItem(item).items[0]
                newRefDes(item, ii, x, y + 1, xsize, ysize, clown)
                newitems.append(ii)

    sch.items = sch.items + newitems

    print 'Saving result to ', outfn
    output = FileAccess(outfn)
    output.write(sch)
Exemple #2
0
def main():
    oparser = initOptions() 
    (opts, args) = oparser.parse_args()
    fn = opts.macrosch
    outfn = opts.schout
    xcopies = opts.xclones
    ycopies = opts.yclones
    xsize = opts.xsize
    ysize = opts.ysize

    if (fn == None) or (outfn == None):
        oparser.exit('File names must be specified, --help for help')
    
    if xcopies + ycopies == 0:
        oparser.exit('Specify more than zero copies in X and/or Y dimensions')

    if (xcopies > 0) and (xsize == 0):
        oparser.exit('Specify xsize of a clone in magic KiCad units, e.g. 8000; --help for help')
    if (ycopies > 0) and (ysize == 0):
        oparser.exit('Specify ysize of a clone in magic KiCad units, e.g. 2000; --help for help')

    print 'Going to make %s copies along X axis with spacing of %s' % (xcopies,xsize)
    print 'Going to make %s copies along Y axis with spacing of %s' % (ycopies,ysize)

    fn = FileAccess(fn)
    sch = SchFile(fn)

    newitems = []
    for item in sch.items:
        clown = -1
        for y in xrange(ycopies+1):
            if y == ycopies: continue
            for x in xrange(xcopies+1):
                clown = clown + 1
                ii = CloneItem(item).items[0]
                newRefDes(item, ii, x, y + 1, xsize, ysize, clown)
                newitems.append(ii)

    sch.items = sch.items + newitems
    
    print 'Saving result to ', outfn
    output = FileAccess(outfn)
    output.write(sch)
Exemple #3
0
def main():
    templateX = 20

    oparser = initOptions()
    (opts, args) = oparser.parse_args()
    schfn = opts.macrosch
    brdfn = opts.brdin
    outfn = opts.brdout
    if (schfn == None) or (brdfn == None) or (outfn == None):
        oparser.exit('All three command-line arguments must be specified')

    sch = SchFile(FileAccess(schfn))
    brd = BrdFile(FileAccess(brdfn))

    print 'hello.jpg'

    # build a list of modules that are supposed to be placed in the template
    originalModRefs = []
    clonedModRefs = []
    for schi in sch.items:
        if schi.__class__ == Component:
            originalModRefs.append(schi.refdes)
            for suff in xrange(100):
                clonedModRefs.append(subRefDes(schi.refdes, suff))

    print 'originalModRefs=', len(originalModRefs)
    print 'clonedModRefs=', len(clonedModRefs)

    templateMods = []
    relocateMods = []
    tracks = []
    for placed in brd.items:
        if placed.__class__ == Module:
            if placed.refdes in originalModRefs:
                templateMods.append(placed)
            elif placed.refdes in clonedModRefs:
                relocateMods.append(placed)
        elif placed.__class__ == Track:
            track = placed
        elif placed.__class__ == CZoneOutline:
            if placed.layer == 25:
                print 'Found zone that defines the tracks to clone'
                zone = placed

    print 'templateMods=', len(templateMods)
    print 'relocateMods=', len(relocateMods)
    print 'tracks=', len(tracks)

    topleft = [10000, 10000]
    bottomright = [-1, -1]
    for c in zone.corners:
        if c[0] < topleft[0]: topleft[0] = c[0]
        if c[1] < topleft[1]: topleft[1] = c[1]
        if c[0] > bottomright[0]: bottomright[0] = c[0]
        if c[1] > bottomright[1]: bottomright[1] = c[1]

    print 'Found clone zone: (%s,%s)-(%s,%s)' % tuple(topleft + bottomright)
    templateX = (bottomright[0] - topleft[0])
    print 'Using width %s as X offset for the clones' % templateX

    nclones = 0
    nclonesmax = 20
    for relocate in relocateMods:
        for template in templateMods:
            for x in xrange(nclonesmax):
                refdes = subRefDes(template.refdes, x)
                if refdes == relocate.refdes:
                    #print 'refdes=', relocate.refdes
                    if (x + 1) > nclones: nclones = x + 1
                    move(relocate, template.xpos + (x + 1) * templateX,
                         template.ypos, template.orientation)

    print 'nclones=', nclones

    newpos = []
    newdes = []
    for po, de in zip(track.po, track.de):
        newpos.append(po)
        newdes.append(de)

        if (po.xstart > topleft[0]) and (po.ystart > topleft[1]) and \
           (po.xend < bottomright[0]) and (po.yend < bottomright[1]):

            for x in xrange(nclones):
                newdes.append(de.clone())
                newpo = po.clone()
                newpo.xstart = po.xstart + (x + 1) * templateX
                newpo.xend = po.xend + (x + 1) * templateX
                newpos.append(newpo)

    track.po = newpos
    track.de = newdes

    print 'Saving output to ', outfn
    output = FileAccess(outfn)
    output.write(brd)
Exemple #4
0
I had a schematic where my resistor parts had the values
in the footprint field (because I incorrectly defined the library part).

So this script replaces 'res' fields with the footprint fields.

'''

import os
import glob
import find_kipy
from kipy.fileobjs import SchFile
from kipy.utility import FileAccess

root = '.'

for fn in glob.glob(os.path.join(root, '*.sch')):
    fn = FileAccess(fn)
    sch = SchFile(fn)
    changed = False
    for item in sch.items:
        if not isinstance(item, sch.Component):
            continue
        fields = item.fields
        if fields[1][0] == 'RES':
            fields[1] = fields[2]
            fields[2] = None
            changed = True
    if changed:
        fn.write(sch)
Exemple #5
0
def main():
    mySVG = svg(0, 0, width="100%", height="100%")

    #~ proj = Project(projname)
    #~ if proj.topschfname:
    #~ try:
    #~ sch = ParseSchematic(proj)
    #~ if not proj.netfn.exists:
    #~ print "Netlist file %s not found" % proj.netfn
    #~ continue
    #~ netlistf = kicadnet.NetInfo(proj.netfn)
    #~ netlistf.checkparsed(sch.netinfo)

    #~ except Exception:
    #~ print traceback.format_exc()

    fn = FileAccess(schpath)
    sch = SchFile(fn)

    #~ printContents(sch)

    # iterate through items in sch, generate svg elements
    dbg = True
    for item in sch.items:
        if isinstance(item, sch.NoConn):
            if dbg: print "NoConn: ", item.posx, item.posy
            radius = 50  # radius in mils - just an indicator
            c = getCircle(item.posx,
                          item.posy,
                          radius,
                          linewidth=0,
                          fillcol='black')
            mySVG.addElement(c)
        if isinstance(item, sch.Connection):
            if dbg: print "Connection: ", item.posx, item.posy
            radius = 50  # radius in mils - just an indicator
            c = getCircle(item.posx, item.posy, radius, linewidth=2)
            mySVG.addElement(c)
        if isinstance(item, sch.Wire):
            # wiretype: Notes Line or Wire Line
            if dbg:
                print "Wire: ", item.startx, item.starty, item.endx, item.endy, item.wiretype
            myStyle = StyleBuilder()
            myStyle.setStrokeWidth(2)
            myStyle.setStroke('black')
            ci = numpy.array([item.startx, item.starty, item.endx, item.endy
                              ]) * mils2inch
            l = line("%fin" % (ci[0]), "%fin" % (ci[1]), "%fin" % (ci[2]),
                     "%fin" % (ci[3]))
            l.set_style(myStyle.getStyle())
            mySVG.addElement(l)
        if isinstance(item, sch.Text):
            # texttype: Label
            if dbg:
                print "Text: ", item.style, item.orientation, item.text, item.posx, item.posy, item.texttype, item.size
            t = getText(item.text, item.posx, item.posy, item.size)
            mySVG.addElement(t)

        if isinstance(item, sch.Component):
            if dbg:
                print "Component: ", item.subpart, item.parttype, item.timestamp, item.altref, item.variant, item.transform, item.redundant_num, item.posx, item.posy, item.parsestate, item.refdes
            rsize = 500  # square size in mils - just an indicator
            r = getRect(item.posx, item.posy, rsize, rsize, linewidth=2)
            mySVG.addElement(r)

            for field in item.fields:
                i_xpos = field[2]
                i_ypos = field[3]
                i_fontsize = field[4]
                i_extranum = field[5]

                if field[0] == item.refdes:
                    if dbg:
                        print ".. refdes", field[
                            0], i_xpos, i_ypos, i_fontsize, i_extranum
                    t = getText(field[0], i_xpos, i_ypos, i_fontsize)
                    mySVG.addElement(t)
                elif field[0] == item.parttype:
                    if dbg:
                        print ".. parttype", field[
                            0], i_xpos, i_ypos, i_fontsize, i_extranum
                    t = getText(field[0], i_xpos, i_ypos, i_fontsize)
                    mySVG.addElement(t)
                else:
                    if dbg:
                        print ".. pcbdes", field[
                            0], i_xpos, i_ypos, i_fontsize, i_extranum
                    t = getText(field[0], i_xpos, i_ypos, i_fontsize)
                    mySVG.addElement(t)

    #~ t=text("pySVG", x=0,y=100)
    #~ group=g()
    #~ group.set_transform("rotate(-30)")
    #~ t.set_stroke_width('1px')
    #~ t.set_stroke('#00C')
    #~ t.set_fill('none')
    #~ t.set_font_size("36")
    #~ group.addElement(t)
    #~ mySVG.addElement(group)

    #~ print mySVG.getXML()
    mySVG.save(svgpath)