Class: MINT::CIC
- Inherits:
-
CIO
show all
- Defined in:
- lib/MINT-core/model/cui/gfx/CIC.rb
Constant Summary
Constants inherited
from Interactor
Interactor::PUBLISH_ATTRIBUTES
Instance Method Summary
collapse
-
#calculate_container(solver, b, layer = 0) ⇒ Object
elements array of elements from left to right and first to last row cx, cy container position ch,cw container size rows and columns b minimal border space between elements.
-
#calculate_gfx__navigation(array) ⇒ Object
-
#calculate_position(parent_cic, elements, solver, i, b, layer = 0) ⇒ Object
-
#calculateColsAndRows(elements_count) ⇒ Object
-
#getChildren ⇒ Object
-
#getSCXML ⇒ Object
-
#iterate_cols_of_row(array, row_nr, index) ⇒ CLinearExpression
Iterates over all columns of one row that is set by #row_nr.
-
#iterate_rows_of_column(array, col_nr, index) ⇒ Object
-
#mda(width, height) ⇒ Object
-
#refresh_children ⇒ Object
-
#save_grid(array) ⇒ Object
Methods inherited from CIO
#calculateMinimumSize, createCIOfromAIO, #down, #getAIO, getModel, #highlight_down, #highlight_left, #highlight_right, #highlight_up, #initialize_points, #left, #pos, #print, #right, #setFixedPositionConstraints, #setFixedSizeConstraints, #setMinimumSizeConstraints, #setTableElementConstraints, #size, #store_calculated_values_in_model, #up
Methods inherited from Interactor
class_from_channel_name, #create_attribute_channel_name, create_channel_name, #create_channel_w_name, get, getModel, get_dm, #init_statemachine, #is_in?, #new_states, notify, #process_event, #process_event!, #process_event_vars, #publish_update, #states, #states=, #sync_event, #sync_states, #to_dot, wait
#restart_timeout, #start_timeout, #stop_timeout
Instance Method Details
#calculate_container(solver, b, layer = 0) ⇒ Object
elements array of elements from left to right and first to last row cx, cy container position ch,cw container size rows and columns b minimal border space between elements
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
199
200
201
202
203
204
205
206
207
208
209
210
|
# File 'lib/MINT-core/model/cui/gfx/CIC.rb', line 99
def calculate_container(solver,b,layer=0)
if self.process_event!("position")
self.layer = layer
aic = AIContainer.first(:name=>self.name)
elements_count = aic.children.length
calculateColsAndRows(elements_count)
self.rows= elements_count if (self.rows == nil)
self.cols= 1 if (self.cols == nil)
grid_hash= mda(self.rows,self.cols)
ai_childs = aic.children
elements=[]
ai_childs.each_with_index do |e,i|
if e.states == [:organized]
cio = CIO.first(:name=>e.name)
if (not cio)
cio = CIO.createCIOfromAIO(e,layer)
else
cio.layer=layer+1
end
if (not cio.kind_of? MINT::CIC)
cio.process_event!("position")
end
elements << cio
cio.setMinimumSizeConstraints(solver)
act_col = i % self.cols
act_row = i / self.cols
grid_hash[act_row][act_col] = cio
cio.col = act_col
cio.row = act_row
cio.setTableElementConstraints(solver,elements, self,act_col,act_row,i,b)
if (cio.kind_of? MINT::CIC)
cio.calculate_container(solver,b,layer+1)
end
end
end
save_grid(grid_hash)
if (self.rows >0)
self.cols.times do |c|
solver.AddConstraint(ClLinearInequality.new(size.Y,CnGEQ,iterate_rows_of_column(grid_hash,c,self.rows-1).Plus(ClLinearExpression.new((self.rows+1)*b)),Cassowary.ClsStrong))
end
end
if (self.cols>0)
self.rows.times do |r|
solver.AddConstraint(ClLinearInequality.new(size.X,CnGEQ,iterate_cols_of_row(grid_hash,r,self.cols-1).Plus(ClLinearExpression.new((self.cols+1)*b)),Cassowary.ClsStrong))
end
end
elements.each { |e|
if (not e.kind_of? MINT::CIC)
e.process_event!("calculated")
end
e.save
}
self.process_event("calculated")
else
aic = AIContainer.first(:name=>name)
elements = []
aic.children.each_with_index do |e,i|
cio = CIO.first(:name=>e.name)
elements << cio
if (not cio)
cio = CIO.createCIOfromAIO(e,layer)
end
calculateColsAndRows(aic.children.length)
cio.col = i % self.cols
cio.row = i / self.cols
cio.layer = layer+1
cio.calculate_position(self,elements,solver,i,b)
end
end
end
|
#calculate_gfx__navigation(array) ⇒ Object
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
|
# File 'lib/MINT-core/model/cui/gfx/CIC.rb', line 235
def calculate_gfx__navigation(array)
array.each_with_index do |row,r|
row.each_with_index do |column,c|
if not c==0
array[r][c-1].right = array[r][c]
array[r][c].left = array[r][c-1]
end
if not r ==0
array[r-1][c].down = array[r][c]
array[r][c].up = array[r-1][c]
end
end
end
end
|
#calculate_position(parent_cic, elements, solver, i, b, layer = 0) ⇒ Object
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
|
# File 'lib/MINT-core/model/cui/gfx/CIC.rb', line 27
def calculate_position(parent_cic,elements,solver,i,b,layer=0)
p "container #{self.name} #{b}"
aic = AIContainer.first(:name=>self.name)
elements = []
if aic.children && aic.children.length>0
calculateColsAndRows(aic.children.length)
grid_hash= mda(self.rows,self.cols)
aic.children.each_with_index do |e,i|
cio = CIO.first(:name=>e.name)
elements << cio
if (not cio)
cio = CIO.createCIOfromAIO(e,layer)
end
cio.col = i % self.cols
cio.row = i / self.cols
cio.layer = layer+1
cio.calculate_position(self,elements,solver,i,b,layer+1)
grid_hash[cio.row][cio.col] = cio
p "child #{cio.name} 1.positioning step"
end
if self.process_event("position")
if parent_cic
solver.AddConstraint(ClLinearEquation.new(self.pos.Y,ClLinearExpression.new(parent_cic.pos.Y.Value).Plus(ClLinearExpression.new(b))))
solver.AddConstraint(ClLinearEquation.new(self.pos.X,ClLinearExpression.new(parent_cic.pos.X.Value).Plus(ClLinearExpression.new(b))))
end
if (self.rows >0)
self.cols.times do |c|
solver.AddConstraint(ClLinearInequality.new(size.Y,CnGEQ,iterate_rows_of_column(grid_hash,c,self.rows-1).Plus(ClLinearExpression.new((self.rows+1)*b)),Cassowary.ClsStrong))
end
end
if (self.cols>0)
self.rows.times do |r|
solver.AddConstraint(ClLinearInequality.new(size.X,CnGEQ,iterate_cols_of_row(grid_hash,r,self.cols-1).Plus(ClLinearExpression.new((self.cols+1)*b)),Cassowary.ClsStrong))
end
end
else
p "CIC fixed#{self.inspect}"
setFixedPositionConstraints(solver)
setFixedSizeConstraints(solver)
end
else
self.cio_calculate_position(parent_cic,elements,solver,i,b,layer)
end
self.process_event("calculated")
end
|
#calculateColsAndRows(elements_count) ⇒ Object
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
|
# File 'lib/MINT-core/model/cui/gfx/CIC.rb', line 216
def calculateColsAndRows(elements_count)
if not self.cols and not self.rows
self.rows = elements_count
self.cols = 1
end
if (elements_count < self.cols*self.rows)
if self.cols == 1
self.rows = elements_count
elsif self.rows ==1
self.cols = elements_count
else
factor = elements_count / self.cols*self.rows
self.cols = (self.cols*factor).round
self.rows = (self.cols*factor).round
end
end
end
|
#getChildren ⇒ Object
9
10
11
12
13
14
15
16
17
|
# File 'lib/MINT-core/model/cui/gfx/CIC.rb', line 9
def getChildren
aio = getAIO()
children = aio.children.map &:name
cios = []
children.each do |name|
cios << CIO.get(CIO.getModel(),name)
end
cios
end
|
#getSCXML ⇒ Object
6
7
8
|
# File 'lib/MINT-core/model/cui/gfx/CIC.rb', line 6
def getSCXML
"#{File.dirname(__FILE__)}/cic.scxml"
end
|
#iterate_cols_of_row(array, row_nr, index) ⇒ CLinearExpression
Iterates over all columns of one row that is set by #row_nr
269
270
271
272
273
274
275
|
# File 'lib/MINT-core/model/cui/gfx/CIC.rb', line 269
def iterate_cols_of_row(array,row_nr,index)
if (index>0)
return ClLinearExpression.new(array[row_nr][index].size.X).Plus(iterate_cols_of_row(array,row_nr,index-1))
else
return ClLinearExpression.new(array[row_nr][index].size.X)
end
end
|
#iterate_rows_of_column(array, col_nr, index) ⇒ Object
277
278
279
280
281
282
283
284
285
286
287
288
|
# File 'lib/MINT-core/model/cui/gfx/CIC.rb', line 277
def iterate_rows_of_column(array,col_nr,index)
begin
if (index>0)
return ClLinearExpression.new(array[index][col_nr].size.Y).Plus(iterate_rows_of_column(array,col_nr,index-1))
else
return ClLinearExpression.new(array[index][col_nr].size.Y)
end
rescue NoMethodError
p "rescue with index #{index} and col_nr #{col_nr}"
end
end
|
#mda(width, height) ⇒ Object
212
213
214
|
# File 'lib/MINT-core/model/cui/gfx/CIC.rb', line 212
def mda(width, height)
return Array.new(width){Array.new(height)}
end
|
#refresh_children ⇒ Object
19
20
21
22
23
24
25
|
# File 'lib/MINT-core/model/cui/gfx/CIC.rb', line 19
def refresh_children
p "i refresh children"
getChildren.each do |cio|
p "refreshing #{cio.name}"
cio.process_event :refresh
end
end
|
#save_grid(array) ⇒ Object
254
255
256
257
258
259
260
|
# File 'lib/MINT-core/model/cui/gfx/CIC.rb', line 254
def save_grid(array)
array.each_with_index do |row,r|
row.each_with_index do |column,c|
array[r][c].save
end
end
end
|