gschem
|
00001 /* gEDA - GPL Electronic Design Automation 00002 * gschem - gEDA Schematic Capture 00003 * Copyright (C) 1998-2010 Ales Hvezda 00004 * Copyright (C) 1998-2010 gEDA Contributors (see ChangeLog for details) 00005 * 00006 * This program is free software; you can redistribute it and/or modify 00007 * it under the terms of the GNU General Public License as published by 00008 * the Free Software Foundation; either version 2 of the License, or 00009 * (at your option) any later version. 00010 * 00011 * This program is distributed in the hope that it will be useful, 00012 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00014 * GNU General Public License for more details. 00015 * 00016 * You should have received a copy of the GNU General Public License 00017 * along with this program; if not, write to the Free Software 00018 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 00019 */ 00020 #include <config.h> 00021 00022 #include "gschem.h" 00023 00024 #ifdef HAVE_LIBSTROKE 00025 #include <stroke.h> 00026 00027 #ifdef HAVE_LIBDMALLOC 00028 #include <dmalloc.h> 00029 #endif 00030 00031 /* 00032 * <B>stroke_points</B> is an array of points for the stroke 00033 * footprints. The points of the stroke are displayed over the display 00034 * area of the main window. They have to be erased when the stroke is 00035 * translated and the sequence evaluated. 00036 * 00037 * Its size will never exceed <B>STROKE_MAX_POINTS</B> (the limit in 00038 * number of points of a stroke provided by libstroke). 00039 */ 00040 typedef struct { 00041 gint x, y; 00042 } StrokePoint; 00043 00044 static GArray *stroke_points = NULL; 00045 00046 00056 void 00057 x_stroke_init (void) 00058 { 00059 g_return_if_fail (stroke_points == NULL); 00060 00061 stroke_init (); 00062 00063 stroke_points = g_array_new (FALSE, 00064 FALSE, 00065 sizeof (StrokePoint)); 00066 } 00067 00073 void 00074 x_stroke_free (void) 00075 { 00076 g_return_if_fail (stroke_points != NULL); 00077 00078 g_array_free (stroke_points, TRUE); 00079 stroke_points = NULL; 00080 } 00081 00093 void 00094 x_stroke_record (GSCHEM_TOPLEVEL *w_current, gint x, gint y) 00095 { 00096 g_assert (stroke_points != NULL); 00097 00098 stroke_record (x, y); 00099 00100 if (stroke_points->len < STROKE_MAX_POINTS) { 00101 StrokePoint point = { x, y }; 00102 00103 g_array_append_val (stroke_points, point); 00104 00105 gdk_gc_set_foreground (w_current->gc, x_get_color (STROKE_COLOR)); 00106 gdk_draw_point (w_current->window, w_current->gc, x, y); 00107 } 00108 00109 } 00110 00126 gint 00127 x_stroke_translate_and_execute (GSCHEM_TOPLEVEL *w_current) 00128 { 00129 gchar sequence[STROKE_MAX_SEQUENCE]; 00130 StrokePoint *point; 00131 int min_x, min_y, max_x, max_y; 00132 gint i; 00133 00134 g_assert (stroke_points != NULL); 00135 00136 if (stroke_points->len == 0) 00137 return 0; 00138 00139 point = &g_array_index (stroke_points, StrokePoint, 0); 00140 min_x = max_x = point->x; 00141 min_y = max_y = point->y; 00142 00143 for (i = 1; i < stroke_points->len; i++) { 00144 point = &g_array_index (stroke_points, StrokePoint, i); 00145 min_x = min (min_x, point->x); 00146 min_y = min (min_y, point->y); 00147 max_x = max (max_x, point->x); 00148 max_y = max (max_y, point->y); 00149 } 00150 00151 o_invalidate_rect (w_current, min_x, min_y, max_x + 1, max_y + 1); 00152 00153 /* resets length of array */ 00154 stroke_points->len = 0; 00155 00156 /* try evaluating stroke */ 00157 if (stroke_trans ((char*)&sequence)) { 00158 gchar *guile_string = 00159 g_strdup_printf("(eval-stroke \"%s\")", sequence); 00160 SCM ret; 00161 00162 scm_dynwind_begin (0); 00163 scm_dynwind_unwind_handler (g_free, guile_string, SCM_F_WIND_EXPLICITLY); 00164 ret = g_scm_c_eval_string_protected (guile_string); 00165 scm_dynwind_end (); 00166 00167 return (SCM_NFALSEP (ret)); 00168 } 00169 00170 return 0; 00171 } 00172 00173 #endif /* HAVE_LIBSTROKE */