pcb 4.1.1
An interactive printed circuit board layout editor.
|
00001 /* 00002 * COPYRIGHT 00003 * 00004 * PCB, interactive printed circuit board design 00005 * Copyright (C) 1994,1995,1996 Thomas Nau 00006 * 00007 * This program is free software; you can redistribute it and/or modify 00008 * it under the terms of the GNU General Public License as published by 00009 * the Free Software Foundation; either version 2 of the License, or 00010 * (at your option) any later version. 00011 * 00012 * This program is distributed in the hope that it will be useful, 00013 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00014 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00015 * GNU General Public License for more details. 00016 * 00017 * You should have received a copy of the GNU General Public License along 00018 * with this program; if not, write to the Free Software Foundation, Inc., 00019 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 00020 * 00021 * Contact addresses for paper mail and Email: 00022 * Thomas Nau, Schlehenweg 15, 88471 Baustetten, Germany 00023 * Thomas.Nau@rz.uni-ulm.de 00024 * 00025 */ 00026 00027 /* This file copied and modified by Peter Clifton, starting from 00028 * gui-pinout-window.c, written by Bill Wilson for the PCB Gtk port */ 00029 00030 #ifdef HAVE_CONFIG_H 00031 #include "config.h" 00032 #endif 00033 00034 #include "global.h" 00035 00036 #include "gui.h" 00037 00038 #include "copy.h" 00039 #include "data.h" 00040 #include "draw.h" 00041 #include "mymem.h" 00042 #include "move.h" 00043 #include "rotate.h" 00044 #include "gui-pinout-preview.h" 00045 00046 #ifdef HAVE_LIBDMALLOC 00047 #include <dmalloc.h> 00048 #endif 00049 00050 /* Just define a sensible scale, lets say (for example), 100 pixel per 150 mil */ 00051 #define SENSIBLE_VIEW_SCALE (100. / MIL_TO_COORD (150.)) 00052 static void 00053 pinout_set_view (GhidPinoutPreview * pinout) 00054 { 00055 float scale = SENSIBLE_VIEW_SCALE; 00056 00057 pinout->x_max = pinout->element->BoundingBox.X2 + Settings.PinoutOffsetX; 00058 pinout->y_max = pinout->element->BoundingBox.Y2 + Settings.PinoutOffsetY; 00059 pinout->w_pixels = scale * (pinout->element->BoundingBox.X2 - 00060 pinout->element->BoundingBox.X1); 00061 pinout->h_pixels = scale * (pinout->element->BoundingBox.Y2 - 00062 pinout->element->BoundingBox.Y1); 00063 } 00064 00065 00066 static void 00067 pinout_set_data (GhidPinoutPreview * pinout, ElementType * element) 00068 { 00069 if (pinout->element != NULL) 00070 { 00071 FreeElementMemory (pinout->element); 00072 g_slice_free (ElementType, pinout->element); 00073 pinout->element = NULL; 00074 } 00075 00076 if (element == NULL) 00077 { 00078 pinout->w_pixels = 0; 00079 pinout->h_pixels = 0; 00080 return; 00081 } 00082 00083 /* 00084 * copy element data 00085 * enable output of pin and padnames 00086 * move element to a 5% offset from zero position 00087 * set all package lines/arcs to zero width 00088 */ 00089 pinout->element = CopyElementLowLevel (NULL, element, FALSE, 0, 0, FOUNDFLAG); 00090 PIN_LOOP (pinout->element); 00091 { 00092 SET_FLAG (DISPLAYNAMEFLAG, pin); 00093 } 00094 END_LOOP; 00095 00096 PAD_LOOP (pinout->element); 00097 { 00098 SET_FLAG (DISPLAYNAMEFLAG, pad); 00099 } 00100 END_LOOP; 00101 00102 00103 MoveElementLowLevel (NULL, pinout->element, 00104 Settings.PinoutOffsetX - 00105 pinout->element->BoundingBox.X1, 00106 Settings.PinoutOffsetY - 00107 pinout->element->BoundingBox.Y1); 00108 00109 pinout_set_view (pinout); 00110 00111 ELEMENTLINE_LOOP (pinout->element); 00112 { 00113 line->Thickness = 0; 00114 } 00115 END_LOOP; 00116 00117 ARC_LOOP (pinout->element); 00118 { 00119 /* 00120 * for whatever reason setting a thickness of 0 causes the arcs to 00121 * not display so pick 1 which does display but is still quite 00122 * thin. 00123 */ 00124 arc->Thickness = 1; 00125 } 00126 END_LOOP; 00127 } 00128 00129 00130 enum 00131 { 00132 PROP_ELEMENT_DATA = 1, 00133 }; 00134 00135 00136 static GObjectClass *ghid_pinout_preview_parent_class = NULL; 00137 00138 00147 static void 00148 ghid_pinout_preview_constructed (GObject *object) 00149 { 00150 /* chain up to the parent class */ 00151 if (G_OBJECT_CLASS (ghid_pinout_preview_parent_class)->constructed != NULL) 00152 G_OBJECT_CLASS (ghid_pinout_preview_parent_class)->constructed (object); 00153 00154 ghid_init_drawing_widget (GTK_WIDGET (object), gport); 00155 } 00156 00157 00158 00167 static void 00168 ghid_pinout_preview_finalize (GObject * object) 00169 { 00170 GhidPinoutPreview *pinout = GHID_PINOUT_PREVIEW (object); 00171 00172 /* Passing NULL for element data will free the old memory */ 00173 pinout_set_data (pinout, NULL); 00174 00175 G_OBJECT_CLASS (ghid_pinout_preview_parent_class)->finalize (object); 00176 } 00177 00178 00191 static void 00192 ghid_pinout_preview_set_property (GObject * object, guint property_id, 00193 const GValue * value, GParamSpec * pspec) 00194 { 00195 GhidPinoutPreview *pinout = GHID_PINOUT_PREVIEW (object); 00196 GdkWindow *window = gtk_widget_get_window (GTK_WIDGET (pinout)); 00197 00198 switch (property_id) 00199 { 00200 case PROP_ELEMENT_DATA: 00201 pinout_set_data (pinout, (ElementType *)g_value_get_pointer (value)); 00202 if (window != NULL) 00203 gdk_window_invalidate_rect (window, NULL, FALSE); 00204 break; 00205 default: 00206 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); 00207 } 00208 00209 } 00210 00211 00224 static void 00225 ghid_pinout_preview_get_property (GObject * object, guint property_id, 00226 GValue * value, GParamSpec * pspec) 00227 { 00228 switch (property_id) 00229 { 00230 default: 00231 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); 00232 } 00233 00234 } 00235 00236 00245 static void 00246 ghid_pinout_preview_class_init (GhidPinoutPreviewClass * klass) 00247 { 00248 GObjectClass *gobject_class = G_OBJECT_CLASS (klass); 00249 GtkWidgetClass *gtk_widget_class = GTK_WIDGET_CLASS (klass); 00250 00251 gobject_class->finalize = ghid_pinout_preview_finalize; 00252 gobject_class->set_property = ghid_pinout_preview_set_property; 00253 gobject_class->get_property = ghid_pinout_preview_get_property; 00254 gobject_class->constructed = ghid_pinout_preview_constructed; 00255 00256 gtk_widget_class->expose_event = ghid_pinout_preview_expose; 00257 00258 ghid_pinout_preview_parent_class = (GObjectClass *)g_type_class_peek_parent (klass); 00259 00260 g_object_class_install_property (gobject_class, PROP_ELEMENT_DATA, 00261 g_param_spec_pointer ("element-data", 00262 "", 00263 "", 00264 G_PARAM_WRITABLE)); 00265 } 00266 00267 00277 GType 00278 ghid_pinout_preview_get_type () 00279 { 00280 static GType ghid_pinout_preview_type = 0; 00281 00282 if (!ghid_pinout_preview_type) 00283 { 00284 static const GTypeInfo ghid_pinout_preview_info = { 00285 sizeof (GhidPinoutPreviewClass), 00286 NULL, /* base_init */ 00287 NULL, /* base_finalize */ 00288 (GClassInitFunc) ghid_pinout_preview_class_init, 00289 NULL, /* class_finalize */ 00290 NULL, /* class_data */ 00291 sizeof (GhidPinoutPreview), 00292 0, /* n_preallocs */ 00293 NULL, /* instance_init */ 00294 }; 00295 00296 ghid_pinout_preview_type = 00297 g_type_register_static (GTK_TYPE_DRAWING_AREA, "GhidPinoutPreview", 00298 &ghid_pinout_preview_info, (GTypeFlags)0); 00299 } 00300 00301 return ghid_pinout_preview_type; 00302 } 00303 00304 00312 GtkWidget * 00313 ghid_pinout_preview_new (ElementType * element) 00314 { 00315 GhidPinoutPreview *pinout_preview; 00316 00317 pinout_preview = (GhidPinoutPreview *)g_object_new (GHID_TYPE_PINOUT_PREVIEW, 00318 "element-data", element, NULL); 00319 00320 return GTK_WIDGET (pinout_preview); 00321 } 00322 00323 00329 void 00330 ghid_pinout_preview_get_natural_size (GhidPinoutPreview * pinout, 00331 int *width, int *height) 00332 { 00333 *width = pinout->w_pixels; 00334 *height = pinout->h_pixels; 00335 }