schdiff: Use a here document for usage.
[geda-gaf/whiteaudio.git] / gschem / src / o_pin.c
blobf2a5ea7708e74cf12e09714e96cd3d88846241dc
1 /* gEDA - GPL Electronic Design Automation
2 * gschem - gEDA Schematic Capture
3 * Copyright (C) 1998-2010 Ales Hvezda
4 * Copyright (C) 1998-2011 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20 #include <config.h>
22 #include <stdio.h>
23 #include <math.h>
25 #include "gschem.h"
27 #ifdef HAVE_LIBDMALLOC
28 #include <dmalloc.h>
29 #endif
31 /*! \todo Finish function documentation!!!
32 * \brief
33 * \par Function Description
36 void o_pin_draw(GSCHEM_TOPLEVEL *w_current, OBJECT *o_current)
38 TOPLEVEL *toplevel = w_current->toplevel;
39 int x1, y1, x2, y2;
40 int size = 0;
42 if (o_current->line == NULL) {
43 return;
46 /* reuse line's routine */
47 if (!o_line_visible (w_current, o_current->line, &x1, &y1, &x2, &y2)) {
48 return;
51 if (toplevel->pin_style == THICK)
52 size = o_current->line_width;
54 gschem_cairo_line (w_current, END_NONE, size, x1, y1, x2, y2);
56 gschem_cairo_set_source_color (w_current,
57 o_drawing_color (w_current, o_current));
58 gschem_cairo_stroke (w_current, TYPE_SOLID, END_NONE, size, -1, -1);
60 /* draw the cue directly */
61 o_cue_draw_lowlevel(w_current, o_current, o_current->whichend);
63 #if DEBUG
64 printf("drawing pin\n");
65 #endif
67 if (o_current->selected && w_current->draw_grips) {
68 o_line_draw_grips (w_current, o_current);
73 /*! \todo Finish function documentation!!!
74 * \brief
75 * \par Function Description
78 void o_pin_draw_place (GSCHEM_TOPLEVEL *w_current, int dx, int dy, OBJECT *o_current)
80 TOPLEVEL *toplevel = w_current->toplevel;
81 int size = 0;
83 if (o_current->line == NULL) {
84 return;
87 if (toplevel->pin_style == THICK)
88 size = o_current->line_width;
90 gschem_cairo_line (w_current, END_NONE, size,
91 o_current->line->x[0] + dx, o_current->line->y[0] + dy,
92 o_current->line->x[1] + dx, o_current->line->y[1] + dy);
94 gschem_cairo_set_source_color (w_current,
95 x_color_lookup_dark (o_current->color));
96 gschem_cairo_stroke (w_current, TYPE_SOLID, END_NONE, size, -1, -1);
99 /*! \todo Finish function documentation!!!
100 * \brief
101 * \par Function Description
104 void o_pin_start(GSCHEM_TOPLEVEL *w_current, int w_x, int w_y)
106 w_current->first_wx = w_current->second_wx = w_x;
107 w_current->first_wy = w_current->second_wy = w_y;
110 /*! \todo Finish function documentation!!!
111 * \brief
112 * \par Function Description
115 void o_pin_end(GSCHEM_TOPLEVEL *w_current, int x, int y)
117 TOPLEVEL *toplevel = w_current->toplevel;
118 OBJECT *new_obj;
119 int color;
121 g_assert( w_current->inside_action != 0 );
123 if (toplevel->override_pin_color == -1) {
124 color = PIN_COLOR;
125 } else {
126 color = toplevel->override_pin_color;
129 /* undraw rubber line */
130 /* o_pin_invalidate_rubber (w_current); */
131 w_current->rubber_visible = 0;
133 /* don't allow zero length pins */
134 if ((w_current->first_wx == w_current->second_wx) &&
135 (w_current->first_wy == w_current->second_wy)) {
136 return;
139 new_obj = o_pin_new(toplevel, OBJ_PIN, color,
140 w_current->first_wx, w_current->first_wy,
141 w_current->second_wx, w_current->second_wy,
142 PIN_TYPE_NET, 0);
143 s_page_append (toplevel, toplevel->page_current, new_obj);
145 /* Call add-objects-hook */
146 g_run_hook_object ("%add-objects-hook", new_obj);
148 toplevel->page_current->CHANGED=1;
149 o_undo_savestate(w_current, UNDO_ALL);
152 /*! \todo Finish function documentation!!!
153 * \brief
154 * \par Function Description
157 void o_pin_motion (GSCHEM_TOPLEVEL *w_current, int w_x, int w_y)
159 g_assert( w_current->inside_action != 0 );
161 /* erase the rubberpin if it is visible */
162 if (w_current->rubber_visible)
163 o_pin_invalidate_rubber (w_current);
165 w_current->second_wx = w_x;
166 w_current->second_wy = w_y;
168 /* decide whether to draw the pin vertical or horizontal */
169 if (abs(w_current->second_wx - w_current->first_wx)
170 >= abs(w_current->second_wy - w_current->first_wy)) {
171 w_current->second_wy = w_current->first_wy;
172 } else {
173 w_current->second_wx = w_current->first_wx;
176 o_pin_invalidate_rubber (w_current);
177 w_current->rubber_visible = 1;
180 /*! \todo Finish function documentation!!!
181 * \brief
182 * \par Function Description
184 void o_pin_invalidate_rubber (GSCHEM_TOPLEVEL *w_current)
186 TOPLEVEL *toplevel = w_current->toplevel;
187 int x1, y1, x2, y2;
188 int min_x, min_y, max_x, max_y;
189 int bloat = 0;
191 WORLDtoSCREEN (w_current, w_current->first_wx, w_current->first_wy, &x1, &y1);
192 WORLDtoSCREEN (w_current, w_current->second_wx, w_current->second_wy, &x2, &y2);
194 /* Pins are always first created as net pins, use net pin width */
195 if (toplevel->net_style == THICK ) {
196 bloat = SCREENabs (w_current, PIN_WIDTH_NET) / 2;
199 min_x = min (x1, x2) - bloat;
200 max_x = max (x1, x2) + bloat;
201 min_y = min (y1, y2) - bloat;
202 max_y = max (y1, y2) + bloat;
204 o_invalidate_rect (w_current, min_x, min_y, max_x, max_y);
208 /*! \todo Finish function documentation!!!
209 * \brief
210 * \par Function Description
213 void o_pin_draw_rubber (GSCHEM_TOPLEVEL *w_current)
215 int size = 0;
217 /* Pins are always first created as net pins, use net pin width */
218 if (w_current->toplevel->net_style == THICK)
219 size = PIN_WIDTH_NET;
221 gschem_cairo_line (w_current, END_NONE, size,
222 w_current->first_wx, w_current->first_wy,
223 w_current->second_wx, w_current->second_wy);
225 gschem_cairo_set_source_color (w_current,
226 x_color_lookup_dark (SELECT_COLOR));
227 gschem_cairo_stroke (w_current, TYPE_SOLID, END_NONE, size, -1, -1);