Skip to content

Commit

Permalink
Add support for KiCAD 9
Browse files Browse the repository at this point in the history
  • Loading branch information
yaqwsx committed Jan 26, 2025
1 parent f972993 commit b6a00ba
Show file tree
Hide file tree
Showing 13 changed files with 3,580 additions and 42 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/test-kikit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ jobs:
runs-on: ubuntu-22.04
strategy:
matrix:
kicad-version: [v7, v7-testing, v8, v8-testing]
kicad-version: [v7, v7-testing, v8, v8-testing, nightly]
steps:
- uses: actions/checkout@v4
- uses: ./.github/actions/setup-kicad
Expand Down
4 changes: 2 additions & 2 deletions kikit/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from typing import List, Optional, Tuple, Union, Callable
from kikit.defs import Layer
from kikit.typing import Box
from pcbnewTransition import pcbnew, isV7, isV8
from pcbnewTransition import pcbnew, kicad_major
from kikit.intervals import AxialLine
from pcbnewTransition.pcbnew import BOX2I, VECTOR2I, EDA_ANGLE
import os
Expand Down Expand Up @@ -44,7 +44,7 @@ def fitsIn(what: Union[BOX2I, VECTOR2I], where: BOX2I) -> bool:
Return true iff 'what' (BOX2I or VECTOR2I) is fully contained in 'where'
(BOX2I)
"""
if isV7() or isV8():
if kicad_major() >= 7:
assert isinstance(what, (BOX2I, VECTOR2I, pcbnew.wxPoint))
else:
assert isinstance(what, (BOX2I, VECTOR2I, pcbnew.wxPoint, pcbnew.EDA_RECT))
Expand Down
104 changes: 99 additions & 5 deletions kikit/defs.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
from enum import Enum, IntEnum
from .units import mm, inch
from pcbnewTransition import kicad_major

# These classes miss in the exported interface

class Layer(IntEnum):
class LayerV1(IntEnum):
F_Cu = 0
B_Cu = 31
In1_Cu = 1
Expand Down Expand Up @@ -66,19 +67,112 @@ class Layer(IntEnum):

@staticmethod
def allCu():
return list(range(Layer.F_Cu, Layer.B_Cu + 1))
return list(range(LayerV1.F_Cu, LayerV1.B_Cu + 1))

@staticmethod
def all():
return list(range(Layer.F_Cu, Layer.User_4 + 1))
return list(range(LayerV1.F_Cu, LayerV1.User_4 + 1))

@staticmethod
def allTech():
return list(x for x in range(Layer.Dwgs_User, Layer.User_4 + 1))
return list(x for x in range(LayerV1.Dwgs_User, LayerV1.User_4 + 1))

@staticmethod
def allSilk():
return [Layer.F_SilkS, Layer.B_SilkS]
return [LayerV1.F_SilkS, LayerV1.B_SilkS]

class LayerV2(IntEnum):
F_Cu = 0
B_Cu = 2
In1_Cu = 4
In2_Cu = 6
In3_Cu = 8
In4_Cu = 10
In5_Cu = 12
In6_Cu = 14
In7_Cu = 16
In8_Cu = 18
In9_Cu = 20
In10_Cu = 22
In11_Cu = 24
In12_Cu = 26
In13_Cu = 28
In14_Cu = 30
In15_Cu = 32
In16_Cu = 34
In17_Cu = 36
In18_Cu = 38
In19_Cu = 40
In20_Cu = 42
In21_Cu = 44
In22_Cu = 46
In23_Cu = 48
In24_Cu = 50
In25_Cu = 52
In26_Cu = 54
In27_Cu = 56
In28_Cu = 58
In29_Cu = 60
In30_Cu = 62

B_Adhes = 11
F_Adhes = 9
B_Paste = 15
F_Paste = 13
B_SilkS = 7
F_SilkS = 5
B_Mask = 3
F_Mask = 1

Dwgs_User = 17
Cmts_User = 19
Eco1_User = 21
Eco2_User = 23
Edge_Cuts = 25
Margin = 27

B_CrtYd = 29
F_CrtYd = 31
B_Fab = 33
F_Fab = 35

User_1 = 39
User_2 = 41
User_3 = 43
User_4 = 45
User_5 = 47
User_6 = 49
User_7 = 51
User_8 = 53
User_9 = 55

@staticmethod
def allCu():
return list(range(LayerV2.F_Cu, LayerV2.In30_Cu + 2, 2))

@staticmethod
def all():
return list(range(64))

@staticmethod
def allTech():
return [
LayerV2.Dwgs_User,
LayerV2.Cmts_User,
LayerV2.Eco1_User,
LayerV2.Eco2_User,
LayerV2.Edge_Cuts,
LayerV2.Margin,
LayerV2.B_CrtYd,
LayerV2.F_CrtYd,
LayerV2.B_Fab,
LayerV2.F_Fab
] + list(range(LayerV2.User_1, LayerV2.User_9 + 2, 2))

if kicad_major() >= 9:
Layer = LayerV2
else:
Layer = LayerV1

class STROKE_T(IntEnum):
S_SEGMENT = 0
Expand Down
7 changes: 6 additions & 1 deletion kikit/drc.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from typing import Any, Dict, Iterable, List, TextIO, Tuple, Union
from pathlib import Path

from pcbnewTransition import isV7, isV8, pcbnew
from pcbnewTransition import isV7, isV8, isV9, pcbnew

from kikit.common import fromMm, toMm
from kikit.drc_ui import ReportLevel
Expand All @@ -21,6 +21,9 @@ def roundCoord(x: int) -> int:
return round(x - 50, -4)

def getItemDescription(item: pcbnew.BOARD_ITEM, units: pcbnew.EDA_UNITS = pcbnew.EDA_UNITS_MILLIMETRES):
if isV9():
uProvider = pcbnew.UNITS_PROVIDER(pcbnew.pcbIUScale, units)
return item.GetItemDescription(uProvider, True)
if isV7() or isV8():
uProvider = pcbnew.UNITS_PROVIDER(pcbnew.pcbIUScale, units)
return item.GetItemDescription(uProvider)
Expand Down Expand Up @@ -236,6 +239,8 @@ def readBoardDrcExclusions(board: pcbnew.BOARD) -> List[DrcExclusion]:
exclusions = project["board"]["design_settings"]["drc_exclusions"]
except KeyError:
return [] # There are no exclusions
if isV9() and len(exclusions) > 0 and isinstance(exclusions[0], list):
exclusions = [x[0] for x in exclusions]
return [deserializeExclusion(e, board) for e in exclusions]

def runImpl(board, useMm, ignoreExcluded, strict, level, yieldViolation):
Expand Down
4 changes: 2 additions & 2 deletions kikit/info.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

from pcbnewTransition import KICAD_VERSION, isV6, isV7, isV8
from pcbnewTransition import KICAD_VERSION, kicad_major
from kikit.common import KIKIT_LIB
import sys
import click
Expand All @@ -16,7 +16,7 @@ def drcapi():
"""
Return version of the DRC API
"""
if isV6() or isV7() or isV8():
if kicad_major() >= 6:
print("1")
else:
print("0")
Expand Down
4 changes: 2 additions & 2 deletions kikit/panelize.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from copy import deepcopy
import itertools
import textwrap
from pcbnewTransition import pcbnew, isV6
from pcbnewTransition import pcbnew, isV6, kicad_major
from kikit import sexpr
from kikit.common import normalize

Expand Down Expand Up @@ -453,7 +453,7 @@ def bakeTextVars(board: pcbnew.BOARD) -> None:
for drawing in board.GetDrawings():
if not isinstance(drawing, pcbnew.PCB_TEXT):
continue
if isV8():
if kicad_major() >= 8:
drawing.SetText(drawing.GetShownText(True))
else:
drawing.SetText(drawing.GetShownText())
Expand Down
2 changes: 1 addition & 1 deletion kikit/substrate.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import json
import numpy as np
from kikit.intervals import Interval, BoxNeighbors, BoxPartitionLines
from pcbnewTransition import pcbnew
from pcbnewTransition import pcbnew, isV8
from enum import IntEnum
from itertools import product

Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@
],
install_requires=[
"numpy", # Required for MacOS
"pcbnewTransition >= 0.4.1, <=0.5",
"pcbnewTransition >= 0.5.0, <=0.6",
"shapely>=2.0.3",
"click>=7.1",
"markdown2>=2.4",
Expand Down
Loading

0 comments on commit b6a00ba

Please sign in to comment.