mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-09-27 10:51:13 +00:00
#1153 New arc from 2 points command for 2D CAD (based on view direction)
This commit is contained in:
@@ -20,9 +20,10 @@ import bpy
|
|||||||
from . import operator, workspace
|
from . import operator, workspace
|
||||||
|
|
||||||
classes = (
|
classes = (
|
||||||
operator.CadTrimExtend,
|
operator.CadArcFrom2Points,
|
||||||
operator.CadMitre,
|
|
||||||
operator.CadFillet,
|
operator.CadFillet,
|
||||||
|
operator.CadMitre,
|
||||||
|
operator.CadTrimExtend,
|
||||||
workspace.CadHotkey,
|
workspace.CadHotkey,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
@@ -20,6 +20,7 @@ import bpy
|
|||||||
import math
|
import math
|
||||||
import bmesh
|
import bmesh
|
||||||
import mathutils
|
import mathutils
|
||||||
|
import bpy_extras
|
||||||
import blenderbim.tool as tool
|
import blenderbim.tool as tool
|
||||||
|
|
||||||
messages = {
|
messages = {
|
||||||
@@ -205,3 +206,52 @@ class CadFillet(bpy.types.Operator):
|
|||||||
bmesh.update_edit_mesh(mesh)
|
bmesh.update_edit_mesh(mesh)
|
||||||
mesh.update()
|
mesh.update()
|
||||||
return {"FINISHED"}
|
return {"FINISHED"}
|
||||||
|
|
||||||
|
|
||||||
|
class CadArcFrom2Points(bpy.types.Operator):
|
||||||
|
bl_idname = "bim.cad_arc_from_2_points"
|
||||||
|
bl_label = "CAD Arc from 2 Points"
|
||||||
|
bl_options = {"REGISTER", "UNDO"}
|
||||||
|
|
||||||
|
resolution: bpy.props.IntProperty(name="Arc Resolution", min=1, default=1)
|
||||||
|
should_flip: bpy.props.BoolProperty(name="Flip", description="Flip arc", default=False)
|
||||||
|
|
||||||
|
def draw(self, context):
|
||||||
|
layout = self.layout
|
||||||
|
for prop in self.__class__.__annotations__.keys():
|
||||||
|
layout.prop(self, prop)
|
||||||
|
|
||||||
|
def execute(self, context):
|
||||||
|
if bpy.context.mode != "EDIT_MESH":
|
||||||
|
return {"CANCELLED"}
|
||||||
|
obj = bpy.context.active_object
|
||||||
|
region = bpy.context.region
|
||||||
|
region_3d = bpy.context.area.spaces.active.region_3d
|
||||||
|
cursor = bpy.context.scene.cursor.location
|
||||||
|
center = bpy_extras.view3d_utils.location_3d_to_region_2d(region, region_3d, cursor)
|
||||||
|
if not center:
|
||||||
|
return {"CANCELLED"}
|
||||||
|
mesh = obj.data
|
||||||
|
bm = bmesh.from_edit_mesh(mesh)
|
||||||
|
selected_verts = [v for v in bm.verts if v.select]
|
||||||
|
if len(selected_verts) != 2:
|
||||||
|
return {"CANCELLED"}
|
||||||
|
v1 = bpy_extras.view3d_utils.location_3d_to_region_2d(region, region_3d, selected_verts[0].co)
|
||||||
|
v2 = bpy_extras.view3d_utils.location_3d_to_region_2d(region, region_3d, selected_verts[1].co)
|
||||||
|
l1 = v1 - center
|
||||||
|
l2 = v2 - center
|
||||||
|
angle = l1.angle_signed(l2)
|
||||||
|
|
||||||
|
if self.should_flip:
|
||||||
|
if angle > 0:
|
||||||
|
angle = -((math.pi * 2) - angle)
|
||||||
|
else:
|
||||||
|
angle = (math.pi * 2) + angle
|
||||||
|
|
||||||
|
v = selected_verts[0]
|
||||||
|
bm.verts.remove(selected_verts[1])
|
||||||
|
axis = region_3d.view_rotation @ mathutils.Vector((0, 0, 1))
|
||||||
|
bmesh.ops.spin(bm, geom=[v], axis=axis, cent=cursor, steps=self.resolution * 4, angle=-angle)
|
||||||
|
bmesh.update_edit_mesh(mesh)
|
||||||
|
mesh.update()
|
||||||
|
return {"FINISHED"}
|
||||||
|
|||||||
@@ -37,9 +37,10 @@ class CadTool(WorkSpaceTool):
|
|||||||
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")]}),
|
("bim.cad_hotkey", {"type": "T", "value": "PRESS", "shift": True}, {"properties": [("hotkey", "S_T")]}),
|
||||||
("bim.cad_fillet", {"type": "F", "value": "PRESS", "shift": True}, {"properties": [("hotkey", "S_F")]}),
|
("bim.cad_fillet", {"type": "F", "value": "PRESS", "shift": True}, {"properties": []}),
|
||||||
# Enable Mesh Tools add-on to get this amazing tool
|
# Enable Mesh Tools add-on to get this amazing tool
|
||||||
("mesh.offset_edges", {"type": "O", "value": "PRESS", "shift": True}, {"properties": [("hotkey", "S_O")]}),
|
("mesh.offset_edges", {"type": "O", "value": "PRESS", "shift": True}, {"properties": []}),
|
||||||
|
("bim.cad_arc_from_2_points", {"type": "C", "value": "PRESS", "shift": True}, {"properties": []}),
|
||||||
)
|
)
|
||||||
|
|
||||||
def draw_settings(context, layout, tool):
|
def draw_settings(context, layout, tool):
|
||||||
@@ -59,6 +60,10 @@ class CadTool(WorkSpaceTool):
|
|||||||
row.label(text="", icon="EVENT_SHIFT")
|
row.label(text="", icon="EVENT_SHIFT")
|
||||||
row.label(text="Offset", icon="EVENT_O")
|
row.label(text="Offset", icon="EVENT_O")
|
||||||
|
|
||||||
|
row = layout.row(align=True)
|
||||||
|
row.label(text="", icon="EVENT_SHIFT")
|
||||||
|
row.label(text="2-Point Arc", icon="EVENT_C")
|
||||||
|
|
||||||
|
|
||||||
class CadHotkey(bpy.types.Operator):
|
class CadHotkey(bpy.types.Operator):
|
||||||
bl_idname = "bim.cad_hotkey"
|
bl_idname = "bim.cad_hotkey"
|
||||||
|
|||||||
@@ -34,7 +34,6 @@ classes = (
|
|||||||
operator.BuildSchedule,
|
operator.BuildSchedule,
|
||||||
operator.CleanWireframes,
|
operator.CleanWireframes,
|
||||||
operator.ContractSheet,
|
operator.ContractSheet,
|
||||||
operator.ConvertEdgeToArc,
|
|
||||||
operator.CopyGrid,
|
operator.CopyGrid,
|
||||||
operator.CreateDrawing,
|
operator.CreateDrawing,
|
||||||
operator.CreateSheets,
|
operator.CreateSheets,
|
||||||
|
|||||||
@@ -40,8 +40,7 @@ import blenderbim.bim.module.drawing.scheduler as scheduler
|
|||||||
import blenderbim.bim.module.drawing.helper as helper
|
import blenderbim.bim.module.drawing.helper as helper
|
||||||
import blenderbim.bim.export_ifc
|
import blenderbim.bim.export_ifc
|
||||||
from lxml import etree
|
from lxml import etree
|
||||||
from math import pi
|
from mathutils import Vector
|
||||||
from mathutils import Vector, Matrix, Euler, geometry
|
|
||||||
from blenderbim.bim.module.drawing.prop import RasterStyleProperty
|
from blenderbim.bim.module.drawing.prop import RasterStyleProperty
|
||||||
from blenderbim.bim.ifc import IfcStore
|
from blenderbim.bim.ifc import IfcStore
|
||||||
from ifcopenshell.api.group.data import Data as GroupData
|
from ifcopenshell.api.group.data import Data as GroupData
|
||||||
@@ -1357,44 +1356,3 @@ class ContractSheet(bpy.types.Operator):
|
|||||||
sheet.is_expanded = False
|
sheet.is_expanded = False
|
||||||
core.load_sheets(tool.Drawing)
|
core.load_sheets(tool.Drawing)
|
||||||
return {"FINISHED"}
|
return {"FINISHED"}
|
||||||
|
|
||||||
|
|
||||||
class ConvertEdgeToArc(bpy.types.Operator):
|
|
||||||
bl_idname = "bim.convert_edge_to_arc"
|
|
||||||
bl_label = "Convert Edge to Arc"
|
|
||||||
bl_options = {"REGISTER", "UNDO"}
|
|
||||||
|
|
||||||
resolution: bpy.props.IntProperty(name="Arc Resolution", min=1, default=1)
|
|
||||||
should_flip: bpy.props.BoolProperty(name="Flip", description="Flip arc", default=False)
|
|
||||||
|
|
||||||
def draw(self, context):
|
|
||||||
layout = self.layout
|
|
||||||
for prop in self.__class__.__annotations__.keys():
|
|
||||||
layout.prop(self, prop)
|
|
||||||
|
|
||||||
def execute(self, context):
|
|
||||||
if bpy.context.mode != "EDIT_MESH":
|
|
||||||
return {"CANCELLED"}
|
|
||||||
obj = bpy.context.active_object
|
|
||||||
cursor = obj.matrix_world.inverted() @ bpy.context.scene.cursor.location
|
|
||||||
mesh = obj.data
|
|
||||||
bm = bmesh.from_edit_mesh(mesh)
|
|
||||||
selected_verts = [v for v in bm.verts if v.select]
|
|
||||||
if len(selected_verts) != 2:
|
|
||||||
return {"CANCELLED"}
|
|
||||||
l1 = selected_verts[0].co - cursor
|
|
||||||
l2 = selected_verts[1].co - cursor
|
|
||||||
angle = l1.xy.angle_signed(l2.xy)
|
|
||||||
|
|
||||||
if self.should_flip:
|
|
||||||
if angle > 0:
|
|
||||||
angle = -((pi * 2) - angle)
|
|
||||||
else:
|
|
||||||
angle = (pi * 2) + angle
|
|
||||||
|
|
||||||
v = selected_verts[0]
|
|
||||||
bm.verts.remove(selected_verts[1])
|
|
||||||
bmesh.ops.spin(bm, geom=[v], axis=(0, 0, 1), cent=cursor, steps=self.resolution * 4, angle=-angle)
|
|
||||||
bmesh.update_edit_mesh(mesh)
|
|
||||||
mesh.update()
|
|
||||||
return {"FINISHED"}
|
|
||||||
|
|||||||
Reference in New Issue
Block a user