0001 function cb_retrieveBtn(varargin)
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011 mainfig = findobj('Tag', 'LTPDARepomainfig');
0012 conn = getappdata(mainfig, 'connection');
0013 if isempty(conn) || ~isa(conn, 'database')
0014 errordlg('Please connect to a database first', 'No connection found');
0015 return
0016 end
0017
0018
0019 h = findobj('Tag', 'objPrefixTxt');
0020 prefix = get(h, 'String');
0021 if isempty(prefix)
0022 prefix = 'obj';
0023 warning('! Using default prefix (obj)');
0024 end
0025 h = findobj('Tag', 'appendObjTypeChk');
0026 appendObj = get(h, 'Value');
0027
0028
0029 [ids, cids] = getIds();
0030
0031
0032
0033
0034 objs = [];
0035 for j=1:length(ids)
0036 disp(sprintf('+ retrieving object %d', ids(j)));
0037
0038
0039 tt = mysql_getObjType(conn, ids(j));
0040 objname = sprintf('%s%03d', prefix, ids(j));
0041 if ~isempty(tt)
0042 if appendObj
0043 objname = [objname '_' tt];
0044 end
0045 else
0046 warning('!!! Object type is unknown');
0047 end
0048
0049
0050 ipbits = regexp(conn.URL, '([0-9]+)', 'match');
0051 ip = [ipbits{1} '.' ipbits{2} '.' ipbits{3} '.' ipbits{4}];
0052 db = regexp(conn.URL, '/', 'split');
0053 db = db{end};
0054
0055 pl = plist('hostname', ip, 'database', db, 'ID', ids(j), 'conn', conn);
0056 obj = eval(sprintf('%s(pl);', tt));
0057
0058 assignin('base', objname, obj);
0059 disp(sprintf('** Retrieve object %d to workspace [%s]', ids(j), objname));
0060
0061 if j==1
0062 objs = {obj};
0063 else
0064 objs = [objs {obj}];
0065 end
0066 end
0067
0068 disp(sprintf('** Retrieved %d objects.', length(ids)));
0069
0070
0071
0072 for k=1:length(cids)
0073
0074
0075 ids = mysql_getObjIds(conn, cids(k));
0076
0077 for j=1:length(ids)
0078 disp(sprintf('+ retrieving collection %d : %d', cids(k), ids(j)));
0079 tt = mysql_getObjType(conn, ids(j));
0080 objname = sprintf('%sC%03d_%03d', prefix, cids(k), ids(j));
0081 if appendObj
0082 objname = [objname '_' tt];
0083 end
0084
0085 ipbits = regexp(conn.URL, '([0-9]+)', 'match');
0086 ip = [ipbits{1} '.' ipbits{2} '.' ipbits{3} '.' ipbits{4}];
0087 db = regexp(conn.URL, '/', 'split');
0088 db = db{end};
0089
0090 pl = plist('hostname', ip, 'database', db, 'ID', ids(j), 'conn', conn);
0091 obj = eval(sprintf('%s(pl);', tt));
0092
0093 assignin('base', objname, obj);
0094 disp(sprintf('** Retrieve object %d to workspace [%s]', ids(j), objname));
0095 if j==1
0096 objs = {obj};
0097 else
0098 objs = [objs {obj}];
0099 end
0100 end
0101 end
0102
0103 disp(sprintf('** Retrieved %d objects.', length(ids)));
0104
0105
0106 end
0107
0108
0109 function [ids, cids] = getIds()
0110
0111 ids = [];
0112 cids = [];
0113
0114 th = findobj('Tag', 'retrieveIDsTxt');
0115 idStr = get(th, 'String');
0116 cs = cellstr(idStr);
0117
0118 for j=1:length(cs)
0119 disp('---------')
0120 ls = cs{j};
0121 [s,r] = strtok(ls);
0122 if ~isempty(s)
0123 if s(1) == 'c'
0124 s = s(2:end);
0125 cids = [cids round(str2num(s))];
0126 else
0127 ids = [ids round(str2num(s))];
0128 end
0129 end
0130 while ~isempty(r)
0131 [s,r] = strtok(r);
0132 if ~isempty(s)
0133 if s(1) == 'c'
0134 s = s(2:end);
0135 cids = [cids round(str2num(s))];
0136 else
0137 ids = [ids round(str2num(s))];
0138 end
0139 end
0140 end
0141 end
0142
0143 end