mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-08-10 09:48:32 +00:00
114 lines
4.4 KiB
Python
114 lines
4.4 KiB
Python
# IfcOpenShell - IFC toolkit and geometry engine
|
|
# Copyright (C) 2022 Dion Moult <dion@thinkmoult.com>
|
|
#
|
|
# This file is part of IfcOpenShell.
|
|
#
|
|
# IfcOpenShell is free software: you can redistribute it and/or modify
|
|
# it under the terms of the GNU Lesser General Public License as published by
|
|
# the Free Software Foundation, either version 3 of the License, or
|
|
# (at your option) any later version.
|
|
#
|
|
# IfcOpenShell is distributed in the hope that it will be useful,
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
# GNU Lesser General Public License for more details.
|
|
#
|
|
# 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
|
|
|
|
|
|
class TestAddSurfaceStyle(test.bootstrap.IFC4):
|
|
def test_adding_a_surface_style(self):
|
|
style = self.file.createIfcSurfaceStyle()
|
|
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},
|
|
)
|
|
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
|
|
assert style.Styles[0] == result
|
|
|
|
def test_adding_a_rendering_style(self):
|
|
style = self.file.createIfcSurfaceStyle()
|
|
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},
|
|
)
|
|
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
|
|
assert style.Styles[0] == result
|
|
|
|
def test_not_adding_a_style_twice(self):
|
|
style = self.file.createIfcSurfaceStyle()
|
|
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},
|
|
)
|
|
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},
|
|
)
|
|
assert style.Styles[0] == result
|
|
assert len(style.Styles) == 1
|
|
|
|
def test_adding_multiple_styles_of_different_types(self):
|
|
style = self.file.createIfcSurfaceStyle()
|
|
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},
|
|
)
|
|
result2 = ifcopenshell.api.run(
|
|
"style.add_surface_style",
|
|
self.file,
|
|
style=style,
|
|
ifc_class="IfcSurfaceStyleWithTextures",
|
|
attributes={},
|
|
)
|
|
assert result1 in style.Styles
|
|
assert result2 in style.Styles
|
|
assert len(style.Styles) == 2
|
|
|
|
def test_ensure_shading_and_rendering_are_mutually_exclusive_when_adding(self):
|
|
style = self.file.createIfcSurfaceStyle()
|
|
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},
|
|
)
|
|
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},
|
|
)
|
|
assert style.Styles[0] == result
|
|
assert len(style.Styles) == 1
|