comparison m-toolbox/classes/@repogui/buildHLQPanel.m @ 0:f0afece42f48

Import.
author Daniele Nicolodi <nicolodi@science.unitn.it>
date Wed, 23 Nov 2011 19:22:13 +0100
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:f0afece42f48
1 % BUILDHLQPANEL build the High Level Queries panel.
2 %
3 % N Tateo 16-04-09
4 %
5 % $Id: buildHLQPanel.m,v 1.6 2011/04/08 08:56:25 hewitson Exp $
6 %
7 function buildHLQPanel(mainfig)
8
9 import utils.const.*
10 utils.helper.msg(msg.PROC1, 'building High Level Queries Panel');
11
12 htab = mainfig.panels(5);
13
14 Gproperties = mainfig.Gproperties;
15 pmarg = 0.025;
16
17 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
18 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
19 % List of HLQs:
20
21 hlq_name = 'ao.name = ''name'' AND tsdata.t0 > x';
22 hlq_desc = 'Select AOs with tsdata of given channel name and initial time successive to a given t0.';
23 hlq_str = ['select objmeta.obj_id from objmeta,ao,tsdata '...
24 'where objmeta.obj_id = ao.obj_id '...
25 'and ao.data_id = tsdata.id '...
26 'and objmeta.name=''var_1'' '...
27 'and tsdata.t0>=''var_2'''];
28 % Each HLQ has its proper list of parameters to set. Each parameter is
29 % defined inside a plist:
30 % - name: the name of the parameters to set.
31 % - type: edit, list, popup, time.
32 % - values: if list/popup, the possible values to choose among.
33 % - default: the default value associated to the parameter.
34 hlq_vars.v1 = plist( ...
35 'name', 'Name:', ...
36 'type', 'string', ...
37 'values', [], ...
38 'default', 'x1');
39 hlq_vars.v2 = plist( ...
40 'name', 'Initial time:', ...
41 'type', 'time', ...
42 'values', [], ...
43 'default', '1970-01-01 00:00:00.000');
44 hlq1 = {hlq_name , hlq_desc , hlq_str , hlq_vars};
45
46 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
47
48 hlq_name = 'ao.name = ''name'' AND x < tsdata.t0 < y';
49 hlq_desc = 'Select AOs with tsdata of given channel name and initial time comprised in a given interval';
50 hlq_str = ['select objmeta.obj_id from objmeta,ao,tsdata ' ...
51 'where objmeta.obj_id=ao.obj_id ' ...
52 'and ao.data_id=tsdata.id ' ...
53 'and objmeta.name = ''var_1'' ' ...
54 'and tsdata.t0 >= ''var_2'' ' ...
55 'and tsdata.t0+INTERVAL tsdata.nsecs SECOND <= ''var_3'' '];
56
57 hlq_vars.v1 = plist( ...
58 'name', 'Name:', ...
59 'type', 'string', ...
60 'values', [], ...
61 'default', 'x1');
62 hlq_vars.v2 = plist( ...
63 'name', 'Initial time:', ...
64 'type', 'time', ...
65 'values', [], ...
66 'default', '1970-01-01 00:00:00.000');
67 hlq_vars.v3 = plist( ...
68 'name', 'Final time:', ...
69 'type', 'time', ...
70 'values', [], ...
71 'default', '1970-01-02 00:00:00.000');
72 hlq2 = {hlq_name , hlq_desc , hlq_str , hlq_vars};
73
74 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
75
76 % hlq_name = 'Query name 3';
77 % hlq_desc = 'Query description';
78 % hlq_str = 'query_string';
79 % hlq_vars.v1 = plist( ...
80 % 'name', '', ...
81 % 'type', '', ...
82 % 'values', [], ...
83 % 'default', []);
84 % hlq_vars.v2 = plist( ...
85 % 'name', '', ...
86 % 'type', '', ...
87 % 'values', [], ...
88 % 'default', []);
89 % hlq3 = {hlq_name , hlq_desc , hlq_str , hlq_vars};
90
91
92 HLQ = [ hlq1 ; hlq2 ];
93
94 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
95 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
96
97 CommonHeight = 0.06;
98
99 % header
100 bw = 0.4;
101 bl = pmarg;
102 bh = CommonHeight;
103 bb = 1-2*pmarg-bh;
104 hlqText = uicontrol(htab, 'Style','text',...
105 'String', 'High Level Queries:',...
106 'BackgroundColor', 'w', ...
107 'Units', 'normalized', ...
108 'Userdata',1,...
109 'Fontsize', Gproperties.fontsize+2, ...
110 'Position',[bl bb bw bh]);
111
112 % list box
113 bh = 0.65;
114 bb = bb - bh - .03;
115 hlqListbox = uicontrol(htab,'Style','list',...
116 'String',HLQ(:,1),...
117 'Min',1,...
118 'Max',1,...
119 'BackgroundColor', 'w',...
120 'Fontsize', Gproperties.fontsize,...
121 'Units', 'normalized', ...
122 'Position', [bl bb bw bh],...
123 'TooltipString', 'These are the supported High Level Queries',...
124 'UserData', HLQ, ...
125 'Tag', 'RepoguiHLQList' , ...
126 'Callback' , @hlqListboxCbk );
127
128 % description field
129 bh = 0.2;
130 bb = bb - bh - .03;
131 bw = .3;
132 hlqDescbox = uicontrol(htab,'Style','text',...
133 'String',HLQ{1,2},...
134 'BackgroundColor', 'w',...
135 'Fontsize', Gproperties.fontsize,...
136 'Units', 'normalized', ...
137 'Position', [bl bb bw bh],...
138 'Tag', 'RepoguiHLQDesc');
139
140 % set button
141 bh = 0.1;
142 bw = 0.1;
143 bl = .4 + pmarg - bw;
144 pbh = uicontrol(htab,'Style','pushbutton',...
145 'String','Set',...
146 'Callback', {'repogui.cb_submit', mainfig}, ...
147 'Units', 'normalized', ...
148 'Fontsize', Gproperties.fontsize, ...
149 'Position',[bl bb+.1 bw bh], ...
150 'Tag','hlqSetButton', ...
151 'Callback' , @hlqSetButtonCbk );
152
153 % query button
154 uicontrol(htab, ...
155 'Style','pushbutton', ...
156 'String','Execute query', ...
157 'Units', 'normalized', ...
158 'Position',[.7 0 .29 .06], ...
159 'Tag', 'executeHLQbutton', ...
160 'Callback', @hlqExecQuery, ...
161 'Userdata', mainfig, ...
162 'enable', 'off');
163
164
165 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
166 % Dynamical part of the panel
167
168 bl = .45;
169 bb = .08;
170 bw = .54;
171 bh = .88;
172 dynpanel = uipanel(htab, ...
173 'BackGroundColor', 'w', ...
174 'Title' , 'Query settings:', ...
175 'Position', [bl bb bw bh], ...
176 'Tag', 'dynamicPanel', ...
177 'Visible', 'on');
178
179
180
181
182
183
184 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
185 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
186 end
187
188 function hlqListboxCbk(hObject,varargin)
189 % Callback associated to the HLQ listbox
190
191 currVal = get(hObject,'Value');
192 hlq = get(hObject,'UserData');
193 currHLQ = hlq(currVal,:);
194 set(findobj(gcf,'Tag','RepoguiHLQDesc'),'String',currHLQ{2})
195
196 end
197
198 function hlqSetButtonCbk(hObject,varargin)
199 % Callback associated to the set button
200
201 currVal = get(findobj(gcf,'Tag','RepoguiHLQList'),'Value');
202 hlq = get(findobj(gcf,'Tag','RepoguiHLQList'),'UserData');
203 hlq = hlq(currVal,:);
204 hlq_vars = hlq{4};
205 dynPanel = findobj(gcf,'Tag','dynamicPanel');
206 set(dynPanel,'Visible','on');
207 set(findobj(gcf,'Tag','executeHLQbutton'),'enable','on')
208 delete(findobj(gcf,'Parent',dynPanel))
209 drawDynamicPanel(dynPanel, hlq_vars,get(hObject,'FontSize'))
210
211 end
212
213 function drawDynamicPanel(dynPanel, hlq_vars, fontsize)
214 % To draw the dynamic panel, showing all query settings.
215
216 bl = .05;
217 bb = .95;
218 bh = .1;
219
220 var_numb = numel(fieldnames(hlq_vars));
221 for ii = 1:var_numb
222 curr_var = ['v' num2str(ii)];
223 curr_var = hlq_vars.(curr_var);
224 % this is the plist
225 var_name = find(curr_var,'name');
226 var_type = find(curr_var,'type');
227 var_val = find(curr_var,'default');
228
229 bb = bb - .12;
230 bw = .4;
231
232 switch var_type
233 case 'string'
234 uicontrol(dynPanel, ...
235 'Style','text', ...
236 'String', var_name, ...
237 'HorizontalAlignment', 'right', ...
238 'BackgroundColor', 'w', ...
239 'ForegroundColor', 'k', ...
240 'Fontsize', fontsize+1, ...
241 'Units', 'normalized', ...
242 'Position',[bl bb bw bh]);
243 uicontrol(dynPanel, ...
244 'Style','edit', ...
245 'String', var_val, ...
246 'HorizontalAlignment', 'center', ...
247 'BackgroundColor', 'w', ...
248 'ForegroundColor', 'k', ...
249 'Fontsize', fontsize+1, ...
250 'Units', 'normalized', ...
251 'Position',[bl+bw+.02 , bb+.038 , bw+.08 , .08],...
252 'Tag',['var_' num2str(ii)]);
253
254 case 'time'
255 bw = .3;
256 uicontrol(dynPanel, ...
257 'Style','text', ...
258 'String', var_name, ...
259 'HorizontalAlignment', 'right', ...
260 'BackgroundColor', 'w', ...
261 'ForegroundColor', 'k', ...
262 'Fontsize', fontsize+1, ...
263 'Units', 'normalized', ...
264 'Position',[bl-.03 bb bw-.05 bh]);
265 uicontrol(dynPanel, ...
266 'Style','edit', ...
267 'String', var_val, ...
268 'TooltipString', 'epoch in milliseconds [0] or time string [1970-01-01 00:00:00.000]', ...
269 'HorizontalAlignment', 'center', ...
270 'BackgroundColor', 'w', ...
271 'ForegroundColor', 'k', ...
272 'Fontsize', fontsize+1, ...
273 'Units', 'normalized', ...
274 'Position',[bl+bw-.06 , bb+.038 , bw+.18 , .08],...
275 'Tag',['var_' num2str(ii)], ...
276 'Callback', @checkTimeInput );
277 prefs = getappdata(0, 'LTPDApreferences');
278 timezoneList = utils.timetools.getTimezone;
279 currTimeZone = find(ismember(timezoneList,prefs.time.timezone));
280 uicontrol(dynPanel, ...
281 'Style','popupmenu', ...
282 'String', timezoneList, ...
283 'Value', currTimeZone, ...
284 'TooltipString', 'Timezone', ...
285 'HorizontalAlignment', 'center', ...
286 'BackgroundColor', 'w', ...
287 'ForegroundColor', 'k', ...
288 'Fontsize', fontsize+1, ...
289 'Units', 'normalized', ...
290 'Position',[bl+bw+.435 , bb+.038 , .2 , .08],...
291 'Tag',['timezone_' num2str(ii)], ...
292 'Callback' , 'set(findobj(gcf,''TooltipString'',''Timezone''),''Value'',get(gco,''Value''))' );
293
294
295 end
296
297 end
298
299 end
300
301 function checkTimeInput(hObject, varargin)
302
303 input = get(hObject,'String');
304 if ~isnan(str2double(input))
305 date_str = datestr(str2double(input),'yyyy-mm-dd HH:MM:SS.FFF');
306 set(hObject,'String',date_str);
307 end
308
309 end
310
311 function hlqExecQuery(hObject,varargin)
312 % Callback associated to the set button
313
314 mainfig = get(hObject,'Userdata');
315 HLQlist = findobj(gcf,'Tag','RepoguiHLQList');
316 HLQ = get(HLQlist,'Userdata');
317 currHLQ = get(HLQlist,'Value');
318 currHLQ = HLQ(currHLQ,:);
319 hlq_str = currHLQ{3};
320 hlq_vars = currHLQ{4};
321 var_numb = numel(fieldnames(hlq_vars));
322
323 for ii=1:var_numb
324 var_str = findobj(gcf,'Tag',['var_' num2str(ii)]);
325 var_str = get(var_str,'String');
326
327 var_type = find(hlq_vars.(['v' num2str(ii)]), 'type');
328 % switch var_type
329 % case 'time'
330 % % Convert the string in UTC timezone
331 % timezone = get(findobj(gcf,'Tag',['timezone_' num2str(currVal)]),'Value');
332 % timezoneList = utils.timetools.getTimezone;
333 % timezone = timezoneList(timezone);
334 % if ~strcmp(timezone,'UTC')
335 % var_str = char(setTimezone( time(plist('time_str',time_str,'timezone',timezone) ,'UTC'));
336 % end
337 % end
338
339 hlq_str = strrep(hlq_str, ['var_' num2str(ii)], var_str);
340 end
341
342 repogui.cb_executeQuery(hlq_str,mainfig)
343
344 end