#!/usr/bin/python3 from tkinter import * import math from random import randint import numpy as np class Room(): def __init__(self, points, Color): self.room = canvas.create_polygon(points, width = 2, outline = 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[0]+Angle[1])) , self.Center[1] - self.radius * math.sin(math.radians(Angle[0]+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]-2, extent = Angle[1]+4, fill = 'black', outline = 'black') def GetExitPos(self, downstream = 0): return self.ExistPos + np.array([ downstream * math.cos(math.radians(self.Angle[0]+self.Angle[1] + 90 )), -downstream * math.sin(math.radians(self.Angle[0] + self.Angle[1] + 90 )) ]) def GetExitRelAngle(self): return self.Angle[0]+self.Angle[1] 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.Active = False 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 def Deactivate(self): self.Active = False self.Color = 'grey10' canvas.itemconfig(self.beamPipe, fill = 'grey10') def Activate(self): self.Active = True def Blink(self): if self.Active == True: if self.Color == 'White' : self.Color = 'Red' canvas.itemconfig(self.beamPipe, fill = 'Red') else: self.Color = 'White' canvas.itemconfig(self.beamPipe, fill = 'White') class BeamCircleElement(): def __init__(self, Center, Size, Color): self.Center = Center self.ULC = [Center[0] - Size/2, Center[1] - Size/2] self.beamCirc = canvas.create_oval(self.ULC[0], self.ULC[1], self.ULC[0] + Size, self.ULC[1]+Size, fill = Color, outline = Color) def GetCenterPos(self): return self.Center class BeamSwitch(): 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( 90 + angle + self.Angle)), - (self.Radius + downstream)*math.sin(math.radians( 90 + angle + self.Angle))]) def GetExistAbsAngle(self, angle): return angle + self.Angle class DetectorStation(): def __init__(self, Center, Size, Name, Color): self.Name = Name self.ULC = [Center[0] - Size/2, Center[1] - Size/2] self.Detector = canvas.create_oval(self.ULC[0], self.ULC[1], self.ULC[0] + Size, self.ULC[1]+Size, fill = Color, width = 0) self.label = Label(canvas, text = Name, bg = Color, cursor = "hand1") self.label.place(x=Center[0], y=Center[1], anchor = "center") canvas.tag_bind(self.Detector, '<1>', self.onClick) self.label.bind('<1>', self.onClick) canvas.tag_bind(self.Detector, '', self.HopOver) canvas.tag_bind(self.Detector, '', self.Leave) def SetColor(self, Color): canvas.itemconfig(self.Detector, fill = Color) self.label.config(bg = Color) def onClick(self, event): print("========== ", self.Name) bl0.Deactivate() bl1.Deactivate() bl1a.Deactivate(); bl1a_1.Deactivate() bl1b.Deactivate() bl1c.Deactivate() bl0a.Deactivate(); bl3.Deactivate() bl2a.Deactivate(); bl2a_1.Deactivate() bl2b.Deactivate() bl2c.Deactivate() bl2c_1.Deactivate() bl2c_2.Deactivate() SetActiveBeamLine(self.Name) return self.Name def HopOver(self, event): canvas.config(cursor="hand1") def Leave(self, event): canvas.config(cursor="") def GetName(self): return self.Name def Activate(self, OnOff): if OnOff == True: self.SetColor('Pink') else: self.SetColor('Pink4') def SetActiveBeamLine(BeamLineName): if BeamLineName == "Gamma\nStation": bl0.Activate() bl1.Activate() bl1a.Activate(); bl1a_1.Deactivate() bl1b.Deactivate() bl1c.Deactivate() bl0a.Deactivate(); bl3.Deactivate() bl2a.Deactivate(); bl2a_1.Deactivate() bl2b.Deactivate() bl2c.Deactivate() bl2c_1.Deactivate() bl2c_2.Deactivate() GammaStation.Activate(True) Catrina.Activate(False) Resolut.Activate(False) Anasen.Activate(False) SPS.Activate(False) Clarion2.Activate(False) elif BeamLineName == "CATRiNA" : bl0.Activate() bl1.Activate() bl1a.Activate(); bl1a_1.Activate() bl1b.Deactivate() bl1c.Deactivate() bl0a.Deactivate(); bl3.Deactivate() bl2a.Deactivate(); bl2a_1.Deactivate() bl2b.Deactivate() bl2c.Deactivate() bl2c_1.Deactivate() bl2c_2.Deactivate() GammaStation.Activate(False) Catrina.Activate(True) Resolut.Activate(False) Anasen.Activate(False) SPS.Activate(False) Clarion2.Activate(False) cursor="hand1" elif BeamLineName == "RESOLUT" : bl0.Activate() bl1.Deactivate() bl1a.Deactivate(); bl1a_1.Deactivate() bl1b.Deactivate() bl1c.Deactivate() bl0a.Activate(); bl3.Activate() bl2a.Activate(); bl2a_1.Activate() bl2b.Deactivate() bl2c.Deactivate() bl2c_1.Deactivate() bl2c_2.Deactivate() GammaStation.Activate(False) Catrina.Activate(False) Resolut.Activate(True) Anasen.Activate(False) SPS.Activate(False) Clarion2.Activate(False) elif BeamLineName == "ANASEN" : bl0.Activate() bl1.Deactivate() bl1a.Deactivate(); bl1a_1.Deactivate() bl1b.Deactivate() bl1c.Deactivate() bl0a.Activate(); bl3.Activate() bl2a.Deactivate(); bl2a_1.Deactivate() bl2b.Activate() bl2c.Deactivate() bl2c_1.Deactivate() bl2c_2.Deactivate() GammaStation.Activate(False) Catrina.Activate(False) Resolut.Activate(False) Anasen.Activate(True) SPS.Activate(False) Clarion2.Activate(False) elif BeamLineName == "SPS" : bl0.Activate() bl1.Deactivate() bl1a.Deactivate(); bl1a_1.Deactivate() bl1b.Deactivate() bl1c.Deactivate() bl0a.Activate(); bl3.Activate() bl2a.Deactivate(); bl2a_1.Deactivate() bl2b.Deactivate() bl2c.Activate() bl2c_1.Activate() bl2c_2.Deactivate() GammaStation.Activate(False) Catrina.Activate(False) Resolut.Activate(False) Anasen.Activate(False) SPS.Activate(True) Clarion2.Activate(False) elif BeamLineName == "CLARION-2" : bl0.Activate() bl1.Deactivate() bl1a.Deactivate(); bl1a_1.Deactivate() bl1b.Deactivate() bl1c.Deactivate() bl0a.Activate(); bl3.Activate() bl2a.Deactivate(); bl2a_1.Deactivate() bl2b.Deactivate() bl2c.Activate() bl2c_1.Deactivate() bl2c_2.Activate() GammaStation.Activate(False) Catrina.Activate(False) Resolut.Activate(False) Anasen.Activate(False) SPS.Activate(False) Clarion2.Activate(True) ############################## Start GUI #windowSize = [3840, 1500]# 4K width windowSize = [3840, 2160]# 4K window = Tk(className = 'FSU Fox\'s Lab Experimental Hall') 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 #room1 = Room([200, 100, 1400, 100, 1400, 250, 3500, 250, 3500, 420, 1400, 420, 1400, 1200, 200, 1200], 'White') #room2 = Room([3300, 420, 3600, 420, 3600, 2000, 3300, 2000], 'White') #room3 = #==================== Beam line #++++++++++++++++ source RFsource1 = BeamRectElement( [windowSize[0]*0.9, windowSize[1]*0.8], [100, 40], 0, 'olivedrab') RFsource2 = BeamRectElement( RFsource1.GetExitPos(), [20, 80], 0, 'olivedrab') blS = BeamRectElement( RFsource2.GetExitPos(), [10, 200], 0, 'white') bfanS = BeamSwitch(RFsource2.GetExitPos(100), 50, 180, 'yellow') blS0 = BeamRectElement( bfanS.GetExitPos(30), [10, 50], bfanS.GetExistAbsAngle(30), 'white') SNICS = BeamRectElement( blS0.GetExitPos(), [50, 50], bfanS.GetExistAbsAngle(30), 'tan') blS1 = BeamRectElement( bfanS.GetExitPos(-30), [10, 50], bfanS.GetExistAbsAngle(-30), 'white') TriSource = BeamRectElement( blS1.GetExitPos(), [50, 50], bfanS.GetExistAbsAngle(-30), 'cyan') tandemSize = [100, 300] # width, height tandem = Tandem(blS.GetExitPos(), 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 = BeamSwitch(bl1.GetExitPos(), 50, 90, 'Yellow') #-------- upper beam line angle_a = -15 beamline1Angle_a = bfan1.GetExistAbsAngle(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 DetectorStation GammaStation = DetectorStation(bl1a.GetExitPos(), 100, "Gamma\nStation", 'Pink4') #.......... Catrina Catrina = DetectorStation(bl1a_1.GetExitPos(), 100, "CATRiNA", 'Pink') #---------middle beam line angle_b = 10 beamline1Angle_b = bfan1.GetExistAbsAngle(angle_b) bl1b = BeamRectElement( bfan1.GetExitPos(angle_b), [10, 300], beamline1Angle_b, 'grey12') #--------- lower beam line angle_c = 40 beamline1Angle_c = bfan1.GetExistAbsAngle(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') df3 = BeamRectElement(d2.GetExitPos(100), [40, 40], 90, 'orange') q4 = BeamRectElement(df3.GetExitPos(50), [60, 60], 90, 'blue') df4 = BeamRectElement(q4.GetExitPos(50), [40, 40], 90, 'orange') buncher = BeamCircleElement(df4.GetExitPos(90), 80, 'ivory2') 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') df5 = BeamRectElement(linac3.GetExitPos(50), [40, 40], 90, 'orange') df6 = BeamRectElement(df5.GetExitPos(50), [40, 40], 90, 'orange') q5 = BeamRectElement(df6.GetExitPos(50), [60, 60], 90, 'blue') df7 = BeamRectElement(q5.GetExitPos(50), [40, 40], 90, 'orange') bfan2 = BeamSwitch(bl3.GetExitPos(), 50, 90, 'Yellow') #------------- beam line 2a angle2a = -15 beamlineAngle2a = bfan2.GetExistAbsAngle(angle2a); bl2a = BeamRectElement( bfan2.GetExitPos(angle2a), [10, 500], beamlineAngle2a, 'grey12') df2a_1 = BeamRectElement( bfan2.GetExitPos(angle2a, 50), [40,40], beamlineAngle2a, 'orange') q2a = BeamRectElement(df2a_1.GetExitPos(30), [60, 60], beamlineAngle2a, 'blue') df2a_2 = BeamRectElement(q2a.GetExitPos(30), [40, 30], beamlineAngle2a, 'orange') df2a_3 = BeamRectElement(df2a_2.GetExitPos(30), [40, 30], beamlineAngle2a, 'orange') d3 = DipoleMagnet(bl2a.GetExitPos(), [100, 40], [beamlineAngle2a, 30], 'yellow') bl2a_1 = BeamRectElement( d3.GetExitPos(), [10, 500], beamlineAngle2a + 30, 'grey12') Resolut = DetectorStation(bl2a_1.GetExitPos(), 100, 'RESOLUT', 'Pink') #------------- beam line 2b angle2b = 0 beamlineAngle2b = bfan2.GetExistAbsAngle(angle2b); bl2b = BeamRectElement( bfan2.GetExitPos(angle2b), [10, 500], beamlineAngle2b, 'grey12') q2b = BeamRectElement(bfan2.GetExitPos(angle2b, 200), [60, 60], beamlineAngle2b, 'blue') df2b = BeamRectElement(q2b.GetExitPos(30), [40, 30], beamlineAngle2b, 'orange') Anasen = DetectorStation( bl2b.GetExitPos(), 100, "ANASEN", 'Pink') #------------- beam line 2c angle2c = 40 beamlineAngle2c = bfan2.GetExistAbsAngle(angle2c); bl2c = BeamRectElement( bfan2.GetExitPos(angle2c), [10, 400], beamlineAngle2c, 'grey12') q2c = BeamRectElement(bfan2.GetExitPos(angle2c, 30), [60, 60], beamlineAngle2c, 'blue') df2c = BeamRectElement(q2c.GetExitPos(30), [40, 30], beamlineAngle2c, 'orange') bfan2c = BeamSwitch(bl2c.GetExitPos(), 50, beamlineAngle2c, 'yellow' ) #-------------------- beam line 2c_1 angle2c_1 = -10 beamlineAngle2c_1 = bfan2c.GetExistAbsAngle(angle2c_1); bl2c_1 = BeamRectElement( bfan2c.GetExitPos(angle2c_1), [10, 400], beamlineAngle2c_1, 'grey12') q2c_1 = BeamRectElement(bfan2c.GetExitPos(angle2c_1, 30), [60, 60], beamlineAngle2c_1, 'blue') df2c_1a = BeamRectElement(q2c_1.GetExitPos(30), [40, 30], beamlineAngle2c_1, 'orange') df2c_1b = BeamRectElement(df2c_1a.GetExitPos(30), [40, 30], beamlineAngle2c_1, 'orange') SPS = DetectorStation( bl2c_1.GetExitPos(), 100, "SPS", 'Pink') #-------------------- beam line 2c_2 angle2c_2 = 30 beamlineAngle2c_2 = bfan2c.GetExistAbsAngle(angle2c_2); bl2c_2 = BeamRectElement( bfan2c.GetExitPos(angle2c_2), [10, 400], beamlineAngle2c_2, 'grey12') q2c_2 = BeamRectElement(bfan2c.GetExitPos(angle2c_2, 30), [60, 60], beamlineAngle2c_2, 'blue') df2c_2a = BeamRectElement(q2c_2.GetExitPos(30), [40, 30], beamlineAngle2c_2, 'orange') df2c_2b = BeamRectElement(df2c_2a.GetExitPos(30), [40, 30], beamlineAngle2c_2, 'orange') Clarion2 = DetectorStation( bl2c_2.GetExitPos(), 100, "CLARION-2", 'Pink') #==================== Labels and info label = Label(canvas, text='hahaha') label.place(x = windowSize[0] * 0.9, y = blS.GetExitPos()[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 Catrina.onClick(Event); def update(): label['text'] = "Pressure : "+ str(randint(0, 1000)) + " bar" bl0.Blink() bl1.Blink() bl1a.Blink(); bl1a_1.Blink() bl1b.Blink() bl1c.Blink() bl0a.Blink(); bl3.Blink() bl2a.Blink(); bl2a_1.Blink() bl2b.Blink() bl2c.Blink() bl2c_1.Blink() bl2c_2.Blink() window.after(1000, update) # run itself again after 1000 ms update() window.mainloop()