gschem

o_pin.c

Go to the documentation of this file.
00001 /* gEDA - GPL Electronic Design Automation
00002  * gschem - gEDA Schematic Capture
00003  * Copyright (C) 1998-2010 Ales Hvezda
00004  * Copyright (C) 1998-2011 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 <stdio.h>
00023 #include <math.h>
00024 
00025 #include "gschem.h"
00026 
00027 #ifdef HAVE_LIBDMALLOC
00028 #include <dmalloc.h>
00029 #endif
00030 
00036 void o_pin_draw(GSCHEM_TOPLEVEL *w_current, OBJECT *o_current)
00037 {
00038   TOPLEVEL *toplevel = w_current->toplevel;
00039   int x1, y1, x2, y2;
00040   int size = 0;
00041 
00042   if (o_current->line == NULL) {
00043     return;
00044   }
00045 
00046   /* reuse line's routine */
00047   if (!o_line_visible (w_current, o_current->line, &x1, &y1, &x2, &y2)) {
00048     return;
00049   }
00050 
00051   if (toplevel->pin_style == THICK)
00052     size = o_current->line_width;
00053 
00054   gschem_cairo_line (w_current, END_NONE, size, x1, y1, x2, y2);
00055 
00056   gschem_cairo_set_source_color (w_current,
00057                                  o_drawing_color (w_current, o_current));
00058   gschem_cairo_stroke (w_current, TYPE_SOLID, END_NONE, size, -1, -1);
00059 
00060   /* draw the cue directly */
00061   o_cue_draw_lowlevel(w_current, o_current, o_current->whichend);
00062 
00063 #if DEBUG
00064   printf("drawing pin\n");
00065 #endif
00066 
00067   if (o_current->selected && w_current->draw_grips) {
00068     o_line_draw_grips (w_current, o_current);
00069   }
00070 }
00071 
00072 
00078 void o_pin_draw_place (GSCHEM_TOPLEVEL *w_current, int dx, int dy, OBJECT *o_current)
00079 {
00080   TOPLEVEL *toplevel = w_current->toplevel;
00081   int size = 0;
00082 
00083   if (o_current->line == NULL) {
00084     return;
00085   }
00086 
00087   if (toplevel->pin_style == THICK)
00088     size = o_current->line_width;
00089 
00090   gschem_cairo_line (w_current, END_NONE, size,
00091                      o_current->line->x[0] + dx, o_current->line->y[0] + dy,
00092                      o_current->line->x[1] + dx, o_current->line->y[1] + dy);
00093 
00094   gschem_cairo_set_source_color (w_current,
00095                                  x_color_lookup_dark (o_current->color));
00096   gschem_cairo_stroke (w_current, TYPE_SOLID, END_NONE, size, -1, -1);
00097 }
00098 
00104 void o_pin_start(GSCHEM_TOPLEVEL *w_current, int w_x, int w_y)
00105 {
00106   w_current->first_wx = w_current->second_wx = w_x;
00107   w_current->first_wy = w_current->second_wy = w_y;
00108 }
00109 
00115 void o_pin_end(GSCHEM_TOPLEVEL *w_current, int x, int y)
00116 {
00117   TOPLEVEL *toplevel = w_current->toplevel;
00118   OBJECT *new_obj;
00119   int color;
00120 
00121   g_assert( w_current->inside_action != 0 );
00122 
00123   if (toplevel->override_pin_color == -1) {
00124     color = PIN_COLOR;
00125   } else {
00126     color = toplevel->override_pin_color;
00127   }
00128 
00129   /* undraw rubber line */
00130   /* o_pin_invalidate_rubber (w_current); */
00131   w_current->rubber_visible = 0;
00132 
00133   /* don't allow zero length pins */
00134   if ((w_current->first_wx == w_current->second_wx) &&
00135       (w_current->first_wy == w_current->second_wy)) {
00136     return;
00137   }
00138 
00139   new_obj = o_pin_new(toplevel, OBJ_PIN, color,
00140                       w_current->first_wx, w_current->first_wy,
00141                       w_current->second_wx, w_current->second_wy,
00142                       PIN_TYPE_NET, 0);
00143   s_page_append (toplevel, toplevel->page_current, new_obj);
00144 
00145   /* Call add-objects-hook */
00146   g_run_hook_object (w_current, "%add-objects-hook", new_obj);
00147 
00148   toplevel->page_current->CHANGED=1;
00149   o_undo_savestate(w_current, UNDO_ALL);
00150 }
00151 
00157 void o_pin_motion (GSCHEM_TOPLEVEL *w_current, int w_x, int w_y)
00158 {
00159   g_assert( w_current->inside_action != 0 );
00160 
00161   /* erase the rubberpin if it is visible */
00162   if (w_current->rubber_visible)
00163     o_pin_invalidate_rubber (w_current);
00164 
00165   w_current->second_wx = w_x;
00166   w_current->second_wy = w_y;
00167 
00168   /* decide whether to draw the pin vertical or horizontal */
00169   if (abs(w_current->second_wx - w_current->first_wx)
00170       >= abs(w_current->second_wy - w_current->first_wy)) {
00171     w_current->second_wy = w_current->first_wy;
00172   } else {
00173     w_current->second_wx = w_current->first_wx;
00174   }
00175 
00176   o_pin_invalidate_rubber (w_current);
00177   w_current->rubber_visible = 1;
00178 }
00179 
00184 void o_pin_invalidate_rubber (GSCHEM_TOPLEVEL *w_current)
00185 {
00186   TOPLEVEL *toplevel = w_current->toplevel;
00187   int x1, y1, x2, y2;
00188   int min_x, min_y, max_x, max_y;
00189   int bloat = 0;
00190 
00191   WORLDtoSCREEN (w_current, w_current->first_wx, w_current->first_wy, &x1, &y1);
00192   WORLDtoSCREEN (w_current, w_current->second_wx, w_current->second_wy, &x2, &y2);
00193 
00194   /* Pins are always first created as net pins, use net pin width */
00195   if (toplevel->net_style == THICK ) {
00196     bloat = SCREENabs (w_current, PIN_WIDTH_NET) / 2;
00197   }
00198 
00199   min_x = min (x1, x2) - bloat;
00200   max_x = max (x1, x2) + bloat;
00201   min_y = min (y1, y2) - bloat;
00202   max_y = max (y1, y2) + bloat;
00203 
00204   o_invalidate_rect (w_current, min_x, min_y, max_x, max_y);
00205 }
00206 
00207 
00213 void o_pin_draw_rubber (GSCHEM_TOPLEVEL *w_current)
00214 {
00215   int size = 0;
00216 
00217   /* Pins are always first created as net pins, use net pin width */
00218   if (w_current->toplevel->net_style == THICK)
00219     size = PIN_WIDTH_NET;
00220 
00221   gschem_cairo_line (w_current, END_NONE, size,
00222                      w_current->first_wx,  w_current->first_wy,
00223                      w_current->second_wx, w_current->second_wy);
00224 
00225   gschem_cairo_set_source_color (w_current,
00226                                  x_color_lookup_dark (SELECT_COLOR));
00227   gschem_cairo_stroke (w_current, TYPE_SOLID, END_NONE, size, -1, -1);
00228 }
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Defines