11#! /usr/bin/env python
22
3+ import warnings
34import sys
45sys .path .append ('/usr/share/inkscape/extensions' )
56import inkex
1718
1819identity_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+
2046class 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 = """
0 commit comments