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

波变换

开发平台:

Matlab

  1. function dynvzaxe(option,fig,varargin)
  2. %DYNVZAXE Dynamic visualization tool (View Axes).
  3. %   DYNVZAXE(OPTION,FIG,VARARGIN)
  4. %   M. Misiti, Y. Misiti, G. Oppenheim, J.M. Poggi 29-May-97.
  5. %   Last Revision: 21-Mar-2003.
  6. %   Copyright 1995-2004 The MathWorks, Inc.
  7. %   $Revision: 1.13.4.2 $ $Date: 2004/03/15 22:40:27 $
  8. % Tag property of objects.
  9. %------------------------
  10. tag_figzaxe = 'Fig_Zaxe';
  11. switch option
  12.     case 'ini'
  13.         % varargin{1} = pos_gra_area.
  14.         % varargin{2} = Tog_View_Axes
  15.         %----------------------------
  16.         oldFig = hdlFigZaxe(fig,tag_figzaxe);
  17.         togBtn = varargin{2};
  18.         if ~isempty(oldFig)
  19.             dynvzaxe('close',oldFig,'direct'); return;
  20.         end
  21.         pos_gra = varargin{1};
  22.         ax      = wfindobj(get(fig,'Children'),'flat','type','axes','Visible','on');
  23.         nb_axes = length(ax);
  24.         if nb_axes<=1 , set(togBtn,'value',0); return; end
  25.         pos_ax  = get(ax,'Position');
  26.         pos_ax  = cat(1,pos_ax{:});
  27.         [pos_ax,ind] = sortrows(pos_ax,[2 1]);
  28.         ax      = ax(ind);
  29.         valmin  = min(pos_ax);
  30.         valmax  = max(pos_ax);
  31.         % Hide 1.
  32.         %--------
  33.         HideNoZoom = 1;
  34.         axNoZoom = [];
  35.         if HideNoZoom
  36.             indHide = [];
  37.             for k=1:length(ax)
  38.                 ud = get(ax(k),'userdata');
  39.                 if isstruct(ud)
  40.                     if isfield(ud,'dynvzaxe')
  41.                         if isequal(lower(ud.dynvzaxe.enable),'off')
  42.                            indHide = [indHide k];
  43.                         end
  44.                    end
  45.                 end
  46.             end
  47. idxSET = setdiff([1:length(ax)],indHide);
  48.             for k=idxSET
  49.                 ud = getappdata(ax(k),'WTBX_UserData');
  50.                 if isstruct(ud)
  51.                     if isfield(ud,'dynvzaxe')
  52.                         if isequal(lower(ud.dynvzaxe.enable),'off')
  53.                            indHide = [indHide k];
  54.                         end
  55.                    end
  56.                 end
  57.             end
  58.             if ~isempty(indHide)
  59.                 axNoZoom    = wfindobj(ax(indHide),'Visible','on');
  60.                 ax(indHide) = [];
  61.                 pos_ax(indHide,:) = [];
  62.                 nb_axes = nb_axes-length(indHide);
  63.             end
  64.         end
  65.         % Hide 2.
  66.         %--------
  67.         ax2Hide = [];
  68.         rapp = pos_ax(:,3)./pos_ax(:,4);
  69.         maxr = 14;
  70.         r    = find(rapp<1/maxr | rapp>maxr);
  71.         lr   = length(r);
  72.         if lr>0
  73.             pos_ax(r,:) = [];
  74.             ax2Hide = wfindobj(ax(r),'Visible','on');
  75.             ax(r)   = [];
  76.             nb_axes = nb_axes-lr;
  77.             if nb_axes<=1, set(togBtn,'value',0); return; end
  78.             valmin = min(pos_ax);
  79.             valmax = max(pos_ax);
  80.         end
  81.         xmin = valmin(1);
  82.         xmax = max(pos_ax(:,1)+pos_ax(:,3));
  83.         wmin = valmin(3);
  84.         wmax = valmax(3);
  85.         ymin = valmin(2);
  86.         ymax = max(pos_ax(:,2)+pos_ax(:,4));
  87.         hmin = valmin(4);
  88.         hmax = valmax(4);
  89.         x0   = 0.025;
  90.         x1   = 0.975;
  91.         y0   = 0.025;
  92.         y1   = 0.975;
  93.         kx   = (x1-x0)/(xmax-xmin);
  94.         ky   = (y1-y0)/(ymax-ymin);
  95.         pos_btn = [...
  96.                     kx*[pos_ax(:,1)-xmin]+x0 , ky*[pos_ax(:,2)-ymin]+y0 , ...
  97.                     kx*pos_ax(:,3) , ky*pos_ax(:,4)];
  98.         pos_fig = [0.02 0.5 0.15 0.20];
  99.         win_units = 'normalized';
  100.         figName = sprintf('View Axes for fig. %s', int2str(fig));
  101.         locfig = wfigmngr('init', ...
  102.                      'Name',figName,...
  103.                      'Visible','Off', ...
  104.                      'Unit',win_units,...
  105.                      'Position',pos_fig...
  106.                      );
  107.         wfigmngr('extfig',locfig,'ExtFig_DynV');
  108.         strnumfig = int2str(locfig);
  109.         % Find UiMenus and UiControls to Diseable.
  110.         %-----------------------------------------
  111.         try
  112.             uimACT = wfigmngr('get_activeHDL',fig,'uimenu');
  113.         catch
  114.             uimACT = [];
  115.         end
  116.         uim     = wfindobj(fig,'type','uimenu','enable','on');
  117.         [a,b]   = wcommon(uim,uimACT);
  118.         uim     = uim(~a);
  119.         [closeBTN,closeUIM] = wfigmngr('get_activeHDL',fig,'close');
  120.         uic     = wfindobj(fig,'type','uicontrol','enable','on');
  121.         uicDYNV = dynvtool('handles',fig,'Array');
  122.         try   ,  uicCOLM = utcolmap('handles',fig);
  123.         catch ,  uicCOLM = [];
  124.         end
  125.         [a,b]   = wcommon(uic,[closeBTN;uicDYNV(:);uicCOLM(:)]);
  126.         uic     = uic(~a);
  127.         txt     = findobj(uic,'style','text');
  128.         [a,b]   = wcommon(uic,txt);
  129.         ud.caller       = fig;
  130.         ud.callTog      = togBtn;
  131.         ud.hdl          = ax;
  132.         ud.savpos       = pos_ax;
  133.         ud.zoompos      = pos_gra+[0.05 0.05 -0.1 -0.1];
  134.         ud.oldpos       = [];
  135.         ud.newpos       = [];
  136.         ud.act          = [];
  137.         ud.hide         = [axNoZoom ; ax2Hide ; getHide(fig,pos_gra)];
  138.         ud.savClose.btn = closeBTN;
  139.         ud.savClose.uim = closeUIM;
  140.         ud.savClose.val = get(fig,'CloseRequestFcn');
  141.         ud.hdlOff       = [uim ; uic(~a)];
  142.         ud.axeTMP = [];
  143.         new_CloseFcn    = ['delete(' strnumfig ');' ud.savClose.val];
  144.         SetCloseFcn(ud,new_CloseFcn)
  145.         surfBtn   = prod(pos_btn(:,[3 4])')';
  146.         [nul,ind] = sort(surfBtn);
  147.         [strBtn,cdataBtn] = setToggle(0);
  148.         for j = nb_axes:-1:1
  149.             k = ind(j);
  150.             cb_tog = [mfilename '(''select'',' strnumfig ',' int2str(k) ');'];
  151.             tog = uicontrol(...
  152.                     'Parent',locfig,        ...
  153.                     'Style','togglebutton', ...
  154.                     'Units','normalized',   ...
  155.                     'Position',pos_btn(k,:),...
  156.                     'FontWeight','bold', ...
  157.                     'String',strBtn, ...
  158.                     'Value',0, ...
  159.                     'Cdata',cdataBtn,...
  160.                     'Userdata',k, ...
  161.                     'Callback',cb_tog);
  162.         end
  163.         cb_close = [mfilename '(''close'',' int2str(locfig) ')'];
  164.         wfigmngr('attach_close',locfig,mfilename);
  165.         % Computing figure position.
  166.         %---------------------------
  167.         [xpixl,ypixl] = wfigutil('prop_size',locfig,1,1);
  168.         wok  = 60*xpixl;
  169.         hok  = 20*ypixl;
  170.         rx   = 1/3;
  171.         ry   = 2/3;
  172.         wmax = max(pos_btn(:,3));
  173.         hmax = max(pos_btn(:,4));
  174.         wmin = min(pos_btn(:,3));
  175.         hmin = min(pos_btn(:,4));
  176.         xmul = wok/wmin;
  177.         ymul = hok/hmin;
  178.         if xmul>1  , pos_fig(3) = pos_fig(3)*xmul; end
  179.         if xmul<rx , pos_fig(3) = pos_fig(3)*rx;   end
  180.         if ymul>1  , pos_fig(4) = pos_fig(4)*ymul; end
  181.         if ymul<ry , pos_fig(4) = pos_fig(4)*ry;   end
  182.         widthmax = 0.20;
  183.         heighmax = 0.35;
  184.         if pos_fig(3)>widthmax
  185.             mulx = widthmax/pos_fig(3);
  186.         else
  187.             mulx = 1;
  188.         end
  189.         if pos_fig(4)>heighmax
  190.             muly = heighmax/pos_fig(4);
  191.         else
  192.             muly = 1;
  193.         end
  194.         if muly>3*mulx , muly = 3*mulx; end
  195.         pos_fig = pos_fig.*[1 1 mulx muly];
  196.         caller_pos = get(fig,'Position');
  197.         pos_fig(1) = caller_pos(1)-pos_fig(3)-0.0075;
  198.         if pos_fig(1)<0 , pos_fig(1) = 0.005; end
  199.         pos_fig(2) = caller_pos(2)+caller_pos(4)-pos_fig(4);
  200.         if pos_fig(2)<0 , pos_fig(2) = 0.005; end
  201.         set(locfig,'Position',pos_fig);
  202.         % Diseable UiMenus and UiControls.
  203.         %---------------------------------
  204.         set(ud.hdlOff,'enable','off');
  205.         set(locfig,...
  206.                 'Visible','On',   ...
  207.                 'Userdata',ud,    ...
  208.                 'tag',tag_figzaxe ...
  209.                 );
  210.     case 'zoom'
  211.         if OKCloseFIG(fig) , return ; end
  212.         num_btn = varargin{1};
  213.         ud     = get(fig,'Userdata');
  214.         act    = ud.act;
  215.         hdl    = ud.hdl;
  216.         savpos = ud.savpos;
  217.         p_axe  = get(hdl,'position');
  218.         nb_axe = size(p_axe,1);
  219.         if nb_axe> 1 , p_axe = cat(1,p_axe{:}); end
  220.         i_axe = setdiff([1:nb_axe],num_btn);
  221.         if isempty(act)
  222.             hdl_btn = GetHdlPUS(fig,num_btn);
  223.             setToggle(1,hdl_btn);
  224.             oldpos  = savpos(num_btn,:);
  225.             newpos  = ud.zoompos;
  226.             act     = num_btn;
  227.             visHide = 'off';
  228.             ud.axeTMP = wfindobj(hdl(i_axe),'visible','on');
  229.             set(ud.axeTMP,'Visible',visHide);
  230.         elseif num_btn==act
  231.             hdl_btn = GetHdlPUS(fig,num_btn);
  232.             setToggle(0,hdl_btn);
  233.             act     = [];
  234.             oldpos  = ud.newpos;
  235.             newpos  = ud.oldpos;
  236.             visHide = 'on';
  237.             tmp = ud.axeTMP;          
  238.             tmp = tmp(ishandle(tmp));
  239.             set(tmp,'Visible',visHide);
  240.             ud.axeTMP = [];
  241.         else
  242.             hdl_btn_new = GetHdlPUS(fig,num_btn);
  243.             hdl_btn_old = GetHdlPUS(fig,act);
  244.             setToggle(0,hdl_btn_old);
  245.             setToggle(1,hdl_btn_new);
  246.             oldpos  = ud.newpos;
  247.             newpos  = ud.oldpos;
  248.             p_axe   = getPos(p_axe,newpos,oldpos);
  249.             oldpos  = savpos(num_btn,:);
  250.             newpos  = ud.zoompos;
  251.             act     = num_btn;
  252.             visHide = 'off';
  253.             tmp = ud.axeTMP;
  254.             tmp = tmp(ishandle(tmp));
  255.             set(tmp,'Visible','On');
  256.             ud.axeTMP = wfindobj(hdl(i_axe),'Visible','on');
  257.             set(ud.axeTMP,'Visible',visHide);
  258.         end
  259.         set(ud.hide,'Visible',visHide);
  260.         p_axe = getPos(p_axe,newpos,oldpos);
  261.         for k=1:length(hdl)
  262.             set(hdl(k),'position',p_axe(k,:));
  263.         end
  264.         ud.act    = act;
  265.         ud.oldpos = oldpos;
  266.         ud.newpos = newpos;
  267.         set(fig,'Userdata',ud);
  268.     case 'select'
  269.         if OKCloseFIG(fig) , return ; end
  270.         num_btn = varargin{1};
  271.         if ~isempty(num_btn)
  272.             refresh(fig);
  273.             dynvzaxe('zoom',fig,num_btn);
  274.         end
  275.     case 'close'
  276.         % in3 = flag for direct closing
  277.         %-------------------------------
  278.         ud = get(fig,'Userdata');
  279.         if ishandle(ud.caller)
  280.             act = ud.act;
  281.             if ~isempty(act) , dynvzaxe('zoom',fig,act); end
  282.             set(ud.hdlOff,'enable','on');
  283.             SetCloseFcn(ud)
  284.             togBtn = ud.callTog;
  285.             set(togBtn,'Value',0);
  286.         end
  287.         if nargin>2 ,  delete(fig); end
  288.     case 'stop'
  289.         figZaxe = wfindobj(0,'type','figure','tag',tag_figzaxe);
  290.         caller  = [];
  291.         if ~isempty(figZaxe)
  292.             for k = 1:length(figZaxe)
  293.                ud = get(figZaxe(k),'Userdata');
  294.                caller = [caller ud.caller];
  295.             end
  296.         end
  297.         [nul,indCaller] = intersect(caller,fig);
  298.         delete(figZaxe(indCaller));
  299.         
  300.     case 'exclude'
  301.         currentAxes = varargin{1};
  302.         ud.dynvzaxe.enable = 'off';
  303.         setappdata(currentAxes,'WTBX_UserData',ud);
  304.         
  305. end
  306. %=============================================================================%
  307. % INTERNAL FUNCTIONS
  308. %=============================================================================%
  309. %-----------------------------------------------------------------------------%
  310. function varargout = depOfMachine(varargin)
  311. scrSize = get(0,'ScreenSize');
  312. wclose  = 80*varargin{1};
  313. if scrSize(4)<=600
  314.     hclose = 22*varargin{2};
  315. else
  316.     hclose = 33*varargin{2};
  317. end
  318. varargout = {wclose,hclose};
  319. %-----------------------------------------------------------------------------%
  320. function [st,x] = setToggle(select,hdl)
  321. st = '';
  322. s = [8 8];
  323. if select,
  324.    x = {ones(s),zeros(s),zeros(s)};
  325. else
  326.    x = {0.6*ones(s),zeros(s),zeros(s)};
  327. end
  328. x = cat(3,x{:});
  329. if nargin>1
  330.     set(hdl,'String',st,'value',select,'cdata',x);
  331. end
  332. %-----------------------------------------------------------------------------%
  333. function hdlFig = hdlFigZaxe(fig,tag)
  334. hdlFig  = [];
  335. figZaxe = wfindobj(0,'type','figure','tag',tag);
  336. if ~isempty(figZaxe)
  337.     for k = 1:length(figZaxe)
  338.         ud = get(figZaxe(k),'Userdata');
  339.         try        
  340.           if isequal(fig,ud.caller)
  341.               hdlFig = figZaxe(k); break;
  342.           end
  343.         end
  344.     end
  345. end
  346. %-----------------------------------------------------------------------------%
  347. function pos_axe = getPos(pos_axe,newpos,oldpos)
  348. diltrans = newpos(3:4)./oldpos(3:4);
  349. diltrans = [newpos(1:2)-oldpos(1:2).*diltrans diltrans];
  350. for k=1:size(pos_axe,1);
  351.     pos_axe(k,1:2) = pos_axe(k,1:2).*diltrans(3:4)+diltrans(1:2);
  352.     pos_axe(k,3:4) = pos_axe(k,3:4).*diltrans(3:4);
  353. end
  354. %-----------------------------------------------------------------------------%
  355. function hideHdl = getHide(fig,pos_gra)
  356. ax      = wfindobj(get(fig,'children'),'flat','type','axes','Visible','off');
  357. hideHdl = wfindobj(ax,'Visible','on');
  358. uic     = wfindobj(fig,'type','uicontrol','Visible','on');
  359. pos_uic = get(uic,'Position');
  360. pos_uic = cat(1,pos_uic{:});
  361. bool    = zeros(size(pos_uic,1),1);
  362. pos_gra = [ pos_gra(1) pos_gra(1)+pos_gra(3) ...
  363.             pos_gra(2) pos_gra(2)+pos_gra(4) ...
  364.             ];
  365. bool = bool+pinrect(pos_uic(:,1:2),pos_gra);
  366. bool = bool + ...
  367.     pinrect([pos_uic(:,1)+pos_uic(:,3),pos_uic(:,2)+pos_uic(:,4)],pos_gra);
  368. bool = bool + ...
  369.     pinrect([pos_uic(:,1)+pos_uic(:,3)/2,pos_uic(:,2)+pos_uic(:,4)/2],pos_gra);
  370. hideHdl = [hideHdl; uic(bool>0)];
  371. %-----------------------------------------------------------------------------%
  372. function bool = pinrect(pts,rect)
  373. %PINRECT Determine if points lie in or on rectangle.
  374. %   Inputs:
  375. %     pts  - n-by-2 array of [x,y] data
  376. %     rect - 1-by-4 vector of [xlim ylim] for the rectangle
  377. %   Outputs:
  378. %     bool - length n binary vector 
  379. [i,j] = find(isnan(pts));
  380. bool = (pts(:,1)<rect(1))|(pts(:,1)>rect(2))|...
  381.        (pts(:,2)<rect(3))|(pts(:,2)>rect(4));
  382. bool = ~bool;
  383. bool(i) = 0;
  384. %-----------------------------------------------------------------------------%
  385. function hdlPUS = GetHdlPUS(fig,num)
  386. btn = wfindobj(fig,'style','togglebutton');
  387. for k =1:length(btn)
  388.     nn = get(btn(k),'Userdata');
  389.     if isequal(nn,num) , hdlPUS = btn(k); break; end
  390. end
  391. %-----------------------------------------------------------------------------%
  392. function SetCloseFcn(ud,CloseFcn)
  393. if nargin<2 , CloseFcn = ud.savClose.val; end
  394. set(ud.savClose.btn,'Callback',CloseFcn);
  395. set(ud.savClose.uim,'Callback',CloseFcn);
  396. set(ud.caller,'CloseRequestFcn',CloseFcn);
  397. %-----------------------------------------------------------------------------%
  398. function ok = OKCloseFIG(fig)
  399. ud     = get(fig,'Userdata');
  400. caller = ud.caller;
  401. if ~ishandle(caller)
  402.     ud.act    = [];
  403.     ud.caller = [];
  404.     set(fig,'Userdata',ud);
  405.     dynvzaxe('close',fig,'direct');
  406.     ok = 1;
  407. else
  408.     ok = 0;
  409. end
  410. %-----------------------------------------------------------------------------%
  411. %=============================================================================%