File Exchange

image thumbnail

UMLgui

version 1.2.0.0 (37.6 KB) by Ben Goddard
Allows automatic generation of UML class diagram

37 Downloads

Updated 21 Mar 2020

View Version History

View License

UMLgui allows the automatic creation of UML class diagrams. Running UMLgui opens the gui. You can then use the four buttons under the main panel to add directories, or directories and their (recursive) subdirectories, as well as deleting selected directories, or clearing the whole list.

Various view options are available, the most significant being the Tree Layout, which is either `Aesthetic', producing a branching tree structure, or `Compact', which produces a much more compact but less visually appealing tree.

Clicking the `Create UML diagram' button creates both an eps and pdf file of the diagram. The output file can either be entered manually, or selected via a browser.

Support is included for classes with multiple superclasses, but due to the potential non-planar nature of the graph, all but the first superclass are joined to the class by straight arrows.

Two very basic examples included in /AnimalExample and /AnimalFruitExample (and subdirectories). The latter demonstrates support for packages.

It is also possible to create a script to bypass the gui; see makeAnimalDiagram.m and makeAnimalFruitDiagram.m for an examples.

Cite As

Ben Goddard (2021). UMLgui (https://www.mathworks.com/matlabcentral/fileexchange/44742-umlgui), MATLAB Central File Exchange. Retrieved .

Comments and Ratings (26)

EM

Works fine after some tweaks (path to GS and error on classes without constructor: namePos = 0 already reported below)

Joan Vazquez

After correcting the path (see Miron Voin and Guido de Hek's comments), AnimalExample works fine.
However, AnimalFruitExample with Add+subdirs throws this error:

"Array indices must be positive integers or logical values.

Error in ClassFile/setMethodsStrings (line 310)
tempString = this.methodsStrings{namePos};

Error in Tree/setPropsAndMethods (line 448)
this.classList(iClass).setMethodsStrings;

Error in Tree (line 124)
setPropsAndMethods(this);

Error in Tree/resort (line 424)
sortedThis = Tree(newNameList,tempOpts);

Error in Tree (line 115)
this = resort(this);

Error in UMLgui/doUML (line 1352)
tree = Tree(fileList,tempguidata.opts);

Error while evaluating UIControl Callback."

Miron Voin

Nicely done! The only issue I had is to insert the correct path to the gswin64c, following Guido de Hek's comment below.
Wish this project will be further supported.

Todd

I like the diagrams that you can get out of this.

I made a couple of tweaks to get this to work for me. First, I removed the addpaths line, because I manage paths using projects. Second, I added this to the doUML method to deal with packages:

% TFV deal with packages
m = strsplit(dirList{iDir},'\\+');

for iFile = 1:nFilesM
classNameM = listingM(iFile).name(1:end-2);
if length(m)>1
% TFV if this is a package, add that to the name
classNameM = strjoin([m(2:end),{classNameM}],'.');
end
classNames = [classNames,classNameM]; %#ok
end
And similarly in the next block, which deals with @ class folders.

Third, I modified Tree to deal with superclasses that the user didn't include in the class list (like matlab.mixin.Copyable.) When an empty parentId is found, I set the level for that class to 1. In setLevelInfo, I sort the class list by parentId and reassign levels, so that only classes in the class list are counted as levels.

% TFV temporarily assign parent id so that we can sort
for ix = 1:this.nClasses
parentId = find(strcmp(this.classNameList,this.classList(ix).parent));
if isempty(parentId)
this.classList(ix).parentId = 0;
else
this.classList(ix).parentId = parentId;
end
end
% TFV recalculate levels from parents down
[~,sortedorder] = sort([this.classList.parentId]);
for ix = sortedorder
if this.classList(ix).parentId > 0
this.classList(ix).level = this.classList(this.classList(ix).parentId).level + 1;
else
this.classList(ix).level = 1;
end
end

An alternate method would be to add missing superclasses to the class list. I think both of these methods would be easier if you could build the tree (or graph, really) by inserting nodes, and then navigate the graph to get the structure in the layout engine.

Todd

This has trouble if you have superclasses that are not included in the list of folders, for example, built-in matlab classes like handle or matlab.mixin.Copyable. Tree sets the parent level for these to zero, but resort tries to use that as an index.

Lockywolf

Well, the layout engine is good, and the diagrams are nicely looking.

But: only class diagrams, no others. (But that's okay, since class diagram is the most important one.

But what's worse, no associations are supported. Which is sort of unlucky.

I know, it's impossible to "directly" extract this information from classdef's, since MATLAB is a weakly typed language.

But I'd be happy to quasi-"mypy" the code with type annotations.

Charles Tatum

Would love to see package support. If I find a modification that works, I'll post it.

Guido de Hek

UMLgui could not find the ghostscript executable. gswin64c was installed in C:\Program Files\gs\gs9.22\bin.
To make it work I've changed the gs path in Tree.m on line 697 to: gs = '"C:\Program Files\gs\gs9.22\bin\gswin64c.exe"';

Johan Degerman

Very nice. Some glitches when using + and packages but still very nice.

Kilian

Benjamin

BUG REPORT: I seem to have discovered a bug. It seems to occur whenever there either class properties or methods have the property Hidden=true. The error disappears if I set Hidden = false. The error I get is:

Cell contents indices must be greater than 0

Error in ClassFile/setMethodsStrings (line 306)
tempString = this.methodsStrings{namePos};

Error in Tree/setPropsAndMethods (line 424)
this.classList(iClass).setMethodsStrings;

Error in Tree (line 123)
setPropsAndMethods(this);

Error in Tree/resort (line 400)
sortedThis = Tree(newNameList,tempOpts);

Error in Tree (line 114)
this = resort(this);

Error in UMLgui/doUML (line 1335)
tree = Tree(fileList,tempguidata.opts);

Sebastian G.

Marcel Tella

Very nice. It worked perfectly. I had to install ghostscript though, for opening the PDF.

Jonathan Joestar

works fine, very usefull

Alexander Lampe

Package support would be great!

I store all my classes in packages and subpackages etc., e.g. a class mypackage.Myclass has a superclass mypackage.superclasses.Superclass1

Mads Olsen

Caspar Jespersen

Very useful tool! Worked right out of the box.

John Reed

Code does not work with packages or class folders

Benjamin

I've just noticed that static methods are not included in the object methods. Is this intentional, and if so is there a possibility of a flag in the gui to include them?
Thanks

Ben Goddard

Benjamin: Thanks for the very helpful suggestion, it should now ignore any .git folders (and any subfolders).

Benjamin

FEATURE REQUEST: I tried for a folder which is under git version control. When adding folder/subfolders, it would be useful to exclude any paths containing '.git'

Benjamin

Very good. Worked first time. Very useful, thanks for creating this.

Ben Goddard

zwergnase: Does it create the pdf file mentioned in the error message?

Are you using the example included with your code or applying it to your own code?

simonflossmann

This tool would be really useful to me but it does not work. :-(

I get the following error:

Error using open (line 102)
File 'C:\Users\u16h62\Desktop\UML\UMLDiagram\Diagrams\UMLdiagram-2015_10_21_8_51_58.227.pdf' not
found.

Error in UMLgui/openPDF (line 759)
open([tempguidata.opts.saveFile]);

Error while evaluating UIControl Callback

Peter

MATLAB Release Compatibility
Created with R2017b
Compatible with any release
Platform Compatibility
Windows macOS Linux

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

UMLgui_1_2

UMLgui_1_2/AnimalExample

UMLgui_1_2/AnimalExample/Birds

UMLgui_1_2/AnimalExample/Mammals

UMLgui_1_2/AnimalFruitExample

UMLgui_1_2/AnimalFruitExample/+fruit

UMLgui_1_2/AnimalFruitExample/Birds

UMLgui_1_2/AnimalFruitExample/Mammals