New feature to conveniently add a default material in a blank project when none exists.

This commit is contained in:
Dion Moult
2021-10-21 19:40:10 +11:00
parent a99df36351
commit 0bc849be5a
13 changed files with 54 additions and 11 deletions
@@ -21,6 +21,7 @@ from . import ui, prop, operator
classes = (
operator.AddConstituent,
operator.AddDefaultMaterial,
operator.AddLayer,
operator.AddListItem,
operator.AddMaterial,
@@ -68,6 +68,16 @@ class AssignParameterizedProfile(bpy.types.Operator):
return {"FINISHED"}
class AddDefaultMaterial(bpy.types.Operator, Operator):
bl_idname = "bim.add_default_material"
bl_label = "Add Default Material"
bl_options = {"REGISTER", "UNDO"}
def _execute(self, context):
core.add_default_material(tool.Ifc, tool.Material)
Data.load(IfcStore.get_file())
class AddMaterial(bpy.types.Operator):
bl_idname = "bim.add_material"
bl_label = "Add Material"
@@ -77,8 +77,9 @@ class BIM_PT_object_material(Panel):
self.product_data = Data.products[self.oprops.ifc_definition_id]
if not Data.materials:
row = self.layout.row()
row = self.layout.row(align=True)
row.label(text="No Materials Available")
row.operator("bim.add_default_material", icon="ADD", text="")
return
if self.product_data:
@@ -116,7 +116,6 @@ class AddTypeInstance(bpy.types.Operator):
bpy.ops.bim.assign_class(obj=obj.name, ifc_class=instance_class)
blenderbim.core.type.assign_type(
tool.Ifc,
tool.Geometry,
tool.Type,
element=tool.Ifc.get_entity(obj),
type=tool.Ifc.get().by_id(int(tprops.relating_type)),
@@ -168,9 +168,7 @@ class DumbProfileGenerator:
obj.rotation_euler[2] = math.pi / 2
element = self.file.by_id(obj.BIMObjectProperties.ifc_definition_id)
blenderbim.core.type.assign_type(
tool.Ifc, tool.Geometry, tool.Type, element=tool.Ifc.get_entity(obj), type=self.relating_type
)
blenderbim.core.type.assign_type(tool.Ifc, tool.Type, element=tool.Ifc.get_entity(obj), type=self.relating_type)
profile_set_usage = ifcopenshell.util.element.get_material(element)
blenderbim.core.geometry.add_representation(
tool.Ifc,
@@ -307,9 +307,7 @@ class DumbSlabGenerator:
ifc_class=ifc_class,
ifc_representation_class="IfcExtrudedAreaSolid/IfcArbitraryProfileDefWithVoids",
)
blenderbim.core.type.assign_type(
tool.Ifc, tool.Geometry, tool.Type, element=tool.Ifc.get_entity(obj), type=self.relating_type
)
blenderbim.core.type.assign_type(tool.Ifc, tool.Type, element=tool.Ifc.get_entity(obj), type=self.relating_type)
element = self.file.by_id(obj.BIMObjectProperties.ifc_definition_id)
pset = ifcopenshell.api.run("pset.add_pset", self.file, product=element, name="EPset_Parametric")
ifcopenshell.api.run("pset.edit_pset", self.file, pset=pset, properties={"Engine": "BlenderBIM.DumbLayer3"})
@@ -807,9 +807,7 @@ class DumbWallGenerator:
ifc_representation_class="IfcExtrudedAreaSolid/IfcArbitraryClosedProfileDef",
)
blenderbim.core.type.assign_type(
tool.Ifc, tool.Geometry, tool.Type, element=tool.Ifc.get_entity(obj), type=self.relating_type
)
blenderbim.core.type.assign_type(tool.Ifc, tool.Type, element=tool.Ifc.get_entity(obj), type=self.relating_type)
element = self.file.by_id(obj.BIMObjectProperties.ifc_definition_id)
pset = ifcopenshell.api.run("pset.add_pset", self.file, product=element, name="EPset_Parametric")
ifcopenshell.api.run("pset.edit_pset", self.file, pset=pset, properties={"Engine": "BlenderBIM.DumbLayer2"})
@@ -19,3 +19,9 @@
def unlink_material(material, obj=None):
material.unlink(obj)
def add_default_material(ifc, material):
obj = material.add_default_material_object()
material.link(ifc.run("material.add_material", name="Default"), obj)
return obj
+2
View File
@@ -90,6 +90,8 @@ class Ifc:
@interface
class Material:
def add_default_material_object(cls): pass
def link(cls, element, obj): pass
def unlink(cls, obj): pass
@@ -16,6 +16,7 @@
# 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
@@ -23,6 +24,10 @@ import blenderbim.bim.helper
class Material(blenderbim.core.tool.Material):
@classmethod
def add_default_material_object(cls):
return bpy.data.materials.new("Default")
@classmethod
def link(cls, material, obj):
obj.BIMObjectProperties.ifc_definition_id = material.id()
@@ -1,6 +1,11 @@
@material
Feature: Material
Scenario: Add default material
Given an empty IFC project
When I press "bim.add_default_material"
Then the material "Default" exists
Scenario: Unlink object
Given an empty IFC project
And I add a cube
@@ -24,3 +24,11 @@ class TestUnlinkMaterial:
def test_run(self, material):
material.unlink("obj").should_be_called()
subject.unlink_material(material, obj="obj")
class TestAddDefaultMaterial:
def test_run(self, ifc, material):
material.add_default_material_object().should_be_called().will_return("obj")
ifc.run("material.add_material", name="Default").should_be_called().will_return("material")
material.link("material", "obj").should_be_called()
assert subject.add_default_material(ifc, material) == "obj"
+12
View File
@@ -24,6 +24,18 @@ from test.bim.bootstrap import NewFile
from blenderbim.tool.material import Material as subject
class TestImplementsTool(NewFile):
def test_run(self):
assert isinstance(subject(), blenderbim.core.tool.Material)
class TestAddDefaultMaterialObject(NewFile):
def test_run(self):
material = subject.add_default_material_object()
assert isinstance(material, bpy.types.Material)
assert material.name == "Default"
class TestLink(NewFile):
def test_run(self):
obj = bpy.data.materials.new("Material")