PCB diff with custom tool and kicad-cli

Hello,

I recently stared working on an application for visual SVG comparison with the intention
of using it for PCB files.
Here it is in action:


I’m basically using kicad-cli and feeding the results to my tool. For convenience I also configured it as git difftool.

#!/bin/sh

# ~/.local/bin/diff-kicad - wrapper for lukaj and kicad-cli

set -euo pipefail

TEMP1=$(mktemp)
TEMP2=$(mktemp)

generate_svg() {
  INPUT=$1
  OUTPUT=$2
  kicad-cli pcb export svg --exclude-drawing-sheet --page-size-mode 2 \
    -l "B.Cu,F.Cu,B.Silkscreen,F.Silkscreen,Edge.Cuts,B.Mask,F.Mask" \
    -o $OUTPUT $INPUT
}

generate_svg $1 $TEMP1
generate_svg $2 $TEMP2

~/.cargo/bin/lukaj $TEMP1 $TEMP2

rm $TEMP1 $TEMP2
[difftool "diff-kicad"]
    cmd = ~/.local/bin/diff-kicad $LOCAL $REMOTE
[alias]
    diff-kicad = "difftool -t diff-kicad"

The project page: GitHub - adamws/lukaj: Interactive diff tool for SVG images
Short post: adamws.github.io - PCB visual diff with kicad-cli and lukaj

4 Likes

Your demo.gif does not render. The forum software sugests it’s too big (>4MB). I have also disabled animated gifs in my browser as a countermeasure against irritating advertisements.

A more interesting comparison would be between MP2-ESC and MP2-DFN.

GitHub - badgineer/MP2-ESC: Multi-Platform, Modular, Powerful ESC

GitHub - owhite/MP2-DFN: A variant of the MP2 electronic speed control with DFNW MOSFETs

It’s an (approx) 75*100mm BLDC motor controller. The ESC variant uses TO220 Fets, while the DFN uses SMT fets and they made some more small design changes.

Cargo? That is a rust thing I believe :slight_smile:
I have seen similar projects but never actually used it. Some of them work with colors to keep the different projects apart. I did download the gif and look at it, and when you move the vertical red bar it is hard to spot the differences. Especially when you do not know on which part of the monitor you should focus. Something with colors (XOR?) gives a much quicker overview of changes, and it could be combined with the shifting bar.

I think my own preference would be to load one of the projects as a background image in the other KiCad project itself. That way you can both look at differences and work on (one of) the projects. Or maybe just load both in different layers of a picture editor. Looking at diffs is not a high priority for me.

I run comparison on those, top-left board coordinates are different and my diff tool does not let to adjust alignment, so it is not usable for this scenario yet.

that’s right

yes, there are images diff tools out there but I didn’t find any with SVG support. Zooming feature was important to me. It probably wold be possible to write imagemagick wrapper to generate raster images (for different zoom levels) out of SVGs and run some compare methods Comparing -- ImageMagick Examples but I think that user experience would be worse. To me, highlighting difference on static image with some color seems worse and more difficult to spot. Subtracting pixels between images would hide the context.
Swiping feels ok, although It might require some passes to spot the difference.
Nevertheless, I’m planning to add more comparison modes to lukaj tool. I think that combining area highlights with swiping might be a sweet spot.

Good test case then to add this. :slight_smile:

I had a bit closer look at the differences. the “Pill” sub assembly in the lower right corner seems to be in the same absolute location. Bottom side too, but the left side is shifted about 2mm. Text diff programs such as meldmerge attempt to re-synchonize. Shifts are quite common. Some people prefer to use absolute (0, 0) as a reference for the PCB regardless of “paper location”, and others put the PCB within the paper borders. It is also common to shift parts of the PCB. Either to make it smaller, or to make room for other things.

I also have a strong tendency to rotate projects that are made in “portrait” format to “landscape” to better fit my monitor.

KiCad-Diff uses a combination of Python and SVG.

And Kdiff which apparently builds upon KiCad-Diff also has Pan & Zoom at 01:50.

it’s definitely on ‘todo’ list

I saw this project, it is more tightly related with KiCad whilst my tool is generic svg diff viewer. I think there is a room for both.

btw, just added new release with precompiled static executables for Windows and Linux: Release v0.1.2 · adamws/lukaj · GitHub

I haven’t updated KiCad-Diff for a while as I have had a lot of other issues to deal with but a colleague who is sometimes on the forum @leoheck has spun off a more polished and complete project - Kiri.
This has a cli (as well as a gui interface) - the cli might fit your needs - and will compare svg diffs of schematics as well as pcb layouts. It builds on some of my code which uses a feMatrix transform function to highlight areas of change.

One of the challenges is to cope with situations where the entire board is moved. A helpful feature would also be to identify nets within the diff.

I figured out better way to start my diff script. It can be added to Tools menu entry of default git gui with following settings:

[guitool "diff-kicad"]
    cmd = git difftool -y -t diff-kicad $FILENAME
    noconsole = yes
    needsfile = yes

and git gui itself can be started with custom simple launcher plugin: GitHub - adamws/kicad-git: Git actions directly from KiCad's PCB editor window
As a bonus, it should be convenient way for committing changes (although KiCad 8 will have some git integration and could make this obsolete)

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.