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
|
@c -*- mode: Noweb; noweb-doc-mode: texinfo-mode; noweb-code-mode: c-mode -*-
@node File o_bus_basic.c,,,Top
@chapter File @file{o_bus_basic.c}
@section File header
<<o_bus_basic.c : *>>=
<<o_bus_basic.c : copyright and license>>
/* DO NOT read or edit this file ! Use ../noweb/o_bus_basic.nw instead */
<<o_bus_basic.c : include directives>>
<<o_bus_basic.c : get_bus_bounds()>>
<<o_bus_basic.c : world_get_bus_bounds()>>
<<o_bus_basic.c : o_bus_add()>>
<<o_bus_basic.c : o_bus_recalc()>>
<<o_bus_basic.c : o_bus_read()>>
<<o_bus_basic.c : o_bus_save()>>
<<o_bus_basic.c : o_bus_translate()>>
<<o_bus_basic.c : o_bus_translate_world()>>
<<o_bus_basic.c : o_bus_copy()>>
<<o_bus_basic.c : o_bus_print()>>
<<o_bus_basic.c : o_bus_image_write()>>
<<o_bus_basic.c : o_bus_rotate()>>
<<o_bus_basic.c : o_bus_rotate_world()>>
<<o_bus_basic.c : o_bus_mirror()>>
<<o_bus_basic.c : o_bus_mirror_world()>>
<<o_bus_basic.c : o_bus_orientation()>>
<<o_bus_basic.c : o_bus_consolidate_lowlevel()>>
<<o_bus_basic.c : o_bus_consolidate_segments()>>
<<o_bus_basic.c : o_bus_consolidate()>>
<<o_bus_basic.c : o_bus_modify()>>
@
<<o_bus_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_bus_basic.c : include directives>>=
#include <config.h>
#include <stdio.h>
#include <math.h>
#include <gtk/gtk.h>
#include <libguile.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"
#ifdef HAVE_LIBDMALLOC
#include <dmalloc.h>
#endif
@ %def
@section Function @code{get_bus_bounds()}
@defun get_bus_bounds w_current line left top right bottom
@end defun
<<o_bus_basic.c : get_bus_bounds()>>=
void
get_bus_bounds(TOPLEVEL *w_current, LINE *line, int *left, int *top,
int *right, int *bottom)
{
*left = w_current->width;
*top = w_current->height;
*right = 0;
*bottom = 0;
if (line->screen_x[0] < *left) *left = line->screen_x[0];
if (line->screen_x[0] > *right) *right = line->screen_x[0];
if (line->screen_y[0] < *top) *top = line->screen_y[0];
if (line->screen_y[0] > *bottom) *bottom = line->screen_y[0];
if (line->screen_x[1] < *left) *left = line->screen_x[1];
if (line->screen_x[1] > *right) *right = line->screen_x[1];
if (line->screen_y[1] < *top) *top = line->screen_y[1];
if (line->screen_y[1] > *bottom) *bottom = line->screen_y[1];
*left = *left - 4;
*top = *top - 4;
*right = *right + 4;
*bottom = *bottom + 4;
}
@ %def get_bus_bounds
@section Function @code{world_get_bus_bounds()}
@defun world_get_bus_bounds w_current line left top right bottom
@end defun
<<o_bus_basic.c : world_get_bus_bounds()>>=
void
world_get_bus_bounds(TOPLEVEL *w_current, LINE *line, int *left, int *top,
int *right, int *bottom)
{
*left = w_current->init_right;
*top = w_current->init_bottom;
*right = 0;
*bottom = 0;
if (line->x[0] < *left) *left = line->x[0];
if (line->x[0] > *right) *right = line->x[0];
if (line->y[0] < *top) *top = line->y[0];
if (line->y[0] > *bottom) *bottom = line->y[0];
if (line->x[1] < *left) *left = line->x[1];
if (line->x[1] > *right) *right = line->x[1];
if (line->y[1] < *top) *top = line->y[1];
if (line->y[1] > *bottom) *bottom = line->y[1];
}
@ %def world_get_bus_bounds
@section Function @code{o_bus_add()}
@defun o_bus_add w_current object_list type color x1 y1 x2 y2 dir
@end defun
<<o_bus_basic.c : o_bus_add()>>=
OBJECT *
o_bus_add(TOPLEVEL *w_current, OBJECT *object_list, char type, int color,
int x1, int y1, int x2, int y2, int bus_ripper_direction)
{
int screen_x, screen_y;
int left, right, top, bottom;
OBJECT *new_node;
new_node = s_basic_init_object("bus");
new_node->type = type;
new_node->color = color;
new_node->line = (LINE *) malloc(sizeof(LINE));
/* check for null */
new_node->line->x[0] = x1;
new_node->line->y[0] = y1;
new_node->line->x[1] = x2;
new_node->line->y[1] = y2;
WORLDtoSCREEN(w_current,
new_node->line->x[0], new_node->line->y[0],
&screen_x,
&screen_y);
new_node->line->screen_x[0] = screen_x;
new_node->line->screen_y[0] = screen_y;
WORLDtoSCREEN(w_current,
new_node->line->x[1], new_node->line->y[1],
&screen_x,
&screen_y);
new_node->line->screen_x[1] = screen_x;
new_node->line->screen_y[1] = screen_y;
new_node->bus_ripper_direction = bus_ripper_direction;
get_bus_bounds(w_current, new_node->line, &left, &top, &right, &bottom);
new_node->left = left;
new_node->top = top;
new_node->right = right;
new_node->bottom = bottom;
/* TODO: questionable cast */
new_node->draw_func = (void *) bus_draw_func;
/* TODO: questionable cast */
new_node->sel_func = (void *) select_func;
object_list = (OBJECT *) s_basic_link_object(new_node, object_list);
s_tile_add_object(w_current, object_list,
new_node->line->x[0], new_node->line->y[0],
new_node->line->x[1], new_node->line->y[1]);
if (!w_current->ADDING_SEL) {
s_conn_update_object(w_current, object_list);
}
return(object_list);
}
@ %def o_bus_add
@section Function @code{o_bus_recalc()}
@defun o_bus_recalc w_current o_current
@end defun
<<o_bus_basic.c : o_bus_recalc()>>=
void
o_bus_recalc(TOPLEVEL *w_current, OBJECT *o_current)
{
int screen_x1, screen_y1;
int screen_x2, screen_y2;
int left, right, top, bottom;
if (o_current == NULL) {
return;
}
if (o_current->line == NULL) {
return;
}
WORLDtoSCREEN(w_current, o_current->line->x[0],
o_current->line->y[0],
&screen_x1,
&screen_y1);
o_current->line->screen_x[0] = screen_x1;
o_current->line->screen_y[0] = screen_y1;
WORLDtoSCREEN(w_current, o_current->line->x[1],
o_current->line->y[1],
&screen_x2,
&screen_y2);
o_current->line->screen_x[1] = screen_x2;
o_current->line->screen_y[1] = screen_y2;
get_bus_bounds(w_current, o_current->line, &left, &top, &right, &bottom);
o_current->left = left;
o_current->top = top;
o_current->right = right;
o_current->bottom = bottom;
}
@ %def o_bus_recalc
@section Function @code{o_bus_read()}
@defun o_bus_read w_current object_list buf version
@end defun
<<o_bus_basic.c : o_bus_read()>>=
OBJECT *
o_bus_read(TOPLEVEL *w_current, OBJECT *object_list, char buf[],
unsigned int release_ver, unsigned int fileformat_ver)
{
char type;
int x1, y1;
int x2, y2;
int d_x1, d_y1;
int d_x2, d_y2;
int color;
int ripper_dir;
if(release_ver <= VERSION_20020825) {
sscanf(buf, "%c %d %d %d %d %d\n", &type, &x1, &y1, &x2, &y2, &color);
ripper_dir = 0;
} else {
sscanf(buf, "%c %d %d %d %d %d %d\n", &type, &x1, &y1, &x2, &y2, &color,
&ripper_dir);
}
d_x1 = x1;
d_y1 = y1;
d_x2 = x2;
d_y2 = y2;
if (x1 == x2 && y1 == y2) {
fprintf(stderr, "Found a zero length bus [ %c %d %d %d %d %d ]\n", type, x1, y1, x2, y2, color);
s_log_message("Found a zero length bus [ %c %d %d %d %d %d ]\n", type, x1, y1, x2, y2, color);
}
if (w_current->override_bus_color != -1) {
color = w_current->override_bus_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;
}
if (ripper_dir < -1 || ripper_dir > 1) {
fprintf(stderr, "Found an invalid bus ripper direction [ %s ]\n", buf);
s_log_message("Found an invalid bus ripper direction [ %s ]\n", buf);
s_log_message("Resetting direction to neutral (no direction)\n");
ripper_dir = 0;
}
object_list = o_bus_add(w_current, object_list, type, color,
d_x1, d_y1, d_x2, d_y2, ripper_dir);
return(object_list);
}
@ %def o_bus_read
@section Function @code{o_bus_save()}
@defun o_bus_save buf object
@end defun
<<o_bus_basic.c : o_bus_save()>>=
char *
o_bus_save(OBJECT *object)
{
int x1, x2, y1, y2;
int color;
char *buf;
x1 = object->line->x[0];
y1 = object->line->y[0];
x2 = object->line->x[1];
y2 = object->line->y[1];
/* Use the right color */
if (object->saved_color == -1) {
color = object->color;
} else {
color = object->saved_color;
}
buf = g_strdup_printf("%c %d %d %d %d %d %d", object->type,
x1, y1, x2, y2, color, object->bus_ripper_direction);
return(buf);
}
@ %def o_bus_save
@section Function @code{o_bus_translate()}
@defun o_bus_translate w_current dx dy object
@end defun
<<o_bus_basic.c : o_bus_translate()>>=
void
o_bus_translate(TOPLEVEL *w_current, int dx, int dy, OBJECT *object)
{
int x, y;
if (object == NULL) printf("nt NO!\n");
/* Do world coords */
object->line->screen_x[0] = object->line->screen_x[0] + dx;
object->line->screen_y[0] = object->line->screen_y[0] + dy;
object->line->screen_x[1] = object->line->screen_x[1] + dx;
object->line->screen_y[1] = object->line->screen_y[1] + dy;
/* do we want snap grid here? */
SCREENtoWORLD(w_current, object->line->screen_x[0],
object->line->screen_y[0],
&x,
&y);
object->line->x[0] = snap_grid(w_current, x);
object->line->y[0] = snap_grid(w_current, y);
SCREENtoWORLD(w_current, object->line->screen_x[1],
object->line->screen_y[1],
&x,
&y);
object->line->x[1] = snap_grid(w_current, x);
object->line->y[1] = snap_grid(w_current, y);
s_tile_update_object(w_current, object);
}
@ %def o_bus_translate
@section Function @code{o_bus_translate_world()}
@defun o_bus_translate_world w_current x1 y1 object
@end defun
<<o_bus_basic.c : o_bus_translate_world()>>=
void
o_bus_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->line->x[0] = object->line->x[0] + x1;
object->line->y[0] = object->line->y[0] + y1;
object->line->x[1] = object->line->x[1] + x1;
object->line->y[1] = object->line->y[1] + y1;
/* update screen coords */
WORLDtoSCREEN(w_current, object->line->x[0],
object->line->y[0],
&screen_x1,
&screen_y1);
object->line->screen_x[0] = screen_x1;
object->line->screen_y[0] = screen_y1;
WORLDtoSCREEN(w_current, object->line->x[1],
object->line->y[1],
&screen_x2,
&screen_y2);
object->line->screen_x[1] = screen_x2;
object->line->screen_y[1] = screen_y2;
/* update bounding box */
get_bus_bounds(w_current, object->line, &left, &top, &right, &bottom);
object->left = left;
object->top = top;
object->right = right;
object->bottom = bottom;
s_tile_update_object(w_current, object);
}
@ %def o_bus_translate_world
@section Function @code{o_bus_copy()}
@defun o_bus_copy w_current list_tail o_current
@end defun
<<o_bus_basic.c : o_bus_copy()>>=
OBJECT *
o_bus_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;
}
/* make sure you fix this in pin and bus as well */
/* still doesn't work... you need to pass in the new values */
/* or don't update and update later */
/* I think for now I'll disable the update and manually update */
new_obj = o_bus_add(w_current, list_tail, OBJ_BUS, color,
o_current->line->x[0], o_current->line->y[0],
o_current->line->x[1], o_current->line->y[1],
o_current->bus_ripper_direction);
new_obj->line->screen_x[0] = o_current->line->screen_x[0];
new_obj->line->screen_y[0] = o_current->line->screen_y[0];
new_obj->line->screen_x[1] = o_current->line->screen_x[1];
new_obj->line->screen_y[1] = o_current->line->screen_y[1];
new_obj->line->x[0] = o_current->line->x[0];
new_obj->line->y[0] = o_current->line->y[0];
new_obj->line->x[1] = o_current->line->x[1];
new_obj->line->y[1] = o_current->line->y[1];
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_bus_copy
@section Function @code{o_bus_print()}
@defun o_bus_print w_current fp o_current origin_x origin_y
@end defun
<<o_bus_basic.c : o_bus_print()>>=
/* need to make this bus specific */
void
o_bus_print(TOPLEVEL *w_current, FILE *fp, OBJECT *o_current,
int origin_x, int origin_y)
{
int offset, offset2;
int cross;
int x1, y1;
int x2, y2;
if (o_current == NULL) {
printf("got null in o_bus_print\n");
return;
}
offset = 7*6;
offset2 = 7;
cross = offset;
if (w_current->print_color) {
f_print_set_color(fp, o_current->color);
}
/* need to make this bus specific */
fprintf(fp, "gsave\n");
fprintf(fp, "newpath\n");
if (w_current->bus_style == THICK) {
fprintf(fp, "%d mils setlinewidth\n", BUS_WIDTH);
}
x1 = o_current->line->x[0]-origin_x,
y1 = o_current->line->y[0]-origin_y;
x2 = o_current->line->x[1]-origin_x,
y2 = o_current->line->y[1]-origin_y;
fprintf(fp, "%d mils %d mils moveto\n", x1, y1);
fprintf(fp, "%d mils %d mils lineto\n", x2, y2);
fprintf(fp, "stroke\n");
#if 0 /* completely redundant, not quite sure why this is here */
/* maybe move this inside, so it doesn't clutter the ps file */
if (w_current->print_color) {
f_print_set_color(fp, w_current->net_endpoint_color);
}
#endif
fprintf(fp, "grestore\n");
}
@ %def o_bus_print
@section Function @code{o_bus_image_write()}
@defun o_bus_image_write w_current o_current origin_x origin_y color_mode
@end defun
<<o_bus_basic.c : o_bus_image_write()>>=
void
o_bus_image_write(TOPLEVEL *w_current, OBJECT *o_current,
int origin_x, int origin_y, int color_mode)
{
int offset, offset2;
int cross;
int x1, y1;
int x2, y2;
int color;
if (o_current == NULL) {
printf("got null in o_bus_image_write\n");
return;
}
if (color_mode == TRUE) {
color = o_image_geda2gd_color(o_current->color);
} else {
color = image_black;
}
offset = SCREENabs(w_current, BUS_WIDTH);
/*
offset = 7 * (float) w_current->height/ (float) w_current->width;
offset2 = 7 * (float) w_current->height/ (float) w_current->width*2;
printf("%f %d %d\n", (float) ( (float) w_current->height/ (float) w_current->width),
offset, offset2);
*/
offset2 = offset*2;
cross = offset;
x1 = o_current->line->screen_x[0];
y1 = o_current->line->screen_y[0];
x2 = o_current->line->screen_x[1];
y2 = o_current->line->screen_y[1];
/* assumes screen coords are already calculated correctly */
#ifdef HAS_LIBGDGEDA
gdImageSetThickness(current_im_ptr, SCREENabs(w_current, BUS_WIDTH));
gdImageLine(current_im_ptr, x1, y1, x2, y2, color);
#endif
}
@ %def o_bus_image_write
@section Function @code{o_bus_rotate()}
@defun o_bus_rotate w_current centerx centery angle object
@end defun
<<o_bus_basic.c : o_bus_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 */
/* fully functional */
void
o_bus_rotate(TOPLEVEL *w_current, int centerx, int centery, int angle,
OBJECT *object)
{
int world_centerx, world_centery;
int newx, newy;
SCREENtoWORLD(w_current, centerx, centery,
&world_centerx,
&world_centery);
/* change the bus ripper orientation when the rotation is 90 degrees */
/* yes it's okay to use o_net_orientation */
if (o_net_orientation(object) == VERTICAL && angle == 90) {
object->bus_ripper_direction = -object->bus_ripper_direction;
}
/* translate object to origin */
o_bus_translate_world(w_current, -world_centerx, -world_centery, object);
rotate_point_90(object->line->x[0], object->line->y[0], angle,
&newx, &newy);
object->line->x[0] = newx;
object->line->y[0] = newy;
rotate_point_90(object->line->x[1], object->line->y[1], angle,
&newx, &newy);
object->line->x[1] = newx;
object->line->y[1] = newy;
o_bus_translate_world(w_current, world_centerx, world_centery, object);
}
@ %def o_bus_rotate
@section Function @code{o_bus_rotate_world()}
@defun o_bus_rotate_world w_current world_centerx world_centery angle object
@end defun
<<o_bus_basic.c : o_bus_rotate_world()>>=
void
o_bus_rotate_world(TOPLEVEL *w_current,
int world_centerx, int world_centery, int angle,
OBJECT *object)
{
int newx, newy;
if (angle == 0)
return;
/* translate object to origin */
o_bus_translate_world(w_current, -world_centerx, -world_centery, object);
rotate_point_90(object->line->x[0], object->line->y[0], angle,
&newx, &newy);
object->line->x[0] = newx;
object->line->y[0] = newy;
rotate_point_90(object->line->x[1], object->line->y[1], angle,
&newx, &newy);
object->line->x[1] = newx;
object->line->y[1] = newy;
o_bus_translate_world(w_current, world_centerx, world_centery, object);
}
@ %def o_bus_rotate_world
@section Function @code{o_bus_mirror()}
@defun o_bus_mirror w_current centerx centery object
@end defun
<<o_bus_basic.c : o_bus_mirror()>>=
void
o_bus_mirror(TOPLEVEL *w_current, int centerx, int centery, OBJECT *object)
{
int world_centerx, world_centery;
SCREENtoWORLD(w_current, centerx, centery,
&world_centerx,
&world_centery);
/* translate object to origin */
o_bus_translate_world(w_current, -world_centerx, -world_centery, object);
object->line->x[0] = -object->line->x[0];
object->line->x[1] = -object->line->x[1];
o_bus_translate_world(w_current, world_centerx, world_centery, object);
}
@ %def o_bus_mirror
@section Function @code{o_bus_mirror_world()}
@defun w_current world_centerx world_centery object
@end defun
<<o_bus_basic.c : o_bus_mirror_world()>>=
void
o_bus_mirror_world(TOPLEVEL *w_current, int world_centerx, int world_centery, OBJECT *object)
{
/* translate object to origin */
o_bus_translate_world(w_current, -world_centerx, -world_centery, object);
object->line->x[0] = -object->line->x[0];
object->line->x[1] = -object->line->x[1];
o_bus_translate_world(w_current, world_centerx, world_centery, object);
}
@ %def o_bus_mirror_world
@section Function @code{o_bus_orientation()}
@defun o_bus_orientation object
@end defun
<<o_bus_basic.c : o_bus_orientation()>>=
int
o_bus_orientation(OBJECT *object)
{
if (object->line->y[0] == object->line->y[1]) {
return(HORIZONTAL);
}
if (object->line->x[0] == object->line->x[1]) {
return(VERTICAL);
}
return(NEITHER);
}
@ %def o_bus_orientation
@section Function @code{o_bus_consolidate_lowlevel()}
@defun o_bus_consolidate_lowlevel object del_object orient
@end defun
<<o_bus_basic.c : o_bus_consolidate_lowlevel()>>=
/* this function does the actual work of making one net segment out of two */
/* connected segments */
/* The second object (del_object) is the object that should be deleted */
/* needs to be bus specific */
void
o_bus_consolidate_lowlevel(OBJECT *object, OBJECT *del_object, int orient)
{
int temp1, temp2;
int final1, final2;
int changed=0;
ATTRIB *tail;
#if DEBUG
printf("o %d %d %d %d\n", object->line->x[0], object->line->y[0], object->line->x[1], object->line->y[1]);
printf("d %d %d %d %d\n", del_object->line->x[0], del_object->line->y[0], del_object->line->x[1], del_object->line->y[1]);
#endif
if (orient == HORIZONTAL) {
temp1 = min(object->line->x[0],
del_object->line->x[0]);
temp2 = min(object->line->x[1],
del_object->line->x[1]);
final1 = min(temp1, temp2);
temp1 = max(object->line->x[0],
del_object->line->x[0]);
temp2 = max(object->line->x[1],
del_object->line->x[1]);
final2 = max(temp1, temp2);
object->line->x[0] = final1;
object->line->x[1] = final2;
changed=1;
}
if (orient == VERTICAL) {
temp1 = min(object->line->y[0],
del_object->line->y[0]);
temp2 = min(object->line->y[1],
del_object->line->y[1]);
final1 = min(temp1, temp2);
temp1 = max(object->line->y[0],
del_object->line->y[0]);
temp2 = max(object->line->y[1],
del_object->line->y[1]);
final2 = max(temp1, temp2);
object->line->y[0] = final1;
object->line->y[1] = final2;
changed=1;
}
#if DEBUG
printf("fo %d %d %d %d\n", object->line->x[0], object->line->y[0], object->line->x[1], object->line->y[1]);
#endif
if (changed) {
/* first check for attributes */
if (del_object->attribs) {
printf("yeah... del object has attributes\n");
printf("reconnecting them to the right place\n");
if (object->attribs) {
printf("object DID have attributes\n");
#if 0
printf("object->attribs\n");
o_attrib_print(object->attribs);
printf("--\n");
printf("del_object->attribs\n");
o_attrib_print(del_object->attribs);
printf("--\n");
#endif
tail = o_attrib_return_tail(object->attribs);
/* skip over old attrib head */
tail->next = del_object->attribs->next;
/* step prev object to point to last object */
tail->next->prev = tail;
/* delete old attrib head */
/* and nothing else */
del_object->attribs->object=NULL;
del_object->attribs->next=NULL;
del_object->attribs->prev=NULL;
o_attrib_delete(del_object->attribs);
/* you don't need to free the attribs list */
/* since it's been relinked into object's */
/* attribs list */
del_object->attribs = NULL;
#if 0
printf("\n\nfinal object->attribs\n");
o_attrib_print(object->attribs);
printf("--\n");
#endif
} else {
printf("object didn't have any attributes\n");
object->attribs = del_object->attribs;
/* TODO: what should this be? */
object->attribs->prev = NULL;
/* setup parent attribute */
object->attribs->object = object;
/* you don't need to free the attribs list */
/* since it's been used by object */
del_object->attribs = NULL;
}
}
}
}
@ %def o_bus_consolidate_lowlevel
@section Function @code{o_bus_consolidate_segments()}
@defun o_bus_consolidate_segments w_current object
@end defun
<<o_bus_basic.c : o_bus_consolidate_segments()>>=
/* needs to be bus specific */
int
o_bus_consolidate_segments(TOPLEVEL *w_current, OBJECT *object)
{
return(0);
}
@ %def o_bus_consolidate_segments
@section Function @code{o_bus_consolidate()}
@defun o_bus_consolidate w_current
@end defun
<<o_bus_basic.c : o_bus_consolidate()>>=
void
o_bus_consolidate(TOPLEVEL *w_current)
{
}
@ %def o_bus_consolidate
@section Function @code{o_bus_modify()}
@defun o_bus_modify w_current object x y whichone
@end defun
<<o_bus_basic.c : o_bus_modify()>>=
void
o_bus_modify(TOPLEVEL *w_current, OBJECT *object,
int x, int y, int whichone)
{
int screen_x, screen_y;
int left, right, top, bottom;
object->line->x[whichone] = x;
object->line->y[whichone] = y;
WORLDtoSCREEN(w_current,
object->line->x[whichone],
object->line->y[whichone],
&screen_x, &screen_y);
object->line->screen_x[whichone] = screen_x;
object->line->screen_y[whichone] = screen_y;
get_bus_bounds(w_current, object->line, &left, &top, &right, &bottom);
object->left = left;
object->top = top;
object->right = right;
object->bottom = bottom;
}
@ %def o_bus_modify
|