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

    classdef StartActions < handle
    %StartActions model browser start actions
    
    %  Copyright 2016-2016 The MathWorks, Inc. 

    properties (SetAccess=private)
        DesignExperiment
        ImportData
        FitModels
        GenerateCalibration
    end
    properties (SetAccess=private)
        Browser
        MessageService
        IsRunning = false;
    end
    
    properties (Dependent,SetAccess=private)
        ActionList
    end    
    
    methods
        function obj = StartActions(Browser,MessageService)
        obj.Browser = Browser;
        obj.MessageService = MessageService;

        obj.DesignExperiment = mbcgui.actions.StatefulAction(@obj.onDesignExperiment,'Design Experiment',...
            'Design experiment to collect data for fitting models.',xregrespath('mbcdesign.png'));
      
        obj.ImportData = mbcgui.actions.StatefulAction(@obj.onImportData,'Import Data',...
            'Import and preprocess data for modeling.',xregrespath('mbcdata.png'));
        obj.FitModels = mbcgui.actions.StatefulAction(@obj.onFitModel,'Fit Models',...
            'Fit models to data.',xregrespath('mbcfitmodel.png'));        
        obj.GenerateCalibration = mbcgui.actions.StatefulAction(@obj.onGenerateCalibration,'Generate Calibration',...
            'Generate calibrations with models.',xregrespath('mbcoptim.png'));        
        
        end
       
        function a = get.ActionList(obj)
        a = [obj.DesignExperiment obj.ImportData obj.FitModels obj.GenerateCalibration];
        end
        
        function reset(obj)
        obj.IsRunning = false;

        end
    end
    
    methods (Access=private)
        function onDesignExperiment(obj,~,~)
        %onDesignExperiment design experiment in new test plan
        if ~obj.IsRunning
            obj.IsRunning = true;
            restore = onCleanup(@obj.reset);
            ms = obj.MessageService;
            a = ms.Actions.DesignExperiment;
            a.execute()
        end
        end
        
        function onImportData(obj,~,~)
        %onImportData import data with choice of source and using editor
        if ~obj.IsRunning
            obj.IsRunning = true;
            restore = onCleanup(@obj.reset);
            % could check for variables in workspace and prompt for source
            ms = obj.MessageService;
            a = ms.Actions.ImportData;
            a.execute()
        end
        
        end
        
        function onFitModel(obj,~,~)
        %onFitModel fit models in new test plan
        if ~obj.IsRunning
            obj.IsRunning = true;
            restore = onCleanup(@obj.reset);
            ms = obj.MessageService;
            a = ms.Actions.FitModels;
            a.execute()
        end
        
        end
        
        function onGenerateCalibration(obj,~,~)
        %onGenerateCalibration generate calibration in CAGE
        %   import tool is opened with model browser models selected
        if ~obj.IsRunning
            obj.IsRunning = true;
            restore = onCleanup(@obj.reset);
            
            % open CAGE
            cage
            % determine whether there are any models
            OK = children(info(obj.Browser.RootNode),@hasBestExportModel);
            if any([OK{:}])
                % open import tool if there are models
                cgimporttool;
            end
        end

        end
    end
    
end