MetaUML

From EduTech Wiki
Jump to: navigation, search

SORRY this page is broken. Had to remove an uml extension for security reasons - Daniel K. Schneider (talk) 16:57, 21 August 2013 (CEST)

1 Definition

MetaUML is a GNU GPL MetaPost library for typesetting UML diagrams, using a human-friendly textual notation. Currently (nov 2008) it offers support for class diagrams, package diagrams, activity diagrams, state machine diagrams use case diagrams and component diagrams.

MetaUML can be used to:

  • Create UML diagrams readily usable in a LaTeX article or book.
  • Create independent PDF-s
  • Create jpeg-s, png-s etc.
  • Insert UML diagrams in Mediawikis (provided that the extension is installed)

This page is for people who don't mind to draw by writing code. If you are looking for a simple drawing program to draw UML diagrams (or quasi UML diagrams), see the Unified modeling language, e.g. have a look at the free Dia program.

Sorry, there is no how-to for now. Look at examples and the manual.

2 Examples

Some drawing that uses empty classes and notes

To make simple drawings, I figured that it is enough to do the following:

  • Define each object
  • Stack them by using constraints (x, y z are distributed horizontally or vertically)
  • Then draw lines from x.compass_direction to y.compass_direction

Look at the source of the follwing example:

<uml>
ClassName.FB("Flex Builder 3");
ClassName.MXML("MXML Compiler");

Note.HTML("application.html");
Note.SWF("application.swf");

Note.AP("Application Project","(directory structure)");
Note.CO("Code", "(MXML and ActionScript)" );
Note.A("Multimedia Assets", "(Images, Audio, ..)");
Note.L("Libraries");

leftToRight(30)(FB,MXML,HTML);
topToBottom(20)(HTML,SWF);
topToBottom(20)(FB,AP);
leftToRight(30)(CO,A,L);
topToBottom(20)(AP,A);

drawObjects(FB, MXML,HTML,SWF,AP,CO,A,L);

link(association)(FB.e -- MXML.w);
link(association)(FB.s -- AP.n);
link(association)(AP.s -- CO.n);
link(association)(AP.s -- A.n);
link(association)(AP.s -- L.n);

link(associationUni)(MXML.e -- HTML.w);
link(associationUni)(MXML.e -- SWF.w);
</uml>

<uml> ClassName.FB("Flex Builder 3"); ClassName.MXML("MXML Compiler");

Note.HTML("application.html"); Note.SWF("application.swf");

Note.AP("Application Project","(directory structure)"); Note.CO("Code", "(MXML and ActionScript)" ); Note.A("Multimedia Assets", "(Images, Audio, ..)"); Note.L("Libraries");

leftToRight(30)(FB,MXML,HTML); topToBottom(20)(HTML,SWF); topToBottom(20)(FB,AP); leftToRight(30)(CO,A,L); topToBottom(20)(AP,A);

drawObjects(FB, MXML,HTML,SWF,AP,CO,A,L);

link(association)(FB.e -- MXML.w); link(association)(FB.s -- AP.n); link(association)(AP.s -- CO.n); link(association)(AP.s -- A.n); link(association)(AP.s -- L.n);

link(associationUni)(MXML.e -- HTML.w); link(associationUni)(MXML.e -- SWF.w);

</uml>

The following was copied from the Extension:UML page

Activity diagram

<uml> Begin.b; Activity.eat("Eat something good", "from the kitchen"); Branch.enough; Fork.fork("h", 50); Activity.read("Read a book"); Activity.listen("Listen to music", "(and ignore it)"); Fork.join("h", 50); End.e;

leftToRight.top(10)(read, listen); Group.readListen(read, listen);

leftToRight(30)(b, eat); topToBottom(20)(eat, enough, fork, readListen, join, e);

drawObjects(b, eat, enough, fork, readListen, join, e);

clink(transition)(b, eat); clink(transition)(eat, enough); link(transition)(pathStepX(enough.e, eat.e, 80)); clink(transition)(enough, fork); clink(transition)(fork, read); clink(transition)(fork, listen); clink(transition)(read, join); clink(transition)(listen, join); clink(transition)(join, e);

item(iGuard)("still hungry")(obj.sw = enough.e + (20, 0)); item(iGuard)("had enough")(obj.nw = enough.s + (0, -4)); </uml>

State diagram

<uml> Begin.b;

 State.reading("Reading commands")();
 State.processing("Processing commands")();

End.e;

State.composite("Working")(b, reading, processing, e); composite.info.left := composite.info.right := 10; composite.info.drawNameLine := 1;

topToBottom(20)(b, reading, processing, e); drawObject(composite);

clink(transition)(b, reading); clink(transition)(reading, processing); clink(transition)(processing, e);

ExitPoint.exit; exit.c=(composite.right, reading.midy); drawObject(exit); item(iAssoc)("error")(obj.nw = exit.s);

clink(transition)(reading, exit);

State.error("Preparing error report")(); State.result("Writing result")(); End.theEnd;

topToBottom(20)(error, result, theEnd); leftToRight(30)(exit, error);

drawObjects(error, result, theEnd);

clink(transition)(exit, error); clink(transition)(error, result); clink(transition)(result, theEnd);

link(transition)(rpathHorizontal(result.w, composite.right)); </uml>

3 Using the MediaWiki extension

Using the MetaUML uml tag in a mediawiki is quite tricky. The only way to figure out errors is to install this software locally (or log on to your wiki server machine) and then test like this. E.g code like this:

 <uml>
 Fork.forkA("h", 100);
 Fork.forkB("v", 20);
 leftToRight(10)(forkA, forkB);
 drawObjects(forkA, forkB);
 </uml>

goes into a xxx.mp file like this:

input metauml;
beginfig(1);
 Fork.forkA("h", 100);
 Fork.forkB("v", 20);
 leftToRight(10)(forkA, forkB);
 drawObjects(forkA, forkB);
endfig;
end

Then, type in a console:

mpost xxx.mp

4 Installation notes for Linux Ubuntu

Install textlive first via aptitude, apt-get or synaptic.

As of Sept 2009, Ubuntu distributes a very old version, since it relies on the CTAN archive which isn't updated with MetaUML. The old version is 0.2.3 and since 1996 the good version is 0.2.5.

You can copy the files to:

usr/share/texmf-texlive/metapost/metauml/

Then type:

texhash

(though I wonder what happens if you then upgrade textlive to an other old MetaUML distro. There certainly must be smarter way...)

Also, I found a missing font: ptmr8r

apt-get install texlive-fonts-recommended

Note on debugging. If you use this with the MediaWiki extension. Quote lines in MetaUML.php.

//    unlink($wgTmpDirectory."/".$tmp_filename.".mp");
//      unlink($wgTmpDirectory."/".$tmp_filename.".log");
//      unlink($wgTmpDirectory."/".$tmp_filename.".1");

Then watch the *.log files in the Mediawiki /images/tmp directory. You also then can directly type something like:

mpost c35cdfb376362cf4eabede45a0762dd7.mp 

... and enjoy the error messages (*.mp is the temporary file that mpost then must process)

5 Installation notes for MetaUML and Mediawiki extension for Solaris

Installing the necessary software requires some installation skills. Here are my (rough) installation notes

Step: Make sure that latex, dvips, gs (ghostscript), and convert (ImageMagick) installed and available in the PATH. Depending on how the system is installed, this also means to fix the path of the Apache webserver.

It probably would be a good idea to install livetex, but since I found I binary for (older) teTex I went with this. texTex in /opt/sfw wasn't correctly installed. Got a new version from http://www.sunfreeware.com/. This package installs in /usr/local

gunzip tetex-3.0-sol10-sparc-local.gz
pkgadd -d tetex-3.0-sol10-sparc-local

teTex now should be installed and there is some postinstall work to do

  • Add /usr/local/teTeX/bin/sparc-sun-solaris2.10 to the path.
  • Configure
texconfig conf

Step: Install texvc (maybe not needed). This is a standard Mediawiki script to render Latex math fragments.

Step: Get the MediaWiki extension

http://www.mediawiki.org/wiki/Extension:UML

Step: Fix some configuration variables. Some documentation on variables is here:

You have to make sure that all these variables are defined:

$wgUseTeX	    = true;
$wgMathPath         = "{$wgUploadPath}/math";
$wgMathDirectory    = "{$wgUploadDirectory}/math";
$wgTmpDirectory     = "{$wgUploadDirectory}/tmp";
$wgImageMagickIdentifyCommand="/usr/local/bin/identify";
$wgImageMagickConvertCommand = "/usr/local/bin/convert";
$wgDvipsCommand="/usr/local/teTeX/bin/sparc-sun-solaris2.10/dvips";

Step: Install MetaUML, UML for LaTeX/MetaPost

6 Links