2 * @file GeneralFunctionDialog.cpp
3 * Implements the GeneralFunctionDialog class.
8 * Copyright 2012 Joel Baxter
10 * This file is part of MeshTex.
12 * MeshTex is free software: you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License as published by
14 * the Free Software Foundation, either version 2 of the License, or
15 * (at your option) any later version.
17 * MeshTex is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
22 * You should have received a copy of the GNU General Public License
23 * along with MeshTex. If not, see <http://www.gnu.org/licenses/>.
28 #include "GenericPluginUI.h"
29 #include "GeneralFunctionDialog.h"
30 #include "PluginUIMessages.h"
36 * Constructor. See MeshEntity::GeneralFunction for details of how these
37 * arguments are interpreted.
39 * @param sFactors Factors to determine the S texture coords; NULL if S
41 * @param tFactors Factors to determine the T texture coords; NULL if T
43 * @param alignRow Pointer to zero-point row; if NULL, row 0 is assumed.
44 * @param alignCol Pointer to zero-point column; if NULL, column 0 is
46 * @param refRow Pointer to reference row description, including how
47 * to use the reference; NULL if no reference.
48 * @param refCol Pointer to reference column description, including
49 * how to use the reference; NULL if no reference.
50 * @param surfaceValues true if calculations are for S/T values on the mesh
51 * surface; false if calculations are for S/T values at
54 GeneralFunctionDialog::GeneralFunctionVisitor::GeneralFunctionVisitor(
55 const MeshEntity::GeneralFunctionFactors *sFactors,
56 const MeshEntity::GeneralFunctionFactors *tFactors,
57 const MeshEntity::SliceDesignation *alignRow,
58 const MeshEntity::SliceDesignation *alignCol,
59 const MeshEntity::RefSliceDescriptor *refRow,
60 const MeshEntity::RefSliceDescriptor *refCol,
68 _surfaceValues(surfaceValues)
73 * Visitor action; invoke MeshEntity::GeneralFunction on a mesh.
75 * @param [in,out] meshEntity The mesh.
80 GeneralFunctionDialog::GeneralFunctionVisitor::Execute(MeshEntity& meshEntity) const
82 meshEntity.GeneralFunction(_sFactors, _tFactors,
83 _alignRow, _alignCol, _refRow, _refCol,
89 * Constructor. Configure the dialog window and create all the contained
90 * widgets. Connect widgets to callbacks as necessary.
92 * @param key The unique key identifying this dialog.
94 GeneralFunctionDialog::GeneralFunctionDialog(const std::string& key) :
96 _nullVisitor(new MeshVisitor())
98 // Enable the usual handling of the close event.
99 CreateWindowCloseCallback();
101 // Configure the dialog window.
102 gtk_window_set_resizable(GTK_WINDOW(_dialog), FALSE);
103 gtk_window_set_title(GTK_WINDOW(_dialog), DIALOG_GEN_FUNC_TITLE);
104 gtk_container_set_border_width(GTK_CONTAINER(_dialog), 10);
106 // Create the contained widgets.
110 GtkWidget *applybutton, *refbutton, *button;
111 GtkWidget *separator;
113 GtkWidget *mainvbox, *vbox, *hbox, *mainhbox;
116 table = gtk_table_new(6, 13, FALSE);
117 gtk_table_set_row_spacing(GTK_TABLE(table), 0, 5);
118 gtk_table_set_row_spacing(GTK_TABLE(table), 1, 10);
119 gtk_table_set_row_spacing(GTK_TABLE(table), 3, 15);
120 gtk_table_set_row_spacing(GTK_TABLE(table), 4, 15);
121 gtk_container_add(GTK_CONTAINER(_dialog), table);
122 gtk_widget_show(table);
124 hbox = gtk_hbox_new(TRUE, 10);
125 gtk_table_attach(GTK_TABLE(table), hbox, 0, 13, 0, 1, GTK_SHRINK, GTK_EXPAND, 0, 0);
126 gtk_widget_show(hbox);
128 // Mutually exclusive "Surface values" and "Control values" radio buttons.
130 button = gtk_radio_button_new_with_label(NULL,
131 DIALOG_GEN_FUNC_SURFACE_VALUES);
132 gtk_object_set_data(GTK_OBJECT(_dialog), "surface", button);
133 gtk_box_pack_start(GTK_BOX(hbox), button, FALSE, FALSE, 0);
134 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(button), TRUE);
135 gtk_widget_show(button);
137 button = gtk_radio_button_new_with_label(
138 gtk_radio_button_group(GTK_RADIO_BUTTON(button)),
139 DIALOG_GEN_FUNC_CONTROL_VALUES);
140 gtk_object_set_data(GTK_OBJECT(_dialog), "control", button);
141 gtk_box_pack_end(GTK_BOX(hbox), button, FALSE, FALSE, 0);
142 gtk_widget_show(button);
144 separator = gtk_hseparator_new();
145 gtk_table_attach_defaults(GTK_TABLE(table), separator, 0, 13, 1, 2);
146 gtk_widget_show(separator);
148 // Checkbox for the "S" row of factors. All the other widgets on this row
149 // will have a dependence registered on this checkbox; i.e. they will only
150 // be active when it is checked.
152 applybutton = gtk_check_button_new();
153 gtk_object_set_data(GTK_OBJECT(_dialog), "s_apply", applybutton);
154 gtk_table_attach_defaults(GTK_TABLE(table), applybutton, 0, 1, 2, 3);
155 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(applybutton), TRUE);
156 gtk_widget_show(applybutton);
158 label = gtk_label_new(DIALOG_GEN_FUNC_S_FUNC_LABEL);
159 gtk_table_attach_defaults(GTK_TABLE(table), label, 1, 2, 2, 3);
160 gtk_widget_show(label);
162 UIInstance().RegisterWidgetDependence(applybutton, label);
164 entry = gtk_entry_new();
165 gtk_object_set_data(GTK_OBJECT(_dialog), "s_oldval", entry);
166 gtk_entry_set_text(GTK_ENTRY(entry), "1.0");
167 gtk_table_attach_defaults(GTK_TABLE(table), entry, 2, 3, 2, 3);
168 gtk_widget_set_usize(entry, 50, -2);
169 gtk_widget_show(entry);
171 UIInstance().RegisterWidgetDependence(applybutton, entry);
173 label = gtk_label_new(DIALOG_GEN_FUNC_OLD_S_LABEL);
174 gtk_table_attach_defaults(GTK_TABLE(table), label, 3, 4, 2, 3);
175 gtk_widget_show(label);
177 UIInstance().RegisterWidgetDependence(applybutton, label);
179 entry = gtk_entry_new();
180 gtk_object_set_data(GTK_OBJECT(_dialog), "s_rowdist", entry);
181 gtk_entry_set_text(GTK_ENTRY(entry), "0.0");
182 gtk_table_attach_defaults(GTK_TABLE(table), entry, 4, 5, 2, 3);
183 gtk_widget_set_usize(entry, 50, -2);
184 gtk_widget_show(entry);
186 UIInstance().RegisterWidgetDependence(applybutton, entry);
188 label = gtk_label_new(DIALOG_GEN_FUNC_ROW_DIST_LABEL);
189 gtk_table_attach_defaults(GTK_TABLE(table), label, 5, 6, 2, 3);
190 gtk_widget_show(label);
192 UIInstance().RegisterWidgetDependence(applybutton, label);
194 entry = gtk_entry_new();
195 gtk_object_set_data(GTK_OBJECT(_dialog), "s_coldist", entry);
196 gtk_entry_set_text(GTK_ENTRY(entry), "0.0");
197 gtk_table_attach_defaults(GTK_TABLE(table), entry, 6, 7, 2, 3);
198 gtk_widget_set_usize(entry, 50, -2);
199 gtk_widget_show(entry);
201 UIInstance().RegisterWidgetDependence(applybutton, entry);
203 label = gtk_label_new(DIALOG_GEN_FUNC_COL_DIST_LABEL);
204 gtk_table_attach_defaults(GTK_TABLE(table), label, 7, 8, 2, 3);
205 gtk_widget_show(label);
207 UIInstance().RegisterWidgetDependence(applybutton, label);
209 entry = gtk_entry_new();
210 gtk_object_set_data(GTK_OBJECT(_dialog), "s_rownum", entry);
211 gtk_entry_set_text(GTK_ENTRY(entry), "0.0");
212 gtk_table_attach_defaults(GTK_TABLE(table), entry, 8, 9, 2, 3);
213 gtk_widget_set_usize(entry, 50, -2);
214 gtk_widget_show(entry);
216 UIInstance().RegisterWidgetDependence(applybutton, entry);
218 label = gtk_label_new(DIALOG_GEN_FUNC_ROW_NUM_LABEL);
219 gtk_table_attach_defaults(GTK_TABLE(table), label, 9, 10, 2, 3);
220 gtk_widget_show(label);
222 UIInstance().RegisterWidgetDependence(applybutton, label);
224 entry = gtk_entry_new();
225 gtk_object_set_data(GTK_OBJECT(_dialog), "s_colnum", entry);
226 gtk_entry_set_text(GTK_ENTRY(entry), "0.0");
227 gtk_table_attach_defaults(GTK_TABLE(table), entry, 10, 11, 2, 3);
228 gtk_widget_set_usize(entry, 50, -2);
229 gtk_widget_show(entry);
231 UIInstance().RegisterWidgetDependence(applybutton, entry);
233 label = gtk_label_new(DIALOG_GEN_FUNC_COL_NUM_LABEL);
234 gtk_table_attach_defaults(GTK_TABLE(table), label, 11, 12, 2, 3);
235 gtk_widget_show(label);
237 UIInstance().RegisterWidgetDependence(applybutton, label);
239 entry = gtk_entry_new();
240 gtk_object_set_data(GTK_OBJECT(_dialog), "s_constant", entry);
241 gtk_entry_set_text(GTK_ENTRY(entry), "0.0");
242 gtk_table_attach_defaults(GTK_TABLE(table), entry, 12, 13, 2, 3);
243 gtk_widget_set_usize(entry, 50, -2);
244 gtk_widget_show(entry);
246 UIInstance().RegisterWidgetDependence(applybutton, entry);
248 // Checkbox for the "T" row of factors. All the other widgets on this row
249 // will have a dependence registered on this checkbox; i.e. they will only
250 // be active when it is checked.
252 applybutton = gtk_check_button_new();
253 gtk_object_set_data(GTK_OBJECT(_dialog), "t_apply", applybutton);
254 gtk_table_attach_defaults(GTK_TABLE(table), applybutton, 0, 1, 3, 4);
255 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(applybutton), TRUE);
256 gtk_widget_show(applybutton);
258 label = gtk_label_new(DIALOG_GEN_FUNC_T_FUNC_LABEL);
259 gtk_table_attach_defaults(GTK_TABLE(table), label, 1, 2, 3, 4);
260 gtk_widget_show(label);
262 UIInstance().RegisterWidgetDependence(applybutton, label);
264 entry = gtk_entry_new();
265 gtk_object_set_data(GTK_OBJECT(_dialog), "t_oldval", entry);
266 gtk_entry_set_text(GTK_ENTRY(entry), "1.0");
267 gtk_table_attach_defaults(GTK_TABLE(table), entry, 2, 3, 3, 4);
268 gtk_widget_set_usize(entry, 50, -2);
269 gtk_widget_show(entry);
271 UIInstance().RegisterWidgetDependence(applybutton, entry);
273 label = gtk_label_new(DIALOG_GEN_FUNC_OLD_T_LABEL);
274 gtk_table_attach_defaults(GTK_TABLE(table), label, 3, 4, 3, 4);
275 gtk_widget_show(label);
277 UIInstance().RegisterWidgetDependence(applybutton, label);
279 entry = gtk_entry_new();
280 gtk_object_set_data(GTK_OBJECT(_dialog), "t_rowdist", entry);
281 gtk_entry_set_text(GTK_ENTRY(entry), "0.0");
282 gtk_table_attach_defaults(GTK_TABLE(table), entry, 4, 5, 3, 4);
283 gtk_widget_set_usize(entry, 50, -2);
284 gtk_widget_show(entry);
286 UIInstance().RegisterWidgetDependence(applybutton, entry);
288 label = gtk_label_new(DIALOG_GEN_FUNC_ROW_DIST_LABEL);
289 gtk_table_attach_defaults(GTK_TABLE(table), label, 5, 6, 3, 4);
290 gtk_widget_show(label);
292 UIInstance().RegisterWidgetDependence(applybutton, label);
294 entry = gtk_entry_new();
295 gtk_object_set_data(GTK_OBJECT(_dialog), "t_coldist", entry);
296 gtk_entry_set_text(GTK_ENTRY(entry), "0.0");
297 gtk_table_attach_defaults(GTK_TABLE(table), entry, 6, 7, 3, 4);
298 gtk_widget_set_usize(entry, 50, -2);
299 gtk_widget_show(entry);
301 UIInstance().RegisterWidgetDependence(applybutton, entry);
303 label = gtk_label_new(DIALOG_GEN_FUNC_COL_DIST_LABEL);
304 gtk_table_attach_defaults(GTK_TABLE(table), label, 7, 8, 3, 4);
305 gtk_widget_show(label);
307 UIInstance().RegisterWidgetDependence(applybutton, label);
309 entry = gtk_entry_new();
310 gtk_object_set_data(GTK_OBJECT(_dialog), "t_rownum", entry);
311 gtk_entry_set_text(GTK_ENTRY(entry), "0.0");
312 gtk_table_attach_defaults(GTK_TABLE(table), entry, 8, 9, 3, 4);
313 gtk_widget_set_usize(entry, 50, -2);
314 gtk_widget_show(entry);
316 UIInstance().RegisterWidgetDependence(applybutton, entry);
318 label = gtk_label_new(DIALOG_GEN_FUNC_ROW_NUM_LABEL);
319 gtk_table_attach_defaults(GTK_TABLE(table), label, 9, 10, 3, 4);
320 gtk_widget_show(label);
322 UIInstance().RegisterWidgetDependence(applybutton, label);
324 entry = gtk_entry_new();
325 gtk_object_set_data(GTK_OBJECT(_dialog), "t_colnum", entry);
326 gtk_entry_set_text(GTK_ENTRY(entry), "0.0");
327 gtk_table_attach_defaults(GTK_TABLE(table), entry, 10, 11, 3, 4);
328 gtk_widget_set_usize(entry, 50, -2);
329 gtk_widget_show(entry);
331 UIInstance().RegisterWidgetDependence(applybutton, entry);
333 label = gtk_label_new(DIALOG_GEN_FUNC_COL_NUM_LABEL);
334 gtk_table_attach_defaults(GTK_TABLE(table), label, 11, 12, 3, 4);
335 gtk_widget_show(label);
337 UIInstance().RegisterWidgetDependence(applybutton, label);
339 entry = gtk_entry_new();
340 gtk_object_set_data(GTK_OBJECT(_dialog), "t_constant", entry);
341 gtk_entry_set_text(GTK_ENTRY(entry), "0.0");
342 gtk_table_attach_defaults(GTK_TABLE(table), entry, 12, 13, 3, 4);
343 gtk_widget_set_usize(entry, 50, -2);
344 gtk_widget_show(entry);
346 UIInstance().RegisterWidgetDependence(applybutton, entry);
348 mainhbox = gtk_hbox_new(TRUE, 0);
349 gtk_table_attach(GTK_TABLE(table), mainhbox, 0, 13, 4, 5, GTK_SHRINK, GTK_EXPAND, 0, 0);
350 gtk_widget_show(mainhbox);
352 mainvbox = gtk_vbox_new(FALSE, 0);
353 gtk_box_pack_start(GTK_BOX(mainhbox), mainvbox, FALSE, FALSE, 0);
354 gtk_widget_show(mainvbox);
356 hbox = gtk_hbox_new(FALSE, 0);
357 gtk_box_pack_start(GTK_BOX(mainvbox), hbox, TRUE, TRUE, 5);
358 gtk_widget_show(hbox);
360 frame = gtk_frame_new(DIALOG_GEN_FUNC_COL_ALIGN_FRAME_LABEL);
361 gtk_box_pack_start(GTK_BOX(hbox), frame, TRUE, TRUE, 5);
362 gtk_widget_show(frame);
364 vbox = gtk_vbox_new(FALSE, 0);
365 gtk_container_add(GTK_CONTAINER(frame), vbox);
366 gtk_widget_show(vbox);
368 hbox = gtk_hbox_new(FALSE, 0);
369 gtk_box_pack_start(GTK_BOX(vbox), hbox, TRUE, TRUE, 5);
370 gtk_widget_show(hbox);
372 // Widgets for specifying the alignment column.
374 button = gtk_radio_button_new(NULL);
375 gtk_box_pack_start(GTK_BOX(hbox), button, FALSE, FALSE, 5);
376 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(button), TRUE);
377 gtk_widget_show(button);
379 entry = gtk_entry_new();
380 gtk_object_set_data(GTK_OBJECT(_dialog), "col_num_align", entry);
381 gtk_entry_set_text(GTK_ENTRY(entry), "0");
382 gtk_box_pack_start(GTK_BOX(hbox), entry, FALSE, FALSE, 5);
383 gtk_widget_set_usize(entry, 25, -2);
384 gtk_widget_show(entry);
386 UIInstance().RegisterWidgetDependence(button, entry);
388 button = gtk_radio_button_new_with_label(
389 gtk_radio_button_group(GTK_RADIO_BUTTON(button)),
390 DIALOG_GEN_FUNC_MAX_OPT_LABEL);
391 gtk_object_set_data(GTK_OBJECT(_dialog), "col_max_align", button);
392 gtk_box_pack_end(GTK_BOX(hbox), button, TRUE, FALSE, 5);
393 gtk_widget_show(button);
395 hbox = gtk_hbox_new(FALSE, 0);
396 gtk_box_pack_start(GTK_BOX(mainvbox), hbox, TRUE, TRUE, 5);
397 gtk_widget_show(hbox);
399 // Widgets for specifying the reference row & usage.
401 refbutton = gtk_check_button_new_with_label(DIALOG_GEN_FUNC_REF_ROW_FRAME_LABEL);
402 gtk_object_set_data(GTK_OBJECT(_dialog), "row_ref", refbutton);
403 gtk_widget_show(refbutton);
405 frame = gtk_frame_new(NULL);
406 gtk_frame_set_label_widget(GTK_FRAME(frame), refbutton);
407 gtk_box_pack_start(GTK_BOX(hbox), frame, TRUE, TRUE, 5);
408 gtk_widget_show(frame);
410 vbox = gtk_vbox_new(FALSE, 0);
411 gtk_container_add(GTK_CONTAINER(frame), vbox);
412 gtk_widget_show(vbox);
414 hbox = gtk_hbox_new(FALSE, 0);
415 gtk_box_pack_start(GTK_BOX(vbox), hbox, TRUE, TRUE, 5);
416 gtk_widget_show(hbox);
418 button = gtk_radio_button_new(NULL);
419 gtk_box_pack_start(GTK_BOX(hbox), button, FALSE, FALSE, 5);
420 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(button), TRUE);
421 gtk_widget_set_sensitive(button, FALSE);
422 gtk_widget_show(button);
424 UIInstance().RegisterWidgetDependence(refbutton, button);
426 entry = gtk_entry_new();
427 gtk_object_set_data(GTK_OBJECT(_dialog), "row_num_ref", entry);
428 gtk_entry_set_text(GTK_ENTRY(entry), "0");
429 gtk_box_pack_start(GTK_BOX(hbox), entry, FALSE, FALSE, 5);
430 gtk_widget_set_usize(entry, 25, -2);
431 gtk_widget_set_sensitive(entry, FALSE);
432 gtk_widget_show(entry);
434 UIInstance().RegisterWidgetDependence(refbutton, entry);
435 UIInstance().RegisterWidgetDependence(button, entry);
437 button = gtk_radio_button_new_with_label(
438 gtk_radio_button_group(GTK_RADIO_BUTTON(button)),
439 DIALOG_GEN_FUNC_MAX_OPT_LABEL);
440 gtk_object_set_data(GTK_OBJECT(_dialog), "row_max_ref", button);
441 gtk_box_pack_end(GTK_BOX(hbox), button, TRUE, FALSE, 5);
442 gtk_widget_set_sensitive(button, FALSE);
443 gtk_widget_show(button);
445 UIInstance().RegisterWidgetDependence(refbutton, button);
447 hbox = gtk_hbox_new(FALSE, 0);
448 gtk_box_pack_end(GTK_BOX(vbox), hbox, TRUE, TRUE, 5);
449 gtk_widget_show(hbox);
451 button = gtk_check_button_new_with_label(DIALOG_GEN_FUNC_REF_TOTAL_OPT_LABEL);
452 gtk_object_set_data(GTK_OBJECT(_dialog), "row_ref_total", button);
453 gtk_box_pack_start(GTK_BOX(hbox), button, FALSE, FALSE, 5);
454 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(button), TRUE);
455 gtk_widget_set_sensitive(button, FALSE);
456 gtk_widget_show(button);
458 UIInstance().RegisterWidgetDependence(refbutton, button);
460 mainvbox = gtk_vbox_new(FALSE, 0);
461 gtk_box_pack_end(GTK_BOX(mainhbox), mainvbox, FALSE, FALSE, 0);
462 gtk_widget_show(mainvbox);
464 hbox = gtk_hbox_new(FALSE, 0);
465 gtk_box_pack_start(GTK_BOX(mainvbox), hbox, TRUE, TRUE, 5);
466 gtk_widget_show(hbox);
468 frame = gtk_frame_new(DIALOG_GEN_FUNC_ROW_ALIGN_FRAME_LABEL);
469 gtk_box_pack_start(GTK_BOX(hbox), frame, TRUE, TRUE, 5);
470 gtk_widget_show(frame);
472 vbox = gtk_vbox_new(FALSE, 0);
473 gtk_container_add(GTK_CONTAINER(frame), vbox);
474 gtk_widget_show(vbox);
476 hbox = gtk_hbox_new(FALSE, 0);
477 gtk_box_pack_start(GTK_BOX(vbox), hbox, TRUE, TRUE, 5);
478 gtk_widget_show(hbox);
480 // Widgets for specifying the alignment row.
482 button = gtk_radio_button_new(NULL);
483 gtk_box_pack_start(GTK_BOX(hbox), button, FALSE, FALSE, 5);
484 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(button), TRUE);
485 gtk_widget_show(button);
487 entry = gtk_entry_new();
488 gtk_object_set_data(GTK_OBJECT(_dialog), "row_num_align", entry);
489 gtk_entry_set_text(GTK_ENTRY(entry), "0");
490 gtk_box_pack_start(GTK_BOX(hbox), entry, FALSE, FALSE, 5);
491 gtk_widget_set_usize(entry, 25, -2);
492 gtk_widget_show(entry);
494 UIInstance().RegisterWidgetDependence(button, entry);
496 button = gtk_radio_button_new_with_label(
497 gtk_radio_button_group(GTK_RADIO_BUTTON(button)),
498 DIALOG_GEN_FUNC_MAX_OPT_LABEL);
499 gtk_object_set_data(GTK_OBJECT(_dialog), "row_max_align", button);
500 gtk_box_pack_end(GTK_BOX(hbox), button, TRUE, FALSE, 5);
501 gtk_widget_show(button);
503 hbox = gtk_hbox_new(FALSE, 0);
504 gtk_box_pack_start(GTK_BOX(mainvbox), hbox, TRUE, TRUE, 5);
505 gtk_widget_show(hbox);
507 // Widgets for specifying the reference column & usage.
509 refbutton = gtk_check_button_new_with_label(DIALOG_GEN_FUNC_REF_COL_FRAME_LABEL);
510 gtk_object_set_data(GTK_OBJECT(_dialog), "col_ref", refbutton);
511 gtk_widget_show(refbutton);
513 frame = gtk_frame_new(NULL);
514 gtk_frame_set_label_widget(GTK_FRAME(frame), refbutton);
515 gtk_box_pack_start(GTK_BOX(hbox), frame, TRUE, TRUE, 5);
516 gtk_widget_show(frame);
518 vbox = gtk_vbox_new(FALSE, 0);
519 gtk_container_add(GTK_CONTAINER(frame), vbox);
520 gtk_widget_show(vbox);
522 hbox = gtk_hbox_new(FALSE, 0);
523 gtk_box_pack_start(GTK_BOX(vbox), hbox, TRUE, TRUE, 5);
524 gtk_widget_show(hbox);
526 button = gtk_radio_button_new(NULL);
527 gtk_box_pack_start(GTK_BOX(hbox), button, FALSE, FALSE, 5);
528 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(button), TRUE);
529 gtk_widget_set_sensitive(button, FALSE);
530 gtk_widget_show(button);
532 UIInstance().RegisterWidgetDependence(refbutton, button);
534 entry = gtk_entry_new();
535 gtk_object_set_data(GTK_OBJECT(_dialog), "col_num_ref", entry);
536 gtk_entry_set_text(GTK_ENTRY(entry), "0");
537 gtk_box_pack_start(GTK_BOX(hbox), entry, FALSE, FALSE, 5);
538 gtk_widget_set_usize(entry, 25, -2);
539 gtk_widget_set_sensitive(entry, FALSE);
540 gtk_widget_show(entry);
542 UIInstance().RegisterWidgetDependence(refbutton, entry);
543 UIInstance().RegisterWidgetDependence(button, entry);
545 button = gtk_radio_button_new_with_label(
546 gtk_radio_button_group(GTK_RADIO_BUTTON(button)),
547 DIALOG_GEN_FUNC_MAX_OPT_LABEL);
548 gtk_object_set_data(GTK_OBJECT(_dialog), "col_max_ref", button);
549 gtk_box_pack_end(GTK_BOX(hbox), button, TRUE, FALSE, 5);
550 gtk_widget_set_sensitive(button, FALSE);
551 gtk_widget_show(button);
553 UIInstance().RegisterWidgetDependence(refbutton, button);
555 hbox = gtk_hbox_new(FALSE, 0);
556 gtk_box_pack_end(GTK_BOX(vbox), hbox, TRUE, TRUE, 5);
557 gtk_widget_show(hbox);
559 button = gtk_check_button_new_with_label(DIALOG_GEN_FUNC_REF_TOTAL_OPT_LABEL);
560 gtk_object_set_data(GTK_OBJECT(_dialog), "col_ref_total", button);
561 gtk_box_pack_start(GTK_BOX(hbox), button, FALSE, FALSE, 5);
562 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(button), TRUE);
563 gtk_widget_set_sensitive(button, FALSE);
564 gtk_widget_show(button);
566 UIInstance().RegisterWidgetDependence(refbutton, button);
568 hbox = gtk_hbox_new(FALSE, 0);
569 gtk_table_attach_defaults(GTK_TABLE(table), hbox, 0, 13, 5, 6);
570 gtk_widget_show(hbox);
572 // Create Cancel button and hook it to callback.
574 button = gtk_button_new_with_label(DIALOG_CANCEL_BUTTON);
575 gtk_box_pack_end(GTK_BOX(hbox), button, FALSE, FALSE, 0);
576 gtk_widget_set_usize(button, 60, -2);
577 gtk_widget_show(button);
579 CreateCancelButtonCallback(button);
581 // Create Apply button and hook it to callback.
583 button = gtk_button_new_with_label(DIALOG_APPLY_BUTTON);
584 gtk_box_pack_end(GTK_BOX(hbox), button, FALSE, FALSE, 10);
585 gtk_widget_set_usize (button, 60, -2);
586 gtk_widget_show(button);
588 CreateApplyButtonCallback(button);
590 // Create OK button and hook it to callback.
592 button = gtk_button_new_with_label(DIALOG_OK_BUTTON);
593 gtk_box_pack_end(GTK_BOX(hbox), button, FALSE, FALSE, 0);
594 gtk_widget_set_usize (button, 60, -2);
595 gtk_widget_show(button);
597 CreateOkButtonCallback(button);
603 GeneralFunctionDialog::~GeneralFunctionDialog()
608 * Handler for the Apply logic for this dialog. Apply the specified equations
609 * to the selected mesh entities.
611 * @return true if any meshes are selected, false otherwise.
614 GeneralFunctionDialog::Apply()
616 // Before doing anything, check to see if there are some meshes selected.
617 _nullVisitor->ResetVisitedCount();
618 GlobalSelectionSystem().foreachSelected(*_nullVisitor);
619 if (_nullVisitor->GetVisitedCount() == 0)
621 // Nope. Warn and bail out.
622 GenericPluginUI::WarningReportDialog(DIALOG_WARNING_TITLE,
623 DIALOG_NOMESHES_MSG);
627 // See if we're going to be affecting the S and/or T texture axis.
628 bool sApply = NamedToggleWidgetActive("s_apply");
629 bool tApply = NamedToggleWidgetActive("t_apply");
631 if (!sApply && !tApply)
633 // Not affecting either, so bail out.
637 // OK read the remaining info from the widgets.
639 MeshEntity::GeneralFunctionFactors s, t;
640 MeshEntity::GeneralFunctionFactors *sFactors = NULL;
641 MeshEntity::GeneralFunctionFactors *tFactors = NULL;
644 // S axis is affected, so read the S factors.
645 s.oldValue = (float)atof(NamedEntryWidgetText("s_oldval"));
646 s.rowDistance = (float)atof(NamedEntryWidgetText("s_rowdist"));
647 s.colDistance = (float)atof(NamedEntryWidgetText("s_coldist"));
648 s.rowNumber = (float)atof(NamedEntryWidgetText("s_rownum"));
649 s.colNumber = (float)atof(NamedEntryWidgetText("s_colnum"));
650 s.constant = (float)atof(NamedEntryWidgetText("s_constant"));
655 // T axis is affected, so read the T factors.
656 t.oldValue = (float)atof(NamedEntryWidgetText("t_oldval"));
657 t.rowDistance = (float)atof(NamedEntryWidgetText("t_rowdist"));
658 t.colDistance = (float)atof(NamedEntryWidgetText("t_coldist"));
659 t.rowNumber = (float)atof(NamedEntryWidgetText("t_rownum"));
660 t.colNumber = (float)atof(NamedEntryWidgetText("t_colnum"));
661 t.constant = (float)atof(NamedEntryWidgetText("t_constant"));
664 MeshEntity::SliceDesignation alignRow, alignCol;
665 alignRow.maxSlice = NamedToggleWidgetActive("row_max_align");
666 alignRow.index = atoi(NamedEntryWidgetText("row_num_align"));
667 alignCol.maxSlice = NamedToggleWidgetActive("col_max_align");
668 alignCol.index = atoi(NamedEntryWidgetText("col_num_align"));
669 MeshEntity::RefSliceDescriptor row, col;
670 MeshEntity::RefSliceDescriptor *refRow = NULL;
671 MeshEntity::RefSliceDescriptor *refCol = NULL;
672 if (NamedToggleWidgetActive("row_ref"))
674 // Reference row is specified, so get that info.
675 row.designation.maxSlice = NamedToggleWidgetActive("row_max_ref");
676 row.designation.index = atoi(NamedEntryWidgetText("row_num_ref"));
677 row.totalLengthOnly = NamedToggleWidgetActive("row_ref_total");
680 if (NamedToggleWidgetActive("col_ref"))
682 // Reference column is specified, so get that info.
683 col.designation.maxSlice = NamedToggleWidgetActive("col_max_ref");
684 col.designation.index = atoi(NamedEntryWidgetText("col_num_ref"));
685 col.totalLengthOnly = NamedToggleWidgetActive("col_ref_total");
688 bool surfaceValues = NamedToggleWidgetActive("surface");
690 // Let Radiant know the name of the operation responsible for the changes
691 // that are about to happen.
692 UndoableCommand undo(_triggerCommand.c_str());
694 // Apply the specified equation to every selected mesh.
695 SmartPointer<GeneralFunctionVisitor> funcVisitor(
696 new GeneralFunctionVisitor(sFactors, tFactors,
697 &alignRow, &alignCol, refRow, refCol,
699 GlobalSelectionSystem().foreachSelected(*funcVisitor);