www.gusucode.com > mbcdesign 工具箱 matlab 源码程序 > mbcdesign/@conellipsoid/generateEditorPages.m

    function hInfo = generateEditorPages(obj, hPageGroup) %#ok<INUSL>
%GENERATEEDITORPAGES Generate a set of dialog pages for constraint editing 
%
%  HINFO = GENERATEEDITORPAGES(OBJ, HPAGEGROUP) returns an arrray of
%  DialogPageInfo objects that describe a set a of panels for editing the
%  constraint.

%  Copyright 2005-2015 The MathWorks, Inc. and Ford Global Technologies, Inc.


hInfo = mbcgui.dialog.PageInfo( ...
    'PageGroup', hPageGroup, ...
    'Name', 'N-D Editor', ...
    'PreferredWidth', 500, ...
    'PreferredHeight', 250, ...
    'HelpHandler', 'mv_helptool', ...
    'HelpCode', 'xreg_ConEllipsoid', ...
    'CreateCallback', @i_createlyt);




function i_createlyt(hInfo, ~)

hParent = hInfo.Parent;
hGroup = hInfo.PageGroup;

% Center point table
TableLabel = xreguicontrol('Parent',  hParent, ...
    'Style', 'text', ...
    'HorizontalAlignment', 'left', ...
    'String', 'Center point:', ...
    'HitTest', 'off', ...
    'Enable', 'inactive');
ud.hCenterTable = mbcwidgets.VariableEditorTable( ...
    'Parent', hParent, ...
    'ColumnWidth', 95, ...
    'NameColumnHeader', 'Factor', ...
    'ValueChangedCallback', {@i_centeredit, hInfo});

TableLabel2 = xreguicontrol('Parent',  hParent, ...
    'Style', 'text', ...
    'HorizontalAlignment', 'left', ...
    'String', 'Ellipsoid form matrix:', ...
    'HitTest', 'off', ...
    'Enable', 'inactive');
P = com.mathworks.toolbox.mbc.gui.peer.Symmetric2DTablePeer;
ud.hFormTable = mbcwidgets.Table2D(P, ...
    'Parent', hParent, ...
    'Editable', true, ...
    'ValueChangedCallback', {@i_formedit, hInfo});
P.setCornerAsBlank;
    
lyt = xreggridbaglayout(hParent, ...
    'dimension', [2 2], ...
    'rowsizes', [15 -1], ...
    'colsizes', [150 -1], ...
    'gapy', 2, ...
    'gapx', 20, ...
    'elements', {TableLabel, ud.hCenterTable, ...
    TableLabel2, ud.hFormTable});

ud.ObjList = event.listener(hGroup, 'ObjectChanged', @(h,evt) i_update(hInfo));

hInfo.UserData = ud;

i_updatecentertable(hInfo);
i_updateformtable(hInfo);

hInfo.setUI(lyt);


function i_update(hInfo)
i_updatecentertable(hInfo);
i_updateformtable(hInfo);


function i_updatecentertable(hInfo)
obj = hInfo.getObject;
ud = hInfo.UserData;
cf = getActiveFactors(obj);
ud.hCenterTable.setVariables(getNames(cf), ones(1,length(cf)), num2cell(getCenter(obj)));


function i_updateformtable(hInfo)
obj = hInfo.getObject;
ud = hInfo.UserData;
cf = getActiveFactors(obj);
ud.hFormTable.Peer.setData(getDistanceMatrix(obj), getNames(cf), getNames(cf));


function i_centeredit(~, ~, hInfo)
obj = hInfo.getObject;
ud = hInfo.UserData;
vals = [ud.hCenterTable.VariableValues{:}];
obj = setCenter(obj, vals);
i_updateandignore(hInfo, obj);


function i_formedit(~, evt, hInfo)
obj = hInfo.getObject;
W = getDistanceMatrix(obj);
W(evt.data.Rows, evt.Data.Columns) = evt.Data.NewValue;

% Make upper triangle of W  the same as the lower triangle
Wnew = tril(W);
Wnew = Wnew + tril(Wnew, -1).';
try
    obj = setDistanceMatrix(obj, Wnew);
    i_updateandignore(hInfo, obj);
catch ME
    % Form matrix was not appropriate
    [ID, comp, msg] = mbcGetLastError(ME);
    if strcmp(comp, 'conellipsoid') && strcmp(ID, 'InvalidArgument')
        % W matrix is bad
        h = errordlg(msg, 'MCB Toolbox', 'modal');
        waitfor(h);
        i_updateformtable(hInfo);
    else
        rethrow(ME);
    end
end


% Update the object and prevent the change event from firing here
function i_updateandignore(hInfo, obj)
ud = hInfo.UserData;
ud.ObjList.Enabled = false;
hInfo.updateObject(obj);
ud.ObjList.Enabled = true;