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

    classdef ViewActions < handle
    %ViewActions view actions definition for global models
    
    %  Copyright 2005-2015 The MathWorks, Inc. and Ford Global Technologies, Inc.
    
    properties (SetAccess=private)
        %Data view data action
        Data
        %TestNumbers show test numbers action
        TestNumbers
    end
    
    properties(Access=private)
        %MessageService store for message service
        MessageService
        %ActionGroup action group for all view actions
        ActionGroup
    end

    
    methods
        
        function obj = ViewActions(ms)
        %ViewActions constructor
        %   obj = ViewActions(MessageService)
        
        obj.MessageService = ms;
        
        obj.Data = mbcgui.actions.StatefulAction(@obj.onViewData,...
            'Modeling Data','View model data',xregrespath('data.bmp'));
        obj.TestNumbers = mbcgui.actions.ToggleAction(@obj.onShowTestNumbers,...
           'Show Test Numbers','Show test numbers');    
        
        obj.ActionGroup = mbcgui.actions.ActionGroup('','View');
        obj.ActionGroup.Actions = [obj.Data,obj.TestNumbers];
        obj.ActionGroup.MenuType = 'separate';        
        
        end
        
        function createMenus(obj,hParent)
        
        hMenu = createMenuItem(obj.ActionGroup,hParent);
        set(hMenu(:),{'Tag'},{'data', 'testnum'}');
        
        end
        

        function enable(obj)
        %enable enable view actions
        
        if obj.MessageService.Status==0 
            set(obj.ActionGroup,'Enabled',false)
        else
            set(obj.ActionGroup,'Enabled',true)
        end
        
        end

    end
    
    
    methods(Access=protected)
            
        function onViewData(obj,~,~)
        %onViewData view data callback
        viewGlobalModellingData(obj)
        end
        
        function onShowTestNumbers(obj,~,~)
        %onShowTestNumbers show test numbers in all plots
        
        % 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

    end

    
end


function viewGlobalModellingData(obj)
%viewGlobalModellingData open data editor with model predictions

% Get the data to send to the editor

ms = obj.MessageService;

X = ms.XData(ms.DataOK,:);
Y = ms.YData(ms.DataOK);

% Need to generate the predicted Y value
m = ms.Model;
% Create a sweepset with the correct size
predictedY = set(Y, 'Name', {['predicted_' varname(m)]} );
% Evaluate the model
predictedY(:, 1) = m(X);
% Make the data all the same size
ss = [X Y predictedY];
% Open data edit facility
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