Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 47 additions & 13 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
# Light CI - runs on dev branch
# Fast feedback loop with linting and quick tests
# CI - runs on PRs to releases branch
# Full test matrix, linting, and build validation

name: CI

on:
push:
branches: [dev]
pull_request:
branches: [dev]
branches: [releases]

jobs:
lint:
Expand All @@ -30,16 +28,21 @@ jobs:
- name: Lint with flake8
run: flake8 microfinity/ tests/ --max-line-length=120 --extend-ignore=E203,W503,F401,F403,F405,E402,F821,W293,W605,F841

test-quick:
name: Quick Tests
test:
name: Test (Python ${{ matrix.python-version }})
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
python-version: ["3.9", "3.10", "3.11", "3.12"]

steps:
- uses: actions/checkout@v4

- name: Set up Python
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v5
with:
python-version: "3.11"
python-version: ${{ matrix.python-version }}

- name: Install dependencies
run: |
Expand All @@ -48,7 +51,38 @@ jobs:
pip install pytest pytest-cov
pip install -e .

- name: Run quick tests
run: pytest -x -v --ignore=tests/test_rbox.py
env:
SKIP_TEST_RBOX: "1"
- name: Run full test suite
run: pytest -v --cov=microfinity --cov-report=xml

- name: Upload coverage
uses: codecov/codecov-action@v4
if: matrix.python-version == '3.11'
with:
files: ./coverage.xml
fail_ci_if_error: false

build:
name: Build Package
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: "3.11"

- name: Install build tools
run: pip install build twine

- name: Build package
run: python -m build

- name: Check package
run: twine check dist/*

- name: Upload build artifacts
uses: actions/upload-artifact@v4
with:
name: dist
path: dist/
88 changes: 0 additions & 88 deletions .github/workflows/release-ci.yml

This file was deleted.

119 changes: 118 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,11 +70,112 @@ microfinity-rugged 5 4 6 --box --lid -f stl

## Classes

### Geometry Classes

- `GridfinityBox` - Boxes with dividers, scoops, labels, magnet holes
- `GridfinityBaseplate` - Baseplates with optional mounting tabs
- `GridfinitySolidBox` - Solid boxes without interior cutout
- `GridfinityBaseplate` - Baseplates with optional mounting tabs and notches
- `GridfinityBaseplateLayout` - Tiled baseplate layouts with automatic partitioning for large prints
- `GridfinityConnectionClip` - Connection clips for joining baseplate pieces
- `GridfinityDrawerSpacer` - Spacers for fitting baseplates in drawers
- `GridfinityRuggedBox` - Rugged storage boxes with lids and handles

### Utility Classes

- `GridfinityExporter` - Export utility for STEP, STL, SVG formats
- `SVGView` - Enum for SVG view directions

### Enums

- `EdgeMode` - Edge treatment options for baseplate layouts
- `SegmentationMode` - Partitioning strategies for large baseplates
- `ToleranceMode` - Tolerance handling for baseplate fitting

## Export

The `GridfinityExporter` class provides a unified interface for exporting Gridfinity objects to various file formats.

### Basic Usage

```python
from microfinity import GridfinityBox, GridfinityExporter, SVGView

# Create a box
box = GridfinityBox(2, 2, 4, holes=True)

# Export using the exporter
exporter = GridfinityExporter(box)
exporter.save_step_file("box.step")
exporter.save_stl_file("box.stl")
exporter.save_svg_file("box.svg", view=SVGView.ISOMETRIC)
```

### Direct Class Methods (Backward Compatible)

All geometry classes also have export methods directly available:

```python
box = GridfinityBox(2, 2, 4)
box.save_stl_file() # Auto-generates filename based on parameters
box.save_step_file("custom_name.step")
box.save_svg_file("preview.svg")
```

### SVG Views

The `SVGView` enum provides the following view options:

| View | Description |
|------|-------------|
| `SVGView.FRONT` | Front view (+Y direction) |
| `SVGView.BACK` | Back view (-Y direction) |
| `SVGView.LEFT` | Left view (-X direction) |
| `SVGView.RIGHT` | Right view (+X direction) |
| `SVGView.TOP` | Top view (+Z direction) |
| `SVGView.BOTTOM` | Bottom view (-Z direction) |
| `SVGView.ISOMETRIC` | Isometric view (default) |

### Export Options

```python
exporter = GridfinityExporter(obj)

# STL with custom tolerance
exporter.save_stl_file("output.stl", tolerance=0.01, angular_tolerance=0.1)

# SVG with custom styling
exporter.save_svg_file(
"output.svg",
view=SVGView.TOP,
line_width=0.5,
show_hidden=False
)
```

### Baseplate Layout Export

`GridfinityBaseplateLayout` has additional export methods for batch exporting all pieces:

```python
from microfinity import GridfinityBaseplateLayout

layout = GridfinityBaseplateLayout(
length_mm=300,
width_mm=200,
max_piece_u=4
)

# Export all pieces and clips
results = layout.export_all(
output_dir="./output",
formats=["stl", "step"],
prefix="my_baseplate"
)

# Export preview SVGs only
layout.export_preview(output_dir="./previews")
```

## Development

```bash
Expand All @@ -84,6 +185,22 @@ pip install -e ".[dev]"
pytest
```

### Running Tests

```bash
# Run all tests
pytest

# Run with coverage
pytest --cov=microfinity

# Run specific test file
pytest tests/test_box.py

# Update golden test baselines
UPDATE_GOLDEN=1 pytest tests/test_golden.py
```

## References

- [Gridfinity wiki](https://gridfinity.xyz)
Expand Down
4 changes: 2 additions & 2 deletions lefthook.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
pre-commit:
parallel: true
commands:
lint-check:
lint-fix:
glob: "*.py"
run: black --check --diff {staged_files}
run: black {staged_files} && git add {staged_files}

commit-msg:
commands:
Expand Down
37 changes: 36 additions & 1 deletion microfinity/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,42 @@

from .constants import *
from .gf_obj import GridfinityObject
from .gf_baseplate import GridfinityBaseplate
from .gf_baseplate import (
GridfinityBaseplate,
NotchSpec,
get_notch_spec,
make_notch_cutter,
make_notch_cutter_outer_anchored,
get_straight_band_z,
compute_notch_z_band,
get_seam_wall_thickness_mm,
get_seam_cut_depth_mm,
NOTCH_WIDTH_MM,
NOTCH_DEPTH_MM,
NOTCH_HEIGHT_MM,
NOTCH_CHAMFER_MM,
NOTCH_TOP_MARGIN_MM,
NOTCH_BOT_MARGIN_MM,
NOTCH_THROUGH_OVERCUT_MM,
NOTCH_KEEPOUT_TOP_MM, # Deprecated
)
from .gf_box import GridfinityBox, GridfinitySolidBox
from .gf_drawer import GridfinityDrawerSpacer
from .gf_ruggedbox import GridfinityRuggedBox
from .gf_baseplate_layout import (
GridfinityBaseplateLayout,
GridfinityConnectionClip,
LayoutResult,
PieceSpec,
EdgeMode,
SegmentationMode,
ToleranceMode,
)
from .test_prints import (
generate_fractional_pocket_test,
generate_fractional_pocket_test_set,
generate_clip_clearance_sweep,
generate_clip_test_set,
export_test_prints,
)
from .gf_export import GridfinityExporter, SVGView
Loading