See #4946. Slowly start refactoring out model module into core for better error handling.

This commit is contained in:
Dion Moult
2024-07-01 00:10:51 +10:00
parent f2c3e62ba1
commit 989219e1e2
3 changed files with 54 additions and 11 deletions
@@ -32,6 +32,7 @@ import blenderbim.bim.handler
import blenderbim.core.type import blenderbim.core.type
import blenderbim.core.root import blenderbim.core.root
import blenderbim.core.geometry import blenderbim.core.geometry
import blenderbim.core.model as core
import blenderbim.tool as tool import blenderbim.tool as tool
from blenderbim.bim.ifc import IfcStore from blenderbim.bim.ifc import IfcStore
from math import pi, sin, cos, degrees from math import pi, sin, cos, degrees
@@ -80,14 +81,12 @@ class JoinWall(bpy.types.Operator, tool.Ifc.Operator):
return {"FINISHED"} return {"FINISHED"}
if self.join_type in ("L", "V"): if self.join_type in ("L", "V"):
if len(selected_objs) != 2: try:
self.report({"ERROR"}, f"It requires 2 selected objects to do join of type {self.join_type}") core.join_wall_LV(tool.Blender, joiner, join_type=self.join_type)
except core.RequireTwoObjectsError:
join_type_name = {"L": "butt", "V": "mitre"}[self.join_type]
self.report({"ERROR"}, f"Please select 2 objects to do a {join_type_name} joint")
return {"CANCELLED"} return {"CANCELLED"}
another_selected_object = next(o for o in selected_objs if o != context.active_object)
if self.join_type == "L":
joiner.join_L(another_selected_object, context.active_object)
elif self.join_type == "V":
joiner.join_V(another_selected_object, context.active_object)
return {"FINISHED"} return {"FINISHED"}
if self.join_type == "T": if self.join_type == "T":
@@ -21,11 +21,11 @@ import bpy
import ifcopenshell import ifcopenshell
import ifcopenshell.util.unit import ifcopenshell.util.unit
import blenderbim.tool as tool import blenderbim.tool as tool
import blenderbim.bim.module.type.prop as type_prop import blenderbim.core.model
from blenderbim.bim.module.model.wall import DumbWallJoiner
from blenderbim.bim.helper import prop_with_search from blenderbim.bim.helper import prop_with_search
from bpy.types import WorkSpaceTool from bpy.types import WorkSpaceTool
from blenderbim.bim.module.model.data import AuthoringData from blenderbim.bim.module.model.data import AuthoringData
from blenderbim.bim.module.drawing.data import DecoratorData
from blenderbim.bim.module.system.data import PortData from blenderbim.bim.module.system.data import PortData
from blenderbim.bim.module.model.prop import get_ifc_class from blenderbim.bim.module.model.prop import get_ifc_class
@@ -781,7 +781,11 @@ class Hotkey(bpy.types.Operator, tool.Ifc.Operator):
if not bpy.context.selected_objects: if not bpy.context.selected_objects:
return return
if self.active_material_usage == "LAYER2": if self.active_material_usage == "LAYER2":
bpy.ops.bim.join_wall(join_type="L") try:
blenderbim.core.model.join_wall_LV(tool.Blender, DumbWallJoiner(), join_type="L")
except blenderbim.core.model.RequireTwoObjectsError:
self.report({"ERROR"}, "Please select 2 objects to do a butt joint")
return {"CANCELLED"}
elif self.active_material_usage == "PROFILE": elif self.active_material_usage == "PROFILE":
bpy.ops.bim.extend_profile(join_type="L") bpy.ops.bim.extend_profile(join_type="L")
@@ -806,7 +810,11 @@ class Hotkey(bpy.types.Operator, tool.Ifc.Operator):
if not bpy.context.selected_objects: if not bpy.context.selected_objects:
return return
if self.active_material_usage == "LAYER2": if self.active_material_usage == "LAYER2":
bpy.ops.bim.join_wall(join_type="V") try:
blenderbim.core.model.join_wall_LV(tool.Blender, DumbWallJoiner(), join_type="V")
except blenderbim.core.model.RequireTwoObjectsError:
self.report({"ERROR"}, "Please select 2 objects to do a mitre joint")
return {"CANCELLED"}
elif self.active_class in ("IfcDuctSegment", "IfcPipeSegment", "IfcCableCarrierSegment", "IfcCableSegment"): elif self.active_class in ("IfcDuctSegment", "IfcPipeSegment", "IfcCableCarrierSegment", "IfcCableSegment"):
bpy.ops.bim.fit_flow_segments() bpy.ops.bim.fit_flow_segments()
elif self.active_material_usage == "PROFILE": elif self.active_material_usage == "PROFILE":
+36
View File
@@ -0,0 +1,36 @@
# BlenderBIM Add-on - OpenBIM Blender Add-on
# Copyright (C) 2021 Dion Moult <dion@thinkmoult.com>
#
# This file is part of BlenderBIM Add-on.
#
# BlenderBIM Add-on is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# BlenderBIM Add-on is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with BlenderBIM Add-on. If not, see <http://www.gnu.org/licenses/>.
import blenderbim.core.tool as tool
from typing import Literal
def join_wall_LV(blender: tool.Blender, joiner, join_type: Literal["L", "V"] = "L") -> None:
if len(selected_objs := blender.get_selected_objects()) != 2:
raise RequireTwoObjectsError()
active_obj = blender.get_active_object()
another_selected_object = next(o for o in selected_objs if o != active_obj)
if join_type == "L":
joiner.join_L(another_selected_object, active_obj)
elif join_type == "V":
joiner.join_V(another_selected_object, active_obj)
class RequireTwoObjectsError(Exception):
pass