mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-09-23 14:26:30 +00:00
style.remove_style to handle IfcFillAreaStyleHatching
This commit is contained in:
@@ -50,17 +50,21 @@ class Usecase:
|
|||||||
settings: dict[str, Any]
|
settings: dict[str, Any]
|
||||||
|
|
||||||
def execute(self, style: ifcopenshell.entity_instance) -> None:
|
def execute(self, style: ifcopenshell.entity_instance) -> None:
|
||||||
self.purge_styled_items(style)
|
self.purge_inverses(style)
|
||||||
if style.is_a("IfcSurfaceStyle"):
|
if style.is_a("IfcSurfaceStyle"):
|
||||||
for style_ in style.Styles:
|
for style_ in style.Styles:
|
||||||
ifcopenshell.api.style.remove_surface_style(self.file, style=style_)
|
ifcopenshell.api.style.remove_surface_style(self.file, style=style_)
|
||||||
self.file.remove(style)
|
self.file.remove(style)
|
||||||
|
|
||||||
def purge_styled_items(self, style: ifcopenshell.entity_instance) -> None:
|
def purge_inverses(self, style: ifcopenshell.entity_instance) -> None:
|
||||||
for inverse in self.file.get_inverse(style):
|
for inverse in self.file.get_inverse(style):
|
||||||
if inverse.is_a("IfcStyledItem") and len(inverse.Styles) == 1:
|
if inverse.is_a("IfcStyledItem"):
|
||||||
self.purge_styled_representations(inverse)
|
if len(inverse.Styles) == 1:
|
||||||
self.file.remove(inverse)
|
self.purge_styled_representations(inverse)
|
||||||
|
self.file.remove(inverse)
|
||||||
|
# IfcCurveStyle -> IfcFillAreaStyleHatching.
|
||||||
|
elif inverse.is_a("IfcFillAreaStyleHatching"):
|
||||||
|
self.purge_fill_area_style_hatching(inverse, style)
|
||||||
|
|
||||||
def purge_styled_representations(self, styled_item: ifcopenshell.entity_instance) -> None:
|
def purge_styled_representations(self, styled_item: ifcopenshell.entity_instance) -> None:
|
||||||
for inverse in self.file.get_inverse(styled_item):
|
for inverse in self.file.get_inverse(styled_item):
|
||||||
@@ -72,3 +76,11 @@ class Usecase:
|
|||||||
for inverse in self.file.get_inverse(styled_representation):
|
for inverse in self.file.get_inverse(styled_representation):
|
||||||
if inverse.is_a("IfcMaterialDefinitionRepresentation") and len(inverse.Representations) == 1:
|
if inverse.is_a("IfcMaterialDefinitionRepresentation") and len(inverse.Representations) == 1:
|
||||||
self.file.remove(inverse)
|
self.file.remove(inverse)
|
||||||
|
|
||||||
|
def purge_fill_area_style_hatching(
|
||||||
|
self, fill_area_style_hatching: ifcopenshell.entity_instance, style: ifcopenshell.entity_instance
|
||||||
|
) -> None:
|
||||||
|
for inverse in self.file.get_inverse(fill_area_style_hatching):
|
||||||
|
if inverse.is_a("IfcFillAreaStyle"):
|
||||||
|
self.execute(inverse)
|
||||||
|
ifcopenshell.util.element.remove_deep2(self.file, fill_area_style_hatching, do_not_delete=[style])
|
||||||
|
|||||||
@@ -18,6 +18,7 @@
|
|||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
import test.bootstrap
|
import test.bootstrap
|
||||||
|
import ifcopenshell.api.material
|
||||||
import ifcopenshell.api.style
|
import ifcopenshell.api.style
|
||||||
|
|
||||||
|
|
||||||
@@ -46,6 +47,28 @@ class TestRemoveStyle(test.bootstrap.IFC4):
|
|||||||
ifcopenshell.api.style.remove_style(self.file, style=style)
|
ifcopenshell.api.style.remove_style(self.file, style=style)
|
||||||
assert len(self.file.by_type("IfcPresentationStyle")) == 0
|
assert len(self.file.by_type("IfcPresentationStyle")) == 0
|
||||||
|
|
||||||
|
def test_remove_curve_style_with_curve_style_hatching(self):
|
||||||
|
element = self.file.create_entity("IfcWall")
|
||||||
|
material = ifcopenshell.api.material.add_material(self.file)
|
||||||
|
ifcopenshell.api.material.assign_material(self.file, products=[element], material=material)
|
||||||
|
curve_style = self.file.create_entity("IfcCurveStyle")
|
||||||
|
fill_style = self.file.create_entity("IfcFillAreaStyleHatching", HatchLineAppearance=curve_style)
|
||||||
|
style = self.file.create_entity("IfcFillAreaStyle", FillStyles=[fill_style])
|
||||||
|
self.file.create_entity(
|
||||||
|
"IfcMaterialDefinitionRepresentation",
|
||||||
|
RepresentedMaterial=material,
|
||||||
|
Representations=[
|
||||||
|
self.file.create_entity(
|
||||||
|
"IfcStyledRepresentation",
|
||||||
|
Items=[self.file.create_entity("IfcStyledItem", Styles=[style])],
|
||||||
|
)
|
||||||
|
],
|
||||||
|
)
|
||||||
|
ifcopenshell.api.style.remove_style(self.file, curve_style)
|
||||||
|
assert len(self.file.by_type("IfcPresentationStyle")) == 0
|
||||||
|
assert len(self.file.by_type("IfcMaterialDefinitionRepresentation")) == 0
|
||||||
|
assert len(self.file.by_type("IfcStyledRepresentation")) == 0
|
||||||
|
|
||||||
|
|
||||||
class TestRemoveStyleIFC2X3(test.bootstrap.IFC2X3, TestRemoveStyle):
|
class TestRemoveStyleIFC2X3(test.bootstrap.IFC2X3, TestRemoveStyle):
|
||||||
pass
|
pass
|
||||||
|
|||||||
Reference in New Issue
Block a user