-
Notifications
You must be signed in to change notification settings - Fork 0
/
Factory.py
78 lines (69 loc) · 2.34 KB
/
Factory.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
from tkinter import Tk
from View import View
from pprint import pprint
from Product import StepResult
import time
import sys
from enum import Enum
import constants
class visibilityStatus(Enum):
NONE = 0
WorkstationPos = 1
ALL = 2
class Factory:
def __init__(self, ws, p, cfs, vs):
self.workStations = ws
self.products = p
self.currentFieldStatus = cfs
self.vs = vs
self.View = None
if vs != visibilityStatus.NONE:
self.viewRoot = Tk()
self.View = View(self.viewRoot, self.products, self.workStations, self)
self.viewRoot.geometry("1000x600+300+50")
def productReset(self):
for p in self.products:
p.reset()
def privateRun(self, vs):
counter = 0
totalMoves = 0
while True:
madeChange = False
isDone = True
for p in self.products:
result = p.run(self.currentFieldStatus)
if result == StepResult.MOVED:
madeChange = True
isDone = False
if result == StepResult.BLOCKED:
isDone = False
if result == StepResult.FIRSTDONE:
madeChange = True
totalMoves += counter
if isDone:
if vs != visibilityStatus.NONE:
self.View.nextTimeStep(self.products, self.workStations)
self.viewRoot.update()
self.View.showButton()
pprint("Done in " + str(counter) + ' steps.')
return counter # * 100000 + totalMoves
if not madeChange:
if vs != visibilityStatus.NONE:
pprint("Blocked")
return sys.maxsize
counter += 1
if vs == visibilityStatus.ALL:
self.View.nextTimeStep(self.products, self.workStations)
self.viewRoot.update()
time.sleep(constants.TIME_PER_STEP)
def run(self):
returnVal = None
def innerRun():
nonlocal returnVal
returnVal = self.privateRun(self.vs)
if self.vs != visibilityStatus.NONE:
self.viewRoot.after(1000, innerRun)
self.viewRoot.mainloop()
else:
innerRun()
return returnVal