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

    classdef AcceptView < mbcgui.multiview.View
    %cageview.optimoutput.AcceptView class
    %   cageview.optimoutput.AcceptView extends mbcgui.multiview.View.
    %
    %    cageview.optimoutput.AcceptView 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.AcceptView 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)
        %HACCEPTCTRL Property is of type 'MATLAB array'
        hAcceptCtrl = [];
        %HEXITFLAGICON Property is of type 'MATLAB array'
        hExitFlagIcon = [];
        %LOADEDEXITFLAG Property is of type 'double'
        LoadedExitFlag
    end
    
    methods  % constructor block
        function obj = AcceptView(varargin)
        %AcceptView Constructor for AcceptView
        %  OBJ = AcceptView(PROP, VALUE) constructs a class that displays the
        %  "Acceptable" status of the currently selected solution.
        
        % Call the inherited constructor
        obj@mbcgui.multiview.View(varargin{ : }); % converted super class constructor call
        
        obj.hAcceptCtrl = uicontrol('Parent', obj.Parent, ...
            'Visible', obj.Visible, ...
            'String', 'Accept', ...
            'Style', 'checkbox', ...
            'Callback', {@i_editAccept, obj});
        
        obj.hExitFlagIcon = mbcgui.widget.Image('Parent', obj.Parent, ...
            'Visible', obj.Visible);
        obj.LoadedExitFlag = NaN;
        
        obj.ContentHandle = xreggridbaglayout(obj.Parent, ...
            'Position', obj.Position, ...
            'dimension', [5 4], ...
            'rowsizes', [-1 2 12 2 -1], ...
            'colsizes', [12 5 60 -1], ...
            'mergeblock', {[2 4], [3 3]}, ...
            'elements', {[], [], obj.hExitFlagIcon, [], [], ...
            [], [], [], [], [], ...
            [], obj.hAcceptCtrl});
        
        % Hook up to the message service if it exists
        if ~isempty(obj.MessageService)
            obj.pPostSetMessageService;
        end
        end  % AcceptView
        
    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 = 'Accept Status';
        
        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)
        
        UpdateFcn = {@i_update, obj};
        
        obj.addMessageServiceListener( {...
            'ObjectChanged', ...
            'AcceptableChanged', ...
            'CurrentFocusChanged', ...
            'SliceDirectionChanged'}, ...
            {UpdateFcn, UpdateFcn, UpdateFcn, UpdateFcn});
        
        % Redraw now
        obj.pUpdate;
        end  % pPostSetMessageService
        
        %----------------------------------------
        function pSetAccept(obj)
        %PSETACCEPT Update accept status from editor
        %  PSETACCEPT(OBJ) updates the current acceptable value in the output
        %  object from the editor.
        
        if obj.hasData
            ms = obj.MessageService;
            out = obj.MessageService.getOptimOutput;
            Sol = obj.MessageService.getFocusSolution;
            Run = obj.MessageService.getFocusRun;
            
            if Sol>0 && Run>0
                V = get(obj.hAcceptCtrl, 'Value');
                out = setAcceptableToUser(out, Run, Sol, logical(V));
                ms.setOptimOutput(out, 'AcceptableChanged');
            end
        end
        
        end  % pSetAccept
        
        %----------------------------------------
        function pUpdate(obj)
        %PUPDATE Refresh the view contents
        %  PUPDATE(OBJ) refreshes the acceptable value that is being displayed.
        
        EF = NaN;
        Accept = false;
        IsEnabled = false;
        if obj.hasData
            out = obj.MessageService.getOptimOutput;
            Sol = obj.MessageService.getFocusSolution;
            Run = obj.MessageService.getFocusRun;
            
            if Sol>0 && Run>0
                EF = getExitFlag(out, Run, Sol);
                Accept = isAcceptable(out, Run, Sol);
                IsEnabled = true;
            elseif Sol>0
                % This occurs when looking at weighted view.  There is not a
                % sensible Acceptable value.  The exit flag can be taken as the
                % worst case of all the runs.
                EF = min(getExitFlag(out, ':', Sol));
            end
        end
        
        % Set checkbox value
        if IsEnabled
            set(obj.hAcceptCtrl, 'Enable', 'on', 'Value', Accept);
        else
            set(obj.hAcceptCtrl, 'Enable', 'off', 'Value', Accept);
        end
        
        % Set exit flag icon
        if EF~=obj.LoadedExitFlag
            if isnan(EF)
                im = '';
                TT = '';
            else
                TT = sprintf('Exit flag: %d', EF);
                if EF>0
                    im = 'optimexitOK.bmp';
                elseif EF==0
                    im = 'optimexitWarn.bmp';
                else
                    im = 'optimexitError.bmp';
                end
            end
            set(obj.hAcceptCtrl, 'TooltipString', TT);
            set(obj.hExitFlagIcon, 'ImageFile', im, 'TooltipString', TT);
            obj.LoadedExitFlag = EF;
        end
        
        end  % pUpdate
        
    end
end  % classdef

function i_editAccept(~, ~, obj)
obj.pSetAccept;
end  % i_editAccept

function i_update(~, ~, obj)
obj.pUpdate;
end  % i_update