Metadata-Version: 2.4
Name: microfinity
Version: 0.2.0
Summary: A python library to make Gridfinity compatible objects with CadQuery.
Author-email: Michael Gale <michael@fxbricks.com>
License: MIT
Project-URL: Homepage, https://github.com/nullstack65/microfinity
Project-URL: Repository, https://github.com/nullstack65/microfinity
Classifier: Development Status :: 4 - Beta
Classifier: Natural Language :: English
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python :: 3.9
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Intended Audience :: Developers
Classifier: License :: OSI Approved :: MIT License
Requires-Python: >=3.9
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: cadquery
Requires-Dist: cqkit>=0.5.6
Provides-Extra: dev
Requires-Dist: pytest; extra == "dev"
Requires-Dist: pytest-cov; extra == "dev"
Requires-Dist: black; extra == "dev"
Requires-Dist: flake8; extra == "dev"
Requires-Dist: commitizen; extra == "dev"
Dynamic: license-file

# microfinity

[![PyPI](https://img.shields.io/pypi/v/microfinity.svg)](https://pypi.org/project/microfinity/)
![python version](https://img.shields.io/static/v1?label=python&message=3.9%2B&color=blue&style=flat&logo=python)
[![CadQuery](https://img.shields.io/static/v1?label=dependencies&message=CadQuery%202.0%2B&color=blue&style=flat)](https://github.com/CadQuery/cadquery)
[![cq-kit](https://img.shields.io/badge/CQ--kit-blue)](https://github.com/michaelgale/cq-kit)
![license](https://img.shields.io/badge/license-MIT-blue.svg)
[![code style: black](https://img.shields.io/badge/code%20style-black-black.svg)](http://github.com/psf/black)

A Python library to make [Gridfinity](https://gridfinity.xyz) compatible objects with [CadQuery](https://github.com/CadQuery/cadquery).

The Gridfinity system was created by [Zach Freedman](https://www.youtube.com/c/ZackFreedman) as a versatile system of modular organization and storage modules. This library provides Python classes to create parameterized Gridfinity components including boxes, baseplates, drawer spacers, and rugged storage boxes.

> **Note:** This is a fork of [cq-gridfinity](https://github.com/michaelgale/cq-gridfinity) by Michael Gale.

## Installation

```bash
pip install microfinity
```

Or install from source:

```bash
git clone https://github.com/nullstack65/microfinity.git
cd microfinity
pip install -e .
```

### Dependencies

- [CadQuery](https://github.com/CadQuery/cadquery)
- [cq-kit](https://github.com/michaelgale/cq-kit)

## Quick Start

```python
import microfinity
print(microfinity.__version__)
```

```python
from microfinity import *

# Make a simple box
box = GridfinityBox(3, 2, 5, holes=True, scoops=True, labels=True)
box.save_stl_file()
# Output: gf_box_3x2x5_holes_scoops_labels.stl
```

## CLI Commands

### `microfinity-box`

```bash
microfinity-box 2 3 5 -m -f stl
```

### `microfinity-base`

```bash
microfinity-base 7 4 -s -f stl
```

### `microfinity-rugged`

```bash
microfinity-rugged 5 4 6 --box --lid -f stl
```

## Classes

### Geometry Classes

- `GridfinityBox` - Boxes with dividers, scoops, labels, magnet holes
- `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
python -m venv .venv
source .venv/bin/activate
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)
- [Original cq-gridfinity](https://github.com/michaelgale/cq-gridfinity) by Michael Gale

## License

MIT License. Originally created by [Michael Gale](https://github.com/michaelgale).
