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

    function View = view(nd, cgh, View)
%VIEW
%
%  VIEWDATA = VIEW(NDE, CGBH, VIEWDATA)

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


% first setup the model description text, and enable menus etc
i_ModelDescription( nd, View );

% view table info
HasFillableTable = iViewTableInfo(nd,View);
iFillDetails(nd,View)
% refresh the history listview
View = pHistoryManager( address(nd), View, 'drawlist' );

% and also clean out the optim managers
View = i_OptManagerRefresh( nd, View,HasFillableTable );


%------------------------------------------------------------
function i_ModelDescription(nd,d)
%------------------------------------------------------------
% This function constructs the models description string, and sets the
% ModText controls to show this.  Also enables/disables menus and other
% controls based on whether there is a moels or not.

pF = getdata(nd);
sf = pF.info;

eqPtr=get(sf , 'equation');

% push all this into the correct places
if isobject(eqPtr) && ~isempty(eqPtr)
    d.Handles.equationview.setExpression(eqPtr.info, name(nd));
else
    d.Handles.equationview.setExpression([], '');
end



%------------------------------------------------------------
function d = i_OptManagerRefresh(nd, d,HasFillableTable)
%------------------------------------------------------------

pF = getdata(nd);

% kill the old optmgrs since the situation may have changed
d.InitialisationManager  = [];

toolbarButtons = [d.Handles.Toolbar.Initialise,...
    d.Handles.Toolbar.Fill];
menuItems = [d.Handles.InitialiseMenu,...
    d.Handles.FillMenu];

% do not recreate the optmgrs here, just check for equations and models
if isempty(pF.get('equation'))
    set(toolbarButtons, 'Enable', 'off');
    set(menuItems, 'Enable', 'off');
else
    set(toolbarButtons, 'Enable', 'on');
    set(menuItems, 'Enable', 'on');
end

cgp = root(nd);
if ~HasFillableTable || (isempty(cgp.getmodels) && isempty(getFillDatasetList(info(pF),cgp)))
    EnableFill = 'off';
else
    EnableFill = 'on';
end

set(d.Handles.FillMenu,'Enable',EnableFill)
set(d.Handles.AddFillMenu,'Enable',EnableFill)
set(d.Handles.Toolbar.Fill,'Enable',EnableFill)
set(d.Handles.FillActions{1},'Enable',EnableFill)





function HasFillableTable = iViewTableInfo(nd,View)

pFeat =getdata(nd);
pAll= unique(getAllInputs(pFeat.info));
HasFillableTable = false;
if ~isempty(pAll)
    % find tables in feature expression
    isTab= parrayeval(pAll,@istable,{},@false);
    TabPtrs= pAll(isTab);
    TableData = cell(length(TabPtrs),3);
    IconData = cell(length(TabPtrs),1);
    
    HasUninitalizedTable = false;
    for i=1:length(TabPtrs)
        % build up table data [name, comment, Date]
        LT = TabPtrs(i).info;
        TableData{i,1}= getname(LT);
        IconData{i} = iconfile(LT);
        Locks= get(TabPtrs(i).info,'vlocks');
        mem = get(LT,'Memory');
        if isempty(LT)
            % table needs to be initialized in cal manager
            TableData{i,2}= 'Uninitialized';
            HasUninitalizedTable = true;
        elseif ~isempty(Locks) && all(Locks(:))
            % table locked
            TableData{i,2}= 'Locked';
        else
            % last history
            TableData{i,2} = mem(end).Information;
            HasFillableTable = true;
        end
        TableData{i,3} = mem(end).Date;
    end
    HasFillableTable = HasFillableTable && ~HasUninitalizedTable;
    View.Handles.TableInfo.setData( TableData,IconData );
    View.Handles.TableInfo.UserData = TabPtrs;
    
    % adjust width for scrollbars
    pos = View.Handles.TableInfo.Position;
    H = pos(4)-2;
    W = pos(3)-3;
    
    if ((length(TabPtrs)+1)*17) > H
        SCROLLBAR_WIDTH = javax.swing.UIManager.get('ScrollBar.width');
        % Make room for the vertical scrollbar
        W = W - SCROLLBAR_WIDTH;
    end
    
    View.Handles.TableInfo.ColumnWidths = [150,max(W-270,150),120];

else
    % no equation expression
    View.Handles.TableInfo.setData( cell(0,3),cell(0,1));
    View.Handles.TableInfo.UserData = mbcpointer(0,1);
end

function iFillDetails(nd,View)
pFeat =getdata(nd);
fill = pFeat.get('cgsimfill');
if isempty(fill)
    fill = cgsimfill.Feature.empty(1,0);
end
FillTableData = detailsTable(fill);
View.Handles.FillDetails.setData( FillTableData );

pos = View.Handles.FillDetails.Position;
H = pos(4)-2;
W = pos(3)-4;

if ((length(fill)+1)*17) > H
    SCROLLBAR_WIDTH = javax.swing.UIManager.get('ScrollBar.width');
    % Make room for the vertical scrollbar
    W = W - SCROLLBAR_WIDTH;
end

View.Handles.FillDetails.ColumnWidths = [max(W-520,200),150,150,100,120];


if isempty(fill)
    cellfun(@(h) set(h,'Enable','off'),View.Handles.FillExists)
else
    % select last row and enable all
    View.Handles.FillDetails.SelectedRows = length(fill);
    cellfun(@(h) set(h,'Enable','on'),View.Handles.FillExists)
end