-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprocSDA.nim
executable file
·749 lines (595 loc) · 25.4 KB
/
procSDA.nim
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
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
import termkey
import procCurs
import strformat
import unicode
import std/[re]
from strutils import parseInt,parseEnum,parseBool
import tables
import json
import os ,times
#proc beug(nline : int ; text :string ) =
# gotoXY(40, 1); echo "ligne>", nline, " :" , text ; discard getFunc()
var cellYellow = new(CELLATRB)
cellYellow.cell_style = {styleDim,styleItalic}
cellYellow.cell_backgr = BackgroundColor.bgblack
cellYellow.cell_backbr = false
cellYellow.cell_foregr = ForegroundColor.fgYellow
cellYellow.cell_forebr = true
#===================================================
# index GRID / COMBO / CALLQRY
func setID*( line : var int ) : string =
line += 1
return $line
#===================================================
#===================================================
var NbrPanel: int = 0
var PanelWork: int = 0
# double buffer
var base = newseq[PANEL]()
var detail : PANEL
var Zgrid : GRIDSFL
var Zdup : GRIDSFL
var Cell_numIDx : int
var pnLx :PANEL
var pnFx :PANEL
var Dspmnu = new(MENU)
var nTest = 0
var key : TKey = TKey.None
var keyG : TKey_Grid
var nPnl : int = 0
var nopt : int = 0
var nchx : int = 0
let mExit: int = 4
var X,Y,XX,YY,SX,SY,NY : Natural
var e_TEXT = newSeq[Rune]()
var v_TEXT : string
var maxY, minY : Natural
var maxX, minX : Natural
initTerm()
titleTerm("DESIGNER")
setTerminal() #default color style erase
base.add(newPanel("Base",1,1,terminalHeight(),terminalWidth(), @[defButton(TKey.None,"")]))
detail = newPanel("Detail",1,1,terminalHeight(),terminalWidth(),@[defButton(TKey.None,"")])
var orderZ :PANEL = newPanel("order",1,1,terminalHeight(),terminalWidth(), @[defButton(TKey.None,"")],line1,"Order Label")
var mnuScrn = new(MENU)
mnuScrn = newMenu("Screen" ,1, 5,vertical,@["Panel ","Zone...","Source " ,"Exit "],line1 )
var mnuOrder = new(MENU)
mnuOrder = newMenu("Order" ,2, 5,vertical,@["Label ","Field ","Menu "],line1 )
var mnuRmv = new(MENU)
mnuRmv = newMenu("Remove" ,2, 5,vertical,@["Label ","Field ","Menu ","Grid"],line1 )
#--------------------------------------------------
# display table decisionel
include callqry
# source label / field
include procPanel
include procLabel
include procField
include procMenu
include procGrid
include procJson
include procInit # depend procJson
if LoadInit() == false :
closeTerm()
while true:
if nopt == mExit : closeTerm()
if nPnl == 0 :
setTerminal()
printMenu(base[0],mnuScrn)
nopt = ioMenu(base[0],mnuScrn,0)
if nopt >= 1 and nopt < mExit :
npnl = nopt
if nopt == 1 : PanelWork = callPanel(base,true)
if nopt != 1 : PanelWork = callPanel(base,false)
if PanelWork == 0 : npnl = 0
elif nopt == 0 : nPnl =0
setTerminal()
# definition Panel
if nPnl == 1 :
PanelDef()
# definition Label Field Menu
if nPnl == 2 :
if fldP.OK == false :
nPnl = 0
setTerminal()
gotoXY(1,1)
offCursor()
continue
setTerminal()
clsPanel(detail)
resetPanel(detail)
detail = newPanel("Detail",1,1,terminalHeight(),terminalWidth(),@[defButton(TKey.None,"")])
detail.posx = base[PanelWork].posx
detail.posy = base[PanelWork].posy
detail.lines = base[PanelWork].lines
detail.cols = base[PanelWork].cols
detail.backgr = base[PanelWork].backgr
detail.backbr = base[PanelWork].backbr
detail.foregr = base[PanelWork].foregr
detail.forebr = base[PanelWork].forebr
detail.style = base[PanelWork].style
detail.cadre = base[PanelWork].cadre
detail.boxpnl = base[PanelWork].boxpnl
detail.index = 0
detail.box = base[PanelWork].box
detail.label = base[PanelWork].label
detail.field = base[PanelWork].field
detail.hiden = base[PanelWork].hiden
detail.button = base[PanelWork].button
detail.funcKey = base[PanelWork].funcKey
detail.mouse = false
detail.setActif(true)
printPanel(detail)
gotoXY(detail.posx,detail.posy)
onCursor()
onMouse()
maxY = detail.cols + detail.posy
if detail.cadre != CADRE.line0 : maxY -= 1
minY = detail.posy # func F1...
if detail.cadre != CADRE.line0 : minY += 1
maxX = detail.lines + detail.posx
if detail.cadre != CADRE.line0 : maxX -= 2
minX= detail.posx
if detail.cadre != CADRE.line0 : minX += 1
gotoXY(minX,minY)
while true :
getCursor(XX , YY)
gotoXY(XX,YY)
onCursor()
key = getFunc(true)
case key
of TKey.CtrlQ:
offMouse()
nPnl = 0
setTerminal()
gotoXY(minX , minY)
offCursor()
break
of TKey.Mouse :
let mi = getMouse()
if mi.action == MouseButtonAction.mbaPressed:
gotoXY(terminalHeight(),terminalWidth()-20); stdout.write " "
# work this first /.../ bla bla
case mi.button
of mbLeft:
gotoXY(terminalHeight(),terminalWidth()-20); stdout.write fmt"{mi.x},{mi.y}"
of mbMiddle:
gotoXY(terminalHeight(),terminalWidth()-20); stdout.write fmt"{mi.x},{mi.y}"
of mbRight:
gotoXY(terminalHeight(),terminalWidth()-20); stdout.write fmt"{mi.x},{mi.y}"
else: discard
elif mi.action == MouseButtonAction.mbaReleased:
gotoXY(terminalHeight(),terminalWidth()-20); stdout.write fmt"{mi.x},{mi.y}"
gotoXY(mi.x,mi.y)
#--------------
# def Label
#--------------
of TKey.altL:
getCursor(X , Y)
if X < minX or X > maxX or Y < minY or Y > maxY :
gotoXY(minX,minY)
continue
labelDef(1)
#--------------
# def Label majuscule
#--------------
of TKey.altT:
getCursor(X , Y)
if X < minX or X > maxX or Y < minY or Y > maxY :
gotoXY(minX,minY)
continue
labelDef(2)
#--------------
# def menu
#--------------
of TKey.altM:
getCursor(X , Y)
if X < minX or X > maxX or Y < minY or Y > maxY :
gotoXY(minX,minY)
continue
writeMenu(callMenu(ZMENU))
setTerminal()
printPanel(detail)
gotoXY(1,1)
onMouse()
#--------------
# def Grid
#--------------
of TKey.altG:
getCursor(X , Y)
if X < minX or X > maxX or Y < minY or Y > maxY :
gotoXY(minX,minY)
continue
SX = X
SY = Y
offMouse()
#clsPanel(pmenu)
gotoXY(terminalHeight(),terminalWidth()-20); stdout.write " "
gotoXY(terminalHeight(),terminalWidth()-20); stdout.write "GRID "
gridDef($base[PanelWork].name)
setTerminal()
printPanel(detail)
gotoXY(1,1)
onMouse()
# print screen full MENU
of TKey.altP:
if len(ZMENU) > 0 :
Dspmnu = new(MENU)
for n in 0..<len(ZMENU):
Dspmnu = newMenu(ZMENU[n].name,ZMENU[n].posx,ZMENU[n].posy,ZMENU[n].orientation,ZMENU[n].item,ZMENU[n].cadre)
dspMenuItem(detail,Dspmnu)
gotoXY(1,1)
onMouse()
#--------------
# def field
#--------------
of TKey.altF:
getCursor(X,Y)
if X < minX or X > maxX or Y < minY or Y > maxY :
gotoXY(minX,minY)
continue
fieldDef(callField(detail))
#--------------
# select Display LABEL / FIELD / MENU
#--------------
of TKey.altD:
printMenu(detail,mnuOrder)
nchx = ioMenu(detail,mnuOrder,0)
case nchx :
of 0 :
restorePanel(detail,mnuOrder)
onMouse()
onCursor()
continue
of 1 :
Zgrid = newGrid("GRID01",1,1,20)
var Cell_idl = defCell("ID",3,DIGIT)
var Cell_namel = defCell("Name",10,TEXT_FREE,cellYellow)
var Cell_posxl = defCell("PosX",4,DIGIT)
var Cell_posyl = defCell("PosY",4,DIGIT)
var Cell_textl = defCell("Text",30,TEXT_FREE)
var Cell_title = defCell("Title",5,SWITCH)
Cell_numIDx = - 1
setHeaders(Zgrid, @[Cell_idl, Cell_namel, Cell_posxl,Cell_posyl,Cell_textl,Cell_title])
for n in 0..len(base[PanelWork].label)-1:
addRows(Zgrid, @[setID(Cell_numIDx), getNameL(base[PanelWork],n), $getPosxL(base[PanelWork],n),$getPosyL(base[PanelWork],n),getTextL(base[PanelWork],n),$isTitle(base[PanelWork],n)])
of 2:
Zgrid = newGrid("GRID01",1,2,20)
var Cell_idf = defCell("ID",3,DIGIT)
var Cell_namef = defCell("Name",15,TEXT_FREE,cellYellow)
var Cell_posxf = defCell("PosX",4,DIGIT)
var Cell_posyf = defCell("PosY",4,DIGIT)
var Cell_typef = defCell("Type",14,TEXT_FREE)
var Cell_lenf = defCell("len" ,4,DIGIT)
var Cell_scalf = defCell("scal",4,DIGIT)
var Cell_emptyf = defCell("empty",5,SWITCH)
var Cell_processf = defCell("process",15,TEXT_FREE)
Cell_numIDx = - 1
setHeaders(Zgrid, @[Cell_idf, Cell_namef, Cell_posxf, Cell_posyf, Cell_typef, Cell_lenf, Cell_scalf, Cell_emptyf, Cell_processf])
for n in 0..len(base[PanelWork].field)-1:
addRows(Zgrid, @[setID(Cell_numIDx), getName(base[PanelWork],n), $getPosx(base[PanelWork],n),$getPosyL(base[PanelWork],n),$getRefType(base[PanelWork],n) ,$getWidth(base[PanelWork],n) ,$getScal(base[PanelWork],n) ,$getEmpty(base[PanelWork],n) ,getProcess(base[PanelWork],n) ])
of 3:
Zgrid = newGrid("GRID01",1,2,20)
var Cell_idm = defCell("ID",3,DIGIT)
var Cell_namem = defCell("Name",10,TEXT_FREE,cellYellow)
var Cell_posxm = defCell("PosX",4,DIGIT)
var Cell_posym = defCell("PosY",4,DIGIT)
var Cell_typem = defCell("Type",14,TEXT_FREE)
Cell_numIDx = - 1
setHeaders(Zgrid, @[Cell_idm, Cell_namem, Cell_posxm, Cell_posym, Cell_typem])
for n in 0..len(ZMENU)-1:
addRows(Zgrid, @[setID(Cell_numIDx), ZMENU[n].name, $ZMENU[n].posx, $ZMENU[n].posy, $ZMENU[n].orientation])
else : discard
# printGridHeader and printGridRows = not call proc oGrid(...)
printGridHeader(Zgrid)
printGridRows(Zgrid)
while true :
offCursor()
key = getFunc()
case key
of TKey.Escape :
setTerminal()
clsPanel(detail)
printPanel(detail)
onMouse()
onCursor()
gotoXY(minX,minY)
resetGrid(Zgrid)
break
of TKey.PageUp :
keyG = pageUpGrid(Zgrid)
if keyG == TKey_Grid.PGup:
gotoXY(terminalHeight(),terminalWidth()-20); stdout.write "Prior"
else:
gotoXY(terminalHeight(),terminalWidth()-20); stdout.write "Home "
of TKey.PageDown :
keyG = pageDownGrid(Zgrid)
if keyG == TKey_Grid.PGdown:
gotoXY(terminalHeight(),terminalWidth()-20); stdout.write "Next "
else:
gotoXY(terminalHeight(),terminalWidth()-20); stdout.write "End "
else : discard
#--------------
# select order
#--------------
of TKey.altO:
offMouse()
setTerminal()
printMenu(detail,mnuOrder)
nchx = ioMenu(detail,mnuOrder,0)
case nchx :
of 1 : orderLabel()
of 2 : orderField()
else : discard
setTerminal()
clsPanel(detail)
printPanel(detail)
gotoXY(minX,minY)
onCursor()
onMouse()
#--------------
# select remove
#--------------
of TKey.altR:
offMouse()
setTerminal()
printMenu(detail,mnuRmv)
nchx = ioMenu(detail,mnuRmv,0)
case nchx
of 1 : rmvLabel()
of 2 : rmvField()
of 3 : rmvMenu()
of 4 : rmvGrid($base[PanelWork].name)
else : discard
setTerminal()
clsPanel(detail)
printPanel(detail)
gotoXY(minX,minY)
onCursor()
onMouse()
#--------------
# select display terminal
#--------------
of TKey.altS:
offMouse()
setTerminal()
printPanel(detail)
gotoXY(minX,minY)
onCursor()
onMouse()
else : discard
#--------------
# write source for pgm
#--------------
if nPnl == 3 :
var nLine = newSeq[string]()
let f = open("Source.nim", fmWrite)
var nbr : bool = false
var v_empty : string
var zone: string
var zoneButton : string
var nbrButton : bool
var btn : BUTTON
var zoneItem :string
nLine.add("import termkey")
nLine.add("import termcurs")
if len(NSFILE) > 0 :
for n in 0..<len(NSFILE):
if NSFILE[n].form == "combo" :
nLine.add(fmt"import tables")
nLine.add(fmt"")
nLine.add(fmt"")
nLine.add(fmt"var callQuery: Table[string, proc(fld : var FIELD)]")
break
nLine.add(fmt"")
for nP in 1..len(base) - 1:
if len(base[nP].field) > 0 :
nLine.add(fmt"")
nLine.add(fmt"type")
zone=" FIELD_" & getPnlName(base[nP]) & " {.pure.}= enum"
nLine.add(zone)
for n in 0..len(base[nP].field) - 1:
nbr= true
if n < len(base[nP].field)-1 : nLine.add(fmt" {getName(base[nP],n)},")
else: nLine.add(fmt" {getName(base[nP],n)}")
if nbr:
zone = fmt"const P{nP}: array[FIELD_{getPnlName(base[nP])}, int] = ["
for n in 0..len(base[nP].field) - 1:
if n < len(base[nP].field)-1 :zone = fmt"{zone}{n},"
else : zone = fmt"{zone}{n}]"
nLine.add(zone)
# write global procédure
if len(ZMENU) > 0 :
nLine.add(fmt"")
nLine.add(fmt"")
nLine.add(fmt"# MENU -> TEST")
for n in 0..<len(ZMENU):
nLine.add(fmt"""var {ZMENU[n].name} = new(MENU)""")
nLine.add(fmt"""{ZMENU[n].name} = newMenu("{ZMENU[n].name}", {ZMENU[n].posx}, {ZMENU[n].posy}, {ZMENU[n].orientation}, {ZMENU[n].item}, {ZMENU[n].cadre})""")
nLine.add(fmt"")
for nP in 1..len(base) - 1:
nbr = false
zoneButton = ""
for i in 0..len(base[nP].button) - 1 :
nbrButton = true
btn = base[nP].button[i]
if i == 0 : zoneButton = fmt"""@[defButton(TKey.{$btn.key},"{btn.text}",{btn.ctrl},{btn.isActif})"""
else: zoneButton = fmt"""{zoneButton}, defButton(TKey.{$btn.key},"{btn.text}",{btn.ctrl},{btn.isActif})"""
if nbrButton : zoneButton = fmt"{zoneButton}]"
nLine.add(fmt"")
nLine.add(fmt"# Panel {getPnlName(base[nP])}")
nLine.add(fmt"")
nLine.add(fmt"var {getPnlName(base[nP])}= new(PANEL)")
nLine.add(fmt"")
nLine.add(fmt"# description")
nLine.add(fmt"proc dsc{getPnlName(base[nP])}() = ")
nLine.add(fmt""" {getPnlName(base[nP])} = newPanel("{getPnlName(base[nP])}",{base[nP].posx},{base[nP].posy},{base[nP].lines},{base[nP].cols},{zoneButton},{base[nP].cadre},"{getPnlTitle(base[nP])}")""")
if len(base[nP].label) > 0 :
nLine.add(fmt"")
nLine.add(fmt" # LABEL -> {getPnlName(base[nP])}")
nLine.add(fmt"")
# label
for n in 0..len(base[nP].label) - 1:
if isTitle(base[nP], n) :
nLine.add(fmt""" {getPnlName(base[nP])}.label.add(defTitle("{getNameL(base[nP],n)}", {$getPosxL(base[nP],n)}, {$getPosyL(base[nP],n)}, "{getTextL(base[nP],n)}"))""")
else :
nLine.add(fmt""" {getPnlName(base[nP])}.label.add(deflabel("{getNameL(base[nP],n)}", {$getPosxL(base[nP],n)}, {$getPosyL(base[nP],n)}, "{getTextL(base[nP],n)}"))""")
#--------------------
if len(base[nP].field) > 0 :
nLine.add(fmt"")
nLine.add(fmt" # FIELD -> {getPnlName(base[nP])}")
nLine.add(fmt"")
# field
for n in 0..len(base[nP].field) - 1:
if getEmpty(base[nP],n) : v_empty = "EMPTY" else: v_empty = "FILL"
case getRefType(base[nP],n)
of ALPHA, ALPHA_UPPER,ALPHA_NUMERIC,ALPHA_NUMERIC_UPPER, TEXT_FREE, TEXT_FULL, PASSWORD, YES_NO, FPROC, FCALL:
nLine.add(fmt""" {getPnlName(base[nP])}.field.add(defString("{getName(base[nP],n)}", {$getPosx(base[nP],n)}, {$getPosy(base[nP],n)}, {$getRefType(base[nP],n)},{$getWidth(base[nP],n)},"", {v_empty}, "{getErrmsg(base[nP],n)}","{getHelp(base[nP],n)}"))""")
of DIGIT , DIGIT_SIGNED , DECIMAL, DECIMAL_SIGNED :
nLine.add(fmt""" {getPnlName(base[nP])}.field.add(defNumeric("{getName(base[nP],n)}", {$getPosx(base[nP],n)}, {$getPosy(base[nP],n)}, {$getRefType(base[nP],n)},{$getWidth(base[nP],n)},{$getScal(base[nP],n)},"", {v_empty},"{getErrmsg(base[nP],n)}", "{getHelp(base[nP],n)}"))""")
of TELEPHONE:
nLine.add(fmt""" {getPnlName(base[nP])}.field.add(defTelephone("{getName(base[nP],n)}", {$getPosx(base[nP],n)}, {$getPosy(base[nP],n)}, {$getRefType(base[nP],n)},{$getWidth(base[nP],n)},"", {v_empty}, "{getErrmsg(base[nP],n)}", "{getHelp(base[nP],n)}"))""")
of DATE_ISO, DATE_FR, DATE_US:
nLine.add(fmt""" {getPnlName(base[nP])}.field.add(defDate("{getName(base[nP],n)}", {$getPosx(base[nP],n)}, {$getPosy(base[nP],n)}, {$getRefType(base[nP],n)},"", {v_empty}, "{getErrmsg(base[nP],n)}", "{getHelp(base[nP],n)}"))""")
of MAIL_ISO:
nLine.add(fmt""" {getPnlName(base[nP])}.field.add(defMail("{getName(base[nP],n)}", {$getPosx(base[nP],n)}, {$getPosy(base[nP],n)}, {$getRefType(base[nP],n)},{$getWidth(base[nP],n)},"", {v_empty}, "{getErrmsg(base[nP],n)}", "{getHelp(base[nP],n)}"))""")
of SWITCH :
nLine.add(fmt""" {getPnlName(base[nP])}.field.add(defSwitch("{getName(base[nP],n)}", {$getPosx(base[nP],n)}, {$getPosy(base[nP],n)}, {$getRefType(base[nP],n)}, false, {v_empty}, "{getErrmsg(base[nP],n)}", "{getHelp(base[nP],n)}"))""")
if getEdtcar(base[nP],n) != "" :
nLine.add(fmt""" setEdtCar({getPnlName(base[nP])}.field[P{nP}[{getName(base[nP],n)}]], "{getEdtcar(base[nP],n)}")""")
if isProtect(base[nP].field[n]) :
nLine.add(fmt""" setProtect({getPnlName(base[nP])}.field[P{nP}[{getName(base[nP],n)}]],true)""")
if isProcess(base[nP],n) :
nLine.add(fmt""" setProcess({getPnlName(base[nP])}.field[P{nP}[{getName(base[nP],n)}]],"{getProcess(base[nP],n)}")""")
#-------------------- End Field
#-------------------------------------------------
# Sous-fichier combo
#-------------------------------------------------
if len(NSFILE) > 0 :
nLine.add(fmt"")
nLine.add(fmt"")
for n in 0..<len(NSFILE):
if NSFILE[n].form == "combo" and NSFILE[n].panel == getPnlName(base[nP]):
nLine.add(fmt"#===================================================")
nLine.add(fmt"proc { NSFILE[n].name}(fld : var FIELD) =")
nLine.add(fmt" var Cell_pos : int = -1")
nLine.add(fmt""" var Xcombo = newGRID("{NSFILE[n].name}",{NSFILE[n].posx},{NSFILE[n].posy},{NSFILE[n].nrow},{NSFILE[n].sep}) """)
for i in 0..len(NSFILE[n].defcell)-1 :
nLine.add(fmt""" var Cell_{NSFILE[n].defcell[i].text} = defCell("{NSFILE[n].defcell[i].text}",{NSFILE[n].defcell[i].long},{NSFILE[n].defcell[i].reftyp},"{NSFILE[n].defcell[i].cellatr}") """)
if NSFILE[n].defcell[i].edtcar > "" :
nLine.add(fmt""" setCellEditCar(Cell_{NSFILE[n].defcell[i].text},"{NSFILE[n].defcell[i].edtcar}")""")
zoneItem = ""
for i in 0..len(NSFILE[n].defcell)-1 :
var u : int
if u < i : zoneItem = fmt"{zoneItem} ,"
zoneItem = fmt"{zoneItem}Cell_{NSFILE[n].defcell[i].text}"
inc(u)
nLine.add(fmt" setHeaders(Xcombo, @[{zoneItem}])")
for i in 0..len(NSFILE[n].citem)-1 :
zoneItem = ""
var u : int = 0
for k in 0..len(NSFILE[n].defcell)-1 :
if u < k : zoneItem = fmt"{zoneItem},"
zoneItem = fmt""" {zoneItem}"{NSFILE[n].citem[i][k]}" """
nLine.add(fmt" addRows(Xcombo, @[{zoneItem}])")
nLine.add(fmt"")
nLine.add(fmt" case fld.text")
for i in 0..len(NSFILE[n].citem)-1 :
nLine.add(fmt""" of "{$NSFILE[n].citem[i][0]}" : Cell_pos = {i} """)
nLine.add(fmt" else : discard")
nLine.add(fmt"")
nLine.add(fmt" while true :")
nLine.add(fmt" let (keys, val) = ioGrid(Xcombo,Cell_pos)")
nLine.add(fmt" case keys")
nLine.add(fmt" of TKey.Enter :")
nLine.add(fmt" restorePanel({$NSFILE[n].panel},Xcombo)")
nLine.add(fmt" fld.text = $val[0]")
nLine.add(fmt" break")
nLine.add(fmt" else: discard")
nLine.add(fmt"")
nLine.add(fmt"""callQuery["{NSFILE[n].name}"] = {NSFILE[n].name} """)
nLine.add(fmt"#===================================================")
nLine.add(fmt"")
#-------------------------------------------------
# Sous-fichier combo
#-------------------------------------------------
if len(NSFILE) > 0 :
nLine.add(fmt"")
nLine.add(fmt"")
for n in 0..<len(NSFILE):
if NSFILE[n].form == "grid" and NSFILE[n].panel == getPnlName(base[nP]):
nLine.add(fmt"var G{NSFILE[n].name}: GRIDSFL")
for n in 0..<len(NSFILE):
if NSFILE[n].form == "grid" and NSFILE[n].panel == getPnlName(base[nP]):
nLine.add(fmt"#===================================================")
nLine.add(fmt"proc { NSFILE[n].name}() =")
nLine.add(fmt""" G{NSFILE[n].name} = newGRID("{NSFILE[n].name}",{NSFILE[n].posx},{NSFILE[n].posy},{NSFILE[n].nrow},{NSFILE[n].sep}) """)
for i in 0..len(NSFILE[n].defcell)-1 :
nLine.add(fmt""" var Cell_{NSFILE[n].defcell[i].text} = defCell("{NSFILE[n].defcell[i].text}",{NSFILE[n].defcell[i].long},{NSFILE[n].defcell[i].reftyp},"{NSFILE[n].defcell[i].cellatr}") """)
if NSFILE[n].defcell[i].edtcar > "" :
nLine.add(fmt""" setCellEditCar(Cell_{NSFILE[n].defcell[i].text},"{NSFILE[n].defcell[i].edtcar}")""")
zoneItem = ""
for i in 0..len(NSFILE[n].defcell)-1 :
var u : int
if u < i : zoneItem = fmt"{zoneItem} ,"
zoneItem = fmt"{zoneItem}Cell_{NSFILE[n].defcell[i].text}"
inc(u)
nLine.add(fmt" setHeaders(G{NSFILE[n].name}, @[{zoneItem}])")
nLine.add(fmt"#===================================================")
nLine.add(fmt"")
nLine.add(fmt"")
nLine.add(fmt"proc main() =")
nLine.add(fmt" initTerm({base[1].lines},{base[1].cols})") # initTerm() = terminal
nLine.add(fmt"")
for nP in 1..len(base) - 1:
nLine.add(fmt" dsc{getPnlName(base[nP])}()")
nLine.add(fmt" printPanel({getPnlName(base[nP])})")
nLine.add(fmt" displayPanel({getPnlName(base[nP])})")
if len(ZMENU) > 0 :
nLine.add(fmt"")
nLine.add(fmt" # ONLY -> FOR TEST")
for n in 0..<len(ZMENU):
nLine.add(fmt" dspMenuItem({getPnlName(base[nP])},{ZMENU[n].name},0)")
nLine.add(fmt" let nTest = ioMenu({getPnlName(base[nP])},{ZMENU[len(ZMENU)-1].name},0)")
nLine.add(fmt"")
nLine.add(fmt"")
nLine.add(fmt" #Exemple ------")
nLine.add(fmt"")
nLine.add(fmt" while true:")
nLine.add(fmt" let key = ioPanel({getPnlName(base[nP])})")
nLine.add(fmt" case key")
for n in 0..len(base[nP].field) - 1:
if isProcess(base[nP],n) and getReftype(base[nP],n) == FPROC :
nLine.add(fmt" of TKey.PROC : # for field Process")
nLine.add(fmt" if isProcess({getPnlName(base[nP])},Index({getPnlName(base[nP])})):")
nLine.add(fmt" callQuery[getProcess({getPnlName(base[nP])},Index({getPnlName(base[nP])}))]({getPnlName(base[nP])}.field[Index({getPnlName(base[nP])})])")
break
for n in 0..len(base[nP].field) - 1:
if isProcess(base[nP],n) and getReftype(base[nP],n) == FCALL :
nLine.add(fmt" of TKey.CALL : # for field Process ex:")
nLine.add(fmt" if isProcess({getPnlName(base[nP])},Index({getPnlName(base[nP])})):")
nLine.add(fmt""" if getProcess({getPnlName(base[nP])},Index({getPnlName(base[nP])})) == "{getProcess(base[nP],n)}":""")
nLine.add(fmt" {getProcess(base[nP],n)}()")
break
nbrButton = false
for i in 0..len(base[nP].button) - 1:
nbrButton = true
btn = base[nP].button[i]
nLine.add(fmt" of TKey.{$btn.key}:")
nLine.add(fmt" break")
if nbrButton :
nLine.add(fmt" else : discard")
nLine.add(fmt"")
nLine.add(fmt" closeTerm()")
nLine.add(fmt"")
nLine.add(fmt"")
nLine.add(fmt"")
nLine.add(fmt"main()")
for Tline in nLine:
f.writeLine(Tline)
f.close()
nPnl = 0
# write File .dspf
jsonFile()
setTerminal()
break
#