1 /* gEDA - GPL Electronic Design Automation
2 * gschem - gEDA Schematic Capture
3 * Copyright (C) 1998-2010 Ales Hvezda
4 * Copyright (C) 1998-2010 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
27 #ifdef HAVE_LIBDMALLOC
31 /*! \todo Finish function documentation!!!
33 * \par Function Description
36 void o_pin_draw(GSCHEM_TOPLEVEL
*w_current
, OBJECT
*o_current
)
38 TOPLEVEL
*toplevel
= w_current
->toplevel
;
42 if (o_current
->line
== NULL
) {
46 /* reuse line's routine */
47 if ( (toplevel
->DONT_REDRAW
== 1) ||
48 (!o_line_visible (w_current
, o_current
->line
, &x1
, &y1
, &x2
, &y2
)) ) {
52 if (toplevel
->DONT_REDRAW
== 0) {
53 if (toplevel
->pin_style
== THICK
)
54 size
= o_current
->line_width
;
56 gschem_cairo_line (w_current
, END_NONE
, size
, x1
, y1
, x2
, y2
);
58 gschem_cairo_set_source_color (w_current
,
59 o_drawing_color (w_current
, o_current
));
60 gschem_cairo_stroke (w_current
, TYPE_SOLID
, END_NONE
, size
, -1, -1);
63 /* draw the cue directly */
64 o_cue_draw_lowlevel(w_current
, o_current
, o_current
->whichend
);
67 printf("drawing pin\n");
70 if (o_current
->selected
&& w_current
->draw_grips
) {
71 o_line_draw_grips (w_current
, o_current
);
76 /*! \todo Finish function documentation!!!
78 * \par Function Description
81 void o_pin_draw_place (GSCHEM_TOPLEVEL
*w_current
, int dx
, int dy
, OBJECT
*o_current
)
83 TOPLEVEL
*toplevel
= w_current
->toplevel
;
86 if (o_current
->line
== NULL
) {
90 if (toplevel
->pin_style
== THICK
)
91 size
= o_current
->line_width
;
93 gschem_cairo_line (w_current
, END_NONE
, size
,
94 o_current
->line
->x
[0] + dx
, o_current
->line
->y
[0] + dy
,
95 o_current
->line
->x
[1] + dx
, o_current
->line
->y
[1] + dy
);
97 gschem_cairo_set_source_color (w_current
,
98 x_color_lookup_dark (o_current
->color
));
99 gschem_cairo_stroke (w_current
, TYPE_SOLID
, END_NONE
, size
, -1, -1);
102 /*! \todo Finish function documentation!!!
104 * \par Function Description
107 void o_pin_start(GSCHEM_TOPLEVEL
*w_current
, int w_x
, int w_y
)
109 w_current
->first_wx
= w_current
->second_wx
= w_x
;
110 w_current
->first_wy
= w_current
->second_wy
= w_y
;
113 /*! \todo Finish function documentation!!!
115 * \par Function Description
118 void o_pin_end(GSCHEM_TOPLEVEL
*w_current
, int x
, int y
)
120 TOPLEVEL
*toplevel
= w_current
->toplevel
;
123 GList
*prev_conn_objects
= NULL
;
124 OBJECT
*o_current
, *o_current_pin
;
126 g_assert( w_current
->inside_action
!= 0 );
128 if (toplevel
->override_pin_color
== -1) {
131 color
= toplevel
->override_pin_color
;
134 /* undraw rubber line */
135 /* o_pin_invalidate_rubber (w_current); */
136 w_current
->rubber_visible
= 0;
138 /* don't allow zero length pins */
139 if ((w_current
->first_wx
== w_current
->second_wx
) &&
140 (w_current
->first_wy
== w_current
->second_wy
)) {
144 new_obj
= o_pin_new(toplevel
, OBJ_PIN
, color
,
145 w_current
->first_wx
, w_current
->first_wy
,
146 w_current
->second_wx
, w_current
->second_wy
,
148 s_page_append (toplevel
, toplevel
->page_current
, new_obj
);
150 o_current
= o_current_pin
= new_obj
;
152 if (scm_hook_empty_p(add_pin_hook
) == SCM_BOOL_F
&&
154 scm_run_hook(add_pin_hook
,
155 scm_cons(g_make_object_smob(toplevel
, o_current
),
159 /* look for connected objects */
160 prev_conn_objects
= s_conn_return_others(prev_conn_objects
, o_current_pin
);
161 o_invalidate_glist (w_current
, prev_conn_objects
);
162 g_list_free (prev_conn_objects
);
163 o_invalidate (w_current
, o_current_pin
);
165 toplevel
->page_current
->CHANGED
=1;
166 o_undo_savestate(w_current
, UNDO_ALL
);
169 /*! \todo Finish function documentation!!!
171 * \par Function Description
174 void o_pin_motion (GSCHEM_TOPLEVEL
*w_current
, int w_x
, int w_y
)
176 g_assert( w_current
->inside_action
!= 0 );
178 /* erase the rubberpin if it is visible */
179 if (w_current
->rubber_visible
)
180 o_pin_invalidate_rubber (w_current
);
182 w_current
->second_wx
= w_x
;
183 w_current
->second_wy
= w_y
;
185 /* decide whether to draw the pin vertical or horizontal */
186 if (abs(w_current
->second_wx
- w_current
->first_wx
)
187 >= abs(w_current
->second_wy
- w_current
->first_wy
)) {
188 w_current
->second_wy
= w_current
->first_wy
;
190 w_current
->second_wx
= w_current
->first_wx
;
193 o_pin_invalidate_rubber (w_current
);
194 w_current
->rubber_visible
= 1;
197 /*! \todo Finish function documentation!!!
199 * \par Function Description
201 void o_pin_invalidate_rubber (GSCHEM_TOPLEVEL
*w_current
)
203 TOPLEVEL
*toplevel
= w_current
->toplevel
;
205 int min_x
, min_y
, max_x
, max_y
;
208 WORLDtoSCREEN (w_current
, w_current
->first_wx
, w_current
->first_wy
, &x1
, &y1
);
209 WORLDtoSCREEN (w_current
, w_current
->second_wx
, w_current
->second_wy
, &x2
, &y2
);
211 /* Pins are always first created as net pins, use net pin width */
212 if (toplevel
->net_style
== THICK
) {
213 bloat
= SCREENabs (w_current
, PIN_WIDTH_NET
) / 2;
216 min_x
= min (x1
, x2
) - bloat
;
217 max_x
= max (x1
, x2
) + bloat
;
218 min_y
= min (y1
, y2
) - bloat
;
219 max_y
= max (y1
, y2
) + bloat
;
221 o_invalidate_rect (w_current
, min_x
, min_y
, max_x
, max_y
);
225 /*! \todo Finish function documentation!!!
227 * \par Function Description
230 void o_pin_draw_rubber (GSCHEM_TOPLEVEL
*w_current
)
234 /* Pins are always first created as net pins, use net pin width */
235 if (w_current
->toplevel
->net_style
== THICK
)
236 size
= PIN_WIDTH_NET
;
238 gschem_cairo_line (w_current
, END_NONE
, size
,
239 w_current
->first_wx
, w_current
->first_wy
,
240 w_current
->second_wx
, w_current
->second_wy
);
242 gschem_cairo_set_source_color (w_current
,
243 x_color_lookup_dark (SELECT_COLOR
));
244 gschem_cairo_stroke (w_current
, TYPE_SOLID
, END_NONE
, size
, -1, -1);