⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 struct_input_condition_ui.m

📁 绝对经典,老外制作的功能强大的matlab实现PLS_TOOBOX
💻 M
📖 第 1 页 / 共 2 页
字号:
function [new_condition, cond_filter, subj_files, reselect_subj] = ...
		struct_input_condition_ui(varargin)

   if nargin == 0
      old_conditions = [];
   end;

   if nargin == 0 | ~ischar(varargin{1})
      old_conditions = varargin{1};
      old_cond_filter = varargin{2};
      old_subj_files = varargin{3};

      init(old_conditions, old_cond_filter, old_subj_files);
      uiwait;				% wait for user finish

      new_condition = getappdata(gcf,'CurrConditions');
      cond_filter = getappdata(gcf,'cond_filter');
      subj_files = getappdata(gcf,'subj_files');
      reselect_subj = getappdata(gcf,'reselect_subj');

      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_CONDFILTER'),
      UpdateCondFilter;
   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');
      old_subj_files = getappdata(gcf,'old_subj_files');

      setappdata(gcf,'CurrConditions',old_conditions);
      setappdata(gcf,'subj_files',old_subj_files);
      setappdata(gcf,'reselect_subj',0);

      uiresume;
   elseif strcmp(action,'DONE_BUTTON_PRESSED'),
      DoneButtonPressed;
   end;

   return;


%----------------------------------------------------------------------------
function init(old_conditions, old_cond_filter, old_subj_files)

   save_setting_status = 'on';
   input_condition_pos = [];

   try
      load('pls_profile');
   catch
   end

   if ~isempty(input_condition_pos) & strcmp(save_setting_status,'on')

      pos = 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','struct_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.31;
   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','Conditions Name', ...
        'tooltipstring','Condition name cannot be duplicated', ...
   	'Tag','ConditionNameEditLbl');

   x = x+w+0.01;
   w = 0.31;

   pos = [x y w h];

   l_h4 = uicontrol('Parent',h0, ...            % condition filter 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 Filter', ...
        'tooltipstring','Condition filter must be able to distinguish conditions', ...
        'Tag','ConditionFilterEditLbl');

   x = 0.03;
   y = 0.83;
   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.31;

   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','', ...
	'tooltip','Condition name cannot be duplicated', ...
   	'Tag','ConditionNameEdit');

   x = x+w+0.01;
   w = 0.31;

   pos = [x y w h];

   c_h4 = uicontrol('Parent',h0, ...            % condition filter
        'Style','edit', ...
        'Units','normal', ...
        'BackgroundColor',[1 1 1], ...
   	'FontUnits','normal', ...
        'FontSize',fnt, ...
        'HorizontalAlignment','left', ...
        'ListboxTop',0, ...
        'Position',pos, ...
        'String','', ...
        'tooltipstring','Condition filter must be able to distinguish conditions', ...
        'Tag','ConditionFilterEdit');

   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','struct_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','struct_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','struct_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',0.5, ...
        'HorizontalAlignment','left', ...
        'Position',pos, ...
        'String','', ...
        'Tag','MessageLine');

   cond1_hdls = [c_h1,c_h2,c_h3,c_h4];         % save handles for condition#1
   setappdata(h0,'Cond_hlist',cond1_hdls);

   cond_template = copyobj(cond1_hdls,h0);
   set(cond_template,'visible','off');

   setappdata(h0,'OldConditions',old_conditions);
   setappdata(h0,'CurrConditions',old_conditions);
   setappdata(h0,'old_cond_filter',old_cond_filter);
   setappdata(h0,'cond_filter',old_cond_filter);
   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,'ConditionMap',[1:length(old_conditions)]);

   setappdata(h0,'old_subj_files', old_subj_files);
   setappdata(h0,'subj_files', old_subj_files);
   setappdata(h0,'reselect_subj',0);

   SetupConditionRows;
   SetupSlider;
   CreateAddRow;
   DisplayConditions;
   UpdateSlider;

   return;						% init


%----------------------------------------------------------------------------
function DoneButtonPressed()

   curr_cond = getappdata(gcf,'CurrConditions');
   cond_filter = getappdata(gcf,'cond_filter');
   num_cond = length(curr_cond);

   empty_condition = 0;
   empty_condfilter = 0;
   no_star = 0;
   no_img = 0;
   narrow_filter = 0;

   for i=1:num_cond,
      if  isempty(curr_cond{i}),
          empty_condition = 1;
          break;
      end;

      if  isempty(cond_filter{i}),
          empty_condfilter = 1;
          break;
      end;

      if isempty(findstr(cond_filter{i},'*'))
          no_star = 1;
          break;
      end;

      if isempty(findstr(cond_filter{i},'img')) & isempty(findstr(cond_filter{i},'nii'))
          no_img = 1;
          break;
      end;

      tmp = strrep(cond_filter{i},'*','');
      tmp = strrep(tmp,'.','');

      if isequal(tmp,'img') | isequal(tmp,'nii')
          narrow_filter = 1;
          break;
      end
   end;

   if (empty_condition | empty_condfilter)
      msg = 'ERROR: All conditions must have a name and a filter.';
      set(findobj(gcf,'Tag','MessageLine'),'String',msg);
      setappdata(gcf,'reselect_subj',0);
      return;
   elseif no_star
      msg = 'ERROR: Please include * in the filter.';
      set(findobj(gcf,'Tag','MessageLine'),'String',msg);
      setappdata(gcf,'reselect_subj',0);
      return;
   elseif no_img
      msg = 'ERROR: Please include either "img" or "nii" in condition filter.';
      set(findobj(gcf,'Tag','MessageLine'),'String',msg);
      setappdata(gcf,'reselect_subj',0);
      return;
   elseif narrow_filter
      msg = 'ERROR: Please narrow down condition filter to make condition distinguishable.';
      set(findobj(gcf,'Tag','MessageLine'),'String',msg);
      setappdata(gcf,'reselect_subj',0);
      return;
   else
      for i=1:num_cond
         for j=i+1:num_cond
            if(strcmp(curr_cond{i}, curr_cond{j}) | strcmp(cond_filter{i}, cond_filter{j}))
               msg = 'ERROR: Condition name or fileter can not be duplicated.';
               set(findobj(gcf,'Tag','MessageLine'),'String',msg);
               setappdata(gcf,'reselect_subj',0);
               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 = 'struct_input_condition_ui(''UPDATE_CONDITION'');';
   edit_cbf4 = 'struct_input_condition_ui(''UPDATE_CONDFILTER'');';
   delete_cbf = 'struct_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,

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -