mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-08-09 09:21:46 +00:00
Add generate flooring from cursor and regen (#3874)
This commit is contained in:
@@ -45,6 +45,7 @@ class CoveringTool(WorkSpaceTool):
|
|||||||
ifc_element_type = "IfcCoveringType"
|
ifc_element_type = "IfcCoveringType"
|
||||||
bl_keymap = tool.Blender.get_default_selection_keypmap() + (
|
bl_keymap = tool.Blender.get_default_selection_keypmap() + (
|
||||||
("bim.covering_hotkey", {"type": "A", "value": "PRESS", "shift": True}, {"properties": [("hotkey", "S_A")]}),
|
("bim.covering_hotkey", {"type": "A", "value": "PRESS", "shift": True}, {"properties": [("hotkey", "S_A")]}),
|
||||||
|
("bim.covering_hotkey", {"type": "G", "value": "PRESS", "shift": True}, {"properties": [("hotkey", "S_G")]}),
|
||||||
)
|
)
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
@@ -93,6 +94,8 @@ class CoveringToolUI:
|
|||||||
row.label(text="", icon="EVENT_A")
|
row.label(text="", icon="EVENT_A")
|
||||||
active_obj = bpy.context.active_object
|
active_obj = bpy.context.active_object
|
||||||
element = tool.Ifc.get_entity(active_obj)
|
element = tool.Ifc.get_entity(active_obj)
|
||||||
|
collection = bpy.context.view_layer.active_layer_collection.collection
|
||||||
|
collection_obj = collection.BIMCollectionProperties.obj
|
||||||
|
|
||||||
if AuthoringData.data["predefined_type"] == "FLOORING":
|
if AuthoringData.data["predefined_type"] == "FLOORING":
|
||||||
if element and bpy.context.selected_objects and element.is_a("IfcWall"):
|
if element and bpy.context.selected_objects and element.is_a("IfcWall"):
|
||||||
@@ -100,13 +103,15 @@ class CoveringToolUI:
|
|||||||
# PLEASE KEEP COMMENTS AS A REMINDER
|
# PLEASE KEEP COMMENTS AS A REMINDER
|
||||||
# elif element and bpy.context.selected_objects and element.is_a("IfcSpace"):
|
# elif element and bpy.context.selected_objects and element.is_a("IfcSpace"):
|
||||||
# op. = row.operator("bim.add_istance_flooring_from_spaces"):
|
# op. = row.operator("bim.add_istance_flooring_from_spaces"):
|
||||||
|
elif tool.Ifc.get_entity(collection_obj):
|
||||||
|
op = row.operator("bim.add_instance_flooring_covering_from_cursor")
|
||||||
else:
|
else:
|
||||||
# op = row.operator("bim.add_instance_flooring_from_cursor")
|
|
||||||
op = row.operator("bim.add_constr_type_instance", text="Add")
|
op = row.operator("bim.add_constr_type_instance", text="Add")
|
||||||
op.from_invoke = True
|
op.from_invoke = True
|
||||||
if cls.props.relating_type_id.isnumeric():
|
if cls.props.relating_type_id.isnumeric():
|
||||||
op.relating_type_id = int(cls.props.relating_type_id)
|
op.relating_type_id = int(cls.props.relating_type_id)
|
||||||
|
|
||||||
|
|
||||||
# elif AuthoringData.data["predefined_type"] == "CEILING":
|
# elif AuthoringData.data["predefined_type"] == "CEILING":
|
||||||
# row = cls.layout.row(align=True)
|
# row = cls.layout.row(align=True)
|
||||||
# row.prop(data=cls.props, property="ceiling_height", text="ceiling height")
|
# row.prop(data=cls.props, property="ceiling_height", text="ceiling height")
|
||||||
@@ -126,6 +131,12 @@ class CoveringToolUI:
|
|||||||
if cls.props.relating_type_id.isnumeric():
|
if cls.props.relating_type_id.isnumeric():
|
||||||
op.relating_type_id = int(cls.props.relating_type_id)
|
op.relating_type_id = int(cls.props.relating_type_id)
|
||||||
|
|
||||||
|
if element and bpy.context.selected_objects and element.is_a("IfcCovering") and AuthoringData.data["predefined_type"] == "FLOORING":
|
||||||
|
row = cls.layout.row(align=True)
|
||||||
|
row.label(text="", icon="EVENT_SHIFT")
|
||||||
|
row.label(text="", icon="EVENT_G")
|
||||||
|
op = row.operator("bim.regen_selected_flooring_object")
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def draw_type_selection_interface(cls):
|
def draw_type_selection_interface(cls):
|
||||||
# shared by both sidebar and header
|
# shared by both sidebar and header
|
||||||
@@ -184,11 +195,23 @@ class Hotkey(bpy.types.Operator, Operator):
|
|||||||
def hotkey_S_A(self):
|
def hotkey_S_A(self):
|
||||||
active_obj = bpy.context.active_object
|
active_obj = bpy.context.active_object
|
||||||
element = tool.Ifc.get_entity(active_obj)
|
element = tool.Ifc.get_entity(active_obj)
|
||||||
|
collection = bpy.context.view_layer.active_layer_collection.collection
|
||||||
|
collection_obj = collection.BIMCollectionProperties.obj
|
||||||
|
|
||||||
if AuthoringData.data["predefined_type"] == "FLOORING":
|
if AuthoringData.data["predefined_type"] == "FLOORING":
|
||||||
if element and bpy.context.selected_objects and element.is_a("IfcWall"):
|
if element and bpy.context.selected_objects and element.is_a("IfcWall"):
|
||||||
bpy.ops.bim.add_instance_flooring_coverings_from_walls()
|
bpy.ops.bim.add_instance_flooring_coverings_from_walls()
|
||||||
|
elif tool.Ifc.get_entity(collection_obj):
|
||||||
|
bpy.ops.bim.add_instance_flooring_covering_from_cursor()
|
||||||
else:
|
else:
|
||||||
bpy.ops.bim.add_constr_type_instance()
|
bpy.ops.bim.add_constr_type_instance()
|
||||||
else:
|
else:
|
||||||
bpy.ops.bim.add_constr_type_instance()
|
bpy.ops.bim.add_constr_type_instance()
|
||||||
|
|
||||||
|
def hotkey_S_G(self):
|
||||||
|
active_obj = bpy.context.active_object
|
||||||
|
element = tool.Ifc.get_entity(active_obj)
|
||||||
|
|
||||||
|
if AuthoringData.data["predefined_type"] == "FLOORING":
|
||||||
|
if element and bpy.context.selected_objects and element.is_a("IfcCovering"):
|
||||||
|
bpy.ops.bim.regen_selected_flooring_object()
|
||||||
|
|||||||
@@ -108,6 +108,8 @@ classes = (
|
|||||||
space.GenerateSpace,
|
space.GenerateSpace,
|
||||||
space.GenerateSpacesFromWalls,
|
space.GenerateSpacesFromWalls,
|
||||||
covering.AddInstanceFlooringCoveringsFromWalls,
|
covering.AddInstanceFlooringCoveringsFromWalls,
|
||||||
|
covering.AddInstanceFlooringCoveringFromCursor,
|
||||||
|
covering.RegenSelectedFlooringObject,
|
||||||
space.ToggleSpaceVisibility,
|
space.ToggleSpaceVisibility,
|
||||||
mep.FitFlowSegments,
|
mep.FitFlowSegments,
|
||||||
mep.RegenerateDistributionElement,
|
mep.RegenerateDistributionElement,
|
||||||
|
|||||||
@@ -22,6 +22,60 @@ import ifcopenshell
|
|||||||
import blenderbim.tool as tool
|
import blenderbim.tool as tool
|
||||||
import blenderbim.core.covering as core
|
import blenderbim.core.covering as core
|
||||||
|
|
||||||
|
class AddInstanceFlooringCoveringFromCursor(bpy.types.Operator, tool.Ifc.Operator):
|
||||||
|
bl_idname = "bim.add_instance_flooring_covering_from_cursor"
|
||||||
|
bl_label = "Add Flooring From Cursor"
|
||||||
|
bl_options = {"REGISTER"}
|
||||||
|
bl_description = "Add a typed instance flooring covering from cursor position. Move the cursor position into the desired position, select the right space collection and run the operator"
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def poll(cls, context):
|
||||||
|
collection = context.view_layer.active_layer_collection.collection
|
||||||
|
collection_obj = collection.BIMCollectionProperties.obj
|
||||||
|
return tool.Ifc.get_entity(collection_obj)
|
||||||
|
|
||||||
|
def _execute(self, context):
|
||||||
|
|
||||||
|
def msg(self, context):
|
||||||
|
self.layout.label(text="NO ACTIVE STOREY")
|
||||||
|
|
||||||
|
collection = context.view_layer.active_layer_collection.collection
|
||||||
|
collection_obj = collection.BIMCollectionProperties.obj
|
||||||
|
if not collection_obj:
|
||||||
|
bpy.context.window_manager.popup_menu(msg, title="Error", icon="ERROR")
|
||||||
|
return
|
||||||
|
spatial_element = tool.Ifc.get_entity(collection_obj)
|
||||||
|
if not spatial_element:
|
||||||
|
bpy.context.window_manager.popup_menu(msg, title="Error", icon="ERROR")
|
||||||
|
return
|
||||||
|
|
||||||
|
core.add_instance_flooring_covering_from_cursor(tool.Ifc, tool.Spatial, tool.Model, tool.Type, tool.Geometry)
|
||||||
|
|
||||||
|
class RegenSelectedFlooringObject(bpy.types.Operator, tool.Ifc.Operator):
|
||||||
|
bl_idname = "bim.regen_selected_flooring_object"
|
||||||
|
bl_label = "Regen Flooring"
|
||||||
|
bl_options = {"REGISTER"}
|
||||||
|
bl_description = "Regen selected flooring object"
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def poll(cls, context):
|
||||||
|
active_obj = bpy.context.active_object
|
||||||
|
element = tool.Ifc.get_entity(active_obj)
|
||||||
|
return element.is_a("IfcCovering")
|
||||||
|
|
||||||
|
def _execute(self, context):
|
||||||
|
|
||||||
|
def msg(self, context):
|
||||||
|
self.layout.label(text="NO ACTIVE STOREY")
|
||||||
|
|
||||||
|
active_obj = bpy.context.active_object
|
||||||
|
element = tool.Ifc.get_entity(active_obj)
|
||||||
|
if not element.is_a("IfcCovering"):
|
||||||
|
bpy.context.window_manager.popup_menu(msg, title="Error", icon="ERROR")
|
||||||
|
return
|
||||||
|
|
||||||
|
core.regen_selected_flooring_object(tool.Ifc, tool.Spatial, tool.Model, tool.Type, tool.Geometry)
|
||||||
|
|
||||||
|
|
||||||
class AddInstanceFlooringCoveringsFromWalls(bpy.types.Operator, tool.Ifc.Operator):
|
class AddInstanceFlooringCoveringsFromWalls(bpy.types.Operator, tool.Ifc.Operator):
|
||||||
bl_idname = "bim.add_instance_flooring_coverings_from_walls"
|
bl_idname = "bim.add_instance_flooring_coverings_from_walls"
|
||||||
|
|||||||
@@ -18,16 +18,11 @@
|
|||||||
|
|
||||||
|
|
||||||
import bpy
|
import bpy
|
||||||
import bmesh
|
|
||||||
import shapely
|
|
||||||
import ifcopenshell
|
import ifcopenshell
|
||||||
import ifcopenshell.util.element
|
import ifcopenshell.util.element
|
||||||
import blenderbim.tool as tool
|
import blenderbim.tool as tool
|
||||||
import blenderbim.core.spatial as core
|
import blenderbim.core.spatial as core
|
||||||
import blenderbim.core.type
|
import blenderbim.core.type
|
||||||
from math import pi
|
|
||||||
from mathutils import Vector, Matrix
|
|
||||||
from shapely import Polygon, MultiPolygon
|
|
||||||
|
|
||||||
|
|
||||||
class GenerateSpace(bpy.types.Operator, tool.Ifc.Operator):
|
class GenerateSpace(bpy.types.Operator, tool.Ifc.Operator):
|
||||||
|
|||||||
@@ -16,6 +16,78 @@
|
|||||||
# You should have received a copy of the GNU General Public License
|
# 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/>.
|
# along with BlenderBIM Add-on. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
def add_instance_flooring_covering_from_cursor(ifc, spatial, model, Type, geometry):
|
||||||
|
active_obj = spatial.get_active_obj()
|
||||||
|
selected_objects = spatial.get_selected_objects()
|
||||||
|
element = None
|
||||||
|
relating_type_id = spatial.get_relating_type_id()
|
||||||
|
|
||||||
|
relating_type = None
|
||||||
|
if relating_type_id:
|
||||||
|
relating_type = ifc.get().by_id(int(relating_type_id))
|
||||||
|
if not relating_type.is_a("IfcCoveringType"):
|
||||||
|
relating_type = None
|
||||||
|
|
||||||
|
if selected_objects and active_obj:
|
||||||
|
x, y, z, h, mat = spatial.get_x_y_z_h_mat_from_active_obj(active_obj)
|
||||||
|
element = ifc.get_entity(active_obj)
|
||||||
|
|
||||||
|
else:
|
||||||
|
x, y, z, h, mat = spatial.get_x_y_z_h_mat_from_cursor()
|
||||||
|
|
||||||
|
space_polygon = spatial.get_space_polygon_from_context_visible_objects(x, y)
|
||||||
|
|
||||||
|
if not space_polygon:
|
||||||
|
return
|
||||||
|
|
||||||
|
bm = spatial.get_bmesh_from_polygon(space_polygon, h=0)
|
||||||
|
name = "Covering"
|
||||||
|
mesh = spatial.get_named_mesh_from_bmesh(name = name, bmesh = bm)
|
||||||
|
|
||||||
|
|
||||||
|
# spatial.edit_active_space_obj_from_mesh(mesh)
|
||||||
|
# else:
|
||||||
|
# if relating_type:
|
||||||
|
# name = model.generate_occurrence_name(relating_type, "IfcCovering")
|
||||||
|
# else:
|
||||||
|
|
||||||
|
obj = spatial.get_named_obj_from_mesh(name, mesh)
|
||||||
|
|
||||||
|
spatial.set_obj_origin_to_cursor_position(obj)
|
||||||
|
# spatial.traslate_obj_to_z_location(obj, z)
|
||||||
|
spatial.link_obj_to_active_collection(obj)
|
||||||
|
points = spatial.get_2d_vertices_from_obj(obj)
|
||||||
|
spatial.assign_type_to_obj(obj)
|
||||||
|
|
||||||
|
spatial.assign_swept_area_outer_curve_from_2d_vertices(obj, vertices = points)
|
||||||
|
body = spatial.get_body_representation(obj)
|
||||||
|
spatial.regen_obj_representation(ifc, geometry, obj, body)
|
||||||
|
|
||||||
|
def regen_selected_flooring_object(ifc, spatial, model, Type, geometry):
|
||||||
|
active_obj = spatial.get_active_obj()
|
||||||
|
selected_objects = spatial.get_selected_objects()
|
||||||
|
|
||||||
|
if selected_objects and active_obj:
|
||||||
|
x, y, z, h, mat = spatial.get_x_y_z_h_mat_from_active_obj(active_obj)
|
||||||
|
element = ifc.get_entity(active_obj)
|
||||||
|
|
||||||
|
space_polygon = spatial.get_space_polygon_from_context_visible_objects(x, y)
|
||||||
|
|
||||||
|
if not space_polygon:
|
||||||
|
return
|
||||||
|
|
||||||
|
bm = spatial.get_bmesh_from_polygon(space_polygon, h=0)
|
||||||
|
|
||||||
|
name = "Aux"
|
||||||
|
mesh = spatial.get_named_mesh_from_bmesh(name = name, bmesh = bm)
|
||||||
|
obj = spatial.get_named_obj_from_mesh(name, mesh)
|
||||||
|
|
||||||
|
points = spatial.get_2d_vertices_from_obj(obj)
|
||||||
|
|
||||||
|
spatial.assign_swept_area_outer_curve_from_2d_vertices(active_obj, vertices = points)
|
||||||
|
body = spatial.get_body_representation(active_obj)
|
||||||
|
spatial.regen_obj_representation(ifc, geometry, active_obj, body)
|
||||||
|
|
||||||
|
|
||||||
def add_instance_flooring_coverings_from_walls(ifc, spatial, collector, geometry):
|
def add_instance_flooring_coverings_from_walls(ifc, spatial, collector, geometry):
|
||||||
z = spatial.get_active_obj_z()
|
z = spatial.get_active_obj_z()
|
||||||
|
|||||||
@@ -299,8 +299,6 @@ class Spatial(blenderbim.core.tool.Spatial):
|
|||||||
boundary_lines = []
|
boundary_lines = []
|
||||||
|
|
||||||
for obj in bpy.context.visible_objects:
|
for obj in bpy.context.visible_objects:
|
||||||
|
|
||||||
|
|
||||||
visible_element = tool.Ifc.get_entity(obj)
|
visible_element = tool.Ifc.get_entity(obj)
|
||||||
|
|
||||||
if (
|
if (
|
||||||
|
|||||||
Reference in New Issue
Block a user