SVG graphics in KiCad (svg2mod)

There didn't seem to be a good way to get vector graphics into Pcbnew, so I wrote a small utility that uses an existing SVG library to read files, and then writes them out as KiCad modules. It seemed generally useful so I put it on github. It should let you make something like this:

svg2mod-dt.png


From a source file like this:

inkscape.png


The tool can scale images by a factor that you provide, and will automatically generate a reversed module for use on the back side of a PCB. 8-)

As mentioned on komar's techblog, it's advisable to create a solder mask negative region slightly larger than your artwork to account for process imprecision during fabrication.

A few things to note.. I don't really understand how the various parts of KiCad interpret polygons, and sometimes Inkscape will save an image in a way that the conversion process doesn't handle correctly. YMMV. Also, although support is underway for .kicad_mod (pretty) format, it hasn't been tested yet.
mtl

Unread post23 Sep 2015, 20:14

X
mtl
 
Posts: 314
Joined: 21 Mar 2011, 01:11
Location: USA
Main keyboard: Custom
Main mouse: IBM TrackPoint IV
Favorite switch: Cherry MX Clicky
Club member: 0007
 
This is great =)

I just tested with the DT logo example in the pretty format (cause that is the good shit). It doesn't seem to add the layer tags, (layer B.Cu) and so on, to the polygon items. At least not for me, but I may be doing it wrong.. I edited the kicad_mod file by hand to add layers, and all polygons are correct otherwise.

Polygons also have a (width "number"). Setting width to 0 ends you up with the polygon you probably wanted. Setting it to some value x also draws a line segment centred on the polygon segment with a width of x. ( And they plot with that
thickness to the gerber output. I nagged on the kicad launchpad site to have them make it that way =D

(Edit: Had a look and the logo gets a bit mangled when there is no width tag at all. The width of the outline segments is set to some default value, which screws everything up..)

You also can't have more than one footprint in a kicad_mod file. Only the first one is read. Anything after the first (module...) block is ignored.

If you generate the image on the back of the board it will (probably) be mirrored to what you'd want when submitting the gerbers to your manufacturer.. Moving a footprint to the back of the board is a simple matter of flipping it in PCBnew. This changes all layers from back to front and the other way around. Mirroring an svg should probably be done with a negative scaling factor instead.

(Edit: I see now that the footprint on the back layer is mirrored compared to the front one when generated. Though I still say only a front one is ever needed.)

Today I did learn about the (descr ) and (tags ) tags though. I used to add comments to my own footprints after the module block. Thank you for this new piece of information =)
bpiphany

Unread post25 Sep 2015, 23:39

X
bpiphany
 
Posts: 390
Joined: 19 Mar 2011, 19:15
Location: Stockhom, Sweden
Main keyboard: Symmetric Stagger Board
Main mouse: Kinzu
Favorite switch: Topre
Club member: -
 
bpiphany.. Thanks for all the great advice (and debugging) on the pretty format! I started writing the code but then realized the version of KiCad I have on Linux is pretty old and will only read the legacy format. I've committed the following changes based on your suggestions:
  • Fixed missing (layer ) tags
  • Set the polygon (width ) tags, including 0 for polys without an outline, and using the this width tag and (fp_poly ) to draw polygons which have both a fill and outline. For outline-only polygons, it still uses (fp_line )s.
  • Only one footprint is now written to the .kicad_mod file.
  • Mirroring is still optional for the legacy format. At least in my old version of KiCad (2013-may-18), flipping in Pcbnew does not mirror the footprint, so a mirrored back module is needed. Though I see your point that having a separate x-axis scale factor option would do the trick, and simplify the code. I'll try to make that change next.
Regarding (desc ) and (tags ).. There's a good reference here with more details. For some other info such as which layers are supported by the pretty format, I had to refer to the KiCad sources. ;)
mtl

Unread post26 Sep 2015, 02:31

X
mtl
 
Posts: 314
Joined: 21 Mar 2011, 01:11
Location: USA
Main keyboard: Custom
Main mouse: IBM TrackPoint IV
Favorite switch: Cherry MX Clicky
Club member: 0007
 
I'm only glad to help. There is a PPA with daily build of KiCAD here https://code.launchpad.net/~js-reynaud/ ... /ppa-kicad I'm currently using that. There was a period of time when there wasn't a PPA, and I had to compile myself. And there was often some sort of trouble with that =P KiCAD has become a lot better. I don't know which version they are up to in legacy, but the new file formats are a jay to work with compared to the old... Also the program seems to crash much less often =)

Polygons are always filled, I think.. It would be great with a non filled version. Writing a separate item for each segment feels a bit unnecessary. fp_poly is actually also always closed. You don't need to specify the first point again at the end.

Ah, yes mirroring of course requires different x- and y-factors. I may have been a bit tired last night.
bpiphany

Unread post26 Sep 2015, 08:12

X
bpiphany
 
Posts: 390
Joined: 19 Mar 2011, 19:15
Location: Stockhom, Sweden
Main keyboard: Symmetric Stagger Board
Main mouse: Kinzu
Favorite switch: Topre
Club member: -
 
A nicely done article on Hackaday by Nava Whiteford highlights some inspiring PCB designs and projects, with an example using svg2mod. :)
mtl

Unread post24 Feb 2016, 00:10

X
mtl
 
Posts: 314
Joined: 21 Mar 2011, 01:11
Location: USA
Main keyboard: Custom
Main mouse: IBM TrackPoint IV
Favorite switch: Cherry MX Clicky
Club member: 0007
 
Blasphemy! Why am I seeing this only now!
mohitgarg

Unread post24 Feb 2016, 07:38

X
mohitgarg
 
Posts: 243
Joined: 12 Aug 2013, 19:26
Main mouse: R.A.T 7
Favorite switch: Blue
Club member: -
 
 
Image
Hi mohitgarg,

I just came across your split 65% keyboard. Awesome project!

There's an SVG OSH logo here that might be helpful. I had a few PCBs made to test it and it came out pretty nice (some pics here).
mtl

Unread post24 Feb 2016, 12:50

X
mtl
 
Posts: 314
Joined: 21 Mar 2011, 01:11
Location: USA
Main keyboard: Custom
Main mouse: IBM TrackPoint IV
Favorite switch: Cherry MX Clicky
Club member: 0007
 

Who is online

Users browsing this forum: Hypersphere, strah, theycallmestino and 32 guests

cron