mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-08-10 09:48:32 +00:00
ifc2x3 tests
This commit is contained in:
@@ -177,11 +177,31 @@ class Usecase:
|
||||
representations.append(self.create_styled_representation())
|
||||
definition_representation.Representations = representations
|
||||
|
||||
def has_proposed_style(self, styled_item):
|
||||
return any(s == self.settings["style"] for s in styled_item.Styles)
|
||||
def has_proposed_style(self, styled_item: ifcopenshell.entity_instance) -> bool:
|
||||
style = self.settings["style"]
|
||||
styles = styled_item.Styles
|
||||
if style in styles:
|
||||
return True
|
||||
if self.file.schema != "IFC4X3":
|
||||
# IfcPresentationStyleAssignment is removed in IFC4X3
|
||||
for s in styles:
|
||||
if s.is_a("IfcPresentationStyleAssignment"):
|
||||
if style in s.Styles:
|
||||
return True
|
||||
return False
|
||||
|
||||
def has_same_style_type(self, styled_item):
|
||||
return any(s.is_a() == self.settings["style"].is_a() for s in styled_item.Styles)
|
||||
def has_same_style_type(self, styled_item: ifcopenshell.entity_instance) -> bool:
|
||||
style = self.settings["style"]
|
||||
style_class = style.is_a()
|
||||
for s in styled_item.Styles:
|
||||
s_class = s.is_a()
|
||||
if s_class == style_class:
|
||||
return True
|
||||
elif s_class == "IfcPresentationStyleAssignment":
|
||||
for ss in s.Styles:
|
||||
if ss.is_a() == style_class:
|
||||
return True
|
||||
return False
|
||||
|
||||
def create_new_definition_representation(self):
|
||||
representation = self.create_styled_representation()
|
||||
@@ -214,6 +234,14 @@ class Usecase:
|
||||
return self.file.create_entity(
|
||||
"IfcStyledItem", **{"Styles": [self.style], "Name": self.settings["style"].Name}
|
||||
)
|
||||
reuse_item.Styles = (self.style,)
|
||||
|
||||
# IfcPresentationStyleAssignment we created end up not being used
|
||||
# TODO: do not create IfcPresentationStyleAssignment in the first place
|
||||
# as it might get removed
|
||||
if reuse_item.is_a("IfcPresentationStyleAssignment") and self.style.is_a("IfcPresentationStyleAssignment"):
|
||||
self.file.remove(self.style)
|
||||
self.style = reuse_item
|
||||
|
||||
reuse_item.Styles = (self.settings["style"],)
|
||||
reuse_item.Name = self.settings["style"].Name
|
||||
return reuse_item
|
||||
|
||||
@@ -45,22 +45,25 @@ def remove_surface_style(file: ifcopenshell.file, style: ifcopenshell.entity_ins
|
||||
# Remove the shading item
|
||||
ifcopenshell.api.run("style.remove_surface_style", model, style=shading)
|
||||
"""
|
||||
settings = {"style": style}
|
||||
|
||||
to_delete = set()
|
||||
if settings["style"].is_a("IfcSurfaceStyleWithTextures"):
|
||||
for texture in settings["style"].Textures or []:
|
||||
if texture.IsMappedBy:
|
||||
for coordinate in texture.IsMappedBy:
|
||||
to_delete.add(coordinate)
|
||||
else:
|
||||
to_delete.add(texture)
|
||||
if style.is_a("IfcSurfaceStyleWithTextures"):
|
||||
textures = style.Textures
|
||||
if file.schema == "IFC2X3":
|
||||
to_delete.update(textures)
|
||||
else:
|
||||
for texture in textures:
|
||||
if coords := texture.IsMappedBy:
|
||||
for coordinate in coords:
|
||||
to_delete.add(coordinate)
|
||||
else:
|
||||
to_delete.add(texture)
|
||||
|
||||
for attribute in settings["style"]:
|
||||
for attribute in style:
|
||||
if isinstance(attribute, ifcopenshell.entity_instance) and attribute.id():
|
||||
to_delete.add(attribute)
|
||||
|
||||
file.remove(settings["style"])
|
||||
file.remove(style)
|
||||
|
||||
for element in to_delete:
|
||||
ifcopenshell.util.element.remove_deep2(file, element)
|
||||
|
||||
@@ -65,7 +65,14 @@ def unassign_material_style(
|
||||
for item in representation.Items:
|
||||
if not item.is_a("IfcStyledItem"):
|
||||
continue
|
||||
styles = [s for s in item.Styles if s != settings["style"]]
|
||||
styles = []
|
||||
for s in item.Styles:
|
||||
if s == settings["style"]:
|
||||
continue
|
||||
if s.is_a("IfcPresentationStyleAssignment"):
|
||||
if s.Styles == (settings["style"],):
|
||||
continue
|
||||
styles.append(s)
|
||||
if not styles:
|
||||
file.remove(item)
|
||||
elif len(styles) != len(item.Styles):
|
||||
|
||||
Reference in New Issue
Block a user