%
%  openda.sty
%  ----------
%
%  OpenDA LaTeX style-file for OpenDA reports
%
%  version 1.0  - 20140224 - initial version
%
%  Options:
%  --------
%  none
%
%  Reports:
%  --------
%
%  \pagestyle{oda_report}  change the headtext: OpenDA, release
%  \maketitle              create a title-page with:
%     \title{}
%     \subtitle{}
%     \reportnumber{}      sets the report number
%     \date{}
%     \cprtext{}           change the copyright notice (default: GNU FDL)
%  \chapter		   modified: show head-text also on chapter-pages
%
%  Additional commands:
%  --------------------
%
%  \tabulminpg{9cm}{text}  creates a minipage with extra height
%
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
%   - for using pdflatex:
%                  \ifpdf
%                      \psfig{figure=*.{jpg,pdf},...}
%                  \else
%                      \psfig{figure=*.{eps,ps},...}
%                  \fi
%
%                  \psfig{figure=<name>.\pdfps,...}
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% Import package hugepag for definitions of pagesize
%
\usepackage{./styles/hugepag}
%
% Import package hyperref to put hyperlinks from PDF
%
\usepackage{hyperref}
%
% Import package svn-multi: svn keyword per input file
%
\usepackage{./styles/svn-multi}
%
% Import packages natbib and chapterbib to put references direct below the
% text per input file
%
\usepackage{natbib}
%\usepackage{chapterbib}
%
% Import packages graphicx for PostScript/PDF-figures
%
\usepackage{graphicx}
\AtBeginDocument{
        \DeclareGraphicsExtensions{.pdf,.jpg,.png}
}
%\fi
\usepackage{epsfig}
%
% Import package color
%
\usepackage{color}
\definecolor{odacolor}{rgb}{ 0.0, 0.0, 0.0}
%
% Import package amssymb
%
\usepackage{amssymb}

\typeout{ }
\typeout{Packages hugepag, hyperref, svn-multi, natbib, graphicx,
  epsfig, color and amssbyb are automatically loaded by openda.sty.}
\typeout{ }
%
% Adjust some elements of head-text etc.
%
\def\pageheadtext{Page}
\def\datetext{Date}
\def\contentstext{Table of contents}
\def\referencetext{References}
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% commands OpenDA
%   openda        -
%   deltares      -
%   tudelft       -
%   vortech       -
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
%\input{openda}
\usepackage{xspace}

\newcommand{\openda}{{\sf The OpenDA Association}\xspace}
\newcommand{\oda}{{\sf OpenDA}\xspace}
\newcommand{\deltares}{{\sf Deltares}\xspace}
\newcommand{\tudelft}{{\sf TU Delft}\xspace}
\newcommand{\vortech}{{\sf V\kern -0.15ex$\cal O$R\-tech}\xspace}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% Define commands and strings for customizing reports
%         user commands                    internal string-commands
%   - title, author, date;             @title, @author, @date
%   - shorttitle, reportnumber;        @shorttitle, @reportnumber%
%   - ourref;                          ourrefer
%   - cprtext;
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
\def\title#1{\def\@title{#1}\def\@shorttitle{#1}}
\def\shorttitle#1{\def\@shorttitle{#1}}
\def\subtitle#1{\def\@subtitle{#1}}
\def\reportnumber#1{\def\@reportnumber{#1}}
\def\revision#1{\def\@revisiontext{#1}}
%
\def\@shorttitle{}
\def\@subtitle{}
\def\@reportnumber{}
\def\@revisiontext{}
\def\cprtext{}

\def\@cprtext{
Copyright \copyright{}  2015  \openda \\
Permission is granted to copy, distribute and/or modify this document under the
terms of the GNU Free Documentation License, Version 1.3 or any later version
published by the Free Software Foundation; with no Invariant Sections, no
Front-Cover Texts, and no Back-Cover Texts. A copy of the license is included
in the section entitled ``GNU Free Documentation License''.}
%
% Parameters in head- en foot-texts in eigen page-styles:
%
\newlength{\textwidthhead}
\setlength{\headheight}{0.5in}
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% Redefine \maketitle for OpenDA reports
% Redefine \chapter: show head-text also on chapter-pages
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% text elements:
%
\def\reptypetext{Documentation}
\def\repauthtext{Author(s)}
%
% Titlepage:
%
\renewcommand{\maketitle}{
   \thispagestyle{empty}
   \allowfloatsattop
   \setlength{\unitlength}{1mm}
   \begin{picture}(150,210)(10,0)
      \put(0,100){\makebox(0,0)[bl]{
                    \begin{minipage}{180mm}\centering\baselineskip 5.0ex
                       \psfig{figure=./styles/OpenDA_logo.jpg,width=100mm,silent=}
                    \end{minipage}}}
      \put(0,90){\makebox(0,0)[bl]{
                    \begin{minipage}{180mm}\centering\baselineskip 5.0ex
                       {\LARGE\textbf{\@title}}
                    \end{minipage}}}
      \put(0,70){\makebox(0,0)[bl]{
                    \begin{minipage}[t]{180mm}\raggedright
                      {\bf \@subtitle}
                    \end{minipage}}}
      \put( 0,20){\makebox(0,0)[bl]{
                    \begin{minipage}{180mm}\centering
                    \begin{tabular}{lll}
%                    Reference      &:& \@reportnumber\\
                    Date           &:& \today \\
                    Contact        &:& {\bf info@openda.org}\\
                    \end{tabular}
                    \end{minipage}}}
      \put( 0,0){\makebox(0,0)[bl]{
                    \begin{minipage}{167mm}
                       \tiny \@cprtext
                    \end{minipage}}}
   \end{picture}
\parskip 1ex
\parindent 0ex
}
%
% standard page-style:
%
\if@twoside
   \def\ps@odareport{
      \def\@oddhead{\begin{picture}(1,1)(0,35)
          \put(  0, 40.5){\makebox(0,0)[bl]{\makebox[\textwidth]{%
                          \hfill\leftmark}}}
          \put(  0, 39  ){\makebox(0,0)[bl]{\rule{\textwidth}{0.2mm}}}
          \end{picture}\hfill}
      \def\@evenhead{\begin{picture}(1,1)(0,35)
          \put(  0, 40.5){\makebox(0,0)[bl]{\makebox[\textwidth]{%
                          \@shorttitle\hfill}}}
          \put(  0, 39  ){\makebox(0,0)[bl]{\rule{\textwidth}{0.2mm}}}
          \end{picture}\hfill}
      \def\@oddfoot{\begin{picture}(1,1)(0,35)
          \put(  0, 39  ){\makebox(0,0)[bl]{\rule{\textwidth}{0.2mm}}}
          \put(  0, 38  ){\makebox(0,0)[tl]{\makebox[\textwidth]{%
                          \small\@revisiontext\hfill\thepage}}}
          \end{picture}\hfill}
      \def\@evenfoot{\begin{picture}(1,1)(0,35)
          \put(  0, 39  ){\makebox(0,0)[bl]{\rule{\textwidth}{0.2mm}}}
          \put(  0, 38  ){\makebox(0,0)[tl]{\makebox[\textwidth]{%
                          \thepage\hfill}}}
          \end{picture}\hfill}
      \let\@mkboth\markboth
    \def\chaptermark##1{%
      \markboth {{%
        \ifnum \c@secnumdepth >\m@ne
            \@chapapp\ \thechapter. \ %
        \fi
        ##1}}{}}%
    \def\sectionmark##1{%
      \markright {{%
        \ifnum \c@secnumdepth >\z@
          \thesection. \ %
        \fi
        ##1}}}}
\else
  \def\ps@odareport{%
    \def\@oddhead{\begin{picture}(1,1)(0,35)
        \put(  0, 40.5){\makebox(0,0)[bl]{\makebox[\textwidth]{%
                        \hfill\rightmark}}}
        \put(  0, 39  ){\makebox(0,0)[bl]{\rule{\textwidth}{0.2mm}}}
        \end{picture}\hfill}
    \def\@oddfoot{\begin{picture}(1,1)(0,35)
        \put(  0, 39  ){\makebox(0,0)[bl]{\rule{\textwidth}{0.2mm}}}
        \put(  0, 38  ){\makebox(0,0)[tl]{\makebox[\textwidth]{%
                        \small\@revisiontext\hfill\thepage}}}
        \end{picture}\hfill}
    \let\@mkboth\markboth
    \def\chaptermark##1{%
      \markright {{%
        \ifnum \c@secnumdepth >\m@ne
            \@chapapp\ \thechapter. \ %
        \fi
        ##1}}}}
\fi
%
% redefine chapter commands
%
\newcommand{\odachapter}[1]
  {\color{odacolor}
   \chapter[#1]{#1\\[-2ex]}
   \color{black}}
\newcommand{\odasection}[1]{\color{odacolor}\section{#1}\color{black}}
\def\chapter{\if@openright\cleardoublepage\else\clearpage\fi
                          \global\@topnum\z@
                          \@afterindentfalse
                          \secdef\@chapter\@schapter}
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% Environment odalogsheet and command odalogentry to create a log sheet
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
\newlength{\logdscrpwidth}
\setlength{\logdscrpwidth}{90mm}

\newlength{\logfilelocwidth}
\setlength{\logfilelocwidth}{\logdscrpwidth}
\addtolength{\logfilelocwidth}{32mm}

\newenvironment{odalogsheet}{%
   \chapter*{Log-sheet}
   \addcontentsline{toc}{chapter}{Log-sheet}

   \begin{table}[h]
   % \sffamily
   \begin{tabular}{|p{11mm}|p{30mm}|p{19.5mm}|p{\logdscrpwidth}|}
   \hline
   \mbox{\hspace{-1mm}Version\hspace{-2mm}} & Author & Date &
                \tabulminpg{\logdscrpwidth}{Description} \\
   \hline\hline
}{
   \end{tabular}
   \end{table}
}

\newcommand{\odalogentry}[4]{\multicolumn{1}{|c|}{#1} & #2 & #3 &
            \tabulminpg{\logdscrpwidth}{\raggedright #4} \\ \hline}

\newcommand{\odafilelocation}[1]{
   \multicolumn{2}{|l}{File location:
       } & \multicolumn{3}{l|}{\tabulminpg{\logfilelocwidth}{#1}} \\ \hline
}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% Commando \tabulminpg used to create 'high' minipages within the
% tabular-environment.
%
\newcommand{\tabulminpg}[2]{%
        \begin{minipage}[t]{#1}%
                \rule{0mm}{2.5ex}#2\rule[-2mm]{0mm}{2mm}%
        \end{minipage}}
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% Prohibit figures and tables to be placed at the top of the first page:
%  - topnumber is the number of floats allowed at the top of a page
%  - save the original value now, i.e. when reading the preamble of
%    the document
%  - set value 0, no floats allowed at this page, i.e. the first page
%  - within maketitle: restore the original value of topnumber, which
%    then takes effect on the following page
%
\newcounter{orig_topnumber}
\setcounter{orig_topnumber}{\value{topnumber}}
\setcounter{topnumber}{0}
\newcommand{\allowfloatsattop}{\setcounter{topnumber}{\value{orig_topnumber}}}

