-
Notifications
You must be signed in to change notification settings - Fork 2
/
cfg.tin
543 lines (461 loc) · 25.9 KB
/
cfg.tin
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
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;; ;;;;
;;;; ;;;;
;;;; ;;;;
;;;; ;;;;
;;;; ;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defnet cfg-cb (self)
(deflocal cfg-info default-info q butbox vbox dlg)
(set cfg-info (assoc))
(set <_kv "cfg-info"> cfg-info)
(set default-info <_kv "default">)
(set q (queue))
(set butbox (iup-box-ok-cancel (netptr cfg-ok) undef q))
(set vbox (iup-vbox
(cfg-setup-tabs q)
butbox ))
(iup-set-str-attribute vbox "MARGIN" "4x4")
(iup-set-int vbox "GAP" 0)
(set dlg (iup-dialog vbox))
(iup-set-dlg-parent self dlg)
(iup-set-str-attribute dlg "TITLE" $"Preferences")
(iup-set-bool dlg "DIALOGFRAME" true)
(iup-set-attribute-handle dlg "DEFAULTENTER" (iup-box-ok-cancel-btn-ok butbox))
(iup-set-attribute-handle dlg "DEFAULTESC" (iup-box-ok-cancel-btn-cancel butbox))
(iup-set-active <cfg-info "sb-sift-scale-pixels"> (cfg-get-or-default "sift-scale" default-info))
(iup-set-callback <cfg-info "tb-sift-scale"> "ACTION" (netptr cfg-toggled-sift-scale))
(iup-set-active <cfg-info "sb-filter-ar1"> (not (cfg-get-or-default "filter-ar1-auto" default-info)))
(iup-set-active <cfg-info "sb-filter-ar2"> (not (cfg-get-or-default "filter-ar2-auto" default-info)))
(iup-set-callback <cfg-info "tb-filter-ar1-auto"> "ACTION" (netptr cfg-toggled-fileter-ar1))
(iup-set-callback <cfg-info "tb-filter-ar2-auto"> "ACTION" (netptr cfg-toggled-fileter-ar2))
(iup-popup dlg (cmacro IUP_CENTERPARENT) (cmacro IUP_CENTERPARENT))
(close dlg)
(iup-close-queue q)
(assoc-clr _kv "cfg-info")
(gui-update)
(gui-update-image) )
(defnet cfg-ok (self)
(sqlite3-begin _db)
(alt (seq (cfg-ok-low self)
(sqlite3-end _db) )
(seq (sqlite3-rollback _db)
(sound-iup-error60 self "errore nel salvataggio configurazione") ))
(iup-exit-loop) )
(defnet cfg-ok-low (self)
(deflocal cfg-info c i which av old-lang new-lang)
(set cfg-info <_kv "cfg-info">)
(for c in [ "sift-scale"
"sift-draw-lines"
"final-closure"
"filter-mirror1"
"filter-mirror2"
"filter-flip1"
"filter-flip2"
"filter-ar1-auto"
"filter-ar2-auto"
"debug-enabled"
"sound-enabled"
"cuvid-enabled"
] do
(cfg-set c (iup-get-bool <cfg-info (+ "tb-" c)> "VALUE")) )
(for c in [ "scd-min-blocks"
"scd-min-avg-block-size"
"frame-buf-size"
"scd-threads"
"supervision-skip-double"
"checks-per-interval"
"checks-per-interval-extra"
"sift-agreements-min"
"sift-scale-pixels"
"min-keypoints"
] do
(cfg-set c (iup-get-int <cfg-info (+ "sb-" c)> "SPINVALUE")) )
(for c in [ "init-scd-threshold"
"min-scd-threshold"
"scd-threshold-ratio"
"min-keypoints-min-ratio"
"min-keypoints-min-ratio-lum"
"sift-match-threshold-val"
"sift-match-threshold-min-ratio"
"sift-proportionality-threshold"
"filter-gamma1"
"filter-gamma2"
"filter-rotate1"
"filter-rotate2"
"filter-ar1"
"filter-ar2"
] do
(cfg-set c (iup-text-spin-ratio-val <cfg-info (+ "sb-" c)>)) )
(for c in [ "filter-rows1"
"filter-rows2"
"filter-deint1"
"filter-deint2"
] do
(cfg-set c (- (iup-get-int <cfg-info (+ "cb-" c)> "VALUE") 1)) )
(set <_kv "debug-enabled"> (cfg-get "debug-enabled"))
(set <_kv "sound-enabled"> (cfg-get "sound-enabled"))
(set i (cfg-get-num "frame-buf-size"))
(for which in 1 .. 2 do
(opt (set av <_kv (+ "av" which)>)
(<> av undef)
(av-set-buf-size av i)
(av-set-filter-rows av (cfg-get-num (+ "filter-rows" which)))
(set c (cfg-get-num (+ "filter-deint" which)))
(if (= c 0)
then (av-set-filter av)
else (av-set-filter av <(deint-filters) c>)
;(set c (pix-create 10 10))
;(pixp c)
;(opt (av-read-frame av c (av-frameno av)))
;(close c)
)))
(set old-lang (lang))
(set new-lang (- (iup-get-int <cfg-info "cb-languages"> "VALUE") 1))
(cfg-set "lang" new-lang)
(if (<> new-lang old-lang)
then (set-lang new-lang)
(iup-warning60 self $"Changing the language requires a restart to take effect.") ))
(defun cfg-setup-tabs (q) net cfg-setup-tabs)
(defnet cfg-setup-tabs (q @wid)
(set @wid (iup-tabs
(cfg-setup-tabs-page1 q)
(cfg-setup-tabs-page2 q)
(cfg-setup-tabs-page3 q)
(cfg-setup-tabs-page4 q)
(cfg-setup-tabs-page5 q) ))
(iup-set-str-attribute @wid "TABTITLE0" $"Sequences")
(iup-set-str-attribute @wid "TABTITLE1" $"Checks")
(iup-set-str-attribute @wid "TABTITLE2" "SIFT")
(iup-set-str-attribute @wid "TABTITLE3" $"Filters")
(iup-set-str-attribute @wid "TABTITLE4" "Misc")
(iup-set-bool @wid "EXPAND" true) )
(defun cfg-setup-tabs-page1 (q) net cfg-setup-tabs-page1)
(defnet cfg-setup-tabs-page1 (q @wid)
(deflocal cfg-info default-info hbox1 hbox2 hbox3)
(set cfg-info <_kv "cfg-info">)
(set default-info <_kv "default">)
(set hbox1 (iup-hbox
(cfg-setup-framed-spin-ratio "Init thres./avg" 4 20
(cfg-get-or-default-num "init-scd-threshold" default-info) 0.1
cfg-info "sb-init-scd-threshold" )
(cfg-setup-framed-spin-ratio "Min thres./avg" 2 8
(cfg-get-or-default-num "min-scd-threshold" default-info) 0.1
cfg-info "sb-min-scd-threshold" )
(cfg-setup-framed-spin-ratio "Thres. ratio" 0.01 0.99
(cfg-get-or-default-num "scd-threshold-ratio" default-info) 0.01
cfg-info "sb-scd-threshold-ratio" )))
(set hbox2 (iup-hbox
(cfg-setup-framed-spin "Min int. blks" 1 50
(cfg-get-or-default-num "scd-min-blocks" default-info)
cfg-info "sb-scd-min-blocks" )
(cfg-setup-framed-spin "Min avg blk size" 1 200
(cfg-get-or-default-num "scd-min-avg-block-size" default-info)
cfg-info "sb-scd-min-avg-block-size" ) ))
(set hbox3 (iup-hbox
(cfg-setup-framed-toggle $"Final closure" $"enabled" (cfg-get-or-default "final-closure" default-info) cfg-info "tb-final-closure") ))
(iup-set-int hbox1 "GAP" 5)
(iup-set-int hbox2 "GAP" 5)
(iup-set-int hbox3 "GAP" 5)
(set @wid (iup-vbox hbox1 hbox2 hbox3))
(iup-set-int @wid "GAP" 2) )
(defun cfg-setup-tabs-page2 (q) net cfg-setup-tabs-page2)
(defnet cfg-setup-tabs-page2 (q @wid)
(deflocal cfg-info default-info hbox1 hbox2 hbox3)
(set cfg-info <_kv "cfg-info">)
(set default-info <_kv "default">)
(set hbox1 (iup-hbox
(iup-frame-with-margin "Checks per interval+extra" (iup-hbox
(cfg-setup-spin 2 100 (cfg-get-or-default-num "checks-per-interval" default-info)
cfg-info "sb-checks-per-interval" )
(cfg-setup-spin 2 100 (cfg-get-or-default-num "checks-per-interval-extra" default-info)
cfg-info "sb-checks-per-interval-extra" )))
(iup-frame-with-margin "Min keypoints+min ratios" (iup-hbox
(cfg-setup-spin 2 1000 (cfg-get-or-default-num "min-keypoints" default-info)
cfg-info "sb-min-keypoints" )
(cfg-setup-spin-ratio 0.01 0.99 (cfg-get-or-default-num "min-keypoints-min-ratio" default-info) 0.01
cfg-info "sb-min-keypoints-min-ratio" )
(cfg-setup-spin-ratio 0.01 0.99 (cfg-get-or-default-num "min-keypoints-min-ratio-lum" default-info) 0.01
cfg-info "sb-min-keypoints-min-ratio-lum" )))))
(set hbox2 (iup-hbox
(cfg-setup-framed-spin "Min agreements" 1000 100000
(cfg-get-or-default-num "sift-agreements-min" default-info)
cfg-info "sb-sift-agreements-min" )
(cfg-setup-framed-spin-ratio "Proport. thres." 0 0.99
(cfg-get-or-default-num "sift-proportionality-threshold" default-info) 0.01
cfg-info "sb-sift-proportionality-threshold" )))
(set hbox3 (iup-hbox
(iup-frame-with-margin $"Scaling" (iup-hbox
(cfg-setup-toggle $"enabled" (cfg-get-or-default "sift-scale" default-info) cfg-info "tb-sift-scale")
(cfg-setup-spin 10000 1000000 (cfg-get-or-default-num "sift-scale-pixels" default-info)
cfg-info "sb-sift-scale-pixels" )))))
(iup-set-int hbox1 "GAP" 5)
(iup-set-int hbox2 "GAP" 5)
(iup-set-int hbox3 "GAP" 5)
(set @wid (iup-vbox hbox1 hbox2 hbox3))
(iup-set-int @wid "GAP" 2) )
(defun cfg-setup-tabs-page3 (q) net cfg-setup-tabs-page3)
(defnet cfg-setup-tabs-page3 (q @wid)
(deflocal cfg-info default-info hbox1 i)
(set cfg-info <_kv "cfg-info">)
(set default-info <_kv "default">)
(set hbox1 (iup-hbox
(iup-frame-with-margin "Match thres.+min ratio" (iup-hbox
(cfg-setup-spin-ratio 0.09 1.95 (cfg-get-or-default-num "sift-match-threshold-val" default-info) 0.01
cfg-info "sb-sift-match-threshold-val" )
(cfg-setup-spin-ratio 0.01 0.99 (cfg-get-or-default-num "sift-match-threshold-min-ratio" default-info) 0.01
cfg-info "sb-sift-match-threshold-min-ratio" )))))
(iup-set-int hbox1 "GAP" 5)
(set @wid (iup-vbox hbox1))
(iup-set-int @wid "GAP" 2) )
(defun cfg-setup-tabs-page4 (q) net cfg-setup-tabs-page4)
(defnet cfg-setup-tabs-page4 (q @wid)
(deflocal cfg-info default-info hbox1 hbox2 hbox3 hbox4 hb1 hb2 rows1-list rows2-list deint1-list deint2-list i)
(set cfg-info <_kv "cfg-info">)
(set default-info <_kv "default">)
(set rows1-list (iup-list))
(set rows2-list (iup-list))
(set <cfg-info "cb-filter-rows1"> rows1-list)
(set <cfg-info "cb-filter-rows2"> rows2-list)
(iup-set-bool rows1-list "DROPDOWN" true)
(iup-set-bool rows2-list "DROPDOWN" true)
(for i in (row-filters) do
(iup-set-str-attribute rows1-list (+ (for-pos) 1) i)
(iup-set-str-attribute rows2-list (+ (for-pos) 1) i) )
(iup-set-int rows1-list "VALUE" (+ (cfg-get-or-default-num "filter-rows1" default-info) 1))
(iup-set-int rows2-list "VALUE" (+ (cfg-get-or-default-num "filter-rows2" default-info) 1))
(set deint1-list (iup-list))
(set deint2-list (iup-list))
(set <cfg-info "cb-filter-deint1"> deint1-list)
(set <cfg-info "cb-filter-deint2"> deint2-list)
(iup-set-bool deint1-list "DROPDOWN" true)
(iup-set-bool deint2-list "DROPDOWN" true)
(for i in (deint-filters) do
(iup-set-str-attribute deint1-list (+ (for-pos) 1) (if (= (for-pos) 0) $"none" i))
(iup-set-str-attribute deint2-list (+ (for-pos) 1) (if (= (for-pos) 0) $"none" i)) )
(iup-set-int deint1-list "VALUE" (+ (cfg-get-or-default-num "filter-deint1" default-info) 1))
(iup-set-int deint2-list "VALUE" (+ (cfg-get-or-default-num "filter-deint2" default-info) 1))
(set hb1 (iup-hbox
(cfg-setup-toggle "auto" (cfg-get-or-default "filter-ar1-auto" default-info) cfg-info "tb-filter-ar1-auto")
(cfg-setup-spin-ratio 0.1 10 (cfg-get-or-default-num "filter-ar1" default-info) 0.01
cfg-info "sb-filter-ar1" )))
(iup-set-str-attribute hb1 "ALIGNMENT" "ACENTER")
(set hb2 (iup-hbox
(cfg-setup-toggle "auto" (cfg-get-or-default "filter-ar2-auto" default-info) cfg-info "tb-filter-ar2-auto")
(cfg-setup-spin-ratio 0.1 10 (cfg-get-or-default-num "filter-ar2" default-info) 0.01
cfg-info "sb-filter-ar2" )))
(iup-set-str-attribute hb2 "ALIGNMENT" "ACENTER")
(set hbox1 (iup-hbox
(cfg-setup-framed-spin-ratio "Gamma 1" 0.01 4
(cfg-get-or-default-num "filter-gamma1" default-info) 0.01
cfg-info "sb-filter-gamma1" )
(cfg-setup-framed-toggle "Mirror 1" $"enabled"
(cfg-get-or-default "filter-mirror1" default-info) cfg-info "tb-filter-mirror1" )
(cfg-setup-framed-toggle "Flip 1" $"enabled"
(cfg-get-or-default "filter-flip1" default-info) cfg-info "tb-filter-flip1" )
(cfg-setup-framed-spin-ratio "Rotate 1" (- 0.01 360) (- 360 0.01)
(cfg-get-or-default-num "filter-rotate1" default-info) 0.01
cfg-info "sb-filter-rotate1" )))
(set hbox2 (iup-hbox
(iup-frame-with-margin "Rows 1" rows1-list)
(iup-frame-with-margin "Deint 1" deint1-list)
(iup-frame-with-margin "Aspect ratio 1" hb1) ))
(set hbox3 (iup-hbox
(cfg-setup-framed-spin-ratio "Gamma 2" 0.01 4
(cfg-get-or-default-num "filter-gamma2" default-info) 0.01
cfg-info "sb-filter-gamma2" )
(cfg-setup-framed-toggle "Mirror 2" $"enabled"
(cfg-get-or-default "filter-mirror2" default-info) cfg-info "tb-filter-mirror2" )
(cfg-setup-framed-toggle "Flip 2" $"enabled"
(cfg-get-or-default "filter-flip2" default-info) cfg-info "tb-filter-flip2" )
(cfg-setup-framed-spin-ratio "Rotate 2" (- 0.01 360) (- 360 0.01)
(cfg-get-or-default-num "filter-rotate2" default-info) 0.01
cfg-info "sb-filter-rotate2" )))
(set hbox4 (iup-hbox
(iup-frame-with-margin "Rows 2" rows2-list)
(iup-frame-with-margin "Deint 2" deint2-list)
(iup-frame-with-margin "Aspect ratio 2" hb2) ))
(iup-set-int hbox1 "GAP" 5)
(iup-set-int hbox2 "GAP" 5)
(iup-set-int hbox3 "GAP" 5)
(iup-set-int hbox4 "GAP" 5)
(set @wid (iup-vbox hbox1 hbox2 hbox3 hbox4))
(iup-set-int @wid "GAP" 2) )
(defun cfg-setup-tabs-page5 (q) net cfg-setup-tabs-page5)
(defnet cfg-setup-tabs-page5 (q @wid)
(deflocal cfg-info default-info hbox1 hbox2 hbox3 list i)
(set cfg-info <_kv "cfg-info">)
(set default-info <_kv "default">)
(set hbox1 (iup-hbox
(cfg-setup-framed-spin "Frame buf size" 2 300
(cfg-get-or-default-num "frame-buf-size" default-info)
cfg-info "sb-frame-buf-size" )
(cfg-setup-framed-spin "SCD threads" 1 100
(cfg-get-or-default-num "scd-threads" default-info)
cfg-info "sb-scd-threads" )
(cfg-setup-framed-toggle $"Line drawing" $"enabled" (cfg-get-or-default "sift-draw-lines" default-info) cfg-info "tb-sift-draw-lines")
(cfg-setup-framed-spin "Sup. step incr." 2 1000
(cfg-get-or-default-num "supervision-skip-double" default-info)
cfg-info "sb-supervision-skip-double" )))
(set hbox2 (iup-hbox
(cfg-setup-framed-toggle "Debug" $"enabled" (cfg-get-or-default "debug-enabled" default-info) cfg-info "tb-debug-enabled")
(cfg-setup-framed-toggle $"Sound" $"enabled" (cfg-get-or-default "sound-enabled" default-info) cfg-info "tb-sound-enabled")
(cfg-setup-framed-toggle "CUVID" $"enabled" (cfg-get-or-default "cuvid-enabled" default-info) cfg-info "tb-cuvid-enabled") ))
(set list (iup-list))
(set <cfg-info "cb-languages"> list)
(iup-set-bool list "DROPDOWN" true)
(for i in (languages) do
(iup-set-str-attribute list (+ (for-pos) 1) i) )
(iup-set-int list "VALUE" (+ (lang) 1))
(set hbox3 (iup-hbox
(iup-frame-with-margin $"Language" list) ))
(iup-set-int hbox1 "GAP" 5)
(iup-set-int hbox2 "GAP" 5)
(iup-set-int hbox3 "GAP" 5)
(set @wid (iup-vbox hbox1 hbox2 hbox3))
(iup-set-int @wid "GAP" 2) )
(defun cfg-setup-toggle (name status cfg-info key) net cfg-setup-toggle)
(defnet cfg-setup-toggle (name status cfg-info key @wid)
(set @wid (iup-toggle (if (iup-gtk3) (+ " " name) name)))
(set <cfg-info key> @wid)
(iup-set-str-attribute @wid "VALUE" (if status "ON" "OFF")) )
(defun cfg-setup-framed-toggle (title name status cfg-info key)
(iup-frame-with-margin title (cfg-setup-toggle name status cfg-info key)) )
(defun cfg-setup-spin (vmin vmax vcur cfg-info key) net cfg-setup-spin)
(defnet cfg-setup-spin (vmin vmax vcur cfg-info key @wid)
(set @wid (iup-text-spin vmin vmax vcur))
(set <cfg-info key> @wid) )
(defun cfg-setup-framed-spin (title vmin vmax vcur cfg-info key)
(iup-frame-with-margin title (cfg-setup-spin vmin vmax vcur cfg-info key)) )
(defun cfg-setup-spin-ratio (vmin vmax vcur vinc cfg-info key) net cfg-setup-spin-ratio)
(defnet cfg-setup-spin-ratio (vmin vmax vcur vinc cfg-info key @wid)
(set @wid (iup-text-spin-ratio vmin vmax vcur vinc))
(set <cfg-info key> @wid) )
(defun cfg-setup-framed-spin-ratio (title vmin vmax vcur vinc cfg-info key)
(iup-frame-with-margin title (cfg-setup-spin-ratio vmin vmax vcur vinc cfg-info key)) )
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;; ;;;;
;;;; ;;;;
;;;; ;;;;
;;;; ;;;;
;;;; ;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defnet cfg-toggled-sift-scale (self)
(iup-set-active <_kv "cfg-info" "sb-sift-scale-pixels"> (iup-get-bool self "VALUE")) )
(defnet cfg-toggled-fileter-ar1 (self)
(iup-set-active <_kv "cfg-info" "sb-filter-ar1"> (not (iup-get-bool self "VALUE"))) )
(defnet cfg-toggled-fileter-ar2 (self)
(iup-set-active <_kv "cfg-info" "sb-filter-ar2"> (not (iup-get-bool self "VALUE"))) )
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;; ;;;;
;;;; ;;;;
;;;; ;;;;
;;;; ;;;;
;;;; ;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defnet cfg-import-cb (self)
(opt (cfg-import-low self)) )
(defnet cfg-import-low (self)
(deflocal path db a msg)
(set path (iup-choose-file-open self $"Select cfg" (if (cmingw) (callpath) (datapath)) "CFG Files|*.cfg|All Files|*.*|" true))
(stringp path)
(set db (sqlite3-open path))
(if (= db undef)
then (sound-iup-error60 self (+ "SQLite3 cannot open `" path "'"))
(fail) )
(set a (array default 0 6 2))
(sqlite3-begin _db)
(alt (iup-progress
(thread-create (netptr cfg-import-th) (thread-self) db a)
self "Importing..." true true true false true )
(seq (sqlite3-rollback _db)
(close db)
(sound-iup-error60 self "Aborted.")
(fail) ))
(sqlite3-end _db)
(close db)
(set msg (+
"imported paths: " <a 0 0> "/" <a 0 1> nl
"imported projects: " <a 1 0> "/" <a 1 1> nl
"imported scd data: " <a 2 0> "/" <a 2 1> nl
"imported sift check data: " <a 3 0> "/" <a 3 1> nl
"imported mapping data: " <a 4 0> "/" <a 4 1> nl
"imported permutation data: " <a 5 0> "/" <a 5 1> nl
nl ))
(iup-text-append-and-go-end <_kv "text2"> msg)
(iup-info60 self msg)
(gui-report)
(gui-update) )
(defnet cfg-import-th (th db a)
(deflocal dlg i)
(send "dlg" to th)
(receive dlg from th)
(alt (seq (opt (sqlite3-exec-data db (netptr cfg-import-cback1) (list th dlg a) "SELECT path,name FROM paths"))
(not (iup-progress-aborted dlg))
(opt (sqlite3-exec-data db (netptr cfg-import-cback2) (list th dlg a) "SELECT name,path1,path2 FROM projects"))
(not (iup-progress-aborted dlg))
(sqlite3-exec-data db (netptr cfg-import-cback3) (list th db dlg a) "SELECT key FROM config ORDER by key")
(send "q" to th) )
(send "a" to th) ))
(defnet cfg-import-cback1 (a path name)
(deflocal th dlg)
(set th <a 0>)
(set dlg <a 1>)
(set a <a 2>)
(not (iup-progress-aborted dlg))
(inc <a 0 1>)
(opt (sqlite3-exec _db undef
"INSERT INTO paths VALUES('" (sqlite3-escape-strings path)
"','" (sqlite3-escape-strings name) "')" )
(inc <a 0 0>)
(sendbuf 100 (cons "m" (+ "imported paths: " <a 0 0>)) to th) ))
(defnet cfg-import-cback2 (a name path1 path2)
(deflocal th dlg)
(set th <a 0>)
(set dlg <a 1>)
(set a <a 2>)
(not (iup-progress-aborted dlg))
(inc <a 1 1>)
(opt (set path1 (sqlite3-escape-strings path1))
(set path2 (sqlite3-escape-strings path2))
(= (str->num <(sqlite3-exec _db "SELECT count(*) FROM projects WHERE path1='" path1 "' AND path2='" path2 "'") 0 0>) 0)
(sqlite3-exec _db undef
"INSERT INTO projects VALUES('" (sqlite3-escape-strings name)
"','" path1 "','" path2 "')" )
(inc <a 1 0>)
(sendbuf 100 (cons "m" (+ "imported projects: " <a 1 0>)) to th) ))
(defnet cfg-import-cback3 (a key)
(deflocal th db dlg value i)
(set th <a 0>)
(set db <a 1>)
(set dlg <a 2>)
(set a <a 3>)
(not (iup-progress-aborted dlg))
(opt (lmatch setidx i key "scd-" "sck-" "map-" "prm-")
(= (length key) (if (= i 0) 44 84))
(inc i 2)
(inc <a i 1>)
(set key (sqlite3-escape-strings key))
(= (str->num <(sqlite3-exec _db "SELECT count(*) FROM config WHERE key='" key "'") 0 0>) 0)
(set value <(sqlite3-exec-raw db "SELECT value FROM config WHERE key='" key "'") 0 0>)
(rawp value)
(sqlite3-exec-raw _db undef
"INSERT INTO config VALUES('" key "','" value "')" )
(close value)
(inc <a i 0>)
(sendbuf 100 (cons "m" (+ "imported " <[ "scd" "sift check" "mapping" "permutation" ] (- i 2)> " data: " <a i 0>)) to th) ))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;; ;;;;
;;;; ;;;;
;;;; ;;;;
;;;; ;;;;
;;;; ;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;