Cleanup: remove "Tweak" event type
[blender-addons.git] / curve_tools / fillet.py
blob6b40f89c0d69e7ff68f969bab287b8196cd8771e
1 # SPDX-License-Identifier: GPL-2.0-or-later
3 bl_info = {
4 'name': 'Curve Fillet',
5 'author': 'Spivak Vladimir (cwolf3d)',
6 'version': (0, 0, 1),
7 'blender': (2, 80, 0),
8 'location': 'Curve Tools addon. (N) Panel',
9 'description': 'Various types of fillet (chamfering)',
10 'warning': '', # used for warning icon and text in addons panel
11 'doc_url': '',
12 'tracker_url': '',
13 'category': 'Curve',
17 import bpy
18 from bpy.props import *
19 from bpy_extras import object_utils, view3d_utils
20 from mathutils import *
21 from math import *
23 def click(self, context, event):
24 bpy.ops.object.mode_set(mode = 'EDIT')
25 bpy.context.view_layer.update()
28 def remove_handler(handlers):
29 for handler in handlers:
30 try:
31 bpy.types.SpaceView3D.draw_handler_remove(handler, 'WINDOW')
32 except:
33 pass
34 for handler in handlers:
35 handlers.remove(handler)
38 class Fillet(bpy.types.Operator):
39 bl_idname = "curvetools.fillet"
40 bl_label = "Curve Fillet"
41 bl_description = "Curve Fillet"
42 bl_options = {'REGISTER', 'UNDO'}
44 x: IntProperty(name="x", description="x")
45 y: IntProperty(name="y", description="y")
46 location3D: FloatVectorProperty(name = "",
47 description = "Start location",
48 default = (0.0, 0.0, 0.0),
49 subtype = 'XYZ')
51 handlers = []
53 def execute(self, context):
54 self.report({'INFO'}, "ESC or TAB - cancel")
55 bpy.ops.object.mode_set(mode = 'EDIT')
57 # color change in the panel
58 self.path_color = bpy.context.scene.curvetools.path_color
59 self.path_thickness = bpy.context.scene.curvetools.path_thickness
61 def modal(self, context, event):
62 context.area.tag_redraw()
64 if event.type in {'ESC', 'TAB'}: # Cancel
65 remove_handler(self.handlers)
66 return {'CANCELLED'}
68 if event.type in {'X', 'DEL'}: # Cancel
69 remove_handler(self.handlers)
70 bpy.ops.curve.delete(type='VERT')
71 return {'RUNNING_MODAL'}
73 elif event.alt and event.shift and event.type == 'LEFTMOUSE':
74 click(self, context, event)
76 elif event.alt and not event.shift and event.type == 'LEFTMOUSE':
77 remove_handler(self.handlers)
78 bpy.ops.curve.select_all(action='DESELECT')
79 click(self, context, event)
81 elif event.alt and event.type == 'RIGHTMOUSE':
82 remove_handler(self.handlers)
83 bpy.ops.curve.select_all(action='DESELECT')
84 click(self, context, event)
86 elif event.alt and not event.shift and event.shift and event.type == 'RIGHTMOUSE':
87 click(self, context, event)
89 elif event.type == 'A':
90 remove_handler(self.handlers)
91 bpy.ops.curve.select_all(action='DESELECT')
93 elif event.type == 'MOUSEMOVE': #
94 self.x = event.mouse_x
95 self.y = event.mouse_y
96 region = bpy.context.region
97 rv3d = bpy.context.space_data.region_3d
98 self.location3D = view3d_utils.region_2d_to_location_3d(
99 region,
100 rv3d,
101 (event.mouse_region_x, event.mouse_region_y),
102 (0.0, 0.0, 0.0)
105 return {'PASS_THROUGH'}
107 def invoke(self, context, event):
108 self.execute(context)
109 context.window_manager.modal_handler_add(self)
110 return {'RUNNING_MODAL'}
112 @classmethod
113 def poll(cls, context):
114 return (context.object is not None and
115 context.object.type == 'CURVE')
117 def register():
118 for cls in classes:
119 bpy.utils.register_class(operators)
121 def unregister():
122 for cls in classes:
123 bpy.utils.unregister_class(operators)
125 if __name__ == "__main__":
126 register()
128 operators = [Fillet]