📄 fmri_input_condition_ui.m
字号:
function [condition_names,condition_baseline,removed_condition_idx] = ...
fmri_input_condition_ui(varargin)
%
% USAGE: [condition_name,condition_baseline,removed_condition_idx] = ...
% fmri_input_condition_ui(old_condition,old_baseline,protected_conds)
%
if nargin == 0
old_conditions = [];
end;
if nargin == 0 | ~ischar(varargin{1})
old_conditions = [];
old_condition_baseline = [];
protected_conds = [];
if (nargin == 1)
old_conditions = varargin{1};
elseif (nargin == 2)
old_conditions = varargin{1};
old_condition_baseline = varargin{2};
elseif (nargin == 3)
old_conditions = varargin{1};
old_condition_baseline = varargin{2};
protected_conds = varargin{3};
end;
init(old_conditions,old_condition_baseline,protected_conds);
uiwait; % wait for user finish
removed_condition_idx = getappdata(gcf,'RemovedConditions');
condition_names = getappdata(gcf,'CurrConditions');
condition_baseline = getappdata(gcf,'CurrConditionBaseline');
close(gcf);
return;
end;
% clear the message line,
%
h = findobj(gcf,'Tag','MessageLine');
set(h,'String','');
action = upper(varargin{1});
if strcmp(action,'UPDATE_CONDITION'),
UpdateCondition;
elseif strcmp(action,'UPDATE_OFFSET'),
UpdateOffset;
elseif strcmp(action,'UPDATE_LENGTH'),
UpdateLength;
elseif strcmp(action,'DELETE_CONDITION'),
DeleteCondition;
elseif strcmp(action,'ADD_CONDITION'),
AddCondition;
elseif strcmp(action,'MOVE_SLIDER'),
MoveSlider;
elseif strcmp(action,'DELETE_FIG')
delete_fig;
elseif strcmp(action,'CANCEL_BUTTON_PRESSED'),
old_conditions = getappdata(gcf,'OldConditions');
setappdata(gcf,'CurrConditions',old_conditions);
uiresume;
elseif strcmp(action,'DONE_BUTTON_PRESSED'),
DoneButtonPressed;
end;
return;
%----------------------------------------------------------------------------
function init(old_conditions,old_condition_baseline,protected_conds)
curr_dir = pwd;
save_setting_status = 'on';
fmri_input_condition_pos = [];
try
load('pls_profile');
catch
end
if ~isempty(fmri_input_condition_pos) & strcmp(save_setting_status,'on')
pos = fmri_input_condition_pos;
else
w = 0.6;
h = 0.7;
x = (1-w)/2;
y = (1-h)/2;
pos = [x y w h];
end
h0 = figure('Color',[0.8 0.8 0.8], ...
'Units','normal', ...
'Name','Edit Condition', ...
'MenuBar','none', ...
'NumberTitle','off', ...
'deletefcn','fmri_input_condition_ui(''DELETE_FIG'');', ...
'Position',pos, ...
'WindowStyle', 'modal', ...
'Tag','InputCondition', ...
'ToolBar','none');
% 'DoubleBuffer', 'on', ...
% 'Renderer', 'OpenGL', ...
x = 0.11;
y = 0.9;
w = 0.21;
h = 0.06;
pos = [x y w h];
fnt = 0.4;
l_h2 = uicontrol('Parent',h0, ... % condition name lbl
'Style','text', ...
'Units','normal', ...
'BackgroundColor',[0.8 0.8 0.8], ...
'FontUnits','normal', ...
'FontSize',fnt, ...
'FontWeight','bold', ...
'HorizontalAlignment','left', ...
'ListboxTop',0, ...
'Position',pos, ...
'String','Condition Name', ...
'tooltipstring','Condition Name', ...
'Tag','ConditionNameEditLbl');
x = x+w+0.01;
w = 0.2;
pos = [x y w h];
l_h4 = uicontrol('Parent',h0, ... % condition offset lbl
'Style','text', ...
'Units','normal', ...
'BackgroundColor',[0.8 0.8 0.8], ...
'FontUnits','normal', ...
'FontSize',fnt, ...
'FontWeight','bold', ...
'HorizontalAlignment','left', ...
'ListboxTop',0, ...
'Position',pos, ...
'String','Reference Scan Onset', ...
'tooltipstring','Reference Scan Onset', ...
'Tag','ConditionOffsetEditLbl');
x = x+w+0.01;
w = 0.2;
pos = [x y w h];
l_h5 = uicontrol('Parent',h0, ... % baseline length lbl
'Style','text', ...
'Units','normal', ...
'BackgroundColor',[0.8 0.8 0.8], ...
'FontUnits','normal', ...
'FontSize',fnt, ...
'FontWeight','bold', ...
'HorizontalAlignment','left', ...
'ListboxTop',0, ...
'Position',pos, ...
'String','Number of Reference Scans', ...
'tooltipstring','Number of Reference Scans', ...
'Tag','ConditionLengthEditLbl');
x = 0.03;
y = 0.82;
w = 0.07;
pos = [x y w h];
fnt = fnt+0.1;
c_h1 = uicontrol('Parent',h0, ... % condition idx
'Style','text', ...
'Units','normal', ...
'BackgroundColor',[0.8 0.8 0.8], ...
'FontUnits','normal', ...
'FontSize',fnt, ...
'HorizontalAlignment','right', ...
'ListboxTop',0, ...
'Position',pos, ...
'String','1.', ...
'Tag','ConditionIdxLabel');
x = x+w+0.01;
w = 0.21;
pos = [x y w h];
c_h2 = uicontrol('Parent',h0, ... % condition name
'Style','edit', ...
'Units','normal', ...
'BackgroundColor',[1 1 1], ...
'FontUnits','normal', ...
'FontSize',fnt, ...
'HorizontalAlignment','left', ...
'ListboxTop',0, ...
'Position',pos, ...
'String','', ...
'tooltipstring','Condition Name', ...
'Tag','ConditionNameEdit');
x = x+w+0.01;
w = 0.2;
pos = [x y w h];
c_h4 = uicontrol('Parent',h0, ... % condition offset
'Style','edit', ...
'Units','normal', ...
'BackgroundColor',[1 1 1], ...
'FontUnits','normal', ...
'FontSize',fnt, ...
'HorizontalAlignment','left', ...
'ListboxTop',0, ...
'Position',pos, ...
'String','', ...
'tooltipstring','Reference scan onset', ...
'Tag','ConditionOffsetEdit');
x = x+w+0.01;
w = 0.2;
pos = [x y w h];
c_h5 = uicontrol('Parent',h0, ... % baseline length
'Style','edit', ...
'Units','normal', ...
'BackgroundColor',[1 1 1], ...
'FontUnits','normal', ...
'FontSize',fnt, ...
'HorizontalAlignment','left', ...
'ListboxTop',0, ...
'Position',pos, ...
'String','', ...
'tooltipstring','Number of reference scans', ...
'Tag','ConditionLengthEdit');
x = x+w+0.01;
w = 0.12;
pos = [x y w h];
c_h3 = uicontrol('Parent',h0, ... % condition button
'Units','normal', ...
'Position',pos, ...
'FontUnits','normal', ...
'FontSize',fnt, ...
'ListboxTop',0, ...
'String','Add', ...
'Tag','ADD/DELButton');
x = x+w+0.02;
w = 0.04;
pos = [x y w h];
h1 = uicontrol('Parent',h0, ... % scroll bar
'Style', 'slider', ...
'Units','normal', ...
'Min',1, ...
'Max',20, ...
'Value',20, ...
'Position',pos, ...
'Callback','fmri_input_condition_ui(''MOVE_SLIDER'');', ...
'Tag','CondSlider');
x = 0.11;
y = 0.08;
w = 0.2;
pos = [x y w h];
h1 = uicontrol('Parent',h0, ... % DONE
'Units','normal', ...
'Callback','', ...
'FontUnits','normal', ...
'FontSize',fnt, ...
'ListboxTop',0, ...
'Position',pos, ...
'String','DONE', ...
'Callback','fmri_input_condition_ui(''DONE_BUTTON_PRESSED'');', ...
'Tag','DONEButton');
x = 0.67;
pos = [x y w h];
h1 = uicontrol('Parent',h0, ... % CANCEL
'Units','normal', ...
'Callback','', ...
'FontUnits','normal', ...
'FontSize',fnt, ...
'ListboxTop',0, ...
'Position',pos, ...
'String','CANCEL', ...
'Callback','fmri_input_condition_ui(''CANCEL_BUTTON_PRESSED'');', ...
'Tag','CANCELButton');
x = 0.01;
y = 0;
w = 1;
pos = [x y w h];
h1 = uicontrol('Parent',h0, ... % Message Line
'Style','text', ...
'Units','normal', ...
'BackgroundColor',[0.8 0.8 0.8], ...
'ForegroundColor',[0.8 0.0 0.0], ...
'FontUnits','normal', ...
'FontSize',fnt, ...
'HorizontalAlignment','left', ...
'Position',pos, ...
'String','', ...
'Tag','MessageLine');
cond1_hdls = [c_h1,c_h2,c_h3,c_h4,c_h5]; % save handles for condition#1
setappdata(h0,'Cond_hlist',cond1_hdls);
cond_template = copyobj(cond1_hdls,h0);
set(cond_template,'visible','off');
setappdata(h0,'ProtectedConditions',protected_conds);
setappdata(h0,'OldConditions',old_conditions);
setappdata(h0,'OldConditionBaseline',old_condition_baseline);
setappdata(h0,'CurrConditions',old_conditions);
setappdata(h0,'CurrConditionBaseline',old_condition_baseline);
setappdata(h0,'ConditionTemplate',cond_template);
cond_h = 0.06;
setappdata(h0,'ConditionHeight', cond_h);
lower_h = 0.01; % vert. space for Number of rows etc.
setappdata(h0,'lower_h',lower_h);
setappdata(h0,'TopConditionIdx',1);
setappdata(h0,'RemovedConditions',[]);
setappdata(h0,'ConditionMap',[1:length(old_conditions)]);
SetupConditionRows;
SetupSlider;
CreateAddRow;
DisplayConditions;
UpdateSlider;
return; % init
%----------------------------------------------------------------------------
function DoneButtonPressed()
curr_cond = getappdata(gcf,'CurrConditions');
num_cond = length(curr_cond);
empty_condition = 0;
for i=1:num_cond,
if isempty(curr_cond{i}),
empty_condition = 1;
break;
end;
end;
if (empty_condition)
msg = 'ERROR: All conditions must have name specified.';
set(findobj(gcf,'Tag','MessageLine'),'String',msg);
return;
else
for i=1:num_cond
for j=i+1:num_cond
if(strcmp(curr_cond{i}, curr_cond{j}))
msg = 'ERROR: No conditions should be duplicated.';
set(findobj(gcf,'Tag','MessageLine'),'String',msg);
return;
end
end;
end
AddCondition;
uiresume;
end;
return; % DoneButtonPressed
%----------------------------------------------------------------------------
function SetupConditionRows()
cond_hdls = getappdata(gcf,'Cond_hlist');
cond_h = getappdata(gcf,'ConditionHeight');
lower_h = getappdata(gcf,'lower_h');
bottom_pos = get(findobj(gcf,'Tag','DONEButton'),'Position');
top_pos = get(cond_hdls(1,2),'Position');
rows = floor(( top_pos(2) - bottom_pos(2) - lower_h ) / cond_h);
% A row of vertical positions, at which the 13 4-controls will be located.
v_pos = top_pos(2) - [0:rows-1]*cond_h;
cond_template = getappdata(gcf,'ConditionTemplate');
edit_cbf = 'fmri_input_condition_ui(''UPDATE_CONDITION'');';
edit_cbf4 = 'fmri_input_condition_ui(''UPDATE_OFFSET'');';
edit_cbf5 = 'fmri_input_condition_ui(''UPDATE_LENGTH'');';
delete_cbf = 'fmri_input_condition_ui(''DELETE_CONDITION'');';
nr = size(cond_hdls,1); % nr = 1 for the initial
if (rows < nr) % too many rows
for i=rows+1:nr,
delete(cond_hdls(i,:));
end;
cond_hdls = cond_hdls(1:rows,:);
else % add new rows to 'rows' amount
for i=nr+1:rows,
new_c_hdls = copyobj(cond_template,gcf);
cond_hdls = [cond_hdls; new_c_hdls'];
end;
end
v = 'off';
for i=1:rows
% take out the handle list created above, and use it in the following 'label,edit,delete'.
% those handles are valid, since they are all obtained from function copyobj() above.
new_c_hdls = cond_hdls(i,:);
% init label
pos = get(new_c_hdls(1),'Position'); pos(2) = v_pos(i)-0.01;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -