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 */
44 #include "gui-pinout-preview.h"
46 #ifdef HAVE_LIBDMALLOC
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.))
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
);
67 pinout_set_data (GhidPinoutPreview
* pinout
, ElementType
* element
)
71 FreeElementMemory (&pinout
->element
);
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
);
90 PAD_LOOP (&pinout
->element
);
92 SET_FLAG (DISPLAYNAMEFLAG
, pad
);
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
);
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
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
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.
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
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
));
194 case PROP_ELEMENT_DATA
:
195 pinout_set_data (pinout
, (ElementType
*)g_value_get_pointer (value
));
197 gdk_window_invalidate_rect (window
, NULL
, FALSE
);
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
219 ghid_pinout_preview_get_property (GObject
* object
, guint property_id
,
220 GValue
* value
, GParamSpec
* pspec
)
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
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",
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.
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
),
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.
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
324 ghid_pinout_preview_get_natural_size (GhidPinoutPreview
* pinout
,
325 int *width
, int *height
)
327 *width
= pinout
->w_pixels
;
328 *height
= pinout
->h_pixels
;