mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-08-10 09:48:32 +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")
|
||||
return
|
||||
|
||||
# core.generate_space(tool.Ifc, tool.Spatial)
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
active_obj = bpy.context.active_object
|
||||
element = None
|
||||
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.
|
||||
# In order to run, the active object must be a wall and
|
||||
# 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)
|
||||
|
||||
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))
|
||||
|
||||
#HERE STARTS SPATIAL TOOL
|
||||
def generate_space(ifc, spatial):
|
||||
pass
|
||||
|
||||
|
||||
def generate_spaces_from_walls(ifc, spatial, collector):
|
||||
active_obj = bpy.context.active_object
|
||||
element = ifc.get_entity(active_obj)
|
||||
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
|
||||
z = spatial.get_active_obj_z()
|
||||
h = spatial.get_active_obj_height()
|
||||
|
||||
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)
|
||||
|
||||
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.matrix_world = mat
|
||||
obj = spatial.get_named_obj_from_bmesh(name, bmesh = bm)
|
||||
|
||||
spatial.set_obj_origin_to_bboxcenter(obj)
|
||||
spatial.traslate_obj_to_z_location(obj, z)
|
||||
|
||||
if z != 0:
|
||||
obj.location = obj.location + Vector((0, 0, z))
|
||||
spatial.link_obj_to_active_collection(obj)
|
||||
spatial.assign_ifcspace_class_to_obj(obj)
|
||||
|
||||
bpy.context.view_layer.active_layer_collection.collection.objects.link(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
|
||||
)
|
||||
spatial.assign_container_to_obj(obj)
|
||||
|
||||
def toggle_space_visibility(ifc, spatial):
|
||||
model = ifc.get()
|
||||
|
||||
@@ -821,12 +821,14 @@ class Spatial:
|
||||
def get_bmesh_from_polygon(cls, poly, h): pass
|
||||
def get_named_obj_from_bmesh(cls, name, bmesh): 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 link_obj_to_active_collection(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 get_body_representation(cls, obj): pass
|
||||
def assign_ifcspace_class_to_obj(cls, obj): pass
|
||||
def assign_type_to_obj(cls, obj): pass
|
||||
def regen_obj_representation(cls, ifc, geometry, obj, body): 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
|
||||
return z
|
||||
|
||||
@classmethod
|
||||
def get_active_obj_height(cls):
|
||||
height = bpy.context.active_object.dimensions.z
|
||||
return height
|
||||
|
||||
@classmethod
|
||||
def traslate_obj_to_z_location(cls, obj, z):
|
||||
if z != 0:
|
||||
@@ -468,6 +473,10 @@ class Spatial(blenderbim.core.tool.Spatial):
|
||||
body = ifcopenshell.util.representation.get_representation(element, "Model", "Body", "MODEL_VIEW")
|
||||
return body
|
||||
|
||||
@classmethod
|
||||
def assign_ifcspace_class_to_obj(cls, obj):
|
||||
bpy.ops.bim.assign_class(obj=obj.name, ifc_class="IfcSpace")
|
||||
|
||||
@classmethod
|
||||
def assign_type_to_obj(cls, obj):
|
||||
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"
|
||||
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
|
||||
Given an empty IFC project
|
||||
And I add a cube
|
||||
|
||||
Reference in New Issue
Block a user