From f1f736cf3c4819bb60bfda6575bec8bc01d52c9e Mon Sep 17 00:00:00 2001 From: Matthijs Kooijman Date: Thu, 22 Jun 2017 11:55:12 +0200 Subject: [PATCH 01/33] Mark the footprint as virtual in the pretty format The export currently adds (attr smd), which marks the footprint as an SMD component (which internally sets the MOD_CMS attribute, and in the GUI marks the component as "Normal+Insert"). This causes it to be exported in a .pos file for a pick & place machine. Since this is just a silkscreen and not an actual component, this makes no sense. This commit instead sets (attr virtual) (which internally sets MOD_VIRTUAL, and in the GUI marks the component as "Virtual") which causes it to be ignored by various parts of kicad that iterate over actual components. --- svg2mod.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/svg2mod.py b/svg2mod.py index 21529f3..4866f8b 100755 --- a/svg2mod.py +++ b/svg2mod.py @@ -1201,7 +1201,7 @@ def _get_module_name( self, front = None ): def _write_library_intro( self ): self.output_file.write( """(module {0} (layer F.Cu) (tedit {1:8X}) - (attr smd) + (attr virtual) (descr "{2}") (tags {3}) """.format( From 75d59f297846c398f3c32d5b0d675c9e08d2bbd2 Mon Sep 17 00:00:00 2001 From: Farsheed Date: Wed, 9 May 2018 12:45:17 -0500 Subject: [PATCH 02/33] Update svg2mod.py to work with python3 methods --- svg2mod/svg2mod.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/svg2mod/svg2mod.py b/svg2mod/svg2mod.py index cc3f060..0428fc8 100755 --- a/svg2mod/svg2mod.py +++ b/svg2mod/svg2mod.py @@ -553,7 +553,7 @@ def _prune( self, items = None ): if items is None: self.layers = {} - for name in self.layer_map.iterkeys(): + for name in self.layer_map.keys(): self.layers[ name ] = None items = self.imported.svg.items @@ -564,7 +564,7 @@ def _prune( self, items = None ): if not isinstance( item, svg.Group ): continue - for name in self.layers.iterkeys(): + for name in self.layers.keys(): #if re.search( name, item.name, re.I ): if name == item.name: print( "Found SVG layer: {}".format( item.name ) ) @@ -653,7 +653,7 @@ def _write_module( self, front ): front, ) - for name, group in self.layers.iteritems(): + for name, group in self.layers.items(): if group is None: continue @@ -1094,7 +1094,7 @@ def _write_library_intro( self ): # Write index: for module_name in sorted( - self.loaded_modules.iterkeys(), + self.loaded_modules.keys(), key = str.lower ): self.output_file.write( module_name + "\n" ) @@ -1111,7 +1111,7 @@ def _write_preserved_modules( self, up_to = None ): up_to = up_to.lower() for module_name in sorted( - self.loaded_modules.iterkeys(), + self.loaded_modules.keys(), key = str.lower ): if up_to is not None and module_name.lower() >= up_to: From a028e419ffa4976b8babcfcf01c5e2248f82cc33 Mon Sep 17 00:00:00 2001 From: Farsheed Date: Wed, 9 May 2018 12:46:27 -0500 Subject: [PATCH 03/33] Updates svg.py to work with python3 --- svg2mod/svg/svg/svg.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/svg2mod/svg/svg/svg.py b/svg2mod/svg/svg/svg.py index 244fdaa..02949d2 100644 --- a/svg2mod/svg/svg/svg.py +++ b/svg2mod/svg/svg/svg.py @@ -262,7 +262,7 @@ def __init__(self, elt=None): self.name = "" if elt is not None: - for id, value in elt.attrib.iteritems(): + for id, value in elt.attrib.items(): id = self.parse_name( id ) if id[ "name" ] == "label": From 57e62dff045832f4adf012445814f4b04d02882e Mon Sep 17 00:00:00 2001 From: Farsheed Date: Wed, 9 May 2018 12:49:04 -0500 Subject: [PATCH 04/33] Update README.md Add notes about python3 --- README.md | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/README.md b/README.md index d048ea5..37e7c09 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,19 @@ # svg2mod This is a small program to convert Inkscape SVG drawings to KiCad footprint module files. It uses [cjlano's python SVG parser and drawing module](https://github.com/cjlano/svg) to interpret drawings and approximate curves using straight line segments. Module files can be output in KiCad's legacy or s-expression (i.e., pretty) formats. Horizontally mirrored modules are automatically generated for use on the back of a 2-layer PCB. +## Requirements + +Python 3 + +## Installation + +```python3 setup.py install``` + +- OR - + +```pip3 install git+https://github.com/zirafa/svg2mod``` + + ## Usage ``` usage: svg2mod.py [-h] -i FILENAME [-o FILENAME] [--name NAME] [--value VALUE] From 231ecdd7683034b112d6f83c834cbb01a94506e3 Mon Sep 17 00:00:00 2001 From: Farsheed Date: Wed, 9 May 2018 12:52:54 -0500 Subject: [PATCH 05/33] Update README.md --- README.md | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 37e7c09..1777191 100644 --- a/README.md +++ b/README.md @@ -9,11 +9,20 @@ Python 3 ```python3 setup.py install``` -- OR - +OR you can install it using the PIP package manager: ```pip3 install git+https://github.com/zirafa/svg2mod``` +## Example + +```python3 svg2mod.py -i input.svg``` + +OR for PIP + +```svg2mod -i input.svg``` + + ## Usage ``` usage: svg2mod.py [-h] -i FILENAME [-o FILENAME] [--name NAME] [--value VALUE] From 32977b8ffdc7a1269bd9656c69c0d738de24d002 Mon Sep 17 00:00:00 2001 From: Farsheed Date: Wed, 9 May 2018 12:56:21 -0500 Subject: [PATCH 06/33] Update README.md --- README.md | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) diff --git a/README.md b/README.md index 1777191..9ba8afc 100644 --- a/README.md +++ b/README.md @@ -7,22 +7,14 @@ Python 3 ## Installation -```python3 setup.py install``` - -OR you can install it using the PIP package manager: - ```pip3 install git+https://github.com/zirafa/svg2mod``` +Note: ```python3 setup.py install``` does not work. ## Example -```python3 svg2mod.py -i input.svg``` - -OR for PIP - ```svg2mod -i input.svg``` - ## Usage ``` usage: svg2mod.py [-h] -i FILENAME [-o FILENAME] [--name NAME] [--value VALUE] From ac6714bf25281bf12317c23045dfc39236839cf0 Mon Sep 17 00:00:00 2001 From: Farsheed Date: Wed, 16 May 2018 16:04:27 -0500 Subject: [PATCH 07/33] Update README.md --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 9ba8afc..930d91e 100644 --- a/README.md +++ b/README.md @@ -13,11 +13,11 @@ Note: ```python3 setup.py install``` does not work. ## Example -```svg2mod -i input.svg``` +```svg2mod -i input.svg -p 1.0``` ## Usage ``` -usage: svg2mod.py [-h] -i FILENAME [-o FILENAME] [--name NAME] [--value VALUE] +usage: svg2mod [-h] -i FILENAME [-o FILENAME] [--name NAME] [--value VALUE] [-f FACTOR] [-p PRECISION] [-d DPI] [--front-only] [--format FORMAT] [--units UNITS] From ecfcabe763ac1e9b7fa14eedfc5a4b9b33c44223 Mon Sep 17 00:00:00 2001 From: NaH012 <1110mdj@gmail.com> Date: Mon, 13 Aug 2018 16:52:03 -0600 Subject: [PATCH 08/33] Update .gitignore to block more files and initial changes to svg2mod --- .gitignore | 4 ++++ svg2mod/svg2mod.py | 36 ++++++++++++++++++++---------------- 2 files changed, 24 insertions(+), 16 deletions(-) diff --git a/.gitignore b/.gitignore index 24bc31d..6509060 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,7 @@ *~ .*.sw? *.pyc +build +dist +svg2mod.egg-info +*.kicad_mod diff --git a/svg2mod/svg2mod.py b/svg2mod/svg2mod.py index cc3f060..b0d8451 100755 --- a/svg2mod/svg2mod.py +++ b/svg2mod/svg2mod.py @@ -535,13 +535,13 @@ def _calculate_translation( self ): min_point, max_point = self.imported.svg.bbox() - # Center the drawing: - adjust_x = min_point.x + ( max_point.x - min_point.x ) / 2.0 - adjust_y = min_point.y + ( max_point.y - min_point.y ) / 2.0 + ## Center the drawing: + #adjust_x = min_point.x + ( max_point.x - min_point.x ) / 2.0 + #adjust_y = min_point.y + ( max_point.y - min_point.y ) / 2.0 self.translation = svg.Point( - 0.0 - adjust_x, - 0.0 - adjust_y, + 0.0, + 0.0, ) @@ -1176,13 +1176,20 @@ class Svg2ModExportPretty( Svg2ModExport ): layer_map = { #'inkscape-name' : kicad-name, - 'Cu' : "{}.Cu", - 'Adhes' : "{}.Adhes", - 'Paste' : "{}.Paste", - 'SilkS' : "{}.SilkS", - 'Mask' : "{}.Mask", - 'CrtYd' : "{}.CrtYd", - 'Fab' : "{}.Fab", + 'F.Cu' : "F.Cu", + 'B.Cu' : "B.Cu", + 'F.Adhes' : "F.Adhes", + 'B.Adhes' : "B.Adhes", + 'F.Paste' : "F.Paste", + 'B.Paste' : "B.Paste", + 'F.SilkS' : "F.SilkS", + 'B.SilkS' : "B.SilkS", + 'F.Mask' : "F.Mask", + 'B.Mask' : "B.Mask", + 'F.CrtYd' : "F.CrtYd", + 'B.CrtYd' : "B.CrtYd", + 'F.Fab' : "F.Fab", + 'B.Fab' : "B.Fab", 'Edge.Cuts' : "Edge.Cuts" } @@ -1191,10 +1198,7 @@ class Svg2ModExportPretty( Svg2ModExport ): def _get_layer_name( self, name, front ): - if front: - return self.layer_map[ name ].format("F") - else: - return self.layer_map[ name ].format("B") + return self.layer_map[ name ] #------------------------------------------------------------------------ From 576f3b7830e55f3272ad24f79bc0bb06e89f1d6a Mon Sep 17 00:00:00 2001 From: NaH012 <1110mdj@gmail.com> Date: Mon, 13 Aug 2018 17:04:55 -0600 Subject: [PATCH 09/33] Update legacy to support layers and update readme --- README.md | 35 ++++++++++++++++++++--------------- svg2mod/svg2mod.py | 15 ++++++++++----- 2 files changed, 30 insertions(+), 20 deletions(-) diff --git a/README.md b/README.md index d048ea5..bb8d486 100644 --- a/README.md +++ b/README.md @@ -39,9 +39,7 @@ svg2mod expects images saved in the uncompressed Inkscape SVG (i.e., not "plain * A path may have holes, defined by interior segments within the path (see included examples). Sometimes this will render propery in KiCad, but sometimes not. * Paths with filled areas within holes may not work at all. * Groups may be used. However, styles applied to groups (e.g., stroke-width) are not applied to contained drawing elements. In these cases, it may be necessary to ungroup (and perhaps regroup) the elements. - * Layers must be used to indicate the mapping of drawing elements to KiCad layers. - * Layers must be named according to the rules below. - * Drawing elements will be mapped to front layers by default. Mirrored images of these elements can be automatically generated and mapped to back layers in a separate module (see --front-only option). + * Layers must be named according to the rules below. * Other types of elements such as rect, arc, and circle are not supported. * Use Inkscape's "Path->Object To Path" and "Path->Stroke To Path" menu options to convert these elements into paths that will work. @@ -50,17 +48,24 @@ Layers must be named (case-insensitive) according to the following rules: | Inkscape layer name | KiCad layer(s) | KiCad legacy | KiCad pretty | |:-------------------:|:----------------:|:------------:|:------------:| -| Cu | F.Cu, B.Cu | Yes | Yes | -| Adhes | F.Adhes, B.Adhes | Yes | Yes | -| Paste | F.Paste, B.Paste | Yes | Yes | -| SilkS | F.SilkS, B.SilkS | Yes | Yes | -| Mask | F.Mask, B.Mask | Yes | Yes | -| Dwgs.User | Dwgs.User | Yes | -- | -| Cmts.User | Cmts.User | Yes | -- | -| Eco1.User | Eco1.User | Yes | -- | -| Eco2.User | Eco2.User | Yes | -- | +| F.Cu | F.Cu | Yes | Yes | +| B.Cu | B.Cu | Yes | Yes | +| F.Adhes | F.Adhes | Yes | Yes | +| B.Adhes | B.Adhes | Yes | Yes | +| F.Paste | F.Paste | Yes | Yes | +| B.Paste | B.Paste | Yes | Yes | +| F.SilkS | F.SilkS | Yes | Yes | +| B.SilkS | B.SilkS | Yes | Yes | +| F.Mask | F.Mask | Yes | Yes | +| B.Mask | B.Mask | Yes | Yes | +| Dwgs.User | Dwgs.User | Yes | Yes | +| Cmts.User | Cmts.User | Yes | Yes | +| Eco1.User | Eco1.User | Yes | Yes | +| Eco2.User | Eco2.User | Yes | Yes | | Edge.Cuts | Edge.Cuts | Yes | Yes | -| Fab | F.Fab, B.Fab | -- | Yes | -| CrtYd | F.CrtYd, B.CrtYd | -- | Yes | +| F.Fab | F.Fab | -- | Yes | +| B.Fab | B.Fab | -- | Yes | +| F.CrtYd | F.CrtYd | -- | Yes | +| B.CrtYd | B.CrtYd | -- | Yes | -Note: If you have a layer "Cu", all of its sub-layers will be treated as "Cu" regardless of their names. +Note: If you have a layer "F.Cu", all of its sub-layers will be treated as "F.Cu" regardless of their names. diff --git a/svg2mod/svg2mod.py b/svg2mod/svg2mod.py index b0d8451..d9dd673 100755 --- a/svg2mod/svg2mod.py +++ b/svg2mod/svg2mod.py @@ -743,11 +743,16 @@ class Svg2ModExportLegacy( Svg2ModExport ): layer_map = { #'inkscape-name' : [ kicad-front, kicad-back ], - 'Cu' : [ 15, 0 ], - 'Adhes' : [ 17, 16 ], - 'Paste' : [ 19, 18 ], - 'SilkS' : [ 21, 20 ], - 'Mask' : [ 23, 22 ], + 'F.Cu' : [ 15, 15 ], + 'B.Cu' : [ 0, 0 ], + 'F.Adhes' : [ 17, 17 ], + 'B.Adhes' : [ 16, 16 ], + 'F.Paste' : [ 19, 19 ], + 'B.Paste' : [ 18, 18 ], + 'F.SilkS' : [ 21, 21 ], + 'B.SilkS' : [ 20, 20 ], + 'F.Mask' : [ 23, 23 ], + 'B.Mask' : [ 22, 22 ], 'Dwgs.User' : [ 24, 24 ], 'Cmts.User' : [ 25, 25 ], 'Eco1.User' : [ 26, 26 ], From fad7bc3773a76e0bca12b5b8d09c1c16a75c5bf8 Mon Sep 17 00:00:00 2001 From: NaH012 <1110mdj@gmail.com> Date: Mon, 13 Aug 2018 17:57:57 -0600 Subject: [PATCH 10/33] Added centering as an option and remove front only option --- svg2mod/svg2mod.py | 44 ++++++++++++++++++++++++++++++++------------ 1 file changed, 32 insertions(+), 12 deletions(-) diff --git a/svg2mod/svg2mod.py b/svg2mod/svg2mod.py index d9dd673..3d32e4d 100755 --- a/svg2mod/svg2mod.py +++ b/svg2mod/svg2mod.py @@ -60,6 +60,7 @@ def main(): exported = Svg2ModExportPretty( imported, args.output_file_name, + args.center, args.scale_factor, args.precision, args.dpi, @@ -75,10 +76,10 @@ def main(): exported = Svg2ModExportLegacyUpdater( imported, args.output_file_name, + args.center, args.scale_factor, args.precision, args.dpi, - include_reverse = not args.front_only, ) except Exception as e: @@ -91,11 +92,11 @@ def main(): exported = Svg2ModExportLegacy( imported, args.output_file_name, + args.center, args.scale_factor, args.precision, use_mm = use_mm, dpi = args.dpi, - include_reverse = not args.front_only, ) # Export the footprint: @@ -509,6 +510,7 @@ def __init__( self, svg2mod_import, file_name, + center, scale_factor = 1.0, precision = 20.0, use_mm = True, @@ -524,6 +526,7 @@ def __init__( self.imported = svg2mod_import self.file_name = file_name + self.center = center self.scale_factor = scale_factor self.precision = precision self.use_mm = use_mm @@ -535,15 +538,21 @@ def _calculate_translation( self ): min_point, max_point = self.imported.svg.bbox() - ## Center the drawing: - #adjust_x = min_point.x + ( max_point.x - min_point.x ) / 2.0 - #adjust_y = min_point.y + ( max_point.y - min_point.y ) / 2.0 + if(self.center): + # Center the drawing: + adjust_x = min_point.x + ( max_point.x - min_point.x ) / 2.0 + adjust_y = min_point.y + ( max_point.y - min_point.y ) / 2.0 - self.translation = svg.Point( - 0.0, - 0.0, - ) + self.translation = svg.Point( + 0.0 - adjust_x, + 0.0 - adjust_y, + ) + else: + self.translation = svg.Point( + 0.0, + 0.0, + ) #------------------------------------------------------------------------ @@ -767,22 +776,23 @@ def __init__( self, svg2mod_import, file_name, + center, scale_factor = 1.0, precision = 20.0, use_mm = True, dpi = DEFAULT_DPI, - include_reverse = True, ): super( Svg2ModExportLegacy, self ).__init__( svg2mod_import, file_name, + center, scale_factor, precision, use_mm, dpi, ) - self.include_reverse = include_reverse + self.include_reverse = True #------------------------------------------------------------------------ @@ -958,6 +968,7 @@ def __init__( self, svg2mod_import, file_name, + center, scale_factor = 1.0, precision = 20.0, dpi = DEFAULT_DPI, @@ -969,11 +980,11 @@ def __init__( super( Svg2ModExportLegacyUpdater, self ).__init__( svg2mod_import, file_name, + center, scale_factor, precision, use_mm, dpi, - include_reverse, ) @@ -1449,6 +1460,15 @@ def get_arguments(): default = DEFAULT_DPI, ) + parser.add_argument( + '--center', + dest = 'center', + action = 'store_const', + const = True, + help = "Center the module to the center of the bounding box", + default = False, + ) + return parser.parse_args(), parser From 8b912e133749562043ccdbc62732369395915ebe Mon Sep 17 00:00:00 2001 From: NaH012 <1110mdj@gmail.com> Date: Mon, 13 Aug 2018 18:00:53 -0600 Subject: [PATCH 11/33] Fix README.md --- README.md | 9 +++++---- svg2mod/svg2mod.py | 1 - 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index bb8d486..01d2f54 100644 --- a/README.md +++ b/README.md @@ -3,9 +3,9 @@ This is a small program to convert Inkscape SVG drawings to KiCad footprint modu ## Usage ``` -usage: svg2mod.py [-h] -i FILENAME [-o FILENAME] [--name NAME] [--value VALUE] - [-f FACTOR] [-p PRECISION] [-d DPI] [--front-only] [--format FORMAT] - [--units UNITS] +usage: svg2mod [-h] -i FILENAME [-o FILENAME] [--name NAME] [--value VALUE] + [-f FACTOR] [-p PRECISION] [--front-only] [--format FORMAT] + [--units UNITS] [-d DPI] [--center] Convert Inkscape SVG drawings to KiCad footprint modules. @@ -24,10 +24,11 @@ optional arguments: -p PRECISION, --precision PRECISION smoothness for approximating curves with line segments (float) - -d DPI, --dpi DPI DPI of the SVG file (int) --front-only omit output of back module (legacy output format) --format FORMAT output module file format (legacy|pretty) --units UNITS output units, if output format is legacy (decimil|mm) + -d DPI, --dpi DPI DPI of the SVG file (int) + --center Center the module to the center of the bounding box ``` ## SVG Files diff --git a/svg2mod/svg2mod.py b/svg2mod/svg2mod.py index 3d32e4d..35168ea 100755 --- a/svg2mod/svg2mod.py +++ b/svg2mod/svg2mod.py @@ -1480,4 +1480,3 @@ def get_arguments(): #---------------------------------------------------------------------------- -# vi: set et sts=4 sw=4 ts=4: From c8792070587e335a433a8c1e66df8e5c1db8e897 Mon Sep 17 00:00:00 2001 From: NaH012 <1110mdj@gmail.com> Date: Mon, 13 Aug 2018 18:04:11 -0600 Subject: [PATCH 12/33] Remove null flags --- README.md | 5 ++--- svg2mod/svg2mod.py | 9 --------- 2 files changed, 2 insertions(+), 12 deletions(-) diff --git a/README.md b/README.md index 01d2f54..69f2113 100644 --- a/README.md +++ b/README.md @@ -4,8 +4,8 @@ This is a small program to convert Inkscape SVG drawings to KiCad footprint modu ## Usage ``` usage: svg2mod [-h] -i FILENAME [-o FILENAME] [--name NAME] [--value VALUE] - [-f FACTOR] [-p PRECISION] [--front-only] [--format FORMAT] - [--units UNITS] [-d DPI] [--center] + [-f FACTOR] [-p PRECISION] [--format FORMAT] [--units UNITS] + [-d DPI] [--center] Convert Inkscape SVG drawings to KiCad footprint modules. @@ -24,7 +24,6 @@ optional arguments: -p PRECISION, --precision PRECISION smoothness for approximating curves with line segments (float) - --front-only omit output of back module (legacy output format) --format FORMAT output module file format (legacy|pretty) --units UNITS output units, if output format is legacy (decimil|mm) -d DPI, --dpi DPI DPI of the SVG file (int) diff --git a/svg2mod/svg2mod.py b/svg2mod/svg2mod.py index 35168ea..46f3806 100755 --- a/svg2mod/svg2mod.py +++ b/svg2mod/svg2mod.py @@ -1422,15 +1422,6 @@ def get_arguments(): default = 10.0, ) - parser.add_argument( - '--front-only', - dest = 'front_only', - action = 'store_const', - const = True, - help = "omit output of back module (legacy output format)", - default = False, - ) - parser.add_argument( '--format', type = str, From 733774554803db52c4151fb7b98bedcab0c23e1e Mon Sep 17 00:00:00 2001 From: NaH012 <1110mdj@gmail.com> Date: Mon, 13 Aug 2018 18:18:41 -0600 Subject: [PATCH 13/33] Add more options for pretty format --- svg2mod/svg2mod.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/svg2mod/svg2mod.py b/svg2mod/svg2mod.py index 46f3806..c480d36 100755 --- a/svg2mod/svg2mod.py +++ b/svg2mod/svg2mod.py @@ -1202,11 +1202,15 @@ class Svg2ModExportPretty( Svg2ModExport ): 'B.SilkS' : "B.SilkS", 'F.Mask' : "F.Mask", 'B.Mask' : "B.Mask", + 'Dwgs.User' : "Dwgs.User", + 'Cmts.User' : "Cmts.User", + 'Eco1.User' : "Eco1.User", + 'Eco2.User' : "Eco2.User", + 'Edge.Cuts' : "Edge.Cuts", 'F.CrtYd' : "F.CrtYd", 'B.CrtYd' : "B.CrtYd", 'F.Fab' : "F.Fab", - 'B.Fab' : "B.Fab", - 'Edge.Cuts' : "Edge.Cuts" + 'B.Fab' : "B.Fab" } From 8115775a7cbd5823a43e553b756fcd04b741aff6 Mon Sep 17 00:00:00 2001 From: Michael Julander <1110mdj@gmail.com> Date: Thu, 23 Aug 2018 13:16:53 -0600 Subject: [PATCH 14/33] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 69f2113..7318059 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,5 @@ # svg2mod -This is a small program to convert Inkscape SVG drawings to KiCad footprint module files. It uses [cjlano's python SVG parser and drawing module](https://github.com/cjlano/svg) to interpret drawings and approximate curves using straight line segments. Module files can be output in KiCad's legacy or s-expression (i.e., pretty) formats. Horizontally mirrored modules are automatically generated for use on the back of a 2-layer PCB. +This is a small program to convert Inkscape SVG drawings to KiCad footprint module files. It uses [cjlano's python SVG parser and drawing module](https://github.com/cjlano/svg) to interpret drawings and approximate curves using straight line segments. Module files can be output in KiCad's legacy or s-expression (i.e., pretty) formats. ## Usage ``` From fae2216436e3fd5ef278d5449185fbda873cfb6f Mon Sep 17 00:00:00 2001 From: Michael Julander <1110mdj@gmail.com> Date: Thu, 23 Aug 2018 14:20:35 -0600 Subject: [PATCH 15/33] Changed the model attribute to virtual The export currently adds (attr smd), which marks the footprint as an SMD component (which internally sets the MOD_CMS attribute, and in the GUI marks the component as "Normal+Insert"). This causes it to be exported in a .pos file for a pick & place machine. Since this is just a silkscreen and not an actual component, this makes no sense. This commit instead sets (attr virtual) (which internally sets MOD_VIRTUAL, and in the GUI marks the component as "Virtual") which causes it to be ignored by various parts of kicad that iterate over actual components. --- svg2mod/svg2mod.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/svg2mod/svg2mod.py b/svg2mod/svg2mod.py index c480d36..52d5c96 100755 --- a/svg2mod/svg2mod.py +++ b/svg2mod/svg2mod.py @@ -1233,7 +1233,7 @@ def _get_module_name( self, front = None ): def _write_library_intro( self ): self.output_file.write( """(module {0} (layer F.Cu) (tedit {1:8X}) - (attr smd) + (attr virtual) (descr "{2}") (tags {3}) """.format( From 5a6b18bbf6b1413eadcb48db2ac72ab9b2d79c34 Mon Sep 17 00:00:00 2001 From: Mark Rages Date: Thu, 14 Feb 2019 22:56:42 -0700 Subject: [PATCH 16/33] Fix closepath per https://github.com/cjlano/svg/pull/12 --- svg2mod/svg/svg/svg.py | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/svg2mod/svg/svg/svg.py b/svg2mod/svg/svg/svg.py index 244fdaa..e5f3a58 100644 --- a/svg2mod/svg/svg/svg.py +++ b/svg2mod/svg/svg/svg.py @@ -258,10 +258,10 @@ class Group(Transformable): def __init__(self, elt=None): Transformable.__init__(self, elt) - + self.name = "" if elt is not None: - + for id, value in elt.attrib.iteritems(): id = self.parse_name( id ) @@ -401,7 +401,7 @@ def parse(self, pathstr): # Close Path l = Segment(current_pt, start_pt) self.items.append(l) - + current_pt = start_pt elif command in 'LHV': # LineTo, Horizontal & Vertical line @@ -708,4 +708,3 @@ def default(self, obj): tag = getattr(cls, 'tag', None) if tag: svgClass[svg_ns + tag] = cls - From 5de072762f7c485a3f22f8fff7a4bba6d2eb0ad8 Mon Sep 17 00:00:00 2001 From: NaH012 <1110mdj@gmail.com> Date: Mon, 13 Aug 2018 16:52:03 -0600 Subject: [PATCH 17/33] Update .gitignore to block more files and initial changes to svg2mod --- .gitignore | 4 ++++ svg2mod/svg2mod.py | 36 ++++++++++++++++++++---------------- 2 files changed, 24 insertions(+), 16 deletions(-) diff --git a/.gitignore b/.gitignore index 24bc31d..6509060 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,7 @@ *~ .*.sw? *.pyc +build +dist +svg2mod.egg-info +*.kicad_mod diff --git a/svg2mod/svg2mod.py b/svg2mod/svg2mod.py index f95c068..51a87c6 100755 --- a/svg2mod/svg2mod.py +++ b/svg2mod/svg2mod.py @@ -535,13 +535,13 @@ def _calculate_translation( self ): min_point, max_point = self.imported.svg.bbox() - # Center the drawing: - adjust_x = min_point.x + ( max_point.x - min_point.x ) / 2.0 - adjust_y = min_point.y + ( max_point.y - min_point.y ) / 2.0 + ## Center the drawing: + #adjust_x = min_point.x + ( max_point.x - min_point.x ) / 2.0 + #adjust_y = min_point.y + ( max_point.y - min_point.y ) / 2.0 self.translation = svg.Point( - 0.0 - adjust_x, - 0.0 - adjust_y, + 0.0, + 0.0, ) @@ -1176,13 +1176,20 @@ class Svg2ModExportPretty( Svg2ModExport ): layer_map = { #'inkscape-name' : kicad-name, - 'Cu' : "{}.Cu", - 'Adhes' : "{}.Adhes", - 'Paste' : "{}.Paste", - 'SilkS' : "{}.SilkS", - 'Mask' : "{}.Mask", - 'CrtYd' : "{}.CrtYd", - 'Fab' : "{}.Fab", + 'F.Cu' : "F.Cu", + 'B.Cu' : "B.Cu", + 'F.Adhes' : "F.Adhes", + 'B.Adhes' : "B.Adhes", + 'F.Paste' : "F.Paste", + 'B.Paste' : "B.Paste", + 'F.SilkS' : "F.SilkS", + 'B.SilkS' : "B.SilkS", + 'F.Mask' : "F.Mask", + 'B.Mask' : "B.Mask", + 'F.CrtYd' : "F.CrtYd", + 'B.CrtYd' : "B.CrtYd", + 'F.Fab' : "F.Fab", + 'B.Fab' : "B.Fab", 'Edge.Cuts' : "Edge.Cuts" } @@ -1191,10 +1198,7 @@ class Svg2ModExportPretty( Svg2ModExport ): def _get_layer_name( self, name, front ): - if front: - return self.layer_map[ name ].format("F") - else: - return self.layer_map[ name ].format("B") + return self.layer_map[ name ] #------------------------------------------------------------------------ From 389af93f2fa514ac86a364475504246efd1d56d7 Mon Sep 17 00:00:00 2001 From: NaH012 <1110mdj@gmail.com> Date: Mon, 13 Aug 2018 17:04:55 -0600 Subject: [PATCH 18/33] Update legacy to support layers and update readme --- README.md | 35 ++++++++++++++++++++--------------- svg2mod/svg2mod.py | 15 ++++++++++----- 2 files changed, 30 insertions(+), 20 deletions(-) diff --git a/README.md b/README.md index d048ea5..bb8d486 100644 --- a/README.md +++ b/README.md @@ -39,9 +39,7 @@ svg2mod expects images saved in the uncompressed Inkscape SVG (i.e., not "plain * A path may have holes, defined by interior segments within the path (see included examples). Sometimes this will render propery in KiCad, but sometimes not. * Paths with filled areas within holes may not work at all. * Groups may be used. However, styles applied to groups (e.g., stroke-width) are not applied to contained drawing elements. In these cases, it may be necessary to ungroup (and perhaps regroup) the elements. - * Layers must be used to indicate the mapping of drawing elements to KiCad layers. - * Layers must be named according to the rules below. - * Drawing elements will be mapped to front layers by default. Mirrored images of these elements can be automatically generated and mapped to back layers in a separate module (see --front-only option). + * Layers must be named according to the rules below. * Other types of elements such as rect, arc, and circle are not supported. * Use Inkscape's "Path->Object To Path" and "Path->Stroke To Path" menu options to convert these elements into paths that will work. @@ -50,17 +48,24 @@ Layers must be named (case-insensitive) according to the following rules: | Inkscape layer name | KiCad layer(s) | KiCad legacy | KiCad pretty | |:-------------------:|:----------------:|:------------:|:------------:| -| Cu | F.Cu, B.Cu | Yes | Yes | -| Adhes | F.Adhes, B.Adhes | Yes | Yes | -| Paste | F.Paste, B.Paste | Yes | Yes | -| SilkS | F.SilkS, B.SilkS | Yes | Yes | -| Mask | F.Mask, B.Mask | Yes | Yes | -| Dwgs.User | Dwgs.User | Yes | -- | -| Cmts.User | Cmts.User | Yes | -- | -| Eco1.User | Eco1.User | Yes | -- | -| Eco2.User | Eco2.User | Yes | -- | +| F.Cu | F.Cu | Yes | Yes | +| B.Cu | B.Cu | Yes | Yes | +| F.Adhes | F.Adhes | Yes | Yes | +| B.Adhes | B.Adhes | Yes | Yes | +| F.Paste | F.Paste | Yes | Yes | +| B.Paste | B.Paste | Yes | Yes | +| F.SilkS | F.SilkS | Yes | Yes | +| B.SilkS | B.SilkS | Yes | Yes | +| F.Mask | F.Mask | Yes | Yes | +| B.Mask | B.Mask | Yes | Yes | +| Dwgs.User | Dwgs.User | Yes | Yes | +| Cmts.User | Cmts.User | Yes | Yes | +| Eco1.User | Eco1.User | Yes | Yes | +| Eco2.User | Eco2.User | Yes | Yes | | Edge.Cuts | Edge.Cuts | Yes | Yes | -| Fab | F.Fab, B.Fab | -- | Yes | -| CrtYd | F.CrtYd, B.CrtYd | -- | Yes | +| F.Fab | F.Fab | -- | Yes | +| B.Fab | B.Fab | -- | Yes | +| F.CrtYd | F.CrtYd | -- | Yes | +| B.CrtYd | B.CrtYd | -- | Yes | -Note: If you have a layer "Cu", all of its sub-layers will be treated as "Cu" regardless of their names. +Note: If you have a layer "F.Cu", all of its sub-layers will be treated as "F.Cu" regardless of their names. diff --git a/svg2mod/svg2mod.py b/svg2mod/svg2mod.py index 51a87c6..a7edb3a 100755 --- a/svg2mod/svg2mod.py +++ b/svg2mod/svg2mod.py @@ -743,11 +743,16 @@ class Svg2ModExportLegacy( Svg2ModExport ): layer_map = { #'inkscape-name' : [ kicad-front, kicad-back ], - 'Cu' : [ 15, 0 ], - 'Adhes' : [ 17, 16 ], - 'Paste' : [ 19, 18 ], - 'SilkS' : [ 21, 20 ], - 'Mask' : [ 23, 22 ], + 'F.Cu' : [ 15, 15 ], + 'B.Cu' : [ 0, 0 ], + 'F.Adhes' : [ 17, 17 ], + 'B.Adhes' : [ 16, 16 ], + 'F.Paste' : [ 19, 19 ], + 'B.Paste' : [ 18, 18 ], + 'F.SilkS' : [ 21, 21 ], + 'B.SilkS' : [ 20, 20 ], + 'F.Mask' : [ 23, 23 ], + 'B.Mask' : [ 22, 22 ], 'Dwgs.User' : [ 24, 24 ], 'Cmts.User' : [ 25, 25 ], 'Eco1.User' : [ 26, 26 ], From da01c78b0d5c1ba11628340f65570f66f368b8c1 Mon Sep 17 00:00:00 2001 From: NaH012 <1110mdj@gmail.com> Date: Mon, 13 Aug 2018 17:57:57 -0600 Subject: [PATCH 19/33] Added centering as an option and remove front only option --- svg2mod/svg2mod.py | 44 ++++++++++++++++++++++++++++++++------------ 1 file changed, 32 insertions(+), 12 deletions(-) diff --git a/svg2mod/svg2mod.py b/svg2mod/svg2mod.py index a7edb3a..d9be704 100755 --- a/svg2mod/svg2mod.py +++ b/svg2mod/svg2mod.py @@ -60,6 +60,7 @@ def main(): exported = Svg2ModExportPretty( imported, args.output_file_name, + args.center, args.scale_factor, args.precision, args.dpi, @@ -75,10 +76,10 @@ def main(): exported = Svg2ModExportLegacyUpdater( imported, args.output_file_name, + args.center, args.scale_factor, args.precision, args.dpi, - include_reverse = not args.front_only, ) except Exception as e: @@ -91,11 +92,11 @@ def main(): exported = Svg2ModExportLegacy( imported, args.output_file_name, + args.center, args.scale_factor, args.precision, use_mm = use_mm, dpi = args.dpi, - include_reverse = not args.front_only, ) # Export the footprint: @@ -509,6 +510,7 @@ def __init__( self, svg2mod_import, file_name, + center, scale_factor = 1.0, precision = 20.0, use_mm = True, @@ -524,6 +526,7 @@ def __init__( self.imported = svg2mod_import self.file_name = file_name + self.center = center self.scale_factor = scale_factor self.precision = precision self.use_mm = use_mm @@ -535,15 +538,21 @@ def _calculate_translation( self ): min_point, max_point = self.imported.svg.bbox() - ## Center the drawing: - #adjust_x = min_point.x + ( max_point.x - min_point.x ) / 2.0 - #adjust_y = min_point.y + ( max_point.y - min_point.y ) / 2.0 + if(self.center): + # Center the drawing: + adjust_x = min_point.x + ( max_point.x - min_point.x ) / 2.0 + adjust_y = min_point.y + ( max_point.y - min_point.y ) / 2.0 - self.translation = svg.Point( - 0.0, - 0.0, - ) + self.translation = svg.Point( + 0.0 - adjust_x, + 0.0 - adjust_y, + ) + else: + self.translation = svg.Point( + 0.0, + 0.0, + ) #------------------------------------------------------------------------ @@ -767,22 +776,23 @@ def __init__( self, svg2mod_import, file_name, + center, scale_factor = 1.0, precision = 20.0, use_mm = True, dpi = DEFAULT_DPI, - include_reverse = True, ): super( Svg2ModExportLegacy, self ).__init__( svg2mod_import, file_name, + center, scale_factor, precision, use_mm, dpi, ) - self.include_reverse = include_reverse + self.include_reverse = True #------------------------------------------------------------------------ @@ -958,6 +968,7 @@ def __init__( self, svg2mod_import, file_name, + center, scale_factor = 1.0, precision = 20.0, dpi = DEFAULT_DPI, @@ -969,11 +980,11 @@ def __init__( super( Svg2ModExportLegacyUpdater, self ).__init__( svg2mod_import, file_name, + center, scale_factor, precision, use_mm, dpi, - include_reverse, ) @@ -1449,6 +1460,15 @@ def get_arguments(): default = DEFAULT_DPI, ) + parser.add_argument( + '--center', + dest = 'center', + action = 'store_const', + const = True, + help = "Center the module to the center of the bounding box", + default = False, + ) + return parser.parse_args(), parser From 5fc8d98e2241f2789eb389aa6e75e4caee7be64a Mon Sep 17 00:00:00 2001 From: NaH012 <1110mdj@gmail.com> Date: Mon, 13 Aug 2018 18:00:53 -0600 Subject: [PATCH 20/33] Fix README.md --- README.md | 9 +++++---- svg2mod/svg2mod.py | 1 - 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index bb8d486..01d2f54 100644 --- a/README.md +++ b/README.md @@ -3,9 +3,9 @@ This is a small program to convert Inkscape SVG drawings to KiCad footprint modu ## Usage ``` -usage: svg2mod.py [-h] -i FILENAME [-o FILENAME] [--name NAME] [--value VALUE] - [-f FACTOR] [-p PRECISION] [-d DPI] [--front-only] [--format FORMAT] - [--units UNITS] +usage: svg2mod [-h] -i FILENAME [-o FILENAME] [--name NAME] [--value VALUE] + [-f FACTOR] [-p PRECISION] [--front-only] [--format FORMAT] + [--units UNITS] [-d DPI] [--center] Convert Inkscape SVG drawings to KiCad footprint modules. @@ -24,10 +24,11 @@ optional arguments: -p PRECISION, --precision PRECISION smoothness for approximating curves with line segments (float) - -d DPI, --dpi DPI DPI of the SVG file (int) --front-only omit output of back module (legacy output format) --format FORMAT output module file format (legacy|pretty) --units UNITS output units, if output format is legacy (decimil|mm) + -d DPI, --dpi DPI DPI of the SVG file (int) + --center Center the module to the center of the bounding box ``` ## SVG Files diff --git a/svg2mod/svg2mod.py b/svg2mod/svg2mod.py index d9be704..30cda21 100755 --- a/svg2mod/svg2mod.py +++ b/svg2mod/svg2mod.py @@ -1480,4 +1480,3 @@ def get_arguments(): #---------------------------------------------------------------------------- -# vi: set et sts=4 sw=4 ts=4: From 78a2857ab9fdcddff6f6ccc6b8a67269e3f85fee Mon Sep 17 00:00:00 2001 From: NaH012 <1110mdj@gmail.com> Date: Mon, 13 Aug 2018 18:04:11 -0600 Subject: [PATCH 21/33] Remove null flags --- README.md | 5 ++--- svg2mod/svg2mod.py | 9 --------- 2 files changed, 2 insertions(+), 12 deletions(-) diff --git a/README.md b/README.md index 01d2f54..69f2113 100644 --- a/README.md +++ b/README.md @@ -4,8 +4,8 @@ This is a small program to convert Inkscape SVG drawings to KiCad footprint modu ## Usage ``` usage: svg2mod [-h] -i FILENAME [-o FILENAME] [--name NAME] [--value VALUE] - [-f FACTOR] [-p PRECISION] [--front-only] [--format FORMAT] - [--units UNITS] [-d DPI] [--center] + [-f FACTOR] [-p PRECISION] [--format FORMAT] [--units UNITS] + [-d DPI] [--center] Convert Inkscape SVG drawings to KiCad footprint modules. @@ -24,7 +24,6 @@ optional arguments: -p PRECISION, --precision PRECISION smoothness for approximating curves with line segments (float) - --front-only omit output of back module (legacy output format) --format FORMAT output module file format (legacy|pretty) --units UNITS output units, if output format is legacy (decimil|mm) -d DPI, --dpi DPI DPI of the SVG file (int) diff --git a/svg2mod/svg2mod.py b/svg2mod/svg2mod.py index 30cda21..031a0fe 100755 --- a/svg2mod/svg2mod.py +++ b/svg2mod/svg2mod.py @@ -1422,15 +1422,6 @@ def get_arguments(): default = 10.0, ) - parser.add_argument( - '--front-only', - dest = 'front_only', - action = 'store_const', - const = True, - help = "omit output of back module (legacy output format)", - default = False, - ) - parser.add_argument( '--format', type = str, From 93b978cbcd2b9f007f4cbe96c33f4bfc04d396cd Mon Sep 17 00:00:00 2001 From: NaH012 <1110mdj@gmail.com> Date: Mon, 13 Aug 2018 18:18:41 -0600 Subject: [PATCH 22/33] Add more options for pretty format --- svg2mod/svg2mod.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/svg2mod/svg2mod.py b/svg2mod/svg2mod.py index 031a0fe..52d5c96 100755 --- a/svg2mod/svg2mod.py +++ b/svg2mod/svg2mod.py @@ -1202,11 +1202,15 @@ class Svg2ModExportPretty( Svg2ModExport ): 'B.SilkS' : "B.SilkS", 'F.Mask' : "F.Mask", 'B.Mask' : "B.Mask", + 'Dwgs.User' : "Dwgs.User", + 'Cmts.User' : "Cmts.User", + 'Eco1.User' : "Eco1.User", + 'Eco2.User' : "Eco2.User", + 'Edge.Cuts' : "Edge.Cuts", 'F.CrtYd' : "F.CrtYd", 'B.CrtYd' : "B.CrtYd", 'F.Fab' : "F.Fab", - 'B.Fab' : "B.Fab", - 'Edge.Cuts' : "Edge.Cuts" + 'B.Fab' : "B.Fab" } From 0f40b47f4fdd70aaedfbcfdd30821f91afc18115 Mon Sep 17 00:00:00 2001 From: Michael Julander <1110mdj@gmail.com> Date: Thu, 23 Aug 2018 13:16:53 -0600 Subject: [PATCH 23/33] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 69f2113..7318059 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,5 @@ # svg2mod -This is a small program to convert Inkscape SVG drawings to KiCad footprint module files. It uses [cjlano's python SVG parser and drawing module](https://github.com/cjlano/svg) to interpret drawings and approximate curves using straight line segments. Module files can be output in KiCad's legacy or s-expression (i.e., pretty) formats. Horizontally mirrored modules are automatically generated for use on the back of a 2-layer PCB. +This is a small program to convert Inkscape SVG drawings to KiCad footprint module files. It uses [cjlano's python SVG parser and drawing module](https://github.com/cjlano/svg) to interpret drawings and approximate curves using straight line segments. Module files can be output in KiCad's legacy or s-expression (i.e., pretty) formats. ## Usage ``` From 0c4627afe54040f647a003a9c6d9cd2dfaa392b4 Mon Sep 17 00:00:00 2001 From: Hector Martin Date: Sat, 1 Dec 2018 13:21:13 +0900 Subject: [PATCH 24/33] Do not close non-filled polygons --- svg2mod/svg2mod.py | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/svg2mod/svg2mod.py b/svg2mod/svg2mod.py index b5ff31d..26a11e6 100755 --- a/svg2mod/svg2mod.py +++ b/svg2mod/svg2mod.py @@ -394,7 +394,7 @@ def intersects( self, line_segment, check_connects ): # Apply all transformations and rounding, then remove duplicate # consecutive points along the path. - def process( self, transformer, flip ): + def process( self, transformer, flip, fill ): points = [] for point in self.points: @@ -417,10 +417,11 @@ def process( self, transformer, flip ): #points[ -1 ].x, points[ -1 ].y, #) ) - points.append( svg.Point( - points[ 0 ].x, - points[ 0 ].y, - ) ) + if fill: + points.append( svg.Point( + points[ 0 ].x, + points[ 0 ].y, + ) ) #else: #print( "Polygon closed: start=({}, {}) end=({}, {})".format( @@ -603,8 +604,10 @@ def _write_items( self, items, layer, flip = False ): ) ] + fill, stroke, stroke_width = self._get_fill_stroke( item ) + for segment in segments: - segment.process( self, flip ) + segment.process( self, flip, fill ) if len( segments ) > 1: points = segments[ 0 ].inline( segments[ 1 : ] ) @@ -612,8 +615,6 @@ def _write_items( self, items, layer, flip = False ): elif len( segments ) > 0: points = segments[ 0 ].points - fill, stroke, stroke_width = self._get_fill_stroke( item ) - if not self.use_mm: stroke_width = self._convert_mm_to_decimil( stroke_width From c162c8e00cfcb1fd107a10ff8063e1c7fa0760c6 Mon Sep 17 00:00:00 2001 From: Hector Martin Date: Mon, 3 Dec 2018 23:26:00 +0900 Subject: [PATCH 25/33] Fix stroke-width calculation for non-px units --- svg2mod/svg2mod.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/svg2mod/svg2mod.py b/svg2mod/svg2mod.py index 26a11e6..8a993a1 100755 --- a/svg2mod/svg2mod.py +++ b/svg2mod/svg2mod.py @@ -493,8 +493,11 @@ def _get_fill_stroke( self, item ): stroke = False elif name == "stroke-width": - value = value.replace( "px", "" ) - stroke_width = float( value ) * 25.4 / float(self.dpi) + if value.endswith("px"): + value = value.replace( "px", "" ) + stroke_width = float( value ) * 25.4 / float(self.dpi) + else: + stroke_width = float( value ) if not stroke: stroke_width = 0.0 From 3b416846ce8dbda0e370f9ce49129a74d0bf23bf Mon Sep 17 00:00:00 2001 From: Terje Tjervaag Date: Fri, 28 Feb 2020 20:39:15 +0100 Subject: [PATCH 26/33] Remove empty style values --- svg2mod/svg2mod.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/svg2mod/svg2mod.py b/svg2mod/svg2mod.py index 8a993a1..2e11764 100755 --- a/svg2mod/svg2mod.py +++ b/svg2mod/svg2mod.py @@ -480,7 +480,7 @@ def _get_fill_stroke( self, item ): if item.style is not None and item.style != "": - for property in item.style.split( ";" ): + for property in filter(None, item.style.split( ";" )): nv = property.split( ":" ); name = nv[ 0 ].strip() From 36853c964157705eade505ca277f90c5dabb54cc Mon Sep 17 00:00:00 2001 From: Sodium-Hydrogen <42423149+Sodium-Hydrogen@users.noreply.github.com> Date: Tue, 10 Mar 2020 10:07:37 -0600 Subject: [PATCH 27/33] Merge terje/svg2mod into master --- README.md | 14 ++++++++++++++ svg2mod/svg/svg/svg.py | 2 +- svg2mod/svg2mod.py | 36 ++++++++++++++++++++---------------- 3 files changed, 35 insertions(+), 17 deletions(-) diff --git a/README.md b/README.md index 7318059..32d56c4 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,20 @@ # svg2mod This is a small program to convert Inkscape SVG drawings to KiCad footprint module files. It uses [cjlano's python SVG parser and drawing module](https://github.com/cjlano/svg) to interpret drawings and approximate curves using straight line segments. Module files can be output in KiCad's legacy or s-expression (i.e., pretty) formats. +## Requirements + +Python 3 + +## Installation + +```pip3 install git+https://github.com/zirafa/svg2mod``` + +Note: ```python3 setup.py install``` does not work. + +## Example + +```svg2mod -i input.svg -p 1.0``` + ## Usage ``` usage: svg2mod [-h] -i FILENAME [-o FILENAME] [--name NAME] [--value VALUE] diff --git a/svg2mod/svg/svg/svg.py b/svg2mod/svg/svg/svg.py index 244fdaa..02949d2 100644 --- a/svg2mod/svg/svg/svg.py +++ b/svg2mod/svg/svg/svg.py @@ -262,7 +262,7 @@ def __init__(self, elt=None): self.name = "" if elt is not None: - for id, value in elt.attrib.iteritems(): + for id, value in elt.attrib.items(): id = self.parse_name( id ) if id[ "name" ] == "label": diff --git a/svg2mod/svg2mod.py b/svg2mod/svg2mod.py index 52d5c96..2e11764 100755 --- a/svg2mod/svg2mod.py +++ b/svg2mod/svg2mod.py @@ -394,7 +394,7 @@ def intersects( self, line_segment, check_connects ): # Apply all transformations and rounding, then remove duplicate # consecutive points along the path. - def process( self, transformer, flip ): + def process( self, transformer, flip, fill ): points = [] for point in self.points: @@ -417,10 +417,11 @@ def process( self, transformer, flip ): #points[ -1 ].x, points[ -1 ].y, #) ) - points.append( svg.Point( - points[ 0 ].x, - points[ 0 ].y, - ) ) + if fill: + points.append( svg.Point( + points[ 0 ].x, + points[ 0 ].y, + ) ) #else: #print( "Polygon closed: start=({}, {}) end=({}, {})".format( @@ -479,7 +480,7 @@ def _get_fill_stroke( self, item ): if item.style is not None and item.style != "": - for property in item.style.split( ";" ): + for property in filter(None, item.style.split( ";" )): nv = property.split( ":" ); name = nv[ 0 ].strip() @@ -492,8 +493,11 @@ def _get_fill_stroke( self, item ): stroke = False elif name == "stroke-width": - value = value.replace( "px", "" ) - stroke_width = float( value ) * 25.4 / float(self.dpi) + if value.endswith("px"): + value = value.replace( "px", "" ) + stroke_width = float( value ) * 25.4 / float(self.dpi) + else: + stroke_width = float( value ) if not stroke: stroke_width = 0.0 @@ -562,7 +566,7 @@ def _prune( self, items = None ): if items is None: self.layers = {} - for name in self.layer_map.iterkeys(): + for name in self.layer_map.keys(): self.layers[ name ] = None items = self.imported.svg.items @@ -573,7 +577,7 @@ def _prune( self, items = None ): if not isinstance( item, svg.Group ): continue - for name in self.layers.iterkeys(): + for name in self.layers.keys(): #if re.search( name, item.name, re.I ): if name == item.name: print( "Found SVG layer: {}".format( item.name ) ) @@ -603,8 +607,10 @@ def _write_items( self, items, layer, flip = False ): ) ] + fill, stroke, stroke_width = self._get_fill_stroke( item ) + for segment in segments: - segment.process( self, flip ) + segment.process( self, flip, fill ) if len( segments ) > 1: points = segments[ 0 ].inline( segments[ 1 : ] ) @@ -612,8 +618,6 @@ def _write_items( self, items, layer, flip = False ): elif len( segments ) > 0: points = segments[ 0 ].points - fill, stroke, stroke_width = self._get_fill_stroke( item ) - if not self.use_mm: stroke_width = self._convert_mm_to_decimil( stroke_width @@ -662,7 +666,7 @@ def _write_module( self, front ): front, ) - for name, group in self.layers.iteritems(): + for name, group in self.layers.items(): if group is None: continue @@ -1110,7 +1114,7 @@ def _write_library_intro( self ): # Write index: for module_name in sorted( - self.loaded_modules.iterkeys(), + self.loaded_modules.keys(), key = str.lower ): self.output_file.write( module_name + "\n" ) @@ -1127,7 +1131,7 @@ def _write_preserved_modules( self, up_to = None ): up_to = up_to.lower() for module_name in sorted( - self.loaded_modules.iterkeys(), + self.loaded_modules.keys(), key = str.lower ): if up_to is not None and module_name.lower() >= up_to: From 29f3d63a024acfdf24a71b3a17776b2b1cd11599 Mon Sep 17 00:00:00 2001 From: Sodium-Hydrogen <42423149+Sodium-Hydrogen@users.noreply.github.com> Date: Tue, 10 Mar 2020 10:19:17 -0600 Subject: [PATCH 28/33] Update pip instructions --- README.md | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/README.md b/README.md index b80a432..3bb276c 100644 --- a/README.md +++ b/README.md @@ -7,7 +7,7 @@ Python 3 ## Installation -```pip3 install git+https://github.com/zirafa/svg2mod``` +```pip3 install git+https://github.com/Sodium-Hydrogen/svg2mod``` Note: ```python3 setup.py install``` does not work. @@ -18,13 +18,8 @@ Note: ```python3 setup.py install``` does not work. ## Usage ``` usage: svg2mod [-h] -i FILENAME [-o FILENAME] [--name NAME] [--value VALUE] -<<<<<<< HEAD [-f FACTOR] [-p PRECISION] [--format FORMAT] [--units UNITS] [-d DPI] [--center] -======= - [-f FACTOR] [-p PRECISION] [-d DPI] [--front-only] [--format FORMAT] - [--units UNITS] ->>>>>>> 3b416846ce8dbda0e370f9ce49129a74d0bf23bf Convert Inkscape SVG drawings to KiCad footprint modules. From a98b69416208b2c8a1d8fee30c4495e7a2363536 Mon Sep 17 00:00:00 2001 From: Sodium-Hydrogen <42423149+Sodium-Hydrogen@users.noreply.github.com> Date: Tue, 10 Mar 2020 14:48:38 -0600 Subject: [PATCH 29/33] travis ci testing --- .travis.yml | 2 ++ setup.py | 4 ++-- 2 files changed, 4 insertions(+), 2 deletions(-) create mode 100644 .travis.yml diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..39bcfdf --- /dev/null +++ b/.travis.yml @@ -0,0 +1,2 @@ +language: python +script: pip3 install ./ diff --git a/setup.py b/setup.py index d51ddd7..a05f4e4 100644 --- a/setup.py +++ b/setup.py @@ -25,9 +25,9 @@ version='0.1.0', description="Convert an SVG file to a KiCad footprint.", long_description=readme, - author='https://github.com/mtl', + author='https://github.com/Sodium-Hydrogen', author_email='', - url='https://github.com/mtl/svg2mod', + url='https://github.com/Sodium-Hydrogen/svg2mod', packages=setuptools.find_packages(), entry_points={'console_scripts':['svg2mod = svg2mod.svg2mod:main']}, package_dir={'svg2mod':'svg2mod'}, From cd2616d28030b5c534ea4864617cd0bcf4bb5a65 Mon Sep 17 00:00:00 2001 From: Sodium-Hydrogen <42423149+Sodium-Hydrogen@users.noreply.github.com> Date: Tue, 10 Mar 2020 14:54:20 -0600 Subject: [PATCH 30/33] Add a sample test --- .travis.yml | 2 +- README.md | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 39bcfdf..9f1311a 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,2 +1,2 @@ language: python -script: pip3 install ./ +script: pip3 install ./ && svg2mod -i examples/dt-logo.svg diff --git a/README.md b/README.md index 3bb276c..70688e4 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,6 @@ # svg2mod +[![Build Status](https://travis-ci.org/Sodium-Hydrogen/svg2mod.svg?branch=travis-testing)](https://travis-ci.org/Sodium-Hydrogen/svg2mod) + This is a small program to convert Inkscape SVG drawings to KiCad footprint module files. It uses [cjlano's python SVG parser and drawing module](https://github.com/cjlano/svg) to interpret drawings and approximate curves using straight line segments. Module files can be output in KiCad's legacy or s-expression (i.e., pretty) formats. ## Requirements From b9d5690c2f2795b02bff5b8884719f8f35c91e38 Mon Sep 17 00:00:00 2001 From: Sodium-Hydrogen <42423149+Sodium-Hydrogen@users.noreply.github.com> Date: Tue, 10 Mar 2020 15:00:06 -0600 Subject: [PATCH 31/33] Better test --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 9f1311a..ed3b24d 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,2 +1,2 @@ language: python -script: pip3 install ./ && svg2mod -i examples/dt-logo.svg +script: pip3 install ./ && svg2mod -i examples/dt-logo.svg -o output.kicad_mod --name TEST --value VALUE -f 2 -p 1 --format pretty --units mm -d 300 --center From 4b4ea8945c43e1f2e1aba08e8cc8312470838ba7 Mon Sep 17 00:00:00 2001 From: Sodium-Hydrogen <42423149+Sodium-Hydrogen@users.noreply.github.com> Date: Tue, 10 Mar 2020 15:12:46 -0600 Subject: [PATCH 32/33] Update Readme.md --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 70688e4..28e1749 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,5 @@ # svg2mod -[![Build Status](https://travis-ci.org/Sodium-Hydrogen/svg2mod.svg?branch=travis-testing)](https://travis-ci.org/Sodium-Hydrogen/svg2mod) +[![Build Status](https://travis-ci.org/Sodium-Hydrogen/svg2mod.svg?branch=master)](https://travis-ci.org/Sodium-Hydrogen/svg2mod) This is a small program to convert Inkscape SVG drawings to KiCad footprint module files. It uses [cjlano's python SVG parser and drawing module](https://github.com/cjlano/svg) to interpret drawings and approximate curves using straight line segments. Module files can be output in KiCad's legacy or s-expression (i.e., pretty) formats. @@ -11,7 +11,7 @@ Python 3 ```pip3 install git+https://github.com/Sodium-Hydrogen/svg2mod``` -Note: ```python3 setup.py install``` does not work. +If building fails make sure setuptools is up to date. `pip3 install setuptools --upgrade` ## Example From 151cd9fd16e336f73f784e4fc32f614e60d72ad7 Mon Sep 17 00:00:00 2001 From: Sodium-Hydrogen <42423149+Sodium-Hydrogen@users.noreply.github.com> Date: Tue, 10 Mar 2020 15:37:30 -0600 Subject: [PATCH 33/33] Fix problem when merging --- svg2mod/svg/svg/svg.py | 6 ------ 1 file changed, 6 deletions(-) diff --git a/svg2mod/svg/svg/svg.py b/svg2mod/svg/svg/svg.py index 3f26c85..55c3da2 100644 --- a/svg2mod/svg/svg/svg.py +++ b/svg2mod/svg/svg/svg.py @@ -261,13 +261,7 @@ def __init__(self, elt=None): self.name = "" if elt is not None: -<<<<<<< HEAD - for id, value in elt.attrib.items(): -======= - - for id, value in elt.attrib.iteritems(): ->>>>>>> 5a6b18bbf6b1413eadcb48db2ac72ab9b2d79c34 id = self.parse_name( id ) if id[ "name" ] == "label":