diff --git a/src/blenderbim/blenderbim/bim/module/cad/__init__.py b/src/blenderbim/blenderbim/bim/module/cad/__init__.py index 37c10ff84e..44d7cf1ce5 100644 --- a/src/blenderbim/blenderbim/bim/module/cad/__init__.py +++ b/src/blenderbim/blenderbim/bim/module/cad/__init__.py @@ -1,5 +1,5 @@ # BlenderBIM Add-on - OpenBIM Blender Add-on -# Copyright (C) 2020, 2021 Dion Moult +# Copyright (C) 2022 Dion Moult # # This file is part of BlenderBIM Add-on. # @@ -17,16 +17,19 @@ # along with BlenderBIM Add-on. If not, see . import bpy -from . import operator +from . import operator, workspace classes = ( - operator.TCAutoVTX, + operator.CadTrimExtend, + workspace.CadHotkey, ) def register(): - pass + if not bpy.app.background: + bpy.utils.register_tool(workspace.CadTool, after={"builtin.transform"}, separator=True, group=True) def unregister(): - pass + if not bpy.app.background: + bpy.utils.unregister_tool(workspace.CadTool) diff --git a/src/blenderbim/blenderbim/bim/module/cad/operator.py b/src/blenderbim/blenderbim/bim/module/cad/operator.py index 0533c636dc..d4ff417384 100644 --- a/src/blenderbim/blenderbim/bim/module/cad/operator.py +++ b/src/blenderbim/blenderbim/bim/module/cad/operator.py @@ -27,11 +27,12 @@ messages = { } -class TCAutoVTX(bpy.types.Operator): +class CadTrimExtend(bpy.types.Operator): """Weld intersecting edges, project converging edges towards their intersection""" - bl_idname = "bim.vtx" - bl_label = "VTX autoVTX" + bl_idname = "bim.cad_trim_extend" + bl_label = "CAD Trim / Extend" + join_type: bpy.props.StringProperty() @classmethod def poll(cls, context): @@ -44,7 +45,6 @@ class TCAutoVTX(bpy.types.Operator): return {"CANCELLED"} def execute(self, context): - # final attempt to enter unfragmented bm/mesh # ghastly, but what can I do? it works with these # fails without. diff --git a/src/blenderbim/blenderbim/bim/module/cad/ops.authoring.cad.dat b/src/blenderbim/blenderbim/bim/module/cad/ops.authoring.cad.dat new file mode 100644 index 0000000000..cde9c94df7 Binary files /dev/null and b/src/blenderbim/blenderbim/bim/module/cad/ops.authoring.cad.dat differ diff --git a/src/blenderbim/blenderbim/bim/module/cad/workspace.py b/src/blenderbim/blenderbim/bim/module/cad/workspace.py new file mode 100644 index 0000000000..33908b3e60 --- /dev/null +++ b/src/blenderbim/blenderbim/bim/module/cad/workspace.py @@ -0,0 +1,64 @@ +# BlenderBIM Add-on - OpenBIM Blender Add-on +# Copyright (C) 2022 Dion Moult +# +# 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 . + +import os +import bpy +import blenderbim.bim.module.type.prop as type_prop +from bpy.types import WorkSpaceTool +from blenderbim.bim.ifc import IfcStore +from blenderbim.bim.module.model.data import AuthoringData + + +class CadTool(WorkSpaceTool): + bl_space_type = "VIEW_3D" + bl_context_mode = "EDIT_MESH" + + bl_idname = "bim.cad_tool" + bl_label = "CAD Tool" + bl_description = "Gives you CAD authoring related superpowers" + bl_icon = os.path.join(os.path.dirname(__file__), "ops.authoring.cad") + bl_widget = None + # https://docs.blender.org/api/current/bpy.types.KeyMapItems.html + bl_keymap = ( + ("bim.cad_hotkey", {"type": "E", "value": "PRESS", "shift": True}, {"properties": [("hotkey", "S_E")]}), + ) + + def draw_settings(context, layout, tool): + row = layout.row(align=True) + row.label(text="", icon="EVENT_SHIFT") + row.label(text="Extend / Trim", icon="EVENT_E") + + +class CadHotkey(bpy.types.Operator): + bl_idname = "bim.cad_hotkey" + bl_label = "CAD Hotkey" + bl_options = {"REGISTER", "UNDO"} + hotkey: bpy.props.StringProperty() + + def execute(self, context): + self.props = context.scene.BIMModelProperties + self.has_ifc_class = True + try: + self.has_ifc_class = bool(self.props.ifc_class) + except: + pass + getattr(self, f"hotkey_{self.hotkey}")() + return {"FINISHED"} + + def hotkey_S_E(self): + bpy.ops.bim.cad_trim_extend(join_type="T")