Skip to content

Commit

Permalink
Merge pull request #84 from twinkletwinkie/master
Browse files Browse the repository at this point in the history
Prepare Document UI & Backend Overhaul
  • Loading branch information
badgeek committed Aug 18, 2020
2 parents e4ee22a + dc21ec6 commit ace80fd
Show file tree
Hide file tree
Showing 3 changed files with 83 additions and 73 deletions.
113 changes: 46 additions & 67 deletions 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
Expand All @@ -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
Expand All @@ -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 [
Expand Down Expand Up @@ -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 = []

Expand All @@ -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]
Expand All @@ -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 = """
Expand Down
2 changes: 1 addition & 1 deletion inkscape/svg2shenzhen_about.inx
Expand Up @@ -8,7 +8,7 @@
<page name='about' _gui-text='About'>
<_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
Expand Down
41 changes: 36 additions & 5 deletions inkscape/svg2shenzhen_prepare.inx
Expand Up @@ -3,11 +3,42 @@
<_name>1. Prepare Document</_name>
<id>net.svg2shenzhen.prepare.doc</id>
<dependency type="executable" location="extensions">svg2shenzhen/prepare.py</dependency>
<param name="help" type="description">Prepare document for Kicad Export</param>
<param name="docwidth" type="float" min="0.0" max="100000.0" _gui-text="Document width (mm)">100</param>
<param name="docheight" type="float" min="0.0" max="100000.0" _gui-text="Document height (mm)">100</param>
<param name="version" type="description">SVG2SHENZHEN SVGSZ_VER</param>

<param name="name" type="notebook">
<page name="Tab1" _gui-text="General">
<label appearance="header">Prepare Document For KiCad Export</label>
<param name="docwidth" type="float" min="0.0" max="100000.0" _gui-text="Document Width (mm)">100</param>
<param name="docheight" type="float" min="0.0" max="100000.0" _gui-text="Document Height (mm)">100</param>
<separator />
<param name="descr" type="description" appearance="header" _gui-description="Layers can be disabled after being created by adding '-disabled' to the layer name e.g. 'F.SilkS-disabled'">Select Layers To Use (!)</param>
<param name="layerDrill" type="boolean" gui-text="Drill" indent="2">true</param>
<param name="layerDwgs_user" type="boolean" gui-text="Dwgs.User" indent="2">true</param>
<param name="layerF_Silks" type="boolean" gui-text="F.SilkS" indent="2">true</param>
<param name="layerF_mask" type="boolean" gui-text="F.Mask" indent="2">true</param>
<param name="layerF_cu" type="boolean" gui-text="F.Cu" indent="2">true</param>
<param name="layerB_silks" type="boolean" gui-text="B.SilkS" indent="2">true</param>
<param name="layerB_mask" type="boolean" gui-text="B.Mask" indent="2">true</param>
<param name="layerB_cu" type="boolean" gui-text="B.Cu" indent="2">true</param>
<param name="layerEdge_Cuts" type="boolean" gui-text="Edge.Cuts" indent="2"></param>
</page>
<page name="Tab2" _gui-text="Other">
<param name="docGrid" type="boolean" _gui-text="Enable Grid View">false</param>
<separator />
<label appearance="header">Optional Layers:</label>
<param name="layerF_Paste" type="boolean" gui-text="F.Paste" indent="2">false</param>
<param name="layerB_paste" type="boolean" gui-text="B.Paste" indent="2">false</param>
<param name="layerF_Adhes" type="boolean" gui-text="F.Adhes" indent="2">false</param>
<param name="layerB_Adhes" type="boolean" gui-text="B.Adhes" indent="2">false</param>
<param name="layerCmts_User" type="boolean" gui-text="Cmts.User" indent="2">false</param>
<param name="layerEco1_User" type="boolean" gui-text="Eco1.User" indent="2">false</param>
<param name="layerEco2_User" type="boolean" gui-text="Eco2.User" indent="2">false</param>
<param name="layerMargin" type="boolean" gui-text="Margin" indent="2">false</param>
<param name="layerB_CrtYd" type="boolean" gui-text="B.CrtYd" indent="2">false</param>
<param name="layerF_CrtYd" type="boolean" gui-text="F.CrtYd" indent="2">false</param>
<param name="layerB_Fab" type="boolean" gui-text="B.Fab" indent="2">false</param>
<param name="layerF_Fab" type="boolean" gui-text="F.Fab" indent="2">false</param>
</page>
</param>
<label>SVG2SHENZHEN SVGSZ_VER</label>
<effect needs-live-preview="false">
<object-type>all</object-type>
<effects-menu _name="Prepare Document">
Expand Down

0 comments on commit ace80fd

Please sign in to comment.