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

波变换

开发平台:

Matlab

  1. function [out1,out2] = mngmbtn(option,fig,varargin)
  2. %MNGMBTN Manage mouse buttons for the dynamical visualization tool.
  3. %   M. Misiti, Y. Misiti, G. Oppenheim, J.M. Poggi 01-May-96.
  4. %   Last Revision: 22-May-2003.
  5. %   Copyright 1995-2004 The MathWorks, Inc.
  6. % $Revision: 1.13.4.2 $
  7. EraseMode = 'xor';
  8. msel_box  = 'n';
  9. msel_trans = 'e';
  10. msel_txt   = 'a';
  11. msel_open  = 'o';
  12. switch option
  13.     case 'move'
  14.         %**********************************************%
  15.         %** OPTION = 'move' DEPLACEMENT DE LA SOURIS **%
  16.         %**********************************************%
  17.         %   DynV_Axe_Sel    = in3(1);
  18.         %   Edi_PosX   = in3(2); (optional)
  19.         %   Edi_PosY   = in3(3); (optional)
  20.         %   mouseT = in4 (selection type)
  21.         %-----------------------------------------
  22.         if get(0,'PointerWindow')~=fig , return; end
  23.         DynV_Axe_Sel = varargin{1}(1);
  24.         mouseT = varargin{2};
  25.         
  26.         [q,x,y] = waxecp(fig,DynV_Axe_Sel);
  27.         if prod(x-q(1))>0 | prod(y-q(2))>0
  28.             % set(fig,'WindowButtonMotionFcn','wtmotion','WindowButtonUpFcn','');
  29.             set(fig,'Pointer','arrow');
  30.             if mouseT~=msel_box , mngmbtn('delLines',fig,'V_H'); end
  31.         %--- selection d'un rectangle ---%
  32.         elseif mouseT==msel_box
  33.             dVTmemB = dynvtool('rmb',fig);
  34.             DynV_Sel_Box = dVTmemB.DynV_Sel_Box;       
  35.             if ~isempty(DynV_Sel_Box)
  36.                 pzbx = get(DynV_Sel_Box,'XData');
  37.                 pzby = get(DynV_Sel_Box,'YData');
  38.                 set(DynV_Sel_Box,...
  39.                         'XData', [pzbx(1) q(1) q(1) pzbx(1) pzbx(1)],...
  40.                         'YData', [pzby(1) pzby(1) q(2) q(2) pzby(1)]);
  41.             end
  42.         %--- ecriture de la position ---%
  43.         elseif mouseT==msel_txt
  44.             dVTmemB = dynvtool('rmb',fig);
  45.             DynV_Line_Hor = dVTmemB.DynV_Line_Hor;
  46.             DynV_Line_Ver = dVTmemB.DynV_Line_Ver;
  47.             if isempty(DynV_Line_Hor) , return; end
  48.             set(DynV_Line_Hor,'YData',[q(2) q(2)]);
  49.             set(DynV_Line_Ver,'XData',[q(1) q(1)]);
  50.             if length(varargin{1})<3 , return; end
  51.             Edi_PosX = varargin{1}(2);
  52.             Edi_PosY = varargin{1}(3);
  53.             mempos_coor = get(Edi_PosX,'UserData');
  54.             fcn_wri   = wmemutil('get',mempos_coor,1);
  55.             param_wri = wmemutil('get',mempos_coor,2);
  56.             if isempty(param_wri)
  57.                [sx,sy] = feval(fcn_wri,q(1),q(2),DynV_Axe_Sel);
  58.             else
  59.                [sx,sy] = feval(fcn_wri,q(1),q(2),DynV_Axe_Sel,param_wri);
  60.             end
  61.             set(Edi_PosX,'String',sx);
  62.             set(Edi_PosY,'String',sy);
  63.         
  64.         %--- gestion des translations ---%
  65.         elseif mouseT==msel_trans
  66.             dVTmemB = dynvtool('rmb',fig);
  67.             DynV_Line_Hor = dVTmemB.DynV_Line_Hor;
  68.             DynV_Line_Ver = dVTmemB.DynV_Line_Ver;
  69.             if isempty(DynV_Line_Hor) , return; end
  70.             x1 = get(DynV_Line_Hor,'XData');
  71.             y1 = get(DynV_Line_Hor,'YData');
  72.             u  = get(DynV_Axe_Sel,'Units');
  73.             rect = get(DynV_Axe_Sel,'Position');
  74.             rx = abs((x1(2)-q(1))/(x(2)-x(1)));
  75.             ry = abs((y1(2)-q(2))/(y(2)-y(1)));
  76.             k  = rect(3)*rx-rect(4)*ry;
  77.             if k>0
  78.                 set(DynV_Line_Hor,...
  79.                         'XData',[x1(2) x1(2) x1(2)],...
  80.                         'YData',[y(1)  y1(2) y(2) ] ...
  81.                         );
  82.                 set(DynV_Line_Ver,...
  83.                         'XData',[q(1) q(1) q(1)],   ...
  84.                         'YData',[y(1) q(2) y(2)]    ...
  85.                         );
  86.                 DynV_Flg_Trans = 1;
  87.             elseif k<0
  88.                 set(DynV_Line_Hor,...
  89.                         'XData',[x(1)  x1(2) x(2) ],...
  90.                         'YData',[y1(2) y1(2) y1(2)] ...
  91.                         );
  92.                 set(DynV_Line_Ver,...
  93.                         'XData',[x(1) q(1) x(2)],   ...
  94.                         'YData',[q(2) q(2) q(2)]    ...
  95.                         );
  96.                 DynV_Flg_Trans = 2;
  97.             else
  98.                 DynV_Flg_Trans = 0;
  99.             end
  100.             dVTmemB.flgTrans = DynV_Flg_Trans;
  101.             dynvtool('wmb',fig,dVTmemB);
  102.         end
  103.     case 'down'
  104.         %***************************************************%
  105.         %** OPTION = 'down' UN BOUTON DE LA SOURIS APPUYE **%
  106.         %***************************************************%
  107.         if isempty(find(wfindobj('figure')==fig)) , return; end
  108.         if get(0,'PointerWindow')~=fig
  109.             dVTmemB = mngmbtn('delLines',fig,'All');
  110.         else
  111.             dVTmemB = dynvtool('rmb',fig);
  112.         end
  113.         mouse  = get(fig,'SelectionType');
  114.         mouseT = mouse(1);
  115.         
  116.         axe_hdls = dVTmemB.axeInd;
  117.         if mouseT==msel_txt
  118.             % DynV_Axe_Act + DynV_Axe_Ind
  119.             axe_hdls = [dVTmemB.axeAct , axe_hdls];
  120.         else    
  121.             % DynV_Axe_Cmd + DynV_Axe_Ind
  122.             axe_hdls = [dVTmemB.axeCmd , axe_hdls];
  123.         end
  124.         axe_hdls = findobj(axe_hdls,'flat','Visible','on');
  125.         DynV_Axe_Sel = [];
  126.         for i=1:length(axe_hdls)
  127.             ax      = axe_hdls(i);
  128.             [q,x,y] = waxecp(fig,ax);
  129.             if  prod(x-q(1))<0 && prod(y-q(2))<0
  130.                 DynV_Axe_Sel = ax;
  131.                 break;
  132.             end
  133.         end
  134.         dVTmemB.axeSel = DynV_Axe_Sel;
  135. dynvtool('wmb',fig,dVTmemB);
  136.         dVTmemB = mngmbtn('delLines',fig,'Down',dVTmemB,DynV_Axe_Sel,mouseT);
  137. if isempty(DynV_Axe_Sel) , return; end
  138.         wtbxappdata('new',fig,'save_WindowButtonUpFcn',get(fig,'WindowButtonUpFcn'));
  139.         Edi_PosX = dVTmemB.handles.Edi_PosX;
  140.         Edi_PosY = dVTmemB.handles.Edi_PosY;
  141.         DynV_Col_Line = dVTmemB.linColor;
  142.         %--- selection d'un rectangle ---%
  143.         switch mouseT
  144.             case msel_box
  145.                 set(fig,'Pointer','crosshair', ...
  146.                         'CurrentAxes',DynV_Axe_Sel);
  147.                 if ~isempty(Edi_PosX)
  148.                     set(Edi_PosX,'String','X = ');
  149.                     set(Edi_PosY,'String','Y = ');
  150.                 end
  151.                 DynV_Sel_Box = line(...
  152.                         'Color',DynV_Col_Line,...
  153.                         'EraseMode',EraseMode,...
  154.                         'XData',[q(1) q(1) q(1) q(1) q(1)],...
  155.                         'YData',[q(2) q(2) q(2) q(2) q(2)] ...
  156.                         );
  157.                 dVTmemB.DynV_Sel_Box = DynV_Sel_Box;
  158.         %--- ecriture de la position ---%
  159.             case msel_txt
  160.                 set(fig,'Pointer','crosshair', ...
  161.                         'CurrentAxes',DynV_Axe_Sel);
  162.                 DynV_Line_Hor = line(...
  163.                         'Color',DynV_Col_Line,...
  164.                         'EraseMode',EraseMode,...
  165.                         'XData',[x(1) x(2)],...
  166.                         'YData',[q(2) q(2)] ...
  167.                         );
  168.                 DynV_Line_Ver = line(...
  169.                         'Color',DynV_Col_Line,...
  170.                         'EraseMode',EraseMode,...
  171.                         'XData',[q(1) q(1)],...
  172.                         'YData',[y(1) y(2)] ...
  173.                         );
  174.                 dVTmemB.DynV_Line_Hor = DynV_Line_Hor;
  175.                 dVTmemB.DynV_Line_Ver = DynV_Line_Ver;
  176.                 if ~isempty(Edi_PosX)
  177.                     mempos_coor = get(Edi_PosX,'UserData');
  178.                     fcn_wri   = wmemutil('get',mempos_coor,1);
  179.                     param_wri = wmemutil('get',mempos_coor,2);
  180.                     if isempty(param_wri)
  181.                        [sx,sy] = feval(fcn_wri,q(1),q(2),DynV_Axe_Sel);
  182.                     else
  183.                        [sx,sy] =  ...
  184.                             feval(fcn_wri,q(1),q(2),DynV_Axe_Sel,param_wri);
  185.                     end
  186. dynvtool('set_BtnOnOff',fig,'On','Info');
  187.                     set(Edi_PosX,'String',sx);
  188.                     set(Edi_PosY,'String',sy);
  189.                 end
  190.         %--- gestion des translations ---%
  191.             case msel_trans
  192.                 set(fig,'Pointer','crosshair','CurrentAxes',DynV_Axe_Sel);
  193.                 if ~isempty(Edi_PosX)
  194.                     set(Edi_PosX,'String','X = ');
  195.                     set(Edi_PosY,'String','Y = ');
  196.                 end
  197.                 DynV_Line_Hor = line(...
  198.                         'LineStyle','--',...
  199.                         'Color',DynV_Col_Line,...
  200.                         'EraseMode',EraseMode,...
  201.                         'XData',[x(1) q(1) x(2)],...
  202.                         'YData',[q(2) q(2) q(2)] ...
  203.                         );
  204.                 DynV_Line_Ver = line(...
  205.                         'LineStyle','--',...
  206.                         'Color',DynV_Col_Line,...
  207.                         'EraseMode',EraseMode',...
  208.                         'XData',[q(1) q(1) q(1)],...
  209.                         'YData',[y(1) q(2) y(2)] ...
  210.                         );
  211.                 dVTmemB.DynV_Line_Hor = DynV_Line_Hor;
  212.                 dVTmemB.DynV_Line_Ver = DynV_Line_Ver;
  213.                 dVTmemB.flgTrans = 0;
  214.         %--- open ---%
  215.             case msel_open
  216.               set(fig,'Pointer','arrow');
  217.               mempos_coor = get(Edi_PosX,'UserData');
  218.               fcn_sel = wmemutil('get',mempos_coor,3);
  219.               if ~isempty(fcn_sel)
  220.   param_sel = wmemutil('get',mempos_coor,4);
  221.   if isempty(param_sel)
  222.   [sx,sy] = feval(fcn_sel,q(1),q(2),DynV_Axe_Sel);
  223.   else
  224.   [sx,sy] = feval(fcn_sel,q(1),q(2),DynV_Axe_Sel,param_sel);
  225.   end
  226.   if ~isempty(sx)
  227.   DynV_Line_Hor = line(...
  228.   'Color',DynV_Col_Line,...
  229.   'EraseMode',EraseMode,...
  230.   'XData',[x(1) x(2)],...
  231.   'YData',[q(2) q(2)] ...
  232.   );
  233.   DynV_Line_Ver = line(...
  234.   'Color',DynV_Col_Line,...
  235.   'EraseMode',EraseMode,...
  236.   'XData',[q(1) q(1)],...
  237.   'YData',[y(1) y(2)] ...
  238.   );
  239.   if ~isempty(Edi_PosX)
  240.   set(Edi_PosX,'String',sx);
  241.   set(Edi_PosY,'String',sy);
  242.   end
  243.   dVTmemB.DynV_Line_Hor = DynV_Line_Hor;
  244.   dVTmemB.DynV_Line_Ver = DynV_Line_Ver;
  245.   end
  246.   end
  247.         end
  248. handles  = num2mstr([DynV_Axe_Sel,Edi_PosX,Edi_PosY]);
  249.         % format = '%.0f';  % OLD 
  250.         format = '%20.15f'; % NEW
  251.         strNumFig = sprintf(format,fig);
  252. endstr   = [strNumFig ',' handles ',''' mouseT ''');'];
  253. cba_move = [mfilename '(''move'',' endstr];
  254. cba_up   = [mfilename '(''up'',' endstr];
  255. set(fig,'WindowButtonMotionFcn',cba_move,'WindowButtonUpFcn',cba_up);
  256. dynvtool('wmb',fig,dVTmemB);
  257.     case 'up'
  258.         %*************************************************%
  259.         %** OPTION = 'up' UN BOUTON DE LA SOURIS APPUYE **%
  260.         %*************************************************%
  261.         %   mouseT = in4 (selection type)
  262.         %-----------------------------------------
  263.         DynV_Axe_Sel = varargin{1}(1);
  264.         save_WindowButtonUpFcn = wtbxappdata('del',fig,'save_WindowButtonUpFcn');
  265. eval(save_WindowButtonUpFcn);
  266.         set(fig,'WindowButtonMotionFcn','wtmotion',...
  267.     'WindowButtonUpFcn',save_WindowButtonUpFcn);
  268. set(fig,'Pointer','arrow');
  269.         mouseT  = varargin{2};
  270. if mouseT==msel_open ,  return; end
  271.         dVTmemB = dynvtool('rmb',fig);
  272.         %--- gestion des translations ---%
  273.         if mouseT==msel_trans
  274.             DynV_Line_Hor = dVTmemB.DynV_Line_Hor;
  275.             DynV_Line_Ver = dVTmemB.DynV_Line_Ver;
  276.             DynV_Flg_Trans = dVTmemB.flgTrans;
  277.             if DynV_Flg_Trans==1
  278.                 x1 = get(DynV_Line_Hor,'XData');
  279.                 x2 = get(DynV_Line_Ver,'XData');
  280.                 dx = x2(2)-x1(2);
  281.             elseif DynV_Flg_Trans==2
  282.                 y1 = get(DynV_Line_Hor,'YData');
  283.                 y2 = get(DynV_Line_Ver,'YData');
  284.                 dy = y2(2)-y1(2);
  285.             end
  286.             dVTmemB = mngmbtn('delLines',fig,'V_H',dVTmemB);
  287.             DynV_Axe_Ind = dVTmemB.axeInd;
  288.             if ~isempty(DynV_Axe_Ind) && ...
  289.                ~isempty(find(DynV_Axe_Sel==DynV_Axe_Ind))
  290.                 DynV_Axe_Act  = DynV_Axe_Sel;
  291.                 DynV_XY_Const = [0 0];
  292.             else
  293.                 DynV_Axe_Act  = dVTmemB.axeAct;
  294.                 DynV_XY_Const = dVTmemB.xyConst;
  295.             end
  296.             if DynV_Flg_Trans==1
  297.                 x0 = get(DynV_Axe_Sel,'XLim');
  298.                 if DynV_XY_Const(1)~=0
  299.                     set(DynV_Axe_Act,'XLim',x0-dx);
  300.                 else
  301.                     set(DynV_Axe_Sel,'XLim',x0-dx);
  302.                 end
  303.                 dynvtool('put',fig);
  304.             elseif DynV_Flg_Trans==2
  305.                 y0 = get(DynV_Axe_Sel,'YLim');
  306.                 if DynV_XY_Const(2)~=0
  307.                     set(DynV_Axe_Act,'YLim',y0-dy);
  308.                 else
  309.                     set(DynV_Axe_Sel,'YLim',y0-dy);
  310.                 end
  311.                 dynvtool('put',fig);
  312.             end
  313.         elseif mouseT==msel_box
  314.             DynV_Sel_Box = dVTmemB.DynV_Sel_Box;
  315.             xd = get(DynV_Sel_Box,'Xdata');
  316.             yd = get(DynV_Sel_Box,'Ydata');
  317.             xl = get(DynV_Axe_Sel,'xlim');
  318.             yl = get(DynV_Axe_Sel,'ylim');
  319.             tol = 0.01;
  320.             if abs((max(xd)-min(xd))/(xl(2)-xl(1)))<tol  | ....
  321.                abs((max(yd)-min(yd))/(yl(2)-yl(1)))<tol
  322.                 mngmbtn('delLines',fig,'Box',dVTmemB);
  323. else
  324. dynvtool('set_BtnOnOff',fig,'On','Zoom');
  325.             end
  326.         end
  327.     case 'getbox'
  328.         %****************************************************%
  329.         %** OPTION = 'getbox' LECTURE DU RECTANGLE DE ZOOM **%
  330.         %****************************************************%
  331.         dVTmemB = dynvtool('rmb',fig);
  332.         DynV_Sel_Box = dVTmemB.DynV_Sel_Box;
  333.         if ~isempty(DynV_Sel_Box)
  334.             out1 = get(DynV_Sel_Box,'XData');
  335.             out2 = get(DynV_Sel_Box,'YData');
  336.             if (min(out1)==max(out1)) | (min(out2)==max(out2))
  337.                 mngmbtn('delLines',fig,'Box',dVTmemB);
  338.                 out1 = [];
  339.                 out2 = [];
  340.             end
  341.         else
  342.             out1 = [];
  343.             out2 = [];
  344.         end
  345.     case 'delLines'
  346.         if nargin<4 , 
  347.             dVTmemB = dynvtool('rmb',fig);
  348.         else
  349.             dVTmemB = varargin{2};
  350.         end
  351.         linHDL = [];
  352.         switch varargin{1}
  353.           case 'Box' ,
  354.             linHDL = dVTmemB.DynV_Sel_Box;
  355.             dVTmemB.DynV_Sel_Box  = [];
  356.           case {'V_H','H_V'}
  357.             linHDL = [dVTmemB.DynV_Line_Hor,dVTmemB.DynV_Line_Ver];
  358.             dVTmemB.DynV_Line_Hor = [];
  359.             dVTmemB.DynV_Line_Ver = [];
  360.           case {'All','Down'}
  361.             linHDL = [dVTmemB.DynV_Sel_Box,...
  362.                       dVTmemB.DynV_Line_Hor,dVTmemB.DynV_Line_Ver];
  363.             dVTmemB.DynV_Sel_Box  = [];
  364.             dVTmemB.DynV_Line_Hor = [];
  365.             dVTmemB.DynV_Line_Ver = [];
  366.         end
  367.         delete(linHDL(ishandle(linHDL)));
  368.         dynvtool('wmb',fig,dVTmemB);
  369. if ~isequal(varargin{1},'V_H') && ~isequal(varargin{1},'H_V')
  370. switch varargin{1}
  371. case 'All'  , typCall = 'All';
  372. case 'Box'  , typCall = 'Zoom';
  373. case 'Down'
  374. DynV_Axe_Sel = varargin{3};
  375. mouseT =  varargin{4};
  376. if ~isempty(DynV_Axe_Sel) && isequal(mouseT,msel_txt)
  377. typCall = 'All';
  378. % typCall = 'Zoom';
  379. else
  380. typCall = 'All';
  381. end
  382. end
  383. dynvtool('set_BtnOnOff',fig,'Off',typCall);
  384. end
  385.         out1 = dVTmemB;
  386.     case 'getLines'
  387.         if nargin<4 , 
  388.             dVTmemB = dynvtool('rmb',fig);
  389.         else
  390.             dVTmemB = varargin{2};
  391.         end
  392.         switch lower(varargin{1})
  393.           case 'box' , out1  = dVTmemB.DynV_Sel_Box;
  394.           case 'hor' , out1  = dVTmemB.DynV_Line_Hor;
  395.           case 'ver' , out1  = dVTmemB.DynV_Line_Ver;
  396.           case 'all' ,
  397.             out1  = [dVTmemB.DynV_Sel_Box,dVTmemB.DynV_Line_Hor,dVTmemB.DynV_Line_Ver];
  398.         end
  399.     case 'cleanXYPos'
  400.         handles = dynvtool('handles',fig);
  401.         Edi_PosX = handles.Edi_PosX;
  402.         Edi_PosY = handles.Edi_PosY;
  403.         set(Edi_PosX,'String','X = ');
  404.         set(Edi_PosY,'String','Y = ');
  405.     otherwise
  406.         errargt(mfilename,'Unknown Option','msg');
  407.         error('*');
  408. end