comparison m-toolbox/classes/+utils/@helper/make_class_diagram.m @ 0:f0afece42f48

Import.
author Daniele Nicolodi <nicolodi@science.unitn.it>
date Wed, 23 Nov 2011 19:22:13 +0100
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:f0afece42f48
1 % A script to plot nicely the class structure of the LTPDA Toolbox,
2 % showing all the dependencies
3 % Setting the flag 'show_methods' to true or false, it is possible to
4 % display also the public methods of the user classes
5 %
6 % M Hewitson 08/04/2011
7 %
8 % VERSION: $Id: make_class_diagram.m,v 1.1 2011/07/05 06:51:37 mauro Exp $
9
10 % display methods or not
11 show_methods = false;
12
13 % get global variables
14 prefs = getappdata(0, 'LTPDApreferences');
15 DOT = char(prefs.getExternalPrefs.getDotBinaryPath);
16 FEXT = char(prefs.getExternalPrefs.getDotOutputFormat);
17
18 classes = utils.helper.ltpda_classes;
19
20 out = sprintf('digraph G \n');
21 out = [out sprintf('{\n')];
22 out = [out sprintf('rankdir = BT\n')];
23
24 out = [out sprintf('handle [fontsize=8 label="handle" shape="ellipse" ];\n')];
25
26 % first class nodes
27 for kk = 1:numel(classes)
28 class = classes{kk};
29 m = eval(['?' class]);
30
31 if ~isempty(m)
32 if show_methods
33 label = sprintf('<<table border="1" cellborder="1" cellpadding="3" cellspacing="0" bgcolor="white"><tr><td bgcolor="black" align="center"><font color="white">%s</font></td></tr>\n', m.Name);
34
35 mthds = m.Methods;
36 for jj = 1:numel(mthds)
37 mthd = mthds{jj};
38 if strcmp(mthd.DefiningClass.Name, m.Name) && strcmp(mthd.Access, 'public')
39 label = [label sprintf('<tr><td align="left" port="r%d">%s</td></tr>\n', jj, mthd.Name)];
40 end
41 end
42 label = [label sprintf('</table>>')];
43 out = [out sprintf('%s [ shape = "plaintext" fontsize=12 label=%s ];\n', m.Name, label)];
44 else
45 out = [out sprintf('%s [fontsize=12 shape=rectangle label="%s"];\n', m.Name, m.Name)];
46 end
47 end
48
49 end
50
51 % now links
52 for kk = 1:numel(classes)
53 class = classes{kk};
54 m = eval(['?' class]);
55 % parents
56 parents = m.SuperClasses;
57
58 % m -> parent
59 for jj = 1:numel(parents)
60 p = parents{jj};
61
62 out = [out sprintf('%s -> %s\n', m.Name, p.Name)];
63
64 end
65
66 end
67
68 out = [out sprintf('}\n')];
69
70 dotfile = 'ltpda_classdiagram.dot';
71 fd = fopen(dotfile, 'w+');
72 fprintf(fd, out);
73 fclose(fd);
74
75 [path, name, ext] = fileparts(dotfile);
76 outfile = fullfile(path, [name '.' FEXT]);
77
78 % Write to graphics file
79 cmd = sprintf('%s -T%s -o %s %s', DOT, FEXT, outfile, dotfile);
80 system(cmd);
81
82 % View graphics file
83 if any(strcmpi(FEXT, {'gif', 'ico', 'jpg', 'jpeg', 'jpe', 'png', 'tiff'}))
84 image(imread(outfile));
85 else
86 open(outfile);
87 end
88