Bonsai: derive prefs PropertyGroups from EDIT_TYPES

Collapse two parallel hand-maintained lists in the addon-preferences
PropertyGroups into derivations from `tool.Parametric.EDIT_TYPES`:

- GizmoPreferences: the 10 `<name>: BoolProperty` annotations now
  generated from the full EDIT_TYPES list.

- DefaultParameters: add `has_default_parameters` flag to
  ParametricObject (set True on door/window/stair/railing/roof);
  derive the 5 `<name>: PointerProperty(type=BIM<X>Properties)`
  annotations and collapse the 5 hand-written `draw_expandable_panel`
  blocks in `draw_default_parameters` into loops driven by the flag.

Existing `test_gizmo_preferences_field_per_registry_entry` pinned the
GizmoPreferences contract; new
`test_default_parameters_field_per_registry_entry_with_defaults`
pins the DefaultParameters contract (one-directional: flag=True
implies field present, flag=False allows absence).

Generated with the assistance of an AI coding tool.
This commit is contained in:
Gorgious56
2026-06-29 16:14:26 +02:00
parent 8bd22178f7
commit a757641b84
3 changed files with 88 additions and 74 deletions
@@ -123,6 +123,31 @@ def test_every_predicate_does_not_raise_on_non_matching_element(registry):
)
def test_default_parameters_field_per_registry_entry_with_defaults(registry):
"""Every entry flagged ``has_default_parameters=True`` must have a matching
``<name>: PointerProperty`` field on ``ui.DefaultParameters`` pointing at
its ``BIM<Name>Properties`` class.
The addon-preferences ``Default Parameters`` panel iterates flagged entries
to render per-type defaults sections, and the matching create operator
(``bim.add_door``, ``bim.add_window``, …) reads the field to seed new
instances from the user's preset values. A missing field means the preset
silently never reaches the operator.
Entries WITHOUT the flag are not required to appear — the contract is
one-directional: ``has_default_parameters=True`` implies a field, but
``False`` allows absence."""
from bonsai.bim import ui
annotations = getattr(ui.DefaultParameters, "__annotations__", {})
missing = [e.name for e in registry if e.has_default_parameters and e.name not in annotations]
assert not missing, (
f"ui.DefaultParameters missing PointerProperty field(s) for: {missing}"
f"each EDIT_TYPES entry with has_default_parameters=True must have a matching "
f"<name>: PointerProperty(type=BIM<Name>Properties) field"
)
def test_gizmo_preferences_field_per_registry_entry(registry):
"""Every registry entry must have a matching ``<name>: BoolProperty`` field
on ``ui.GizmoPreferences`` so the addon-preferences UI auto-renders a