www.gusucode.com > mbctools 工具箱 matlab 源码程序 > mbctools/+mbcmodelview/+local/ViewActions.m

    classdef ViewActions < handle
    %ViewActions local node view actions 
    
    %  Copyright 2005-2015 The MathWorks, Inc. and Ford Global Technologies, Inc.
    
    properties (SetAccess=private)
        %LocalData view local fit data in read-only data editor
        LocalData
        %RFData view response feature data in read-only data editor
        RFData
        %TestNumbers view record numbers
        TestNumbers
        %NextTest goto next test
        NextTest
        %PreviousTest goto previous test
        PreviousTest
        %SelectTest select test from dialog
        SelectTest
    end
    
    properties(SetAccess=private)
        MessageService
        %ViewGroup action group for other view items
        ViewGroup
        %TestGroup action group for test navigation
        TestGroup
    end

    
    methods
        
        function obj = ViewActions(ms)
        %ViewActions constructor
        %   obj = ViewActions(MessageService)
        
        obj.MessageService = ms;
        
        obj.LocalData = mbcgui.actions.StatefulAction(@obj.onViewLocalData,...
            '&Local Fit Data','View local model data',xregrespath('data.bmp'));
        obj.RFData = mbcgui.actions.StatefulAction(@obj.onViewResponseData,...
            'Resp&onse Feature Data','View response feature data',xregrespath('data.bmp'));
        obj.TestNumbers = mbcgui.actions.ToggleAction(@obj.onShowTestNumbers,...
           'Show Record Numbers','Show record numbers');    
        
        obj.ViewGroup = mbcgui.actions.ActionGroup('','View');
        obj.ViewGroup.Actions = [obj.LocalData, obj.RFData,obj.TestNumbers];
        obj.ViewGroup.MenuType = 'separate';   
        
        obj.NextTest = mbcgui.actions.StatefulAction(@obj.onNextTest,...
            '&Next Test','Next test',xregrespath('arrow_move_right_lg.bmp'));
        obj.PreviousTest = mbcgui.actions.StatefulAction(@obj.onPreviousTest,...
            '&Previous Test','Previous test',xregrespath('arrow_move_left_lg.bmp'));
        obj.SelectTest = mbcgui.actions.StatefulAction(@obj.onSelectTest,...
            '&Select Test...','Select test','');
        obj.TestGroup = mbcgui.actions.ActionGroup('','Test Selector');
        obj.TestGroup.Actions = [obj.NextTest,obj.PreviousTest,obj.SelectTest];
        obj.TestGroup.MenuType = 'separate';
        
        end
        
        function createMenus(obj,hParent)
        %createMenus create view menu items
        
        createMenuItem(obj.ViewGroup,hParent);
        hMenu = createMenuItem(obj.TestGroup,hParent);
        % add accelerators for next and previous test menus
        Accel={'F','B',''}';
        Tags={'ForwardMenu','BackwardMenu','SelectMenu'}';
        set(hMenu(:),{'Tag'},Tags,{'Accelerator'},Accel);
        
        end
        
        function enable(obj)
        %enable enable actions
        
        ms = obj.MessageService;
        obj.PreviousTest.Enabled =  ms.CurrentTest>1;
        obj.NextTest.Enabled =  ms.CurrentTest<ms.NumTests;
        
        end

    end
    
    
    methods(Access=protected)
            
        function onViewLocalData(obj,~,~)
        %onViewLocalData view local data callback
        viewLocalData(obj.MessageService)
        end

        function onViewResponseData(obj,~,~)
        %viewResponseData view response feature data callback
        viewResponseData(obj.MessageService)
        end

        function onShowTestNumbers(obj,~,~)
        %onShowTestNumbers show test numbers callback
        
        % toggle ShowTestNumbers property
        %  Views that need to show test plans are listening to changes in
        %  MessageService ShowTestNumbers property
        obj.MessageService.ShowTestNumbers = ~obj.MessageService.ShowTestNumbers;
        end
        
        function onNextTest(obj,~,~)
        %onNextTest next test callback
        
        ms = obj.MessageService;
        busy(ms);
        updateTest(ms,ms.CurrentTest+1);
        idle(ms);
        end
        
        function onPreviousTest(obj,~,~)
        %onPreviousTest previous test callback
        
        ms = obj.MessageService;
        busy(ms);
        updateTest(ms,ms.CurrentTest-1);
        idle(ms);
        end


        function onSelectTest(obj,~,~)
        %onSelectTest select test callback
        ms = obj.MessageService;
        NewTest = TestChooser(ms.ModelDev,ms.CurrentTest);
        OK= NewTest~=0;
        if OK
            busy(ms);
            updateTest(ms,NewTest);
            idle(ms);
        end
        end
        
    end

    
end

function viewLocalData(ms)
%viewLocalData view local data in data editor

% Set pointer to be a watch
busy(ms);
ss = getLocalData(ms);
% Open data edit facility
i_openDataEditor(ms, ss)
% Set pointer to be the default
idle(ms);
end

%----------------------------------------------------------------------
%  function i_viewData
%----------------------------------------------------------------------
function viewResponseData(ms)
md = ms.ModelDev;
% Set pointer to be a watch
busy(ms)
% Get the data to send to the editor
responseData = info(RFData(md));
XFit = getdata(md, 'FIT');
globalData = XFit{end};
% Concatenate the data
ss = [responseData globalData];
% Open data edit facility
i_openDataEditor(ms,ss)
% Set pointer to be the default
idle(ms)
end

%----------------------------------------------------------------------
% Data Editor opening utility
%----------------------------------------------------------------------
function i_openDataEditor(ms,ss)
%i_openDataEditor open data editor 
%   i_openDataEditor(ms,ss)
hData = xregdatagui.Editor.create;
% Register as a subfigure
registerSubFigure(ms,hData.Figure);
% Send the modelling data to the data editor
hData.MessageService.setDataObject(ss);
hData.MessageService.isReadOnly = true;
end

function ss = getLocalData(ms)
%getLocalData get local data
md = ms.ModelDev;
% Get the data to send to the editor
fullData = getdata(md, 'ALLDATA');
[X, Y] = getdata(md);
predictedYLocal = set(Y, 'Name', 'predictedY_local');
% Do local prediction
allModels = LocalModel(md, ':');
if ~iscell(allModels)
    allModels= {allModels};
end
% Loop through the local models and produce the localfit data
for i = 1:length(allModels)
    predictedYLocal{i} = allModels{i}(X{i});
end
% Concatenate the data
ss = [fullData predictedYLocal];
% Get the two stage model
TS = BestModel(md);
% Is it empty
if ~isempty(TS)    
    predictedYTwostage = set(Y, 'Name', 'predictedY_twostage');
    % Get the global fit data
    Xfit = getdata(md, 'FIT');
    % Fit the twostage model
    predictedYTwostage(:,1) = TS(Xfit);
    % Concatenate
    ss = [ss predictedYTwostage];
end
end