time | Calls | line |
---|
| | 1 | function varargout = snapnow(varargin)
|
| | 2 | %SNAPNOW Force a snapshot of output.
|
| | 3 | % SNAPNOW forces checking for figure and system changes when inside
|
| | 4 | % publishing, and acts as a DRAWNOW otherwise.
|
| | 5 |
|
| | 6 | % DATA = SNAPNOW('get') returns the persistent data which is generated
|
| | 7 | % and used during publishing.
|
| | 8 | %
|
| | 9 | % SNAPNOW('set', DATA) sets this persistent data. If empty, it is
|
| | 10 | % assumed that publishing is exiting. Otherwise it is assumed that
|
| | 11 | % publishing is commencing, and other initializations to this data occur.
|
| | 12 | %
|
| | 13 | % F = SNAPNOW('beginCell', iCell, ...) indicates that the cell iCell is
|
| | 14 | % being entered during publishing. SNAPNOW returns false, for its use in
|
| | 15 | % conditional breakpoints.
|
| | 16 | %
|
| | 17 | % F = SNAPNOW('endCell', iCell, ...) indicates that the cell iCell is
|
| | 18 | % being left. Again, SNAPNOW returns false, for its use in conditional
|
| | 19 | % breakpoints.
|
| | 20 | %
|
| | 21 | % These two forms may be combined:
|
| | 22 | %
|
| | 23 | % snapnow('endCell', 2, 'beginCell', 3)
|
| | 24 | %
|
| | 25 | % such as occurs on a cell-to-cell boundary.
|
| | 26 |
|
| | 27 | % Matthew J. Simoneau, October 2006
|
| | 28 | % Copyright 2006-2011 The MathWorks, Inc.
|
| | 29 |
|
< 0.001 | 5 | 30 | persistent data
|
< 0.001 | 5 | 31 | persistent cellStack
|
| | 32 |
|
| | 33 | % Return false to continue execution.
|
< 0.001 | 5 | 34 | if (nargout == 1)
|
< 0.001 | 5 | 35 | varargout = {false};
|
< 0.001 | 5 | 36 | end
|
| | 37 |
|
| | 38 | % Because publishing behaves so badly when there is an error in a
|
| | 39 | % conditional breakpoint (which there shouldn't be), put this all in a
|
| | 40 | % try-catch.
|
< 0.001 | 5 | 41 | try
|
| | 42 |
|
| | 43 | % Parse inputs.
|
< 0.001 | 5 | 44 | if nargin > 0
|
< 0.001 | 5 | 45 | switch varargin{1}
|
< 0.001 | 5 | 46 | case 'get'
|
| | 47 | varargout = {data};
|
| | 48 |
|
< 0.001 | 5 | 49 | case 'set'
|
| | 50 | cellStack = [];
|
| | 51 | data = varargin{2};
|
| | 52 | if isempty(data)
|
| | 53 | % Leaving publishing.
|
| | 54 | munlock;
|
| | 55 | data = [];
|
| | 56 | else
|
| | 57 | % Initializing publishing.
|
| | 58 | mlock;
|
| | 59 | data.counter = makeCounter(0);
|
| | 60 | data.pictureList = {};
|
| | 61 | data.placeList = [];
|
| | 62 | data.options.filenameGenerator = makeFilenameGenerator(data.baseImageName);
|
| | 63 |
|
| | 64 | % Systems.
|
| | 65 | data.plugins(1).check = @hasSimulink;
|
| | 66 | data.plugins(1).classname = 'internal.matlab.publish.PublishSimulinkSystems';
|
| | 67 | data.plugins(1).instance = [];
|
| | 68 |
|
| | 69 | % Figures.
|
| | 70 | data.plugins(2).check = @true;
|
| | 71 | data.plugins(2).classname = 'internal.matlab.publish.PublishFigures';
|
| | 72 | data.plugins(2).instance = [];
|
| | 73 |
|
| | 74 | % This gives us a placement for files with parse errors.
|
| | 75 | data.lastGo = 1;
|
| | 76 | end
|
| | 77 |
|
< 0.001 | 5 | 78 | case 'append'
|
| | 79 | % Undocumented prototype code for creating animated GIFs.
|
| | 80 | %
|
| | 81 | % SNAPNOW is being called to createa an animation.
|
| | 82 | %
|
| | 83 | % For example: snapnow('append')
|
| | 84 |
|
| | 85 | if isempty(data)
|
| | 86 | % Running normally, outside the context of publishing.
|
| | 87 | if (nargin > 1)
|
| | 88 | pause(varargin{2})
|
| | 89 | end
|
| | 90 | drawnow
|
| | 91 | else
|
| | 92 | % Inside the context of publishing.
|
| | 93 | if (nargin > 1)
|
| | 94 | data.append = varargin{2};
|
| | 95 | else
|
| | 96 | data.append = Inf;
|
| | 97 | end
|
| | 98 | iCell = cellStack(end);
|
| | 99 | data = leavingCell(iCell, data, true);
|
| | 100 | data = enteringCell(iCell, data, false);
|
| | 101 | data = rmfield(data,'append');
|
| | 102 | end
|
| | 103 |
|
< 0.001 | 5 | 104 | otherwise
|
| | 105 | % SNAPNOW is being called in a conditional breakpoint at a
|
| | 106 | % cell boundary. Pairs of arguments are processed in turn.
|
| | 107 | %
|
| | 108 | % For example: snapnow('endCell', 2, 'beginCell', 3);
|
| | 109 |
|
| | 110 | % Assume odd inputs are either beginCell or endCell.
|
< 0.001 | 5 | 111 | exiting = strcmp(varargin(1:2:end), 'endCell');
|
< 0.001 | 5 | 112 | iCell = [varargin{2:2:end}];
|
| | 113 |
|
| | 114 | % We've exited the file, perhaps prematurely.
|
< 0.001 | 5 | 115 | iCell(iCell < 0) = data.lastGo;
|
| | 116 |
|
| | 117 | % Short-circuit when this is a redundancy.
|
| | 118 | % That is, when entering a cell that is alreay on the stack.
|
| | 119 | % or leaving a cell that is not on the stack.
|
0.008 | 5 | 120 | toRemove = xor(ismember(iCell, cellStack), exiting);
|
< 0.001 | 5 | 121 | exiting(toRemove) = [];
|
< 0.001 | 5 | 122 | iCell(toRemove) = [];
|
| | 123 |
|
| | 124 | % Do a capture/compare on only the first "beginCell" or
|
| | 125 | % "endCell". Subsequent cases would recapture the same info.
|
< 0.001 | 5 | 126 | doCapture = false(size(iCell));
|
< 0.001 | 5 | 127 | doCapture(1) = true;
|
| | 128 |
|
| | 129 | % Take the appropriate action for each pair.
|
< 0.001 | 5 | 130 | for k = 1:numel(iCell)
|
< 0.001 | 10 | 131 | if exiting(k)
|
< 0.001 | 5 | 132 | cellStack(cellStack == iCell(k)) = [];
|
0.160 | 5 | 133 | data = leavingCell(iCell(k), data, doCapture(k));
|
< 0.001 | 5 | 134 | else
|
< 0.001 | 5 | 135 | cellStack(end + 1) = iCell(k); %#ok<AGROW>
|
0.002 | 5 | 136 | data = enteringCell(iCell(k), data, doCapture(k));
|
< 0.001 | 10 | 137 | end
|
< 0.001 | 10 | 138 | end
|
| | 139 |
|
< 0.001 | 5 | 140 | end
|
| | 141 | else
|
| | 142 | % Called directly with no arguments from user code.
|
| | 143 | if isempty(data)
|
| | 144 | % Running normally, outside the context of publishing.
|
| | 145 | drawnow
|
| | 146 | else
|
| | 147 | % Inside the context of publishing.
|
| | 148 | iCell = cellStack(end);
|
| | 149 | data = leavingCell(iCell, data, true);
|
| | 150 | data = enteringCell(iCell, data, false);
|
| | 151 | end
|
< 0.001 | 5 | 152 | end
|
| | 153 |
|
| | 154 | catch e
|
| | 155 | % Something went wrong in the publishing infrastructure.
|
| | 156 | disp(getReport(e))
|
| | 157 |
|
| | 158 | end
|
| | 159 |
|
< 0.001 | 5 | 160 | end
|
Other subfunctions in this file are not included in this listing.