mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-08-10 17:58:20 +00:00
Replace all ifcopenshell.api.run with ifcopenshell.api static functions.
This commit is contained in:
@@ -16,9 +16,8 @@
|
||||
# You should have received a copy of the GNU Lesser General Public License
|
||||
# along with IfcOpenShell. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
import pytest
|
||||
import test.bootstrap
|
||||
import ifcopenshell.api
|
||||
import ifcopenshell.api.style
|
||||
|
||||
|
||||
class TestAddSurfaceStyle(test.bootstrap.IFC4):
|
||||
@@ -27,8 +26,7 @@ class TestAddSurfaceStyle(test.bootstrap.IFC4):
|
||||
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",
|
||||
result = ifcopenshell.api.style.add_surface_style(
|
||||
self.file,
|
||||
style=style,
|
||||
ifc_class="IfcSurfaceStyleShading",
|
||||
@@ -47,8 +45,7 @@ class TestAddSurfaceStyle(test.bootstrap.IFC4):
|
||||
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",
|
||||
result = ifcopenshell.api.style.add_surface_style(
|
||||
self.file,
|
||||
style=style,
|
||||
ifc_class="IfcSurfaceStyleRendering",
|
||||
@@ -67,15 +64,13 @@ class TestAddSurfaceStyle(test.bootstrap.IFC4):
|
||||
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",
|
||||
ifcopenshell.api.style.add_surface_style(
|
||||
self.file,
|
||||
style=style,
|
||||
ifc_class="IfcSurfaceStyleRendering",
|
||||
attributes=attrs,
|
||||
)
|
||||
result = ifcopenshell.api.run(
|
||||
"style.add_surface_style",
|
||||
result = ifcopenshell.api.style.add_surface_style(
|
||||
self.file,
|
||||
style=style,
|
||||
ifc_class="IfcSurfaceStyleRendering",
|
||||
@@ -89,15 +84,13 @@ class TestAddSurfaceStyle(test.bootstrap.IFC4):
|
||||
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",
|
||||
result1 = ifcopenshell.api.style.add_surface_style(
|
||||
self.file,
|
||||
style=style,
|
||||
ifc_class="IfcSurfaceStyleShading",
|
||||
attributes=attrs,
|
||||
)
|
||||
result2 = ifcopenshell.api.run(
|
||||
"style.add_surface_style",
|
||||
result2 = ifcopenshell.api.style.add_surface_style(
|
||||
self.file,
|
||||
style=style,
|
||||
ifc_class="IfcSurfaceStyleWithTextures",
|
||||
@@ -112,15 +105,13 @@ class TestAddSurfaceStyle(test.bootstrap.IFC4):
|
||||
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",
|
||||
ifcopenshell.api.style.add_surface_style(
|
||||
self.file,
|
||||
style=style,
|
||||
ifc_class="IfcSurfaceStyleShading",
|
||||
attributes=attrs,
|
||||
)
|
||||
result = ifcopenshell.api.run(
|
||||
"style.add_surface_style",
|
||||
result = ifcopenshell.api.style.add_surface_style(
|
||||
self.file,
|
||||
style=style,
|
||||
ifc_class="IfcSurfaceStyleRendering",
|
||||
|
||||
@@ -18,7 +18,7 @@
|
||||
|
||||
import pytest
|
||||
import test.bootstrap
|
||||
import ifcopenshell.api
|
||||
import ifcopenshell.api.style
|
||||
|
||||
|
||||
# TODO: add ifc2x3 tests after add_surface_textures will support ifc2x3
|
||||
@@ -51,7 +51,7 @@ class TestAddSurfaceTexture(test.bootstrap.IFC4):
|
||||
def test_add_surface_textures_from_data(self):
|
||||
texture_data = self.get_default_texture_data()
|
||||
|
||||
textures = ifcopenshell.api.run("style.add_surface_textures", self.file, textures=texture_data)
|
||||
textures = ifcopenshell.api.style.add_surface_textures(self.file, textures=texture_data)
|
||||
assert len(list(self.file)) == len(texture_data)
|
||||
|
||||
for texture, data in zip(textures, texture_data):
|
||||
@@ -64,7 +64,7 @@ class TestAddSurfaceTexture(test.bootstrap.IFC4):
|
||||
texture_data[2]["uv_mode"] = "UV"
|
||||
texture_data[3]["uv_mode"] = None
|
||||
|
||||
textures = ifcopenshell.api.run("style.add_surface_textures", self.file, textures=texture_data)
|
||||
textures = ifcopenshell.api.style.add_surface_textures(self.file, textures=texture_data)
|
||||
for texture, data in zip(textures, texture_data):
|
||||
self.compare_texture_to_data(texture, data)
|
||||
|
||||
@@ -77,6 +77,6 @@ class TestAddSurfaceTexture(test.bootstrap.IFC4):
|
||||
texture_data[3]["uv_mode"] = None
|
||||
|
||||
uv_maps = [self.file.create_entity("IfcTextureCoordinateGenerator", Maps=[], Mode="COORD") for i in range(5)]
|
||||
textures = ifcopenshell.api.run("style.add_surface_textures", self.file, textures=texture_data, uv_maps=uv_maps)
|
||||
textures = ifcopenshell.api.style.add_surface_textures(self.file, textures=texture_data, uv_maps=uv_maps)
|
||||
for texture, data in zip(textures, texture_data):
|
||||
self.compare_texture_to_data(texture, data, uv_maps)
|
||||
|
||||
@@ -16,18 +16,19 @@
|
||||
# You should have received a copy of the GNU Lesser General Public License
|
||||
# along with IfcOpenShell. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
import pytest
|
||||
import test.bootstrap
|
||||
import ifcopenshell
|
||||
import ifcopenshell.api
|
||||
import ifcopenshell.api.root
|
||||
import ifcopenshell.api.style
|
||||
import ifcopenshell.api.material
|
||||
|
||||
|
||||
class TestAssignMaterialStyleIFC2X3(test.bootstrap.IFC2X3):
|
||||
def test_run(self):
|
||||
material = ifcopenshell.api.run("material.add_material", self.file)
|
||||
material = ifcopenshell.api.material.add_material(self.file)
|
||||
context = self.file.createIfcGeometricRepresentationContext()
|
||||
style = self.file.createIfcSurfaceStyle()
|
||||
ifcopenshell.api.run("style.assign_material_style", self.file, material=material, style=style, context=context)
|
||||
ifcopenshell.api.style.assign_material_style(self.file, material=material, style=style, context=context)
|
||||
|
||||
assert len(material.HasRepresentation) == 1
|
||||
definition = material.HasRepresentation[0]
|
||||
@@ -46,7 +47,7 @@ class TestAssignMaterialStyleIFC2X3(test.bootstrap.IFC2X3):
|
||||
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)
|
||||
ifcopenshell.api.style.assign_material_style(self.file, material=material, style=style2, context=context)
|
||||
|
||||
# reuse existing elements and reassign the style
|
||||
assert material.HasRepresentation == (definition,)
|
||||
@@ -66,7 +67,7 @@ class TestAssignMaterialStyleIFC4(test.bootstrap.IFC4, TestAssignMaterialStyleIF
|
||||
def test_update_shape_aspect_representations_items_styles_if_material_is_part_of_matching_material_constituents(
|
||||
self,
|
||||
):
|
||||
element = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWall")
|
||||
element = ifcopenshell.api.root.create_entity(self.file, ifc_class="IfcWall")
|
||||
name = "Concrete"
|
||||
product_shape = self.file.createIfcProductDefinitionShape()
|
||||
element.Representation = product_shape
|
||||
@@ -80,16 +81,16 @@ class TestAssignMaterialStyleIFC4(test.bootstrap.IFC4, TestAssignMaterialStyleIF
|
||||
shape_aspect.PartOfProductDefinitionShape = product_shape
|
||||
|
||||
style = self.file.createIfcSurfaceStyle()
|
||||
material = ifcopenshell.api.run("material.add_material", self.file)
|
||||
material_set = ifcopenshell.api.run(
|
||||
"material.add_material_set", self.file, set_type="IfcMaterialConstituentSet"
|
||||
material = ifcopenshell.api.material.add_material(self.file)
|
||||
material_set = ifcopenshell.api.material.add_material_set(
|
||||
self.file, set_type="IfcMaterialConstituentSet"
|
||||
)
|
||||
constituent = ifcopenshell.api.run(
|
||||
"material.add_constituent", self.file, constituent_set=material_set, material=material
|
||||
constituent = ifcopenshell.api.material.add_constituent(
|
||||
self.file, constituent_set=material_set, material=material
|
||||
)
|
||||
constituent.Name = name
|
||||
ifcopenshell.api.run("material.assign_material", self.file, products=[element], material=material_set)
|
||||
ifcopenshell.api.material.assign_material(self.file, products=[element], material=material_set)
|
||||
|
||||
ifcopenshell.api.run("style.assign_material_style", self.file, material=material, style=style, context=context)
|
||||
ifcopenshell.api.style.assign_material_style(self.file, material=material, style=style, context=context)
|
||||
|
||||
assert item.StyledByItem[0].Styles == (style,)
|
||||
|
||||
@@ -16,15 +16,15 @@
|
||||
# You should have received a copy of the GNU Lesser General Public License
|
||||
# along with IfcOpenShell. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
import pytest
|
||||
import test.bootstrap
|
||||
import ifcopenshell
|
||||
import ifcopenshell.api
|
||||
import ifcopenshell.api.root
|
||||
import ifcopenshell.api.style
|
||||
|
||||
|
||||
class TestAssignRepresentationStyles(test.bootstrap.IFC4):
|
||||
def test_run(self):
|
||||
element = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWall")
|
||||
element = ifcopenshell.api.root.create_entity(self.file, ifc_class="IfcWall")
|
||||
product_shape = self.file.createIfcProductDefinitionShape()
|
||||
element.Representation = product_shape
|
||||
|
||||
@@ -33,29 +33,29 @@ class TestAssignRepresentationStyles(test.bootstrap.IFC4):
|
||||
representation.Items = [item]
|
||||
|
||||
style = self.file.createIfcSurfaceStyle()
|
||||
ifcopenshell.api.run(
|
||||
"style.assign_representation_styles", self.file, styles=[style], shape_representation=representation
|
||||
ifcopenshell.api.style.assign_representation_styles(
|
||||
self.file, styles=[style], shape_representation=representation
|
||||
)
|
||||
assert item.StyledByItem[0].Styles == (style,)
|
||||
|
||||
# reusing existing styled item for different style type
|
||||
style2 = self.file.createIfcFillAreaStyle()
|
||||
ifcopenshell.api.run(
|
||||
"style.assign_representation_styles", self.file, styles=[style2], shape_representation=representation
|
||||
ifcopenshell.api.style.assign_representation_styles(
|
||||
self.file, styles=[style2], shape_representation=representation
|
||||
)
|
||||
assert item.StyledByItem[0].Styles == (style, style2)
|
||||
assert len(self.file.by_type("IfcStyledItem")) == 1
|
||||
|
||||
# replacing existing style of the same type
|
||||
style3 = self.file.createIfcSurfaceStyle()
|
||||
ifcopenshell.api.run(
|
||||
"style.assign_representation_styles", self.file, styles=[style3], shape_representation=representation
|
||||
ifcopenshell.api.style.assign_representation_styles(
|
||||
self.file, styles=[style3], shape_representation=representation
|
||||
)
|
||||
assert item.StyledByItem[0].Styles == (style2, style3)
|
||||
assert len(self.file.by_type("IfcStyledItem")) == 1
|
||||
|
||||
def test_assign_using_style_assignment(self):
|
||||
element = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWall")
|
||||
element = ifcopenshell.api.root.create_entity(self.file, ifc_class="IfcWall")
|
||||
product_shape = self.file.createIfcProductDefinitionShape()
|
||||
element.Representation = product_shape
|
||||
|
||||
@@ -64,8 +64,7 @@ class TestAssignRepresentationStyles(test.bootstrap.IFC4):
|
||||
representation.Items = [item]
|
||||
|
||||
style = self.file.createIfcSurfaceStyle()
|
||||
ifcopenshell.api.run(
|
||||
"style.assign_representation_styles",
|
||||
ifcopenshell.api.style.assign_representation_styles(
|
||||
self.file,
|
||||
styles=[style],
|
||||
shape_representation=representation,
|
||||
@@ -78,8 +77,7 @@ class TestAssignRepresentationStyles(test.bootstrap.IFC4):
|
||||
|
||||
# reusing existing styled item for different style type
|
||||
style2 = self.file.createIfcFillAreaStyle()
|
||||
ifcopenshell.api.run(
|
||||
"style.assign_representation_styles",
|
||||
ifcopenshell.api.style.assign_representation_styles(
|
||||
self.file,
|
||||
styles=[style2],
|
||||
shape_representation=representation,
|
||||
@@ -93,8 +91,7 @@ class TestAssignRepresentationStyles(test.bootstrap.IFC4):
|
||||
|
||||
# replacing existing style of the same type
|
||||
style3 = self.file.createIfcSurfaceStyle()
|
||||
ifcopenshell.api.run(
|
||||
"style.assign_representation_styles",
|
||||
ifcopenshell.api.style.assign_representation_styles(
|
||||
self.file,
|
||||
styles=[style3],
|
||||
shape_representation=representation,
|
||||
|
||||
@@ -18,7 +18,7 @@
|
||||
|
||||
import pytest
|
||||
import test.bootstrap
|
||||
import ifcopenshell.api
|
||||
import ifcopenshell.api.style
|
||||
|
||||
|
||||
class TestEditSurfaceStyle(test.bootstrap.IFC4):
|
||||
@@ -28,8 +28,7 @@ class TestEditSurfaceStyle(test.bootstrap.IFC4):
|
||||
attrs = {"SurfaceColour": {"Red": 1, "Green": 1, "Blue": 1}}
|
||||
if self.file.schema != "IFC2X3":
|
||||
attrs["Transparency"] = 0.5
|
||||
ifcopenshell.api.run(
|
||||
"style.edit_surface_style",
|
||||
ifcopenshell.api.style.edit_surface_style(
|
||||
self.file,
|
||||
style=style,
|
||||
attributes=attrs,
|
||||
@@ -48,8 +47,7 @@ class TestEditSurfaceStyle(test.bootstrap.IFC4):
|
||||
"SpecularColour",
|
||||
]:
|
||||
style = self.file.createIfcSurfaceStyleRendering(self.file.createIfcColourRgb(None, 0, 0, 0))
|
||||
ifcopenshell.api.run(
|
||||
"style.edit_surface_style",
|
||||
ifcopenshell.api.style.edit_surface_style(
|
||||
self.file,
|
||||
style=style,
|
||||
attributes={attribute: {"Red": 1, "Green": 1, "Blue": 1}},
|
||||
@@ -67,8 +65,7 @@ class TestEditSurfaceStyle(test.bootstrap.IFC4):
|
||||
colour = self.file.createIfcColourRgb(None, 0, 0, 0)
|
||||
style = self.file.createIfcSurfaceStyleRendering(self.file.createIfcColourRgb(None, 0, 0, 0))
|
||||
setattr(style, attribute, colour)
|
||||
ifcopenshell.api.run(
|
||||
"style.edit_surface_style",
|
||||
ifcopenshell.api.style.edit_surface_style(
|
||||
self.file,
|
||||
style=style,
|
||||
attributes={attribute: {"Red": 1, "Green": 1, "Blue": 1}},
|
||||
@@ -87,7 +84,7 @@ class TestEditSurfaceStyle(test.bootstrap.IFC4):
|
||||
colour_id = colour.id()
|
||||
style = self.file.createIfcSurfaceStyleRendering(self.file.createIfcColourRgb(None, 0, 0, 0))
|
||||
setattr(style, attribute, colour)
|
||||
ifcopenshell.api.run("style.edit_surface_style", self.file, style=style, attributes={attribute: 0.5})
|
||||
ifcopenshell.api.style.edit_surface_style(self.file, style=style, attributes={attribute: 0.5})
|
||||
with pytest.raises(RuntimeError):
|
||||
self.file.by_id(colour_id)
|
||||
assert getattr(style, attribute).wrappedValue == 0.5
|
||||
@@ -102,7 +99,7 @@ class TestEditSurfaceStyle(test.bootstrap.IFC4):
|
||||
]:
|
||||
style = self.file.createIfcSurfaceStyleRendering(self.file.createIfcColourRgb(None, 0, 0, 0))
|
||||
setattr(style, attribute, self.file.createIfcNormalisedRatioMeasure(0.5))
|
||||
ifcopenshell.api.run("style.edit_surface_style", self.file, style=style, attributes={attribute: 0.4})
|
||||
ifcopenshell.api.style.edit_surface_style(self.file, style=style, attributes={attribute: 0.4})
|
||||
assert getattr(style, attribute).wrappedValue == 0.4
|
||||
|
||||
def test_editing_an_existing_factor_to_a_colour(self):
|
||||
@@ -115,8 +112,7 @@ class TestEditSurfaceStyle(test.bootstrap.IFC4):
|
||||
]:
|
||||
style = self.file.createIfcSurfaceStyleRendering(self.file.createIfcColourRgb(None, 0, 0, 0))
|
||||
setattr(style, attribute, self.file.createIfcNormalisedRatioMeasure(0.5))
|
||||
ifcopenshell.api.run(
|
||||
"style.edit_surface_style",
|
||||
ifcopenshell.api.style.edit_surface_style(
|
||||
self.file,
|
||||
style=style,
|
||||
attributes={attribute: {"Red": 1, "Green": 1, "Blue": 1}},
|
||||
@@ -125,8 +121,7 @@ class TestEditSurfaceStyle(test.bootstrap.IFC4):
|
||||
|
||||
def test_editing_a_specular_highlight_as_an_exponent(self):
|
||||
style = self.file.createIfcSurfaceStyleRendering(self.file.createIfcColourRgb(None, 0, 0, 0))
|
||||
ifcopenshell.api.run(
|
||||
"style.edit_surface_style",
|
||||
ifcopenshell.api.style.edit_surface_style(
|
||||
self.file,
|
||||
style=style,
|
||||
attributes={"SpecularHighlight": {"IfcSpecularExponent": 2}},
|
||||
@@ -136,8 +131,7 @@ class TestEditSurfaceStyle(test.bootstrap.IFC4):
|
||||
|
||||
def test_editing_a_specular_highlight_as_a_roughness(self):
|
||||
style = self.file.createIfcSurfaceStyleRendering(self.file.createIfcColourRgb(None, 0, 0, 0))
|
||||
ifcopenshell.api.run(
|
||||
"style.edit_surface_style",
|
||||
ifcopenshell.api.style.edit_surface_style(
|
||||
self.file,
|
||||
style=style,
|
||||
attributes={"SpecularHighlight": {"IfcSpecularRoughness": 0.5}},
|
||||
@@ -148,9 +142,8 @@ class TestEditSurfaceStyle(test.bootstrap.IFC4):
|
||||
def test_editing_texture_style(self):
|
||||
style = self.file.createIfcSurfaceStyleWithTextures()
|
||||
textures = ({"Mode": "DIFFUSE", "RepeatS": True, "RepeatT": True, "URLReference": "diffuse.jpg"},)
|
||||
textures = ifcopenshell.api.run("style.add_surface_textures", self.file, textures=textures)
|
||||
ifcopenshell.api.run(
|
||||
"style.edit_surface_style",
|
||||
textures = ifcopenshell.api.style.add_surface_textures(self.file, textures=textures)
|
||||
ifcopenshell.api.style.edit_surface_style(
|
||||
self.file,
|
||||
style=style,
|
||||
attributes={"Textures": textures},
|
||||
@@ -166,8 +159,7 @@ class TestEditSurfaceStyle(test.bootstrap.IFC4):
|
||||
"ReflectanceColour",
|
||||
)
|
||||
attributes = {a: {"Red": 1, "Green": 1, "Blue": 1} for a in attributes}
|
||||
ifcopenshell.api.run(
|
||||
"style.edit_surface_style",
|
||||
ifcopenshell.api.style.edit_surface_style(
|
||||
self.file,
|
||||
style=style,
|
||||
attributes=attributes,
|
||||
|
||||
@@ -18,21 +18,21 @@
|
||||
|
||||
import pytest
|
||||
import test.bootstrap
|
||||
import ifcopenshell.api
|
||||
import ifcopenshell.api.style
|
||||
|
||||
|
||||
class TestRemoveStyle(test.bootstrap.IFC4):
|
||||
def test_removing_a_style(self):
|
||||
shading = self.file.createIfcSurfaceStyleShading()
|
||||
style = self.file.createIfcSurfaceStyle(Styles=[shading])
|
||||
ifcopenshell.api.run("style.remove_style", self.file, style=style)
|
||||
ifcopenshell.api.style.remove_style(self.file, style=style)
|
||||
assert len(list(self.file)) == 0
|
||||
|
||||
def test_removing_any_styled_items_referencing_the_style(self):
|
||||
shading = self.file.createIfcSurfaceStyleShading()
|
||||
style = self.file.createIfcSurfaceStyle(Styles=[shading])
|
||||
styled_item = self.file.createIfcStyledItem(Styles=[style])
|
||||
ifcopenshell.api.run("style.remove_style", self.file, style=style)
|
||||
ifcopenshell.api.style.remove_style(self.file, style=style)
|
||||
assert len(list(self.file)) == 0
|
||||
|
||||
|
||||
|
||||
@@ -18,19 +18,19 @@
|
||||
|
||||
import pytest
|
||||
import test.bootstrap
|
||||
import ifcopenshell.api
|
||||
import ifcopenshell.api.style
|
||||
|
||||
|
||||
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)
|
||||
ifcopenshell.api.style.remove_surface_style(self.file, style=style)
|
||||
assert len(list(self.file)) == 0
|
||||
|
||||
def test_removing_a_texture_style(self):
|
||||
texture = self.file.createIfcImageTexture()
|
||||
style = self.file.createIfcSurfaceStyleWithTextures(Textures=[texture])
|
||||
ifcopenshell.api.run("style.remove_surface_style", self.file, style=style)
|
||||
ifcopenshell.api.style.remove_surface_style(self.file, style=style)
|
||||
assert len(list(self.file)) == 0
|
||||
|
||||
def test_removing_a_rendering_style(self):
|
||||
@@ -46,7 +46,7 @@ class TestRemoveSurfaceStyleIFC2X3(test.bootstrap.IFC2X3):
|
||||
# remove entity_instances() without an ID if we create them afresh, but
|
||||
# will segfault if we load them stale.
|
||||
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])
|
||||
ifcopenshell.api.style.remove_surface_style(g, style=g.by_type("IfcSurfaceStyleRendering")[0])
|
||||
assert len(list(g)) == 0
|
||||
|
||||
|
||||
@@ -56,5 +56,5 @@ class TestRemoveSurfaceStyleIFC4(test.bootstrap.IFC4, TestRemoveSurfaceStyleIFC2
|
||||
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)
|
||||
ifcopenshell.api.style.remove_surface_style(self.file, style=style)
|
||||
assert len(list(self.file)) == 0
|
||||
|
||||
@@ -16,26 +16,25 @@
|
||||
# You should have received a copy of the GNU Lesser General Public License
|
||||
# along with IfcOpenShell. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
import pytest
|
||||
import test.bootstrap
|
||||
import ifcopenshell
|
||||
import ifcopenshell.api
|
||||
import ifcopenshell.api.root
|
||||
import ifcopenshell.api.style
|
||||
import ifcopenshell.api.material
|
||||
|
||||
|
||||
class TestUnassignMaterialStyleIFC2X3(test.bootstrap.IFC2X3):
|
||||
def test_run(self):
|
||||
material = ifcopenshell.api.run("material.add_material", self.file)
|
||||
material = ifcopenshell.api.material.add_material(self.file)
|
||||
context = self.file.createIfcGeometricRepresentationContext()
|
||||
style = self.file.createIfcSurfaceStyle()
|
||||
ifcopenshell.api.run("style.assign_material_style", self.file, material=material, style=style, context=context)
|
||||
ifcopenshell.api.style.assign_material_style(self.file, material=material, style=style, context=context)
|
||||
|
||||
# unassign 1 style
|
||||
style2 = self.file.createIfcSurfaceStyle()
|
||||
item = self.file.by_type("IfcStyledItem")[0]
|
||||
item.Styles = item.Styles + (style2,)
|
||||
ifcopenshell.api.run(
|
||||
"style.unassign_material_style", self.file, material=material, style=style2, context=context
|
||||
)
|
||||
ifcopenshell.api.style.unassign_material_style(self.file, material=material, style=style2, context=context)
|
||||
if self.file.schema != "IFC2X3":
|
||||
assert item.Styles == (style,)
|
||||
else:
|
||||
@@ -44,9 +43,7 @@ class TestUnassignMaterialStyleIFC2X3(test.bootstrap.IFC2X3):
|
||||
assert item.Styles[0].Styles == (style,)
|
||||
|
||||
# unassign last style
|
||||
ifcopenshell.api.run(
|
||||
"style.unassign_material_style", self.file, material=material, style=style, context=context
|
||||
)
|
||||
ifcopenshell.api.style.unassign_material_style(self.file, material=material, style=style, context=context)
|
||||
assert len(self.file.by_type("IfcMaterialDefinitionRepresentation")) == 0
|
||||
assert len(self.file.by_type("IfcStyledRepresentation")) == 0
|
||||
assert len(self.file.by_type("IfcStyledItem")) == 0
|
||||
@@ -57,7 +54,7 @@ class TestUnassignMaterialStyleIFC4(test.bootstrap.IFC4, TestUnassignMaterialSty
|
||||
def test_update_shape_aspect_representaitons_items_styles_if_material_is_part_of_matching_material_constituents(
|
||||
self,
|
||||
):
|
||||
element = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWall")
|
||||
element = ifcopenshell.api.root.create_entity(self.file, ifc_class="IfcWall")
|
||||
name = "Concrete"
|
||||
product_shape = self.file.createIfcProductDefinitionShape()
|
||||
element.Representation = product_shape
|
||||
@@ -71,19 +68,15 @@ class TestUnassignMaterialStyleIFC4(test.bootstrap.IFC4, TestUnassignMaterialSty
|
||||
shape_aspect.PartOfProductDefinitionShape = product_shape
|
||||
|
||||
style = self.file.createIfcSurfaceStyle()
|
||||
material = ifcopenshell.api.run("material.add_material", self.file)
|
||||
material_set = ifcopenshell.api.run(
|
||||
"material.add_material_set", self.file, set_type="IfcMaterialConstituentSet"
|
||||
)
|
||||
constituent = ifcopenshell.api.run(
|
||||
"material.add_constituent", self.file, constituent_set=material_set, material=material
|
||||
material = ifcopenshell.api.material.add_material(self.file)
|
||||
material_set = ifcopenshell.api.material.add_material_set(self.file, set_type="IfcMaterialConstituentSet")
|
||||
constituent = ifcopenshell.api.material.add_constituent(
|
||||
self.file, constituent_set=material_set, material=material
|
||||
)
|
||||
constituent.Name = name
|
||||
ifcopenshell.api.run("material.assign_material", self.file, products=[element], material=material_set)
|
||||
ifcopenshell.api.material.assign_material(self.file, products=[element], material=material_set)
|
||||
|
||||
ifcopenshell.api.run("style.assign_material_style", self.file, material=material, style=style, context=context)
|
||||
ifcopenshell.api.run(
|
||||
"style.unassign_material_style", self.file, material=material, style=style, context=context
|
||||
)
|
||||
ifcopenshell.api.style.assign_material_style(self.file, material=material, style=style, context=context)
|
||||
ifcopenshell.api.style.unassign_material_style(self.file, material=material, style=style, context=context)
|
||||
|
||||
assert len(item.StyledByItem) == 0
|
||||
|
||||
@@ -16,15 +16,15 @@
|
||||
# You should have received a copy of the GNU Lesser General Public License
|
||||
# along with IfcOpenShell. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
import pytest
|
||||
import test.bootstrap
|
||||
import ifcopenshell
|
||||
import ifcopenshell.api
|
||||
import ifcopenshell.api.root
|
||||
import ifcopenshell.api.style
|
||||
|
||||
|
||||
class TestUnassignRepresentationStyles(test.bootstrap.IFC4):
|
||||
def test_run(self):
|
||||
element = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWall")
|
||||
element = ifcopenshell.api.root.create_entity(self.file, ifc_class="IfcWall")
|
||||
product_shape = self.file.createIfcProductDefinitionShape()
|
||||
element.Representation = product_shape
|
||||
|
||||
@@ -33,12 +33,11 @@ class TestUnassignRepresentationStyles(test.bootstrap.IFC4):
|
||||
representation.Items = [item]
|
||||
|
||||
style = self.file.createIfcSurfaceStyle()
|
||||
ifcopenshell.api.run(
|
||||
"style.assign_representation_styles", self.file, styles=[style], shape_representation=representation
|
||||
ifcopenshell.api.style.assign_representation_styles(
|
||||
self.file, styles=[style], shape_representation=representation
|
||||
)
|
||||
style2 = self.file.createIfcSurfaceStyle()
|
||||
ifcopenshell.api.run(
|
||||
"style.assign_representation_styles",
|
||||
ifcopenshell.api.style.assign_representation_styles(
|
||||
self.file,
|
||||
styles=[style2],
|
||||
shape_representation=representation,
|
||||
@@ -46,20 +45,20 @@ class TestUnassignRepresentationStyles(test.bootstrap.IFC4):
|
||||
)
|
||||
assert item.StyledByItem[0].Styles == (style, style2)
|
||||
|
||||
ifcopenshell.api.run(
|
||||
"style.unassign_representation_styles", self.file, styles=[style], shape_representation=representation
|
||||
ifcopenshell.api.style.unassign_representation_styles(
|
||||
self.file, styles=[style], shape_representation=representation
|
||||
)
|
||||
assert item.StyledByItem[0].Styles == (style2,)
|
||||
|
||||
# unassigning last style removes styled item
|
||||
ifcopenshell.api.run(
|
||||
"style.unassign_representation_styles", self.file, styles=[style2], shape_representation=representation
|
||||
ifcopenshell.api.style.unassign_representation_styles(
|
||||
self.file, styles=[style2], shape_representation=representation
|
||||
)
|
||||
assert len(item.StyledByItem) == 0
|
||||
assert len(self.file.by_type("IfcStyledItem")) == 0
|
||||
|
||||
def test_assign_using_style_assignment(self):
|
||||
element = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWall")
|
||||
element = ifcopenshell.api.root.create_entity(self.file, ifc_class="IfcWall")
|
||||
product_shape = self.file.createIfcProductDefinitionShape()
|
||||
element.Representation = product_shape
|
||||
|
||||
@@ -68,8 +67,7 @@ class TestUnassignRepresentationStyles(test.bootstrap.IFC4):
|
||||
representation.Items = [item]
|
||||
|
||||
style = self.file.createIfcSurfaceStyle()
|
||||
ifcopenshell.api.run(
|
||||
"style.assign_representation_styles",
|
||||
ifcopenshell.api.style.assign_representation_styles(
|
||||
self.file,
|
||||
styles=[style],
|
||||
shape_representation=representation,
|
||||
@@ -79,8 +77,7 @@ class TestUnassignRepresentationStyles(test.bootstrap.IFC4):
|
||||
|
||||
# reusing existing styled item and style assignment
|
||||
style2 = self.file.createIfcSurfaceStyle()
|
||||
ifcopenshell.api.run(
|
||||
"style.assign_representation_styles",
|
||||
ifcopenshell.api.style.assign_representation_styles(
|
||||
self.file,
|
||||
styles=[style2],
|
||||
shape_representation=representation,
|
||||
@@ -89,8 +86,7 @@ class TestUnassignRepresentationStyles(test.bootstrap.IFC4):
|
||||
)
|
||||
assert style_assignment.Styles == (style, style2)
|
||||
|
||||
ifcopenshell.api.run(
|
||||
"style.unassign_representation_styles",
|
||||
ifcopenshell.api.style.unassign_representation_styles(
|
||||
self.file,
|
||||
styles=[style],
|
||||
shape_representation=representation,
|
||||
@@ -99,8 +95,7 @@ class TestUnassignRepresentationStyles(test.bootstrap.IFC4):
|
||||
assert style_assignment.Styles == (style2,)
|
||||
|
||||
# unassigning last style removes styled item and presentation style
|
||||
ifcopenshell.api.run(
|
||||
"style.unassign_representation_styles",
|
||||
ifcopenshell.api.style.unassign_representation_styles(
|
||||
self.file,
|
||||
styles=[style2],
|
||||
shape_representation=representation,
|
||||
|
||||
Reference in New Issue
Block a user