Skip to main content

KiCad PCB/SCH Diff

Project description

KiDiff (kicad-diff or kicad_pcb-diff)

This program generates a PDF file showing the changes between two KiCad PCB or SCH files.

PCBs are plotted into PDF files, one for each layer. Then ImageMagick is used to compare the layers and PNG files are generated. The PNGs are finally assembled into one PDF file and the default PDF reader is invoked.

All the intermediate files are generated in the system temporal directory and removed as soon as the job is finished. You can cache the layers PDFs specifying a cache directory and keep the resulting diff images specifying an output directory.

For SCHs the process is similar, but using KiAuto. Note that one schematic is compared at a time. The --all_pages option allows comparing multiple pages, but both documents must have the same ammount of pages.

The default resolution for the images is 150 DPI. It can be increased for better images, at the cost of (exponetially) longer execution times. You can provide a smaller resolution for faster processing. For high resolution you could need to configure the ImageMagick limits. Consult the 'identify -list resource' command.

Installation

Dependencies

In order to run the scripts you need:

  • Python 3.5 or newer
  • KiCad 5.1 or newer
  • Python3 wxWidgets (i.e. python3-wxgtk4.0). This is usually installed with KiCad.
  • ImageMagick tools (i.e. imagemagick Debian package). Used to manipulate images and create PDF files.
  • pdftoppm tool (i.e. poppler-utils Debian package). Used to decode PDF files.
    • Alternative: Ghostscript (slower and worst results)
  • xdg-open tool (i.e. xdg-utils Debian package). Used to open the PDF viewer.
  • KiAuto. Used to print the schematic in PDF format.

In a Debian/Ubuntu system you'll first need to add this repo and then use:

$ sudo apt-get install python3 kicad imagemagick poppler-utils xdg-utils kiauto`

Note: if you are using Debian, or some derived distro like Ubuntu, you can find a Debian package in the releases section.

Standalone use

  1. As root run:
# make install

The scripts will be copied to /usr/local/bin. If you want to install the scripts in /usr/bin run

# make prefix=/usr install

Note: if you are using Debian, or some derived distro like Ubuntu, you can find a Debian package in the releases section.

Git plug-in

  1. Install the scripts
  2. To initialize a repo just run the kicad_pcb-diff-init.py script from the root of the repo.
    This will configure the repo to read extra configuration from the .gitconfig file.
    It will also associate the kicad_pcb file extension with the kicad-git-diff.py script.
  3. The initialization script will create a list of layers to be excluded in the .kicad-git-diff file.
    Review this file and adjust it to your needs. Lines starting with # will be ignored.

Once configured the tool will be used every time you do a diff using git.

Usage

The kicad-git-diff.py is a plug-in for git so you just need to configure git and then it becomes transparent. If you need to create a diff between two files outside git you can use the kicad-diff.py script.

You have to provide the name of the two PCBs to be compared. The additional command line options are:

-h

Shows a very brief list of the available options.

--help

Shows a more detailed list of the available options.

-v/--verbose

Increases the level of verbosity. The default is a quite, specifying one level (-v) you'll get information messages about what's going on. If you increase the level to two (-vv) you'll get very detailed information, most probably useful only to debug problems.

--version

Print the script version, copyright and license.

--all_pages

Compare all pages for a schematic. Note that the tool doesn't cuurently support adding or removing sheets, both documents must have the same ammount of pages.

--cache_dir

The PCB/SCH files are plotted to PDF files. One PDF file for layer. To avoid plotting them over and over you can specify a cache directory to store the PDFs.

--output_dir

Five seconds after invoking the PDF viewer the output files are removed. If you want to keep them for later review, or five seconds isn't enough for your system, you can specify a directory to store the generated files.

Note: individual PNGs are always removed, consult --keep_pngs

--output_name

Used to complement --output_dir. The default name is diff.pdf

--keep_pngs

Don't remove the individual PNGs. Complements --output_dir. They are usually removed as soon as we get the output PDF.

--resolution

The PDF files are converted to bitmaps to be compared. The default resolution for these bitmaps is 150 DPIs. This is a compromise between speed and legibility. For faster compares you can use a smaller resolution. For detailed comparison you can use a higher resolution. Be careful because the time is increased exponentially. You can also run out of resources. In particular ImageMagick defines some limits to the disk used for operations. These limits can be very low for default installations. You can consult the limits using the following command:

identify -list resource

Consult ImageMagick documentation in order to increase them.

--old_file_hash

The plotted PDF files for each layer are stored in the cache directory using a SHA1 of the PCB/SCH file as name for the directory. You can specify another hash here to identify the old PCB/SCH file.

The git plug-in uses the hash provided by git instead of the SHA1 for the file.

--new_file_hash

This is the equivalent of the --old_file_hash option used for the new PCB/SCH file.

--exclude

Specifies the name of a file containing a list of layers to be excluded. Each line of the file is interpreted as a layer name. An example for this file could be:

B.Adhes
F.Adhes
Cmts.User
Eco1.User
Eco2.User
Edge.Cuts
Margin

You can also use the KiCad internal layer ID number. Note that currently when using KiCad 6 the name of the layer is the default KiCad name, not the name defined by the user.

Note that when using the git plug-in the script looks for a file named .kicad-git-diff at the root of the repo.

Using this you can reduce the time wasted computing diffs for empty or useless layers.

--no_reader

Use it to avoid invoking the default PDF viewer. Note that you should also provide an output directory using --output_dir.

The default PDF reader is invoked using xdg-open

Credits and notes

  • This script is strongly based on Jesse Vincent work.
  • I borrowed the command to compare two images from Brecht Machiels. In particular from his diffpdf.sh tool.
  • I'm not a Python programmer, stackoverflow helps me ...

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

kidiff-2.2.0.tar.gz (14.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

kidiff-2.2.0-py3-none-any.whl (20.5 kB view details)

Uploaded Python 3

File details

Details for the file kidiff-2.2.0.tar.gz.

File metadata

  • Download URL: kidiff-2.2.0.tar.gz
  • Upload date:
  • Size: 14.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.3.0 pkginfo/1.4.2 requests/2.25.1 setuptools/52.0.0 requests-toolbelt/0.9.1 tqdm/4.57.0 CPython/3.9.2

File hashes

Hashes for kidiff-2.2.0.tar.gz
Algorithm Hash digest
SHA256 27fa5a77570bc6ffa0001992b064e58da4b69998c3f8ec7d2a92e15b7173f038
MD5 b34d771becbda1eda112a3081cde6cd5
BLAKE2b-256 241c8f136aad24daf791046026dced1304b8b09273346b0d60cb02ce3e5ffe8e

See more details on using hashes here.

File details

Details for the file kidiff-2.2.0-py3-none-any.whl.

File metadata

  • Download URL: kidiff-2.2.0-py3-none-any.whl
  • Upload date:
  • Size: 20.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.3.0 pkginfo/1.4.2 requests/2.25.1 setuptools/52.0.0 requests-toolbelt/0.9.1 tqdm/4.57.0 CPython/3.9.2

File hashes

Hashes for kidiff-2.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 4e4e97b8d3f6c2a4c2a696640c83835cbea24e59cf4da9ee2de2edc1a7d2abc0
MD5 f01fb76d68b8f82b5f589b5e9e87aeb7
BLAKE2b-256 adb6a62932d208d5c4964ac630ce214545bab5060c02532c40d189d55194c5b8

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page