home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / x / volume19 / xfig / part03 / e_convert.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-05-27  |  4.1 KB  |  162 lines

  1. /*
  2.  * FIG : Facility for Interactive Generation of figures
  3.  * Copyright (c) 1985 by Supoj Sutanthavibul
  4.  *
  5.  * "Permission to use, copy, modify, distribute, and sell this software and its
  6.  * documentation for any purpose is hereby granted without fee, provided that
  7.  * the above copyright notice appear in all copies and that both the copyright
  8.  * notice and this permission notice appear in supporting documentation. 
  9.  * No representations are made about the suitability of this software for 
  10.  * any purpose.  It is provided "as is" without express or implied warranty."
  11.  */
  12.  
  13. #include "fig.h"
  14. #include "resources.h"
  15. #include "mode.h"
  16. #include "object.h"
  17. #include "paintop.h"
  18. #include "u_create.h"
  19. #include "u_list.h"
  20. #include "u_search.h"
  21. #include "w_canvas.h"
  22. #include "w_mousefun.h"
  23.  
  24. static int    init_convert();
  25.  
  26. convert_selected()
  27. {
  28.     set_mousefun("spline<->line", "", "");
  29.     canvas_kbd_proc = null_proc;
  30.     canvas_locmove_proc = null_proc;
  31.     init_searchproc_left(init_convert);
  32.     canvas_leftbut_proc = object_search_left;
  33.     canvas_middlebut_proc = null_proc;
  34.     canvas_rightbut_proc = null_proc;
  35.     set_cursor(pick15_cursor);
  36. }
  37.  
  38. static
  39. init_convert(p, type, x, y, px, py)
  40.     char       *p;
  41.     int            type;
  42.     int            x, y;
  43.     int            px, py;
  44. {
  45.     switch (type) {
  46.     case O_POLYLINE:
  47.     cur_l = (F_line *) p;
  48.     /* the search routine will ensure that we don't have a box */
  49.     line_2_spline(cur_l);
  50.     break;
  51.     case O_SPLINE:
  52.     cur_s = (F_spline *) p;
  53.     /* the search routine will ensure that we have a interp spline */
  54.     spline_2_line(cur_s);
  55.     break;
  56.     default:
  57.     return;
  58.     }
  59. }
  60.  
  61. line_2_spline(l)
  62.     F_line       *l;
  63. {
  64.     F_spline       *s;
  65.  
  66.     if (num_points(l->points) < 3) {
  67.     put_msg("Can't CONVERT this line into a spline: insufficient points");
  68.     return;
  69.     }
  70.     if ((s = create_spline()) == NULL)
  71.     return;
  72.  
  73.     if (l->type == T_POLYGON)
  74.     s->type = T_CLOSED_INTERP;
  75.     else
  76.     s->type = T_OPEN_INTERP;
  77.     s->style = l->style;
  78.     s->thickness = l->thickness;
  79.     s->color = l->color;
  80.     s->depth = l->depth;
  81.     s->style_val = l->style_val;
  82.     s->pen = l->pen;
  83.     s->fill_style = l->fill_style;
  84.     s->for_arrow = l->for_arrow;
  85.     s->back_arrow = l->back_arrow;
  86.     s->points = l->points;
  87.     s->controls = NULL;
  88.     s->next = NULL;
  89.  
  90.     if (-1 == create_control_list(s)) {
  91.     free_splinestorage(s);
  92.     return;
  93.     }
  94.     remake_control_points(s);
  95.  
  96.     /* now we have finished creating the spline, we can get rid of the line */
  97.     /* first off the screen */
  98.     mask_toggle_linemarker(l);
  99.     draw_line(l, ERASE);
  100.     list_delete_line(&objects.lines, l);
  101.     /* we reuse the arrows and points, so `detach' them from the line */
  102.     l->for_arrow = l->back_arrow = NULL;
  103.     l->points = NULL;
  104.     /* now get rid of the rest */
  105.     free_linestorage(l);
  106.  
  107.     /* now put back the new spline */
  108.     draw_spline(s, PAINT);
  109.     mask_toggle_splinemarker(s);
  110.     list_add_spline(&objects.splines, s);
  111.     clean_up();
  112.     set_action_object(F_CONVERT, O_POLYLINE);
  113.     set_latestspline(s);
  114.     return;
  115. }
  116.  
  117. spline_2_line(s)
  118.     F_spline       *s;
  119. {
  120.     F_line       *l;
  121.  
  122.     /* Now we turn s into a line */
  123.     if ((l = create_line()) == NULL)
  124.     return;
  125.  
  126.     if (s->type == T_OPEN_INTERP)
  127.     l->type = T_POLYLINE;
  128.     else if (s->type == T_CLOSED_INTERP)
  129.     l->type = T_POLYGON;
  130.     l->style = s->style;
  131.     l->thickness = s->thickness;
  132.     l->color = s->color;
  133.     l->depth = s->depth;
  134.     l->style_val = s->style_val;
  135.     l->pen = s->pen;
  136.     l->radius = DEF_BOXRADIUS;
  137.     l->fill_style = s->fill_style;
  138.     l->for_arrow = s->for_arrow;
  139.     l->back_arrow = s->back_arrow;
  140.     l->points = s->points;
  141.  
  142.     /* now we have finished creating the line, we can get rid of the spline */
  143.     /* first off the screen */
  144.     mask_toggle_splinemarker(s);
  145.     draw_spline(s, ERASE);
  146.     list_delete_spline(&objects.splines, s);
  147.     /* we reuse the arrows and points, so `detach' them from the spline */
  148.     s->for_arrow = s->back_arrow = NULL;
  149.     s->points = NULL;
  150.     /* now get rid of the rest */
  151.     free_splinestorage(s);
  152.  
  153.     /* and put in the new line */
  154.     draw_line(l, PAINT);
  155.     mask_toggle_linemarker(l);
  156.     list_add_line(&objects.lines, l);
  157.     clean_up();
  158.     set_action_object(F_CONVERT, O_SPLINE);
  159.     set_latestline(l);
  160.     return;
  161. }
  162.