Added a new parameter to o_redraw and o_cue_redraw_all,
[geda-gaf/whiteaudio.git] / gschem / src / o_pin.c
blob20397c96b4b140e3e9dedb4de1a6f66a4797405f
1 /* gEDA - GPL Electronic Design Automation
2 * gschem - gEDA Schematic Capture
3 * Copyright (C) 1998-2000 Ales V. Hvezda
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111 USA
19 #include <config.h>
21 #include <stdio.h>
22 #include <math.h>
24 #include <libgeda/libgeda.h>
26 #include "../include/globals.h"
27 #include "../include/x_states.h"
28 #include "../include/prototype.h"
30 #ifdef HAVE_LIBDMALLOC
31 #include <dmalloc.h>
32 #endif
34 /*! \todo Finish function documentation!!!
35 * \brief
36 * \par Function Description
39 void o_pin_draw(TOPLEVEL *w_current, OBJECT *o_current)
41 int size;
42 int x1, y1, x2, y2; /* screen coords */
44 if (o_current->line == NULL) {
45 return;
48 o_pin_recalc(w_current, o_current);
50 /* reuse line's routine */
51 if ( (w_current->DONT_REDRAW == 1) ||
52 (!o_line_visible(w_current, o_current->line, &x1, &y1, &x2, &y2)) ) {
53 return;
56 #if DEBUG
57 printf("drawing pin\n\n");
58 #endif
60 if (w_current->pin_style == THICK ) {
61 size = SCREENabs(w_current, PIN_WIDTH);
62 gdk_gc_set_line_attributes(w_current->gc, size, GDK_LINE_SOLID,
63 GDK_CAP_NOT_LAST,
64 GDK_JOIN_MITER);
67 if (w_current->override_color != -1 ) {
68 gdk_gc_set_foreground(w_current->gc,
69 x_get_color(w_current->override_color));
70 if (w_current->DONT_REDRAW == 0) {
71 gdk_draw_line(w_current->window, w_current->gc,
72 x1, y1, x2, y2);
73 gdk_draw_line(w_current->backingstore, w_current->gc,
74 x1, y1, x2, y2);
76 } else {
77 if (w_current->DONT_REDRAW == 0) {
78 gdk_gc_set_foreground(w_current->gc, x_get_color(o_current->color));
79 gdk_draw_line(w_current->window, w_current->gc,
80 x1, y1, x2, y2);
81 gdk_draw_line(w_current->backingstore, w_current->gc,
82 x1, y1, x2, y2);
86 /* draw the cue directly */
87 o_cue_draw_lowlevel(w_current, o_current, o_current->whichend);
89 /* yes zero is right for the width -> use hardware lines */
90 if (w_current->pin_style == THICK ) {
91 gdk_gc_set_line_attributes(w_current->gc, 0, GDK_LINE_SOLID,
92 GDK_CAP_NOT_LAST,
93 GDK_JOIN_MITER);
96 #if DEBUG
97 printf("drawing pin\n");
98 #endif
100 if (o_current->draw_grips && w_current->draw_grips == TRUE) {
101 /* pb20011109 - modified to use the new o_line_[draw|erase]_grips() */
102 /* reuse the line functions */
103 if (!o_current->selected) {
104 /* object is no more selected, erase the grips */
105 o_current->draw_grips = FALSE;
106 o_line_erase_grips(w_current, o_current);
107 } else {
108 /* object is selected, draw the grips */
109 o_line_draw_grips(w_current, o_current);
114 /*! \todo Finish function documentation!!!
115 * \brief
116 * \par Function Description
119 void o_pin_erase(TOPLEVEL *w_current, OBJECT *o_current)
121 w_current->override_color = w_current->background_color;
122 o_pin_draw(w_current, o_current);
123 w_current->override_color = -1;
126 /*! \todo Finish function documentation!!!
127 * \brief
128 * \par Function Description
131 void o_pin_draw_xor(TOPLEVEL *w_current, int dx, int dy, OBJECT *o_current)
133 int size;
134 int color;
136 if (o_current->line == NULL) {
137 return;
140 if (o_current->saved_color != -1) {
141 color = o_current->saved_color;
142 } else {
143 color = o_current->color;
146 gdk_gc_set_foreground(w_current->xor_gc, x_get_darkcolor(color));
148 if (w_current->pin_style == THICK ) {
149 size = SCREENabs(w_current, PIN_WIDTH);
150 gdk_gc_set_line_attributes(w_current->xor_gc, size,
151 GDK_LINE_SOLID,
152 GDK_CAP_NOT_LAST,
153 GDK_JOIN_MITER);
156 gdk_draw_line(w_current->window, w_current->xor_gc,
157 o_current->line->screen_x[0]+dx,
158 o_current->line->screen_y[0]+dy,
159 o_current->line->screen_x[1]+dx,
160 o_current->line->screen_y[1]+dy);
162 if (w_current->pin_style == THICK ) {
163 gdk_gc_set_line_attributes(w_current->xor_gc, 0,
164 GDK_LINE_SOLID,
165 GDK_CAP_NOT_LAST,
166 GDK_JOIN_MITER);
170 /*! \todo Finish function documentation!!!
171 * \brief
172 * \par Function Description
175 void o_pin_start(TOPLEVEL *w_current, int x, int y)
177 int size;
178 w_current->last_x = w_current->start_x = fix_x(w_current, x);
179 w_current->last_y = w_current->start_y = fix_y(w_current, y);
181 if (w_current->pin_style == THICK ) {
182 size = SCREENabs(w_current, PIN_WIDTH);
183 gdk_gc_set_line_attributes(w_current->xor_gc, size,
184 GDK_LINE_SOLID,
185 GDK_CAP_NOT_LAST,
186 GDK_JOIN_MITER);
189 gdk_gc_set_foreground(w_current->xor_gc,
190 x_get_darkcolor(w_current->select_color) );
191 gdk_draw_line(w_current->window, w_current->xor_gc,
192 w_current->start_x, w_current->start_y,
193 w_current->last_x, w_current->last_y);
195 if (w_current->pin_style == THICK ) {
196 gdk_gc_set_line_attributes(w_current->xor_gc, 0,
197 GDK_LINE_SOLID,
198 GDK_CAP_NOT_LAST,
199 GDK_JOIN_MITER);
203 /*! \todo Finish function documentation!!!
204 * \brief
205 * \par Function Description
208 void o_pin_end(TOPLEVEL *w_current, int x, int y)
210 int x1, y1;
211 int x2, y2;
212 int color;
213 GList *other_objects = NULL;
214 OBJECT *o_current, *o_current_pin;
216 if (w_current->inside_action == 0) {
217 o_redraw(w_current, w_current->page_current->object_head, TRUE);
218 return;
221 if (w_current->override_pin_color == -1) {
222 color = w_current->pin_color;
223 } else {
224 color = w_current->override_pin_color;
227 /* removed 3/15 to see if we can get pins to be ortho only */
228 /* w_current->last_x = fix_x(w_current, x);
229 w_current->last_y = fix_y(w_current, y);*/
231 /* don't allow zero length pins */
232 if ( (w_current->start_x == w_current->last_x) &&
233 (w_current->start_y == w_current->last_y) ) {
234 w_current->start_x = (-1);
235 w_current->start_y = (-1);
236 w_current->last_x = (-1);
237 w_current->last_y = (-1);
238 return;
241 SCREENtoWORLD(w_current, w_current->start_x,w_current->start_y, &x1, &y1);
242 SCREENtoWORLD(w_current, w_current->last_x, w_current->last_y, &x2, &y2);
243 x1 = snap_grid(w_current, x1);
244 y1 = snap_grid(w_current, y1);
245 x2 = snap_grid(w_current, x2);
246 y2 = snap_grid(w_current, y2);
248 w_current->page_current->object_tail =
249 o_pin_add(w_current,
250 w_current->page_current->object_tail,
251 OBJ_PIN, color,
252 x1, y1, x2, y2,
253 PIN_TYPE_NET, 0);
255 o_current = o_current_pin = w_current->page_current->object_tail;
257 if (scm_hook_empty_p(add_pin_hook) == SCM_BOOL_F &&
258 o_current != NULL) {
259 scm_run_hook(add_pin_hook,
260 scm_cons(g_make_object_smob(w_current, o_current),
261 SCM_EOL));
264 other_objects = s_conn_return_others(other_objects, o_current_pin);
265 o_cue_undraw_list(w_current, other_objects);
266 o_cue_draw_list(w_current, other_objects);
267 g_list_free(other_objects);
268 o_cue_draw_single(w_current, o_current_pin);
269 o_pin_draw(w_current, o_current_pin);
271 w_current->start_x = (-1);
272 w_current->start_y = (-1);
273 w_current->last_x = (-1);
274 w_current->last_y = (-1);
275 w_current->page_current->CHANGED=1;
277 o_undo_savestate(w_current, UNDO_ALL);
280 /*! \todo Finish function documentation!!!
281 * \brief
282 * \par Function Description
285 void o_pin_rubberpin(TOPLEVEL *w_current, int x, int y)
287 int size;
288 int diff_x, diff_y;
290 if (w_current->inside_action == 0) {
291 o_redraw(w_current, w_current->page_current->object_head, TRUE);
292 return;
295 size = SCREENabs(w_current, PIN_WIDTH);
297 if (w_current->pin_style == THICK ) {
298 gdk_gc_set_line_attributes(w_current->xor_gc, size,
299 GDK_LINE_SOLID,
300 GDK_CAP_NOT_LAST,
301 GDK_JOIN_MITER);
304 gdk_gc_set_foreground(w_current->xor_gc,
305 x_get_darkcolor(w_current->select_color) );
306 gdk_draw_line(w_current->window, w_current->xor_gc,
307 w_current->start_x, w_current->start_y,
308 w_current->last_x, w_current->last_y);
310 w_current->last_x = fix_x(w_current, x);
311 w_current->last_y = fix_y(w_current, y);
313 diff_x = abs(w_current->last_x - w_current->start_x);
314 diff_y = abs(w_current->last_y - w_current->start_y);
316 if (diff_x >= diff_y) {
317 w_current->last_y = w_current->start_y;
318 } else {
319 w_current->last_x = w_current->start_x;
322 gdk_gc_set_foreground(w_current->xor_gc,
323 x_get_darkcolor(w_current->select_color) );
324 gdk_draw_line(w_current->window, w_current->xor_gc,
325 w_current->start_x, w_current->start_y,
326 w_current->last_x, w_current->last_y);
328 if (w_current->pin_style == THICK ) {
329 gdk_gc_set_line_attributes(w_current->xor_gc, 0,
330 GDK_LINE_SOLID,
331 GDK_CAP_NOT_LAST,
332 GDK_JOIN_MITER);
336 /*! \todo Finish function documentation!!!
337 * \brief
338 * \par Function Description
340 * \note
341 * used in o_stretch.c
343 void o_pin_eraserubber(TOPLEVEL *w_current)
345 int size;
347 if (w_current->net_style == THICK ) {
348 size = SCREENabs(w_current, PIN_WIDTH);
350 if (size < 0)
351 size=0;
353 gdk_gc_set_line_attributes(w_current->xor_gc, size,
354 GDK_LINE_SOLID,
355 GDK_CAP_NOT_LAST,
356 GDK_JOIN_MITER);
359 #if 0
360 gdk_gc_set_foreground(w_current->xor_gc,
361 x_get_color(w_current->background_color) );
362 #endif
364 gdk_draw_line(w_current->window, w_current->xor_gc, w_current->start_x, w_current->start_y, w_current->last_x, w_current->last_y);
366 if (w_current->net_style == THICK ) {
367 gdk_gc_set_line_attributes(w_current->xor_gc, 0,
368 GDK_LINE_SOLID,
369 GDK_CAP_NOT_LAST,
370 GDK_JOIN_MITER);