forked from yaqwsx/KiKit
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 8bb2900
Showing
17 changed files
with
1,649 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
# Ignore python files | ||
__pycache__ | ||
|
||
# Ignore dev kicad files | ||
*.kicad_pcb* | ||
*.pro | ||
fp-info-cache | ||
|
||
# Ignore VS Code | ||
.vscode | ||
|
||
# Ignore build | ||
build |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
MIT License | ||
|
||
Copyright (c) 2020 Jan Mrázek | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
|
||
|
||
.PHONY: doc | ||
|
||
doc: doc/panelization.md | ||
|
||
doc/panelization.md: kikit/panelize.py scripts/panelizeDoc.py | ||
PYTHONPATH=`pwd` python3 scripts/panelizeDoc.py > $@ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
# KiKit - Automatization for KiCAD | ||
|
||
KiKit is a Python library and CLI tool to automate several task in standard | ||
KiCAD workflow like: | ||
|
||
- panelization of the boards | ||
- exporting manufacturing data | ||
|
||
 | ||
|
||
## Why Should I Use It? | ||
|
||
Everything KiKit does can be also done via Pcbnew in KiCAD. But you have to do | ||
it manually. One of the common scenarios is creation of panels. Most of the | ||
tutorials on the internet guide you to use the "append board" functionality of | ||
Pcbnew. However, this approach labour-intensive, error-prone and whenever you | ||
change the board, you have to do it again. | ||
|
||
With KiKit you just call a CLI command if you have a simple layout (e.g., grid) | ||
or write few Python instructions like "place board here", "add bridge here", | ||
"separate boards via mouse bites/v-cuts" and you are done. The process is | ||
repeatable and actually much simpler than hand-drawing the panels. KiKit also | ||
allows you to easily export all the Gerbers in a single step. | ||
|
||
You can then write a Makefile and simply call `make` to get all your | ||
manufacturing data. | ||
|
||
|
||
See [BatteryPack](https://github.com/RoboticsBrno/RB0002-BatteryPack) as an | ||
example usage of KiKit. | ||
|
||
## Feature List | ||
|
||
- create panels by appending boards and pieces of substrate (bridges) | ||
- easily create mouse-bites/V-CUTS | ||
- compared to hand-creation of panels, your panels will pass DRC (as tracks from | ||
different instances of the same board have distinct nets when using KiKit) | ||
- if you have multiple boards in a single file, you can split them | ||
- automated export of gerber files | ||
|
||
## How To Use It? | ||
|
||
Read the [CLI documentation](doc/cli.md) and the [panelize | ||
documentation](doc/panelize.md). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
# KiKit CLI interface | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
|
||
# Panelization | ||
|
||
When you want to panelize a board, you are expected to load the `kikit.panelize` | ||
module and create an instance of the `Panel` class. | ||
|
||
All units are in the internal KiCAD units (1 nm). You can use functions `fromMm(mm)` and | ||
`toMm(kiUnits)` to convert to/from them (synopsis below). You are also encouraged to use | ||
the functions and objects the native KiCAD Python API offers, e.g.: `wxPoint(args)`, `wxPointMM(mmx, mmy)`, `wxRect(args)`, `wxRectMM(x, y, wx, wy)`. | ||
|
||
|
||
|
||
## Panel class | ||
|
||
Basic interface for panel building. Instance of this class represents a | ||
single panel. You can append boards, add substrate pieces, make cuts or add | ||
holes to the panel. Once you finish, you have to save the panel to a file. | ||
``` | ||
appendBoard(self, filename, destination, sourceArea=None, origin=Origin.Center, | ||
rotationAngle=0, shrink=False, tolerance=0) | ||
``` | ||
Appends a board to the panel. | ||
|
||
The sourceArea (wxRect) of the board specified by filename is extracted | ||
and placed at destination (wxPoint). The source area (wxRect) can be | ||
auto detected if it is not provided. Only board items which fit entirely | ||
into the source area are selected. You can also specify rotation. Both | ||
translation and rotation origin are specified by origin. Origin | ||
specifies which point of the sourceArea is used for translation and | ||
rotation (origin it is placed to destination). It is possible to specify | ||
coarse source area and automatically shrink it if shrink is True. | ||
Tolerance enlarges (even shrinked) source area - useful for inclusion of | ||
filled zones which can reach out of the board edges. | ||
|
||
Returns bounding box (wxRect) of the extracted area. | ||
``` | ||
save(self, filename) | ||
``` | ||
Saves the panel to a file. | ||
``` | ||
appendSubstrate(self, substrate, filletRadius=0) | ||
``` | ||
Append a piece of substrate to the panel. Substrate can be either wxRect | ||
or Shapely polygon. Newly appended corners can be rounded by specifying | ||
non-zero filletRadius. | ||
``` | ||
makeGrid(self, boardfile, rows, cols, destination, sourceArea=None, tolerance=0, | ||
radius=0, verSpace=0, horSpace=0, verTabWidth=0, horTabWidth=0, | ||
outerVerTabThickness=0, outerHorTabThickness=0) | ||
``` | ||
Creates a grid of boards (row x col) as a panel at given destination | ||
separated by V-CUTS. The source can be either extract automatically of | ||
from given sourceArea. There can be a spacing between the individual | ||
board (verSpacing, horSpacing) and the tab width can be adjusted | ||
(verTabWidth, horTabWidth). Also the user can control whether append the | ||
outer tabs (e.g. to connect it to a frame) by setting outerVerTabsWidth | ||
and outerHorTabsWidth. | ||
|
||
Returns a tuple - wxRect with the panel bounding box (excluding | ||
outerTabs) and a list of cuts (list of lines) to make. You can use the | ||
list to either create a V-CUTS via makeVCuts or mouse bites via | ||
makeMouseBites. | ||
``` | ||
makeTightGrid(self, boardfile, rows, cols, destination, verSpace, horSpace, | ||
slotWidth, width, height, sourceArea=None, tolerance=0, radius=0, | ||
verTabWidth=0, horTabWidth=0) | ||
``` | ||
Creates a grid of boards just like `makeGrid`, however, it creates a | ||
milled slot around perimeter of each board and 4 tabs. | ||
``` | ||
makeFrame(self, innerArea, width, height, offset, radius=0) | ||
``` | ||
Adds a frame around given `innerArea` (`wxRect`), which can be obtained, | ||
e.g., by `makeGrid`, with given `width` and `height`. Space with width | ||
`offset` is added around the `innerArea`. | ||
``` | ||
makeVCuts(self, cuts) | ||
``` | ||
Take a list of lines to cut and performs V-CUTS | ||
``` | ||
makeMouseBites(self, cuts, diameter, spacing) | ||
``` | ||
Take a list of cuts and perform mouse bites. | ||
``` | ||
addNPTHole(self, position, diameter) | ||
``` | ||
Add a drilled non-plated hole to the position (`wxPoint`) with given | ||
diameter. | ||
|
||
## Examples | ||
|
||
### Simple grid | ||
|
||
The following example creates 3 x 3 grid of boards in a frame separated by V-CUTS. | ||
|
||
``` | ||
panel = Panel() | ||
size, cuts = panel.makeGrid("test.kicad_pcb", 4, 3, wxPointMM(100, 40), | ||
tolerance=fromMm(5), verSpace=fromMm(5), horSpace=fromMm(5), | ||
outerHorTabThickness=fromMm(3), outerVerTabThickness=fromMm(3), | ||
verTabWidth=fromMm(15), horTabWidth=fromMm(8), | ||
radius=fromMm(1)) | ||
panel.makeVCuts(cuts) | ||
# alternative: panel.makeMouseBites(cuts, diameter=fromMm(0.5), spacing=fromMm(1)) | ||
panel.makeFrame(size, fromMm(100), fromMm(100), fromMm(3), radius=fromMm(1)) | ||
panel.save("out.kicad_pcb") | ||
``` | ||
|
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
from enum import Enum, IntEnum | ||
|
||
# These classes miss in the exported interface | ||
|
||
class Layer(IntEnum): | ||
B_Adhes = 32 | ||
F_Adhes = 33 | ||
B_Paste = 34 | ||
F_Paste = 35 | ||
B_SilkS = 36 | ||
F_SilkS = 37 | ||
B_Mask = 38 | ||
F_Mask = 39 | ||
Dwgs_User = 40 | ||
Cmts_User = 41 | ||
Eco1_User = 42 | ||
Eco2_User = 43 | ||
Edge_Cuts = 44 | ||
Margin = 45 | ||
B_CrtYd = 46 | ||
F_CrtYd = 47 | ||
B_Fab = 48 | ||
F_Fab = 49 | ||
|
||
class STROKE_T(IntEnum): | ||
S_SEGMENT = 0 | ||
S_RECT = 1 | ||
S_ARC = 2 | ||
S_CIRCLE = 3 | ||
S_POLYGON = 4 | ||
S_CURVE = 5 | ||
|
||
class EDA_TEXT_HJUSTIFY_T(IntEnum): | ||
GR_TEXT_HJUSTIFY_LEFT = -1 | ||
GR_TEXT_HJUSTIFY_CENTER = 0 | ||
GR_TEXT_HJUSTIFY_RIGHT = 1 | ||
|
||
class EDA_TEXT_VJUSTIFY_T(IntEnum): | ||
GR_TEXT_VJUSTIFY_TOP = -1 | ||
GR_TEXT_VJUSTIFY_CENTER = 0 | ||
GR_TEXT_VJUSTIFY_BOTTOM = 1 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import inspect | ||
|
||
def header(func): | ||
signature = inspect.signature(func) | ||
args = [str(k) if v.default is inspect.Parameter.empty else str(k) + "=" + str(v.default) | ||
for k, v in signature.parameters.items()] | ||
currentLine = func.__name__ + "(" | ||
lines = [] | ||
indent = " " * (len(func.__name__) + 1) | ||
separator = "" | ||
for arg in args: | ||
newLine = currentLine + separator + arg | ||
if len(newLine) > 80: | ||
lines.append(currentLine + separator) | ||
currentLine = indent + arg | ||
else: | ||
currentLine = newLine | ||
separator = ", " | ||
lines.append(currentLine + ")") | ||
return("\n".join(lines)) | ||
|
||
def printHeader(func): | ||
print("```\n" + header(func) + "\n```") | ||
|
||
def printHelp(x): | ||
print(inspect.getdoc(x)) |
Oops, something went wrong.