forked from hlorus/CAD_Sketcher
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathworkspacetools.py
352 lines (307 loc) · 10.2 KB
/
workspacetools.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
import os
import bpy
from bpy.types import WorkSpaceTool
from .declarations import GizmoGroups, Operators, WorkSpaceTools
from .keymaps import tool_access
from .stateful_operator.utilities.keymap import operator_access
from .stateful_operator.tool import GenericStateTool
def get_addon_icon_path(icon_name):
return os.path.join(os.path.dirname(__file__), "ressources/icons", icon_name)
generic_keymap = (
# Disabling gizmos when pressing ctrl + shift
# Add two etries so it doesn't matter which key is pressed first
# NOTE: This cannot be done as a normal modifier key to selection since it has to toggle a global property
(
"wm.context_set_boolean",
{"type": "LEFT_SHIFT", "value": "PRESS", "ctrl": True},
{
"properties": [
("data_path", "scene.sketcher.selectable_constraints"),
("value", False),
]
},
),
(
"wm.context_set_boolean",
{"type": "LEFT_CTRL", "value": "PRESS", "shift": True},
{
"properties": [
("data_path", "scene.sketcher.selectable_constraints"),
("value", False),
]
},
),
(
"wm.context_set_boolean",
{"type": "LEFT_SHIFT", "value": "RELEASE", "any": True},
{
"properties": [
("data_path", "scene.sketcher.selectable_constraints"),
("value", True),
]
},
),
)
class VIEW3D_T_slvs_select(WorkSpaceTool):
bl_space_type = "VIEW_3D"
bl_context_mode = "OBJECT"
bl_idname = WorkSpaceTools.Select
bl_label = "Solvespace Select"
bl_description = "Select Solvespace Entities"
bl_icon = "ops.generic.select"
bl_widget = GizmoGroups.Preselection
bl_keymap = (
*generic_keymap,
(
Operators.SelectAll,
{"type": "ESC", "value": "PRESS"},
{"properties": [("deselect", True)]},
),
(
Operators.SelectAll,
{"type": "A", "value": "PRESS", "ctrl": True},
{"properties": [("deselect", False)]},
),
(
Operators.Select,
{"type": "LEFTMOUSE", "value": "CLICK", "any": True},
None,
),
(
Operators.Select,
{"type": "LEFTMOUSE", "value": "CLICK", "shift": True},
{"properties": [("mode", "EXTEND")]},
),
(
Operators.Select,
{"type": "LEFTMOUSE", "value": "CLICK", "ctrl": True},
{"properties": [("mode", "SUBTRACT")]},
),
(Operators.SelectInvert, {"type": "I", "value": "PRESS", "ctrl": True}, None),
(Operators.SelectExtend, {"type": "E", "value": "PRESS", "ctrl": True}, None),
(
Operators.SelectExtendAll,
{"type": "E", "value": "PRESS", "ctrl": True, "shift": True},
None,
),
(
Operators.Tweak,
{"type": "LEFTMOUSE", "value": "CLICK_DRAG"},
None,
),
(
Operators.ContextMenu,
{"type": "RIGHTMOUSE", "value": "PRESS"},
{"properties": [("delayed", True)]},
),
(
Operators.DeleteEntity,
{"type": "DEL", "value": "PRESS"},
None,
),
*tool_access,
)
def draw_settings(context, layout, tool):
props = tool.operator_properties(Operators.Select)
layout.prop(props, "mode", text="", expand=True, icon_only=True)
tool_keymap = (
*generic_keymap,
(
"wm.tool_set_by_id",
{"type": "ESC", "value": "PRESS"},
{"properties": [("name", VIEW3D_T_slvs_select.bl_idname)]},
),
(
"wm.tool_set_by_id",
{"type": "RIGHTMOUSE", "value": "PRESS"},
{"properties": [("name", VIEW3D_T_slvs_select.bl_idname)]},
),
)
class View3D_T_slvs_add_point3d(GenericStateTool, WorkSpaceTool):
bl_space_type = "VIEW_3D"
bl_context_mode = "OBJECT"
bl_idname = WorkSpaceTools.AddPoint3D
bl_label = "Add 3D Point"
bl_operator = Operators.AddPoint3D
bl_icon = get_addon_icon_path("ops.bgs.add_point")
bl_widget = GizmoGroups.Preselection
bl_keymap = (
*tool_keymap,
*tool_access,
*operator_access(Operators.AddPoint3D),
)
class View3D_T_slvs_add_point2d(GenericStateTool, WorkSpaceTool):
bl_space_type = "VIEW_3D"
bl_context_mode = "OBJECT"
bl_idname = WorkSpaceTools.AddPoint2D
bl_label = "Add 2D Point"
bl_operator = Operators.AddPoint2D
bl_icon = get_addon_icon_path("ops.bgs.add_point")
bl_widget = GizmoGroups.Preselection
bl_keymap = (
*tool_keymap,
*tool_access,
*operator_access(Operators.AddPoint2D),
)
class View3D_T_slvs_add_line3d(GenericStateTool, WorkSpaceTool):
bl_space_type = "VIEW_3D"
bl_context_mode = "OBJECT"
bl_idname = WorkSpaceTools.AddLine3D
bl_label = "Add 3D Line"
bl_operator = Operators.AddLine3D
bl_icon = "ops.gpencil.primitive_line"
bl_widget = GizmoGroups.Preselection
bl_keymap = (
*tool_keymap,
*tool_access,
*operator_access(Operators.AddLine3D),
)
def draw_settings(context, layout, tool):
props = tool.operator_properties(Operators.AddLine3D)
layout.prop(props, "continuous_draw")
class View3D_T_slvs_add_line2d(GenericStateTool, WorkSpaceTool):
bl_space_type = "VIEW_3D"
bl_context_mode = "OBJECT"
bl_idname = WorkSpaceTools.AddLine2D
bl_label = "Add 2D Line"
bl_operator = Operators.AddLine2D
bl_icon = "ops.gpencil.primitive_line"
bl_widget = GizmoGroups.Preselection
bl_keymap = (
*tool_keymap,
*tool_access,
*operator_access(Operators.AddLine2D),
)
def draw_settings(context, layout, tool):
props = tool.operator_properties(Operators.AddLine2D)
layout.prop(props, "continuous_draw")
class View3D_T_slvs_add_circle2d(GenericStateTool, WorkSpaceTool):
bl_space_type = "VIEW_3D"
bl_context_mode = "OBJECT"
bl_idname = WorkSpaceTools.AddCircle2D
bl_label = "Add 2D Circle"
bl_operator = Operators.AddCircle2D
bl_icon = "ops.gpencil.primitive_circle"
bl_widget = GizmoGroups.Preselection
bl_keymap = (
*tool_keymap,
*tool_access,
*operator_access(Operators.AddCircle2D),
)
class View3D_T_slvs_add_arc2d(GenericStateTool, WorkSpaceTool):
bl_space_type = "VIEW_3D"
bl_context_mode = "OBJECT"
bl_idname = WorkSpaceTools.AddArc2D
bl_label = "Add 2D Arc"
bl_operator = Operators.AddArc2D
bl_icon = "ops.gpencil.primitive_arc"
bl_widget = GizmoGroups.Preselection
bl_keymap = (
*tool_keymap,
*tool_access,
*operator_access(Operators.AddArc2D),
)
class View3D_T_slvs_add_rectangle(GenericStateTool, WorkSpaceTool):
bl_space_type = "VIEW_3D"
bl_context_mode = "OBJECT"
bl_idname = WorkSpaceTools.AddRectangle
bl_label = "Add Rectangle"
bl_operator = Operators.AddRectangle
bl_icon = "ops.gpencil.primitive_box"
bl_widget = GizmoGroups.Preselection
bl_keymap = (
*tool_keymap,
*tool_access,
*operator_access(Operators.AddRectangle),
)
class View3D_T_slvs_trim(GenericStateTool, WorkSpaceTool):
bl_space_type = "VIEW_3D"
bl_context_mode = "OBJECT"
bl_idname = WorkSpaceTools.Trim
bl_label = "Trim"
bl_operator = Operators.Trim
bl_icon = "ops.gpencil.stroke_cutter"
bl_widget = GizmoGroups.Preselection
bl_keymap = (
*tool_keymap,
*tool_access,
*operator_access(Operators.Trim),
)
class View3D_T_slvs_bevel(GenericStateTool, WorkSpaceTool):
bl_space_type = "VIEW_3D"
bl_context_mode = "OBJECT"
bl_idname = WorkSpaceTools.Bevel
bl_label = "Bevel"
bl_operator = Operators.Bevel
bl_icon = get_addon_icon_path("ops.bgs.bevel")
bl_widget = GizmoGroups.Preselection
bl_keymap = (
*tool_keymap,
*tool_access,
*operator_access(Operators.Bevel),
)
class View3D_T_slvs_add_workplane_face(GenericStateTool, WorkSpaceTool):
bl_space_type = "VIEW_3D"
bl_context_mode = "OBJECT"
bl_idname = WorkSpaceTools.AddWorkplaneFace
bl_label = "Add Workplane on mesh face"
bl_operator = Operators.AddWorkPlaneFace
bl_icon = "ops.mesh.primitive_grid_add_gizmo"
bl_widget = GizmoGroups.Preselection
bl_keymap = (
*tool_keymap,
*tool_access,
*operator_access(Operators.AddWorkPlaneFace),
)
class View3D_T_slvs_add_workplane(GenericStateTool, WorkSpaceTool):
bl_space_type = "VIEW_3D"
bl_context_mode = "OBJECT"
bl_idname = WorkSpaceTools.AddWorkplane
bl_label = "Add Workplane"
bl_operator = Operators.AddWorkPlane
bl_icon = "ops.mesh.primitive_grid_add_gizmo"
bl_widget = GizmoGroups.Preselection
bl_keymap = (
*tool_keymap,
*tool_access,
*operator_access(Operators.AddWorkPlane),
)
tools = (
(VIEW3D_T_slvs_select, {"separator": True, "group": False}),
(View3D_T_slvs_add_point2d, {"separator": True, "group": True}),
(
View3D_T_slvs_add_point3d,
{
"after": {View3D_T_slvs_add_point2d.bl_idname},
},
),
(View3D_T_slvs_add_line2d, {"separator": False, "group": True}),
(
View3D_T_slvs_add_line3d,
{
"after": {View3D_T_slvs_add_line2d.bl_idname},
},
),
(View3D_T_slvs_add_circle2d, {"separator": False, "group": False}),
(View3D_T_slvs_add_arc2d, {"separator": False, "group": False}),
(View3D_T_slvs_add_rectangle, {"separator": False, "group": False}),
(View3D_T_slvs_trim, {"separator": True, "group": False}),
(View3D_T_slvs_bevel, {"separator": False, "group": False}),
(View3D_T_slvs_add_workplane_face, {"separator": True, "group": True}),
(
View3D_T_slvs_add_workplane,
{"after": {View3D_T_slvs_add_workplane_face.bl_idname}},
),
)
def register():
if bpy.app.background:
return
from bpy.utils import register_tool
for tool in tools:
register_tool(tool[0], **tool[1])
def unregister():
if bpy.app.background:
return
from bpy.utils import unregister_tool
for tool in reversed(tools):
unregister_tool(tool[0])