-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathshowscan.m
134 lines (124 loc) · 4.77 KB
/
showscan.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
function showscan
% SHOWSCAN Called by specr to show the current scan data.
hFigSpecr = findall(0,'Tag','specr_Fig');
settings = getappdata(hFigSpecr,'settings');
% --- open GUI to display the selected scans
h = findall(0,'Tag','figSpecrShowScan');
if ~isempty(h)
figure(h);
else
p0 = get(hFigSpecr,'position'); % main figure position
p1(3) = 800; % p1 is the setting figure position
p1(4) = 400;
p1(1) = p0(1)+p0(3)/2-p1(3)/2;
p1(2) = p0(2)+p0(4)/2-p1(4)/2;
h = figure(...
'Units','pixels',...
'MenuBar','none',...
'Units','pixels',...
'Name','Spec Reader - Current Scan',...
'NumberTitle','off',...
'IntegerHandle','off',...
'Position',p1,...
'ResizeFcn',@resizefcn,...
'HandleVisibility','callback',...
'Tag','figSpecrShowScan',...
'WindowStyle','normal',...
'UserData',[]);
panelSize = [10 60 p1(3)-20 p1(4)-70];
hPanel1 = uipanel(...
'Parent',h,...
'BackgroundColor',get(h,'Color'),...
'Title','Select Scan',...
'Units','pixels',...
'Tag','figspecrshowscan_panel1',...
'Position',panelSize);
hPopupmenu1 = uicontrol(...
'Parent',hPanel1,...
'Style','popupmenu',...
'HorizontalAlignment','left',...
'BackgroundColor','w',...
'Position',[10 panelSize(4)-40 panelSize(3)-20 20],...
'String','No scan selected',...
'Value',1,...
'callback',@callback_popupmenu1,...
'Tag','figspecrshowscan_popupmenu1');
hEdit2 = uicontrol(...
'Parent',hPanel1,...
'Style','edit',...
'BackgroundColor','w',...
'Position',[10 10 panelSize(3)-20 panelSize(4)-60],...
'String',{'';'';'';'';'';'No scan selected.'},...
'Max',2,...
'Min',0,...
'HorizontalAlignment','center',...
'Tag','figspecrshowscan_edit2');
hPushbuttonRefresh = uicontrol(...
'Parent',h,...
'Style','pushbutton',...
'String','Refresh',...
'tag','figspecrshowscan_pushbuttonRefresh',...
'Position',[20 20 50 25],...
'callback','showscan;');
hPushbuttonClose = uicontrol(...
'Parent',h,...
'Style','pushbutton',...
'String','Close',...
'tag','figspecrshowscan_pushbuttonClose',...
'Position',[p1(3)/2+10 20 50 25],...
'Callback','delete(gcf);');
end
file = settings.file;
scan = settings.scan;
if isempty(file) | isempty(scan) | ~isfield(scan,'selection') | isempty(scan.selection{1})
return;
end
% --- load the scan text
selection = scan.selectionIndex;
scanHead = cell(length(selection),1);
scanText = cell(length(selection),1);
[fid,message] = fopen(file);
for iSelection = 1:length(selection)
fseek(fid,scan.fidPos(selection(iSelection)),'bof');
scanHead{iSelection} = fgetl(fid);
scanText{iSelection} = scanHead{iSelection};
if selection(iSelection) < length(scan.fidPos) % if not the last scan
while ftell(fid) < scan.fidPos(selection(iSelection)+1)
scanText{iSelection} = [scanText{iSelection};{fgetl(fid)}];
end
else % if the last scan
while ~feof(fid)
scanText{iSelection} = [scanText{iSelection};{fgetl(fid)}];
end
end
end
setappdata(h,'scanText',scanText);
hPopupmenu1 = findobj(h,'Tag','figspecrshowscan_popupmenu1');
hEdit2 = findobj(h,'Tag','figspecrshowscan_edit2');
set(hPopupmenu1,'String',scanHead,'value',1);
set(hEdit2,'String',scanText{1},'HorizontalAlignment','left');
%================================================================
% --- callback of popupmenu1
%================================================================
function callback_popupmenu1(hObject,eventdata)
h = findall(0,'Tag','figSpecrShowScan');
hPopupmenu1 = findobj(h,'Tag','figspecrshowscan_popupmenu1');
hEdit2 = findobj(h,'Tag','figspecrshowscan_edit2');
scanText = getappdata(h,'scanText');
set(hEdit2,'String',scanText{get(hPopupmenu1,'value')});
return;
%=================================================================
% --- figure resizefcn function
%=================================================================
function resizefcn(hObject,eventdata)
h = gcbo;
p1 = get(h,'Position');
panelSize = [10 60 p1(3)-20 p1(4)-70];
try
set(findobj(h,'tag','figspecrshowscan_panel1'),'position',panelSize);
set(findobj(h,'tag','figspecrshowscan_popupmenu1'),'position',[10 panelSize(4)-40 panelSize(3)-20 20]);
set(findobj(h,'tag','figspecrshowscan_edit2'),'position',[10 10 panelSize(3)-20 panelSize(4)-60]);
set(findobj(h,'tag','figspecrshowscan_pushbuttonRefresh'),'position',[p1(3)-20-160 20 80 25]);
set(findobj(h,'tag','figspecrshowscan_pushbuttonClose'),'position',[p1(3)-10-80 20 80 25]);
catch
end