classdef ApplyOptimizationSolutionAction < fxptui.internal.action.Action
    %APPLYOPTIMIZATIONSOLUTIONACTION Action of applying a solution from the
    %latest fxpopt OptimizationResult
    
    %   Copyright 2019-2021 The MathWorks, Inc.
    
    
    methods(Access = {?fxptui.internal.action.Action, ?WorkflowTestCase})
        
        function executeLocal(~, ~, workflowSetting)
            
            % extract the TopModel information from the DesignSetting
            designSettings = workflowSetting.getSettingValue('DesignSetting');
            topModel = designSettings.TopModel;
            
            % extract the TopModel information from the DesignSetting
            exploreSetting = workflowSetting.getSettingValue('ExploreSetting');
            solutionIndex = exploreSetting.SolutionIndex;
            scenarioIndex = exploreSetting.ScenarioIndex;
            
            result = fxptui.internal.action.getMostRecentResult(topModel, 'DataTypeOptimization.OptimizationResult');
            allSolutions = fxptui.internal.action.getAllSolutions(result);
            
            solution = allSolutions(solutionIndex);
            result.exploreSolution(solution, scenarioIndex, false);
            
        end
        
    end
    
end
