www.gusucode.com > mbctools 工具箱 matlab 源码程序 > mbctools/@mdevtestplan/private/DataCardThree.m

    function lyt=DataCardThree(fH, iFace, LocalData)
%DATACARDTHREE wizard pane for altering response model settings
%
%  lyt=DataCardThree(T,fH, iFace) creates a layout for selecting the
%  response model type as part of the data selection wizard. 

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


% get up-to-date object
if isa(fH, 'xregcontainer')
    lyt = fH;
    ud = get(lyt, 'UserData');
    i_setvalues(ud);
else
    % put signal chooser layout is inside a layoutlayout
    [lyt,ud] = i_createlyt(fH,iFace,LocalData);

    infoStr = 'Choose responses to be modeled. You can also change model types.';
    lyt = xreglayerlayout( fH,...
        'Elements', {mbcgui.container.InfoPane( 'Parent', fH,...
        'Visible', 'off',...
        'Title', 'Response Models',...
        'InfoString', infoStr,...
        'Center', lyt )} );
    % store pointer to testplan
    % next and finish routine
    ud.nextFcn = @iCardNext;
    ud.finishFcn = @iCardFinish;
end

% data editor
set(ud.DataEditor,'Value',ud.ModelData.OpenDataEditor)

T= info(ud.pointer);
% must build some responses before proceeding
feval(iFace.setFinishButton, true);
feval(iFace.setNextButton, ~isExpData(T.DesignDev));
set(lyt, 'UserData', ud);


%--------------------------------------------------------------------------
function [nextCardID, LocalData] = iCardNext(ud,~)
% next card for wizard


% local data for next card
LocalData.ModelData = ud.ModelData; 
LocalData.pointer = ud.pointer;        

% next card
nextCardID = @DataCardFour;

%--------------------------------------------------------------------------
function iCardFinish(~, ~)
% finish wizard


%--------------------------------------------------------------------------
function [lyt,ud] = i_createlyt(figh,iFace,ud)
% main layout creation routin

T = info(ud.pointer);

SC = xregGui.SystemColorsDbl;

% listbox of data variables
ytxt = uicontrol('Parent',figh,...
    'Style','text',...
    'Visible', 'off', ...
    'HorizontalAlignment','left',...
    'String','Unused data signals:');
ud.ylist=uicontrol('Parent',figh,...
    'Style','listbox',...
    'Visible', 'off', ...
    'Tag', 'variables',...
    'BackgroundColor',SC.WINDOW_BG);
ylyt= xreggridbaglayout(figh,...
    'dimension',[2 1],...
    'rowsizes', [15 -1], ...
    'gapy', 2, ...
    'elements',{ytxt,ud.ylist});

% listbox of responses
rtxt = uicontrol('Style','text',...
    'Parent',figh,...
    'Visible', 'off', ...
    'HorizontalAlignment','left',...
    'String','Responses:');
ud.rlist = uicontrol('Style','listbox',...
    'Parent',figh,...
    'Visible', 'off', ...
    'Tag', 'responses',...
    'BackgroundColor',SC.WINDOW_BG,...
    'Callback',{@i_SelectModel,iFace});


% Model Setup 
if strcmpi(type(T),'two-stage')
    [ud,ModelLyt,ModelLytSize]= iTwoStageSetup(ud,figh,iFace);
else
    [ud,ModelLyt,ModelLytSize]= iOneStageSetup(ud,figh,iFace);
end

ud.Boundary= xreguicontrol('Parent', figh,...
    'Visible', 'off', ...
    'Style', 'checkbox',...
    'Tag','BoundaryModel',...
    'HorizontalAlignment','right',...
    'Callback',{@iBoundary,ud.ModelData},...
    'Value',ud.ModelData.Boundary,...
    'String', 'Fit boundary model');
    

rlyt = xreggridbaglayout(figh, ...
    'dimension', [6 1], ...
    'rowsizes', [15 2 -1 10 ModelLytSize,15], ...
    'elements', {rtxt, [], ud.rlist, [], ModelLyt,ud.Boundary});

% buttons between the lists match/add/delete
ud.SelBtn = xregGui.iconuicontrol('Parent',figh,...
    'Visible', 'off', ...
    'imageFile',[xregrespath,'\leftarrow.bmp'],...
    'transparentColor', [255 255 0],...
    'ToolTip','Match data signal to response',...
    'Callback',{@i_Select,iFace});
ud.AddBtn = uicontrol('Parent',figh,...
    'Visible', 'off', ...
    'Style','pushbutton',...
    'String','< Add',...
    'TooltipString','Add data signal as new response',...
    'Callback',{@i_AddResponse,iFace});
ud.DelBtn = uicontrol('Parent',figh,...
    'Style','pushbutton',...
    'Visible', 'off', ...
    'String','Delete',...
    'TooltipString','Delete selected response',...
    'Callback',{@i_DeleteResponse,iFace});

% Main Layout
mainlyt = xreggridbaglayout(figh,...
    'dimension',[5 3],...
    'gapy', 5, ...
    'gapx', 10, ...
    'rowsizes', [30 80 25 25 -1], ...
    'colsizes', [-1 80 -1], ...
    'mergeblock', {[1 5], [1 1]}, ...
    'mergeblock', {[1 5], [3 3]}, ...
    'elements', {rlyt, [], [], [], [], [], ud.SelBtn, ud.AddBtn, ud.DelBtn [], ylyt});

ud.DataEditor = uicontrol('Parent', figh,...
    'Visible', 'off', ...
    'Style', 'checkbox',...
    'HorizontalAlignment','right',...
    'Value',1,...
    'Callback',{@iDoOpenEditor,ud.ModelData},...
    'String', 'Open Data Editor on completion');

lyt= xreggridbaglayout(figh, ...
    'border',[7 0 7 10],...
    'dimension', [2, 3], ...
    'rowsizes', [-1 20], ...
    'colsizes', [240 80 -1], ...
    'gapy', 10, ...
    'gapx',10,...
    'mergeblock', {[1 1], [1 3]}, ...
    'elements',{mainlyt [] ,[],[], [],ud.DataEditor});

% initialise values
i_setvalues(ud);

%--------------------------------------------------------------------------
function [ud,frame,sz]= iOneStageSetup(ud,figh,iFace)

% ui for one-stage model setup
globalbtn = uicontrol('Parent',figh,...
    'Visible', 'off', ...
    'Style','pushbutton',...
    'String','Set Up...', ...
    'Callback',{@i_setModel,iFace});
ud.globalMod = xregGui.labelcontrol('Parent', figh, ...
    'Visible', 'off', ...
    'LabelSize', 90, ...
    'LabelSizeMode', 'absolute', ...
    'ControlSize', 60, ...
    'Control', globalbtn);
globaltxt = xregGui.labelcontrol('Parent', figh, ...
    'Visible', 'off', ...
    'String', 'Model:', ...
    'LabelSize', 70, ...
    'LabelSizeMode', 'absolute', ...
    'ControlSize', 1, ...
    'ControlSizeMode', 'relative', ...
    'Control', ud.globalMod);

frame = globaltxt;
sz = 20;

ud.SetBtns = globalbtn;
ud.gsetup = globalbtn;

%--------------------------------------------------------------------------
function [ud,frame,sz]= iTwoStageSetup(ud,figh,iFace)

% twostage option layouts
% the frame and controls for changing local, global and datum models
SC = xregGui.SystemColorsDbl;
frame = mbcgui.container.layoutpanel(...
    'Parent', figh,...
    'Visible', 'off', ...
    'BorderType', 'etchedin', ...
    'title','Model');
localbtn = uicontrol('Parent',frame,...
    'Style','pushbutton',...
    'String','Set Up...',...
    'Callback',{@i_setLocal,iFace});
ud.localMod = xregGui.labelcontrol('Parent', frame, ...
    'LabelSize', 90, ...
    'LabelSizeMode', 'absolute', ...
    'ControlSize', 60, ...
    'Control', localbtn);
localtxt = xregGui.labelcontrol('Parent', frame, ...
    'String', 'Local model:', ...
    'LabelSize', 70, ...
    'LabelSizeMode', 'absolute', ...
    'ControlSize', 1, ...
    'ControlSizeMode', 'relative', ...
    'Control', ud.localMod);

globalbtn = uicontrol('Parent',frame,...
    'Style','pushbutton',...
    'String','Set Up...', ...
    'Callback',{@i_setGlobal,iFace});
ud.globalMod = xregGui.labelcontrol('Parent', frame, ...
    'LabelSize', 90, ...
    'LabelSizeMode', 'absolute', ...
    'ControlSize', 60, ...
    'Control', globalbtn);
globaltxt = xregGui.labelcontrol('Parent', frame, ...
    'String', 'Global model:', ...
    'LabelSize', 70, ...
    'LabelSizeMode', 'absolute', ...
    'ControlSize', 1, ...
    'ControlSizeMode', 'relative', ...
    'Control', ud.globalMod);

ud.dtmpop=uicontrol('Parent',frame,...
    'Style','popupmenu',...
    'String',{'None','Maximum','Minimum','Link to R1 datum'},...
    'BackgroundColor',SC.WINDOW_BG,...
    'UserData',1, ...
    'Callback',{@i_dtmmodel,iFace});
dtmtxt = xregGui.labelcontrol('Parent', frame, ...
    'String', 'Datum:', ...
    'LabelSize', 70, ...
    'LabelSizeMode', 'absolute', ...
    'ControlSize', 90, ...
    'Control', ud.dtmpop);

grd = xreggridbaglayout(frame, ...
    'dimension', [3 1], ...
    'gapy', 5, ...
    'rowsizes', [20 20 20], ...
    'border', [10 10 10 5], ...
    'elements', {localtxt, dtmtxt, globaltxt});
set(frame, 'LayoutComponent', {grd});

sz = 105;

ud.SetBtns = [localbtn;globalbtn;ud.dtmpop];
ud.gsetup = globalbtn;

%--------------------------------------------------------------------------
function i_setvalues(ud,sel)
T= ud.pointer.info;

TestData=  T.DataLink.info;
VarNames= get(TestData,'Name');
VarUnits= get(TestData,'Units');

Xnames= factors(T);
% remove X variables to get a list of possible response variables 
[VarNames,ind]=setdiff(VarNames,Xnames);
VarUnits= VarUnits(ind);
selVar = min(1,length(VarNames));
set(ud.ylist,'String',VarNames,'Value',selVar)
if isempty(VarNames)
   set(ud.AddBtn,'Enable','off')
else
    set(ud.AddBtn,'Enable','on')
end

if isempty(VarNames)
   T.Responses = {}; 
   xregpointer(T);
end

% make list of response models
rlist= cell(1,length(T.Responses));
NotFnd=1;
for i=1:length(T.Responses)
    m= T.Responses{i};
    VarInd= find(strcmp(varname(m),VarNames));
    if isempty(VarInd)
        % can't find variable - choose one
        m= setResponse(m,VarNames{NotFnd},VarUnits{NotFnd},varname(m));
        T.Responses{i}= m;
        pointer(T);
        NotFnd= min(NotFnd+1,length(VarNames));
    else
        % update units
        m= setResponse(m,VarNames{VarInd},VarUnits{VarInd});
    end
        
    rlist{i}= ResponseLabel(m);
end

if nargin<2
    % choose first response in list by default
    sel= min(1,length(T.Responses));
end
set(ud.rlist,'String',rlist,'Value',sel);

if sel
    % enable set model, deletion and selection buttons
    set(ud.DelBtn,'Enable','on');
    set(ud.SetBtns,'Enable','on');
    set(ud.SelBtn,'Enable','on');
    i_SelectModel(ud)
else
    % no responses: disable set buttons
    set(ud.SetBtns,'Enable','off');
    set(ud.DelBtn,'Enable','off');
    set(ud.SelBtn,'Enable','off');
end


%--------------------------------------------------------------------------
function i_SelectModel(h,~,iFace)


if nargin==1
    % can be called with one argument for convenience
    ud = h;
else
    % from callback
    ud = feval(iFace.getCardUserdata);
end


T= ud.pointer.info;
ind = get(ud.rlist,'Value');
if isempty(ind) || ind==0
   return 
end

m= T.Responses{ind};

if isPointByPoint(m)
    set(ud.globalMod,'String',getType( get(m,'Local')))
elseif isa(m,'xregtwostage')
    % update two-stage setup uis
    iSetTwostage(m,T,ud,ind)
else
    % one-stage model
    set(ud.globalMod,'String',name(m))
end

VarInd= find(strcmp(varname(m),get(ud.ylist,'String')));
if ~isempty(VarInd)
    % select data list to match response
    set(ud.ylist,...
        'ListboxTop',max(1,VarInd-5),...
        'Value',VarInd);
end


%--------------------------------------------------------------------------
function iSetTwostage(m,T,ud,ind)
% update two-stage setup uis

% set up string in Datum popupmenu
DatumTypes = {'None','Maximum','Minimum','R1 datum'};
if ind==1
    % can't have link to R1 for R1!
    DatumTypes = DatumTypes(1:end-1);
elseif ~get(T.Responses{1},'datumtype')
    % No datum defined for R1 so can't have link;
    DatumTypes = DatumTypes(1:end-1);
else
    DatumTypes{end}= sprintf('%s datum',varname(T.Responses{1}));
end
set(ud.dtmpop,'String',DatumTypes);

% stages
L = get(m,'local');

% datum model
if permitsDatum(L)
    set(ud.dtmpop,'Enable','on');
else
    set(L,'DatumType',0);
    set(ud.dtmpop,'Value',1,'Enable','off');
end
set(ud.localMod,'String',name(L))

G = get(m,'global');
isSame= 0;
if ~isempty(G)
    n1= name(G{1});
    isSame= 1;
    for i=2:length(G)
        isSame = isSame && strcmp(n1,name(G{i}));
    end
    set(ud.gsetup,'Enable','on')
else
    % no global models
    set(ud.gsetup,'Enable','off')
end

if isSame
    % only display name for gobal model if they are all the same
    set(ud.globalMod,'String',n1)
else
    set(ud.globalMod,'String','')
end

set(ud.dtmpop,...
    'Value',get(m,'DatumType')+1,...
    'UserData',get(m,'DatumType')+1);



%--------------------------------------------------------------------------
function i_dtmmodel(~,~,iFace)
% update datum type

ud = feval(iFace.getCardUserdata);
T= ud.pointer.info;
ind= get(ud.rlist,'Value');
m= T.Responses{ind};

newval=get(ud.dtmpop,'Value');
DatumType = newval - 1;
OldDatumType= get(m,'datumtype');
if OldDatumType ~= DatumType
    % change to datum type

    DatumModel= get(m,'datum');
    if DatumType && ~OldDatumType
        % need a default global model for the datum model
        DatumModel = getModel(T.DesignDev(end));
    elseif ~DatumType
        % no datum mpdel
        DatumModel = 0;
    end

    L= get(m,'local');
    if DatumType && ~permitsDatum(L)
        % make local model which permits a datum
        L= copymodel(L,localpoly);
    end
    % datum type and update twostage model
    set(L,'DatumType',DatumType);
    set(m,'Local',L);
    set(m,'Datum',DatumModel);
    if ind==1 && ~(DatumType==1 || DatumType==2)
        % datum removed from first response so have to remove datumlinks
        for i=2:length(T.Responses)
            if get(T.Responses{i},'DatumType')==3
                % remove datumlink
                L= get(T.Responses{i},'Local');
                set(L,'DatumType',0);
                T.Responses{i}= set(T.Responses{i},'Local',L);
            end
        end
    end

    % update testplan
    T.Responses{ind}= m;
    xregpointer(T);
end


%--------------------------------------------------------------------------
function i_setLocal(~,~,iFace)
% setup local model for current response

ud = feval(iFace.getCardUserdata);
T= ud.pointer.info;

% find response
ind= get(ud.rlist,'Value');
TS= T.Responses{ind};

L= get(TS,'local');
XNames= factors(T);
xL= T.DataLink.info(:,XNames{1});

% call main setup dialog for local models
[L,OK]= gui_localmodsetup(L,'figure',isEquiSpaced(xL(:,1)),nfactors(L));
if OK
    set(TS,'Local',L);

    if permitsDatum(L)
        set(ud.dtmpop,'Enable','on');
    else
        set(L,'DatumType',0);
        set(ud.dtmpop,'Value',1,'Enable','off');
    end

    set(ud.localMod,'String',name(L))
    % get default global model from testplan
    GM = getModel(T.DesignDev(end));
    % model type or num response features have changed
    TS= xregtwostage(L,GM);
    T.Responses{ind}= TS;
    xregpointer(T);
    if numfeats(L)>0
        set(ud.gsetup,'Enable','on')
    else
        % no response features
        set(ud.gsetup,'Enable','off')
    end
end

%--------------------------------------------------------------------------
function i_setGlobal(~,~,iFace)
% set up global model for current response

ud = feval(iFace.getCardUserdata);
T= ud.pointer.info;

% find current response
ind= get(ud.rlist,'Value');
TS= T.Responses{ind};

GM= get(TS,'baseglobal');

if ~isempty(GM)
    % there may be no global models
    [m,OK]= gui_ModelSetup(GM);
    if OK
        % rebuild the twostage model
        L= get(TS,'local');
        TS= xregtwostage(L,m);
        T.Responses{ind}= TS;
        xregpointer(T);
        set(ud.globalMod,'String',name(m));
    end
end


%--------------------------------------------------------------------------
function i_setModel(~,~,iFace)
% swtup for a one-stage model

ud = feval(iFace.getCardUserdata);
T= ud.pointer.info;

% get current response
ind= get(ud.rlist,'Value');
m= T.Responses{ind};

% setup dialog
if isPointByPoint(m)
    % point-by-point
    L = get(m,'local');
    [L,OK]= gui_ModelSetup(L);
    newname = getType(L);
    m = set(m,'local',L);
else
    [m,OK]= gui_ModelSetup(m);
    newname = name(m);
end
if OK
    % change model
    T.Responses{ind}= m;
    xregpointer(T);
    set(ud.globalMod,'String',newname);
end


%--------------------------------------------------------------------------
function i_Select(~,~,iFace)
% select a new response variable for current model

ud = feval(iFace.getCardUserdata);
T= ud.pointer.info;
ind= get(ud.rlist,'Value');
m= T.Responses{ind};

% get data list
dlist= get(ud.ylist,'String');
dind= get(ud.ylist,'Value');

% get signal name and units for response
varName= dlist{dind};
S= T.DataLink.info(:,varName);
un= get(S,'Units');

% copy signal and units to model
m= setResponse(m,varName,un{1});
T.Responses{ind}= m;
xregpointer(T);

% update response model list
rlist= get(ud.rlist,'String');
rlist{ind}= ResponseLabel(m);
set(ud.rlist,'String',rlist);



%--------------------------------------------------------------------------
function i_AddResponse(~,~,iFace)
% add a new response 

ud = feval(iFace.getCardUserdata);
T= ud.pointer.info;

% default model (one or two stage)
m= HSModel(T.DesignDev);

% get data list
dlist= get(ud.ylist,'String');
dind= get(ud.ylist,'Value');
% get signal name and units for response
varName= dlist{dind};
S= T.DataLink.info(:,varName);
un= get(S,'Units');

% copy signal and units to model
m= setResponse(m,varName,un{1});

if isempty(T.Responses)
    T.Responses= {m};
else
    % add to the end of the list
    T.Responses{end+1}= m;
end
xregpointer(T);

% select new response
i_setvalues(ud,length(T.Responses));

if ~isempty(T.Responses)
    % must build some responses before proceeding
    feval(iFace.setNextButton, ~isExpData(T.DesignDev));
    feval(iFace.setFinishButton, 1);
end

%--------------------------------------------------------------------------
function i_DeleteResponse(~,~,iFace)
% delete current response

ud = feval(iFace.getCardUserdata);
ind = get(ud.rlist,'Value');

T= ud.pointer.info;
m= T.Responses{ind};

if ind==1 && length(T.DesignDev)>1
    % check if deleting first response and there are datum links
    DatumType= get(m,'DatumType');
    if (DatumType==1 || DatumType==2)
        % change datumlink models
        for i=2:length(T.Responses)
            if get(T.Responses{i},'DatumType')==3
                L= get(T.Responses{i},'Local');
                set(L,'DatumType',0);
                T.Responses{i}= set(T.Responses{i},'Local',L);
            end
        end
    end
end
T.Responses(ind)= [];
xregpointer(T);

i_setvalues(ud,min(ind+1,length(T.Responses)));


%--------------------------------------------------------------------------
function iDoOpenEditor(h,~,ModelData)

% set OpenDataEditor
ModelData.OpenDataEditor = get(h,'Value');


function iBoundary(h,~,ModelData)
% set Boundary
ModelData.Boundary = get(h,'Value');


function OK = isPointByPoint(m)

OK = isa(m,'xregtwostage') && isa(get(m,'local'),'localmulti');