home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Dream 55
/
Amiga_Dream_55.iso
/
RISCOS
/
APPS
/
SCI
/
ELECTRON
/
AUTOPC.ZIP
/
!AutoPCB
/
Source
/
c
/
AutoPCB
< prev
next >
Wrap
Text File
|
1991-04-06
|
9KB
|
369 lines
/*
** printed circuit board autorouter, Copyright (C) Randy Nevin 1989.
**
** you may give this software to anyone, make as many copies as you like, and
** post it on public computer bulletin boards and file servers. you may not
** sell it or charge any fee for distribution (except for media and postage),
** remove this comment or the copyright notice from the code, or claim that
** you wrote this code or anything derived from it. you may modify the code as
** much as you want (please document clearly with comments, and maintain the
** coding style), but programs which are derived from this one are subject to
** the conditions stated here. i am providing this code so that people can
** learn from it, so if you distribute it, please include source code, not
** just executables. contact me to report bugs or suggest enhancements; i do
** not guarantee support, but i will make an effort in good faith to help you,
** and i want to act as a central clearing house for future versions. you
** should contact me before undertaking a significant development effort, to
** avoid reinventing the wheel. if you come up with an enhancement you
** consider particularly useful, i would appreciate being informed so that it
** can be incorporated in future versions. my address is: Randy Nevin,
** 1731 211th PL NE, Redmond, WA 98053. this code is available directly from
** the author; just send a floppy and a self-addressed floppy mailer with
** sufficient postage.
**
** HISTORY
** (name date description)
** ----------------------------------------------------
** randy nevin 2/1/89 initial version
** randy nevin 2/4/89 made retrace table driven, instead of
** doubly-nested switch statements.
** randy nevin 2/4/89 changed dir from int to char (cut
** storage for it in half).
** randy nevin 2/8/89 changed SetQueue and ReSetQueue to
** give priority to goal nodes.
** randy nevin 2/11/89 don't output incremental search
** results if stdout is redirected.
** randy nevin 2/11/89 released version 1.00
** pete goodwin 17/3/91 adapted for Archimedes
*/
/* C routines */
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <string.h>
/* WIMP */
#include "os.h"
#include "wimp.h"
#include "wimpt.h"
#include "win.h"
#include "res.h"
#include "resspr.h"
#include "template.h"
#include "dbox.h"
#include "baricon.h"
#include "event.h"
#include "menu.h"
#include "werr.h"
#include "flex.h"
#include "heap.h"
#include "xferrecv.h"
#include "alarm.h"
#include "visdelay.h"
#include "saveas.h"
/* Auto PCB stuff */
#include "cell.h"
#include "coordmap.h"
#include "draw.h"
/* DRAW file 1 thou of an inch */
#define MIL (180*256/1000)
#define BLACK 0x00000000
#define WHITE 0x00000000
#define TRANS 0xffffffff
#define RED 0x0000ff00
#define GREEN 0x00ff0000
#define BLUE 0xff000000
extern int Nrows;
extern int Ncols;
extern void InitBoard(void);
extern long GetCell(int, int, int);
extern void SetCell(int, int, int, long);
extern void PlotCell(int, int, int, int);
static int scale, colfact, rowfact, show_hole,
show_top, show_bottom, DP, DPlimit;
#define ICON_MENU 0
#define ICON_MENU_INFO 1
#define ICON_MENU_QUIT 2
#define DBOX_CMD 0
#define PROCESS 0
#define FILE_SOURCE 13
#define TIME 16
#define PLOT 17
#define OPT_HOLE 14
#define OPT_TOP 15
#define OPT_BOTTOM 16
int justboard = 0; /* need all data structures, not just the board */
extern void Initialize( FILE * );
extern BOOL Solve( void );
extern void Report( FILE * );
dbox cmd_dbox;
static menu icon_menu;
static BOOL solving;
static long start, stop;
static FILE *fin;
void Nomem(void)
{
werr(0, "Out of memory");
}
void move(int x, int y)
{
draw_path_move(x * MIL, y * MIL);
}
void draw(int x, int y)
{
draw_path_line(x * MIL, y * MIL);
}
void circle(int x, int y, int r)
{
draw_path_circle(x * MIL, y * MIL, r * MIL);
}
static void process_display()
{
long x;
int r, c, hole, top, bottom, mark;
double scale;
char buffer[13];
hole = dbox_getnumeric(cmd_dbox, OPT_HOLE);
top = dbox_getnumeric(cmd_dbox, OPT_TOP);
bottom = dbox_getnumeric(cmd_dbox, OPT_BOTTOM);
scale = 2.0;
draw_file_header("Auto PCB ");
if (bottom)
{
draw_object_header(2, Ncols * 50 * MIL, Nrows * 50 * MIL);
draw_path_header(TRANS, GREEN);
for (r = 0; r < Nrows; r++)
for (c = 0; c < Ncols; c++)
{
x = GetCell(r, c, BOTTOM);
if (x & HOLE)
PlotLine(x, c, r, BOTTOM);
}
draw_path_end();
}
if (top)
{
draw_object_header(2, Ncols * 50 * MIL, Nrows * 50 * MIL);
draw_path_header(TRANS, RED);
for (r = 0; r < Nrows; r++)
for (c = 0; c < Ncols; c++)
{
x = GetCell(r, c, TOP);
if (x & HOLE)
PlotLine(x, c, r, TOP);
}
draw_path_end();
}
if (hole)
{
draw_object_header(2, Ncols * 50 * MIL, Nrows * 50 * MIL);
draw_path_header(TRANS, BLACK);
for (r = 0; r < Nrows; r++)
for (c = 0; c < Ncols; c++)
{
x = GetCell(r, c, TOP);
if (x & HOLE)
circle(c * 50 + 25, r * 50 + 25, 15);
}
draw_path_end();
}
draw_display(scale);
}
static BOOL save_diag(char *name, void *handle)
{
BOOL ok;
int id;
os_filestr file;
id = (int)handle;
visdelay_begin();
file.action = 10;
file.name = name;
file.loadaddr = 0xaff;
file.start = (int)diag;
file.end = (int)&diag[diagp];
ok = (wimpt_complain(os_file(&file)) == 0);
visdelay_end();
return ok;
}
static void process_pcb()
{
saveas(0xAFF, "DrawFile", 1000, save_diag, NULL, NULL, 0);
}
static void icon_event(wimp_i icon)
{
dbox_showstatic(cmd_dbox);
}
static void menu_event(void *handle, char *hit)
{
int id;
id = (int)handle;
if (id == ICON_MENU)
switch(hit[0])
{
case ICON_MENU_INFO:
{
dbox d;
d = dbox_new("info");
dbox_show(d);
dbox_fillin(d);
dbox_dispose(&d);
}
break;
case ICON_MENU_QUIT:
exit(0);
}
}
static void dbox_event(dbox d, void *handle)
{
int id;
dbox_field field;
id = (int)handle;
field = dbox_get(d);
if (field == dbox_CLOSE)
dbox_hide(d);
if (id == DBOX_CMD && field == PROCESS && !solving)
process_pcb();
if (id == DBOX_CMD && field == PLOT && !solving)
process_display();
}
static void start_solve(int at, void *handle)
{
visdelay_begin();
if (solving = Solve())
alarm_set(alarm_timenow()+10, start_solve, 0);
else
{
stop = time(NULL) - start;
dbox_setnumeric(cmd_dbox, TIME, stop);
dbox_setfield(cmd_dbox, PROCESS, "Save route");
}
visdelay_end();
}
static BOOL dbox_raw_event(dbox d, void *event, void *handle)
{
int id;
wimp_eventstr *e;
id = (int)handle;
e = (wimp_eventstr *)event;
switch(e->e)
{
case wimp_ESEND:
case wimp_ESENDWANTACK:
switch(e->data.msg.hdr.action)
{
case wimp_MDATALOAD:
case wimp_MDATAOPEN:
{
char *name;
int filetype;
filetype = xferrecv_checkinsert(&name);
if (filetype != -1)
{
if (filetype == 0xfff)
{
dbox_setfield(cmd_dbox, FILE_SOURCE, name);
fin = fopen(name, "rb");
if (fin != NULL)
{
xferrecv_insertfileok();
Initialize(fin);
start = time(NULL);
dbox_setfield(cmd_dbox, PROCESS, "Processing");
start_solve(0, 0);
}
}
else
werr(0, "can't load filetype &%x", filetype);
}
}
return TRUE;
}
break;
}
return FALSE;
}
int main (int argc, char *argv[] )
{
wimpt_init("Auto PCB");
res_init("autopcb");
resspr_init();
template_init();
dbox_init();
flex_init();
heap_init(TRUE);
visdelay_init();
baricon("!autopcb", (int)resspr_area(), icon_event);
icon_menu = menu_new("AutoPCB", ">Info,Quit");
event_attachmenu(win_ICONBAR, icon_menu, menu_event, (void *)ICON_MENU);
cmd_dbox = dbox_new("command");
dbox_eventhandler(cmd_dbox, dbox_event, DBOX_CMD);
dbox_raw_eventhandler(cmd_dbox, dbox_raw_event, DBOX_CMD);
dbox_setfield(cmd_dbox, FILE_SOURCE, "<Source file>");
solving = TRUE;
draw_init();
while (TRUE)
event_process();
}