Merge branch 'IfcOpenShell:v0.7.0' into v0.7.0

This commit is contained in:
Martin15135215
2022-09-04 09:22:58 +00:00
committed by GitHub
7 changed files with 53 additions and 43 deletions
@@ -400,6 +400,12 @@ class IfcImporter:
items = representation["raw"].Items or [] # Be forgiving of invalid IFCs because Revit :( items = representation["raw"].Items or [] # Be forgiving of invalid IFCs because Revit :(
if len(items) == 1 and items[0].is_a("IfcSweptDiskSolid"): if len(items) == 1 and items[0].is_a("IfcSweptDiskSolid"):
return True return True
elif (
items[0].is_a("IfcSweptDiskSolid")
and len({i.is_a() for i in items}) == 1
and len({i.Radius for i in items}) == 1
):
return True
return False return False
def is_native_faceted_brep(self, representations): def is_native_faceted_brep(self, representations):
@@ -20,19 +20,18 @@ import bpy
from . import ui, prop, operator from . import ui, prop, operator
classes = ( classes = (
operator.LoadGroups,
operator.ToggleGroup,
operator.DisableGroupEditingUI,
operator.AddGroup, operator.AddGroup,
operator.AddGroupToGroup,
operator.EditGroup,
operator.RemoveGroup,
operator.ToggleAssigningGroup,
operator.AssignGroup, operator.AssignGroup,
operator.UnassignGroup,
operator.EnableEditingGroup,
operator.DisableEditingGroup, operator.DisableEditingGroup,
operator.DisableGroupEditingUI,
operator.EditGroup,
operator.EnableEditingGroup,
operator.LoadGroups,
operator.RemoveGroup,
operator.SelectGroupProducts, operator.SelectGroupProducts,
operator.ToggleAssigningGroup,
operator.ToggleGroup,
operator.UnassignGroup,
operator.UpdateGroup, operator.UpdateGroup,
prop.ExpandedGroups, prop.ExpandedGroups,
prop.Group, prop.Group,
@@ -20,6 +20,7 @@ import bpy
import ifcopenshell.util.attribute import ifcopenshell.util.attribute
import ifcopenshell.api import ifcopenshell.api
import blenderbim.bim.helper import blenderbim.bim.helper
import blenderbim.tool as tool
from blenderbim.bim.ifc import IfcStore from blenderbim.bim.ifc import IfcStore
from ifcopenshell.api.group.data import Data from ifcopenshell.api.group.data import Data
from ifcopenshell.util.selector import Selector from ifcopenshell.util.selector import Selector
@@ -120,37 +121,19 @@ class AddGroup(bpy.types.Operator):
bl_idname = "bim.add_group" bl_idname = "bim.add_group"
bl_label = "Add New Group" bl_label = "Add New Group"
bl_options = {"REGISTER", "UNDO"} bl_options = {"REGISTER", "UNDO"}
group: bpy.props.IntProperty()
def execute(self, context): def execute(self, context):
return IfcStore.execute_ifc_operator(self, context) return IfcStore.execute_ifc_operator(self, context)
def _execute(self, context): def _execute(self, context):
result = ifcopenshell.api.run("group.add_group", IfcStore.get_file()) result = ifcopenshell.api.run("group.add_group", tool.Ifc.get())
Data.load(IfcStore.get_file()) if self.group:
ifcopenshell.api.run(
"group.assign_group", tool.Ifc.get(), products=[result], group=tool.Ifc.get().by_id(self.group)
)
Data.load(tool.Ifc.get())
bpy.ops.bim.load_groups(is_refresh=True) bpy.ops.bim.load_groups(is_refresh=True)
bpy.ops.bim.enable_editing_group(group=result.id())
return {"FINISHED"}
class AddGroupToGroup(bpy.types.Operator):
bl_idname = "bim.add_group_to_group"
bl_label = "Add Group to Group"
bl_options = {"REGISTER", "UNDO"}
group: bpy.props.IntProperty(name="Group ID")
def execute(self, context):
return IfcStore.execute_ifc_operator(self, context)
def _execute(self, context):
self.file = IfcStore.get_file()
result = ifcopenshell.api.run("group.add_group", self.file)
ifcopenshell.api.run(
"group.assign_group", IfcStore.get_file(), products=[result], group=self.file.by_id(self.group)
)
Data.load(IfcStore.get_file())
bpy.ops.bim.load_groups(is_refresh=True)
bpy.ops.bim.disable_group_editing_ui()
return {"FINISHED"} return {"FINISHED"}
@@ -42,7 +42,7 @@ class BIM_PT_groups(Panel):
row = self.layout.row(align=True) row = self.layout.row(align=True)
row.label(text=f"{len(Data.groups)} Groups Found", icon="OUTLINER") row.label(text=f"{len(Data.groups)} Groups Found", icon="OUTLINER")
if self.props.is_editing: if self.props.is_editing:
row.operator("bim.add_group", text="", icon="ADD") row.operator("bim.add_group", text="", icon="ADD").group = 0
row.operator("bim.disable_group_editing_ui", text="", icon="CANCEL") row.operator("bim.disable_group_editing_ui", text="", icon="CANCEL")
else: else:
row.operator("bim.load_groups", text="", icon="GREASEPENCIL") row.operator("bim.load_groups", text="", icon="GREASEPENCIL")
@@ -140,7 +140,7 @@ class BIM_UL_groups(UIList):
elif context.scene.BIMGroupProperties.active_group_id: elif context.scene.BIMGroupProperties.active_group_id:
op = row.operator("bim.select_group_products", text="", icon="RESTRICT_SELECT_OFF") op = row.operator("bim.select_group_products", text="", icon="RESTRICT_SELECT_OFF")
op.group = group_id op.group = group_id
op = row.operator("bim.add_group_to_group", text="", icon="ADD") op = row.operator("bim.add_group", text="", icon="ADD")
op.group = group_id op.group = group_id
op = row.operator("bim.remove_group", text="", icon="X") op = row.operator("bim.remove_group", text="", icon="X")
op.group = group_id op.group = group_id
@@ -153,7 +153,7 @@ class BIM_UL_groups(UIList):
op.group = group_id op.group = group_id
op = row.operator("bim.enable_editing_group", text="", icon="GREASEPENCIL") op = row.operator("bim.enable_editing_group", text="", icon="GREASEPENCIL")
op.group = group_id op.group = group_id
op = row.operator("bim.add_group_to_group", text="", icon="ADD") op = row.operator("bim.add_group", text="", icon="ADD")
op.group = group_id op.group = group_id
op = row.operator("bim.remove_group", text="", icon="X") op = row.operator("bim.remove_group", text="", icon="X")
op.group = group_id op.group = group_id
+6 -4
View File
@@ -25,6 +25,7 @@ import ifcopenshell.api
import ifcopenshell.api.owner.settings import ifcopenshell.api.owner.settings
from pathlib import Path from pathlib import Path
import numpy as np
class Obj2Ifc: class Obj2Ifc:
def __init__(self, path): def __init__(self, path):
@@ -44,9 +45,10 @@ class Obj2Ifc:
faces = mesh.face_matrix() faces = mesh.face_matrix()
vertices = mesh.vertex_matrix() vertices = mesh.vertex_matrix()
ifc_faces = []
for face in faces: ifc_faces = np.zeros([len(faces)], dtype=object)
ifc_faces.append( for i, face in enumerate(faces):
ifc_faces[i] = (
self.file.createIfcFace( self.file.createIfcFace(
[ [
self.file.createIfcFaceOuterBound( self.file.createIfcFaceOuterBound(
@@ -71,7 +73,7 @@ class Obj2Ifc:
self.context, self.context,
"Body", "Body",
"Brep", "Brep",
[self.file.createIfcFacetedBrep(self.file.createIfcClosedShell(ifc_faces))], [self.file.createIfcFacetedBrep(self.file.createIfcClosedShell(ifc_faces.tolist()))],
) )
], ],
) )
@@ -217,7 +217,9 @@ class Usecase:
) )
def create_variable_representation(self): def create_variable_representation(self):
if isinstance(self.settings["geometry"], bpy.types.Curve): if isinstance(self.settings["geometry"], bpy.types.Curve) and self.settings["geometry"].bevel_depth:
return self.create_swept_disk_solid_representation()
elif isinstance(self.settings["geometry"], bpy.types.Curve):
return self.create_curve3d_representation() return self.create_curve3d_representation()
elif isinstance(self.settings["geometry"], bpy.types.Camera): elif isinstance(self.settings["geometry"], bpy.types.Camera):
return self.create_camera_block_representation() return self.create_camera_block_representation()
@@ -273,6 +275,14 @@ class Usecase:
> self.settings["geometry"].BIMCameraProperties.raster_y > self.settings["geometry"].BIMCameraProperties.raster_y
) )
def create_swept_disk_solid_representation(self):
return self.file.createIfcShapeRepresentation(
self.settings["context"],
self.settings["context"].ContextIdentifier,
"AdvancedSweptSolid",
self.create_swept_disk_solids(),
)
def create_curve3d_representation(self): def create_curve3d_representation(self):
return self.file.createIfcShapeRepresentation( return self.file.createIfcShapeRepresentation(
self.settings["context"], self.settings["context"],
@@ -335,6 +345,14 @@ class Usecase:
] ]
return self.file.createIfcPolyline([points[i] for i in indices]) return self.file.createIfcPolyline([points[i] for i in indices])
def create_swept_disk_solids(self):
curves = self.create_curves()
results = []
radius = self.convert_si_to_unit(round(self.settings["geometry"].bevel_depth, 3))
for curve in curves:
results.append(self.file.createIfcSweptDiskSolid(curve, radius))
return results
def create_curves(self, should_exclude_faces=False, is_2d=False): def create_curves(self, should_exclude_faces=False, is_2d=False):
if isinstance(self.settings["geometry"], bpy.types.Mesh): if isinstance(self.settings["geometry"], bpy.types.Mesh):
if self.file.schema == "IFC2X3": if self.file.schema == "IFC2X3":
@@ -38,7 +38,9 @@ class Usecase:
for item in element.Items: for item in element.Items:
if not item.is_a("IfcGeometricRepresentationItem"): if not item.is_a("IfcGeometricRepresentationItem"):
continue continue
style = self.settings["styles"].pop(0) if self.settings["styles"]:
# If there are more items than styles, fallback to using the last style
style = self.settings["styles"].pop(0)
name = style.Name name = style.Name
if self.file.schema == "IFC2X3" or self.settings["should_use_presentation_style_assignment"]: if self.file.schema == "IFC2X3" or self.settings["should_use_presentation_style_assignment"]:
style = self.file.createIfcPresentationStyleAssignment([style]) style = self.file.createIfcPresentationStyleAssignment([style])