From 65f34b39e0473b324f13affeb5665e75335ad0f6 Mon Sep 17 00:00:00 2001 From: cpu Date: Fri, 19 Jun 2026 13:18:45 +0200 Subject: [PATCH] flatcam externalized --- .gitignore | 4 +-- Readme.md | 68 ++++++++++++++++++++++++++++++++++---------------- run_stencil.sh | 4 +-- 3 files changed, 50 insertions(+), 26 deletions(-) diff --git a/.gitignore b/.gitignore index ef9f69a..3a26ce8 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,2 @@ gcode/ -gerbers/ -.flatcam-env/ -flatcam-beta/ \ No newline at end of file +gerbers/ \ No newline at end of file diff --git a/Readme.md b/Readme.md index d1b1378..8317190 100644 --- a/Readme.md +++ b/Readme.md @@ -2,6 +2,8 @@ Automates the conversion of a KiCad v9 `F.Paste` and `B.Paste` Gerber to G-code for CNC milling a solder paste stencil, using FlatCAM beta 8.995 headless. Tested on Ubuntu 24.04 with Python 3.12 and a Frezu 3040 / FluidNC controller. +This project shares a single FlatCAM install (`~/flatcam-beta`) with other `kicad2*` pipelines (e.g. `kicad2outlines`). Install FlatCAM once; each project just points to it. + --- ## Prerequisites @@ -21,37 +23,39 @@ Automates the conversion of a KiCad v9 `F.Paste` and `B.Paste` Gerber to G-code sudo apt install python3-venv python3-pip libgeos-dev libspatialindex-dev libxcb-cursor0 ``` -### 2. Clone FlatCAM beta 8.995 +### 2. Install FlatCAM beta 8.995 (shared, once) + +If `~/flatcam-beta` already exists, skip to step 3 — there's nothing to do here. ```bash -git clone --branch mstanciu_Beta_8.995 --depth 1 https://github.com/dwrobel/flatcam.git flatcam-beta -``` - -### 3. Create a Python venv and install dependencies - -```bash -cd flatcam-beta +git clone --branch mstanciu_Beta_8.995 --depth 1 https://github.com/dwrobel/flatcam.git ~/flatcam-beta +cd ~/flatcam-beta python3 -m venv .flatcam-env source .flatcam-env/bin/activate pip install PyQt6 PyQt6-Qt6 PyQt6-sip -# Skip ortools (path optimizer), rasterio, and gdal (image import) — not needed for stencils +# Skip ortools (path optimizer), rasterio, and gdal (image import) — not needed for stencils/outlines grep -vE "ortools|rasterio|gdal" requirements.txt | pip install -r /dev/stdin + +deactivate ``` -### 4. Verify +### 3. Verify ```bash -python flatcam.py --version +~/flatcam-beta/.flatcam-env/bin/python ~/flatcam-beta/flatcam.py --version ``` You should see the FlatCAM version string printed without errors. -Go back to the project directory: +### 4. Point this project at the shared install + +`run_stencil.sh` reads the `FLATCAM_HOME` environment variable, defaulting to `~/flatcam-beta` if unset. Override it only if your install lives elsewhere: + ```bash -cd .. +export FLATCAM_HOME=~/flatcam-beta # default, usually no need to set this ``` ### 5. Export the stencil gerbers @@ -65,22 +69,41 @@ kicad-cli pcb export gerbers -o gerbers -l F.Paste,B.Paste ../kicad2panel/panel/ ## Usage -Generate the stencil G-code for both layers: +Generate the stencil G-code for the layer `F.Paste`: ```bash ./run_stencil.sh gerbers/Flow_Controller_Panel-F_Paste.gtp \ gcode/Flow_Controller_Panel-F_Paste-stencil.nc +``` +It should output: + +``` +→ Running FlatCAM headless... + Gerber : gerbers/Flow_Controller_Panel-F_Paste.gtp + Output : gcode/Flow_Controller_Panel-F_Paste-stencil.nc + + + +✓ Done: gcode/Flow_Controller_Panel-F_Paste-stencil.nc (277 lines) +``` + +Generate the stencil G-code for the layer `B.Paste`: +```bash ./run_stencil.sh gerbers/Flow_Controller_Panel-B_Paste.gbp \ gcode/Flow_Controller_Panel-B_Paste-stencil.nc ``` -G-code for both layers should be in: +It should output: ``` -gcode/Flow_Controller_Panel-F_Paste-stencil.nc -gcode/Flow_Controller_Panel-B_Paste-stencil.nc -``` +→ Running FlatCAM headless... + Gerber : gerbers/Flow_Controller_Panel-B_Paste.gbp + Output : gcode/Flow_Controller_Panel-B_Paste-stencil.nc + + +✓ Done: gcode/Flow_Controller_Panel-B_Paste-stencil.nc (1895 lines) +``` --- ## Parameters @@ -129,10 +152,10 @@ Alternative: `GRBL_11_no_M6` suppresses tool change commands — not needed for The `run_stencil.sh` wrapper detects the `TclCommandQuit` log line and kills the process after 3 seconds. This is expected behavior — FlatCAM's Qt GUI cleanup hangs in headless mode. **`ImportError: cannot import name 'Inf' from numpy`** -You have the old PyPI FlatCAM 8.5 installed. Follow the installation steps above to switch to the beta 8.995 clone. +You have the old PyPI FlatCAM 8.5 installed somewhere on your `PATH`/venv. Make sure `FLATCAM_HOME` points at `~/flatcam-beta` (the beta 8.995 clone from the install steps above), not a pip-installed FlatCAM. **`ImportError: cannot import name 'cascaded_union' from shapely.ops`** -Same cause — old FlatCAM 8.5 is incompatible with Shapely 2.0. Switch to beta 8.995. +Same cause — old FlatCAM 8.5 is incompatible with Shapely 2.0. Check `FLATCAM_HOME` as above. **G-code cuts everything except the pads** You used `ncc` (non-copper clear) instead of `paint`. The correct command is `paint` — it pockets the pad polygons. `ncc` clears everything around them, which is the inverse. @@ -141,4 +164,7 @@ You used `ncc` (non-copper clear) instead of `paint`. The correct command is `pa Skip it — `gdal` is only needed for the image import plugin. Use: ```bash grep -vE "ortools|rasterio|gdal" requirements.txt | pip install -r /dev/stdin -``` \ No newline at end of file +``` + +**Multiple projects, which one owns the FlatCAM install?** +None of them — `~/flatcam-beta` is shared and project-agnostic. Install it once via any one project's instructions above; every other `kicad2*` project just needs `FLATCAM_HOME` set (or left at its default) to find it. Don't `git clone` a second copy per project. \ No newline at end of file diff --git a/run_stencil.sh b/run_stencil.sh index d99892e..0981ac6 100755 --- a/run_stencil.sh +++ b/run_stencil.sh @@ -11,8 +11,8 @@ OUTPUT="${2:?Usage: $0 }" SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)" TCL_SCRIPT="$SCRIPT_DIR/paste_stencil.tcl" -FLATCAM_PY="$HOME/proj/kicad2stencil/flatcam-beta/flatcam.py" -FLATCAM_ENV="$HOME/proj/kicad2stencil/.flatcam-env" +FLATCAM_PY="$HOME/flatcam-beta/flatcam.py" +FLATCAM_ENV="$HOME/flatcam-beta/.flatcam-env" if [ ! -f "$FLATCAM_PY" ]; then echo "ERROR: flatcam.py not found at $FLATCAM_PY"