www.gusucode.com > mbcmodels 工具箱 matlab 源码程序 > mbcmodels/@localmod/gui_respfeat.m

    function [Lout,ok]=gui_respfeat(L,rfno,action,varargin)
% GUI_RESPFEAT   Dialog for altering response feature settings
%
%   [LM,OK]=GUI_RESPFEAT(LM,RFNO) creates a modal dialog box for choosing
%   a response feature from LM and using it as the feature with index RFNO.
%  

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

if nargin<3
   action='figure';
end
if nargin<2
   rfno=1;
end

Lout= [];
ok= false;
switch lower(action)
case 'figure'
   [Lout,ok]=i_createfig(L,rfno);
case 'layout'
   Lout=i_createlyt(varargin{:}, rfno);
   ok=1;
end


%--------------------------------------------------------------------------
function [lmout,ok]=i_createfig(lm,rfno)

try
    % check that response features are OK
    features(lm);
    SelectRF(lm);
catch ME
    xregerror('Response feature error',ME.message);
    lmout= lm;
    ok= false;
    return
end

wid= 230+max(0,nfactors(lm)-2)*55;
dlg=mbcgui.container.Dialog(...
    'Name','Response Features',...
    'Size',[wid 300],...
    'Tag','RespFeat',...
    'Buttons','OK_CANCEL_HELP',...
    'HelpCode','xreg_rfSetup',...
    'Resize','off');

p=xregpointer(lm);
dlg.Content=i_createlyt(dlg.Figure,p,rfno);


closeMode = dlg.showDialog( );
switch lower(closeMode)
    case 'ok'
        lmout=p.info;
        ok=1;
    otherwise
        lmout=lm;
        ok=0;
end
freeptr(p);
delete(dlg);
drawnow

%--------------------------------------------------------------------------
function lyt=i_createlyt(figh,p,rfno)

L= p.info;
if ~isa(figh,'xregcontainer')
    ud.pointer=p;
    ud.rfno=rfno;
    
    optsFrame=mbcgui.container.layoutpanel(...
        'Parent', figh,...
        'BorderType', 'etchedin',...
        'Title','Options');
    featureFrame=mbcgui.container.layoutpanel(...
        'Parent', figh,...
        'BorderType', 'etchedin',...
        'Title','Feature');
    
    txt=uicontrol('Style','text',...
        'Parent',featureFrame,...
        'String','Select the response feature you wish to model:',...
        'HorizontalAlignment','left');
    ud.resplist=uicontrol('Style','listbox',...
        'BackgroundColor','w',...
        'Parent',featureFrame);
    noopts=uicontrol('Style','text',...
        'Parent',optsFrame,...
        'String','No options are available for this response feature.',...
        'HorizontalAlignment','left');
    for i= 1:nfactors(L)
        ud.value(i)=uicontrol('Style','edit',...
            'Parent',optsFrame,...
            'BackgroundColor','w',...
            'Position',[0 0 50 20]);
    end
    ud.lims(1)=uicontrol('Style','edit',...
        'Parent',optsFrame,...
        'BackgroundColor','w',...
        'Position',[0 0 50 20]);
    ud.lims(2)=uicontrol('Style','edit',...
        'Parent',optsFrame,...
        'BackgroundColor','w',...
        'Position',[0 0 50 20]);
    text1=uicontrol('Style','text',...
        'Parent',optsFrame,...
        'String','Value:',...
        'Position',[0 0 35 15],...
        'HorizontalAlignment','left');
    text2=uicontrol('Style','text',...
        'Parent',optsFrame,...
        'String','Limits:',...
        'Position',[0 0 35 15],...
        'HorizontalAlignment','left');
    
    % set up data
    udh= txt;
    
    % callbacks
    set(ud.resplist,'Callback',{@i_changerf,udh});
    set(ud.value,'Callback',{@i_changevals,udh});
    set(ud.lims,'Callback',{@i_changevals,udh});
    
    flw1=xregflowlayout(optsFrame,'orientation','left/center',...
        'elements',[{text1},num2cell(ud.value)],...
        'gap',5,...
        'border',[-5 0 0 0],...
        'packstatus','off');
    flw2=xregflowlayout(optsFrame,'orientation','left/center',...
        'elements',{text2,ud.lims(1),ud.lims(2)},...
        'gap',5,...
        'border',[-5 0 0 0]);
    grd=xreggridlayout(optsFrame,'correctalg','on',...
        'dimension',[2 1],...
        'elements',{flw1,flw2},...
        'gapy',5);
    ud.crd=xregcardlayout(optsFrame,...
        'numcards',2, ...
        'border', [10 10 10 5]);
    attach(ud.crd,noopts,1);
    attach(ud.crd,grd,2);
    set(optsFrame, 'LayoutComponent', {ud.crd});
    
    brd=xregborderlayout(featureFrame,'center',ud.resplist,...
        'north',txt,...
        'border', [10 10 10 5], ...
        'innerborder',[0 0 0 30]);
    set(featureFrame, 'LayoutComponent', {brd});
    
    lyt=xreggridbaglayout(figh, ...
        'dimension', [2 1], ...
        'rowsizes', [-1 80], ...
        'gap', 10, ...
        'elements', {featureFrame, optsFrame});
    
    set(txt,'UserData',ud);
else
    lyt=figh;
    udh=get(get(get(lyt,'center'),'center'),'north');
    ud=get(udh,'UserData');
    ud.pointer=p;
    set(udh,'UserData',ud);
end

i_setvalues(ud,p,rfno);



%--------------------------------------------------------------------------
function i_setvalues(ud,p,rfno)
% set up control values from object

L=p.info;

flist=DatumDisplay(L,features(L));
LFeats= get(L,'features');

if rfno>length(LFeats)
   rfno=length(LFeats);
end

Nind= find( strcmpi( LFeats( rfno ).Display,{ flist.Display } ) );
top= max(1,Nind-5);
set(ud.resplist,'String',{flist.Display},'Value',Nind,'ListboxTop',top)

if ~isempty(strfind(flist( Nind ).Function,'Value'));
   % value used in this rf
   
   % Value
   Value= get(L,'values');
   Value= num2cell(Value(rfno,:));
   set(ud.value(:),{'String'},Value(:));
   
   % Limits
   Limits= get(L,'limits');
   Limits= Limits(:,rfno);
   set(ud.lims,...
      {'String'},{Limits(1);Limits(2)});

   set(ud.crd,'currentcard',2);
else
   % no value used for rf
   set(ud.value,'String',0);
   set(ud.lims,...
      {'String'},{-10000;10000});
   set(ud.crd,'currentcard',1);
end



%--------------------------------------------------------------------------
function i_changerf(~,~,udh)
% swap to new response feature type
ud=get(udh,'UserData');
[lm,vals]=i_change(ud.pointer.info,ud);
ud.pointer.info=lm;
set(ud.crd,'currentcard',vals+1);


%--------------------------------------------------------------------------
function i_changevals(~,~,udh)
% swap to new response feature type
ud=get(udh,'UserData');
ud.pointer.info=i_change(ud.pointer.info,ud);


%--------------------------------------------------------------------------
function [lm,vals] = i_change(lm,ud)

% response feature number
RFno= ud.rfno;

Type= get(ud.resplist,'Value');

% get values and limits
vals= get(ud.value,{'String'});
vals= sprintf('%10s ',vals{:});
Value= str2double(vals);
Limmin= str2double(get(ud.lims(1),'String'));
Limmax= str2double(get(ud.lims(2),'String'));


% check values 
if isempty(Value) || length(Value)>nfactors(lm) ...
      || isempty(Limmin) || length(Limmin)>1 ...
      || isempty(Limmax) || length(Limmax)>1
   % reset ui values and exit
   p=xregpointer(lm);
   i_setvalues(ud,p,RFno);
   freeptr(p);
   return
end

Limits= [Limmin;Limmax]; 
lm= EditFeat(lm,RFno,Value,Type,Limits);

if nargout>1
   flist=DatumDisplay(lm,features(lm));
   if ~isempty(strfind(flist( Type ).Function,'Value'));
      vals=1;
   else
      vals=0;
   end
end
return