#!/usr/bin/python3 from tkinter import * import math from random import randint import numpy as np #class Room(): # def __init__(self, points, Color) class DipoleMagnet(): def __init__(self, EntryPos, Size, Angle, Color): self.radius = (Size[0] + Size[1])/2 self.EntryPos = EntryPos self.Angle = Angle self.Center = [ self.EntryPos[0] - self.radius * math.cos(math.radians(Angle[0])) , self.EntryPos[1] + self.radius * math.sin(math.radians(Angle[0])) ] self.ULC = [ self.Center[0] - Size[0], self.Center[1] - Size[0] ] self.ExistPos = np.array([self.Center[0] + self.radius * math.cos(math.radians(Angle[1])) , self.Center[1] - self.radius * math.sin(math.radians(Angle[1])) ]) self.dMagnet1 = canvas.create_arc ( self.ULC[0], self.ULC[1], self.ULC[0] + 2*Size[0], self.ULC[1] + 2*Size[0], start = Angle[0], extent = Angle[1], fill = Color, outline = Color) self.dMagnet2 = canvas.create_arc ( self.ULC[0] + (Size[0] - Size[1]), self.ULC[1] + (Size[0] - Size[1]), self.ULC[0] + (Size[0] + Size[1]), self.ULC[1] + (Size[0] + Size[1]), start = Angle[0], extent = Angle[1], fill = 'black', outline = 'black') def GetExitPos(self, downstream = 0): return self.ExistPos + np.array([ downstream * math.cos(math.radians(self.Angle[1] + 90 )), -downstream * math.sin(math.radians(self.Angle[1] + 90 )) ]) class Tandem(): def __init__(self, EntryPos, Size, Color): self.ULC = [EntryPos[0] - Size[0]/2, EntryPos[1] - Size[1] ] self.ExistPos = np.array([ EntryPos[0] , EntryPos[1] - Size[1] ]) self.tandem1 = canvas.create_arc (self.ULC[0], self.ULC[1] , self.ULC[0] + Size[0], self.ULC[1] + Size[0] , start = 0, extent = 180, fill = Color, outline = Color) self.tandem2 = canvas.create_rectangle(self.ULC[0], self.ULC[1] + Size[0]/2 , self.ULC[0] + Size[0], self.ULC[1] + Size[1] - Size[0]/2 , fill = Color, outline = Color) self.tandem3 = canvas.create_arc (self.ULC[0], self.ULC[1] + Size[1] - Size[0], self.ULC[0] + Size[0], self.ULC[1] + Size[1] , start = 0, extent = -180, fill = Color, outline = Color) def GetExitPos(self, downstream = 0): return self.ExistPos + np.array([0, - downstream]) class BeamRectElement(): def __init__(self, EntryPos, Size, Angle, Color): self.Color = Color self.p1 = [ EntryPos[0] - Size[0]/2 * math.cos(math.radians(Angle)), EntryPos[1] + Size[0]/2 * math.sin(math.radians(Angle))] self.p2 = [self.p1[0] + Size[0] * math.cos(math.radians(Angle)), self.p1[1] - Size[0] * math.sin(math.radians(Angle)) ] self.p3 = [self.p2[0] - Size[1] * math.sin(math.radians(Angle)), self.p2[1] - Size[1] * math.cos(math.radians(Angle)) ] self.p4 = [self.p3[0] - Size[0] * math.cos(math.radians(Angle)), self.p3[1] + Size[0] * math.sin(math.radians(Angle)) ] self.pts = [self.p1[0], self.p1[1], self.p2[0], self.p2[1], self.p3[0], self.p3[1], self.p4[0], self.p4[1] ] self.Angle = Angle self.ExistPos = np.array([(self.p4[0] + self.p3[0])/2, (self.p4[1] + self.p3[1])/2 ]) self.beamPipe = canvas.create_polygon(self.pts, fill = Color, width = 0) def GetExitPos(self, downstream = 0): return self.ExistPos + np.array([ - downstream * math.sin(math.radians(self.Angle )), - downstream * math.cos(math.radians(self.Angle )) ]) def SetColor(self, Color): self.Color = Color canvas.itemconfig(self.beamPipe, fill = Color) def GetColor(self): return self.Color class Beam90DegreeFan(): def __init__(self, EntryPos, Radius, Angle, Color): self.EntryPos = np.array(EntryPos) self.Radius = Radius self.Angle = Angle self.ULC = [EntryPos[0] - Radius, EntryPos[1] - Radius] self.beamFan1 = BeamRectElement(EntryPos, [Radius/2, Radius/2], Angle, Color) self.beamFan2 = canvas.create_arc( self.ULC[0], self.ULC[1], self.ULC[0] + 2 * Radius, self.ULC[1] + 2 * Radius , start = 45 + Angle, extent = 90, fill = Color, outline = Color) def GetExitPos(self, angle, downstream = 0): return self.EntryPos + np.array([ (self.Radius + downstream)* math.cos(math.radians( 45 + angle + self.Angle)), - (self.Radius + downstream)*math.sin(math.radians( 45 + angle + self.Angle))]) def GetExitAngle(self, angle): return 45 + angle + self.Angle - 90 class Station(): def __init__(self, Center, Size, Name, Color): self.ULC = [Center[0] - Size/2, Center[1] - Size/2] self.station = canvas.create_oval(self.ULC[0], self.ULC[1], self.ULC[0] + Size, self.ULC[1]+Size, fill = Color, outline = Color) self.label = Label(canvas, text = Name, bg = Color) self.label.place(x=Center[0], y=Center[1], anchor = "center") ############################## Start GUI windowSize = [3840, 1500]# 4K upper half window = Tk(className = 'FSU Fox\'s Lab Experimental Hall') #window.geometry("1920x1080") @ 2K #window.geometry("3840x2160") # 4K window.geometry(str(windowSize[0]) + "x" + str(windowSize[1])) window.configure(bg='black') #window.attributes('-fullscreen', True) canvas = Canvas(window) canvas.configure(bg='black', bd = 0, highlightthickness=0, relief='ridge') canvas.pack( expand = True, fill = BOTH) #==================== interlock #==================== Beam line #++++++++++++++++ source tandemStart = [windowSize[0] * 0.9, windowSize[1] * 0.8] # beam entry pos tandemSize = [100, 300] # width, height tandem = Tandem(tandemStart, tandemSize, 'Green') bl0 = BeamRectElement( tandem.GetExitPos() , [10, 300], 0, 'white') bl0a = BeamRectElement( bl0.GetExitPos(), [10, 400], 0, 'grey12') # beam by-pass D-1 q1 = BeamRectElement(tandem.GetExitPos(50) , [60, 60], 0, 'Blue') df1 = BeamRectElement(q1.GetExitPos(50) , [40, 30], 0, 'orange') df2 = BeamRectElement(df1.GetExitPos(20), [40, 30], 0, 'orange') #++++++++++++++++ beam line to target room 1 dMagnetSize = [80, 20] # outer, inner radius d1 = DipoleMagnet(bl0.GetExitPos(), dMagnetSize, [0, 90], 'Yellow') bl1 = BeamRectElement( d1.GetExitPos(), [10, 100], 90, 'white') bfan1 = Beam90DegreeFan(bl1.GetExitPos(), 100, 90, 'Yellow') #-------- upper beam line angle_a = 30 beamline1Angle_a = bfan1.GetExitAngle(angle_a) bl1a = BeamRectElement( bfan1.GetExitPos(angle_a), [10, 350], beamline1Angle_a, 'white') q1a = BeamRectElement(bfan1.GetExitPos(angle_a, 100), [60, 60], beamline1Angle_a, 'blue') df1a = BeamRectElement(q1a.GetExitPos(30), [40, 30], beamline1Angle_a, 'orange') bl1a_1 = BeamRectElement( bl1a.GetExitPos(), [10, 200], beamline1Angle_a, 'white') #.......... Gamma station GammaStation = Station(bl1a.GetExitPos(), 100, "Gamma\nStation", 'Pink4') #.......... Catrina Catrina = Station(bl1a_1.GetExitPos(), 100, "Catrina", 'Pink') #---------middle beam line angle_b = 50 beamline1Angle_b = bfan1.GetExitAngle(angle_b) bl1b = BeamRectElement( bfan1.GetExitPos(angle_b), [10, 300], beamline1Angle_b, 'grey12') #--------- lower beam line angle_c = 70 beamline1Angle_c = bfan1.GetExitAngle(angle_c) bl1c = BeamRectElement( bfan1.GetExitPos(angle_c), [10, 300], beamline1Angle_c, 'grey12') q1c = BeamRectElement(bfan1.GetExitPos(angle_c, 100), [60, 60], beamline1Angle_c, 'blue') df1c = BeamRectElement(q1c.GetExitPos(50), [40, 30], beamline1Angle_c, 'orange') #++++++++++++++++ beam line to target room 2 q2 = BeamRectElement( bl0.GetExitPos(100), [60, 60], 0, 'blue') df2 = BeamRectElement( q2.GetExitPos(50), [40, 40], 0, 'orange') q3 = BeamRectElement( df2.GetExitPos(50), [60, 60], 0, 'blue') d2 = DipoleMagnet(bl0a.GetExitPos(), [80, 20], [0, 90], 'Yellow') bl3 = BeamRectElement(d2.GetExitPos(), [10, 2000], 90, 'grey12') linac1 = BeamRectElement(d2.GetExitPos(500) , [80, 300], 90, 'cyan') linac2 = BeamRectElement(linac1.GetExitPos(30) , [80, 300], 90, 'cyan') linac3 = BeamRectElement(linac2.GetExitPos(30) , [80, 300], 90, 'cyan') #==================== Labels and info label = Label(canvas, text='hahaha') label.place(x = windowSize[0] * 0.9, y = tandemStart[1] - 100) #label.bind('', lambda e: label.configure(text='Moved mouse inside')) #label.bind('', lambda e: label.configure(text='Moved mouse outside')) #==================== Button exit_button = Button(canvas, text="Exit", command=window.destroy) exit_button.place(x = windowSize[0] - 200, y = 50) ###################### Beam line activation def update(): label['text'] = "Pressure : "+ str(randint(0, 1000)) + " bar" if bl0.GetColor() == 'Red' : bl0.SetColor('White') bl1.SetColor('White') bl1a.SetColor('White') bl1a_1.SetColor('White') else: bl0.SetColor('Red') bl1.SetColor('Red') bl1a.SetColor('Red') bl1a_1.SetColor('Red') window.after(1000, update) # run itself again after 1000 ms update() window.mainloop()