New UI to add / edit / remove library information and references.

This commit is contained in:
Dion Moult
2021-11-16 22:15:54 +11:00
parent 468192e849
commit fae607f8ce
16 changed files with 961 additions and 2 deletions
@@ -0,0 +1,105 @@
@library
Feature: Library
Scenario: Add library
Given an empty IFC project
When I press "bim.add_library"
Then nothing happens
Scenario: Remove library
Given an empty IFC project
And I press "bim.add_library"
And the variable "library" is "{ifc}.by_type('IfcLibraryInformation')[-1].id()"
When I press "bim.remove_library(library={library})"
Then nothing happens
Scenario: Enable editing library references
Given an empty IFC project
And I press "bim.add_library"
And the variable "library" is "{ifc}.by_type('IfcLibraryInformation')[-1].id()"
When I press "bim.enable_editing_library_references(library={library})"
Then nothing happens
Scenario: Disable editing library references
Given an empty IFC project
And I press "bim.add_library"
And the variable "library" is "{ifc}.by_type('IfcLibraryInformation')[-1].id()"
And I press "bim.enable_editing_library_references(library={library})"
When I press "bim.disable_editing_library_references"
Then nothing happens
Scenario: Enable editing library
Given an empty IFC project
And I press "bim.add_library"
And the variable "library" is "{ifc}.by_type('IfcLibraryInformation')[-1].id()"
And I press "bim.enable_editing_library_references(library={library})"
When I press "bim.enable_editing_library"
Then nothing happens
Scenario: Disable editing library
Given an empty IFC project
And I press "bim.add_library"
And the variable "library" is "{ifc}.by_type('IfcLibraryInformation')[-1].id()"
And I press "bim.enable_editing_library_references(library={library})"
And I press "bim.enable_editing_library"
When I press "bim.disable_editing_library"
Then nothing happens
Scenario: Edit library
Given an empty IFC project
And I press "bim.add_library"
And the variable "library" is "{ifc}.by_type('IfcLibraryInformation')[-1].id()"
And I press "bim.enable_editing_library_references(library={library})"
And I press "bim.enable_editing_library"
When I press "bim.edit_library"
Then nothing happens
Scenario: Add library reference
Given an empty IFC project
And I press "bim.add_library"
And the variable "library" is "{ifc}.by_type('IfcLibraryInformation')[-1].id()"
And I press "bim.enable_editing_library_references(library={library})"
When I press "bim.add_library_reference"
Then nothing happens
Scenario: Remove library reference
Given an empty IFC project
And I press "bim.add_library"
And the variable "library" is "{ifc}.by_type('IfcLibraryInformation')[-1].id()"
And I press "bim.enable_editing_library_references(library={library})"
And I press "bim.add_library_reference"
And the variable "reference" is "{ifc}.by_type('IfcLibraryReference')[-1].id()"
When I press "bim.remove_library_reference(reference={reference})"
Then nothing happens
Scenario: Enable editing library reference
Given an empty IFC project
And I press "bim.add_library"
And the variable "library" is "{ifc}.by_type('IfcLibraryInformation')[-1].id()"
And I press "bim.enable_editing_library_references(library={library})"
And I press "bim.add_library_reference"
And the variable "reference" is "{ifc}.by_type('IfcLibraryReference')[-1].id()"
When I press "bim.enable_editing_library_reference(reference={reference})"
Then nothing happens
Scenario: Disable editing library reference
Given an empty IFC project
And I press "bim.add_library"
And the variable "library" is "{ifc}.by_type('IfcLibraryInformation')[-1].id()"
And I press "bim.enable_editing_library_references(library={library})"
And I press "bim.add_library_reference"
And the variable "reference" is "{ifc}.by_type('IfcLibraryReference')[-1].id()"
And I press "bim.enable_editing_library_reference(reference={reference})"
When I press "bim.disable_editing_library_reference()"
Then nothing happens
Scenario: Edit library reference
Given an empty IFC project
And I press "bim.add_library"
And the variable "library" is "{ifc}.by_type('IfcLibraryInformation')[-1].id()"
And I press "bim.enable_editing_library_references(library={library})"
And I press "bim.add_library_reference"
And the variable "reference" is "{ifc}.by_type('IfcLibraryReference')[-1].id()"
And I press "bim.enable_editing_library_reference(reference={reference})"
When I press "bim.edit_library_reference()"
Then nothing happens
+7
View File
@@ -77,6 +77,13 @@ def geometry():
prophet.verify()
@pytest.fixture
def library():
prophet = Prophecy(blenderbim.core.tool.Library)
yield prophet
prophet.verify()
@pytest.fixture
def material():
prophet = Prophecy(blenderbim.core.tool.Material)
+111
View File
@@ -0,0 +1,111 @@
# 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.library as subject
from test.core.bootstrap import ifc, library
class TestAddLibrary:
def test_run(self, ifc):
ifc.run("library.add_library", name="Unnamed").should_be_called().will_return("library")
assert subject.add_library(ifc) == "library"
class TestRemoveLibrary:
def test_run(self, ifc):
ifc.run("library.remove_library", library="library").should_be_called()
subject.remove_library(ifc, library="library")
class TestEnableEditingLibraryReferences:
def test_run(self, library):
library.set_editing_mode("REFERENCES").should_be_called()
library.set_active_library("library").should_be_called()
library.import_references("library").should_be_called()
subject.enable_editing_library_references(library, library="library")
class TestDisableEditingLibraryReferences:
def test_run(self, library):
library.clear_editing_mode().should_be_called()
subject.disable_editing_library_references(library)
class TestEnableEditingLibrary:
def test_run(self, library):
library.set_editing_mode("LIBRARY").should_be_called()
library.get_active_library().should_be_called().will_return("library")
library.import_library_attributes("library").should_be_called()
subject.enable_editing_library(library)
class TestDisableEditingLibrary:
def test_run(self, library):
library.set_editing_mode("REFERENCES").should_be_called()
subject.disable_editing_library(library)
class TestEditLibrary:
def test_run(self, ifc, library):
library.set_editing_mode("REFERENCES").should_be_called()
library.get_active_library().should_be_called().will_return("library")
library.export_library_attributes().should_be_called().will_return("attributes")
ifc.run("library.edit_library", library="library", attributes="attributes").should_be_called()
library.import_references("library").should_be_called()
subject.edit_library(ifc, library)
class TestAddLibraryReference:
def test_run(self, ifc, library):
library.get_active_library().should_be_called().will_return("library")
ifc.run("library.add_reference", library="library").should_be_called()
library.import_references("library").should_be_called()
subject.add_library_reference(ifc, library)
class TestRemoveLibraryReference:
def test_run(self, ifc, library):
ifc.run("library.remove_reference", reference="reference").should_be_called()
library.get_active_library().should_be_called().will_return("library")
library.import_references("library").should_be_called()
subject.remove_library_reference(ifc, library, reference="reference")
class TestEnableEditingLibraryReference:
def test_run(self, library):
library.set_editing_mode("REFERENCE").should_be_called()
library.set_active_reference("reference").should_be_called()
library.import_reference_attributes("reference").should_be_called()
subject.enable_editing_library_reference(library, reference="reference")
class TestDisableEditingLibraryReference:
def test_run(self, library):
library.set_editing_mode("REFERENCES").should_be_called()
subject.disable_editing_library_reference(library)
class TestEditLibraryReference:
def test_run(self, ifc, library):
library.set_editing_mode("REFERENCES").should_be_called()
library.get_active_reference().should_be_called().will_return("reference")
library.export_reference_attributes().should_be_called().will_return("attributes")
ifc.run("library.edit_reference", reference="reference", attributes="attributes").should_be_called()
library.get_active_library().should_be_called().will_return("library")
library.import_references("library").should_be_called()
subject.edit_library_reference(ifc, library)
+134
View File
@@ -0,0 +1,134 @@
# 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.library import Library as subject
class TestImplementsTool(NewFile):
def test_run(self):
assert isinstance(subject(), blenderbim.core.tool.Library)
class TestClearEditingMode(NewFile):
def test_run(self):
props = bpy.context.scene.BIMLibraryProperties
props.editing_mode = "foo"
subject.clear_editing_mode()
assert props.editing_mode == ""
class TestExportLibraryAttributes(NewFile):
def test_run(self):
TestImportLibraryAttributes().test_run()
assert subject.export_library_attributes() == {
"Name": "Name",
"Version": "Version",
"VersionDate": "VersionDate",
"Location": "Location",
"Description": "Description",
}
class TestExportReferenceAttributes(NewFile):
def test_run(self):
TestImportReferenceAttributes().test_run()
assert subject.export_reference_attributes() == {
"Location": "Location",
"Identification": "Identification",
"Name": "Name",
"Description": "Description",
"Language": "Language",
}
class TestGetActiveLibrary(NewFile):
def test_run(self):
TestSetActiveLibrary().test_run()
assert subject.get_active_library().is_a("IfcLibraryInformation")
class TestGetActiveReference(NewFile):
def test_run(self):
TestSetActiveReference().test_run()
assert subject.get_active_reference().is_a("IfcLibraryReference")
class TestImportLibraryAttributes(NewFile):
def test_run(self):
ifc = ifcopenshell.file()
library = ifc.createIfcLibraryInformation("Name", "Version", None, "VersionDate", "Location", "Description")
subject.import_library_attributes(library)
props = bpy.context.scene.BIMLibraryProperties
assert props.library_attributes.get("Name").string_value == "Name"
assert props.library_attributes.get("Version").string_value == "Version"
assert props.library_attributes.get("VersionDate").string_value == "VersionDate"
assert props.library_attributes.get("Location").string_value == "Location"
assert props.library_attributes.get("Description").string_value == "Description"
class TestImportReferenceAttributes(NewFile):
def test_run(self):
ifc = ifcopenshell.file()
reference = ifc.createIfcLibraryReference("Location", "Identification", "Name", "Description", "Language")
subject.import_reference_attributes(reference)
props = bpy.context.scene.BIMLibraryProperties
assert props.reference_attributes.get("Location").string_value == "Location"
assert props.reference_attributes.get("Identification").string_value == "Identification"
assert props.reference_attributes.get("Name").string_value == "Name"
assert props.reference_attributes.get("Description").string_value == "Description"
assert props.reference_attributes.get("Language").string_value == "Language"
class TestImportReferences(NewFile):
def test_run(self):
ifc = ifcopenshell.file()
library = ifc.createIfcLibraryInformation()
reference = ifc.createIfcLibraryReference(Name="Reference", ReferencedLibrary=library)
subject.import_references(library)
props = bpy.context.scene.BIMLibraryProperties
assert props.references[0].ifc_definition_id == reference.id()
assert props.references[0].name == "Reference"
class TestSetActiveLibrary(NewFile):
def test_run(self):
ifc = ifcopenshell.file()
tool.Ifc.set(ifc)
library = ifc.createIfcLibraryInformation()
subject.set_active_library(library)
assert bpy.context.scene.BIMLibraryProperties.active_library_id == library.id()
class TestSetActiveReference(NewFile):
def test_run(self):
ifc = ifcopenshell.file()
tool.Ifc.set(ifc)
reference = ifc.createIfcLibraryReference()
subject.set_active_reference(reference)
assert bpy.context.scene.BIMLibraryProperties.active_reference_id == reference.id()
class TestSetEditingMode(NewFile):
def test_run(self):
subject.set_editing_mode("FOO")
assert bpy.context.scene.BIMLibraryProperties.editing_mode == "FOO"