Sun Position: update translation
[blender-addons.git] / curve_tools / fillet.py
blobbb7451ce645104cb82de9b8db6af5d0a4068f8fa
1 # SPDX-FileCopyrightText: 2019-2022 Blender Foundation
3 # SPDX-License-Identifier: GPL-2.0-or-later
5 bl_info = {
6 'name': 'Curve Fillet',
7 'author': 'Spivak Vladimir (cwolf3d)',
8 'version': (0, 0, 1),
9 'blender': (2, 80, 0),
10 'location': 'Curve Tools addon. (N) Panel',
11 'description': 'Various types of fillet (chamfering)',
12 'warning': '', # used for warning icon and text in addons panel
13 'doc_url': '',
14 'tracker_url': '',
15 'category': 'Curve',
19 import bpy
20 from bpy.props import *
21 from bpy_extras import object_utils, view3d_utils
22 from mathutils import *
23 from math import *
25 def click(self, context, event):
26 bpy.ops.object.mode_set(mode = 'EDIT')
27 bpy.context.view_layer.update()
30 def remove_handler(handlers):
31 for handler in handlers:
32 try:
33 bpy.types.SpaceView3D.draw_handler_remove(handler, 'WINDOW')
34 except:
35 pass
36 for handler in handlers:
37 handlers.remove(handler)
40 class Fillet(bpy.types.Operator):
41 bl_idname = "curvetools.fillet"
42 bl_label = "Curve Fillet"
43 bl_description = "Curve Fillet"
44 bl_options = {'REGISTER', 'UNDO'}
46 x: IntProperty(name="x", description="x")
47 y: IntProperty(name="y", description="y")
48 location3D: FloatVectorProperty(name = "",
49 description = "Start location",
50 default = (0.0, 0.0, 0.0),
51 subtype = 'XYZ')
53 handlers = []
55 def execute(self, context):
56 self.report({'INFO'}, "ESC or TAB - cancel")
57 bpy.ops.object.mode_set(mode = 'EDIT')
59 # color change in the panel
60 self.path_color = bpy.context.scene.curvetools.path_color
61 self.path_thickness = bpy.context.scene.curvetools.path_thickness
63 def modal(self, context, event):
64 context.area.tag_redraw()
66 if event.type in {'ESC', 'TAB'}: # Cancel
67 remove_handler(self.handlers)
68 return {'CANCELLED'}
70 if event.type in {'X', 'DEL'}: # Cancel
71 remove_handler(self.handlers)
72 bpy.ops.curve.delete(type='VERT')
73 return {'RUNNING_MODAL'}
75 elif event.alt and event.shift and event.type == 'LEFTMOUSE':
76 click(self, context, event)
78 elif event.alt and not event.shift and event.type == 'LEFTMOUSE':
79 remove_handler(self.handlers)
80 bpy.ops.curve.select_all(action='DESELECT')
81 click(self, context, event)
83 elif event.alt and event.type == 'RIGHTMOUSE':
84 remove_handler(self.handlers)
85 bpy.ops.curve.select_all(action='DESELECT')
86 click(self, context, event)
88 elif event.alt and not event.shift and event.shift and event.type == 'RIGHTMOUSE':
89 click(self, context, event)
91 elif event.type == 'A':
92 remove_handler(self.handlers)
93 bpy.ops.curve.select_all(action='DESELECT')
95 elif event.type == 'MOUSEMOVE': #
96 self.x = event.mouse_x
97 self.y = event.mouse_y
98 region = bpy.context.region
99 rv3d = bpy.context.space_data.region_3d
100 self.location3D = view3d_utils.region_2d_to_location_3d(
101 region,
102 rv3d,
103 (event.mouse_region_x, event.mouse_region_y),
104 (0.0, 0.0, 0.0)
107 return {'PASS_THROUGH'}
109 def invoke(self, context, event):
110 self.execute(context)
111 context.window_manager.modal_handler_add(self)
112 return {'RUNNING_MODAL'}
114 @classmethod
115 def poll(cls, context):
116 return (context.object is not None and
117 context.object.type == 'CURVE')
119 def register():
120 for cls in classes:
121 bpy.utils.register_class(operators)
123 def unregister():
124 for cls in classes:
125 bpy.utils.unregister_class(operators)
127 if __name__ == "__main__":
128 register()
130 operators = [Fillet]