source: MML/trunk/applications/loco/locoeditlist.m @ 4

Last change on this file since 4 was 4, checked in by zhangj, 10 years ago

Initial import--MML version from SOLEIL@2013

File size: 4.2 KB
Line 
1function newList = locoeditlist(List, ListName, CheckList)
2%LOCOEDITLIST - Device list editor
3% newList = locoeditlist(List)
4% newList = locoeditlist(List, InfoString)
5% newList = locoeditlist(List, InfoString, CheckList)
6%
7% Allows one to easily edit a element or device list
8% Inputs:  List       = list to edit
9%          InfoString = informational string {optional}
10%          CheckList  = 0 - don't check, else check
11%
12% Note:  Closing the window will result in no change to the list
13%
14% Writen by Greg Portmann
15
16if nargin < 1
17   error('At least 1 input is required.')
18end
19
20if nargin < 2
21   ListName = '';
22end
23
24if isstr(List)
25   error('First input cannot be a string');
26   return
27end
28
29if nargin < 3
30   CheckList = ones(max(size(List)),1);
31end
32if ~isstr(ListName)
33   CheckList = ListName;   
34   ListName = '';
35end
36
37if length(CheckList) ~= max(size(List))
38   error('List and CheckList must have the same max(size).');
39end
40
41
42if isunix
43   ScaleFactor = 8;
44   ButtonHeight  = 20;
45   Offset = 6;
46else
47   ScaleFactor = 6.5;
48   ButtonHeight  = 16;
49   Offset = 6;
50end
51
52
53if size(List,2) == 2
54   % Column vector
55   RowVectorFlag = 0;
56   ButtonWidth = round(ScaleFactor*length(sprintf('%s(%d), RingData(%d)', ListName, max(List(:,1)), max(List(:,1))))+Offset);
57elseif size(List,1) == 1
58   % Row vector
59   List = List';
60   RowVectorFlag = 1;
61   ButtonWidth = round(ScaleFactor*length(sprintf('%s(%d)', ListName, max(List)))+Offset);
62elseif size(List,2) == 1
63   % Column vector
64   RowVectorFlag = 0;
65   ButtonWidth = round(ScaleFactor*length(sprintf('%s(%d)', ListName, max(List)))+Offset);
66elseif size(List,2) > 2
67   % More than 2 columns is a problem
68   error('Input list must be 1 or 2 columns.')
69end
70if ButtonWidth < 75
71   ButtonWidth = 75;
72end
73
74% Add a buffer to ButtonWidth
75ButtonWidth = 1.15*ButtonWidth;
76
77n = size(List,1);
78col = ceil(n/40);
79row = ceil(n/col);
80
81
82FigWidth = col*ButtonWidth + (col-1)*3 + 6;
83FigHeight  = 3+(row+1)*ButtonHeight;
84
85
86% Change figure position
87set(0,'Units','pixels');
88p=get(0,'screensize');
89
90h0 = figure( ...
91   'Color',[0.8 0.8 0.8], ...
92   'HandleVisibility','On', ...
93   'Interruptible', 'on', ...
94   'MenuBar','none', ...
95   'Name',['Edit ', ListName, ' List'], ...
96   'NumberTitle','Off', ...
97   'Units','pixels', ...   
98   'Position',[30 p(4)-FigHeight-40 FigWidth FigHeight], ...
99   'Resize','on', ...
100   'Userdata', [], ...
101   'Tag','EditListFigure');
102
103k = 1;
104for j = 1:col
105   for i = 1:row
106     
107      if size(List,2) == 2
108         liststring = sprintf('%s(%d), RingData(%d)', ListName, List(k,1), List(k,2));
109         %liststring = sprintf('%s(%d,%d)', ListName, List(k,1), List(k,2));
110      else
111         liststring = sprintf('%s(%d)', ListName, List(k,1));
112      end
113     
114      if CheckList(k)
115         EnableFlag = 1;
116      else
117         EnableFlag = 0;
118      end
119     
120      h(k) = uicontrol('Parent',h0, ...
121         'Callback','', ...
122         'Enable','On', ...
123         'FontName', 'MS Sans Serif', ...
124         'FontSize', [8], ...
125         'FontUnits', 'points', ...
126         'Interruptible','Off', ...
127         'Position',[6+(j-1)*(ButtonWidth+3) 3+(row-i+1)*ButtonHeight ButtonWidth-0*6 ButtonHeight], ...
128         'Style','radio', ...
129         'String',liststring, ...
130         'Value',EnableFlag, ...
131         'Userdata',List(k,:), ...
132         'Tag','Radio1');
133      k = k + 1;
134      if k > n
135         break
136      end   
137   end
138end
139
140h1 = uicontrol(...
141   'Parent',h0, ...
142   'Callback',[...
143      'h = get(gco,''userdata'');', ...
144      'l=[];m=1;', ...
145      'for i = 1:length(h);', ...
146      '   if get(h(i),''Value'') == 1', ...
147      '      l(m,:) = get(h(i),''userdata'');', ...
148      '      m=m+1;', ...
149      '   end;', ...
150      'end;', ...
151      'set(gco,''userdata'',l);', ...
152      'set(gcf,''userdata'',1);' , ...
153      'drawnow;';], ...
154   'Enable','On', ...
155   'Interruptible','Off', ...
156   'Position',[3 3+0*ButtonHeight FigWidth-6 ButtonHeight], ...
157   'String','Change List', ...
158   'userdata', h, ...
159   'Tag','EditListClose');
160
161
162waitfor(gcf,'userdata');
163newList=get(gco,'userdata');
164
165if gcf == h0
166   close(h0);
167else
168   % If the figure is closed (not changed) return the old list
169   i = find(CheckList);
170   newList = List(i,:);
171end
172
173if RowVectorFlag
174   newList = newList';
175end
176
177
178
179
180
181
182
183
184
185
Note: See TracBrowser for help on using the repository browser.