Skip to content

Bonsai: per element drawing appearance via assignable CSS classes - #8800

Open
BIMvoice wants to merge 1 commit into
v0.8.0from
bonsai-6425-element-drawing-classes
Open

BIMvoice wants to merge 1 commit into
v0.8.0from
bonsai-6425-element-drawing-classes

Conversation

@BIMvoice

Copy link
Copy Markdown
Contributor

Fixes #6425 (D&D Phase 1 Item 04, funded via the OSArch campaign linked by @theoryshaw).

@jes-r asked for a way to make one slab draw with dashed contours while another draws as a filled grey area, reusing the predefined line types rather than a new styling mechanism.

Drawings are already styled with CSS, and CreateDrawing.get_svg_classes already emits a class list per element. What was missing is a per-element channel: EPset_Annotation.Classes existed but was read only for annotations, had no UI, and default.css scoped its line types to .PredefinedType-LINEWORK so they never reached building elements.

This makes get_svg_classes read the same property, so custom classes reach cut, projection, surface and space geometry, and adds a Drawing Classes panel on the object tab to assign and unassign them across the selection. default.css gains matching element-level rules for line weight, line style and fill (declared last so they override class/material/predefined-type rules, while the existing .PredefinedType-LINEWORK.* rules keep winning for linework by specificity). SvgWriter now shares the tool helper instead of duplicating the lookup.

This deliberately reuses the CSS pipeline rather than adding a second one. The classes land in the same class attribute and are resolved by the same stylesheet, so existing custom stylesheets keep working and can select on the new classes. The presets in the menu are a convenience only, any class name may be typed.

One point worth a maintainer opinion: the property reused is EPset_Annotation.Classes, which now appears on regular products. Introducing a separate product-level property felt like a parallel mechanism for the same concept, but happy to rename if preferred.

Test plan

Verified in headless Blender by generating a real drawing with two slabs, one assigned dashed and one fill-grey. The output PLAN_VIEW.svg contains class="IfcSlab material-null dashed projection" and class="IfcSlab material-null fill-grey projection" (plus the cut group), with the embedded stylesheet carrying .dashed { stroke-dasharray: 3, 2; } and .fill-grey { fill: #aaaaaa; } — jes-r's own example working end to end.

Also verified: class sanitisation, storage in the pset, persistence through save and reopen, per-element separation in get_svg_classes, every UI preset having a matching default.css rule, removal, and panel/menu registration. test/core/test_drawing.py 43 passed; new TestElementClasses cases pass; black+ruff clean.

Siblings #6423 (extra parametric lines) and #6424 (elements hidden behind others) are not addressed here. Per-drawing overrides (element X dashed only in drawing Y) are also out of scope — today's model is per-element and global, and whether the funders expect per-drawing scoping is worth a maintainer's call.

This PR contains AI-generated code, generated with the assistance of an AI coding tool.

Drawings are styled with CSS. Every element already gets a generated class
list (IFC class, material, predefined type, drawing metadata keys), and
annotations could additionally carry hand written classes in
EPset_Annotation.Classes, read by SvgWriter. Regular building elements had no
such channel, so there was no way to make one slab dash and another fill grey
without hand editing the property set and the stylesheet.

CreateDrawing.get_svg_classes now reads the same EPset_Annotation.Classes
property, so custom classes reach cut, projection, surface and space geometry
too. SvgWriter reuses the shared tool.Drawing helper instead of its own lookup.

A Drawing Classes panel on the object tab assigns and unassigns those classes
across the selection, offering the line weight, line style and fill classes
that default.css ships, plus free text for stylesheet authors. default.css
gains matching element level rules, declared last so they override the class,
material and predefined type rules above them.

No new rendering path is introduced. The classes land in the same class
attribute and are resolved by the same stylesheet, so existing custom CSS keeps
working and can select on the new classes.

Generated with the assistance of an AI coding tool.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

D&D Phase 1 Item 04 - Element visibility options

1 participant