Code covered by the BSD License  

Highlights from
CTMSIM - an interactive freeway traffic macrosimulator

image thumbnail
from CTMSIM - an interactive freeway traffic macrosimulator by Alex Kurzhanskiy
Freeway traffic simulation based on Asymmetric Cell Transmission Model

save_dialog(varargin)
function answer = save_dialog(varargin)
% save_dialog Application M-file for save_dialog.fig
%    answer = save_dialog return the answer.
%    save_dialog('callback_name') invoke the named callback.
%    save_dialog([left bottom]) locates the dialog.
% Last Modified by GUIDE v2.5 08-Nov-2006 17:15:33

error(nargchk(0, 4, nargin))  % function takes only 0 or 4 argument

if nargin == 0 | isnumeric(varargin{1})  % LAUNCH GUI
  fig = openfig(mfilename,'reuse');

  % Generate a structure of handles to pass to callbacks, and store it. 
  handles = guihandles(fig);
  guidata(fig, handles);
  
  % Question
  if nargin == 2
    set(handles.text1, 'String', varargin{2});
  end

  % Position figure
  if nargin >= 1
    pos_size = get(fig,'Position');
    pos      = varargin{1};
    if length(pos) ~= 2
      error('SAVE_DIALOG: Input argument must be a 2-element vector.')
    end
    new_pos = [pos(1) pos(2) pos_size(3) pos_size(4)];
    set(fig, 'Position', new_pos, 'Visible', 'on')
    figure(fig);
  end

  % Wait for callbacks to run and window to be dismissed:
  uiwait(fig);

  % UIWAIT might have returned because the window was deleted using
  % the close box - in that case, return 'cancel' as the answer, and
  % don't bother deleting the window!
  if ~ishandle(fig)
    answer = 2;
  else
    % otherwise, we got here because the user pushed one of the two buttons.
    % retrieve the latest copy of the 'handles' struct, and return the answer.
    % Also, we need to delete the window.
    handles = guidata(fig);
    answer  = handles.answer;
    delete(fig);
  end
elseif ischar(varargin{1})   % INVOKE NAMED SUBFUNCTION OR CALLBACK
  try
    [varargout{1:nargout}] = feval(varargin{:});  % FEVAL switchyard
  catch
    disp(lasterr);
  end 
end

return;





function varargout = noButton_Callback(h, eventdata, handles, varargin)
handles.answer = 0;
guidata(h, handles);
uiresume(handles.figure1);

return;



function varargout = yesButton_Callback(h, eventdata, handles, varargin)
handles.answer = 1;
guidata(h,handles);
uiresume(handles.figure1);

return;


function varargout = cancelButton_Callback(h, eventdata, handles, varargin)
handles.answer = 2;
guidata(h,handles);
uiresume(handles.figure1);

return;

Contact us at files@mathworks.com