Redesigned document UI to handle hierarchical documents and make it easier to reference

This commit is contained in:
Dion Moult
2022-03-15 14:48:59 +11:00
parent 233e73f9f6
commit 38b708ff1f
12 changed files with 485 additions and 296 deletions
@@ -0,0 +1,112 @@
@document
Feature: Document
Scenario: Load project documents
Given an empty IFC project
When I press "bim.load_project_documents"
Then nothing happens
Scenario: Load document
Given an empty IFC project
And I press "bim.load_project_documents"
And I press "bim.add_information"
And the variable "information" is "{ifc}.by_type('IfcDocumentInformation')[-1].id()"
When I press "bim.load_document(document={information})"
Then nothing happens
Scenario: Load parent document
Given an empty IFC project
And I press "bim.load_project_documents"
And I press "bim.add_information"
And the variable "information" is "{ifc}.by_type('IfcDocumentInformation')[-1].id()"
And I press "bim.load_document(document={information})"
When I press "bim.load_parent_document"
Then nothing happens
Scenario: Disable document editing UI
Given an empty IFC project
And I press "bim.load_project_documents"
When I press "bim.disable_document_editing_ui"
Then nothing happens
Scenario: Enable editing document
Given an empty IFC project
And I press "bim.load_project_documents"
And I press "bim.add_information"
And the variable "information" is "{ifc}.by_type('IfcDocumentInformation')[-1].id()"
When I press "bim.enable_editing_document(document={information})"
Then nothing happens
Scenario: Disable editing document
Given an empty IFC project
And I press "bim.load_project_documents"
And I press "bim.add_information"
And the variable "information" is "{ifc}.by_type('IfcDocumentInformation')[-1].id()"
And I press "bim.enable_editing_document(document={information})"
When I press "bim.disable_editing_document"
Then nothing happens
Scenario: Add information
Given an empty IFC project
And I press "bim.load_project_documents"
When I press "bim.add_information"
Then nothing happens
Scenario: Add document reference
Given an empty IFC project
And I press "bim.load_project_documents"
And I press "bim.add_information"
And the variable "information" is "{ifc}.by_type('IfcDocumentInformation')[-1].id()"
And I press "bim.load_document(document={information})"
When I press "bim.add_document_reference"
Then nothing happens
Scenario: Edit document
Given an empty IFC project
And I press "bim.load_project_documents"
And I press "bim.add_information"
And the variable "information" is "{ifc}.by_type('IfcDocumentInformation')[-1].id()"
And I press "bim.enable_editing_document(document={information})"
When I press "bim.edit_document"
Then nothing happens
Scenario: Remove document
Given an empty IFC project
And I press "bim.load_project_documents"
And I press "bim.add_information"
And the variable "information" is "{ifc}.by_type('IfcDocumentInformation')[-1].id()"
When I press "bim.remove_document(document={information})"
Then nothing happens
Scenario: Assign document
Given an empty IFC project
And I press "bim.load_project_documents"
And I press "bim.add_information"
And the variable "information" is "{ifc}.by_type('IfcDocumentInformation')[-1].id()"
And I press "bim.load_document(document={information})"
And I press "bim.add_document_reference"
And the variable "reference" is "{ifc}.by_type('IfcDocumentReference')[-1].id()"
And I add a cube
And the object "Cube" is selected
And I set "scene.BIMRootProperties.ifc_product" to "IfcElement"
And I set "scene.BIMRootProperties.ifc_class" to "IfcWall"
And I press "bim.assign_class"
When I press "bim.assign_document(document={reference})"
Then nothing happens
Scenario: Unassign document
Given an empty IFC project
And I press "bim.load_project_documents"
And I press "bim.add_information"
And the variable "information" is "{ifc}.by_type('IfcDocumentInformation')[-1].id()"
And I press "bim.load_document(document={information})"
And I press "bim.add_document_reference"
And the variable "reference" is "{ifc}.by_type('IfcDocumentReference')[-1].id()"
And I add a cube
And the object "Cube" is selected
And I set "scene.BIMRootProperties.ifc_product" to "IfcElement"
And I set "scene.BIMRootProperties.ifc_class" to "IfcWall"
And I press "bim.assign_class"
And I press "bim.assign_document(document={reference})"
When I press "bim.unassign_document(document={reference})"
Then nothing happens
+55 -50
View File
@@ -21,20 +21,23 @@ import blenderbim.core.document as subject
from test.core.bootstrap import ifc, document
class TestLoadInformation:
class TestLoadProjectDocuments:
def test_run(self, document):
document.import_information().should_be_called()
document.enable_information_editing_ui().should_be_called()
document.disable_editing_document().should_be_called()
subject.load_information(document)
document.clear_document_tree().should_be_called()
document.import_project_documents().should_be_called()
document.clear_breadcrumbs().should_be_called()
document.enable_editing_ui().should_be_called()
subject.load_project_documents(document)
class TestLoadReferences:
class TestLoadDocument:
def test_run(self, document):
document.import_references().should_be_called()
document.enable_reference_editing_ui().should_be_called()
document.clear_document_tree().should_be_called()
document.import_subdocuments("document").should_be_called()
document.import_references("document").should_be_called()
document.disable_editing_document().should_be_called()
subject.load_references(document)
document.add_breadcrumb("document").should_be_called()
subject.load_document(document, document="document")
class TestDisableDocumentEditingUi:
@@ -58,72 +61,74 @@ class TestDisableEditingDocument:
class TestAddInformation:
def test_run(self, ifc, document):
ifc.run("document.add_information").should_be_called().will_return("information")
document.import_information().should_be_called()
document.import_document_attributes("information").should_be_called()
document.set_active_document("information").should_be_called()
def test_add_and_reload_tree_at_project_root(self, ifc, document):
document.clear_document_tree().should_be_called()
document.get_active_breadcrumb().should_be_called().will_return(None)
ifc.run("document.add_information", parent=None).should_be_called()
document.import_project_documents().should_be_called()
subject.add_information(ifc, document)
def test_add_and_reload_tree_at_current_parent(self, ifc, document):
document.clear_document_tree().should_be_called()
document.get_active_breadcrumb().should_be_called().will_return("parent")
ifc.run("document.add_information", parent="parent").should_be_called()
document.import_subdocuments("parent").should_be_called()
document.import_references("parent").should_be_called()
subject.add_information(ifc, document)
class TestAddReference:
def test_run(self, ifc, document):
ifc.run("document.add_reference").should_be_called().will_return("reference")
document.import_references().should_be_called()
document.import_document_attributes("reference").should_be_called()
document.set_active_document("reference").should_be_called()
document.get_active_breadcrumb().should_be_called().will_return("parent")
ifc.run("document.add_reference", information="parent").should_be_called()
document.clear_document_tree().should_be_called()
document.import_subdocuments("parent").should_be_called()
document.import_references("parent").should_be_called()
subject.add_reference(ifc, document)
class TestEditInformation:
def test_run(self, ifc, document):
class TestEditDocument:
def test_edit_information(self, ifc, document):
document.export_document_attributes().should_be_called().will_return("attributes")
ifc.run("document.edit_information", information="information", attributes="attributes").should_be_called()
document.is_document_information("document").should_be_called().will_return(True)
ifc.run("document.edit_information", information="document", attributes="attributes").should_be_called()
document.disable_editing_document().should_be_called()
document.import_information().should_be_called()
subject.edit_information(ifc, document, information="information")
document.clear_document_tree().should_be_called()
document.get_active_breadcrumb().should_be_called().will_return(None)
document.import_project_documents().should_be_called()
subject.edit_document(ifc, document, document="document")
class TestEditInformation:
def test_run(self, ifc, document):
def test_edit_reference(self, ifc, document):
document.export_document_attributes().should_be_called().will_return("attributes")
ifc.run("document.edit_reference", reference="reference", attributes="attributes").should_be_called()
document.is_document_information("document").should_be_called().will_return(False)
ifc.run("document.edit_reference", reference="document", attributes="attributes").should_be_called()
document.disable_editing_document().should_be_called()
document.import_references().should_be_called()
subject.edit_reference(ifc, document, reference="reference")
document.clear_document_tree().should_be_called()
document.get_active_breadcrumb().should_be_called().will_return("parent")
document.import_subdocuments("parent").should_be_called()
document.import_references("parent").should_be_called()
subject.edit_document(ifc, document, document="document")
class TestRemoveDocument:
def test_remove_information(self, ifc, document):
document.clear_document_tree().should_be_called()
document.is_document_information("document").should_be_called().will_return(True)
ifc.run("document.remove_document", document="document").should_be_called()
document.import_information().should_be_called()
document.disable_editing_document().should_be_called()
ifc.run("document.remove_information", information="document").should_be_called()
document.get_active_breadcrumb().should_be_called().will_return(None)
document.import_project_documents().should_be_called()
subject.remove_document(ifc, document, document="document")
def test_remove_reference(self, ifc, document):
document.clear_document_tree().should_be_called()
document.is_document_information("document").should_be_called().will_return(False)
ifc.run("document.remove_document", document="document").should_be_called()
document.import_references().should_be_called()
document.disable_editing_document().should_be_called()
ifc.run("document.remove_reference", reference="document").should_be_called()
document.get_active_breadcrumb().should_be_called().will_return("parent")
document.import_subdocuments("parent").should_be_called()
document.import_references("parent").should_be_called()
subject.remove_document(ifc, document, document="document")
class TestEnableAssigningDocument:
def test_run(self, document):
document.import_references().should_be_called()
document.enable_reference_editing_ui().should_be_called()
document.disable_editing_document().should_be_called()
document.enable_document_assignment_ui("obj").should_be_called()
subject.enable_assigning_document(document, obj="obj")
class TestDisableAssigningDocument:
def test_run(self, document):
document.disable_document_assignment_ui("obj").should_be_called()
subject.disable_assigning_document(document, obj="obj")
class TestAssignDocument:
def test_run(self, ifc):
ifc.run("document.assign_document", product="product", document="document").should_be_called()
+77 -35
View File
@@ -29,12 +29,30 @@ class TestImplementsTool(NewFile):
assert isinstance(subject(), blenderbim.core.tool.Document)
class TestDisableDocumentAssignmentUI(NewFile):
class TestAddBreadcrumb(NewFile):
def test_run(self):
obj = bpy.data.objects.new("Object", None)
obj.BIMObjectDocumentProperties.is_adding = "foo"
subject.disable_document_assignment_ui(obj)
assert obj.BIMObjectDocumentProperties.is_adding == ""
ifc = ifcopenshell.file()
tool.Ifc().set(ifc)
document = ifc.createIfcDocumentInformation()
subject.add_breadcrumb(document)
props = bpy.context.scene.BIMDocumentProperties
assert props.breadcrumbs[0].name == str(document.id())
class TestClearBreadcrumbs(NewFile):
def test_run(self):
props = bpy.context.scene.BIMDocumentProperties
props.breadcrumbs.add()
subject.clear_breadcrumbs()
assert len(props.breadcrumbs) == 0
class TestClearDocumentTree(NewFile):
def test_run(self):
props = bpy.context.scene.BIMDocumentProperties
new = props.documents.add()
subject.clear_document_tree()
assert len(props.documents) == 0
class TestDisableEditingDocument(NewFile):
@@ -46,31 +64,16 @@ class TestDisableEditingDocument(NewFile):
class TestDisableEditingUI(NewFile):
def test_run(self):
bpy.context.scene.BIMDocumentProperties.is_editing = "is_editing"
bpy.context.scene.BIMDocumentProperties.is_editing = True
subject.disable_editing_ui()
assert bpy.context.scene.BIMDocumentProperties.is_editing == ""
assert bpy.context.scene.BIMDocumentProperties.is_editing == False
class TestEnableDocumentAssignmentUI(NewFile):
class TestEnableEditingUI(NewFile):
def test_run(self):
obj = bpy.data.objects.new("Object", None)
obj.BIMObjectDocumentProperties.is_adding = ""
subject.enable_document_assignment_ui(obj)
assert obj.BIMObjectDocumentProperties.is_adding == "IfcDocumentReference"
class TestEnableInformationEditingUI(NewFile):
def test_run(self):
bpy.context.scene.BIMDocumentProperties.is_editing = ""
subject.enable_information_editing_ui()
assert bpy.context.scene.BIMDocumentProperties.is_editing == "information"
class TestEnableReferenceEditingUI(NewFile):
def test_run(self):
bpy.context.scene.BIMDocumentProperties.is_editing = ""
subject.enable_reference_editing_ui()
assert bpy.context.scene.BIMDocumentProperties.is_editing == "reference"
bpy.context.scene.BIMDocumentProperties.is_editing = False
subject.enable_editing_ui()
assert bpy.context.scene.BIMDocumentProperties.is_editing == True
class TestExportDocumentAttributes(NewFile):
@@ -95,6 +98,15 @@ class TestExportDocumentAttributes(NewFile):
}
class TestGetActiveBreadcrumb(NewFile):
def test_run(self):
ifc = ifcopenshell.file()
tool.Ifc().set(ifc)
document = ifc.createIfcDocumentInformation()
subject.add_breadcrumb(document)
assert subject.get_active_breadcrumb() == document
class TestImportDocumentAttributes(NewFile):
def test_importing_information(self):
ifc = ifcopenshell.file()
@@ -149,30 +161,51 @@ class TestImportDocumentAttributes(NewFile):
assert props.document_attributes.get("Description").string_value == "Description"
class TestImportInformation(NewFile):
class TestImportProjectDocuments(NewFile):
def test_run(self):
ifc = ifcopenshell.file()
tool.Ifc().set(ifc)
document = ifc.createIfcDocumentInformation()
subject.import_information()
ifc.createIfcProject()
document = ifcopenshell.api.run("document.add_information", ifc)
subject.import_project_documents()
props = bpy.context.scene.BIMDocumentProperties
assert len(props.documents) == 1
assert props.documents[0].ifc_definition_id == document.id()
assert props.documents[0].name == "Unnamed"
assert props.documents[0].identification == "*"
assert props.documents[0].identification == "X"
assert props.documents[0].is_information is True
class TestImportReference(NewFile):
class TestImportReferences(NewFile):
def test_run(self):
ifc = ifcopenshell.file()
tool.Ifc().set(ifc)
document = ifc.createIfcDocumentReference()
subject.import_references()
ifc.createIfcProject()
document = ifcopenshell.api.run("document.add_information", ifc)
reference = ifcopenshell.api.run("document.add_reference", ifc, information=document)
subject.import_references(document)
props = bpy.context.scene.BIMDocumentProperties
assert len(props.documents) == 1
assert props.documents[0].ifc_definition_id == document.id()
assert props.documents[0].ifc_definition_id == reference.id()
assert props.documents[0].name == "Unnamed"
assert props.documents[0].identification == "*"
assert props.documents[0].identification == "X"
assert props.documents[0].is_information is False
class TestImportSubdocuments(NewFile):
def test_run(self):
ifc = ifcopenshell.file()
tool.Ifc().set(ifc)
ifc.createIfcProject()
document = ifcopenshell.api.run("document.add_information", ifc)
subdocument = ifcopenshell.api.run("document.add_information", ifc, parent=document)
subject.import_subdocuments(document)
props = bpy.context.scene.BIMDocumentProperties
assert len(props.documents) == 1
assert props.documents[0].ifc_definition_id == subdocument.id()
assert props.documents[0].name == "Unnamed"
assert props.documents[0].identification == "X"
assert props.documents[0].is_information is True
class TestIsDocumentInformation(NewFile):
@@ -184,6 +217,15 @@ class TestIsDocumentInformation(NewFile):
assert subject.is_document_information(reference) is False
class TestRemoveLatestBreadcrumb(NewFile):
def test_run(self):
props = bpy.context.scene.BIMDocumentProperties
props.breadcrumbs.add()
props.breadcrumbs.add()
subject.remove_latest_breadcrumb()
assert len(props.breadcrumbs) == 1
class TestSetActiveDocument(NewFile):
def test_run(self):
ifc = ifcopenshell.file()