time | Calls | line |
---|
| | 61 | function newFiles = leavingCell(obj,~)
|
| | 62 | % Before doing anything else, especially DRAWNOW, get the
|
| | 63 | % figure order.
|
0.009 | 5 | 64 | figuresOriginal = allchild(0);
|
| | 65 |
|
| | 66 | % Determine which figures need a snapshot.
|
0.011 | 5 | 67 | newFigures = internal.matlab.publish.captureFigures;
|
0.015 | 5 | 68 | figuresToSnap = internal.matlab.publish.compareFigures(obj.savedState, newFigures);
|
| | 69 |
|
| | 70 | % Use the original order, just in case they have been moved
|
| | 71 | % about by the operating system during DRAWNOWs.
|
0.031 | 5 | 72 | missingFigures = setdiff(figuresToSnap,figuresOriginal)';
|
0.009 | 5 | 73 | isSnapped = ismember(figuresOriginal,figuresToSnap);
|
< 0.001 | 5 | 74 | figuresToSnap = flipud(figuresOriginal(isSnapped));
|
< 0.001 | 5 | 75 | figuresToSnap = [figuresToSnap; missingFigures];
|
| | 76 |
|
| | 77 | % Take a snapshot of the each figure that needs it.
|
| | 78 | % Ensure that for figures docked to a
|
| | 79 | % matlabshared.scopes.Container, only one snapshot is taken per
|
| | 80 | % container when leaving the cell.
|
< 0.001 | 5 | 81 | newFiles = cell(size(figuresToSnap));
|
< 0.001 | 5 | 82 | figContainersSnapped = cell(size(figuresToSnap));
|
< 0.001 | 5 | 83 | for figuresToSnapCount = 1:numel(figuresToSnap)
|
| | 84 | f = figuresToSnap(figuresToSnapCount);
|
| | 85 |
|
| | 86 | isDocked = strcmpi(f.WindowStyle,'docked');
|
| | 87 | grpName = '';
|
| | 88 | if isDocked
|
| | 89 | % Determine the group name
|
| | 90 | [lastWarnMsg,lastWarnId] = lastwarn;
|
| | 91 | warnstate = warning('off','MATLAB:HandleGraphics:ObsoletedProperty:JavaFrame');
|
| | 92 | jf = get(f, 'JavaFrame');
|
| | 93 | warning(warnstate); % Restore the original warning state
|
| | 94 | % restore the last warning thrown
|
| | 95 | lastwarn(lastWarnMsg, lastWarnId);
|
| | 96 | if ~isempty(jf)
|
| | 97 | grpName = char(jf.getGroupName);
|
| | 98 | end
|
| | 99 | end
|
| | 100 | % Do not snap if we have already snapped the
|
| | 101 | % group/container to which the figure belongs.
|
| | 102 | shouldSnap = ~isDocked || (isDocked && ~any(strcmpi(figContainersSnapped,grpName)));
|
| | 103 |
|
| | 104 | if shouldSnap
|
| | 105 | imgFilename = snap(obj, f);
|
| | 106 | if isDocked && ismember(grpName,internal.matlab.publish.PublishFigures.setgetContainerNames)
|
| | 107 | % Add the group/container name that was snapped
|
| | 108 | figContainersSnapped{figuresToSnapCount} = grpName;
|
| | 109 | end
|
| | 110 |
|
| | 111 | % Add to list of figures.
|
| | 112 | newFiles{figuresToSnapCount} = imgFilename;
|
| | 113 | end
|
| | 114 |
|
| | 115 | end
|
| | 116 |
|
| | 117 | % Remove empty filename as it will error with fileparts call to
|
| | 118 | % determine the file extension and result in empty file
|
| | 119 | % references.
|
< 0.001 | 5 | 120 | newFiles(cellfun('isempty',newFiles)) = [];
|
| | 121 |
|
| | 122 | % Update SNAPNOW's view of the current state of figures.
|
| | 123 | % Since the process of printing can change certain properties,
|
| | 124 | % recapture figures to prevent extra snaps.
|
0.008 | 5 | 125 | obj.savedState = internal.matlab.publish.captureFigures;
|
| | 126 |
|
| | 127 | % Restore the figures to the original order, in case printing
|
| | 128 | % or something else jostled them.
|
< 0.001 | 5 | 129 | try
|
| | 130 | % Use ishandle to ignore figures which have closed.
|
< 0.001 | 5 | 131 | set(0,'children',figuresOriginal(ishandle(figuresOriginal)));
|
| | 132 | catch e
|
| | 133 | if strcmp(e.identifier,'MATLAB:hg:g_object:BadChildren')
|
| | 134 | warning(e.identifier,e.message)
|
| | 135 | else
|
| | 136 | rethrow(e)
|
| | 137 | end
|
| | 138 | end
|
< 0.001 | 5 | 139 | end
|
Other subfunctions in this file are not included in this listing.