classdef SimulinkActions < fxptds.AbstractActions
    % SIMULINKACTIONS Defines the actions supported on results from Simulink in Fixed-Point Tool
    
    % Copyright 2012-2019 The MathWorks, Inc.
    
    methods
        function this = SimulinkActions(result)
            this@fxptds.AbstractActions(result);
        end
        
        function invokeMethod(this, methodName)
            this.(methodName);
        end
    end
    
    methods(Access = protected)
        function actions = getSupportedActions(this)
            if this.Result.isPlottable || this.isHistogramAvailable
                actions = this.getPlottingActions;
            else
                actions = this.getRunCompareAction;
            end
            actions = [actions this.getHiliteAction this.getUnhiliteAction];
            if hasDTGroup(this.Result)
                actions(end+1) = this.getHiliteDTGroupAction;
            end
            if isResultValid(this.Result)
                actions(end+1) = this.getOpenDialogAction;
            end
            if hasOutput(this.Result)
                actions(end+1) =  this.getOpenSignalDialogAction;
            end
        end
        
        function action = getOpenDialogAction(~)
            action = fxptds.Action('', fxptui.message('actionOPENBLOCKDIALOG'), ...
                'FPT_simulink_openblkdlg',...
                'fxptds.AbstractActions.selectAndInvoke(''openBlockDialog'')');
        end
        
        function action = getOpenSignalDialogAction(~)
            action = fxptds.Action('', fxptui.message('actionOPENSIGNALDIALOG'), ...
                'FPT_simulink_opensigprops',...
                'fxptds.AbstractActions.selectAndInvoke(''openSignalDialog'')');
        end
        
        function actions = getPlottingActions(this)
            str = fxptui.message('actionVIEWTSINFIGURESDI');
            actions = fxptds.Action(fullfile(matlabroot, 'toolbox', 'fixedpoint', 'fixedpointtool', 'resources', 'plot.png'), ...
                str, 'FPT_view_tsinfigure','fxptds.AbstractActions.selectAndInvoke(''plotSignal'')');
            
            actions(end+1) = fxptds.Action(fullfile(matlabroot, 'toolbox', 'fixedpoint', 'fixedpointtool', 'resources', 'plothist.png'),...
                fxptui.message('actionVIEWHISTINFIGURE'),'FPT_view_histinfigure',...
                'fxptds.AbstractActions.selectAndInvoke(''plotHistogram'')');
            
            str = fxptui.message('actionVIEWDIFFINFIGURESDI');
            actions(end+1)= fxptds.Action(fullfile(matlabroot, 'toolbox', 'fixedpoint', 'fixedpointtool', 'resources', 'plotdiff.png'), ...
                str,'FPT_view_diffinfigure','fxptds.AbstractActions.selectAndInvoke(''plotDifference'')');
            
            actions(end+1) = this.getRunCompareAction;
        end
        
        function action = getRunCompareAction(~)
            str = fxptui.message('actionVIEWRUNCOMPARESDI');
            action = fxptds.Action(fullfile(matlabroot, 'toolbox', 'fixedpoint', 'fixedpointtool', 'resources', 'plotcompare.png'), ...
                str,'FPT_compare_runs','fxptds.AbstractActions.selectAndInvoke(''compareRuns'')');
        end
        
        function openBlockDialog(this)
            openDialog(this.Result.getUniqueIdentifier);
        end
        
    end
    
    methods (Access=protected)
        
        function openSignalDialog(this)
            openSignalPropertiesDialog(this.Result.getUniqueIdentifier);
        end
        
    end
    
end
