view m-toolbox/m/gui/gltpda/g_LoadInputParamCallback.m @ 52:daf4eab1a51e database-connection-manager tip

Fix. Default password should be [] not an empty string
author Daniele Nicolodi <nicolodi@science.unitn.it>
date Wed, 07 Dec 2011 17:29:47 +0100
parents f0afece42f48
children
line wrap: on
line source

    function g_LoadInputParamCallback(currPanel,varargin)   
    % This callback is called whenever the user selects an Input block. The
    % callback draws the panel to set the only parameter associated to this
    % type of block: the ordinal number of AO.
    
        global LTPDAinvar selBlocks
        
        backColor   = get(currPanel, 'BackgroundColor');
        panelDimens = get(currPanel, 'Position');

        if length(LTPDAinvar)<1
          % Text: 'Please load at least one AO in memory'
            uicontrol('Parent',currPanel,'BackgroundColor',backColor,'Units','pixels','HorizontalAlignment','center','Position',[(panelDimens(4)-200)/2 panelDimens(4)-100 200 30],'String','Please load at least one AO in memory','Visible','on','Style','text');
          % Button: 'Add data'
            uicontrol('Parent',currPanel,'Units','pixels','HorizontalAlignment','center','Position',[(panelDimens(4)-200)/2 panelDimens(4)-150 200 30],'String','Add data','FontSize',guiFontSize+1,'Visible','on','Enable','on','Callback',@AddButtonCallback,'Style','pushbutton');
        else
          % Text: 'Obj input:'
            uicontrol('Parent',currPanel,'BackgroundColor',backColor,'Units','pixels','HorizontalAlignment','left','Position',[100 panelDimens(4)-60 80 20],'String','Object input:','Visible','on','Style','text');
          % Edit field:
            children    = get_param(gcb,'Blocks');
            inputblock  = strcat(gcb,'/',children{1});
            currAOinput = get_param(inputblock,'Value');
            uicontrol('Parent',currPanel,'Units','pixels','HorizontalAlignment','center','Position',[190 panelDimens(4)-57 50 20],'String',currAOinput,'Visible','on','Enable','on','Callback',@InputEditCallback,'Tag','inputEditField','Style','edit');
            
          % Text: 'Objs list:'
            uicontrol('Parent',currPanel,'BackgroundColor',backColor,'Units','pixels','HorizontalAlignment','left','Position',[20 panelDimens(4)-135 50 20],'String','Object list:','Visible','on','Style','text');
          % Popup input objs list:
            xx = size(LTPDAinvar,1);
            listInput = cell(xx,1);
            for j=1:xx
                switch class(LTPDAinvar{j,1})
                    case 'ao'
                        anobject  = LTPDAinvar{j,1};
                        aoname    = anobject.name;
                        aocreated = char(anobject.created);
                        listInput{j,1} = [num2str(j) , ' . AO .' , aoname , '__' , aocreated];
                    case 'plist'
                        paramNumb = nparams(LTPDAinvar{j,1});
                        objcreated = char(LTPDAinvar{j,1}.created);
                        listInput{j,1}=[num2str(j),' . PLIST .',num2str(paramNumb),' params','__',objcreated];
                    case 'specwin'
                        listInput{j,1}=[num2str(j),' . SPECWIN .','__','no creation time'];
                    case 'pzmodel'
                        objcreated = char(LTPDAinvar{j,1}.created);
                        listInput{j,1}=[num2str(j),' . PZMODEL .','__',objcreated];
                    otherwise
                        if isa(LTPDAinvar{j,1},'ltpda_uo')
                            objclass  = class(LTPDAinvar{j,1});
                            if ~isempty(LTPDAinvar{j,1}), listInput{j,1}=[num2str(j),' . ',objclass]; end
                        end
                end
            end
            for j=xx:-1:1
                if isempty(listInput{j,1})
                    listInput(j,:)=[];
                end
            end
            inputPopup = uicontrol('Parent',currPanel,'Units','pixels','HorizontalAlignment','center','Position',[80 panelDimens(4)-130 500 20],'String',listInput,'Visible','on','Enable','on','Callback',@InputPopupCallback,'Tag','inputPopupField','Style','popup');
            
          % Set the popup list on the proper line:
            for ii = 1:size(listInput,1)
                if str2double(deblank(strtok(listInput{ii}))) == str2double(currAOinput), break; end
            end
            set(inputPopup,'Value',ii);
        end
        
        
        
    %----------------------------------------------------------------------
    function InputEditCallback(hObject, varargin)   
    % This callback is called whenever the user modify the input parameter
    % associated to an Input block
    
         if ~isempty(varargin{1}), newValue = varargin{1};
         else newValue   = str2double(get(hObject,'String'));
         end
       % Check it's an integer:
         newValue = round(newValue);
       % Check if the value is acceptable, ie:
       % - if it's <length(LTPDAinvar)
         if newValue>length(LTPDAinvar)
             newValue=length(LTPDAinvar);
         end
       % - if it's a LTPDA valid object:
         if ~isa(LTPDAinvar{newValue,1},'ltpda_uo')
             children   = get_param(gcbh,'Blocks');
             inputblock = strcat(strcat(get(gcbh,'Path'),'/',get(gcbh,'Name')),'/',children{1});
             oldValue   = get_param(inputblock,'Value');
             set(findobj('Tag','inputEditField'),'String',oldValue);
             return
         end
         
         set(hObject,'String',num2str(newValue));
         
       % Set the popup list on the proper line:
         inputPopup = findobj('Tag','inputPopupField');
         listInput = get(inputPopup,'String');
         for mm = 1:size(listInput,1)
             if str2double(deblank(strtok(listInput{mm}))) == newValue, break; end
         end
         set(inputPopup,'Value',mm);

       % Object name for the annotation:
         objName = LTPDAinvar{newValue,1}.name;
         if numel(objName)>3 && strcmpi(objName,'none'), objName = class(LTPDAinvar{newValue,1}); end
         if numel(objName)>20, objName = ['...',LTPDAinvar{newValue,1}.name(end-20:end)]; end
         objName = [num2str(newValue),': ',objName];
         
         for i=1:length(selBlocks)
           % Since all input blocks are masks, and we want to change the
           % value deep inside a block INSIDE this mask, we can't use the
           % direct handles but the following:
             children{i}=get_param(selBlocks(i),'Blocks');
             inputblock=strcat(strcat(get(selBlocks(i),'Path'),'/',get(selBlocks(i),'Name')),'/',children{i}{1});
             set_param(inputblock,'Value',num2str(newValue));
           % Set the annotation:
             set_param(selBlocks(i),'AttributesFormatString',objName);
           % Set the MaskDisplay = n° of input
             set_param(selBlocks(i),'MaskDisplay',sprintf('disp(''%s'')',num2str(newValue)));
         end
    end
    %----------------------------------------------------------------------

    %----------------------------------------------------------------------
    function InputPopupCallback(hObject, varargin)  
    % This callback is called whenever the user clicks on the input list in
    % the parameters panel asociated to the 'Input Obj' block
    
        val = get(hObject, 'Value');
        objLines = get(hObject, 'String');
        objnumb = str2double(deblank(strtok(objLines{val})));
        
        InputEditCallback(findobj('Tag','inputEditField'),objnumb);
        
    end
    %----------------------------------------------------------------------

    %----------------------------------------------------------------------
    function AddButtonCallback(varargin)   
    % Callback function: run when the user click the "Add data" button
    
         filenames = uipickfiles('REFilter','.txt');
         if ~isempty(filenames) && ~isnumeric(filenames(1,1))
             [x,y]=size(filenames);
             for nn=1:y
                 anobject = {ao(filenames{nn}),1,'From file'};
                 LTPDAinvar = [LTPDAinvar;anobject];
             end
             disp(sprintf('  + %g AOs added to the global variable LTPDAinvar', y))
             ltpdagui('Redraw',2);
         end
    end   
    %----------------------------------------------------------------------

        
    end