mikew@wyse.wyse.com (Mike Wexler) (08/17/88)
Submitted-by: ken@cs.rochester.edu (Ken Yap) Posting-number: Volume 1, Issue 7 Archive-name: xfig/part06 #! /bin/sh # This is a shell archive. Remove anything before this line, then unpack # it by saving it into a file and typing "sh file". To overwrite existing # files, type "sh file -c". You can also feed this as standard input via # unshar, or by typing "sh <file", e.g.. If this archive is complete, you # will see the following message at the end: # "End of archive 6 (of 11)." # Contents: bound.c ellipse.c glue.c read1_3.c rotate.c # Wrapped by mikew@wyse on Tue Aug 16 13:14:39 1988 PATH=/bin:/usr/bin:/usr/ucb ; export PATH if test -f bound.c -a "${1}" != "-c" ; then echo shar: Will not over-write existing file \"bound.c\" else echo shar: Extracting \"bound.c\" \(9642 characters\) sed "s/^X//" >bound.c <<'END_OF_bound.c' X/* X * FIG : Facility for Interactive Generation of figures X * X * Copyright (c) 1985 by Supoj Sutanthavibul (supoj@sally.UTEXAS.EDU) X * January 1985. X * 1st revision : August 1985. X * 2nd revision : April 1988. X * X * %W% %G% X*/ X#include "fig.h" X#include "object.h" X X#define Ninety_deg M_PI_2 X#define One_eighty_deg M_PI X#define Two_seventy_deg (M_PI + M_PI_2) X#define Three_sixty_deg (M_PI + M_PI) X#define round(x) ((int)((x) + .5)) X#define half(z1 ,z2) ((z1+z2)/2.0) X#define max(a, b) (((a) > (b)) ? (a) : (b)) X#define min(a, b) (((a) < (b)) ? (a) : (b)) X Xarc_bound(arc, xmin, ymin, xmax, ymax) XF_arc *arc; Xint *xmin, *ymin, *xmax, *ymax; X{ X float alpha, beta; X double dx, dy, radius; X int bx, by, sx, sy; X X dx = arc->point[0].x - arc->center.x; X dy = arc->center.y - arc->point[0].y; X alpha = atan2(dy, dx); X if (alpha < 0.0) alpha += Three_sixty_deg; X /* compute_angle returns value between 0 to 2PI */ X X radius = sqrt((double)(dx * dx + dy * dy)); X X dx = arc->point[2].x - arc->center.x; X dy = arc->center.y - arc->point[2].y; X beta = atan2(dy, dx); X if (beta < 0.0) beta += Three_sixty_deg; X X bx = max(arc->point[0].x, arc->point[1].x); X bx = max(arc->point[2].x, bx); X by = max(arc->point[0].y, arc->point[1].y); X by = max(arc->point[2].y, by); X sx = min(arc->point[0].x, arc->point[1].x); X sx = min(arc->point[2].x, sx); X sy = min(arc->point[0].y, arc->point[1].y); X sy = min(arc->point[2].y, sy); X X if (arc->direction == 1) { /* counter clockwise */ X if (alpha > beta) { X if (alpha <= 0 || 0 <= beta) X bx = (int)(arc->center.x + radius + 1.0); X if (alpha <= Ninety_deg || Ninety_deg <= beta) X sy = (int)(arc->center.y - radius - 1.0); X if (alpha <= One_eighty_deg || One_eighty_deg <= beta) X sx = (int)(arc->center.x - radius - 1.0); X if (alpha <= Two_seventy_deg || Two_seventy_deg <= beta) X by = (int)(arc->center.y + radius + 1.0); X } X else { X if (0 <= beta && alpha <= 0) X bx = (int)(arc->center.x + radius + 1.0); X if (Ninety_deg <= beta && alpha <= Ninety_deg) X sy = (int)(arc->center.y - radius - 1.0); X if (One_eighty_deg <= beta && alpha <= One_eighty_deg) X sx = (int)(arc->center.x - radius - 1.0); X if (Two_seventy_deg <= beta && alpha <= Two_seventy_deg) X by = (int)(arc->center.y + radius + 1.0); X } X } X else { /* clockwise */ X if (alpha > beta) { X if (beta <= 0 && 0 <= alpha) X bx = (int)(arc->center.x + radius + 1.0); X if (beta <= Ninety_deg && Ninety_deg <= alpha) X sy = (int)(arc->center.y - radius - 1.0); X if (beta <= One_eighty_deg && One_eighty_deg <= alpha) X sx = (int)(arc->center.x - radius - 1.0); X if (beta <= Two_seventy_deg && Two_seventy_deg <= alpha) X by = (int)(arc->center.y + radius + 1.0); X } X else { X if (0 <= alpha || beta <= 0) X bx = (int)(arc->center.x + radius + 1.0); X if (Ninety_deg <= alpha || beta <= Ninety_deg) X sy = (int)(arc->center.y - radius - 1.0); X if (One_eighty_deg <= alpha || beta <= One_eighty_deg) X sx = (int)(arc->center.x - radius - 1.0); X if (Two_seventy_deg <= alpha || beta <= Two_seventy_deg) X by = (int)(arc->center.y + radius + 1.0); X } X } X *xmax = bx; *ymax = by; X *xmin = sx; *ymin = sy; X } X Xcompound_bound(compound, xmin, ymin, xmax, ymax) XF_compound *compound; Xint *xmin, *ymin, *xmax, *ymax; X{ X F_arc *a; X F_ellipse *e; X F_compound *c; X F_spline *s; X F_line *l; X F_text *t; X int bx, by, sx, sy, first = 1; X int llx, lly, urx, ury; X X for (a = compound->arcs; a != NULL; a = a->next) { X arc_bound(a, &sx, &sy, &bx, &by); X if (first) { X first = 0; X llx = sx; lly = sy; X urx = bx; ury = by; X } X else { X llx = min(llx, sx); lly = min(lly, sy); X urx = max(urx, bx); ury = max(ury, by); X } X } X X for (c = compound->compounds; c != NULL; c = c->next) { X compound_bound(c, &sx, &sy, &bx, &by); X if (first) { X first = 0; X llx = sx; lly = sy; X urx = bx; ury = by; X } X else { X llx = min(llx, sx); lly = min(lly, sy); X urx = max(urx, bx); ury = max(ury, by); X } X } X X for (e = compound->ellipses; e != NULL; e = e->next) { X ellipse_bound(e, &sx, &sy, &bx, &by); X if (first) { X first = 0; X llx = sx; lly = sy; X urx = bx; ury = by; X } X else { X llx = min(llx, sx); lly = min(lly, sy); X urx = max(urx, bx); ury = max(ury, by); X } X } X X for (l = compound->lines; l != NULL; l = l->next) { X line_bound(l, &sx, &sy, &bx, &by); X if (first) { X first = 0; X llx = sx; lly = sy; X urx = bx; ury = by; X } X else { X llx = min(llx, sx); lly = min(lly, sy); X urx = max(urx, bx); ury = max(ury, by); X } X } X X for (s = compound->splines; s != NULL; s = s->next) { X spline_bound(s, &sx, &sy, &bx, &by); X if (first) { X first = 0; X llx = sx; lly = sy; X urx = bx; ury = by; X } X else { X llx = min(llx, sx); lly = min(lly, sy); X urx = max(urx, bx); ury = max(ury, by); X } X } X X for (t = compound->texts; t != NULL; t = t->next) { X text_bound(t, &sx, &sy, &bx, &by); X if (first) { X first = 0; X llx = sx; lly = sy; X urx = bx; ury = by; X } X else { X llx = min(llx, sx); lly = min(lly, sy); X urx = max(urx, bx); ury = max(ury, by); X } X } X X *xmin = llx; *ymin = lly; X *xmax = urx; *ymax = ury; X } X Xellipse_bound(e, xmin, ymin, xmax, ymax) XF_ellipse *e; Xint *xmin, *ymin, *xmax, *ymax; X{ X *xmin = e->center.x - e->radiuses.x; X *ymin = e->center.y - e->radiuses.y; X *xmax = e->center.x + e->radiuses.x; X *ymax = e->center.y + e->radiuses.y; X } X Xline_bound(l, xmin, ymin, xmax, ymax) XF_line *l; Xint *xmin, *ymin, *xmax, *ymax; X{ X points_bound(l->points, xmin, ymin, xmax, ymax); X } X Xspline_bound(s, xmin, ymin, xmax, ymax) XF_spline *s; Xint *xmin, *ymin, *xmax, *ymax; X{ X if (int_spline(s)) { X int_spline_bound(s, xmin, ymin, xmax, ymax); X } X else { X normal_spline_bound(s, xmin, ymin, xmax, ymax); X } X } X Xint_spline_bound(s, xmin, ymin, xmax, ymax) XF_spline *s; Xint *xmin, *ymin, *xmax, *ymax; X{ X F_point *p1, *p2; X F_control *cp1, *cp2; X float x0, y0, x1, y1, x2, y2, x3, y3, sx1, sy1, sx2, sy2; X float tx, ty, tx1, ty1, tx2, ty2; X float sx, sy, bx, by; X X p1 = s->points; X sx = bx = p1->x; X sy = by = p1->y; X cp1 = s->controls; X for (p2 = p1->next, cp2 = cp1->next; p2 != NULL; X p1 = p2, cp1 = cp2, p2 = p2->next, cp2 = cp2->next) { X x0 = p1->x; y0 = p1->y; X x1 = cp1->rx; y1 = cp1->ry; X x2 = cp2->lx; y2 = cp2->ly; X x3 = p2->x; y3 = p2->y; X tx = half(x1, x2); ty = half(y1, y2); X sx1 = half(x0, x1); sy1 = half(y0, y1); X sx2 = half(sx1, tx); sy2 = half(sy1, ty); X tx2 = half(x2, x3); ty2 = half(y2, y3); X tx1 = half(tx2, tx); ty1 = half(ty2, ty); X X sx = min(x0, sx); sy = min(y0, sy); X sx = min(sx1, sx); sy = min(sy1, sy); X sx = min(sx2, sx); sy = min(sy2, sy); X sx = min(tx1, sx); sy = min(ty1, sy); X sx = min(tx2, sx); sy = min(ty2, sy); X sx = min(x3, sx); sy = min(y3, sy); X X bx = max(x0, bx); by = max(y0, by); X bx = max(sx1, bx); by = max(sy1, by); X bx = max(sx2, bx); by = max(sy2, by); X bx = max(tx1, bx); by = max(ty1, by); X bx = max(tx2, bx); by = max(ty2, by); X bx = max(x3, bx); by = max(y3, by); X } X *xmin = round(sx); X *ymin = round(sy); X *xmax = round(bx); X *ymax = round(by); X } X Xnormal_spline_bound(s, xmin, ymin, xmax, ymax) XF_spline *s; Xint *xmin, *ymin, *xmax, *ymax; X{ X F_point *p; X float cx1, cy1, cx2, cy2, cx3, cy3, cx4, cy4; X float x1, y1, x2, y2, sx, sy, bx, by; X float px, py, qx, qy; X X p = s->points; X x1 = p->x; y1 = p->y; X p = p->next; X x2 = p->x; y2 = p->y; X cx1 = (x1 + x2) / 2.0; cy1 = (y1 + y2) / 2.0; X cx2 = (cx1 + x2) / 2.0; cy2 = (cy1 + y2) / 2.0; X if (closed_spline(s)) { X x1 = (cx1 + x1) / 2.0; X y1 = (cy1 + y1) / 2.0; X } X sx = min(x1, cx2); sy = min(y1, cy2); X bx = max(x1, cx2); by = max(y1, cy2); X X for (p = p->next; p != NULL; p = p->next) { X x1 = x2; y1 = y2; X x2 = p->x; y2 = p->y; X cx4 = (x1 + x2) / 2.0; cy4 = (y1 + y2) / 2.0; X cx3 = (x1 + cx4) / 2.0; cy3 = (y1 + cy4) / 2.0; X cx2 = (cx4 + x2) / 2.0; cy2 = (cy4 + y2) / 2.0; X X px = min(cx2, cx3); py = min(cy2, cy3); X qx = max(cx2, cx3); qy = max(cy2, cy3); X X sx = min(sx, px); sy = min(sy, py); X bx = max(bx, qx); by = max(by, qy); X } X if (closed_spline(s)) { X *xmin = round(sx); *ymin = round(sy); X *xmax = round(bx); *ymax = round(by); X } X else { X *xmin = round(min(sx, x2)); *ymin = round(min(sy, y2)); X *xmax = round(max(bx, x2)); *ymax = round(max(by, y2)); X } X } X Xtext_bound(t, xmin, ymin, xmax, ymax) XF_text *t; Xint *xmin, *ymin, *xmax, *ymax; X{ X *xmin = t->base_x; X *ymin = t->base_y - t->height; X *xmax = t->base_x + t->length; X *ymax = t->base_y; X } X Xpoints_bound(points, xmin, ymin, xmax, ymax) XF_point *points; Xint *xmin, *ymin, *xmax, *ymax; X{ X int bx, by, sx, sy; X F_point *p; X X bx = sx = points->x; by = sy = points->y; X for (p = points->next; p != NULL; p = p->next) { X sx = min(sx, p->x); sy = min(sy, p->y); X bx = max(bx, p->x); by = max(by, p->y); X } X *xmin = sx; *ymin = sy; X *xmax = bx; *ymax = by; X } X Xcontrol_points_bound(cps, xmin, ymin, xmax, ymax) XF_control *cps; Xint *xmin, *ymin, *xmax, *ymax; X{ X F_control *c; X float bx, by, sx, sy; X X bx = sx = cps->lx; X by = sy = cps->ly; X sx = min(sx, cps->rx); sy = min(sy, cps->ry); X bx = max(bx, cps->rx); by = max(by, cps->ry); X for (c = cps->next; c != NULL; c = c->next) { X sx = min(sx, c->lx); sy = min(sy, c->ly); X bx = max(bx, c->lx); by = max(by, c->ly); X sx = min(sx, c->rx); sy = min(sy, c->ry); X bx = max(bx, c->rx); by = max(by, c->ry); X } X *xmin = round(sx); *ymin = round(sy); X *xmax = round(bx); *ymax = round(by); X } END_OF_bound.c if test 9642 -ne `wc -c <bound.c`; then echo shar: \"bound.c\" unpacked with wrong size! fi # end of overwriting check fi if test -f ellipse.c -a "${1}" != "-c" ; then echo shar: Will not over-write existing file \"ellipse.c\" else echo shar: Extracting \"ellipse.c\" \(9624 characters\) sed "s/^X//" >ellipse.c <<'END_OF_ellipse.c' X/* X * FIG : Facility for Interactive Generation of figures X * X * Copyright (c) 1985 by Supoj Sutanthavibul (supoj@sally.UTEXAS.EDU) X * January 1985. X * 1st revision : Aug 1985. X * X * %W% %G% X*/ X#include "fig.h" X#include "resources.h" X#include "alloc.h" X#include "func.h" X#include "object.h" X#include "paintop.h" X Xextern int cur_line_style, line_thickness; Xextern float cur_styleval; Xextern float cur_angle; Xextern int cur_color; Xextern int fix_x, fix_y, cur_x, cur_y; X Xextern (*canvas_kbd_proc)(); Xextern (*canvas_locmove_proc)(); Xextern (*canvas_leftbut_proc)(); Xextern (*canvas_middlebut_proc)(); Xextern (*canvas_rightbut_proc)(); Xextern null_proc(); Xextern set_popupmenu(); X Xextern F_compound objects; X X/************************* local procedures ********************/ X X init_ellipsebyradius_drawing(); X init_ellipsebydiameter_drawing(); X init_circlebyradius_drawing(); X init_circlebydiameter_drawing(); X move_ebrbox(), move_ebdbox(); X move_cbrbox(), move_cbdbox(); Xint create_ellipsebydia(); Xint create_ellipsebyrad(); Xint create_circlebyrad(); Xint create_circlebydia(); X X#define round(z) (int)((z)+.5) X Xcenter_marker(x, y) Xint x, y; X{ X pw_vector(canvas_pixwin, x, y-2, x, y+2, INV_PAINT, 1); X pw_vector(canvas_pixwin, x-2, y, x+2, y, INV_PAINT, 1); X } X Xellipsebyradius_drawing_selected() X{ X canvas_kbd_proc = null_proc; X canvas_locmove_proc = null_proc; X canvas_leftbut_proc = init_ellipsebyradius_drawing; X canvas_middlebut_proc = null_proc; X canvas_rightbut_proc = set_popupmenu; X set_cursor(&arrow_cursor); X reset_action_on(); X } X Xinit_ellipsebyradius_drawing(x, y) Xint x, y; X{ X cur_x = fix_x = x; X cur_y = fix_y = y; X center_marker(fix_x, fix_y); X canvas_locmove_proc = move_ebrbox; X canvas_leftbut_proc = canvas_rightbut_proc = null_proc; X canvas_middlebut_proc = create_ellipsebyrad; X set_temp_cursor(&null_cursor); X ellipsebyrad_box(INV_PAINT); X set_action_on(); X } X Xmove_ebrbox(x, y) Xint x, y; X{ X ellipsebyrad_box(INV_PAINT); X cur_x = x; X cur_y = y; X ellipsebyrad_box(INV_PAINT); X } X Xellipsebyrad_box(op) Xint op; X{ X register int x1, y1, x2, y2; X int rx, ry; X X rx = cur_x - fix_x; X ry = cur_y - fix_y; X x1 = fix_x + rx; X x2 = fix_x - rx; X y1 = fix_y + ry; X y2 = fix_y - ry; X draw_rectbox(x1, y1, x2, y2, op); X } X Xcreate_ellipsebyrad(x, y) Xint x, y; X{ X F_ellipse *ellipse; X X ellipsebyrad_box(INV_PAINT); X center_marker(fix_x, fix_y); X if (NULL == (Ellipse_malloc(ellipse))) { X blink_msg(); X put_msg(Err_mem); X return; X } X ellipse->type = T_ELLIPSE_BY_RAD; X ellipse->style = cur_line_style; X ellipse->thickness = line_thickness; X ellipse->style_val = cur_styleval; X ellipse->angle = cur_angle; X ellipse->color = cur_color; X ellipse->depth = 0; X ellipse->pen = NULL; X ellipse->area_fill = NULL; X ellipse->direction = 1; X ellipse->center.x = fix_x; X ellipse->center.y = fix_y; X ellipse->radiuses.x = abs(x - fix_x) +1; X ellipse->radiuses.y = abs(y - fix_y) +1; X ellipse->start.x = fix_x; X ellipse->start.y = fix_y; X ellipse->end.x = x; X ellipse->end.y = y; X ellipse->next = NULL; X pw_batch_on(canvas_pixwin); X draw_ellipse(ellipse, DRAW); X pw_batch_off(canvas_pixwin); X clean_up(); X set_action_object(F_CREATE, O_ELLIPSE); X insert_ellipse(&objects.ellipses, ellipse); X set_latestellipse(ellipse); X set_modifiedflag(); X ellipsebyradius_drawing_selected(); X } X Xellipsebydiameter_drawing_selected() X{ X canvas_kbd_proc = null_proc; X canvas_locmove_proc = null_proc; X canvas_leftbut_proc = init_ellipsebydiameter_drawing; X canvas_middlebut_proc = null_proc; X canvas_rightbut_proc = set_popupmenu; X set_cursor(&arrow_cursor); X reset_action_on(); X } X Xinit_ellipsebydiameter_drawing(x, y) Xint x, y; X{ X cur_x = fix_x = x; X cur_y = fix_y = y; X center_marker(fix_x, fix_y); X canvas_locmove_proc = move_ebdbox; X canvas_leftbut_proc = null_proc; X canvas_middlebut_proc = create_ellipsebydia; X set_temp_cursor(&null_cursor); X ellipsebydia_box(INV_PAINT); X set_action_on(); X } X Xmove_ebdbox(x, y) Xint x, y; X{ X ellipsebydia_box(INV_PAINT); X cur_x = x; X cur_y = y; X ellipsebydia_box(INV_PAINT); X } X Xellipsebydia_box(op) Xint op; X{ X draw_rectbox(fix_x, fix_y, cur_x, cur_y, op); X } X Xcreate_ellipsebydia(x, y) Xint x, y; X{ X F_ellipse *ellipse; X X ellipsebydia_box(INV_PAINT); X center_marker(fix_x, fix_y); X if (NULL == (Ellipse_malloc(ellipse))) { X blink_msg(); X put_msg(Err_mem); X return; X } X ellipse->type = T_ELLIPSE_BY_DIA; X ellipse->style = cur_line_style; X ellipse->thickness = line_thickness; X ellipse->style_val = cur_styleval; X ellipse->angle = cur_angle; X ellipse->color = cur_color; X ellipse->depth = 0; X ellipse->pen = NULL; X ellipse->area_fill = NULL; X ellipse->direction = 1; X ellipse->center.x = (fix_x + x) / 2; X ellipse->center.y = (fix_y + y) / 2; X ellipse->radiuses.x = abs(ellipse->center.x - fix_x); X ellipse->radiuses.y = abs(ellipse->center.y - fix_y); X ellipse->start.x = fix_x; X ellipse->start.y = fix_y; X ellipse->end.x = x; X ellipse->end.y = y; X ellipse->next = NULL; X pw_batch_on(canvas_pixwin); X draw_ellipse(ellipse, DRAW); X pw_batch_off(canvas_pixwin); X clean_up(); X set_action_object(F_CREATE, O_ELLIPSE); X insert_ellipse(&objects.ellipses, ellipse); X set_latestellipse(ellipse); X set_modifiedflag(); X ellipsebydiameter_drawing_selected(); X } X X/*************************** circle section ************************/ X Xcirclebyradius_drawing_selected() X{ X canvas_kbd_proc = null_proc; X canvas_locmove_proc = null_proc; X canvas_leftbut_proc = init_circlebyradius_drawing; X canvas_middlebut_proc = null_proc; X canvas_rightbut_proc = set_popupmenu; X set_cursor(&arrow_cursor); X reset_action_on(); X } X Xinit_circlebyradius_drawing(x, y) Xint x, y; X{ X cur_x = fix_x = x; X cur_y = fix_y = y; X center_marker(fix_x, fix_y); X canvas_locmove_proc = move_cbrbox; X canvas_leftbut_proc = null_proc; X canvas_middlebut_proc = create_circlebyrad; X set_temp_cursor(&null_cursor); X circlebyrad_box(INV_PAINT); X set_action_on(); X } X Xmove_cbrbox(x, y) Xint x, y; X{ X circlebyrad_box(INV_PAINT); X cur_x = x; X cur_y = y; X circlebyrad_box(INV_PAINT); X } X Xcirclebyrad_box(op) Xint op; X{ X register int x1, y1, x2, y2; X int radius, rx, ry; X X rx = cur_x - fix_x; X ry = cur_y - fix_y; X radius = round(sqrt((double) (rx*rx + ry*ry))); X x1 = fix_x + radius; X x2 = fix_x - radius; X y1 = fix_y + radius; X y2 = fix_y - radius; X draw_rectbox(x1, y1, x2, y2, op); X pw_vector(canvas_pixwin, fix_x, fix_y, cur_x, cur_y, op, 1); X } X Xcreate_circlebyrad(x, y) Xint x, y; X{ X F_ellipse *c; X int rx, ry; X X circlebyrad_box(INV_PAINT); X center_marker(fix_x, fix_y); X if (NULL == (Ellipse_malloc(c))) { X blink_msg(); X put_msg(Err_mem); X return; X } X c->type = T_CIRCLE_BY_RAD; X c->style = cur_line_style; X c->thickness = line_thickness; X c->style_val = cur_styleval; X c->angle = 0.0; X c->color = cur_color; X c->depth = 0; X c->pen = NULL; X c->area_fill = NULL; X c->direction = 1; X c->center.x = fix_x; X c->center.y = fix_y; X rx = fix_x - x; ry = fix_y - y; X c->radiuses.x = c->radiuses.y = round(sqrt((double)(rx*rx + ry*ry))); X c->start.x = fix_x; X c->start.y = fix_y; X c->end.x = x; X c->end.y = y; X c->next = NULL; X pw_batch_on(canvas_pixwin); X draw_ellipse(c, DRAW); X pw_batch_off(canvas_pixwin); X clean_up(); X set_action_object(F_CREATE, O_ELLIPSE); X insert_ellipse(&objects.ellipses, c); X set_latestellipse(c); X set_modifiedflag(); X circlebyradius_drawing_selected(); X } X Xcirclebydiameter_drawing_selected() X{ X canvas_kbd_proc = null_proc; X canvas_locmove_proc = null_proc; X canvas_leftbut_proc = init_circlebydiameter_drawing; X canvas_middlebut_proc = null_proc; X canvas_rightbut_proc = set_popupmenu; X set_cursor(&arrow_cursor); X reset_action_on(); X } X Xinit_circlebydiameter_drawing(x, y) Xint x, y; X{ X cur_x = fix_x = x; X cur_y = fix_y = y; X center_marker(fix_x, fix_y); X canvas_locmove_proc = move_cbdbox; X canvas_leftbut_proc = null_proc; X canvas_middlebut_proc = create_circlebydia; X set_temp_cursor(&null_cursor); X circlebydia_box(INV_PAINT); X set_action_on(); X } X Xmove_cbdbox(x, y) Xint x, y; X{ X circlebydia_box(INV_PAINT); X cur_x = x; X cur_y = y; X circlebydia_box(INV_PAINT); X } X Xcirclebydia_box(op) Xint op; X{ X register int x1, y1, x2, y2; X int radius, rx, ry; X X rx = (cur_x - fix_x) / 2; X ry = (cur_y - fix_y) / 2; X radius = round(sqrt((double) (rx*rx + ry*ry))); X x1 = fix_x + rx + radius; X x2 = fix_x + rx - radius; X y1 = fix_y + ry + radius; X y2 = fix_y + ry - radius; X draw_rectbox(x1, y1, x2, y2, op); X pw_vector(canvas_pixwin, fix_x, fix_y, cur_x, cur_y, op, 1); X } X Xcreate_circlebydia(x, y) Xint x, y; X{ X F_ellipse *c; X int rx, ry; X X circlebydia_box(INV_PAINT); X center_marker(fix_x, fix_y); X if (NULL == (Ellipse_malloc(c))) { X blink_msg(); X put_msg(Err_mem); X return; X } X c->type = T_CIRCLE_BY_DIA; X c->style = cur_line_style; X c->thickness = line_thickness; X c->style_val = cur_styleval; X c->angle = 0.0; X c->color = cur_color; X c->depth = 0; X c->pen = NULL; X c->area_fill = NULL; X c->direction = 1; X c->center.x = (fix_x + x) / 2 + .5; X c->center.y = (fix_y + y) / 2 + .5; X rx = x - c->center.x; ry = y - c->center.y; X c->radiuses.x = c->radiuses.y = round(sqrt((double)(rx*rx + ry*ry))); X c->start.x = fix_x; X c->start.y = fix_y; X c->end.x = x; X c->end.y = y; X c->next = NULL; X pw_batch_on(canvas_pixwin); X draw_ellipse(c, DRAW); X pw_batch_off(canvas_pixwin); X clean_up(); X set_action_object(F_CREATE, O_ELLIPSE); X insert_ellipse(&objects.ellipses, c); X set_latestellipse(c); X set_modifiedflag(); X circlebydiameter_drawing_selected(); X } X Xdraw_ellipse(e, op) XF_ellipse *e; Xint op; X{ X int a, b; X X a = e->radiuses.x; X b = e->radiuses.y; X curve(a, 0, a, 0, e->direction, (b*b), (a*a), e->center.x, X e->center.y, op); X } END_OF_ellipse.c if test 9624 -ne `wc -c <ellipse.c`; then echo shar: \"ellipse.c\" unpacked with wrong size! fi # end of overwriting check fi if test -f glue.c -a "${1}" != "-c" ; then echo shar: Will not over-write existing file \"glue.c\" else echo shar: Extracting \"glue.c\" \(9601 characters\) sed "s/^X//" >glue.c <<'END_OF_glue.c' X/* X * FIG : Facility for Interactive Generation of figures X * X * Copyright (c) 1985 by Supoj Sutanthavibul (supoj@sally.UTEXAS.EDU) X * January 1985. X * 1st revision : Aug 1985. X * X * %W% %G% X*/ X#include "fig.h" X#include "resources.h" X#include "alloc.h" X#include "func.h" X#include "object.h" X#include "paintop.h" X X#define TOLERANCE 7 X#define min(a, b) (((a) < (b)) ? (a) : (b)) X#define max(a, b) (((a) > (b)) ? (a) : (b)) X Xextern F_pos last_position, new_position; /* undo.c */ Xextern int fix_x, fix_y, cur_x, cur_y; X Xextern (*canvas_kbd_proc)(); Xextern (*canvas_locmove_proc)(); Xextern (*canvas_leftbut_proc)(); Xextern (*canvas_middlebut_proc)(); Xextern (*canvas_rightbut_proc)(); Xextern null_proc(); Xextern set_popupmenu(); X Xextern F_compound objects; Xextern int compoundbox_shown; Xextern int pointmarker_shown; Xextern int foreground_color, background_color; X X create_compound(); XF_compound *compound_point_search(); X X init_create_compound(); X Xcompound_selected() X{ X canvas_kbd_proc = null_proc; X canvas_locmove_proc = null_proc; X canvas_leftbut_proc = init_create_compound; X canvas_middlebut_proc = null_proc; X canvas_rightbut_proc = set_popupmenu; X set_cursor(&arrow_cursor); X reset_action_on(); X } X Xinit_create_compound(x, y) Xint x, y; X{ X init_box_drawing(x, y); X canvas_middlebut_proc = create_compound; X canvas_leftbut_proc = canvas_rightbut_proc = null_proc; X } X Xcreate_compound(x, y) Xint x, y; X{ X F_compound *c; X X if (NULL == (Compound_malloc(c))) { X put_msg(Err_mem); X return; X } X draw_rectbox(fix_x, fix_y, cur_x, cur_y, INV_PAINT); X c->nwcorner.x = min(fix_x, x); X c->nwcorner.y = min(fix_y, y); X c->secorner.x = max(fix_x, x); X c->secorner.y = max(fix_y, y); X if (compose_compound(c) == 0) { X free((char*)c); X compound_selected(); X put_msg("Empty compound, ignore"); X return; X } X draw_compoundbox(c, INV_PAINT); X c->next = NULL; X clean_up(); X set_action(F_GLUE); X insert_compound(&objects.compounds, c); X set_latestcompound(c); X compound_selected(); X } X Xcompose_compound(c) XF_compound *c; X{ X c->ellipses = NULL; X c->lines = NULL; X c->texts = NULL; X c->splines = NULL; X c->arcs = NULL; X c->compounds = NULL; X get_ellipse(&c->ellipses, c->nwcorner.x, c->nwcorner.y, X c->secorner.x, c->secorner.y); X get_lineobj(&c->lines, c->nwcorner.x, c->nwcorner.y, X c->secorner.x, c->secorner.y); X get_spline(&c->splines, c->nwcorner.x, c->nwcorner.y, X c->secorner.x, c->secorner.y); X get_text(&c->texts, c->nwcorner.x, c->nwcorner.y, X c->secorner.x, c->secorner.y); X get_arc(&c->arcs, c->nwcorner.x, c->nwcorner.y, X c->secorner.x, c->secorner.y); X /* get rid of point-marker */ X if (pointmarker_shown) toggle_compoundpointmarker(c); X if (c->ellipses != NULL) return(1); X if (c->splines != NULL) return(1); X if (c->lines != NULL) return(1); X if (c->texts != NULL) return(1); X if (c->arcs != NULL) return(1); X return(0); X } X Xdraw_compoundbox(c, op) XF_compound *c; Xint op; X{ X draw_rectbox( c->nwcorner.x-1, c->nwcorner.y-1, X c->secorner.x+1, c->secorner.y+1, op); X draw_rectbox( c->nwcorner.x, c->nwcorner.y, X c->secorner.x, c->secorner.y, op); X draw_rectbox( c->nwcorner.x+1, c->nwcorner.y+1, X c->secorner.x-1, c->secorner.y-1, op); X } X Xget_ellipse(list, xmin, ymin, xmax, ymax) XF_ellipse **list; Xint xmin, ymin, xmax, ymax; X{ X F_ellipse *e, *ee, *ellipse; X X for (e = objects.ellipses; e != NULL;) { X if (xmin > e->center.x - e->radiuses.x) { X ee = e; e = e->next; continue; X } X if (xmax < e->center.x + e->radiuses.x) { X ee = e; e = e->next; continue; X } X if (ymin > e->center.y - e->radiuses.y) { X ee = e; e = e->next; continue; X } X if (ymax < e->center.y + e->radiuses.y) { X ee = e; e = e->next; continue; X } X ellipse = e; X if (e == objects.ellipses) X e = objects.ellipses = objects.ellipses->next; X else { X e = ee->next = e->next; X } X ellipse->next = *list; X *list = ellipse; X } X } X Xget_arc(list, xmin, ymin, xmax, ymax) XF_arc **list; Xint xmin, ymin, xmax, ymax; X{ X F_arc *a, *arc, *aa; X int urx, ury, llx, lly; X X for (a = objects.arcs; a != NULL;) { X arc_bound(a, &llx, &lly, &urx, &ury); X if (xmin > llx) goto out; X if (xmax < urx) goto out; X if (ymin > lly) goto out; X if (ymax < ury) goto out; X arc = a; X if (a == objects.arcs) X a = objects.arcs = objects.arcs->next; X else X a = aa->next = a->next; X arc->next = *list; X *list = arc; X continue; X out: X aa = a; a = a->next; X } X } X Xget_lineobj(list, xmin, ymin, xmax, ymax) XF_line **list; Xint xmin, ymin, xmax, ymax; X{ X F_line *line, *l, *ll; X F_point *p; X int inbound; X X for (l = objects.lines; l != NULL;) { X for (inbound = 1, p = l->points; p!= NULL && inbound; X p = p->next) { X inbound = 0; X if (xmin > p->x) continue; X if (xmax < p->x) continue; X if (ymin > p->y) continue; X if (ymax < p->y) continue; X inbound = 1; X } X if (! inbound) { X ll = l; l = l->next; continue; X } X line = l; X if (l == objects.lines) X l = objects.lines = objects.lines->next; X else X l = ll->next = l->next; X line->next = *list; X *list = line; X } X } X Xget_spline(list, xmin, ymin, xmax, ymax) XF_spline **list; Xint xmin, ymin, xmax, ymax; X{ X F_spline *spline, *s, *ss; X int urx, ury, llx, lly; X X for (s = objects.splines; s != NULL;) { X spline_bound(s, &llx, &lly, &urx, &ury); X if (xmin > llx) goto out; X if (xmax < urx) goto out; X if (ymin > lly) goto out; X if (ymax < ury) goto out; X spline = s; X if (s == objects.splines) X s = objects.splines = objects.splines->next; X else X s = ss->next = s->next; X spline->next = *list; X *list = spline; X continue; X out: X ss = s; s = s->next; X } X } X Xget_text(list, xmin, ymin, xmax, ymax) XF_text **list; Xint xmin, ymin, xmax, ymax; X{ X F_text *text, *t, *tt; X for (t = objects.texts; t != NULL;) { X if (xmin > t->base_x) { X tt = t; t = t->next; continue; X } X if (xmax < t->base_x + t->length) { X tt = t; t = t->next; continue; X } X if (ymin > t->base_y - t->height) { X tt = t; t = t->next; continue; X } X if (ymax < t->base_y) { X tt = t; t = t->next; continue; X } X text = t; X if (t == objects.texts) X t = objects.texts = objects.texts->next; X else X t = tt->next = t->next; X text->next = *list; X *list = text; X } X } X XF_compound * Xcompound_point_search(x, y, tol, px, py) Xint x, y, tol, *px, *py; X{ X F_compound *c; X X for (c = objects.compounds; c != NULL; c = c->next) { X if (abs(c->nwcorner.x - x) <= tol && X abs(c->nwcorner.y - y) <= tol) { X *px = c->nwcorner.x; X *py = c->nwcorner.y; X return(c); X } X if (abs(c->nwcorner.x - x) <= tol && X abs(c->secorner.y - y) <= tol) { X *px = c->nwcorner.x; X *py = c->secorner.y; X return(c); X } X if (abs(c->secorner.x - x) <= tol && X abs(c->nwcorner.y - y) <= tol) { X *px = c->secorner.x; X *py = c->nwcorner.y; X return(c); X } X if (abs(c->secorner.x - x) <= tol && X abs(c->secorner.y - y) <= tol) { X *px = c->secorner.x; X *py = c->secorner.y; X return(c); X } X } X return(NULL); X } X Xdraw_compound(c) XF_compound *c; X{ X draw_compoundelements(c, foreground_color, foreground_color, X PAINT, PAINT, PAINT); X } X Xerase_compound(c) XF_compound *c; X{ X draw_compoundelements(c, background_color, background_color, X ERASE, ERASE, INV_PAINT); X } X Xdraw_compoundelements(c, arcop, ellipseop, lineop, splineop, textop) XF_compound *c; Xint arcop, ellipseop, lineop, splineop, textop; X{ X F_line *l; X F_spline *s; X F_ellipse *e; X F_text *t; X F_arc *a; X X pw_batch_on(canvas_pixwin); X for (l = c->lines; l != NULL; l = l->next) { X draw_line(l, lineop); X } X for (s = c->splines; s != NULL; s = s->next) { X draw_spline(s, splineop); X } X for (a = c->arcs; a != NULL; a = a->next) { X draw_arc(a, arcop); X } X for (e = c->ellipses; e != NULL; e = e->next) { X draw_ellipse(e, ellipseop); X } X for (t = c->texts; t != NULL; t = t->next) { X draw_text(t, textop); X } X pw_batch_off(canvas_pixwin); X } X XF_compound * Xcompound_search(x, y, tolerance, px, py) Xint x, y, tolerance, *px, *py; X{ X F_compound *c; X float tol2; X X tol2 = tolerance * tolerance; X X for (c = objects.compounds; c != NULL; c = c->next) { X if (close_to_vector(c->nwcorner.x, c->nwcorner.y, c->nwcorner.x, X c->secorner.y, x, y, tolerance, tol2, px, py)) X return(c); X if (close_to_vector(c->secorner.x, c->secorner.y, c->nwcorner.x, X c->secorner.y, x, y, tolerance, tol2, px, py)) X return(c); X if (close_to_vector(c->secorner.x, c->secorner.y, c->secorner.x, X c->nwcorner.y, x, y, tolerance, tol2, px, py)) X return(c); X if (close_to_vector(c->nwcorner.x, c->nwcorner.y, c->secorner.x, X c->nwcorner.y, x, y, tolerance, tol2, px, py)) X return(c); X } X return(NULL); X } X Xtoggle_compoundpointmarker(c) XF_compound *c; X{ X F_line *l; X F_spline *s; X F_ellipse *e; X F_arc *a; X X for (l = c->lines; l != NULL; l = l->next) { X toggle_linepointmarker(l); X } X for (s = c->splines; s != NULL; s = s->next) { X toggle_splinepointmarker(s); X } X for (a = c->arcs; a != NULL; a = a->next) { X toggle_arcpointmarker(a); X } X for (e = c->ellipses; e != NULL; e = e->next) { X toggle_ellipsepointmarker(e); X } X } X Xshow_compoundbox() X{ X F_compound *c; X X if (compoundbox_shown) return; X compoundbox_shown = 1; X for (c = objects.compounds; c != NULL; c = c->next) X draw_compoundbox(c, INV_PAINT); X } X Xerase_compoundbox() X{ X F_compound *c; X X if (! compoundbox_shown) return; X compoundbox_shown = 0; X for (c = objects.compounds; c != NULL; c = c->next) X draw_compoundbox(c, INV_PAINT); X } END_OF_glue.c if test 9601 -ne `wc -c <glue.c`; then echo shar: \"glue.c\" unpacked with wrong size! fi # end of overwriting check fi if test -f read1_3.c -a "${1}" != "-c" ; then echo shar: Will not over-write existing file \"read1_3.c\" else echo shar: Extracting \"read1_3.c\" \(9960 characters\) sed "s/^X//" >read1_3.c <<'END_OF_read1_3.c' X/* X * FIG : Facility for Interactive Generation of figures X * X * Copyright (c) 1985, 1988 by Supoj Sutanthavibul (supoj@sally.UTEXAS.EDU) X * January 1985. X * 1st revision : March 1988. X * X * %W% %G% X*/ X X/*******************************************************************/ X/*************** Read version 1.3 format ***************/ X/*******************************************************************/ X#include "fig.h" X#include "alloc.h" X#include "object.h" X X/******* Fig 1.3 subtype of objects *******/ X#define DRAW_ELLIPSE_BY_RAD 1 X#define DRAW_ELLIPSE_BY_DIA 2 X#define DRAW_CIRCLE_BY_RAD 3 X#define DRAW_CIRCLE_BY_DIA 4 X#define DRAW_CIRCULAR_ARC 5 X#define DRAW_POLYLINE 6 X#define DRAW_BOX 7 X#define DRAW_POLYGON 8 X#define DRAW_TEXT 9 X#define DRAW_SPLINE 10 X#define DRAW_CLOSEDSPLINE 11 X#define DRAW_COMPOUND 13 X Xextern F_arrow *forward_arrow(), *backward_arrow(); Xextern int figure_modified; Xextern int errno; Xextern char *sys_errlist[]; Xextern int sys_nerr, errno; X Xstatic F_ellipse *read_ellipseobject(); Xstatic F_line *read_lineobject(); Xstatic F_text *read_textobject(); Xstatic F_spline *read_splineobject(); Xstatic F_arc *read_arcobject(); Xstatic F_compound *read_compoundobject(); X Xextern int line_no; Xextern int num_object; X Xint Xread_1_3_objects(fp, obj) XFILE *fp; XF_compound *obj; X{ X F_ellipse *e, *le = NULL; X F_line *l, *ll = NULL; X F_text *t, *lt = NULL; X F_spline *s, *ls = NULL; X F_arc *a, *la = NULL; X F_compound *c, *lc = NULL; X int n; X int object, pixperinch, canvaswid, canvasht, coord_sys; X X n = fscanf(fp,"%d%d%d%d\n", &pixperinch, &coord_sys, &canvaswid, &canvasht); X if (n != 4) { X put_msg("Incorrect format in the first line in input file"); X return(-1); X } X obj->nwcorner.x = pixperinch; X obj->nwcorner.y = coord_sys; X while (fscanf(fp, "%d", &object) == 1) { X switch (object) { X case O_POLYLINE : X if ((l = read_lineobject(fp)) == NULL) return(-1); X if (ll) X ll = (ll->next = l); X else X ll = obj->lines = l; X num_object++; X break; X case O_SPLINE : X if ((s = read_splineobject(fp)) == NULL) return(-1); X if (ls) X ls = (ls->next = s); X else X ls = obj->splines = s; X num_object++; X break; X case O_ELLIPSE : X if ((e = read_ellipseobject(fp)) == NULL) return(-1); X if (le) X le = (le->next = e); X else X le = obj->ellipses = e; X num_object++; X break; X case O_ARC : X if ((a = read_arcobject(fp)) == NULL) return(-1); X if (la) X la = (la->next = a); X else X la = obj->arcs = a; X num_object++; X break; X case O_TEXT : X if ((t = read_textobject(fp)) == NULL) return(-1); X if (lt) X lt = (lt->next = t); X else X lt = obj->texts = t; X num_object++; X break; X case O_COMPOUND : X if ((c = read_compoundobject(fp)) == NULL) return(-1); X if (lc) X lc = (lc->next = c); X else X lc = obj->compounds = c; X num_object++; X break; X default: X put_msg("Incorrect object code %d", object); X return(-1); X } /* switch */ X } /* while */ X if (feof(fp)) X return(0); X else X return(errno); X } X Xstatic F_arc * Xread_arcobject(fp) XFILE *fp; X{ X F_arc *a; X int f, b, h, w, n; X X Arc_malloc(a); X a->type = T_3_POINTS_ARC; X a->color = BLACK; X a->depth = 0; X a->pen = NULL; X a->for_arrow = NULL; X a->back_arrow = NULL; X a->next = NULL; X n = fscanf(fp, " %d %d %d %f %d %d %d %d %d %f %f %d %d %d %d %d %d\n", X &a->type, &a->style, &a->thickness, X &a->style_val, &a->direction, &f, &b, X &h, &w, &a->center.x, &a->center.y, X &a->point[0].x, &a->point[0].y, X &a->point[1].x, &a->point[1].y, X &a->point[2].x, &a->point[2].y); X if (n != 17) { X put_msg("incomplete arc data"); X free((char*)a); X return(NULL); X } X if (f) { X a->for_arrow = forward_arrow(); X a->for_arrow->wid = w; X a->for_arrow->ht = h; X } X if (b) { X a->back_arrow = backward_arrow(); X a->back_arrow->wid = w; X a->back_arrow->ht = h; X } X return(a); X } X Xstatic F_compound * Xread_compoundobject(fp) XFILE *fp; X{ X F_arc *a, *la = NULL; X F_ellipse *e, *le = NULL; X F_line *l, *ll = NULL; X F_spline *s, *ls = NULL; X F_text *t, *lt = NULL; X F_compound *com, *c, *lc = NULL; X int n, object; X X Compound_malloc(com); X com->arcs = NULL; X com->ellipses = NULL; X com->lines = NULL; X com->splines = NULL; X com->texts = NULL; X com->compounds = NULL; X com->next = NULL; X n = fscanf(fp, " %d %d %d %d\n", &com->nwcorner.x, &com->nwcorner.y, X &com->secorner.x, &com->secorner.y); X if (n != 4) { X put_msg("Incorrect compound object format"); X return(NULL); X } X while (fscanf(fp, "%d", &object) == 1) { X switch (object) { X case O_POLYLINE : X if ((l = read_lineobject(fp)) == NULL) { X free_line(&l); X return(NULL); X } X if (ll) X ll = (ll->next = l); X else X ll = com->lines = l; X break; X case O_SPLINE : X if ((s = read_splineobject(fp)) == NULL) { X free_spline(&s); X return(NULL); X } X if (ls) X ls = (ls->next = s); X else X ls = com->splines = s; X break; X case O_ELLIPSE : X if ((e = read_ellipseobject(fp)) == NULL) { X free_ellipse(&e); X return(NULL); X } X if (le) X le = (le->next = e); X else X le = com->ellipses = e; X break; X case O_ARC : X if ((a = read_arcobject(fp)) == NULL) { X free_arc(&a); X return(NULL); X } X if (la) X la = (la->next = a); X else X la = com->arcs = a; X break; X case O_TEXT : X if ((t = read_textobject(fp)) == NULL) { X free_text(&t); X return(NULL); X } X if (lt) X lt = (lt->next = t); X else X lt = com->texts = t; X break; X case O_COMPOUND : X if ((c = read_compoundobject(fp)) == NULL) { X free_compound(&c); X return(NULL); X } X if (lc) X lc = (lc->next = c); X else X lc = com->compounds = c; X break; X case O_END_COMPOUND : X return(com); X } /* switch */ X } X if (feof(fp)) X return(com); X else { X put_msg("Format error: %s", sys_errlist[errno]); X return(NULL); X } X } X Xstatic F_ellipse * Xread_ellipseobject(fp) XFILE *fp; X{ X F_ellipse *e; X int n, t; X X Ellipse_malloc(e); X e->color = BLACK; X e->angle = 0.0; X e->depth = 0; X e->pen = NULL; X e->area_fill = NULL; X e->next = NULL; X n = fscanf(fp," %d %d %d %f %d %d %d %d %d %d %d %d %d\n", X &t, &e->style, X &e->thickness, &e->style_val, &e->direction, X &e->center.x, &e->center.y, X &e->radiuses.x, &e->radiuses.y, X &e->start.x, &e->start.y, X &e->end.x, &e->end.y); X if (n != 13) { X put_msg("incomplete ellipse data"); X free((char*)e); X return(NULL); X } X if (t == DRAW_ELLIPSE_BY_RAD) X e->type = T_ELLIPSE_BY_RAD; X else if (t == DRAW_ELLIPSE_BY_DIA) X e->type = T_ELLIPSE_BY_DIA; X else if (t == DRAW_CIRCLE_BY_RAD) X e->type = T_CIRCLE_BY_RAD; X else X e->type = T_CIRCLE_BY_DIA; X return(e); X } X Xstatic F_line * Xread_lineobject(fp) XFILE *fp; X{ X F_line *l; X F_point *p, *q; X int f, b, h, w, n, t, x, y; X X Line_malloc(l); X l->color = BLACK; X l->depth = 0; X l->pen = NULL; X l->area_fill = NULL; X l->for_arrow = NULL; X l->back_arrow = NULL; X l->next = NULL; X l->points = Point_malloc(p); X n = fscanf(fp, " %d %d %d %f %d %d %d %d %d %d", &t, X &l->style, &l->thickness, &l->style_val, X &f, &b, &h, &w, &p->x, &p->y); X if (n != 10) { X put_msg("incomplete line data"); X free((char*)l); X return(NULL); X } X if (t == DRAW_POLYLINE) X l->type = T_POLYLINE; X else if (t == DRAW_POLYGON) X l->type = T_POLYGON; X else X l->type = T_BOX; X if (f) { X l->for_arrow = forward_arrow(); X l->for_arrow->wid = w; X l->for_arrow->ht = h; X } X if (b) { X l->back_arrow = backward_arrow(); X l->back_arrow->wid = w; X l->back_arrow->ht = h; X } X for (;;) { X if (fscanf(fp, " %d %d", &x, &y) != 2) { X put_msg("incomplete line object"); X free_linestorage(l); X return(NULL); X } X if (x == 9999) break; X Point_malloc(q); X q->x = x; X q->y = y; X q->next = NULL; X p->next = q; X p = q; X } X return(l); X } X Xstatic F_spline * Xread_splineobject(fp) XFILE *fp; X{ X F_spline *s; X F_point *p, *q; X int f, b, h, w, n, t, x, y; X X Spline_malloc(s); X s->color = BLACK; X s->depth = 0; X s->pen = NULL; X s->area_fill = NULL; X s->for_arrow = NULL; X s->back_arrow = NULL; X s->controls = NULL; X s->next = NULL; X s->points = Point_malloc(p); X n = fscanf(fp, " %d %d %d %f %d %d %d %d %d %d", X &t, &s->style, &s->thickness, &s->style_val, X &f, &b, X &h, &w, &p->x, &p->y); X if (n != 10) { X put_msg("incomplete spline data"); X free((char*)s); X return(NULL); X } X if (t == DRAW_CLOSEDSPLINE) X s->type = T_CLOSED_NORMAL; X else X s->type = T_OPEN_NORMAL; X if (f) { X s->for_arrow = forward_arrow(); X s->for_arrow->wid = w; X s->for_arrow->ht = h; X } X if (b) { X s->back_arrow = backward_arrow(); X s->back_arrow->wid = w; X s->back_arrow->ht = h; X } X for (;;) { X if (fscanf(fp, " %d %d", &x, &y) != 2) { X put_msg("incomplete spline object"); X free_splinestorage(s); X return(NULL); X }; X if (x == 9999) break; X Point_malloc(q); X q->x = x; X q->y = y; X q->next = NULL; X p->next = q; X p = q; X } X return(s); X } X Xstatic F_text * Xread_textobject(fp) XFILE *fp; X{ X F_text *t; X int n; X char buf[128]; X X Text_malloc(t); X t->type = T_LEFT_JUSTIFIED; X t->style = PLAIN; X t->color = BLACK; X t->depth = 0; X t->pen = NULL; X t->angle = 0.0; X t->next = NULL; X n = fscanf(fp," %d %d %d %d %d %d %d %[^\n]", &t->font, X &t->size, &t->style, &t->height, &t->length, X &t->base_x, &t->base_y, buf); X if (n != 8) { X put_msg("incomplete text data"); X free((char*)t); X return(NULL); X } X t->cstring = (char *) calloc((unsigned)(strlen(buf)+1), sizeof(char)); X if (t->cstring == NULL) { X put_msg(Err_mem); X free((char*) t); X return(NULL); X } X strcpy(t->cstring, buf); X if (t->size == 0) t->size == 18; X return(t); X } END_OF_read1_3.c if test 9960 -ne `wc -c <read1_3.c`; then echo shar: \"read1_3.c\" unpacked with wrong size! fi # end of overwriting check fi if test -f rotate.c -a "${1}" != "-c" ; then echo shar: Will not over-write existing file \"rotate.c\" else echo shar: Extracting \"rotate.c\" \(10970 characters\) sed "s/^X//" >rotate.c <<'END_OF_rotate.c' X/* X * FIG : Facility for Interactive Generation of figures X * X * Copyright (c) 1985 by Supoj Sutanthavibul (supoj@sally.UTEXAS.EDU) X * January 1985. X * 1st revision : Aug 1985. X * X * %W% %G% X*/ X#include "fig.h" X#include "resources.h" X#include "func.h" X#include "object.h" X#include "paintop.h" X X#define TOLERANCE 7 X Xextern (*canvas_kbd_proc)(); Xextern (*canvas_locmove_proc)(); Xextern (*canvas_leftbut_proc)(); Xextern (*canvas_middlebut_proc)(); Xextern (*canvas_rightbut_proc)(); Xextern null_proc(); Xextern set_popupmenu(); X Xextern F_line *line_search(), *copy_line(); Xextern F_ellipse *ellipse_search(), *copy_ellipse(); Xextern F_ellipse *ellipse_point_search(); Xextern F_spline *spline_search(), *copy_spline(); Xextern F_arc *arc_point_search(), *copy_arc(); Xextern F_compound *compound_search(), *copy_compound(); X Xextern F_compound objects; X Xextern int rotate_angle; Xextern int pointmarker_shown; Xextern int foreground_color, background_color; X Xstatic int copy; X init_rotate(); X init_copynrotate(); X Xrotate_selected() X{ X canvas_kbd_proc = null_proc; X canvas_locmove_proc = null_proc; X canvas_leftbut_proc = init_copynrotate; X canvas_middlebut_proc = init_rotate; X canvas_rightbut_proc = set_popupmenu; X set_cursor(&pick15_cursor); X } X Xinit_rotate(x, y) Xint x, y; X{ X copy = 0; X rotate_search(x, y); X } X Xinit_copynrotate(x, y) Xint x, y; X{ X copy = 1; X rotate_search(x, y); X } X Xrotate_search(x, y) Xint x, y; X{ X F_line *l; X F_arc *a; X F_ellipse *e; X F_spline *s; X F_compound *c; X int px, py; X X if ((l = line_search(x, y, TOLERANCE, &px, &py)) != NULL) { X init_rotateline(l, px, py); X } X else if ((e = ellipse_point_search(x, y, TOLERANCE, &px)) != NULL) { X if (px == 0) X init_rotateellipse(e, e->start.x, e->start.y); X else X init_rotateellipse(e, e->end.x, e->end.y); X } X else if ((e = ellipse_search(x, y, TOLERANCE, &px, &py)) != NULL) { X init_rotateellipse(e, x, y); X } X else if ((a = arc_point_search(x, y, TOLERANCE, &px)) != NULL) { X init_rotatearc(a, a->point[px].x, a->point[px].y); X } X else if ((s = spline_search(x, y, TOLERANCE, &px, &py)) != NULL) { X init_rotatespline(s, px, py); X } X else if ((c = compound_search(x, y, TOLERANCE, &px, &py)) != NULL) { X init_rotatecompound(c, px, py); X } X else { X return; X } X set_modifiedflag(); X } X Xinit_rotateline(l, px, py) XF_line *l; Xint px, py; X{ X F_line *line; X X win_setmouseposition(canvas_swfd, px, py); X if (pointmarker_shown) toggle_linepointmarker(l); X if (copy) { X line = copy_line(l); X rotate_line(line, px, py, rotate_angle); X insert_line(&objects.lines, line); X clean_up(); X set_action_object(F_CREATE, O_POLYLINE); X draw_line(line, PAINT); X } X else { X draw_line(l, ERASE); X rotate_line(l, px, py, rotate_angle); X clean_up(); X set_action_object(F_ROTATE, O_POLYLINE); X set_lastangle(rotate_angle); X set_lastposition(px, py); X draw_line(l, PAINT); X line = l; X } X if (pointmarker_shown) { X if (copy) toggle_linepointmarker(line); X toggle_linepointmarker(l); X } X set_latestline(line); X } X Xinit_rotateellipse(e, px, py) XF_ellipse *e; Xint px, py; X{ X F_ellipse *ellipse; X X win_setmouseposition(canvas_swfd, px, py); X if (pointmarker_shown) toggle_ellipsepointmarker(e); X if (copy) { X ellipse = copy_ellipse(e); X rotate_ellipse(ellipse, px, py, rotate_angle); X insert_ellipse(&objects.ellipses, ellipse); X clean_up(); X set_action_object(F_CREATE, O_ELLIPSE); X draw_ellipse(ellipse, PAINT); X } X else { X draw_ellipse(e, background_color); X rotate_ellipse(e, px, py, rotate_angle); X clean_up(); X set_action_object(F_ROTATE, O_ELLIPSE); X set_lastangle(rotate_angle); X set_lastposition(px, py); X draw_ellipse(e, foreground_color); X ellipse = e; X } X if (pointmarker_shown) { X if (copy) toggle_ellipsepointmarker(ellipse); X toggle_ellipsepointmarker(e); X } X set_latestellipse(ellipse); X } X Xinit_rotatearc(a, px, py) XF_arc *a; Xint px, py; X{ X F_arc *arc; X X win_setmouseposition(canvas_swfd, px, py); X if (pointmarker_shown) toggle_arcpointmarker(a); X if (copy) { X arc = copy_arc(a); X rotate_arc(arc, px, py, rotate_angle); X insert_arc(&objects.arcs, arc); X clean_up(); X set_action_object(F_CREATE, O_ARC); X draw_arc(arc, foreground_color); X } X else { X draw_arc(a, background_color); X rotate_arc(a, px, py, rotate_angle); X clean_up(); X set_action_object(F_ROTATE, O_ARC); X set_lastangle(rotate_angle); X set_lastposition(px, py); X draw_arc(a, foreground_color); X arc = a; X } X if (pointmarker_shown) { X if (copy) toggle_arcpointmarker(arc); X toggle_arcpointmarker(a); X } X set_latestarc(arc); X } X Xinit_rotatespline(s, px, py) XF_spline *s; Xint px, py; X{ X F_spline *spline; X X win_setmouseposition(canvas_swfd, px, py); X if (pointmarker_shown) toggle_splinepointmarker(s); X if (copy) { X spline = copy_spline(s); X rotate_spline(spline, px, py, rotate_angle); X insert_spline(&objects.splines, spline); X clean_up(); X set_action_object(F_CREATE, O_SPLINE); X draw_spline(spline, PAINT); X } X else { X draw_spline(s, ERASE); X rotate_spline(s, px, py, rotate_angle); X clean_up(); X set_action_object(F_ROTATE, O_SPLINE); X set_lastangle(rotate_angle); X set_lastposition(px, py); X draw_spline(s, PAINT); X spline = s; X } X if (pointmarker_shown) { X if (copy) toggle_splinepointmarker(spline); X toggle_splinepointmarker(s); X } X set_latestspline(spline); X } X Xinit_rotatecompound(c, px, py) XF_compound *c; Xint px, py; X{ X F_compound *compound; X X win_setmouseposition(canvas_swfd, px, py); X set_temp_cursor(&wait_cursor); X if (copy) { X compound = copy_compound(c); X rotate_compound(compound, px, py, rotate_angle); X insert_compound(&objects.compounds, compound); X clean_up(); X set_action_object(F_CREATE, O_COMPOUND); X draw_compound(compound); X draw_compoundbox(compound, INV_PAINT); X } X else { X draw_compoundbox(c, INV_PAINT); X erase_compound(c); X rotate_compound(c, px, py, rotate_angle); X clean_up(); X set_action_object(F_ROTATE, O_COMPOUND); X set_lastangle(rotate_angle); X set_lastposition(px, py); X draw_compound(c); X draw_compoundbox(c, INV_PAINT); X compound = c; X } X set_latestcompound(compound); X set_temp_cursor(cur_cursor); X } X Xrotate_line(l, x, y, rotate_angle) XF_line *l; Xint x, y, rotate_angle; X{ X F_point *p; X int dx; X X switch(rotate_angle) { X case 270 : X for (p = l->points; p != NULL; p = p->next) { X dx = p->x - x; X p->x = x + (y - p->y); X p->y = y + dx; X } X break; X case 90 : X for (p = l->points; p != NULL; p = p->next) { X dx = p->x - x; X p->x = x - (y - p->y); X p->y = y - dx; X } X break; X } X } X Xrotate_spline(s, x, y, rotate_angle) XF_spline *s; Xint x, y, rotate_angle; X{ X F_point *p; X F_control *cp; X int dx; X X switch(rotate_angle) { X case 270 : X for (p = s->points; p != NULL; p = p->next) { X dx = p->x - x; X p->x = x + (y - p->y); X p->y = y + dx; X } X for (cp = s->controls; cp != NULL; cp = cp->next) { X dx = cp->lx - x; X cp->lx = x + (y - cp->ly); X cp->ly = y + dx; X dx = cp->rx - x; X cp->rx = x + (y - cp->ry); X cp->ry = y + dx; X } X break; X case 90 : X for (p = s->points; p != NULL; p = p->next) { X dx = p->x - x; X p->x = x - (y - p->y); X p->y = y - dx; X } X for (cp = s->controls; cp != NULL; cp = cp->next) { X dx = cp->lx - x; X cp->lx = x - (y - cp->ly); X cp->ly = y - dx; X dx = cp->rx - x; X cp->rx = x - (y - cp->ry); X cp->ry = y - dx; X } X break; X } X } X Xrotate_text(t, x, y, rotate_angle) XF_text *t; Xint x, y, rotate_angle; X{ X int dx; X X switch(rotate_angle) { X case 270 : X dx = t->base_x - x; X t->base_x = x - (t->base_y - y); X t->base_y = y + dx; X break; X case 90 : X dx = t->base_x - x; X t->base_x = x + (t->base_y - y); X t->base_y = y - dx; X break; X } X } X Xrotate_ellipse(e, x, y, rotate_angle) XF_ellipse *e; Xint x, y, rotate_angle; X{ X int dx; X X switch(rotate_angle) { X case 270 : X dx = e->center.x - x; X e->center.x = x - (e->center.y - y); X e->center.y = y + dx; X dx = e->radiuses.x; X e->radiuses.x = e->radiuses.y; X e->radiuses.y = dx; X dx = e->start.x - x; X e->start.x = x - (e->start.y - y); X e->start.y = y + dx; X dx = e->end.x - x; X e->end.x = x - (e->end.y - y); X e->end.y = y + dx; X break; X case 90 : X dx = e->center.x - x; X e->center.x = x + (e->center.y - y); X e->center.y = y - dx; X dx = e->radiuses.x; X e->radiuses.x = e->radiuses.y; X e->radiuses.y = dx; X dx = e->start.x - x; X e->start.x = x + (e->start.y - y); X e->start.y = y - dx; X dx = e->end.x - x; X e->end.x = x + (e->end.y - y); X e->end.y = y - dx; X break; X } X } X Xrotate_arc(a, x, y, rotate_angle) XF_arc *a; Xint x, y, rotate_angle; X{ X int dx; X X switch(rotate_angle) { X case 270 : X dx = a->center.x - x; X a->center.x = x - (a->center.y - y); X a->center.y = y + dx; X dx = a->point[0].x - x; X a->point[0].x = x - (a->point[0].y - y); X a->point[0].y = y + dx; X dx = a->point[1].x - x; X a->point[1].x = x - (a->point[1].y - y); X a->point[1].y = y + dx; X dx = a->point[2].x - x; X a->point[2].x = x - (a->point[2].y - y); X a->point[2].y = y + dx; X break; X case 90 : X dx = a->center.x - x; X a->center.x = x + (a->center.y - y); X a->center.y = y - dx; X dx = a->point[0].x - x; X a->point[0].x = x + (a->point[0].y - y); X a->point[0].y = y - dx; X dx = a->point[1].x - x; X a->point[1].x = x + (a->point[1].y - y); X a->point[1].y = y - dx; X dx = a->point[2].x - x; X a->point[2].x = x + (a->point[2].y - y); X a->point[2].y = y - dx; X break; X } X } X X#define min(a, b) (((a) < (b)) ? (a) : (b)) X#define max(a, b) (((a) > (b)) ? (a) : (b)) X Xrotate_compound(c, x, y, rotate_angle) XF_compound *c; Xint x, y, rotate_angle; X{ X F_line *l; X F_arc *a; X F_ellipse *e; X F_spline *s; X F_text *t; X int x1, y1, x2, y2; X X switch(rotate_angle) { X case 270 : X x1 = x - (c->nwcorner.y - y); X y1 = y + (c->nwcorner.x - x); X x2 = x - (c->secorner.y - y); X y2 = y + (c->secorner.x - x); X break; X case 90 : X x1 = x + (c->nwcorner.y - y); X y1 = y - (c->nwcorner.x - x); X x2 = x + (c->secorner.y - y); X y2 = y - (c->secorner.x - x); X break; X } X c->nwcorner.x = min(x1, x2); X c->nwcorner.y = min(y1, y2); X c->secorner.x = max(x1, x2); X c->secorner.y = max(y1, y2); X for (l = c->lines; l != NULL; l = l->next) X rotate_line(l, x, y, rotate_angle); X for (a = c->arcs; a != NULL; a = a->next) X rotate_arc(a, x, y, rotate_angle); X for (e = c->ellipses; e != NULL; e = e->next) X rotate_ellipse(e, x, y, rotate_angle); X for (s = c->splines; s != NULL; s = s->next) X rotate_spline(s, x, y, rotate_angle); X for (t = c->texts; t != NULL; t = t->next) X rotate_text(t, x, y, rotate_angle); X } END_OF_rotate.c if test 10970 -ne `wc -c <rotate.c`; then echo shar: \"rotate.c\" unpacked with wrong size! fi # end of overwriting check fi echo shar: End of archive 6 \(of 11\). cp /dev/null ark6isdone MISSING="" for I in 1 2 3 4 5 6 7 8 9 10 11 ; do if test ! -f ark${I}isdone ; then MISSING="${MISSING} ${I}" fi done if test "${MISSING}" = "" ; then echo You have unpacked all 11 archives. rm -f ark[1-9]isdone ark[1-9][0-9]isdone else echo You still need to unpack the following archives: echo " " ${MISSING} fi ## End of shell archive. exit 0 -- Mike Wexler(wyse!mikew) Phone: (408)433-1000 x1330