mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-08-09 09:21:46 +00:00
Merge branch 'v0.6.0' of https://github.com/IfcOpenShell/IfcOpenShell into v0.6.0
This commit is contained in:
@@ -21,6 +21,7 @@ import numpy as np
|
||||
from pathlib import Path
|
||||
from itertools import cycle
|
||||
from datetime import datetime
|
||||
from blenderbim.bim.module.context.data import Data as ContextData
|
||||
from blenderbim.bim.ifc import IfcStore
|
||||
from . import schema
|
||||
|
||||
@@ -284,7 +285,6 @@ class IfcImporter:
|
||||
self.settings_native.set(self.settings_native.INCLUDE_CURVES, True)
|
||||
self.settings_2d = ifcopenshell.geom.settings()
|
||||
self.settings_2d.set(self.settings_2d.INCLUDE_CURVES, True)
|
||||
self.existing_elements = {}
|
||||
self.include_elements = []
|
||||
self.exclude_elements = []
|
||||
self.project = None
|
||||
@@ -297,6 +297,7 @@ class IfcImporter:
|
||||
self.mesh_shapes = {}
|
||||
self.time = 0
|
||||
self.unit_scale = 1
|
||||
self.added_data = {}
|
||||
self.native_elements = {}
|
||||
self.native_data = {}
|
||||
self.aggregates = {}
|
||||
@@ -318,8 +319,6 @@ class IfcImporter:
|
||||
self.profile_code("Purge diffs")
|
||||
self.load_file()
|
||||
self.profile_code("Loading file")
|
||||
self.load_existing_rooted_elements()
|
||||
self.profile_code("Load existing rooted elements")
|
||||
self.set_ifc_file()
|
||||
self.profile_code("Setting file")
|
||||
if self.ifc_import_settings.should_auto_set_workarounds:
|
||||
@@ -628,9 +627,6 @@ class IfcImporter:
|
||||
|
||||
def create_type_product(self, element):
|
||||
self.ifc_import_settings.logger.info("Creating object %s", element)
|
||||
if element.GlobalId in self.existing_elements:
|
||||
self.type_products[element.GlobalId] = self.existing_elements[element.GlobalId]
|
||||
return
|
||||
representation_map = self.get_type_product_body_representation_map(element)
|
||||
mesh = None
|
||||
if representation_map:
|
||||
@@ -645,9 +641,8 @@ class IfcImporter:
|
||||
except:
|
||||
self.ifc_import_settings.logger.error("Failed to generate shape for %s", element)
|
||||
obj = bpy.data.objects.new(self.get_name(element), mesh)
|
||||
obj.BIMObjectProperties.ifc_definition_id = element.id()
|
||||
self.link_element(element, obj)
|
||||
self.material_creator.create(element, obj, mesh)
|
||||
self.type_collection.objects.link(obj)
|
||||
self.type_products[element.GlobalId] = obj
|
||||
|
||||
def get_type_product_body_representation_map(self, element):
|
||||
@@ -756,9 +751,6 @@ class IfcImporter:
|
||||
if not self.ifc_import_settings.should_import_spaces and element.is_a("IfcSpace"):
|
||||
return
|
||||
|
||||
if element.GlobalId in self.existing_elements:
|
||||
return self.existing_elements[element.GlobalId]
|
||||
|
||||
self.ifc_import_settings.logger.info("Creating object %s", element)
|
||||
|
||||
if shape:
|
||||
@@ -778,7 +770,7 @@ class IfcImporter:
|
||||
mesh = None
|
||||
|
||||
obj = bpy.data.objects.new(self.get_name(element), mesh)
|
||||
IfcStore.link_element(element, obj)
|
||||
self.link_element(element, obj)
|
||||
|
||||
if shape:
|
||||
m = shape.transformation.matrix.data
|
||||
@@ -1021,7 +1013,7 @@ class IfcImporter:
|
||||
|
||||
def merge_by_class(self):
|
||||
merge_set = {}
|
||||
for obj in IfcStore.id_map.values():
|
||||
for obj in self.added_data.values():
|
||||
if "/" not in obj.name or "IfcRelAggregates" in obj.users_collection[0].name:
|
||||
continue
|
||||
merge_set.setdefault(obj.name.split("/")[0], []).append(obj)
|
||||
@@ -1029,7 +1021,7 @@ class IfcImporter:
|
||||
|
||||
def merge_by_material(self):
|
||||
merge_set = {}
|
||||
for obj in IfcStore.id_map.values():
|
||||
for obj in self.added_data.values():
|
||||
if "/" not in obj.name or "IfcRelAggregates" in obj.users_collection[0].name:
|
||||
continue
|
||||
if not obj.material_slots:
|
||||
@@ -1055,7 +1047,7 @@ class IfcImporter:
|
||||
cleaned_material["material"] = bpy.data.materials.new("Merged Material")
|
||||
cleaned_material["material"].diffuse_color = cleaned_material["diffuse_color"]
|
||||
|
||||
for obj in IfcStore.id_map.values():
|
||||
for obj in self.added_data.values():
|
||||
if not hasattr(obj, "material_slots") or not obj.material_slots:
|
||||
continue
|
||||
for slot in obj.material_slots:
|
||||
@@ -1079,7 +1071,7 @@ class IfcImporter:
|
||||
def clean_mesh(self):
|
||||
obj = None
|
||||
last_obj = None
|
||||
for obj in IfcStore.id_map.values():
|
||||
for obj in self.added_data.values():
|
||||
if obj.type == "MESH":
|
||||
obj.select_set(True)
|
||||
last_obj = obj
|
||||
@@ -1098,12 +1090,6 @@ class IfcImporter:
|
||||
return
|
||||
self.openings[element.GlobalId] = obj
|
||||
|
||||
def load_existing_rooted_elements(self):
|
||||
# TODO: consider how this impacts file reloading, for now we assume you only ever load the same file again
|
||||
for obj in bpy.data.objects:
|
||||
if hasattr(obj, "BIMObjectProperties") and obj.BIMObjectProperties.ifc_definition_id:
|
||||
self.existing_elements[self.file.by_id(obj.BIMObjectProperties.ifc_definition_id).GlobalId] = obj
|
||||
|
||||
def load_diff(self):
|
||||
if not self.ifc_import_settings.diff_file:
|
||||
return
|
||||
@@ -1174,9 +1160,6 @@ class IfcImporter:
|
||||
|
||||
def create_project(self):
|
||||
self.project = {"ifc": self.file.by_type("IfcProject")[0]}
|
||||
if self.project["ifc"].GlobalId in self.existing_elements:
|
||||
self.project["blender"] = self.existing_elements[self.project["ifc"].GlobalId].users_collection[0]
|
||||
return
|
||||
self.project["blender"] = bpy.data.collections.new("IfcProject/{}".format(self.project["ifc"].Name))
|
||||
obj = self.create_product(self.project["ifc"])
|
||||
if obj:
|
||||
@@ -1192,17 +1175,13 @@ class IfcImporter:
|
||||
if element.is_a("IfcSpace"):
|
||||
continue
|
||||
global_id = element.GlobalId
|
||||
if global_id in self.existing_elements:
|
||||
collection = self.existing_elements[global_id].users_collection[0]
|
||||
self.spatial_structure_elements[global_id] = {"blender": collection}
|
||||
else:
|
||||
collection = bpy.data.collections.new(self.get_name(element))
|
||||
self.spatial_structure_elements[global_id] = {"blender": collection}
|
||||
parent.children.link(collection)
|
||||
obj = self.create_product(element)
|
||||
if obj:
|
||||
self.spatial_structure_elements[global_id]["blender_obj"] = obj
|
||||
collection.objects.link(obj)
|
||||
collection = bpy.data.collections.new(self.get_name(element))
|
||||
self.spatial_structure_elements[global_id] = {"blender": collection}
|
||||
parent.children.link(collection)
|
||||
obj = self.create_product(element)
|
||||
if obj:
|
||||
self.spatial_structure_elements[global_id]["blender_obj"] = obj
|
||||
collection.objects.link(obj)
|
||||
if element.IsDecomposedBy:
|
||||
for rel_aggregate in element.IsDecomposedBy:
|
||||
self.add_related_objects(collection, rel_aggregate.RelatedObjects)
|
||||
@@ -1228,7 +1207,7 @@ class IfcImporter:
|
||||
element = rel_aggregate.RelatingObject
|
||||
|
||||
obj = bpy.data.objects.new("{}/{}".format(element.is_a(), element.Name), None)
|
||||
IfcStore.link_element(element, obj)
|
||||
self.link_element(element, obj)
|
||||
self.place_object_in_spatial_tree(element, obj)
|
||||
|
||||
collection = bpy.data.collections.new(obj.name)
|
||||
@@ -1259,12 +1238,14 @@ class IfcImporter:
|
||||
bpy.ops.object.delete({"selected_objects": objects_to_purge})
|
||||
|
||||
def place_objects_in_spatial_tree(self):
|
||||
for ifc_definition_id, obj in IfcStore.id_map.items():
|
||||
self.place_object_in_spatial_tree(self.file.by_id(ifc_definition_id), obj)
|
||||
for global_id, obj in self.added_data.items():
|
||||
self.place_object_in_spatial_tree(self.file.by_guid(global_id), obj)
|
||||
|
||||
def place_object_in_spatial_tree(self, element, obj):
|
||||
if element.is_a("IfcProject"):
|
||||
return
|
||||
elif element.is_a("IfcTypeObject"):
|
||||
self.type_collection.objects.link(obj)
|
||||
elif element.GlobalId in self.spatial_structure_elements:
|
||||
if not obj.data:
|
||||
return
|
||||
@@ -1566,11 +1547,16 @@ class IfcImporter:
|
||||
return parent @ self.get_axis2placement(plc.RelativePlacement)
|
||||
|
||||
def set_default_context(self):
|
||||
ContextData.load()
|
||||
for subcontext in self.file.by_type("IfcGeometricRepresentationSubContext"):
|
||||
if subcontext.ContextIdentifier == "Body":
|
||||
bpy.context.scene.BIMProperties.contexts = str(subcontext.id())
|
||||
break
|
||||
|
||||
def link_element(self, element, obj):
|
||||
self.added_data[element.GlobalId] = obj
|
||||
IfcStore.link_element(element, obj)
|
||||
|
||||
|
||||
class IfcImportSettings:
|
||||
def __init__(self):
|
||||
|
||||
@@ -4,6 +4,7 @@ from . import ui, prop, operator
|
||||
classes = (
|
||||
operator.EditObjectPlacement,
|
||||
operator.AddRepresentation,
|
||||
operator.MapRepresentations,
|
||||
operator.MapRepresentation,
|
||||
operator.SwitchRepresentation,
|
||||
operator.RemoveRepresentation,
|
||||
|
||||
@@ -19,7 +19,10 @@ class Data:
|
||||
product = file.by_id(product_id)
|
||||
representations = []
|
||||
if product.is_a("IfcProduct"):
|
||||
representations = product.Representation.Representations
|
||||
if product.Representation:
|
||||
representations = product.Representation.Representations
|
||||
else:
|
||||
representations = []
|
||||
elif product.is_a("IfcTypeProduct"):
|
||||
representations = [rm.MappedRepresentation for rm in product.RepresentationMaps]
|
||||
for representation in representations:
|
||||
|
||||
@@ -203,15 +203,16 @@ class SwitchRepresentation(bpy.types.Operator):
|
||||
class RemoveRepresentation(bpy.types.Operator):
|
||||
bl_idname = "bim.remove_representation"
|
||||
bl_label = "Remove Representation"
|
||||
obj: bpy.props.StringProperty() # TODO
|
||||
obj: bpy.props.StringProperty()
|
||||
representation_id: bpy.props.IntProperty()
|
||||
|
||||
def execute(self, context):
|
||||
self.file = IfcStore.get_file()
|
||||
representation = self.file.by_id(self.representation_id)
|
||||
obj = bpy.context.active_object
|
||||
obj = bpy.data.objects.get(self.obj) if self.obj else bpy.context.active_object
|
||||
product = self.file.by_id(obj.BIMObjectProperties.ifc_definition_id)
|
||||
if representation.RepresentationType == "MappedRepresentation":
|
||||
is_mapped_representation = representation.RepresentationType == "MappedRepresentation"
|
||||
if is_mapped_representation:
|
||||
mesh_name = "{}/{}".format(
|
||||
representation.ContextOfItems.id(), representation.Items[0].MappingSource.MappedRepresentation.id()
|
||||
)
|
||||
@@ -225,33 +226,64 @@ class RemoveRepresentation(bpy.types.Operator):
|
||||
if not void_mesh:
|
||||
void_mesh = bpy.data.meshes.new("Void")
|
||||
obj.data = void_mesh
|
||||
if representation.RepresentationType != "MappedRepresentation":
|
||||
if not is_mapped_representation:
|
||||
bpy.data.meshes.remove(mesh)
|
||||
product = self.file.by_id(obj.BIMObjectProperties.ifc_definition_id)
|
||||
unassign_representation.Usecase(self.file, {"product": product, "representation": representation}).execute()
|
||||
remove_representation.Usecase(self.file, {"representation": representation}).execute()
|
||||
if not is_mapped_representation:
|
||||
remove_representation.Usecase(self.file, {"representation": representation}).execute()
|
||||
Data.load(product.id())
|
||||
return {"FINISHED"}
|
||||
|
||||
|
||||
class MapRepresentations(bpy.types.Operator):
|
||||
bl_idname = "bim.map_representations"
|
||||
bl_label = "Map Representations"
|
||||
product_id: bpy.props.IntProperty()
|
||||
type_product_id: bpy.props.IntProperty()
|
||||
|
||||
def execute(self, context):
|
||||
related_object = IfcStore.id_map[self.product_id]
|
||||
|
||||
if self.product_id not in Data.products:
|
||||
Data.load(self.product_id)
|
||||
|
||||
for representation_id in Data.products[self.product_id]:
|
||||
bpy.ops.bim.remove_representation(obj=related_object.name, representation_id=representation_id)
|
||||
|
||||
if self.type_product_id not in Data.products:
|
||||
Data.load(self.type_product_id)
|
||||
|
||||
for representation_id in Data.products[self.type_product_id]:
|
||||
bpy.ops.bim.map_representation(
|
||||
obj=related_object.name,
|
||||
representation_id=representation_id,
|
||||
obj_data=IfcStore.id_map[self.type_product_id].data.name,
|
||||
)
|
||||
return {"FINISHED"}
|
||||
|
||||
|
||||
class MapRepresentation(bpy.types.Operator):
|
||||
bl_idname = "bim.map_representation"
|
||||
bl_label = "Map Representation"
|
||||
obj: bpy.props.StringProperty()
|
||||
representation_id: bpy.props.IntProperty()
|
||||
obj_data: bpy.props.StringProperty()
|
||||
|
||||
def execute(self, context):
|
||||
objs = [bpy.data.objects.get(self.obj)] if self.obj else bpy.context.selected_objects
|
||||
obj_data = bpy.data.meshes.get(self.obj_data) if self.obj_data else bpy.context.active_object.data
|
||||
objs = [o for o in objs if o.data != obj_data]
|
||||
obj_data = bpy.data.meshes.get(self.obj_data) if self.obj_data else None
|
||||
|
||||
self.file = IfcStore.get_file()
|
||||
|
||||
for obj in objs:
|
||||
bpy.ops.bim.edit_object_placement(obj=obj.name)
|
||||
product = self.file.by_id(obj.BIMObjectProperties.ifc_definition_id)
|
||||
target_representation = self.file.by_id(obj_data.BIMMeshProperties.ifc_definition_id)
|
||||
obj.data = obj_data
|
||||
result = map_representation.Usecase(self.file, {"representation": target_representation}).execute()
|
||||
if obj_data:
|
||||
obj.data = obj_data
|
||||
result = map_representation.Usecase(
|
||||
self.file, {"representation": self.file.by_id(self.representation_id)}
|
||||
).execute()
|
||||
assign_representation.Usecase(self.file, {"product": product, "representation": result}).execute()
|
||||
Data.load(obj.BIMObjectProperties.ifc_definition_id)
|
||||
return {"FINISHED"}
|
||||
|
||||
@@ -32,10 +32,10 @@ class Usecase:
|
||||
self.settings["product"].RepresentationMaps = self.settings["product"].RepresentationMaps or None
|
||||
|
||||
def remove_representation_map_only(self, representation_map):
|
||||
dummy_representation = self.file.createIfcShapeRepresentation()
|
||||
representation_map.MappedRepresentation = dummy_representation
|
||||
ifcopenshell.util.element.remove_deep(self.file, representation_map)
|
||||
self.file.remove(representation_map)
|
||||
dummy_representation = self.file.createIfcShapeRepresentation()
|
||||
representation_map.MappedRepresentation = dummy_representation
|
||||
ifcopenshell.util.element.remove_deep(self.file, representation_map)
|
||||
self.file.remove(representation_map)
|
||||
|
||||
def unassign_products_using_mapped_representation(self, representation_map):
|
||||
mapped_representations = []
|
||||
@@ -46,10 +46,7 @@ class Usecase:
|
||||
continue
|
||||
for definition in inverse.OfProductRepresentation or []:
|
||||
for product in definition.ShapeOfProduct or []:
|
||||
mapped_representations.append({
|
||||
"product": product,
|
||||
"representation": inverse
|
||||
})
|
||||
mapped_representations.append({"product": product, "representation": inverse})
|
||||
just_representations.append(inverse)
|
||||
for item in mapped_representations:
|
||||
self.unassign_product_representation(item["product"], item["representation"])
|
||||
|
||||
@@ -115,7 +115,6 @@ class VIEW3D_MT_PIE_bim(bpy.types.Menu):
|
||||
pie = self.layout.menu_pie()
|
||||
pie.operator("bim.edit_object_placement")
|
||||
pie.operator("bim.update_mesh_representation")
|
||||
pie.operator("bim.map_representation")
|
||||
pie.operator("bim.pie_add_opening")
|
||||
pie.operator("bim.pie_update_container")
|
||||
pie.operator("bim.open_pie_class", text="Assign IFC Class")
|
||||
|
||||
@@ -2,6 +2,7 @@ import bpy
|
||||
import numpy as np
|
||||
import ifcopenshell
|
||||
import ifcopenshell.util.schema
|
||||
import ifcopenshell.util.element
|
||||
import blenderbim.bim.module.root.create_product as create_product
|
||||
import blenderbim.bim.module.root.remove_product as remove_product
|
||||
import blenderbim.bim.module.root.reassign_class as reassign_class
|
||||
@@ -219,16 +220,14 @@ class CopyClass(bpy.types.Operator):
|
||||
for obj in objects:
|
||||
if not obj.BIMObjectProperties.ifc_definition_id:
|
||||
continue
|
||||
result = copy_class.Usecase(self.file, {
|
||||
"product": self.file.by_id(obj.BIMObjectProperties.ifc_definition_id)
|
||||
}).execute()
|
||||
result = copy_class.Usecase(
|
||||
self.file, {"product": self.file.by_id(obj.BIMObjectProperties.ifc_definition_id)}
|
||||
).execute()
|
||||
IfcStore.link_element(result, obj)
|
||||
if obj.data.users == 1:
|
||||
bpy.ops.bim.add_representation(obj=obj.name)
|
||||
else:
|
||||
obj_data = obj.data.name
|
||||
temporary_mesh = bpy.data.meshes.new("Temporary Mesh")
|
||||
obj.data = temporary_mesh
|
||||
bpy.ops.bim.map_representation(obj=obj.name, obj_data=obj_data)
|
||||
bpy.data.meshes.remove(temporary_mesh)
|
||||
bpy.ops.bim.map_representations(
|
||||
product_id=result.id(), type_product_id=ifcopenshell.util.element.get_type(result).id()
|
||||
)
|
||||
return {"FINISHED"}
|
||||
|
||||
@@ -12,6 +12,7 @@ class AssignType(bpy.types.Operator):
|
||||
bl_label = "Assign Type"
|
||||
relating_type: bpy.props.IntProperty()
|
||||
related_object: bpy.props.StringProperty()
|
||||
should_map_representations: bpy.props.BoolProperty()
|
||||
|
||||
def execute(self, context):
|
||||
self.file = IfcStore.get_file()
|
||||
@@ -27,6 +28,10 @@ class AssignType(bpy.types.Operator):
|
||||
},
|
||||
).execute()
|
||||
Data.load(oprops.ifc_definition_id)
|
||||
|
||||
if self.should_map_representations:
|
||||
bpy.ops.bim.map_representations(product_id=oprops.ifc_definition_id, type_product_id=relating_type)
|
||||
|
||||
bpy.ops.bim.disable_editing_type(obj=related_object.name)
|
||||
return {"FINISHED"}
|
||||
|
||||
@@ -82,13 +87,13 @@ class SelectSimilarType(bpy.types.Operator):
|
||||
product = self.file.by_id(oprops.ifc_definition_id)
|
||||
declaration = IfcStore.get_schema().declaration_by_name(product.is_a())
|
||||
if ifcopenshell.util.schema.is_a(declaration, "IfcElementType"):
|
||||
related_objects = get_related_objects.Usecase(self.file, {
|
||||
"relating_type": self.file.by_id(oprops.ifc_definition_id)
|
||||
}).execute()
|
||||
related_objects = get_related_objects.Usecase(
|
||||
self.file, {"relating_type": self.file.by_id(oprops.ifc_definition_id)}
|
||||
).execute()
|
||||
else:
|
||||
related_objects = get_related_objects.Usecase(self.file, {
|
||||
"related_object": self.file.by_id(oprops.ifc_definition_id)
|
||||
}).execute()
|
||||
related_objects = get_related_objects.Usecase(
|
||||
self.file, {"related_object": self.file.by_id(oprops.ifc_definition_id)}
|
||||
).execute()
|
||||
for obj in bpy.context.visible_objects:
|
||||
if obj.BIMObjectProperties.ifc_definition_id in related_objects:
|
||||
obj.select_set(True)
|
||||
|
||||
@@ -35,7 +35,8 @@ class BIM_PT_type(Panel):
|
||||
row.prop(props, "relating_type_class", text="")
|
||||
if props.relating_type:
|
||||
row.prop(props, "relating_type", text="")
|
||||
row.operator("bim.assign_type", icon="CHECKMARK", text="")
|
||||
op = row.operator("bim.assign_type", icon="CHECKMARK", text="")
|
||||
op.should_map_representations = props.should_map_representations
|
||||
else:
|
||||
row.prop(props, "blank_relating_type", text="")
|
||||
row.operator("bim.disable_editing_type", icon="X", text="")
|
||||
|
||||
@@ -34,6 +34,21 @@ sheets_enum = []
|
||||
vector_styles_enum = []
|
||||
|
||||
|
||||
def updateIfcFile(self, context):
|
||||
if context.scene.BIMProperties.ifc_file:
|
||||
IfcStore.file = None
|
||||
IfcStore.schema = None
|
||||
# Purge data cache
|
||||
from blenderbim.bim import modules
|
||||
for module in modules.values():
|
||||
if not module:
|
||||
continue
|
||||
try:
|
||||
getattr(getattr(module, 'data'), 'Data').purge()
|
||||
except AttributeError:
|
||||
pass
|
||||
|
||||
|
||||
def getDiagramScales(self, context):
|
||||
global diagram_scales_enum
|
||||
if (
|
||||
@@ -391,7 +406,7 @@ class BIMTextProperties(PropertyGroup):
|
||||
class BIMProperties(PropertyGroup):
|
||||
schema_dir: StringProperty(default=os.path.join(cwd, "schema") + os.path.sep, name="Schema Directory")
|
||||
data_dir: StringProperty(default=os.path.join(cwd, "data") + os.path.sep, name="Data Directory")
|
||||
ifc_file: StringProperty(name="IFC File")
|
||||
ifc_file: StringProperty(name="IFC File", update=updateIfcFile)
|
||||
id_map: StringProperty(name="ID Map")
|
||||
guid_map: StringProperty(name="GUID Map")
|
||||
export_schema: EnumProperty(items=[("IFC4", "IFC4", ""), ("IFC2X3", "IFC2X3", "")], name="IFC Schema")
|
||||
|
||||
Reference in New Issue
Block a user