Mercurial > hg > ltpda
comparison m-toolbox/classes/@ssm/dotview.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 % DOTVIEW view an ssm object via the DOT interpreter. | |
2 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
3 % | |
4 % DESCRIPTION: DOTVIEW view an ssm object via the DOT interpreter. | |
5 % | |
6 % The ssm object is converted to a dot file (www.graphviz.org) then: | |
7 % 1) rendered to the format specified inside the user's LTPDA Toolbox Preferences | |
8 % (accessible via the dedicated GUI or typing "LTPDAprefs" on the Matlb terminal) | |
9 % 2) opened with the chosen viewer. | |
10 % 3) The graphic file is kept. | |
11 % | |
12 % CALL: dotview(s, pl); | |
13 % dotview(s, 'my_filename'); | |
14 % dotview(s); % Displays only the diagram | |
15 % | |
16 % INPUTS: h - ssm object | |
17 % pl - plist of options | |
18 % | |
19 % <a href="matlab:utils.helper.displayMethodInfo('ssm', 'dotview')">Parameters Description</a> | |
20 % | |
21 % VERSION: $Id: dotview.m,v 1.16 2011/04/08 08:56:23 hewitson Exp $ | |
22 % | |
23 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
24 | |
25 | |
26 function varargout = dotview(varargin) | |
27 | |
28 %%% Check if this is a call for parameters | |
29 if utils.helper.isinfocall(varargin{:}) | |
30 varargout{1} = getInfo(varargin{3}); | |
31 return | |
32 end | |
33 | |
34 % get global variables | |
35 prefs = getappdata(0, 'LTPDApreferences'); | |
36 DOT = char(prefs.getExternalPrefs.getDotBinaryPath); | |
37 FEXT = char(prefs.getExternalPrefs.getDotOutputFormat); | |
38 | |
39 %%% Set inputs | |
40 objs = utils.helper.collect_objects(varargin(:), 'ssm'); | |
41 pl = utils.helper.collect_objects(varargin(:), 'plist'); | |
42 fn = utils.helper.collect_objects(varargin(:), 'char'); | |
43 | |
44 pl = combine(pl, getDefaultPlist); | |
45 | |
46 view = find(pl, 'view'); | |
47 iformat = find(pl, 'format'); | |
48 if ~isempty(fn) | |
49 filename = fn; | |
50 else | |
51 filename = find(pl, 'filename'); | |
52 end | |
53 | |
54 % Create tempoary filename | |
55 if isempty(filename) | |
56 filename = fullfile(tempdir, 'ltpda_dotview.pdf'); | |
57 end | |
58 if ~isempty(iformat) | |
59 FEXT = iformat; | |
60 end | |
61 | |
62 for jj=1:numel(objs) | |
63 | |
64 [path, name, ext] = fileparts(filename); | |
65 | |
66 % Convert ssm to a tmp dot file | |
67 tname = tempname; | |
68 dotfile = [tname '.dot']; | |
69 outfile = fullfile(path, [name '.' FEXT]); | |
70 | |
71 % Make DOT file | |
72 ssm2dot(objs(jj), plist('filename', dotfile)); | |
73 | |
74 % Write to graphics file | |
75 cmd = sprintf('%s -T%s -o %s %s', DOT, FEXT, outfile, dotfile); | |
76 system(cmd); | |
77 | |
78 % View graphics file | |
79 if view | |
80 if any(strcmpi(FEXT, {'gif', 'ico', 'jpg', 'jpeg', 'jpe', 'png', 'tiff'})) | |
81 image(imread(outfile)); | |
82 else | |
83 open(outfile); | |
84 end | |
85 end | |
86 | |
87 % Delete tmp dotfile | |
88 delete(dotfile); | |
89 | |
90 end | |
91 | |
92 end | |
93 | |
94 | |
95 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
96 % Local Functions % | |
97 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
98 | |
99 %-------------------------------------------------------------------------- | |
100 % Get Info Object | |
101 %-------------------------------------------------------------------------- | |
102 function ii = getInfo(varargin) | |
103 if nargin == 1 && strcmpi(varargin{1}, 'None') | |
104 sets = {}; | |
105 pl = []; | |
106 else | |
107 sets = {'Default'}; | |
108 pl = getDefaultPlist; | |
109 end | |
110 % Build info object | |
111 ii = minfo(mfilename, 'ssm', 'ltpda', utils.const.categories.output, '$Id: dotview.m,v 1.16 2011/04/08 08:56:23 hewitson Exp $', sets, pl); | |
112 ii.setOutmin(0); | |
113 ii.setOutmax(0); | |
114 end | |
115 | |
116 | |
117 %-------------------------------------------------------------------------- | |
118 % Get Default Plist | |
119 %-------------------------------------------------------------------------- | |
120 function plo = getDefaultPlist() | |
121 | |
122 % Use the "factory" plist | |
123 plo = plist.DOTVIEW_PLIST; | |
124 | |
125 end |