Prioritise editing rendering surface styles over shading surface styles

This commit is contained in:
Dion Moult
2021-10-07 18:51:50 +11:00
parent 9508858fcb
commit f26d43e0cd
44 changed files with 1670 additions and 1468 deletions
@@ -0,0 +1,59 @@
@style
Feature: Style
Scenario: Update style colours
Given an empty IFC project
And I add a cube
And I add a material
And I press "bim.add_style"
When I press "bim.update_style_colours"
Then nothing happens
Scenario: Remove style
Given an empty IFC project
And I add a cube
And I add a material
And I press "bim.add_style"
When I press "bim.remove_style"
Then nothing happens
Scenario: Add style
Given an empty IFC project
And I add a cube
And I add a material
When I press "bim.add_style"
Then nothing happens
Scenario: Unlink style
Given an empty IFC project
And I add a cube
And I add a material
And I press "bim.add_style"
When I press "bim.unlink_style"
Then nothing happens
Scenario: Enable editing style
Given an empty IFC project
And I add a cube
And I add a material
And I press "bim.add_style"
When I press "bim.enable_editing_style"
Then nothing happens
Scenario: Disable editing style
Given an empty IFC project
And I add a cube
And I add a material
And I press "bim.add_style"
And I press "bim.enable_editing_style"
When I press "bim.disable_editing_style"
Then nothing happens
Scenario: Edit style
Given an empty IFC project
And I add a cube
And I add a material
And I press "bim.add_style"
And I press "bim.enable_editing_style"
When I press "bim.edit_style"
Then nothing happens
+5
View File
@@ -49,6 +49,11 @@ def i_add_a_cube():
bpy.ops.mesh.primitive_cube_add()
@given("I add a material")
def i_add_a_material():
bpy.context.active_object.active_material = bpy.data.materials.new("Material")
@when(parsers.parse('I add a cube of size "{size}" at "{location}"'))
def i_add_a_cube_of_size_size_at_location(size, location):
bpy.ops.mesh.primitive_cube_add(size=float(size), location=[float(co) for co in location.split(",")])
+11 -32
View File
@@ -36,43 +36,15 @@ def blender():
@pytest.fixture
def aggregator():
prophet = Prophecy(blenderbim.core.tool.Aggregator)
def aggregate():
prophet = Prophecy(blenderbim.core.tool.Aggregate)
yield prophet
prophet.verify()
@pytest.fixture
def person_editor():
prophet = Prophecy(blenderbim.core.tool.PersonEditor)
yield prophet
prophet.verify()
@pytest.fixture
def role_editor():
prophet = Prophecy(blenderbim.core.tool.RoleEditor)
yield prophet
prophet.verify()
@pytest.fixture
def address_editor():
prophet = Prophecy(blenderbim.core.tool.AddressEditor)
yield prophet
prophet.verify()
@pytest.fixture
def organisation_editor():
prophet = Prophecy(blenderbim.core.tool.OrganisationEditor)
yield prophet
prophet.verify()
@pytest.fixture
def context_editor():
prophet = Prophecy(blenderbim.core.tool.ContextEditor)
def context():
prophet = Prophecy(blenderbim.core.tool.Context)
yield prophet
prophet.verify()
@@ -98,6 +70,13 @@ def selector():
prophet.verify()
@pytest.fixture
def style():
prophet = Prophecy(blenderbim.core.tool.Style)
yield prophet
prophet.verify()
@pytest.fixture
def surveyor():
prophet = Prophecy(blenderbim.core.tool.Surveyor)
+29 -11
View File
@@ -1,32 +1,50 @@
# BlenderBIM Add-on - OpenBIM Blender Add-on
# Copyright (C) 2021 Dion Moult <dion@thinkmoult.com>
#
# This file is part of BlenderBIM Add-on.
#
# BlenderBIM Add-on is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# BlenderBIM Add-on 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 General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with BlenderBIM Add-on. If not, see <http://www.gnu.org/licenses/>.
import blenderbim.core.aggregate as subject
from test.core.bootstrap import ifc, aggregator, collector
from test.core.bootstrap import ifc, aggregate, collector
class TestEnableEditingAggregate:
def test_run(self, aggregator):
aggregator.enable_editing("obj").should_be_called()
subject.enable_editing_aggregate(aggregator, obj="obj")
def test_run(self, aggregate):
aggregate.enable_editing("obj").should_be_called()
subject.enable_editing_aggregate(aggregate, obj="obj")
class TestDisableEditingAggregate:
def test_run(self, aggregator):
aggregator.disable_editing("obj").should_be_called()
subject.disable_editing_aggregate(aggregator, obj="obj")
def test_run(self, aggregate):
aggregate.disable_editing("obj").should_be_called()
subject.disable_editing_aggregate(aggregate, obj="obj")
class TestAssignObject:
def test_run(self, ifc, aggregator, collector):
aggregator.can_aggregate("relating_obj", "related_obj").should_be_called().will_return(True)
def test_run(self, ifc, aggregate, collector):
aggregate.can_aggregate("relating_obj", "related_obj").should_be_called().will_return(True)
ifc.get_entity("relating_obj").should_be_called().will_return("relating_object")
ifc.get_entity("related_obj").should_be_called().will_return("related_object")
ifc.run(
"aggregate.assign_object", product="related_object", relating_object="relating_object"
).should_be_called().will_return("rel")
aggregator.disable_editing("related_obj").should_be_called()
aggregate.disable_editing("related_obj").should_be_called()
collector.assign("relating_obj").should_be_called()
collector.assign("related_obj").should_be_called()
assert (
subject.assign_object(ifc, aggregator, collector, relating_obj="relating_obj", related_obj="related_obj")
subject.assign_object(ifc, aggregate, collector, relating_obj="relating_obj", related_obj="related_obj")
== "rel"
)
+13 -13
View File
@@ -17,7 +17,7 @@
# along with BlenderBIM Add-on. If not, see <http://www.gnu.org/licenses/>.
import blenderbim.core.context as subject
from test.core.bootstrap import ifc, context_editor
from test.core.bootstrap import ifc, context
class TestAddContext:
@@ -53,22 +53,22 @@ class TestRemoveContext:
class TestEnableEditingContext:
def test_run(self, context_editor):
context_editor.set_context("context").should_be_called()
context_editor.import_attributes().should_be_called()
subject.enable_editing_context(context_editor, context="context")
def test_run(self, context):
context.set_context("context").should_be_called()
context.import_attributes().should_be_called()
subject.enable_editing_context(context, context="context")
class TestDisableEditingContext:
def test_run(self, context_editor):
context_editor.clear_context().should_be_called()
subject.disable_editing_context(context_editor)
def test_run(self, context):
context.clear_context().should_be_called()
subject.disable_editing_context(context)
class TestEditContext:
def test_run(self, ifc, context_editor):
context_editor.get_context().should_be_called().will_return("context")
context_editor.export_attributes().should_be_called().will_return("attributes")
def test_run(self, ifc, context):
context.get_context().should_be_called().will_return("context")
context.export_attributes().should_be_called().will_return("attributes")
ifc.run("context.edit_context", context="context", attributes="attributes").should_be_called()
context_editor.clear_context().should_be_called()
subject.edit_context(ifc, context_editor)
context.clear_context().should_be_called()
subject.edit_context(ifc, context)
+61 -61
View File
@@ -18,7 +18,7 @@
import blenderbim.core.owner as subject
from test.core.bootstrap import ifc, blender, person_editor, role_editor, address_editor, organisation_editor, owner
from test.core.bootstrap import ifc, owner
class TestAddPerson:
@@ -34,37 +34,37 @@ class TestRemovePerson:
class TestEnableEditingPerson:
def test_run(self, person_editor):
person_editor.set_person("person").should_be_called()
person_editor.import_attributes().should_be_called()
subject.enable_editing_person(person_editor, person="person")
def test_run(self, owner):
owner.set_person("person").should_be_called()
owner.import_person_attributes().should_be_called()
subject.enable_editing_person(owner, person="person")
class TestDisableEditingPerson:
def test_run(self, person_editor):
person_editor.clear_person().should_be_called()
subject.disable_editing_person(person_editor)
def test_run(self, owner):
owner.clear_person().should_be_called()
subject.disable_editing_person(owner)
class TestEditPerson:
def test_run(self, ifc, person_editor):
person_editor.get_person().should_be_called().will_return("person")
person_editor.export_attributes().should_be_called().will_return("attributes")
def test_run(self, ifc, owner):
owner.get_person().should_be_called().will_return("person")
owner.export_person_attributes().should_be_called().will_return("attributes")
ifc.run("owner.edit_person", person="person", attributes="attributes").should_be_called()
person_editor.clear_person().should_be_called()
subject.edit_person(ifc, person_editor)
owner.clear_person().should_be_called()
subject.edit_person(ifc, owner)
class TestAddPersonAttribute:
def test_run(self, person_editor):
person_editor.add_attribute("name").should_be_called()
subject.add_person_attribute(person_editor, name="name")
def test_run(self, owner):
owner.add_person_attribute("name").should_be_called()
subject.add_person_attribute(owner, name="name")
class TestRemovePersonAttribute:
def test_run(self, person_editor):
person_editor.remove_attribute("name", "id").should_be_called()
subject.remove_person_attribute(person_editor, name="name", id="id")
def test_run(self, owner):
owner.remove_person_attribute("name", "id").should_be_called()
subject.remove_person_attribute(owner, name="name", id="id")
class TestAddRole:
@@ -80,25 +80,25 @@ class TestRemoveRole:
class TestEnableEditingRole:
def test_run(self, role_editor):
role_editor.set_role("role").should_be_called()
role_editor.import_attributes().should_be_called()
subject.enable_editing_role(role_editor, role="role")
def test_run(self, owner):
owner.set_role("role").should_be_called()
owner.import_role_attributes().should_be_called()
subject.enable_editing_role(owner, role="role")
class TestDisableEditingRole:
def test_run(self, role_editor):
role_editor.clear_role().should_be_called()
subject.disable_editing_role(role_editor)
def test_run(self, owner):
owner.clear_role().should_be_called()
subject.disable_editing_role(owner)
class TestEditRole:
def test_run(self, ifc, role_editor):
role_editor.export_attributes().should_be_called().will_return("attributes")
role_editor.get_role().should_be_called().will_return("role")
def test_run(self, ifc, owner):
owner.export_role_attributes().should_be_called().will_return("attributes")
owner.get_role().should_be_called().will_return("role")
ifc.run("owner.edit_role", role="role", attributes="attributes").should_be_called()
role_editor.clear_role().should_be_called()
subject.edit_role(ifc, role_editor)
owner.clear_role().should_be_called()
subject.edit_role(ifc, owner)
class TestAddAddress:
@@ -116,37 +116,37 @@ class TestRemoveAddress:
class TestEnableEditingAddress:
def test_run(self, address_editor):
address_editor.set_address("address").should_be_called()
address_editor.import_attributes().should_be_called()
subject.enable_editing_address(address_editor, address="address")
def test_run(self, owner):
owner.set_address("address").should_be_called()
owner.import_address_attributes().should_be_called()
subject.enable_editing_address(owner, address="address")
class TestDisableEditingAddress:
def test_run(self, address_editor):
address_editor.clear_address().should_be_called()
subject.disable_editing_address(address_editor)
def test_run(self, owner):
owner.clear_address().should_be_called()
subject.disable_editing_address(owner)
class TestEditAddress:
def test_run(self, ifc, address_editor):
address_editor.get_address().should_be_called().will_return("address")
address_editor.export_attributes().should_be_called().will_return("attributes")
def test_run(self, ifc, owner):
owner.get_address().should_be_called().will_return("address")
owner.export_address_attributes().should_be_called().will_return("attributes")
ifc.run("owner.edit_address", address="address", attributes="attributes").should_be_called()
address_editor.clear_address().should_be_called()
subject.edit_address(ifc, address_editor)
owner.clear_address().should_be_called()
subject.edit_address(ifc, owner)
class TestAddAddressAttribute:
def test_run(self, address_editor):
address_editor.add_attribute("name").should_be_called()
subject.add_address_attribute(address_editor, name="name")
def test_run(self, owner):
owner.add_address_attribute("name").should_be_called()
subject.add_address_attribute(owner, name="name")
class TestRemoveAddressAttribute:
def test_run(self, address_editor):
address_editor.remove_attribute("name", "id").should_be_called()
subject.remove_address_attribute(address_editor, name="name", id="id")
def test_run(self, owner):
owner.remove_address_attribute("name", "id").should_be_called()
subject.remove_address_attribute(owner, name="name", id="id")
class TestAddOrganisation:
@@ -162,25 +162,25 @@ class TestRemoveOrganisation:
class TestEnableEditingOrganisation:
def test_run(self, organisation_editor):
organisation_editor.set_organisation("organisation").should_be_called()
organisation_editor.import_attributes().should_be_called()
subject.enable_editing_organisation(organisation_editor, organisation="organisation")
def test_run(self, owner):
owner.set_organisation("organisation").should_be_called()
owner.import_organisation_attributes().should_be_called()
subject.enable_editing_organisation(owner, organisation="organisation")
class TestDisableEditingOrganisation:
def test_run(self, organisation_editor):
organisation_editor.clear_organisation().should_be_called()
subject.disable_editing_organisation(organisation_editor)
def test_run(self, owner):
owner.clear_organisation().should_be_called()
subject.disable_editing_organisation(owner)
class TestEditOrganisation:
def test_run(self, ifc, organisation_editor):
organisation_editor.get_organisation().should_be_called().will_return("organisation")
organisation_editor.export_attributes().should_be_called().will_return("attributes")
def test_run(self, ifc, owner):
owner.get_organisation().should_be_called().will_return("organisation")
owner.export_organisation_attributes().should_be_called().will_return("attributes")
ifc.run("owner.edit_organisation", organisation="organisation", attributes="attributes").should_be_called()
organisation_editor.clear_organisation().should_be_called()
subject.edit_organisation(ifc, organisation_editor)
owner.clear_organisation().should_be_called()
subject.edit_organisation(ifc, owner)
class TestAddPersonAndOrganisation:
+98
View File
@@ -0,0 +1,98 @@
# BlenderBIM Add-on - OpenBIM Blender Add-on
# Copyright (C) 2021 Dion Moult <dion@thinkmoult.com>
#
# This file is part of BlenderBIM Add-on.
#
# BlenderBIM Add-on is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# BlenderBIM Add-on 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 General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with BlenderBIM Add-on. If not, see <http://www.gnu.org/licenses/>.
import blenderbim.core.style as subject
from test.core.bootstrap import ifc, style
class TestAddStyle:
def test_it_adds_a_style_with_rendering_attributes(self, ifc, style):
style.get_name("obj").should_be_called().will_return("name")
ifc.run("style.add_style", name="name").should_be_called().will_return("style")
style.link("style", "obj").should_be_called()
style.get_surface_rendering_attributes("obj").should_be_called().will_return("attributes")
ifc.run(
"style.add_surface_style", style="style", ifc_class="IfcSurfaceStyleRendering", attributes="attributes"
).should_be_called()
ifc.get_entity("obj").should_be_called().will_return(None)
assert subject.add_style(ifc, style, obj="obj") == "style"
def test_adding_a_style_linked_to_a_material(self, ifc, style):
style.get_name("obj").should_be_called().will_return("name")
ifc.run("style.add_style", name="name").should_be_called().will_return("style")
style.link("style", "obj").should_be_called()
style.get_surface_rendering_attributes("obj").should_be_called().will_return("attributes")
ifc.run(
"style.add_surface_style", style="style", ifc_class="IfcSurfaceStyleRendering", attributes="attributes"
).should_be_called()
ifc.get_entity("obj").should_be_called().will_return("material")
style.get_context("obj").should_be_called().will_return("context")
ifc.run("style.assign_material_style", material="material", style="style", context="context").should_be_called()
assert subject.add_style(ifc, style, obj="obj") == "style"
class TestRemoveStyle:
def test_run(self, ifc, style):
style.get_style("obj").should_be_called().will_return("style")
ifc.run("style.remove_style", style="style").should_be_called()
style.unlink(obj="obj").should_be_called()
subject.remove_style(ifc, style, obj="obj")
class TestUpdateStyleColours:
def test_updating_rendering_colours_if_available(self, ifc, style):
style.get_surface_rendering_style("obj").should_be_called().will_return("style")
style.get_surface_rendering_attributes("obj").should_be_called().will_return("attributes")
ifc.run("style.edit_surface_style", style="style", attributes="attributes").should_be_called()
subject.update_style_colours(ifc, style, obj="obj")
def test_updating_shading_colours_as_a_fallback_if_available(self, ifc, style):
style.get_surface_rendering_style("obj").should_be_called().will_return(None)
style.get_surface_shading_style("obj").should_be_called().will_return("style")
style.get_surface_shading_attributes("obj").should_be_called().will_return("attributes")
ifc.run("style.edit_surface_style", style="style", attributes="attributes").should_be_called()
subject.update_style_colours(ifc, style, obj="obj")
class TestUnlinkStyle:
def test_run(self, style):
style.unlink("obj").should_be_called()
subject.unlink_style(style, obj="obj")
class TestEnableEditingStyle:
def test_run(self, style):
style.enable_editing("obj").should_be_called()
style.get_style("obj").should_be_called().will_return("style")
style.import_surface_attributes("style", "obj").should_be_called()
subject.enable_editing_style(style, obj="obj")
class TestDisableEditingStyle:
def test_run(self, style):
style.disable_editing("obj").should_be_called()
subject.disable_editing_style(style, obj="obj")
class TestEditStyle:
def test_run(self, ifc, style):
style.get_style("obj").should_be_called().will_return("style")
style.export_surface_attributes("obj").should_be_called().will_return("attributes")
ifc.run("style.edit_presentation_style", style="style", attributes="attributes").should_be_called()
style.disable_editing("obj").should_be_called()
subject.edit_style(ifc, style, obj="obj")
@@ -1,197 +0,0 @@
# BlenderBIM Add-on - OpenBIM Blender Add-on
# Copyright (C) 2021 Dion Moult <dion@thinkmoult.com>
#
# This file is part of BlenderBIM Add-on.
#
# BlenderBIM Add-on is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# BlenderBIM Add-on 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 General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with BlenderBIM Add-on. If not, see <http://www.gnu.org/licenses/>.
import bpy
import ifcopenshell
import test.bim.bootstrap
import blenderbim.core.tool
import blenderbim.tool as tool
from blenderbim.tool.address_editor import AddressEditor as subject
class TestImplementsTool(test.bim.bootstrap.NewFile):
def test_run(self):
assert isinstance(subject(), blenderbim.core.tool.AddressEditor)
class TestSetAddress(test.bim.bootstrap.NewFile):
def test_run(self):
ifc = ifcopenshell.file()
address = ifc.createIfcPostalAddress()
subject().set_address(address)
assert bpy.context.scene.BIMOwnerProperties.active_address_id == address.id()
class TestImportAttributes(test.bim.bootstrap.NewFile):
def test_importing_a_postal_address(self):
ifc = ifcopenshell.file()
tool.Ifc().set(ifc)
address = ifc.createIfcPostalAddress()
address.Purpose = "USERDEFINED"
address.Description = "Description"
address.UserDefinedPurpose = "UserDefinedPurpose"
address.InternalLocation = "InternalLocation"
address.AddressLines = ["Address", "Lines"]
address.PostalBox = "PostalBox"
address.Town = "Town"
address.Region = "Region"
address.PostalCode = "PostalCode"
address.Country = "Country"
subject().set_address(address)
subject().import_attributes()
props = bpy.context.scene.BIMOwnerProperties
assert props.address_attributes.get("Purpose").enum_value == "USERDEFINED"
assert props.address_attributes.get("Description").string_value == "Description"
assert props.address_attributes.get("UserDefinedPurpose").string_value == "UserDefinedPurpose"
assert props.address_attributes.get("InternalLocation").string_value == "InternalLocation"
assert props.address_attributes.get("PostalBox").string_value == "PostalBox"
assert props.address_attributes.get("Town").string_value == "Town"
assert props.address_attributes.get("Region").string_value == "Region"
assert props.address_attributes.get("PostalCode").string_value == "PostalCode"
assert props.address_attributes.get("Country").string_value == "Country"
assert len(props.address_lines) == 2
assert props.address_lines[0].name == "Address"
assert props.address_lines[1].name == "Lines"
def test_importing_a_postal_address_twice(self):
self.test_importing_a_postal_address()
ifc = tool.Ifc().get()
address = ifc.createIfcPostalAddress()
address.Purpose = "OFFICE"
subject().set_address(address)
subject().import_attributes()
props = bpy.context.scene.BIMOwnerProperties
assert props.address_attributes.get("Purpose").enum_value == "OFFICE"
assert len(props.address_lines) == 0
def test_importing_a_telecom_address(self):
ifc = ifcopenshell.file()
tool.Ifc().set(ifc)
address = ifc.createIfcTelecomAddress()
address.Purpose = "USERDEFINED"
address.Description = "Description"
address.UserDefinedPurpose = "UserDefinedPurpose"
address.TelephoneNumbers = ["Telephone", "Numbers"]
address.FacsimileNumbers = ["Facsimile", "Numbers"]
address.PagerNumber = "PagerNumber"
address.ElectronicMailAddresses = ["Electronic", "Mail", "Addresses"]
address.WWWHomePageURL = "WWWHomePageURL"
address.MessagingIDs = ["Messaging", "IDs"]
subject().set_address(address)
subject().import_attributes()
props = bpy.context.scene.BIMOwnerProperties
assert props.address_attributes.get("Purpose").enum_value == "USERDEFINED"
assert props.address_attributes.get("Description").string_value == "Description"
assert props.address_attributes.get("UserDefinedPurpose").string_value == "UserDefinedPurpose"
assert [a.name for a in props.telephone_numbers] == ["Telephone", "Numbers"]
assert [a.name for a in props.facsimile_numbers] == ["Facsimile", "Numbers"]
assert [a.name for a in props.electronic_mail_addresses] == ["Electronic", "Mail", "Addresses"]
assert [a.name for a in props.messaging_ids] == ["Messaging", "IDs"]
def test_importing_a_telecom_address_twice(self):
self.test_importing_a_telecom_address()
ifc = tool.Ifc().get()
address = ifc.createIfcTelecomAddress()
address.Purpose = "OFFICE"
subject().set_address(address)
subject().import_attributes()
props = bpy.context.scene.BIMOwnerProperties
assert props.address_attributes.get("Purpose").enum_value == "OFFICE"
assert len(props.telephone_numbers) == 0
assert len(props.facsimile_numbers) == 0
assert len(props.electronic_mail_addresses) == 0
assert len(props.messaging_ids) == 0
class TestClearAddress(test.bim.bootstrap.NewFile):
def test_run(self):
ifc = ifcopenshell.file()
address = ifc.createIfcPostalAddress()
subject().set_address(address)
subject().clear_address()
assert bpy.context.scene.BIMOwnerProperties.active_address_id == 0
class TestGetAddress(test.bim.bootstrap.NewFile):
def test_run(self):
ifc = ifcopenshell.file()
tool.Ifc().set(ifc)
address = ifc.createIfcPostalAddress()
subject().set_address(address)
assert subject().get_address() == address
class TestExportAttributes(test.bim.bootstrap.NewFile):
def test_exporting_a_postal_address(self):
TestImportAttributes().test_importing_a_postal_address()
assert subject().export_attributes() == {
"Purpose": "USERDEFINED",
"Description": "Description",
"UserDefinedPurpose": "UserDefinedPurpose",
"InternalLocation": "InternalLocation",
"AddressLines": ["Address", "Lines"],
"PostalBox": "PostalBox",
"Town": "Town",
"Region": "Region",
"PostalCode": "PostalCode",
"Country": "Country",
}
def test_exporting_a_telecom_address(self):
TestImportAttributes().test_importing_a_telecom_address()
assert subject().export_attributes() == {
"Purpose": "USERDEFINED",
"Description": "Description",
"UserDefinedPurpose": "UserDefinedPurpose",
"TelephoneNumbers": ["Telephone", "Numbers"],
"FacsimileNumbers": ["Facsimile", "Numbers"],
"PagerNumber": "PagerNumber",
"ElectronicMailAddresses": ["Electronic", "Mail", "Addresses"],
"WWWHomePageURL": "WWWHomePageURL",
"MessagingIDs": ["Messaging", "IDs"],
}
class TestAddAttribute(test.bim.bootstrap.NewFile):
def test_run(self):
subject().add_attribute("AddressLines")
subject().add_attribute("TelephoneNumbers")
subject().add_attribute("FacsimileNumbers")
subject().add_attribute("ElectronicMailAddresses")
subject().add_attribute("MessagingIDs")
props = bpy.context.scene.BIMOwnerProperties
assert len(props.address_lines) == 1
assert len(props.telephone_numbers) == 1
assert len(props.facsimile_numbers) == 1
assert len(props.electronic_mail_addresses) == 1
assert len(props.messaging_ids) == 1
class TestRemoveAddress(test.bim.bootstrap.NewFile):
TestAddAttribute().test_run()
subject().remove_attribute("AddressLines", 0)
subject().remove_attribute("TelephoneNumbers", 0)
subject().remove_attribute("FacsimileNumbers", 0)
subject().remove_attribute("ElectronicMailAddresses", 0)
subject().remove_attribute("MessagingIDs", 0)
props = bpy.context.scene.BIMOwnerProperties
assert len(props.address_lines) == 0
assert len(props.telephone_numbers) == 0
assert len(props.facsimile_numbers) == 0
assert len(props.electronic_mail_addresses) == 0
assert len(props.messaging_ids) == 0
@@ -1,14 +1,32 @@
# BlenderBIM Add-on - OpenBIM Blender Add-on
# Copyright (C) 2021 Dion Moult <dion@thinkmoult.com>
#
# This file is part of BlenderBIM Add-on.
#
# BlenderBIM Add-on is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# BlenderBIM Add-on 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 General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with BlenderBIM Add-on. If not, see <http://www.gnu.org/licenses/>.
import bpy
import ifcopenshell
import blenderbim.core.tool
import blenderbim.tool as tool
from test.bim.bootstrap import NewFile
from blenderbim.tool.aggregator import Aggregator as subject
from blenderbim.tool.aggregate import Aggregate as subject
class TestImplementsTool(NewFile):
def test_run(self):
assert isinstance(subject(), blenderbim.core.tool.Aggregator)
assert isinstance(subject(), blenderbim.core.tool.Aggregate)
class TestEnableEditing(NewFile):
@@ -21,12 +21,12 @@ import ifcopenshell
import test.bim.bootstrap
import blenderbim.core.tool
import blenderbim.tool as tool
from blenderbim.tool.context_editor import ContextEditor as subject
from blenderbim.tool.context import Context as subject
class TestImplementsTool(test.bim.bootstrap.NewFile):
def test_run(self):
assert isinstance(subject(), blenderbim.core.tool.ContextEditor)
assert isinstance(subject(), blenderbim.core.tool.Context)
class TestSetContext(test.bim.bootstrap.NewFile):
@@ -1,94 +0,0 @@
# BlenderBIM Add-on - OpenBIM Blender Add-on
# Copyright (C) 2021 Dion Moult <dion@thinkmoult.com>
#
# This file is part of BlenderBIM Add-on.
#
# BlenderBIM Add-on is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# BlenderBIM Add-on 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 General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with BlenderBIM Add-on. If not, see <http://www.gnu.org/licenses/>.
import bpy
import ifcopenshell
import test.bim.bootstrap
import blenderbim.core.tool
import blenderbim.tool as tool
from blenderbim.tool.organisation_editor import OrganisationEditor as subject
class TestImplementsTool(test.bim.bootstrap.NewFile):
def test_run(self):
assert isinstance(subject(), blenderbim.core.tool.OrganisationEditor)
class TestSetOrganisation(test.bim.bootstrap.NewFile):
def test_run(self):
organisation = ifcopenshell.file().createIfcOrganization()
subject().set_organisation(organisation)
assert bpy.context.scene.BIMOwnerProperties.active_organisation_id == organisation.id()
class TestImportAttributes(test.bim.bootstrap.NewFile):
def test_run(self):
ifc = ifcopenshell.file()
tool.Ifc().set(ifc)
organisation = ifc.createIfcOrganization()
organisation.Identification = "Identification"
organisation.Name = "Name"
organisation.Description = "Description"
subject().set_organisation(organisation)
subject().import_attributes()
props = bpy.context.scene.BIMOwnerProperties
assert props.organisation_attributes.get("Identification").string_value == "Identification"
assert props.organisation_attributes.get("Name").string_value == "Name"
assert props.organisation_attributes.get("Description").string_value == "Description"
def test_overwriting_a_previous_import(self):
ifc = ifcopenshell.file()
tool.Ifc().set(ifc)
organisation = ifc.createIfcOrganization()
organisation.Identification = "Identification"
organisation.Description = "Description"
subject().set_organisation(organisation)
subject().import_attributes()
organisation.Identification = "Identification2"
organisation.Description = None
subject().import_attributes()
props = bpy.context.scene.BIMOwnerProperties
assert props.organisation_attributes.get("Identification").string_value == "Identification2"
assert props.organisation_attributes.get("Description").string_value == ""
class TestClearOrganisation(test.bim.bootstrap.NewFile):
def test_run(self):
props = bpy.context.scene.BIMOwnerProperties
props.active_organisation_id = 1
subject().clear_organisation()
assert props.active_organisation_id == 0
class TestExportAttributes(test.bim.bootstrap.NewFile):
def test_run(self):
TestImportAttributes().test_run()
assert subject().export_attributes() == {
"Identification": "Identification",
"Name": "Name",
"Description": "Description",
}
class TestGetOrganisation(test.bim.bootstrap.NewFile):
def test_run(self):
ifc = ifcopenshell.file()
tool.Ifc().set(ifc)
organisation = ifc.createIfcOrganization()
subject().set_organisation(organisation)
assert subject().get_organisation() == organisation
+425
View File
@@ -51,3 +51,428 @@ class TestClearUser(test.bim.bootstrap.NewFile):
TestSetUser().test_run()
subject.clear_user()
assert bpy.context.scene.BIMOwnerProperties.active_user_id == 0
class TestSetAddress(test.bim.bootstrap.NewFile):
def test_run(self):
ifc = ifcopenshell.file()
address = ifc.createIfcPostalAddress()
subject().set_address(address)
assert bpy.context.scene.BIMOwnerProperties.active_address_id == address.id()
class TestImportAddressAttributes(test.bim.bootstrap.NewFile):
def test_importing_a_postal_address(self):
ifc = ifcopenshell.file()
tool.Ifc().set(ifc)
address = ifc.createIfcPostalAddress()
address.Purpose = "USERDEFINED"
address.Description = "Description"
address.UserDefinedPurpose = "UserDefinedPurpose"
address.InternalLocation = "InternalLocation"
address.AddressLines = ["Address", "Lines"]
address.PostalBox = "PostalBox"
address.Town = "Town"
address.Region = "Region"
address.PostalCode = "PostalCode"
address.Country = "Country"
subject().set_address(address)
subject().import_address_attributes()
props = bpy.context.scene.BIMOwnerProperties
assert props.address_attributes.get("Purpose").enum_value == "USERDEFINED"
assert props.address_attributes.get("Description").string_value == "Description"
assert props.address_attributes.get("UserDefinedPurpose").string_value == "UserDefinedPurpose"
assert props.address_attributes.get("InternalLocation").string_value == "InternalLocation"
assert props.address_attributes.get("PostalBox").string_value == "PostalBox"
assert props.address_attributes.get("Town").string_value == "Town"
assert props.address_attributes.get("Region").string_value == "Region"
assert props.address_attributes.get("PostalCode").string_value == "PostalCode"
assert props.address_attributes.get("Country").string_value == "Country"
assert len(props.address_lines) == 2
assert props.address_lines[0].name == "Address"
assert props.address_lines[1].name == "Lines"
def test_importing_a_postal_address_twice(self):
self.test_importing_a_postal_address()
ifc = tool.Ifc().get()
address = ifc.createIfcPostalAddress()
address.Purpose = "OFFICE"
subject().set_address(address)
subject().import_address_attributes()
props = bpy.context.scene.BIMOwnerProperties
assert props.address_attributes.get("Purpose").enum_value == "OFFICE"
assert len(props.address_lines) == 0
def test_importing_a_telecom_address(self):
ifc = ifcopenshell.file()
tool.Ifc().set(ifc)
address = ifc.createIfcTelecomAddress()
address.Purpose = "USERDEFINED"
address.Description = "Description"
address.UserDefinedPurpose = "UserDefinedPurpose"
address.TelephoneNumbers = ["Telephone", "Numbers"]
address.FacsimileNumbers = ["Facsimile", "Numbers"]
address.PagerNumber = "PagerNumber"
address.ElectronicMailAddresses = ["Electronic", "Mail", "Addresses"]
address.WWWHomePageURL = "WWWHomePageURL"
address.MessagingIDs = ["Messaging", "IDs"]
subject().set_address(address)
subject().import_address_attributes()
props = bpy.context.scene.BIMOwnerProperties
assert props.address_attributes.get("Purpose").enum_value == "USERDEFINED"
assert props.address_attributes.get("Description").string_value == "Description"
assert props.address_attributes.get("UserDefinedPurpose").string_value == "UserDefinedPurpose"
assert [a.name for a in props.telephone_numbers] == ["Telephone", "Numbers"]
assert [a.name for a in props.facsimile_numbers] == ["Facsimile", "Numbers"]
assert [a.name for a in props.electronic_mail_addresses] == ["Electronic", "Mail", "Addresses"]
assert [a.name for a in props.messaging_ids] == ["Messaging", "IDs"]
def test_importing_a_telecom_address_twice(self):
self.test_importing_a_telecom_address()
ifc = tool.Ifc().get()
address = ifc.createIfcTelecomAddress()
address.Purpose = "OFFICE"
subject().set_address(address)
subject().import_address_attributes()
props = bpy.context.scene.BIMOwnerProperties
assert props.address_attributes.get("Purpose").enum_value == "OFFICE"
assert len(props.telephone_numbers) == 0
assert len(props.facsimile_numbers) == 0
assert len(props.electronic_mail_addresses) == 0
assert len(props.messaging_ids) == 0
class TestClearAddress(test.bim.bootstrap.NewFile):
def test_run(self):
ifc = ifcopenshell.file()
address = ifc.createIfcPostalAddress()
subject().set_address(address)
subject().clear_address()
assert bpy.context.scene.BIMOwnerProperties.active_address_id == 0
class TestGetAddress(test.bim.bootstrap.NewFile):
def test_run(self):
ifc = ifcopenshell.file()
tool.Ifc().set(ifc)
address = ifc.createIfcPostalAddress()
subject().set_address(address)
assert subject().get_address() == address
class TestExportAttributes(test.bim.bootstrap.NewFile):
def test_exporting_a_postal_address(self):
TestImportAddressAttributes().test_importing_a_postal_address()
assert subject().export_address_attributes() == {
"Purpose": "USERDEFINED",
"Description": "Description",
"UserDefinedPurpose": "UserDefinedPurpose",
"InternalLocation": "InternalLocation",
"AddressLines": ["Address", "Lines"],
"PostalBox": "PostalBox",
"Town": "Town",
"Region": "Region",
"PostalCode": "PostalCode",
"Country": "Country",
}
def test_exporting_a_telecom_address(self):
TestImportAddressAttributes().test_importing_a_telecom_address()
assert subject().export_address_attributes() == {
"Purpose": "USERDEFINED",
"Description": "Description",
"UserDefinedPurpose": "UserDefinedPurpose",
"TelephoneNumbers": ["Telephone", "Numbers"],
"FacsimileNumbers": ["Facsimile", "Numbers"],
"PagerNumber": "PagerNumber",
"ElectronicMailAddresses": ["Electronic", "Mail", "Addresses"],
"WWWHomePageURL": "WWWHomePageURL",
"MessagingIDs": ["Messaging", "IDs"],
}
class TestAddAddressAttribute(test.bim.bootstrap.NewFile):
def test_run(self):
subject().add_address_attribute("AddressLines")
subject().add_address_attribute("TelephoneNumbers")
subject().add_address_attribute("FacsimileNumbers")
subject().add_address_attribute("ElectronicMailAddresses")
subject().add_address_attribute("MessagingIDs")
props = bpy.context.scene.BIMOwnerProperties
assert len(props.address_lines) == 1
assert len(props.telephone_numbers) == 1
assert len(props.facsimile_numbers) == 1
assert len(props.electronic_mail_addresses) == 1
assert len(props.messaging_ids) == 1
class TestRemoveAddressAttribute(test.bim.bootstrap.NewFile):
TestAddAddressAttribute().test_run()
subject().remove_address_attribute("AddressLines", 0)
subject().remove_address_attribute("TelephoneNumbers", 0)
subject().remove_address_attribute("FacsimileNumbers", 0)
subject().remove_address_attribute("ElectronicMailAddresses", 0)
subject().remove_address_attribute("MessagingIDs", 0)
props = bpy.context.scene.BIMOwnerProperties
assert len(props.address_lines) == 0
assert len(props.telephone_numbers) == 0
assert len(props.facsimile_numbers) == 0
assert len(props.electronic_mail_addresses) == 0
assert len(props.messaging_ids) == 0
class TestSetOrganisation(test.bim.bootstrap.NewFile):
def test_run(self):
organisation = ifcopenshell.file().createIfcOrganization()
subject().set_organisation(organisation)
assert bpy.context.scene.BIMOwnerProperties.active_organisation_id == organisation.id()
class TestImportOrganisationAttributes(test.bim.bootstrap.NewFile):
def test_run(self):
ifc = ifcopenshell.file()
tool.Ifc().set(ifc)
organisation = ifc.createIfcOrganization()
organisation.Identification = "Identification"
organisation.Name = "Name"
organisation.Description = "Description"
subject().set_organisation(organisation)
subject().import_organisation_attributes()
props = bpy.context.scene.BIMOwnerProperties
assert props.organisation_attributes.get("Identification").string_value == "Identification"
assert props.organisation_attributes.get("Name").string_value == "Name"
assert props.organisation_attributes.get("Description").string_value == "Description"
def test_overwriting_a_previous_import(self):
ifc = ifcopenshell.file()
tool.Ifc().set(ifc)
organisation = ifc.createIfcOrganization()
organisation.Identification = "Identification"
organisation.Description = "Description"
subject().set_organisation(organisation)
subject().import_organisation_attributes()
organisation.Identification = "Identification2"
organisation.Description = None
subject().import_organisation_attributes()
props = bpy.context.scene.BIMOwnerProperties
assert props.organisation_attributes.get("Identification").string_value == "Identification2"
assert props.organisation_attributes.get("Description").string_value == ""
class TestClearOrganisation(test.bim.bootstrap.NewFile):
def test_run(self):
props = bpy.context.scene.BIMOwnerProperties
props.active_organisation_id = 1
subject().clear_organisation()
assert props.active_organisation_id == 0
class TestExportOrganisationAttributes(test.bim.bootstrap.NewFile):
def test_run(self):
TestImportOrganisationAttributes().test_run()
assert subject().export_organisation_attributes() == {
"Identification": "Identification",
"Name": "Name",
"Description": "Description",
}
class TestGetOrganisation(test.bim.bootstrap.NewFile):
def test_run(self):
ifc = ifcopenshell.file()
tool.Ifc().set(ifc)
organisation = ifc.createIfcOrganization()
subject().set_organisation(organisation)
assert subject().get_organisation() == organisation
class TestSetPerson(test.bim.bootstrap.NewFile):
def test_run(self):
person = ifcopenshell.file().createIfcPerson()
subject().set_person(person)
assert bpy.context.scene.BIMOwnerProperties.active_person_id == person.id()
class TestImportPersonAttributes(test.bim.bootstrap.NewFile):
def test_run(self):
ifc = ifcopenshell.file()
tool.Ifc().set(ifc)
person = ifc.createIfcPerson()
person.Identification = "identification"
person.GivenName = "given_name"
person.FamilyName = "family_name"
person.MiddleNames = ("middle", "names")
person.PrefixTitles = ("prefix", "titles")
person.SuffixTitles = ("suffix", "titles")
subject().set_person(person)
subject().import_person_attributes()
props = bpy.context.scene.BIMOwnerProperties
assert props.person_attributes.get("Identification").string_value == "identification"
assert props.person_attributes.get("GivenName").string_value == "given_name"
assert props.person_attributes.get("FamilyName").string_value == "family_name"
assert len(props.middle_names) == 2
assert props.middle_names[0].name == "middle"
assert props.middle_names[1].name == "names"
assert len(props.prefix_titles) == 2
assert props.prefix_titles[0].name == "prefix"
assert props.prefix_titles[1].name == "titles"
assert len(props.suffix_titles) == 2
assert props.suffix_titles[0].name == "suffix"
assert props.suffix_titles[1].name == "titles"
def test_overwriting_a_previous_import(self):
ifc = ifcopenshell.file()
tool.Ifc().set(ifc)
person = ifc.createIfcPerson()
person.Identification = "identification"
person.GivenName = "given_name"
subject().set_person(person)
subject().import_person_attributes()
person.Identification = "identification2"
person.GivenName = None
subject().import_person_attributes()
props = bpy.context.scene.BIMOwnerProperties
assert props.person_attributes.get("Identification").string_value == "identification2"
assert props.person_attributes.get("GivenName").string_value == ""
class TestClearPerson(test.bim.bootstrap.NewFile):
def test_run(self):
props = bpy.context.scene.BIMOwnerProperties
props.active_person_id = 1
subject().clear_person()
assert props.active_person_id == 0
class TestExportPersonAttributes(test.bim.bootstrap.NewFile):
def test_run(self):
ifc = ifcopenshell.file()
tool.Ifc().set(ifc)
person = ifc.createIfcPerson()
person.Identification = "identification"
person.GivenName = "given_name"
person.FamilyName = "family_name"
person.MiddleNames = ("middle", "names")
person.PrefixTitles = ("prefix", "titles")
person.SuffixTitles = ("suffix", "titles")
subject().set_person(person)
subject().import_person_attributes()
assert subject().export_person_attributes() == {
"Identification": "identification",
"GivenName": "given_name",
"FamilyName": "family_name",
"MiddleNames": ["middle", "names"],
"PrefixTitles": ["prefix", "titles"],
"SuffixTitles": ["suffix", "titles"],
}
def test_getting_empty_list_attributes_as_none(self):
ifc = ifcopenshell.file()
tool.Ifc().set(ifc)
result = subject().export_person_attributes()
assert result["MiddleNames"] is None
assert result["PrefixTitles"] is None
assert result["SuffixTitles"] is None
class TestGetPerson(test.bim.bootstrap.NewFile):
def test_run(self):
ifc = ifcopenshell.file()
tool.Ifc().set(ifc)
person = ifc.createIfcPerson()
subject().set_person(person)
assert subject().get_person() == person
class TestAddPersonAttribute(test.bim.bootstrap.NewFile):
def test_run(self):
subject().add_person_attribute("MiddleNames")
subject().add_person_attribute("PrefixTitles")
subject().add_person_attribute("SuffixTitles")
props = bpy.context.scene.BIMOwnerProperties
assert len(props.middle_names) == 1
assert len(props.prefix_titles) == 1
assert len(props.suffix_titles) == 1
class TestRemovePersonAttribute(test.bim.bootstrap.NewFile):
def test_run(self):
subject().add_person_attribute("MiddleNames")
subject().remove_person_attribute("MiddleNames", 0)
subject().add_person_attribute("PrefixTitles")
subject().remove_person_attribute("PrefixTitles", 0)
subject().add_person_attribute("SuffixTitles")
subject().remove_person_attribute("SuffixTitles", 0)
props = bpy.context.scene.BIMOwnerProperties
assert len(props.middle_names) == 0
assert len(props.prefix_titles) == 0
assert len(props.suffix_titles) == 0
class TestSetRole(test.bim.bootstrap.NewFile):
def test_run(self):
role = ifcopenshell.file().createIfcActorRole()
subject().set_role(role)
assert bpy.context.scene.BIMOwnerProperties.active_role_id == role.id()
class TestImportRoleAttributes(test.bim.bootstrap.NewFile):
def test_run(self):
ifc = ifcopenshell.file()
tool.Ifc().set(ifc)
role = ifc.createIfcActorRole()
role.Role = "USERDEFINED"
role.UserDefinedRole = "UserDefinedRole"
role.Description = "Description"
subject().set_role(role)
subject().import_role_attributes()
props = bpy.context.scene.BIMOwnerProperties
assert props.role_attributes.get("Role").enum_value == "USERDEFINED"
assert props.role_attributes.get("UserDefinedRole").string_value == "UserDefinedRole"
assert props.role_attributes.get("Description").string_value == "Description"
def test_importing_twice(self):
ifc = ifcopenshell.file()
tool.Ifc().set(ifc)
role = ifc.createIfcActorRole()
role.Role = "USERDEFINED"
subject().set_role(role)
subject().import_role_attributes()
role.Role = "ARCHITECT"
subject().import_role_attributes()
props = bpy.context.scene.BIMOwnerProperties
assert props.role_attributes.get("Role").enum_value == "ARCHITECT"
class TestClearRole(test.bim.bootstrap.NewFile):
def test_run(self):
role = ifcopenshell.file().createIfcActorRole()
subject().set_role(role)
subject().clear_role()
assert bpy.context.scene.BIMOwnerProperties.active_role_id == 0
class TestGetRole(test.bim.bootstrap.NewFile):
def test_run(self):
ifc = ifcopenshell.file()
tool.Ifc().set(ifc)
role = ifc.createIfcActorRole()
subject().set_role(role)
assert subject().get_role() == role
class TestExportRoleAttributes(test.bim.bootstrap.NewFile):
def test_run(self):
ifc = ifcopenshell.file()
tool.Ifc().set(ifc)
role = ifc.createIfcActorRole()
role.Role = "USERDEFINED"
role.UserDefinedRole = "UserDefinedRole"
role.Description = "Description"
subject().set_role(role)
subject().import_role_attributes()
assert subject().export_role_attributes() == {
"Role": "USERDEFINED",
"UserDefinedRole": "UserDefinedRole",
"Description": "Description",
}
@@ -1,152 +0,0 @@
# BlenderBIM Add-on - OpenBIM Blender Add-on
# Copyright (C) 2021 Dion Moult <dion@thinkmoult.com>
#
# This file is part of BlenderBIM Add-on.
#
# BlenderBIM Add-on is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# BlenderBIM Add-on 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 General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with BlenderBIM Add-on. If not, see <http://www.gnu.org/licenses/>.
import bpy
import ifcopenshell
import test.bim.bootstrap
import blenderbim.core.tool
import blenderbim.tool as tool
from blenderbim.tool.person_editor import PersonEditor as subject
class TestImplementsTool(test.bim.bootstrap.NewFile):
def test_run(self):
assert isinstance(subject(), blenderbim.core.tool.PersonEditor)
class TestSetPerson(test.bim.bootstrap.NewFile):
def test_run(self):
person = ifcopenshell.file().createIfcPerson()
subject().set_person(person)
assert bpy.context.scene.BIMOwnerProperties.active_person_id == person.id()
class TestImportAttributes(test.bim.bootstrap.NewFile):
def test_run(self):
ifc = ifcopenshell.file()
tool.Ifc().set(ifc)
person = ifc.createIfcPerson()
person.Identification = "identification"
person.GivenName = "given_name"
person.FamilyName = "family_name"
person.MiddleNames = ("middle", "names")
person.PrefixTitles = ("prefix", "titles")
person.SuffixTitles = ("suffix", "titles")
subject().set_person(person)
subject().import_attributes()
props = bpy.context.scene.BIMOwnerProperties
assert props.person_attributes.get("Identification").string_value == "identification"
assert props.person_attributes.get("GivenName").string_value == "given_name"
assert props.person_attributes.get("FamilyName").string_value == "family_name"
assert len(props.middle_names) == 2
assert props.middle_names[0].name == "middle"
assert props.middle_names[1].name == "names"
assert len(props.prefix_titles) == 2
assert props.prefix_titles[0].name == "prefix"
assert props.prefix_titles[1].name == "titles"
assert len(props.suffix_titles) == 2
assert props.suffix_titles[0].name == "suffix"
assert props.suffix_titles[1].name == "titles"
def test_overwriting_a_previous_import(self):
ifc = ifcopenshell.file()
tool.Ifc().set(ifc)
person = ifc.createIfcPerson()
person.Identification = "identification"
person.GivenName = "given_name"
subject().set_person(person)
subject().import_attributes()
person.Identification = "identification2"
person.GivenName = None
subject().import_attributes()
props = bpy.context.scene.BIMOwnerProperties
assert props.person_attributes.get("Identification").string_value == "identification2"
assert props.person_attributes.get("GivenName").string_value == ""
class TestClearPerson(test.bim.bootstrap.NewFile):
def test_run(self):
props = bpy.context.scene.BIMOwnerProperties
props.active_person_id = 1
subject().clear_person()
assert props.active_person_id == 0
class TestExportAttributes(test.bim.bootstrap.NewFile):
def test_run(self):
ifc = ifcopenshell.file()
tool.Ifc().set(ifc)
person = ifc.createIfcPerson()
person.Identification = "identification"
person.GivenName = "given_name"
person.FamilyName = "family_name"
person.MiddleNames = ("middle", "names")
person.PrefixTitles = ("prefix", "titles")
person.SuffixTitles = ("suffix", "titles")
subject().set_person(person)
subject().import_attributes()
assert subject().export_attributes() == {
"Identification": "identification",
"GivenName": "given_name",
"FamilyName": "family_name",
"MiddleNames": ["middle", "names"],
"PrefixTitles": ["prefix", "titles"],
"SuffixTitles": ["suffix", "titles"],
}
def test_getting_empty_list_attributes_as_none(self):
ifc = ifcopenshell.file()
tool.Ifc().set(ifc)
result = subject().export_attributes()
assert result["MiddleNames"] is None
assert result["PrefixTitles"] is None
assert result["SuffixTitles"] is None
class TestGetPerson(test.bim.bootstrap.NewFile):
def test_run(self):
ifc = ifcopenshell.file()
tool.Ifc().set(ifc)
person = ifc.createIfcPerson()
subject().set_person(person)
assert subject().get_person() == person
class TestAddAttribute(test.bim.bootstrap.NewFile):
def test_run(self):
subject().add_attribute("MiddleNames")
subject().add_attribute("PrefixTitles")
subject().add_attribute("SuffixTitles")
props = bpy.context.scene.BIMOwnerProperties
assert len(props.middle_names) == 1
assert len(props.prefix_titles) == 1
assert len(props.suffix_titles) == 1
class TestRemoveAttribute(test.bim.bootstrap.NewFile):
def test_run(self):
subject().add_attribute("MiddleNames")
subject().remove_attribute("MiddleNames", 0)
subject().add_attribute("PrefixTitles")
subject().remove_attribute("PrefixTitles", 0)
subject().add_attribute("SuffixTitles")
subject().remove_attribute("SuffixTitles", 0)
props = bpy.context.scene.BIMOwnerProperties
assert len(props.middle_names) == 0
assert len(props.prefix_titles) == 0
assert len(props.suffix_titles) == 0
@@ -1,98 +0,0 @@
# BlenderBIM Add-on - OpenBIM Blender Add-on
# Copyright (C) 2021 Dion Moult <dion@thinkmoult.com>
#
# This file is part of BlenderBIM Add-on.
#
# BlenderBIM Add-on is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# BlenderBIM Add-on 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 General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with BlenderBIM Add-on. If not, see <http://www.gnu.org/licenses/>.
import bpy
import ifcopenshell
import test.bim.bootstrap
import blenderbim.core.tool
import blenderbim.tool as tool
from blenderbim.tool.role_editor import RoleEditor as subject
class TestImplementsTool(test.bim.bootstrap.NewFile):
def test_run(self):
assert isinstance(subject(), blenderbim.core.tool.RoleEditor)
class TestSetRole(test.bim.bootstrap.NewFile):
def test_run(self):
role = ifcopenshell.file().createIfcActorRole()
subject().set_role(role)
assert bpy.context.scene.BIMOwnerProperties.active_role_id == role.id()
class TestImportAttributes(test.bim.bootstrap.NewFile):
def test_run(self):
ifc = ifcopenshell.file()
tool.Ifc().set(ifc)
role = ifc.createIfcActorRole()
role.Role = "USERDEFINED"
role.UserDefinedRole = "UserDefinedRole"
role.Description = "Description"
subject().set_role(role)
subject().import_attributes()
props = bpy.context.scene.BIMOwnerProperties
assert props.role_attributes.get("Role").enum_value == "USERDEFINED"
assert props.role_attributes.get("UserDefinedRole").string_value == "UserDefinedRole"
assert props.role_attributes.get("Description").string_value == "Description"
def test_importing_twice(self):
ifc = ifcopenshell.file()
tool.Ifc().set(ifc)
role = ifc.createIfcActorRole()
role.Role = "USERDEFINED"
subject().set_role(role)
subject().import_attributes()
role.Role = "ARCHITECT"
subject().import_attributes()
props = bpy.context.scene.BIMOwnerProperties
assert props.role_attributes.get("Role").enum_value == "ARCHITECT"
class TestClearRole(test.bim.bootstrap.NewFile):
def test_run(self):
role = ifcopenshell.file().createIfcActorRole()
subject().set_role(role)
subject().clear_role()
assert bpy.context.scene.BIMOwnerProperties.active_role_id == 0
class TestGetRole(test.bim.bootstrap.NewFile):
def test_run(self):
ifc = ifcopenshell.file()
tool.Ifc().set(ifc)
role = ifc.createIfcActorRole()
subject().set_role(role)
assert subject().get_role() == role
class TestExportAttributes(test.bim.bootstrap.NewFile):
def test_run(self):
ifc = ifcopenshell.file()
tool.Ifc().set(ifc)
role = ifc.createIfcActorRole()
role.Role = "USERDEFINED"
role.UserDefinedRole = "UserDefinedRole"
role.Description = "Description"
subject().set_role(role)
subject().import_attributes()
assert subject().export_attributes() == {
"Role": "USERDEFINED",
"UserDefinedRole": "UserDefinedRole",
"Description": "Description",
}
+183
View File
@@ -0,0 +1,183 @@
# BlenderBIM Add-on - OpenBIM Blender Add-on
# Copyright (C) 2021 Dion Moult <dion@thinkmoult.com>
#
# This file is part of BlenderBIM Add-on.
#
# BlenderBIM Add-on is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# BlenderBIM Add-on 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 General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with BlenderBIM Add-on. If not, see <http://www.gnu.org/licenses/>.
import bpy
import ifcopenshell
import blenderbim.core.tool
import blenderbim.tool as tool
from test.bim.bootstrap import NewFile
from blenderbim.tool.style import Style as subject
class TestImplementsTool(NewFile):
def test_run(self):
assert isinstance(subject(), blenderbim.core.tool.Style)
class TestDisableEditing(NewFile):
def test_run(self):
obj = bpy.data.materials.new("Material")
obj.BIMStyleProperties.is_editing = True
subject.disable_editing(obj)
assert obj.BIMStyleProperties.is_editing is False
class TestEnableEditing(NewFile):
def test_run(self):
obj = bpy.data.materials.new("Material")
subject.enable_editing(obj)
assert obj.BIMStyleProperties.is_editing is True
class TestExportSurfaceAttributes(NewFile):
def test_run(self):
TestImportSurfaceAttributes().test_run()
obj = bpy.data.materials.get("Material")
assert subject.export_surface_attributes(obj) == {"Name": "Name", "Side": "BOTH"}
class TestGetContext(NewFile):
def test_run(self):
bpy.ops.bim.create_project()
context = ifcopenshell.util.representation.get_context(tool.Ifc.get(), "Model", "Body", "MODEL_VIEW")
assert subject.get_context("obj") == context
class TestGetName(NewFile):
def test_run(self):
assert subject.get_name(bpy.data.materials.new("Material")) == "Material"
class TestGetStyle(NewFile):
def test_getting_no_style(self):
assert subject.get_style(bpy.data.materials.new("Material")) is None
def test_getting_a_linked_style(self):
tool.Ifc.set(ifcopenshell.file())
style = tool.Ifc.get().createIfcSurfaceStyle()
obj = bpy.data.materials.new("Material")
obj.BIMMaterialProperties.ifc_style_id = style.id()
assert subject.get_style(obj) == style
class TestGetSurfaceRenderingAttributes(NewFile):
def test_get_colours_from_a_basic_material(self):
obj = bpy.data.materials.new("Material")
obj.diffuse_color = [1, 1, 1, 1]
assert subject.get_surface_rendering_attributes(obj) == {
"SurfaceColour": {
"Name": None,
"Red": 1,
"Green": 1,
"Blue": 1,
},
"Transparency": 0,
"DiffuseColour": {
"Name": None,
"Red": 1,
"Green": 1,
"Blue": 1,
},
}
def test_get_different_surface_and_diffuse_colours_from_a_node_based_material(self):
obj = bpy.data.materials.new("Material")
obj.diffuse_color = [1, 1, 1, 1]
obj.use_nodes = True
node = obj.node_tree.nodes["Principled BSDF"]
node.inputs["Alpha"].default_value = 0.8
node.inputs["Base Color"].default_value = [0.5, 0.5, 0.5, 0.5]
assert subject.get_surface_rendering_attributes(obj) == {
"SurfaceColour": {
"Name": None,
"Red": 1,
"Green": 1,
"Blue": 1,
},
"Transparency": 1 - node.inputs["Alpha"].default_value,
"DiffuseColour": {
"Name": None,
"Red": 1,
"Green": 1,
"Blue": 1,
},
}
class TestGetSurfaceRenderingStyle(NewFile):
def test_run(self):
tool.Ifc.set(ifcopenshell.file())
style_item = tool.Ifc.get().createIfcSurfaceStyleRendering()
style = tool.Ifc.get().createIfcSurfaceStyle(Styles=[style_item])
obj = bpy.data.materials.new("Material")
obj.BIMMaterialProperties.ifc_style_id = style.id()
assert subject.get_surface_rendering_style(obj) == style_item
class TestGetSurfaceShadingAttributes(NewFile):
def test_get_colours_from_a_basic_material(self):
obj = bpy.data.materials.new("Material")
obj.diffuse_color = [1, 1, 1, 1]
assert subject.get_surface_shading_attributes(obj) == {
"SurfaceColour": {
"Name": None,
"Red": 1,
"Green": 1,
"Blue": 1,
},
"Transparency": 0,
}
class TestGetSurfaceShadingStyle(NewFile):
def test_run(self):
tool.Ifc.set(ifcopenshell.file())
style_item = tool.Ifc.get().createIfcSurfaceStyleShading()
style = tool.Ifc.get().createIfcSurfaceStyle(Styles=[style_item])
obj = bpy.data.materials.new("Material")
obj.BIMMaterialProperties.ifc_style_id = style.id()
assert subject.get_surface_shading_style(obj) == style_item
class TestImportSurfaceAttributes(NewFile):
def test_run(self):
ifc = ifcopenshell.file()
style = ifc.createIfcSurfaceStyle("Name", "BOTH")
obj = bpy.data.materials.new("Material")
subject.import_surface_attributes(style, obj)
assert obj.BIMStyleProperties.attributes.get("Name").string_value == "Name"
assert obj.BIMStyleProperties.attributes.get("Side").enum_value == "BOTH"
class TestLink(NewFile):
def test_run(self):
obj = bpy.data.materials.new("Material")
ifc = ifcopenshell.file()
style = ifc.createIfcSurfaceStyle()
subject.link(style, obj)
assert obj.BIMMaterialProperties.ifc_style_id == style.id()
class TestUnlink(NewFile):
def test_run(self):
obj = bpy.data.materials.new("Material")
ifc = ifcopenshell.file()
style = ifc.createIfcSurfaceStyle()
subject.link(style, obj)
subject.unlink(obj)
assert obj.BIMMaterialProperties.ifc_style_id == 0