summaryrefslogtreecommitdiff
path: root/graphics/pgf/contrib/yquant/tex/yquant-draw.tex
diff options
context:
space:
mode:
Diffstat (limited to 'graphics/pgf/contrib/yquant/tex/yquant-draw.tex')
-rw-r--r--graphics/pgf/contrib/yquant/tex/yquant-draw.tex218
1 files changed, 167 insertions, 51 deletions
diff --git a/graphics/pgf/contrib/yquant/tex/yquant-draw.tex b/graphics/pgf/contrib/yquant/tex/yquant-draw.tex
index 7527e1ea05..574a45eec1 100644
--- a/graphics/pgf/contrib/yquant/tex/yquant-draw.tex
+++ b/graphics/pgf/contrib/yquant/tex/yquant-draw.tex
@@ -9,16 +9,12 @@
\ifx\yquant@draw@init@type\yquant@register@type@none%
% in case the wire was discarded before, forget about the lastx position, it should always start with the others
\yquant@register@get@lastwire{#1}\wirelast%
- \expandafter\expandafter\expandafter\ifstrempty\expandafter\expandafter\expandafter{%
- \expandafter\@thirdoffour\wirelast%
- }{%
- \yquant@register@set@lastwire{#1}{%
- {\yquant@draw@subcircuit@wirestart}{\yquant@draw@subcircuit@wirestart}{}%
- {\unexpanded\expandafter\expandafter\expandafter{%
- \expandafter\@fourthoffour\wirelast%
- }}%
- }%
- }\relax
+ \yquant@register@set@lastwire{#1}{%
+ {\yquant@draw@subcircuit@wirestart}{\yquant@draw@subcircuit@wirestart}{}%
+ {\unexpanded\expandafter\expandafter\expandafter{%
+ \expandafter\@fourthoffour\wirelast%
+ }}%
+ }%
\fi%
\yquant@register@set@type{#1}{#2}%
\fi%
@@ -476,51 +472,142 @@
\let\yquant@draw@subcircuit@wirestart=\newx%
\let\yquant@parent=\yquant@prefix%
\def\yquant@prefix{yquant@env#1@}%
- \ifstrempty{#2}{%
- % we make sure there are no conflicts by prefixing any named nodes in any case.
+ \pgfkeysgetvalue{/tikz/name prefix}\yquant@draw@subcircuit@prevprefix%
+ % name mangling
+ \ifcase\yquant@config@operator@subcircuit@mangling\relax%
+ % prefix or discard: if we have an outer name, use it as the prefix; if not, discard all names
+ \ifstrempty{#2}{%
+ % we make sure there are no conflicts by prefixing any named nodes in any case.
+ \pgfkeys{/tikz/name prefix/.expanded={sub\yquant@prefix-}}%
+ \let\pgf@nodecallback=\yquant@draw@subcircuit@nodecallback%
+ }{%
+ \pgfkeys{/tikz/name prefix/.expanded={\yquant@draw@subcircuit@prevprefix#2-}}%
+ \ifnum#3=1 %
+ \let\pgf@nodecallback=\yquant@draw@subcircuit@nodecallback%
+ \fi%
+ }%
+ \or%
+ % prefix or transparent: if we have an outer name, use it as a prefix; if not, directly use the outer namespace
+ \ifstrempty{#2}\relax{%
+ \pgfkeys{/tikz/name prefix/.expanded={\yquant@draw@subcircuit@prevprefix#2-}}%
+ \ifnum#3=1 %
+ \let\pgf@nodecallback=\yquant@draw@subcircuit@nodecallback%
+ \fi%
+ }%
+ \or%
+ % transparent: all names go directly in the outer namespace
+ \or%
+ % discard: no name will be visible in the outer namespace whatsoever
\pgfkeys{/tikz/name prefix/.expanded={sub\yquant@prefix-}}%
\let\pgf@nodecallback=\yquant@draw@subcircuit@nodecallback%
- }{%
- \pgfkeys{/tikz/name prefix/.expanded={\pgfkeysvalueof{/tikz/name prefix}#2-}}%
- \ifnum#3=1 %
- \let\pgf@nodecallback=\yquant@draw@subcircuit@nodecallback%
- \fi%
- }%
+ \else%
+ \PackageError{yquant.sty}{Assertion failure}{Unknown value for name mangling.}%
+ \fi%
\pgfkeys{/yquant/operators/this subcircuit box/.style={}}%
\edef\yquant@draw@subcircuit@style{%
/yquant/every operator, \yquant@draw@@style,%
/yquant/this operator, /yquant/internal/multi main=true,%
- }
+ }%
\expandafter\tikzset\expandafter{\yquant@draw@subcircuit@style}%
- \csname\yquant@prefix draw\endcsname%
- \dimen0=\yquant@register@get@y1\relax%
- \ifdim\dimen0>\pgf@picmaxy %
- \global\pgf@picmaxy=\dimen0 %
- \fi%
- \dimen0=\dimexpr\yquant@register@get@y{\csname\yquant@prefix registers\endcsname}\relax%
- \ifdim\dimen0<\pgf@picminy %
- \global\pgf@picminy=\dimen0 %
+ \begingroup%
+ \csname\yquant@prefix draw\endcsname%
+ \endgroup%
+ % BEGIN_FOLD bounding box
+ % Completely empty wires did not yet affect the bounding box
+ % Problem: we compare an user-mode TikZ position (register y position) with a system-level pgf position (picture boundary box). If shifts or scalings are in effect, we must first transform the point appropriately. Note that negative scalings may upset our assumption of which is the minimum and which is the maximum! If additionally rotations are in effect, we must even consider those transformations for the leftmost and the rightmost point, which makes all of this far more complicated than it should be. For this reason, we have a shortcut in action in case no nontranslation transformations are present.
+ \ifpgf@pt@identity%
+ \dimen0=\dimexpr\yquant@register@get@y1+\pgf@pt@y\relax%
+ \ifdim\dimen0>\pgf@picmaxy %
+ \global\pgf@picmaxy=\dimen0 %
+ \fi%
+ \dimen0=\dimexpr\yquant@register@get@y{\csname\yquant@prefix registers\endcsname}+\pgf@pt@y\relax%
+ \ifdim\dimen0<\pgf@picminy %
+ \global\pgf@picminy=\dimen0 %
+ \fi%
+ \else%
+ % first wire, left end
+ \pgfpointtransformed{\pgfqpoint{\yquant@draw@@x-.5\dimexpr\@firstofthree#4\relax}{\yquant@register@get@y1\relax}}%
+ \ifdim\pgf@y>\pgf@picmaxy %
+ \global\pgf@picmaxy=\pgf@y %
+ \fi%
+ \ifdim\pgf@y<\pgf@picminy % negative scaling
+ \global\pgf@picminy=\pgf@y %
+ \fi%
+ % first wire, right end
+ \pgfpointtransformed{\pgfqpoint{\yquant@draw@@x+.5\dimenxpr\@firstofthree#4\relax}{\yquant@register@get@y1\relax}}%
+ \ifdim\pgf@y>\pgf@picmaxy %
+ \global\pgf@picmaxy=\pgf@y %
+ \fi%
+ \ifdim\pgf@y<\pgf@picminy % negative scaling
+ \global\pgf@picminy=\pgf@y %
+ \fi%
+ % last wire, left end
+ \pgfpointtransformed{\pgfqpoint{\yquant@draw@@x-.5\dimexpr\@firstofthree#4\relax}{\yquant@register@get@y{\csname\yquant@prefix registers\endcsname}\relax}}%
+ \ifdim\pgf@y>\pgf@picmaxy %
+ \global\pgf@picmaxy=\pgf@y %
+ \fi%
+ \ifdim\pgf@y<\pgf@picminy % negative scaling
+ \global\pgf@picminy=\pgf@y %
+ \fi%
+ % last wire, right end
+ \pgfpointtransformed{\pgfqpoint{\yquant@draw@@x+.5\dimenxpr\@firstofthree#4\relax}{\yquant@register@get@y{\csname\yquant@prefix registers\endcsname}\relax}}%
+ \ifdim\pgf@y>\pgf@picmaxy %
+ \global\pgf@picmaxy=\pgf@y %
+ \fi%
+ \ifdim\pgf@y<\pgf@picminy % negative scaling
+ \global\pgf@picminy=\pgf@y %
+ \fi%
\fi%
- \ifnum#3=1 %
- % we must apply the aliasing to all the included nodes. We do this in this group, which still has the callback available, so that the aliased nodes will also be added to the list and can propagate (note that the number of node names is then exponential in the number of nested subcircuits)
- \protected\def\yquant@draw@subcircuit@alias@do##1#2-##2\relax##3\relax{%
- \ifstrempty{##1}{%
- \pgfnodealias{\yquant@draw@subcircuit@alias@removezero#2-##2}{#2-##2}%
- \@gobble% there is an additional \relax
- }\relax%
- }%
- \forlistcsloop%
- {\yquant@draw@subcircuit@alias{#2}}\yquant@draw@subcircuit@nodelist%
+ % END_FOLD
+ \ifnum\yquant@config@operator@subcircuit@mangling<2 %
+ % only bother with aliasing if the prefix is present at all
+ \ifnum#3=1 %
+ \ifstrempty{#2}\relax{%
+ % we must apply the aliasing to all the included nodes. We do this in this group, which still has the callback available, so that the aliased nodes will also be added to the list and can propagate (note that the number of node names is then exponential in the number of nested subcircuits)
+ \pgfkeysgetvalue{/tikz/name prefix}\yquant@draw@subcircuit@alias@prefix%
+ \expandafter\protected\expandafter\edef\expandafter%
+ \yquant@draw@subcircuit@alias@do\expandafter##\expandafter1\yquant@draw@subcircuit@alias@prefix##2\relax##3\relax{%
+ \noexpand\ifstrempty{##1}{%
+ \noexpand\pgfnodealias{\yquant@draw@subcircuit@prevprefix\yquant@draw@subcircuit@alias@removezero#2-##2}{\yquant@draw@subcircuit@alias@prefix##2}%
+ \noexpand\@gobble% there is an additional \relax
+ }\relax%
+ }%
+ \expandafter\forlistcsloop\expandafter%
+ {\expandafter\yquant@draw@subcircuit@alias\expandafter{%
+ \yquant@draw@subcircuit@alias@prefix}%
+ }\yquant@draw@subcircuit@nodelist%
+ }%
+ \fi%
\fi%
}}%
+ \ifpgf@pt@identity%
+ \dimen0=\dimexpr.5\pgf@picminy+.5\pgf@picmaxy-\pgf@pt@y\relax%
+ \dimen2=\dimexpr\pgf@picmaxy-\pgf@picminy\relax%
+ \else%
+ \begingroup%
+ \pgftransforminvert%
+ \pgfpointtransformed{\pgfqpoint{\pgf@picminx}{\pgf@picminy}}%
+ \@tempdima=\pgf@y%
+ \pgfpointtransform{\pgfqpoint{\pgf@picmaxx}{\pgf@picmaxy}}%
+ \edef\cmd{\@tempdima=\the\@tempdima\space\@tempdimb=\the\@tempdimb\space}%
+ \expandafter%
+ \endgroup%
+ \cmd%
+ \pgfpointtransformed{\pgfqpoint{\yquant@draw@@x}%
+ {.5\dimexpr\@tempdima+\@tempdimb\relax}}%
+ \dimen0=\pgf@y%
+ \pgfpointtransformed{\pgfqpoint{\yquant@draw@@x}%
+ {\dimexpr\@tempdimb-\@tempdima\relax}}%
+ \dimen2=\pgf@y%
+ \fi%
\edef\cmd{%
- \noexpand\path (\yquant@draw@@x, \the\dimexpr.5\pgf@picminy+.5\pgf@picmaxy\relax)%
+ \noexpand\path (\yquant@draw@@x, \the\dimen0)%
node[/yquant/every operator, \yquant@draw@@style,%
/yquant/operators/every subcircuit box, /yquant/this operator,%
/yquant/operators/this subcircuit box,%
/yquant/internal/multi main=true,%
name prefix=, name suffix=, name=yquantbox]%
- {\vbox to \the\dimexpr\pgf@picmaxy-\pgf@picminy\relax {\hbox to \@firstofthree#4 {}}};%
+ {\vbox to \the\dimen2 {\hbox to \@firstofthree#4 {}}};%
}%
\cmd%
\unhbox\yquant@prepare@subcircuit@box%
@@ -535,8 +622,40 @@
% Now that the subcircuit is finished, we need advance all the wires
\dimdef\newx{\yquant@draw@@x+.5\dimexpr\yquant@draw@@width\relax}%
\forlistloop\yquant@draw@group@advance{#5}%
- \ifstrempty{#2}{%
- % However, if the outer node was not named, no access to the inner nodes is desired, so we delete all nodes again.
+ % name mangling
+ \ifcase\yquant@config@operator@subcircuit@mangling\relax%
+ % prefix or discard
+ \ifstrempty{#2}{%
+ % However, if the outer node was not named, no access to the inner nodes is desired, so we delete all nodes again.
+ \def\do##1{%
+ \csgundef{pgf@sh@ns@##1}%
+ \csgundef{pgf@sh@np@##1}%
+ \csgundef{pgf@sh@nt@##1}%
+ \csgundef{pgf@sh@pi@##1}%
+ \csgundef{pgf@sh@ma@##1}%
+ }%
+ \dolistcsloop{\yquant@draw@subcircuit@nodelist}%
+ \csgundef\yquant@draw@subcircuit@nodelist%
+ }{%
+ \ifcsname\yquant@prefix draw@subcircuit@nodelist\endcsname%
+ \csxappto{\yquant@prefix draw@subcircuit@nodelist}%
+ {\csname\yquant@draw@subcircuit@nodelist\endcsname}%
+ \fi%
+ }%
+ \or%
+ % prefix or transparent: in any case, make everything available for mangling in the outer circuit
+ \ifcsname\yquant@prefix draw@subcircuit@nodelist\endcsname%
+ \csxappto{\yquant@prefix draw@subcircuit@nodelist}%
+ {\csname\yquant@draw@subcircuit@nodelist\endcsname}%
+ \fi%
+ \or%
+ % transparent: same
+ \ifcsname\yquant@prefix draw@subcircuit@nodelist\endcsname%
+ \csxappto{\yquant@prefix draw@subcircuit@nodelist}%
+ {\csname\yquant@draw@subcircuit@nodelist\endcsname}%
+ \fi%
+ \or%
+ % discard: remove them all
\def\do##1{%
\csgundef{pgf@sh@ns@##1}%
\csgundef{pgf@sh@np@##1}%
@@ -546,18 +665,15 @@
}%
\dolistcsloop{\yquant@draw@subcircuit@nodelist}%
\csgundef\yquant@draw@subcircuit@nodelist%
- }{%
- \ifcsname\yquant@prefix draw@subcircuit@nodelist\endcsname%
- \csxappto{\yquant@prefix draw@subcircuit@nodelist}%
- {\csname\yquant@draw@subcircuit@nodelist\endcsname}%
- \fi%
- }%
+ \else%
+ \PackageError{yquant.sty}{Assertion failure}{Unknown value for name mangling (2).}%
+ \fi%
}
\def\yquant@draw@subcircuit@alias@removezero#1-0{#1}
\def\yquant@draw@subcircuit@alias#1#2{%
- \yquant@draw@subcircuit@alias@do#2\relax#1-0-\relax\relax%
+ \yquant@draw@subcircuit@alias@do#2\relax#10-\relax\relax%
}
\protected\long\def\yquant@draw@subcircuit@single#1#2#3#4#5{%
@@ -606,7 +722,7 @@
\yquant@softpath@extractmaxxat\nonaffectedpgfshapeclippathhorzresult%
{\yquant@register@get@y\i}%
\let\pgfshapeclippathhorzresult=\empty%
- \yquant@circuit@extendwire\i{*}%
+ \yquant@circuit@extendwire\i*%
}{%
\let\pgfshapeclippathhorzresult=\nonaffectedpgfshapeclippathhorzresult%
\yquant@circuit@extendwire\i{center}%
@@ -767,9 +883,9 @@
\pgf@picmaxy=0pt %
\fi%
\pgftransforminvert%
- \pgfpointtransformednonlinear{\pgfqpoint{\pgf@picminx}{\pgf@picminy}}%
+ \pgfpointtransformed{\pgfqpoint{\pgf@picminx}{\pgf@picminy}}%
\global\@tempdima=\pgf@y%
- \pgfpointtransformednonlinear{\pgfqpoint{\pgf@picmaxx}{\pgf@picmaxy}}%
+ \pgfpointtransformed{\pgfqpoint{\pgf@picmaxx}{\pgf@picmaxy}}%
\global\@tempdimb=\pgf@y%
\endgroup%
% To avoid rendering artifacts at all zoom levels with all renderers, we need to make the clipping region large. Let's try the current bounding box first.