-
-
Notifications
You must be signed in to change notification settings - Fork 203
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Configured CLI to allow 'manual' option for layout. #535
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,6 +5,7 @@ | |
import glob | ||
import traceback | ||
from kikit.panelize_ui_sections import * | ||
from json import JSONDecodeError | ||
|
||
PKG_BASE = os.path.dirname(__file__) | ||
PRESETS = os.path.join(PKG_BASE, "resources/panelizePresets") | ||
|
@@ -34,6 +35,44 @@ def splitStr(delimiter, escapeChar, s): | |
return x | ||
|
||
|
||
class Input(click.ParamType): | ||
""" | ||
A CLI argument type for defining input boards. Can be either | ||
- Path to PCB file | ||
- Path to JSON file containing list of Board objects | ||
- JSON string containing list of Board objects | ||
""" | ||
name = "input" | ||
|
||
def convert(self, value, param, ctx): | ||
if len(value.strip()) == 0: | ||
self.fail(f"{value} is not a valid argument specification", | ||
param, ctx) | ||
try: | ||
values = [] | ||
if value.endswith(".kicad_pcb"): | ||
values.append(Board(value, ["0mm","0mm"])) | ||
else: | ||
json_str = value | ||
s = Section() | ||
if value.endswith(".json"): | ||
with open(value) as json_file: | ||
json_str = json_file.read() | ||
for d in json.loads(json_str): | ||
source = {} | ||
if "source" in d.keys(): | ||
source = s.convert(d.get("source"), param, ctx) | ||
values.append(Board(d["board"], d["pos"], source)) | ||
return values | ||
except IOError: | ||
self.fail(f"Could not open file '{value}'", | ||
param, | ||
ctx) | ||
except JSONDecodeError as e: | ||
self.fail(f"Invalid JSON at Line: {e.lineno}, Col: {e.colno}", | ||
param, | ||
ctx) | ||
|
||
class Section(click.ParamType): | ||
""" | ||
A CLI argument type for overriding section parameters. Basically a semicolon | ||
|
@@ -138,8 +177,7 @@ def fun(ctx, args, incomplete): | |
return fun | ||
|
||
@click.command() | ||
@click.argument("input", type=click.Path(dir_okay=False), | ||
**addCompatibleShellCompletion(pathCompletion(".kicad_pcb"))) | ||
@click.argument("input", type=Input()) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Unsure what to do about shell completion |
||
@click.argument("output", type=click.Path(dir_okay=False), | ||
**addCompatibleShellCompletion(pathCompletion(".kicad_pcb"))) | ||
@click.option("--preset", "-p", multiple=True, | ||
|
@@ -244,7 +282,8 @@ def doPanelization(input, output, preset, plugins=[]): | |
import kikit.substrate | ||
kikit.substrate.TABFAIL_VISUAL = True | ||
|
||
board = LoadBoard(input) | ||
|
||
board = LoadBoard(input[0].path) | ||
panel = Panel(output) | ||
|
||
useHookPlugins = ki.loadHookPlugins(plugins, board, preset) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -229,7 +229,7 @@ def obtainPreset(presetPaths, validate=True, **kwargs): | |
postProcessPreset(preset) | ||
return preset | ||
|
||
def buildLayout(preset, panel, sourceBoard, sourceArea): | ||
def buildLayout(preset, panel, boardList, sourceArea): | ||
""" | ||
Build layout for the boards - e.g., make a grid out of them. | ||
|
||
|
@@ -252,7 +252,7 @@ def buildLayout(preset, panel, sourceBoard, sourceArea): | |
hbonefirst=layout["hbonefirst"], | ||
vbonefirst=layout["vbonefirst"]) | ||
substrates = panel.makeGrid( | ||
boardfile=sourceBoard, sourceArea=sourceArea, | ||
boardfile=boardList[0].path, sourceArea=sourceArea, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Just uses the first board in the list. |
||
rows=layout["rows"], cols=layout["cols"], destination=VECTOR2I(0, 0), | ||
rotation=layout["rotation"], placer=placer, | ||
netRenamePattern=layout["renamenet"], refRenamePattern=layout["renameref"], | ||
|
@@ -261,11 +261,22 @@ def buildLayout(preset, panel, sourceBoard, sourceArea): | |
panel.buildPartitionLineFromBB(framingSubstrates) | ||
backboneCuts = buildBackBone(layout, panel, substrates, framing) | ||
return substrates, framingSubstrates, backboneCuts | ||
if type == "manual": | ||
for current in boardList: | ||
board = LoadBoard(current.path) | ||
sourceArea = readSourceArea(current.mergeSource(preset["source"]), board) | ||
panel.appendBoard(current.path, VECTOR2I(*current.pos), sourceArea, inheritDrc=False) | ||
substrates = panel.substrates | ||
framingSubstrates = dummyFramingSubstrate(substrates, preset) | ||
panel.buildPartitionLineFromBB(framingSubstrates) | ||
backboneCuts = buildBackBone(layout, panel, substrates, framing) | ||
return substrates, framingSubstrates, backboneCuts | ||
|
||
if type == "plugin": | ||
lPlugin = layout["code"](preset, layout["arg"], layout["renamenet"], | ||
layout["renameref"], layout["vspace"], | ||
layout["hspace"], layout["rotation"]) | ||
substrates = lPlugin.buildLayout(panel, sourceBoard, sourceArea) | ||
substrates = lPlugin.buildLayout(panel, boardList, sourceArea) | ||
framingSubstrates = dummyFramingSubstrate(substrates, preset) | ||
lPlugin.buildPartitionLine(panel, framingSubstrates) | ||
backboneCuts = lPlugin.buildExtraCuts(panel) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Using
Section
object in order to not rewrite the conversion code.Might be cleaner to move that code out into it's own function?