diff --git a/src/blenderbim/blenderbim/bim/module/model/data.py b/src/blenderbim/blenderbim/bim/module/model/data.py index 92d37d2e28..461255dbd2 100644 --- a/src/blenderbim/blenderbim/bim/module/model/data.py +++ b/src/blenderbim/blenderbim/bim/module/model/data.py @@ -324,14 +324,14 @@ class AuthoringData: def new_relating_type(cls, ifc_class=None, relating_type_id=None): if ifc_class is None: bpy.ops.bim.add_constr_type_instance( - ifc_class=cls.props.ifc_class, relating_type_id=int(cls.props.relating_type_id), link_to_scene=True + ifc_class=cls.props.ifc_class, relating_type_id=int(cls.props.relating_type_id) ) else: cls.props.updating = True cls.props.ifc_class = ifc_class cls.props.relating_type_id = str(relating_type_id) cls.props.updating = False - bpy.ops.bim.add_constr_type_instance(link_to_scene=True) + bpy.ops.bim.add_constr_type_instance() return bpy.context.selected_objects[-1] @staticmethod diff --git a/src/blenderbim/blenderbim/bim/module/model/mep.py b/src/blenderbim/blenderbim/bim/module/model/mep.py index 1e6f3019d4..a8381f6e43 100644 --- a/src/blenderbim/blenderbim/bim/module/model/mep.py +++ b/src/blenderbim/blenderbim/bim/module/model/mep.py @@ -38,7 +38,7 @@ class MepGenerator: def __init__(self, relating_type): self.relating_type = relating_type - def generate(self, link_to_scene=True): + def generate(self): self.file = tool.Ifc.get() self.collection = bpy.context.view_layer.active_layer_collection.collection @@ -55,15 +55,15 @@ class MepGenerator: self.height = dimensions.get("NominalHeight") self.length = 1 - return self.derive_from_cursor(link_to_scene=link_to_scene) + return self.derive_from_cursor() elif self.relating_type.is_a("IfcPipeSegmentType"): pass - def derive_from_cursor(self, link_to_scene): + def derive_from_cursor(self): self.location = bpy.context.scene.cursor.location - return self.create_rectangle_segment(link_to_scene) + return self.create_rectangle_segment() - def create_rectangle_segment(self, link_to_scene): + def create_rectangle_segment(self): verts = [ Vector((-self.width / 2, self.height / 2, 0)), Vector((-self.width / 2, -self.height / 2, 0)), @@ -89,11 +89,11 @@ class MepGenerator: ifc_class = ifc_classes[0] obj = bpy.data.objects.new(tool.Model.generate_occurrence_name(self.relating_type, ifc_class), mesh) - if link_to_scene: - obj.location = self.location - obj.rotation_euler[0] = math.pi / 2 - obj.rotation_euler[2] = math.pi / 2 - self.collection.objects.link(obj) + + obj.location = self.location + obj.rotation_euler[0] = math.pi / 2 + obj.rotation_euler[2] = math.pi / 2 + self.collection.objects.link(obj) bpy.ops.bim.assign_class( obj=obj.name, diff --git a/src/blenderbim/blenderbim/bim/module/model/product.py b/src/blenderbim/blenderbim/bim/module/model/product.py index 6d93cb8ee5..f50a785824 100644 --- a/src/blenderbim/blenderbim/bim/module/model/product.py +++ b/src/blenderbim/blenderbim/bim/module/model/product.py @@ -68,7 +68,6 @@ class AddConstrTypeInstance(bpy.types.Operator): ifc_class: bpy.props.StringProperty() relating_type_id: bpy.props.IntProperty() from_invoke: bpy.props.BoolProperty(default=False) - link_to_scene: bpy.props.BoolProperty(default=True) def invoke(self, context, event): return self.execute(context) @@ -94,14 +93,14 @@ class AddConstrTypeInstance(bpy.types.Operator): material = ifcopenshell.util.element.get_material(relating_type) if material and material.is_a("IfcMaterialProfileSet"): - if profile.DumbProfileGenerator(relating_type).generate(link_to_scene=self.link_to_scene): + if profile.DumbProfileGenerator(relating_type).generate(): return {"FINISHED"} elif material and material.is_a("IfcMaterialLayerSet"): - if self.generate_layered_element(ifc_class, relating_type, link_to_scene=self.link_to_scene): + if self.generate_layered_element(ifc_class, relating_type): select_and_activate_single_object(context, context.selected_objects[-1]) return {"FINISHED"} if relating_type.is_a("IfcFlowSegmentType") and not relating_type.RepresentationMaps: - if mep.MepGenerator(relating_type).generate(link_to_scene=self.link_to_scene): + if mep.MepGenerator(relating_type).generate(): return {"FINISHED"} building_obj = None @@ -132,17 +131,18 @@ class AddConstrTypeInstance(bpy.types.Operator): mesh = bpy.data.meshes.new(name="Instance") mesh.from_pydata(verts, edges, faces) obj = bpy.data.objects.new(tool.Model.generate_occurrence_name(relating_type, instance_class), mesh) - if self.link_to_scene: - obj.location = context.scene.cursor.location - collection = context.view_layer.active_layer_collection.collection - collection.objects.link(obj) - collection_obj = bpy.data.objects.get(collection.name) + + obj.location = context.scene.cursor.location + collection = context.view_layer.active_layer_collection.collection + collection.objects.link(obj) + collection_obj = bpy.data.objects.get(collection.name) + bpy.ops.bim.assign_class(obj=obj.name, ifc_class=instance_class) element = tool.Ifc.get_entity(obj) blenderbim.core.type.assign_type(tool.Ifc, tool.Type, element=element, type=relating_type) - if self.link_to_scene: - # Update required as core.type.assign_type may change obj.data - context.view_layer.update() + + # Update required as core.type.assign_type may change obj.data + context.view_layer.update() # set occurences properties for the types defined with modifiers if instance_class in ["IfcWindow", "IfcDoor"]: @@ -161,7 +161,7 @@ class AddConstrTypeInstance(bpy.types.Operator): if instance_class in ["IfcWindow", "IfcDoor"]: # TODO For now we are hardcoding windows and doors as a prototype bpy.ops.bim.add_filled_opening(voided_obj=building_obj.name, filling_obj=obj.name) - elif self.link_to_scene: + else: if collection_obj and collection_obj.BIMObjectProperties.ifc_definition_id: obj.location[2] = collection_obj.location[2] - min([v[2] for v in obj.bound_box]) @@ -183,7 +183,7 @@ class AddConstrTypeInstance(bpy.types.Operator): return {"FINISHED"} @staticmethod - def generate_layered_element(ifc_class, relating_type, link_to_scene=True): + def generate_layered_element(ifc_class, relating_type): layer_set_direction = None parametric = ifcopenshell.util.element.get_psets(relating_type).get("EPset_Parametric") @@ -197,9 +197,9 @@ class AddConstrTypeInstance(bpy.types.Operator): obj = None if layer_set_direction == "AXIS3": - obj = slab.DumbSlabGenerator(relating_type).generate(link_to_scene=link_to_scene) + obj = slab.DumbSlabGenerator(relating_type).generate() elif layer_set_direction == "AXIS2": - obj = wall.DumbWallGenerator(relating_type).generate(link_to_scene=link_to_scene) + obj = wall.DumbWallGenerator(relating_type).generate() else: pass # Dumb block generator? Eh? :) diff --git a/src/blenderbim/blenderbim/bim/module/model/profile.py b/src/blenderbim/blenderbim/bim/module/model/profile.py index 75a8579f6f..19878e32b8 100644 --- a/src/blenderbim/blenderbim/bim/module/model/profile.py +++ b/src/blenderbim/blenderbim/bim/module/model/profile.py @@ -96,7 +96,7 @@ class DumbProfileGenerator: self.relating_type = relating_type self.unit_scale = ifcopenshell.util.unit.calculate_unit_scale(tool.Ifc.get()) - def generate(self, link_to_scene=True): + def generate(self): self.file = IfcStore.get_file() self.unit_scale = ifcopenshell.util.unit.calculate_unit_scale(IfcStore.get_file()) material = ifcopenshell.util.element.get_material(self.relating_type) @@ -114,13 +114,13 @@ class DumbProfileGenerator: self.rotation = 0 self.location = Vector((0, 0, 0)) self.cardinal_point = int(bpy.context.scene.BIMModelProperties.cardinal_point) - return self.derive_from_cursor(link_to_scene=link_to_scene) + return self.derive_from_cursor() - def derive_from_cursor(self, link_to_scene): + def derive_from_cursor(self): self.location = bpy.context.scene.cursor.location - return self.create_profile(link_to_scene) + return self.create_profile() - def create_profile(self, link_to_scene): + def create_profile(self): ifc_classes = ifcopenshell.util.type.get_applicable_entities(self.relating_type.is_a(), self.file.schema) # Standard cases are deprecated, so let's cull them ifc_class = [c for c in ifc_classes if "StandardCase" not in c][0] @@ -132,10 +132,9 @@ class DumbProfileGenerator: if self.relating_type.is_a() in ["IfcBeamType", "IfcMemberType"]: matrix_world = Matrix.Rotation(pi / 2, 4, "Z") @ Matrix.Rotation(pi / 2, 4, "X") @ matrix_world matrix_world.col[3] = self.location.to_4d() - if link_to_scene and self.collection_obj and self.collection_obj.BIMObjectProperties.ifc_definition_id: + if self.collection_obj and self.collection_obj.BIMObjectProperties.ifc_definition_id: matrix_world[2][3] = self.collection_obj.location[2] - if link_to_scene: - self.collection.objects.link(obj) + self.collection.objects.link(obj) element = blenderbim.core.root.assign_class( tool.Ifc, @@ -190,8 +189,7 @@ class DumbProfileGenerator: pset = ifcopenshell.api.run("pset.add_pset", self.file, product=element, name="EPset_Parametric") ifcopenshell.api.run("pset.edit_pset", self.file, pset=pset, properties={"Engine": "BlenderBIM.DumbProfile"}) - if link_to_scene: - obj.select_set(True) + obj.select_set(True) return obj diff --git a/src/blenderbim/blenderbim/bim/module/model/slab.py b/src/blenderbim/blenderbim/bim/module/model/slab.py index 044a63f73c..15e60d43bc 100644 --- a/src/blenderbim/blenderbim/bim/module/model/slab.py +++ b/src/blenderbim/blenderbim/bim/module/model/slab.py @@ -122,7 +122,7 @@ class DumbSlabGenerator: def __init__(self, relating_type): self.relating_type = relating_type - def generate(self, link_to_scene=True): + def generate(self): self.file = IfcStore.get_file() unit_scale = ifcopenshell.util.unit.calculate_unit_scale(IfcStore.get_file()) thicknesses = [] @@ -149,13 +149,13 @@ class DumbSlabGenerator: self.rotation = 0 self.location = Vector((0, 0, 0)) self.x_angle = 0 if tool.Cad.is_x(props.x_angle, 0, tolerance=0.001) else radians(props.x_angle) - return self.derive_from_cursor(link_to_scene=link_to_scene) + return self.derive_from_cursor() - def derive_from_cursor(self, link_to_scene): + def derive_from_cursor(self): self.location = bpy.context.scene.cursor.location - return self.create_slab(link_to_scene) + return self.create_slab() - def create_slab(self, link_to_scene): + def create_slab(self): ifc_classes = ifcopenshell.util.type.get_applicable_entities(self.relating_type.is_a(), self.file.schema) # Standard cases are deprecated, so let's cull them ifc_class = [c for c in ifc_classes if "StandardCase" not in c][0] @@ -163,16 +163,15 @@ class DumbSlabGenerator: mesh = bpy.data.meshes.new("Dummy") obj = bpy.data.objects.new(tool.Model.generate_occurrence_name(self.relating_type, ifc_class), mesh) - if link_to_scene: - matrix_world = Matrix() - matrix_world.col[3] = self.location.to_4d() - if self.collection_obj and self.collection_obj.BIMObjectProperties.ifc_definition_id: - matrix_world[2][3] = self.collection_obj.location[2] - self.depth - else: - matrix_world[2][3] -= self.depth - obj.matrix_world = Matrix.Rotation(self.x_angle, 4, "X") @ matrix_world - bpy.context.view_layer.update() - self.collection.objects.link(obj) + matrix_world = Matrix() + matrix_world.col[3] = self.location.to_4d() + if self.collection_obj and self.collection_obj.BIMObjectProperties.ifc_definition_id: + matrix_world[2][3] = self.collection_obj.location[2] - self.depth + else: + matrix_world[2][3] -= self.depth + obj.matrix_world = Matrix.Rotation(self.x_angle, 4, "X") @ matrix_world + bpy.context.view_layer.update() + self.collection.objects.link(obj) element = blenderbim.core.root.assign_class( tool.Ifc, diff --git a/src/blenderbim/blenderbim/bim/module/model/wall.py b/src/blenderbim/blenderbim/bim/module/model/wall.py index f6fd0ac275..16b2832cfb 100644 --- a/src/blenderbim/blenderbim/bim/module/model/wall.py +++ b/src/blenderbim/blenderbim/bim/module/model/wall.py @@ -473,7 +473,7 @@ class DumbWallGenerator: self.relating_type = relating_type self.unit_scale = ifcopenshell.util.unit.calculate_unit_scale(tool.Ifc.get()) - def generate(self, link_to_scene=True): + def generate(self): self.file = IfcStore.get_file() self.layers = tool.Model.get_material_layer_parameters(self.relating_type) if not self.layers["thickness"]: @@ -495,7 +495,7 @@ class DumbWallGenerator: if self.has_sketch(): return # For now return self.derive_from_sketch() - return self.derive_from_cursor(link_to_scene) + return self.derive_from_cursor() def has_sketch(self): return ( @@ -574,7 +574,7 @@ class DumbWallGenerator: def is_near(self, point1, point2): return (point1 - point2).length < 0.1 - def derive_from_cursor(self, link_to_scene): + def derive_from_cursor(self): self.location = bpy.context.scene.cursor.location if self.collection: for sibling_obj in self.collection.objects: @@ -600,21 +600,21 @@ class DumbWallGenerator: normal = (sibling_obj.matrix_world.to_quaternion() @ face.normal).normalized() self.rotation = math.atan2(normal[1], normal[0]) break - return self.create_wall(link_to_scene) + return self.create_wall() - def create_wall(self, link_to_scene): + def create_wall(self): props = bpy.context.scene.BIMModelProperties ifc_class = self.get_relating_type_class(self.relating_type) mesh = bpy.data.meshes.new("Dummy") obj = bpy.data.objects.new(tool.Model.generate_occurrence_name(self.relating_type, ifc_class), mesh) - if link_to_scene: - matrix_world = Matrix.Rotation(self.rotation, 4, "Z") - matrix_world.col[3] = self.location.to_4d() - if self.collection_obj and self.collection_obj.BIMObjectProperties.ifc_definition_id: - matrix_world[2][3] = self.collection_obj.location[2] + (props.rl1 * self.unit_scale) - obj.matrix_world = matrix_world - bpy.context.view_layer.update() - self.collection.objects.link(obj) + + matrix_world = Matrix.Rotation(self.rotation, 4, "Z") + matrix_world.col[3] = self.location.to_4d() + if self.collection_obj and self.collection_obj.BIMObjectProperties.ifc_definition_id: + matrix_world[2][3] = self.collection_obj.location[2] + (props.rl1 * self.unit_scale) + obj.matrix_world = matrix_world + bpy.context.view_layer.update() + self.collection.objects.link(obj) element = blenderbim.core.root.assign_class( tool.Ifc,