0
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1 function pan6globals(varargin)
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
2
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
3 % ========================================================================
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
4 % ====================== Panel for the globals ===========================
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
5 % ========================================================================
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
6 % This is the GUI m-file to show that the panel relative to the global
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
7 % variables set by the user.
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
8 %
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
9 % $Id: pan6globals.m,v 1.6 2008/08/30 12:32:25 nicola Exp $
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
10
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
11 global gl currSys
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
12 currPanel = varargin{1};
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
13 panelDimens = get(currPanel, 'Position');
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
14 backColor = get(currPanel, 'BackgroundColor');
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
15 selBlocks = 0;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
16 enlargedFont = 0;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
17 currSys = '';
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
18
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
19 alltimers = timerfindall;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
20 stop(alltimers(1));
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
21 set(alltimers(1),'TimerFcn',@ContinuousParamCheck,'Period',0.3);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
22 start(alltimers(1));
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
23
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
24 %----------------------------------------------------------------------
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
25 function buildGlobalPanel(varargin)
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
26 %----------------------------------------------------------------------
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
27
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
28 globBlock = find_system(bdroot,'SearchDepth',1,'BlockType','SubSystem','Tag','globals');
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
29 if isempty(globBlock) || (~isempty(varargin) && isnumeric(varargin{3}) && varargin{3}==-1)
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
30 gl = struct();
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
31 updateGlobalBlock()
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
32 else
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
33 gl = get_param(globBlock{1},'UserData');
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
34 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
35
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
36 % if isempty(gl) || (~isempty(varargin) && isnumeric(varargin{3}) && varargin{3}==-1), gl=struct(); end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
37
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
38 panelDimens = get(currPanel, 'Position');
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
39 delete(findobj(gcf,'Parent',currPanel))
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
40 varnames = fieldnames(gl);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
41 y = numel(varnames);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
42
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
43 % 'List of global variables' text:
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
44 uicontrol('Parent',currPanel,'BackgroundColor',backColor,'Units','pixels','Position',[20 panelDimens(4)-40 panelDimens(3)-40 20],'String','List of global variables:','HorizontalAlignment','center','FontSize',enlargedFont+10,'FontWeight','bold','Visible','on','Style','text');
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
45 % 'Global names' text:
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
46 uicontrol('Parent',currPanel,'BackgroundColor',backColor,'Units','pixels','Position',[panelDimens(3)/2-150-20 panelDimens(4)-70 150 20],'String','Names:','HorizontalAlignment','right','FontSize',enlargedFont+9,'Visible','on','Style','text');
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
47 % 'Global values' text:
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
48 uicontrol('Parent',currPanel,'BackgroundColor',backColor,'Units','pixels','Position',[panelDimens(3)/2+20 panelDimens(4)-70 150 20],'String','Values:','HorizontalAlignment','left','FontSize',enlargedFont+9,'Visible','on','Style','text');
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
49
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
50 for i=1:y
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
51 % % 'gl.' text:
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
52 % uicontrol('Parent',currPanel,'BackgroundColor',backColor,'Units','pixels','Position',[panelDimens(3)/2-200-20-15 panelDimens(4)-20-24*(i+2)-5 12 20],'String','gl.','FontSize',enlargedFont+8,'Visible','on','Enable','off','Style','text');
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
53 % Variable name edit field:
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
54 uicontrol('Parent',currPanel,'Units','pixels','Position',[panelDimens(3)/2-200-20 panelDimens(4)-20-24*(i+2) 200 20],'String',['gl.',varnames{i}],'FontSize',enlargedFont+8,'Visible','on','Enable','on','UserData',i,'Callback',@globalName,'Style','edit');
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
55 % Variable value edit field:
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
56 currVal = gl.(varnames{i});
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
57 if iscell(currVal), currVal = cell2str(currVal);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
58 else currVal = mat2str(currVal);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
59 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
60 uicontrol('Parent',currPanel,'Units','pixels','Position',[panelDimens(3)/2+20 panelDimens(4)-20-24*(i+2) 200 20],'String',currVal,'FontSize',enlargedFont+8,'Visible','on','Enable','on','UserData',i,'Callback',@globalValue,'Style','edit');
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
61 % Remove input button
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
62 uicontrol('Parent',currPanel,'Units','pixels','Position',[700 panelDimens(4)-20-24*(i+2) 20 20],'String','-','Visible','on','Enable','on','Callback', @RemoveGlobal,'UserData',i,'Style','pushbutton');
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
63 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
64
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
65 % Add input button
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
66 uicontrol('Parent',currPanel,'Units','pixels','Position',[panelDimens(3)/2-10 panelDimens(4)-50-24*(y+2) 20 20],'String','+','TooltipString','Add a global variable','Visible','on','Enable','on','Callback', @AddGlobal,'Style','pushbutton');
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
67
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
68 % Clear all button:
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
69 uicontrol('Parent',currPanel,'Units','pixels','HorizontalAlignment','center','Position',[panelDimens(3)-100 10 80 16],'FontAngle','italic','FontSize',enlargedFont+8,'String','Clear all','TooltipString','Clear all the global variables','Visible','on','Callback',{@buildGlobalPanel,-1},'Style','pushbutton');
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
70
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
71
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
72 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
73 %----------------------------------------------------------------------
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
74
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
75 %%
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
76 %----------------------------------------------------------------------
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
77 function ContinuousParamCheck(varargin)
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
78 % This is the function to execute a continuous check on the status
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
79 % of the current selection (system and block).
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
80
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
81 % Clear if nothing's selected
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
82 if isempty(bdroot) || strcmp(get_param(bdroot,'BlockDiagramType'),'library') || isempty(find_system(bdroot,'FindAll','on','Type','Annotation','Tag','ltpda model'))
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
83 delete(findobj(gcf,'Parent',currPanel))
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
84 currSys = gcs;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
85 gl = struct();
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
86 return
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
87 else
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
88 if ~strcmp(gcs,currSys)
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
89 % The selection changed.
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
90 currSys = gcs;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
91 buildGlobalPanel();
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
92 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
93 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
94
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
95 % if ~isempty(find_system(bdroot,'FindAll','on','Type','Annotation','Tag','ltpda model'))
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
96 % % It's selected a ltpda simulink analysis diagram.
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
97 % if ~strcmp(gcs,currSys)
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
98 % % The selection changed.
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
99 % currSys = gcs;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
100 % buildGlobalPanel();
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
101 % end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
102 % end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
103
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
104 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
105 %----------------------------------------------------------------------
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
106
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
107 %%
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
108 %----------------------------------------------------------------------
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
109 function AddGlobal(varargin)
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
110
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
111 newGlob = 'global';
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
112 ii = 1;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
113 while isfield(gl,[newGlob,num2str(ii)]), ii = ii+1; end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
114 newGlob = [newGlob,num2str(ii)];
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
115 gl.(newGlob) = [];
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
116 updateGlobalBlock()
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
117 buildGlobalPanel()
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
118
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
119 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
120 %----------------------------------------------------------------------
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
121
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
122 %----------------------------------------------------------------------
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
123 function RemoveGlobal(hObject,varargin)
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
124
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
125 currGlob = get(hObject,'Userdata');
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
126 varnames = fieldnames(gl);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
127 gl = rmfield(gl,varnames{currGlob});
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
128 updateGlobalBlock()
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
129 buildGlobalPanel()
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
130
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
131 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
132 %----------------------------------------------------------------------
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
133
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
134 %----------------------------------------------------------------------
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
135 function globalName(hObject,varargin)
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
136
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
137 currGlob = get(hObject,'Userdata');
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
138 varnames = fieldnames(gl);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
139 newGlobName = get(hObject,'String');
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
140 if numel(newGlobName)<4 || ~strcmp(newGlobName(1:3),'gl.'), newGlobName = ['gl.',strrep(newGlobName,'.','')]; end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
141
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
142 newGlobName = ['gl.',genvarname(newGlobName(4:end))];
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
143 if isempty(get(hObject,'String')) || isfield(gl,newGlobName(4:end)), set(hObject,'String',['gl.',varnames{currGlob}]); return; end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
144
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
145 set(hObject,'String',newGlobName);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
146 gl = utils.prog.rnfield(gl,varnames{currGlob},newGlobName(4:end));
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
147 updateGlobalBlock()
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
148 buildGlobalPanel()
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
149
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
150 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
151 %----------------------------------------------------------------------
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
152
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
153 %----------------------------------------------------------------------
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
154 function globalValue(hObject,varargin)
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
155
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
156 currGlob = get(hObject,'Userdata');
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
157 newValue = get(hObject,'String');
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
158 varnames = fieldnames(gl);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
159 try newValue = eval(newValue); catch end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
160 gl.(varnames{currGlob}) = newValue;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
161 updateGlobalBlock()
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
162 buildGlobalPanel()
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
163
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
164 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
165 %----------------------------------------------------------------------
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
166
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
167 %----------------------------------------------------------------------
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
168 function updateGlobalBlock(varargin)
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
169
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
170 varNames = fieldnames(gl);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
171
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
172 if numel(varNames)==0
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
173 % Remove the block if no globals are left:
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
174 globBlock = find_system(bdroot,'BlockType','SubSystem','Tag','globals');
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
175 if ~isempty(globBlock)
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
176 delete_block(globBlock)
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
177 return;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
178 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
179 else
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
180 globBlock = find_system(bdroot,'SearchDepth',1,'BlockType','SubSystem','Tag','globals');
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
181 try globBlock = globBlock{1}; catch end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
182 % Check if the globals block exists:
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
183 if isempty(globBlock)
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
184 globBlock = add_block('ltpda_library/Commonly Used Blocks/Globals',[bdroot '/Globals']);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
185 annotation = find_system(bdroot,'FindAll','on','Type','Annotation','Tag','ltpda model');
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
186 position = get_param(annotation,'Position');
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
187 set_param(globBlock,'Position',[position(1)+20 position(2)-25 position(1)+150 position(2)-10 ])
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
188 set_param(globBlock,'DropShadow','on')
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
189 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
190
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
191 % Update the globals block:
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
192 set_param(globBlock,'UserData',gl)
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
193 set_param(globBlock,'UserDataPersistent','on')
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
194 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
195
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
196
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
197 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
198 %----------------------------------------------------------------------
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
199
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
200 %%
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
201 end |