www.gusucode.com > mbcview 工具箱matlab源码程序 > mbcview/@cgddnode/view.m

    function View=view(nd,cgh,View)
%VIEW
%
%  View=view(nd,cgh,View)

%  Copyright 2000-2010 The MathWorks, Inc. and Ford Global Technologies, Inc.



d=cgh.getViewData;
pN = cgh.CurrentNode;
pS = cgh.CurrentSubItem;

ctrlen=repmat({'off'},6,1);  % default enable setting for each control
menuen=repmat({'off'},4,1);  % default enable setting for each menu
hndls=d.Handles;
ON_SET={'on'};
OFF_SET={'off'};

if (pS~=0)
    S = pS.info;
    ctrlen(1:2)=ON_SET;
    menuen(1)=ON_SET;
    set(hndls.Name,'BarTitle',getname(S));
    set(hndls.Descr.Control,'String',getdescription(S));
    set(hndls.Alias.Control,'String',getaliasstring(S));
    
    if isconstant(S)
        set([hndls.Min.Control;hndls.Max.Control],'Max',1,'Min',-1,'Value',0);
        constval = getnomvalue(S);
        set(hndls.Const.Control,'Min', -inf, 'Max', inf, 'Value',constval);
        set(hndls.Func.Control,'String','');
        menuen(4)=ON_SET;
        menuen(2)=ON_SET;
        ctrlen(5)=ON_SET;
    else
        ctrlen(3:4)=ON_SET;
        menuen(3)=ON_SET;
        R = getrange(S);
        set(hndls.Min.Control,'Max',R(2)-eps, ...
            'Min',-inf, ...
            'Value',R(1));
        set(hndls.Max.Control,'Min',R(1)+eps, ...
            'Max',inf, ...
            'Value',R(2));
        set(hndls.Const.Control, 'Min', R(1)+eps, ...
            'Max', R(2)-eps, ...
            'Value', get(S, 'setpoint'));
        if issymvalue(S)
            ctrlen(6)=ON_SET;
            menuen(4)=ON_SET;
            set(hndls.Func.Control,'String',getequation(S));
        else
            ctrlen(5)=ON_SET;
            menuen(2)=ON_SET;
            set(hndls.Func.Control,'String','');
        end
    end
else
    % No selected item
    % set blank strings
    set(hndls.Name,'BarTitle','');
    set([hndls.Alias.Control;hndls.Descr.Control;hndls.Func.Control],'String','');
    set([hndls.Min.Control;hndls.Max.Control],'Min',1,'Max',1,'Value',0);
    set(hndls.Const.Control,'Value',0);
end

set([hndls.Alias;hndls.Descr;hndls.Min;hndls.Max;hndls.Const;hndls.Func],{'Enable'},ctrlen);
set([hndls.Tools;hndls.MakeFormula;hndls.MakeConst;hndls.MakeVar],{'Enable'},menuen);
set([hndls.ContextChg;hndls.ContextMakeFor;hndls.ContextMakeCon;hndls.ContextMakeVar],{'Enable'},menuen);

% If the variable list is empty, add a status message to inform the user what to do
if isempty(listptrs(pN.info))
    MsgID = cgh.addStatusMsg('Use the toolbar buttons to add a variable, or import variables from a variable dictionary (File -> Import)');
    View.StatusMsgID = MsgID;
end