47 lines
2.6 KiB
Markdown
47 lines
2.6 KiB
Markdown
# PrusaSlicer Profiles Module
|
|
|
|
This module handles the parsing, management, and evaluation of PrusaSlicer configuration profiles (`.ini` files). It supports profile inheritance, compatibility evaluation using PrusaSlicer's expression language, and generating merged configurations for slicing.
|
|
|
|
## Project Structure
|
|
|
|
- **`__init__.py`**: Exports the primary API (`LocalCache`, `Profile`, `ConfigWriter`).
|
|
- **`cache.py`**: Contains the `LocalCache` class for managing profile loading and metadata.
|
|
- **`models.py`**: Defines core data models like `Profile` (as a dataclass) and `ConfigWriter`.
|
|
- **`parser.py`**: Implements a recursive descent parser for PrusaSlicer's expression language.
|
|
- **`fields.py`**: Robustly loads and searches PrusaSlicer setting metadata (JSON/CSV).
|
|
- **`utils.py`**: Contains canonical implementations of INI parsing and configuration merging (`generate_conf`).
|
|
|
|
## Core Components
|
|
|
|
### 1. `LocalCache` (`cache.py`)
|
|
- Manages a collection of profiles loaded from disk.
|
|
- Scans directories for `.ini` files and tracks changes using file metadata.
|
|
- Categorizes profiles into `printer`, `print`, and `filament`.
|
|
- `evaluate_compatibility`: Checks which filament and print profiles are compatible with specific printer profiles.
|
|
- `generate_conf_writer`: Creates a `ConfigWriter` by merging a printer, print, and one or more filament profiles.
|
|
|
|
### 2. `Profile` (`models.py`)
|
|
- Represents a single PrusaSlicer profile (Printer, Filament, or Print).
|
|
- Stores configuration as a dictionary (`conf_dict`).
|
|
- Handles inheritance logic via `generate_inherited_confs`.
|
|
- Supports compatibility checks via `evaluate_compatibility`.
|
|
|
|
### 3. `ConfigWriter` (`models.py`)
|
|
- Helper to write merged configurations to a file (e.g., for passing to a slicer or embedding in a 3MF).
|
|
- Includes checksum generation for configuration integrity.
|
|
|
|
### 4. `Parser` (`parser.py`)
|
|
- Tokenizes and parses expression strings into an AST that can be evaluated against a configuration dictionary.
|
|
- Supports variables, indexing, logical operators, and regex matching.
|
|
|
|
### 5. `fields.py`
|
|
- Loads metadata about PrusaSlicer configuration fields from `prusaslicer_fields.json` and `prusaslicer_modifier_fields.csv`.
|
|
- Uses robust path resolution relative to the module's directory.
|
|
|
|
## Typical Workflow
|
|
1. Initialize `LocalCache`.
|
|
2. Call `cache.load([paths_to_profiles])`.
|
|
3. Select a printer, print, and filament profile(s).
|
|
4. (Optional) Evaluate compatibility using `cache.evaluate_compatibility`.
|
|
5. Generate a merged config using `cache.generate_conf_writer`.
|
|
6. Use `ConfigWriter` to output the final configuration for slicing.
|