www.gusucode.com > mbcdesign 工具箱 matlab 源码程序 > mbcdesign/@cset_userdef/propertypage.m
function out=propertypage(obj,action,varargin) % PROPERTYPAGE Create a property gui for CandidateSet % % % This should be overloaded by child classes % % Interface: Lyt=propertypage(cs,'layout',fig); % Lyt=propertypage(cs,'update',lyt,p_cs,model); % Copyright 2000-2015 The MathWorks, Inc. and Ford Global Technologies, Inc. switch lower(action) case 'layout' out=i_createlyt(varargin{:}); case 'update' out=i_update(varargin{:}); end function lyt=i_createlyt(figh,varargin) % create new layout in figure ud.pointer=[]; ud.figure=figh; ud.model=[]; ud.callback=''; for n=1:2:length(varargin) switch lower(varargin{n}) case 'callback' ud.callback=varargin{n+1}; end end SC = xregGui.SystemColorsDbl; ud.datasrc = uicontrol('Parent',figh,... 'Style','popupmenu',... 'String',{'MATLAB workspace';'mat file'},... 'Value',1,... 'BackgroundColor',SC.WINDOW_BG); ud.DataSourceLabel = xregGui.labelcontrol('parent',figh,... 'LabelSizeMode','absolute',... 'LabelSize',75,... 'ControlSizeMode','relative',... 'ControlSize',1,... 'string','Data source:',... 'Control',ud.datasrc); ud.newdata=uicontrol('Parent',figh,... 'Style','pushbutton',... 'String','Replace'); ud.NewDataLabel = xregGui.labelcontrol('parent',figh,... 'ControlSize',65,... 'string','Replace current data with new data:',... 'Control',ud.newdata); ud.adddata=uicontrol('Parent',figh,... 'Style','pushbutton',... 'String','Augment'); ud.AddDataLabel = xregGui.labelcontrol('parent',figh,... 'ControlSize',65,... 'string','Augment current data with new data:',... 'Control',ud.adddata); div1=xregGui.dividerline(figh); str=['Use the buttons above to load a custom candidate set. The candidate list must',... ' have at least one point.']; ud.InfoStr=uicontrol('Parent',figh,... 'Style','text',... 'String',str,... 'UserData',xregdesign,... 'HorizontalAlignment','left'); ud.current=uicontrol('Parent',figh,... 'Style','text',... 'String','Current candidate list size: n points',... 'HorizontalAlignment','left'); udh=ud.current; % callbacks set(ud.newdata,'Callback',{@i_newdata,udh}); set(ud.adddata,'Callback',{@i_adddata,udh}); lyt=xreggridbaglayout(figh, ... 'dimension',[8 2],... 'rowsizes',[20 10 25 10 25 20 15 30],... 'colsizes', [260 -1], ... 'mergeblock', {[6 6],[1 2]}, ... 'mergeblock', {[7 7],[1 2]}, ... 'mergeblock', {[8 8],[1 2]}, ... 'elements',{ud.DataSourceLabel,[],ud.NewDataLabel,[], ud.AddDataLabel, ... div1,ud.current,ud.InfoStr}); ud.layout=lyt; set(udh,'UserData',ud); function lyt=i_update(lyt,p,m) % update current layout udh=get(lyt,'elements'); udh=udh{7}; ud=get(udh,'UserData'); ud.pointer=p; ud.model=m; ud=i_setvalues(ud); set(udh,'UserData',ud); function ud=i_setvalues(ud) np=npoints(ud.pointer.info); if np==1 set(ud.current,'String',['Current candidate list size: ' sprintf('%d',np) ' point.']); else set(ud.current,'String',['Current candidate list size: ' sprintf('%d',np) ' points.']); end function i_newdata(obj,nul,udh) ud=get(udh,'UserData'); % internal function for getting data [data ok]=i_getdata(ud); if ok ud.pointer.info=set(ud.pointer.info,'Data',data); ud=i_setvalues(ud); set(udh,'UserData',ud); i_firecb(ud); end function i_adddata(obj,nul,udh) ud=get(udh,'UserData'); % internal function for getting data [data ok]=i_getdata(ud); if ok % add new data ud.pointer.info=set(ud.pointer.info,'Data',[get(ud.pointer.info,'Data'); data]); ud=i_setvalues(ud); set(udh,'UserData',ud); i_firecb(ud); end function [x,ok]=i_getdata(ud) % popup appropriate gui for getting new data in popval=get(ud.datasrc,'Value'); nf=nfactors(ud.pointer.info); switch popval case 1 % workspace [x,ok]=mv_getmatrix([NaN nf],'double'); case 2 % mat file % load dialog, then check contents for matching matrices [f,p]=uigetfile('*.mat','Load candidate data'); if f==0 x=[]; ok=0; return end vars=load([p f]); fnms=fieldnames(vars); S.type='.'; opt=true(length(fnms),1); for i=1:length(fnms) S.subs=fnms{i}; x=subsref(vars,S); % check each data for type and size if ~strcmp(class(x),'double') || size(x,2)~=nf opt(i)=0; end end if sum(opt)==1 % only one matching matrix S.subs=fnms{find(opt)}; x=subsref(vars,S); ok=1; elseif any(opt) % multiple options in file [selind,ok]=mv_listdlg('liststring',fnms(opt),'selectionmode','single','name','Select Matrix',... 'uh',25,'listsize',[160 200]); if ok fd=find(opt); selind=fd(selind); S.subs=fnms{selind}; x=subsref(vars,S); else x=[]; end else errordlg('There are no matrices of the appropriate size in this file!','modal'); x=[]; ok=0; end end if ok % code data x=code(ud.model,x); end function i_firecb(ud) xregcallback(ud.callback, ud.layout, []);