% Package for Unified Process Methodology's documents
%
% Copyright (c) 2006-2007 Stephane GALLAND <galland@arakhne.org>
% 
% This program is free library; you can redistribute it and/or modify
% it under the terms of the GNU Lesser General Public License as
% published by the Free Software Foundation; either version 3 of the
% License, or any later version.
%
% This library is distributed in the hope that it will be useful, but
% WITHOUT ANY WARRANTY; without even the implied warranty of
% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
% Lesser General Public License for more details.
%
% You should have received a copy of the GNU Lesser General Public
% License along with this library; see the file COPYING.  If not,
% write to the Free Software Foundation, Inc., 59 Temple Place - Suite
% 330, Boston, MA 02111-1307, USA.
%
% Creation date: 2006-04-20
% Modifications:
%   2007-07-05   Add people name formatting function.
%   2007-07-03   Add extension feature.
%   2007-03-19   Add localization.
%   2006-04-19   Add version number.
%                Add mtabular and mtable.
%   2006-04-20   Reformat validator list.
%                Add sectioning commands.
%

\global\edef\upm@package@doc@ver{2007/07/03}

\NeedsTeXFormat{LaTeX2e}[1995/12/01]
\ProvidesPackage{upmethodology-document}[\upm@package@doc@ver]

%----------------------------------------
% LOCALES
%----------------------------------------
\def\upm@document@lang@english{%
  \gdef\upm@lang@@{\message{**** upmethodology-document is using English language ****}}%
  \gdef\upm@lang@@lang@{english}%
  \gdef\upm@lang@project{Project}%
  \gdef\upm@lang@document{Document}%
  \gdef\upm@lang@docref{Reference}%
  \gdef\upm@lang@lastupdate{Last Update}%
  \gdef\upm@lang@lastupdate@short{Updated}%
  \gdef\upm@lang@document@summary{Document Summary}%
  \gdef\upm@lang@status{Status}%
  \gdef\upm@lang@document@authors{Authors}%
  \gdef\upm@lang@document@informed{Informed People}%
  \gdef\upm@lang@document@validators{Validators}%
  \gdef\upm@lang@document@names{Names}%
  \gdef\upm@lang@document@emails{Emails}%
  \gdef\upm@lang@document@initials{Initials}%
}
\def\upm@document@lang@french{%
  \gdef\upm@lang@@{\message{**** upmethodology-document is using French language ****}}%
  \gdef\upm@lang@@lang@{french}%
  \gdef\upm@lang@project{Projet}%
  \gdef\upm@lang@document{Document}%
  \gdef\upm@lang@docref{R\'ef\'erence}%
  \gdef\upm@lang@lastupdate{Derni\`ere modification}%
  \gdef\upm@lang@lastupdate@short{Modifi\'e}%
  \gdef\upm@lang@document@summary{Synoptique}%
  \gdef\upm@lang@status{Statut}%
  \gdef\upm@lang@document@authors{Auteurs}%
  \gdef\upm@lang@document@informed{Pour information}%
  \gdef\upm@lang@document@validators{Validateurs}%
  \gdef\upm@lang@document@names{Noms}%
  \gdef\upm@lang@document@emails{Emails}%
  \gdef\upm@lang@document@initials{Initiales}%
}

%----------------------------------------
% OPTIONS
%----------------------------------------
\newif\ifupm@document@langset\upm@document@langsetfalse
\DeclareOption{french}{%
  \upm@document@lang@french
  \upm@document@langsettrue
}
\DeclareOption{francais}{%
  \upm@document@lang@french
  \upm@document@langsettrue
}
\DeclareOption{english}{%
  \upm@document@lang@english
}
\ExecuteOptions{english}
\ProcessOptions

\upm@lang@@

\ifupm@document@langset\else\PassOptionsToPackage{english}{babel}\fi
\RequirePackage{babel}
\RequirePackage{ifthen}
\RequirePackage{xspace}
\RequirePackage{graphicx}
\RequirePackage{vmargin}
\RequirePackage{url}
\RequirePackage[pdftex]{thumbpdf} % PDF thumbail
\RequirePackage[pdftex=true,
                pdfpagelayout = useoutlines,
                bookmarks,
                bookmarksopen = true,
                bookmarksnumbered = true,
                breaklinks = true,
                linktocpage,
                %backref, % Ecrit le lieu citation (lien) ds la biblio
                linkcolor = blue,
                urlcolor  = blue,
                citecolor = blue,
                anchorcolor = blue,
                hyperindex = true,
                hyperfigures
                ]{hyperref}
\urlstyle{sf}

\RequirePackage{upmethodology-fmt}
\RequirePackage{upmethodology-version}

\def\upm@ifnotempty#1{\ifthenelse{\equal{#1}{\@empty}}{}}

%----------------------------------------
% DOCUMENT MANAGEMENT
%----------------------------------------

%-----
% Declare a project's document
%\declaredocument{project}{name}{ref}
\newcommand{\declaredocument}[3]{%
	\gdef\theupmproject{#1}%
	\gdef\theupmsubproject{}%
	\gdef\theupmdocname{#2}%
	\gdef\theupmdocref{#3}%
}

%-----
% Declare a project's document
%\declaredocumentex{project}{subproject}{name}{ref}
\newcommand{\declaredocumentex}[4]{%
	\gdef\theupmproject{#1}%
	\gdef\theupmsubproject{#2}%
	\gdef\theupmdocname{#3}%
	\gdef\theupmdocref{#4}%
}

%-----
% Display the summary of the document
%\upmdocumentsummary[width]
\newcommand{\upmdocumentsummary}[1][\linewidth]{%
	\noindent\begin{mtabular}[#1]{5}{|X|X|c|c|c|}%
	\tabulartitle{\upm@lang@document@summary}%
	\tabularheader{\upm@lang@project}{\upm@lang@document}{\upm@lang@docref}{\upm@lang@version}{\upm@lang@lastupdate}%
	\hline
	\theupmproject\upm@ifnotempty{\theupmsubproject}{ -- \theupmsubproject} & \theupmdocname & \theupmdocref & \theupmversion & \theupmdate \\
	\hline
	\end{mtabular}\par\vspace{.5cm}%
}

%-----
%Name of the project for which this document was written
\def\theupmproject{Arakhn\^e Project}

%-----
%Name of the sub-project for which this document was written
\def\theupmsubproject{}

%-----
%Name of the document
\def\theupmdocname{Arakhn\^e Document}

%-----
%Reference of the document
\def\theupmdocref{XXX}


%-----
%Name of the logo
\def\theupmsmalldoclogo{smalllogo}
\def\theupmdoclogo{logo}

%-----
% Define the name of the logo picture to use
\newcommand{\defupmsmalllogo}[1]{\global\edef\theupmsmalldoclogo{#1}}
\newcommand{\defupmlogo}[1]{\global\edef\theupmdoclogo{#1}}

%-----
%Full name of the document
\def\theupmfulldocname{%
	\theupmproject%
	\upm@ifnotempty{\theupmsubproject}{/\theupmsubproject}%
	\upm@ifnotempty{\theupmdocname}{ -- \theupmdocname}%
}

%----------------------------------------
% AUTHOR MANAGEMENT
%----------------------------------------

\def\upm@document@author@tab{}

%-----
\def\theauthorlist{}

%-----
%Add an author
%\addauthor[email]{firstname}{name}
\newcommand{\addauthor}[3][]{%
	\global\protected@edef\theauthorlist{\theauthorlist\protect\upm@ifnotempty{\theauthorlist}{,} \protect\upmmakename{#2}{#3}{~}}
	\global\protected@edef\upm@document@author@tab{\upm@document@author@tab \protect\upmmakename{#2}{#3}{~} & 
	\protect\upm@ifnotempty{#1}{\protect\href{mailto:#1}{#1}} \protect\\}
}

%-----
% Display the summary of the authors
%\upmdocumentauthors[width]
\newcommand{\upmdocumentauthors}[1][\linewidth]{%
	\upm@ifnotempty{\upm@document@author@tab}{%
	\noindent\expandafter\begin{mtabular}[#1]{2}{|X|c|}%
	\tabulartitle{\upm@lang@document@authors}%
	\tabularheader{\upm@lang@document@names}{\upm@lang@document@emails}%
	\upm@document@author@tab
	\hline%
	\expandafter\end{mtabular}\par\vspace{.5cm}}%
}

%----------------------------------------
% VALIDATOR MANAGEMENT
%----------------------------------------

\def\upm@document@validator@tab{}

%-----
\def\thevalidatorlist{}

%-----
%Add a validator
%\addvalidator[email]{firstname}{name}
\newcommand{\addvalidator}[3][]{%
	\global\protected@edef\thevalidatorlist{\thevalidatorlist\protect\upm@ifnotempty{\thevalidatorlist}{,} \protect\upmmakename{#2}{#3}{~}}
	\global\protected@edef\upm@document@validator@tab{\upm@document@validator@tab \protect\upmmakename{#2}{#3}{~} & 
	\protect\upm@ifnotempty{#1}{\protect\href{mailto:#1}{#1}} & \protect\\}
}

%-----
% Display the summary of the validators
%\upmdocumentvalidators[width]
\newcommand{\upmdocumentvalidators}[1][\linewidth]{%
	\upm@ifnotempty{\upm@document@validator@tab}{%
	\noindent\expandafter\begin{mtabular}[#1]{3}{|X|c|p{3cm}|}%
	\tabulartitle{\upm@lang@document@validators}%
	\tabularheader{\upm@lang@document@names}{\upm@lang@document@emails}{\upm@lang@document@initials}%
	\upm@document@validator@tab
	\hline%
	\expandafter\end{mtabular}\par\vspace{.5cm}}%
}


%-----
%Add an author/validator
%\addvalidator[email]{firstname}{name}
\newcommand{\addauthorvalidator}[3][]{%
	\addauthor[#1]{#2}{#3}\addvalidator[#1]{#2}{#3}%
}

%----------------------------------------
% INFORMED MANAGEMENT
%----------------------------------------

\def\upm@document@informed@tab{}

%-----
\def\theinformedlist{}

%-----
%Add an informed
%\addinformed[email]{firstname}{name}
\newcommand{\addinformed}[3][]{%
	\global\protected@edef\theinformedlist{\theinformedlist\protect\upm@ifnotempty{\theinformedlist}{,} \protect\upmmakename{#2}{#3}{~}}
	\global\protected@edef\upm@document@informed@tab{\upm@document@informed@tab \protect\upmmakename{#2}{#3}{~} & 
	\protect\upm@ifnotempty{#1}{\protect\href{mailto:#1}{#1}} \protect\\}
}

%-----
% Display the summary of the informed people
%\upmdocumentinformedpeople[width]
\newcommand{\upmdocumentinformedpeople}[1][\linewidth]{%
	\upm@ifnotempty{\upm@document@informed@tab}{%
	\noindent\expandafter\begin{mtabular}[#1]{2}{|X|c|}%
	\tabulartitle{\upm@lang@document@informed}%
	\tabularheader{\upm@lang@document@names}{\upm@lang@document@emails}%
	\upm@document@informed@tab
	\hline%
	\expandafter\end{mtabular}\par\vspace{.5cm}}%
}

%----------------------------------------
% PUBLISHER
%----------------------------------------

\gdef\theupmpublisher{Arakhn\^e.org Group}
\gdef\theupmpublishingdate{}

%-----
%Set the publisher identity
%\setpublisher{name}
\newcommand{\setpublisher}[1]{%
	\gdef\theupmpublisher{#1}%
}

%----------------------------------------
% DOCUMENT SECTIONS
%----------------------------------------

\gdef\upm@document@section@alignment{}

%-----
% Part without number but inside the TOC
%\parttoc [toctitle]{title} % left-alignment inside TOC
%\parttoc*[toctitle]{title} % right-alignment inside TOC
\def\parttoc{\@ifstar%
	{\gdef\upm@document@section@alignment{\protect\numberline{}}\expandafter\upm@document@section@part}%
	{\gdef\upm@document@section@alignment{}\expandafter\upm@document@section@part}}
\def\upm@document@section@part{\@ifnextchar [%
	{\expandafter\upm@document@section@part@opt}%
	{\expandafter\upm@document@section@part@nopt}}
\def\upm@document@section@part@opt[#1]#2{%
	\part*{#2\addcontentsline{toc}{part}{\upm@document@section@alignment{#1}}}%
	\chaptermark{}%
}
\def\upm@document@section@part@nopt#1{%
	\part*{#1\addcontentsline{toc}{part}{\upm@document@section@alignment{#1}}}%
	\chaptermark{}%
}

%-----
% Chapter without number but inside the TOC
%\chaptertoc [toctitle]{title} % left-alignment inside TOC
%\chaptertoc*[toctitle]{title} % right-alignment inside TOC
\def\chaptertoc{\@ifstar%
	{\gdef\upm@document@section@alignment{\protect\numberline{}}\expandafter\upm@document@section@chapter}%
	{\gdef\upm@document@section@alignment{}\expandafter\upm@document@section@chapter}}
\def\upm@document@section@chapter{\@ifnextchar [%
	{\expandafter\upm@document@section@chapter@opt}%
	{\expandafter\upm@document@section@chapter@nopt}}
\def\upm@document@section@chapter@opt[#1]#2{%
	\@schapter{#2\addcontentsline{toc}{chapter}{\upm@document@section@alignment{#1}}}%
	\chaptermark{#1}%
}
\def\upm@document@section@chapter@nopt#1{%
	\@schapter{#1\addcontentsline{toc}{chapter}{\upm@document@section@alignment{#1}}}%
	\chaptermark{#1}%
}

%-----
% Section without number but inside the TOC
%\sectiontoc [toctitle]{title} % left-alignment inside TOC
%\sectiontoc*[toctitle]{title} % right-alignment inside TOC
\def\sectiontoc{\@ifstar%
	{\gdef\upm@document@section@alignment{\protect\numberline{}}\expandafter\upm@document@section@section}%
	{\gdef\upm@document@section@alignment{}\expandafter\upm@document@section@section}}
\def\upm@document@section@section{\@ifnextchar [%
	{\expandafter\upm@document@section@section@opt}%
	{\expandafter\upm@document@section@section@nopt}}
\def\upm@document@section@section@opt[#1]#2{%
	\section*{#2\addcontentsline{toc}{section}{\upm@document@section@alignment{#1}}}%
}
\def\upm@document@section@section@nopt#1{%
	\section*{#1\addcontentsline{toc}{section}{\upm@document@section@alignment{#1}}}%
}

%-----
% Subsection without number but inside the TOC
%\subsectiontoc [toctitle]{title} % left-alignment inside TOC
%\subsectiontoc*[toctitle]{title} % right-alignment inside TOC
\def\subsectiontoc{\@ifstar%
	{\gdef\upm@document@section@alignment{\protect\numberline{}}\expandafter\upm@document@section@subsection}%
	{\gdef\upm@document@section@alignment{}\expandafter\upm@document@section@subsection}}
\def\upm@document@section@subsection{\@ifnextchar [%
	{\expandafter\upm@document@section@subsection@opt}%
	{\expandafter\upm@document@section@subsection@nopt}}
\def\upm@document@section@subsection@opt[#1]#2{%
	\subsection*{#2\addcontentsline{toc}{subsection}{\upm@document@section@alignment{#1}}}%
}
\def\upm@document@section@subsection@nopt#1{%
	\subsection*{#1\addcontentsline{toc}{subsection}{\upm@document@section@alignment{#1}}}%
}

%-----
% Subsubsection without number but inside the TOC
%\subsubsectiontoc [toctitle]{title} % left-alignment inside TOC
%\subsubsectiontoc*[toctitle]{title} % right-alignment inside TOC
\def\subsubsectiontoc{\@ifstar%
	{\gdef\upm@document@section@alignment{\protect\numberline{}}\expandafter\upm@document@section@subsubsection}%
	{\gdef\upm@document@section@alignment{}\expandafter\upm@document@section@subsubsection}}
\def\upm@document@section@subsubsection{\@ifnextchar [%
	{\expandafter\upm@document@section@subsubsection@opt}%
	{\expandafter\upm@document@section@subsubsection@nopt}}
\def\upm@document@section@subsubsection@opt[#1]#2{%
	\subsubsection*{#2\addcontentsline{toc}{subsubsection}{\upm@document@section@alignment{#1}}}%
}
\def\upm@document@section@subsubsection@nopt#1{%
	\subsubsection*{#1\addcontentsline{toc}{subsubsection}{\upm@document@section@alignment{#1}}}%
}

%----------------------------------------
% EXTENSION MANAGEMENT
%----------------------------------------

%-----
% Use the specified extension
%\upmuse{extension_name}
\newcommand{\upmuse}[1]{%
	\message{**** including upm extension #1 (upmext-#1.cfg) ****}%
	{\begingroup%
	\newcommand{\set}[3][\upm@lang@@lang@]{%
		% NORMAL LOGO
		\ifthenelse{\equal{##2}{logo}}{\defupmlogo{##3}}{%
		% SMALL LOGO
		\ifthenelse{\equal{##2}{smalllogo}}{\defupmsmalllogo{##3}}{%
		% PUBLISHER
		\ifthenelse{\equal{##2}{publisher}}{%
			\ifthenelse{\equal{\upm@lang@@lang@}{##1}}{%
				\setpublisher{##3}%
			}{}%
		% ERROR ON ATTRIBUTE
		}{%
		\errmessage{extension's value '##2' is not supported.}%
		}}}%
	}%
	\input{upmext-#1.cfg}%
	\endgroup}%
}

\endinput
