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

    function [dout,ret]=gui_addpoints(des,action,varargin)
%GUI_ADDPOINTS Gui for adding design points
%
%  [D,RET]=GUI_ADDPOINTS(D) brings up a GUI for manually adding points to a
%  design.  The GUI blocks until OK/Cancel has been pressed RET is set to 0
%  if cancel was pressed, 1 otherwise.

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

% Note: this dialog is unusual in that no changes are made until OK is pressed
% i.e. the dynamic design pointer is not used for on-the-fly updating

if nargin<2
   action='create';
end

switch lower(action)
case 'create'
   [dout,ret]=i_createfig(des,varargin{:});
case 'layout'
   % no support yet   
end

function [dout,ok]=i_createfig(des,varargin)

dlgH = mbcgui.container.Dialog(...
    'Name','Add Design Points',...
    'Resize','on',...
    'Size', [400 400],...
    'Buttons', 'OK_CANCEL_HELP',...
    'HelpCode', 'xreg_desAddPoints' );
figh = dlgH.Figure;

p=xregpointer(des);
lyt = i_createlyt(figh,p,varargin{:});
dlgH.Content = lyt;

%dialog blocks here
closeMode = dlgH.showDialog();

if strcmp( closeMode, 'OK' )
   i_finalise( lyt );
   dout=p.info;
   ok=1;
else
   dout=des;
   ok=0;
end
delete(dlgH);
freeptr(p);


function L=i_createlyt(F,p,varargin)

NP=1;
if nargin>2
   % parse additional options
   for n=1:2:length(varargin)
      switch lower(varargin{n})
      case 'npoints'
         NP=varargin{n+1};
      end
   end
end

ud.despointer=p;
[ud.optsinfo,ud.defopt]=gui_augmethods(ud.despointer.info);
ud.currentpopval=0;
ud.currentopt=ud.defopt(1);
ud.drawn=zeros(1,length(ud.optsinfo));

udh=xregGui.RunTimePointer;
udh.LinkToObject(F);

ud.algpop=xregGui.labelcontrol('parent',F,...
   'visible','off',...
   'string','Augment method:',...
   'labelsizemode','absolute',...
   'labelsize',110,...
   'controlsizemode','absolute',...
   'controlsize',150,...
   'gap',5,...
   'Control',uicontrol('Parent',F,...
   'Style','popupmenu',...
   'BackgroundColor','w',...
   'Visible','off',...
   'Callback',{@i_algpop,udh}, ...
   'Tag', 'AugmentMethod'));
ud.optsframe = mbcgui.container.layoutpanel(...
   'Parent', F,...
   'Visible', 'off', ...
   'Title','Options',...
   'BorderType','etchedin', ...
   'LayoutBorder', [10 10 10 5]);
ud.cards=xregcardlayout(ud.optsframe,...
   'numcards',length(ud.drawn),...
   'packstatus','off');
set(ud.optsframe, 'LayoutComponent', {ud.cards});

L=xreggridbaglayout(F,...
   'dimension',[2 1],...
   'gapy',10,...
   'rowsizes',[30 -1],...
   'elements',{ud.algpop,ud.optsframe},...
   'userdata',udh);

ud=i_setvals(ud);

% select first option
lyt=feval(ud.optsinfo(ud.defopt(1)).CreateFcn,ud.optsframe,p);
attach(ud.cards,lyt,ud.defopt(1));
set(ud.cards,'currentcard',ud.defopt(1));
ud.currentpopval=ud.defopt(2);
ud.drawn(ud.defopt(1))=1;

if NP~=1
   % set default number of points 
   feval(ud.optsinfo(ud.defopt(1)).NPointsFcn,lyt,p,NP);
end

udh.info=ud;
return



function ud=i_setvals(ud)
% set correct string in alg popup
str={};
for n=1:length(ud.optsinfo)
   s2=ud.optsinfo(n).Name;
   if iscell(s2)
      str=[str s2];
      Nitems=length(s2);
   else
      str=[str {s2}];
      Nitems=1;
   end
   if n<ud.defopt(1)
      ud.defopt(2)=ud.defopt(2)+Nitems;
   end
end
set(ud.algpop.Control,'String',str,'Value',ud.defopt(2));



function i_algpop(src,evt,udh)
newval=get(src,'Value');
ud=udh.info;
if newval~=ud.currentpopval
   str=get(src,'String');
   str=str{newval};
   % find string in options
   viewind=0;
   for n=1:length(ud.drawn)
      if any(strcmp(str,ud.optsinfo(n).Name))
         viewind=n;
         break
      end
   end
   if viewind
      % synchronize number of points
      Lold=getcard(ud.cards,ud.currentopt);
      Lold=Lold{1};
      if ud.drawn(viewind)
         % set number of points
         Lnew=getcard(ud.cards,viewind);
         Lnew=Lnew{1};
         feval(ud.optsinfo(viewind).NPointsFcn,Lnew, ud.despointer, ...
            feval(ud.optsinfo(ud.currentopt).NPointsFcn, Lold, ud.despointer));
         % switch card
         set(ud.cards,'currentcard',viewind);
      else
         lyt=feval(ud.optsinfo(viewind).CreateFcn,ud.optsframe,ud.despointer);
         attach(ud.cards,lyt,viewind);
         % set number of points
         feval(ud.optsinfo(viewind).NPointsFcn,lyt, ud.despointer, ...
            feval(ud.optsinfo(ud.currentopt).NPointsFcn, Lold, ud.despointer));
         % switch card
         set(ud.cards,'packstatus','on','currentcard',viewind);
         ud.drawn(viewind)=1;
      end
      ud.currentpopval=newval;
      ud.currentopt=viewind;
      udh.info=ud;
   end
end


function i_finalise(L)
udh=get(L,'UserData');
ud=udh.info;
newval=get(ud.algpop.Control,'Value');

str=get(ud.algpop.Control,'String');
str=str{newval};
% find string in options
viewind=0;
optind=0;
for n=1:length(ud.drawn)
   mtch=strcmp(str,ud.optsinfo(n).Name);
   if any(mtch)
      viewind=n;
      optind=find(mtch);
      break
   end
end
if viewind
   L=getcard(ud.cards,viewind);
   L=L{1};
   feval(ud.optsinfo(n).FinaliseFcn,L,ud.despointer,optind);
end