-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathControl.py
165 lines (154 loc) · 7.07 KB
/
Control.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
import init_screen
import results_screen
from Utility import PathDefs, init_utilities, MaterialTypes, MachiningTypes, Suppliers, db_utils, slider_utilities
import PySimpleGUI as sg
import slider_screen
import subprocess
import graph_screen
import webbrowser
import math
print(PathDefs.executable_path)
proc = subprocess.Popen(
#["C:\\Users\\akimmel\\PycharmProjects\\LMCOgui\\Utility\\Data\\executable-win\\executable-win\\lmco.exe"]
[PathDefs.executable_path])
if __name__ == '__main__':
window = init_screen.make_window()
preferences = []
prev_factor_values = {}
selectAllMat_cur = False
selectAllMan_cur = False
selectAllBus_cur = False
all_results = []
results = []
dataMaxes = {}
parameters = []
while True:
event, values = window.read()
if event == sg.WIN_CLOSED or event == 'Exit':
break
##---INIT SCREEN CONTROLS---##
if event == 'SelectAllMaterials':
selectAllMat_cur = not selectAllMat_cur
for material in MaterialTypes.materials:
window[material].update(selectAllMat_cur)
if event == 'SelectAllManufacturing':
selectAllMan_cur = not selectAllMan_cur
for machineType in MachiningTypes.machiningTypes:
window[machineType].update(selectAllMan_cur)
if event == 'SelectAllBusinesses':
selectAllBus_cur = not selectAllBus_cur
for business in Suppliers.suppliers:
window[business].update(selectAllBus_cur)
if event == 'Edit Me':
sg.execute_editor(__file__)
if event == 'nextwindow':
preferences = init_utilities.save_preferences(values)
design = values['design_option']
output = db_utils.getBids(design, preferences, values['quantity'], values['-CALStart-'], values['-CALEnd-'])
if len(output) != 2:
sg.popup(str(output) + "Please select new options.", title="Select new options", keep_on_top=True)
else:
all_results = output[0]
results = output[0]
dataMaxes = output[1]
window.close()
window = slider_screen.make_window(dataMaxes, 'DarkTeal12')
##---SLIDER SCREEN CONTROLS---##
if event == 'usealloptions':
window["costs_max"].update(math.ceil(dataMaxes["cost"]))
window["mass_max"].update(math.ceil(dataMaxes["mass"]/1000))
window["displacement_max"].update(math.ceil(dataMaxes["disp"]))
window["time_max"].update(math.ceil(dataMaxes["time"]/(24*60*60)))
if event == 'generateoptions':
# if any of the maximums are empty, just use the data maximums
if values["costs_max"] == "":
values["costs_max"] = math.ceil(dataMaxes["cost"])
if values["mass_max"] == "":
values["mass_max"] = math.ceil(dataMaxes["mass"]/1000)
if values["displacement_max"] == "":
values["displacement_max"] = math.ceil(dataMaxes["disp"])
if values["time_max"] == "":
values["time_max"] = math.ceil(dataMaxes["time"]/(24*60*60))
prev_factor_values = values
parameters = slider_utilities.generate_parameters(values)
window.close()
window, results = results_screen.make_window(parameters, all_results, dataMaxes)
if event == 'agents':
webbrowser.open("http://localhost:9090/agents-graph")
if event == 'lots':
webbrowser.open("http://localhost:9090/lots-graph")
if event == 'backtoinit':
window.close()
window = init_screen.make_window()
selectAllMat_cur = False
selectAllMan_cur = False
selectAllBus_cur = False
##---RESULTS SCREEN CONTROLS---##
if event == 're-sort':
sort_on = ""
if values['sort_design_options'] == 'Highest Score':
sort_on = "score"
default_val = 'Highest Score'
if values['sort_design_options'] == 'Fastest':
sort_on = "time"
default_val = 'Fastest'
if values['sort_design_options'] == 'Cheapest':
sort_on = "cost"
default_val = 'Cheapest'
if values['sort_design_options'] == 'Lightest':
sort_on = "mass"
default_val = 'Lightest'
if values['sort_design_options'] == 'Firmest':
sort_on = "disp"
default_val = 'Firmest'
window.close()
window, results = results_screen.make_window(parameters, results, dataMaxes, sort_on, default_val)
if event == "graphs":
window.close()
window = graph_screen.drawChart(results, 'time', 'cost')
if "supplier" in str(event):
for bid in results:
if bid["link"] == event[8:]:
sg.popup("Suppliers: " + str(bid["suppliers"]) + "\n"
+ "Cost: " + str(bid["cost"]) + " ($)\n"
+ "Mass: " + str(round(bid["mass"], 3)) + " (g)\n"
+ "Lead Time: " + str(bid["time"]) + " (sec)\n"
+ "Displacement: " + str(round(bid["disp"], 3)) + " (mm)\n"
+ "___________________________________________",
title=bid["link"], keep_on_top=True)
break
if "pplan" in str(event):
for bid in results:
if bid["link"] == event[5:]:
sg.popup(str(bid["processPlan"]), title=bid["link"], keep_on_top=True)
break
if "designf" in str(event):
for bid in results:
if bid["link"] == event[7:]:
# path = "`C:\\Users\\akimmel\\PycharmProjects\\LMCOgui\\Utility\\Data\\executable-win\\executable-win\\data\\burak-initial-dataset-v4-zbr\\Generative_Design_Data\\" + bid["link"]
path = PathDefs.design_path / bid["link"]
cmd = 'explorer "' + str(path) + '"'
subprocess.Popen(cmd)
break
if event == "backtosliders":
window.close()
if len(prev_factor_values) != 0:
window = slider_screen.make_window(dataMaxes, 'DarkTeal12', prev_factor_values)
else:
window = slider_screen.make_window(dataMaxes, 'DarkTeal12')
if event == "backtoinit-results":
window.close()
window = init_screen.make_window()
selectAllMat_cur = False
selectAllMan_cur = False
selectAllBus_cur = False
##---GRAPH SCREEN CONTROLS---##
if event == 'backtoresults':
window.close()
window, results = results_screen.make_window(parameters, results, dataMaxes)
if event == 'viewgraph':
x_sel = values["x_option"]
y_sel = values["y_option"]
graph_screen.updateChart(results, x_sel, y_sel)
window.close()
proc.terminate()