1 | function UpdateIcons(SYS, BPM) |
---|
2 | |
---|
3 | %update icons in display bar |
---|
4 | ElementIcons=getappdata(0,'ElementIcons'); |
---|
5 | |
---|
6 | %define number of icons to display |
---|
7 | num=size(SYS.elhndl,1)/2; %defined as x2 in elementiconinit |
---|
8 | nicon=2*num; |
---|
9 | len=length(SYS.elemind); |
---|
10 | |
---|
11 | %get BPM index in the AT lattice |
---|
12 | if SYS.plane==1 |
---|
13 | indx=BPM(1).ATindex(BPM(1).id); |
---|
14 | elseif SYS.plane==2 |
---|
15 | indx=family2atindex('BPMy',BPM(2).id); |
---|
16 | end |
---|
17 | |
---|
18 | %locate where BPM is in drift-free list of elements |
---|
19 | indx=find(SYS.elemind==indx); |
---|
20 | |
---|
21 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
---|
22 | %if BPM index closer to 'num' from beginning, set it to 'num+1' |
---|
23 | if indx-num<0 |
---|
24 | indx=num+1; |
---|
25 | end |
---|
26 | |
---|
27 | %if BPM index closer to 'num' from end, set it to 'len-num' |
---|
28 | if indx+num>len |
---|
29 | indx=len-num+1; |
---|
30 | end |
---|
31 | |
---|
32 | for ii=1:nicon |
---|
33 | xpos=(ii-0.5)/(nicon+1); %...SYS.ahpos has x limits 0 to 1 |
---|
34 | ind=SYS.elemind(indx+ii-(num+1)); %...back up from BPM index |
---|
35 | set(SYS.elhndl(ii), 'XData', xpos+ElementIcons{ind}.xpts,... |
---|
36 | 'YData', ElementIcons{ind}.ypts,... |
---|
37 | 'FaceColor', ElementIcons{ind}.color,... |
---|
38 | 'UserData',ind); %Userdata stores element index in THERING |
---|
39 | end |
---|
40 | |
---|
41 | % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
---|
42 | % % %if BPM index closer to 'num' from beginning, set it to 'num+1' |
---|
43 | % % if indx-num<0 |
---|
44 | % % indx=num+1; |
---|
45 | % % end |
---|
46 | % % |
---|
47 | % % %if BPM index closer to 'num' from end, set it to 'len-num' |
---|
48 | % % if indx+num>len |
---|
49 | % % indx=len-num+1; |
---|
50 | % % end |
---|
51 | % % |
---|
52 | % % for ii=1:nicon |
---|
53 | % % xpos=(ii-0.5)/(nicon+1); %...SYS.ahpos has x limits 0 to 1 |
---|
54 | % % ind=indx+ii-(num+1); %...back up from BPM index |
---|
55 | % % set(SYS.elhndl(ii), 'XData', xpos+THERING{ind}.xpts,... |
---|
56 | % % 'YData', THERING{ind}.ypts,... |
---|
57 | % % 'FaceColor', THERING{ind}.color,... |
---|
58 | % % 'UserData',ind); %Userdata stores element index in THERING |
---|
59 | % % end |
---|
60 | % % % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
---|
61 | % % % %alternative method that does not show drift sections |
---|
62 | % % % %indx=BPM index |
---|
63 | % % % %num=number of elements to display |
---|
64 | % % % |
---|
65 | % % % ibehind=zeros(num,1); %pre-allocate |
---|
66 | % % % iahead=zeros(num,1); |
---|
67 | % % % |
---|
68 | % % % %==================================== |
---|
69 | % % % %locate non-drift elements behind BPM |
---|
70 | % % % %==================================== |
---|
71 | % % % %look behind, stop if encounter beginning of ring |
---|
72 | % % % jj=0; ii=indx; |
---|
73 | % % % while jj<=num-1 && ii>1 |
---|
74 | % % % ii=ii-1; |
---|
75 | % % % if ~strcmp(THERING{ii}.PassMethod,'DriftPass'); |
---|
76 | % % % jj=jj+1; |
---|
77 | % % % ibehind(jj)=ii; |
---|
78 | % % % end |
---|
79 | % % % end |
---|
80 | % % % ibehind=flipud(ibehind(find(ibehind))); |
---|
81 | % % % |
---|
82 | % % % %enlarge range ahead if needed |
---|
83 | % % % if length(ibehind)<num-1 |
---|
84 | % % % num=2*num-length(ibehind); |
---|
85 | % % % end |
---|
86 | % % % |
---|
87 | % % % %====================================== |
---|
88 | % % % %locate non-drift elements ahead of BPM |
---|
89 | % % % %====================================== |
---|
90 | % % % jj=0; ii=indx; |
---|
91 | % % % while jj<=num-2 && ii<len %take one less ahead of BPM so BPM can be in handle array |
---|
92 | % % % ii=ii+1; |
---|
93 | % % % if ~strcmp(THERING{ii}.PassMethod,'DriftPass'); |
---|
94 | % % % jj=jj+1; |
---|
95 | % % % iahead(jj)=ii; |
---|
96 | % % % end |
---|
97 | % % % end |
---|
98 | % % % iahead=iahead(find(iahead)); |
---|
99 | % % % |
---|
100 | % % % %enlarge range behind if needed |
---|
101 | % % % if length(iahead)<num-1 |
---|
102 | % % % num=2*num-length(iahead); |
---|
103 | % % % |
---|
104 | % % % jj=0; ii=indx; ibehind=[]; |
---|
105 | % % % while jj<=num-2 && ii>1 |
---|
106 | % % % ii=ii-1; |
---|
107 | % % % if ~strcmp(THERING{ii}.PassMethod,'DriftPass'); |
---|
108 | % % % jj=jj+1; |
---|
109 | % % % ibehind(jj)=ii; |
---|
110 | % % % end |
---|
111 | % % % end |
---|
112 | % % % ibehind=flipud(ibehind(find(ibehind))); |
---|
113 | % % % end |
---|
114 | % % % |
---|
115 | % % % elem=[ibehind(:); indx; iahead(:)]; |
---|
116 | % % % |
---|
117 | % % % for ii=1:length(elem) |
---|
118 | % % % xpos=(ii-0.5)/(nicon+1); %...SYS.ahpos has x limits 0 to 1 |
---|
119 | % % % ind=elem(ii) ; %...behind BPM index |
---|
120 | % % % set(SYS.elhndl(ii), 'XData', xpos+THERING{ind}.xpts,... |
---|
121 | % % % 'YData', THERING{ind}.ypts,... |
---|
122 | % % % 'FaceColor', THERING{ind}.color,... |
---|
123 | % % % 'UserData',ind); %Userdata stores element index in THERING |
---|
124 | % % % end |
---|
125 | |
---|
126 | |
---|