mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-09-28 11:18:18 +00:00
Parametric profiles now auto sync prior to depth changes. See #1588.
This commit is contained in:
@@ -7,6 +7,7 @@ import bmesh
|
|||||||
import shutil
|
import shutil
|
||||||
import subprocess
|
import subprocess
|
||||||
import webbrowser
|
import webbrowser
|
||||||
|
import multiprocessing
|
||||||
import ifcopenshell
|
import ifcopenshell
|
||||||
import ifcopenshell.geom
|
import ifcopenshell.geom
|
||||||
import ifcopenshell.util.selector
|
import ifcopenshell.util.selector
|
||||||
@@ -236,7 +237,7 @@ class CreateDrawing(bpy.types.Operator):
|
|||||||
# This is a work in progress. See #1153 and #1564.
|
# This is a work in progress. See #1153 and #1564.
|
||||||
# Switch from old to new if you are testing v0.7.0
|
# Switch from old to new if you are testing v0.7.0
|
||||||
self.generate_linework_old(svg_path)
|
self.generate_linework_old(svg_path)
|
||||||
#self.generate_linework_new(svg_path)
|
# self.generate_linework_new(svg_path)
|
||||||
return svg_path
|
return svg_path
|
||||||
|
|
||||||
def generate_linework_new(self, svg_path):
|
def generate_linework_new(self, svg_path):
|
||||||
@@ -257,7 +258,9 @@ class CreateDrawing(bpy.types.Operator):
|
|||||||
excluded_elements = []
|
excluded_elements = []
|
||||||
for ifc_class in ["IfcSpace", "IfcOpeningElement", "IfcDoor", "IfcWindow"]:
|
for ifc_class in ["IfcSpace", "IfcOpeningElement", "IfcDoor", "IfcWindow"]:
|
||||||
excluded_elements += self.file.by_type(ifc_class)
|
excluded_elements += self.file.by_type(ifc_class)
|
||||||
for element in ifcopenshell.geom.iterate(settings, self.file, exclude=excluded_elements):
|
for element in ifcopenshell.geom.iterate(
|
||||||
|
settings, self.file, multiprocessing.cpu_count(), exclude=excluded_elements
|
||||||
|
):
|
||||||
serialiser.write(element)
|
serialiser.write(element)
|
||||||
serialiser.finalize()
|
serialiser.finalize()
|
||||||
with open(svg_path, "w") as svg:
|
with open(svg_path, "w") as svg:
|
||||||
|
|||||||
@@ -57,6 +57,11 @@ def load_post(*args):
|
|||||||
ifcopenshell.api.add_pre_listener(
|
ifcopenshell.api.add_pre_listener(
|
||||||
"geometry.add_representation", "BlenderBIM.DumbProfile.EnsureSolid", profile.ensure_solid
|
"geometry.add_representation", "BlenderBIM.DumbProfile.EnsureSolid", profile.ensure_solid
|
||||||
)
|
)
|
||||||
|
ifcopenshell.api.add_pre_listener(
|
||||||
|
"material.edit_profile",
|
||||||
|
"BlenderBIM.DumbProfile.SyncObjectFromProfile",
|
||||||
|
profile.DumbProfileRegenerator().sync_object_from_profile,
|
||||||
|
)
|
||||||
ifcopenshell.api.add_post_listener(
|
ifcopenshell.api.add_post_listener(
|
||||||
"material.edit_profile",
|
"material.edit_profile",
|
||||||
"BlenderBIM.DumbProfile.RegenerateFromProfile",
|
"BlenderBIM.DumbProfile.RegenerateFromProfile",
|
||||||
|
|||||||
@@ -20,7 +20,7 @@ def element_listener(element, obj):
|
|||||||
|
|
||||||
|
|
||||||
def mode_callback(obj, data):
|
def mode_callback(obj, data):
|
||||||
for obj in bpy.context.selected_objects + [bpy.context.active_object]:
|
for obj in set(bpy.context.selected_objects + [bpy.context.active_object]):
|
||||||
if (
|
if (
|
||||||
obj.mode != "EDIT"
|
obj.mode != "EDIT"
|
||||||
or not obj.data
|
or not obj.data
|
||||||
@@ -147,30 +147,40 @@ class DumbProfileGenerator:
|
|||||||
|
|
||||||
class DumbProfileRegenerator:
|
class DumbProfileRegenerator:
|
||||||
def regenerate_from_profile(self, usecase_path, ifc_file, settings):
|
def regenerate_from_profile(self, usecase_path, ifc_file, settings):
|
||||||
self.file = IfcStore.get_file()
|
self.file = ifc_file
|
||||||
self.unit_scale = ifcopenshell.util.unit.calculate_unit_scale(ifc_file)
|
|
||||||
profile = settings["profile"].Profile
|
profile = settings["profile"].Profile
|
||||||
if not profile:
|
if not profile:
|
||||||
return
|
return
|
||||||
|
for element in self.get_elements_using_profile(profile):
|
||||||
|
self.change_profile(element)
|
||||||
|
|
||||||
|
def sync_object_from_profile(self, usecase_path, ifc_file, settings):
|
||||||
|
self.file = ifc_file
|
||||||
|
profile = settings["profile"].Profile
|
||||||
|
if not profile:
|
||||||
|
return
|
||||||
|
for element in self.get_elements_using_profile(profile):
|
||||||
|
self.sync_object(element)
|
||||||
|
|
||||||
|
def get_elements_using_profile(self, profile):
|
||||||
|
results = []
|
||||||
for profile_set in [
|
for profile_set in [
|
||||||
mp.ToMaterialProfileSet[0] for mp in self.file.get_inverse(profile) if mp.is_a("IfcMaterialProfile")
|
mp.ToMaterialProfileSet[0] for mp in self.file.get_inverse(profile) if mp.is_a("IfcMaterialProfile")
|
||||||
]:
|
]:
|
||||||
for inverse in ifc_file.get_inverse(profile_set):
|
for inverse in self.file.get_inverse(profile_set):
|
||||||
if not inverse.is_a("IfcMaterialProfileSetUsage"):
|
if not inverse.is_a("IfcMaterialProfileSetUsage"):
|
||||||
continue
|
continue
|
||||||
if ifc_file.schema == "IFC2X3":
|
if self.file.schema == "IFC2X3":
|
||||||
for rel in ifc_file.get_inverse(inverse):
|
for rel in self.file.get_inverse(inverse):
|
||||||
if not rel.is_a("IfcRelAssociatesMaterial"):
|
if not rel.is_a("IfcRelAssociatesMaterial"):
|
||||||
continue
|
continue
|
||||||
for element in rel.RelatedObjects:
|
results.extend(rel.RelatedObjects)
|
||||||
self.change_profile(element)
|
|
||||||
else:
|
else:
|
||||||
for rel in inverse.AssociatedTo:
|
for rel in inverse.AssociatedTo:
|
||||||
for element in rel.RelatedObjects:
|
results.extend(rel.RelatedObjects)
|
||||||
self.change_profile(element)
|
return results
|
||||||
|
|
||||||
def regenerate_from_type(self, usecase_path, ifc_file, settings):
|
def regenerate_from_type(self, usecase_path, ifc_file, settings):
|
||||||
self.unit_scale = ifcopenshell.util.unit.calculate_unit_scale(ifc_file)
|
|
||||||
new_material = ifcopenshell.util.element.get_material(settings["relating_type"])
|
new_material = ifcopenshell.util.element.get_material(settings["relating_type"])
|
||||||
if not new_material or not new_material.is_a("IfcMaterialProfileSet"):
|
if not new_material or not new_material.is_a("IfcMaterialProfileSet"):
|
||||||
return
|
return
|
||||||
@@ -185,3 +195,9 @@ class DumbProfileRegenerator:
|
|||||||
bpy.ops.bim.switch_representation(
|
bpy.ops.bim.switch_representation(
|
||||||
obj=obj.name, ifc_definition_id=representation.id(), should_reload=True, should_switch_all_meshes=True
|
obj=obj.name, ifc_definition_id=representation.id(), should_reload=True, should_switch_all_meshes=True
|
||||||
)
|
)
|
||||||
|
|
||||||
|
def sync_object(self, element):
|
||||||
|
obj = IfcStore.get_element(element.id())
|
||||||
|
if not obj or obj not in IfcStore.edited_objs:
|
||||||
|
return
|
||||||
|
bpy.ops.bim.update_representation(obj=obj.name)
|
||||||
|
|||||||
Reference in New Issue
Block a user