-
Notifications
You must be signed in to change notification settings - Fork 2
/
MAGETABL.c
1235 lines (1126 loc) · 48.6 KB
/
MAGETABL.c
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
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*3456789_123456789_123456789_123456789_123456789_123456789_123456789_12345678*/
/*MAGETABL.c*/
#include "MAGE.h"
#include "MAGEFLAG.h"
#include "MAGELIST.h"
#include "MAGEBBOX.h"
#define MAGETABL
#include "MAGETABL.h"
#undef MAGETABL
#define tablepick(i,j) tablepick[i*(MAXCOL+1)+j] /*pointer arithmetic*/
#define tablepointptr(i,j) tablepointptr[i*(MAXCOL+1)+j]
#define tablecolwide(j) tablecolwide[j]
#define tablerowhigh(j) tablerowhigh[j]
static pointstructptr* tablepointptr;
static int* tablerowhigh; /*will get alloc as an array of MAXROW items*/
static int* tablecolwide; /*will get alloc as an array of MAXCOL items*/
static int* tablepick;
static pointstruct* savedvictimptr = NULL; /*last deleted point */
/*beware, if try to destroy this point after alloc, parent list NULL or wierd*/
int scantableforpick(pointstructptr*); /*MAGETABL.c*/
void freetablearrays(void);
static pointstruct* tablesearchrefpointptr = NULL;
/*Like everything else in mage and the kinemage format, there is great */
/*flexibility despite arbitrary limitations based on original intended use, */
/* and no effective protection against the kinemage author/reader from making */
/*totally obscure and meaningless kinemages. However, for good or ill, */
/*MAGE remains ignorant of any particular subject of science, like molecules. */
/*Good luck! */
/****drawtable()***************************************************************/
void drawtable(int ipass)
{/*can only get here called from ____DRAW.c/redrawtable(): SetPort(tableWindow) */
/*EXCEPT on first setup called from createtable to get actual row and col sizes*/
/*Ltablepicked flags table initiated pick, set here, used in MAGEDRAW.c/drawvec()*/
/*Ltablegraphpicked flags graph initiated pick, set by graphic, used here*/
/*both of these flags are used for both discovery and final show passes */
/*Ltablepicked managed by DotableContentClick()*/
/*Ltablegraphpicked managed by redrawtable()*/
int rowstack = 0;
int lasty = 0;
int row = 0;
int col = 0;
int colleft = 0;
int colx = 0;
int wraps = 0;
int rowy = 0;
int cellx = 0;
int celly = 0;
int color = 0;
int icolor = 0;
int bcolor = 0;
int idecue = 0;
int ideepcolor = 0;
pointstructptr currentpointptr = NULL;
int Lcellpicked = 0;
int Lthiscellpicked = 0;
int i,j;
int trialrowhigh = 0;
int maxx = 0;
int maxy = 0;
int Nrowpicked = -1;
int Ncolpicked = -1;
int Lneedcolornumber = 0, numcolor = 0;
/*calc the height of the set of rows to be shown*/
/*rowlast, collast are the max row,col numbers read in for this kinemage*/
for(row=0; row<= MAXROW; row++)
{
if( (row==0 && (tablewrapcol >= tableheaderMAXCOL) ) )
{
;/*don't include row0 in rowstack*/
}
else
{
/*ipass INITIAL determines height of rows*/
rowstack = rowstack + tablerowhigh[row];
}
}
rowy = tablezerohigh; /*starting position in absolute coordinates*/
/*keep setting actual table sizes as they are determined*/
/*loop over all table items*/
for(row = 0; row <= MAXROW; row++)
{/*loop over rows, the y, vertical, direction*/
colx = tablezerowide; /*scroll bar sets effective zero of coordinates*/
colleft = 0;
wraps = 0; /*start of new row, is in first set of a stack of rows*/
tablerowheight = tablerowhigh[row]; /*global value of latest row height*/
/*set y position after the row since use upper left of cell for point*/
for(col = 0; col <= MAXCOL; col++)
{/*loop over columns, the x, horizontal, direction*/
if(tablewrapcol && ((col) > (colleft + tablewrapcol )) )
{/*more columns than desired horizontally, wrap them*/
colleft = colleft + tablewrapcol;
wraps++;
/*wraped lines start under col(1)*/
colx = tablezerowide + tablecolwide(0);
}
/*colx is augmented by the column width after cell is written*/
cellx = colx; /*index point at upper left of cell*/
celly = rowy + wraps * rowstack;
tablecolwidth = tablecolwide[col]; /*global value of latest col width*/
/*retrieve the kinemage data point that is associated with this cell*/
currentpointptr = tablepointptr(row,col);
if(currentpointptr != NULL)
{/*cell has designated contents to be put in the table*/
if( (currentpointptr->type & UNPICKABLE)==0 || Lsuperpick||col==0||row==0)/*000324*/
{/*pickable cell*/
if(Ltablepicked == 0 && Ltablegraphpicked==3)
{/*3: graphics call from displayed table object: match pickedpointptr*/
if(pickedpointptr==currentpointptr)
{/*graphics copy of this point has been picked*/
/*only expect one such pick per pass, reset flag now*/
Ltablegraphpicked=1; /*1 for another pass to show all current picks*/
Lthiscellpicked = 1;
}
}
else if(Ltablepicked == 0 && Ltablegraphpicked==2)
{/*2: arbitrary graphics point has been picked, */
/*this can flag more than one table cell*/
if( pickedpointptr->fx == currentpointptr->fx
&& pickedpointptr->fy == currentpointptr->fy
&& pickedpointptr->fz == currentpointptr->fz )
{
/*could be more than one such pick per pass, DO NOT reset flag now*/
/*Ltablegraphpicked left ==2, */
/*later: set 1 for another pass to show all current picks*/
Lthiscellpicked = 1;
}
}
else if( Ltablepicked == 2
&& tablepickx >= cellx && tablepickx <= cellx + tablecolwide(col)
&& tablepicky >= celly && tablepicky <= celly + tablerowhigh(row))
{/*table cell has been picked*/
if(col==0 && row==0) /*000324*/
{
;
}
else if(col==0) /*000324*/
{
/*zeroth cell picked when OFF, turns row ON*/
if( tablepick(row,col) == 0) Nrowpicked = row; /*010916*/
/*zeroth cell picked when ON, turns row OFF*/
else Nrowpicked = -1; /*010916*/
Lthiscellpicked = 1; /*010916*/
Ltablecellnewlypicked = 1;
Ltablepicked = 1; /* 1 for another pass to show all current picks*/
}
else if(row==0) /*000324*/
{
/*zeroth cell picked when OFF, turns column ON*/
if( tablepick(row,col) == 0) Ncolpicked = col; /*010916*/
/*zeroth cell picked when ON, turns column OFF*/
else Ncolpicked = -1; /*010916*/
Lthiscellpicked = 1; /*010916*/
Ltablecellnewlypicked = 1;
Ltablepicked = 1; /* 1 for another pass to show all current picks*/
}
else
{
if( tablepick(row,col) == 0)
{/*pick of previously NOT-picked cell (else will toggle it to not-picked)*/
Ltablecellnewlypicked = 1;
pickedpointptr = currentpointptr;
pickedlistptr = currentpointptr->listptr;
pickedsgrpptr = pickedlistptr->sgrpptr; /*for safety of completeness*/
pickedgrupptr = pickedsgrpptr->grupptr; /*for safety of completeness*/
}
/*only allow one such positional pick per pass, reset flag now*/
Ltablepicked = 1; /* 1 for another pass to show all current picks*/
Lthiscellpicked = 1;
} /*000324*/
}
if(col>0 && Nrowpicked == row)/*000324*/
{
Lthiscellpicked = 1;
}
else if(row>0 && Ncolpicked == col)/*000324*/
{
Lthiscellpicked = 1;
}
if(Lthiscellpicked > 0)
{/*this cell is picked*/
Lthiscellpicked = 0; /*just for this cell*/
Lcellpicked++;
/*toggle pick state of this cell*/
if(tablepick(row,col) == 0)
{
tablepick(row,col) = 1;
}
else if(Nrowpicked != row && Ncolpicked != col)/*000324*/
{
tablepick(row,col) = 0;
}
/*problem Lshiftkey: */
/*shifted state has special, wierd meaning for graphics picking*/
if(row!=0 && col!=0 && !Lshiftkey && Lcellpicked==1 && tablepick(row,col) == 1)
{/*first ordinary cell picked this pass, wipe out all previous pickstates*/
for(i=0; i<= MAXROW; i++) /*i.e. MAXROW+1 entries including 0*/
for(j=0; j<= MAXCOL; j++) /*i.e. MAXCOL+1 entries including 0*/
if(i==row && j==col) ;
else tablepick(i,j) = 0;
}
if(row==0 && col!=0 && (Lcellpicked==1 && tablepick(row,col) == 0))
{/*zeroth row toggled OFF turns OFF whole column*/
for(i=0; i<= MAXROW; i++) /*i.e. MAXROW+1 entries including 0*/
for(j=0; j<= MAXCOL; j++) /*i.e. MAXCOL+1 entries including 0*/
if(j==col) tablepick(i,j) = 0;
}
if(row!=0 && col==0 && (Lcellpicked==1 && tablepick(row,col) == 0))
{/*zeroth col toggled OFF turns OFF whole row*/
for(i=0; i<= MAXROW; i++) /*i.e. MAXROW+1 entries including 0*/
for(j=0; j<= MAXCOL; j++) /*i.e. MAXCOL+1 entries including 0*/
if(i==row) tablepick(i,j) = 0;
}
}/*this cell is picked*/
}/*pickable cell*/
/*getptIDstring(word, currentpointptr);*/
/*word char str stored in pointstruct pointed to by tablepointptr*/
getcommentstring(word, currentpointptr);/*MAGELIST gets wordcom[]*/
/* note: 3 byte format info on front of string*/
/*as of 991008 only use color, not type, depthcue, penwidth of a point*/
/*table entries are all of one type: label: where pointID --> cell*/
/*penwidth is not used for the font*/
/*depthcue modification of color is used for highlighting*/
/*(later might use background color for highlighting also)*/
/*However, there is the option of list color and point color*/
Lneedcolornumber = 1;
if( naspectsthiskinemage > 0 /*there are aspects possible*/
&& currentaspect > 0 /*an aspect is selected*/
&& currentaspect <= MAXPOINTASPECTS /*point storage limited*/
)
{/*aspect color dominant*/
numcolor = decodecolor(currentpointptr->aspects,currentaspect);
if(numcolor > 0 && numcolor < 32)
{/*renderer can translate colornumber to palette index*/
color=((numcolor&31) | ((currentpointptr->colorwidth) & ~31));/*121108 (logic)*/
/*~31: one's complement of 31, i.e. bits 1->0,0->1*/
/*i.e. include everything except color code*/
Lneedcolornumber = 0;
}
}/*aspect color dominant*/
if(Lneedcolornumber)
{/*NOT aspect color, try for point color, then try list color*/
if( ((currentpointptr->colorwidth) & 31) > 0)
{/*point has its own color*/
if(Listcolordominant)
{/*do not use this point's color*/
color = ((currentpointptr->listptr)->color & 31);
}
else
{color = ((currentpointptr->colorwidth) & 31);}
}/*point has its own color*/
else {color = ((currentpointptr->listptr)->color & 31);}
}/*NOT aspect color, try for point color, then try list color*/
/*idecue = 0; for black bkg palette*/
/*idecue =25; for white bkg palette*/
/*ideepcolor = 0; for furthest back to background*/
/*ideepcolor = 4; for nearest-to-front color hue and saturation*/
/*depthcue 1-5 used as ideepcolor 0-4*/
if(tablepick(row,col) == 1)
{/*make colored background in cell*/
/*bcolor = numberofcolor("gray");*/ /*MAGECOLR.c*/
bcolor = numberofcolor("white"); /*MAGECOLR.c*/
/*use gray or less saturated of same color ????*/
/*ideepcolor = 4;*/ /*0 far from viewer, to 4 close to viewer*/
ideepcolor = 2; /*0 far from viewer, to 4 close to viewer*/
if(Ltableblackbkg)
{
idecue = 0; /*for black bkg palette*/
}
else
{
idecue = 25; /*for white bkg palette*/
}
if(LLcolor) /*can support real color*/
{/*use depthque bin selected for highlight property*/
bcolor = (bcolor & 31) + 50*ideepcolor + idecue;
}/*the "& 31" is a final sanity filter limit for valid color values*/
else
{/*fudge gray level by explicit "depthcue"*/
bcolor= numberofcolor("gray") + 50*ideepcolor +idecue;
}
/*
rectangletoscreen(cellx, celly
, cellx + tablecolwide(col), celly + tablerowhigh(row), bcolor);
*/
Ltablecellispicked = 1;
currentpointptr->STATUS = currentpointptr->STATUS | ON;/*ON*/
/*000324 pick state of cell sets ON/OFF of putative graphics point*/
}
else
{/*000324 pick state of cell sets ON/OFF of putative graphics point*/
Ltablecellispicked = 0;
currentpointptr->STATUS = currentpointptr->STATUS & ~ON; /*OFF*/
}
/*Now write cell characters to the table*/
/*color >= 0 && color <= 255 is pretty robust, don't bother to check*/
if(color == 31 && ipass > 0)
{/*invisible and not checking col 1 of row 1 for actual drawn width*/
icolor = -1;
}
else
{/*visible color value*/
ideepcolor = 4;
if(Ltableblackbkg)
{
idecue = 0; /*for black bkg palette*/
}
else
{
idecue = 25; /*for white bkg palette*/
}
if(LLcolor) /*can support real color*/
{/*use depthque bin selected for foreground*/
icolor = (color & 31) + 50*ideepcolor + idecue;
}/*the "& 31" is a final sanity filter limit for valid color values*/
else
{/*fudge gray level by explicit "depthcue"*/
icolor= numberofcolor("gray") + 50*ideepcolor +idecue;
}
}/*visible color value*/
if( (ipass == 0) && (row==1) && (col==0||col==1) )
/*if( (ipass == 0) && (row==0) && (col==0||col==1) )*/ /*000324*/
{
Ltablecellgetwidth = 1;
}
else
{
Ltablecellgetwidth = 0;
}
if(ipass == 0 || ipass == 1 || (ipass == 2 && tablepick(row,col) == 1) )
{/*actual call to draw contents in cell*/
/*only use bcolor when a pick is current, so bcolor is defined correctly*/
tablewordwidth = 0; /*so return with word witdth of this word itself*/
/*010916 linehigh == tablefontsize + 4*/
lasty = wordstotable(word,cellx,celly + tablefontsize
, icolor, bcolor, ipass );
/*____DRAW.C*/
/*lasty is max y of a character placed in the table*/
/*tablewordwidth == max string width on any one line of the word str*/
}
if(ipass==0 && row==0)
{/*pass==0 special processing of row 0*/
tableheaderMAXCOL = col;
}
}/*cell has designated contents*/
if(ipass==0 && row==1) /*see if can improve on default col widths, & row height*/
{/*pass==0 special processing of row 1, col 0 and 1 */
if(col==0 || col==1)
{
if(tablecolscale < 0.1 || tablecolscale > 100.1 ) { tablecolscale = 1.0;}
if(tablewordwidth > 0)
{
tablecolwide(col) = (int)(tablewordwidth * tablecolscale);
}
}
if(col==0)
{
if( (lasty - celly)>0) trialrowhigh = lasty - celly;
else trialrowhigh = 0;
}
else if(col==1)
{
if( (lasty - celly)>0 && (lasty - celly) >trialrowhigh)
tablerowhigh(1) = lasty - celly;
else if(trialrowhigh > 0)
tablerowhigh(1) = trialrowhigh;
}
}/*pass==0 special processing of row 1, col 0 and 1 */
/*set x position for the next cell*/
colx = colx + tablecolwide(col);
if(maxx < colx) maxx = colx;
}/*loop over columns, the x, horizontal, direction*/
/*now increase y for the next row of cells*/
rowy = rowy + tablerowhigh(row);
if(maxy < celly+tablerowhigh(row)) maxy = celly+tablerowhigh(row);
}/*loop over rows, the y, vertical, direction*/
if(Ltablepicked > 0 && Lcellpicked > 0)
Ltablepicked = 1; /*update pick state of graphics*/
/*Ltablepicked managed by DotableContentClick(), will be set to 0 when done*/
if(Ltablegraphpicked > 0 && Lcellpicked > 0)
Ltablegraphpicked = 1; /*update pick state of table*/
/*Ltablegraphpicked managed by redrawtable(), will be set to 0 when done*/
Lcellpicked = 0;/*redundant, local for new picks of current pass*/
/*table actually written between absolute coords tablezerowide to maxx*/
/* and tablezerohigh to maxy, where tablezeros can be negative*/
/* In absolute terms: */
tablehigh = maxy - tablezerohigh;
tablewide = maxx - tablezerowide;
if(ipass==0) {Ltableready = 1;}
}
/*___drawtable()______________________________________________________________*/
/****scantableforpick()********************************************************/
int scantableforpick(pointstructptr* apointptrptr)
{
int row = 0;
int col = 0;
int npicks = 0;
/*apointptr = NULL;*/
for(row = 0; row <= MAXROW; row++)
{/*loop over rows, the y, vertical, direction*/
for(col = 0; col <= MAXCOL; col++)
{/*loop over columns, the x, horizontal, direction*/
if(tablepick(row,col) == 1)
{/*cell is in picked state*/
*apointptrptr = tablepointptr(row,col);
if(*apointptrptr != NULL)
{/*picked cell is occupied*/
npicks = npicks + 1;
}/*picked cell is occupied*/
}/*cell is in picked state*/
}/*loop over columns, the x, horizontal, direction*/
}/*loop over rows, the y, vertical, direction*/
return(npicks); /*apointptr points to last picked point*/
}
/*___scantableforpick()_______________________________________________________*/
/****setuptable()**************************************************************/
void setuptable()
{
int j=0;
int left=0, top=0, right=0, bottom=0;
/*initial values, fit table into window. Can be changed by input or in run*/
gettablewinedges(&left, &top, &right, &bottom);
tablewindowhigh = bottom - top - 22;
tablewindowwide = right - left - 22;
tablezerohigh = 0; /*keeps track of scrolled effective top window place*/
tablezerowide = 0; /*keeps track of scrolled effective left window place*/
tablewordwidth = 0; /*keeps track of maximum width of table cells*/
tablehigh = 0;
/*if(tablerowhigh(0) == 0) tablerowhigh(0) = tablefontsize/2;*/
if(tablerowhigh(0) == 0) tablerowhigh(0) = tablefontsize;/*000324*/
tablehigh = tablehigh + tablerowhigh(0);
if(tablerowhigh(1) == 0) tablerowhigh(1) = tablefontsize;
tablehigh = tablehigh + tablerowhigh(1);
for(j=2; j<= MAXROW; j++) /*i.e. MAXROW+1 entries including 0*/
{
tablerowhigh(j) = tablerowhigh(1);
tablehigh = tablehigh + tablerowhigh(j);
}
if(Ltest)
printf("setuptable set values for tablerowhigh(0) %d\n",tablerowhigh(0));
if(Ltest)
printf("setuptable set values for tablerowhigh(1) %d\n",tablerowhigh(1));
tablewide = 0;
if(tablecolwide(0) == 0) tablecolwide(0) = 16;
tablewide = tablewide + tablecolwide(0);
if(tablecolwide(1) == 0) tablecolwide(1) = 32;
tablewide = tablewide + tablecolwide(1);
for(j=2; j<= MAXCOL; j++) /*i.e. MAXCOL+1 entries including 0*/
{
tablecolwide(j) = tablecolwide(1);
tablewide = tablewide + tablecolwide(j);
}
if(Ltest)
printf("setuptable set values for tablecolwide(0) %d\n",tablecolwide(0));
if(Ltest)
printf("setuptable set values for tablecolwide(1) %d\n",tablecolwide(1));
/*if(tablewrapcol ==0) table will not wrap, else wraps at the # columns*/
}
/*___setuptable()_____________________________________________________________*/
/****loadtable()***************************************************************/
void loadtable(int ipass)
{
int row = 0;
int col = 0;
int rowmax = 0;
int colmax = 0;
float angle = 0;
/*only called if Ltablepresent flag set for this kinemage*/
/*scan over all groups, etc.: future plans for embedded table info anywhere*/
row = 0;
thisgrupptr = firstgrupptr;
while(thisgrupptr != NULL)
{/*begin-loop-over-groups*/
if((thisgrupptr->type & TABLEFLAG) == TABLEFLAG) /*991009 only condition*/
{/*table group*/
if(row==0 && (thisgrupptr->type & TABLECOLHEAD) == TABLECOLHEAD)
{
row = 0; /*000324*/
Ltablecolheaders = 1; /*000324*/
}
else
{
row++;
}
/*get row,col assignment or set*/
if(row>rowmax) rowmax = row;
col = 0; /*each row starts with a zeroth col*/
thissgrpptr = thisgrupptr->firstsgrpptr;
while(thissgrpptr != NULL)
{/*begin-loop-over-sets*/
thislistptr = thissgrpptr->firstlistptr;
while(thislistptr != NULL)
{/*begin-loop-over-lists*/
/*if((thislistptr->type & WORDS) == WORDS)*/
{/*only can handle wordlists as of 991009*/
/*000324 treats anything like a wordlist crt setting table cells*/
thispointptr = thislistptr->firstpointptr;
while(thispointptr != NULL)
{/*begin-loop-of-points*/
if(ipass != 0) /*pass 0 just counts rows and columns*/
{/*regular flow, load the cell point pointer*/
/*turn all points OFF as far as graphics is concerned*/
thispointptr->STATUS = thispointptr->STATUS & ~ON; /*i.e. OFF*/
tablepointptr(row,col) = thispointptr;
/*establish any special characteristics of this point as a function*/
/*of position in the table*/
if((thispointptr->type & MARKTYPE)==MARKTYPE)
{/*special type of marks presented in graphics when cell picked*/
if((thispointptr->STYLE & FANSTYLE)==FANSTYLE)
{/*radial magnitude at row indexed postion in a fan shape*/
/*for now, just count rows, presume all have fan spines*/
angle = (float)(row*(180/(MAXROW+1)));/*line at angle degrees from 0*/
if(((thispointptr->moreinfoptr) = allocmoreinfostructure()) != NULL)
{
(thispointptr->moreinfoptr)->f1
= (float)cos((double)((2*3.14159)*angle/360));
(thispointptr->moreinfoptr)->f2
= (float)sin((double)((2*3.14159)*angle/360));
}
}/*radial magnitude at row indexed postion in a fan shape*/
}/*special type of marks presented in graphics when cell picked*/
}/*regular flow, load the cell point pointer*/
col++; /*augment for next entry*/
if(col>colmax) colmax = col;
if(thispointptr == thislistptr->lastpointptr)
thispointptr=NULL;
else thispointptr = thispointptr->nextptr;
}/*endof-draw-loop-of-points*/
}/*only can handle wordlists as of 991009*/
/*000324 treats anything like a wordlist crt setting table cells*/
if(thislistptr == thissgrpptr->lastlistptr) thislistptr=NULL;
else thislistptr = thislistptr->nextptr;
}/*endof-loop-over-lists*/
if(thissgrpptr == thisgrupptr->lastsgrpptr) thissgrpptr=NULL;
else thissgrpptr = thissgrpptr->nextptr;
}/*endof-loop-over-subgroups*/
}/*table group*/
thisgrupptr = thisgrupptr->nextptr;/*==NULL if last group*/
}/*endof-loop-over-groups*/
if(ipass==0)
{
MAXROW = rowmax;
MAXCOL = colmax;
if(Ltest)
printf("pass: %d: loadtable gets MAXROW %d, MAXCOL %d\n",ipass,MAXROW,MAXCOL);
}
}
/*____loadtable()_____________________________________________________________*/
/****createtable()*************************************************************/
void createtable()
{/*called when Ltablepresent > 1 when return from GetStuffFromFile()*/
Ltablepresent = 1; /*keep true, but don't construct more table windows*/
Ltablepicked = 0; /*initialize*/
Ltablepickactive = 0;
Ltablegraphpicked = 0;
Ltablegroupgraphed = 0;
/*compromise size, since font size NOT really correlated to window size*/
SetUptableWindow(); /*____INIT.c*/
constructtablecells();
createtablescrollbars(); /*separately done after window and cells defined*/
}
/*___createtable()____________________________________________________________*/
/****constructtablecells()*****************************************************/
void constructtablecells()
{
tableheaderMAXCOL = 0;
loadtable(0); /*first pass gets MAXROW, MAXCOL, nothing to load yet*/
alloctablearray(); /*using MAXROW, MAXCOL, so arrays for loading will exist*/
setuptable(); /*default sizes for table of MAXROW,MAXCOL, to display cells*/
loadtable(1); /*now can associate data points with table cells*/
dodrawtable(0); /*now can get actual row and col sizes from content*/
setuptable(); /*default sizes for table of MAXROW,MAXCOL, to display cells*/
dodrawtable(1); /*now can get actual row and col sizes from content*/
}
/*___constructtablecells()___________________________________________________*/
/****tablecelldelete()********************************************************/
void tablecelldelete(void)
{
pointstruct* victimptr = NULL; /*point picked*/
int npicks = 0; /*number of picks found*/
npicks = scantableforpick(&victimptr);
if(npicks == 1)
{/*found unique picked point*/
/*first set up to be able to undo destruction*/
if(savedvictimptr == NULL)
{
savedvictimptr = alloclonelypointstructure();
}
if(savedvictimptr != NULL)
{
copypointstructure(savedvictimptr, victimptr);
savedvictimptr->listptr = victimptr->listptr; /*020830 re MAGESCOR*/
/*so stored saved point knows who its original list is */
}
destroypointstructure(victimptr);
/*now rebuild table*/
freetablearrays(); /*first destroy the old table arrays, leaving window*/
/*then reconstruct the table as it is now defined by the kinemage groups*/
constructtablecells();
}/*found unique picked point*/
else
{
sprintf(alertstr,"Deletion NOT done, will only work if just one cell picked");
sprintf(alertstr2," Scan of table found %d cells flagged as picked",npicks);
sprintf(alertstr3," ");
DoMageDLOGreport(1); /*___DLOG.C*/ /*alertstr,alertstr2,alertstr3*/
}
}
/*___tablecelldelete()_______________________________________________________*/
/****restoredeletedpoint()****************************************************/
void restoredeletedpoint()
{
pointstruct* apointptr = NULL; /*point created*/
if(savedvictimptr != NULL)
{/*saved point exists*/
if(savedvictimptr->previousptr != NULL)
{/*can do insertion after a neighbor point*/
apointptr = insertpointstructure(savedvictimptr->previousptr, 1);
}
else if(savedvictimptr->nextptr != NULL)
{/*can do insertion before a neighbor point*/
apointptr = insertpointstructure(savedvictimptr->nextptr,-1);
}
else if(savedvictimptr->listptr != NULL)
{/*must have been last member of otherwise empty list*/
apointptr = allocpointstructure(savedvictimptr->listptr);
}
if(apointptr != NULL)
{/*restore point to table*/
copypointstructure(apointptr, savedvictimptr);
apointptr->listptr = savedvictimptr->listptr; /*020830 re MAGESCOR*/
/*so new recovered point knows its parent list*/
/*now rebuild table*/
freetablearrays(); /*first destroy the old table arrays, leaving window*/
/*then reconstruct the table as it is now defined by the kinemage groups*/
constructtablecells();
}
}/*saved point exists*/
else
{
sprintf(alertstr,"Restoration NOT done, did not find a saved point");
sprintf(alertstr2," ");
sprintf(alertstr3," ");
DoMageDLOGreport(1); /*___DLOG.C*/ /*alertstr,alertstr2,alertstr3*/
}
}
/*___restoredeletedpoint()___________________________________________________*/
/****tablecellinsert()********************************************************/
void tablecellinsert(int where)
{
pointstruct* victimptr = NULL; /*point picked*/
pointstruct* apointptr = NULL; /*point created*/
int npicks = 0; /*number of picks found*/
/*where > 0 for placing after picked cell, <= 0 for placing before*/
npicks = scantableforpick(&victimptr);
if(npicks == 1)
{/*found unique picked point*/
apointptr = insertpointstructure(victimptr, where);
if(apointptr != NULL)
{/*now rebuild table*/
freetablearrays(); /*first destroy the old table arrays, leaving window*/
/*then reconstruct the table as it is now defined by the kinemage groups*/
constructtablecells();
}
}/*found unique picked point*/
else
{
sprintf(alertstr,"Insertion NOT done, will only work if just one cell picked");
sprintf(alertstr2," Scan of table found %d cells flagged as picked",npicks);
sprintf(alertstr3," ");
DoMageDLOGreport(1); /*___DLOG.C*/ /*alertstr,alertstr2,alertstr3*/
}
}
/*___tablecellinsert()_______________________________________________________*/
/****tablerebuild()************************************************************/
void tablerebuild()
{
freetablearrays(); /*first destroy the old table arrays, leaving window*/
/*then reconstruct the table as it is now defined by the kinemage groups*/
constructtablecells();
}
/*___tablerebuild()___________________________________________________________*/
/****tablecolor()**************************************************************/
void tablecolor()
{
pointstruct* victimptr = NULL; /*point picked*/
int npicks = 0; /*number of picks found*/
/*where > 0 for placing after picked cell, <= 0 for placing before*/
npicks = scantableforpick(&victimptr);
if(npicks == 1)
{/*found unique picked point*/
pickedpointptr = victimptr;
pickedlistptr = victimptr->listptr;
pickedsgrpptr = pickedlistptr->sgrpptr; /*for safety of completeness*/
pickedgrupptr = pickedsgrpptr->grupptr; /*for safety of completeness*/
DocolorshowDialog(); /*operates on global pickedpointptr*/
}/*found unique picked point*/
}
/*tablecolor()______________________________________________________________*/
/****alloctablearray()*********************************************************/
void alloctablearray()
{/*one shot version of allocating pointptr array for this kinemage's table*/
int ifail;
int row,col;
ifail = 0;
if( (MAXROW*MAXCOL) < 0) ifail = 1; /*large number rolls to negative*/
if(ifail==0)
{/*still OK */
tablepointptr = (pointstructptr *)malloc(
sizeof(pointstructptr)*(MAXCOL+1)*(MAXROW+1));
if(tablepointptr==NULL) ifail = 1;
else
{
for(row=0; row<=MAXROW; row++) /*i.e. MAXROW+1 entries including 0*/
{
for(col = 0; col <= MAXCOL; col++)
{/*loop over columns, the x, horizontal, direction*/
tablepointptr(row,col) = NULL;
}/*loop over columns, the x, horizontal, direction*/
}
}
}
if(ifail==0)
{/*still OK */
tablepick = (int *)malloc(sizeof(int)*(MAXCOL+1)*(MAXROW+1));
if(tablepick==NULL) ifail = 1;
else
{
for(row=0; row<=MAXROW; row++)
{
for(col = 0; col <= MAXCOL; col++)
{/*loop over columns, the x, horizontal, direction*/
tablepick(row,col) = 0;
}/*loop over columns, the x, horizontal, direction*/
}
}
}
if(ifail==0)
{/*still OK */
tablerowhigh = (int *)malloc(sizeof(int)*(MAXROW+1));
if(tablerowhigh==NULL) ifail = 1;
else
{
for(row = 0; row <= MAXROW; row++)
{/*loop over rows, the y, vertical, direction*/
tablerowhigh(row) = 0;
}
}
}
if(ifail==0)
{/*still OK */
tablecolwide = (int *)malloc(sizeof(int)*(MAXCOL+1));
if(tablecolwide==NULL) ifail = 1;
else
{
for(col = 0; col <= MAXCOL; col++)
{/*loop over columns, the x, horizontal, direction*/
tablecolwide(col) = 0;
}
}
}
if(ifail)
{/*failure at first load, report real trouble*/
printf("failure allocating table array\n");
sprintf(alertstr,"allocation of table space failed");
sprintf(alertstr2,"table cells will not be referred to graphics objects");
#ifdef MACINTOSH
sprintf(alertstr3
,"Perhaps preferred size too small: Before launching MAGE:"
CRLF"one click on MAGE, choose Info under File Menu: "
CRLF"change preferred size to, e.g., 10000 ");
#else
sprintf(alertstr3," ");
#endif
DoMageDLOGreport(2); /*___DLOG.C*/ /*alertstr,alertstr2,alertstr3*/
/*cleanup();*/
/*exit(EXIT_FAILURE);*/
}/*failure at first load, report real trouble*/
}
/*___alloctablearray()_______________________________________________________*/
/****freetablearrays()********************************************************/
void freetablearrays()
{
if (tablepointptr != NULL)
{
free(tablepointptr);
tablepointptr = NULL;
}
if (tablepick != NULL)
{
free(tablepick);
tablepick = NULL;
}
if (tablerowhigh != NULL)
{
free(tablerowhigh);
tablerowhigh = NULL;
}
if (tablecolwide != NULL)
{
free(tablecolwide);
tablecolwide = NULL;
}
}
/*___freetablearrays()_______________________________________________________*/
/*3456789_123456789_123456789_123456789_123456789_123456789_123456789_12345678*/
/****cleanuptable()***********************************************************/
void cleanuptable(void)
{
Ltablepresent = 0; /*called when new kinemage comes in */
Ltableready = 0;
/* before GetStuffFromFile has a chance to find a new table group */
freetablearrays();
killtablemarkers();
#ifdef UNIX_X11
XtDestroyWidget(toptable);
#endif
#ifdef MACINTOSH
DisposeControl(htableScroll);
DisposeControl(vtableScroll);
DisposeWindow(tableWindow);
#endif
#ifdef PCWINDOWS
ReleaseDC(tableWindow,tableDC);
tableDC = NULL;
DestroyWindow(tableWindow);
#endif
}
/*___cleanuptable()__________________________________________________________*/
/*3456789_123456789_123456789_123456789_123456789_123456789_123456789_12345678*/
/*****searchtablecells()******************************************************/
int searchtablecells(int how) /* <- MAGEDLOG/SearchDialog() */
{
int kmax=0,ifoundpart=0,ifoundcell=0,ireturn=0;
int col = 0, row = 0;
#ifdef OLDCODE
int k=0,kk=0,j = 0;
#endif
pointstructptr currentpointptr;
if(isearch1>0) uctolcstr(search1str);
if(isearch2>0) uctolcstr(search2str);
/*loop over all table items*/
for(row = 0; row <= MAXROW; row++)
{/*loop over rows, the y, vertical, direction*/
for(col = 0; col <= MAXCOL; col++)
{/*loop over columns, the x, horizontal, direction*/
/*retrieve the kinemage data point that is associated with this cell*/
currentpointptr = tablepointptr(row,col);
if(currentpointptr != NULL)
{/*cell has designated contents in the table*/
/*copy char str from storage */
if(how == 1)
{/*search for match in cell contents themselves, i.e. the <comment>*/
getcommentstring(trystr, currentpointptr);/*MAGELIST gets wordcom[]*/
/*strip off 3 byte format info on front of string*/
for(kmax=0;kmax<256;kmax++)
{
trystr[kmax] = trystr[kmax+3];
if(trystr[kmax] == '\n' || trystr[kmax] == '\r') trystr[kmax] = ' ';
if(trystr[kmax]=='\0') break;
}/*kmax is size of plain str comment*/
}
else
{/*search for match in cell's point ID, i.e. the {ptID} */
getptIDstring(trystr, currentpointptr);/*MAGELIST*/
for(kmax=0;kmax<256;kmax++)
{
if(trystr[kmax]=='\0') break;
}/*kmax is size of pointID str*/
}
if(kmax > 0)
{/*trial str not null*/ /*000410*/
uctolcstr(trystr); /*ignore case */
if(isearch1 > 0)
{/*compare with first search string*/
ifoundpart = matchstrings(trystr,search1str); /*MAGEUTIL.c*/
}/*compare with first search string*/
if(ifoundpart && isearch2>0)
{/*compare with second search string*/
ifoundpart = matchstrings(trystr,search2str); /*MAGEUTIL.c*/
}/*compare with second search string*/
if(ifoundpart)
{
tablepick(row,col) = 1; /*protect or amplify row 0, col 0 ???? */
ifoundcell = 1;
}
}/*trial str not null*/ /*000410*/
}/*cell has designated contents in the table*/
}/*loop over columns, the x, horizontal, direction*/
}/*loop over rows, the y, vertical, direction*/
if(ifoundcell)
{
Lsearchatend = 1;
Lpick = 1; /* flag for successful pick */
ipick = 0; /*so will not try to find a pickpoint by cursor x,y*/
ireturn = 1;
}
return(ireturn);
}
/*____searchtablecells()_____________________________________________________*/
/*3456789_123456789_123456789_123456789_123456789_123456789_123456789_12345678*/
/****addtablemarker()*********************************************************/
void addtablemarker(struct pointstruct* subjectpointptr)
{
if(tablemarkergrupptr==NULL)
{
if( !allocgrupstructure() )
{