Skip to content

Commit 36fab12

Browse files
committed
Refactor and re-use common spatial_tool.select_products
1 parent 3239313 commit 36fab12

16 files changed

Lines changed: 43 additions & 72 deletions

File tree

src/blenderbim/blenderbim/bim/module/material/operator.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ class SelectByMaterial(bpy.types.Operator, tool.Ifc.Operator):
5656
material: bpy.props.IntProperty()
5757

5858
def _execute(self, context):
59-
core.select_by_material(tool.Material, material=tool.Ifc.get().by_id(self.material))
59+
core.select_by_material(tool.Material, tool.Spatial, material=tool.Ifc.get().by_id(self.material))
6060

6161

6262
class EnableEditingMaterial(bpy.types.Operator, tool.Ifc.Operator):

src/blenderbim/blenderbim/bim/module/style/operator.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -332,4 +332,4 @@ class SelectByStyle(bpy.types.Operator, tool.Ifc.Operator):
332332
style: bpy.props.IntProperty()
333333

334334
def _execute(self, context):
335-
core.select_by_style(tool.Style, style=tool.Ifc.get().by_id(self.style))
335+
core.select_by_style(tool.Style, tool.Spatial, style=tool.Ifc.get().by_id(self.style))

src/blenderbim/blenderbim/bim/module/system/operator.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ class ShowPorts(bpy.types.Operator, Operator):
140140
bl_options = {"REGISTER", "UNDO"}
141141

142142
def _execute(self, context):
143-
core.show_ports(tool.Ifc, tool.System, element=tool.Ifc.get_entity(context.active_object))
143+
core.show_ports(tool.Ifc, tool.System, tool.Spatial, element=tool.Ifc.get_entity(context.active_object))
144144

145145

146146
class HidePorts(bpy.types.Operator, Operator):

src/blenderbim/blenderbim/core/material.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,13 +70,15 @@ def disable_editing_materials(material):
7070
material.disable_editing_materials()
7171

7272

73-
def select_by_material(material_tool, material=None):
74-
material_tool.select_elements(material_tool.get_elements_by_material(material))
73+
def select_by_material(material_tool, spatial, material=None):
74+
spatial.select_products(material_tool.get_elements_by_material(material))
75+
7576

7677
def enable_editing_material(material_tool, material):
7778
material_tool.load_material_attributes(material)
7879
material_tool.enable_editing_material(material)
7980

81+
8082
def edit_material(ifc, material_tool, material):
8183
attributes = material_tool.get_material_attributes()
8284
ifc.run("material.edit_material", material=material, attributes=attributes)
@@ -85,5 +87,6 @@ def edit_material(ifc, material_tool, material):
8587
material_tool.import_material_definitions(material_type)
8688
material_tool.enable_editing_materials()
8789

90+
8891
def disable_editing_material(material_tool):
8992
material_tool.disable_editing_material()

src/blenderbim/blenderbim/core/style.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -142,5 +142,5 @@ def disable_editing_styles(style):
142142
style.disable_editing_styles()
143143

144144

145-
def select_by_style(style_tool, style=None):
146-
style_tool.select_elements(style_tool.get_elements_by_style(style))
145+
def select_by_style(style_tool, spatial, style=None):
146+
spatial.select_products(style_tool.get_elements_by_style(style))

src/blenderbim/blenderbim/core/system.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,14 +66,14 @@ def select_system_products(system_tool, system=None):
6666
system_tool.select_system_products(system)
6767

6868

69-
def show_ports(ifc, system, element=None):
69+
def show_ports(ifc, system, spatial, element=None):
7070
obj = ifc.get_object(element)
7171
if obj and ifc.is_moved(obj):
7272
system.run_geometry_edit_object_placement(obj=obj)
7373

7474
ports = system.get_ports(element)
7575
system.load_ports(element, ports)
76-
system.select_elements(ports)
76+
spatial.select_products(ports)
7777

7878

7979
def hide_ports(ifc, system, element=None):

src/blenderbim/blenderbim/core/tool.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -447,7 +447,6 @@ def import_material_definitions(cls, material_type): pass
447447
def is_editing_materials(cls): pass
448448
def is_material_used_in_sets(cls, material): pass
449449
def load_material_attributes(cls, material): pass
450-
def select_elements(cls, elements): pass
451450

452451

453452
@interface
@@ -816,7 +815,6 @@ def import_presentation_styles(cls, style_type): pass
816815
def import_surface_attributes(cls, style, obj): pass
817816
def is_editing_styles(cls): pass
818817
def record_shading(cls, obj): pass
819-
def select_elements(cls, elements): pass
820818

821819

822820
@interface
@@ -839,7 +837,6 @@ def import_systems(cls): pass
839837
def load_ports(cls, element, ports): pass
840838
def run_geometry_edit_object_placement(cls, obj=None): pass
841839
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
842-
def select_elements(cls, elements): pass
843840
def select_system_products(cls, system): pass
844841
def set_active_system(cls, system): pass
845842

src/blenderbim/blenderbim/tool/material.py

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -101,13 +101,6 @@ def is_material_used_in_sets(cls, material):
101101
return True
102102
return False
103103

104-
@classmethod
105-
def select_elements(cls, elements):
106-
for element in elements:
107-
obj = tool.Ifc.get_object(element)
108-
if obj:
109-
obj.select_set(True)
110-
111104
@classmethod
112105
def get_active_material_type(cls):
113106
return bpy.context.scene.BIMMaterialProperties.material_type

src/blenderbim/blenderbim/tool/system.py

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -129,16 +129,10 @@ def run_root_assign_class(
129129
ifc_representation_class=ifc_representation_class,
130130
)
131131

132-
@classmethod
133-
def select_elements(cls, elements):
134-
for element in elements:
135-
obj = tool.Ifc.get_object(element)
136-
if obj:
137-
obj.select_set(True)
138132

139133
@classmethod
140134
def select_system_products(cls, system):
141-
cls.select_elements(ifcopenshell.util.system.get_system_elements(system))
135+
tool.Spatial.select_products(ifcopenshell.util.system.get_system_elements(system))
142136

143137
@classmethod
144138
def set_active_system(cls, system):

src/blenderbim/test/core/test_material.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
# along with BlenderBIM Add-on. If not, see <http://www.gnu.org/licenses/>.
1818

1919
import blenderbim.core.material as subject
20-
from test.core.bootstrap import ifc, material, style
20+
from test.core.bootstrap import ifc, material, style, spatial
2121

2222

2323
class TestUnlinkMaterial:
@@ -158,7 +158,7 @@ def test_run(self, material):
158158

159159

160160
class TestSelectByMaterial:
161-
def test_run(self, material):
161+
def test_run(self, material, spatial):
162162
material.get_elements_by_material("material").should_be_called().will_return("elements")
163-
material.select_elements("elements").should_be_called()
163+
spatial.select_products("elements").should_be_called()
164164
subject.select_by_material(material, material="material")

0 commit comments

Comments
 (0)