GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Fix for leaf entity rule · opensourceBIM/python-mvdxml@e940b2e

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • model.py
  • tests
    • test_graphviz.py
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎model.py‎

Copy file name to clipboardExpand all lines: model.py
+9-3Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,12 @@ def extract(self, ifc_data: ifcopenshell.entity_instance | Any) -> extracted_dat
7777
except (AttributeError, TypeError):
7878
return [{self: "Invalid Attribute"}]
7979
return [{self: value}]
80+
if (
81+
self.tag == "EntityRule"
82+
and isinstance(ifc_data, ifcopenshell.entity_instance)
83+
and not ifc_data.is_a(self.attribute)
84+
):
85+
return []
8086
return [{self: ifc_data}]
8187

8288
if self.tag == "AttributeRule":
@@ -192,10 +198,10 @@ def extract(self, ifc_data: ifcopenshell.entity_instance | Any) -> extracted_dat
192198
def binding_for(self, target: rule) -> str | None:
193199
binding: str | None = None
194200

195-
def find(current: rule, parent: rule | None) -> None:
201+
def find(rule: rule, parent: rule | None) -> None:
196202
nonlocal binding
197-
if current is target:
198-
binding = current.bind or (parent.bind if parent else None)
203+
if rule is target:
204+
binding = rule.bind or (parent.bind if parent else None)
199205

200206
self.traverse(find)
201207
return binding
Collapse file

‎tests/test_graphviz.py‎

Copy file name to clipboardExpand all lines: tests/test_graphviz.py
+43-3Lines changed: 43 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import pytest
44

5+
import ifcopenshell
56
from ifcopenshell.mvd import rule, template
67

78

@@ -117,7 +118,46 @@ def test_from_graphviz_reports_unknown_reference() -> None:
117118
```
118119
"""
119120

120-
with pytest.raises(
121-
ValueError, match="Unknown Graphviz template reference: Surface_Color_Style"
122-
):
121+
with pytest.raises(ValueError, match="Unknown Graphviz template reference: Surface_Color_Style"):
123122
template.from_graphviz(source)
123+
124+
125+
def test_from_graphviz_entity_leaf_filters_ifc_type() -> None:
126+
source = """\
127+
```
128+
concept {
129+
IfcRelDefinesByProperties:RelatingPropertyDefinition -> IfcPropertySetDefinitionSet
130+
}
131+
```
132+
"""
133+
parsed = template.from_graphviz(source)
134+
135+
class entity(ifcopenshell.entity_instance):
136+
def __init__(self, ifc_class: str):
137+
self.ifc_class = ifc_class
138+
139+
def is_a(self, ifc_class: str) -> bool:
140+
return self.ifc_class == ifc_class
141+
142+
class relationship:
143+
def __init__(self, relating_property_definition: entity):
144+
self.RelatingPropertyDefinition = relating_property_definition
145+
146+
assert parsed.extract(relationship(entity("IfcPropertySetDefinitionSet")))
147+
assert not parsed.extract(relationship(entity("IfcPropertySet")))
148+
149+
150+
def test_from_graphviz_leaf_uses_parent_attribute_binding() -> None:
151+
source = """\
152+
```
153+
concept {
154+
IfcPointByDistanceExpression:BasisCurve -> IfcCurve
155+
IfcPointByDistanceExpression:BasisCurve[binding="BasisCurve"]
156+
}
157+
```
158+
"""
159+
160+
parsed = template.from_graphviz(source)
161+
leaf = parsed.rules[0].nodes[0]
162+
163+
assert parsed.binding_for(leaf) == "BasisCurve"

0 commit comments

Comments
0 (0)
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.