mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-09-26 18:21:59 +00:00
WIP merge MVDs into geometry workarounds UI. Cleaner, more usable import / export UI. Remove obsoleted MVD options. See #1222.
This commit is contained in:
@@ -30,4 +30,4 @@ def register():
|
||||
|
||||
def unregister():
|
||||
del bpy.types.Scene.BIMConstraintProperties
|
||||
del bpy.types.Scene.BIMObjectConstraintProperties
|
||||
del bpy.types.Object.BIMObjectConstraintProperties
|
||||
|
||||
@@ -33,4 +33,4 @@ def register():
|
||||
|
||||
def unregister():
|
||||
del bpy.types.Scene.BIMDocumentProperties
|
||||
del bpy.types.Scene.BIMObjectDocumentProperties
|
||||
del bpy.types.Object.BIMObjectDocumentProperties
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import bpy
|
||||
from . import ui, operator
|
||||
from . import ui, prop, operator
|
||||
|
||||
classes = (
|
||||
operator.EditObjectPlacement,
|
||||
@@ -9,14 +9,18 @@ classes = (
|
||||
operator.UpdateMeshRepresentation,
|
||||
operator.UpdateParametricRepresentation,
|
||||
operator.GetRepresentationIfcParameters,
|
||||
prop.BIMGeometryProperties,
|
||||
ui.BIM_PT_representations,
|
||||
ui.BIM_PT_mesh,
|
||||
ui.BIM_PT_workarounds,
|
||||
)
|
||||
|
||||
|
||||
def register():
|
||||
bpy.types.Scene.BIMGeometryProperties = bpy.props.PointerProperty(type=prop.BIMGeometryProperties)
|
||||
bpy.types.OBJECT_PT_transform.append(ui.BIM_PT_transform)
|
||||
|
||||
|
||||
def unregister():
|
||||
bpy.types.OBJECT_PT_transform.remove(ui.BIM_PT_transform)
|
||||
del bpy.types.Scene.BIMGeometryProperties
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
import bpy
|
||||
import bmesh
|
||||
import ifcopenshell.util.unit
|
||||
|
||||
|
||||
@@ -7,10 +9,12 @@ class Usecase:
|
||||
self.file = file
|
||||
self.settings = {
|
||||
"context": None, # IfcGeometricRepresentationContext
|
||||
"blender_object": None, # This is (currently) a Blender object, hence this depends on Blender now
|
||||
"geometry": None, # This is (currently) a Blender data object, hence this depends on Blender now
|
||||
"total_items": 1, # How many representation items to create
|
||||
"unit_scale": None, # A scale factor to apply for all vectors in case the unit is different
|
||||
"should_force_faceted_brep": False, # If we should force faceted breps for meshes
|
||||
"should_force_triangulation": False, # If we should force triangulation for meshes
|
||||
"is_wireframe": False, # If the geometry is a wireframe
|
||||
"is_curve": False, # If the geometry is a Blender curve
|
||||
"is_point_cloud": False, # If the geometry is a point cloud
|
||||
@@ -20,6 +24,7 @@ class Usecase:
|
||||
self.settings[key] = value
|
||||
|
||||
def execute(self):
|
||||
self.evaluate_geometry()
|
||||
if self.settings["unit_scale"] is None:
|
||||
self.settings["unit_scale"] = ifcopenshell.util.unit.calculate_unit_scale(self.file)
|
||||
if self.settings["context"].ContextType == "Model":
|
||||
@@ -28,6 +33,34 @@ class Usecase:
|
||||
return self.create_plan_representation()
|
||||
return self.create_variable_representation()
|
||||
|
||||
def evaluate_geometry(self):
|
||||
self.boolean_modifiers = []
|
||||
for modifier in self.settings["blender_object"].modifiers:
|
||||
if not modifier.type == "BOOLEAN":
|
||||
continue
|
||||
modifier_data = {}
|
||||
for name in ["operation", "operand_type", "object", "solver", "use_self"]:
|
||||
modifier_data[name] = getattr(modifier, name)
|
||||
self.boolean_modifiers.append(modifier_data)
|
||||
self.settings["blender_object"].modifiers.remove(modifier)
|
||||
|
||||
if self.settings["should_force_triangulation"]:
|
||||
mesh = self.settings["blender_object"].evaluated_get(bpy.context.evaluated_depsgraph_get()).to_mesh()
|
||||
bm = bmesh.new()
|
||||
bm.from_mesh(mesh)
|
||||
bmesh.ops.triangulate(bm, faces=bm.faces)
|
||||
bm.to_mesh(mesh)
|
||||
bm.free()
|
||||
del bm
|
||||
self.settings["geometry"] = mesh
|
||||
else:
|
||||
self.settings["geometry"] = self.settings["blender_object"].evaluated_get(bpy.context.evaluated_depsgraph_get()).to_mesh()
|
||||
|
||||
for modifier in self.boolean_modifiers:
|
||||
new = self.settings["blender_object"].modifiers.new("IfcOpeningElement", "BOOLEAN")
|
||||
for key, value in modifier.items():
|
||||
setattr(new, key, value)
|
||||
|
||||
def create_model_representation(self):
|
||||
if self.settings["context"].is_a() == "IfcGeometricRepresentationContext":
|
||||
return self.create_variable_representation()
|
||||
|
||||
@@ -39,7 +39,10 @@ class Usecase:
|
||||
ifcopenshell.util.element.replace_attribute(
|
||||
inverse, self.settings["product"].ObjectPlacement, placement
|
||||
)
|
||||
self.file.remove(self.settings["product"].ObjectPlacement)
|
||||
old = self.settings["product"].ObjectPlacement
|
||||
self.settings["product"].ObjectPlacement = None
|
||||
if not self.file.get_inverse(old):
|
||||
ifcopenshell.util.element.remove_deep(self.file, old)
|
||||
self.settings["product"].ObjectPlacement = placement
|
||||
|
||||
for settings in dependent_objects:
|
||||
|
||||
@@ -76,8 +76,11 @@ class AddRepresentation(bpy.types.Operator):
|
||||
self.file,
|
||||
{
|
||||
"context": self.file.by_id(context_id),
|
||||
"blender_object": obj,
|
||||
"geometry": obj.data,
|
||||
"total_items": max(1, len(obj.material_slots)),
|
||||
"should_force_faceted_brep": context.scene.BIMGeometryProperties.should_force_faceted_brep,
|
||||
"should_force_triangulation": context.scene.BIMGeometryProperties.should_force_triangulation
|
||||
},
|
||||
).execute()
|
||||
if not result:
|
||||
@@ -92,6 +95,7 @@ class AddRepresentation(bpy.types.Operator):
|
||||
for s in obj.material_slots
|
||||
if s.material
|
||||
],
|
||||
"should_use_presentation_style_assignment": context.scene.BIMGeometryProperties.should_use_presentation_style_assignment
|
||||
},
|
||||
).execute()
|
||||
assign_representation.Usecase(
|
||||
@@ -183,8 +187,11 @@ class UpdateMeshRepresentation(bpy.types.Operator):
|
||||
self.file,
|
||||
{
|
||||
"context": old_representation.ContextOfItems,
|
||||
"blender_object": obj,
|
||||
"geometry": obj.data,
|
||||
"total_items": max(1, len(obj.material_slots)),
|
||||
"should_force_faceted_brep": context.scene.BIMGeometryProperties.should_force_faceted_brep,
|
||||
"should_force_triangulation": context.scene.BIMGeometryProperties.should_force_triangulation
|
||||
},
|
||||
).execute()
|
||||
if not new_representation:
|
||||
@@ -200,6 +207,7 @@ class UpdateMeshRepresentation(bpy.types.Operator):
|
||||
for s in obj.material_slots
|
||||
if s.material
|
||||
],
|
||||
"should_use_presentation_style_assignment": context.scene.BIMGeometryProperties.should_use_presentation_style_assignment
|
||||
},
|
||||
).execute()
|
||||
|
||||
|
||||
@@ -0,0 +1,22 @@
|
||||
import bpy
|
||||
from blenderbim.bim.prop import StrProperty, Attribute
|
||||
from bpy.types import PropertyGroup
|
||||
from bpy.props import (
|
||||
PointerProperty,
|
||||
StringProperty,
|
||||
EnumProperty,
|
||||
BoolProperty,
|
||||
IntProperty,
|
||||
FloatProperty,
|
||||
FloatVectorProperty,
|
||||
CollectionProperty,
|
||||
)
|
||||
|
||||
|
||||
class BIMGeometryProperties(PropertyGroup):
|
||||
# Revit workaround
|
||||
should_use_presentation_style_assignment: BoolProperty(name="Force Presentation Style Assignment", default=False)
|
||||
# RIB iTwo, DESITE BIM workaround
|
||||
should_force_faceted_brep: BoolProperty(name="Force Faceted Breps", default=False)
|
||||
# Navisworks workaround
|
||||
should_force_triangulation: BoolProperty(name="Force Triangulation", default=False)
|
||||
@@ -1,3 +1,5 @@
|
||||
import ifcopenshell.util.element
|
||||
|
||||
class Usecase:
|
||||
def __init__(self, file, settings=None):
|
||||
self.file = file
|
||||
@@ -6,17 +8,10 @@ class Usecase:
|
||||
self.settings[key] = value
|
||||
|
||||
def execute(self):
|
||||
styles = []
|
||||
dummy_context = self.file.create_entity("IfcRepresentationContext")
|
||||
for subelement in self.file.traverse(self.settings["representation"]):
|
||||
if subelement.is_a("IfcRepresentationItem") and subelement.StyledByItem:
|
||||
styles.append(subelement)
|
||||
for style in styles:
|
||||
self.remove_deep(style)
|
||||
self.remove_deep(self.settings["representation"])
|
||||
|
||||
def remove_deep(self, element):
|
||||
subgraph = list(self.file.traverse(element))
|
||||
subgraph_set = set(subgraph)
|
||||
for ref in subgraph[::-1]:
|
||||
if ref.id() and len(set(self.file.get_inverse(ref)) - subgraph_set) == 0:
|
||||
self.file.remove(ref)
|
||||
[self.file.remove(s) for s in subelement.StyledByItem]
|
||||
elif subelement.is_a("IfcRepresentation"):
|
||||
subelement.ContextOfItems = dummy_context
|
||||
ifcopenshell.util.element.remove_deep(self.file, self.settings["representation"])
|
||||
|
||||
@@ -55,6 +55,7 @@ class BIM_PT_mesh(Panel):
|
||||
context.active_object is not None
|
||||
and context.active_object.type == "MESH"
|
||||
and hasattr(context.active_object.data, "BIMMeshProperties")
|
||||
and context.active_object.data.BIMMeshProperties.ifc_definition_id
|
||||
)
|
||||
|
||||
def draw(self, context):
|
||||
@@ -78,3 +79,30 @@ def BIM_PT_transform(self, context):
|
||||
if context.active_object and context.active_object.BIMObjectProperties.ifc_definition_id:
|
||||
row = self.layout.row()
|
||||
row.operator("bim.edit_object_placement")
|
||||
|
||||
|
||||
class BIM_PT_workarounds(Panel):
|
||||
bl_label = "IFC Vendor Workarounds"
|
||||
bl_idname = "BIM_PT_workarounds"
|
||||
bl_options = {"DEFAULT_CLOSED"}
|
||||
bl_space_type = "PROPERTIES"
|
||||
bl_region_type = "WINDOW"
|
||||
bl_context = "data"
|
||||
|
||||
@classmethod
|
||||
def poll(cls, context):
|
||||
return (
|
||||
context.active_object is not None
|
||||
and context.active_object.type == "MESH"
|
||||
and hasattr(context.active_object.data, "BIMMeshProperties")
|
||||
and context.active_object.data.BIMMeshProperties.ifc_definition_id
|
||||
)
|
||||
|
||||
def draw(self, context):
|
||||
props = context.scene.BIMGeometryProperties
|
||||
row = self.layout.row()
|
||||
row.prop(props, "should_force_faceted_brep")
|
||||
row = self.layout.row()
|
||||
row.prop(props, "should_force_triangulation")
|
||||
row = self.layout.row()
|
||||
row.prop(props, "should_use_presentation_style_assignment")
|
||||
|
||||
Reference in New Issue
Block a user