mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-09-29 11:46:33 +00:00
WIP unbreak drawing generation and support box context generation. See #1222.
This commit is contained in:
@@ -377,6 +377,8 @@ class IfcImporter:
|
|||||||
if self.ifc_import_settings.should_clean_mesh and len(self.file.by_type("IfcElement")) < 1000:
|
if self.ifc_import_settings.should_clean_mesh and len(self.file.by_type("IfcElement")) < 1000:
|
||||||
self.clean_mesh()
|
self.clean_mesh()
|
||||||
self.profile_code("Mesh cleaning")
|
self.profile_code("Mesh cleaning")
|
||||||
|
self.set_default_context()
|
||||||
|
self.profile_code("Setting default context")
|
||||||
|
|
||||||
def auto_set_workarounds(self):
|
def auto_set_workarounds(self):
|
||||||
applications = self.file.by_type("IfcApplication")
|
applications = self.file.by_type("IfcApplication")
|
||||||
@@ -1539,6 +1541,12 @@ class IfcImporter:
|
|||||||
parent = self.get_local_placement(plc.PlacementRelTo)
|
parent = self.get_local_placement(plc.PlacementRelTo)
|
||||||
return parent @ self.get_axis2placement(plc.RelativePlacement)
|
return parent @ self.get_axis2placement(plc.RelativePlacement)
|
||||||
|
|
||||||
|
def set_default_context(self):
|
||||||
|
for subcontext in self.file.by_type("IfcGeometricRepresentationSubContext"):
|
||||||
|
if subcontext.ContextIdentifier == "Body":
|
||||||
|
bpy.context.scene.BIMProperties.contexts = str(subcontext.id())
|
||||||
|
break
|
||||||
|
|
||||||
|
|
||||||
class IfcImportSettings:
|
class IfcImportSettings:
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
|
|||||||
@@ -300,3 +300,18 @@ class Usecase:
|
|||||||
"GeometricCurveSet",
|
"GeometricCurveSet",
|
||||||
[geometric_curve_set],
|
[geometric_curve_set],
|
||||||
)
|
)
|
||||||
|
|
||||||
|
def create_box_representation(self):
|
||||||
|
obj = self.settings["blender_object"]
|
||||||
|
bounding_box = self.file.createIfcBoundingBox(
|
||||||
|
self.create_cartesian_point(obj.bound_box[0][0], obj.bound_box[0][1], obj.bound_box[0][2]),
|
||||||
|
self.convert_si_to_unit(obj.dimensions[0]),
|
||||||
|
self.convert_si_to_unit(obj.dimensions[1]),
|
||||||
|
self.convert_si_to_unit(obj.dimensions[2]),
|
||||||
|
)
|
||||||
|
return self.file.createIfcShapeRepresentation(
|
||||||
|
self.settings["context"],
|
||||||
|
self.settings["context"].ContextIdentifier,
|
||||||
|
"BoundingBox",
|
||||||
|
[bounding_box],
|
||||||
|
)
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
import bpy
|
import bpy
|
||||||
import numpy as np
|
import numpy as np
|
||||||
import ifcopenshell
|
import ifcopenshell
|
||||||
|
import ifcopenshell.util.element
|
||||||
import logging
|
import logging
|
||||||
import blenderbim.bim.module.geometry.edit_object_placement as edit_object_placement
|
import blenderbim.bim.module.geometry.edit_object_placement as edit_object_placement
|
||||||
import blenderbim.bim.module.geometry.add_representation as add_representation
|
import blenderbim.bim.module.geometry.add_representation as add_representation
|
||||||
@@ -11,6 +12,15 @@ import blenderbim.bim.module.geometry.remove_representation as remove_representa
|
|||||||
from blenderbim.bim.ifc import IfcStore
|
from blenderbim.bim.ifc import IfcStore
|
||||||
from blenderbim.bim import import_ifc
|
from blenderbim.bim import import_ifc
|
||||||
from blenderbim.bim.module.geometry.data import Data
|
from blenderbim.bim.module.geometry.data import Data
|
||||||
|
from blenderbim.bim.module.context.data import Data as ContextData
|
||||||
|
|
||||||
|
|
||||||
|
def get_box_context_id():
|
||||||
|
for context in ContextData.contexts.values():
|
||||||
|
if context["ContextType"] == "Model":
|
||||||
|
for i, subcontext in context["HasSubContexts"].items():
|
||||||
|
if subcontext["ContextIdentifier"] == "Box" and subcontext["TargetView"] == "MODEL_VIEW":
|
||||||
|
return i
|
||||||
|
|
||||||
|
|
||||||
class EditObjectPlacement(bpy.types.Operator):
|
class EditObjectPlacement(bpy.types.Operator):
|
||||||
@@ -76,20 +86,35 @@ class AddRepresentation(bpy.types.Operator):
|
|||||||
bpy.ops.bim.edit_object_placement(obj=obj.name)
|
bpy.ops.bim.edit_object_placement(obj=obj.name)
|
||||||
|
|
||||||
if obj.data:
|
if obj.data:
|
||||||
result = add_representation.Usecase(
|
product = self.file.by_id(obj.BIMObjectProperties.ifc_definition_id)
|
||||||
self.file,
|
context_of_items = self.file.by_id(context_id)
|
||||||
{
|
|
||||||
"context": self.file.by_id(context_id),
|
representation_data = {
|
||||||
"blender_object": obj,
|
"context": context_of_items,
|
||||||
"geometry": obj.data,
|
"blender_object": obj,
|
||||||
"total_items": max(1, len(obj.material_slots)),
|
"geometry": obj.data,
|
||||||
"should_force_faceted_brep": context.scene.BIMGeometryProperties.should_force_faceted_brep,
|
"total_items": max(1, len(obj.material_slots)),
|
||||||
"should_force_triangulation": context.scene.BIMGeometryProperties.should_force_triangulation,
|
"should_force_faceted_brep": context.scene.BIMGeometryProperties.should_force_faceted_brep,
|
||||||
},
|
"should_force_triangulation": context.scene.BIMGeometryProperties.should_force_triangulation,
|
||||||
).execute()
|
}
|
||||||
|
|
||||||
|
result = add_representation.Usecase(self.file, representation_data).execute()
|
||||||
|
|
||||||
if not result:
|
if not result:
|
||||||
print("Failed to write shape representation")
|
print("Failed to write shape representation")
|
||||||
return {"FINISHED"}
|
return {"FINISHED"}
|
||||||
|
|
||||||
|
box_context_id = get_box_context_id()
|
||||||
|
if (
|
||||||
|
box_context_id
|
||||||
|
and context_of_items.ContextType == "Model"
|
||||||
|
and context_of_items.ContextIdentifier
|
||||||
|
and context_of_items.ContextIdentifier == "Body"
|
||||||
|
):
|
||||||
|
representation_data["context"] = self.file.by_id(box_context_id)
|
||||||
|
new_box = add_representation.Usecase(self.file, representation_data).execute()
|
||||||
|
assign_representation.Usecase(self.file, {"product": product, "representation": new_box}).execute()
|
||||||
|
|
||||||
assign_styles.Usecase(
|
assign_styles.Usecase(
|
||||||
self.file,
|
self.file,
|
||||||
{
|
{
|
||||||
@@ -102,10 +127,7 @@ class AddRepresentation(bpy.types.Operator):
|
|||||||
"should_use_presentation_style_assignment": context.scene.BIMGeometryProperties.should_use_presentation_style_assignment,
|
"should_use_presentation_style_assignment": context.scene.BIMGeometryProperties.should_use_presentation_style_assignment,
|
||||||
},
|
},
|
||||||
).execute()
|
).execute()
|
||||||
assign_representation.Usecase(
|
assign_representation.Usecase(self.file, {"product": product, "representation": result}).execute()
|
||||||
self.file,
|
|
||||||
{"product": self.file.by_id(obj.BIMObjectProperties.ifc_definition_id), "representation": result},
|
|
||||||
).execute()
|
|
||||||
|
|
||||||
existing_mesh = obj.data
|
existing_mesh = obj.data
|
||||||
mesh = obj.data.copy()
|
mesh = obj.data.copy()
|
||||||
@@ -216,28 +238,48 @@ class UpdateMeshRepresentation(bpy.types.Operator):
|
|||||||
obj: bpy.props.StringProperty()
|
obj: bpy.props.StringProperty()
|
||||||
|
|
||||||
def execute(self, context):
|
def execute(self, context):
|
||||||
|
if not ContextData.is_loaded:
|
||||||
|
ContextData.load()
|
||||||
|
|
||||||
objs = [bpy.data.objects.get(self.obj)] if self.obj else bpy.context.selected_objects
|
objs = [bpy.data.objects.get(self.obj)] if self.obj else bpy.context.selected_objects
|
||||||
self.file = IfcStore.get_file()
|
self.file = IfcStore.get_file()
|
||||||
|
|
||||||
for obj in objs:
|
for obj in objs:
|
||||||
bpy.ops.bim.edit_object_placement(obj=obj.name)
|
bpy.ops.bim.edit_object_placement(obj=obj.name)
|
||||||
|
|
||||||
|
product = self.file.by_id(obj.BIMObjectProperties.ifc_definition_id)
|
||||||
old_representation = self.file.by_id(obj.data.BIMMeshProperties.ifc_definition_id)
|
old_representation = self.file.by_id(obj.data.BIMMeshProperties.ifc_definition_id)
|
||||||
new_representation = add_representation.Usecase(
|
context_of_items = old_representation.ContextOfItems
|
||||||
self.file,
|
|
||||||
{
|
representation_data = {
|
||||||
"context": old_representation.ContextOfItems,
|
"context": context_of_items,
|
||||||
"blender_object": obj,
|
"blender_object": obj,
|
||||||
"geometry": obj.data,
|
"geometry": obj.data,
|
||||||
"total_items": max(1, len(obj.material_slots)),
|
"total_items": max(1, len(obj.material_slots)),
|
||||||
"should_force_faceted_brep": context.scene.BIMGeometryProperties.should_force_faceted_brep,
|
"should_force_faceted_brep": context.scene.BIMGeometryProperties.should_force_faceted_brep,
|
||||||
"should_force_triangulation": context.scene.BIMGeometryProperties.should_force_triangulation,
|
"should_force_triangulation": context.scene.BIMGeometryProperties.should_force_triangulation,
|
||||||
},
|
}
|
||||||
).execute()
|
|
||||||
|
new_representation = add_representation.Usecase(self.file, representation_data).execute()
|
||||||
|
|
||||||
if not new_representation:
|
if not new_representation:
|
||||||
print("Failed to write shape representation")
|
print("Failed to write shape representation")
|
||||||
return {"FINISHED"}
|
return {"FINISHED"}
|
||||||
|
|
||||||
|
box_context_id = get_box_context_id()
|
||||||
|
old_box = ifcopenshell.util.element.get_representation(product, "Model", "Box", "MODEL_VIEW")
|
||||||
|
if (
|
||||||
|
box_context_id
|
||||||
|
and old_box
|
||||||
|
and context_of_items.ContextType == "Model"
|
||||||
|
and context_of_items.ContextIdentifier
|
||||||
|
and context_of_items.ContextIdentifier == "Body"
|
||||||
|
):
|
||||||
|
representation_data["context"] = self.file.by_id(box_context_id)
|
||||||
|
new_box = add_representation.Usecase(self.file, representation_data).execute()
|
||||||
|
for inverse in self.file.get_inverse(old_box):
|
||||||
|
ifcopenshell.util.element.replace_attribute(inverse, old_box, new_box)
|
||||||
|
|
||||||
assign_styles.Usecase(
|
assign_styles.Usecase(
|
||||||
self.file,
|
self.file,
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -614,10 +614,14 @@ class CutSection(bpy.types.Operator):
|
|||||||
bpy.data.objects[name].hide_set(value)
|
bpy.data.objects[name].hide_set(value)
|
||||||
|
|
||||||
def does_obj_have_target_view_representation(self, obj, camera):
|
def does_obj_have_target_view_representation(self, obj, camera):
|
||||||
for representation in obj.BIMObjectProperties.representations:
|
if not obj.BIMObjectProperties.ifc_definition_id:
|
||||||
element = self.file.by_id(representation.ifc_definition_id)
|
return False
|
||||||
|
element = self.file.by_id(obj.BIMObjectProperties.ifc_definition_id)
|
||||||
|
if not element.Representation:
|
||||||
|
return False
|
||||||
|
for representation in element.Representation.Representations:
|
||||||
if ifcopenshell.util.element.is_representation_of_context(
|
if ifcopenshell.util.element.is_representation_of_context(
|
||||||
element, "Plan", "Annotation", camera.data.BIMCameraProperties.target_view
|
representation, "Plan", "Annotation", camera.data.BIMCameraProperties.target_view
|
||||||
):
|
):
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user