From 09dc1104c19615b7a9eda10e6b48487474758d6c Mon Sep 17 00:00:00 2001 From: SysAdmin Date: Fri, 9 Sep 2022 15:42:22 -0400 Subject: [PATCH] kind of complete the beam line, need to add functions --- dashboard.py | 327 ++++++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 283 insertions(+), 44 deletions(-) diff --git a/dashboard.py b/dashboard.py index 3e4f037..c28a3a0 100755 --- a/dashboard.py +++ b/dashboard.py @@ -5,8 +5,9 @@ import math from random import randint import numpy as np -#class Room(): -# def __init__(self, points, Color) +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): @@ -15,11 +16,13 @@ class DipoleMagnet(): 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.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], extent = Angle[1], fill = 'black', outline = 'black') + 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[1] + 90 )), -downstream * math.sin(math.radians(self.Angle[1] + 90 )) ]) + 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(): @@ -34,6 +37,7 @@ class Tandem(): 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)) ] @@ -50,8 +54,29 @@ class BeamRectElement(): canvas.itemconfig(self.beamPipe, fill = Color) def GetColor(self): return self.Color - -class Beam90DegreeFan(): + def Deactivate(self): + self.Active = False + self.Color = 'grey10' + canvas.itemconfig(self.beamPipe, fill = 'grey10') + def Activate(self): + 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 @@ -60,23 +85,161 @@ class Beam90DegreeFan(): 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 + 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 Station(): +class DetectorStation(): def __init__(self, Center, Size, Name, Color): + self.Name = Name 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.Detector = 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") + + canvas.tag_bind(self.Detector, '<1>', self.onClick) + self.label.bind('<1>', self.onClick) + + def SetColor(Color): + canvas.itemconfig(self.Detector, fill = Color) + self.label.config(bg = Color) + + def onClick(self, event): + global ActiveBeamLine + ActiveBeamLine = self.Name + print("========== ", ActiveBeamLine) + return self.Name + + def GetName(self): + return self.Name + + +def SetActiveBeamLine( ): + global ActiveBeamLine + if ActiveBeamLine == "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() + + if ActiveBeamLine == "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() + + if ActiveBeamLine == "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() + + if ActiveBeamLine == "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() + + if ActiveBeamLine == "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() + + if ActiveBeamLine == "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() ############################## Start GUI -windowSize = [3840, 1500]# 4K upper half +windowSize = [3840, 1500]# 4K width +#windowSize = [3840, 2160]# 4K 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) @@ -85,20 +248,32 @@ 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.95], [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') -tandemStart = [windowSize[0] * 0.9, windowSize[1] * 0.8] # beam entry pos tandemSize = [100, 300] # width, height -tandem = Tandem(tandemStart, tandemSize, 'Green') +tandem = Tandem(blS.GetExitPos(), tandemSize, 'Green') bl0 = BeamRectElement( tandem.GetExitPos() , [10, 300], 0, 'white') @@ -108,18 +283,17 @@ 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') +bfan1 = BeamSwitch(bl1.GetExitPos(), 50, 90, 'Yellow') #-------- upper beam line -angle_a = 30 -beamline1Angle_a = bfan1.GetExitAngle(angle_a) +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') @@ -127,20 +301,20 @@ 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') +#.......... Gamma DetectorStation +GammaStation = DetectorStation(bl1a.GetExitPos(), 100, "Gamma\nStation", 'Pink4') #.......... Catrina -Catrina = Station(bl1a_1.GetExitPos(), 100, "Catrina", 'Pink') +Catrina = DetectorStation(bl1a_1.GetExitPos(), 100, "CATRiNA", 'Pink') #---------middle beam line -angle_b = 50 -beamline1Angle_b = bfan1.GetExitAngle(angle_b) +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 = 70 -beamline1Angle_c = bfan1.GetExitAngle(angle_c) +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') @@ -149,24 +323,96 @@ 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 = tandemStart[1] - 100) +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')) @@ -181,19 +427,12 @@ exit_button.place(x = windowSize[0] - 200, y = 50) ###################### Beam line activation +global ActiveBeamLine +ActiveBeamLine = Catrina.GetName() + 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') - + SetActiveBeamLine() window.after(1000, update) # run itself again after 1000 ms update()