#!/usr/bin/env python
# Expose track for pcbnew

import pcbnew

def AddMask():
#Copy track to mask layer

    pcb = pcbnew.GetBoard()
    count = 0
    for track in pcb.GetTracks():
    #Set mask layer
        if type(track) == pcbnew.TRACK:
            if track.GetLayer() == pcbnew.F_Cu:
                maskLayer = pcbnew.F_Mask
            else:
                if(track.GetLayer() == pcbnew.B_Cu):
                    maskLayer = pcbnew.B_Mask
                else:
                    continue

            trackMask = pcbnew.TRACK(aParent=None, idtype=PCB_TRACE_T)
            trackMask.SetStart(track.GetStart())
            trackMask.SetEnd(track.GetEnd())
            trackMask.SetWidth(track.GetWidth())
            trackMask.SetLayer(maskLayer)
            pcb.Add(trackMask)
            count = count + 1

    print('{0} track masks added'.format(count))