Skip to content

Commit ace80fd

Browse files
authored
Merge pull request #84 from twinkletwinkie/master
Prepare Document UI & Backend Overhaul
2 parents e4ee22a + dc21ec6 commit ace80fd

File tree

3 files changed

+83
-73
lines changed

3 files changed

+83
-73
lines changed

inkscape/svg2shenzhen/prepare.py

Lines changed: 46 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#! /usr/bin/env python
22

3+
import warnings
34
import sys
45
sys.path.append('/usr/share/inkscape/extensions')
56
import inkex
@@ -17,11 +18,36 @@
1718

1819
identity_m = [[1.0,0.0,0.0],[0.0,1.0,0.0]]
1920

21+
kicadLayers = {
22+
"layerDrill" : "Drill",
23+
"layerDwgs_user" : "Dwgs.User",
24+
"layerF_Silks" : "F.SilkS",
25+
"layerF_Paste" : "F.Paste",
26+
"layerF_mask" : "F.Mask",
27+
"layerF_cu" : "F.Cu",
28+
"layerB_silks" : "B.SilkS",
29+
"layerB_paste" : "B.Paste",
30+
"layerB_mask" : "B.Mask",
31+
"layerB_cu" : "B.Cu",
32+
"layerEdge_Cuts" : "Edge.Cuts",
33+
"layerF_Adhes" : "F.Adhes",
34+
"layerB_Adhes" : "B.Adhes",
35+
"layerCmts_User" : "Cmts.User",
36+
"layerEco1_User" : "Eco1.User",
37+
"layerEco2_User" : "Eco2.User",
38+
"layerMargin" : "Margin",
39+
"layerB_CrtYd" : "B.CrtYd",
40+
"layerF_CrtYd" : "F.CrtYd",
41+
"layerB_Fab" : "B.Fab",
42+
"layerF_Fab" : "F.Fab"
43+
}
44+
kicadLayersSelected = {}
45+
2046
class Svg2ShenzhenPrepare(inkex.Effect):
2147
def __init__(self):
22-
"""init the effetc library and get options from gui"""
48+
"""init the effect library and get options from gui"""
2349
inkex.Effect.__init__(self)
24-
50+
2551
self.bb_width_center = 0
2652
self.bb_height_center = 0
2753
self.bb_scaling_h = 0
@@ -31,6 +57,13 @@ def __init__(self):
3157
def add_arguments(self, pars):
3258
pars.add_argument("--docwidth", type=float, default=0.0)
3359
pars.add_argument("--docheight", type=float, default=0.0)
60+
pars.add_argument("--name")
61+
pars.add_argument("--docGrid")
62+
# Prepare the Arguments for all of the Layers
63+
for key, value in kicadLayers.items():
64+
argumentKey = "--" + key
65+
pars.add_argument(argumentKey)
66+
3467

3568
def coordToKicad(self,XYCoord):
3669
return [
@@ -108,7 +141,7 @@ def addStamp(self,layer, textStr):
108141
layer.append(text)
109142

110143

111-
def prepareDocument(self):
144+
def prepareDocument(self, options):
112145
svg_layers = self.document.xpath('//svg:g[@inkscape:groupmode="layer"]', namespaces=inkex.NSS)
113146
layers = []
114147

@@ -135,68 +168,13 @@ def prepareDocument(self):
135168
rect = self.createWhitebg()
136169
white_layer.append(rect)
137170

138-
if ("F.Cu" not in layers and "F.Cu-disabled" not in layers):
139-
self.createLayer("F.Cu")
140-
141-
if ("B.Cu-disabled" not in layers and "B.Cu" not in layers):
142-
self.createLayer("B.Cu-disabled")
143-
144-
if ("B.Adhes-disabled" not in layers and "B.Adhes" not in layers):
145-
self.createLayer("B.Adhes-disabled")
146-
147-
if ("F.Adhes-disabled" not in layers and "F.Adhes" not in layers):
148-
self.createLayer("F.Adhes-disabled")
149-
150-
if ("B.Paste-disabled" not in layers and "B.Paste" not in layers):
151-
self.createLayer("B.Paste-disabled")
152-
153-
if ("F.Paste-disabled" not in layers and "F.Paste" not in layers):
154-
self.createLayer("F.Paste-disabled")
155-
156-
if ("B.SilkS-disabled" not in layers and "B.SilkS" not in layers):
157-
self.createLayer("B.SilkS-disabled")
158-
159-
if ("F.SilkS-disabled" not in layers and "F.SilkS" not in layers):
160-
self.createLayer("F.SilkS-disabled")
161-
162-
if ("B.Mask-disabled" not in layers and "B.Mask" not in layers):
163-
self.createLayer("B.Mask-disabled")
164-
165-
if ("F.Mask-disabled" not in layers and "F.Mask" not in layers):
166-
self.createLayer("F.Mask-disabled")
167-
168-
if ("Dwgs.User-disabled" not in layers and "Dwgs.User" not in layers):
169-
self.createLayer("Dwgs.User-disabled")
170-
171-
if ("Cmts.User-disabled" not in layers and "Cmts.User" not in layers):
172-
self.createLayer("Cmts.User-disabled")
173-
174-
if ("Eco1.User-disabled" not in layers and "Eco1.User" not in layers):
175-
self.createLayer("Eco1.User-disabled")
176-
177-
if ("Eco2.User-disabled" not in layers and "Eco2.User" not in layers):
178-
self.createLayer("Eco2.User-disabled")
179-
180-
if ("Edge.Cuts" not in layers):
181-
self.createLayer("Edge.Cuts")
182-
183-
if ("Margin-disabled" not in layers and "Margin" not in layers):
184-
self.createLayer("Margin-disabled")
185-
186-
if ("B.CrtYd-disabled" not in layers and "B.CrtYd" not in layers):
187-
self.createLayer("B.CrtYd-disabled")
188-
189-
if ("F.CrtYd-disabled" not in layers and "F.CrtYd" not in layers):
190-
self.createLayer("F.CrtYd-disabled")
191-
192-
if ("B.Fab-disabled" not in layers and "B.Fab" not in layers):
193-
self.createLayer("B.Fab-disabled")
194-
195-
if ("F.Fab-disabled" not in layers and "F.Fab" not in layers):
196-
self.createLayer("F.Fab-disabled")
171+
# Create the Selected Layers
172+
for key, value in reversed(kicadLayers.items()):
173+
disabledValue = '%s-disabled' % (value)
174+
selectedValue = getattr(options, key)
175+
if selectedValue == "true" and value not in layers and disabledValue not in layers:
176+
self.createLayer(value)
197177

198-
if ("Drill" not in layers):
199-
self.createLayer("Drill")
200178

201179
def setDocumentGrid(self):
202180
doc_view = self.document.xpath('//sodipodi:namedview',namespaces=inkex.NSS)[0]
@@ -220,10 +198,11 @@ def setDefaultUnits(self):
220198
def effect(self):
221199
self.setDocumentSquare(self.options.docwidth, self.options.docheight)
222200
self.setInkscapeScaling()
223-
self.prepareDocument()
224-
self.setDocumentGrid()
201+
self.prepareDocument(self.options)
202+
if self.options.docGrid == "true":
203+
self.setDocumentGrid()
225204
self.setDefaultUnits()
226-
205+
#warnings.warn(getattr(self.options, "layerF_Silk"))
227206

228207
def prepareLogo(self, lyr):
229208
logo_xml = """

inkscape/svg2shenzhen_about.inx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
<page name='about' _gui-text='About'>
99
<_param name="help" type="description">
1010
Svg2Shenzhen version SVGSZ_VER
11-
Inkscape extension for exporting drawing into Kicad PCB
11+
Inkscape extension to export drawing as a KiCad Module or KiCad Project
1212

1313
Get New Update:
1414
https://github.com/badgeek/svg2shenzhen

inkscape/svg2shenzhen_prepare.inx

Lines changed: 36 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,42 @@
33
<_name>1. Prepare Document</_name>
44
<id>net.svg2shenzhen.prepare.doc</id>
55
<dependency type="executable" location="extensions">svg2shenzhen/prepare.py</dependency>
6-
<param name="help" type="description">Prepare document for Kicad Export</param>
7-
<param name="docwidth" type="float" min="0.0" max="100000.0" _gui-text="Document width (mm)">100</param>
8-
<param name="docheight" type="float" min="0.0" max="100000.0" _gui-text="Document height (mm)">100</param>
9-
<param name="version" type="description">SVG2SHENZHEN SVGSZ_VER</param>
10-
6+
<param name="name" type="notebook">
7+
<page name="Tab1" _gui-text="General">
8+
<label appearance="header">Prepare Document For KiCad Export</label>
9+
<param name="docwidth" type="float" min="0.0" max="100000.0" _gui-text="Document Width (mm)">100</param>
10+
<param name="docheight" type="float" min="0.0" max="100000.0" _gui-text="Document Height (mm)">100</param>
11+
<separator />
12+
<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>
13+
<param name="layerDrill" type="boolean" gui-text="Drill" indent="2">true</param>
14+
<param name="layerDwgs_user" type="boolean" gui-text="Dwgs.User" indent="2">true</param>
15+
<param name="layerF_Silks" type="boolean" gui-text="F.SilkS" indent="2">true</param>
16+
<param name="layerF_mask" type="boolean" gui-text="F.Mask" indent="2">true</param>
17+
<param name="layerF_cu" type="boolean" gui-text="F.Cu" indent="2">true</param>
18+
<param name="layerB_silks" type="boolean" gui-text="B.SilkS" indent="2">true</param>
19+
<param name="layerB_mask" type="boolean" gui-text="B.Mask" indent="2">true</param>
20+
<param name="layerB_cu" type="boolean" gui-text="B.Cu" indent="2">true</param>
21+
<param name="layerEdge_Cuts" type="boolean" gui-text="Edge.Cuts" indent="2"></param>
22+
</page>
23+
<page name="Tab2" _gui-text="Other">
24+
<param name="docGrid" type="boolean" _gui-text="Enable Grid View">false</param>
25+
<separator />
26+
<label appearance="header">Optional Layers:</label>
27+
<param name="layerF_Paste" type="boolean" gui-text="F.Paste" indent="2">false</param>
28+
<param name="layerB_paste" type="boolean" gui-text="B.Paste" indent="2">false</param>
29+
<param name="layerF_Adhes" type="boolean" gui-text="F.Adhes" indent="2">false</param>
30+
<param name="layerB_Adhes" type="boolean" gui-text="B.Adhes" indent="2">false</param>
31+
<param name="layerCmts_User" type="boolean" gui-text="Cmts.User" indent="2">false</param>
32+
<param name="layerEco1_User" type="boolean" gui-text="Eco1.User" indent="2">false</param>
33+
<param name="layerEco2_User" type="boolean" gui-text="Eco2.User" indent="2">false</param>
34+
<param name="layerMargin" type="boolean" gui-text="Margin" indent="2">false</param>
35+
<param name="layerB_CrtYd" type="boolean" gui-text="B.CrtYd" indent="2">false</param>
36+
<param name="layerF_CrtYd" type="boolean" gui-text="F.CrtYd" indent="2">false</param>
37+
<param name="layerB_Fab" type="boolean" gui-text="B.Fab" indent="2">false</param>
38+
<param name="layerF_Fab" type="boolean" gui-text="F.Fab" indent="2">false</param>
39+
</page>
40+
</param>
41+
<label>SVG2SHENZHEN SVGSZ_VER</label>
1142
<effect needs-live-preview="false">
1243
<object-type>all</object-type>
1344
<effects-menu _name="Prepare Document">

0 commit comments

Comments
 (0)