0001 function rest_waitbar(APercent, AMessage, ATitle, AIsUpdateWho, ANeedCancel, ACancelCallback)
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017 global hParent hChild;
0018 persistent Last_UpdateClock;
0019 if isempty(Last_UpdateClock),
0020 Last_UpdateClock =clock;
0021 setappdata(0, 'FlagToRaiseError','no');
0022 end
0023
0024
0025 if isappdata(0, 'FlagToRaiseError') ...
0026 && strcmpi(getappdata(0, 'FlagToRaiseError'), 'Yes'),
0027
0028 rmappdata(0, 'FlagToRaiseError');
0029
0030 error('User canceled the operation!');
0031 end
0032
0033 if nargin==0
0034
0035 if rest_misc( 'ForceCheckExistFigure' , hParent)
0036 close(hParent);
0037 end
0038 if rest_misc( 'ForceCheckExistFigure' , hChild)
0039 close(hChild);
0040 end
0041 clear hParent hChild;
0042 elseif (nargin==1)||(nargin==3)
0043
0044 if rest_misc( 'ForceCheckExistFigure' , hChild)
0045 if (nargin==1)
0046 rest_progress(APercent,hChild);
0047 elseif nargin==3
0048 rest_progress(APercent,hChild, AMessage, 'Name', ATitle);
0049 end
0050 else
0051 error('progress bar has not initialized.');
0052 end
0053 elseif nargin==4 || nargin==5 ||nargin==6
0054
0055 if nargin==4
0056 ANeedCancel ='I don''t need';
0057 ACancelCallback ='';
0058 elseif nargin==5
0059 ACancelCallback ='';
0060 elseif nargin==6
0061
0062 end
0063 if strcmpi(AIsUpdateWho, 'parent')
0064 GetHandleOrCreate('parent', 'true', ANeedCancel, ACancelCallback);
0065
0066 rest_progress(APercent,hParent,sprintf('Total progress:\n%s',AMessage), 'Name', ATitle);
0067 elseif strcmpi(AIsUpdateWho, 'child')
0068 GetHandleOrCreate('child', 'true', ANeedCancel, ACancelCallback);
0069
0070 if rest_misc( 'ForceCheckExistFigure' , hParent)
0071 theMsg =sprintf('Current progress:\n%s',AMessage);
0072 else
0073 theMsg =AMessage;
0074 end
0075
0076 rest_progress(APercent,hChild, theMsg, 'Name', ATitle);
0077 if etime(clock, Last_UpdateClock)>1
0078 Last_UpdateClock =clock;
0079 if rest_misc( 'ForceCheckExistFigure' , hParent)
0080 rest_progress(-1,hParent);
0081 end
0082 end
0083 end
0084
0085 if rest_misc( 'ForceCheckExistFigure' , hParent) ...
0086 && rest_misc( 'ForceCheckExistFigure' , hChild) ,
0087 theParentPosition =get(hParent, 'Position');
0088 theChildPosition =get(hChild, 'Position');
0089 theChildPosition(1) =theParentPosition(1);
0090 theChildPosition(2) = theParentPosition(4) +theParentPosition(2) +50;
0091 set(hChild, 'Position', theChildPosition);
0092 end
0093 else
0094 error('Bad call to rest_waitbar(AIsUpdateWho, APercent, AMessage, ATitle)');
0095 end
0096
0097
0098 function GetHandleOrCreate(AIsCheckWho, AIsCreate, ANeedCancel, ACancelCallback)
0099 global hParent hChild
0100
0101 if strcmpi(AIsCheckWho, 'parent')
0102 hParent = findobj(allchild(0),'flat','Tag','DParent_Waitbar');
0103 if isempty(hParent) && strcmpi(AIsCreate, 'true') ...
0104 && ~rest_misc( 'ForceCheckExistFigure' , hParent),
0105
0106 if strcmpi(ANeedCancel,'NeedCancelBtn'),
0107 hParent=rest_progress(0,'Total Progress','Tag','DParent_Waitbar', ...
0108 'CreateCancelBtn', @BtnCancelCallback);
0109 else
0110 hParent=rest_progress(0,'Total Progress','Tag','DParent_Waitbar');
0111 end
0112 end
0113 elseif strcmpi(AIsCheckWho, 'child')
0114 hChild = findobj(allchild(0),'flat','Tag','DChild_Waitbar');
0115 if isempty(hChild) && strcmpi(AIsCreate, 'true') ...
0116 && ~rest_misc( 'ForceCheckExistFigure' , hChild),
0117
0118 if strcmpi(ANeedCancel,'NeedCancelBtn'),
0119 hChild=rest_progress(0,'Current Progress','Tag','DChild_Waitbar', ...
0120 'CreateCancelBtn', @BtnCancelCallback);
0121 else
0122 hChild=rest_progress(0,'Current Progress','Tag','DChild_Waitbar');
0123 end
0124 end
0125 end
0126 function BtnCancelCallback(h,varargin)
0127
0128
0129
0130
0131 setappdata(0, 'FlagToRaiseError',questdlg('Cancel calculating?','Confirm','Cancel'));
0132
0133
0134
0135
0136
0137