-
Notifications
You must be signed in to change notification settings - Fork 0
/
dataselection.m
214 lines (189 loc) · 7.47 KB
/
dataselection.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
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
function dataselection(app)
fig = uifigure('Position',[100 100 250 400]);
% Create Numeric Edit Field
ef_x = uieditfield(fig,'numeric',...
'Editable',false,...
'Position',[125 360 100 22]);
ef_y = uieditfield(fig,'numeric',...
'Editable',false,...
'Position',[125 320 100 22]);
ef_z = uieditfield(fig,'numeric',...
'Editable',false,...
'Position',[125 280 100 22]);
ef_PFS = uieditfield(fig,'numeric',...
'Editable',false,...
'Position',[125 240 100 22]);
% Create List Box
lbox = uilistbox(fig,...
'Items', {},...
'ItemsData', [],...
'Position',[10 80 100 300],...
'ValueChangedFcn', @(src,event) selectionChanged(src));
% Create a push button
btn = uibutton(fig,'push',...
'Text','Move',...
'Enable',false,...
'Position',[125, 200, 100, 22],...
'ButtonPushedFcn', @(btn,event) MoveStage(btn,event,lbox));
% Create a push button
btn2 = uibutton(fig,'push',...
'Text','Replace',...
'Enable',false,...
'Position',[125, 170, 100, 22],...
'ButtonPushedFcn', @(btn2,event) UpdateList(btn2,event,lbox));
% Create a push button
btn3 = uibutton(fig,'push',...
'Text','Save',...
'Enable',false,...
'Position',[125, 140, 100, 22],...
'ButtonPushedFcn', @(btn3,event) SaveList(btn3,event,lbox));
% Create a push button
btn4 = uibutton(fig,'push',...
'Text','Load',...
'Enable',true,...
'Position',[125, 110, 100, 22],...
'ButtonPushedFcn', @(btn4,event) LoadList(btn4,event,lbox));
% Create a push button
btn5 = uibutton(fig,'push',...
'Text','Nis2Mat',...
'Enable',true,...
'Position',[125, 80, 100, 22],...
'ButtonPushedFcn', @(btn5,event) Nis2Mat(btn5,event,lbox));
% Create a push button
btn6 = uibutton(fig,'push',...
'Text','Mat2Nis',...
'Enable',true,...
'Position',[125, 50, 100, 22],...
'ButtonPushedFcn', @(btn6,event) Mat2Nis(btn6,event,lbox));
%
if size(app.listing_pos,1)>0
btn.Enable = true;
btn2.Enable = true;
btn3.Enable = true;
for i = 1:size(app.listing_pos,1)
Items{i} = strcat('XY',num2str(i));
ItemsData(i) = i;
end
lbox.Items = Items;
lbox.ItemsData = ItemsData;
end
% ValueChangedFcn callback
function selectionChanged(src,event)
% Display list box data in edit field
idx = src.Value;
ef_x.Value = app.listing_pos(idx,1);
ef_y.Value = app.listing_pos(idx,2);
ef_z.Value = app.listing_pos(idx,3);
ef_PFS.Value = app.listing_pos(idx,4);
end
% Create the function for the ButtonPushedFcn callback
function MoveStage(btn,event,lbox)
if (app.StageConnectButton.Value==1)
idx = lbox.Value;
app.listing_pos(idx,:);
% move stage
app.mmc.setXYPosition(app.listing_pos(idx,1),app.listing_pos(idx,2));
if strcmp(app.mmc.getProperty('TIPFSStatus','State'),'Off')
app.mmc.setPosition(app.listing_pos(idx,3));
else
app.mmc.setProperty('TIPFSOffset','Position',num2str(app.listing_pos(idx,4)));
end
pause(0.2) % to make sure the stage is arrived at defined position
History = flip(app.HistoryTextArea.Value,1);
nHistorys = size(History,1);
History{nHistorys+1,1} = char(strcat(string(datetime(now,'ConvertFrom','datenum')),' -- Move stage to XY', num2str(idx),'.'));
app.HistoryTextArea.Value = flip(History,1);
end
end
% Create the function for the ButtonPushedFcn callback
function UpdateList(btn2,event,lbox)
if (app.StageConnectButton.Value==1)
idx = lbox.Value;
x = app.mmc.getXPosition();
y = app.mmc.getYPosition();
z = app.mmc.getPosition();
pfs_z = str2double(app.mmc.getProperty('TIPFSOffset','Position'));
app.listing_pos(idx,:) = [x,y,z,pfs_z];
ef_x.Value = app.listing_pos(idx,1);
ef_y.Value = app.listing_pos(idx,2);
ef_z.Value = app.listing_pos(idx,3);
ef_PFS.Value = app.listing_pos(idx,4);
History = flip(app.HistoryTextArea.Value,1);
nHistorys = size(History,1);
History{nHistorys+1,1} = char(strcat(string(datetime(now,'ConvertFrom','datenum')),' -- Renew a new coordinate of XY', num2str(idx),'.'));
app.HistoryTextArea.Value = flip(History,1);
end
end
% Create the function for the ButtonPushedFcn callback
function SaveList(btn3,event,lbox)
selpath = uigetdir();
if selpath~=0
outputfile = strcat(selpath,'\',string(datetime(floor(now),'ConvertFrom','datenum')),'_listing_pos.mat');%[selpath,'\listing_pos.mat'];
Pos = app.listing_pos;
save(outputfile,'Pos');
History = flip(app.HistoryTextArea.Value,1);
nHistorys = size(History,1);
History{nHistorys+1,1} = char(strcat(string(datetime(now,'ConvertFrom','datenum')),' -- Save positions.'));
app.HistoryTextArea.Value = flip(History,1);
end
end
% Create the function for the ButtonPushedFcn callback
function LoadList(btn4,event,lbox)
[file,path] = uigetfile('*.mat');
if path~=0
S = load([path,file]);
app.listing_pos = S.Pos0;
for i = 1:size(app.listing_pos,1)
Items{i} = strcat('XY',num2str(i));
ItemsData(i) = i;
end
lbox.Items = Items;
lbox.ItemsData = ItemsData;
btn.Enable = true;
btn2.Enable = true;
btn3.Enable = true;
History = flip(app.HistoryTextArea.Value,1);
nHistorys = size(History,1);
History{nHistorys+1,1} = char(strcat(string(datetime(now,'ConvertFrom','datenum')),' -- Load positions.'));
app.HistoryTextArea.Value = flip(History,1);
end
end
% Convert nis position to matlab array
function Nis2Mat(btn5,event,lbox)
% [file,path] = uigetfile('*.xml');
% if path~=0
% inputfile=[path,file];
% S = readstruct(inputfile);
% SS = S.no_name;
% fields = fieldnames(SS);
%
% listing_Pos = [];
% for nPt = 4:length(fieldnames(S.no_name))
% SSS = getfield(SS,fields{nPt});
% x = SSS.dXPosition.valueAttribute;
% y = SSS.dYPosition.valueAttribute;
% PFS = SSS.dPFSOffset.valueAttribute/40;
% listing_Pos = [listing_Pos;x,y,PFS];
% end
%
% app.listing_pos=listing_Pos;
%
% History = flip(app.HistoryTextArea.Value,1);
% nHistorys = size(History,1);
% History{nHistorys+1,1} = char(strcat(string(datetime(now,'ConvertFrom','datenum')),' -- Load positions from NIS to MATLAB.'));
% app.HistoryTextArea.Value = flip(History,1);
% end
end
% Convert nis position to matlab array
function Mat2Nis(btn6,event,lbox)
% inputfile = 'template_TiE.xml';
%
%
%
%
% History = flip(app.HistoryTextArea.Value,1);
% nHistorys = size(History,1);
% History{nHistorys+1,1} = char(strcat(string(datetime(now,'ConvertFrom','datenum')),' -- Export positions from MATLAB to NIS.'));
% app.HistoryTextArea.Value = flip(History,1);
end
end