www.gusucode.com > mbctools 工具箱 matlab 源码程序 > mbctools/+mbcmodelview/+ptbypt/ModelActions.m
classdef ModelActions < handle %ModelActions Model actions for point-by-point models % Copyright 2015 The MathWorks, Inc. and Ford Global Technologies, Inc. properties (SetAccess=private) %ModelEdit model setup dialog ModelEdit %Evaluate evaluate menu (has submenus) Evaluate %SummaryStatistics set summary statistics SummaryStatistics %SelectModel open model selection figure SelectModel %AddModel add alternative model AddModel end properties(Access=private) %MessageService MessageService handle MessageService %ModelEditGroup model edit group ModelEditGroup %ModelSelection model selection group ModelSelection end methods function obj = ModelActions(MessageService) %GlobalModel constructor obj.MessageService = MessageService; obj.ModelEdit = mbcgui.actions.StatefulAction(@obj.onModelEdit,... '&Edit Model...','Edit model definition',xregrespath('locreg.bmp')); obj.ModelEdit.TransparentColor = [255 0 255]; obj.AddModel = mbcgui.actions.StatefulAction(@obj.onAddModel,... '&Add Local Model...','Add local model',xregrespath('newlocalmod.bmp')); obj.SummaryStatistics = mbcgui.actions.StatefulAction(@obj.onSummaryStats,... '&Summary Statistics...','Define summary statistics',[]); % Model evaluation options obj.Evaluate = mbcgui.actions.ActionGroup('',... '&Evaluate','Evaluate current model response',[]); obj.Evaluate.MenuType = 'submenu'; obj.Evaluate.Actions = [mbcgui.actions.StatefulAction(@obj.onEvaluateFitData,'&Fit Data...') mbcgui.actions.StatefulAction(@obj.onEvaluateValData,'&Validation Data...') mbcgui.actions.StatefulAction(@obj.onEvaluateNoData,'&No Data...') mbcgui.actions.StatefulAction(@obj.onEvaluateOtherData,'&Other Data...')]; obj.ModelEditGroup = mbcgui.actions.ActionGroup([],'Model Edit'); obj.ModelEditGroup.Actions = [obj.ModelEdit,obj.AddModel,obj.SummaryStatistics,obj.Evaluate]; obj.ModelEditGroup.MenuType = 'separate'; % model selection actions obj.SelectModel= mbcgui.actions.StatefulAction(@obj.onSelectModel,... '&Selection Window...','Model selection window',[]); obj.ModelSelection = mbcgui.actions.ActionGroup([],'Model Selection','Model selection functions',[]); obj.ModelSelection.Actions = obj.SelectModel; obj.ModelSelection.MenuType = 'separate'; end function createMenus(obj,Parent) %createMenus create model menus from actions hMenu = createMenuItem(obj.ModelEditGroup,Parent); set(hMenu(1),'Accelerator','M'); set(hMenu(:),{'Tag'},{'setup','','','evaluate','fitdata','valdata','nodata','otherdata'}'); hMenu = createMenuItem(obj.ModelSelection,Parent); set(hMenu(:),{'Tag'},{'select'}'); end function createWorkflowItems(obj,hWorkflow) %createWorkflowItems AG = mbcgui.actions.ActionGroup([],'Workflow'); % could have New Model as well AG.Actions = [obj.ModelEdit,obj.AddModel]; createWorkflowItems(AG,hWorkflow); end function enable(obj) %enable enable model actions ms = obj.MessageService; obj.Evaluate.Enabled = ms.Status~=0; % Evaluate with validation data obj.Evaluate.Actions(2).Enabled = ms.Status~=0 && ~isempty(ms.ValidationXData); obj.SelectModel.Enabled = any(ms.AlternativeStatus) || ms.Status~=0; end end methods(Access=private) function onModelEdit(obj,~,~) %onModelEdit edit model setup ms = obj.MessageService; OldModel= model(ms.ModelDev); if closeSubFigures(ms) % have to close down sub-figures etc. [NewModel,OK]= gui_localmodsetup(OldModel,'figure'); if OK && ~isequal(NewModel,OldModel) busy(ms); mv_busy('Fitting local models'); drawnow update setupModel(ms,NewModel); mv_busy('delete') idle(ms); end end end function onSelectModel(obj,~,~) %onSelectModel open model selection figure obj.MessageService.selectModelFigure; end function onAddModel(obj,~,~) %onAddModel add new alternative model ms = obj.MessageService; m= get(ms.Model,'currentmodel'); [m,OK]= gui_ModelSetup(m); if OK busy(obj.MessageService); [~,ModelsChanged] = addModelandRefit(ms.ModelDev,m); update(ms) idle(ms); if any(ModelsChanged) X = getdata(ms.ModelDev); tnums= sprintf('%d,',testnum(X(:,:,ModelsChanged))); h = msgbox(sprintf('The new model has been selected for tests %s.',tnums(1:end-1)),'Add Model'); else h = msgbox('The new model has not been selected for any test.','Add Model'); end uiwait(h); end end function onSummaryStats(obj,~,~) %onSummaryStats update summary statistics ms = obj.MessageService; [L,OK]= gui_SummaryStats(ms.Model); if OK ms.Pointer.model(L); update(ms) end end % evaluate callbacks function onEvaluateFitData(obj,~,~) %onEvaluateFitData evaluation figure with fit data evaluateFitData(obj.MessageService); end function onEvaluateValData(obj,~,~) %onEvaluateValData evaluation figure with validation data evaluateValData(obj.MessageService); end function onEvaluateNoData(obj,~,~) %onEvaluateNoData evaluation figure with no data evaluateNoData(obj.MessageService); end function onEvaluateOtherData(obj,~,~) %onEvaluateOtherData evaluation figure with other (selected) data evaluateOtherData(obj.MessageService); end end end