| 1 |
% Copyright 2022 by Qrrbrbirlbel |
| 2 |
% |
| 3 |
% This file may be distributed and/or modified |
| 4 |
% |
| 5 |
% 1. under the LaTeX Project Public License and/or |
| 6 |
% 2. under the GNU Free Documentation License. |
| 7 |
% |
| 8 |
|
| 9 |
\pgfdeclarelayer{discard} |
| 10 |
|
| 11 |
\def\tikzext@layers@swapfirstsetbox#1\setbox#2\tikzext@stop{% |
| 12 |
#1\tikzext@layers@setbox@which#2% |
| 13 |
} |
| 14 |
\def\tikzext@layers@whichbox{\tikz@figbox}% |
| 15 |
\let\tikzext@layers@setbox@which\setbox |
| 16 |
|
| 17 |
\def\tikzextshowdiscardlayeranyway{\box\pgf@layerbox@discard} |
| 18 |
\pgfqkeys{/tikz/ext/layers}{ |
| 19 |
discard layer/.code=\expandafter\let\csname pgf@layerbox@#1\endcsname\pgfutil@voidb@x, |
| 20 |
discard layer global/.code=\expandafter\global\expandafter\let\csname pgf@layerbox@#1\endcsname\pgfutil@voidb@x, |
| 21 |
in box/.code={% |
| 22 |
\expandafter\ifx\tikzext@layers@whichbox#1% |
| 23 |
\pgfutil@packagewarning{tikz-ext}{Layer is already set. Setting will be skipped.}% |
| 24 |
\else |
| 25 |
\def\tikzext@layers@whichbox{#1}% |
| 26 |
\def\tikz@whichbox{#1}% |
| 27 |
\def\tikzext@layers@setbox@which{\global\setbox}% |
| 28 |
\fi |
| 29 |
}, |
| 30 |
on layer/.style={ |
| 31 |
/tikz/ext/layers/in box/.expand once=\csname pgf@layerbox@#1\endcsname |
| 32 |
}, |
| 33 |
discard/.style={ |
| 34 |
/tikz/ext/layers/on layer=discard |
| 35 |
}, |
| 36 |
patch/.is choice, |
| 37 |
patch/all/.style={ |
| 38 |
/tikz/ext/layers/patch/@common patch, |
| 39 |
/tikz/ext/layers/patch/node, |
| 40 |
/tikz/ext/layers/patch/matrix, |
| 41 |
/tikz/ext/layers/patch/pic, |
| 42 |
/tikz/ext/layers/patch/edge, |
| 43 |
}, |
| 44 |
patch/@common patch/.style={ |
| 45 |
/tikz/behind path/.append code =\let\tikzext@layers@setbox@which\setbox, |
| 46 |
/tikz/in front of path/.append code =\let\tikzext@layers@setbox@which\setbox, |
| 47 |
/tikz/ext/layers/patch/@common patch/.code=% |
| 48 |
}, |
| 49 |
patch/node/.style={% |
| 50 |
/utils/exec=% |
| 51 |
\expandafter\expandafter\expandafter\def |
| 52 |
\expandafter\expandafter\expandafter\tikz@fig@continue |
| 53 |
\expandafter\expandafter\expandafter{\expandafter\tikzext@layers@swapfirstsetbox\tikz@fig@continue\tikzext@stop},% |
| 54 |
/tikz/ext/layers/patch/@common patch, |
| 55 |
/tikz/ext/layers/patch/node/.code=\pgfutil@packagewarning{tikz-ext}{You can't apply the layers patch twice.}, |
| 56 |
/tikz/ext/discard node/.style ={/tikz/ext/layers/discard}, |
| 57 |
/tikz/ext/node on layer/.style={/tikz/ext/layers/on layer={##1}}, |
| 58 |
/tikz/ext/node in box/.style ={/tikz/ext/layers/in box={##1}}, |
| 59 |
}, |
| 60 |
patch/matrix/.style={% |
| 61 |
/utils/exec=% |
| 62 |
\expandafter\expandafter\expandafter\def |
| 63 |
\expandafter\expandafter\expandafter\tikz@do@matrix |
| 64 |
\expandafter\expandafter\expandafter{\expandafter\tikzext@layers@swapfirstsetbox\tikz@do@matrix\tikzext@stop},% |
| 65 |
/tikz/ext/layers/patch/@common patch, |
| 66 |
/tikz/ext/layers/patch/matrix/.code=\pgfutil@packagewarning{tikz-ext}{You can't apply the layers patch twice.}, |
| 67 |
/tikz/execute at begin matrix={% in case patched node/edge/pic is used inside matrix |
| 68 |
\let\tikzext@layers@setbox@which\setbox |
| 69 |
\def\tikz@whichbox{\tikz@figbox}% |
| 70 |
\tikzextset{layers/in box/.code=\pgfutil@packageerror{tikz-ext}{Layers inside a matrix can't be used.}}% |
| 71 |
}, |
| 72 |
/tikz/ext/discard matrix/.style ={/tikz/ext/layers/discard}, |
| 73 |
/tikz/ext/matrix on layer/.style={/tikz/ext/layers/on layer={##1}}, |
| 74 |
/tikz/ext/matrix in box/.style ={/tikz/ext/layers/in box={##1}}, |
| 75 |
}, |
| 76 |
patch/edge/.style={% |
| 77 |
/utils/exec=\let\tikz@do@edge\tikzext@layers@tikz@do@edge, |
| 78 |
/tikz/ext/layers/patch/@common patch, |
| 79 |
/tikz/ext/layers/patch/edge/.code=\pgfutil@packagewarning{tikz-ext}{You can't apply the layers patch twice.}, |
| 80 |
/tikz/ext/discard edge/.style={/tikz-ext/layers/discard}, |
| 81 |
/tikz/ext/edge on layer/.style={ |
| 82 |
/tikz/ext/layers/on layer={##1} |
| 83 |
}, |
| 84 |
/tikz/ext/edge in box/.style={/tikz/ext/layers/in box={##1}}, |
| 85 |
}, |
| 86 |
patch/pic/.style={% |
| 87 |
/utils/exec=\let\tikz@subpicture@handle@\tikzext@layers@tikz@subpicture@handle@, |
| 88 |
/tikz/ext/layers/patch/@common patch, |
| 89 |
/tikz/ext/layers/patch/pic/.code=\pgfutil@packagewarning{tikz-ext}{You can't apply the layers patch twice.}, |
| 90 |
/tikz/ext/discard pic/.style={/tikz/ext/layers/discard}, |
| 91 |
/tikz/ext/pic on layer/.style={/tikz/ext/layers/on layer={##1}}, |
| 92 |
/tikz/ext/pic in box/.style={/tikz/ext/layers/in box={##1}}, |
| 93 |
} |
| 94 |
} |
| 95 |
\def\tikzext@layers@tikz@do@edge{% |
| 96 |
\ifx\tikz@edge@macro\pgfutil@empty% |
| 97 |
\tikzext@layers@setbox@which\tikz@whichbox=\hbox\bgroup% |
| 98 |
\unhbox\tikz@whichbox% |
| 99 |
\hbox\bgroup |
| 100 |
\bgroup% |
| 101 |
\pgfinterruptpath% |
| 102 |
\pgfscope% |
| 103 |
\let\tikz@transform=\pgfutil@empty% |
| 104 |
\let\tikz@options=\pgfutil@empty% |
| 105 |
\tikz@clear@rdf@options% |
| 106 |
\let\tikz@tonodes=\tikz@collected@onpath% |
| 107 |
\def\tikztonodes{{\pgfextra{\tikz@node@is@a@labeltrue}\tikz@tonodes}}% |
| 108 |
\let\tikz@collected@onpath=\pgfutil@empty% |
| 109 |
\tikz@options% |
| 110 |
\tikz@do@rdf@pre@options% |
| 111 |
\pgfidscope% |
| 112 |
\tikz@do@rdf@post@options% |
| 113 |
\tikz@transform% |
| 114 |
\let\tikz@transform=\relax% |
| 115 |
% Typeset node: |
| 116 |
\let\tikz@after@path\pgfutil@empty% |
| 117 |
\tikz@atbegin@to% |
| 118 |
\tikz@enable@edge@quotes% |
| 119 |
% in case patched nodes/edges/pics/matrices are used |
| 120 |
\let\tikzext@layers@setbox@which\setbox |
| 121 |
\def\tikz@whichbox{\tikz@figbox}% |
| 122 |
\path[style=every edge]\expandafter[\tikz@@to@local@options](\tikztostart)\tikz@to@path |
| 123 |
\pgfextra{\global\let\tikz@after@path@smuggle=\tikz@after@path};% |
| 124 |
\tikz@atend@to% |
| 125 |
\endpgfidscope% |
| 126 |
\endpgfscope% |
| 127 |
\endpgfinterruptpath% |
| 128 |
\egroup |
| 129 |
\egroup% |
| 130 |
\egroup% |
| 131 |
\ifx\tikzext@layers@setbox@which\setbox |
| 132 |
\global\setbox\tikz@tempbox=\box\tikz@whichbox% |
| 133 |
\expandafter\endgroup% |
| 134 |
\expandafter\setbox\tikz@whichbox=\box\tikz@tempbox% |
| 135 |
\else |
| 136 |
\endgroup |
| 137 |
\fi |
| 138 |
\else% |
| 139 |
\expandafter\expandafter\expandafter\tikz@edge@macro% |
| 140 |
\expandafter\expandafter\expandafter{\expandafter\tikz@@to@local@options\expandafter}\expandafter{\tikz@collected@onpath}% |
| 141 |
\endgroup% |
| 142 |
\let\tikz@after@path@smuggle=\pgfutil@empty% |
| 143 |
\fi% |
| 144 |
\expandafter\tikz@scan@next@command\tikz@after@path@smuggle% |
| 145 |
}% |
| 146 |
\def\tikzext@layers@tikz@subpicture@handle@#1{ |
| 147 |
\pgfkeys{/tikz/pics/.cd,#1}% |
| 148 |
\tikz@node@transformations% |
| 149 |
\let\tikz@transform=\relax% |
| 150 |
\let\tikz@picmode\tikz@mode% |
| 151 |
\tikzset{name prefix ../.style/.expanded={/tikz/name prefix=\pgfkeysvalueof{/tikz/name prefix}}}% |
| 152 |
\ifx\tikz@fig@name\pgfutil@empty\else% |
| 153 |
\tikzset{name prefix/.expanded=\tikz@fig@name}% |
| 154 |
\fi% |
| 155 |
\pgfkeysvalueof{/tikz/pics/setup code}% |
| 156 |
\pgfkeysgetvalue{/tikz/pics/code}{\tikz@pic@code} |
| 157 |
\ifx\tikz@pic@code\pgfutil@empty\else% Qrr: next line |
| 158 |
\tikzext@layers@setbox@which\tikz@whichbox=\hbox\bgroup% |
| 159 |
\unhbox\tikz@whichbox% |
| 160 |
\hbox\bgroup |
| 161 |
\bgroup% |
| 162 |
\pgfinterruptpath% |
| 163 |
\pgfscope% |
| 164 |
\tikz@options% |
| 165 |
% Qrr: in case patched node/matrix/edge/pic is used inside the pic |
| 166 |
\let\tikzext@layers@setbox@which\setbox |
| 167 |
\def\tikz@whichbox{\tikz@figbox}% |
| 168 |
\setbox\tikz@figbox=\box\pgfutil@voidb@x% |
| 169 |
\setbox\tikz@figbox@bg=\box\pgfutil@voidb@x% |
| 170 |
\tikz@atbegin@scope% |
| 171 |
\scope[every pic/.try]% |
| 172 |
\tikz@pic@code% |
| 173 |
\endscope% |
| 174 |
\tikz@atend@scope% |
| 175 |
\endpgfscope% |
| 176 |
\endpgfinterruptpath% |
| 177 |
\egroup |
| 178 |
\egroup% |
| 179 |
\egroup% |
| 180 |
\fi% |
| 181 |
\pgfkeysgetvalue{/tikz/pics/foreground code}{\tikz@pic@code} |
| 182 |
\ifx\tikz@pic@code\pgfutil@empty\else% |
| 183 |
\unless\ifx\tikzext@layers@setbox@which\setbox |
| 184 |
\pgfutil@packagewarning{tikz-ext}{Only the main pic code can be placed on selective layers.} |
| 185 |
\fi |
| 186 |
\setbox\tikz@figbox=\hbox\bgroup% |
| 187 |
\unhbox\tikz@figbox% |
| 188 |
\hbox\bgroup |
| 189 |
\bgroup% |
| 190 |
\pgfinterruptpath% |
| 191 |
\pgfscope% |
| 192 |
\tikz@options% |
| 193 |
\setbox\tikz@figbox=\box\pgfutil@voidb@x% |
| 194 |
\setbox\tikz@figbox@bg=\box\pgfutil@voidb@x% |
| 195 |
\tikz@atbegin@scope% |
| 196 |
\scope[every front pic/.try]% |
| 197 |
\tikz@pic@code% |
| 198 |
\endscope% |
| 199 |
\tikz@atend@scope% |
| 200 |
\endpgfscope% |
| 201 |
\endpgfinterruptpath% |
| 202 |
\egroup |
| 203 |
\egroup% |
| 204 |
\egroup% |
| 205 |
\fi% |
| 206 |
\pgfkeysgetvalue{/tikz/pics/background code}{\tikz@pic@code} |
| 207 |
\ifx\tikz@pic@code\pgfutil@empty\else% |
| 208 |
\unless\ifx\tikzext@layers@setbox@which\setbox |
| 209 |
\pgfutil@packagewarning{tikz-ext}{Only the main pic code can be placed on selective layers.} |
| 210 |
\fi |
| 211 |
\setbox\tikz@figbox@bg=\hbox\bgroup% |
| 212 |
\unhbox\tikz@figbox@bg% |
| 213 |
\hbox\bgroup |
| 214 |
\bgroup% |
| 215 |
\pgfinterruptpath% |
| 216 |
\pgfscope% |
| 217 |
\tikz@options% |
| 218 |
\setbox\tikz@figbox=\box\pgfutil@voidb@x% |
| 219 |
\setbox\tikz@figbox@bg=\box\pgfutil@voidb@x% |
| 220 |
\tikz@atbegin@scope% |
| 221 |
\scope[every behind pic/.try]% |
| 222 |
\tikz@pic@code% |
| 223 |
\endscope% |
| 224 |
\tikz@atend@scope% |
| 225 |
\endpgfscope% |
| 226 |
\endpgfinterruptpath% |
| 227 |
\egroup |
| 228 |
\egroup% |
| 229 |
\egroup% |
| 230 |
\fi% |
| 231 |
\tikz@node@finish% |
| 232 |
}% |
| 233 |
\endinput |
| 234 |
|
| 235 |
%%% Compatibility |
| 236 |
\tikzextset{ |
| 237 |
/tikz-ext/compat/add library={layers}{pre 0.6}, |
| 238 |
compat/layers/warn/.append code=% |
| 239 |
% \pgfkeyssetvalue{/tikz/ext/compat/layers@}{3}% |
| 240 |
\tikzextutil@compatwarning@key{layers}{pre 0.6}{/tikz-ext/patch} {/tikz/ext/layers/patch}% |
| 241 |
\tikzextutil@compatwarning@key{layers}{pre 0.6}{/tikz/node on layer} {/tikz/ext/node on layer}% |
| 242 |
\tikzextutil@compatwarning@key{layers}{pre 0.6}{/tikz/matrix on layer}{/tikz/ext/matrix on layer}% |
| 243 |
\tikzextutil@compatwarning@key{layers}{pre 0.6}{/tikz/edge on layer} {/tikz/ext/edge on layer}% |
| 244 |
\tikzextutil@compatwarning@key{layers}{pre 0.6}{/tikz/pic on layer} {/tikz/ext/pic on layer}, |
| 245 |
compat/layers/pre 0.6/.append code=% |
| 246 |
% \pgfkeyssetvalue{/tikz/ext/compat/layers@}{2}% |
| 247 |
\pgfkeysdef{/tikz-ext/patch} {\pgfkeysvalueof{/tikz/ext/layers/patch/.@cmd}##1\pgfeov}% |
| 248 |
\pgfkeysdef{/tikz/node on layer} {\pgfkeysvalueof{/tikz/ext/node on layer/.@cmd}##1\pgfeov}% |
| 249 |
\pgfkeysdef{/tikz/matrix on layer}{\pgfkeysvalueof{/tikz/ext/matrix on layer/.@cmd}##1\pgfeov}% |
| 250 |
\pgfkeysdef{/tikz/edge on layer} {\pgfkeysvalueof{/tikz/ext/edge on layer/.@cmd}##1\pgfeov}% |
| 251 |
\pgfkeysdef{/tikz/pic on layer} {\pgfkeysvalueof{/tikz/ext/pic on layer/.@cmd}##1\pgfeov}, |
| 252 |
% compat/layers/0.6/.append code=\pgfkeyssetvalue{/tikz/ext/compat/layers@}{1}, |
| 253 |
% compat/layers/newest/.append code=\pgfkeyssetvalue{/tikz/ext/compat/layers@}{0}, |
| 254 |
compat/layers/\pgfkeysvalueof{/tikz/ext/compat/layers}% |
| 255 |
} |
| 256 |
\endinput |