www.gusucode.com > mbcview 工具箱matlab源码程序 > mbcview/+cageview/+optimoutput/IndexerView.m

    classdef IndexerView < mbcgui.multiview.View
    %cageview.optimoutput.IndexerView class
    %   cageview.optimoutput.IndexerView extends mbcgui.multiview.View.
    %
    %    cageview.optimoutput.IndexerView properties:
    %       Parent - Property is of type 'MATLAB array'
    %       Position - Property is of type 'rect'
    %       Enable - Property is of type 'on/off'
    %       Visible - Property is of type 'on/off'
    %       UserData - Property is of type 'MATLAB array'
    %       Tag - Property is of type 'string'
    %       MessageService - Property is of type 'handle'
    %       Options - Property is of type 'handle vector'
    %       Actions - Property is of type 'handle vector'
    %       UIContextMenu - Property is of type 'MATLAB array'
    %
    %    cageview.optimoutput.IndexerView methods:
    %       gettitle - Return string to use as title for view
    
    %  Copyright 2005-2015 The MathWorks, Inc. and Ford Global Technologies, Inc.
    
    properties (Access=protected, AbortSet)
        %HSLICESOLDATA Property is of type 'handle'
        hSliceSolData = [];
        %HSLICEPARETODATA Property is of type 'handle'
        hSliceParetoData = [];
        %HSLICEDISPLAY Property is of type 'handle'
        hSliceDisplay = [];
        %HFOCUSRUN Property is of type 'MATLAB array'
        hFocusRun = [];
        %HFOCUSSOLUTION Property is of type 'MATLAB array'
        hFocusSolution = [];
        %HFOCUSSELECTEDSOLUTION Property is of type 'MATLAB array'
        hFocusSelectedSolution = [];
        %SOLUTIONDISPLAY Property is of type 'MATLAB array'
        SolutionDisplay = [];
    end
    
    methods  % constructor block
        function obj = IndexerView(varargin)
        %IndexerView Constructor for IndexerView
        %  OBJ = IndexerView(PROP, VALUE) constructs a class that edits the
        %  current index into the optimization output.
        
        % Call the inherited constructor
        obj@mbcgui.multiview.View(varargin{ : }); % converted super class constructor call
        
        obj.hSliceSolData = mbcfoundation.memImageStrip;
        obj.hSliceSolData.readFromFile(cgrespath('optim_widget_vert.bmp'), 32);
        obj.hSliceParetoData = mbcfoundation.memImageStrip;
        obj.hSliceParetoData.readFromFile(cgrespath('optim_widget_horz.bmp'), 32);
        obj.hSliceDisplay = xregGui.imagePlayer('Parent', obj.Parent,...
            'Visible', obj.Visible, ...
            'imageSource', obj.hSliceSolData, ...
            'min', 1);
        
        obj.hFocusRun = mbcgui.widget.Spinner('Parent', obj.Parent,...
            'Visible', obj.Visible, ...
            'Max', Inf, ...
            'Min', 1, ...
            'Rule', 'int', ...
            'FontWeight', 'bold', ...
            'Callback', @obj.onChangeRun);
        
        obj.hFocusSolution = mbcgui.widget.Spinner('Parent', obj.Parent,...
            'Visible', obj.Visible, ...
            'Max', Inf, ...
            'Min', 1, ...
            'Rule', 'int', ...
            'FontWeight', 'bold', ...
            'Callback', @obj.onChangeSolution);
        
        obj.hFocusSelectedSolution = mbcgui.widget.Spinner('Parent', obj.Parent,...
            'Visible', obj.Visible, ...
            'Max', Inf, ...
            'Min', 1, ...
            'Rule', 'int', ...
            'FontWeight', 'bold', ...
            'Callback', @obj.onSelectSolution);
        
        hRunItem = xregGui.labelcontrol('parent', obj.Parent,...
            'visible', obj.Visible, ...
            'string', 'Current run:', ...
            'ControlSizeMode', 'absolute', ...
            'ControlSize', 50, ...
            'Gap',0,...
            'LabelSizeMode', 'absolute', ...
            'Labelsize', 80, ...
            'Fontweight', 'bold', ...
            'Control', obj.hFocusRun);
        
        hSolutionItem = xregGui.labelcontrol('parent', obj.Parent,...
            'visible', obj.Visible, ...
            'string', 'Current solution:', ...
            'ControlSizeMode', 'absolute', ...
            'Gap',0,...
            'ControlSize', 50, ...
            'LabelSizeMode', 'absolute', ...
            'Labelsize', 105, ...
            'Fontweight', 'bold', ...
            'Control', obj.hFocusSolution);
        
        hSelectedSolution = xregGui.labelcontrol('parent', obj.Parent,...
            'visible', obj.Visible, ...
            'string', 'Selected solution:', ...
            'LabelSizeMode', 'absolute', ...
            'Labelsize', 105, ...
            'ControlSizeMode', 'absolute', ...
            'ControlSize', 50, ...
            'Fontweight', 'bold', ...
            'Control', obj.hFocusSelectedSolution);
        
        div = xregGui.dividerline('Parent', obj.Parent, ...
            'Visible', obj.Visible, ...
            'Orientation', 'vertical');
        
        hSolutionDisplay = xreggridbaglayout(obj.Parent, ...
            'Position', obj.Position, ...
            'dimension', [1 2], ...
            'colsizes', [175 175], ...
            'gapx', 10, ...
            'elements', {hSolutionItem,hSelectedSolution});
        
        obj.SolutionDisplay = xregcardlayout(obj.Parent,...
            'Position', obj.Position, ...
            'numcards',2);
        attach(obj.SolutionDisplay,hSolutionDisplay,1);
        
        obj.ContentHandle = xreggridbaglayout(obj.Parent, ...
            'Position', obj.Position, ...
            'dimension', [5 4], ...
            'rowsizes', [-1 6 20 6 -1], ...
            'colsizes', [32 2 150 360], ...
            'gapx', 10, ...
            'mergeblock', {[2 4], [1 1]}, ...
            'mergeblock', {[1 5], [2 2]}, ...
            'mergeblock', {[2 4], [4 4]}, ...
            'elements', {[], obj.hSliceDisplay, [], [], [], ...
            div, [], [], [], [], ...
            [], [], hRunItem, [], [], ...
            [], [],obj.SolutionDisplay,[],[]});
        
        ms = obj.MessageService;
        obj.Actions.Actions = ms.Actions.IndexerActions;
        
        % Hook up to the message service if it exists
        if ~isempty(obj.MessageService)
            obj.pPostSetMessageService;
        end
        end  % IndexerView
        
        
        
        
    end  % constructor block
    
    methods  % public methods
        %----------------------------------------
        function str = gettitle(obj) %#ok<MANU>
        %GETTITLE Return string to use as title for view
        %  STR = GETTITLE(OBJ) returns a string that should be used as a title for
        %  the container the view sits in.
        
        str = 'Slice Selection';
        
        end  % gettitle
        
    end  % public methods
    
    methods(Access=protected)
        %----------------------------------------
        function pPostSetMessageService(obj)
        %PPOSTSETMESSAGESERVICE Method that is called when the message service is set
        %  PPOSTSETMESSAGESERVICE(OBJ) is called in response to a new message
        %  service being set in the object.
        
        pPostSetMessageService@mbcgui.multiview.View(obj)
        
        obj.addMessageServiceListener( {...
            'ObjectChanged', ...
            'CurrentFocusChanged', ...
            'SliceDirectionChanged',...
            'SelectedSolutionChanged'}, ...
            {@obj.pUpdate, @obj.pUpdate, @obj.pUpdate, @obj.pUpdate});
        
        % Redraw now
        obj.pUpdate;
        end  % pPostSetMessageService
        
        %----------------------------------------
        function pSetIndex(obj,Type)
        %PSETINDEX Update index from editor
        %  PSETINDEX(OBJ) updates the current index value in the message service
        %  from the editor.
        
        if obj.hasData
            ms = obj.MessageService;
            switch Type
                case 'solution'
                    ms.setCurrentSolution(obj.hFocusSolution.Value);
                case 'run'
                    ms.setCurrentRun(obj.hFocusRun.Value);
            end
        end
        
        end  % pSetIndex
        
        %----------------------------------------
        function pUpdate(obj,~,~)
        %PUPDATE Refresh the view contents
        %  PUPDATE(OBJ) refreshes the index that is being displayed.
        
        IndexMin = 1;
        IndexMax = 1;
        IndexVal = 1;
        ImageSrc = obj.hSliceSolData;
        FocusRun = 0;
        FocusSol = 0;
        SelSolNum = 0;
        SliceIdx = [];
        nSol = 1;
        SolnEnable = 'on';
        SelSolEnable ='on';
        
        AG = obj.Actions(1).Actions;
        SliceActionEnabled = repmat({true}, size(AG.Actions));

        if obj.hasData
            out = obj.MessageService.getOptimOutput;
            switch obj.MessageService.CurrentSliceDirection
                case 'solution'
                    IndexMax = getNumSolutions(out);
                    IndexVal = obj.MessageService.getFocusSolution;
                    
                    SliceIdx = 1;
                    SelSolEnable ='off';
                    
                case 'pareto'
                    IndexMax = getNumRuns(out);
                    ImageSrc = obj.hSliceParetoData;
                    IndexVal = obj.MessageService.getFocusRun;
                    SliceIdx = 2;
                    
                case 'selectedsolution'
                    IndexMax = getNumSolutions(out);
                    IndexVal = obj.MessageService.getFocusSolution;
                    SliceIdx = 4;
                    % Solution index cannot be changed in this mode
                    SolnEnable = 'off';
                    
                case 'weightedsolution'
                    ImageSrc = obj.hSliceParetoData;
                    SliceIdx = 3;
                    
            end
            
            FocusRun = obj.MessageService.getFocusRun;
            FocusSol = obj.MessageService.getFocusSolution;
            
            if FocusRun>0
                SelSolNum = getSelectedSolutionNumber(out,FocusRun);
            else
                SelSolNum=0;
            end
            
            
            nR = getNumRuns(out);
            nSol = getNumSolutions(out);
            if nR==1 && nSol>1
                % Disable Solution view
                SliceActionEnabled{1} = false;
                
            elseif nSol==1
                % Disable Pareto view and Selected Solution view
                SliceActionEnabled{2} = false;
                SliceActionEnabled{4} = false;
            end
            
        end
        
        if FocusRun>0
            set(obj.hFocusRun, ...
                'Enable','on',...
                'Min', 1, 'Max', nR, ...
                'Value', FocusRun);
        else
            set(obj.hFocusRun, ...
                'Enable','off',...
                'Min', 0, 'Max', 0, ...
                'Value', 0);
        end
        
        set(obj.hSliceDisplay, 'ImageSource', ImageSrc, ...
            'Min', IndexMin, 'Max', IndexMax, 'Value', IndexVal);
        
        % Update current index display
        if nSol>1
            if FocusSol>0
                set(obj.hFocusSolution, ...
                    'Enable',SolnEnable,...
                    'Min', 1, 'Max', nSol, ...
                    'Value', FocusSol);
            else
                set(obj.hFocusSolution, ...
                    'Enable','off',...
                    'Min', 0, 'Max', 0, ...
                    'Value', 0);
            end
            
            if SelSolNum>0
                set(obj.hFocusSelectedSolution, 'Value', SelSolNum,...
                    'Min',1,'Max',nSol,'Enable',SelSolEnable);
            else
                set(obj.hFocusSelectedSolution, 'Value', 0,...
                    'Min',0,'Max',0,'Enable','off');
            end
            
            set(obj.SolutionDisplay ,'CurrentCard',1);
        else
            
            set(obj.SolutionDisplay ,'CurrentCard',2);
        end
        
        % Update status of actions that indicate slice direction
        SelectedMode = repmat({false}, size(AG.Actions));
        SelectedMode(SliceIdx) = {true};
        set(AG.Actions, {'Selected'}, SelectedMode, {'Enabled'}, SliceActionEnabled);
        
        end  % pUpdate
        
        function onSelectSolution(obj,h,~)
        ms = obj.MessageService;
        
        if ms.hasFocusIndex
            hOut = ms.getOptimOutput;
            hOut = setSelectedSolutionNumber(hOut, ms.getFocusRun, h.Value);
            ms.setOptimOutput(hOut, {'SelectedSolutionChanged','CurrentFocusChanged'});
        end
        end
        
        function onChangeRun(obj,~,~)
        obj.pSetIndex('run');
        end
        function onChangeSolution(obj,~,~)
        obj.pSetIndex('solution');
        end
        
       
    end
    
end  % classdef