mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-09-21 14:23:53 +00:00
#1153 New mitre command for 2D cad (like chamfer with 0 distance)
This commit is contained in:
@@ -21,6 +21,7 @@ from . import operator, workspace
|
|||||||
|
|
||||||
classes = (
|
classes = (
|
||||||
operator.CadTrimExtend,
|
operator.CadTrimExtend,
|
||||||
|
operator.CadMitre,
|
||||||
workspace.CadHotkey,
|
workspace.CadHotkey,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
@@ -28,11 +28,8 @@ messages = {
|
|||||||
|
|
||||||
|
|
||||||
class CadTrimExtend(bpy.types.Operator):
|
class CadTrimExtend(bpy.types.Operator):
|
||||||
"""Weld intersecting edges, project converging edges towards their intersection"""
|
|
||||||
|
|
||||||
bl_idname = "bim.cad_trim_extend"
|
bl_idname = "bim.cad_trim_extend"
|
||||||
bl_label = "CAD Trim / Extend"
|
bl_label = "CAD Trim / Extend"
|
||||||
join_type: bpy.props.StringProperty()
|
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def poll(cls, context):
|
def poll(cls, context):
|
||||||
@@ -61,7 +58,53 @@ class CadTrimExtend(bpy.types.Operator):
|
|||||||
edges = [e for e in bm.edges if e.select and not e.hide]
|
edges = [e for e in bm.edges if e.select and not e.hide]
|
||||||
|
|
||||||
if len(edges) == 2:
|
if len(edges) == 2:
|
||||||
message = tool.Cad.do_vtx_if_appropriate(bm, edges)
|
message = tool.Cad.do_vtx_if_appropriate(bm, edges, mode="T")
|
||||||
|
if isinstance(message, set):
|
||||||
|
msg = messages.get(message.pop())
|
||||||
|
return self.cancel_message(msg)
|
||||||
|
bm = message
|
||||||
|
else:
|
||||||
|
return self.cancel_message("select two edges!")
|
||||||
|
|
||||||
|
bm.verts.index_update()
|
||||||
|
bm.edges.index_update()
|
||||||
|
bmesh.update_edit_mesh(me, loop_triangles=True)
|
||||||
|
|
||||||
|
return {"FINISHED"}
|
||||||
|
|
||||||
|
|
||||||
|
class CadMitre(bpy.types.Operator):
|
||||||
|
bl_idname = "bim.cad_mitre"
|
||||||
|
bl_label = "CAD Trim / Extend"
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def poll(cls, context):
|
||||||
|
obj = context.active_object
|
||||||
|
return bool(obj) and obj.type == "MESH"
|
||||||
|
|
||||||
|
def cancel_message(self, msg):
|
||||||
|
print(msg)
|
||||||
|
self.report({"WARNING"}, msg)
|
||||||
|
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.
|
||||||
|
bpy.ops.object.mode_set(mode="OBJECT")
|
||||||
|
bpy.ops.object.mode_set(mode="EDIT")
|
||||||
|
|
||||||
|
obj = context.active_object
|
||||||
|
me = obj.data
|
||||||
|
|
||||||
|
bm = bmesh.from_edit_mesh(me)
|
||||||
|
bm.verts.ensure_lookup_table()
|
||||||
|
bm.edges.ensure_lookup_table()
|
||||||
|
|
||||||
|
edges = [e for e in bm.edges if e.select and not e.hide]
|
||||||
|
|
||||||
|
if len(edges) == 2:
|
||||||
|
message = tool.Cad.do_vtx_if_appropriate(bm, edges, mode="V")
|
||||||
if isinstance(message, set):
|
if isinstance(message, set):
|
||||||
msg = messages.get(message.pop())
|
msg = messages.get(message.pop())
|
||||||
return self.cancel_message(msg)
|
return self.cancel_message(msg)
|
||||||
|
|||||||
@@ -36,6 +36,7 @@ class CadTool(WorkSpaceTool):
|
|||||||
# https://docs.blender.org/api/current/bpy.types.KeyMapItems.html
|
# https://docs.blender.org/api/current/bpy.types.KeyMapItems.html
|
||||||
bl_keymap = (
|
bl_keymap = (
|
||||||
("bim.cad_hotkey", {"type": "E", "value": "PRESS", "shift": True}, {"properties": [("hotkey", "S_E")]}),
|
("bim.cad_hotkey", {"type": "E", "value": "PRESS", "shift": True}, {"properties": [("hotkey", "S_E")]}),
|
||||||
|
("bim.cad_hotkey", {"type": "T", "value": "PRESS", "shift": True}, {"properties": [("hotkey", "S_T")]}),
|
||||||
)
|
)
|
||||||
|
|
||||||
def draw_settings(context, layout, tool):
|
def draw_settings(context, layout, tool):
|
||||||
@@ -61,4 +62,7 @@ class CadHotkey(bpy.types.Operator):
|
|||||||
return {"FINISHED"}
|
return {"FINISHED"}
|
||||||
|
|
||||||
def hotkey_S_E(self):
|
def hotkey_S_E(self):
|
||||||
bpy.ops.bim.cad_trim_extend(join_type="T")
|
bpy.ops.bim.cad_trim_extend()
|
||||||
|
|
||||||
|
def hotkey_S_T(self):
|
||||||
|
bpy.ops.bim.cad_mitre()
|
||||||
|
|||||||
@@ -24,6 +24,7 @@
|
|||||||
# Changes include:
|
# Changes include:
|
||||||
#
|
#
|
||||||
# - Instead of AutoVTX, user explicitly chooses V, T, or X mode
|
# - Instead of AutoVTX, user explicitly chooses V, T, or X mode
|
||||||
|
# - Instead of adding edges, existing edges are extended
|
||||||
|
|
||||||
|
|
||||||
import sys
|
import sys
|
||||||
@@ -261,12 +262,18 @@ class Cad:
|
|||||||
bm.edges.index_update()
|
bm.edges.index_update()
|
||||||
return bm
|
return bm
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def perform_v(cls, bm, pt, target, edge, pts, vertex_indices):
|
||||||
|
bm = cls.perform_t(bm, pt, target, edge, pts, vertex_indices)
|
||||||
|
bm = cls.perform_t(bm, pt, edge, target, pts, vertex_indices)
|
||||||
|
return bm
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def prioritise_active_edge(cls, bm, edges):
|
def prioritise_active_edge(cls, bm, edges):
|
||||||
return [edges[0], edges[1]] if bm.select_history.active == edges[0] else [edges[1], edges[0]]
|
return [edges[0], edges[1]] if bm.select_history.active == edges[0] else [edges[1], edges[0]]
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def do_vtx_if_appropriate(cls, bm, edges):
|
def do_vtx_if_appropriate(cls, bm, edges, mode):
|
||||||
vertex_indices = cls.get_vert_indices_from_bmedges(edges)
|
vertex_indices = cls.get_vert_indices_from_bmedges(edges)
|
||||||
|
|
||||||
# test 1, are there shared vers? if so return non-viable
|
# test 1, are there shared vers? if so return non-viable
|
||||||
@@ -285,6 +292,9 @@ class Cad:
|
|||||||
return {"NON_PLANAR_EDGES"}
|
return {"NON_PLANAR_EDGES"}
|
||||||
|
|
||||||
edges = cls.prioritise_active_edge(bm, edges)
|
edges = cls.prioritise_active_edge(bm, edges)
|
||||||
# point must lie on an edge or the virtual extention of an edge
|
# point must lie on an edge or the virtual extension of an edge
|
||||||
bm = cls.perform_t(bm, point, edges[0], edges[1], (p1, p2, p3, p4), vertex_indices)
|
if mode == "T":
|
||||||
|
bm = cls.perform_t(bm, point, edges[0], edges[1], (p1, p2, p3, p4), vertex_indices)
|
||||||
|
elif mode == "V":
|
||||||
|
bm = cls.perform_v(bm, point, edges[0], edges[1], (p1, p2, p3, p4), vertex_indices)
|
||||||
return bm
|
return bm
|
||||||
|
|||||||
Reference in New Issue
Block a user