source: plugins/copy_data_to_workspace.m @ 74

Last change on this file since 74 was 45, checked in by tjniskan, 11 years ago
  • Changed a small thing in license notices

M an2_export_gui.m
M an2_cellsprintf.m
M an2_getfilefilter.m
M an2_calc_wait.m
M an2_smiswrite.m
M misclib/spectrsum.m
M misclib/shiftind.m
M misclib/nifti4dto3d.m
M misclib/nifti3dto4d.m
M misclib/dcm_info.m
M misclib/addicon.m
M misclib/makelcmraw.m
M an2_check_file_exist.m
M an2_iseven.m
M an2_cellwrite.m
M an2_wbar.m
M an2_rot3d.m
M an2_readfdf.m
M an2_revision.m
M an2_viewprocpar.m
M an2_checkcthdr.m
M an2_readprocpar.m
M an2_fitmaps.m
M an2_read_nifti.m
M an2_data_read.m
M an2_smisread.m
M an2_resviewer.m
M an2_maptool.m
M aedes.m
M an2_helpabout.m
M an2_res2table.m
M an2_copy_roi.m
M plugins/save_roi_as_mask.m
M plugins/write_difference_images.m
M plugins/plot_profile.m
M plugins/calculate_t2_map.m
M plugins/calculate_t1r_map.m
M plugins/view_kspace.m
M plugins/copy_data_to_workspace.m
M plugins/take_snapshot.m
M an2_inputdlg.m
M an2_roi_copy_gui.m
M an2_readctdata.m
M an2_readfid.m
M an2_readfidprefs.m
M an2_readtab.m
M an2_check_updates.m
M an2_killfigs.m
M an2_roi_stats.m
M an2_saveres.m
M an2_rotateflip.m
M an2_juigetfiles.m
M an2_gui_defaults.m
M an2_editstack.m
M an2_errordump.m
M an2_update.m
M an2_write_nifti.m

File size: 8.1 KB
Line 
1function copy_data_to_workspace(DATA,ROI,AddInfo)
2% COPY_DATA_TO_WORKSPACE - Copy (assign) DATA and ROI structures to workspace
3%   (this is an Aedes plugin)
4%
5% Synopsis:
6%
7% Description:
8%
9% Examples:
10%
11% See also:
12%
13
14% This function is a part of Aedes - A graphical tool for analyzing
15% medical images
16%
17% Copyright (C) 2006 Juha-Pekka Niskanen <Juha-Pekka.Niskanen@uku.fi>
18%
19% Department of Physics, Department of Neurobiology
20% University of Kuopio, FINLAND
21%
22% This program may be used under the terms of the GNU General Public
23% License version 2.0 as published by the Free Software Foundation
24% and appearing in the file LICENSE.TXT included in the packaging of
25% this program.
26%
27% This program is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
28% WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
29
30
31%% Init figure size
32FigColor=get(0,'DefaultUicontrolBackgroundcolor');
33fig_h = 160;
34fig_w = 245;
35scrsz = get(0,'screensize');
36
37fh = figure('units','pixel',...
38            'position',...
39            [scrsz(3)/2-fig_w/2 scrsz(4)/2-fig_h/2 ...
40             fig_w fig_h],...
41            'Name','Copy to workspace',...
42            'numbertitle','off',...
43            'Toolbar','none',...
44            'Color',FigColor,...%[236 233 216]./255,...
45            'Menubar','none',...
46            'DoubleBuffer','on',...
47            'DockControls','off',...
48            'renderer','painters',...
49            'resize','off',...
50            'Handlevisibility','off');
51
52uipanel_h = uipanel('parent',fh,...
53                    'units','pixel',...
54                    'position',[10 40 fig_w-20 fig_h-50]);
55
56data_tx = uicontrol('parent',uipanel_h,...
57                    'units','pixel',...
58                    'position',[10 80 205 18],...
59                    'style','text',...
60                    'backgroundcolor',FigColor,...%[236 233 216]./255,...
61                    'horizontalalign','left',...
62                    'string','Data structure variable name');
63tmp=get(data_tx,'position');
64data_edit = uicontrol('parent',uipanel_h,...
65                      'units','pixel',...
66                      'position',[tmp(1) tmp(2)-tmp(4) 205 20],...
67                      'style','edit',...
68                      'backgroundcolor','w',...
69                      'horizontalalign','left',...
70                                          'tag','data_edit',...
71                      'string','DATA',...
72                      'userdata','DATA',...
73                                          'keypress',@l_VariableNameKeyPress);
74
75tmp=get(data_edit,'position');
76roi_tx = uicontrol('parent',uipanel_h,...
77                   'units','pixel',...
78                   'position',[tmp(1) tmp(2)-tmp(4)-10 205 18],...
79                   'style','text',...
80                   'backgroundcolor',FigColor,...%[236 233 216]./255,...
81                   'horizontalalign','left',...
82                   'string','ROI structure variable name');
83tmp=get(roi_tx,'position');
84roi_edit = uicontrol('parent',uipanel_h,...
85                     'units','pixel',...
86                     'position',[tmp(1) tmp(2)-tmp(4) tmp(3:4)],...
87                     'style','edit',...
88                     'backgroundcolor','w',...
89                     'horizontalalign','left',...
90                                         'tag','roi_edit',...
91                     'string','ROI',...
92                     'userdata','ROI',...
93                     'keypress',@l_VariableNameKeyPress);
94
95%% OK and Cancel buttons
96tmp=get(uipanel_h,'position');
97ok_btn = uicontrol('parent',fh,...
98                   'units','pixel',...
99                   'position',[tmp(1)+79 tmp(2)-35 70 30],...
100                   'style','pushbutton',...
101                   'string','OK',...
102                   'callback',@l_AssignVariables);
103tmp=get(ok_btn,'position');
104cancel_btn = uicontrol('parent',fh,...
105                       'units','pixel',...
106                       'position',[tmp(1)+tmp(3)+5 tmp(2:4)],...
107                       'style','pushbutton',...
108                       'string','Cancel',...
109                       'callback','close(gcbf)');
110dummy_btn = uicontrol('parent',fh,...
111                      'units','pixel',...
112                      'position',[-30 0 1 1],...
113                      'style','pushbutton',...
114                                          'tag','dummy_btn',...
115                      'string','',...
116                      'callback','');
117%set([data_edit,roi_edit],'userdata',dummy_btn)
118
119
120%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
121% Variable name checking
122%
123% NOTE: This doesn't work properly in newer Matlab versions...
124%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
125function l_VariableNameKeyPress(h,evd)
126
127% This function doesn't work in new Matlab versions so do nothing...
128return
129 
130% Switch focus between uicontrols (a Matlab bug workaround)
131uicontrol(dummy_btn)
132uicontrol(h)
133
134% Call drawnow twice to refresh the editbox (yet another Matlab bug
135% workaround)
136drawnow
137drawnow
138
139% Query the editbox string value
140str=get(h,'string')
141
142%set(h,'value',length(str))
143%drawnow
144%drawnow
145if isempty(str)
146  return
147end
148
149%% Check first letter
150if ~any('abcdefghijklmnopqrstuvwxyz'==lower(str(1)))
151  warndlg('The first character in the variable name has to be a letter.',...
152          'Invalid character entered.','modal')
153  set(h,'string',get(h,'userdata'))
154  uicontrol(dummy_btn)
155  uicontrol(h)
156  drawnow
157  drawnow
158  return
159end
160
161%% Check other letters
162if length(str)>1
163  ind=ismember(lower(str(2:end)), ...
164               '1234567890abcdefghijklmnopqrstuvwxyz_');
165  if ~all(ind)
166    warndlg({'Variable name can only contain the following characters:',...
167             '','1234567890abcdefghijklmnopqrstuvwxyz_'},...
168            'Invalid character entered.','modal')
169    set(h,'string',get(h,'userdata'))
170    uicontrol(dummy_btn)
171    uicontrol(h)
172    drawnow
173    drawnow
174    return
175  end
176end
177
178set(h,'userdata',str)
179
180end % function l_VariableNameKeyPress(h,
181
182%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
183% Assign variables
184%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
185function l_AssignVariables(h,evd)
186 
187%% Check current workspace variable names
188var_names = evalin('base','who');
189
190%% Get DATA structure name
191data_name = get(data_edit,'string');
192
193%% Get ROI structure name
194roi_name = get(roi_edit,'string');
195
196%% Check that the variable names are not empty
197if isempty(data_name)
198  hh=warndlg('Data variable name is empty!',...
199             'Empty variable name','modal');
200  return
201end
202if isempty(roi_name)
203  hh=warndlg('Roi variable name is empty!',...
204             'Empty variable name','modal');
205  return
206end
207
208%% Check variable names for invalid characters
209str = {data_name,roi_name};
210for ii=1:2
211  %% Check first letter
212  if ~any('abcdefghijklmnopqrstuvwxyz'==lower(str{ii}(1)))
213        h_warn=warndlg('The first character in the variable name has to be a letter.',...
214          'Invalid character entered.','modal');
215        uiwait(h_warn)
216        uicontrol(dummy_btn)
217        if ii==1
218          uicontrol(data_edit)
219        else
220          uicontrol(roi_edit)
221        end
222        drawnow
223        drawnow
224        return
225  end
226 
227  %% Check other letters
228  if length(str{ii})>1
229        ind=ismember(lower(str{ii}(2:end)), ...
230          '1234567890abcdefghijklmnopqrstuvwxyz_');
231        if ~all(ind)
232          warndlg({'Variable name can only contain the following characters:',...
233                '','1234567890abcdefghijklmnopqrstuvwxyz_'},...
234                'Invalid character entered.','modal')
235          uicontrol(dummy_btn)
236          if ii==1
237                uicontrol(data_edit)
238          else
239                uicontrol(roi_edit)
240          end
241          drawnow
242          drawnow
243          return
244        end
245  end
246end
247
248
249%% Check if variables are being overwritten
250if any(strcmpi(data_name,var_names))
251  resp=questdlg({['A variable named "',data_name,...
252                  '" already exists in the current workspace.'],'',...
253                'Overwrite variable?'},...
254                'Overwrite workspace variable?','Yes','No','No');
255  if strcmpi(resp,'no')
256    return
257  end
258end
259if any(strcmpi(roi_name,var_names))
260  resp=questdlg({['A variable named "',roi_name,...
261                  '" already exists in the current workspace.'],'',...
262                 'Overwrite variable?'},...
263                'Overwrite workspace variable?','Yes','No','No');
264  if strcmpi(resp,'no')
265    return
266  end
267end
268
269%% Assign variables into workspace
270if length(DATA)==1
271  assignin('base',data_name,DATA{1});
272else
273  assignin('base',data_name,DATA);
274end
275assignin('base',roi_name,ROI);
276
277%% Close window
278delete(fh)
279
280end % function l_AssignVariables(h,
281
282end
Note: See TracBrowser for help on using the repository browser.

Powered by Trac 1.0.9.Copyright © Juha-Pekka Niskanen 2008