mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-09-17 22:11:36 +00:00
refactor create spaces from walls
This commit is contained in:
@@ -68,6 +68,13 @@ class GenerateSpace(bpy.types.Operator, tool.Ifc.Operator):
|
|||||||
bpy.context.window_manager.popup_menu(msg, title="Error", icon="ERROR")
|
bpy.context.window_manager.popup_menu(msg, title="Error", icon="ERROR")
|
||||||
return
|
return
|
||||||
|
|
||||||
|
# core.generate_space(tool.Ifc, tool.Spatial)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
active_obj = bpy.context.active_object
|
active_obj = bpy.context.active_object
|
||||||
element = None
|
element = None
|
||||||
if bpy.context.selected_objects and active_obj:
|
if bpy.context.selected_objects and active_obj:
|
||||||
@@ -233,6 +240,26 @@ class GenerateSpacesFromWalls(bpy.types.Operator, tool.Ifc.Operator):
|
|||||||
# walls (i.e. prismatic) in the active object storey.
|
# walls (i.e. prismatic) in the active object storey.
|
||||||
# In order to run, the active object must be a wall and
|
# In order to run, the active object must be a wall and
|
||||||
# there must be selected walls
|
# there must be selected walls
|
||||||
|
|
||||||
|
active_obj = bpy.context.active_object
|
||||||
|
element = tool.Ifc.get_entity(active_obj)
|
||||||
|
container = tool.Spatial.get_container(element)
|
||||||
|
|
||||||
|
if not active_obj:
|
||||||
|
self.report({"ERROR"}, "No active object. Please select a wall")
|
||||||
|
return
|
||||||
|
|
||||||
|
element = tool.Ifc.get_entity(active_obj)
|
||||||
|
if element and not element.is_a("IfcWall"):
|
||||||
|
return self.report({"ERROR"}, "The active object is not a wall. Please select a wall.")
|
||||||
|
|
||||||
|
if not container:
|
||||||
|
self.report({"ERROR"}, "The wall is not contained.")
|
||||||
|
|
||||||
|
if not bpy.context.selected_objects:
|
||||||
|
self.report({"ERROR"}, "No selected objects found. Please select walls.")
|
||||||
|
return
|
||||||
|
|
||||||
core.generate_spaces_from_walls(tool.Ifc, tool.Spatial, tool.Collector)
|
core.generate_spaces_from_walls(tool.Ifc, tool.Spatial, tool.Collector)
|
||||||
|
|
||||||
class ToggleSpaceVisibility(bpy.types.Operator, tool.Ifc.Operator):
|
class ToggleSpaceVisibility(bpy.types.Operator, tool.Ifc.Operator):
|
||||||
|
|||||||
@@ -123,31 +123,13 @@ def select_decomposed_elements(spatial):
|
|||||||
spatial.select_products(spatial.get_decomposed_elements(container))
|
spatial.select_products(spatial.get_decomposed_elements(container))
|
||||||
|
|
||||||
#HERE STARTS SPATIAL TOOL
|
#HERE STARTS SPATIAL TOOL
|
||||||
|
def generate_space(ifc, spatial):
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
def generate_spaces_from_walls(ifc, spatial, collector):
|
def generate_spaces_from_walls(ifc, spatial, collector):
|
||||||
active_obj = bpy.context.active_object
|
z = spatial.get_active_obj_z()
|
||||||
element = ifc.get_entity(active_obj)
|
h = spatial.get_active_obj_height()
|
||||||
container = spatial.get_container(element)
|
|
||||||
|
|
||||||
if not active_obj:
|
|
||||||
self.report({"ERROR"}, "No active object. Please select a wall")
|
|
||||||
return
|
|
||||||
|
|
||||||
element = ifc.get_entity(active_obj)
|
|
||||||
if element and not element.is_a("IfcWall"):
|
|
||||||
return self.report({"ERROR"}, "The active object is not a wall. Please select a wall.")
|
|
||||||
|
|
||||||
if not container:
|
|
||||||
self.report({"ERROR"}, "The wall is not contained.")
|
|
||||||
|
|
||||||
if not bpy.context.selected_objects:
|
|
||||||
self.report({"ERROR"}, "No selected objects found. Please select walls.")
|
|
||||||
return
|
|
||||||
|
|
||||||
x, y, z = active_obj.matrix_world.translation.xyz
|
|
||||||
mat = active_obj.matrix_world
|
|
||||||
h = active_obj.dimensions.z
|
|
||||||
selected_objects = bpy.context.selected_objects
|
|
||||||
|
|
||||||
union = spatial.get_union_shape_from_selected_objects()
|
union = spatial.get_union_shape_from_selected_objects()
|
||||||
|
|
||||||
@@ -157,24 +139,16 @@ def generate_spaces_from_walls(ifc, spatial, collector):
|
|||||||
bm = spatial.get_bmesh_from_polygon(poly, h)
|
bm = spatial.get_bmesh_from_polygon(poly, h)
|
||||||
|
|
||||||
name = "Space" + str(i)
|
name = "Space" + str(i)
|
||||||
mesh = bpy.data.meshes.new(name=name)
|
|
||||||
bm.to_mesh(mesh)
|
|
||||||
bm.free()
|
|
||||||
|
|
||||||
obj = bpy.data.objects.new(name, mesh)
|
obj = spatial.get_named_obj_from_bmesh(name, bmesh = bm)
|
||||||
obj.matrix_world = mat
|
|
||||||
|
|
||||||
spatial.set_obj_origin_to_bboxcenter(obj)
|
spatial.set_obj_origin_to_bboxcenter(obj)
|
||||||
|
spatial.traslate_obj_to_z_location(obj, z)
|
||||||
|
|
||||||
if z != 0:
|
spatial.link_obj_to_active_collection(obj)
|
||||||
obj.location = obj.location + Vector((0, 0, z))
|
spatial.assign_ifcspace_class_to_obj(obj)
|
||||||
|
|
||||||
bpy.context.view_layer.active_layer_collection.collection.objects.link(obj)
|
spatial.assign_container_to_obj(obj)
|
||||||
bpy.ops.bim.assign_class(obj=obj.name, ifc_class="IfcSpace")
|
|
||||||
container_obj = ifc.get_object(container)
|
|
||||||
blenderbim.core.spatial.assign_container(
|
|
||||||
ifc, collector, spatial, structure_obj=container_obj, element_obj=obj
|
|
||||||
)
|
|
||||||
|
|
||||||
def toggle_space_visibility(ifc, spatial):
|
def toggle_space_visibility(ifc, spatial):
|
||||||
model = ifc.get()
|
model = ifc.get()
|
||||||
|
|||||||
@@ -821,12 +821,14 @@ class Spatial:
|
|||||||
def get_bmesh_from_polygon(cls, poly, h): pass
|
def get_bmesh_from_polygon(cls, poly, h): pass
|
||||||
def get_named_obj_from_bmesh(cls, name, bmesh): pass
|
def get_named_obj_from_bmesh(cls, name, bmesh): pass
|
||||||
def set_obj_origin_to_bboxcenter(cls, obj): pass
|
def set_obj_origin_to_bboxcenter(cls, obj): pass
|
||||||
def get_active_obj_z(cls, obj): pass
|
def get_active_obj_z(cls): pass
|
||||||
|
def get_active_obj_height(cls): pass
|
||||||
def traslate_obj_to_z_location(cls, obj): pass
|
def traslate_obj_to_z_location(cls, obj): pass
|
||||||
def link_obj_to_active_collection(cls, obj): pass
|
def link_obj_to_active_collection(cls, obj): pass
|
||||||
def get_2d_vertices_from_obj(cls, obj): pass
|
def get_2d_vertices_from_obj(cls, obj): pass
|
||||||
def assign_swept_area_outer_curve_from_2d_vertices(cls, obj, vertices): pass
|
def assign_swept_area_outer_curve_from_2d_vertices(cls, obj, vertices): pass
|
||||||
def get_body_representation(cls, obj): pass
|
def get_body_representation(cls, obj): pass
|
||||||
|
def assign_ifcspace_class_to_obj(cls, obj): pass
|
||||||
def assign_type_to_obj(cls, obj): pass
|
def assign_type_to_obj(cls, obj): pass
|
||||||
def regen_obj_representation(cls, ifc, geometry, obj, body): pass
|
def regen_obj_representation(cls, ifc, geometry, obj, body): pass
|
||||||
def toggle_spaces_visibility_wired_and_textured(cls, spaces): pass
|
def toggle_spaces_visibility_wired_and_textured(cls, spaces): pass
|
||||||
|
|||||||
@@ -427,6 +427,11 @@ class Spatial(blenderbim.core.tool.Spatial):
|
|||||||
x, y, z = bpy.context.active_object.matrix_world.translation.xyz
|
x, y, z = bpy.context.active_object.matrix_world.translation.xyz
|
||||||
return z
|
return z
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def get_active_obj_height(cls):
|
||||||
|
height = bpy.context.active_object.dimensions.z
|
||||||
|
return height
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def traslate_obj_to_z_location(cls, obj, z):
|
def traslate_obj_to_z_location(cls, obj, z):
|
||||||
if z != 0:
|
if z != 0:
|
||||||
@@ -468,6 +473,10 @@ class Spatial(blenderbim.core.tool.Spatial):
|
|||||||
body = ifcopenshell.util.representation.get_representation(element, "Model", "Body", "MODEL_VIEW")
|
body = ifcopenshell.util.representation.get_representation(element, "Model", "Body", "MODEL_VIEW")
|
||||||
return body
|
return body
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def assign_ifcspace_class_to_obj(cls, obj):
|
||||||
|
bpy.ops.bim.assign_class(obj=obj.name, ifc_class="IfcSpace")
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def assign_type_to_obj(cls, obj):
|
def assign_type_to_obj(cls, obj):
|
||||||
relating_type_id = bpy.context.scene.BIMModelProperties.relating_type_id
|
relating_type_id = bpy.context.scene.BIMModelProperties.relating_type_id
|
||||||
|
|||||||
@@ -116,17 +116,6 @@ Scenario: Execute generate spaces from walls
|
|||||||
When I press "bim.generate_spaces_from_walls"
|
When I press "bim.generate_spaces_from_walls"
|
||||||
Then nothing happens
|
Then nothing happens
|
||||||
|
|
||||||
Scenario: Execute generate flooring coverings from walls
|
|
||||||
Given an empty IFC project
|
|
||||||
And I load the demo construction library
|
|
||||||
And I set "scene.BIMModelProperties.ifc_class" to "IfcWallType"
|
|
||||||
And the variable "element_type" is "[e for e in {ifc}.by_type('IfcWallType') if e.Name == 'WAL100'][0].id()"
|
|
||||||
And I set "scene.BIMModelProperties.relating_type_id" to "{element_type}"
|
|
||||||
And I press "bim.add_constr_type_instance"
|
|
||||||
And the object "IfcWall/Wall" is selected
|
|
||||||
When I press "bim.generate_flooring_coverings_from_walls"
|
|
||||||
Then nothing happens
|
|
||||||
|
|
||||||
Scenario: Execute toggle space visibility
|
Scenario: Execute toggle space visibility
|
||||||
Given an empty IFC project
|
Given an empty IFC project
|
||||||
And I add a cube
|
And I add a cube
|
||||||
|
|||||||
Reference in New Issue
Block a user