Newer
Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
classdef Cell < handle
properties
subgrid = [];
cond = [];
cond_text = [];
cell_index = 0;
parent_grid = [];
width = 0;
height = 0;
grid_pb = [];
pb_flag = 0;
color = [];
condition_text_width = 200;
condition_text_height = 40;
condition_text_x = 10;
condition_text_y = 10;
condition_text_offset = 20;
grid_push_width = 30;
end
methods
%% Cell
%
% inputs:
% index:integer - cells index
% p_grid:Grid - Parent grid of cell
% outputs;
% obj:Cell - created cell
function obj = Cell(index, p_grid)
obj.cell_index = index;
obj.parent_grid = p_grid;
obj.pb_flag = 1;
end
%% new_Grid
%
% inputs:
% obj:Cell - Current Cell Object
% outputs;
%
function [] = new_Grid(obj)
obj.subgrid = Grid(obj.cell_index,obj);
obj.subgrid.new_Cell;
obj.subgrid.new_Cell;
obj.subgrid.set_rGrid(obj.parent_grid.rGrid);
obj.pb_flag = 0;
delete(obj.grid_pb);
if(~isempty(obj.parent_grid.rGrid))
obj.parent_grid.rGrid.delete_g2s(obj);
end
end
%% delete_Cell
% deletes the current cell, will recursively delete any subgrids
% if they exist.
% inputs:
% obj:Cell - Current Cell Object
% outputs;
% none
function [] = delete_Cell(obj)
if(isempty(obj.subgrid))
delete(obj.grid_pb);
delete(obj.cond);
obj.cond = [];
obj.grid_pb = [];
delete(obj);
else
% delete the subgrid
obj.subgrid.deep_delete
if(ishghandle(obj.grid_pb))
delete(obj.grid_pb);
end
delete(obj.cond);
obj.cond = [];
obj.grid_pb = [];
delete(obj);
end
end
%% set_pb
% create the new subgrid push button handle
% inputs:
% obj:Cell - Current Cell Object
% outputs;
% none
function [] = set_pb(obj,fig,pos)
if(obj.pb_flag == 1 && (isempty(obj.grid_pb) || ~ishghandle(obj.grid_pb)))
obj.grid_pb = uicontrol('style','push',...
'units','pix',...
'string','+',...
'HorizontalAlign','left',...
'Parent',fig,...
'position',pos,...
'callback',@(src,event)pb_call(obj,src,event));
elseif (obj.pb_flag == 1 && ~isempty(obj.grid_pb))
set(obj.grid_pb,'position',pos);
else
end
end
%% pb_call
% callback function for the new subgrid button
% inputs:
% object:Cell - Current Cell Object
% src:double - Source of the callback
% event:eventdata - Data of the eventcall
% outputs;
% none
function [] = pb_call(object,src,event)
gui = get(src,'userdata');
object.new_Grid;
gui.reset_wh();
%gui.draw_grid2(gui.Grid2);
gui.draw_allgrids(0);
end
%% cal_height
% calculates the height in number of cells of the current cell.
% if the cell does not have a subgrid the height will be 1, else
% it will be the height of the subgrid.
% inputs:
% obj:Cell - Current Cell Object
% edit:boolean - 0 when not in edit mode, 1 in edit mode
% outputs;
% h:double - height in number of cells
function h = cal_height(obj,edit)
h = 0;
if (isempty(obj.subgrid))
h = 1;
else
for i=1:size(obj.subgrid.cells,2)
h = h + cal_height(obj.subgrid.cells(i),edit);
end
% edit button is half a cell high, if in edit mode increase
% by 0.5
if (edit == 1)
h = h + 0.5;
end
end
end
%% get_pos
% Returns the position of the edit box for the cell
% inputs:
% obj:Cell - Current Cell Object
% outputs;
% pos:[double double double double] - position of the cell
function pos = get_pos(obj)
if (~isempty(obj.cond))
pos = get(obj.cond,'position');
end
end
%% set_pos
% allows accessor to set the position of the edit box for the
% cell.
% inputs:
% obj:Cell - Current Cell Object
% pos:[double double double double] - the new position of the
% cell
% outputs;
% none
function [] = set_pos(obj,pos)
if (~isempty(obj.cond))
set(obj.cond,'position',pos);
end
end
%% flag_cell
% mode
% 0 - normal
% 1 - red (error/false)
% 2 - green (ok/true)
function [] = flag_cell(obj,mode)
if (isempty(obj.color))
obj.color = get(obj.cond,'BackgroundColor');
end
if (mode == 0)
set(obj.cond,'BackgroundColor',obj.color);
elseif (mode == 1)
set(obj.cond,'BackgroundColor',[0.92 0.65 0.65])
elseif (mode == 2)
set(obj.cond,'BackgroundColor',[0.03 1.0 0.32]);
end
end
end
end