1

My code is

\documentclass{standalone}
\usepackage{pgf-umlcd}

\renewcommand{\unidirectionalAssociation}[4]
{
  draw[umlcd style, ->] (#1) -- (#4)
  node[near end, auto]{#2}
  node[near end, auto,swap]{#3};
}

\begin{document}
\begin{tikzpicture}

  \begin{abstractclass}[text width = 6cm]{FileStore}{0,0}
    \attribute{$\sim$ com.alhelal.textpad}
    \operation{+ orderFile(file : File) : EditableFile} 
    \operation[0]{\# createFile(file : File) : EditableFile}
  \end{abstractclass}

  \begin{class}[text width = 6cm,anchor = west,xshift = 5cm]{ProgrammFileFactory}{FileStore.east}
    \inherit{FileStore}
    \attribute{$\sim$ com.alhelal.textpad}
    \operation{+ orderFile(file : File) : EditableFile} 
  \end{class}

  \begin{class}[text width = 11cm, yshift = -2cm]{EditableFile}{ProgrammFileFactory.south}
    \attribute{$\sim$ com.alhelal.textpad}
    \attribute{+ languageBehavior : LanguageBehavior} 
    \operation{+ options : Options} 
    \operation{+ getCodeAreaFromTab(tb : Tab) : CodeArea} 
    \operation{+ saveFile(fileTabArrayList : ArrayList$<$FileTab$>$, option : Options)}
    \operation{+ printFile(node : Node)}
    \operation{+ toggleLineNumber(cd : CodeArea)}
    \operation{+ setLanguageBehavior(langBehavior : LanguageBehavior)}
    \operation{+ performRunCode(file : File)}
    \operation{+ performBuildCode(file : File)}
    \operation{+ performSetHighlightableText()}
    \operation{+ performSetAutocompletableText()}
  \end{class}

  \begin{class}[text width = 3.5cm,anchor=north east,yshift = -2cm, xshift=-6cm]{TextFile}{EditableFile.south west}
    \inherit{EditableFile}
    \attribute{$\sim$ com.alhelal.textpad}
  \end{class}

  \begin{class}[text width = 3.5cm,anchor=north east,yshift = -2cm, xshift = -1.5cm]{CFile}{EditableFile.south west}
    \inherit{EditableFile}
    \attribute{$\sim$ com.alhelal.textpad}
    \attribute{-path : String}
  \end{class}

  \begin{class}[text width=3.5cm,anchor=north west,yshift = -2cm,xshift=-3cm]{CplusFile}{EditableFile.south}
    \inherit{EditableFile}
    \attribute{$\sim$ com.alhelal.textpad}
  \end{class}

  \begin{class}[text width  = 3.5cm, anchor = north west, yshift = -2cm, xshift = -4cm]{JavaFile}{EditableFile.south east}
    \inherit{EditableFile}
    \attribute{$\sim$ com.alhelal.textpad}
  \end{class}

  \begin{class}[text width = 3.5cm,yshift = -2cm,xshift = 1cm]{PythonFile}{EditableFile.south east}
    \inherit{EditableFile}
    \attribute{$\sim$ com.alhelal.textpad}
  \end{class}

  \begin{class}[text width = 3.5cm, anchor = north west, yshift =-2cm,xshift = 5cm]{LaTeXFile}{EditableFile.south east}
    \inherit{EditableFile}
    \attribute{$\sim$ com.alhelal.textpad}
  \end{class}
  \unidirectionalAssociation{ProgrammFileFactory}{}{$<<$instantiate$>>$}{EditableFile}
  \node [above=3mm] at (current bounding box.north) {Factory Method Pattern}
\end{tikzpicture}
\end{document}

I run this using pdflatex in terminal that results in

enter image description here

Andrew Swann
  • 95,762
alhelal
  • 2,451

1 Answers1

3

The general syntax of TikZ is to enter the stuff you want to be drawn in a format matching something like:

\command [ options ] ( location ) { stuff } ;

Where almost everything might not be needed. Just the \command (e.g. \draw) and the trailing ; to limit the scope of the command, are important. You forgot that ; in the last line of your tikzpicture and therefore get this error. And you forgot a \ at beginning of draw in the \unidirectionAssociation renaming block.
Use \draw[umlcd style, ->] (#1) -- (#4) instead of draw[umlcd style, ->] (#1) -- (#4)

The following compiles:

\documentclass{standalone}
\usepackage{pgf-umlcd}

\renewcommand{\unidirectionalAssociation}[4]
{
  \draw[umlcd style, ->] (#1) -- (#4)% <------
  node[near end, auto]{#2}
  node[near end, auto,swap]{#3};
}

\begin{document}
\begin{tikzpicture}

  \begin{abstractclass}[text width = 6cm]{FileStore}{0,0}
    \attribute{$\sim$ com.alhelal.textpad}
    \operation{+ orderFile(file : File) : EditableFile} 
    \operation[0]{\# createFile(file : File) : EditableFile}
  \end{abstractclass}

  \begin{class}[text width = 6cm,anchor = west,xshift = 5cm]{ProgrammFileFactory}{FileStore.east}
    \inherit{FileStore}
    \attribute{$\sim$ com.alhelal.textpad}
    \operation{+ orderFile(file : File) : EditableFile} 
  \end{class}

  \begin{class}[text width = 11cm, yshift = -2cm]{EditableFile}{ProgrammFileFactory.south}
    \attribute{$\sim$ com.alhelal.textpad}
    \attribute{+ languageBehavior : LanguageBehavior} 
    \operation{+ options : Options} 
    \operation{+ getCodeAreaFromTab(tb : Tab) : CodeArea} 
    \operation{+ saveFile(fileTabArrayList : ArrayList$<$FileTab$>$, option : Options)}
    \operation{+ printFile(node : Node)}
    \operation{+ toggleLineNumber(cd : CodeArea)}
    \operation{+ setLanguageBehavior(langBehavior : LanguageBehavior)}
    \operation{+ performRunCode(file : File)}
    \operation{+ performBuildCode(file : File)}
    \operation{+ performSetHighlightableText()}
    \operation{+ performSetAutocompletableText()}
  \end{class}

  \begin{class}[text width = 3.5cm,anchor=north east,yshift = -2cm, xshift=-6cm]{TextFile}{EditableFile.south west}
    \inherit{EditableFile}
    \attribute{$\sim$ com.alhelal.textpad}
  \end{class}

  \begin{class}[text width = 3.5cm,anchor=north east,yshift = -2cm, xshift = -1.5cm]{CFile}{EditableFile.south west}
    \inherit{EditableFile}
    \attribute{$\sim$ com.alhelal.textpad}
    \attribute{-path : String}
  \end{class}

  \begin{class}[text width=3.5cm,anchor=north west,yshift = -2cm,xshift=-3cm]{CplusFile}{EditableFile.south}
    \inherit{EditableFile}
    \attribute{$\sim$ com.alhelal.textpad}
  \end{class}

  \begin{class}[text width  = 3.5cm, anchor = north west, yshift = -2cm, xshift = -4cm]{JavaFile}{EditableFile.south east}
    \inherit{EditableFile}
    \attribute{$\sim$ com.alhelal.textpad}
  \end{class}

  \begin{class}[text width = 3.5cm,yshift = -2cm,xshift = 1cm]{PythonFile}{EditableFile.south east}
    \inherit{EditableFile}
    \attribute{$\sim$ com.alhelal.textpad}
  \end{class}

  \begin{class}[text width = 3.5cm, anchor = north west, yshift =-2cm,xshift = 5cm]{LaTeXFile}{EditableFile.south east}
    \inherit{EditableFile}
    \attribute{$\sim$ com.alhelal.textpad}
  \end{class}
  \unidirectionalAssociation{ProgrammFileFactory}{}{$<<$instantiate$>>$}{EditableFile}
  \node [above=3mm] at (current bounding box.north) {Factory Method Pattern};% <-------
\end{tikzpicture}
\end{document}

I marked the lines I changed with % <-------.

EDIT: I've updated the above code to include the correct redefinition of \unidirectionalAssociation thanks to the clarifications provided by @TorbjørnT.

enter image description here

Skillmon
  • 60,462
  • I put \ which included in my question. Your solution doesn't results any error message, but I don't get the proper output. association not shown. see this and why no.2 and no.4 inherited line arrow is less deep. see tihs – alhelal Oct 28 '17 at 08:34
  • @alhelal did you apply the proposed changes (the last code block in my answer) to \unidirectionalAssociation? With this the two described issues are solved. – Skillmon Oct 28 '17 at 08:49
  • @alhelal why do you change the definition of \unidirectionalAssociation in the first place? – Skillmon Oct 28 '17 at 08:59
  • The macro redefinition was suggested by me (https://tex.stackexchange.com/a/389248/) because the original one doesn't work for vertical lines. And your last version is the one I suggested, somehow the OP lost a \ along the way. Edit: I'd suggest changing the one in the complete example to the same, instead of adding those semicolons. – Torbjørn T. Oct 28 '17 at 10:27
  • @TorbjørnT. thanks for the clarification, I'll edit my answer. – Skillmon Oct 28 '17 at 11:33
  • @Skillmon I spend long time to find out the missing \, that makes my output ambiguous, so I edit your answer with this information. – alhelal Oct 28 '17 at 13:59