diff --git a/pcb-expose.sh b/pcb-expose.sh new file mode 100755 index 0000000..f5bb4da --- /dev/null +++ b/pcb-expose.sh @@ -0,0 +1,133 @@ +#!/usr/bin/env bash +# +# Wrapper for the OFFICIAL UVtoolsCmd release, using the generic `run` command +# with the new FileArray-capable PCBExposure operation. +# +# It maps everything onto: +# +# UVtoolsCmd run PCBExposure \ +# -p FileArray= -p FileArray= ... \ +# -p InvertColor=true -p Mirror=true -p ExposureTime=120 ... \ +# --output +# +# Usage: +# pcb-expose.sh [options] +# +# Example: +# pcb-expose.sh Dummy.pm4n \ +# gerbers/Flow_Controller_Panel-Front.gtl \ +# --invert --mirror --exposure 120 \ +# --output Flow_Controller_Panel-Front.pm4n +# +# Options: +# -e, --exposure Sets ExposureTime +# -i, --invert Sets InvertColor=true +# -m, --mirror Sets Mirror=true +# --merge Sets MergeFiles=true +# --aa Sets EnableAntiAliasing=true +# --offset-x Sets OffsetX +# --offset-y Sets OffsetY +# -o, --output Output file (default: overwrite dummy file) +# +# NOTE: --invert-polarity (per-file InvertPolarity) is NOT supported by this +# wrapper, because the official FileArray property only accepts plain +# file paths, not the InvertPolarity flag per file. If you need that, +# use pcb-expose-patched.sh instead. +# +# Configure the path to your official build below, or override via: +# UVTOOLSCMD=/path/to/UVtoolsCmd pcb-expose.sh ... + +set -euo pipefail + +UVTOOLSCMD="${UVTOOLSCMD:-$HOME/UVtools/UVtoolsCmd}" + +if [ ! -x "$UVTOOLSCMD" ]; then + echo "Error: UVtoolsCmd not found or not executable at: $UVTOOLSCMD" >&2 + echo "Set UVTOOLSCMD=/path/to/UVtoolsCmd or edit this script." >&2 + exit 1 +fi + +if [ $# -lt 2 ]; then + echo "Usage: $0 [options]" >&2 + exit 1 +fi + +DUMMY_FILE="$1" +shift + +GERBERS=() +PROPS=() # FileArray entries + scalar properties, built below +OUTPUT_FILE="" + +EXPOSURE="" +INVERT="false" +MIRROR="false" +MERGE="false" +AA="false" +OFFSET_X="" +OFFSET_Y="" +INVERT_POLARITY="false" + +while [ $# -gt 0 ]; do + case "$1" in + -e|--exposure) + EXPOSURE="$2"; shift 2 ;; + -i|--invert) + INVERT="true"; shift ;; + -m|--mirror) + MIRROR="true"; shift ;; + --merge) + MERGE="true"; shift ;; + --aa) + AA="true"; shift ;; + --offset-x) + OFFSET_X="$2"; shift 2 ;; + --offset-y) + OFFSET_Y="$2"; shift 2 ;; + --invert-polarity) + INVERT_POLARITY="true"; shift ;; + -o|--output) + OUTPUT_FILE="$2"; shift 2 ;; + -*) + echo "Unknown option: $1" >&2 + exit 1 ;; + *) + GERBERS+=("$1"); shift ;; + esac +done + +if [ "$INVERT_POLARITY" = "true" ]; then + echo "Warning: --invert-polarity is not supported via the official FileArray" >&2 + echo " property and will be ignored." >&2 +fi + +if [ ${#GERBERS[@]} -eq 0 ]; then + echo "Error: specify at least one gerber file." >&2 + exit 1 +fi + +for g in "${GERBERS[@]}"; do + if [ ! -f "$g" ]; then + echo "Error: gerber file not found: $g" >&2 + exit 1 + fi +done + +# Build -p FileArray=... entries +for g in "${GERBERS[@]}"; do + PROPS+=(-p "FileArray=$g") +done + +[ -n "$EXPOSURE" ] && PROPS+=(-p "ExposureTime=$EXPOSURE") +[ "$INVERT" = "true" ] && PROPS+=(-p "InvertColor=true") +[ "$MIRROR" = "true" ] && PROPS+=(-p "Mirror=true") +[ "$MERGE" = "true" ] && PROPS+=(-p "MergeFiles=true") +[ "$AA" = "true" ] && PROPS+=(-p "EnableAntiAliasing=true") +[ -n "$OFFSET_X" ] && PROPS+=(-p "OffsetX=$OFFSET_X") +[ -n "$OFFSET_Y" ] && PROPS+=(-p "OffsetY=$OFFSET_Y") + +CMD=("$UVTOOLSCMD" run "$DUMMY_FILE" PCBExposure "${PROPS[@]}") +[ -n "$OUTPUT_FILE" ] && CMD+=(--output "$OUTPUT_FILE") + +echo "+ ${CMD[*]}" >&2 +exec "${CMD[@]}"