diff --git a/inkscape/svg2shenzhen/prepare.py b/inkscape/svg2shenzhen/prepare.py index 84b93ac..507cf43 100644 --- a/inkscape/svg2shenzhen/prepare.py +++ b/inkscape/svg2shenzhen/prepare.py @@ -1,5 +1,6 @@ #! /usr/bin/env python +import warnings import sys sys.path.append('/usr/share/inkscape/extensions') import inkex @@ -17,11 +18,36 @@ identity_m = [[1.0,0.0,0.0],[0.0,1.0,0.0]] +kicadLayers = { + "layerDrill" : "Drill", + "layerDwgs_user" : "Dwgs.User", + "layerF_Silks" : "F.SilkS", + "layerF_Paste" : "F.Paste", + "layerF_mask" : "F.Mask", + "layerF_cu" : "F.Cu", + "layerB_silks" : "B.SilkS", + "layerB_paste" : "B.Paste", + "layerB_mask" : "B.Mask", + "layerB_cu" : "B.Cu", + "layerEdge_Cuts" : "Edge.Cuts", + "layerF_Adhes" : "F.Adhes", + "layerB_Adhes" : "B.Adhes", + "layerCmts_User" : "Cmts.User", + "layerEco1_User" : "Eco1.User", + "layerEco2_User" : "Eco2.User", + "layerMargin" : "Margin", + "layerB_CrtYd" : "B.CrtYd", + "layerF_CrtYd" : "F.CrtYd", + "layerB_Fab" : "B.Fab", + "layerF_Fab" : "F.Fab" +} +kicadLayersSelected = {} + class Svg2ShenzhenPrepare(inkex.Effect): def __init__(self): - """init the effetc library and get options from gui""" + """init the effect library and get options from gui""" inkex.Effect.__init__(self) - + self.bb_width_center = 0 self.bb_height_center = 0 self.bb_scaling_h = 0 @@ -31,6 +57,13 @@ def __init__(self): def add_arguments(self, pars): pars.add_argument("--docwidth", type=float, default=0.0) pars.add_argument("--docheight", type=float, default=0.0) + pars.add_argument("--name") + pars.add_argument("--docGrid") + # Prepare the Arguments for all of the Layers + for key, value in kicadLayers.items(): + argumentKey = "--" + key + pars.add_argument(argumentKey) + def coordToKicad(self,XYCoord): return [ @@ -108,7 +141,7 @@ def addStamp(self,layer, textStr): layer.append(text) - def prepareDocument(self): + def prepareDocument(self, options): svg_layers = self.document.xpath('//svg:g[@inkscape:groupmode="layer"]', namespaces=inkex.NSS) layers = [] @@ -135,68 +168,13 @@ def prepareDocument(self): rect = self.createWhitebg() white_layer.append(rect) - if ("F.Cu" not in layers and "F.Cu-disabled" not in layers): - self.createLayer("F.Cu") - - if ("B.Cu-disabled" not in layers and "B.Cu" not in layers): - self.createLayer("B.Cu-disabled") - - if ("B.Adhes-disabled" not in layers and "B.Adhes" not in layers): - self.createLayer("B.Adhes-disabled") - - if ("F.Adhes-disabled" not in layers and "F.Adhes" not in layers): - self.createLayer("F.Adhes-disabled") - - if ("B.Paste-disabled" not in layers and "B.Paste" not in layers): - self.createLayer("B.Paste-disabled") - - if ("F.Paste-disabled" not in layers and "F.Paste" not in layers): - self.createLayer("F.Paste-disabled") - - if ("B.SilkS-disabled" not in layers and "B.SilkS" not in layers): - self.createLayer("B.SilkS-disabled") - - if ("F.SilkS-disabled" not in layers and "F.SilkS" not in layers): - self.createLayer("F.SilkS-disabled") - - if ("B.Mask-disabled" not in layers and "B.Mask" not in layers): - self.createLayer("B.Mask-disabled") - - if ("F.Mask-disabled" not in layers and "F.Mask" not in layers): - self.createLayer("F.Mask-disabled") - - if ("Dwgs.User-disabled" not in layers and "Dwgs.User" not in layers): - self.createLayer("Dwgs.User-disabled") - - if ("Cmts.User-disabled" not in layers and "Cmts.User" not in layers): - self.createLayer("Cmts.User-disabled") - - if ("Eco1.User-disabled" not in layers and "Eco1.User" not in layers): - self.createLayer("Eco1.User-disabled") - - if ("Eco2.User-disabled" not in layers and "Eco2.User" not in layers): - self.createLayer("Eco2.User-disabled") - - if ("Edge.Cuts" not in layers): - self.createLayer("Edge.Cuts") - - if ("Margin-disabled" not in layers and "Margin" not in layers): - self.createLayer("Margin-disabled") - - if ("B.CrtYd-disabled" not in layers and "B.CrtYd" not in layers): - self.createLayer("B.CrtYd-disabled") - - if ("F.CrtYd-disabled" not in layers and "F.CrtYd" not in layers): - self.createLayer("F.CrtYd-disabled") - - if ("B.Fab-disabled" not in layers and "B.Fab" not in layers): - self.createLayer("B.Fab-disabled") - - if ("F.Fab-disabled" not in layers and "F.Fab" not in layers): - self.createLayer("F.Fab-disabled") + # Create the Selected Layers + for key, value in reversed(kicadLayers.items()): + disabledValue = '%s-disabled' % (value) + selectedValue = getattr(options, key) + if selectedValue == "true" and value not in layers and disabledValue not in layers: + self.createLayer(value) - if ("Drill" not in layers): - self.createLayer("Drill") def setDocumentGrid(self): doc_view = self.document.xpath('//sodipodi:namedview',namespaces=inkex.NSS)[0] @@ -220,10 +198,11 @@ def setDefaultUnits(self): def effect(self): self.setDocumentSquare(self.options.docwidth, self.options.docheight) self.setInkscapeScaling() - self.prepareDocument() - self.setDocumentGrid() + self.prepareDocument(self.options) + if self.options.docGrid == "true": + self.setDocumentGrid() self.setDefaultUnits() - + #warnings.warn(getattr(self.options, "layerF_Silk")) def prepareLogo(self, lyr): logo_xml = """ diff --git a/inkscape/svg2shenzhen_about.inx b/inkscape/svg2shenzhen_about.inx index 84c1834..aea2f7e 100644 --- a/inkscape/svg2shenzhen_about.inx +++ b/inkscape/svg2shenzhen_about.inx @@ -8,7 +8,7 @@ <_param name="help" type="description"> Svg2Shenzhen version SVGSZ_VER -Inkscape extension for exporting drawing into Kicad PCB +Inkscape extension to export drawing as a KiCad Module or KiCad Project Get New Update: https://github.com/badgeek/svg2shenzhen diff --git a/inkscape/svg2shenzhen_prepare.inx b/inkscape/svg2shenzhen_prepare.inx index ca29742..ba9d14e 100644 --- a/inkscape/svg2shenzhen_prepare.inx +++ b/inkscape/svg2shenzhen_prepare.inx @@ -3,11 +3,42 @@ <_name>1. Prepare Document net.svg2shenzhen.prepare.doc svg2shenzhen/prepare.py - Prepare document for Kicad Export - 100 - 100 - SVG2SHENZHEN SVGSZ_VER - + + + + 100 + 100 + + Select Layers To Use (!) + true + true + true + true + true + true + true + true + + + + false + + + false + false + false + false + false + false + false + false + false + false + false + false + + + all