-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathface.c
5656 lines (4994 loc) · 153 KB
/
face.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
#include "dna.h" // Basic data types come first
#include "scroll.h"
#include "hand.h"
#include "face.h" // UIR constant file
#include "facetwo.h" // Hold constants and (extern) globals
#include "brain.h" // Function prototypes, BRAIN globals
#include "dde.h"
#include "recent.h"
#include <userint.h>
//TESTING
//#include "memory.h"
//#define BUGHUNT2
// UIR panel hanndle variables
//
//This is the FACE of Word Generator 2.
//
//Here is the user interface, much of which is created programatically.
//
//Note: execution begins in this file
//
//As this is an event driven interface, all execution starts here (almost)
//and so all the error returning that is going on ends up here as well.
//
//Error handling will likely be done in the future. for now it is
//largely ignored.
//
#include <cvirte.h>
// Needed if linking in external compiler; harmless otherwise
// Redundant since also included in FACE.h automatically
static int arf=-1;
static int wg=-1;
static int auxwait=-1; // Handle to window for J5
static int auxwaitQ=dnaFalse; // True when displayed
// UI constants that are only needed in FACE.c
static const int NumColors = 4;
/* TODO FIXME : The orange or green is too bright, it rounds off to white in Black
* and white printing. Make it darker. */
// RRGGBB RR=Red,GG=Green,BB=Blue component
static const int Red = 0x00FF0000;
static const int Blue = 0x000000FF;
//static const int Orange = 0x00FF8200; // This was too bright
static const int Orange = 0x00FF7000;
static const int Green = 0x00009a00;
static const int ColorBorder = 0x00000000;
static const int ColorGraphOn = 0x00009a00;
static int ColorCanvas=0; // loaded from default
static int ColorGraphOff=0; // loaded from default
//static const int Colors[4] = {0x00FF0000,0x000000FF,0x00FF8000,0x00009900};
// 65536 color mode needs:
static const int Colors[/*NumColors*/4] = {/*Red*/0x00FF0000,/*Blue*/0x000000FF,
/*Orange*/0x00FF7000,/*Green*/0x00009a00};
// Hand Coded parameters for making the GUI
// May be from ini file in the future
/* UIClusters is the number of words on the panel at a time */
static const int UIClusters = faceCLUSTERS;
#if WGFLAG == 2
/* Why is this 48 and not 32 ? */
/* UIDigitalOutputs is the number of outputs displayed */
static const int UIDigitalOutputs = 48;
/* UIUsedOutputs is the number of outputs enabled */
static const int UIUsedOutputs = 48;
#elif WGFLAG == 3
/* UIDigitalOutputs is the number of outputs displayed */
// WG2->3 APC, was 48 (why?) now 64
static const int UIDigitalOutputs = 64;
/* UIUsedOutputs is the number of outputs enabled */
// WG2->3 APC, was 48 (why?) now 64
static const int UIUsedOutputs = 64;
#endif
/* UIXYValues is the number of x,y points displayed for editing graphs */
static const int UIXYValues = faceXYValues;
// These labels are the defaults
// GOTCHA : 13 is minimum needed length of string bufferd to hold values.
#if WGFLAG == 2
static char GraphLabelPrefix[faceGRAPHS][13] = {"AO 0","AO 1","AO 2",
"AO 3","AO 4","AO 5","AO 6","AO 7","AO 8","AO 9",
"RF Amplitude","RF Frequency"};
#elif WGFLAG == 3
static char GraphLabelPrefix[faceGRAPHS][13] = {"AO 0","AO 1","AO 2",
"AO 3","AO 4","AO 5","AO 6","AO 7",
"RF Amplitude","RF Frequency"};
#endif
/* This allows for easier customiztion of terms */
static const char Unknown[] = "Unknown";
static const char Unused[] = "Unused";
static const char XValueStr[] = "X Values";
static const char YValueStr[] = "Y Values";
// These are the major FACES.c global structures
static faceARFGraphs ARFGraphs;
static faceClusterArray ClusterArray;
static facePOPUPData POPData;
static faceClipboard Clipboard;
//************ Forward declarations ****************
int changedGraphSelection(int index);
int enableXYValues(void);
int AddRecentFilename(char * filename);
//**************************************************
//*********************************************************************
//
//
// BRAIN Global and other Accessors
//
//
//*********************************************************************
// These hide the dichotomy of storage from other functions
// index is a cluster index
dnaCluster * GetCluster(int index)
{
if (Clusters.Clusters)
if (index < Clusters.NumberOfClusters)
return &(Clusters.Clusters[index]);
else
return 0;
else
return 0;
}
// This detects whether "invalidate pointers" was called
// index is a graph index
dnaByte ValidGroup(int index)
{
if (-1==index) {
return dnaFalse; // Paranoia
}
if (index < dnaAnalogChannels) {
if (ARFGraphs.AnalogGroup)
return dnaTrue;
else
return dnaFalse;
}
else {
index -= dnaAnalogChannels;
if (ARFGraphs.RFGroup)
return dnaTrue;
else
return dnaFalse;
}
}
// index is a graph index
// index is set to the corect value for the BRAIN group int the array
dnaARFGroupArray *GetGroupArray(int *index) //note index is modified here
{
if (!index) // Paranoia
return 0;
if ((*index) < dnaAnalogChannels)
return (&AGroups);
else {
(*index) -= dnaAnalogChannels;
if ((*index)<RFGroups.NumberOfGraphs)
return (&RFGroups);
else
return 0; // Paranoia
}
}
// index is a graph index
// index is set to the corect value for the BRAIN group
dnaARFGroup *GetGroup(int *index)
{
if (ValidGroup(*index)) {
if ((*index) < dnaAnalogChannels)
return (ARFGraphs.AnalogGroup);
else {
(*index) -= dnaAnalogChannels;
if ((*index)<RFGroups.NumberOfGraphs)
return (ARFGraphs.RFGroup);
else
return 0; // Paranoia
}
}
else
return 0;
}
// index is a graph index
// index is NOT chaged
dnaARFGraph *GetGraph(int index)
{
dnaARFGroup * group;
group=GetGroup(&index);
if (!group)
return 0;
if ((group->ARFGraphs) && (index<group->NumberOfGraphs))
return &(group->ARFGraphs[index]);
else
return 0;
}
// index is a graph index
dnaByte GetEnabledQ(int index)
{
dnaARFGroupArray *groupArray;
if (index<0)
return dnaFalse;
groupArray=GetGroupArray(&index);
if (index>groupArray->NumberOfGraphs)
return dnaFalse;
if (!groupArray)
return dnaFalse; // Paranoia
if (groupArray->EnabledQ)
return (groupArray->EnabledQ[index]);
else
return dnaFalse; // Paranoia
}
int GetClusterIndex(int index)
{
int err=0,BrainIndex=0;
nullChk(ClusterArray.Cluster);
errChk(GetCtrlVal(ClusterArray.panel,ClusterArray.Cluster[index].INDEX,
&BrainIndex));
Error:
return (err?-1:BrainIndex);
}
//*********************************************************************
//
//
// Functions to access control states
//
//
//*********************************************************************
dnaByte PinValuesQ(void)
{
int MyValue=dnaFalse;
GetCtrlVal (ARFGraphs.panel, ARF_PINRANGEQ, &MyValue);
return MyValue;
}
dnaByte RepeatRunQ(void) // FACETWO.h
{
int MyValue=dnaFalse;
GetCtrlVal (ClusterArray.panel, WG_REPEATRUN, &MyValue);
return MyValue;
}
dnaByte CameraTriggerQ(void) // FACETWO.h
{
int MyValue=dnaFalse;
GetCtrlVal (ClusterArray.panel, WG_TRIGGERRUN, &MyValue);
return MyValue;
}
//*********************************************************************
//
//
// Functions to redisplay data
//
//
//*********************************************************************
//
// Parameter index is the FACE UI Graph index, assumed to be valid
//ShutoffQ false declares that the checkbox should be
// enabled in an unchecked state.
//ShufoffQ declares the graph at index is not a possible functioning unit
//of the interface. It need never even exist as a control.
int disableGraph(int index,int ShutoffQ)
{
int err=0;
int panel,GRAPH; // short handles....
// dim the graph and NOT set its label to the default value
errChk(SetCtrlAttribute (ARFGraphs.panel, ARFGraphs.GRAPH[index],
ATTR_DIMMED, dnaTrue));
errChk(SetCtrlAttribute (ARFGraphs.panel, ARFGraphs.GRAPH[index],
ATTR_LABEL_TEXT,GraphLabelPrefix[index]));
errChk(SetCtrlAttribute (ARFGraphs.panel, ARFGraphs.GRAPH[index],
ATTR_LABEL_LEFT,VAL_AUTO_CENTER));
// errChk(SetCtrlVal (ARFGraphs.panel, ARFGraphs.ENABLEDQ[index],dnaFalse));
// Do not leave erroneous plots on the screen....
panel=ARFGraphs.panel; // FACES.h constant handle
GRAPH=ARFGraphs.GRAPH[index]; // FACES.c constant handle
if (ARFGraphs.PLOT[index]>=0) { // there is so delete it...
DeleteGraphPlot (panel, GRAPH, ARFGraphs.PLOT[index], VAL_DELAYED_DRAW);
ARFGraphs.PLOT[index]=-1; // Invalidate handle
}
if (ARFGraphs.IPLOT[index]>=0) { // there is so delete it...
DeleteGraphPlot (panel, GRAPH, ARFGraphs.PLOT[index], VAL_DELAYED_DRAW);
ARFGraphs.IPLOT[index]=-1; // Invalidate handle
}
// ensure the checkbox has the right value
errChk(SetCtrlVal(ARFGraphs.panel, ARFGraphs.ENABLEDQ[index],dnaFalse));
if (ShutoffQ) // If terminating with prejudice
errChk(SetCtrlAttribute (ARFGraphs.panel, ARFGraphs.ENABLEDQ[index],
ATTR_DIMMED, dnaTrue));
else // We can let them click on it
errChk(SetCtrlAttribute (ARFGraphs.panel, ARFGraphs.ENABLEDQ[index],
ATTR_DIMMED, dnaFalse));
Error:
return err;
}
//
// Parameter i is the FACE UI cluster offset
// Parameter j is the digital line
// Parameter Value is obvious (i hope)
//
// This assumes i and j are valid !!!!!!
//
// It always plots onto the canvas.
int setDigitalValue(int i, int j, dnaByte Value)
{
int err=0;
int color;
Rect R;
R.height=ClusterArray.DigitalHeight;
R.width=ClusterArray.DigitalWidth;
R.left=R.width*i;
R.top=R.height*j;
R.top++;
R.left++;
R.width-=2;
R.height-=2;
if(Value)
color=Colors[j%NumColors];
else
color=ColorCanvas;
errChk(SetCtrlAttribute (ClusterArray.vframe, ClusterArray.CANVAS,
ATTR_PEN_FILL_COLOR, color));
errChk(CanvasDrawRect(ClusterArray.vframe, ClusterArray.CANVAS, R, VAL_DRAW_INTERIOR));
Error:
return (err?-1:0);
}
// Parameter i is the UI cluster index, assumed to be valid.
int disableCluster(int i, dnaByte ClearDigitalQ)
{
int err=0;
int j; // looping variable
faceClusterHandles *fPtr;
int panel;
nullChk(ClusterArray.Cluster);
fPtr=&ClusterArray.Cluster[i]; // desired structure with handles
// See if Already disabled
errChk(GetCtrlVal (ClusterArray.panel, fPtr->INDEX, &j));
if(-1==j) {
err=0;
goto Error;
}
panel = ClusterArray.panel;
// errChk(SetCtrlAttribute(panel,fPtr->INDEX, ATTR_DIMMED, dnaTrue));
errChk(SetCtrlAttribute(panel,fPtr->LABEL, ATTR_DIMMED, dnaTrue));
errChk(SetCtrlAttribute(panel,fPtr->ENABLEDQ, ATTR_DIMMED, dnaTrue));
errChk(SetCtrlAttribute(panel,fPtr->TICKS, ATTR_DIMMED, dnaTrue));
errChk(SetCtrlAttribute(panel,fPtr->TIMEUNIT, ATTR_DIMMED, dnaTrue));
errChk(SetCtrlAttribute(panel,fPtr->ANALOGRING, ATTR_DIMMED, dnaTrue));
errChk(SetCtrlAttribute(panel,fPtr->ANALOGGROUP, ATTR_DIMMED, dnaTrue));
errChk(SetCtrlAttribute(panel,fPtr->RFRING, ATTR_DIMMED, dnaTrue));
errChk(SetCtrlAttribute(panel,fPtr->RFGROUP, ATTR_DIMMED, dnaTrue));
errChk(SetCtrlVal(panel,fPtr->INDEX, -1));
errChk(SetCtrlVal(panel,fPtr->LABEL, Unknown));
errChk(SetCtrlVal(panel,fPtr->ENABLEDQ, dnaFalse));
errChk(SetCtrlVal(panel,fPtr->TICKS, 1));
errChk(SetCtrlVal(panel,fPtr->TIMEUNIT, dnaSEC));
errChk(SetCtrlVal(panel,fPtr->ANALOGRING, dnaARFContinue));
errChk(SetCtrlVal(panel,fPtr->ANALOGGROUP, -1));
errChk(SetCtrlVal(panel,fPtr->RFRING, dnaARFContinue));
errChk(SetCtrlVal(panel,fPtr->RFGROUP, -1));
fPtr->ClusterData=0;
if (ClearDigitalQ) {
for (j=0; j<ClusterArray.NumberOfOutputs; j++) {
errChk(setDigitalValue(i,j,dnaFalse));
}
}
err=0;
Error:
return (err?-1:0);
}
//
// Parameter i is the FACE UI cluster offset
// Parameter j is the BRAIN cluster data offset
// This assumes i and j are valid !!!!!!
// It always writes the digital values to the canvas!
int loadCluster(int i,int j)
{
int k,err=0;
int panel,max;
faceClusterHandles *fPtr;
dnaCluster *dPtr;
char name[32]; // GOTCHA FIXME : make this less hard coded
#if defined BUGHUNT
printf("i=%d, (i<NumClusters)=%d\n",i,(i<ClusterArray.NumClusters));
if (i>=15) printf("loadCluster{ClusterArray.NumClusters=%d}\n",ClusterArray.NumClusters);
#endif
require(i<ClusterArray.NumClusters);
nullChk(ClusterArray.Cluster);
fPtr=&ClusterArray.Cluster[i]; // FACE.c structure
nullChk(fPtr);
dPtr=GetCluster(j); // BRAIN.c structure
nullChk(dPtr);
fPtr->ClusterData=dPtr; // Remember where data is taken from
panel = ClusterArray.panel;
#if defined BUGHUNT
if (i>=15) printf("loadCluster{Set dim state}\n");
#endif
// set dim state
errChk(SetCtrlAttribute (panel,fPtr->INDEX, ATTR_DIMMED, dnaFalse));
errChk(SetCtrlAttribute (panel,fPtr->LABEL, ATTR_DIMMED, dnaFalse));
errChk(SetCtrlAttribute (panel,fPtr->ENABLEDQ, ATTR_DIMMED, dnaFalse));
errChk(SetCtrlAttribute (panel,fPtr->TICKS, ATTR_DIMMED, dnaFalse));
errChk(SetCtrlAttribute (panel,fPtr->TIMEUNIT, ATTR_DIMMED, dnaFalse));
errChk(SetCtrlAttribute (panel,fPtr->ANALOGRING, ATTR_DIMMED, dnaFalse));
errChk(SetCtrlAttribute (panel,fPtr->RFRING, ATTR_DIMMED, dnaFalse));
#if defined BUGHUNT
if (i>=15) printf("loadCluster{Load values}\n");
#endif
// set values
errChk(SetCtrlVal (panel, fPtr->INDEX, j));
if (!dPtr->Label) {
negChk(Fmt(name,"%s<#%d",j));
errChk(dna_SetClusterLabel (dPtr, name));
}
errChk(SetCtrlVal (panel, fPtr->LABEL, dPtr->Label));
errChk(SetCtrlVal (panel, fPtr->ENABLEDQ, dPtr->EnabledQ));
errChk(SetCtrlVal (panel, fPtr->TICKS, dPtr->Ticks));
errChk(SetCtrlVal (panel, fPtr->TIMEUNIT, dPtr->TimeUnit));
errChk(SetCtrlVal (panel, fPtr->ANALOGRING, dPtr->AnalogSelector));
errChk(SetCtrlVal (panel, fPtr->ANALOGGROUP, dPtr->AnalogGroup));
errChk(SetCtrlVal (panel, fPtr->RFRING, dPtr->RFSelector));
errChk(SetCtrlVal (panel, fPtr->RFGROUP, dPtr->RFGroup));
// Conditional dim state of Analog and RF Group indices
switch (dPtr->AnalogSelector) {
case dnaARFContinue :
case dnaARFStop :
errChk(SetCtrlAttribute(panel,fPtr->ANALOGGROUP,
ATTR_DIMMED,dnaTrue));
break;
case dnaARFStartGroup:
errChk(SetCtrlAttribute(panel,fPtr->ANALOGGROUP,
ATTR_DIMMED,dnaFalse));
break;
}
switch (dPtr->RFSelector) {
case dnaARFContinue :
case dnaARFStop :
errChk(SetCtrlAttribute (panel, fPtr->RFGROUP,
ATTR_DIMMED, dnaTrue));
break;
case dnaARFStartGroup :
errChk(SetCtrlAttribute (panel, fPtr->RFGROUP,
ATTR_DIMMED, dnaFalse));
break;
}
// Check to make sure we assign the right amount of data to canvas
#if defined BUGHUNT
if (i>=15) printf("loadCluster{SetDigitalValue loop}\n");
#endif
max = dPtr->NumberOfValues;
if (max>ClusterArray.NumberOfOutputs)
max=ClusterArray.NumberOfOutputs;
for (k=0;k<max;k++) {
#if defined BUGHUNT
if (i>=15) printf("loadCluster{SetDigitalValue(%d,%d,%d)}\n",i,k,dPtr->Digital[k]);
#endif
errChk(setDigitalValue(i,k,dPtr->Digital[k]));
}
Error:
return (err?-1:0);
}
//
// Clusters.NumberOfClusters should be correct (vis a vis offset).
/* This sets both the numerical control and the horiz. scroll bar */
int changedGlobalOffset(int offset)
{
int err=0;
int i,j; // looping
int n,max; // Short names for easy of use;
dnaCluster *cPtr;
#if defined BUGHUNT
printf("changedGlobalOffset{}\n");
#endif
n=Clusters.NumberOfClusters; // Number that exist in memory
if (n<=offset) { // Paranoia
err=-1;
goto Error;
}
if (offset<0) { // No Clusters, cannot handle
err=-1;
goto Error;
}
ClusterArray.GlobalOffset=offset; // First to display
errChk(SetCtrlVal (ClusterArray.panel, WG_GLOBALOFFSET, offset));
errChk(ScrollBar_SetAttribute (ClusterArray.panel, WG_HSCROLL, ATTR_SB_VALUE,offset));
if (ClusterArray.OnlyEnabledQ) {
#if defined BUGHUNT
printf("changedGlobalOffset{OnlyEnabledQ True}\n");
#endif
i=0; // FACE UI index, ClusterArray
j=offset; // BRAIN index, Clusters
cPtr=GetCluster(j);
while ((i<ClusterArray.NumClusters) && (j<n)) {
if (cPtr->EnabledQ) {
errChk(loadCluster(i,j));
i++;
}
j++;
cPtr=GetCluster(j);
}
while (i<ClusterArray.NumClusters) {
errChk(disableCluster(i,dnaTrue));
i++;
}
}
else {
#if defined BUGHUNT
printf("changedGlobalOffset{OnlyEnabledQ False}\n");
#endif
max = offset+ClusterArray.NumClusters-1; // Last index display could fit
if (max>n-1) // Reduce if memory smaller
max=n-1;
// Now max is the last index to be displayed
for(i=0; i<=max-offset; i++) {
#if defined BUGHUNT
printf("changedGlobalOffset{loadCluster(%d,%d)}\n",i,i+offset);
#endif
errChk(loadCluster(i,i+offset));
}
// continue and shut off extra displayed columns
for(; i<ClusterArray.NumClusters; i++) {
#if defined BUGHUNT
printf("changedGlobalOffset{disableCluster(%d,1)}\n",i);
#endif
errChk(disableCluster(i,dnaTrue)); // Also will clear canvas
}
}
#if defined BUGHUNT
printf("changedGlobalOffset{Exiting Normally}\n");
#endif
Error:
return (err?-1:0);
}
//
// enableGraph does the ACTUAL PLOTTING.
// This assumes that the ENABLEDQ for this graph should be made checked
// The graph enabling function. Interpolated values need to be constructed
// for all the enabled graphs of the groups being displayed.
// Disabled graphs are only first drawn when enabled.
// Assumes that the checkbox and the memory byte are set correctly
int enableGraph(int index) // index is 0..11 of the UI index!
{
int err=0;
int panel,ENABLEDQ,GRAPH;
dnaARFGroupArray *groupArray;
dnaARFGroup *group;
dnaARFGraph *graph;
char * Label;
int n,dummy; // Number of points to interpolate
int max,SortQ; // Number of pixels wide of plot area
int BrainIndex,dummyindex;
int TicksLT, TimeUnitLT;
// Grab some short names for what we are up to
panel=ARFGraphs.panel; // FACES.h constant handle
GRAPH=ARFGraphs.GRAPH[index]; // FACES.c constant handle
ENABLEDQ=ARFGraphs.ENABLEDQ[index]; // FACES.c constant handle
// get the group array
BrainIndex=index;
groupArray=GetGroupArray(&BrainIndex); // changes Brain Index
nullChk(groupArray);
// get the label
if (groupArray->Labels)
Label=groupArray->Labels[BrainIndex];
else {
// If no label, employ the default
Label=GraphLabelPrefix[index];
}
if (!Label) {
errChk(dna_SetGraphLabel(groupArray,BrainIndex,
GraphLabelPrefix[index]));
Label=groupArray->Labels[BrainIndex];
}
// get the group (for duration)
BrainIndex=index; // changes Brain Index
group=GetGroup(&BrainIndex);
nullChk(group); // Cannot enable if invalidated
// get the graph (of course)
graph=GetGraph(index);
nullChk(graph);
// we are enabled
errChk(SetCtrlVal (panel,ENABLEDQ,dnaTrue));
// we are not dimmed
errChk(SetCtrlAttribute(panel,GRAPH,ATTR_DIMMED, dnaFalse));
errChk(SetCtrlAttribute(panel,ENABLEDQ,ATTR_DIMMED,dnaFalse));
// we have a name
if (Label)
errChk(SetCtrlAttribute(panel,GRAPH,ATTR_LABEL_TEXT,Label));
else // we should have a name.....
errChk(SetCtrlAttribute(panel,GRAPH,ATTR_LABEL_TEXT,Unknown));
errChk(SetCtrlAttribute (panel, GRAPH,
ATTR_LABEL_LEFT,VAL_AUTO_CENTER));
// See if there are existing plots
if (ARFGraphs.PLOT[index]>=0) { // there is so delete it...
DeleteGraphPlot (panel, GRAPH, ARFGraphs.PLOT[index], VAL_DELAYED_DRAW);
ARFGraphs.PLOT[index]=-1; // Invalidate handle
}
if (ARFGraphs.IPLOT[index]>=0) { // there is so delete it...
DeleteGraphPlot (panel, GRAPH, ARFGraphs.PLOT[index], VAL_DELAYED_DRAW);
ARFGraphs.IPLOT[index]=-1; // Invalidate handle
}
// Now we are ready to look at the actual plot data
/* I think I remember why we do this */
/* After saving and loading an experiment which does not use XY values, it
is possible that there is no memory allocated. This will catch that case
the first time the group is used / displayed
*/
if(0==graph->NumberOfValues) { // we need to allocate memory
// guarantee that we have allocated enough memory to hold faceXYValues number of XY pairs
dna_SetGraphValues (graph, faceXYValues); // GOTCHA from DNA.h
}
/* This does ILinear if IUnknown was selected */
if(dnaNoInterp==graph->InterpType) {
graph->InterpType=dnaILinear;
}
// Do we have values to plot...
if (!graph->InterpReadyQ) {
// get the number of pixels as the maximum number of points to plot
errChk(GetCtrlAttribute (panel, GRAPH, ATTR_PLOT_AREA_WIDTH, &max));
// calculate the minimum number of request points to plot
n=group->TicksD * group->TimeUnitD;
n=(n/(group->Ticks * group->TimeUnit))+1;
if (n>max) // reduce if too many to display
n=max;
SortQ=MakeInterp(group,graph,n); // Pass off work to Brain
negChk(SortQ);
if (SortQ)
errChk(enableXYValues());
}
// Want to update TicksLT and TimeUnitLT ?
if (index>=dnaAnalogChannels) {
TicksLT = (group->TicksD * group->TimeUnitD);
TicksLT -= (group->Ticks * group->TimeUnit);
TimeUnitLT=1; // usec
if (0==TicksLT%1000L) {
TicksLT /= 1000L;
TimeUnitLT*=1000L; // msec
}
if (0==TicksLT%1000L) {
TicksLT /= 1000L;
TimeUnitLT*=1000L; // sec
}
SetCtrlVal (panel, ARF_RFTICKSLT, TicksLT);
SetCtrlVal (panel, ARF_RFTIMEUNITLT, TimeUnitLT);
}
// Now actualy update the plots
if (graph->InterpReadyQ) {
// USERPIN : Always run through the PinGraphValues to act user min/max?
if (PinValuesQ())
errChk(dna_PinGraphValues (graph));
if (InterpData[graph->InterpType].ValuesEnabledQ)
ARFGraphs.PLOT[index] = PlotXY (panel, GRAPH, graph->XScaled,
graph->YScaled,
graph->NumberOfValues, VAL_DOUBLE,
VAL_DOUBLE, VAL_SCATTER,
VAL_SOLID_SQUARE, VAL_SOLID, 1,
VAL_BLACK);
ARFGraphs.IPLOT[index]= PlotXY (panel, GRAPH, graph->InterpXValues,
graph->InterpYValues,
graph->NumberOfInterps, VAL_DOUBLE,
VAL_DOUBLE, VAL_THIN_LINE,
VAL_EMPTY_SQUARE, VAL_SOLID, 1,
VAL_RED);
}
else {
RefreshGraph (panel, GRAPH);
}
Error:
return (err?-1:0);
}
//
// This assumes any pointers are to old stuff.
// The ARFGraphs and control are both changed.
// Old graphing interpolation data is touched (deleted).
int changedAnalogIndex(int index)
{
int err=0;
int i; // looping
int old;
int panel;
char name[32]; // GOTCHA FIXME : Make this less hard coded
int dummy,min,max;
dnaARFGroupArray * groupArray;
dnaARFGraph * graph;
if (index>=AGroups.NumberOfGroups) // Paranoia
index=-1; // Handle by shutting off
// make certain no graph data is still being edited
if (-1!=ARFGraphs.GraphSelected)
changedGraphSelection(-1);
if (ValidGroup(0)) { // Checks for valid old Analog Group
old = ARFGraphs.AnalogIndex;
if (0<=old)
// We ought to free memory by touching all graph data
for (i=0; i<dnaAnalogChannels; i++) {
graph = GetGraph(i);
if (graph)
errChk(dna_TouchARFGraph (graph));
}
}
panel = ARFGraphs.panel;
// Next statement may be redundant
errChk(SetCtrlVal(panel,ARF_AINDEX,index));
ARFGraphs.AnalogIndex = index;
if (index<0) { // Need to disable stuff
// Dim everything in header
errChk(SetCtrlAttribute(panel,ARF_ALABEL, ATTR_DIMMED,dnaTrue));
errChk(SetCtrlAttribute(panel,ARF_ATICKS, ATTR_DIMMED,dnaTrue));
errChk(SetCtrlAttribute(panel,ARF_ATIMEUNIT, ATTR_DIMMED,dnaTrue));
errChk(SetCtrlAttribute(panel,ARF_ATICKSD, ATTR_DIMMED,dnaTrue));
errChk(SetCtrlAttribute(panel,ARF_ATIMEUNITD, ATTR_DIMMED,dnaTrue));
ARFGraphs.AnalogGroup = 0; // NULL
// Label of analog group being displayed
errChk(SetCtrlVal(panel,ARF_ALABEL,Unused));
// Timebase Ticks of analog group being displayed
errChk(SetCtrlVal(panel,ARF_ATICKS,-1));
// Timebase Unit of analog group being displayed
errChk(SetCtrlVal(panel,ARF_ATIMEUNIT,dnaMSEC));
// Duration Ticks of analog group being displayed
errChk(SetCtrlVal(panel,ARF_ATICKSD,-1));
// Duration Unit of analog group being displayed
errChk(SetCtrlVal(panel,ARF_ATIMEUNITD,dnaMSEC));
// GOTCHA : lots of values here ...
min=0;
max=dnaAnalogChannels;
if (max>ARFGraphs.NumGraphs)
(max=ARFGraphs.NumGraphs);
for (i=min; i<max; i++) {
errChk(disableGraph(i,dnaTrue)); // check box also disabled
}
}
else {
// un-dim everything in header
errChk(SetCtrlAttribute(panel,ARF_ALABEL, ATTR_DIMMED,dnaFalse));
errChk(SetCtrlAttribute(panel,ARF_ATICKS, ATTR_DIMMED,dnaFalse));
errChk(SetCtrlAttribute(panel,ARF_ATIMEUNIT, ATTR_DIMMED,dnaFalse));
errChk(SetCtrlAttribute(panel,ARF_ATICKSD, ATTR_DIMMED,dnaFalse));
errChk(SetCtrlAttribute(panel,ARF_ATIMEUNITD, ATTR_DIMMED,dnaFalse));
// Get a valid group pointer
dummy=0; // GOTCHA
groupArray=GetGroupArray(&dummy);
nullChk(groupArray);
nullChk(groupArray->ARFGroups);
ARFGraphs.AnalogGroup=&(groupArray->ARFGroups[index]);
// Label of analog group being displayed
if (!ARFGraphs.AnalogGroup->Label) {
negChk(Fmt(name,"%s<Analog Group #%d",index));
dna_SetGroupLabel (ARFGraphs.AnalogGroup, name);
}
if (ARFGraphs.AnalogGroup->Label)
errChk(SetCtrlVal(panel,ARF_ALABEL,ARFGraphs.AnalogGroup->Label));
else
errChk(SetCtrlVal(panel,ARF_ALABEL,Unknown));
// Timebase Ticks of analog group being displayed
errChk(SetCtrlVal(panel,ARF_ATICKS,ARFGraphs.AnalogGroup->Ticks));
// Timebase Unit of analog group being displayed
errChk(SetCtrlVal(panel,ARF_ATIMEUNIT,
ARFGraphs.AnalogGroup->TimeUnit));
// Duration Ticks of analog group being displayed
errChk(SetCtrlVal(panel,ARF_ATICKSD,ARFGraphs.AnalogGroup->TicksD));
// Duration Unit of analog group being displayed
errChk(SetCtrlVal(panel,ARF_ATIMEUNITD,
ARFGraphs.AnalogGroup->TimeUnitD));
// GOTCHA : lots of values here ...
min=0;
max=dnaAnalogChannels; // Number in memory
if (max>ARFGraphs.NumGraphs) // Number on panel
(max=ARFGraphs.NumGraphs);
if (!(groupArray->EnabledQ)) // if there is no array to check
max=min; // then disabled completely
for (i=min; i<max; i++) {
if (groupArray->EnabledQ[i])
errChk(enableGraph(i)); // plot the data
else
errChk(disableGraph(i,dnaFalse)); // dim/plot nothing
}
for (;i<dnaAnalogChannels;i++) // disable the rest
errChk(disableGraph(i,dnaTrue)); // dim/plot nothing
}
Error:
return (err?-1:0);
}
//
// This assumes that the RF Index control is already setup.
// (specifically its DIM status and MAX attribute) and the value
// in ARFGraphs matches.
int changedRFIndex(int index)
{
int err=0;
int i; // looping
int old;
int panel;
int dummy,min,max;
int TicksLT;
char name[32]; // GOTCHA FIXME : Make this less ahrd coded
dnaTimeUnits UnitLT;
dnaARFGroupArray * groupArray;
dnaARFGraph * graph;
if (index>=RFGroups.NumberOfGroups) // Paranoia
index=-1;
old = ARFGraphs.RFIndex;
// make certain no graph data is still being edited
if (-1!=ARFGraphs.GraphSelected)
changedGraphSelection(-1);
if (ValidGroup(dnaAnalogChannels)) { // GOTCHA
old = ARFGraphs.RFIndex;
if (0<=old)
// We ought to free memory by touching all graph data
for (i=dnaAnalogChannels; i<ARFGraphs.NumGraphs; i++) {
graph = GetGraph(i);
if (graph)
errChk(dna_TouchARFGraph (graph));
}
}
panel = ARFGraphs.panel;
// Next statement may be redundant
errChk(SetCtrlVal(panel,ARF_RFINDEX,index));
ARFGraphs.RFIndex = index;
if (index<0) { // Need to disable stuff
errChk(SetCtrlAttribute(panel, ARF_RFLABEL, ATTR_DIMMED, dnaTrue));
errChk(SetCtrlAttribute(panel, ARF_RFTICKS, ATTR_DIMMED, dnaTrue));
errChk(SetCtrlAttribute(panel, ARF_RFTIMEUNIT, ATTR_DIMMED, dnaTrue));
errChk(SetCtrlAttribute(panel, ARF_RFTICKSD, ATTR_DIMMED, dnaTrue));
errChk(SetCtrlAttribute(panel, ARF_RFTIMEUNITD, ATTR_DIMMED, dnaTrue));
errChk(SetCtrlAttribute(panel, ARF_RFTICKSLT, ATTR_DIMMED, dnaTrue));
errChk(SetCtrlAttribute(panel, ARF_RFTIMEUNITLT,ATTR_DIMMED, dnaTrue));
ARFGraphs.RFGroup=0; // NULL
// Label of RF group being displayed
errChk(SetCtrlVal(panel,ARF_RFLABEL,Unused));
// Timebase Ticks of RF group being displayed
errChk(SetCtrlVal(panel,ARF_RFTICKS,-1));
// Timebase Unit of RF group being displayed
errChk(SetCtrlVal(panel,ARF_RFTIMEUNIT,dnaMSEC));
// Duration Ticks of RF group being displayed
errChk(SetCtrlVal(panel,ARF_RFTICKSD,-1));
// Duration Unit of RF group being displayed
errChk(SetCtrlVal(panel,ARF_RFTIMEUNITD,dnaMSEC));
// Ticks for time of last command of RF group being displayed
errChk(SetCtrlVal(panel,ARF_RFTICKSLT,-1));
// Time Unit for itme of last command of RF group being displayed
errChk(SetCtrlVal(panel,ARF_RFTIMEUNITLT,dnaMSEC));
min=dnaAnalogChannels; // GOTCHA
max=ARFGraphs.NumGraphs; // GOTCHA
for (i=min; i<max; i++) {
errChk(disableGraph(i,dnaTrue)); // check box also disabled
}
}
else {
errChk(SetCtrlAttribute(panel, ARF_RFLABEL, ATTR_DIMMED, dnaFalse));
errChk(SetCtrlAttribute(panel, ARF_RFTICKS, ATTR_DIMMED, dnaFalse));
errChk(SetCtrlAttribute(panel, ARF_RFTIMEUNIT, ATTR_DIMMED, dnaFalse));
errChk(SetCtrlAttribute(panel, ARF_RFTICKSD, ATTR_DIMMED, dnaFalse));
errChk(SetCtrlAttribute(panel, ARF_RFTIMEUNITD, ATTR_DIMMED, dnaFalse));
errChk(SetCtrlAttribute(panel, ARF_RFTICKSLT, ATTR_DIMMED, dnaFalse));
errChk(SetCtrlAttribute(panel, ARF_RFTIMEUNITLT,ATTR_DIMMED, dnaFalse));
// Get a valid group pointer
dummy=dnaAnalogChannels; // GOTCHA
groupArray=GetGroupArray(&dummy);
nullChk(groupArray);
nullChk(groupArray->ARFGroups);
ARFGraphs.RFGroup=&(groupArray->ARFGroups[index]);
// Label of RF group being displayed
if (!ARFGraphs.RFGroup->Label) {
negChk(Fmt(name,"%s<RF Group #%d",index));
dna_SetGroupLabel (ARFGraphs.RFGroup, name);
}
if (ARFGraphs.RFGroup->Label)
errChk(SetCtrlVal(panel,ARF_RFLABEL,ARFGraphs.RFGroup->Label));
else
errChk(SetCtrlVal(panel,ARF_RFLABEL,Unknown));
// Timebase Ticks of RF group being displayed
errChk(SetCtrlVal(panel,ARF_RFTICKS,ARFGraphs.RFGroup->Ticks));
// Timebase Unit of RF group being displayed
errChk(SetCtrlVal(panel,ARF_RFTIMEUNIT,ARFGraphs.RFGroup->TimeUnit));
// Duration Ticks of RF group being displayed
errChk(SetCtrlVal(panel,ARF_RFTICKSD,ARFGraphs.RFGroup->TicksD));
// Duration Unit of RF group being displayed
errChk(SetCtrlVal(panel,ARF_RFTIMEUNITD,
ARFGraphs.RFGroup->TimeUnitD));
TicksLT= ARFGraphs.RFGroup->TicksD*ARFGraphs.RFGroup->TimeUnitD-
ARFGraphs.RFGroup->Ticks*ARFGraphs.RFGroup->TimeUnit;
UnitLT=dnaUSEC;
TicksLT=TicksLT/1000; // always can convert to msec
UnitLT=dnaMSEC;
if (0==(TicksLT % 1000)) {
TicksLT/=1000; // sometimes convert to sec
UnitLT=dnaSEC;
}
// Ticks for time of last command of RF group being displayed
errChk(SetCtrlVal(panel,ARF_RFTICKSLT,TicksLT));
// Time Unit for itme of last command of RF group being displayed
errChk(SetCtrlVal(panel,ARF_RFTIMEUNITLT,UnitLT));
// Duration Unit of RF group being displayed
errChk(SetCtrlVal(panel,ARF_RFTIMEUNITD,
ARFGraphs.RFGroup->TimeUnitD));
min=dnaAnalogChannels; // GOTCHA
max=ARFGraphs.NumGraphs; // GOTCHA
if (!(groupArray->EnabledQ)) // if there is no array to check
max=min; // then disabled completely
for (i=min; i<max; i++) {
if (RFGroups.EnabledQ[i-min])
errChk(enableGraph(i)); // So much work for one line of code....