Robochameleon  v1.0
unit_view.m
Go to the documentation of this file.
1 classdef unit_view
2  properties(GetAccess=private,SetAccess=private,Hidden)
3  nextNodes;
4  destInputs;
5  label;
6  debugMode;
7  end
8 
9  methods
10  function obj=unit_view(nextNodes,destInputs,label)
11  % Setter
12  obj.nextNodes = nextNodes;
13  obj.destInputs = destInputs;
14  obj.label = label;
15 
16  % Create GUI and populate
17  obj.createUI();
18 
19  end
20 
21 
22  end
23  methods (Access=public)
24  function select(obj,~,~,ui)
25  list = ui.listbox.Value;
26  N = length(list);
27  for i=1:N
28  fprintf('\n%s:\n',[obj.label ' --> ' obj.nextNodes{i}.label '[' num2str(obj.destInputs(i)) ']']);
29  disp(obj.nextNodes{list(i)}.inputBuffer{obj.destInputs(list(i))});
30  end
31  end
32  function copy2Cell(obj,~,~,ui)
33  list = ui.listbox.Value;
34  N = length(list);
35  sig = cell(1,N);
36  for i=1:N
37  sig{i}=obj.nextNodes{list(i)}.inputBuffer{obj.destInputs(list(i))};
38  end
39  assignin('base','sig',sig)
40  fprintf('Saved chosen signals to workspace as cell (1,%g).\n',N)
41  end
42  function plotTime(obj,~,~,ui)
43  list = ui.listbox.Value;
44  N = length(list);
45  sig = zeros(obj.nextNodes{1}.inputBuffer{list(1)}.L,N);
46  for i=1:length(list)
47  sig(:,i)=get(obj.nextNodes{list(i)}.inputBuffer{list(i)});
48  end
49  t = 0:obj.nextNodes{list(1)}.inputBuffer{list(1)}.Ts:(obj.nextNodes{list(1)}.inputBuffer{list(1)}.L-1)*obj.nextNodes{list(1)}.inputBuffer{list(1)}.Ts;
50  figure()
51  plot(t,sig);
52  xlabel('Time');
53  ylabel('Magnitude');
54  title(obj.label);
55  end
56  function plotFreq(obj,~,~,ui)
57  list = ui.listbox.Value;
58  N = length(list);
59  sig = zeros(obj.nextNodes{1}.inputBuffer{list(1)}.L,N);
60  for i=1:length(list)
61  sig(:,i)=get(obj.nextNodes{list(i)}.inputBuffer{list(i)});
62  end
63  f = linspace(-1/obj.nextNodes{list(1)}.inputBuffer{list(1)}.Ts/2,1/obj.nextNodes{list(1)}.inputBuffer{list(1)}.Ts/2,obj.nextNodes{list(1)}.inputBuffer{list(1)}.L);
64  SIG = abs(fftshift(fft(sig))).^2;
65  figure()
66  plot(f,SIG);
67  xlabel('Frequency');
68  ylabel('Power');
69  title(obj.label);
70  end
71  end
72  methods (Access=private)
73  function ui = createUI(obj)
74  % Create and then hide the UI as it is being constructed.
75  f = figure('Visible','off',...
76  'Name',obj.label,...
77  'NumberTitle','off',...
78  'MenuBar', 'none',...
79  'ToolBar', 'none');
80  ratioW = 0.3;
81  ratioH = 0.3;
82  scrsz = get(0,'ScreenSize');
83  set(gcf,'OuterPosition',[1 scrsz(4)*(1-ratioH) scrsz(3)*ratioW scrsz(4)*ratioH ])
84  pos = get(gcf,'Position');
85  w = pos(3);
86  h = pos(4);
87  ui=struct;
88  N=numel(obj.nextNodes);
89  popupmenu_data = cell(1,N);
90  for i=1:N
91  popupmenu_data{i} = [obj.label ' --> ' obj.nextNodes{i}.label '[' num2str(obj.destInputs(i)) ']'];
92  end
93  if(isempty(popupmenu_data) || (~ispref('robochameleon','debugMode') || ~getpref('robochameleon','debugMode')))
94  fprintf('This is a sink unit or debugMode is turned off.\n')
95  enablebtn = 'off';
96  else
97  enablebtn = 'on';
98  end
99  ui.listbox = uicontrol('Style','listbox',...
100  'String',popupmenu_data,...
101  'max',100,...
102  'min',1,...
103  'Position',[0 h-285 200 285]);
104  ui.showbtn = uicontrol('Style', 'pushbutton',...
105  'String', 'disp()',...
106  'Position', [210 h-25 160 25],...
107  'Enable',enablebtn,...
108  'Callback', @(hObject,callbackdata) obj.select(hObject,callbackdata,ui));
109 % ui.timebtn = uicontrol('Style', 'pushbutton',...
110 % 'String', 'plot(t,sig) (TODO)',...
111 % 'Position', [210 3*28 160 25],...
112 % 'Enable','off',...
113 % 'Callback', @(hObject,callbackdata) obj.plotTime(hObject,callbackdata,ui));
114 % ui.freqbtn = uicontrol('Style', 'pushbutton',...
115 % 'String', 'plot(f,fft(sig)) (TODO)',...
116 % 'Position', [210 2*28 160 25],...
117 % 'Enable','off',...
118 % 'Callback', @(hObject,callbackdata) obj.plotFreq(hObject,callbackdata,ui));
119 % ui.workspacebtn1 = uicontrol('Style', 'pushbutton',...
120 % 'String', 'Copy to workspace as matrix',...
121 % 'Position', [210 28 160 25],...
122 % 'Enable',enablebtn,...
123 % 'Callback', @(hObject,callbackdata) obj.copy2Mat(hObject,callbackdata,ui));
124  ui.workspacebtn2 = uicontrol('Style', 'pushbutton',...
125  'String', 'Copy to workspace as cell',...
126  'Position', [210 h-25-1*28 160 25],...
127  'Enable',enablebtn,...
128  'Callback', @(hObject,callbackdata) obj.copy2Cell(hObject,callbackdata,ui));
129  % Make the UI visible.
130  f.Visible = 'on';
131 
132  end
133  end
134 end
135 
Superclass: graphical interface for units.
Definition: unit_view.m:17