www.gusucode.com > mbcdata 工具箱 matlab 源码程序 > mbcdata/@cgcaloutput/gui_export.m

    function gui_export(obj)
%GUI_EXPORT dialog for export calibration data.
%
%  GUI_EXPORT(OBJ) executes an export process on OBJ.  An error dialog is
%  shown if an the export function used returns an error code.

%  Copyright 2000-2015 The MathWorks, Inc. and Ford Global Technologies, Inc.

if isempty(obj)
    h = errordlg('There are no initialized calibration items available for export.', ...
        'CAGE', 'modal');
    waitfor(h);
else
    
    figSize = [400 430];
    hDlg = mbcgui.container.Dialog('Name', 'Export Calibration Data', ...
        'Tag', 'CalExport', ...
        'Buttons', 'OK_CANCEL',...
        'Size', figSize, ...
        'PersistPosition', false, ...
        'Resize', 'off');
    hFig = hDlg.Figure;
    [lyt,ud] = iCreateLyt(obj,hFig);
    
    
    hDlg.Content = lyt;
    set(hFig, 'UserData', ud);
    closeMode = hDlg.showDialog;
    
    if strcmp(closeMode, 'OK')
        % get selected items
        SelectedItems = ud.hCalItems.getChecks;
        if any(SelectedItems)
            % update list to be exported
            obj.ptrlist = obj.ptrlist(SelectedItems);
            % Export
            drawnow  %Need to ensure list dialog is destroyed
            selection = get(ud.ExportDst,'Value');
            fcns = getoutputfunctions(obj);
            feval(fcns{selection}, obj);
        else
            h = errordlg('There are no calibration items selected for export.', ...
                'CAGE', 'modal');
            waitfor(h);
        end
    end
    delete(hDlg)
end


function [lyt,ud] = iCreateLyt(obj,hFig)

[fcns, descriptions] = getoutputfunctions(obj);

ud.ExportDst = uicontrol('Parent',hFig,...
    'Style','popupmenu',...
    'String',descriptions,...
    'Value',1,...
    'BackgroundColor','w');

hExprtLabelLabel = xregGui.labelcontrol('parent', hFig, ...
    'String', 'Export to:', ...
    'LabelSizeMode', 'absolute', ...
    'ControlSizeMode','absolute',...
    'LabelSize', 60, ...
    'ControlSize',150, ...
    'Control', ud.ExportDst);

p = obj.Source;
if p.isproject
    [pth,fname]= fileparts(p.projectfile);
    desc = sprintf('Calibration items in the CAGE project %s:',fname);
else 
    desc = sprintf('Calibration items from %s:',p.getname);
end
hItemsHeader = uicontrol('Parent',hFig,...
    'Style','text',...
    'HorizontalAlignment','left',...
    'String',desc);

ud.hCalItems = cgtools.exprList( ...
    'SelectionStyle','None',...
    'Items',obj.ptrlist,...
    'DisplayChecks',true,...
    'Parent', hFig);
ud.hCalItems.setChecks(true(length(obj.ptrlist),1));

hTypeFilter = uicontrol('Parent',hFig,...
    'Style','text',...
    'HorizontalAlignment','left',...
    'String','Select all by type:');
Types = pveceval(obj.ptrlist,@gettype);
CalTypes = {'2D table','1D table','Normalizer','Scalar constant'};
hCheckType= cell(1,length(CalTypes));
hText = hCheckType;
IsType= cell(1,length(CalTypes));
for i=1:length(CalTypes)
    IsType{i} = ismember(Types,CalTypes{i});
    Val = any(IsType{i});
    % separate text and checkbox so the check box can be disabled when some
    % of the items are selected. The button down function is used rather
    % than the callback so the enable state has to be set to inactive.
    hText{i} = uicontrol('Parent',hFig,...
        'Style','text',...
        'HorizontalAlignment','left',...
        'String',sprintf('%ss',CalTypes{i}));
    hCheckType{i} = uicontrol('Parent',hFig,...
        'Style','checkbox',...
        'HorizontalAlignment','left',...
        'Value',Val, ...
        'Tag', CalTypes{i});
    if Val
        set(hText{i},'Enable','inactive')
        set(hCheckType{i},'Enable','inactive')
        % make sure that the check state gets toggled when selected the
        % text
        set(hText{i},'ButtonDownFcn',{@cbkSelectFilter,ud.hCalItems,IsType{i},hCheckType{i}});
        set(hCheckType{i},'ButtonDownFcn',{@cbkSelectFilter,ud.hCalItems,IsType{i},hCheckType{i}});
    else
        set(hText{i},'Enable','off')
        set(hCheckType{i},'Enable','off')
    end
    
end
    
ud.hListener = handle.listener(ud.hCalItems.Display, 'ValueChanged',{@cbkSelectItem,ud.hCalItems,hCheckType,hText,IsType});

lyt = xreggridbaglayout(hFig,...
    'dimension', [18  5], ...
    'border', [0 5 0 5], ...
    'rowsizes',[15 -1 5 15 4 15 1 4 15 1 4 15 1 4 15 1 5 20],...
    'colsizes',[10 16 120 -1 165],...
    'mergeblock',{[1 1],[1 5]},...
    'mergeblock',{[2 2],[1 5]},...
    'mergeblock',{[4 4],[1 5]},...
    'mergeblock',{[18 18],[1 5]},...
    'mergeblock',{[5 7],[2 2]},... 
    'mergeblock',{[8 10],[2 2]},...
    'mergeblock',{[11 13],[2 2]},...
    'mergeblock',{[14 16],[2 2]},...
    'elements', ...
    {hItemsHeader,ud.hCalItems,[],hTypeFilter,[],[],[],[],[], ...
    [],[],[],[],[],[],[],[],hExprtLabelLabel,...
    [],[],[],[],hCheckType{1},[],[],hCheckType{2},...
    [],[], hCheckType{3},[],[], hCheckType{4},[],[],[],[],...
    [],[],[],[],[],hText{1},[],[], hText{2},[],[],...
    hText{3},[],[], hText{4},[],[],[],...
    [],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],...
    [],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[]});




function cbkSelectFilter(~,~,hCalItems,IsType,hCheck)

% toggle the checkbox and call its callback
set(hCheck,'Value',~get(hCheck,'Value'))
cbkSelectType([],[],hCalItems,IsType,hCheck)

function cbkSelectType(~,~,hCalItems,IsType,hCheck)

Selected = hCalItems.getChecks;
Selected(IsType) = get(hCheck,'Value');
hCalItems.setChecks(Selected);
set(hCheck,'Enable','inactive');

function cbkSelectItem(~,~,hCalItems,hCheck,hText,IsType)

Selected = hCalItems.getChecks;
for i=1:length(IsType)
    if ~strcmp(get(hText{i},'Enable'),'off')
        if all( Selected(IsType{i}) )
            % all items selected - check the checkbox
            set(hCheck{i},'Value',true,'Enable','inactive');
        elseif ~any( Selected(IsType{i}) )
            % no items selected - uncheck the checkbox
            set(hCheck{i},'Value',false,'Enable','inactive');
        else
            % some items selected - turn enable to 'off' so the checkbox is
            % grey
            set(hCheck{i},'Value',true,'Enable','off');
        end
    end
end