source: MML/trunk/machine/SOLEIL/common/drawlattice.m @ 17

Last change on this file since 17 was 17, checked in by zhangj, 10 years ago

To have a stable version on the server.

  • Property svn:executable set to *
File size: 8.9 KB
Line 
1function drawlattice(Offset, Scaling, hAxes)
2%DRAWLATTICE - Draws the AT lattice to a figure
3%  drawlattice(Offset {0}, Scaling {1}, hAxes {gca})
4%
5%  Programmers Note: The AT index is stored in the Userdata of each symbol.
6
7%
8%  Written by Greg Portmann
9%  Adapted for SOLEIL, Laurent S. Nadolski
10
11global THERING
12
13
14% Minimum icon width in meters
15MinIconWidth = .2;
16
17if nargin < 1
18    Offset = 0;
19end
20Offset = Offset(1);
21if nargin < 2
22    Scaling = 1;
23end
24Scaling = Scaling(1);
25
26if nargin < 3
27    hAxes = gca;
28end
29
30SPositions = findspos(THERING, 1:length(THERING)+1);
31L = SPositions(end);
32plot(hAxes, [0 L], [0 0]+Offset, 'k');
33
34% Remember the hold state then turn hold on
35HoldState = ishold(hAxes);
36hold(hAxes, 'on');
37
38
39ATIndexHCM = family2atindex(gethcmfamily);
40ATIndexVCM = family2atindex(getvcmfamily);
41
42
43% Make default icons for elements of different physical types
44for i = 1:length(THERING)
45    NumberOfFinds = 0;
46   
47    SPos = SPositions(i);
48    if isfield(THERING{i},'BendingAngle') && THERING{i}.BendingAngle
49        % make icons for bending magnets
50        NumberOfFinds = NumberOfFinds + 1;
51        IconHeight = .3;
52        IconColor = [1 0 0];
53        IconWidth = THERING{i}.Length;
54        if IconWidth < MinIconWidth % meters
55            IconWidth = MinIconWidth;
56            SPos = SPos - IconWidth/2 + THERING{i}.Length/2;
57        end
58        vx = [SPos SPos+IconWidth SPos+IconWidth SPos];
59        vy = [IconHeight IconHeight -IconHeight -IconHeight];
60        h = patch(vx, Scaling*vy+Offset, IconColor,'LineStyle','-', 'Parent',hAxes);
61        set(h, 'UserData', i);
62
63        %if IconWidth < .1 % meters
64        %    set(h, 'EdgeColor', IconColor);
65        %end
66
67    elseif isfield(THERING{i},'K') && THERING{i}.K
68        % Quadrupole
69        NumberOfFinds = NumberOfFinds + 1;
70       if THERING{i}.K >= 0
71            % Focusing quadrupole           
72            IconHeight = .8;
73            IconColor = [0 0 1];
74            IconWidth = THERING{i}.Length;
75            if IconWidth < MinIconWidth % meters
76                IconWidth = MinIconWidth;
77                SPos = SPos - IconWidth/2 + THERING{i}.Length/2;
78            end
79            vx = [SPos SPos+IconWidth/2  SPos+IconWidth SPos+IconWidth/2 SPos];
80            vy = [0          IconHeight               0      -IconHeight    0];
81        else
82            % Defocusing quadrupole
83            IconHeight = .7;
84            IconColor = [0 0 1];
85            IconWidth = THERING{i}.Length;
86            if IconWidth < MinIconWidth % meters
87                % Center about starting point
88                IconWidth = MinIconWidth;
89                SPos = SPos - IconWidth/2 + THERING{i}.Length/2;
90            end
91            vx = [SPos+.4*IconWidth    SPos    SPos+IconWidth  SPos+.6*IconWidth  SPos+IconWidth    SPos      SPos+.4*IconWidth];
92            vy = [     0            IconHeight   IconHeight          0              -IconHeight  -IconHeight    0];
93        end
94        h = patch(vx, Scaling*vy+Offset, IconColor,'LineStyle','-', 'Parent',hAxes);
95        set(h, 'UserData', i);
96        %if IconWidth < .1 % meters
97        %    set(h, 'EdgeColor', IconColor);
98        %end
99
100    elseif isfield(THERING{i},'PolynomB') && length(THERING{i}.PolynomB)>2 && (THERING{i}.PolynomB(3) || any(strcmpi(THERING{i}.FamName,{'SF','SFF','SD','SDD'})))
101        % Sextupole
102        NumberOfFinds = NumberOfFinds + 1;
103        if THERING{i}.PolynomB(3)>0 || any(strcmpi(THERING{i}.FamName,{'SF','SFF'}))
104            % Focusing sextupole
105            IconHeight = .6;
106            IconColor = [1 1 0];
107            IconWidth = THERING{i}.Length;
108            if IconWidth < MinIconWidth % meters
109                IconWidth = MinIconWidth;
110                SPos = SPos - IconWidth/2 + THERING{i}.Length/2;
111            end
112            vx = [SPos          SPos+.25*IconWidth  SPos+.75*IconWidth  SPos+IconWidth   SPos+IconWidth   SPos+.75*IconWidth  SPos+.25*IconWidth      SPos          SPos];
113            vy = [IconHeight/3      IconHeight          IconHeight        IconHeight/3    -IconHeight/3      -IconHeight          -IconHeight     -IconHeight/3  IconHeight/3];
114        else
115            % Defocusing sextupole
116            IconHeight = .6;
117            IconColor = [1 1 0];
118            IconWidth = THERING{i}.Length;
119            if IconWidth < MinIconWidth % meters
120                IconWidth = MinIconWidth;
121                SPos = SPos - IconWidth/2 + THERING{i}.Length/2;
122            end
123            vx = [SPos+.25*IconWidth   SPos             SPos+IconWidth    SPos+0.75*IconWidth   SPos+0.75*IconWidth   SPos+IconWidth  SPos      SPos+.25*IconWidth          SPos+.25*IconWidth];
124            vy = [IconHeight/3        IconHeight          IconHeight        IconHeight/3         -IconHeight/3      -IconHeight          -IconHeight     -IconHeight/3  IconHeight/3];
125        end
126        h = patch(vx, Scaling*vy+Offset, IconColor,'LineStyle','-', 'Parent',hAxes);
127        set(h, 'UserData', i);
128        %if IconWidth < .1 % meters
129        %    set(h, 'EdgeColor', IconColor);
130        %end
131
132    elseif isfield(THERING{i},'Frequency') && isfield(THERING{i},'Voltage')
133        % RF cavity
134        NumberOfFinds = NumberOfFinds + 1;
135        IconColor = [1 0.5 0];
136        h = plot(hAxes, SPos, 0+Offset, 'o', 'MarkerFaceColor', IconColor, 'Color', IconColor, 'MarkerSize', 4);
137        set(h, 'UserData', i);
138
139    elseif strcmpi(THERING{i}.FamName,'BPM')
140        % BPM
141        NumberOfFinds = NumberOfFinds + 1;
142        IconColor = 'k';
143        h = plot(hAxes, SPos, 0+Offset, '.', 'Color', IconColor);
144        %h = plot(hAxes, SPos, 0, 'o', 'MarkerFaceColor', IconColor, 'Color', IconColor, 'MarkerSize', 1.5)
145        set(h, 'UserData', i);
146       
147    elseif strcmpi(THERING{i}.FamName,'TV')
148        % TV screen
149        NumberOfFinds = NumberOfFinds + 1;
150        IconHeight = .7;
151        IconColor = [.5 0 0];  %'k';
152        %h = plot(hAxes, SPos, 0+Offset, 'x', 'Color', IconColor);
153        h = plot(hAxes, SPos, Scaling*IconHeight+Offset, 'Marker','Square', 'MarkerFaceColor', IconColor, 'Color', IconColor, 'MarkerSize', 3.5);
154        set(h, 'UserData', i);
155    end
156   
157    % Since correctors could be a combined function magnet, test separately
158    if any(strcmpi(THERING{i}.FamName,{'COR','XCOR','YCOR','HCOR','VCOR'})) || isfield(THERING{i},'KickAngle')
159        % Corrector
160        NumberOfFinds = NumberOfFinds + 1;
161       
162        if NumberOfFinds > 1
163            IconWidth = 0;
164        else
165            IconWidth = THERING{i}.Length;
166        end
167        IconHeight = 1.0;  % was .8
168        vx = [SPos   SPos];
169
170        % Draw a line above for a HCM and below for a VCM
171        % If it's not in the ML, then draw a line above and below
172        CMFound = 1;
173        if any(i == ATIndexVCM)
174            IconColor = [0 0 0];
175            vy = [-IconHeight 0];
176            if IconWidth < MinIconWidth
177                h = plot(hAxes, vx, Scaling*vy+Offset, 'Color', IconColor);
178            else
179                IconWidth = THERING{i}.Length;
180                vx = [SPos SPos+IconWidth SPos+IconWidth SPos];
181                vy = [0 0 -IconHeight -IconHeight];
182                %vy = [IconHeight IconHeight -IconHeight -IconHeight];
183                h = patch(vx, Scaling*vy+Offset, IconColor, 'LineStyle', '-', 'Parent',hAxes);
184                if IconWidth < MinIconWidth*2 % meters
185                    set(h, 'EdgeColor', IconColor);
186                end
187            end
188            set(h, 'UserData', i);
189            CMFound = 0;
190        end
191
192        if any(i == ATIndexHCM)
193            IconColor = [0 0 0];
194            vy = [0 IconHeight];
195            if IconWidth < MinIconWidth
196                h = plot(hAxes, vx, Scaling*vy+Offset, 'Color', IconColor);
197            else
198                IconWidth = THERING{i}.Length;
199                vx = [SPos SPos+IconWidth SPos+IconWidth SPos];
200                vy = [IconHeight IconHeight 0 0];
201                %vy = [IconHeight IconHeight -IconHeight -IconHeight];
202                h = patch(vx, Scaling*vy+Offset, IconColor, 'LineStyle', '-', 'Parent',hAxes);
203                if IconWidth < MinIconWidth*2 % meters
204                    set(h, 'EdgeColor', IconColor);
205                end
206            end
207            set(h, 'UserData', i);
208            CMFound = 0;
209        end
210       
211        if CMFound
212            IconColor = [0 0 0];
213            vy = [-IconHeight IconHeight];
214            if IconWidth < MinIconWidth
215                h = plot(hAxes, vx, Scaling*vy+Offset, 'Color', IconColor);
216            else
217                IconWidth = THERING{i}.Length;
218                vx = [SPos SPos+IconWidth SPos+IconWidth SPos];
219                vy = [IconHeight IconHeight -IconHeight -IconHeight];
220                h = patch(vx, Scaling*vy+Offset, IconColor, 'LineStyle', '-', 'Parent',hAxes);
221                if IconWidth < MinIconWidth*2 % meters
222                    set(h, 'EdgeColor', IconColor);
223                end
224            end
225            set(h, 'UserData', i);
226            CMFound = 0;
227        end
228
229    end
230end
231
232
233% Leave the hold state as it was at the start
234if ~HoldState
235    hold(hAxes, 'off');
236end
237
238a = axis(hAxes);
239axis(hAxes, [0 L a(3:4)]);
240
Note: See TracBrowser for help on using the repository browser.