mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-08-10 17:58:20 +00:00
ifc2x3 tests
This commit is contained in:
@@ -24,63 +24,77 @@ import ifcopenshell.api
|
||||
class TestAddSurfaceStyle(test.bootstrap.IFC4):
|
||||
def test_adding_a_surface_style(self):
|
||||
style = self.file.createIfcSurfaceStyle()
|
||||
attrs = {"SurfaceColour": {"Name": "", "Red": 1, "Green": 1, "Blue": 1}}
|
||||
if self.file.schema != "IFC2X3":
|
||||
attrs["Transparency"] = 0.5
|
||||
result = ifcopenshell.api.run(
|
||||
"style.add_surface_style",
|
||||
self.file,
|
||||
style=style,
|
||||
ifc_class="IfcSurfaceStyleShading",
|
||||
attributes={"SurfaceColour": {"Name": "", "Red": 1, "Green": 1, "Blue": 1}, "Transparency": 0.5},
|
||||
attributes=attrs,
|
||||
)
|
||||
assert result.is_a("IfcSurfaceStyleShading")
|
||||
assert result.SurfaceColour.Red == 1
|
||||
assert result.SurfaceColour.Green == 1
|
||||
assert result.SurfaceColour.Blue == 1
|
||||
assert result.Transparency == 0.5
|
||||
if self.file.schema != "IFC2X3":
|
||||
assert result.Transparency == 0.5
|
||||
assert style.Styles[0] == result
|
||||
|
||||
def test_adding_a_rendering_style(self):
|
||||
style = self.file.createIfcSurfaceStyle()
|
||||
attrs = {"SurfaceColour": {"Name": "", "Red": 1, "Green": 1, "Blue": 1}}
|
||||
if self.file.schema != "IFC2X3":
|
||||
attrs["Transparency"] = 0.5
|
||||
result = ifcopenshell.api.run(
|
||||
"style.add_surface_style",
|
||||
self.file,
|
||||
style=style,
|
||||
ifc_class="IfcSurfaceStyleRendering",
|
||||
attributes={"SurfaceColour": {"Name": "", "Red": 1, "Green": 1, "Blue": 1}, "Transparency": 0.5},
|
||||
attributes=attrs,
|
||||
)
|
||||
assert result.is_a("IfcSurfaceStyleRendering")
|
||||
assert result.SurfaceColour.Red == 1
|
||||
assert result.SurfaceColour.Green == 1
|
||||
assert result.SurfaceColour.Blue == 1
|
||||
assert result.Transparency == 0.5
|
||||
if self.file.schema != "IFC2X3":
|
||||
assert result.Transparency == 0.5
|
||||
assert style.Styles[0] == result
|
||||
|
||||
def test_not_adding_a_style_twice(self):
|
||||
style = self.file.createIfcSurfaceStyle()
|
||||
attrs = {"SurfaceColour": {"Name": "", "Red": 1, "Green": 1, "Blue": 1}}
|
||||
if self.file.schema != "IFC2X3":
|
||||
attrs["Transparency"] = 0.5
|
||||
ifcopenshell.api.run(
|
||||
"style.add_surface_style",
|
||||
self.file,
|
||||
style=style,
|
||||
ifc_class="IfcSurfaceStyleRendering",
|
||||
attributes={"SurfaceColour": {"Name": "", "Red": 1, "Green": 1, "Blue": 1}, "Transparency": 0.5},
|
||||
attributes=attrs,
|
||||
)
|
||||
result = ifcopenshell.api.run(
|
||||
"style.add_surface_style",
|
||||
self.file,
|
||||
style=style,
|
||||
ifc_class="IfcSurfaceStyleRendering",
|
||||
attributes={"SurfaceColour": {"Name": "", "Red": 1, "Green": 1, "Blue": 1}, "Transparency": 0.5},
|
||||
attributes=attrs,
|
||||
)
|
||||
assert style.Styles[0] == result
|
||||
assert len(style.Styles) == 1
|
||||
|
||||
def test_adding_multiple_styles_of_different_types(self):
|
||||
style = self.file.createIfcSurfaceStyle()
|
||||
attrs = {"SurfaceColour": {"Name": "", "Red": 1, "Green": 1, "Blue": 1}}
|
||||
if self.file.schema != "IFC2X3":
|
||||
attrs["Transparency"] = 0.5
|
||||
result1 = ifcopenshell.api.run(
|
||||
"style.add_surface_style",
|
||||
self.file,
|
||||
style=style,
|
||||
ifc_class="IfcSurfaceStyleShading",
|
||||
attributes={"SurfaceColour": {"Name": "", "Red": 1, "Green": 1, "Blue": 1}, "Transparency": 0.5},
|
||||
attributes=attrs,
|
||||
)
|
||||
result2 = ifcopenshell.api.run(
|
||||
"style.add_surface_style",
|
||||
@@ -95,19 +109,26 @@ class TestAddSurfaceStyle(test.bootstrap.IFC4):
|
||||
|
||||
def test_ensure_shading_and_rendering_are_mutually_exclusive_when_adding(self):
|
||||
style = self.file.createIfcSurfaceStyle()
|
||||
attrs = {"SurfaceColour": {"Name": "", "Red": 1, "Green": 1, "Blue": 1}}
|
||||
if self.file.schema != "IFC2X3":
|
||||
attrs["Transparency"] = 0.5
|
||||
ifcopenshell.api.run(
|
||||
"style.add_surface_style",
|
||||
self.file,
|
||||
style=style,
|
||||
ifc_class="IfcSurfaceStyleShading",
|
||||
attributes={"SurfaceColour": {"Name": "", "Red": 1, "Green": 1, "Blue": 1}, "Transparency": 0.5},
|
||||
attributes=attrs,
|
||||
)
|
||||
result = ifcopenshell.api.run(
|
||||
"style.add_surface_style",
|
||||
self.file,
|
||||
style=style,
|
||||
ifc_class="IfcSurfaceStyleRendering",
|
||||
attributes={"SurfaceColour": {"Name": "", "Red": 1, "Green": 1, "Blue": 1}, "Transparency": 0.5},
|
||||
attributes=attrs,
|
||||
)
|
||||
assert style.Styles[0] == result
|
||||
assert len(style.Styles) == 1
|
||||
|
||||
|
||||
class TestAddSurfaceStyleIFC2X3(test.bootstrap.IFC2X3, TestAddSurfaceStyle):
|
||||
pass
|
||||
|
||||
@@ -21,6 +21,7 @@ import test.bootstrap
|
||||
import ifcopenshell.api
|
||||
|
||||
|
||||
# TODO: add ifc2x3 tests after add_surface_textures will support ifc2x3
|
||||
class TestAddSurfaceTexture(test.bootstrap.IFC4):
|
||||
def get_default_texture_data(self):
|
||||
return [
|
||||
@@ -67,6 +68,7 @@ class TestAddSurfaceTexture(test.bootstrap.IFC4):
|
||||
for texture, data in zip(textures, texture_data):
|
||||
self.compare_texture_to_data(texture, data)
|
||||
|
||||
# NOTE: IfcTextureCoordinate doesn't have Maps in IFC2X3
|
||||
def test_add_surface_textures_from_data_with_uv_maps(self):
|
||||
texture_data = self.get_default_texture_data()
|
||||
texture_data[0]["uv_mode"] = "Generated"
|
||||
|
||||
@@ -22,7 +22,7 @@ import ifcopenshell
|
||||
import ifcopenshell.api
|
||||
|
||||
|
||||
class TestAssignMaterialStyle(test.bootstrap.IFC4):
|
||||
class TestAssignMaterialStyleIFC2X3(test.bootstrap.IFC2X3):
|
||||
def test_run(self):
|
||||
material = ifcopenshell.api.run("material.add_material", self.file)
|
||||
context = self.file.createIfcGeometricRepresentationContext()
|
||||
@@ -38,7 +38,12 @@ class TestAssignMaterialStyle(test.bootstrap.IFC4):
|
||||
assert len(representation.Items) == 1
|
||||
item = representation.Items[0]
|
||||
assert item.is_a("IfcStyledItem")
|
||||
assert item.Styles == (style,)
|
||||
if self.file.schema != "IFC2X3":
|
||||
assert item.Styles == (style,)
|
||||
else:
|
||||
# IfcPresentationStyleAssignment
|
||||
assert len(item.Styles[0]) == 1
|
||||
assert item.Styles[0].Styles == (style,)
|
||||
|
||||
style2 = self.file.createIfcSurfaceStyle()
|
||||
ifcopenshell.api.run("style.assign_material_style", self.file, material=material, style=style2, context=context)
|
||||
@@ -48,8 +53,16 @@ class TestAssignMaterialStyle(test.bootstrap.IFC4):
|
||||
assert definition.Representations == (representation,)
|
||||
assert len(representation.Items) == 1
|
||||
assert representation.Items[0] == item
|
||||
assert representation.Items[0].Styles == (style2,)
|
||||
if self.file.schema != "IFC2X3":
|
||||
assert representation.Items[0].Styles == (style2,)
|
||||
else:
|
||||
# IfcPresentationStyleAssignment
|
||||
assert len(representation.Items[0].Styles) == 1
|
||||
assert representation.Items[0].Styles == (style2,)
|
||||
|
||||
|
||||
class TestAssignMaterialStyleIFC4(test.bootstrap.IFC4, TestAssignMaterialStyleIFC2X3):
|
||||
# IfcMaterialConstituentSet was added in IFC4
|
||||
def test_update_shape_aspect_representations_items_styles_if_material_is_part_of_matching_material_constituents(
|
||||
self,
|
||||
):
|
||||
|
||||
@@ -25,15 +25,19 @@ class TestEditSurfaceStyle(test.bootstrap.IFC4):
|
||||
def test_editing_a_shading_style(self):
|
||||
colour = self.file.createIfcColourRgb(None, 0, 0, 0)
|
||||
style = self.file.createIfcSurfaceStyleShading(colour)
|
||||
attrs = {"SurfaceColour": {"Red": 1, "Green": 1, "Blue": 1}}
|
||||
if self.file.schema != "IFC2X3":
|
||||
attrs["Transparency"] = 0.5
|
||||
ifcopenshell.api.run(
|
||||
"style.edit_surface_style",
|
||||
self.file,
|
||||
style=style,
|
||||
attributes={"SurfaceColour": {"Red": 1, "Green": 1, "Blue": 1}, "Transparency": 0.5},
|
||||
attributes=attrs,
|
||||
)
|
||||
assert style.SurfaceColour == colour
|
||||
assert list(colour) == [None, 1, 1, 1]
|
||||
assert style.Transparency == 0.5
|
||||
if self.file.schema != "IFC2X3":
|
||||
assert style.Transparency == 0.5
|
||||
|
||||
def test_editing_an_empty_colour_or_factor(self):
|
||||
for attribute in [
|
||||
@@ -170,3 +174,7 @@ class TestEditSurfaceStyle(test.bootstrap.IFC4):
|
||||
)
|
||||
for attribute in attributes:
|
||||
assert tuple(getattr(style, attribute)) == (None, 1, 1, 1)
|
||||
|
||||
|
||||
class TestEditSurfaceStyleIFC2X3(test.bootstrap.IFC2X3, TestEditSurfaceStyle):
|
||||
pass
|
||||
|
||||
@@ -34,3 +34,7 @@ class TestRemoveStyle(test.bootstrap.IFC4):
|
||||
styled_item = self.file.createIfcStyledItem(Styles=[style])
|
||||
ifcopenshell.api.run("style.remove_style", self.file, style=style)
|
||||
assert len(list(self.file)) == 0
|
||||
|
||||
|
||||
class TestRemoveStyleIFC2X3(test.bootstrap.IFC2X3, TestRemoveStyle):
|
||||
pass
|
||||
|
||||
@@ -21,7 +21,7 @@ import test.bootstrap
|
||||
import ifcopenshell.api
|
||||
|
||||
|
||||
class TestRemoveSurfaceStyle(test.bootstrap.IFC4):
|
||||
class TestRemoveSurfaceStyleIFC2X3(test.bootstrap.IFC2X3):
|
||||
def test_removing_a_shading_style(self):
|
||||
style = self.file.createIfcSurfaceStyleShading(SurfaceColour=self.file.createIfcColourRgb(None, 1, 1, 1))
|
||||
ifcopenshell.api.run("style.remove_surface_style", self.file, style=style)
|
||||
@@ -33,13 +33,6 @@ class TestRemoveSurfaceStyle(test.bootstrap.IFC4):
|
||||
ifcopenshell.api.run("style.remove_surface_style", self.file, style=style)
|
||||
assert len(list(self.file)) == 0
|
||||
|
||||
def test_removing_a_texture_style_with_all_of_its_coordinates(self):
|
||||
texture = self.file.createIfcImageTexture()
|
||||
coordinates = self.file.createIfcTextureCoordinateGenerator(Maps=[texture])
|
||||
style = self.file.createIfcSurfaceStyleWithTextures(Textures=[texture])
|
||||
ifcopenshell.api.run("style.remove_surface_style", self.file, style=style)
|
||||
assert len(list(self.file)) == 0
|
||||
|
||||
def test_removing_a_rendering_style(self):
|
||||
style = self.file.createIfcSurfaceStyleRendering(
|
||||
SurfaceColour=self.file.createIfcColourRgb(None, 1, 1, 1),
|
||||
@@ -55,3 +48,13 @@ class TestRemoveSurfaceStyle(test.bootstrap.IFC4):
|
||||
g = ifcopenshell.file.from_string(self.file.wrapped_data.to_string())
|
||||
ifcopenshell.api.run("style.remove_surface_style", g, style=g.by_type("IfcSurfaceStyleRendering")[0])
|
||||
assert len(list(g)) == 0
|
||||
|
||||
|
||||
class TestRemoveSurfaceStyleIFC4(test.bootstrap.IFC4, TestRemoveSurfaceStyleIFC2X3):
|
||||
# IfcTextureCoordinateGenerator doesn't have Maps in IFC2X3
|
||||
def test_removing_a_texture_style_with_all_of_its_coordinates(self):
|
||||
texture = self.file.createIfcImageTexture()
|
||||
coordinates = self.file.createIfcTextureCoordinateGenerator(Maps=[texture])
|
||||
style = self.file.createIfcSurfaceStyleWithTextures(Textures=[texture])
|
||||
ifcopenshell.api.run("style.remove_surface_style", self.file, style=style)
|
||||
assert len(list(self.file)) == 0
|
||||
|
||||
@@ -22,7 +22,7 @@ import ifcopenshell
|
||||
import ifcopenshell.api
|
||||
|
||||
|
||||
class TestAssignMaterialStyle(test.bootstrap.IFC4):
|
||||
class TestUnassignMaterialStyleIFC2X3(test.bootstrap.IFC2X3):
|
||||
def test_run(self):
|
||||
material = ifcopenshell.api.run("material.add_material", self.file)
|
||||
context = self.file.createIfcGeometricRepresentationContext()
|
||||
@@ -36,7 +36,12 @@ class TestAssignMaterialStyle(test.bootstrap.IFC4):
|
||||
ifcopenshell.api.run(
|
||||
"style.unassign_material_style", self.file, material=material, style=style2, context=context
|
||||
)
|
||||
assert item.Styles == (style,)
|
||||
if self.file.schema != "IFC2X3":
|
||||
assert item.Styles == (style,)
|
||||
else:
|
||||
# IfcPresentationStyleAssignment
|
||||
assert len(item.Styles) == 1
|
||||
assert item.Styles[0].Styles == (style,)
|
||||
|
||||
# unassign last style
|
||||
ifcopenshell.api.run(
|
||||
@@ -46,6 +51,9 @@ class TestAssignMaterialStyle(test.bootstrap.IFC4):
|
||||
assert len(self.file.by_type("IfcStyledRepresentation")) == 0
|
||||
assert len(self.file.by_type("IfcStyledItem")) == 0
|
||||
|
||||
|
||||
class TestUnassignMaterialStyleIFC4(test.bootstrap.IFC4, TestUnassignMaterialStyleIFC2X3):
|
||||
# IfcMaterialConstituentSet was added in IFC4
|
||||
def test_update_shape_aspect_representaitons_items_styles_if_material_is_part_of_matching_material_constituents(
|
||||
self,
|
||||
):
|
||||
|
||||
Reference in New Issue
Block a user