1 | function varargout = TuneMovePanel(varargin) |
---|
2 | % TUNEMOVEPANEL M-file for TuneMovePanel.fig |
---|
3 | % TUNEMOVEPANEL, by itself, creates a new TUNEMOVEPANEL or raises the existing |
---|
4 | % singleton*. |
---|
5 | % |
---|
6 | % H = TUNEMOVEPANEL returns the handle to a new TUNEMOVEPANEL or the handle to |
---|
7 | % the existing singleton*. |
---|
8 | % |
---|
9 | % TUNEMOVEPANEL('CALLBACK',hObject,eventData,handles,...) calls the local |
---|
10 | % function named CALLBACK in TUNEMOVEPANEL.M with the given input arguments. |
---|
11 | % |
---|
12 | % TUNEMOVEPANEL('Property','Value',...) creates a new TUNEMOVEPANEL or raises the |
---|
13 | % existing singleton*. Starting from the left, property value pairs are |
---|
14 | % applied to the GUI before TuneMovePanel_OpeningFunction gets called. An |
---|
15 | % unrecognized property name or invalid value makes property application |
---|
16 | % stop. All inputs are passed to TuneMovePanel_OpeningFcn via varargin. |
---|
17 | % |
---|
18 | % *See GUI Options on GUIDE's Tools menu. Choose "GUI allows only one |
---|
19 | % instance to run (singleton)". |
---|
20 | % |
---|
21 | % See also: GUIDE, GUIDATA, GUIHANDLES |
---|
22 | |
---|
23 | % Edit the above text to modify the response to help TuneMovePanel |
---|
24 | |
---|
25 | % Last Modified by GUIDE v2.5 05-Aug-2005 17:18:44 |
---|
26 | |
---|
27 | % Begin initialization code - DO NOT EDIT |
---|
28 | gui_Singleton = 1; |
---|
29 | gui_State = struct('gui_Name', mfilename, ... |
---|
30 | 'gui_Singleton', gui_Singleton, ... |
---|
31 | 'gui_OpeningFcn', @TuneMovePanel_OpeningFcn, ... |
---|
32 | 'gui_OutputFcn', @TuneMovePanel_OutputFcn, ... |
---|
33 | 'gui_LayoutFcn', [] , ... |
---|
34 | 'gui_Callback', []); |
---|
35 | if nargin && ischar(varargin{1}) |
---|
36 | gui_State.gui_Callback = str2func(varargin{1}); |
---|
37 | end |
---|
38 | |
---|
39 | if nargout |
---|
40 | [varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:}); |
---|
41 | else |
---|
42 | gui_mainfcn(gui_State, varargin{:}); |
---|
43 | end |
---|
44 | % End initialization code - DO NOT EDIT |
---|
45 | |
---|
46 | % --- Executes just before TuneMovePanel is made visible. |
---|
47 | function TuneMovePanel_OpeningFcn(hObject, eventdata, handles, varargin) |
---|
48 | % This function has no output args, see OutputFcn. |
---|
49 | % hObject handle to figure |
---|
50 | % eventdata reserved - to be defined in a future version of MATLAB |
---|
51 | % handles structure with handles and user data (see GUIDATA) |
---|
52 | % varargin command line arguments to TuneMovePanel (see VARARGIN) |
---|
53 | |
---|
54 | % Choose default command line output for TuneMovePanel |
---|
55 | handles.output = hObject; |
---|
56 | |
---|
57 | % Update handles structure |
---|
58 | display('Launching Tune Move Panel ....'); |
---|
59 | |
---|
60 | theReset(hObject, eventdata, handles) |
---|
61 | |
---|
62 | %tunespaceplot([18 18.5] , [8 8.5], 8, 4, handles.webAxe); |
---|
63 | |
---|
64 | % UIWAIT makes TuneMovePanel wait for user response (see UIRESUME) |
---|
65 | % uiwait(handles.figure1); |
---|
66 | |
---|
67 | |
---|
68 | % --- Outputs from this function are returned to the command line. |
---|
69 | function varargout = TuneMovePanel_OutputFcn(hObject, eventdata, handles) |
---|
70 | % varargout cell array for returning output args (see VARARGOUT); |
---|
71 | % hObject handle to figure |
---|
72 | % eventdata reserved - to be defined in a future version of MATLAB |
---|
73 | % handles structure with handles and user data (see GUIDATA) |
---|
74 | |
---|
75 | % Get default command line output from handles structure |
---|
76 | varargout{1} = handles.output; |
---|
77 | |
---|
78 | |
---|
79 | |
---|
80 | function dqField_Callback(hObject, eventdata, handles) |
---|
81 | % hObject handle to dqField (see GCBO) |
---|
82 | % eventdata reserved - to be defined in a future version of MATLAB |
---|
83 | % handles structure with handles and user data (see GUIDATA) |
---|
84 | |
---|
85 | % Hints: get(hObject,'String') returns contents of dqField as text |
---|
86 | % str2double(get(hObject,'String')) returns contents of dqField as a double |
---|
87 | |
---|
88 | |
---|
89 | % --- Executes during object creation, after setting all properties. |
---|
90 | function dqField_CreateFcn(hObject, eventdata, handles) |
---|
91 | % hObject handle to dqField (see GCBO) |
---|
92 | % eventdata reserved - to be defined in a future version of MATLAB |
---|
93 | % handles empty - handles not created until after all CreateFcns called |
---|
94 | |
---|
95 | % Hint: edit controls usually have a white background on Windows. |
---|
96 | % See ISPC and COMPUTER. |
---|
97 | if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor')) |
---|
98 | set(hObject,'BackgroundColor','white'); |
---|
99 | end |
---|
100 | |
---|
101 | % --- Executes on button press in qyUpButton. |
---|
102 | function qyUpButton_Callback(hObject, eventdata, handles) |
---|
103 | % hObject handle to qyUpButton (see GCBO) |
---|
104 | % eventdata reserved - to be defined in a future version of MATLAB |
---|
105 | % handles structure with handles and user data (see GUIDATA) |
---|
106 | dQx=0; |
---|
107 | dQy=str2double(get(handles.dqField,'string')); |
---|
108 | thesteptune(dQx,dQy); |
---|
109 | UpdatePlot(hObject, handles); |
---|
110 | % --- Executes on button press in qyDownButton. |
---|
111 | function qyDownButton_Callback(hObject, eventdata, handles) |
---|
112 | % hObject handle to qyDownButton (see GCBO) |
---|
113 | % eventdata reserved - to be defined in a future version of MATLAB |
---|
114 | % handles structure with handles and user data (see GUIDATA) |
---|
115 | dQx=0; |
---|
116 | dQy=str2double(get(handles.dqField,'string')); |
---|
117 | thesteptune(dQx,-dQy); |
---|
118 | UpdatePlot(hObject, handles); |
---|
119 | % --- Executes on button press in qxUpButton. |
---|
120 | function qxUpButton_Callback(hObject, eventdata, handles) |
---|
121 | % hObject handle to qxUpButton (see GCBO) |
---|
122 | % eventdata reserved - to be defined in a future version of MATLAB |
---|
123 | % handles structure with handles and user data (see GUIDATA) |
---|
124 | dQx=str2double(get(handles.dqField,'string')); |
---|
125 | dQy=0; |
---|
126 | thesteptune(dQx,dQy); |
---|
127 | UpdatePlot(hObject, handles); |
---|
128 | |
---|
129 | % --- Executes on button press in qxDownButton. |
---|
130 | function qxDownButton_Callback(hObject, eventdata, handles) |
---|
131 | % hObject handle to qxDownButton (see GCBO) |
---|
132 | % eventdata reserved - to be defined in a future version of MATLAB |
---|
133 | % handles structure with handles and user data (see GUIDATA) |
---|
134 | dQx=str2double(get(handles.dqField,'string')); |
---|
135 | dQy=0; |
---|
136 | thesteptune(-dQx,dQy); |
---|
137 | UpdatePlot(hObject, handles); |
---|
138 | |
---|
139 | %% Update the Plots |
---|
140 | |
---|
141 | function UpdatePlot(hObject, handles) |
---|
142 | |
---|
143 | global THERING; |
---|
144 | handles.THERING = THERING; |
---|
145 | [TD, tune, chrom] = twissring(handles.THERING,0,1:handles.L+1,'chrom', 1e-8); |
---|
146 | BETA = cat(1,TD.beta); |
---|
147 | S = cat(1,TD.SPos); |
---|
148 | Disp =cat(2,TD.Dispersion); |
---|
149 | |
---|
150 | |
---|
151 | set(handles.betax,'YData',BETA(:,1)); |
---|
152 | set(handles.qxText,'String',num2str(tune(1))); |
---|
153 | |
---|
154 | set(handles.betay,'YData',BETA(:,2)); |
---|
155 | set(handles.qyText,'String',num2str(tune(2))); |
---|
156 | |
---|
157 | set(handles.dx, 'YData', 10*Disp(1,:)'); |
---|
158 | |
---|
159 | delete(handles.QDot); |
---|
160 | |
---|
161 | handles.Qx = tune(1); |
---|
162 | handles.Qy = tune(2); |
---|
163 | handles.QDot = line('parent',handles.webAxe,'XData',handles.Qx,'YData',handles.Qy,'Marker','+','MarkerSize',12.0); |
---|
164 | |
---|
165 | [name, val] = quad_getsetpoint; |
---|
166 | |
---|
167 | %handles.figure1; |
---|
168 | quad_table('title', name, val, [0.1 0.45 0.2 0.325]); |
---|
169 | set(handles.cxText,'String',num2str(chrom(1))); |
---|
170 | set(handles.cyText,'String',num2str(chrom(2))); |
---|
171 | if handles.emitCalc |
---|
172 | e=getemit(TD); |
---|
173 | set(handles.emitText,'String',num2str(e(1))); |
---|
174 | else |
---|
175 | set(handles.emitText,'String','No Calc'); |
---|
176 | end |
---|
177 | guidata(hObject,handles); |
---|
178 | |
---|
179 | |
---|
180 | % --- Executes on button press in summaryButton. |
---|
181 | function summaryButton_Callback(hObject, eventdata, handles) |
---|
182 | % hObject handle to summaryButton (see GCBO) |
---|
183 | % eventdata reserved - to be defined in a future version of MATLAB |
---|
184 | % handles structure with handles and user data (see GUIDATA) |
---|
185 | |
---|
186 | |
---|
187 | % --- Executes on button press in emitCheckBox. |
---|
188 | function emitCheckBox_Callback(hObject, eventdata, handles) |
---|
189 | % hObject handle to emitCheckBox (see GCBO) |
---|
190 | % eventdata reserved - to be defined in a future version of MATLAB |
---|
191 | % handles structure with handles and user data (see GUIDATA) |
---|
192 | |
---|
193 | % Hint: get(hObject,'Value') returns toggle state of emitCheckBox |
---|
194 | if (get(hObject,'Value') == get(hObject,'Max')) |
---|
195 | % then checkbox is checked-take approriate action |
---|
196 | handles.emitCalc=true; |
---|
197 | else |
---|
198 | % checkbox is not checked-take approriate action |
---|
199 | handles.emitCalc=false; |
---|
200 | end |
---|
201 | guidata(hObject,handles); |
---|
202 | |
---|
203 | function thesteptune(dqx, dqy) |
---|
204 | %ALBAsteptune(dqx, dqy); |
---|
205 | % original was |
---|
206 | steptune([dqx dqy],'Model'); % Laurent |
---|
207 | |
---|
208 | |
---|
209 | % -------------------------------------------------------------------- |
---|
210 | function optionsMeno_Callback(hObject, eventdata, handles) |
---|
211 | % hObject handle to optionsMeno (see GCBO) |
---|
212 | % eventdata reserved - to be defined in a future version of MATLAB |
---|
213 | % handles structure with handles and user data (see GUIDATA) |
---|
214 | |
---|
215 | |
---|
216 | % -------------------------------------------------------------------- |
---|
217 | function panelResetMenu_Callback(hObject, eventdata, handles) |
---|
218 | % hObject handle to panelResetMenu (see GCBO) |
---|
219 | % eventdata reserved - to be defined in a future version of MATLAB |
---|
220 | % handles structure with handles and user data (see GUIDATA) |
---|
221 | delete(handles.QDot); |
---|
222 | delete(handles.betax); |
---|
223 | delete(handles.betay); |
---|
224 | delete(handles.dx); |
---|
225 | theReset (hObject, eventdata, handles) |
---|
226 | |
---|
227 | % Local reset function |
---|
228 | function theReset(hObject, eventdata, handles) |
---|
229 | global THERING |
---|
230 | |
---|
231 | handles.L = length(THERING); |
---|
232 | [TD, tune] = twissring(THERING,0,1:handles.L+1); |
---|
233 | handles.spos = findspos(THERING,1:handles.L+1); |
---|
234 | handles.THERING = THERING; |
---|
235 | handles.betax = line('parent',handles.betaAxe,'XData',handles.spos,'YData',0*handles.spos,'Color','r'); |
---|
236 | handles.betay = line('parent',handles.betaAxe,'XData',handles.spos,'YData',0.*handles.spos,'Color','b'); |
---|
237 | handles.dx = line('parent',handles.betaAxe,'XData',handles.spos,'YData',0.*handles.spos,'Color','g'); |
---|
238 | |
---|
239 | guidata(hObject,handles); |
---|
240 | |
---|
241 | drawlattice_local(handles, -1, 1); |
---|
242 | |
---|
243 | xlabel(handles.betaAxe,'s - position [m]'); |
---|
244 | ylabel(handles.betaAxe,'\beta [m]'); |
---|
245 | xaxis([0 handles.spos(handles.L+1)/4], handles.betaAxe); |
---|
246 | |
---|
247 | |
---|
248 | handles.Qx = tune(1); |
---|
249 | handles.Qy = tune(2); |
---|
250 | handles.emitCalc = true; |
---|
251 | handles.QDot = line('parent',handles.webAxe,'XData',handles.Qx,'YData',handles.Qy,'Marker','+'); |
---|
252 | UpdatePlot(hObject, handles); |
---|
253 | |
---|
254 | |
---|
255 | % resonance diagramme |
---|
256 | handles.webAxe; |
---|
257 | max_order= 5; |
---|
258 | per = 4; |
---|
259 | |
---|
260 | window = [tune(1)-0.255 tune(1)+0.255 tune(2)-0.255 tune(2)+0.255]; |
---|
261 | |
---|
262 | for i = max_order:-1:1, |
---|
263 | [k, tab] = reson(i,per,window); |
---|
264 | end |
---|
265 | |
---|
266 | axis(window); |
---|
267 | |
---|
268 | handles.betaAxe; |
---|
269 | set(handles.emitCheckBox, 'Value',1); |
---|
270 | |
---|
271 | |
---|
272 | function drawlattice_local(hParent, Offset, Scaling) |
---|
273 | %DRAWLATTICE - Draws the AT lattice to a figure |
---|
274 | % drawlattice(Offset, Scaling) |
---|
275 | % |
---|
276 | |
---|
277 | if nargin < 2 |
---|
278 | Offset = 0; |
---|
279 | end |
---|
280 | Offset = Offset(1); |
---|
281 | if nargin < 3 |
---|
282 | Scaling = 1; |
---|
283 | end |
---|
284 | Scaling = Scaling(1); |
---|
285 | |
---|
286 | global THERING |
---|
287 | |
---|
288 | SPositions = findspos(THERING, 1:length(THERING)+1); |
---|
289 | L = SPositions(end); |
---|
290 | line('parent',hParent.betaAxe,'XData',[0 L],'YData',[0 0]+Offset,'Color','k'); |
---|
291 | |
---|
292 | % Remember the hold state then turn hold on |
---|
293 | HoldState = ishold; |
---|
294 | hold on; |
---|
295 | |
---|
296 | % Make default icons for elements of different physical types |
---|
297 | for i = 1:length(THERING) |
---|
298 | SPos = SPositions(i); |
---|
299 | if isfield(THERING{i},'BendingAngle') & THERING{i}.BendingAngle |
---|
300 | % make icons for bending magnets |
---|
301 | IconHeight = .3; |
---|
302 | IconColor = [1 1 0]; |
---|
303 | IconWidth = THERING{i}.Length; |
---|
304 | if IconWidth < .15 % meters |
---|
305 | IconWidth = .15; |
---|
306 | SPos = SPos - IconWidth/2 + THERING{i}.Length/2; |
---|
307 | end |
---|
308 | vx = [SPos SPos+IconWidth SPos+IconWidth SPos]; |
---|
309 | vy = [IconHeight IconHeight -IconHeight -IconHeight]; |
---|
310 | h = patch(vx, Scaling*vy+Offset, IconColor,'LineStyle','-','parent',hParent.betaAxe); |
---|
311 | %if IconWidth < .1 % meters |
---|
312 | % set(h, 'EdgeColor', IconColor); |
---|
313 | %end |
---|
314 | |
---|
315 | elseif isfield(THERING{i},'K') & THERING{i}.K |
---|
316 | % Quadrupole |
---|
317 | if THERING{i}.K > 0 |
---|
318 | % Focusing quadrupole |
---|
319 | IconHeight = .6; |
---|
320 | IconColor = [1 0 0]; |
---|
321 | IconWidth = THERING{i}.Length; |
---|
322 | if IconWidth < .15 % meters |
---|
323 | IconWidth = .15; |
---|
324 | SPos = SPos - IconWidth/2 + THERING{i}.Length/2; |
---|
325 | end |
---|
326 | vx = [SPos SPos+IconWidth/2 SPos+IconWidth SPos+IconWidth/2 SPos]; |
---|
327 | vy = [0 IconHeight 0 -IconHeight 0]; |
---|
328 | else |
---|
329 | % Defocusing quadrupole |
---|
330 | IconHeight = .6; |
---|
331 | IconColor = [0 0 1]; |
---|
332 | IconWidth = THERING{i}.Length; |
---|
333 | if IconWidth < .15 % meters |
---|
334 | IconWidth = .15; |
---|
335 | SPos = SPos - IconWidth/2 + THERING{i}.Length/2; |
---|
336 | end |
---|
337 | vx = [SPos+.4*IconWidth SPos SPos+IconWidth SPos+.6*IconWidth SPos+IconWidth SPos SPos+.4*IconWidth]; |
---|
338 | vy = [ 0 IconHeight IconHeight 0 -IconHeight -IconHeight 0]; |
---|
339 | end |
---|
340 | h = patch(vx, Scaling*vy+Offset, IconColor,'LineStyle','-','Parent',hParent.betaAxe); |
---|
341 | %if IconWidth < .1 % meters |
---|
342 | % set(h, 'EdgeColor', IconColor); |
---|
343 | %end |
---|
344 | |
---|
345 | elseif isfield(THERING{i},'PolynomB') & length(THERING{i}.PolynomB)>2 & THERING{i}.PolynomB(3) |
---|
346 | % Sextupole |
---|
347 | if THERING{i}.PolynomB(3)>0 |
---|
348 | % Focusing sextupole |
---|
349 | IconHeight = .5; |
---|
350 | IconColor = [1 0 1]; |
---|
351 | IconWidth = THERING{i}.Length; |
---|
352 | if IconWidth < .1 % meters |
---|
353 | IconWidth = .1; |
---|
354 | SPos = SPos - IconWidth/2 + THERING{i}.Length/2; |
---|
355 | end |
---|
356 | vx = [SPos SPos+.33*IconWidth SPos+.66*IconWidth SPos+IconWidth SPos+IconWidth SPos+.66*IconWidth SPos+.33*IconWidth SPos SPos]; |
---|
357 | vy = [IconHeight/3 IconHeight IconHeight IconHeight/3 -IconHeight/3 -IconHeight -IconHeight -IconHeight/3 IconHeight/3]; |
---|
358 | else |
---|
359 | % Defocusing sextupole |
---|
360 | IconHeight = .5; |
---|
361 | IconColor = [0 1 0]; |
---|
362 | IconWidth = THERING{i}.Length; |
---|
363 | if IconWidth < .1 % meters |
---|
364 | IconWidth = .1; |
---|
365 | SPos = SPos - IconWidth/2 + THERING{i}.Length/2; |
---|
366 | end |
---|
367 | vx = [SPos SPos+.33*IconWidth SPos+.66*IconWidth SPos+IconWidth SPos+IconWidth SPos+.66*IconWidth SPos+.33*IconWidth SPos SPos]; |
---|
368 | vy = [IconHeight/3 IconHeight IconHeight IconHeight/3 -IconHeight/3 -IconHeight -IconHeight -IconHeight/3 IconHeight/3]; |
---|
369 | end |
---|
370 | h = patch(vx, Scaling*vy+Offset, IconColor,'LineStyle','-'); |
---|
371 | %if IconWidth < .1 % meters |
---|
372 | % set(h, 'EdgeColor', IconColor); |
---|
373 | %end |
---|
374 | |
---|
375 | elseif isfield(THERING{i},'Frequency') & isfield(THERING{i},'Voltage') |
---|
376 | % RF cavity |
---|
377 | IconColor = [1 0.5 0]; |
---|
378 | plot(SPos, 0+Offset, 'o', 'MarkerFaceColor', IconColor, 'Color', IconColor, 'MarkerSize', 4) |
---|
379 | |
---|
380 | elseif strcmpi(THERING{i}.FamName,'BPM') |
---|
381 | % BPM |
---|
382 | IconColor = 'k'; |
---|
383 | plot(SPos, 0+Offset, '.-', 'Color', IconColor) |
---|
384 | %plot(SPos, 0, 'o', 'MarkerFaceColor', IconColor, 'Color', IconColor, 'MarkerSize', 1.5) |
---|
385 | |
---|
386 | elseif any(strcmpi(THERING{i}.FamName,{'COR','XCOR','YCOR','HCOR','VCOR'})) | isfield(THERING{i},'KickAngle') |
---|
387 | % Corrector |
---|
388 | IconHeight = .8; |
---|
389 | IconColor = [0 0 0]; |
---|
390 | vx = [SPos SPos]; |
---|
391 | vy = [-IconHeight IconHeight]; |
---|
392 | %plot(vx, Scaling*vy+Offset, 'Color', IconColor); |
---|
393 | IconWidth = THERING{i}.Length; |
---|
394 | vx = [SPos SPos+IconWidth SPos+IconWidth SPos]; |
---|
395 | vy = [IconHeight IconHeight -IconHeight -IconHeight]; |
---|
396 | h = patch(vx, Scaling*vy+Offset, IconColor,'LineStyle', '-','parent',hParent.betaAxe); |
---|
397 | if IconWidth < .1 % meters |
---|
398 | set(h, 'EdgeColor', IconColor); |
---|
399 | end |
---|
400 | end |
---|
401 | end |
---|
402 | |
---|
403 | |
---|
404 | % Leave the hold state as it was at the start |
---|
405 | if ~HoldState |
---|
406 | hold off |
---|
407 | end |
---|
408 | %yaxis([-3 3]); |
---|