function varargout = commblktriggeredbuffer(block, varargin)
% COMMBLKTRIGGEREDBUFFER Mask dynamic dialog function for triggered buffer block

% Copyright 1996-2016 The MathWorks, Inc.

nvarargin = nargin - 1;

switch nvarargin
	case 0
		action = '';
	case 1
		action = varargin{1};
		Args = 0;
	otherwise
		action = varargin{1};
		Args = varargin{2:end};
end

% --- Field data
Vals	= get_param(block, 'maskvalues');
Vis	= get_param(block, 'maskvisibilities');
En  	= get_param(block, 'maskenables');

% --- Field numbers
StartSample    = 1;
NumChan        = 2;
InputWidthMode = 3;
InputWidth     = 4;
InputWidthMin  = 5;
InputWidthStep = 6;
InputWidthMax  = 7;

%*********************************************************************
% Function:			initialize
% Description:		Set the dialogs up based on the parameter values.
%						MaskEnables/MaskVisibles are not save in reference 
%						blocks.
% Inputs:			current block
% Return Values:	none
%
%********************************************************************

if(strcmp(action,'init'))
	feval(mfilename,block,'UpdateFields');
	%feval(mfilename,block,'UpdateBlocks',Args);
	[varargout{1}] = feval(mfilename,block,'UpdateWs',Args);
end

%----------------------------------------------------------------------
%	Block specific update functions
%----------------------------------------------------------------------

%*********************************************************************
% Function:			UpdateWs
% Description:		Set the simulink blocks as required
% Inputs:			current block
% Return Values:	none
%********************************************************************
if(strcmp(action,'UpdateWs'))
   % --- Set the block display strings
   s.i1 = 1; s.i1s = ''; 
   s.o1 = 1; s.o1s = 'f()';
   s.o2 = 2; s.o2s = 'Out';
   % --- Assign output arguments
   varargout{1} = s;
end

%*********************************************************************
% Function:			UpdateFields
% Description:		Update the dialog fields.
%						Indicate that block updates are not required
% Inputs:			current block
% Return Values:	none
%********************************************************************
if(strcmp(action,'UpdateFields'))
	feval(mfilename,block,'InputWidthMode',1);
end


%----------------------------------------------------------------------
%	Dynamic Dialog specific field functions
%----------------------------------------------------------------------
%*********************************************************************
% Function Name:	'InputWidthMode'
% Description:		Deal with the input width mode of the operation
% Inputs:			current block
%						Update mode: Args = 0, block update required
%										 Args = 1, no block update required
% Return Values:	none
%********************************************************************

if(strcmp(action,'InputWidthMode'))

   if(strcmp(Vals{InputWidthMode},'Specify'))
		if(strcmp(Vis{InputWidth},'off'))

         % --- The Specify mode is selected, but the width field is invisible
         %     so this field requires a change

         % --- Switch on the Specify related field
			Vis{InputWidth} = 'on';
			En{InputWidth}  = 'on';

         % --- Switch off the Based on output related fields
			Vis{InputWidthMin}  = 'off';
			Vis{InputWidthStep} = 'off';
			Vis{InputWidthMax}  = 'off';
			En{InputWidthMin}   = 'off';
			En{InputWidthStep}  = 'off';
			En{InputWidthMax}   = 'off';

			set_param(block,'MaskEnables',En,'MaskVisibilities',Vis);
			if(~Args)
            % --- If update of the block is required when the dynamic dialog
            %     changes, the uncomment the following
				%feval(mfilename,block,'UpdateBlocks');
			end
		end
   elseif(strcmp(Vals{InputWidthMode},'Inherit'))
		if(strcmp(Vis{InputWidth},'on') | strcmp(Vis{InputWidthMin},'on'))

         % --- The Inherit mode is selected, but the width field is visible
         %     so this field requires a change

         % --- Switch off the Specify related field
			Vis{InputWidth} = 'off';
			En{InputWidth}  = 'off';

         % --- Switch off the Based on output related fields
			Vis{InputWidthMin}  = 'off';
			Vis{InputWidthStep} = 'off';
			Vis{InputWidthMax}  = 'off';
			En{InputWidthMin}   = 'off';
			En{InputWidthStep}  = 'off';
			En{InputWidthMax}   = 'off';

			set_param(block,'MaskEnables',En,'MaskVisibilities',Vis);
			if(~Args)
            % --- If update of the block is required when the dynamic dialog
            %     changes, the uncomment the following
				%feval(mfilename,block,'UpdateBlocks');
			end
		end
   elseif(strcmp(Vals{InputWidthMode},'Based on output width'))
		if(strcmp(Vis{InputWidthMin},'off'))

         % --- The 'Based on output width' mode is selected, but the minimum 
         %     width field is invisible so this field requires a change

         % --- Switch off the Specify related field
			Vis{InputWidth} = 'off';
			En{InputWidth}  = 'off';

         % --- Switch off the Based on output related fields
			Vis{InputWidthMin}  = 'on';
			Vis{InputWidthStep} = 'on';
			Vis{InputWidthMax}  = 'on';
			En{InputWidthMin}   = 'on';
			En{InputWidthStep}  = 'on';
			En{InputWidthMax}   = 'on';

			set_param(block,'MaskEnables',En,'MaskVisibilities',Vis);
			if(~Args)
            % --- If update of the block is required when the dynamic dialog
            %     changes, the uncomment the following
				%feval(mfilename,block,'UpdateBlocks');
			end
		end
   else
      error(message('comm:commblktriggeredbuffer:InvalidMode'));
	end

end

% [EOF]
