-
Notifications
You must be signed in to change notification settings - Fork 24
/
Copy pathparameter.c
2689 lines (2386 loc) · 81 KB
/
parameter.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
/*----------------------------------------------------------------------*/
/* parameter.c */
/* Copyright (c) 2002 Tim Edwards, Johns Hopkins University */
/*----------------------------------------------------------------------*/
/*----------------------------------------------------------------------*/
/* written by Tim Edwards, 10/26/99 */
/* revised for segmented strings, 3/8/01 */
/*----------------------------------------------------------------------*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#ifndef XC_WIN32
#include <X11/Intrinsic.h>
#include <X11/StringDefs.h>
#endif
#ifdef TCL_WRAPPER
#include <tk.h>
#else
#ifndef XC_WIN32
#include "Xw/Xw.h"
#endif
#endif
/*----------------------------------------------------------------------*/
/* Local includes */
/*----------------------------------------------------------------------*/
#include "xcircuit.h"
#include "menudep.h"
/*----------------------------------------------------------------------*/
/* Function prototype declarations */
/*----------------------------------------------------------------------*/
#include "prototypes.h"
/*----------------------------------------------------------------------*/
/* Externally declared global variables */
/*----------------------------------------------------------------------*/
#ifdef TCL_WRAPPER
extern Tcl_Interp *xcinterp;
#endif
extern Globaldata xobjs;
extern XCWindowData *areawin;
#ifndef TCL_WRAPPER
extern Widget menuwidgets[];
#endif
extern char _STR[150];
/*----------------------------------------------------------------------*/
/* The following u_char array matches parameterization types to element */
/* types which are able to accept the given parameterization. */
/*----------------------------------------------------------------------*/
u_char param_select[] = {
ALL_TYPES, /* P_NUMERIC */
LABEL, /* P_SUBSTRING */
POLYGON | SPLINE | LABEL | OBJINST | ARC, /* P_POSITION_X */
POLYGON | SPLINE | LABEL | OBJINST | ARC, /* P_POSITION_Y */
POLYGON | SPLINE | ARC | PATH, /* P_STYLE */
LABEL, /* P_ANCHOR */
ARC, /* P_ANGLE1 */
ARC, /* P_ANGLE2 */
ARC, /* P_RADIUS */
ARC, /* P_MINOR_AXIS */
LABEL | OBJINST, /* P_ROTATION */
LABEL | OBJINST, /* P_SCALE */
POLYGON | SPLINE | ARC | PATH, /* P_LINEWIDTH */
ALL_TYPES, /* P_COLOR */
ALL_TYPES, /* P_EXPRESSION */
POLYGON | SPLINE | LABEL | OBJINST | ARC /* P_POSITION */
};
#ifdef TCL_WRAPPER
#ifndef _MSC_VER
xcWidget *param_buttons[] = { NULL /* (jdk) */
/* To be done---map buttons to Tk_Windows! */
};
#else
xcWidget *param_buttons[];
#endif
#else
Widget *param_buttons[] = {
&ParametersNumericButton, /* P_NUMERIC */
&ParametersSubstringButton, /* P_SUBSTRING */
&ParametersPositionButton, /* P_POSITION_X */
&ParametersPositionButton, /* P_POSITION_Y */
&ParametersStyleButton, /* P_STYLE */
&ParametersAnchoringButton, /* P_ANCHOR */
&ParametersStartAngleButton, /* P_ANGLE1 */
&ParametersEndAngleButton, /* P_ANGLE2 */
&ParametersRadiusButton, /* P_RADIUS */
&ParametersMinorAxisButton, /* P_MINOR_AXIS */
&ParametersRotationButton, /* P_ROTATION */
&ParametersScaleButton, /* P_SCALE */
&ParametersLinewidthButton, /* P_LINEWIDTH */
&ParametersColorButton, /* P_COLOR */
&ParametersPositionButton, /* P_POSITION */
};
#endif
/*----------------------------------------------------------------------*/
/* Basic routines for matching parameters by key values. Note that */
/* this really, really ought to be replaced by a hash table search! */
/*----------------------------------------------------------------------*/
/*----------------------------------------------------------------------*/
/* Check for the existance of a parameter with key "key" in object */
/* "thisobj". Return true if the parameter exists. */
/*----------------------------------------------------------------------*/
Boolean check_param(objectptr thisobj, char *key)
{
oparamptr tops;
for (tops = thisobj->params; tops != NULL; tops = tops->next)
if (!strcmp(tops->key, key))
return TRUE;
return FALSE;
}
/*----------------------------------------------------------------------*/
/* Create a new parameter; allocate memory for the parameter and the */
/* key. */
/*----------------------------------------------------------------------*/
oparamptr make_new_parameter(char *key)
{
oparamptr newops;
newops = (oparamptr)malloc(sizeof(oparam));
newops->next = NULL;
newops->key = (char *)malloc(1 + strlen(key));
strcpy(newops->key, key);
return newops;
}
/*----------------------------------------------------------------------*/
/* Create a new element (numeric) parameter. Fill in essential values */
/*----------------------------------------------------------------------*/
eparamptr make_new_eparam(char *key)
{
eparamptr newepp;
newepp = (eparamptr)malloc(sizeof(eparam));
newepp->next = NULL;
newepp->key = (char *)malloc(1 + strlen(key));
strcpy(newepp->key, key);
newepp->pdata.refkey = NULL; /* equivalently, sets pointno=0 */
newepp->flags = 0;
return newepp;
}
/*----------------------------------------------------------------------*/
/* Determine if a parameter is indirectly referenced. If so, return */
/* the parameter name. If not, return NULL. */
/*----------------------------------------------------------------------*/
char *find_indirect_param(objinstptr thisinst, char *refkey)
{
eparamptr epp;
for (epp = thisinst->passed; epp != NULL; epp = epp->next) {
if ((epp->flags & P_INDIRECT) && !strcmp(epp->pdata.refkey, refkey))
return epp->key;
}
return NULL;
}
/*----------------------------------------------------------------------*/
/* Find the parameter in the indicated object by key */
/*----------------------------------------------------------------------*/
oparamptr match_param(objectptr thisobj, char *key)
{
oparamptr fparam;
for (fparam = thisobj->params; fparam != NULL; fparam = fparam->next)
if (!strcmp(fparam->key, key))
return fparam;
return NULL; /* No parameter matched the key---error condition */
}
/*----------------------------------------------------------------------*/
/* Find the parameter in the indicated instance by key. If no such */
/* instance value exists, return NULL. */
/*----------------------------------------------------------------------*/
oparamptr match_instance_param(objinstptr thisinst, char *key)
{
oparamptr fparam;
for (fparam = thisinst->params; fparam != NULL; fparam = fparam->next)
if (!strcmp(fparam->key, key))
return fparam;
return NULL; /* No parameter matched the key---error condition */
}
/*----------------------------------------------------------------------*/
/* Find the parameter in the indicated instance by key. If no such */
/* instance value exists, return the object (default) parameter. */
/* */
/* find_param() hides instances of expression parameters, returning the */
/* default parameter value. In cases where the instance value (last */
/* evaluated expression result) is needed, use match_instance_param(). */
/* An exception is made when the instance param has type XC_EXPR, */
/* indicating that the instance redefines the entire expression. */
/*----------------------------------------------------------------------*/
oparamptr find_param(objinstptr thisinst, char *key)
{
oparamptr fparam, ops;
fparam = match_instance_param(thisinst, key);
ops = match_param(thisinst->thisobject, key);
if ((fparam == NULL) || ((ops->type == XC_EXPR) && (fparam->type != XC_EXPR)))
fparam = ops;
return fparam;
}
/*----------------------------------------------------------------------*/
/* Find the total number of parameters in an object */
/*----------------------------------------------------------------------*/
int get_num_params(objectptr thisobj)
{
oparamptr fparam;
int nparam = 0;
for (fparam = thisobj->params; fparam != NULL; fparam = fparam->next)
nparam++;
return nparam;
}
/*----------------------------------------------------------------------*/
/* Remove all element parameters from an element */
/*----------------------------------------------------------------------*/
void free_all_eparams(genericptr thiselem)
{
while (thiselem->passed != NULL)
free_element_param(thiselem, thiselem->passed);
}
/*----------------------------------------------------------------------*/
/* Remove an element parameter (eparam) and free memory associated with */
/* the parameter key. */
/*----------------------------------------------------------------------*/
void free_element_param(genericptr thiselem, eparamptr thisepp)
{
eparamptr epp, lastepp = NULL;
for (epp = thiselem->passed; epp != NULL; epp = epp->next) {
if (epp == thisepp) {
if (lastepp != NULL)
lastepp->next = epp->next;
else
thiselem->passed = epp->next;
/* If object is an instance and the pdata record is not NULL, */
/* then this is an indirect reference with the reference key */
/* stored as an allocated string in pdata.refkey, which needs */
/* to be free'd. */
if ((epp->flags & P_INDIRECT) && (epp->pdata.refkey != NULL))
free(epp->pdata.refkey);
free(epp->key);
free(epp);
break;
}
lastepp = epp;
}
}
/*----------------------------------------------------------------------*/
/* Free an instance parameter. Note that this routine does not free */
/* any strings associated with string parameters! */
/* */
/* Return a pointer to the entry before the one deleted, so we can use */
/* free_instance_param() inside a loop over an instance's parameters */
/* without having to keep track of the previous pointer position. */
/*----------------------------------------------------------------------*/
oparamptr free_instance_param(objinstptr thisinst, oparamptr thisparam)
{
oparamptr ops, lastops = NULL;
for (ops = thisinst->params; ops != NULL; ops = ops->next) {
if (ops == thisparam) {
if (lastops != NULL)
lastops->next = ops->next;
else
thisinst->params = ops->next;
free(ops->key);
free(ops);
break;
}
lastops = ops;
}
return lastops;
}
/*----------------------------------------------------------------------*/
/* Convenience function used by files.c to set a color parameter. */
/*----------------------------------------------------------------------*/
void std_eparam(genericptr gen, char *key)
{
eparamptr epp;
if (key == NULL) return;
epp = make_new_eparam(key);
epp->next = gen->passed;
gen->passed = epp;
}
/*----------------------------------------------*/
/* Draw a circle at all parameter positions */
/*----------------------------------------------*/
void indicateparams(genericptr thiselem)
{
int k;
oparamptr ops;
eparamptr epp;
genericptr *pgen;
if (thiselem != NULL) {
for (epp = thiselem->passed; epp != NULL; epp = epp->next) {
ops = match_param(topobject, epp->key);
if (ops == NULL) continue; /* error condition */
if (ELEMENTTYPE(thiselem) == PATH)
k = epp->pdata.pathpt[1];
else
k = epp->pdata.pointno;
if (k < 0) k = 0;
switch(ops->which) {
case P_POSITION: case P_POSITION_X: case P_POSITION_Y:
switch(thiselem->type) {
case ARC:
UDrawCircle(&TOARC(&thiselem)->position, ops->which);
break;
case LABEL:
UDrawCircle(&TOLABEL(&thiselem)->position, ops->which);
break;
case OBJINST:
UDrawCircle(&TOOBJINST(&thiselem)->position, ops->which);
break;
case POLYGON:
UDrawCircle(TOPOLY(&thiselem)->points + k, ops->which);
break;
case SPLINE:
UDrawCircle(&TOSPLINE(&thiselem)->ctrl[k], ops->which);
break;
case PATH:
if (epp->pdata.pathpt[0] < 0)
pgen = ((pathptr)thiselem)->plist;
else
pgen = ((pathptr)thiselem)->plist + epp->pdata.pathpt[0];
if (ELEMENTTYPE(*pgen) == POLYGON)
UDrawCircle(TOPOLY(pgen)->points + k, ops->which);
else /* spline */
UDrawCircle(&TOSPLINE(pgen)->ctrl[k], ops->which);
break;
}
break;
}
}
}
}
/*----------------------------------------------*/
/* Set the menu marks according to properties */
/* which are parameterized. Unmanage the */
/* buttons which do not apply. */
/* */
/* pgen = NULL returns menu to default settings */
/*----------------------------------------------*/
#ifdef TCL_WRAPPER
void setparammarks(genericptr thiselem)
{
/* Set GUI variables associated with the "parameter" menu. */
int i;
oparamptr ops;
eparamptr epp;
Boolean ptest[NUM_PARAM_TYPES];
for (i = 0; i < NUM_PARAM_TYPES; i++)
ptest[i] = FALSE;
/* For each parameter declared, set the corresponding Tcl variable */
if (thiselem != NULL) {
for (epp = thiselem->passed; epp != NULL; epp = epp->next) {
ops = match_param(topobject, epp->key);
if (ops == NULL) continue; /* error condition */
XcInternalTagCall(xcinterp, 3, "parameter", "make",
translateparamtype(ops->which));
ptest[ops->which] = TRUE;
}
}
/* Now reset all of those parameters that were not set above. */
/* Note that the parameters that we want to mark ignore the following types: */
/* "numeric", "substring", "expression", and "position". */
for (i = P_POSITION_X; i <= P_COLOR; i++)
if (ptest[i] != TRUE)
XcInternalTagCall(xcinterp, 3, "parameter", "replace", translateparamtype(i));
}
#else
void setparammarks(genericptr thiselem)
{
Widget w;
Arg wargs[1];
const int rlength = sizeof(param_buttons) / sizeof(Widget *);
int i, j, paramno;
oparamptr ops;
eparamptr epp;
/* Clear all checkmarks */
for (i = 0; i < rlength; i++) {
XtSetArg(wargs[0], XtNsetMark, False);
XtSetValues(*param_buttons[i], wargs, 1);
}
/* Check those properties which are parameterized in the element */
if (thiselem != NULL) {
for (epp = thiselem->passed; epp != NULL; epp = epp->next) {
ops = match_param(topobject, epp->key);
w = *param_buttons[ops->which];
XtSetArg(wargs[0], XtNsetMark, True);
XtSetValues(w, wargs, 1);
}
}
/* Unmanage widgets which do not apply to the element type */
for (i = 0; i < rlength; i++) {
if ((thiselem == NULL) || (param_select[i] & thiselem->type))
XtManageChild(*param_buttons[i]);
else
XtUnmanageChild(*param_buttons[i]);
}
}
#endif
/*------------------------------------------------------*/
/* This function is like epsubstitute() below it, but */
/* only substitutes those values that are expression */
/* types. This allows constraints to be applied when */
/* editing elements. */
/*------------------------------------------------------*/
void exprsub(genericptr thiselem)
{
genericptr *pgen;
eparamptr epp;
int k, ival;
oparamptr dps, ops;
float fval;
XPoint *setpt;
char *promoted;
for (epp = thiselem->passed; epp != NULL; epp = epp->next) {
ops = match_param(topobject, epp->key);
dps = find_param(areawin->topinstance, epp->key);
if (dps != NULL) {
switch(dps->type) {
case XC_EXPR:
if ((promoted = evaluate_expr(topobject, dps, areawin->topinstance))
== NULL) continue;
if (sscanf(promoted, "%g", &fval) == 1)
ival = (int)(fval + 0.5);
free(promoted);
if (ELEMENTTYPE(thiselem) == PATH)
k = epp->pdata.pathpt[1];
else
k = epp->pdata.pointno;
if (ops->which == P_POSITION_X) {
switch(thiselem->type) {
case PATH:
pgen = TOPATH(&thiselem)->plist + epp->pdata.pathpt[0];
if (ELEMENTTYPE(*pgen) == POLYGON) {
setpt = TOPOLY(pgen)->points + k;
setpt->x = ival;
}
else { /* spline */
TOSPLINE(pgen)->ctrl[k].x = ival;
}
break;
case POLYGON:
setpt = TOPOLY(&thiselem)->points + k;
setpt->x = ival;
break;
case SPLINE:
TOSPLINE(&thiselem)->ctrl[k].x = ival;
break;
}
}
else if (ops->which == P_POSITION_Y) {
switch(thiselem->type) {
case PATH:
pgen = TOPATH(&thiselem)->plist + epp->pdata.pathpt[0];
if (ELEMENTTYPE(*pgen) == POLYGON) {
setpt = TOPOLY(pgen)->points + k;
setpt->y = ival;
}
else { /* spline */
TOSPLINE(pgen)->ctrl[k].y = ival;
}
break;
case POLYGON:
setpt = TOPOLY(&thiselem)->points + k;
setpt->y = ival;
break;
case SPLINE:
TOSPLINE(&thiselem)->ctrl[k].y = ival;
break;
}
}
}
}
}
}
/*------------------------------------------------------*/
/* Make numerical parameter substitutions into an */
/* element. */
/*------------------------------------------------------*/
int epsubstitute(genericptr thiselem, objectptr thisobj, objinstptr pinst,
Boolean *needrecalc)
{
genericptr *pgen;
eparamptr epp;
oparamptr dps, ops;
int retval = -1;
int i, k, ival, diff;
char *key;
float fval;
XPoint *setpt;
char *promoted;
for (epp = thiselem->passed; epp != NULL; epp = epp->next) {
/* Use the parameter from the instance, if available. */
/* Otherwise, revert to the type of the object. */
/* Normally they will be the same. */
ops = match_param(thisobj, epp->key);
dps = (pinst != NULL) ? find_param(pinst, epp->key) : ops;
if (dps != NULL) {
/* Get integer and float values. Promote types if necessary */
switch(dps->type) {
case XC_INT:
ival = dps->parameter.ivalue;
fval = (float)(ival);
break;
case XC_FLOAT:
fval = dps->parameter.fvalue;
ival = (int)(fval + ((fval < 0) ? -0.5 : 0.5));
break;
case XC_STRING:
promoted = textprint(dps->parameter.string, pinst);
if (sscanf(promoted, "%g", &fval) == 1)
ival = (int)(fval + ((fval < 0) ? -0.5 : 0.5));
else
ival = 0;
free(promoted);
break;
case XC_EXPR:
if ((promoted = evaluate_expr(thisobj, dps, pinst)) == NULL) continue;
if (sscanf(promoted, "%g", &fval) == 1)
ival = (int)(fval + ((fval < 0) ? -0.5 : 0.5));
free(promoted);
break;
}
}
else if (ops == NULL)
continue;
if ((epp->flags & P_INDIRECT) && (epp->pdata.refkey != NULL)) {
key = epp->pdata.refkey;
if (key != NULL) {
objinstptr thisinst;
oparamptr refop, newop;
thisinst = (objinstptr)thiselem;
/* Sanity check: refkey must exist in object */
refop = match_param(thisinst->thisobject, key);
if (refop == NULL) {
Fprintf(stderr, "Error: Reference key %s does not"
" exist in object %s\n",
key, thisinst->thisobject->name);
continue;
}
/* If an instance value already exists, remove it */
newop = match_instance_param(thisinst, refop->key);
if (newop != NULL)
free_instance_param(thisinst, newop);
/* Create a new instance parameter */
newop = copyparameter(dps);
newop->next = thisinst->params;
thisinst->params = newop;
/* Change the key from the parent to the child */
if (strcmp(ops->key, refop->key)) {
free(newop->key);
newop->key = strdup(refop->key);
}
continue;
}
}
if (ELEMENTTYPE(thiselem) == PATH)
k = epp->pdata.pathpt[1];
else
k = epp->pdata.pointno;
switch(ops->which) {
case P_POSITION_X:
retval = max(retval, 1);
switch(thiselem->type) {
case PATH:
if (k < 0) {
pgen = TOPATH(&thiselem)->plist;
if (ELEMENTTYPE(*pgen) == POLYGON) {
setpt = TOPOLY(pgen)->points;
diff = ival - setpt->x;
}
else { /* spline */
diff = ival - TOSPLINE(pgen)->ctrl[0].x;
}
for (pgen = TOPATH(&thiselem)->plist; pgen <
TOPATH(&thiselem)->plist +
TOPATH(&thiselem)->parts; pgen++) {
if (ELEMENTTYPE(*pgen) == POLYGON) {
for (i = 0; i < TOPOLY(pgen)->number; i++) {
setpt = TOPOLY(pgen)->points + i;
setpt->x += diff;
}
}
else { /* spline */
for (i = 0; i < 4; i++) {
TOSPLINE(pgen)->ctrl[i].x += diff;
}
if (needrecalc) *needrecalc = True;
}
}
}
else {
pgen = TOPATH(&thiselem)->plist + epp->pdata.pathpt[0];
if (ELEMENTTYPE(*pgen) == POLYGON) {
setpt = TOPOLY(pgen)->points + k;
setpt->x = ival;
}
else { /* spline */
TOSPLINE(pgen)->ctrl[k].x = ival;
if (needrecalc) *needrecalc = True;
}
}
break;
case POLYGON:
if (k < 0) {
setpt = TOPOLY(&thiselem)->points;
diff = ival - setpt->x;
for (i = 0; i < TOPOLY(&thiselem)->number; i++) {
setpt = TOPOLY(&thiselem)->points + i;
setpt->x += diff;
}
}
else {
setpt = TOPOLY(&thiselem)->points + k;
setpt->x = ival;
}
break;
case SPLINE:
if (k < 0) {
setpt = &(TOSPLINE(&thiselem)->ctrl[0]);
diff = ival - setpt->x;
for (i = 0; i < 4; i++) {
setpt = &(TOSPLINE(&thiselem)->ctrl[i]);
setpt->x += diff;
}
}
else {
TOSPLINE(&thiselem)->ctrl[k].x = ival;
}
if (needrecalc) *needrecalc = True;
break;
case LABEL:
TOLABEL(&thiselem)->position.x = ival;
break;
case OBJINST:
TOOBJINST(&thiselem)->position.x = ival;
break;
case ARC:
TOARC(&thiselem)->position.x = ival;
break;
}
break;
case P_POSITION_Y:
retval = max(retval, 1);
switch(thiselem->type) {
case PATH:
if (k < 0) {
pgen = TOPATH(&thiselem)->plist;
if (ELEMENTTYPE(*pgen) == POLYGON) {
setpt = TOPOLY(pgen)->points;
diff = ival - setpt->y;
}
else { /* spline */
diff = ival - TOSPLINE(pgen)->ctrl[0].y;
}
for (pgen = TOPATH(&thiselem)->plist; pgen <
TOPATH(&thiselem)->plist +
TOPATH(&thiselem)->parts; pgen++) {
if (ELEMENTTYPE(*pgen) == POLYGON) {
for (i = 0; i < TOPOLY(pgen)->number; i++) {
setpt = TOPOLY(pgen)->points + i;
setpt->y += diff;
}
}
else { /* spline */
for (i = 0; i < 4; i++) {
TOSPLINE(pgen)->ctrl[i].y += diff;
}
if (needrecalc) *needrecalc = True;
}
}
}
else {
pgen = TOPATH(&thiselem)->plist + epp->pdata.pathpt[0];
if (ELEMENTTYPE(*pgen) == POLYGON) {
setpt = TOPOLY(pgen)->points + k;
setpt->y = ival;
}
else { /* spline */
TOSPLINE(pgen)->ctrl[k].y = ival;
if (needrecalc) *needrecalc = True;
}
}
break;
case POLYGON:
if (k < 0) {
setpt = TOPOLY(&thiselem)->points;
diff = ival - setpt->y;
for (i = 0; i < TOPOLY(&thiselem)->number; i++) {
setpt = TOPOLY(&thiselem)->points + i;
setpt->y += diff;
}
}
else {
setpt = TOPOLY(&thiselem)->points + k;
setpt->y = ival;
}
break;
case SPLINE:
if (k < 0) {
setpt = &(TOSPLINE(&thiselem)->ctrl[0]);
diff = ival - setpt->y;
for (i = 0; i < 4; i++) {
setpt = &(TOSPLINE(&thiselem)->ctrl[i]);
setpt->y += diff;
}
}
else {
TOSPLINE(&thiselem)->ctrl[k].y = ival;
}
if (needrecalc) *needrecalc = True;
break;
case LABEL:
TOLABEL(&thiselem)->position.y = ival;
break;
case OBJINST:
TOOBJINST(&thiselem)->position.y = ival;
break;
case ARC:
TOARC(&thiselem)->position.y = ival;
break;
}
break;
case P_STYLE:
retval = max(retval, 0);
switch(thiselem->type) {
case POLYGON:
TOPOLY(&thiselem)->style = ival;
break;
case SPLINE:
TOSPLINE(&thiselem)->style = ival;
break;
case ARC:
TOARC(&thiselem)->style = ival;
break;
case PATH:
TOPATH(&thiselem)->style = ival;
break;
}
break;
case P_ANCHOR:
retval = max(retval, 1);
switch(thiselem->type) {
case LABEL:
TOLABEL(&thiselem)->anchor = ival;
break;
}
break;
case P_ANGLE1:
retval = max(retval, 1);
switch(thiselem->type) {
case ARC:
TOARC(&thiselem)->angle1 = fval;
if (needrecalc) *needrecalc = True;
break;
}
break;
case P_ANGLE2:
retval = max(retval, 1);
switch(thiselem->type) {
case ARC:
TOARC(&thiselem)->angle1 = fval;
if (needrecalc) *needrecalc = True;
break;
}
break;
case P_RADIUS:
retval = max(retval, 1);
switch(thiselem->type) {
case ARC:
TOARC(&thiselem)->radius = ival;
TOARC(&thiselem)->yaxis = ival;
if (needrecalc) *needrecalc = True;
break;
}
break;
case P_MINOR_AXIS:
retval = max(retval, 1);
switch(thiselem->type) {
case ARC:
TOARC(&thiselem)->yaxis = ival;
if (needrecalc) *needrecalc = True;
break;
}
break;
case P_ROTATION:
retval = max(retval, 1);
switch(thiselem->type) {
case LABEL:
TOLABEL(&thiselem)->rotation = fval;
break;
case OBJINST:
TOOBJINST(&thiselem)->rotation = fval;
break;
}
break;
case P_SCALE:
retval = max(retval, 1);
switch(thiselem->type) {
case LABEL:
TOLABEL(&thiselem)->scale = fval;
break;
case OBJINST:
TOOBJINST(&thiselem)->scale = fval;
break;
}
break;
case P_LINEWIDTH:
retval = max(retval, 0);
switch(thiselem->type) {
case POLYGON:
TOPOLY(&thiselem)->width = fval;
break;
case SPLINE:
TOSPLINE(&thiselem)->width = fval;
break;
case ARC:
TOARC(&thiselem)->width = fval;
break;
case PATH:
TOPATH(&thiselem)->width = fval;
break;
}
break;
case P_COLOR:
retval = max(retval, 0);
thiselem->color = ival;
break;
}
}
return retval;
}
/*------------------------------------------------------*/
/* Make numerical parameter substitutions into all */
/* elements of an object. "thisinst" may be NULL, in */
/* which case all default values are used in the */
/* substitution. */
/* */
/* Return values: */
/* -1 if the instance declares no parameters */
/* 0 if parameters do not change the instance's bbox */
/* 1 if parameters change instance's bbox */
/* 2 if parameters change instance's netlist */
/*------------------------------------------------------*/
int opsubstitute(objectptr thisobj, objinstptr pinst)
{
genericptr *eptr, *pgen, thiselem;
stringpart *strptr;
int retval = -1;
Boolean needrecalc; /* for arcs and splines */
/* Perform expression parameter substitutions on all labels. */
/* Note that this used to be done on an immediate basis as */
/* labels were parsed. The main difference is that only one */
/* expression parameter can be used per label if it is to */
/* compute the result of some aspect of the label, such as */
/* position; this is a tradeoff for much simplified handling */
/* of expression results, like having to avoid infinite */
/* recursion in an expression result. */
for (eptr = thisobj->plist; eptr < thisobj->plist + thisobj->parts; eptr++)
if ((*eptr)->type == LABEL)
for (strptr = (TOLABEL(eptr))->string; strptr != NULL; strptr =
nextstringpartrecompute(strptr, pinst));
if (thisobj->params == NULL)
return -1; /* object has no parameters */
for (eptr = thisobj->plist; eptr < thisobj->plist + thisobj->parts; eptr++) {
needrecalc = False;
thiselem = *eptr;
if (thiselem->passed == NULL) continue; /* Nothing to substitute */
retval = epsubstitute(thiselem, thisobj, pinst, &needrecalc);
/* substitutions into arcs and splines require that the */
/* line segments be recalculated. */
if (needrecalc) {
switch(thiselem->type) {
case ARC:
calcarc((arcptr)thiselem);
break;
case SPLINE:
calcspline((splineptr)thiselem);
break;
case PATH:
for (pgen = ((pathptr)thiselem)->plist; pgen < ((pathptr)thiselem)->plist
+ ((pathptr)thiselem)->parts; pgen++)
if (ELEMENTTYPE(*pgen) == SPLINE)
calcspline((splineptr)*pgen);
break;
}
}
}
return retval;
}
/*------------------------------------------------------*/
/* Same as above, but determines the object from the */
/* current page hierarchy. */
/*------------------------------------------------------*/
int psubstitute(objinstptr thisinst)
{
objinstptr pinst;
objectptr thisobj;
pinst = (thisinst == areawin->topinstance) ? areawin->topinstance : thisinst;
if (pinst == NULL) return -1; /* there is no instance */
thisobj = pinst->thisobject;
return opsubstitute(thisobj, pinst);
}