diff --git a/main.py b/main.py index 3f574bb..9ed6481 100644 --- a/main.py +++ b/main.py @@ -1,6 +1,6 @@ import os import sys -from copy import copy, deepcopy +from copy import copy from math import sqrt, ceil, floor import numpy as np import tkinter as tk @@ -28,14 +28,6 @@ bins = None blocked = False saveBinsButton = None showKeyButton = None -exportHeightEntry = None -exportWidthEntry = None -exportKerfEntry = None -lastW = None -lastH = None -lastK = None -resultWinHeight = None -resultWinWidth = None # shows dimensions and layer count in main gui window @@ -110,14 +102,12 @@ def focus_results(): # bring results window forward if results is not None and 'normal' == results.state(): results.focus_set() - results.geometry("") - return # run slices, show export window def go(): - global combined, sections, results, saveBinsButton, showKeyButton, showKey, exportHeightEntry, exportWidthEntry, exportKerfEntry, resultWinWidth, resultWinHeight + global combined, sections, results, saveBinsButton, showKeyButton, showKey focus_results() @@ -144,7 +134,6 @@ def go(): results = tk.Toplevel(root) results.title("Results") results.protocol("WM_DELETE_WINDOW", clearResults) - results.resizable(0, 0) buttonFrame = tk.Frame(results) viewFrame = tk.Frame(buttonFrame) @@ -193,9 +182,6 @@ def go(): results.update() results.geometry(f'+{root.winfo_rootx()+int((root.winfo_width()-results.winfo_width())/2)}+{root.winfo_rooty()+int((root.winfo_height()-results.winfo_height())/2)}') - - resultWinWidth = results.winfo_width() - resultWinHeight = results.winfo_height() results.mainloop() @@ -255,37 +241,15 @@ def export(): blocked = False -def checkPrepared(args=None): - shouldRemove = False - try: - shouldRemove = float(exportWidthEntry.get()) != lastW or float(exportHeightEntry.get()) != lastH or float(exportKerfEntry.get()) != lastK - except ValueError: - shouldRemove = True - finally: - if shouldRemove: - saveBinsButton.pack_forget() - showKeyButton.pack_forget() - - results.geometry(f"{resultWinHeight}x{resultWinHeight}") - else: - if not saveBinsButton.winfo_ismapped(): - results.geometry("") - saveBinsButton.pack(side=LEFT, padx=1) - showKeyButton.pack(side=LEFT) - # prepares bins for export, performs bin packing # arguments: bin height, bin width, kerf def exportFile(h, w, k): - global blocked, bins, pdfSections, exportWidthEntry, exportHeightEntry, exportKerfEntry, lastW, lastH, lastK + global blocked, bins, pdfSections # if other window is not open if not blocked: blocked = True - lastW = w - lastH = h - lastK = k - # prepare packers, one with rotation enabled, one disabled, results will be compared later packer = newPacker(mode=PackingMode.Offline, bin_algo=PackingBin.Global, sort_algo=SORT_NONE, rotation=False) rotPacker = newPacker(mode=PackingMode.Offline, bin_algo=PackingBin.Global, sort_algo=SORT_NONE, rotation=True) @@ -294,10 +258,9 @@ def exportFile(h, w, k): for i in range(len(sections)): dimensions = sections[i].bounds - sect = deepcopy(sections[i]) - sect.apply_translation((-dimensions[0][0], -dimensions[0][1])) + sections[i].apply_translation((-dimensions[0][0], -dimensions[0][1])) - dimensions = sect.bounds + dimensions = sections[i].bounds # set dimensions to bounds plus kerf r = (float2dec((dimensions[1][0]) + k, 5), float2dec((dimensions[1][1]) + k, 5)) @@ -314,7 +277,6 @@ def exportFile(h, w, k): # init var to largest bin area of packers, will be overridden to find minimum area used, minimizing material wastage leastBinSum = w * h * max(len(packer), len(rotPacker)) - leastPacker = packer # loop through packers for pack in (packer, rotPacker): binSum = 0 @@ -367,7 +329,7 @@ def exportFile(h, w, k): # add rectangles to their designated bins for rect in packer.rect_list(): - section = deepcopy(sections[rect[5]]) + section = sections[rect[5]] bin = rect[0] # find position of bin for display purposes (bins displayed in grid, find row & col) @@ -410,12 +372,6 @@ def exportFile(h, w, k): saveBinsButton.pack(side=LEFT, padx=1) showKeyButton.pack(side=LEFT) - exportWidthEntry.bind('', checkPrepared) - exportHeightEntry.bind('', checkPrepared) - exportKerfEntry.bind('', checkPrepared) - - focus_results() - blocked = False @@ -478,7 +434,6 @@ root.attributes("-toolwindow", 1) p1 = tk.PhotoImage(file=resource_path('icon.png')) # Icon set for program window root.iconphoto(True, p1) -root.resizable(0, 0) # clear children of base window clearList = root.winfo_children()