function menufcn(action)
%MENUFCN  Handles callbacks for Response Object context menus.
%
%   MENUFCN(ACTION) performs the action specified by ACTION, for the
%   Response Object associated with the Callback Object GCBO.

%   Authors: Karen Gondoly, 1-27-98
%   Revised: Adam DiVergilio, 2-2000
%   Copyright 1986-2000 The MathWorks, Inc. 
%   $Revision: 1.13 $  $Date: 2000/06/14 19:59:11 $

%---Get Response object associated with gcbo's uicontextmenu parent
Parent = get(gcbo,'Parent');
if ~strcmp(get(Parent,'Type'),'uicontextmenu')
   % GCBO is a submenu
   Parent = get(Parent,'Parent');
end
RespObj = get(Parent,'UserData');
ContextMenu = get(RespObj,'UIContextMenu');

switch action,

case 'propcallback',
   cstpropedit(RespObj);

case 'gridcallback',
   %---Grid Menu callback
   if strcmp(get(gcbo,'check'),'off'),
      set(RespObj,'Grid','on')
   else,
      set(RespObj,'Grid','off')
   end 
   
case 'groupcallback',
   %---Axes Grouping menu callback
   MenuName = get(gcbo,'Tag');
   set(RespObj,'AxesGrouping',lower(MenuName));
   
case 'selectios',
   %---I/O selector menu callback
   if strcmp(get(gcbo,'check'),'off'),
      set(RespObj,'ChannelSelector','on')
   else,
      set(RespObj,'ChannelSelector','off')
   end 
   
case 'selectmodels',
   %---Array selector menu callback
   if strcmp(get(gcbo,'check'),'off'),
      set(RespObj,'ArraySelector','on')
   else,
      set(RespObj,'ArraySelector','off')
   end 
   
case 'systemtoggle',
   %---System Name menu callback
   SysPos = get(gcbo,'Position');
   SysVis = get(RespObj,'SystemVisibility');
   
   if strcmp(get(gcbo,'check'),'off'),
      SysVis{SysPos} = 'on';
   else
      SysVis{SysPos} = 'off';
   end
   
   set(RespObj,'SystemVisibility',SysVis);
   
case 'togglemargin',
   %---Gain/Phase Margin Plot Option Menu callback
   if strcmp(get(gcbo,'check'),'off'),
      set(RespObj,'StabilityMargin','on')
   else,
      set(RespObj,'StabilityMargin','off')
   end 

case 'toggleallmargin',
   %---Gain/Phase Margin Plot Option Menu callback (all)
   if strcmp(get(gcbo,'check'),'off'),
      set(RespObj,'AllStabilityMargin','on')
   else,
      set(RespObj,'AllStabilityMargin','off')
   end 
   
case 'togglepeak',
   %---Peak Response Plot Option Menu callback
   if strcmp(get(gcbo,'check'),'off'),
      set(RespObj,'PeakResponse','on')
   else,
      set(RespObj,'PeakResponse','off')
   end 
   
case 'togglerise',
   %---Rise Time Plot Option Menu callback
   if strcmp(get(gcbo,'check'),'off'),
      set(RespObj,'RiseTime','on')
   else,
      set(RespObj,'RiseTime','off')
   end 
   
case 'togglesettling',
   %---Settling Time Plot Option Menu callback
   if strcmp(get(gcbo,'check'),'off'),
      set(RespObj,'SettlingTime','on')
   else,
      set(RespObj,'SettlingTime','off')
   end 

case 'togglesteady'
   %---Steady State Plot Option Menu callback
   if strcmp(get(gcbo,'check'),'off'),
      set(RespObj,'SteadyState','on')
   else,
      set(RespObj,'SteadyState','off')
   end 
   
case 'zoomcallback',
   %---Zoom menu callbacks
   ZoomPos = get(gcbo,'Position'); % 1 = 'on', 2 - 'xon', 3 = 'yon', 4 = 'reset'
   if strcmp(get(gcbo,'check'),'off'),
      switch ZoomPos,
      case 1, % X-Y
         set(RespObj,'Zoom','on');
      case 2, % X-only
         set(RespObj,'Zoom','xon')
      case 3, % Y-only
         set(RespObj,'Zoom','yon')
      case 4, % Out
         set(RespObj,'Zoom','reset');
      case 5, % Tight (Nyquist and nichols only)
         set(RespObj,'Zoom','tight');
      case 6, % Critical (Nyquist only)
         set(RespObj,'Zoom','critical');
      end % switch ZoomPos
   else
      if any(strcmp(get(RespObj,'Zoom'),{'tight','critical'})),
         set(RespObj,'Zoom','reset')
      else
         set(RespObj,'Zoom','off')
      end
   end  % if/else strcmp(...
   fig = get(RespObj,'Parent');
   WBMF = get(fig,'WindowButtonMotionFcn');
   if ~isempty(WBMF)
      feval(WBMF);
   end

end % switch action

%---Store Object in the Context Menu Userdata (This ensures the whole object,
%----and not just the Response Object parent is stored)
set(ContextMenu.Main,'UserData',RespObj);
