function restack

% function restack
%
% This function is used in conjunction with FD3.  It is used to change the
% stacking order of the objects which compose FD3 flow diagrams.  Primary
% objects are given the highest priority in the stacking order and are drawn
% in FD3AXES(3).  Module labels, stream labels, streams, stream arrows, and
% text objects are given the second highest priority in the stacking order
% and are drawn in FD3AXES(2).  Boxes and secondary modules are given the
% lowest priority priority in the stacking order and are drawn in FD3AXES(1).
% This program changes the stacking order by judiciously calling the axes
% command a maximum of two times.
%
% ACP

% Last update:  July 11, 1993
% Author:       Adrian C. Penisson

global FD3AXES FD3FIGURE

child=get(FD3FIGURE,'Children');

pos1=find(FD3AXES(1)==child);
pos2=find(FD3AXES(2)==child);
pos3=find(FD3AXES(3)==child);

[junk,ranks]=sort([pos1 pos2 pos3]);

if all(ranks==[2 1 3]) | all(ranks==[2 1 3])
   % FD3AXES(3) is not on top but FD3AXES(2) is above AXES(1)
   axes(FD3AXES(3))
elseif ~all(ranks==[3 2 1])
   % FD3AXES is all out of whack.  Move FD3AXES(2) to top then move FD3AXES(3)
   % to the top.
   axes(FD3AXES(2))
   axes(FD3AXES(3))
end
