Skip to content

feat: add directory opening support (gerbv .)#309

Merged
spe-ciellt merged 3 commits intogerbv:developfrom
SourceParts:feat/open-directory
Mar 5, 2026
Merged

feat: add directory opening support (gerbv .)#309
spe-ciellt merged 3 commits intogerbv:developfrom
SourceParts:feat/open-directory

Conversation

@rampageservices
Copy link
Copy Markdown
Contributor

Summary

Like code . opens VS Code with the current directory, gerbv . should open all recognized gerber/drill/PnP files from a directory. Currently gerbv treats . as a filename, which fails.

Changes

  • src/gerbv.c — Add gerbv_is_loadable_file() content probe that runs the same four detection functions used by gerbv_open_image (RS-274X, Excellon, PnP, RS-274D)
  • src/gerbv.h — Declare gerbv_is_loadable_file()
  • src/main.c — Add scan_directory() helper and modify the CLI file-loading loop to handle directory arguments

How it works

When a CLI argument is a directory, scan_directory() iterates its entries, probes each regular file with gerbv_is_loadable_file(), and collects matches into a sorted list. The probe reuses the exact same detection functions as gerbv_open_image — no extension guessing. This handles extensionless files and dot-prefixed files like .GBL, .GTL (Altium output) since detection is purely content-based.

Usage

Command Result
gerbv . Load all recognized files from CWD
gerbv ./gerbers/ Load all recognized files from gerbers/
gerbv file.gbr Unchanged — single file
gerbv ./gerbers/ extra.gbr Mix directories and files freely
gerbv empty-dir/ Prints "No loadable files found" to stderr

Export mode

Directory arguments work with --export too. All files from the directory are loaded as layers and composited into a single output image, exactly as if each file had been listed individually:

# These are equivalent:
gerbv --export=png -o board.png ./gerbers/
gerbv --export=png -o board.png gerbers/copper.gbr gerbers/mask.gbr gerbers/drill.drl

The output is one image with all layers stacked and color-coded — the same view you'd see in the GUI.

Design decisions

  • Content-based, not extension-based — gerber files have inconsistent naming across EDA tools (Altium, KiCad, Eagle all differ). Probing file contents is the only reliable detection method.
  • Not recursive — only scans the specified directory, not subdirectories. This matches the code . convention and avoids surprises with nested output directories.
  • No hidden-file filter — some gerber files are dot-prefixed with no basename (e.g. .GBL). Since every file is content-probed, non-gerber files are silently skipped regardless of name.
  • Alphabetical ordering — files are sorted case-insensitively for predictable layer ordering.

Closes #308

Test plan

  • cmake --build build — clean build, zero warnings
  • ctest — 94/104 pass (unchanged from baseline)
  • gerbv test/inputs/ — loads all test gerber/drill files
  • gerbv . from empty dir — prints "No loadable files found"
  • gerbv file.gbr — single file unchanged
  • gerbv --export=png -o out.png test/inputs/ — directory works with export

Allow passing a directory path as a CLI argument to load all
recognized gerber, drill, and pick-and-place files from it.
Detection is content-based using the existing probe functions,
so extensionless and dot-prefixed files (e.g. Altium output)
are handled correctly.
@spe-ciellt spe-ciellt merged commit a6c7226 into gerbv:develop Mar 5, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feat: open directory of gerber files (gerbv .)

2 participants