Skip to content

Commit

Permalink
Added PCM and KiCAD 7.0 update
Browse files Browse the repository at this point in the history
  • Loading branch information
zykrah committed Feb 13, 2023
1 parent e2f803b commit aa33285
Show file tree
Hide file tree
Showing 5 changed files with 135 additions and 9 deletions.
45 changes: 45 additions & 0 deletions .github/workflows/kicad-pcm.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
# This is a workflow to generate the zip file and metadata.json for KiCAD PCM
# https://gitlab.com/kicad/addons/metadata/-/merge_requests/14

name: KiCAD PCM packaging
on: # yamllint disable-line rule:truthy
release:
branches: [master]
types:
- published
workflow_dispatch:

jobs:
create_archive:
runs-on: ubuntu-latest
steps:
- name: Get latest tag
uses: oprypin/find-latest-tag@v1
with:
repository: zykrah/kicad-kle-placer
releases-only: true
id: latest-release

- name: Checkout repo
uses: actions/checkout@v2

- name: Create archive
run: sh ./PCM/create_pcm_archive.sh ${{ steps.latest-release.outputs.tag }}

- name: Upload zip as asset to release
uses: svenstaro/upload-release-action@v2
with:
repo_token: ${{ secrets.GITHUB_TOKEN }}
file: ./PCM/KiCAD-PCM-${{ steps.latest-release.outputs.tag }}.zip
asset_name: KiCAD-PCM-${{ steps.latest-release.outputs.tag }}.zip
overwrite: true
tag: ${{ steps.latest-release.outputs.tag }}

- name: Trigger custom kicad repo rebuild
uses: benc-uk/workflow-dispatch@v1
with:
workflow: Rebuild repository
ref: refs/heads/main
repo: zykrah/zykrah-kicad-repository
token: ${{ secrets.PERSONAL_TOKEN }}
inputs: '{ "VERSION": "${{env.VERSION}}", "DOWNLOAD_SHA256": "${{env.DOWNLOAD_SHA256}}", "DOWNLOAD_SIZE": "${{env.DOWNLOAD_SIZE}}", "DOWNLOAD_URL": "${{env.DOWNLOAD_URL}}", "INSTALL_SIZE": "${{env.INSTALL_SIZE}}" }'
46 changes: 46 additions & 0 deletions PCM/create_pcm_archive.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
#!/bin/sh

# heavily inspired by https://github.com/4ms/4ms-kicad-lib/blob/master/PCM/make_archive.sh

VERSION=$1

echo "Clean up old files"
rm -f PCM/*.zip
rm -rf PCM/archive


echo "Create folder structure for ZIP"
mkdir -p PCM/archive/plugins
mkdir -p PCM/archive/resources

echo "Copy files to destination"
cp VERSION PCM/archive/plugins
cp *.py PCM/archive/plugins
cp *.png PCM/archive/plugins
cp settings.json PCM/archive/plugins
cp -r icons PCM/archive/plugins
cp PCM/icon.png PCM/archive/resources
cp PCM/metadata.template.json PCM/archive/metadata.json

echo "Write version info to file"
echo $VERSION > PCM/archive/plugins/VERSION

echo "Modify archive metadata.json"
sed -i "s/VERSION_HERE/$VERSION/g" PCM/archive/metadata.json
sed -i "s/\"kicad_version\": \"7.0\",/\"kicad_version\": \"7.0\"/g" PCM/archive/metadata.json
sed -i "/SHA256_HERE/d" PCM/archive/metadata.json
sed -i "/DOWNLOAD_SIZE_HERE/d" PCM/archive/metadata.json
sed -i "/DOWNLOAD_URL_HERE/d" PCM/archive/metadata.json
sed -i "/INSTALL_SIZE_HERE/d" PCM/archive/metadata.json

echo "Zip PCM archive"
cd PCM/archive
zip -r ../KiCAD-PCM-$VERSION.zip .
cd ../..

echo "Gather data for repo rebuild"
echo VERSION=$VERSION >> $GITHUB_ENV
echo DOWNLOAD_SHA256=$(shasum --algorithm 256 PCM/KiCAD-PCM-$VERSION.zip | xargs | cut -d' ' -f1) >> $GITHUB_ENV
echo DOWNLOAD_SIZE=$(ls -l PCM/KiCAD-PCM-$VERSION.zip | xargs | cut -d' ' -f5) >> $GITHUB_ENV
echo DOWNLOAD_URL="https:\/\/github.com\/zykrah\/kicad-kle-placer\/releases\/download\/$VERSION\/KiCAD-PCM-$VERSION.zip" >> $GITHUB_ENV
echo INSTALL_SIZE=$(unzip -l PCM/KiCAD-PCM-$VERSION.zip | tail -1 | xargs | cut -d' ' -f1) >> $GITHUB_ENV
33 changes: 33 additions & 0 deletions PCM/metadata.template.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
{
"$schema": "https://go.kicad.org/pcm/schemas/v1",
"name": "KiCAD KLE Placer",
"description": "A plugin for KiCAD used to place switches based on a KLE.",
"description_full": "This plugin allows you to automatically place footprints of your chosing from a generated KLE .json file.",
"identifier": "com.github.zykrah.kicad-kle-placer",
"type": "plugin",
"author": {
"name": "zykrah",
"contact": {
"github": "zykrah"
}
},
"maintainer": {
"name": "zykrah",
"contact": {
"github": "zykrah"
}
},
"license": "MIT",
"resources": {
"homepage": "https://github.com/zykrah/kicad-kle-placer"
},
"versions": [{
"version": "VERSION_HERE",
"status": "testing",
"kicad_version": "7.0",
"download_sha256": "SHA256_HERE",
"download_size": DOWNLOAD_SIZE_HERE,
"download_url": "DOWNLOAD_URL_HERE",
"install_size": INSTALL_SIZE_HERE
}]
}
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ NOTE:


# Installation
Download the github code and place it into `C:\Users\<user>\Documents\KiCad\6.0\scripting\plugins\kicad-kle-placer` (or wherever your plugins folder is located):
Download the github code and place it into `C:\Users\<user>\Documents\KiCad\7.0\scripting\plugins\kicad-kle-placer` (or wherever your plugins folder is located):

![image](https://user-images.githubusercontent.com/23428162/175076873-44e1a3c8-77f8-4e67-b2b9-29ffcd3559e7.png)

Expand Down
18 changes: 10 additions & 8 deletions kle_placer_action.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import pcbnew
from pcbnew import BOARD, FOOTPRINT, VECTOR2I, wxPoint, EDA_ANGLE

import wx
import os
import re
Expand Down Expand Up @@ -118,39 +120,39 @@ def get_specific_ref_mode_bool(self):
return self.specific_ref_mode.GetValue()

class BoardModifier():
def __init__(self, logger, board):
def __init__(self, logger, board: BOARD):
self.logger = logger
self.board = board
self.board: BOARD = board

def mm_to_nm(self, v):
return int(v * 1000000)

def nm_to_mm(self, v):
return v / 1000000.0

def get_footprint(self, reference, required=True):
def get_footprint(self, reference, required=True) -> FOOTPRINT:
self.logger.info("Searching for {} footprint".format(reference))
footprint = self.board.FindFootprintByReference(reference)
if footprint == None and required:
self.logger.error("Footprint not found")
raise Exception("Cannot find footprint {}".format(reference))
return footprint

def set_position(self, footprint, position):
def set_position(self, footprint: FOOTPRINT, position: wxPoint):
self.logger.info("Setting {} footprint position: {}".format(footprint.GetReference(), position))
footprint.SetPosition(position)
footprint.SetPosition(VECTOR2I(position))

def set_relative_position_mm(self, footprint, referencePoint, direction):
position = pcbnew.wxPoint(referencePoint.x + pcbnew.FromMM(direction[0]), referencePoint.y + pcbnew.FromMM(direction[1]))
self.set_position(footprint, position)

def rotate(self, footprint, rotationReference, angle):
def rotate(self, footprint: FOOTPRINT, rotationReference, angle):
self.logger.info("Rotating {} footprint: rotationReference: {}, rotationAngle: {}".format(footprint.GetReference(), rotationReference, angle))
footprint.Rotate(rotationReference, angle * -10)
footprint.Rotate(VECTOR2I(rotationReference), EDA_ANGLE(angle*-1, pcbnew.DEGREES_T))


class KeyPlacer(BoardModifier):
def __init__(self, logger, board, layout):
def __init__(self, logger, board: BOARD, layout):
super().__init__(logger, board)
self.layout: Keyboard = layout
self.key_distance = pcbnew.FromMM(19.05)
Expand Down

0 comments on commit aa33285

Please sign in to comment.