Skip to content
Open
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
16 changes: 16 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,22 @@ All notable changes to Rayforge will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## Unreleased

### Added

- Calibration tests: the Test Settings now live in the settings dialog
of the test's layer, together with the other layer settings. The item
properties panel shows a card with an Open Layer Settings button that
opens that dialog for the selected test

### Changed

- Calibration tests: a test now owns its layer. Paste, import and
drag-and-drop of other workpieces into a test's layer are refused;
moving a cell out of the test or deleting one stays possible.
Projects from older versions open unchanged

## 1.14.0

### Added
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@
from .material_test_grid import MaterialTestGridGenerator
from .record import CalibrationRecord, CalibrationState

#: The layer type of the layer a test is generated on. Tests own their
#: layer, so other workpieces cannot be placed in it.
LAYER_TYPE_ID = "calibration_test"

GENERATORS: dict[str, CalibrationGenerator] = {
generator.id: generator
for generator in (
Expand All @@ -33,6 +37,7 @@

__all__ = [
"GENERATORS",
"LAYER_TYPE_ID",
"CalibrationGenerator",
"CalibrationLayout",
"CalibrationRecord",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"""Finds the calibration test that selected workpieces belong to."""

from collections.abc import Iterable
from collections.abc import Iterable, Sequence
from typing import TYPE_CHECKING, cast

from rayforge.core.item import DocItem
Expand All @@ -17,9 +17,12 @@
if TYPE_CHECKING:
from rayforge.core.asset import IAsset
from rayforge.core.doc import Doc
from rayforge.core.layer import Layer


def record_for_items(items: list[DocItem]) -> CalibrationRecord | None:
def record_for_items(
items: Sequence[DocItem],
) -> CalibrationRecord | None:
"""
The record of the test all *items* belong to, or None.

Expand Down Expand Up @@ -55,6 +58,27 @@ def find_record(doc: "Doc", workpiece_uid: str) -> CalibrationRecord | None:
return None


def record_for_layer(doc: "Doc", layer: "Layer") -> CalibrationRecord | None:
"""
The record of the test that lives on *layer*, or None.

Records are matched by their layer uid. A Material Test Grid made
by an older version has no record; for it a record is made from its
step, without adding it to the document.
"""
for asset in doc.get_all_assets():
if asset.asset_type_name != CalibrationRecord.asset_type_name:
continue
record = cast(CalibrationRecord, asset)
if record.layer_uid == layer.uid:
return record
for wp in layer.workpieces:
record = find_record(doc, wp.uid) or _legacy_record(wp)
if record is not None:
return record
return None


def _legacy_record(wp: DocItem) -> CalibrationRecord | None:
assert isinstance(wp, WorkPiece)
layer = wp.layer
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
from rayforge.core.workpiece import WorkPiece
from rayforge.doceditor.layer_cmd import AddLayerAndSetActiveCommand

from ..calibration import GENERATORS, CalibrationGenerator
from ..calibration import GENERATORS, LAYER_TYPE_ID, CalibrationGenerator
from ..calibration.builder import BuiltTest, CalibrationBuilder, bounds_of
from ..calibration.lookup import record_for_items, unused_assets
from ..calibration.record import CalibrationRecord, CalibrationState
Expand Down Expand Up @@ -97,6 +97,7 @@ def _new_layer(self, title: str) -> Layer:
name = f"{title} {number}"
number += 1
layer = Layer(name)
layer.layer_type = LAYER_TYPE_ID
material = get_context().material_mgr.get_default_material()
layer.set_stock_material_uid(material.uid)
layer.set_color(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,17 @@
from gi.repository import Gio

from rayforge.core.hooks import hookimpl
from rayforge.core.layer_types import LayerType, layer_type_registry
from rayforge.ui_gtk.action_registry import MenuPlacement
from rayforge.ui_gtk.doceditor.layer_settings_sections import (
layer_settings_section_registry,
)
from rayforge.ui_gtk.icons import register_icon_path

from .calibration import LAYER_TYPE_ID
from .commands import CalibrationCmd, CalibrationSync
from .widgets import ASSEMBLER_WIDGETS
from .widgets.calibration_layer_section import CalibrationLayerSettingsSection
from .widgets.calibration_provider import (
register_test_settings,
show_new_test,
Expand All @@ -37,8 +43,20 @@ def register_step_settings_pages(step_settings_page_registry):

@hookimpl
def rayforge_init(context):
"""Register the Test Settings with the item properties panel."""
"""Register the Test Settings and the test layer type."""
register_test_settings(ADDON_NAME)
layer_settings_section_registry.register(
CalibrationLayerSettingsSection, ADDON_NAME
)
layer_type_registry.register(
LayerType(
id=LAYER_TYPE_ID,
title=_("Calibration Test"),
icon_name="test-symbolic",
locked=True,
),
ADDON_NAME,
)


@hookimpl
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
"""
The Test Settings section of the layer settings dialog.

It shows the settings of the calibration test that lives on the layer,
so the settings are found in the layer settings like every other layer
setting.
"""

import logging
from typing import TYPE_CHECKING

from gi.repository import Adw

from rayforge.core.layer import Layer
from rayforge.ui_gtk.doceditor.layer_settings_sections import (
LayerSettingsSection,
)

from ..calibration.lookup import record_for_layer
from ..calibration.record import CalibrationRecord
from .calibration_settings import CalibrationSettingsController

if TYPE_CHECKING:
from rayforge.doceditor.editor import DocEditor

logger = logging.getLogger(__name__)


class CalibrationLayerSettingsSection(LayerSettingsSection):
"""Shows the settings of the test that lives on the layer."""

def __init__(self):
self._controller: CalibrationSettingsController | None = None

def can_handle(self, layer: Layer, editor: "DocEditor") -> bool:
return self._record_for(layer, editor) is not None

def create_widgets(
self, layer: Layer, editor: "DocEditor"
) -> list[Adw.PreferencesGroup]:
record = self._record_for(layer, editor)
assert record is not None
self._controller = CalibrationSettingsController(editor, record)
return self._controller.widgets()

def close(self):
if self._controller is not None:
self._controller.close()
self._controller = None

@staticmethod
def _record_for(
layer: Layer, editor: "DocEditor"
) -> CalibrationRecord | None:
return record_for_layer(editor.doc, layer)
Loading
Loading