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 written by Bill Wilson for the PCB Gtk port. */
38 #include "pcb-printf.h"
40 #ifdef HAVE_LIBDMALLOC
44 static GtkWidget
*export_dialog
= NULL
;
47 set_flag_cb (GtkToggleButton
* button
, void * flag
)
49 *(gboolean
*)flag
= gtk_toggle_button_get_active (button
);
54 intspinner_changed_cb (GtkSpinButton
* spin_button
, gpointer data
)
56 int *ival
= (int *)data
;
58 *ival
= gtk_spin_button_get_value (GTK_SPIN_BUTTON ((GtkWidget
*)spin_button
));
62 coordentry_changed_cb (GtkEntry
* entry
, Coord
* res
)
64 const gchar
*s
= gtk_entry_get_text (entry
);
65 *res
= GetValue (s
, NULL
, NULL
);
69 dblspinner_changed_cb (GtkSpinButton
* spin_button
, gpointer data
)
71 double *dval
= (double *)data
;
73 *dval
= gtk_spin_button_get_value (GTK_SPIN_BUTTON ((GtkWidget
*)spin_button
));
78 entry_changed_cb (GtkEntry
* entry
, char **str
)
82 s
= gtk_entry_get_text (entry
);
90 enum_changed_cb (GtkWidget
* combo_box
, int *val
)
94 active
= gtk_combo_box_get_active (GTK_COMBO_BOX (combo_box
));
100 ghid_attribute_dialog (HID_Attribute
* attrs
,
101 int n_attrs
, HID_Attr_Val
* results
,
106 GtkWidget
*content_area
;
107 GtkWidget
*main_vbox
, *vbox
, *vbox1
, *hbox
, *entry
;
110 GHidPort
*out
= &ghid_port
;
114 dialog
= gtk_dialog_new_with_buttons (_(title
),
115 GTK_WINDOW (out
->top_window
),
116 (GtkDialogFlags
)(GTK_DIALOG_MODAL
117 | GTK_DIALOG_DESTROY_WITH_PARENT
),
118 GTK_STOCK_CANCEL
, GTK_RESPONSE_NONE
,
119 GTK_STOCK_OK
, GTK_RESPONSE_OK
, NULL
);
120 gtk_window_set_wmclass (GTK_WINDOW (dialog
), "PCB_attribute_editor", "PCB");
122 content_area
= gtk_dialog_get_content_area (GTK_DIALOG (dialog
));
124 main_vbox
= gtk_vbox_new (FALSE
, 6);
125 gtk_container_set_border_width (GTK_CONTAINER (main_vbox
), 6);
126 gtk_container_add (GTK_CONTAINER (content_area
), main_vbox
);
128 vbox
= ghid_category_vbox (main_vbox
, descr
!= NULL
? descr
: "",
132 * Iterate over all the export options and build up a dialog box
133 * that lets us control all of the options. By doing things this
134 * way, any changes to the exporter HID's automatically are
135 * reflected in this dialog box.
137 for (j
= 0; j
< n_attrs
; j
++)
139 const Unit
*unit_list
;
140 if (attrs
[j
].help_text
== ATTR_UNDOCUMENTED
)
142 switch (attrs
[j
].type
)
145 widget
= gtk_label_new (attrs
[j
].name
);
146 gtk_box_pack_start (GTK_BOX (vbox
), widget
, FALSE
, FALSE
, 0);
147 gtk_widget_set_tooltip_text (widget
, attrs
[j
].help_text
);
151 hbox
= gtk_hbox_new (FALSE
, 4);
152 gtk_box_pack_start (GTK_BOX (vbox
), hbox
, FALSE
, FALSE
, 0);
156 * need to pick the "digits" argument based on min/max
159 ghid_spin_button (hbox
, &widget
, attrs
[j
].default_val
.int_value
,
160 attrs
[j
].min_val
, attrs
[j
].max_val
, 1.0, 1.0, 0, 0,
161 intspinner_changed_cb
,
162 &(attrs
[j
].default_val
.int_value
), FALSE
, NULL
);
163 gtk_widget_set_tooltip_text (widget
, attrs
[j
].help_text
);
165 widget
= gtk_label_new (attrs
[j
].name
);
166 gtk_box_pack_start (GTK_BOX (hbox
), widget
, FALSE
, FALSE
, 0);
170 hbox
= gtk_hbox_new (FALSE
, 4);
171 gtk_box_pack_start (GTK_BOX (vbox
), hbox
, FALSE
, FALSE
, 0);
173 entry
= ghid_coord_entry_new (attrs
[j
].min_val
, attrs
[j
].max_val
,
174 attrs
[j
].default_val
.coord_value
,
175 Settings
.grid_unit
, CE_SMALL
);
176 gtk_box_pack_start (GTK_BOX (hbox
), entry
, FALSE
, FALSE
, 0);
177 if(attrs
[j
].default_val
.str_value
!= NULL
)
178 gtk_entry_set_text (GTK_ENTRY (entry
),
179 attrs
[j
].default_val
.str_value
);
180 gtk_widget_set_tooltip_text (entry
, attrs
[j
].help_text
);
181 g_signal_connect (G_OBJECT (entry
), "changed",
182 G_CALLBACK (coordentry_changed_cb
),
183 &(attrs
[j
].default_val
.coord_value
));
185 widget
= gtk_label_new (attrs
[j
].name
);
186 gtk_box_pack_start (GTK_BOX (hbox
), widget
, FALSE
, FALSE
, 0);
190 hbox
= gtk_hbox_new (FALSE
, 4);
191 gtk_box_pack_start (GTK_BOX (vbox
), hbox
, FALSE
, FALSE
, 0);
195 * need to pick the "digits" and step size argument more
198 ghid_spin_button (hbox
, &widget
, attrs
[j
].default_val
.real_value
,
199 attrs
[j
].min_val
, attrs
[j
].max_val
, 0.01, 0.01, 3,
201 dblspinner_changed_cb
,
202 &(attrs
[j
].default_val
.real_value
), FALSE
, NULL
);
204 gtk_widget_set_tooltip_text (widget
, attrs
[j
].help_text
);
206 widget
= gtk_label_new (attrs
[j
].name
);
207 gtk_box_pack_start (GTK_BOX (hbox
), widget
, FALSE
, FALSE
, 0);
211 hbox
= gtk_hbox_new (FALSE
, 4);
212 gtk_box_pack_start (GTK_BOX (vbox
), hbox
, FALSE
, FALSE
, 0);
214 entry
= gtk_entry_new ();
215 gtk_box_pack_start (GTK_BOX (hbox
), entry
, FALSE
, FALSE
, 0);
216 if(attrs
[j
].default_val
.str_value
!= NULL
)
217 gtk_entry_set_text (GTK_ENTRY (entry
),
218 attrs
[j
].default_val
.str_value
);
219 gtk_widget_set_tooltip_text (entry
, attrs
[j
].help_text
);
220 g_signal_connect (G_OBJECT (entry
), "changed",
221 G_CALLBACK (entry_changed_cb
),
222 &(attrs
[j
].default_val
.str_value
));
224 widget
= gtk_label_new (attrs
[j
].name
);
225 gtk_box_pack_start (GTK_BOX (hbox
), widget
, FALSE
, FALSE
, 0);
229 /* put this in a check button */
230 ghid_check_button_connected (vbox
, &widget
,
231 attrs
[j
].default_val
.int_value
,
232 TRUE
, FALSE
, FALSE
, 0, set_flag_cb
,
233 &(attrs
[j
].default_val
.int_value
),
235 gtk_widget_set_tooltip_text (widget
, attrs
[j
].help_text
);
239 hbox
= gtk_hbox_new (FALSE
, 4);
240 gtk_box_pack_start (GTK_BOX (vbox
), hbox
, FALSE
, FALSE
, 0);
243 combo
= gtk_combo_box_new_text ();
244 gtk_widget_set_tooltip_text (combo
, attrs
[j
].help_text
);
245 gtk_box_pack_start (GTK_BOX (hbox
), combo
, FALSE
, FALSE
, 0);
246 g_signal_connect (G_OBJECT (combo
), "changed",
247 G_CALLBACK (enum_changed_cb
),
248 &(attrs
[j
].default_val
.int_value
));
252 * Iterate through each value and add them to the
256 while (attrs
[j
].enumerations
[i
])
258 gtk_combo_box_append_text (GTK_COMBO_BOX (combo
),
259 attrs
[j
].enumerations
[i
]);
262 gtk_combo_box_set_active (GTK_COMBO_BOX (combo
),
263 attrs
[j
].default_val
.int_value
);
264 widget
= gtk_label_new (attrs
[j
].name
);
265 gtk_box_pack_start (GTK_BOX (hbox
), widget
, FALSE
, FALSE
, 0);
269 hbox
= gtk_hbox_new (FALSE
, 4);
270 gtk_box_pack_start (GTK_BOX (vbox
), hbox
, FALSE
, FALSE
, 0);
274 * need to pick the "digits" and step size argument more
277 ghid_spin_button (hbox
, &widget
, attrs
[j
].default_val
.real_value
,
278 attrs
[j
].min_val
, attrs
[j
].max_val
, 0.01, 0.01, 3,
280 dblspinner_changed_cb
,
281 &(attrs
[j
].default_val
.real_value
), FALSE
, NULL
);
282 gtk_widget_set_tooltip_text (widget
, attrs
[j
].help_text
);
288 vbox1
= ghid_category_vbox (vbox
, attrs
[j
].name
, 4, 2, TRUE
, TRUE
);
289 entry
= gtk_entry_new ();
290 gtk_box_pack_start (GTK_BOX (vbox1
), entry
, FALSE
, FALSE
, 0);
291 gtk_entry_set_text (GTK_ENTRY (entry
),
292 attrs
[j
].default_val
.str_value
);
293 g_signal_connect (G_OBJECT (entry
), "changed",
294 G_CALLBACK (entry_changed_cb
),
295 &(attrs
[j
].default_val
.str_value
));
297 gtk_widget_set_tooltip_text (entry
, attrs
[j
].help_text
);
301 unit_list
= get_unit_list ();
304 hbox
= gtk_hbox_new (FALSE
, 4);
305 gtk_box_pack_start (GTK_BOX (vbox
), hbox
, FALSE
, FALSE
, 0);
307 combo
= gtk_combo_box_new_text ();
308 gtk_widget_set_tooltip_text (combo
, attrs
[j
].help_text
);
309 gtk_box_pack_start (GTK_BOX (hbox
), combo
, FALSE
, FALSE
, 0);
310 g_signal_connect (G_OBJECT (combo
), "changed",
311 G_CALLBACK (enum_changed_cb
),
312 &(attrs
[j
].default_val
.int_value
));
315 * Iterate through each value and add them to the
318 for (i
= 0; i
< n
; ++i
)
319 gtk_combo_box_append_text (GTK_COMBO_BOX (combo
),
320 unit_list
[i
].in_suffix
);
321 gtk_combo_box_set_active (GTK_COMBO_BOX (combo
),
322 attrs
[j
].default_val
.int_value
);
323 widget
= gtk_label_new (attrs
[j
].name
);
324 gtk_box_pack_start (GTK_BOX (hbox
), widget
, FALSE
, FALSE
, 0);
327 printf ("%s: unknown type of HID attribute\n", __FUNCTION__
);
333 gtk_widget_show_all (dialog
);
335 if (gtk_dialog_run (GTK_DIALOG (dialog
)) == GTK_RESPONSE_OK
)
337 /* copy over the results */
338 for (i
= 0; i
< n_attrs
; i
++)
340 results
[i
] = attrs
[i
].default_val
;
341 if (results
[i
].str_value
)
342 results
[i
].str_value
= strdup (results
[i
].str_value
);
349 gtk_widget_destroy (dialog
);
357 exporter_clicked_cb (GtkButton
* button
, HID
* exporter
)
359 ghid_dialog_print (exporter
);
363 ghid_dialog_print (HID
*hid
)
368 HID_Attr_Val
* results
= NULL
;
370 /* signal the initial export select dialog that it should close */
372 gtk_dialog_response (GTK_DIALOG (export_dialog
), GTK_RESPONSE_CANCEL
);
376 attr
= exporter
->get_export_options (&n
);
379 results
= (HID_Attr_Val
*) malloc (n
* sizeof (HID_Attr_Val
));
382 fprintf (stderr
, "%s() -- malloc failed\n", __FUNCTION__
);
386 /* non-zero means cancel was picked */
387 if (ghid_attribute_dialog (attr
, n
, results
, _("PCB Print Layout"),
388 exporter
->description
))
393 exporter
->do_export (results
);
395 for (i
= 0; i
< n
; i
++)
397 if (results
[i
].str_value
)
398 free ((void *) results
[i
].str_value
);
408 ghid_dialog_export (void)
410 GtkWidget
*content_area
;
411 GtkWidget
*vbox
, *button
;
412 GHidPort
*out
= &ghid_port
;
415 gboolean no_exporter
= TRUE
;
417 export_dialog
= gtk_dialog_new_with_buttons (_("PCB Export Layout"),
418 GTK_WINDOW (out
->top_window
),
419 (GtkDialogFlags
)(GTK_DIALOG_MODAL
421 GTK_DIALOG_DESTROY_WITH_PARENT
),
423 GTK_RESPONSE_CANCEL
, NULL
);
424 gtk_window_set_wmclass (GTK_WINDOW (export_dialog
), "PCB_Export", "PCB");
426 content_area
= gtk_dialog_get_content_area (GTK_DIALOG (export_dialog
));
428 vbox
= gtk_vbox_new (FALSE
, 6);
429 gtk_container_set_border_width (GTK_CONTAINER (vbox
), 6);
430 gtk_container_add (GTK_CONTAINER (content_area
), vbox
);
433 * Iterate over all the export HID's and build up a dialog box that
434 * lets us choose which one we want to use.
435 * This way, any additions to the exporter HID's automatically are
436 * reflected in this dialog box.
439 hids
= hid_enumerate ();
440 for (i
= 0; hids
[i
]; i
++)
442 if (hids
[i
]->exporter
)
445 button
= gtk_button_new_with_label (hids
[i
]->name
);
446 gtk_widget_set_tooltip_text (button
, hids
[i
]->description
);
447 gtk_box_pack_start (GTK_BOX (vbox
), button
, FALSE
, FALSE
, 0);
448 g_signal_connect (G_OBJECT (button
), "clicked",
449 G_CALLBACK (exporter_clicked_cb
), hids
[i
]);
455 gui
->log (_("Can't find a suitable exporter HID"));
458 gtk_widget_show_all (export_dialog
);
459 gtk_dialog_run (GTK_DIALOG (export_dialog
));
461 if (export_dialog
!= NULL
)
462 gtk_widget_destroy (export_dialog
);
463 export_dialog
= NULL
;