Mercurial > hg > ltpda
comparison m-toolbox/classes/@repogui2/cb_importBtn.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 % CB_IMPORTBTN callback executed when the user clicks on the import button. | |
2 % | |
3 % M Hewitson | |
4 % | |
5 % $Id: cb_importBtn.m,v 1.2 2008/11/27 14:27:43 hewitson Exp $ | |
6 % | |
7 function cb_importBtn(varargin) | |
8 | |
9 | |
10 % Get connection | |
11 mainfig = varargin{end}; | |
12 conn = mainfig.connection; | |
13 if isempty(conn) || ~isa(conn, 'database') | |
14 errordlg('Please connect to a database first', 'No connection found'); | |
15 return | |
16 end | |
17 | |
18 % Get variable name specs | |
19 h = findobj(mainfig.handle, 'Tag', 'objPrefixTxt'); | |
20 prefix = get(h, 'String'); | |
21 if isempty(prefix) | |
22 prefix = 'obj'; | |
23 warning('! Using default prefix (obj)'); | |
24 end | |
25 h = findobj(mainfig.handle, 'Tag', 'appendObjTypeChk'); | |
26 appendObj = get(h, 'Value'); | |
27 h = findobj(mainfig.handle, 'Tag', 'retrieveBinaryChk'); | |
28 retrieveBinary = get(h, 'Value'); | |
29 | |
30 % Get IDs from text box | |
31 [ids, cids] = getIds(mainfig); | |
32 | |
33 | |
34 %--------------------------------------------------------------- | |
35 % Retrieve these ids | |
36 objs = []; | |
37 for j=1:length(ids) | |
38 disp(sprintf('+ retrieving object %d', ids(j))); | |
39 | |
40 % determine object type | |
41 tt = utils.mysql.getObjType(conn, ids(j)); | |
42 objname = sprintf('%s%03d', prefix, ids(j)); | |
43 if ~isempty(tt) && ~strcmp(tt, 'No Data') | |
44 if appendObj | |
45 objname = [objname '_' tt]; | |
46 end | |
47 else | |
48 error('!!! Object type is unknown. Does this object really exist?'); | |
49 end | |
50 | |
51 % Retrieve object | |
52 a = regexp(conn.URL, '//(\S+)/', 'tokens'); | |
53 db = regexp(conn.URL, '/', 'split'); | |
54 db = db{end}; | |
55 % add history | |
56 pl = plist('hostname', a{1}, 'database', db, 'ID', ids(j), 'conn', conn); | |
57 if retrieveBinary | |
58 pl.append('Binary', 'yes'); | |
59 disp(sprintf('*** performing binary retrieval.')); | |
60 end | |
61 obj = eval(sprintf('%s(pl);', tt)); | |
62 | |
63 assignin('base', objname, obj); | |
64 disp(sprintf('** Retrieve object %d to workspace [%s]', ids(j), objname)); | |
65 | |
66 if j==1 | |
67 objs = {obj}; | |
68 else | |
69 objs = [objs {obj}]; | |
70 end | |
71 end | |
72 | |
73 %--------------------------------------------------------------- | |
74 % Retrieve these Collections | |
75 for k=1:length(cids) | |
76 | |
77 % get Ids from Cid | |
78 ids = utils.mysql.getObjIds(conn, cids(k)); | |
79 if isempty(ids) | |
80 error('### This collection doesn''t seem to exist.'); | |
81 end | |
82 | |
83 for j=1:length(ids) | |
84 disp(sprintf('+ retrieving collection %d : %d', cids(k), ids(j))); | |
85 tt = utils.mysql.getObjType(conn, ids(j)); | |
86 if ismember(tt, utils.helper.ltpda_userclasses) | |
87 objname = sprintf('%sC%03d_%03d', prefix, cids(k), ids(j)); | |
88 if appendObj | |
89 objname = [objname '_' tt]; | |
90 end | |
91 % Retrieve object | |
92 ipbits = regexp(conn.URL, '([0-9]+)', 'match'); | |
93 ip = [ipbits{1} '.' ipbits{2} '.' ipbits{3} '.' ipbits{4}]; | |
94 db = regexp(conn.URL, '/', 'split'); | |
95 db = db{end}; | |
96 % add history | |
97 pl = plist('hostname', ip, 'database', db, 'ID', ids(j), 'conn', conn); | |
98 obj = eval(sprintf('%s(pl);', tt)); | |
99 | |
100 assignin('base', objname, obj); | |
101 disp(sprintf('** Retrieve object %d to workspace [%s]', ids(j), objname)); | |
102 if j==1 | |
103 objs = {obj}; | |
104 else | |
105 objs = [objs {obj}]; | |
106 end | |
107 else | |
108 warning('!!! Objects of type %s are no longer considered user objects and can not be retrieved.', tt); | |
109 end | |
110 end | |
111 end | |
112 | |
113 disp(sprintf('** Retrieved %d objects.', length(objs))); | |
114 | |
115 end | |
116 | |
117 | |
118 function [ids, cids] = getIds(mainfig) | |
119 | |
120 ids = []; | |
121 cids = []; | |
122 | |
123 th = findobj(mainfig.handle, 'Tag', 'retrieveIDsTxt'); | |
124 idStr = get(th, 'String'); | |
125 cs = cellstr(idStr); | |
126 | |
127 for j=1:length(cs) | |
128 disp('---------') | |
129 ls = cs{j}; | |
130 [s,r] = strtok(ls); | |
131 if ~isempty(s) | |
132 if s(1) == 'c' | |
133 s = s(2:end); | |
134 cids = [cids round(str2num(s))]; | |
135 else | |
136 ids = [ids round(str2num(s))]; | |
137 end | |
138 end | |
139 while ~isempty(r) | |
140 [s,r] = strtok(r); | |
141 if ~isempty(s) | |
142 if s(1) == 'c' | |
143 s = s(2:end); | |
144 cids = [cids round(str2num(s))]; | |
145 else | |
146 ids = [ids round(str2num(s))]; | |
147 end | |
148 end | |
149 end | |
150 end | |
151 | |
152 end |