copy.c: Add mask_flags parameter to CopyElementLowLevel()
[geda-pcb/pcjc2.git] / src / hid / gtk / gui-pinout-preview.c
blobd354ff15e1b917e4a46e9bab1ea66d53aed6813b
1 /*
2 * COPYRIGHT
4 * PCB, interactive printed circuit board design
5 * Copyright (C) 1994,1995,1996 Thomas Nau
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21 * Contact addresses for paper mail and Email:
22 * Thomas Nau, Schlehenweg 15, 88471 Baustetten, Germany
23 * Thomas.Nau@rz.uni-ulm.de
27 /* This file copied and modified by Peter Clifton, starting from
28 * gui-pinout-window.c, written by Bill Wilson for the PCB Gtk port */
30 #ifdef HAVE_CONFIG_H
31 #include "config.h"
32 #endif
34 #include "global.h"
36 #include "gui.h"
38 #include "copy.h"
39 #include "data.h"
40 #include "draw.h"
41 #include "mymem.h"
42 #include "move.h"
43 #include "rotate.h"
44 #include "gui-pinout-preview.h"
46 #ifdef HAVE_LIBDMALLOC
47 #include <dmalloc.h>
48 #endif
50 /* Just define a sensible scale, lets say (for example), 100 pixel per 150 mil */
51 #define SENSIBLE_VIEW_SCALE (100. / MIL_TO_COORD (150.))
52 static void
53 pinout_set_view (GhidPinoutPreview * pinout)
55 float scale = SENSIBLE_VIEW_SCALE;
57 pinout->x_max = pinout->element.BoundingBox.X2 + Settings.PinoutOffsetX;
58 pinout->y_max = pinout->element.BoundingBox.Y2 + Settings.PinoutOffsetY;
59 pinout->w_pixels = scale * (pinout->element.BoundingBox.X2 -
60 pinout->element.BoundingBox.X1);
61 pinout->h_pixels = scale * (pinout->element.BoundingBox.Y2 -
62 pinout->element.BoundingBox.Y1);
66 static void
67 pinout_set_data (GhidPinoutPreview * pinout, ElementType * element)
69 if (element == NULL)
71 FreeElementMemory (&pinout->element);
72 pinout->w_pixels = 0;
73 pinout->h_pixels = 0;
74 return;
77 /*
78 * copy element data
79 * enable output of pin and padnames
80 * move element to a 5% offset from zero position
81 * set all package lines/arcs to zero width
83 CopyElementLowLevel (NULL, &pinout->element, element, FALSE, 0, 0, FOUNDFLAG);
84 PIN_LOOP (&pinout->element);
86 SET_FLAG (DISPLAYNAMEFLAG, pin);
88 END_LOOP;
90 PAD_LOOP (&pinout->element);
92 SET_FLAG (DISPLAYNAMEFLAG, pad);
94 END_LOOP;
97 MoveElementLowLevel (NULL, &pinout->element,
98 Settings.PinoutOffsetX -
99 pinout->element.BoundingBox.X1,
100 Settings.PinoutOffsetY -
101 pinout->element.BoundingBox.Y1);
103 pinout_set_view (pinout);
105 ELEMENTLINE_LOOP (&pinout->element);
107 line->Thickness = 0;
109 END_LOOP;
111 ARC_LOOP (&pinout->element);
114 * for whatever reason setting a thickness of 0 causes the arcs to
115 * not display so pick 1 which does display but is still quite
116 * thin.
118 arc->Thickness = 1;
120 END_LOOP;
124 enum
126 PROP_ELEMENT_DATA = 1,
130 static GObjectClass *ghid_pinout_preview_parent_class = NULL;
133 /*! \brief GObject constructed
135 * \par Function Description
136 * Initialise the pinout preview object once it is constructed.
137 * Chain up in case the parent class wants to do anything too.
139 * \param [in] object The pinout preview object
141 static void
142 ghid_pinout_preview_constructed (GObject *object)
144 /* chain up to the parent class */
145 if (G_OBJECT_CLASS (ghid_pinout_preview_parent_class)->constructed != NULL)
146 G_OBJECT_CLASS (ghid_pinout_preview_parent_class)->constructed (object);
148 ghid_init_drawing_widget (GTK_WIDGET (object), gport);
153 /*! \brief GObject finalise handler
155 * \par Function Description
156 * Just before the GhidPinoutPreview GObject is finalized, free our
157 * allocated data, and then chain up to the parent's finalize handler.
159 * \param [in] widget The GObject being finalized.
161 static void
162 ghid_pinout_preview_finalize (GObject * object)
164 GhidPinoutPreview *pinout = GHID_PINOUT_PREVIEW (object);
166 /* Passing NULL for element data will free the old memory */
167 pinout_set_data (pinout, NULL);
169 G_OBJECT_CLASS (ghid_pinout_preview_parent_class)->finalize (object);
173 /*! \brief GObject property setter function
175 * \par Function Description
176 * Setter function for GhidPinoutPreview's GObject properties,
177 * "settings-name" and "toplevel".
179 * \param [in] object The GObject whose properties we are setting
180 * \param [in] property_id The numeric id. under which the property was
181 * registered with g_object_class_install_property()
182 * \param [in] value The GValue the property is being set from
183 * \param [in] pspec A GParamSpec describing the property being set
185 static void
186 ghid_pinout_preview_set_property (GObject * object, guint property_id,
187 const GValue * value, GParamSpec * pspec)
189 GhidPinoutPreview *pinout = GHID_PINOUT_PREVIEW (object);
190 GdkWindow *window = gtk_widget_get_window (GTK_WIDGET (pinout));
192 switch (property_id)
194 case PROP_ELEMENT_DATA:
195 pinout_set_data (pinout, (ElementType *)g_value_get_pointer (value));
196 if (window != NULL)
197 gdk_window_invalidate_rect (window, NULL, FALSE);
198 break;
199 default:
200 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
206 /*! \brief GObject property getter function
208 * \par Function Description
209 * Getter function for GhidPinoutPreview's GObject properties,
210 * "settings-name" and "toplevel".
212 * \param [in] object The GObject whose properties we are getting
213 * \param [in] property_id The numeric id. under which the property was
214 * registered with g_object_class_install_property()
215 * \param [out] value The GValue in which to return the value of the property
216 * \param [in] pspec A GParamSpec describing the property being got
218 static void
219 ghid_pinout_preview_get_property (GObject * object, guint property_id,
220 GValue * value, GParamSpec * pspec)
222 switch (property_id)
224 default:
225 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
231 /*! \brief GType class initialiser for GhidPinoutPreview
233 * \par Function Description
234 * GType class initialiser for GhidPinoutPreview. We override our parent
235 * virtual class methods as needed and register our GObject properties.
237 * \param [in] klass The GhidPinoutPreviewClass we are initialising
239 static void
240 ghid_pinout_preview_class_init (GhidPinoutPreviewClass * klass)
242 GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
243 GtkWidgetClass *gtk_widget_class = GTK_WIDGET_CLASS (klass);
245 gobject_class->finalize = ghid_pinout_preview_finalize;
246 gobject_class->set_property = ghid_pinout_preview_set_property;
247 gobject_class->get_property = ghid_pinout_preview_get_property;
248 gobject_class->constructed = ghid_pinout_preview_constructed;
250 gtk_widget_class->expose_event = ghid_pinout_preview_expose;
252 ghid_pinout_preview_parent_class = (GObjectClass *)g_type_class_peek_parent (klass);
254 g_object_class_install_property (gobject_class, PROP_ELEMENT_DATA,
255 g_param_spec_pointer ("element-data",
258 G_PARAM_WRITABLE));
262 /*! \brief Function to retrieve GhidPinoutPreview's GType identifier.
264 * \par Function Description
265 * Function to retrieve GhidPinoutPreview's GType identifier.
266 * Upon first call, this registers the GhidPinoutPreview in the GType system.
267 * Subsequently it returns the saved value from its first execution.
269 * \return the GType identifier associated with GhidPinoutPreview.
271 GType
272 ghid_pinout_preview_get_type ()
274 static GType ghid_pinout_preview_type = 0;
276 if (!ghid_pinout_preview_type)
278 static const GTypeInfo ghid_pinout_preview_info = {
279 sizeof (GhidPinoutPreviewClass),
280 NULL, /* base_init */
281 NULL, /* base_finalize */
282 (GClassInitFunc) ghid_pinout_preview_class_init,
283 NULL, /* class_finalize */
284 NULL, /* class_data */
285 sizeof (GhidPinoutPreview),
286 0, /* n_preallocs */
287 NULL, /* instance_init */
290 ghid_pinout_preview_type =
291 g_type_register_static (GTK_TYPE_DRAWING_AREA, "GhidPinoutPreview",
292 &ghid_pinout_preview_info, (GTypeFlags)0);
295 return ghid_pinout_preview_type;
299 /*! \brief Convenience function to create a new pinout preview
301 * \par Function Description
302 * Convenience function which creates a GhidPinoutPreview.
304 * \return The GhidPinoutPreview created.
306 GtkWidget *
307 ghid_pinout_preview_new (ElementType * element)
309 GhidPinoutPreview *pinout_preview;
311 pinout_preview = (GhidPinoutPreview *)g_object_new (GHID_TYPE_PINOUT_PREVIEW,
312 "element-data", element, NULL);
314 return GTK_WIDGET (pinout_preview);
318 /*! \brief Query the natural size of a pinout preview
320 * \par Function Description
321 * Convenience function to query the natural size of a pinout preview
323 void
324 ghid_pinout_preview_get_natural_size (GhidPinoutPreview * pinout,
325 int *width, int *height)
327 *width = pinout->w_pixels;
328 *height = pinout->h_pixels;