mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-08-10 09:48:32 +00:00
Refactor and re-use common spatial_tool.select_products
This commit is contained in:
@@ -56,7 +56,7 @@ class SelectByMaterial(bpy.types.Operator, tool.Ifc.Operator):
|
||||
material: bpy.props.IntProperty()
|
||||
|
||||
def _execute(self, context):
|
||||
core.select_by_material(tool.Material, material=tool.Ifc.get().by_id(self.material))
|
||||
core.select_by_material(tool.Material, tool.Spatial, material=tool.Ifc.get().by_id(self.material))
|
||||
|
||||
|
||||
class EnableEditingMaterial(bpy.types.Operator, tool.Ifc.Operator):
|
||||
|
||||
@@ -332,4 +332,4 @@ class SelectByStyle(bpy.types.Operator, tool.Ifc.Operator):
|
||||
style: bpy.props.IntProperty()
|
||||
|
||||
def _execute(self, context):
|
||||
core.select_by_style(tool.Style, style=tool.Ifc.get().by_id(self.style))
|
||||
core.select_by_style(tool.Style, tool.Spatial, style=tool.Ifc.get().by_id(self.style))
|
||||
|
||||
@@ -140,7 +140,7 @@ class ShowPorts(bpy.types.Operator, Operator):
|
||||
bl_options = {"REGISTER", "UNDO"}
|
||||
|
||||
def _execute(self, context):
|
||||
core.show_ports(tool.Ifc, tool.System, element=tool.Ifc.get_entity(context.active_object))
|
||||
core.show_ports(tool.Ifc, tool.System, tool.Spatial, element=tool.Ifc.get_entity(context.active_object))
|
||||
|
||||
|
||||
class HidePorts(bpy.types.Operator, Operator):
|
||||
|
||||
@@ -70,13 +70,15 @@ def disable_editing_materials(material):
|
||||
material.disable_editing_materials()
|
||||
|
||||
|
||||
def select_by_material(material_tool, material=None):
|
||||
material_tool.select_elements(material_tool.get_elements_by_material(material))
|
||||
def select_by_material(material_tool, spatial, material=None):
|
||||
spatial.select_products(material_tool.get_elements_by_material(material))
|
||||
|
||||
|
||||
def enable_editing_material(material_tool, material):
|
||||
material_tool.load_material_attributes(material)
|
||||
material_tool.enable_editing_material(material)
|
||||
|
||||
|
||||
def edit_material(ifc, material_tool, material):
|
||||
attributes = material_tool.get_material_attributes()
|
||||
ifc.run("material.edit_material", material=material, attributes=attributes)
|
||||
@@ -85,5 +87,6 @@ def edit_material(ifc, material_tool, material):
|
||||
material_tool.import_material_definitions(material_type)
|
||||
material_tool.enable_editing_materials()
|
||||
|
||||
|
||||
def disable_editing_material(material_tool):
|
||||
material_tool.disable_editing_material()
|
||||
|
||||
@@ -142,5 +142,5 @@ def disable_editing_styles(style):
|
||||
style.disable_editing_styles()
|
||||
|
||||
|
||||
def select_by_style(style_tool, style=None):
|
||||
style_tool.select_elements(style_tool.get_elements_by_style(style))
|
||||
def select_by_style(style_tool, spatial, style=None):
|
||||
spatial.select_products(style_tool.get_elements_by_style(style))
|
||||
|
||||
@@ -66,14 +66,14 @@ def select_system_products(system_tool, system=None):
|
||||
system_tool.select_system_products(system)
|
||||
|
||||
|
||||
def show_ports(ifc, system, element=None):
|
||||
def show_ports(ifc, system, spatial, element=None):
|
||||
obj = ifc.get_object(element)
|
||||
if obj and ifc.is_moved(obj):
|
||||
system.run_geometry_edit_object_placement(obj=obj)
|
||||
|
||||
ports = system.get_ports(element)
|
||||
system.load_ports(element, ports)
|
||||
system.select_elements(ports)
|
||||
spatial.select_products(ports)
|
||||
|
||||
|
||||
def hide_ports(ifc, system, element=None):
|
||||
|
||||
@@ -447,7 +447,6 @@ class Material:
|
||||
def is_editing_materials(cls): pass
|
||||
def is_material_used_in_sets(cls, material): pass
|
||||
def load_material_attributes(cls, material): pass
|
||||
def select_elements(cls, elements): pass
|
||||
|
||||
|
||||
@interface
|
||||
@@ -816,7 +815,6 @@ class Style:
|
||||
def import_surface_attributes(cls, style, obj): pass
|
||||
def is_editing_styles(cls): pass
|
||||
def record_shading(cls, obj): pass
|
||||
def select_elements(cls, elements): pass
|
||||
|
||||
|
||||
@interface
|
||||
@@ -839,7 +837,6 @@ class System:
|
||||
def load_ports(cls, element, ports): pass
|
||||
def run_geometry_edit_object_placement(cls, obj=None): pass
|
||||
def run_root_assign_class(cls, obj=None, ifc_class=None, predefined_type=None, should_add_representation=True, context=None, ifc_representation_class=None): pass
|
||||
def select_elements(cls, elements): pass
|
||||
def select_system_products(cls, system): pass
|
||||
def set_active_system(cls, system): pass
|
||||
|
||||
|
||||
@@ -101,13 +101,6 @@ class Material(blenderbim.core.tool.Material):
|
||||
return True
|
||||
return False
|
||||
|
||||
@classmethod
|
||||
def select_elements(cls, elements):
|
||||
for element in elements:
|
||||
obj = tool.Ifc.get_object(element)
|
||||
if obj:
|
||||
obj.select_set(True)
|
||||
|
||||
@classmethod
|
||||
def get_active_material_type(cls):
|
||||
return bpy.context.scene.BIMMaterialProperties.material_type
|
||||
|
||||
@@ -129,16 +129,10 @@ class System(blenderbim.core.tool.System):
|
||||
ifc_representation_class=ifc_representation_class,
|
||||
)
|
||||
|
||||
@classmethod
|
||||
def select_elements(cls, elements):
|
||||
for element in elements:
|
||||
obj = tool.Ifc.get_object(element)
|
||||
if obj:
|
||||
obj.select_set(True)
|
||||
|
||||
@classmethod
|
||||
def select_system_products(cls, system):
|
||||
cls.select_elements(ifcopenshell.util.system.get_system_elements(system))
|
||||
tool.Spatial.select_products(ifcopenshell.util.system.get_system_elements(system))
|
||||
|
||||
@classmethod
|
||||
def set_active_system(cls, system):
|
||||
|
||||
@@ -17,7 +17,7 @@
|
||||
# along with BlenderBIM Add-on. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
import blenderbim.core.material as subject
|
||||
from test.core.bootstrap import ifc, material, style
|
||||
from test.core.bootstrap import ifc, material, style, spatial
|
||||
|
||||
|
||||
class TestUnlinkMaterial:
|
||||
@@ -158,7 +158,7 @@ class TestDisableEditingMaterials:
|
||||
|
||||
|
||||
class TestSelectByMaterial:
|
||||
def test_run(self, material):
|
||||
def test_run(self, material, spatial):
|
||||
material.get_elements_by_material("material").should_be_called().will_return("elements")
|
||||
material.select_elements("elements").should_be_called()
|
||||
spatial.select_products("elements").should_be_called()
|
||||
subject.select_by_material(material, material="material")
|
||||
|
||||
@@ -17,7 +17,7 @@
|
||||
# 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, material, style
|
||||
from test.core.bootstrap import ifc, material, style, spatial
|
||||
|
||||
|
||||
class TestAddStyle:
|
||||
@@ -212,3 +212,10 @@ class TestDisableEditingStyles:
|
||||
def test_run(self, style):
|
||||
style.disable_editing_styles().should_be_called()
|
||||
subject.disable_editing_styles(style)
|
||||
|
||||
|
||||
class TestSelectByStyle:
|
||||
def test_run(self, style, spatial):
|
||||
style.get_elements_by_style("style").should_be_called().will_return("elements")
|
||||
spatial.select_products("elements").should_be_called()
|
||||
subject.select_by_style(style, style="style")
|
||||
|
||||
@@ -18,7 +18,7 @@
|
||||
|
||||
|
||||
import blenderbim.core.system as subject
|
||||
from test.core.bootstrap import ifc, system
|
||||
from test.core.bootstrap import ifc, system, spatial
|
||||
|
||||
|
||||
class TestLoadSystems:
|
||||
@@ -91,24 +91,24 @@ class TestSelectSystemProducts:
|
||||
|
||||
|
||||
class TestShowPorts:
|
||||
def test_run(self, ifc, system):
|
||||
def test_run(self, ifc, system, spatial):
|
||||
ifc.get_object("element").should_be_called().will_return("obj")
|
||||
ifc.is_moved("obj").should_be_called().will_return(False)
|
||||
|
||||
system.get_ports("element").should_be_called().will_return(["port"])
|
||||
system.load_ports("element", ["port"]).should_be_called()
|
||||
system.select_elements(["port"]).should_be_called()
|
||||
subject.show_ports(ifc, system, element="element")
|
||||
spatial.select_products(["port"]).should_be_called()
|
||||
subject.show_ports(ifc, system, spatial, element="element")
|
||||
|
||||
def test_syncing_locations_if_objects_moved_prior_to_showing_ports(self, ifc, system):
|
||||
def test_syncing_locations_if_objects_moved_prior_to_showing_ports(self, ifc, system, spatial):
|
||||
ifc.get_object("element").should_be_called().will_return("obj")
|
||||
ifc.is_moved("obj").should_be_called().will_return(True)
|
||||
system.run_geometry_edit_object_placement(obj="obj").should_be_called()
|
||||
|
||||
system.get_ports("element").should_be_called().will_return(["port"])
|
||||
system.load_ports("element", ["port"]).should_be_called()
|
||||
system.select_elements(["port"]).should_be_called()
|
||||
subject.show_ports(ifc, system, element="element")
|
||||
spatial.select_products(["port"]).should_be_called()
|
||||
subject.show_ports(ifc, system, spatial, element="element")
|
||||
|
||||
|
||||
class TestHidePorts:
|
||||
|
||||
@@ -170,14 +170,3 @@ class TestIsMaterialUsedInSets(NewFile):
|
||||
material_set_item.Material = material
|
||||
assert subject.is_material_used_in_sets(material) is True
|
||||
|
||||
|
||||
class TestSelectElements(NewFile):
|
||||
def test_run(self):
|
||||
ifc = ifcopenshell.file()
|
||||
tool.Ifc().set(ifc)
|
||||
element = ifcopenshell.api.run("root.create_entity", ifc, ifc_class="IfcPump")
|
||||
obj = bpy.data.objects.new("Object", None)
|
||||
bpy.context.scene.collection.objects.link(obj)
|
||||
tool.Ifc.link(element, obj)
|
||||
subject.select_elements([element])
|
||||
assert obj in bpy.context.selected_objects
|
||||
|
||||
@@ -257,3 +257,15 @@ class TestSetRelativeObjectMatrix(NewFile):
|
||||
matrix[0][3] = 1
|
||||
subject.set_relative_object_matrix(obj, relative_obj, matrix)
|
||||
assert obj.matrix_world[0][3] == 2
|
||||
|
||||
|
||||
class TestSelectProducts(NewFile):
|
||||
def test_select_products(self):
|
||||
ifc = ifcopenshell.file()
|
||||
tool.Ifc.set(ifc)
|
||||
product = ifcopenshell.api.run("root.create_entity", ifc, ifc_class="IfcWall")
|
||||
obj = bpy.data.objects.new("Object", None)
|
||||
bpy.context.scene.collection.objects.link(obj)
|
||||
tool.Ifc.link(product, obj)
|
||||
subject.select_products([product])
|
||||
assert obj in bpy.context.selected_objects
|
||||
@@ -440,15 +440,3 @@ class TestIsEditingStyles(NewFile):
|
||||
subject.is_editing_styles() is False
|
||||
bpy.context.scene.BIMStylesProperties.is_editing = True
|
||||
subject.is_editing_styles() is True
|
||||
|
||||
|
||||
class TestSelectElements(NewFile):
|
||||
def test_run(self):
|
||||
ifc = ifcopenshell.file()
|
||||
tool.Ifc().set(ifc)
|
||||
element = ifcopenshell.api.run("root.create_entity", ifc, ifc_class="IfcPump")
|
||||
obj = bpy.data.objects.new("Object", None)
|
||||
bpy.context.scene.collection.objects.link(obj)
|
||||
tool.Ifc.link(element, obj)
|
||||
subject.select_elements([element])
|
||||
assert obj in bpy.context.selected_objects
|
||||
|
||||
@@ -196,18 +196,6 @@ class TestRunRootAssignClass(NewFile):
|
||||
pass
|
||||
|
||||
|
||||
class TestSelectElements(NewFile):
|
||||
def test_run(self):
|
||||
ifc = ifcopenshell.file()
|
||||
tool.Ifc().set(ifc)
|
||||
element = ifcopenshell.api.run("root.create_entity", ifc, ifc_class="IfcPump")
|
||||
obj = bpy.data.objects.new("Object", None)
|
||||
bpy.context.scene.collection.objects.link(obj)
|
||||
tool.Ifc.link(element, obj)
|
||||
subject.select_elements([element])
|
||||
assert obj in bpy.context.selected_objects
|
||||
|
||||
|
||||
class TestSelectSystemProducts(NewFile):
|
||||
def test_run(self):
|
||||
ifc = ifcopenshell.file()
|
||||
|
||||
Reference in New Issue
Block a user