FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Fix EPset_Drawing.BringToFront not applying to merged cut geometry by theoryshaw · Pull Request #9318 · IfcOpenShell/IfcOpenShell · GitHub

Fix EPset_Drawing.BringToFront not applying to merged cut geometry - #9318

Open
theoryshaw wants to merge 1 commit into
IfcOpenShell:v0.8.0from
theoryshaw:fix_bringtofront_svg_namespace_9317
Open

Fix EPset_Drawing.BringToFront not applying to merged cut geometry#9318
theoryshaw wants to merge 1 commit into
IfcOpenShell:v0.8.0from
theoryshaw:fix_bringtofront_svg_namespace_9317

Conversation

Copy link
Copy Markdown
Member

Fixes #9317

EPset_Drawing.BringToFront only reordered some of an element's SVG groups. The ones it missed were the merged cut and material-layer groups — i.e. exactly the groups holding the filled, closed polygons that do the occluding — so a listed element failed to hide anything behind it.

merge_linework_and_add_metadata created those groups with etree.Element("g"), which puts them outside the SVG namespace. move_elements_to_top looks for them with .//svg:g[contains(@class, '...')], which cannot match an unnamespaced element.

The reason this went unnoticed is that it is invisible in the written file. lxml serialises an unnamespaced <g> inside an SVG-default-namespace parent as plain <g class="..."> — no xmlns="" — so on re-parse the element is SVG-namespaced. The mismatch exists only in memory, during the one session where it matters:

>>> from lxml import etree
>>> root = etree.fromstring(b'<svg xmlns="http://www.w3.org/2000/svg"><g class="outer"/></svg>')
>>> group = root.find('{http://www.w3.org/2000/svg}g')
>>> g = etree.Element('g'); g.set('class', 'merged IfcSlab')
>>> group.append(g)
>>> etree.tostring(root)
b'<svg xmlns="http://www.w3.org/2000/svg"><g class="outer"><g class="merged IfcSlab"/></g></svg>'
>>> len(root.xpath('.//svg:g[contains(@class,"IfcSlab")]', namespaces={'svg': 'http://www.w3.org/2000/svg'}))
0

Creating the group and path in the SVG namespace leaves the serialised output byte-identical and makes them visible to the later XPath queries.

Before / after

Test case: a section with EPset_Drawing.BringToFront = "IfcSlab", where the slab passes through a wall.

Group order before — only the serializer's projection group (correctly namespaced) reaches the end; the two merged IfcSlab cut groups stay underneath the wall:

IfcWall material-null projection
0faNkgG_1DN9MDzCSffnKC IfcSlab cut material-null              <- should be on top
cut IfcWall material-null 1skYUSkBX1HwA9bn4RdVwu
IfcSlab layer-material-Unknown cut IfcMaterialLayer ...       <- should be on top
IfcWall cut layer-material-Framing ... IfcMaterialLayer ...   <- paints over the slab
IfcWall cut ... IfcMaterialLayer layer-material-Glazing ...   <- paints over the slab
IfcSlab material-null projection                              <- the only group that moved

After, all IfcSlab groups are moved to the end and the slab correctly occludes the wall. (The remaining sliver of wall on the far side is correct — the slab genuinely does not extend that far.)

Not addressed here

There are two more unnamespaced etree.Element("path") calls in the same file (the SHAPELY surface fills and the IfcSpace pass). Nothing queries them in-memory afterwards, so they are latent rather than broken; left alone to keep this change minimal.

🤖 Generated with Claude Code

merge_linework_and_add_metadata created its merged groups with
etree.Element("g"), which puts them outside the SVG namespace.
move_elements_to_top then looks for them with ".//svg:g[...]", so
EPset_Drawing.BringToFront never matched the merged cut and material
layer groups - i.e. exactly the groups holding the filled, closed
polygons that do the occluding. Listed elements failed to hide what was
behind them.

This is invisible in the written file: lxml serialises an unnamespaced
<g> inside an SVG-default-namespace parent as plain <g class="...">
without xmlns="", so on re-parse it is SVG-namespaced. The mismatch only
exists in memory, during the session where it matters.

Creating the group and path in the SVG namespace leaves the serialised
output byte-identical and makes them visible to the later XPath queries.

Fixes IfcOpenShell#9317

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
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.

1 participant


Back | FazBrowse Home | New Git URL