utanapar.m
上传用户:haiyisale
上传日期:2013-01-09
资源大小:3246k
文件大小:15k
源码类别:

波变换

开发平台:

Matlab

  1. function varargout = utanapar(option,fig,varargin)
  2. %UTANAPAR Utilities for wavelet analysis parameters.
  3. %   VARARGOUT = UTANAPAR(OPTION,FIG,VARARGIN)
  4. %   M. Misiti, Y. Misiti, G. Oppenheim, J.M. Poggi 04-May-98.
  5. %   Last Revision: 13-Feb-2003.
  6. %   Copyright 1995-2004 The MathWorks, Inc.
  7. %   $Revision: 1.6.4.2 $  $Date: 2004/03/15 22:42:04 $
  8. % Default values.
  9. %----------------
  10. max_lev_anal = 12;
  11. % Tag property of objects.
  12. %-------------------------
  13. tag_ana_par = 'Fra_AnaPar';
  14. switch option
  15.     case {'Install_V3','Install_V3_CB','create'}
  16.         % Defaults.
  17.         %----------
  18.         xleft = Inf; xright  = Inf; xloc = Inf;
  19.         ytop  = Inf; ybottom = Inf; yloc = Inf;
  20.         bkColor = '';
  21.         datFlag = 1;
  22.         levFlag = 1;
  23.         enaVAL  = 'on';
  24.         wtype   = 'dwt';
  25.         deflev  = 1;
  26.         maxlev  = max_lev_anal;
  27.         % Inputs.
  28.         %--------        
  29.         nbarg = length(varargin);
  30.         for k=1:2:nbarg
  31.             arg = lower(varargin{k});
  32.             switch arg
  33.               case 'left'    , xleft   = varargin{k+1};
  34.               case 'right'   , xright  = varargin{k+1};
  35.               case 'xloc'    , xloc    = varargin{k+1};
  36.               case 'bottom'  , ybottom = varargin{k+1};
  37.               case 'top'     , ytop    = varargin{k+1};
  38.               case 'yloc'    , yloc    = varargin{k+1};
  39.               case 'bkcolor' , bkColor = varargin{k+1};              
  40.               case 'datflag' , datFlag = varargin{k+1};
  41.               case 'levflag' , levFlag = varargin{k+1};
  42.               case 'enable'  , enaVAL  = varargin{k+1};
  43.               case 'wtype'   , wtype   = varargin{k+1};
  44.               case 'deflev'  , deflev  = varargin{k+1};
  45.               case 'maxlev'  , maxlev  = varargin{k+1};
  46.             end 
  47.         end
  48.         str_numfig = num2mstr(fig);
  49.     
  50.         % String property of objects (Not all are used).
  51.         %-----------------------------------------------
  52.         str_txt_typ = 'Data  (Size)';
  53.         str_txt_nam = '';
  54.         str_txt_wav = 'Wavelet';
  55.         str_pop_fam = wavemngr('tfsn',wtype);
  56.         str_pop_num = wavemngr('fields',{'fsn',str_pop_fam(1,:)},'tabNums');
  57.         if isempty(str_pop_num) , str_pop_num = 'no'; end
  58.         str_txt_lev = 'Level';
  59.         str_levels  = int2str([1:maxlev]');
  60.         
  61.         switch option
  62.             case {'Install_V3','Install_V3_CB'}
  63.                 % Get Handles.
  64.                 %-------------
  65.                 handles = guihandles(fig);
  66.                 Fra_AnaPar  = handles.Fra_AnaPar;
  67.                 try
  68.                     Txt_Data_NS = handles.Txt_Data_NS;
  69.                     Edi_Data_NS = handles.Edi_Data_NS;
  70.                 catch
  71.                     datFlag = false;
  72.                 end
  73.                 Txt_Wav     = handles.Txt_Wav;
  74.                 Pop_Wav_Fam = handles.Pop_Wav_Fam;
  75.                 Pop_Wav_Num = handles.Pop_Wav_Num; 
  76.                 try
  77.                     Txt_Lev     = handles.Txt_Lev;
  78.                     Pop_Lev     = handles.Pop_Lev;
  79.                 catch
  80.                     levFlag = false;
  81.                 end
  82.                 if ~datFlag
  83.                     Txt_Data_NS = NaN;
  84.                     Edi_Data_NS = NaN;
  85.                 end
  86.                 if ~levFlag
  87.                     Txt_Lev = NaN;
  88.                     Pop_Lev = NaN;
  89.                 end
  90.                 
  91.                 % UIC Updates.
  92.                 %-------------
  93.                 set(Pop_Wav_Fam,'String',str_pop_fam);
  94.                 set(Pop_Wav_Num,'String',str_pop_num);
  95.                 if levFlag
  96.                     set(Pop_Lev,'String',str_levels,'Enable',enaVAL);
  97.                 end
  98.                 set([Pop_Wav_Fam,Pop_Wav_Num],'Enable',enaVAL);
  99.                 
  100.             case 'create'
  101.                 % Get Globals.
  102.                 %--------------
  103.                 [Def_Txt_Height,Def_Btn_Height, ...
  104.                         X_Spacing,Y_Spacing,Def_FraBkColor] = ...
  105.                     mextglob('get',...
  106.                     'Def_Txt_Height','Def_Btn_Height', ...
  107.                     'X_Spacing','Y_Spacing','Def_FraBkColor');
  108.                 if isempty(bkColor)
  109.                     bkColor = mextglob('get','Def_FraBkColor');
  110.                 end
  111.                 
  112.                 % Positions utilities.
  113.                 %---------------------
  114.                 dx = X_Spacing; bdx = 3;
  115.                 dy = Y_Spacing; bdy = 4;        
  116.                 d_txt  = (Def_Btn_Height-Def_Txt_Height);
  117.                 deltaY = (Def_Btn_Height+dy);
  118.                 
  119.                 old_units  = get(fig,'units');
  120.                 fig_units  = 'pixels';
  121.                 if ~isequal(old_units,fig_units), set(fig,'units',fig_units); end       
  122.                 
  123.                 % Setting frame position.
  124.                 %------------------------
  125.                 w_fra   = wfigmngr('get',fig,'fra_width');
  126.                 h_fra   = Def_Btn_Height+(datFlag+levFlag)*deltaY+2*bdy;
  127.                 xleft   = utposfra(xleft,xright,xloc,w_fra);
  128.                 ybottom = utposfra(ybottom,ytop,yloc,h_fra);
  129.                 pos_fra = [xleft,ybottom,w_fra,h_fra];
  130.                 
  131.                 % Position property of objects.
  132.                 %------------------------------
  133.                 w_uic = (w_fra-3*bdx)/3;
  134.                 x_uic = pos_fra(1)+bdx;
  135.                 ylow  = ybottom+h_fra-Def_Btn_Height-bdy;
  136.                 
  137.                 if datFlag
  138.                     pos_txt_typ = [x_uic, ylow+d_txt/2, w_uic, Def_Txt_Height];
  139.                     xleft       = pos_txt_typ(1)+pos_txt_typ(3);
  140.                     pos_txt_nam = [xleft , ylow , 2*w_uic , Def_Btn_Height];
  141.                     ylow        = ylow-deltaY;
  142.                 end
  143.                 xplus = 2;     
  144.                 pos_txt_wav    = [x_uic, ylow+d_txt/2, w_uic, Def_Txt_Height];
  145.                 xleft          = pos_txt_wav(1)+pos_txt_wav(3);
  146.                 pos_pop_fam    = [xleft, ylow, w_uic-xplus, Def_Btn_Height];
  147.                 pos_pop_num    = pos_pop_fam;
  148.                 pos_pop_num(1) = pos_pop_fam(1)+w_uic;
  149.                 pos_pop_num(3) = w_uic;
  150.                 
  151.                 if levFlag
  152.                     ylow           = ylow-deltaY;
  153.                     pos_txt_lev    = pos_txt_wav;
  154.                     pos_txt_lev(2) = ylow+d_txt/2;
  155.                     xleft          = pos_txt_lev(1)+pos_txt_lev(3);
  156.                     pos_pop_lev    = [xleft, ylow, w_uic-xplus, Def_Btn_Height];
  157.                 end
  158.                 
  159.                 % Create objects.
  160.                 %----------------
  161.                 comFigProp = {'Parent',fig,'Unit',fig_units};
  162.                 Fra_AnaPar = uicontrol(comFigProp{:},...
  163.                     'Style','frame', ...
  164.                     'Position',pos_fra, ...
  165.                     'Backgroundcolor',bkColor, ...
  166.                     'Tag',tag_ana_par ...
  167.                 );
  168.                 
  169.                 if datFlag
  170.                     Txt_Data_NS = uicontrol(comFigProp{:},...
  171.                         'Style','text',               ...
  172.                         'HorizontalAlignment','left', ...
  173.                         'Position',pos_txt_typ,       ...
  174.                         'String',str_txt_typ,         ...
  175.                         'Backgroundcolor',bkColor     ...
  176.                     );
  177.                     
  178.                     Edi_Data_NS = uicontrol(comFigProp{:},...
  179.                         'Style','Edit',           ...
  180.                         'Position',pos_txt_nam,   ...
  181.                         'String',str_txt_nam,     ...
  182.                         'Enable','inactive',      ...
  183.                         'Backgroundcolor',bkColor ...
  184.                     );
  185.                 else
  186.                     Txt_Data_NS = NaN;
  187.                     Edi_Data_NS = NaN;
  188.                 end
  189.                 Txt_Wav = uicontrol(comFigProp{:},...
  190.                     'Style','text',               ...
  191.                     'HorizontalAlignment','left', ...
  192.                     'Position',pos_txt_wav,       ...
  193.                     'String',str_txt_wav          ...
  194.                 );
  195.                 
  196.                 Pop_Wav_Fam = uicontrol(comFigProp{:},...
  197.                     'Style','Popup',        ...
  198.                     'Position',pos_pop_fam, ...
  199.                     'String',str_pop_fam,   ...
  200.                     'Enable',enaVAL         ...
  201.                 );
  202.                 
  203.                 Pop_Wav_Num = uicontrol(comFigProp{:},...
  204.                     'Style','Popup',        ...
  205.                     'Position',pos_pop_num, ...
  206.                     'String',str_pop_num,   ...
  207.                     'Visible','Off',        ...
  208.                     'Enable',enaVAL         ...
  209.                 );
  210.                 if levFlag
  211.                     Txt_Lev = uicontrol(comFigProp{:},...
  212.                         'Style','text',               ...
  213.                         'HorizontalAlignment','left', ...
  214.                         'Position',pos_txt_lev,       ...
  215.                         'String',str_txt_lev,         ...
  216.                         'Backgroundcolor',bkColor     ...
  217.                     );
  218.                     
  219.                     Pop_Lev = uicontrol(comFigProp{:},...
  220.                         'Style','Popup',        ...
  221.                         'Position',pos_pop_lev, ...
  222.                         'String',str_levels,    ...
  223.                         'Enable',enaVAL,        ...
  224.                         'Value',deflev          ...
  225.                     );
  226.                 else
  227.                     Txt_Lev = NaN;
  228.                     Pop_Lev = NaN;
  229.                 end
  230.                
  231.                 if ~isequal(old_units,fig_units)
  232.                     set([fig;ud.handles],'units',old_units);
  233.                 end       
  234.                 drawnow;
  235.                 
  236.         end
  237.         
  238.         % Set Wavelet Buttons.
  239.         %---------------------
  240.         cbanapar('cba_fam',fig,[Pop_Wav_Fam,Pop_Wav_Num]);
  241.         % Callbacks update.
  242.         %------------------
  243.         switch option
  244.             case {'Install_V3'} ,
  245.             case {'Install_V3_CB','create'}
  246.                 cbanapar('cba_fam',fig,[Pop_Wav_Fam,Pop_Wav_Num]);
  247.                 pop_str     = num2mstr([Pop_Wav_Fam;Pop_Wav_Num]);
  248.                 cba_pop_fam = ['cbanapar(''cba_fam'',' str_numfig ',' pop_str ');']; 
  249.                 cba_pop_num = ['cbanapar(''cba_num'',' str_numfig ',' pop_str ');'];
  250.                 set(Pop_Wav_Fam,'Callback',cba_pop_fam);
  251.                 set(Pop_Wav_Num,'Callback',cba_pop_num);
  252.         end
  253.                        
  254. % Add Context Sensitive Help (CSHelp).
  255. %-------------------------------------
  256. hdl_UT_WAVELET = [Txt_Wav,Pop_Wav_Fam,Pop_Wav_Num];
  257. wfighelp('add_ContextMenu',fig,hdl_UT_WAVELET,'UT_WAVELET');
  258. %-------------------------------------
  259.         % Store handles.
  260.         %---------------
  261.         ud.handles = [Fra_AnaPar;Txt_Data_NS;Edi_Data_NS;...
  262.                       Txt_Wav;Pop_Wav_Fam;Pop_Wav_Num;Txt_Lev;Pop_Lev];
  263.         set(Fra_AnaPar,'Userdata',ud);
  264.         if nargout>0 , varargout = {get(Fra_AnaPar,'Position') , ud.handles}; end
  265.     case 'create_copy'
  266.         createArg = varargin{1};
  267.         cbArg     = varargin{2};
  268.         [toolPos,hdlNew] = utanapar('create',fig,createArg{:});
  269.         popNew = findobj(hdlNew,'style','popupmenu');
  270.         cbanapar('set',fig,cbArg{:});
  271.         copyOpt = 1;
  272.         if copyOpt
  273.             Def_FraBkColor = mextglob('get','Def_FraBkColor');
  274.             prop    = get(popNew,{'Value','String'});
  275.             newProp = {'Style','Edit','BackGroundColor',Def_FraBkColor, ...
  276.                        'Enable','Inactive', ...
  277.                        'String'};
  278.             for k = 1:size(prop,1)
  279.                set(popNew(k),newProp{:},prop{k,2}(prop{k,1},:));
  280.             end
  281.         else
  282.             inactCol = mextglob('get','Def_TxtBkColor');
  283.             set(popNew,'enable','inactive','ForeGroundColor',inactCol);
  284.         end
  285.         if nargout>0 , varargout = {toolPos,hdlNew}; end
  286.     case 'create_copyB'
  287.         inFig = varargin{1};
  288.         uic = findobj(get(fig,'Children'),'flat','type','uicontrol');
  289.         fra = findobj(uic,'style','frame','tag',tag_ana_par);
  290.         ud  = get(fra,'userdata');
  291.         handles = ud.handles;
  292.         handles = copyobj(handles,inFig);
  293.         % Store handles.
  294.         %---------------
  295.         ud.handles = handles;
  296.         set(handles(1),'Userdata',ud);
  297.         pop = findobj(handles,'style','popupmenu');
  298.         if ~isempty(pop)
  299.             Def_FraBkColor = mextglob('get','Def_FraBkColor');
  300.             prop    = get(pop,{'Value','String'});
  301.             newProp = {'Style','Edit','BackGroundColor',Def_FraBkColor, ...
  302.                        'Enable','Inactive', ...
  303.                        'String'};
  304.             for k = 1:size(prop,1)
  305.                set(pop(k),newProp{:},prop{k,2}(prop{k,1},:));
  306.             end
  307.         end
  308. % Add Context Sensitive Help (CSHelp).
  309. %-------------------------------------
  310. [Txt_Wav,Pop_Wav_Fam,Pop_Wav_Num] = utanapar('handles',inFig,'nam','fam','num');
  311. hdl_UT_WAVELET = [Txt_Wav,Pop_Wav_Fam,Pop_Wav_Num];
  312. wfighelp('add_ContextMenu',inFig,hdl_UT_WAVELET,'UT_WAVELET');
  313. %-------------------------------------
  314.     case 'handles'
  315.         uic = findobj(get(fig,'Children'),'flat','type','uicontrol');
  316.         fra = findobj(uic,'style','frame','tag',tag_ana_par);
  317.         ud  = get(fra,'userdata');
  318.         handles = ud.handles;
  319.         handles([1,4,7]) = [];
  320.         nbarg = length(varargin);
  321.         if nbarg>0 & isequal(varargin{1},'all')
  322.             varargout{1} = handles; return
  323.         end       
  324.         varargout = num2cell(handles);
  325.         if  nbarg<1 , return; end
  326.         ind = [];
  327.         for k = 1:nbarg
  328.            hdlType = varargin{k};
  329.            switch hdlType
  330.              case 'typ' , ind = [ind;1];
  331.              case 'nam' , ind = [ind;2];
  332.              case 'fam' , ind = [ind;3];
  333.              case 'num' , ind = [ind;4];
  334.              case 'lev' , ind = [ind;5];
  335.              case 'pop' , ind = [ind;[3:5]'];
  336.            end       
  337.         end
  338.         varargout = varargout(ind);
  339.     case {'toolPosition','position'}
  340.         fra = findobj(fig,'style','frame','tag',tag_ana_par);
  341.         varargout = get(fra,{'Position','Units'});
  342.     case 'set_cba_num'
  343.         [Pop_Wav_Fam,Pop_Wav_Num] = utanapar('handles',fig,'fam','num');
  344.         if nargin>2
  345.             ena_hdl = varargin{1};
  346.             pop_str = num2mstr([Pop_Wav_Fam ; Pop_Wav_Num]);
  347.             cba_pop_num = ['cbanapar(''cba_num'','        ...
  348.                             num2mstr(fig) ',' pop_str ',[],' ...
  349.                             num2mstr([ena_hdl]) ');'];
  350.             set(Pop_Wav_Num,'Callback',cba_pop_num);
  351.         end 
  352.     otherwise
  353.         errargt(mfilename,'Unknown Option','msg');
  354.         error('*');
  355. end
  356. %------------------------------------------------------------------------