-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathdraw.c
2636 lines (2252 loc) · 67 KB
/
draw.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 <math.h>
#include <X11/Xlib.h>
#include <string.h>
#include "db.h"
#include "rubber.h"
#include "xwin.h"
#include "postscript.h"
#include "eprintf.h"
#include "equate.h"
#include "ev.h"
#include "readfont.h"
#define UNUSED(x) (void)(x)
#define FUZZBAND 0.01 /* how big the fuzz around lines is as */
/* a fraction of minimum window dimension */
/* for the purpose of picking objects */
/* global variables that need to eventually be on a stack for nested edits */
static int drawon=1; /* 0 = dont draw, 1 = draw (used in nesting)*/
static int showon=1; /* 0 = layer currently turned off */
// static int nestlevel=9; // nesting level
// int physicalnest=1; // 1=physical (WIN:N), 0=logical (WIN:L)
static int draw_fill=FILL_OFF;
static int layer_fill=FILL_OFF;
static int X=1; /* 1 = draw to X, 0 = emit autoplot commands */
FILE *PLOT_FD; /* file descriptor for plotting */
int filled_object = 0; /* global for managing polygon filling */
int n_poly_points = 0; /* number of points in filled polygon */
#define MAXPOLY 1024 /* maximum polygon size */
XPoint Poly[MAXPOLY];
void clipl(); /* polygon clipping pipeline: clip left side */
void clipr(); /* clip right side */
void clipt(); /* clip top */
void clipb(); /* clip bottom */
void clip_setwindow(); /* set clipping window */
static double xmin;
static double xmax;
static double ymin;
static double ymax;
int pickcheck();
void emit();
static int debug = 0;
/****************************************************/
/* rendering routines */
/* db_render() sets globals xmax, ymax, xmin, ymin; */
/****************************************************/
void db_set_fill(int fill)
{
extern int draw_fill;
if (fill == FILL_TOGGLE) {
if (draw_fill == FILL_ON) {
draw_fill = FILL_OFF;
} else {
draw_fill = FILL_ON;
}
} else if (fill == FILL_ON || fill == FILL_OFF) {
draw_fill = fill;
} else {
printf("bad fill argument in db_set_fill() %d\n", fill);
exit(1);
}
}
void db_set_physical(int physical) // 1=physical (WIN:N), 0=logical (WIN:L)
{
if (currep != NULL) {
currep->physical = physical;
}
}
void db_set_nest(int nest)
{
if (currep != NULL) {
currep->nestlevel = nest;
}
}
void db_bounds_update(BOUNDS *mybb, BOUNDS *childbb)
{
if (mybb->init==0) {
mybb->xmin = childbb->xmin;
mybb->ymin = childbb->ymin;
mybb->xmax = childbb->xmax;
mybb->ymax = childbb->ymax;
mybb->init++;
} else if (childbb->init != 0 && mybb->init != 0) {
/* pass bounding box back */
mybb->xmin=min(mybb->xmin, childbb->xmin);
mybb->ymin=min(mybb->ymin, childbb->ymin);
mybb->xmax=max(mybb->xmax, childbb->xmax);
mybb->ymax=max(mybb->ymax, childbb->ymax);
}
return;
}
/* a fast approximation to euclidian distance */
/* with no sqrt() and about 5% accuracy */
double dist(double dx,double dy)
{
dx = dx<0?-dx:dx; /* absolute value */
dy = dy<0?-dy:dy;
if (dx > dy) {
return(dx + 0.3333*dy);
} else {
return(dy + 0.3333*dx);
}
// if you want more accuracy
// at the cost of another multiply use
// 0.9615dx + 0.39*dy
}
/* called with pick point x,y and bounding box in p return -1 if xy */
/* inside bb, otherwise return a number between zero and 1 */
/* monotonically related to inverse distance of xy from bounding box */
double bb_distance(double x, double y, DB_DEFLIST *p, double fuzz)
{
int outcode;
double retval;
double tmp;
outcode = 0;
/* 9 8 10
1 0 2
5 4 6 */
if (p->xmin > p->xmax) {
tmp = p->xmax;
p->xmax = p->xmin;
p->xmin = tmp;
}
if (p->ymin > p->ymax) {
tmp = p->ymax;
p->ymax = p->ymin;
p->ymin = tmp;
}
if (x <= p->xmin-fuzz) outcode += 1;
if (x > p->xmax+fuzz) outcode += 2;
if (y <= p->ymin-fuzz) outcode += 4;
if (y > p->ymax+fuzz) outcode += 8;
switch (outcode) {
case 0: /* p is inside BB */
retval = -1.0;
break;
case 1: /* p is West */
retval = 1.0/(1.0 + (p->xmin-x));
break;
case 2: /* p is East */
retval = 1.0/(1.0 + (x-p->xmax));
break;
case 4: /* p is South */
retval = 1.0/(1.0 + (p->ymin-y));
break;
case 5: /* p is SouthWest */
retval = 1.0/(1.0 + dist(p->ymin-y,p->xmin-x));
break;
case 6: /* p is SouthEast */
retval = 1.0/(1.0 + dist(p->ymin-y,x-p->xmax));
break;
case 8: /* p is North */
retval = 1.0/(1.0 + (y-p->ymax));
break;
case 9: /* p is NorthWest */
retval = 1.0/(1.0 + dist(y-p->ymax, p->xmin-x));
break;
case 10: /* p is NorthEast */
retval = 1.0/(1.0 + dist(y-p->ymax, x-p->xmax));
break;
default:
printf("bad case in bb_distance %d\n", outcode);
exit(1);
break;
}
/* printf("%.5g %.5g %.5g %.5g %.5g %d\n",
p->xmin, p->ymin, p->xmax, p->ymax, retval, outcode); */
return (retval);
}
/*
* db_ident() takes a pick point (x,y) and renders through
* the database to find the best candidate near the point.
*
* Run through all components in the device and
* give each a score. The component with the best score is
* returned as the final pick.
*
* three different scores:
* CASE 1: ; pick point is outside of BoundingBox (BB),
* higher score the closer to BB
* (0< score < 1)
* score is 1/(1+distance to cell BB)
* CASE 2: ; pick inside of BB, doesn't touch any rendered lines
* (1<= score < 2)
* score is 1+1/(1+min_dimension_of cell BB)
* score is weighted so that smaller BBs get better score
* This allows picking the inner of nested rectangles
* CASE 3: ; pick inside of BB, touches a rendered line
* (2<= score < 3)
* score is 2+1/(1+min_dimension_of line BB)
*
* CASE 1 serves as a crude selector in the case that the
* pick point is not inside any bounding box. It also serves
* as a crude screening to avoid having to test all the components
* in detail.
*
* CASE 2 is for picks that fall inside a bounding box. It has a
* higher score than anything in CASE 1 so it will take priority
* Smaller bounding boxes get higher ranking.
*
* CASE 3 overrides CASE 1 and CASE 2. It comes into play when
* the pick point is near an actual drawn segment of a component.
*
*/
DB_DEFLIST *db_ident(
DB_TAB *cell, /* device being edited */
double x, double y, /* pick point */
int mode, /* 0=ident (any visible), 1=pick (pick restricted to modifiable objects) */
int pick_layer, /* layer restriction, or 0=all */
int comp, /* comp restriction */
char *name /* instance name restrict or NULL */
)
{
DB_DEFLIST *p;
DB_DEFLIST *p_best = NULL; /* gets returned */
int debug=0;
BOUNDS childbb;
double pick_score=0.0;
double pick_best=0.0;
double fuzz;
int layer;
int bad_comp;
if (cell == NULL) {
printf("no cell currently being edited!\n");
return(0);
}
if (mode && debug) { /* pick rather than ident mode */
printf("db_ident: called with layer %d, comp %d, name %s\n",
pick_layer, comp, name);
}
/* pick fuzz should be a fraction of total window size */
fuzz = max((cell->maxx-cell->minx),(cell->maxy-cell->miny))*FUZZBAND;
for (p=cell->dbhead; p!=(DB_DEFLIST *)0; p=p->next) {
childbb.init=0;
/* screen components by crude bounding boxes then */
/* render each one in D_PICK mode for detailed test */
switch (p->type) {
case ARC: /* arc definition */
layer = p->u.a->layer;
break;
case CIRC: /* arc definition */
layer = p->u.c->layer;
break;
case LINE: /* arc definition */
layer = p->u.l->layer;
break;
case NOTE: /* note definition */
layer = p->u.n->layer;
break;
case OVAL: /* oval definition */
layer = p->u.o->layer;
break;
case POLY: /* polygon definition */
layer = p->u.p->layer;
break;
case RECT: /* rectangle definition */
layer = p->u.r->layer;
break;
case TEXT: /* text definition */
layer = p->u.t->layer;
break;
case INST: /* instance definition */
layer = 0;
break;
default:
layer = 0;
printf("error in db_ident switch\n");
break;
}
/* check all the restrictions on picking something */
if (name != NULL) {comp = INST;}
bad_comp=0;
if ((pick_layer != 0 && layer != pick_layer) ||
(comp != 0 && comp != ALL && p->type != comp) ||
(mode == 0 && !show_check_visible(currep, p->type, layer)) ||
(mode == 1 && !show_check_modifiable(currep, p->type, layer)) ||
(p->type==INST && name!=NULL && strncmp(name, p->u.i->name, MAXFILENAME))!=0) {
bad_comp++;
}
if (!bad_comp) {
if ((pick_score=bb_distance(x,y,p,fuzz)) < 0.0) { /* inside BB */
/* pick point inside BB gives a score ranging from */
/* 1.0 to 2.0, with smaller BB's getting higher score */
pick_score = 1.0 + 1.0/(1.0+min(fabs(p->xmax-p->xmin),
fabs(p->ymax-p->ymin)));
/* a bit of a hack, but we overload the childbb */
/* structure to pass the point into the draw routine. */
/* If a hit, then childbb.xmax is set to 1.0 */
/* seemed cleaner than more arguments, or */
/* yet another global variable */
childbb.xmin = x;
childbb.ymin = y;
childbb.xmax = 0.0;
switch (p->type) {
case ARC: /* arc definition */
do_arc(p, &childbb, D_PICK);
if (debug) printf("in arc %g\n", childbb.xmax);
break;
case CIRC: /* circle definition */
do_circ(p, &childbb, D_PICK);
if (debug) printf("in circ %g\n", childbb.xmax);
break;
case LINE: /* line definition */
do_line(p, &childbb, D_PICK);
if (debug) printf("in line %g\n", childbb.xmax);
break;
case NOTE: /* note definition */
do_note(p, &childbb, D_PICK);
if (debug) printf("in note %g\n", childbb.xmax);
break;
case OVAL: /* oval definition */
do_oval(p, &childbb, D_PICK);
if (debug) printf("in oval %g\n", childbb.xmax);
break;
case POLY: /* polygon definition */
do_poly(p, &childbb, D_PICK);
if (debug) printf("in poly %g\n", childbb.xmax);
break;
case RECT: /* rectangle definition */
do_rect(p, &childbb, D_PICK);
if (debug) printf("in rect %g\n", childbb.xmax);
break;
case TEXT: /* text definition */
do_text(p, &childbb, D_PICK);
if (debug) printf("in text %g\n", childbb.xmax);
break;
case INST: /* recursive instance call */
if (debug) printf("in inst %g\n", childbb.xmax);
break;
default:
eprintf("unknown record type: %d in db_ident\n", p->type);
return(0);
break;
}
pick_score += childbb.xmax*3.0;
/* now do some special cases - exact hits on 0,0 coords */
if (p->type == INST && p->u.i->x == x && p->u.i->y == y) {
pick_score += 4.0;
} else if (p->type == CIRC && p->u.c->x1 == x && p->u.c->y1 == y) {
pick_score += 4.0;
}
} else {
/* bb_distance() gives pick_score {0...1} based on bb distances */
}
}
/* keep track of the best of the lot */
/* 0 < pick_score < 1 -> pick is outside bb */
/* 1 < pick_score < 2 -> pick is inside bb */
/* 4 < pick_score < 5 -> pick is inside bb and a fuzzy hit on some line */
if (pick_score > pick_best) {
if (debug) printf("pick_score %g, best %g\n",
pick_score, pick_best);
fflush(stdout);
pick_best=pick_score;
p_best = p;
}
}
return(p_best);
}
SELPNT *db_ident2(
DB_TAB *cell, /* device being edited */
double x, double y, /* pick point */
int mode, /* 0=ident (any visible), 1=pick (only modifiable objects) */
int pick_layer, /* layer restriction, or 0=all */
int comp, /* comp restriction */
char *name /* instance name restrict or NULL */
)
{
DB_DEFLIST *p;
DB_DEFLIST *p_best=NULL;
COORDS *coords;
SELPNT *selpnt; /* gets returned */
int debug=0;
BOUNDS childbb;
double pick_score=0.0;
double pick_best=0.0;
double fuzz;
int layer;
int bad_comp;
if (cell == NULL) {
printf("no cell currently being edited!\n");
return(0);
}
if (mode && debug) { /* pick rather than ident mode */
printf("db_ident: called with layer %d, comp %d, name %s\n",
pick_layer, comp, name);
}
/* pick fuzz should be a fraction of total window size */
fuzz = max((cell->maxx-cell->minx),(cell->maxy-cell->miny))*FUZZBAND;
for (p=cell->dbhead; p!=(DB_DEFLIST *)0; p=p->next) {
childbb.init=0;
/* screen components by crude bounding boxes then */
/* render each one in D_PICK mode for detailed test */
switch (p->type) {
case ARC: /* arc definition */
layer = p->u.a->layer;
break;
case CIRC: /* arc definition */
layer = p->u.c->layer;
break;
case LINE: /* arc definition */
layer = p->u.l->layer;
break;
case NOTE: /* note definition */
layer = p->u.n->layer;
break;
case OVAL: /* oval definition */
layer = p->u.o->layer;
break;
case POLY: /* polygon definition */
layer = p->u.p->layer;
break;
case RECT: /* rectangle definition */
layer = p->u.r->layer;
break;
case TEXT: /* text definition */
layer = p->u.t->layer;
break;
case INST: /* instance definition */
layer = 0;
break;
default:
layer = 0;
printf("error in db_ident switch\n");
break;
}
/* check all the restrictions on picking something */
if (name != NULL) {comp = INST;}
bad_comp=0;
if ((pick_layer != 0 && layer != pick_layer) ||
(comp != 0 && comp != ALL && p->type != comp) ||
(mode == 0 && !show_check_visible(currep, p->type, layer)) ||
(mode == 1 && !show_check_modifiable(currep, p->type, layer)) ||
(p->type==INST && name!=NULL && strncmp(name, p->u.i->name, MAXFILENAME))!=0) {
bad_comp++;
}
if (!bad_comp) {
if ((pick_score=bb_distance(x,y,p,fuzz)) < 0.0) { /* inside BB */
/* pick point inside BB gives a score ranging from */
/* 1.0 to 2.0, with smaller BB's getting higher score */
pick_score = 1.0 + 1.0/(1.0+min(fabs(p->xmax-p->xmin),
fabs(p->ymax-p->ymin)));
/* a bit of a hack, but we overload the childbb */
/* structure to pass the point into the draw routine. */
/* If a hit, then childbb.xmax is set to 1.0 */
/* seemed cleaner than more arguments, or */
/* yet another global variable */
childbb.xmin = x;
childbb.ymin = y;
childbb.xmax = 0.0;
switch (p->type) {
case ARC: /* arc definition */
do_arc(p, &childbb, D_PICK);
if (debug) printf("in arc %g\n", childbb.xmax);
break;
case CIRC: /* circle definition */
do_circ(p, &childbb, D_PICK);
if (debug) printf("in circ %g\n", childbb.xmax);
break;
case LINE: /* line definition */
do_line(p, &childbb, D_PICK);
if (debug) printf("in line %g\n", childbb.xmax);
break;
case NOTE: /* note definition */
do_note(p, &childbb, D_PICK);
if (debug) printf("in note %g\n", childbb.xmax);
break;
case OVAL: /* oval definition */
do_oval(p, &childbb, D_PICK);
if (debug) printf("in oval %g\n", childbb.xmax);
break;
case POLY: /* polygon definition */
do_poly(p, &childbb, D_PICK);
if (debug) printf("in poly %g\n", childbb.xmax);
break;
case RECT: /* rectangle definition */
do_rect(p, &childbb, D_PICK);
if (debug) printf("in rect %g\n", childbb.xmax);
break;
case TEXT: /* text definition */
do_text(p, &childbb, D_PICK);
if (debug) printf("in text %g\n", childbb.xmax);
break;
case INST: /* recursive instance call */
if (debug) printf("in inst %g\n", childbb.xmax);
break;
default:
eprintf("unknown record type: %d in db_ident\n", p->type);
return(0);
break;
}
pick_score += childbb.xmax*3.0;
/* now do some special cases - exact hits on 0,0 coords */
if (p->type == INST && p->u.i->x == x && p->u.i->y == y) {
pick_score += 4.0;
} else if (p->type == CIRC && p->u.c->x1 == x && p->u.c->y1 == y) {
pick_score += 4.0;
}
} else {
/* bb_distance() gives pick_score {0...1} based on bb distances */
}
}
/* keep track of the best of the lot */
/* 0 < pick_score < 1 -> pick is outside bb */
/* 1 < pick_score < 2 -> pick is inside bb */
/* 4 < pick_score < 5 -> pick is inside bb and a fuzzy hit on some line */
if (pick_score > pick_best) {
if (debug) printf("pick_score %g, best %g\n",
pick_score, pick_best);
fflush(stdout);
pick_best=pick_score;
p_best = p;
}
}
selpnt = NULL;
if (p_best != NULL) {
p = p_best;
/* selpnt_clear(&selpnt); */
switch (p->type) {
case ARC:
selpnt_save(&selpnt, &(p->u.a->x1), &(p->u.a->y1), NULL);
selpnt_save(&selpnt, &(p->u.a->x2), &(p->u.a->y2), NULL);
selpnt_save(&selpnt, &(p->u.a->x3), &(p->u.a->y3), NULL);
break;
case CIRC:
selpnt_save(&selpnt, &(p->u.c->x1), &(p->u.c->y1), NULL);
selpnt_save(&selpnt, &(p->u.c->x2), &(p->u.c->y2), NULL);
break;
case INST:
selpnt_save(&selpnt, &(p->u.i->x), &(p->u.i->y), NULL);
break;
case LINE:
for (coords=p->u.l->coords;coords!=NULL;coords=coords->next) {
selpnt_save(&selpnt, &(coords->coord.x), &(coords->coord.y),NULL);
}
break;
case NOTE:
selpnt_save(&selpnt, &(p->u.n->x), &(p->u.n->y), NULL);
break;
case POLY:
for (coords=p->u.p->coords;coords!=NULL;coords=coords->next) {
selpnt_save(&selpnt, &(coords->coord.x), &(coords->coord.y),NULL);
}
break;
case RECT:
selpnt_save(&selpnt, &(p->u.r->x1), &(p->u.r->y1), NULL);
selpnt_save(&selpnt, &(p->u.r->x2), &(p->u.r->y2), NULL);
break;
case TEXT:
selpnt_save(&selpnt, &(p->u.t->x), &(p->u.t->y), NULL);
break;
default:
printf(" not a stretchable object\n");
}
selpnt_save(&selpnt, NULL, NULL, p); /* save comp */
}
return(selpnt);
}
int bb_overlap(
double x1,
double y1,
double x2,
double y2,
double xc1,
double yc1,
double xc2,
double yc2
) {
int err = 0;
double tmp;
/* canonicalize inputs */
if (x1 > x2) { tmp = x2; x2 = x1; x1 = tmp; }
if (y1 > y2) { tmp = y2; y2 = y1; y1 = tmp; }
if (xc1 > xc2) { tmp = xc2; xc2 = xc1; xc1 = tmp; }
if (yc1 > yc2) { tmp = yc2; yc2 = yc1; yc1 = tmp; }
if (y2 < yc1 ) err++;
if (xc2 < x1 ) err++;
if (yc2 < y1 ) err++;
if (xc1 > x2 ) err++;
/* clip one rectangle against another */
if (y1 < yc1 && yc1 < y2) y1 = yc1; /* trim bottom */
if (x1 < xc2 && xc2 < x2) x2 = xc2; /* trim right */
if (y1 < yc2 && yc2 < y2) y2 = yc2; /* trim top */
if (x1 < xc1 && xc1 < x2) x1 = xc1; /* trim left */
if (x1 >= x2) err++;
if (y1 >= y2) err++;
if (!err) {
return 1;
} else {
return 0;
}
}
int bounded(double *x, double *y, double xmin, double ymin, double xmax, double ymax) {
double tmp;
/* canonicalize bounding box */
if (xmax < xmin) { tmp = xmax; xmax = xmin; xmin = tmp; }
if (ymax < ymin) { tmp = ymax; ymax = ymin; ymin = tmp; }
if ((*x >= xmin && *x <= xmax) && (*y >= ymin && *y <= ymax)) {
return 1;
} else {
return 0;
}
}
SELPNT *db_ident_region2(
DB_TAB *cell, /* device being edited */
NUM x1, NUM y1, /* pick point */
NUM x2, NUM y2, /* pick point */
int mode, /* 0 = ident (any visible) */
/* 1 = enclose pick (pick restricted to modifiable objects) */
/* 2 = boundary overlap (restricted to modifiable objects) */
int pick_layer, /* layer restriction, or 0=all */
int comp, /* comp restriction */
char *name /* instance name restrict or NULL */
) {
DB_DEFLIST *p;
SELPNT *selpnt=NULL; /* gets returned */
/* int debug=0; */
// BOUNDS childbb;
double tmp;
int layer;
int bad_comp;
int gotpnts;
double *xsel;
double *ysel;
COORDS *coords;
double *xmin, *ymin, *xmax, *ymax;
int sel;
if (cell == NULL) {
printf("no cell currently being edited!\n");
return(0);
}
selpnt=NULL;
for (p=cell->dbhead; p!=(DB_DEFLIST *)0; p=p->next) {
// childbb.init=0;
/* screen components by layers and bounding boxes */
switch (p->type) {
case ARC: /* arc definition */
layer = p->u.a->layer;
break;
case CIRC: /* arc definition */
layer = p->u.c->layer;
break;
case LINE: /* arc definition */
layer = p->u.l->layer;
break;
case NOTE: /* note definition */
layer = p->u.n->layer;
break;
case OVAL: /* oval definition */
layer = p->u.o->layer;
break;
case POLY: /* polygon definition */
layer = p->u.p->layer;
break;
case RECT: /* rectangle definition */
layer = p->u.r->layer;
break;
case TEXT: /* text definition */
layer = p->u.t->layer;
break;
case INST: /* instance definition */
layer = 0;
break;
default:
layer = 0;
printf("error in db_ident switch\n");
break;
}
/* check all the restrictions on picking something */
if (name != NULL) { comp = INST; }
bad_comp=0;
if ((pick_layer != 0 && layer != pick_layer) ||
(comp != 0 && comp != ALL && p->type != comp) ||
(!mode && !show_check_visible(currep, p->type, layer)) ||
(mode && !show_check_modifiable(currep, p->type, layer)) ||
(p->type==INST && name!=NULL && strncmp(name, p->u.i->name, MAXFILENAME))!=0) {
bad_comp++;
}
if (!bad_comp) {
if (x1 > x2) { /* canonicalize coords */
tmp = x2; x2 = x1; x1 = tmp;
}
if (y1 > y2) {
tmp = y2; y2 = y1; y1 = tmp;
}
if ( ( (mode==0 || mode==1) && /* check for enclosure */
(x1<=p->xmin && x2>=p->xmax && y1<=p->ymin && y2>=p->ymax) ) ||
( (mode==2) && /* check for mutual overlap */
(bb_overlap(x1, y1, x2, y2, p->xmin, p->ymin, p->xmax, p->ymax)) ) ) {
gotpnts = 0;
switch (p->type) {
case ARC:
xsel = &(p->u.a->x3);
ysel = &(p->u.a->y3);
if (bounded (xsel, ysel, x1, y1, x2, y2)) {
selpnt_save(&selpnt, xsel, ysel, NULL);
gotpnts++;
}
xsel = &(p->u.a->x2);
ysel = &(p->u.a->y2);
if (bounded (xsel, ysel, x1, y1, x2, y2)) {
selpnt_save(&selpnt, xsel, ysel, NULL);
gotpnts++;
}
xsel = &(p->u.a->x1);
ysel = &(p->u.a->y1);
if (bounded (xsel, ysel, x1, y1, x2, y2)) {
selpnt_save(&selpnt, xsel, ysel, NULL);
gotpnts++;
}
break;
case CIRC:
xsel = &(p->u.c->x2);
ysel = &(p->u.c->y2);
if (bounded (xsel, ysel, x1, y1, x2, y2)) {
selpnt_save(&selpnt, xsel, ysel, NULL);
gotpnts++;
}
xsel = &(p->u.c->x1);
ysel = &(p->u.c->y1);
if (bounded (xsel, ysel, x1, y1, x2, y2)) {
selpnt_save(&selpnt, xsel, ysel, NULL);
gotpnts++;
}
break;
case INST:
xsel = &(p->u.i->x);
ysel = &(p->u.i->y);
if (bounded (xsel, ysel, x1, y1, x2, y2)) {
selpnt_save(&selpnt, xsel, ysel, NULL);
gotpnts++;
}
break;
case LINE:
for (coords=p->u.l->coords;coords!=NULL;coords=coords->next) {
xsel = &(coords->coord.x);
ysel = &(coords->coord.y);
if (bounded (xsel, ysel, x1, y1, x2, y2)) {
selpnt_save(&selpnt, xsel, ysel, NULL);
gotpnts++;
}
}
break;
case NOTE:
xsel = &(p->u.n->x);
ysel = &(p->u.n->y);
if (bounded (xsel, ysel, x1, y1, x2, y2)) {
selpnt_save(&selpnt, xsel, ysel, NULL);
gotpnts++;
}
break;
case POLY:
for (coords=p->u.p->coords;coords!=NULL;coords=coords->next) {
xsel = &(coords->coord.x);
ysel = &(coords->coord.y);
if (bounded (xsel, ysel, x1, y1, x2, y2)) {
selpnt_save(&selpnt, xsel, ysel, NULL);
gotpnts++;
}
}
break;
case RECT:
xmin = &(p->u.r->x1);
xmax = &(p->u.r->x2);
ymin = &(p->u.r->y1);
ymax = &(p->u.r->y2);
sel=0;
if (bounded (xmin, ymin, x1, y1, x2, y2)) sel += 1;
if (bounded (xmin, ymax, x1, y1, x2, y2)) sel += 2;
if (bounded (xmax, ymax, x1, y1, x2, y2)) sel += 4;
if (bounded (xmax, ymin, x1, y1, x2, y2)) sel += 8;
switch (sel) {
case 0:
break;
case 1:
selpnt_save(&selpnt, xmin, ymin, NULL);
gotpnts++;
break;
case 2:
selpnt_save(&selpnt, xmin, ymax, NULL);
gotpnts++;
break;
case 3: /* left side */
selpnt_save(&selpnt, xmin, NULL, NULL);
gotpnts++;
break;
case 4:
selpnt_save(&selpnt, xmax, ymax, NULL);
gotpnts++;
break;
case 6: /* top side */
selpnt_save(&selpnt, NULL, ymax, NULL);
gotpnts++;
break;
case 8:
selpnt_save(&selpnt, xmax, ymin, NULL);
gotpnts++;
break;
case 9: /* bottom side */
selpnt_save(&selpnt,NULL, ymin, NULL);
gotpnts++;
break;
case 12: /* right side */
selpnt_save(&selpnt,xmax, NULL, NULL);
gotpnts++;
break;
case 15: /* entire rectangle */
selpnt_save(&selpnt,xmin, ymin, NULL);
selpnt_save(&selpnt,xmax, ymax, NULL);
gotpnts+=2;
break;
default:
printf(" COM_STRETCH: case %d should never occur!\n",sel);
break;
}
break;
case TEXT:
xsel = &(p->u.t->x);
ysel = &(p->u.t->y);
if (bounded (xsel, ysel, x1, y1, x2, y2)) {
selpnt_save(&selpnt,xsel, ysel, NULL);
gotpnts+=2;
}
break;
default:
printf(" not a stretchable object\n");
db_notate(p); /* print information */
break;
}
if (gotpnts) {
selpnt_save(&selpnt, NULL, NULL, p); /* save comp */
}
}
}
}
return(selpnt);
}
STACK *db_ident_region(
DB_TAB *cell, /* device being edited */
NUM x1, NUM y1, /* pick point */
NUM x2, NUM y2, /* pick point */
int mode, /* 0 = ident (any visible) */
/* 1 = enclose pick (pick restricted to modifiable objects) */
/* 2 = boundary overlap (restricted to modifiable objects) */
int pick_layer, /* layer restriction, or 0=all */
int comp, /* comp restriction */
char *name /* instance name restrict or NULL */