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
|
/*-------------------------------------------------------------------------*/
/* schema.c --- xcircuit routines specific to the schematic capture system */
/* Copyright (c) 2002 Tim Edwards, Johns Hopkins University */
/*-------------------------------------------------------------------------*/
/*-------------------------------------------------------------------------*/
/* written by Tim Edwards, 10/13/97 */
/*-------------------------------------------------------------------------*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#if defined(DARWIN)
#include <sys/malloc.h>
#else
#include <malloc.h>
#endif
#include <X11/Intrinsic.h>
#include <X11/StringDefs.h>
#include "Xw/Xw.h"
#include "Xw/MenuBtn.h"
/*-------------------------------------------------------------------------*/
/* Local includes */
/*-------------------------------------------------------------------------*/
#include "xcircuit.h"
#include "colordefs.h"
#include "menudep.h"
/*----------------------------------------------------------------------*/
/* Function prototype declarations */
/*----------------------------------------------------------------------*/
#include "prototypes.h"
/*------------------------------------------------------------------------*/
/* External Variable definitions */
/*------------------------------------------------------------------------*/
extern Globaldata xobjs;
extern Clientdata areastruct;
extern short eventmode;
extern int *appcolors;
extern Widget menuwidgets[];
extern Widget netbutton;
extern objectpair *pushlist;
extern char _STR[150];
extern char _STR2[250];
/*-------------------------------------------------------------------------*/
#ifdef SCHEMA
extern Widget wsymb, wschema;
/*--------------------------------------------------------*/
/* Menu calls (procedure wrappers) */
/*--------------------------------------------------------*/
void callgennet(Widget w, u_int mode, caddr_t calldata)
{
switch(mode) {
case 0:
gennet("spice", "spc");
break;
case 1:
gennet("sim", "sim");
break;
case 2:
gennet("pcb", "pcb");
break;
case 3:
gennet("flatspice", "fspc");
break;
case 4:
gennet("idxpcb", ""); /* Auto-numbering: no output generated */
break;
}
}
/*------------------------------------------------------------*/
/* Enable schematic capture (set schemon and realize widgets) */
/*------------------------------------------------------------*/
void doxschema(Widget w, caddr_t clientdata, caddr_t calldata)
{
Arg wargs[1];
if (areastruct.schemon) {
areastruct.schemon = False;
XtUnmanageChild(wschema);
XtUnmanageChild(wsymb);
XtUnmanageChild(netbutton);
XtSetArg(wargs[0], XtNlabel, "Enable XSchema");
XtSetValues(OptionsEnableXSchemaButton, wargs, 1);
}
else {
areastruct.schemon = True;
XtManageChild(wschema);
XtManageChild(wsymb);
XtManageChild(netbutton);
XtSetArg(wargs[0], XtNlabel, "Disable XSchema");
XtSetValues(OptionsEnableXSchemaButton, wargs, 1);
}
/* Redraw the screen, since this action may effect the presence of */
/* pins and schematic informational labels. */
drawarea(NULL, NULL, NULL);
}
/*------------------------------------------------------------------------*/
/* Ensure that a page name is unique (required for schematic association) */
/*------------------------------------------------------------------------*/
int checkpagename(objectptr thispageobj)
{
int p, thispage;
char *objname = thispageobj->name;
Boolean changed;
Boolean update = False;
char *clnptr = NULL;
int n;
/* Check for ":n" suffix and prepare for possible update */
clnptr = strrchr(thispageobj->name, ':');
if (clnptr != NULL)
if (sscanf(clnptr + 1, "%d", &n) != 1)
clnptr = NULL;
/* Find the page number of this page object */
for (p = 0; p < xobjs.pages; p++) {
if (xobjs.pagelist[p]->pageobj != NULL) {
if (xobjs.pagelist[p]->pageobj == thispageobj) {
thispage = p;
break;
}
}
}
if (p == xobjs.pages) {
fprintf(stderr, "Error: Object is not a page object!\n");
return 0;
}
/* Look for any other pages with the same name */
do {
changed = False;
for (p = 0; p < xobjs.pages; p++) {
if (p == thispage) continue;
if (xobjs.pagelist[p]->pageobj != NULL) {
if (!strcmp(xobjs.pagelist[p]->pageobj->name, thispageobj->name)) {
/* append ":2" to name or update suffix to ensure uniqueness */
if (clnptr == NULL)
sprintf(thispageobj->name, "%s:2", thispageobj->name);
else
sprintf(clnptr + 1, "%d", n + 1);
changed = True;
update = True;
break;
}
}
}
} while (changed);
if (update) {
renamepage(thispage);
return -1;
}
return 0;
}
/*--------------------------------------*/
/* Find connectivity of a selection */
/*--------------------------------------*/
void startconnect(Widget button, caddr_t clientdata, caddr_t calldata)
{
if (areastruct.selects > 0)
connectivity(button, clientdata, calldata);
else if (eventmode == NORMAL_MODE) {
Wprintf("Click button1 on wire to see connectivity.");
eventmode = CONNECT_MODE;
}
}
/*----------------------------------------------------------------------*/
/* rconnectivity(): Find electrical connections into a node. */
/* (does recursive search on object heirarchy) */
/*----------------------------------------------------------------------*/
void connectivity(Widget button, caddr_t clientdata, caddr_t calldata)
{
short *gsel;
genericptr ggen;
int depth, netid;
objectpair *seltop, *nextptr;
objectptr nettop, thisobj;
char *snew;
stringpart *ppin;
seltop = (objectpair *)malloc(sizeof(objectpair));
seltop->thisobject = objectdata;
seltop->thisinst = NULL;
seltop->nextpair = NULL;
/* pick the first selection that looks like a valid network part */
if (areastruct.selects > 0) {
for (gsel = areastruct.selectlist; gsel < areastruct.selectlist +
areastruct.selects; gsel++) {
ggen = *(objectdata->plist + *gsel);
if (SELECTTYPE(gsel) == LABEL) {
labelptr glab = SELTOLABEL(gsel);
if (glab->pin == LOCAL || glab->pin == GLOBAL) break;
}
else if (SELECTTYPE(gsel) == POLYGON) {
polyptr gpoly = SELTOPOLY(gsel);
if (!nonnetwork(gpoly)) break;
}
}
if (gsel == areastruct.selectlist + areastruct.selects) {
Wprintf("Selected element is not part of a valid network.");
}
}
else
ggen = recurselect(POLYGON | LABEL, &seltop);
/* Determine the netid and the topmost object in which that */
/* net appears. Then build the transformation matrix down */
/* to that object. highlightnet() should end by popping the */
/* entire matrix stack. */
if (ggen != NULL) {
if (checkvalid(objectdata) == -1) {
destroynets();
createnets();
}
if ((netid = is_resolved(&ggen, seltop, &nettop)) != 0) {
/* printf("Net ID is %d in object %s\n", netid, nettop->name); */
depth = pushnetwork(seltop, nettop);
/* printf(">> Pushed network %d levels deep\n", depth); */
nextptr = seltop;
while (nextptr->thisobject != nettop)
nextptr = nextptr->nextpair;
highlightnet(nettop, nextptr->thisinst, netid);
/* pop the matrix stack */
while (depth-- > 0)
UPopCTM();
/* print the net name to the message window */
ppin = nettopin(netid, nettop, NULL);
snew = textprint(ppin, NORMINST);
sprintf(_STR, "Network is \"%s\" in %s", snew, nettop->name);
Wprintf(_STR);
free(snew);
}
else
Wprintf("Selected element is not part of a valid network.");
}
else
Wprintf("No networks found near the cursor position");
/* free up linked list */
while (seltop != NULL) {
nextptr = seltop->nextpair;
free(seltop);
seltop = nextptr;
}
}
/*--------------------------------------------------------------*/
/* Set object type to FUNDAMENTAL if it contains one or more */
/* info labels and is not associated with a schematic/symbol. */
/* */
/* Return TRUE if the object has electrically relevant */
/* networks, FALSE if not. */
/*--------------------------------------------------------------*/
Boolean setobjecttype(objectptr cschem)
{
genericptr *cgen;
labelptr clab;
/* Apply only to schematic objects */
if (cschem->schemtype != SCHEMATIC && cschem->symschem == NULL) {
if (cschem->schemtype == FUNDAMENTAL) cschem->schemtype = SYMBOL;
for (cgen = cschem->plist; cgen < cschem->plist + cschem->parts; cgen++) {
if ((*cgen)->type == LABEL) {
clab = TOLABEL(cgen);
if (clab->pin == INFO) {
cschem->schemtype = FUNDAMENTAL;
break;
}
}
}
}
if ((cschem->symschem != NULL) && (cschem->schemtype == SYMBOL))
return False;
else if ((cschem->schemtype == TRIVIAL) || (cschem->schemtype == FUNDAMENTAL))
return False;
return True;
}
/*------------------------------------------------------*/
/* Pin conversion subroutine for dopintype() */
/*------------------------------------------------------*/
void pinconvert(labelptr thislab, u_int mode)
{
thislab->pin = mode;
switch (mode) {
case NORMAL:
thislab->color = DEFAULTCOLOR; /* nominally black */
break;
case GLOBAL:
thislab->color = BBOXCOLOR; /* orange */
break;
case LOCAL:
thislab->color = SNAPCOLOR; /* red */
break;
case INFO:
thislab->color = AUXCOLOR; /* green */
break;
}
}
/*---------------------------------------------------------*/
/* Change a label's type to NORMAL, GLOBAL, INFO, or LOCAL */
/*---------------------------------------------------------*/
void dopintype(Widget w, u_int mode, caddr_t calldata)
{
short *gsel;
char typestr[40];
short savetype = -1;
if (areastruct.selects == 0) {
Wprintf("Must first select a label to change type");
return;
}
strcpy(typestr, "Changed label to ");
switch(mode) {
case NORMAL:
strcat(typestr, "normal label");
break;
case GLOBAL:
strcat(typestr, "global pin");
break;
case LOCAL:
strcat(typestr, "local pin");
break;
case INFO:
strcat(typestr, "info-label");
break;
}
for (gsel = areastruct.selectlist; gsel < areastruct.selectlist +
areastruct.selects; gsel++)
if (SELECTTYPE(gsel) == LABEL) {
labelptr glab = SELTOLABEL(gsel);
savetype = glab->pin;
pinconvert(glab, mode);
setobjecttype(objectdata);
}
if (savetype >= 0) {
objectdeselect();
drawarea(NULL, NULL, NULL);
Wprintf(typestr);
}
else {
Wprintf("No labels selected.");
}
}
/*----------------------------------------------------------*/
/* Set colors on the symbol/schematic buttons appropriately */
/*----------------------------------------------------------*/
void setsymschem()
{
Arg aargs[2], bargs[2];
/* Set menu items appropriately for this object */
if (objectdata->symschem != NULL) {
if (objectdata->schemtype == SCHEMATIC) {
XtSetArg(aargs[0], XtNlabel, "Go To Symbol");
XtSetArg(bargs[0], XtNlabel, "Disassociate Symbol");
}
else {
XtSetArg(aargs[0], XtNlabel, "Go To Schematic");
XtSetArg(bargs[0], XtNlabel, "Disassociate Schematic");
}
}
else {
if (objectdata->schemtype == SCHEMATIC) {
XtSetArg(aargs[0], XtNlabel, "Make Matching Symbol");
XtSetArg(bargs[0], XtNlabel, "Associate with Symbol");
}
else {
XtSetArg(aargs[0], XtNlabel, "Make Matching Schematic");
XtSetArg(bargs[0], XtNlabel, "Associate with Schematic");
}
}
XtSetValues(NetlistMakeMatchingSymbolButton, aargs, 1);
XtSetValues(NetlistAssociatewithSymbolButton, bargs, 1);
/* Set colors on the symbol and schematic buttons */
if (objectdata->schemtype == SCHEMATIC) {
if (objectdata->symschem == NULL) {
XtSetArg(aargs[0], XtNbackground, OFFBUTTONCOLOR);
XtSetArg(aargs[1], XtNforeground, OFFBUTTONCOLOR);
}
else {
XtSetArg(aargs[0], XtNbackground, BACKGROUND);
XtSetArg(aargs[1], XtNforeground, FOREGROUND);
}
XtSetArg(bargs[1], XtNforeground, FOREGROUND);
XtSetArg(bargs[0], XtNbackground, SNAPCOLOR);
}
else {
if (objectdata->symschem != NULL) {
XtSetArg(bargs[0], XtNbackground, BACKGROUND);
XtSetArg(bargs[1], XtNforeground, FOREGROUND);
}
else {
XtSetArg(bargs[0], XtNbackground, OFFBUTTONCOLOR);
XtSetArg(bargs[1], XtNforeground, OFFBUTTONCOLOR);
}
XtSetArg(aargs[1], XtNforeground, FOREGROUND);
if (objectdata->schemtype == FUNDAMENTAL)
XtSetArg(aargs[0], XtNbackground, AUXCOLOR);
else if (objectdata->schemtype == TRIVIAL || objectdata->symschem != NULL)
XtSetArg(aargs[0], XtNbackground, SNAPCOLOR);
else {
XtSetArg(aargs[0], XtNbackground, OFFBUTTONCOLOR);
XtSetArg(aargs[1], XtNforeground, OFFBUTTONCOLOR);
XtSetArg(bargs[0], XtNbackground, BBOXCOLOR);
XtSetArg(bargs[1], XtNforeground, FOREGROUND);
}
}
XtSetValues(wsymb, aargs, 2);
XtSetValues(wschema, bargs, 2);
}
/*--------------------------------------------------------*/
/* Find the page number for an object */
/*--------------------------------------------------------*/
int findpageobj(objectptr pobj)
{
int tpage;
for (tpage = 0; tpage < xobjs.pages; tpage++) {
if (xobjs.pagelist[tpage]->pageobj == pobj) return tpage;
}
return -1;
}
/*-------------------------------------------------------*/
/* Recursively find all sub-circuits associated with the */
/* top-level circuit and set their filenames to be the */
/* same. */
/* */
/* Avoid possible recursion problems by limiting the */
/* number of recursion levels. Presumably no circuit */
/* would have more than several hundred hierarchical */
/* levels. */
/*-------------------------------------------------------*/
int findsubschems(int toppage, objectptr cschem, int level)
{
genericptr *cgen;
if (level == HIERARCHY_LIMIT) return -1;
for (cgen = cschem->plist; cgen < cschem->plist + cschem->parts; cgen++) {
if ((*cgen)->type == OBJECT) {
objectptr cobj = TOOBJINST(cgen)->thisobject;
if (cobj->symschem != NULL) {
int pageno = findpageobj(cobj->symschem);
/* printf("Symbol %s has schematic at page %d\n", cobj->name, pageno); */
if (pageno < 0) { /* This shouldn't happen (hopefully) */
Wprintf("Error: disconnected schematic!\n");
}
else {
if (xobjs.pagelist[pageno]->filename != NULL)
free(xobjs.pagelist[pageno]->filename);
xobjs.pagelist[pageno]->filename =
strdup(xobjs.pagelist[toppage]->filename);
}
/* A symbol on its own schematic page is allowed for clarity */
/* of the schematic, but this cannot be a functional part of */
/* the schematic circuit! */
if (cobj->symschem != cschem) {
/* printf("Searching for dependencies of symbol %s\n", cobj->name); */
if (findsubschems(toppage, cobj->symschem, level + 1) == -1)
return -1;
}
}
else if (cobj->schemtype != FUNDAMENTAL && cobj->schemtype != TRIVIAL) {
/* Check symbols acting as their own schematics */
if (findsubschems(toppage, cobj, level + 1) == -1)
return -1;
}
}
}
return 0;
}
/*--------------------------------------------------------*/
/* Copy label to corresponding schematic/symbol */
/*--------------------------------------------------------*/
void copypinlabel(labelptr pinlab)
{
labelptr *newlabel, tlabel;
genericptr *tgen;
objectptr schemobj = objectdata->symschem;
if (areastruct.schemon && schemobj != NULL && (pinlab->pin == LOCAL)) {
/* If this pin already exists, don't copy it */
for (tgen = schemobj->plist; tgen < schemobj->plist + schemobj->parts;
tgen++) {
if ((*tgen)->type == LABEL) {
tlabel = TOLABEL(tgen);
if (!stringcomp(tlabel->string, pinlab->string)) return;
}
}
NEW_LABEL(newlabel, schemobj);
(*newlabel)->pin = pinlab->pin;
(*newlabel)->rotation = pinlab->rotation;
(*newlabel)->justify = pinlab->justify;
(*newlabel)->color = pinlab->color;
(*newlabel)->scale = pinlab->scale;
(*newlabel)->string = stringcopy(pinlab->string);
(*newlabel)->num_params = 0;
(*newlabel)->passed = NULL;
/* place label just outside bounding box, then recompute bbox */
(*newlabel)->position.x = schemobj->lowerleft.x + (schemobj->width >> 1);
(*newlabel)->position.y = schemobj->lowerleft.y - TEXTHEIGHT
* (*newlabel)->scale;
schemobj->parts++;
incr_changes(schemobj);
schemobj->valid = False;
singlebbox(objectdata, ENDPART);
}
}
/*-------------------------------------------------------*/
/* Check if top-level page is the same name as a library */
/* object; if so, connect it. */
/* Note that it is not an error not to find the matching */
/* symbol/schematic. "is_schematic" and "is_symbol" */
/* comments in the .ps file are complementary, so the */
/* first one encountered will always fail, and the other */
/* will succeed. */
/*-------------------------------------------------------*/
int checkschem(objectptr thisobj, char *cname)
{
objectptr *tlib;
short i, j;
if (areastruct.schemon == False || thisobj->symschem != NULL) return 0;
for (i = 0; i < xobjs.numlibs; i++) {
for (j = 0; j < xobjs.userlibs[i].number; j++) {
tlib = xobjs.userlibs[i].library + j;
if (!strcmp(cname, (*tlib)->name)) {
thisobj->symschem = (*tlib);
thisobj->schemtype = SCHEMATIC;
(*tlib)->symschem = thisobj;
(*tlib)->schemtype = SYMBOL;
return 1;
}
}
}
return 0;
}
/*--------------------------------------------------------*/
/* Complement to the above routine: If a library object */
/* name is the same as a top-level page, connect them. */
/*--------------------------------------------------------*/
int checksym(objectptr symobj, char *cname)
{
short cpage;
objectptr checkpage;
if (areastruct.schemon == False || symobj->symschem != NULL) return 0;
for (cpage = 0; cpage < xobjs.pages; cpage++) {
checkpage = xobjs.pagelist[cpage]->pageobj;
if (checkpage != NULL) {
if (!strcmp(checkpage->name, cname)) {
symobj->symschem = checkpage;
symobj->schemtype = SYMBOL;
checkpage->symschem = symobj;
checkpage->schemtype = SCHEMATIC;
return 1;
}
}
}
return 0;
}
/*----------------------------------------------------------------------*/
/* Find location of corresponding pin in symbol/schematic and change it */
/* to the text of the indicated label. If "newlabel" is NULL, then */
/* change the other label from pin to normal text. */
/*----------------------------------------------------------------------*/
void changeotherpins(labelptr newlabel, stringpart *oldstring)
{
objectptr other = objectdata->symschem;
genericptr *tgen;
labelptr tlab;
if (other == NULL) return;
for (tgen = other->plist; tgen < other->plist + other->parts; tgen++) {
if ((*tgen)->type == LABEL) {
tlab = TOLABEL(tgen);
if (!stringcomp(tlab->string, oldstring)) {
if (newlabel != NULL) {
free(tlab->string);
tlab->string = stringcopy(newlabel->string);
}
else
tlab->pin = NORMAL;
}
}
}
}
/*----------------------------------------------------------------------*/
/* Swap object schematic and symbol pages. */
/* mode = 0 disallows creation of a new schematic or symbol; i.e., if */
/* there is no corresponding schematic/symbol, nothing happens. */
/*----------------------------------------------------------------------*/
void swapschem(Widget w, u_int mode, caddr_t calldata)
{
objectptr savepage = objectdata;
labelptr *pinlab;
genericptr *plab;
Boolean lflag;
if (areastruct.schemon == False) return;
if (eventmode == PRESS_MODE || eventmode == COPY2_MODE)
objectdelete(NORMAL);
/* Create symbol or schematic, if allowed by mode */
if ((objectdata->symschem == NULL) && (mode != 0)) {
if (objectdata->schemtype != SCHEMATIC) {
int tpage;
/* create a new page for the new schematic */
for (tpage = 0; tpage < xobjs.pages; tpage++)
if (xobjs.pagelist[tpage]->pageobj == NULL) break;
changepage(tpage);
}
else {
objectptr *newobject;
short libnum = USERLIB - LIBRARY;
/* create a new library object for the new symbol */
xobjs.userlibs[libnum].library = (objectptr *)
realloc(xobjs.userlibs[libnum].library,
++xobjs.userlibs[libnum].number * sizeof(objectptr));
newobject = xobjs.userlibs[libnum].library
+ xobjs.userlibs[libnum].number - 1;
*newobject = (objectptr) malloc(sizeof(object));
initmem(*newobject);
(*newobject)->schemtype = SYMBOL;
(*newobject)->hidden = False;
(*newobject)->devname = NULL;
objectdata = *newobject;
/* Generate the default bounding box for a size-zero object */
calcbbox(*newobject);
}
/* set links between the two objects */
savepage->symschem = objectdata;
objectdata->symschem = savepage;
/* make the name of the new object equal to that of the old */
strcpy(objectdata->name, savepage->name);
/* copy all pin labels into the new object */
for (plab = savepage->plist; plab < savepage->plist + savepage->parts;
plab++) {
if ((*plab)->type == LABEL) {
genericptr *tgen;
labelptr tlab, lpin = (labelptr)*plab;
if (lpin->pin == LOCAL) {
/* Only make one copy of each pin name */
lflag = False;
for (tgen = objectdata->plist; tgen <
objectdata->plist + objectdata->parts; tgen++) {
if ((*tgen)->type == LABEL) {
tlab = TOLABEL(tgen);
if (!stringcomp(tlab->string, lpin->string)) lflag = True;
}
}
if (lflag == True) continue;
NEW_LABEL(pinlab, objectdata);
(*pinlab)->pin = lpin->pin;
(*pinlab)->color = lpin->color;
(*pinlab)->rotation = 0;
(*pinlab)->scale = 1.0;
(*pinlab)->justify = areastruct.justify;
(*pinlab)->position.x = 0;
(*pinlab)->position.y = objectdata->parts * (TEXTHEIGHT + 10);
(*pinlab)->num_params = 0;
(*pinlab)->passed = NULL;
u2u_snap(&((*pinlab)->position));
(*pinlab)->string = stringcopy(lpin->string);
objectdata->parts++;
incr_changes(objectdata);
}
}
calcbbox(objectdata);
}
/* Recreate the user library with the new symbol */
if (savepage->schemtype != SYMBOL) composelib(USERLIB);
}
else if (objectdata->symschem != NULL) {
objectdata = objectdata->symschem;
}
if (areastruct.selects > 0) free(areastruct.selectlist);
areastruct.selects = 0;
setpage();
transferselects();
refresh(NULL, NULL, NULL);
setsymschem();
}
/*----------------------------------------------------------------------*/
/* Wrapper for swapschem() when generating a new symbol. */
/*----------------------------------------------------------------------*/
void makesymbol(Widget w, caddr_t calldata)
{
/* copy name from popup prompt buffer and check */
strcpy(objectdata->name, _STR2);
checkname(objectdata);
swapschem(w, (u_int)1, calldata);
}
/*----------------------------------------------------------------------*/
/* Check name before doing a swap: If name begins with "Page", prompt */
/* for the object name, as you would when doing selectsave(). */
/*----------------------------------------------------------------------*/
void dobeforeswap(Widget w, caddr_t clientdata, caddr_t calldata)
{
buttonsave *popdata = (buttonsave *)malloc(sizeof(buttonsave));
/* Check if this function is valid */
if (areastruct.schemon == False) return;
/* Check for requirement to change the name before creating the symbol */
if ((objectdata->symschem == NULL) && (objectdata->schemtype == SCHEMATIC)
&& (strstr(objectdata->name, "Page ") != NULL)) {
/* Get a name for the new object */
eventmode = NORMAL_MODE;
popdata->dataptr = NULL;
popdata->button = NULL; /* indicates that no button is assc'd w/ the popup */
popupprompt(w, "Enter name for new object:", "\0", makesymbol, popdata, NULL);
}
else
swapschem(w, (u_int)1, calldata);
}
/*------------------------------------------*/
/* Disassociate a symbol from its schematic */
/*------------------------------------------*/
void schemdisassoc()
{
if (eventmode != NORMAL) {
Wprintf("Cannot disassociate schematics in this mode");
}
else {
objectdata->symschem->symschem = NULL;
objectdata->symschem = NULL;
setsymschem();
Wprintf("Schematic and symbol are now unlinked.");
}
}
/*--------------------------------------------------------------*/
/* Schematic<-->symbol association. Determine action from */
/* context (associate/disassociate, symbol or schematic) */
/*--------------------------------------------------------------*/
void startschemassoc(Widget w, caddr_t clientdata, caddr_t calldata)
{
if (objectdata->symschem != NULL)
schemdisassoc();
else {
eventmode = ASSOC_MODE;
if (objectdata->schemtype == SCHEMATIC) {
/* Find a symbol to associate */
startcatalog(w, LIBLIB, NULL);
Wprintf("Click on library page, then symbol to associate.");
}
else {
/* Find a schematic (page) to associate */
startcatalog(w, PAGELIB, NULL);
Wprintf("Click on schematic page to associate.");
}
}
}
/*--------------------------------------------------------------*/
/* Callback procedures on the schematic/symbol buttons. */
/*--------------------------------------------------------------*/
void schemassoc(objectptr schemobj, objectptr symbolobj)
{
if (eventmode != ASSOC_MODE) {
Wprintf("Cannot make (dis)association in this mode");
}
else if (schemobj->symschem != NULL || symbolobj->symschem != NULL) {
Wprintf("Both objects must be disassociated first.");
}
else {
schemobj->symschem = symbolobj;
symbolobj->symschem = schemobj;
if (symbolobj->schemtype == TRIVIAL)
symbolobj->schemtype = SYMBOL;
/* Schematic takes the name of its associated symbol, by default */
strcpy(schemobj->name, symbolobj->name);
/* Ensure that schematic (page) name is unique */
while (checkpagename(schemobj) < 0);
setsymschem(); /* Set buttons and menu items appropriately */
}
}
#endif
/*-------------------------------------------------------------------------*/
|