Newer
Older
end
grid.cells(i).set_pb(obj.fig,pb_pos)
set(grid.cells(i).grid_pb,'UserData',obj);
elseif(grid.cells(i).pb_flag == 1 && obj.edit ~= 1)
if (ishghandle(grid.cells(i).grid_pb))
set(grid.cells(i).grid_pb,'Visible','off')
end
end
delete_pb_pos = [];
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
% detemine if we want to draw the new cell buttons,
% which are located at the botton of the set of cells.
if (i == size(grid.cells,2) && obj.edit == 1)
new_pb_pos = pos;
new_pb_pos(4) = grid.cells(i).condition_text_height/2;
new_pb_pos(3) = pos(3)/2;
new_pb_pos(2) = pos(2) - new_pb_pos(4);
if (ishghandle(grid.new_cell_pb))
set(grid.new_cell_pb,'Visible','on');
end
grid.set_pb(obj.fig,new_pb_pos);
set(grid.new_cell_pb,'userdata',obj);
delete_pb_pos = new_pb_pos;
delete_pb_pos(1) = new_pb_pos(1) + new_pb_pos(3);
if (ishghandle(grid.delete_cell_pb))
set(grid.delete_cell_pb,'Visible','on');
end
grid.set_delete_pb(obj.fig,delete_pb_pos);
set(grid.delete_cell_pb,'userdata',obj);
elseif (i == size(grid.cells,2) && obj.edit ~= 1)
if (ishghandle(grid.new_cell_pb))
set(grid.new_cell_pb,'Visible','off');
end
if (ishghandle(grid.delete_cell_pb))
set(grid.delete_cell_pb,'Visible','off');
end
end
% recursively draw the subgrid of the cell if it
% exists.
obj.draw_grid2(grid.cells(i).subgrid,load);
end
end
end
%% reset_wh
% function will call the set_widths and set_heights methods on
% the left grid in the table. The height and width values are
% used to draw the grid.
% inputs:
% obj:GUI - current GUI object
% outputs;
% none
function [] = reset_wh(obj)
width = obj.Grid2.max_width(1);
obj.Grid2.set_widths(width);
obj.Grid2.set_heights(obj.edit);
end
%% draw_grid1
% Draws the grid on the top onto the figure. the current
% assumption is that the top grid does not have any subgrids,
% inputs:
% obj:GUI - current GUI object
% grid:Grid - grid to be drawn, should be grid on top.
% load:boolean - 0 if grid is being refreshed, 1 if grid is being
% loaded for the firs time.
% outputs;
% none
function [] = draw_grid1(obj,grid,load)
% assumption grid 1 has no subgrids
pos = [];
for i=1:size(grid.cells,2)
% if we are in edit mode we need to shift over the cells to
% accomidate for the new grid buttons in the left grid.
if(obj.edit == 1)
pb_space = grid.cells(i).grid_push_width;
else
pb_space = 0;
end
figpos = get(obj.fig,'position');
% check if grid2 is empty, currently grid 2 will never be
% empty, may change in future though.
if (isempty(obj.Grid2))
pos = [grid.cells(i).condition_text_x grid.cells(i).condition_text_y grid.cells(i).condition_text_width grid.cells(i).condition_text_height];
else
pos = [grid.cells(i).condition_text_x+grid.cells(i).condition_text_width*obj.Grid2.max_width(1) figpos(4)-obj.header_height-grid.cells(i).condition_text_y-grid.cells(i).condition_text_height grid.cells(i).condition_text_width grid.cells(i).condition_text_height];
end
% set the x coordinate of the cell
pos(1) = pos(1) + (i-1)*grid.cells(i).condition_text_width + grid.cells(i).condition_text_offset + pb_space;
% if the edit box does not exist create it, if it does
% adjust it's position.
if (isempty(grid.cells(i).cond) || load == 1)
grid.cells(i).cond = obj.create_std_text(obj.fig,pos);
if (load == 1)
set(grid.cells(i).cond,'String',grid.cells(i).cond_text);
end
else
grid.cells(i).set_pos(pos);
end
end
% if we are in edit mode, draw the new and delete buttons at
% the right of the last cell
if( obj.edit == 1)
pos(1) = pos(1) + pos(3);
pos(2) = pos(2) + 20;
pos(4) = 20;
pos(3) = 60;
grid.set_pb(obj.fig,pos);
pos(2) = pos(2) - 20;
grid.set_delete_pb(obj.fig,pos);
set(grid.delete_cell_pb,'userdata',obj);
set(grid.new_cell_pb,'userdata',obj);
else
delete(grid.new_cell_pb)
grid.new_cell_pb = [];
delete(grid.delete_cell_pb)
grid.delete_cell_pb = [];
end
if obj.edit ==1 || load == 1
fig_pos = get(obj.fig,'position');
fig_pos(3) = pos(1)+pos(3);
set(obj.fig,'position',fig_pos);
elseif (pos(1) + pos(3)<obj.fig_width)
fig_pos(3) = obj.fig_width;
set(obj.fig,'position',fig_pos);
elseif (pos(1) + pos(3)<fig_pos(3) && pos(1) +pos(3) >obj.fig_width)
fig_pos(3) = pos(1)+pos(3);
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
set(obj.fig,'position',fig_pos);
end
end
end
%% draw_grid0
% function will draw the output grid onto the figure
% inputs:
% obj:GUI - current GUI object
% grid:Grid - grid to be drawn, should be grid on left.
% load:boolean - 0 if grid is being refreshed, 1 if grid is being
% loaded for the firs time.
% outputs;
% none
function [] = draw_grid0(obj,grid,load)
% ensure that the results grid is up to date.
grid.refresh();
for i=1:size(grid.Cells,2)
% get the x coordinate from the associated top grid cell,
% get the y coordinate from the associated right grid cell.
pos1 = grid.Cells(i).Cell1.get_pos;
pos2 = grid.Cells(i).Cell2.get_pos;
pos = [0 0 0 0];
pos(1) = pos1(1);
pos(2) = pos2(2);
pos(3) = pos1(3);
pos(4) = pos2(4);
if isempty(grid.Cells(i).result) || load == 1
grid.Cells(i).result = obj.create_std_text(obj.fig,pos);
% if we are loading the cell, try to restore the text
% that was saved using save_results.
if load == 1
set(grid.Cells(i).result,'String',grid.Cells(i).result_text);
end
else
set(grid.Cells(i).result,'position',pos);
end
end
end
%% draw_allgrids
% function will call the draw methods for each of the 3 grids.
% inputs:
% obj:GUI - current GUI object
% load:boolean - 0 if grid is being refreshed, 1 if grid is being
% loaded for the firs time.
% outputs;
% none
function [] = draw_allgrids(obj,load)
obj.draw_grid2(obj.Grid2,load);
obj.draw_grid1(obj.Grid1,load);
obj.draw_grid0(obj.Grid0,load);
end
%% evaluate_counter
function [] = evaluate_counter(obj,counter)
problem = obj.evaluate_counter_grid(obj.Grid2, counter);
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
if(~problem)
obj.evaluate_counter_grid(obj.Grid1, counter)
end
end
%% evaluate_counter_grid
% counter has form 'x=0\ny=2'
function problem = evaluate_counter_grid(obj,grid,counter)
% split the list of inputs to get inputs seperatly
inputs = get(obj.function_inputs_control,'String');
inputs = regexp(inputs,',','split');
check_string = [];
% keep track of the number of condtitions that evaulate to true
true_conds = 0;
sub_problem = 0;
problem = 0;
empty_cell = 0;
% initialize inputs to zero
% functions are assumed to be total, so 0 is just for
% convienence
for i=1:size(inputs,2)
% set to zero
%need to parse the types out of the inputs
inputi = regexp(char(inputs(i)),'\w*','match','once');
check_string = [check_string sprintf('%s=0;\n',char(inputi))];
end
check_string = [check_string counter sprintf('\n')];
for i=1:size(grid.cells,2)
condition_string = get(grid.cells(i).cond,'string');
if(~isempty(condition_string))
eval([check_string 'result =(' char(condition_string) ');'])
if(result == 0)
grid.cells(i).flag_cell(1);
else
true_conds = true_conds + 1;
grid.cells(i).flag_cell(2);
end
else
empty_cell = 1;
end
end
if (true_conds == 1)
for i=1:size(grid.cells,2)
condition_string = get(grid.cells(i).cond,'string');
if(~isempty(condition_string))
eval([check_string 'result =(' char(condition_string) ');'])
if(result == 0)
grid.cells(i).flag_cell(1);
else
if (~isempty(grid.cells(i).subgrid))
sub_problem = obj.evaluate_counter_grid(grid.cells(i).subgrid,counter);
end
grid.cells(i).flag_cell(2);
end
else
empty_cell = 1;
end
end
end
if (true_conds ~= 1 || sub_problem == 1)
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
end
end
%% create_std_text
% function will create an edit text box used for conditons and
% results. we want these to be consistent so its easier for it to
% be in one function.
% inputs:
% obj:GUI - current GUI object
% Parent:double - handle to parent figure
% position:[double double double double] - position to place edit
% box in.
% outputs;
% control:double - handle pointing to newly created uicontrol
function control = create_std_text(obj, Parent, position)
control = uicontrol('style','edit',...
'Parent',Parent,...
'units','pix',...
'position',position,...
'min',0,'max',1,... % This is the key to multiline edits.
'string',{''},...
'Max',2.0,...
'Clipping','on',...
'fontweight','bold',...
'BackgroundColor',[1 1 1],...
'horizontalalign','center',...
'KeyPressFcn',@(src,event)textbox_callback(obj,src,event),...
%%
function [] = textbox_callback(object,src,event)
if(~isempty(unicode2native(event.Character)))
if event.Character > 33 || event.Character == 8
if object.pvs_checked == 1
object.pvs_checked = 0;
object.update_Statusbar
if (object.mode == 1)
TableBlock.set_block_display(object.block_handle,object.pvs_checked);
end
end
end
Colin Eles
committed
end
Colin Eles
committed
function error = check_inputs(obj)
parsed_input = EMLGenerator.parse_inputs(get(obj.function_inputs_control,'string'));
error = [];
for i=1:size(parsed_input,2)
if(size(parsed_input{i},2) == 2)
if (strcmp(parsed_input{i}(2),'error'))
error = [error sprintf('%s is not a valid variable name\n',char(parsed_input{i}(1))) ];
end
end
end
end
Colin Eles
committed
function [] = setPBenable(obj)
if size(obj.Grid1.cells,2) > 1
set(obj.Grid1.delete_cell_pb,'Enable','on');
else
set(obj.Grid1.delete_cell_pb,'Enable','off');
end
if size(obj.Grid2.cells,2) > 1
set(obj.Grid2.delete_cell_pb,'Enable','on');
else
set(obj.Grid2.delete_cell_pb,'Enable','off');
end
%set(obj.Grid2.delete_cell_pb,'Enable','off');
%set(obj.Grid1.delete_cell_pb,'Enable','off');
end