Merge branch 'blender-v4.0-release'
[blender-addons.git] / object_print3d_utils / ui.py
blobb534f2be0876cb6b477b9087e96d0c7d18f7a044
1 # SPDX-FileCopyrightText: 2013-2022 Blender Foundation
3 # SPDX-License-Identifier: GPL-2.0-or-later
5 # Interface for this addon.
8 from bpy.types import Panel
9 import bmesh
11 from . import report
14 class View3DPrintPanel:
15 bl_category = "3D-Print"
16 bl_space_type = 'VIEW_3D'
17 bl_region_type = 'UI'
19 @classmethod
20 def poll(cls, context):
21 obj = context.active_object
22 return obj is not None and obj.type == 'MESH' and obj.mode in {'OBJECT', 'EDIT'}
25 class VIEW3D_PT_print3d_analyze(View3DPrintPanel, Panel):
26 bl_label = "Analyze"
28 _type_to_icon = {
29 bmesh.types.BMVert: 'VERTEXSEL',
30 bmesh.types.BMEdge: 'EDGESEL',
31 bmesh.types.BMFace: 'FACESEL',
34 def draw_report(self, context):
35 layout = self.layout
36 info = report.info()
38 if info:
39 is_edit = context.edit_object is not None
41 layout.label(text="Result")
42 box = layout.box()
43 col = box.column()
45 for i, (text, data) in enumerate(info):
46 if is_edit and data and data[1]:
47 bm_type, _bm_array = data
48 col.operator("mesh.print3d_select_report", text=text, icon=self._type_to_icon[bm_type],).index = i
49 else:
50 col.label(text=text)
52 def draw(self, context):
53 layout = self.layout
55 print_3d = context.scene.print_3d
57 # TODO, presets
59 layout.label(text="Statistics")
60 row = layout.row(align=True)
61 row.operator("mesh.print3d_info_volume", text="Volume")
62 row.operator("mesh.print3d_info_area", text="Area")
64 layout.label(text="Checks")
65 col = layout.column(align=True)
66 col.operator("mesh.print3d_check_solid", text="Solid")
67 col.operator("mesh.print3d_check_intersect", text="Intersections")
68 row = col.row(align=True)
69 row.operator("mesh.print3d_check_degenerate", text="Degenerate")
70 row.prop(print_3d, "threshold_zero", text="")
71 row = col.row(align=True)
72 row.operator("mesh.print3d_check_distort", text="Distorted")
73 row.prop(print_3d, "angle_distort", text="")
74 row = col.row(align=True)
75 row.operator("mesh.print3d_check_thick", text="Thickness")
76 row.prop(print_3d, "thickness_min", text="")
77 row = col.row(align=True)
78 row.operator("mesh.print3d_check_sharp", text="Edge Sharp")
79 row.prop(print_3d, "angle_sharp", text="")
80 row = col.row(align=True)
81 row.operator("mesh.print3d_check_overhang", text="Overhang")
82 row.prop(print_3d, "angle_overhang", text="")
83 layout.operator("mesh.print3d_check_all", text="Check All")
85 self.draw_report(context)
88 class VIEW3D_PT_print3d_cleanup(View3DPrintPanel, Panel):
89 bl_label = "Clean Up"
90 bl_options = {"DEFAULT_CLOSED"}
92 def draw(self, context):
93 layout = self.layout
95 print_3d = context.scene.print_3d
97 row = layout.row(align=True)
98 row.operator("mesh.print3d_clean_distorted", text="Distorted")
99 row.prop(print_3d, "angle_distort", text="")
100 layout.operator("mesh.print3d_clean_non_manifold", text="Make Manifold")
101 # XXX TODO
102 # layout.operator("mesh.print3d_clean_thin", text="Wall Thickness")
105 class VIEW3D_PT_print3d_transform(View3DPrintPanel, Panel):
106 bl_label = "Transform"
107 bl_options = {"DEFAULT_CLOSED"}
109 def draw(self, context):
110 layout = self.layout
112 print_3d = context.scene.print_3d
114 layout.label(text="Scale To")
115 row = layout.row(align=True)
116 row.operator("mesh.print3d_scale_to_volume", text="Volume")
117 row.operator("mesh.print3d_scale_to_bounds", text="Bounds")
118 row = layout.row(align=True)
119 row.operator("mesh.print3d_align_to_xy", text="Align XY")
120 row.prop(print_3d, "use_alignxy_face_area")
123 class VIEW3D_PT_print3d_export(View3DPrintPanel, Panel):
124 bl_label = "Export"
125 bl_options = {"DEFAULT_CLOSED"}
127 def draw(self, context):
128 layout = self.layout
129 layout.use_property_split = True
130 layout.use_property_decorate = False
132 print_3d = context.scene.print_3d
134 layout.prop(print_3d, "export_path", text="")
135 layout.prop(print_3d, "export_format")
137 col = layout.column()
138 col.prop(print_3d, "use_apply_scale")
139 col.prop(print_3d, "use_export_texture")
140 sub = col.column()
141 sub.active = print_3d.export_format != "STL"
142 sub.prop(print_3d, "use_data_layers")
144 layout.operator("mesh.print3d_export", text="Export", icon='EXPORT')