You can now create new projects starting from a template.

This commit is contained in:
Dion Moult
2022-02-03 18:25:03 +11:00
parent 3e99393895
commit 89d5c44855
13 changed files with 466 additions and 73 deletions
+7
View File
@@ -126,6 +126,13 @@ def patch():
prophet.verify()
@pytest.fixture
def project():
prophet = Prophecy(blenderbim.core.tool.Project)
yield prophet
prophet.verify()
@pytest.fixture
def pset():
prophet = Prophecy(blenderbim.core.tool.Pset)
+156
View File
@@ -0,0 +1,156 @@
# BlenderBIM Add-on - OpenBIM Blender Add-on
# Copyright (C) 2022 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.project as subject
from test.core.bootstrap import ifc, project
class TestCreateProject:
def test_do_nothing_if_a_project_already_exists(self, ifc, project):
ifc.get().should_be_called().will_return("ifc")
subject.create_project(ifc, project, schema="IFC4", template=None)
def test_create_an_ifc4_project(self, ifc, project):
ifc.get().should_be_called().will_return(None)
ifc.run("project.create_file", version="IFC4").should_be_called().will_return("ifc")
ifc.set("ifc").should_be_called()
project.create_empty("My Project").should_be_called().will_return("project")
project.create_empty("My Site").should_be_called().will_return("site")
project.create_empty("My Building").should_be_called().will_return("building")
project.create_empty("My Storey").should_be_called().will_return("storey")
project.run_root_assign_class(obj="project", ifc_class="IfcProject").should_be_called()
project.run_unit_assign_scene_units().should_be_called()
project.run_context_add_context(
context_type="Model", context_identifier="", target_view="", parent=0
).should_be_called().will_return("model")
project.run_context_add_context(
context_type="Model", context_identifier="Body", target_view="MODEL_VIEW", parent="model"
).should_be_called().will_return("body")
project.run_context_add_context(
context_type="Model", context_identifier="Box", target_view="MODEL_VIEW", parent="model"
).should_be_called()
project.run_context_add_context(
context_type="Plan", context_identifier="", target_view="", parent=0
).should_be_called().will_return("plan")
project.run_context_add_context(
context_type="Plan", context_identifier="Annotation", target_view="PLAN_VIEW", parent="plan"
).should_be_called()
project.run_root_assign_class(obj="site", ifc_class="IfcSite", context="body").should_be_called()
project.run_root_assign_class(obj="building", ifc_class="IfcBuilding", context="body").should_be_called()
project.run_root_assign_class(obj="storey", ifc_class="IfcBuildingStorey", context="body").should_be_called()
project.run_aggregate_assign_object(relating_obj="project", related_obj="site").should_be_called()
project.run_aggregate_assign_object(relating_obj="site", related_obj="building").should_be_called()
project.run_aggregate_assign_object(relating_obj="building", related_obj="storey").should_be_called()
project.set_context("body").should_be_called()
subject.create_project(ifc, project, schema="IFC4", template=None)
def test_appending_project_template_types_if_specified(self, ifc, project):
ifc.get().should_be_called().will_return(None)
ifc.run("project.create_file", version="IFC4").should_be_called().will_return("ifc")
ifc.set("ifc").should_be_called()
project.create_empty("My Project").should_be_called().will_return("project")
project.create_empty("My Site").should_be_called().will_return("site")
project.create_empty("My Building").should_be_called().will_return("building")
project.create_empty("My Storey").should_be_called().will_return("storey")
project.run_root_assign_class(obj="project", ifc_class="IfcProject").should_be_called()
project.run_unit_assign_scene_units().should_be_called()
project.run_context_add_context(
context_type="Model", context_identifier="", target_view="", parent=0
).should_be_called().will_return("model")
project.run_context_add_context(
context_type="Model", context_identifier="Body", target_view="MODEL_VIEW", parent="model"
).should_be_called().will_return("body")
project.run_context_add_context(
context_type="Model", context_identifier="Box", target_view="MODEL_VIEW", parent="model"
).should_be_called()
project.run_context_add_context(
context_type="Plan", context_identifier="", target_view="", parent=0
).should_be_called().will_return("plan")
project.run_context_add_context(
context_type="Plan", context_identifier="Annotation", target_view="PLAN_VIEW", parent="plan"
).should_be_called()
project.run_root_assign_class(obj="site", ifc_class="IfcSite", context="body").should_be_called()
project.run_root_assign_class(obj="building", ifc_class="IfcBuilding", context="body").should_be_called()
project.run_root_assign_class(obj="storey", ifc_class="IfcBuildingStorey", context="body").should_be_called()
project.run_aggregate_assign_object(relating_obj="project", related_obj="site").should_be_called()
project.run_aggregate_assign_object(relating_obj="site", related_obj="building").should_be_called()
project.run_aggregate_assign_object(relating_obj="building", related_obj="storey").should_be_called()
project.set_context("body").should_be_called()
project.append_all_types_from_template("template").should_be_called()
subject.create_project(ifc, project, schema="IFC4", template="template")
def test_create_an_ifc2x3_project_with_owner_defaults(self, ifc, project):
ifc.get().should_be_called().will_return(None)
ifc.run("project.create_file", version="IFC2X3").should_be_called().will_return("ifc")
ifc.set("ifc").should_be_called()
project.run_owner_add_person().should_be_called().will_return("person")
project.run_owner_add_organisation().should_be_called().will_return("organisation")
project.run_owner_add_person_and_organisation(
person="person", organisation="organisation"
).should_be_called().will_return("user")
project.run_owner_set_user(user="user").should_be_called()
project.create_empty("My Project").should_be_called().will_return("project")
project.create_empty("My Site").should_be_called().will_return("site")
project.create_empty("My Building").should_be_called().will_return("building")
project.create_empty("My Storey").should_be_called().will_return("storey")
project.run_root_assign_class(obj="project", ifc_class="IfcProject").should_be_called()
project.run_unit_assign_scene_units().should_be_called()
project.run_context_add_context(
context_type="Model", context_identifier="", target_view="", parent=0
).should_be_called().will_return("model")
project.run_context_add_context(
context_type="Model", context_identifier="Body", target_view="MODEL_VIEW", parent="model"
).should_be_called().will_return("body")
project.run_context_add_context(
context_type="Model", context_identifier="Box", target_view="MODEL_VIEW", parent="model"
).should_be_called()
project.run_context_add_context(
context_type="Plan", context_identifier="", target_view="", parent=0
).should_be_called().will_return("plan")
project.run_context_add_context(
context_type="Plan", context_identifier="Annotation", target_view="PLAN_VIEW", parent="plan"
).should_be_called()
project.run_root_assign_class(obj="site", ifc_class="IfcSite", context="body").should_be_called()
project.run_root_assign_class(obj="building", ifc_class="IfcBuilding", context="body").should_be_called()
project.run_root_assign_class(obj="storey", ifc_class="IfcBuildingStorey", context="body").should_be_called()
project.run_aggregate_assign_object(relating_obj="project", related_obj="site").should_be_called()
project.run_aggregate_assign_object(relating_obj="site", related_obj="building").should_be_called()
project.run_aggregate_assign_object(relating_obj="building", related_obj="storey").should_be_called()
project.set_context("body").should_be_called()
subject.create_project(ifc, project, schema="IFC2X3", template=None)
+91
View File
@@ -0,0 +1,91 @@
# 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.project import Project as subject
class TestImplementsTool(NewFile):
def test_run(self):
assert isinstance(subject(), blenderbim.core.tool.Project)
class TestAppendAllTypesFromTemplate(NewFile):
def test_nothing(self):
# TODO refactor
pass
class TestCreateEmpty(NewFile):
def test_run(self):
subject.create_empty("Foobar")
assert bpy.data.objects.get("Foobar")
assert not bpy.data.objects.get("Foobar").data
class TestRunAggregateAssignObject(NewFile):
def test_nothing(self):
pass
class TestRunContextAddContext(NewFile):
def test_nothing(self):
pass
class TestRunOwnerAddOrganisation(NewFile):
def test_nothing(self):
pass
class TestRunOwnerAddPerson(NewFile):
def test_nothing(self):
pass
class TestRunOwnerAddPersonAndOrganisation(NewFile):
def test_nothing(self):
pass
class TestRunOwnerSetUser(NewFile):
def test_nothing(self):
pass
class TestRunAssignClass(NewFile):
def test_nothing(self):
pass
class TestRunUnitAssignSceneUnits(NewFile):
def test_nothing(self):
pass
class TestSetContext(NewFile):
def test_run(self):
ifc = ifcopenshell.file()
tool.Ifc.set(ifc)
context = ifc.createIfcGeometricRepresentationContext()
subject.set_context(context)
assert bpy.context.scene.BIMRootProperties.contexts == str(context.id())