File: o_box_basic.nw

package info (click to toggle)
libgeda 20010722-4
  • links: PTS
  • area: main
  • in suites: woody
  • size: 2,208 kB
  • ctags: 1,564
  • sloc: ansic: 15,815; sh: 7,883; makefile: 135; awk: 131; perl: 59
file content (1559 lines) | stat: -rw-r--r-- 47,014 bytes parent folder | download
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
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
@c -*- mode: Noweb; noweb-doc-mode: texinfo-mode; noweb-code-mode: c-mode -*-

@node File o_box_basic.c,,,Top
@chapter File @file{o_box_basic.c}

@section File header

<<o_box_basic.c : *>>=
<<o_box_basic.c : copyright and license>>

/* DO NOT read or edit this file ! Use ../noweb/o_box_basic.nw instead */

<<o_box_basic.c : include directives>>
<<o_box_basic.c : macros>>
<<o_box_basic.c : get_box_bounds()>>
<<o_box_basic.c : world_get_box_bounds()>>
<<o_box_basic.c : o_box_add()>>
<<o_box_basic.c : o_box_recalc()>>
<<o_box_basic.c : o_box_read()>>
<<o_box_basic.c : o_box_save()>>
<<o_box_basic.c : o_box_translate()>>
<<o_box_basic.c : o_box_translate_world()>>
<<o_box_basic.c : o_box_copy()>>
<<o_box_basic.c : o_box_print()>>         /* done */
<<o_box_basic.c : o_box_print_solid()>>   /* done */
<<o_box_basic.c : o_box_print_dotted()>>  /* done */
<<o_box_basic.c : o_box_print_dashed()>>  /* done */
<<o_box_basic.c : o_box_print_center()>>  /* done */
<<o_box_basic.c : o_box_print_phantom()>> /* done */
<<o_box_basic.c : o_box_print_filled()>>  /* done */
<<o_box_basic.c : o_box_print_mesh()>>    /* done */
<<o_box_basic.c : o_box_print_hatch()>>   /* done */

#if 0 /* original way of printing box, no longer used */
<<o_box_basic.c : o_box_print_old()>>
#endif

<<o_box_basic.c : o_box_image_write()>>
<<o_box_basic.c : o_box_rotate()>>
<<o_box_basic.c : o_box_rotate_world()>>
<<o_box_basic.c : o_box_mirror()>>
<<o_box_basic.c : o_box_mirror_world()>>
<<o_box_basic.c : o_box_modify()>>

@

<<o_box_basic.c : copyright and license>>=
/* gEDA - GPL Electronic Design Automation
 * libgeda - gEDA's library
 * Copyright (C) 1998-2000 Ales V. Hvezda
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111 USA
 */

@ 

<<o_box_basic.c : include directives>>=
#include <config.h>
#include <math.h>
#include <stdio.h>

#include <gtk/gtk.h>
#include <gdk/gdk.h>
#include <gdk/gdkx.h>

#include <guile/gh.h>

#ifdef HAS_LIBGDGEDA
#include <gdgeda/gd.h>
#endif

#include "defines.h"
#include "struct.h"
#include "globals.h"
#include "o_types.h"

#include "colors.h"
#include "funcs.h"

#include "../include/prototype.h"

@ 

<<o_box_basic.c : macros>>=
/* Kazu on July 16, 1999 - Added these macros to simplify the code */
#define GET_BOX_WIDTH(w)                        \
        abs((w)->last_x - (w)->start_x)
#define GET_BOX_HEIGHT(w)                       \
	        abs((w)->last_y - (w)->start_y)
#define GET_BOX_LEFT(w)                         \
	        min((w)->start_x, (w)->last_x);
#define GET_BOX_TOP(w)                          \
		min((w)->start_y, (w)->last_y);

#define VERSION_20000704 20000704

@ %def GET_BOX_WIDTH GET_BOX_HEIGHT GET_BOX_LEFT GET_BOX_TOP VERSION_20000704


@section Function @code{get_box_bounds()}

@defun get_box_bounds w_current object left top right bottom
@end defun

<<o_box_basic.c : get_box_bounds()>>=
void
get_box_bounds(TOPLEVEL *w_current, BOX *box, int *left, int *top,
               int *right, int *bottom)
{
  *left = box->screen_upper_x;
  *top = box->screen_upper_y;
  *right = box->screen_lower_x;
  *bottom = box->screen_lower_y;

  /* PB : bounding box has to take into account the width of the line it is
     composed with, ie adding/substracting half the width to this box */
  /* PB : but width is unknown here */	
	
  *left = *left - 4;
  *top = *top - 4;
	
  *right = *right + 4;
  *bottom = *bottom + 4;
}

@ %def get_box_bounds


@section Function @code{world_get_box_bounds()}

@defun world_get_box_bounds w_current box left top right bottom
@end defun

<<o_box_basic.c : world_get_box_bounds()>>=
void
world_get_box_bounds(TOPLEVEL *w_current, BOX *box, int *left, int *top, int *right, int *bottom)
{
  *left = min(box->upper_x, box->lower_x);
  *top = min(box->upper_y, box->lower_y);
  *right = max(box->upper_x, box->lower_x);
  *bottom = max(box->upper_y, box->lower_y);

  /* PB : same as above here */	


#if DEBUG 
  printf("box: %d %d %d %d\n", *left, *top, *right, *bottom);
#endif

	
}
                 
@ %def world_get_box_bounds


@section Function @code{o_box_add()}

@defun o_box_add w_current object_list type color x1 y1 x2 y2
@end defun

<<o_box_basic.c : o_box_add()>>=
OBJECT *
o_box_add(TOPLEVEL *w_current, OBJECT *object_list,
		  char type, int color,
		  int x1, int y1, int x2, int y2)
{
  OBJECT *new_node;
  BOX *box;

  new_node = s_basic_init_object("box");
  new_node->type = type;
  new_node->color = color;

  box = (BOX *) malloc(sizeof(BOX));

  box->upper_x = x1;
  box->upper_y = y1;
  box->lower_x = x2;
  box->lower_y = y2;

  new_node->box = box;

  /* Init */
  o_set_line_options(w_current, new_node,
                     END_NONE, TYPE_SOLID, 0, -1, -1);
  o_set_fill_options(w_current, new_node,
                     FILLING_HOLLOW, -1, -1, -1, -1, -1);
	
  o_box_recalc(w_current, new_node);

  /* TODO: questionable cast */     
  new_node->draw_func = (void *) box_draw_func; 
  /* TODO: questionable cast */     
  new_node->sel_func = (void *) select_func;  

  object_list = (OBJECT *) s_basic_link_object(new_node, object_list);
  return(object_list);
}

@ %def o_box_add


@section Function @code{o_box_recalc()}

@defun o_box_recalc w_current o_current
@end defun

<<o_box_basic.c : o_box_recalc()>>=
void
o_box_recalc(TOPLEVEL *w_current, OBJECT *o_current)
{
  int left, top, right, bottom;
  int screen_x1, screen_y1;
  int screen_x2, screen_y2;

  if (o_current->box == NULL) {
    return;
  }

  WORLDtoSCREEN(w_current, o_current->box->upper_x, 
                o_current->box->upper_y, 
                &screen_x1,
                &screen_y1);  

  o_current->box->screen_upper_x = screen_x1;
  o_current->box->screen_upper_y = screen_y1;

  WORLDtoSCREEN(w_current, o_current->box->lower_x, 
                o_current->box->lower_y, 
                &screen_x2,
                &screen_y2);  

  o_current->box->screen_lower_x = screen_x2;
  o_current->box->screen_lower_y = screen_y2;
	
  get_box_bounds(w_current, o_current->box, &left, &top, &right, &bottom);

  o_current->left = left;
  o_current->top = top;
  o_current->right = right;
  o_current->bottom = bottom;

  o_object_recalc(w_current, o_current);
	
}

@ %def o_box_recalc


@section Function @code{o_box_read()}

@defun o_box_read w_current object_list buf version
@end defun

<<o_box_basic.c : o_box_read()>>=
OBJECT *
o_box_read(TOPLEVEL *w_current, OBJECT *object_list, char buf[], char *version)
{
  char type; 
  int x1, y1;
  int width, height; 
  int d_x1, d_y1;
  int d_x2, d_y2;
  int color;
  int box_width, box_space, box_length;
  int fill_width, angle1, pitch1, angle2, pitch2;
  OBJECT_END box_end;
  OBJECT_TYPE box_type;
  OBJECT_FILLING box_filling;
  long int ver;

  ver = strtol(version, NULL, 10);
  if(ver <= VERSION_20000704) {
    sscanf(buf, "%c %d %d %d %d %d\n",
           &type, &x1, &y1, &width, &height, &color);

    box_width   = 0;
    box_end     = END_NONE;
    box_type    = TYPE_SOLID;
    box_length  = -1;
    box_space   = -1;

    box_filling = FILLING_HOLLOW;		
    fill_width  = 0;
    angle1      = -1;
    pitch1      = -1;
    angle2      = -1;
    pitch2      = -1;
  } else {
    sscanf(buf, "%c %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d\n",
           &type, &x1, &y1, &width, &height, &color,
           &box_width, &box_end, &box_type, &box_length, 
           &box_space, &box_filling,
           &fill_width, &angle1, &pitch1, &angle2, &pitch2);			   
  }

  d_x1 = x1;
  d_y1 = y1+height; /* move box origin to top left */

  d_x2 = x1+width; /* end points of the box */
  d_y2 = y1;

  if (width == 0 || height == 0) {
    fprintf(stderr, "Found a zero width/height box [ %c %d %d %d %d %d ]\n",
            type, x1, y1, width, height, color);
    s_log_message("Found a zero width/height box [ %c %d %d %d %d %d ]\n",
                  type, x1, y1, width, height, color);
  }

  if (color < 0 || color > MAX_COLORS) {
    fprintf(stderr, "Found an invalid color [ %s ]\n", buf);
    s_log_message("Found an invalid color [ %s ]\n", buf);
    s_log_message("Setting color to WHITE\n");
    color = WHITE;
  }
	
  object_list = (OBJECT *) o_box_add(w_current, object_list,
                                     type, color,
                                     d_x1, d_y1, d_x2, d_y2);
  o_set_line_options(w_current, object_list,
                     box_end, box_type, box_width, 
                     box_length, box_space);
  o_set_fill_options(w_current, object_list,
                     box_filling, fill_width,
                     pitch1, angle1, pitch2, angle2);

  return(object_list);
}

@ %def o_box_read


@section Function @code{o_box_save()}

@defun o_box_save buf object
@end defun

<<o_box_basic.c : o_box_save()>>=
char *
o_box_save(char *buf, OBJECT *object)
{
  int x1, y1; 
  int width, height;
  int color;
  int box_width, box_space, box_length;
  int fill_width, angle1, pitch1, angle2, pitch2;
  OBJECT_END box_end;
  OBJECT_TYPE box_type;
  OBJECT_FILLING box_fill;
		
  width  = abs(object->box->lower_x - object->box->upper_x); 
  height = abs(object->box->upper_y - object->box->lower_y);

  x1 = object->box->upper_x;
  y1 = object->box->upper_y - height; /* move the origin to 0, 0*/

#if DEBUG
  printf("box: %d %d %d %d\n", x1, y1, d_x, d_y);
#endif

  /* Use the right color */
  if (object->saved_color == -1) {
    color = object->color;
  } else {
    color = object->saved_color;
  }

  box_end    = object->line_end;
  box_width  = object->line_width;
  box_type   = object->line_type;
  box_length = object->line_length;
  box_space  = object->line_space;
	
  box_fill   = object->fill_type;
  fill_width = object->fill_width;
  angle1     = object->fill_angle1;
  pitch1     = object->fill_pitch1;
  angle2     = object->fill_angle2;
  pitch2     = object->fill_pitch2;

  sprintf(buf, "%c %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d", 
          object->type,
          x1, y1, width, height, color,
          box_width, box_end, box_type, box_length, box_space, 
          box_fill,
          fill_width, angle1, pitch1, angle2, pitch2);
			
  return(buf);
}

@ %def o_box_save


@section Function @code{o_box_translate()}

@defun o_box_translate w_current dx dy object
@end defun

<<o_box_basic.c : o_box_translate()>>=
void
o_box_translate(TOPLEVEL *w_current, int dx, int dy, OBJECT *object)
{
  int x, y;

  if (object == NULL) printf("bt NO!\n");
	

  /* Do screen coords */
  object->box->screen_upper_x = object->box->screen_upper_x + dx;
  object->box->screen_upper_y = object->box->screen_upper_y + dy;
  object->box->screen_lower_x = object->box->screen_lower_x + dx;
  object->box->screen_lower_y = object->box->screen_lower_y + dy;

  /* printf("box: trans: %d %d\n", dx, dy);*/

  SCREENtoWORLD(w_current, object->box->screen_upper_x,
                object->box->screen_upper_y,
                &x,
                &y);
	
  object->box->upper_x = snap_grid(w_current, x);
  object->box->upper_y = snap_grid(w_current, y);
	
  SCREENtoWORLD(w_current, object->box->screen_lower_x,
                object->box->screen_lower_y,
                &x,
                &y);
	
  object->box->lower_x = snap_grid(w_current, x);
  object->box->lower_y = snap_grid(w_current, y);
}

@ %def o_box_translate


@section Function @code{o_box_translate_world()}

@defun o_box_translate_world w_current x1 y1 object
@end defun

<<o_box_basic.c : o_box_translate_world()>>=
void
o_box_translate_world(TOPLEVEL *w_current, int x1, int y1, OBJECT *object)
{
  int screen_x1, screen_y1;
  int screen_x2, screen_y2;
  int left, right, top, bottom;

  if (object == NULL) printf("btw NO!\n");
	
	
  /* Do world coords */
  object->box->upper_x = object->box->upper_x + x1;
  object->box->upper_y = object->box->upper_y + y1;
  object->box->lower_x = object->box->lower_x + x1;
  object->box->lower_y = object->box->lower_y + y1;     
	
  WORLDtoSCREEN(w_current, object->box->upper_x, 
                object->box->upper_y, 
                &screen_x1,
                &screen_y1);  
	
  object->box->screen_upper_x = screen_x1;
  object->box->screen_upper_y = screen_y1;
	
  WORLDtoSCREEN(w_current, object->box->lower_x, 
                object->box->lower_y, 
                &screen_x2,
                &screen_y2);  
	
  object->box->screen_lower_x = screen_x2;
  object->box->screen_lower_y = screen_y2;
	
  get_box_bounds(w_current, object->box, &left, &top, &right, &bottom);
	
  object->left = left;
  object->top = top;
  object->right = right;
  object->bottom = bottom;
}

@ %def o_box_translate_world


@section Function @code{o_box_copy()}

@defun o_box_copy w_current list_tail o_current
@end defun

<<o_box_basic.c : o_box_copy()>>=
OBJECT *
o_box_copy(TOPLEVEL *w_current, OBJECT *list_tail, OBJECT *o_current)
{
  OBJECT *new_obj;
  ATTRIB *a_current;
  int color;
	
  if (o_current->saved_color == -1) {
    color = o_current->color;
  } else {
    color = o_current->saved_color;
  }
	
  new_obj = o_box_add(w_current, list_tail,
                      OBJ_BOX, color,
                      0, 0, 0, 0);
	
  new_obj->box->screen_upper_x = o_current->box->screen_upper_x;
  new_obj->box->screen_upper_y = o_current->box->screen_upper_y;
  new_obj->box->screen_lower_x = o_current->box->screen_lower_x;
  new_obj->box->screen_lower_y = o_current->box->screen_lower_y;  
	
  new_obj->box->upper_x = o_current->box->upper_x;
  new_obj->box->upper_y = o_current->box->upper_y;
  new_obj->box->lower_x = o_current->box->lower_x;
  new_obj->box->lower_y = o_current->box->lower_y;

	
  o_set_line_options(w_current, new_obj, o_current->line_end,
                     o_current->line_type, o_current->line_width,
                     o_current->line_length, o_current->line_space);
  o_set_fill_options(w_current, new_obj,
                     o_current->fill_type, o_current->fill_width,
                     o_current->fill_pitch1, o_current->fill_angle1,
                     o_current->fill_pitch2, o_current->fill_angle2);
	
  /*	new_obj->attribute = 0;*/
  a_current = o_current->attribs;
  if (a_current) {
    while ( a_current ) {
			
      /* head attrib node has prev = NULL */
      if (a_current->prev != NULL) {
        a_current->copied_to = new_obj;
      }
      a_current = a_current->next;
    }
  }

  return(new_obj);
} 

@ %def o_box_copy


@section Function @code{o_box_print()}

@defun o_box_print w_current fp o_current origin_x origin_y
This function write in a postscript file the box described by the [[o_current]] pointed object. It takes into account its line type and fill type.
The postscript resulting file is descibed by the file pointer [[fp]].
@end defun

The validity of the [[o_current]] pointer is verified : a null pointer causes an error message and a return.

The description of the box is extracted from the [[o_current]] pointed object : the coordinates of the box - upper left corner and width and height of the box -, its line type, its fill type.

The outline and the inside of the box are successively handled by two differend sets of functions.

<<o_box_basic.c : o_box_print()>>=
void
o_box_print(TOPLEVEL *w_current, FILE *fp, OBJECT *o_current, 
			 int origin_x, int origin_y)
{
  int x, y, width, height;
  int color;
  int line_width, length, space;
  int fill_width, angle1, pitch1, angle2, pitch2;
  void (*outl_func)() = NULL;
  void (*fill_func)() = NULL;

  if (o_current == NULL) {
    printf("got null in o_box_print\n");
    return;
  }

  x = o_current->box->upper_x;
  y = o_current->box->upper_y;
  width  = abs(o_current->box->lower_x - o_current->box->upper_x);
  height = abs(o_current->box->lower_y - o_current->box->upper_y);
  color  = o_current->color;

  <<o_box_print() : printing outline>>
  <<o_box_print() : printing the filling>>

}
@ %def o_box_print


Depending on the type of the line for this particular box, the appropriate function is chosen among [[o_box_print_solid()]], [[o_box_print_dotted()]], [[o_box_print_dashed()]], [[o_box_print_center]] and [[o_box_print_phantom()]].

The needed parameters for each of these type is extracted from the [[o_current]] object. Depending on the type, unused parameters are set to -1.

In the eventuality of a length and/or space null, the line is printed solid to avoid and endless loop produced by other functions in such a case.

<<o_box_print() : printing outline>>=
  line_width = o_current->line_width;
  length = o_current->line_length;
  space  = o_current->line_space;
	
  switch(o_current->line_type) {
    case(TYPE_SOLID):
      length = -1; space  = -1;
      outl_func = (void *) o_box_print_solid;
      break;

    case(TYPE_DOTTED):
      length = -1;
      outl_func = (void *) o_box_print_dotted;
      break;

    case(TYPE_DASHED):
      outl_func = (void *) o_box_print_dashed;
      break;

    case(TYPE_CENTER):
      outl_func = (void *) o_box_print_center;
      break;

    case(TYPE_PHANTOM):
      outl_func = (void *) o_box_print_phantom;
      break;

    case(TYPE_ERASE):
      /* Unused for now, print it solid */
      length = -1; space  = -1;
      outl_func = (void *) o_box_print_solid;
      break;
  }

  if((length == 0) || (space == 0)) {
    length = -1; space  = -1;
    outl_func = (void *) o_box_print_solid;
  }

  (*outl_func)(w_current, fp,
               x, y, width, height,
               color,
               line_width,
               length, space,
               origin_x, origin_y);

@ 


If the filling type of the box is not [[HOLLOW]], the appropriate function is chosen among [[o_box_print_filled()]], [[o_box_print_mesh()]] and [[o_box_print_hatch()]]. The corresponding parameters are extracted from the [[o_current]] object and corrected afterward.

The case where [[pitch1]] and [[pitch2]] are null or negative is avoided as it leads to an endless loop in most of the called functions. In such a case, the box is printed filled. Unused parameters for each of these functions are set to -1 or any passive value.

<<o_box_print() : printing the filling>>=
  if(o_current->fill_type != FILLING_HOLLOW) {
    fill_width = o_current->fill_width;
    angle1     = o_current->fill_angle1;
    pitch1     = o_current->fill_pitch1;
    angle2     = o_current->fill_angle2;
    pitch2     = o_current->fill_pitch2;
		
    switch(o_current->fill_type) {
      case(FILLING_FILL):
        angle1 = -1; pitch1 = 1;
        angle2 = -1; pitch2 = 1;
        fill_width = -1;
        fill_func = (void *) o_box_print_filled;
        break;
			
      case(FILLING_MESH):
        fill_func = (void *) o_box_print_mesh;
        break;
				
      case(FILLING_HATCH):
        angle2 = -1; pitch2 = 1;
        fill_func = (void *) o_box_print_hatch;
        break;
				
      case(FILLING_VOID):
        /* Unused for now, print it filled */
        angle1 = -1; pitch1 = 1;
        angle2 = -1; pitch2 = 1;
        fill_width = -1;
        fill_func = (void *) o_box_print_filled;
        break;
    }

    if((pitch1 <= 0) || (pitch2 <= 0)) {
      angle1 = -1; pitch1 = 1;
      angle2 = -1; pitch2 = 1;
      fill_func = (void *) o_box_print_filled;
    }
		
    (*fill_func)(w_current, fp,
                 x, y, width, height,
                 color,
                 fill_width,
                 angle1, pitch1, angle2, pitch2,
                 origin_x, origin_y);
  }

@


@section Function @code{o_box_print_solid()}

@defun o_box_print_solid w_current fp x y width height color line_width length space orign_x origin_y
This function prints the outline of a box when a solid line type is required. The box is defined by the coordinates of its upper left corner in ([[x]],[[y]]) and its width and height given by the [[width]] and [[height]] parameters. 
The postscript file is defined by the file pointer [[fp]].
The parameters [[length]] and [[space]] are ignored.
@end defun

It uses the function [[o_line_print_solid()]] to print the outline. It performs four calls to this function, one for each of its side.

All dimensions are in mils.

<<o_box_basic.c : o_box_print_solid()>>=
/* PB : parameter filled removed */
void
o_box_print_solid(TOPLEVEL *w_current, FILE *fp,
                  int x, int y,
                  int width, int height,
                  int color,
                  int line_width, int length, int space, 
                  int origin_x, int origin_y)
{
  int x1, y1;

  fprintf(fp, "gsave\n");
  if (w_current->print_color) {
    f_print_set_color(fp, color);
  }

  f_print_set_line_width(fp, line_width);

  x1 = x;
  y1 = y - height; /* move the origin to 0, 0*/

  o_line_print_solid(w_current, fp,
                     x1, y1, x1 + width, y1,
                     color,
                     line_width, length, space,
                     origin_x, origin_y);
  o_line_print_solid(w_current, fp,
                     x1 + width, y1, x1 + width, y1 + height,
                     color,
                     line_width, length, space,
                     origin_x, origin_y);
  o_line_print_solid(w_current, fp,
                     x1 + width, y1 + height, x1, y1 + height,
                     color,
                     line_width, length, space,
                     origin_x, origin_y);
  o_line_print_solid(w_current, fp,
                     x1, y1 + height, x1, y1,
                     color,
                     line_width, length, space,
                     origin_x, origin_y);
  fprintf(fp, "grestore\n");
	
}

@ %def o_box_print_solid


@section Function @code{o_box_print_dotted()}

@defun o_box_print_dotted w_current fp x y width height color line_width length space origin_x origin_y
This function prints the outline of a box when a dotted line type is required. The box is defined by the coordinates of its upper left corner in ([[x]],[[y]]) and its width and height given by the [[width]] and [[height]] parameters. 
The postscript file is defined by the file pointer [[fp]].
The parameters [[length]] is ignored.
@end defun

It uses the function [[o_line_print_dotted()]] to print the outline. It performs four calls to this function, one for each of its side.

All dimensions are in mils.

<<o_box_basic.c : o_box_print_dotted()>>=
/* PB : parameter filled removed */
/* PB : parameter o_current removed */
void
o_box_print_dotted(TOPLEVEL *w_current, FILE *fp,
                   int x, int y,
                   int width, int height,
                   int color,
                   int line_width, int length, int space, 
                   int origin_x, int origin_y)
{
  int x1, y1;

  fprintf(fp, "gsave\n");
  if (w_current->print_color) {
    f_print_set_color(fp, color);
  }

  f_print_set_line_width(fp, line_width);

  x1 = x;
  y1 = y - height; /* move the origin to 0, 0*/

  o_line_print_dotted(w_current, fp,
                      x1, y1, x1 + width, y1,
                      color,
                      line_width, length, space,
                      origin_x, origin_y);
  o_line_print_dotted(w_current, fp,
                      x1 + width, y1, x1 + width, y1 + height,
                      color,
                      line_width, length, space,
                      origin_x, origin_y);
  o_line_print_dotted(w_current, fp,
                      x1 + width, y1 + height, x1, y1 + height,
                      color,
                      line_width, length, space,
                      origin_x, origin_y);
  o_line_print_dotted(w_current, fp,
                      x1, y1 + height, x1, y1,
                      color,
                      line_width, length, space,
                      origin_x, origin_y);
  fprintf(fp, "grestore\n");
	
}

@ %def o_box_print_dotted


@section Function @code{o_box_print_dashed()}

@defun o_box_print_dashed w_current fp x y width height color line_width length space origin_x origin_y
This function prints the outline of a box when a dashed line type is required. The box is defined by the coordinates of its upper left corner in ([[x]],[[y]]) and its width and height given by the [[width]] and [[height]] parameters. 
The postscript file is defined by the file pointer [[fp]].
@end defun

It uses the function [[o_line_print_dashed()]] to print the outline. It performs four calls to this function, one for each of its side.

All dimensions are in mils.

<<o_box_basic.c : o_box_print_dashed()>>=
/* PB : parameter filled removed */
/* PB : parameter o_current removed */
void
o_box_print_dashed(TOPLEVEL *w_current, FILE *fp,
				   int x, int y,
				   int width, int height,
				   int color,
				   int line_width, int length, int space, 
				   int origin_x, int origin_y)
{
  int x1, y1;

  fprintf(fp, "gsave\n");
  if (w_current->print_color) {
    f_print_set_color(fp, color);
  }

  f_print_set_line_width(fp, line_width);

  x1 = x;
  y1 = y - height; /* move the origin to 0, 0*/

  o_line_print_dashed(w_current, fp,
                      x1, y1, x1 + width, y1,
                      color,
                      line_width, length, space,
                      origin_x, origin_y);
  o_line_print_dashed(w_current, fp,
                      x1 + width, y1, x1 + width, y1 + height,
                      color,
                      line_width, length, space,
                      origin_x, origin_y);
  o_line_print_dashed(w_current, fp,
                      x1 + width, y1 + height, x1, y1 + height,
                      color,
                      line_width, length, space,
                      origin_x, origin_y);
  o_line_print_dashed(w_current, fp,
                      x1, y1 + height, x1, y1,
                      color,
                      line_width, length, space,
                      origin_x, origin_y);
  fprintf(fp, "grestore\n");
	
}

@ %def o_box_print_dashed


@section Function @code{o_box_print_center()}

@defun o_box_print_center w_current fp x y width height color line_width length space origin_x origin_y
This function prints the outline of a box when a centered line type is required. The box is defined by the coordinates of its upper left corner in ([[x]],[[y]]) and its width and height given by the [[width]] and [[height]] parameters. 
The postscript file is defined by the file pointer [[fp]].
@end defun

It uses the function [[o_line_print_center()]] to print the outline. It performs four calls to this function, one for each of its side.

All dimensions are in mils.

<<o_box_basic.c : o_box_print_center()>>=
/* PB : parameter filled removed */
/* PB : parameter o_current removed */
void
o_box_print_center(TOPLEVEL *w_current, FILE *fp,
                   int x, int y,
                   int width, int height,
                   int color,
                   int line_width, int length, int space, 
                   int origin_x, int origin_y)
{
  int x1, y1;

  fprintf(fp, "gsave\n");
  if (w_current->print_color) {
    f_print_set_color(fp, color);
  }

  f_print_set_line_width(fp, line_width);

  x1 = x;
  y1 = y - height; /* move the origin to 0, 0*/

  o_line_print_center(w_current, fp,
                      x1, y1, x1 + width, y1,
                      color,
                      line_width, length, space,
                      origin_x, origin_y);
  o_line_print_center(w_current, fp,
                      x1 + width, y1, x1 + width, y1 + height,
                      color,
                      line_width, length, space,
                      origin_x, origin_y);
  o_line_print_center(w_current, fp,
                      x1 + width, y1 + height, x1, y1 + height,
                      color,
                      line_width, length, space,
                      origin_x, origin_y);
  o_line_print_center(w_current, fp,
                      x1, y1 + height, x1, y1,
                      color,
                      line_width, length, space,
                      origin_x, origin_y);
  fprintf(fp, "grestore\n");

}

@ %def o_box_print_center


@section Function @code{o_box_print_phantom()}

@defun o_box_print_phantom w_current fp x y width height color line_width length space origin_x origin_y
This function prints the outline of a box when a phantom line type is required. The box is defined by the coordinates of its upper left corner in ([[x]],[[y]]) and its width and height given by the [[width]] and [[height]] parameters. 
The postscript file is defined by the file pointer [[fp]].
@end defun

It uses the function [[o_line_print_phantom()]] to print the outline. It performs four calls to this function, one for each of its side.

All dimensions are in mils.

<<o_box_basic.c : o_box_print_phantom()>>=
/* PB : parameter filled removed */
/* PB : parameter o_current removed */
void
o_box_print_phantom(TOPLEVEL *w_current, FILE *fp,
                    int x, int y,
                    int width, int height,
                    int color,
                    int line_width, int length, int space, 
                    int origin_x, int origin_y)
{
  int x1, y1;

  fprintf(fp, "gsave\n");
  if (w_current->print_color) {
    f_print_set_color(fp, color);
  }

  f_print_set_line_width(fp, line_width);

  x1 = x;
  y1 = y - height; /* move the origin to 0, 0*/

  o_line_print_phantom(w_current, fp,
                       x1, y1, x1 + width, y1,
                       color,
                       line_width, length, space,
                       origin_x, origin_y);
  o_line_print_phantom(w_current, fp,
                       x1 + width, y1, x1 + width, y1 + height,
                       color,
                       line_width, length, space,
                       origin_x, origin_y);
  o_line_print_phantom(w_current, fp,
                       x1 + width, y1 + height, x1, y1 + height,
                       color,
                       line_width, length, space,
                       origin_x, origin_y);
  o_line_print_phantom(w_current, fp,
                       x1, y1 + height, x1, y1,
                       color,
                       line_width, length, space,
                       origin_x, origin_y);
  fprintf(fp, "grestore\n");
}

@ %def o_box_print_phantom


@section Function @code{o_box_print_filled()}

@defun o_box_print_filled w_current fp x y width height color fill_width angle1 pitch1 angle2 pitch2 origin_x origin_y
The function prints a filled box with a solid pattern. No outline is printed. 
The box is defined by the coordinates of its upper left corner in ([[x]],[[y]])
and its width and height given by the [[width]] and [[height]] parameters. The 
postscript file is defined by the file pointer [[fp]].
[[fill_width]], [[angle1]] and [[pitch1]], [[angle2]] and [[pitch2]] parameters
are ignored in this functions but kept for compatibility with other fill 
functions.
@end defun

It uses the fbox postscript function defined in the file @file{f_print.c} to 
specify a filled box.

All dimensions are in mils.

<<o_box_basic.c : o_box_print_filled()>>=
void
o_box_print_filled(TOPLEVEL *w_current, FILE *fp,
                   int x, int y,
                   int width, int height,
                   int color,
                   int fill_width,
                   int angle1, int pitch1,
                   int angle2, int pitch2,
                   int origin_x, int origin_y)
{
  int x1, y1;

  fprintf(fp, "gsave\n");
  if (w_current->print_color) {
    f_print_set_color(fp, color);
  }

  f_print_set_line_width(fp, 1);

  x1 = x;
  y1 = y-height; /* move the origin to 0, 0*/

  fprintf(fp, "newpath\n");
  fprintf(fp, "%d mils %d mils moveto\n", x1-origin_x, y1-origin_y);
  fprintf(fp, "%d mils %d mils fbox\n", width, height);
  fprintf(fp, "grestore\n");

}

@ %def o_box_print_filled


@section Function @code{o_box_print_mesh()}

@defun o_box_print_mesh w_current fp o_current x y width height color fill_width angle1 pitch1 angle2 pitch2 origin_x origin_y
The function prints a meshed box. No outline is printed. The box is defined by the coordinates of its upper left corner in ([[x]],[[y]]) and its width and height given by the [[width]] and [[height]] parameters. The postscript file is defined by the file pointer [[fp]]. 
@end defun

The inside mesh is achieved by two successive call to the [[o_box_print_hatch()]] function, given [[angle1]] and [[pitch1]] the first time and [[angle2]] and [[pitch2]] the second time.

Negative or null values for [[pitch1]] and/or [[pitch2]] are not allowed as it leads to an endless loop in [[o_box_print_hatch]].

All dimensions are in mils.

<<o_box_basic.c : o_box_print_mesh()>>=
void
o_box_print_mesh(TOPLEVEL *w_current, FILE *fp,
                 int x, int y,
                 int width, int height,
                 int color,
                 int fill_width,
                 int angle1, int pitch1,
                 int angle2, int pitch2,
                 int origin_x, int origin_y)
{
  o_box_print_hatch(w_current, fp,
                    x, y, width, height,
                    color,
                    fill_width,
                    angle1, pitch1, -1, -1,
                    origin_x, origin_y);
  o_box_print_hatch(w_current, fp,
                    x, y, width, height,
                    color,
                    fill_width,
                    angle2, pitch2, -1, -1,
                    origin_x, origin_y);

}

@ %def o_box_print_mesh


@section Function @code{o_box_print_hatch()}

@defun o_box_print_hacth w_current fp x y width height color fill_width angle1 pitch1 angle2 pitch2 origin_x origin_y
The function prints a hatched box. No outline is printed. The box is defined by the coordinates of its upper left corner in ([[x]],[[y]]) and its width and height given by the [[width]] and [[height]] parameters. The postscript file is defined by the file pointer [[fp]]. 
[[fill_width]], [[angle1]], [[pitch1]] parameters define the way the box has to be hatched.
[[angle2]] and [[pitch2]] parameters are unused but kept for compatibility with other fill functions.
@end defun

Negative or null values for [[pitch1]] are not allowed as it leads to an endless loop.

All dimensions are in mils.

<<o_box_basic.c : o_box_print_hatch()>>=
void
o_box_print_hatch(TOPLEVEL *w_current, FILE *fp,
                  int x, int y,
                  int width, int height,
                  int color,
                  int fill_width,
                  int angle1, int pitch1,
                  int angle2, int pitch2,
                  int origin_x, int origin_y)
{
  int x3, y3, x4, y4;
  double cos_a_, sin_a_;
  double x0, y0, r;
  double x1, y1, x2, y2;
  double amin, amax, a[4], min1, min2, max1, max2;

  fprintf(fp, "gsave\n");
  if (w_current->print_color) {
    f_print_set_color(fp, color);
  }

  f_print_set_line_width(fp, fill_width);	
 	
@ %def o_box_print_hatch	

The cosinus and sinus of [[angle1]] are computed once and reused later.
	
<<o_box_basic.c : o_box_print_hatch()>>=
  cos_a_ = cos(((double) angle1) * M_PI/180);
  sin_a_ = sin(((double) angle1) * M_PI/180);

@ 

The function considers the smallest circle around the box. Its radius is given by the following relation. Its center is given by the point at the middle of the box horizontally and vertically (intersection of its two diagonals).

<<o_box_basic.c : o_box_print_hatch()>>=	
  r = sqrt((double) (pow(width, 2) + pow(height, 2))) / 2;

  <<o_box_print_hatch() : calculating and printing the lines>>

  fprintf(fp, "grestore\n");
	
}
@ 

When drawing a line in a circle there is two intersections. With the previously described circle, these intersections are out of the box. They can be easily calculated, the first by resolution of an equation and the second one by symetry in relation to the vertical axis going through the center of the circle.

These two points are then rotated of angle @code{angle1} using the matrix previously mentionned.

<<o_box_print_hatch() : calculating and printing the lines>>=
  y0 = 0;
  while(y0 < r) {
    x0 = pow(r, 2) - pow(y0, 2);
    x0 = sqrt(x0);

    x1 = (x0*cos_a_ - y0*sin_a_);
    y1 = (x0*sin_a_ + y0*cos_a_);
    x2 = ((-x0)*cos_a_ - y0*sin_a_);
    y2 = ((-x0)*sin_a_ + y0*cos_a_);
  

@ 

It now parametrizes the segment : first intersection is given the value of 0 and the second is given the value of 1. The four values for each intersection of the segment and the four sides (vertical or horizontal) of the box are given by the following relations :

<<o_box_print_hatch() : calculating and printing the lines>>=
                                                                        
                                                                                      if((int) (x2 - x1) != 0) {
		a[0] = ((-width/2) - x1) / (x2 - x1);
		a[1] = ((width/2)  - x1) / (x2 - x1);
	} else {
		a[0] = 0; a[1] = 1;
	}
 
	if((int) (y2 - y1) != 0) {
		a[2] = ((-height/2) - y1) / (y2 - y1);
		a[3] = ((height/2)  - y1) / (y2 - y1);
	} else {
		a[2] = 0; a[3] = 1;
	}
@ 

It now has to check which of these four values are for intersections with the sides of the box (some values may be for intersections out of the box). This is made by a min/max function.

<<o_box_print_hatch() : calculating and printing the lines>>=		
		if(a[0] < a[1]) {
			min1 = a[0]; max1 = a[1];
		} else {
			min1 = a[1]; max1 = a[0];
		}

		if(a[2] < a[3]) {
			min2 = a[2]; max2 = a[3];
		} else {
			min2 = a[3]; max2 = a[2];
		}

		amin = (min1 < min2) ? min2 : min1;
		amin = (amin < 0) ? 0 : amin;

		amax = (max1 < max2) ? max1 : max2;
		amax = (amax < 1) ? amax : 1;

@ 

If the segment really go through the box it prints the line. It also take the opportunity of the symetry in the box in relation to its center to print the second line at the same time.

If there is no intersection of the segment with any of the sides, then there is no need to continue : there would be no more segment in the box to print.

<<o_box_print_hatch() : calculating and printing the lines>>=		
		if((amax > amin) && (amax != 1) && (amin != 0)) {
			/* There is intersection between the line and the box edges */
			x3 = (int) (x1 + amin*(x2 - x1));
			y3 = (int) (y1 + amin*(y2 - y1));

			x4 = (int) (x1 + amax*(x2 - x1));
			y4 = (int) (y1 + amax*(y2 - y1));

			fprintf(fp, "newpath\n");
			fprintf(fp, "%d mils %d mils moveto\n",
  					x3 + (x + width/2), y3 + (y - height/2));
			fprintf(fp, "%d mils %d mils lineto\n",
  					x4 + (x + width/2), y4 + (y - height/2));

			fprintf(fp, "stroke\n");

			fprintf(fp, "newpath\n");
			fprintf(fp, "%d mils %d mils moveto\n",
					-x3 + (x + width/2), -y3 + (y - height/2));
			fprintf(fp, "%d mils %d mils lineto\n",
					-x4 + (x + width/2), -y4 + (y - height/2));
			fprintf(fp, "stroke\n");
			
		} else {
			break;
		}
		
		y0 = y0 + pitch1;
	}

@


@section Function @code{o_box_print_old()}

@defun o_box_print_old w_current fp o_current origin_x origin_y
@end defun

<<o_box_basic.c : o_box_print_old()>>=
void
o_box_print_old(TOPLEVEL *w_current, FILE *fp,
                int origin_x, int origin_y)
{
  int width, height;
  int x1, y1;
  if (o_current == NULL) {
    printf("got null in o_box_print\n");
    return;
  }

  if (w_current->print_color) {
    f_print_set_color(fp, o_current->color);
  }


  width = abs(o_current->line_points->x2 - o_current->line_points->x1); 
  height = abs(o_current->line_points->y1 - o_current->line_points->y2);

  x1 = o_current->line_points->x1;
  y1 = o_current->line_points->y1-height; /* move the origin to 0, 0*/

  fprintf(fp, "newpath\n");
  fprintf(fp, "%d mils %d mils moveto\n", x1-origin_x, y1-origin_y);
  fprintf(fp, "%d mils %d mils box\n", width, height);

}

@ %def o_box_print_old


@section Function @code{o_box_image_write()}

@defun o_box_image_write w_current o_current origin_x origin_y color_mode
@end defun

<<o_box_basic.c : o_box_image_write()>>=
void
o_box_image_write(TOPLEVEL *w_current, OBJECT *o_current, 
                  int origin_x, int origin_y, int color_mode)
{
  int color;


  if (o_current == NULL) {
    printf("got null in o_box_image_write\n");
    return;
  }


  if (color_mode == TRUE) {
    color = o_image_geda2gd_color(o_current->color);
  } else {
    color = image_black;
  }

  /* assumes screen coords are already calculated correctly */
#ifdef HAS_LIBGDGEDA
  gdImageRectangle(current_im_ptr, 
                   o_current->box->screen_upper_x,
                   o_current->box->screen_upper_y,
                   o_current->box->screen_lower_x,
                   o_current->box->screen_lower_y, 
                   color);
#endif

}

@ %def o_box_image_write


@section Function @code{o_box_rotate()}

@defun o_box_rotate w_current centerx centery angle object
@end defun

<<o_box_basic.c : o_box_rotate()>>=
/* takes in screen coordinates for the centerx,y, and then does the rotate 
 * in world space */
/* also ignores angle argument... for now, rotate only in 90 degree 
 * increments */
/* fixed to 90 degrees... it's *not* general now */
void
o_box_rotate(TOPLEVEL *w_current, int centerx, int centery, int angle,
             OBJECT *object)
{
  int world_centerx, world_centery;
  int newx1, newy1;
  int newx2, newy2;
  int width, height;

  SCREENtoWORLD(w_current, centerx, centery, 
                &world_centerx,
                &world_centery);  

  width = abs(object->box->upper_x - object->box->lower_x);
  height = abs(object->box->upper_y - object->box->lower_y);

  /* translate object to origin */
  o_box_translate_world(w_current, -world_centerx, -world_centery, object);
  rotate_point_90(object->box->upper_x, object->box->upper_y, angle,
                  &newx1, &newy1);

  rotate_point_90(object->box->lower_x, object->box->lower_y, angle,
                  &newx2, &newy2);



  object->box->upper_x = min(newx1,newx2);
  object->box->upper_y = max(newy1,newy2);
  object->box->lower_x = max(newx1,newx2);
  object->box->lower_y = min(newy1,newy2);
	
  o_box_translate_world(w_current, world_centerx, world_centery, object);
}

@ %def o_box_rotate


@section Function @code{o_box_rotate_world()}

@defun o_box_rotate_world w_current world_centerx world_centery angle object
@end defun

<<o_box_basic.c : o_box_rotate_world()>>=
void
o_box_rotate_world(TOPLEVEL *w_current, 
                   int world_centerx, int world_centery, int angle,
                   OBJECT *object)
{
  int newx1, newy1;
  int newx2, newy2;
  int width, height;

  if (angle == 0)
  return;
		

  width = abs(object->box->upper_x - object->box->lower_x);
  height = abs(object->box->upper_y - object->box->lower_y);

  /* translate object to origin */
  o_box_translate_world(w_current, -world_centerx, -world_centery, object);
  rotate_point_90(object->box->upper_x, object->box->upper_y, angle,
                  &newx1, &newy1);

  rotate_point_90(object->box->lower_x, object->box->lower_y, angle,
                  &newx2, &newy2);

  object->box->upper_x = min(newx1,newx2);
  object->box->upper_y = max(newy1,newy2);
  object->box->lower_x = max(newx1,newx2);
  object->box->lower_y = min(newy1,newy2);
	
  o_box_translate_world(w_current, world_centerx, world_centery, object);
}

@ %def o_box_rotate_world


@section Function @code{o_box_mirror()}

@defun o_box_mirror w_current centerx centery object
@end defun

<<o_box_basic.c : o_box_mirror()>>=
void
o_box_mirror(TOPLEVEL *w_current, int centerx, int centery, OBJECT *object)
{
  int world_centerx, world_centery;
  int newx1, newy1;
  int newx2, newy2;
  int width, height;

  SCREENtoWORLD(w_current, centerx, centery, 
                &world_centerx,
                &world_centery);  

  width = abs(object->box->upper_x - object->box->lower_x);
  height = abs(object->box->upper_y - object->box->lower_y);

  /* translate object to origin */
  o_box_translate_world(w_current, -world_centerx, -world_centery, object);

  newx1 = -object->box->upper_x;
  newy1 = object->box->upper_y;
  newx2 = -object->box->lower_x;
  newy2 = object->box->lower_y;

  object->box->upper_x = min(newx1,newx2);
  object->box->upper_y = max(newy1,newy2);
  object->box->lower_x = max(newx1,newx2);
  object->box->lower_y = min(newy1,newy2);
	
  o_box_translate_world(w_current, world_centerx, world_centery, object);
}

@ %def o_box_mirror


@section Function @code{o_box_mirror_world()}

@defun o_box_mirror_world w_current world_centerx world_centery object
@end defun

<<o_box_basic.c : o_box_mirror_world()>>=
void
o_box_mirror_world(TOPLEVEL *w_current, int world_centerx, int world_centery,
                   OBJECT *object)
{
  int newx1, newy1;
  int newx2, newy2;
  int width, height;

  width = abs(object->box->upper_x - object->box->lower_x);
  height = abs(object->box->upper_y - object->box->lower_y);

  /* translate object to origin */
  o_box_translate_world(w_current, -world_centerx, -world_centery, object);

  newx1 = -object->box->upper_x;
  newy1 = object->box->upper_y;
  newx2 = -object->box->lower_x;
  newy2 = object->box->lower_y;

  object->box->upper_x = min(newx1,newx2);
  object->box->upper_y = max(newy1,newy2);
  object->box->lower_x = max(newx1,newx2);
  object->box->lower_y = min(newy1,newy2);
	
  o_box_translate_world(w_current, world_centerx, world_centery, object);
}

@ %def o_box_mirror_world


@section Function @code{o_box_modify()}

@defun o_box_modify w_current object x y whichone
@end defun

<<o_box_basic.c : o_box_modify()>>=
void
o_box_modify(TOPLEVEL *w_current, OBJECT *object, 
	     int x, int y, int whichone)
{
  int x1, y1, x2, y2;
  int left, right, top, bottom;
  int box_width, box_height, box_left, box_top;

  box_width  = GET_BOX_WIDTH (w_current);
  box_height = GET_BOX_HEIGHT(w_current);
  box_left   = GET_BOX_LEFT  (w_current);
  box_top    = GET_BOX_TOP   (w_current);

  SCREENtoWORLD(w_current,
                box_left,
                box_top,
                &x1,
                &y1);
  SCREENtoWORLD(w_current,
                box_left + box_width,
                box_top  + box_height,
                &x2,
                &y2);

  x1 = snap_grid(w_current, x1);
  y1 = snap_grid(w_current, y1);
  x2 = snap_grid(w_current, x2);
  y2 = snap_grid(w_current, y2);

  object->box->upper_x = x1; 
  object->box->upper_y = y1;
  object->box->lower_x = x2; 
  object->box->lower_y = y2;

  object->box->screen_upper_x = box_left; 
  object->box->screen_upper_y = box_top;
  object->box->screen_lower_x = box_left + box_width; 
  object->box->screen_lower_y = box_top  + box_height;

  get_box_bounds(w_current, object->box, &left, &top, &right, &bottom);
	
  object->left = left;
  object->top = top;
  object->right = right;
  object->bottom = bottom;	
}

@ %def o_box_modify