Home > atgui > intelem.m

intelem

PURPOSE ^

INTELEM - interactive element editor.

SYNOPSIS ^

function h0 = intelem(varargin)

DESCRIPTION ^

INTELEM - interactive element editor. 
    
    INTELEM(INDEX) retrieves THERING{INDEX} from the
        main workspace and displays the values of all fields for that element
        Fields that are 1xN vectors or MxN matrixies 
        such as multipole field data stored in 'PolynomA' are displayed
        in M raws and N columns, each element in a separate text box.

    INTELEM(INDEX, Fields2Display)
        Some element models/definitions contain large number of
        parameters. It may be desired to interactively control only few of them 
        A cell array of strings Fields2Display allows to select which 
        element parameters are included in the GUI. 
        When Fields2Display contains a field name that does not exist for 
         an elemet no error is generated ,that field is ignored.
     For example 
            Fields2Display = {'FamName' 'Length' 'K' 'BendingAngle'}  
             INELEM displays 'FamName' and 'Length' when called for a drift
            'FamName','Length','K' when called for a quadrupole
            'FamName','Length','BendingAngle' for a bending magnet etc.
        
    INTELEM('action') when the first argument is a string
    recursively called from inside the INTELEM GUI to evaluate callbacks
    Possible values for action are
    'set'
    'reset'
    'synch'

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function h0 = intelem(varargin)
0002 
0003 %INTELEM - interactive element editor.
0004 %
0005 %    INTELEM(INDEX) retrieves THERING{INDEX} from the
0006 %        main workspace and displays the values of all fields for that element
0007 %        Fields that are 1xN vectors or MxN matrixies
0008 %        such as multipole field data stored in 'PolynomA' are displayed
0009 %        in M raws and N columns, each element in a separate text box.
0010 %
0011 %    INTELEM(INDEX, Fields2Display)
0012 %        Some element models/definitions contain large number of
0013 %        parameters. It may be desired to interactively control only few of them
0014 %        A cell array of strings Fields2Display allows to select which
0015 %        element parameters are included in the GUI.
0016 %        When Fields2Display contains a field name that does not exist for
0017 %         an elemet no error is generated ,that field is ignored.
0018 %     For example
0019 %            Fields2Display = {'FamName' 'Length' 'K' 'BendingAngle'}
0020 %             INELEM displays 'FamName' and 'Length' when called for a drift
0021 %            'FamName','Length','K' when called for a quadrupole
0022 %            'FamName','Length','BendingAngle' for a bending magnet etc.
0023 %
0024 %    INTELEM('action') when the first argument is a string
0025 %    recursively called from inside the INTELEM GUI to evaluate callbacks
0026 %    Possible values for action are
0027 %    'set'
0028 %    'reset'
0029 %    'synch'
0030 
0031 global THERING  
0032 
0033 if isnumeric(varargin{1})    %initial call
0034     index = varargin{1};
0035     UD.LatticeIndex = index;
0036 
0037     ElementRecordCopy = THERING{index};
0038     if nargin > 1
0039         NumFields = 0;
0040         Names = {};
0041         for i = 1:length(varargin{2})
0042             if isfield(THERING{index},varargin{2}{i})
0043                 NumFields = NumFields+1;
0044                 Names{NumFields} = varargin{2}{i};
0045             end
0046         end
0047     else
0048         Names = fieldnames(THERING{index});
0049         NumFields = length(Names);
0050     end
0051 
0052 
0053 
0054     NameBoxWidth = 70;
0055     NameBoxHeight = 14;
0056 
0057     EditBoxWidth = 60;
0058     EditBoxWidth2 = 40;
0059     EditBoxHeight = 14;
0060 
0061     SpaceX =20;
0062     SpaceY = 15;
0063 
0064     FamilyIndexes = findcells(THERING,'FamName',THERING{index}.FamName);
0065     KidNum = find(FamilyIndexes == index);
0066     h0 = figure('Color', [0.8 0.8 0.8], ...
0067         'PaperPosition',[18 180 576 432], 'Units','points', 'Position',[30 30 600 200], ...
0068         'ToolBar','none','MenuBar','none','NumberTitle','off','Visible','off',...
0069         'Name',['Lattice Position: ',int2str(index),'      Elemenet # ',int2str(KidNum),...
0070             '  Element Family: ',THERING{index}.FamName]);
0071 
0072     Handles = cell(1,NumFields);
0073     TextHandles = zeros(1,NumFields);
0074 
0075     % Create editable text controls for each field
0076     % If a field is an MxN  matrix (Multipole coefficients)
0077     % create MxN text controls for each element of the matrix
0078 
0079     LastPos = 0;
0080     
0081     for i = 1:NumFields
0082         
0083         FieldData = getfield(THERING{index},Names{NumFields-i+1});
0084         if ~isempty(FieldData)
0085             [M,N] = size(FieldData);
0086             Name = Names{NumFields-i+1};
0087             UD.FieldName = Name;
0088             
0089             LastPos = LastPos + SpaceY  + (M-1)*EditBoxHeight;
0090             
0091             % One Static Text control per field
0092             TextHandles(i) = uicontrol('Parent',h0, 'Units','points', ...
0093                 'BackgroundColor',[0.8 0.8 0.8], ...
0094                 'FontSize',8, ...
0095                 'FontSize',8 , ...
0096                 'ListboxTop',0, ...
0097                 'Position',[SpaceX  LastPos  NameBoxWidth  NameBoxHeight], ...
0098                 'String',Name, ...
0099                 'HorizontalAlignment','right', ...
0100                 'Style','text', ...
0101                 'Tag','StaticText1');
0102             
0103             
0104             if isnumeric(FieldData)
0105                 for m = 1:M
0106                     UD.M = m;
0107                     for n = 1:N
0108                         UD.N = n;
0109                         EditHandles{i}(m,n)=uicontrol('Parent',h0, 'Units','points', ...
0110                             'BackgroundColor',[1 1 1], 'FontSize',8 , ...
0111                             'Position',[2*SpaceX+NameBoxWidth+(n-1)*EditBoxWidth2 ,  LastPos-(m-1)*EditBoxHeight,  EditBoxWidth2, EditBoxHeight], ...
0112                             'Style','edit', ...
0113                             'String',sprintf('%.6f',FieldData(m,n)),'HorizontalAlignment','right', ...      
0114                             'UserData',UD,...
0115                             'Callback','intelem sync', ...
0116                             'Tag','EditText1');
0117                     end
0118                 end  
0119             elseif ischar(FieldData)
0120                 UD.M = 1;
0121                 UD.N = 1;
0122                 EditHandles{i}=uicontrol('Parent',h0,'Units','points', ...
0123                     'BackgroundColor',[1 1 1],'FontSize',8 , ...
0124                     'Position',[2*SpaceX+NameBoxWidth LastPos  100 EditBoxHeight],'Style','edit', ...
0125                     'String',FieldData, 'HorizontalAlignment','left', ...
0126                     'UserData',UD, ...
0127                     'Callback','intelem sync', ...
0128                     'Tag','EditText1');
0129             end
0130         end
0131     end
0132 
0133     H = get(h0,'Position');
0134     H(4) = LastPos+40;
0135     set(h0,'Position',H);
0136     set(h0,'HandleVisibility','off','Visible','on');
0137 
0138 elseif ischar(varargin{1})
0139 
0140     switch varargin{1} 
0141     case 'sync'
0142         UD = get(gcbo,'UserData');
0143         OldValue = getfield(THERING{UD.LatticeIndex},UD.FieldName);
0144         if ischar(OldValue)
0145             THERING{UD.LatticeIndex}=setfield(THERING{UD.LatticeIndex},UD.FieldName,get(gcbo,'String'));
0146         elseif isnumeric(OldValue)
0147             st = get(gcbo,'String');
0148             NewValue = sscanf(st,'%f');
0149             THERING{UD.LatticeIndex}=setfield(THERING{UD.LatticeIndex},UD.FieldName,{UD.M,UD.N},NewValue);
0150         end
0151 
0152     end
0153 end

Generated on Thu 24-Aug-2017 18:47:33 by m2html © 2005