Skip to content

Commit 9b31f10

Browse files
authored
Merge pull request #738 from BackplaneWorks/backplane/pr-sweep-platform
Reconcile macOS KiCad launch and mechanical project guidance
2 parents dc4052d + e8893cc commit 9b31f10

9 files changed

Lines changed: 143 additions & 8 deletions

File tree

‎README.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ See [installation](docs/install.md) for setup, phone pairing and uninstalling. Y
5151
The viewers show the design as the agent works.
5252

5353
- **Board, Schematic, 3D.** Hierarchical schematics, layer controls in KiCad’s order and names, and cross-probing between views.
54-
- **Mech.** View STEP or GLB models. Agents model parts with FreeCAD scripts, export STEP, and show the result here.
54+
- **Mech.** View STEP or GLB models. Agents model parts with FreeCAD scripts, export STEP, and show the result here. Mechanical-only folders need no KiCad project; see the [mechanical quickstart](docs/mechanical.md).
5555
- **History and review.** Compare versions, inspect changes by sheet and layer, pin comments to a board or schematic, and run BOM, ERC and DRC checks from the Review tab.
5656
- **Skills.** KiCad skills from [KiStack](https://github.com/BackplaneWorks/kistack) ship with the app: schematic, layout, footprints, BOM and fabrication exports.
5757
- **Ordering.** When a design has a fab file, Buy it opens a thread that checks the design and gets a quote. See [ordering](docs/order.md).

‎docs/mechanical.md‎

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
# Mechanical projects
2+
3+
A Backplane project can be an ordinary folder containing mechanical parts.
4+
It does not need a KiCad project or a board. The files and modelling tools
5+
live on the machine running the hub, even when you use a browser or phone.
6+
7+
## View an existing model
8+
9+
1. Add the project folder to Backplane and open a thread in it.
10+
2. Put the models you want in the parts list in a folder named `mech/` at
11+
the project's root. For example:
12+
13+
```text
14+
bracket-project/
15+
mech/
16+
bracket.step
17+
spacer.step
18+
```
19+
20+
3. Open the viewer's **Mech** tab and select a part to turn it in 3D.
21+
4. For still images, open **Renders**, then **Create renders**. Backplane
22+
writes isometric, front, top and right views under `mech/renders/`.
23+
The renders page also has **Refresh** to reload the parts list.
24+
25+
The supported model formats are `.step`, `.stp` and `.glb`. STEP inspection uses the configured conversion helper; no KiCad project
26+
is required. FreeCAD documents (`.FCStd`)
27+
and STL meshes are not displayed directly; export or convert them to a
28+
supported format first.
29+
30+
A model can also stay elsewhere in the project. Open it from **Files**,
31+
or ask the agent:
32+
33+
> Show `vendor/spacer.step` on the Mech tab without changing it.
34+
35+
The agent can use `viewer_show` with the file's absolute path and
36+
`kind: "mech"`. The viewer follows saves to that file. Copy or export it
37+
into `mech/` if you also want it in the project's parts list. The **3D**
38+
tab is for the KiCad board; standalone models belong on **Mech**.
39+
40+
## Model a part with an agent
41+
42+
Install FreeCAD on the hub's machine for modelling and STEP conversion.
43+
See [installation](install.md) for platform setup. Set `BACKPLANE_FREECAD`
44+
to its console executable when starting the hub if automatic discovery
45+
does not find it. Existing GLB models can be viewed without a conversion.
46+
47+
Start with a small, concrete request, for example:
48+
49+
> Make an 80 by 30 by 3 mm rectangular mounting plate with two 5 mm
50+
> through-holes, centred across its width and 60 mm apart along its length.
51+
> Centre the pair on the plate. Keep the dimensions as named parameters
52+
> in `mech/plate.py`, save `mech/plate.FCStd`, export `mech/plate.step`,
53+
> and show it on the Mech tab.
54+
55+
Backplane's mechanical instructions tell the agent to work in millimetres,
56+
with Z up and the front facing -Y, check the shape's validity, and keep
57+
the script, FreeCAD document and STEP export together. Ask for changes to
58+
the script and regenerate the export to see each revision.
59+
60+
Keep the source and exports in Git if you want to track mechanical
61+
revisions. The design history's per-tool KiCad snapshots and board or
62+
schematic Compare do not provide a STEP geometry comparison.

‎i18n/en.msg‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1159,7 +1159,7 @@ native.hub.failure = {reason, select, timeout {Hub response timed out; retrying}
11591159
# Native file, review, task and space controls.
11601160
native.viewer.source = Source
11611161
native.file.image.unsupported = This image cannot be shown here
1162-
native.file.pdf.error = {kind, select, send {The hub could not send this PDF (it may be over 12 MB)} http {The hub answered {code}} other {This PDF cannot be shown here}}
1162+
native.file.pdf.error = {kind, select, send {The hub could not read this PDF} http {The hub answered {code}} other {This PDF cannot be shown here}}
11631163
native.file.page = Page {number}
11641164
native.review.comment = Comment
11651165
native.review.resolved = Resolved

‎i18n/ja.msg‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1179,7 +1179,7 @@ native.hub.failure = {reason, select, timeout {ハブの応答がタイムアウ
11791179
# Native file, review, task and space controls.
11801180
native.viewer.source = 表示元
11811181
native.file.image.unsupported = この画像は表示できません
1182-
native.file.pdf.error = {kind, select, send {ハブからPDFを取得できません(12 MBを超えている可能性があります)} http {ハブの応答:{code}} other {このPDFは表示できません}}
1182+
native.file.pdf.error = {kind, select, send {ハブからPDFを取得できません} http {ハブの応答:{code}} other {このPDFは表示できません}}
11831183
native.file.page = {number}ページ
11841184
native.review.comment = コメント
11851185
native.review.resolved = 解決済み

‎mobile/android/app/src/main/java/dev/backplane/mobile/NativeMessages.kt‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -334,7 +334,7 @@ object NativeMessages {
334334

335335
// native.file.pdf.error
336336
fun native_file_pdf_error(tag: String, arg0: String, arg1: String): String =
337-
if (tag == "ja") ((if (arg0 == "send") "ハブからPDFを取得できません(12 MBを超えている可能性があります)" else (if (arg0 == "http") "ハブの応答:" + arg1 else "このPDFは表示できません"))) else ((if (arg0 == "send") "The hub could not send this PDF (it may be over 12 MB)" else (if (arg0 == "http") "The hub answered " + arg1 else "This PDF cannot be shown here")))
337+
if (tag == "ja") ((if (arg0 == "send") "ハブからPDFを取得できません" else (if (arg0 == "http") "ハブの応答:" + arg1 else "このPDFは表示できません"))) else ((if (arg0 == "send") "The hub could not read this PDF" else (if (arg0 == "http") "The hub answered " + arg1 else "This PDF cannot be shown here")))
338338

339339
// native.file.text.error
340340
fun native_file_text_error(tag: String, arg0: String): String =

‎mobile/ios/Shared/NativeMessages.swift‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -421,7 +421,7 @@ enum NativeMessages {
421421

422422
// native.file.pdf.error
423423
static func native_file_pdf_error(_ tag: String, _ arg0: String, _ arg1: String) -> String {
424-
tag == "ja" ? ((arg0 == "send" ? "ハブからPDFを取得できません(12 MBを超えている可能性があります)" : (arg0 == "http" ? "ハブの応答:" + arg1 : "このPDFは表示できません"))) : ((arg0 == "send" ? "The hub could not send this PDF (it may be over 12 MB)" : (arg0 == "http" ? "The hub answered " + arg1 : "This PDF cannot be shown here")))
424+
tag == "ja" ? ((arg0 == "send" ? "ハブからPDFを取得できません" : (arg0 == "http" ? "ハブの応答:" + arg1 : "このPDFは表示できません"))) : ((arg0 == "send" ? "The hub could not read this PDF" : (arg0 == "http" ? "The hub answered " + arg1 : "This PDF cannot be shown here")))
425425
}
426426

427427
// native.file.text.error

‎src/core/msgs.bend‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2869,9 +2869,9 @@ def T.native.file.page(l: I.Loc, arg0: String) -> String:
28692869
def T.native.file.pdf.error(l: I.Loc, +arg0: String, arg1: String) -> String:
28702870
match l:
28712871
case I.En{}:
2872-
I.I18n.sel(arg0, "send", "The hub could not send this PDF (it may be over 12 MB)", I.I18n.sel(arg0, "http", "The hub answered " ++ arg1, "This PDF cannot be shown here"))
2872+
I.I18n.sel(arg0, "send", "The hub could not read this PDF", I.I18n.sel(arg0, "http", "The hub answered " ++ arg1, "This PDF cannot be shown here"))
28732873
case I.Ja{}:
2874-
I.I18n.sel(arg0, "send", "ハブからPDFを取得できません(12 MBを超えている可能性があります)", I.I18n.sel(arg0, "http", "ハブの応答:" ++ arg1, "このPDFは表示できません"))
2874+
I.I18n.sel(arg0, "send", "ハブからPDFを取得できません", I.I18n.sel(arg0, "http", "ハブの応答:" ++ arg1, "このPDFは表示できません"))
28752875

28762876
def T.native.file.text.error(l: I.Loc, arg0: String) -> String:
28772877
match l:

‎src/server/kicad.bend‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -972,7 +972,7 @@ def KiCad.open.said(r: P.Ran) -> String:
972972
String.trim(out)
973973

974974
def KiCad.open.script() -> String:
975-
"set -eu\nr=$1\nif [ -n \"$2\" ]; then set -- kicad \"$2\"; elif [ -n \"$3\" ]; then set -- pcbnew \"$3\"; elif [ -n \"$4\" ]; then set -- eeschema \"$4\"; else echo 'no KiCad project here'; exit 1; fi\ng=$r/bin/$1\n[ -x \"$g\" ] || g=$g.exe\n[ -x \"$g\" ] || { echo \"Backplane KiCad has no $1\"; exit 1; }\nif command -v setsid >/dev/null 2>&1; then\n setsid -f \"$g\" \"$2\" </dev/null >/dev/null 2>&1\nelse\n perl -MPOSIX -e 'defined(my $pid=fork) or exit 127; exit 0 if $pid; POSIX::setsid(); exec {$ARGV[0]} @ARGV or exit 127' \"$g\" \"$2\" </dev/null >/dev/null 2>&1\nfi\n"
975+
"set -eu\nr=$1\nif [ -n \"$2\" ]; then set -- kicad \"$2\"; elif [ -n \"$3\" ]; then set -- pcbnew \"$3\"; elif [ -n \"$4\" ]; then set -- eeschema \"$4\"; else echo 'no KiCad project here'; exit 1; fi\nif [ \"$(uname)\" = Darwin ]; then\n a=$r/KiCad.app\n [ \"$1\" = kicad ] || a=$a/Contents/Applications/$1.app\n [ -d \"$a\" ] || { echo \"Backplane KiCad has no $1\"; exit 1; }\n exec open -a \"$a\" \"$2\"\nfi\ng=$r/bin/$1\n[ -x \"$g\" ] || g=$g.exe\n[ -x \"$g\" ] || { echo \"Backplane KiCad has no $1\"; exit 1; }\nif command -v setsid >/dev/null 2>&1; then\n setsid -f \"$g\" \"$2\" </dev/null >/dev/null 2>&1\nelse\n perl -MPOSIX -e 'defined(my $pid=fork) or exit 127; exit 0 if $pid; POSIX::setsid(); exec {$ARGV[0]} @ARGV or exit 127' \"$g\" \"$2\" </dev/null >/dev/null 2>&1\nfi\n"
976976

977977
def KiCad.open.ready(fork: Bool, +cli: String, +fs: Files) -> IO(String):
978978
match fork fs:
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
"""Run the production launcher with synthetic apps and command stand-ins."""
2+
import ast
3+
import json
4+
import os
5+
from pathlib import Path
6+
import re
7+
import subprocess
8+
import tempfile
9+
import unittest
10+
11+
ROOT = Path(__file__).resolve().parents[2]
12+
13+
14+
class KiCadOpenTest(unittest.TestCase):
15+
def setUp(self):
16+
self.tmp = tempfile.TemporaryDirectory(prefix="bp-kicad-open-")
17+
self.addCleanup(self.tmp.cleanup)
18+
self.home = Path(self.tmp.name)
19+
self.bin = self.home / "commands"
20+
self.bin.mkdir()
21+
self.runtime = self.home / "runtime with spaces"
22+
self.runtime.mkdir()
23+
self.record = self.home / "args.json"
24+
text = (ROOT / "src/server/kicad.bend").read_text()
25+
self.script = ast.literal_eval(re.search(r'def KiCad.open.script\(\) -> String:\n ("[^\n]+")', text)[1])
26+
self.command("uname", "#!/bin/sh\nprintf '%s\\n' \"$TEST_PLATFORM\"\n")
27+
for name in ["open", "setsid"]:
28+
self.command(name, "#!/usr/bin/env python3\nimport json,os,sys\nopen(os.environ['TEST_RECORD'],'w').write(json.dumps(sys.argv[1:]))\n")
29+
30+
def command(self, name, text):
31+
path = self.bin / name
32+
path.write_text(text)
33+
path.chmod(0o755)
34+
35+
def run_launcher(self, platform, files):
36+
return subprocess.run(["sh", "-c", self.script, "sh", str(self.runtime), *files],
37+
env={**os.environ, "PATH": str(self.bin) + os.pathsep + os.environ["PATH"],
38+
"TEST_PLATFORM": platform, "TEST_RECORD": str(self.record)},
39+
text=True, capture_output=True, timeout=5)
40+
41+
def test_mac_routes_project_and_lone_editors(self):
42+
for files, app, target in [(["project with spaces.kicad_pro", "b", "s"], "KiCad.app", "project with spaces.kicad_pro"),
43+
(["", "board.kicad_pcb", "s"], "KiCad.app/Contents/Applications/pcbnew.app", "board.kicad_pcb"),
44+
(["", "", "sheet.kicad_sch"], "KiCad.app/Contents/Applications/eeschema.app", "sheet.kicad_sch")]:
45+
with self.subTest(app=app):
46+
(self.runtime / app).mkdir(parents=True, exist_ok=True)
47+
result = self.run_launcher("Darwin", files)
48+
self.assertEqual(result.returncode, 0, result.stderr)
49+
self.assertEqual(json.loads(self.record.read_text()), ["-a", str(self.runtime / app), target])
50+
51+
def test_missing_package_and_project_refuse(self):
52+
for files, diagnostic in [(["p.kicad_pro", "", ""], "Backplane KiCad has no kicad"),
53+
(["", "", ""], "no KiCad project here")]:
54+
result = self.run_launcher("Darwin", files)
55+
self.assertNotEqual(result.returncode, 0)
56+
self.assertIn(diagnostic, result.stdout)
57+
self.assertFalse(self.record.exists())
58+
59+
def test_other_platform_launchers_and_exe_fallback(self):
60+
(self.runtime / "bin").mkdir()
61+
for platform, binary in [("Linux", "kicad"), ("MINGW64_NT", "kicad.exe")]:
62+
with self.subTest(platform=platform):
63+
path = self.runtime / "bin" / binary
64+
path.write_text("#!/bin/sh\nexit 0\n")
65+
path.chmod(0o755)
66+
result = self.run_launcher(platform, ["p.kicad_pro", "", ""])
67+
self.assertEqual(result.returncode, 0, result.stderr)
68+
self.assertEqual(json.loads(self.record.read_text()), ["-f", str(path), "p.kicad_pro"])
69+
path.unlink()
70+
71+
72+
if __name__ == "__main__":
73+
unittest.main()

0 commit comments

Comments
 (0)