source: MML/trunk/at/atgui/intelem.m @ 4

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

Initial import--MML version from SOLEIL@2013

File size: 5.5 KB
Line 
1function h0 = intelem(varargin)
2
3%INTELEM - interactive element editor.
4%       
5%       INTELEM(INDEX) retrieves THERING{INDEX} from the
6%               main workspace and displays the values of all fields for that element
7%               Fields that are 1xN vectors or MxN matrixies
8%               such as multipole field data stored in 'PolynomA' are displayed
9%               in M raws and N columns, each element in a separate text box.
10%
11%       INTELEM(INDEX, Fields2Display)
12%               Some element models/definitions contain large number of
13%               parameters. It may be desired to interactively control only few of them
14%               A cell array of strings Fields2Display allows to select which
15%               element parameters are included in the GUI.
16%               When Fields2Display contains a field name that does not exist for
17%               an elemet no error is generated ,that field is ignored.
18%     For example
19%                       Fields2Display = {'FamName' 'Length' 'K' 'BendingAngle'} 
20%                       INELEM displays 'FamName' and 'Length' when called for a drift
21%                       'FamName','Length','K' when called for a quadrupole
22%                       'FamName','Length','BendingAngle' for a bending magnet etc.
23%               
24%       INTELEM('action') when the first argument is a string
25%       recursively called from inside the INTELEM GUI to evaluate callbacks
26%       Possible values for action are
27%       'set'
28%       'reset'
29%       'synch'
30
31global THERING 
32
33if isnumeric(varargin{1})       %initial call
34    index = varargin{1};
35    UD.LatticeIndex = index;
36
37    ElementRecordCopy = THERING{index};
38    if nargin > 1
39        NumFields = 0;
40        Names = {};
41        for i = 1:length(varargin{2})
42            if isfield(THERING{index},varargin{2}{i})
43                NumFields = NumFields+1;
44                Names{NumFields} = varargin{2}{i};
45            end
46        end
47    else
48        Names = fieldnames(THERING{index});
49        NumFields = length(Names);
50    end
51
52
53
54    NameBoxWidth = 70;
55    NameBoxHeight = 14;
56
57    EditBoxWidth = 60;
58    EditBoxWidth2 = 40;
59    EditBoxHeight = 14;
60
61    SpaceX =20;
62    SpaceY = 15;
63
64    FamilyIndexes = findcells(THERING,'FamName',THERING{index}.FamName);
65    KidNum = find(FamilyIndexes == index);
66    h0 = figure('Color', [0.8 0.8 0.8], ...
67            'PaperPosition',[18 180 576 432], 'Units','points', 'Position',[30 30 600 200], ...
68            'ToolBar','none','MenuBar','none','NumberTitle','off','Visible','off',...
69        'Name',['Lattice Position: ',int2str(index),'      Elemenet # ',int2str(KidNum),...
70            '  Element Family: ',THERING{index}.FamName]);
71
72    Handles = cell(1,NumFields);
73    TextHandles = zeros(1,NumFields);
74
75    % Create editable text controls for each field
76    % If a field is an MxN  matrix (Multipole coefficients)
77    % create MxN text controls for each element of the matrix
78
79    LastPos = 0;
80   
81    for i = 1:NumFields
82       
83        FieldData = getfield(THERING{index},Names{NumFields-i+1});
84        if ~isempty(FieldData)
85            [M,N] = size(FieldData);
86            Name = Names{NumFields-i+1};
87            UD.FieldName = Name;
88           
89            LastPos = LastPos + SpaceY  + (M-1)*EditBoxHeight;
90           
91            % One Static Text control per field
92            TextHandles(i) = uicontrol('Parent',h0, 'Units','points', ...
93                'BackgroundColor',[0.8 0.8 0.8], ...
94                'FontSize',8, ...
95                'FontSize',8, ...
96                'ListboxTop',0, ...
97                'Position',[SpaceX  LastPos  NameBoxWidth  NameBoxHeight], ...
98                'String',Name, ...
99                'HorizontalAlignment','right', ...
100                'Style','text', ...
101                'Tag','StaticText1');
102           
103           
104            if isnumeric(FieldData)
105                for m = 1:M
106                    UD.M = m;
107                    for n = 1:N
108                        UD.N = n;
109                        EditHandles{i}(m,n)=uicontrol('Parent',h0, 'Units','points', ...
110                            'BackgroundColor',[1 1 1], 'FontSize',8 , ...
111                            'Position',[2*SpaceX+NameBoxWidth+(n-1)*EditBoxWidth2 ,  LastPos-(m-1)*EditBoxHeight,  EditBoxWidth2, EditBoxHeight], ...
112                            'Style','edit', ...
113                            'String',sprintf('%.6f',FieldData(m,n)),'HorizontalAlignment','right', ...     
114                            'UserData',UD,...
115                            'Callback','intelem sync', ...
116                            'Tag','EditText1');
117                    end
118                end 
119            elseif ischar(FieldData)
120                UD.M = 1;
121                UD.N = 1;
122                EditHandles{i}=uicontrol('Parent',h0,'Units','points', ...
123                    'BackgroundColor',[1 1 1],'FontSize',8 , ...
124                    'Position',[2*SpaceX+NameBoxWidth LastPos  100 EditBoxHeight],'Style','edit', ...
125                    'String',FieldData, 'HorizontalAlignment','left', ...
126                    'UserData',UD, ...
127                    'Callback','intelem sync', ...
128                    'Tag','EditText1');
129            end
130        end
131    end
132
133    H = get(h0,'Position');
134    H(4) = LastPos+40;
135    set(h0,'Position',H);
136    set(h0,'HandleVisibility','off','Visible','on');
137
138elseif ischar(varargin{1})
139
140    switch varargin{1}
141    case 'sync'
142        UD = get(gcbo,'UserData');
143        OldValue = getfield(THERING{UD.LatticeIndex},UD.FieldName);
144        if ischar(OldValue)
145            THERING{UD.LatticeIndex}=setfield(THERING{UD.LatticeIndex},UD.FieldName,get(gcbo,'String'));
146        elseif isnumeric(OldValue)
147            st = get(gcbo,'String');
148            NewValue = sscanf(st,'%f');
149            THERING{UD.LatticeIndex}=setfield(THERING{UD.LatticeIndex},UD.FieldName,{UD.M,UD.N},NewValue);
150        end
151
152    end
153end
Note: See TracBrowser for help on using the repository browser.