-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathui.py
220 lines (169 loc) · 8.41 KB
/
ui.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
import bpy
import webbrowser
# from .rectpack.packer import PackingMode
# Define the options for each EnumProperty
mode_items = [
('PackingMode.Offline', "Offline", "PackingMode.Offline"),
# ('PackingMode.Online', "Online", "PackingMode.Online")
]
bin_algo_items = [
('BNF', "Bin Next Fit", "PackingBin.BNF"),
('BFF', "Bin First Fit", "PackingBin.BFF"),
('BBF', "Bin Best Fit", "PackingBin.BBF"),
('Global', "Global", "PackingBin.Global")
]
pack_algo_items = [
# MaxRects variants
('MaxRectsBl', "MaxRects Bottom-Left", "MaxRectsBl"),
('MaxRectsBssf', "MaxRects Best Short Side Fit", "MaxRectsBssf"),
('MaxRectsBaf', "MaxRects Best Area Fit", "MaxRectsBaf"),
('MaxRectsBlsf', "MaxRects Best Long Side Fit", "MaxRectsBlsf"),
# Skyline variants
('SkylineBl', "Skyline Bottom-Left", "SkylineBl"),
('SkylineBlWm', "Skyline Bottom-Left WasteMap", "SkylineBlWm"),
('SkylineMwf', "Skyline Min Waste Fit", "SkylineMwf"),
('SkylineMwfl', "Skyline Min Waste Fit Level", "SkylineMwfl"),
('SkylineMwfWm', "Skyline Min Waste Fit WasteMap", "SkylineMwfWm"),
('SkylineMwflWm', "Skyline Min Waste Fit Level WasteMap", "SkylineMwflWm"),
# Guillotine variants
('GuillotineBssfSas', "Guillotine BSSF Split Shorter Axis", "GuillotineBssfSas"),
('GuillotineBssfLas', "Guillotine BSSF Split Longer Axis", "GuillotineBssfLas"),
('GuillotineBssfSlas', "Guillotine BSSF Split Longer Axis Shorter Leftover", "GuillotineBssfSlas"),
('GuillotineBssfLlas', "Guillotine BSSF Split Longer Axis Longer Leftover", "GuillotineBssfLlas"),
('GuillotineBssfMaxas', "Guillotine BSSF Split Max Axis", "GuillotineBssfMaxas"),
('GuillotineBssfMinas', "Guillotine BSSF Split Min Axis", "GuillotineBssfMinas"),
('GuillotineBlsfSas', "Guillotine BLSF Split Shorter Axis", "GuillotineBlsfSas"),
('GuillotineBlsfLas', "Guillotine BLSF Split Longer Axis", "GuillotineBlsfLas"),
('GuillotineBlsfSlas', "Guillotine BLSF Split Longer Axis Shorter Leftover", "GuillotineBlsfSlas"),
('GuillotineBlsfLlas', "Guillotine BLSF Split Longer Axis Longer Leftover", "GuillotineBlsfLlas"),
('GuillotineBlsfMaxas', "Guillotine BLSF Split Max Axis", "GuillotineBlsfMaxas"),
('GuillotineBlsfMinas', "Guillotine BLSF Split Min Axis", "GuillotineBlsfMinas"),
('GuillotineBafSas', "Guillotine BAF Split Shorter Axis", "GuillotineBafSas"),
('GuillotineBafLas', "Guillotine BAF Split Longer Axis", "GuillotineBafLas"),
('GuillotineBafSlas', "Guillotine BAF Split Longer Axis Shorter Leftover", "GuillotineBafSlas"),
('GuillotineBafLlas', "Guillotine BAF Split Longer Axis Longer Leftover", "GuillotineBafLlas"),
('GuillotineBafMaxas', "Guillotine BAF Split Max Axis", "GuillotineBafMaxas"),
('GuillotineBafMinas', "Guillotine BAF Split Min Axis", "GuillotineBafMinas"),
]
sort_algo_items = [
('SORT_NONE', "None", "SORT_NONE"),
('SORT_AREA', "Area", "SORT_AREA"),
('SORT_PERI', "Perimeter", "SORT_PERI"),
('SORT_DIFF', "Difference", "SORT_DIFF"),
('SORT_SSIDE', "Short Side", "SORT_SSIDE"),
('SORT_LSIDE', "Long Side", "SORT_LSIDE"),
('SORT_RATIO', "Ratio", "SORT_RATIO")
]
rotation_items = [
('ENABLED', "Enabled", "Enable rotation"),
('DISABLED', "Disabled", "Disable rotation")
]
# Function to open the PayPal donation link
def open_paypal_link():
webbrowser.open_new_tab("Your_PayPal_Donation_Link")
# Custom UI List
class SimpleUlDimensions(bpy.types.UIList):
def draw_item(self, context, layout, data, item, icon, active_data, active_propname, index):
sorted_dims = sorted([item.width, item.height, item.length], reverse=True)
sorted_dims = [round(x, 2) for x in sorted_dims]
# Split the layout and add the index as a label
layout = layout.split(factor=0.8)
row = layout.row()
row.label(text=f"{index + 1}") # Add +1 to index for human-readable numbering (starting from 1)
row.label(text=f"{item.name}")
row.label(text=f"{sorted_dims[0]:.2f}")
row.label(text=f"{sorted_dims[1]:.2f}")
row.label(text=f"{sorted_dims[2]:.2f}")
for i in range(1, 5):
is_toggled = getattr(item, f'is_toggled_{i}')
toggle_icon = "SEQUENCE_COLOR_04" if is_toggled else "SEQUENCE_COLOR_09"
label_text = "Long" if i <= 2 else "Short"
toggle_op = row.operator("object.toggle_entry", icon=toggle_icon, text=label_text)
toggle_op.index = index
toggle_op.toggle_id = i
remove_op = layout.operator("object.remove_dimension", text="X")
remove_op.index = index
# Panel
class SimplePanel(bpy.types.Panel):
bl_label = "Dimension Panel"
bl_idname = "PT_DimensionPanel"
bl_space_type = 'VIEW_3D'
bl_region_type = 'UI'
bl_category = 'Arka'
def draw(self, context):
layout = self.layout
row = layout.row()
row.prop(context.scene, "project_name", text="Project")
row = layout.row()
row.prop(context.scene, "material_name", text="Material")
layout.separator()
row = layout.row(align=True)
row.operator("object.get_dimension")
row.operator("object.regenerate_dimensions")
row.operator("object.clear_all_dimensions")
layout.separator()
row = layout.row()
row.template_list("SimpleUlDimensions", "", context.scene, "dimension_entries", context.scene, "dimension_entries_index", rows=7)
row = layout.row()
row.prop(context.scene, "container_width", text="Container Width(cm)")
row.prop(context.scene, "container_height", text="Container Height(cm)")
row.prop(context.scene, "spacing", text="Spacing")
layout.separator()
layout.label(text="Packing Options:")
# Dropdown for mode
row = layout.row()
row.prop(context.scene, "packing_mode", text="Mode")
# Dropdown for bin_algo
row = layout.row()
row.prop(context.scene, "bin_algo", text="Bin Algorithm")
# Dropdown for pack_algo
row = layout.row()
row.prop(context.scene, "pack_algo", text="Packing Algorithm")
# Dropdown for sort_algo
row = layout.row()
row.prop(context.scene, "sort_algo", text="Sort Algorithm")
# Dropdown for rotation
row = layout.row()
row.prop(context.scene, "rotation", text="Rotation")
layout.separator()
row = layout.row(align=True)
row.operator("object.run_project_objects")
row.operator("object.run_nesting_algorithm")
row = layout.row(align=True)
row.operator("object.export_csv")
row.operator("object.stickers_operator")
layout.operator("object.export_canvas_as_pdf", text="Canvas")
layout.separator()
# PayPal.me donation button
paypal_button = layout.row()
paypal_button.operator("wm.url_open", text="Support via PayPal").url = "https://www.paypal.me/JovanSerbia"
# Placeholder text message below the button
layout.label(text="Your support helps us improve and maintain this add-on!")
def register():
bpy.utils.register_class(SimpleUlDimensions)
bpy.utils.register_class(SimplePanel)
bpy.types.Scene.project_name = bpy.props.StringProperty(name="Project")
bpy.types.Scene.material_name = bpy.props.StringProperty(name="Material")
bpy.types.Scene.spacing = bpy.props.IntProperty(name="Spacing")
bpy.types.Scene.container_width = bpy.props.IntProperty(name="Container Width")
bpy.types.Scene.container_height = bpy.props.IntProperty(name="Container Height")
bpy.types.Scene.packing_mode = bpy.props.EnumProperty(items=mode_items)
bpy.types.Scene.bin_algo = bpy.props.EnumProperty(items=bin_algo_items)
bpy.types.Scene.pack_algo = bpy.props.EnumProperty(items=pack_algo_items)
bpy.types.Scene.sort_algo = bpy.props.EnumProperty(items=sort_algo_items)
bpy.types.Scene.rotation = bpy.props.EnumProperty(items=rotation_items)
def unregister():
bpy.utils.unregister_class(SimplePanel)
bpy.utils.unregister_class(SimpleUlDimensions)
del bpy.types.Scene.project_name
del bpy.types.Scene.material_name
del bpy.types.Scene.spacing
del bpy.types.Scene.container_width
del bpy.types.Scene.container_height
del bpy.types.Scene.packing_mode
del bpy.types.Scene.bin_algo
del bpy.types.Scene.pack_algo
del bpy.types.Scene.sort_algo
del bpy.types.Scene.rotation
if __name__ == "__main__":
register()