File Exchange

image thumbnail

m2uml

version 1.12 (1.63 MB) by

m2uml generates UML class diagrams from m-code

54 Downloads

Updated

View License

This version, v1.1, of m2uml is more useful than previous version, v1.0
1. m2uml uses a semi-automated method to generate a class diagram for a user-selected set of classes. Reverse engineering of the Matlab code generates the entire inheritance tree structure. The other relationships are part of the input to m2uml. The result is either a png- or a svg-file. The latter is displayed in the Matlab web browser.
2. New: m2uml v1.1 adds tool-tips to the svg-file. The classes and all the methods show their H1-lines as tool-tip.
3. New: m2uml v1.1 adds hyper-links to the svg-file. Clicking the name of a class or method opens the file in the Matlab editor and moves the cursor to the first occurrence of the specified item.

4. New: m2uml v1.1 displays TODO/FIXME annotations in a separate compartment of the box of the class. These annotations have tool-tips and hyper-links.

I envision m2uml as a tool to support design and implementation of software. Creating class diagrams for the documentation comes second.

Read "m2uml generates UML Class Diagrams", which is created with the function, publish. It contains a description of m2uml v1.0 together with links and examples.

Next read "m2uml 1.1 - Hyper-links and tool-tips", which is also created with publish. It concentrates on new features in m2uml v1.1.

m2uml v1.1 comes in a zip-file. Unzip it to a new folder and add that to the Matlab-path. Remove the m2uml v1.0 folder from the path, if there is one. To test the installation, open m2uml_cloud_m2uml.m in the editor, and Run Section by section. If PlantUML-code ending with @enduml appears in a document in the editor, m2uml is probably working.

m2uml is based on PlantUML and Graphviz. m2uml retrieves information from the Matlab-code and outputs PlantUML-code. PlantUML uses GraphViz and draws the class diagram. To make a local installation of PlantUML see http://plantuml.com/starting. The two functions, m2uml.call_local_PlantUML and m2uml.uml2web, contain the assignment "plantuml_jar='c:\_MyPrg\PlantUML\plantuml.jar';". Edit that to fit your installation of PlantUML.

However, experiments with m2uml don't require installations of PlantUML and Graphviz. PlantUML-code may be created locally and converted to a diagram in the cloud, e.g. https://www.planttext.com/.

Comments and Ratings (13)

per isakson

An updated version of get_H1_line.m, which returns an appropriate string when the method is defined in a superclass, is attached to a comment to the question, https://uk.mathworks.com/matlabcentral/answers/308970-what-s-required-of-an-automatic-uml-class-diagrams-tool-to-be-useful

per isakson

@Andrew Joslin, thank you for your comment.

I'm a bit puzzled by your proposal. Maybe, I'm missing something.

Yes, an error is thrown for H1=get_H1_line(filespec,fnc-name) if fnc_name doesn't exist in filespec (by design). However, there are two exceptions 1) implicit constructor and 2) the method is defined in a separate file in a class-folder.

Question: Did you get this error when you executed m2uml or get_H1_line in isolation? (My intention is that m2uml shall only call get_H1_line with fnc_name defined in filespec. If the error is thrown when called from m2uml the problem is somewhere else in the code. I have never seen the error when running m2uml.)

The reason I made get_H1_line is speed (compared to help). I hesitate to involve superclasses in this function. And want to honor single responsibility.

I find UML tricky. I use UML Distilled by Fowler (and the Internet). Your comment suggests that a method, which is defined in a superclass, shall be displayed in both the superclass and the subclass. I understand that a method shall be displayed in both the superclass and the subclass only if its overloaded in the subclass. (That makes the diagram more compact, which is good.) However, I haven't seen that written down explicitly.

I have a considerable back-log and plan to submit a new version.

I would appreciate more details on the case which caused the error. If you want to attach files and screen-clips make it an answer to https://uk.mathworks.com/matlabcentral/answers/308970-what-s-required-of-an-automatic-uml-class-diagrams-tool-to-be-useful

Excellent tool, thanks for submitting!

I might have found a bug in get_H1_line.m that you might want to know about (user error is possible).
For me, it throws an error when the method in the "fnc_name" variable is inherited from a superclass. In this instance, the 2 cases defined in the code ("1. Implicit contructor of class", and "2. Inherited from superclass") don't seem to cover the 3rd case where the method is inherited from the superclass.

Setting variable "H1" to "['Inherited from ' <comma-separated list of superclasses which have this method>]" would fix the problem, though I don't think it would ever result in more than one item in the list of superclasses.

Hope this helps.

Peter Németh

per isakson

It's by design. The reason was that the width of the diagram explodes.

function [out1,out2]=method(obj,inp1,inp2)

Doesn't the same apply to the output parameters? And Matlab allows more than one. What format should be used for the method line? I want the method name to the left of the parameter names.

The solution is to let the user decide by choosing among options.

Does not recognise method input parameters. E.g.

function method(obj, inp1, inp2)
% Implementation
end

results in method() in the diagram.

per isakson

Regarding "Interface and Interface2D". I stumbled into something similar. In my case the reason was that the constructor of the class, "Interface2D", by mistake was named "Interface". That raises the question whether the class diagram should indicate the "color" of the code analyzer.

Regarding matlab.mixin.Copyable. Under the hood of Matlab has a complex (and growing?) structure of nested packages. And their names are often long. I agree, this can and shall not be displayed in the diagrams. However, how much information can be and is desirable to communicated with one letter? KISS.

matlab.mixin.Copyable is not inhereted properly (see the screenshot below). In my opinion, it should be handled just as the handle class (i.e. not display in the class diagram) as matlab.mixin.Copyable only serves for deep copying of handle classes.

Here is a screenshot: http://imgur.com/a/MdeJD

@per isakson
which('Interface') returns only the class Interface but not the class Interface2D.

per isakson

@Zoltán Csáti, thank you for your comment.

which('Interface') shouldn't return both Interface and Interface2D - or do I miss something. Does that really happen?

The rationale behind which(file_name,'-all') is to avoid that Matlab files shadows user defined files. Furthermore, I want to assert that the user doesn't have modules with identical names on the search path. However, this function is the wrong place to do that. I'll do something to it, but please modify your copy in the meantime.

The aggregation/composition relationships have caused me problems. 1) There is no "easy" way to extract that information from the m-code or the meta-object. 2) I might be missing some nuances of the UML-standard, but I don't care that much. 3) Matlab isn't a pure OO-language; I need to include functions in the diagram. (For example, I often implement factories with function.)

Anyhow, my highest priority is to show "all" dependencies.

Suggestions are welcome!

Superb package. I would have one suggestion though: when classes begin with the same name (e.g. Interface and Interface2D in my case), the assertion on line 14 of has_explicit_constructor.m fails. The quick fix of using filespec{1} = which( file_name ); instead of filespec = which ( file_name, 'all' ); solves this issue.
Is it possible to somehow extract the aggregation/composition relationships?

per isakson

I write "Next read "m2uml 1.1 - Hyper-links and tool-tips", but there is no corresponding light-bulb-link in the right column. I cannot figure out why.

The zip-file contains html\m2uml_v11_hyperlinks_tooltips_publish.html,
which displays fine in my local browser.

Vandana Rajan

Updates

1.12

New attempt to fix the broken light-bulb-link.

1.11

Fixed broken link

1.1

m2uml v1.1 adds tool-tips and hyper-links and displays the class diagram in the Matlab browser

1.0

Fixed spelling mistake.

MATLAB Release
MATLAB 9.0 (R2016a)
Acknowledgements

Inspired by: youemel

Download apps, toolboxes, and other File Exchange content using Add-On Explorer in MATLAB.

» Watch video

Win prizes and improve your MATLAB skills

Play today