%%
%% This is file `pst-featdiag.tex',
%% generated with the docstrip utility.
%%
%% The original source files were:
%%
%% pst-featdiag.dtx  (with options: `pst-featdiag')
%% 
%% IMPORTANT NOTICE:
%% 
%% For the copyright see the source file.
%% 
%% Any modified versions of this file must be renamed
%% with new filenames distinct from pst-featdiag.tex.
%% 
%% For distribution of the original source see the terms
%% for copying and modification in the file pst-featdiag.dtx.
%% 
%% This generated file may be distributed as long as the
%% original source files, as listed above, are part of the
%% same distribution. (The sources need not necessarily be
%% in the same archive or directory.)


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\csname PSTfeatdiagLoaded\endcsname
\let\PSTfeatdiagLoaded\endinput
\ifx\PSTreeLoaded\endinput\else\input pst-tree.tex\fi\relax
\message{PST-featdiag v\fileversion date \filedate (GB)}
\input pst-key.tex
\edef\TheAtCode{\the\catcode`\@}
\catcode`\@=11

\newbox\fd@nodebox%

\newdimen\fd@radius%

\newcount\fd@fdcount\fd@fdcount=0%

\newcount\fd@nodecount\fd@nodecount=0%

\newrgbcolor{fdstubcolor}{0.8 0.8 0.8}%


\edef\fd@node@optional{optional}%
\edef\fd@node@mandatory{mandatory}%
\edef\fd@nodetype{optional}%

\edef\fd@group@cumulative{cumulative}%
\edef\fd@group@alternative{alternative}%
\edef\fd@grouptype{alternative}%

\def\fd@groupparent{}%
\def\fd@groupfirst{}%
\def\fd@grouplast{}%

\def\fd@nodeid{}%
\def\fd@nodeformat#1{#1}%


\define@key{psset}{fdnodeformat}{\def\fd@nodeformat##1{#1}}%
\define@key{psset}{fdnodetype}{\edef\fd@nodetype{#1}}%
\define@key{psset}{fdgrouptype}{\edef\fd@grouptype{#1}}%
\define@key{psset}{fdradius}{\pssetlength\fd@radius{#1}}%
\newif\ifFd@stub%
\define@key{psset}{fdstub}[true]{\@nameuse{Fd@stub#1}}%
\define@key{psset}{fddefaults}[true]{%
\psset{fdstub=false,fdradius=8mm,dotsize=1.6mm,fillcolor=black,linestyle=solid,fillstyle=none,levelsep=*2cm,treesep=0.75cm}%
}%
\psset{fddefaults}%

\def\featurediagram{\@ifnextchar[{\featurediagram@i}{\featurediagram@i[]}}%
\def\featurediagram@i[#1]{%
\begingroup%
\setkeys{psset}{nodesepB=0.8mm,vref=2.5ex,angleA=-90,angleB=90,armB=0.8mm,armA=0.3pt}%
\setkeys{psset}{#1}%
\pst@dima=\psk@@dotsize\p@%
\divide\pst@dima 2%
\setkeys{psset}{nodesepB=\pst@dima,armB=\pst@dima}%
\global\fd@nodecount=0%
\edef\fd@groupparent{}%
\edef\fd@groupfirst{}%
\edef\fd@grouplast{}%
\edef\fd@node@default{\fd@nodetype}%
\edef\fd@nodename{}%
\SpecialCoor%
\relax%
}

\def\endfeaturediagram{%
\hskip3.5pt % add right space which is substracted by the nodes
\NormalCoor%
\endgroup%
\global\advance\fd@fdcount by 1%
}

\def\fd@setnodename#1{%
\edef\fd@nodename{}%
\fd@getname@i#1,\relax,%
}%

\def\fd@getname@i#1,{%
\ifx\relax#1\empty\else%
\fd@getname@sp#1==\relax%
\expandafter\fd@getname@i%
\fi%
}%

\def\fd@getname@sp#1=#2=#3{%
\def\name{name}%
\def\tmp{#1}%
\ifx\tmp\name%
\edef\fd@nodename{#2}%
\fi%
}%

\def\fdnode{\pst@ifstar{\@ifnextchar[{\fdnode@i}{\fdnode@i[]}}}%
\def\fdnode@i[#1]{\@ifnextchar[{\fdnode@ii[#1]}{\fdnode@ii[#1][]}}%
\def\fdnode@ii[#1][#2]#3#4{%
\fd@setnodename{#1}%
\ifx\fd@nodename\empty%
\edef\fd@nodeid{fd\the\fd@fdcount .node\the\fd@nodecount}%
\global\advance\fd@nodecount by 1%
\else%
\edef\fd@nodeid{\fd@nodename}%
\fi%

\ifx\fd@groupfirst\empty%
\edef\fd@groupfirst{\fd@nodeid}%
\fi%

\edef\fd@grouplast{\fd@nodeid}%

\begingroup%
\setkeys{psset}{#1}%

\if@star%
\edef\fd@nodetype{\fd@node@mandatory}%
\fi%

        % test if node is a leaf
        \def\tempty{#4}%
        \ifx\tempty\empty%
\psset{levelsep=0cm}%
\fi%

\ifx\fd@nodetype\fd@node@optional%
\def\fd@edge{\ncdiag[fillcolor=white,fillstyle=solid]{-o}}%
\else%
\ifx\fd@nodetype\fd@node@mandatory%
\def\fd@edge{\ncdiag{-*}}%
\edef\fd@nodetype{optional}%
\else%
\errmessage{unknown feature node type: '\fd@nodetype'%
            must be 'mandatory' or 'optional'}%
\fi\fi%

\pstree{%
\TR[name=\fd@nodeid,edge=\fd@edge]{%
\ifFd@stub%
\psset{fillstyle=solid,fillcolor=fdstubcolor}%
\else%
\psset{fillstyle=solid,fillcolor=white}%
\fi%
\psframebox[#2]{\fd@nodeformat{#3}}%
}%
}{\edef\fd@groupparent{\fd@nodeid}#4}%
\hskip-3.5pt%
\endgroup%
}


\def\fd@wedge#1#2#3#4{%
\pst@dima=\psk@@dotsize\p@%
\advance \pst@dima by -0.15pt%
\nput[labelsep=0.2pt]{-90}{#2}{%
\pswedge[#1]{\fd@radius}{([angle=90,nodesep=\pst@dima]#3)}{([angle=90,nodesep=\pst@dima]#4)}}%
}%

\def\fdgroup{\pst@ifstar{\@ifnextchar[{\fdgroup@i}{\fdgroup@i[]}}}%
\def\fdgroup@i[#1]{%
\begingroup%
\setkeys{psset}{#1}%
\if@star%
\edef\fd@grouptype{\fd@group@cumulative}%
\fi%
\edef\fd@nodename{}%
\edef\fd@groupfirst{}%
}

\def\endfdgroup{%
\ifx\fd@grouptype\fd@group@alternative%
\fd@wedge{fillstyle=none}{\fd@groupparent}{\fd@groupfirst}{\fd@grouplast}%
\else%
\ifx\fd@grouptype\fd@group@cumulative%
\fd@wedge{fillstyle=solid}{\fd@groupparent}{\fd@groupfirst}{\fd@grouplast}%
\edef\fd@grouptype{\fd@group@alternative}%
\else%
\errmessage{unknown feature group type: '\fd@grouptype' must be 'alternative' or 'cumulative'}%
\fi\fi%
\endgroup%
}

\def\fdspace#1#2{%
        \tspace{#1}%
        \Tn%
        \tspace{#2}%
}%


\endinput
%%
%% End of file `pst-featdiag.tex'.
