Bumped versions to 1.1.2/20070818/30:2:0 for the next development snapshot
[geda-gaf/whiteaudio.git] / gschem / src / o_pin.c
blobec871ecf42b7188e761e522cfb7b86f46fb7b602
1 /* gEDA - GPL Electronic Design Automation
2 * gschem - gEDA Schematic Capture
3 * Copyright (C) 1998-2007 Ales Hvezda
4 * Copyright (C) 1998-2007 gEDA Contributors (see ChangeLog for details)
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111 USA
20 #include <config.h>
22 #include <stdio.h>
23 #include <math.h>
25 #include <libgeda/libgeda.h>
27 #include "../include/globals.h"
28 #include "../include/x_states.h"
29 #include "../include/prototype.h"
31 #ifdef HAVE_LIBDMALLOC
32 #include <dmalloc.h>
33 #endif
35 /*! \todo Finish function documentation!!!
36 * \brief
37 * \par Function Description
40 void o_pin_draw(TOPLEVEL *w_current, OBJECT *o_current)
42 int size;
43 int x1, y1, x2, y2; /* screen coords */
45 if (o_current->line == NULL) {
46 return;
49 /* reuse line's routine */
50 if ( (w_current->DONT_REDRAW == 1) ||
51 (!o_line_visible(w_current, o_current->line, &x1, &y1, &x2, &y2)) ) {
52 return;
55 #if DEBUG
56 printf("drawing pin\n\n");
57 #endif
59 if (w_current->pin_style == THICK ) {
60 size = SCREENabs(w_current, PIN_WIDTH);
61 gdk_gc_set_line_attributes(w_current->gc, size, GDK_LINE_SOLID,
62 GDK_CAP_NOT_LAST,
63 GDK_JOIN_MITER);
66 if (w_current->override_color != -1 ) {
67 gdk_gc_set_foreground(w_current->gc,
68 x_get_color(w_current->override_color));
69 if (w_current->DONT_REDRAW == 0) {
70 gdk_draw_line(w_current->window, w_current->gc,
71 x1, y1, x2, y2);
72 gdk_draw_line(w_current->backingstore, w_current->gc,
73 x1, y1, x2, y2);
75 } else {
76 if (w_current->DONT_REDRAW == 0) {
77 gdk_gc_set_foreground(w_current->gc, x_get_color(o_current->color));
78 gdk_draw_line(w_current->window, w_current->gc,
79 x1, y1, x2, y2);
80 gdk_draw_line(w_current->backingstore, w_current->gc,
81 x1, y1, x2, y2);
85 /* draw the cue directly */
86 o_cue_draw_lowlevel(w_current, o_current, o_current->whichend);
88 /* yes zero is right for the width -> use hardware lines */
89 if (w_current->pin_style == THICK ) {
90 gdk_gc_set_line_attributes(w_current->gc, 0, GDK_LINE_SOLID,
91 GDK_CAP_NOT_LAST,
92 GDK_JOIN_MITER);
95 #if DEBUG
96 printf("drawing pin\n");
97 #endif
99 if (o_current->draw_grips && w_current->draw_grips == TRUE) {
100 /* pb20011109 - modified to use the new o_line_[draw|erase]_grips() */
101 /* reuse the line functions */
102 if (!o_current->selected) {
103 /* object is no more selected, erase the grips */
104 o_current->draw_grips = FALSE;
105 o_line_erase_grips(w_current, o_current);
106 } else {
107 /* object is selected, draw the grips */
108 o_line_draw_grips(w_current, o_current);
113 /*! \todo Finish function documentation!!!
114 * \brief
115 * \par Function Description
118 void o_pin_erase(TOPLEVEL *w_current, OBJECT *o_current)
120 w_current->override_color = w_current->background_color;
121 o_pin_draw(w_current, o_current);
122 w_current->override_color = -1;
125 /*! \todo Finish function documentation!!!
126 * \brief
127 * \par Function Description
130 void o_pin_draw_xor(TOPLEVEL *w_current, int dx, int dy, OBJECT *o_current)
132 int size;
133 int color;
134 int sx[2], sy[2];
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 WORLDtoSCREEN( w_current, o_current->line->x[0], o_current->line->y[0], &sx[0], &sy[0] );
157 WORLDtoSCREEN( w_current, o_current->line->x[1], o_current->line->y[1], &sx[1], &sy[1] );
159 gdk_draw_line(w_current->window, w_current->xor_gc,
160 sx[0]+dx, sy[0]+dy,
161 sx[1]+dx, sy[1]+dy);
163 if (w_current->pin_style == THICK ) {
164 gdk_gc_set_line_attributes(w_current->xor_gc, 0,
165 GDK_LINE_SOLID,
166 GDK_CAP_NOT_LAST,
167 GDK_JOIN_MITER);
171 /*! \todo Finish function documentation!!!
172 * \brief
173 * \par Function Description
176 void o_pin_start(TOPLEVEL *w_current, int x, int y)
178 int size;
179 w_current->last_x = w_current->start_x = fix_x(w_current, x);
180 w_current->last_y = w_current->start_y = fix_y(w_current, y);
182 if (w_current->pin_style == THICK ) {
183 size = SCREENabs(w_current, PIN_WIDTH);
184 gdk_gc_set_line_attributes(w_current->xor_gc, size,
185 GDK_LINE_SOLID,
186 GDK_CAP_NOT_LAST,
187 GDK_JOIN_MITER);
190 gdk_gc_set_foreground(w_current->xor_gc,
191 x_get_darkcolor(w_current->select_color) );
192 gdk_draw_line(w_current->window, w_current->xor_gc,
193 w_current->start_x, w_current->start_y,
194 w_current->last_x, w_current->last_y);
196 if (w_current->pin_style == THICK ) {
197 gdk_gc_set_line_attributes(w_current->xor_gc, 0,
198 GDK_LINE_SOLID,
199 GDK_CAP_NOT_LAST,
200 GDK_JOIN_MITER);
204 /*! \todo Finish function documentation!!!
205 * \brief
206 * \par Function Description
209 void o_pin_end(TOPLEVEL *w_current, int x, int y)
211 int x1, y1;
212 int x2, y2;
213 int color;
214 GList *other_objects = NULL;
215 OBJECT *o_current, *o_current_pin;
217 if (w_current->inside_action == 0) {
218 o_redraw(w_current, w_current->page_current->object_head, TRUE);
219 return;
222 if (w_current->override_pin_color == -1) {
223 color = w_current->pin_color;
224 } else {
225 color = w_current->override_pin_color;
228 /* removed 3/15 to see if we can get pins to be ortho only */
229 /* w_current->last_x = fix_x(w_current, x);
230 w_current->last_y = fix_y(w_current, y);*/
232 /* don't allow zero length pins */
233 if ( (w_current->start_x == w_current->last_x) &&
234 (w_current->start_y == w_current->last_y) ) {
235 w_current->start_x = (-1);
236 w_current->start_y = (-1);
237 w_current->last_x = (-1);
238 w_current->last_y = (-1);
239 return;
242 SCREENtoWORLD(w_current, w_current->start_x,w_current->start_y, &x1, &y1);
243 SCREENtoWORLD(w_current, w_current->last_x, w_current->last_y, &x2, &y2);
244 x1 = snap_grid(w_current, x1);
245 y1 = snap_grid(w_current, y1);
246 x2 = snap_grid(w_current, x2);
247 y2 = snap_grid(w_current, y2);
249 w_current->page_current->object_tail =
250 o_pin_add(w_current,
251 w_current->page_current->object_tail,
252 OBJ_PIN, color,
253 x1, y1, x2, y2,
254 PIN_TYPE_NET, 0);
256 o_current = o_current_pin = w_current->page_current->object_tail;
258 if (scm_hook_empty_p(add_pin_hook) == SCM_BOOL_F &&
259 o_current != NULL) {
260 scm_run_hook(add_pin_hook,
261 scm_cons(g_make_object_smob(w_current, o_current),
262 SCM_EOL));
265 other_objects = s_conn_return_others(other_objects, o_current_pin);
266 o_cue_undraw_list(w_current, other_objects);
267 o_cue_draw_list(w_current, other_objects);
268 g_list_free(other_objects);
269 o_cue_draw_single(w_current, o_current_pin);
270 o_pin_draw(w_current, o_current_pin);
272 w_current->start_x = (-1);
273 w_current->start_y = (-1);
274 w_current->last_x = (-1);
275 w_current->last_y = (-1);
276 w_current->page_current->CHANGED=1;
278 o_undo_savestate(w_current, UNDO_ALL);
281 /*! \todo Finish function documentation!!!
282 * \brief
283 * \par Function Description
286 void o_pin_rubberpin(TOPLEVEL *w_current, int x, int y)
288 int size;
289 int diff_x, diff_y;
291 if (w_current->inside_action == 0) {
292 o_redraw(w_current, w_current->page_current->object_head, TRUE);
293 return;
296 size = SCREENabs(w_current, PIN_WIDTH);
298 if (w_current->pin_style == THICK ) {
299 gdk_gc_set_line_attributes(w_current->xor_gc, size,
300 GDK_LINE_SOLID,
301 GDK_CAP_NOT_LAST,
302 GDK_JOIN_MITER);
305 gdk_gc_set_foreground(w_current->xor_gc,
306 x_get_darkcolor(w_current->select_color) );
307 gdk_draw_line(w_current->window, w_current->xor_gc,
308 w_current->start_x, w_current->start_y,
309 w_current->last_x, w_current->last_y);
311 w_current->last_x = fix_x(w_current, x);
312 w_current->last_y = fix_y(w_current, y);
314 diff_x = abs(w_current->last_x - w_current->start_x);
315 diff_y = abs(w_current->last_y - w_current->start_y);
317 if (diff_x >= diff_y) {
318 w_current->last_y = w_current->start_y;
319 } else {
320 w_current->last_x = w_current->start_x;
323 gdk_gc_set_foreground(w_current->xor_gc,
324 x_get_darkcolor(w_current->select_color) );
325 gdk_draw_line(w_current->window, w_current->xor_gc,
326 w_current->start_x, w_current->start_y,
327 w_current->last_x, w_current->last_y);
329 if (w_current->pin_style == THICK ) {
330 gdk_gc_set_line_attributes(w_current->xor_gc, 0,
331 GDK_LINE_SOLID,
332 GDK_CAP_NOT_LAST,
333 GDK_JOIN_MITER);
337 /*! \todo Finish function documentation!!!
338 * \brief
339 * \par Function Description
341 * \note
342 * used in o_stretch.c
344 void o_pin_eraserubber(TOPLEVEL *w_current)
346 int size;
348 if (w_current->net_style == THICK ) {
349 size = SCREENabs(w_current, PIN_WIDTH);
351 if (size < 0)
352 size=0;
354 gdk_gc_set_line_attributes(w_current->xor_gc, size,
355 GDK_LINE_SOLID,
356 GDK_CAP_NOT_LAST,
357 GDK_JOIN_MITER);
360 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);
362 if (w_current->net_style == THICK ) {
363 gdk_gc_set_line_attributes(w_current->xor_gc, 0,
364 GDK_LINE_SOLID,
365 GDK_CAP_NOT_LAST,
366 GDK_JOIN_MITER);