www.gusucode.com > mbcdata 工具箱 matlab 源码程序 > mbcdata/+cgfillsetup/TablePage.m

    classdef TablePage < cgcalsetup.WizardPage 
    %CGFILLSETUP.TABLEPAGE table selection page for table fill wizard
    
    %  Copyright 2009-2012 The MathWorks, Inc. and Ford Global Technologies, Inc.

    
    properties
        %HRLIST right hand list for selected tables
        hrlist
        %HLLIST left hand list for unselected tables
        hllist
        %RHTABIND indices to selected tables
        rhtabind
        %LHTABIND indices to unselected tables
        lhtabind
        %SELECT select table buttom
        select
        %DESELECT select table buttom
        deselect
    end
    
    
    methods

        function updatePage(T,iFace) 
            %UPDATEPAGE update wizard page from data
            
            F = T.Data;
            pTabs = F.PossibleTables;
            
            % Are we editing an existing valid set-up, or creating a new table fill
            % set-up?
            pSetUpTabs = F.Tables;
            if isempty(pSetUpTabs)
                % put the cage table names in the lhs listbox
                T.hllist.Items = pTabs;
                T.lhtabind = 1:length(pTabs);
                T.rhtabind = [];
            else
                % determine which tables have been set up to be filled.
                selinds = findptrs(pSetUpTabs, pTabs);
                selinds(selinds==0)=[];
                notselinds = setdiff(1:length(pTabs), selinds);
                T.lhtabind = notselinds;
                T.rhtabind = selinds;
                T.hllist.Items = pTabs(notselinds);
                T.hrlist.Items = pTabs(selinds);
                if ~isempty(notselinds)
                    T.hllist.SelectedItems = pTabs(notselinds(1));
                end
                if ~isempty(selinds)
                    T.hrlist.SelectedItems = pTabs(selinds(1));
                end
            end
            
            feval( iFace.setFinishButton, 'off' );
            enableNext(T,iFace);
        end
        
        function updateData(T)
            %UPDATEDATA update cgoptimtablefiller with selected tables
            
            F = T.Data;
            % update setlected tables 
            F.Tables = F.PossibleTables(T.rhtabind);
            
        end
    end
    
    
    methods(Access=protected)
        function T = TablePage(fh,iFace,C)
            %TABLEPAGE protected constructor
            T.Data = C;
            T.Layout = createLayout(T,fh,iFace);
            updatePage(T,iFace)
        end
        
        function MainLyt =createLayout(T,fh,iFace)
            %CREATELAYOUT main layout for wizard page
            
            [llistlyt, T.hllist] = iCreateListLayout(fh, 'Available CAGE tables:');
            % pseudo tag for testing
            set(T.hllist,'UserData','AvailableTables')
            
            T.select = xregGui.iconuicontrol('parent',  fh, ...
                'style', 'pushbutton', ...
                'TransparentColor', [0 255 0], ...
                'ImageFile', cgrespath('rightarrow.bmp'), ...
                'tooltipstring', 'Add table to fill', ...
                'Tag', 'add_table', ...
                'callback', {@cbPushSelect, T,iFace});
            
            T.deselect = xregGui.iconuicontrol('Parent',  fh, ...
                'Style', 'pushbutton', ...
                'TransparentColor', [0 255 0], ...
                'ImageFile', cgrespath('leftarrow.bmp'), ...
                'ToolTipString', 'Remove table to fill', ...
                'Tag', 'remove_table', ...
                'Callback', {@cbPushDeselect, T,iFace});
            
            btnlyt = xreggridbaglayout(fh, ...
                'Dimension', [5 1], ...
                'RowSizes', [-1 25 5 25 -1], ...
                'Gapy', 5, ...
                'Elements', {[], T.select, [], T.deselect, []});
            
            [rlistlyt, T.hrlist] = iCreateListLayout(fh, 'CAGE tables to be filled:');
            % pseudo tag for testing
            set(T.hrlist,'UserData','FillTables')

            

            layout = xreggridbaglayout(fh, ...
                'Dimension', [1 5], ...
                'ColSizes', [-1 10 25 10 -1], ...
                'Elements', {llistlyt, [], btnlyt, [], rlistlyt},...
                'Border', [7 15 7 10]);
            
            MainLyt = addInfoPane(T,fh,'Table Selection',layout);
            T.hInfoPane.InfoString = 'Select the CAGE tables that you wish to fill from the optimization results';
            
        end
        
        function f= getNextPage(W) %#ok<MANU>
            %GETNEXTPAGE the next page in the table filling wizard is FillPage
            f = @cgfillsetup.FillPage.createPage;
        end
        
        function enableNext(T,iFace)
            %ENABLENEXT enable next button in wizard
            if ~isempty(T.rhtabind)
                en = 'on';
            else
                en = 'off';
            end
            feval( iFace.setNextButton,   en );
        end
        
    end
    
    methods(Static)
        function layout = createPage( fh, iFace, C )
            %CREATE create normalizer wizard page
            %     layout = cgfillsetup.TablePage.createPage( fh, iFace, C )
            if isa(fh, 'xregcontainer')
                N = get(fh,'UserData');
                updatePage(N,iFace)
            else
                feval(iFace.setWizardSize, [650 400])
                set(fh,'Resize','off');
                iFace.setUserData(C);
                N = cgfillsetup.TablePage(fh,iFace,C);
            end
            layout = N.Layout;
        end
    end
    
end


function [layout, listbox] = iCreateListLayout(fh, titlestr)
%ICREATELISTLAYOUT main list in layout
%    [layout, listbox] = iCreateListLayout(fh, titlestr)

listtitle = uicontrol('Parent', fh, ...
    'Style', 'text', ...
    'String', titlestr, ...
    'Enable', 'inactive', ...
    'HorizontalAlignment', 'left');

listbox = cgtools.exprList('parent', fh, ...
    'displaytypecolumn', false, ...
    'SelectionStyle', 'multiple', ...
    'DisplayInputNames','inputs',...
    'itemheadertext', 'Table');

layout = xreggridbaglayout(fh, ...
    'dimension', [3 1], ...
    'rowsizes', [15 5 -1], ...
    'elements', {listtitle,[], listbox});

end



function cbPushDeselect(~, ~, T,iFace)
%CBPUSHDESELECT callback to deselect a table

% Retrieve the selected table from the 'selected' list
[T.hrlist, UD.hllist, T.rhtabind, T.lhtabind] = ...
    iSelectTables(T.hrlist, T.hllist, T.rhtabind, T.lhtabind, T.Data.PossibleTables);
% set the next button in the wizard
enableNext(T, iFace);

end


function cbPushSelect(~, ~,T, iFace)
%CBPUSHSELECT callback to select a table

% Push the selected table into the 'selected' list
[T.hllist, T.hrlist, T.lhtabind, T.rhtabind] = ...
    iSelectTables(T.hllist, T.hrlist, T.lhtabind, T.rhtabind, T.Data.PossibleTables);
% set the next button in the wizard
enableNext(T, iFace);

end


function [hSource, hSink, indSource, indSink] = ...
    iSelectTables(hSource, hSink, indSource, indSink, allTabs)
%ISELECTTABLES selection between lists
% Have a source list ----> sink list

lhval = hSource.SelectedIndex;
if ~isempty(lhval) 
    % Set indices
    lhItems = hSource.Items;
    NLHS = length(lhItems);
    newlhind = setdiff(1:NLHS, lhval);
    newtabind = indSource(lhval);
    indSink = [indSink newtabind];
    indSink = sort(indSink);
    indSource = indSource(newlhind);
    % Set strings
    newlhtabs = allTabs(indSource);
    newrhtabs = allTabs(indSink);
    hSource.Items = newlhtabs;
    hSink.Items = newrhtabs;
    % Set selected item in source list
    if ~isempty(indSource)
        % Choose the source item closest to the lowest table selected
        [~, chooseIdx] = sort(indSource - newtabind(end));
        hSource.SelectedItems = allTabs(indSource(chooseIdx(1)));
    end
    % Set selected item in sink list
    hSink.SelectedItems = allTabs(newtabind);
else
    % No CAGE table is selected
end
end