1 /* fault_dialog.c: dialogs and callbacks for drawing a fault
2 *
3 * Copyright (C) 2003 Patrice St-Gelais
4 * patrstg@users.sourceforge.net
5 * www.oricom.ca/patrice.st-gelais
6 *
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.
11 *
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.
16 *
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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
20 */
21
22 #include "fault.h"
23 #include "draw_tools_dialog.h"
24 #include "dialog_utilities.h"
25 #include "line_dialog.h"
26 #include <gtk/gtk.h>
27 // #include "../utils/menus_n_tools.h"
28 #include "globals.h"
29 // #include "view_area.h"
30 #include "hf_wrapper.h"
31
display_fault_line(gpointer hf_wrapper,gint x0,gint y0,gint x1,gint y1)32 void display_fault_line (gpointer hf_wrapper, gint x0, gint y0, gint x1, gint y1) {
33 // Display the fault line only, without computing the altitude difference,
34 // typically when the mouse moves
35 // 2006-01: not used anymore - seems to be kept for testing purposes only
36 // (e.g. displaying the polyline in the HF)
37
38 gdouble ddist, startx=0.0, starty=0.0, endx=0.0, endy=0.0;
39 hf_type value = 0;
40 fault_struct *f;
41 hf_wrapper_struct *hfw = (hf_wrapper_struct *) hf_wrapper;
42
43 // We need TMP_BUF for buffering the original HF, when displaying the fault line
44 if (!hfw->hf_struct->tmp_buf)
45 hf_backup(hfw->hf_struct);
46
47 hf_restore(hfw->hf_struct);
48
49 f = hfw->hf_options->draw->fault_pen;
50
51 // First we compute the axis on which to draw the line
52 // We extend the line marked by the mouse from edge to edge
53
54 if (! intersect_rect (0,0,hfw->hf_struct->max_x-1, hfw->hf_struct->max_y-1,
55 x0, y0, x1, y1, &startx, &starty, &endx, &endy) )
56 return;
57 // printf("********* Master line: (%d,%d) - (%d,%d); extended line: (%d, %d) - (%d, %d)\n",x0,y0,x1,y1,startx, starty, endx, endy);
58 // set_line_translation (f->line, startx, starty,
59 // hfw->hf_struct->max_x, hfw->hf_struct->max_y );
60
61 ddist = DIST2(startx, starty, endx, endy);
62 set_line_scale (f->fractal_line->polyline, ddist, ddist);
63
64 draw_n_transform_all_segments (f->fractal_line->polyline,
65 endx-startx, endy-starty,
66 startx, starty,
67 (gpointer) hfw->hf_struct->hf_buf,
68 hfw->hf_struct->max_x,
69 hfw->hf_struct->max_y,
70 (gpointer) &value,
71 HF_TYPE_ID,
72 OVERFLOW_ZERO);
73
74 // hf_simple_merge (hfw->hf_struct->tmp_buf, f->buffer,hfw->hf_struct->hf_buf , 100,
75 // 0, 0, f->buf_size, f->buf_size, MULTIPLY);
76
77 draw_hf(hfw);
78 }
79
update_fault_callb(GtkWidget * wdg,gpointer data)80 static gint update_fault_callb (GtkWidget *wdg, gpointer data) {
81 draw_tools_struct *dts;
82 hf_wrapper_struct *hfw;
83 hfw = (hf_wrapper_struct *) * (hf_wrapper_struct **) data;
84
85 // printf("UPDATE_FAULT_CALLB\n");
86 // Compute only if a control line is active
87 if (!hfw->control_line)
88 return TRUE;
89 if (!hfw->control_line->active)
90 return TRUE;
91
92 dts = hfw->hf_options->draw;
93
94 if (hfw->control_line->revert_ends) {
95 compute_fault (dts->fault_pen, hfw->hf_struct,
96 LEFT_SHIFT((gint) hfw->control_line->x1, get_scale(hfw->sbs)),
97 LEFT_SHIFT((gint) hfw->control_line->y1, get_scale(hfw->sbs)),
98 LEFT_SHIFT((gint) hfw->control_line->x0, get_scale(hfw->sbs)),
99 LEFT_SHIFT((gint) hfw->control_line->y0, get_scale(hfw->sbs)),
100 hfw->hf_options->dist_matrix,
101 hfw->hf_options->gauss_list);
102 }
103 else {
104 compute_fault (dts->fault_pen, hfw->hf_struct,
105 LEFT_SHIFT((gint) hfw->control_line->x1, get_scale(hfw->sbs)),
106 LEFT_SHIFT((gint) hfw->control_line->y1, get_scale(hfw->sbs)),
107 LEFT_SHIFT((gint) hfw->control_line->x0, get_scale(hfw->sbs)),
108 LEFT_SHIFT((gint) hfw->control_line->y0, get_scale(hfw->sbs)),
109 hfw->hf_options->dist_matrix,
110 hfw->hf_options->gauss_list);
111 }
112 gtk_widget_set_sensitive (GTK_WIDGET(dts->fault_accept), TRUE);
113 draw_hf(hfw);
114 return FALSE;
115 }
116
accept_fault_fn(hf_wrapper_struct * hfw)117 void accept_fault_fn (hf_wrapper_struct *hfw) {
118 // printf("ACCEPT_FAULT_FN\n");
119 if (!hfw)
120 return;
121 hf_backup(hfw->hf_struct);
122 commit_pending_record(hfw);
123 // Here, reset the control widgets if needed
124 hfw->if_calculated = FALSE;
125 control_line_unactivate (hfw->control_line);
126 // Faults remove tiling most of the time
127 if (hfw->tiling_ptr) {
128 *hfw->tiling_ptr = FALSE;
129 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(hfw->tiling_wdg),*hfw->tiling_ptr);
130 }
131 draw_hf(hfw);
132 }
133
accept_fault_callb(GtkWidget * wdg,gpointer data)134 static gint accept_fault_callb (GtkWidget *wdg, gpointer data) {
135 hf_wrapper_struct *hfw;
136 if (!data)
137 return FALSE;
138 hfw = (hf_wrapper_struct *) * (hf_wrapper_struct **) data;
139 accept_fault_fn (hfw);
140 return FALSE;
141 }
142
reset_fault_callb(GtkWidget * wdg,gpointer data)143 static gint reset_fault_callb(GtkWidget *wdg, gpointer data) {
144 // Cancels the current operation by copying the temp buffer (backuped)
145 // into the current (modified) one
146 hf_wrapper_struct *hfw;
147 hfw = (hf_wrapper_struct *) * (hf_wrapper_struct **) data;
148
149 hf_restore (hfw->hf_struct);
150 // Here, reset the control widgets if needed
151 control_line_unactivate (hfw->control_line);
152 draw_hf(hfw);
153 return FALSE;
154 }
155
unset_preview_mode(GtkWidget * widget,GdkEventButton * event,gpointer data)156 static gint unset_preview_mode (GtkWidget *widget, GdkEventButton *event, gpointer data) {
157 hf_wrapper_struct *hfw;
158 hfw = (hf_wrapper_struct *) * (hf_wrapper_struct **) data;
159 if (!hfw)
160 return FALSE;
161 if (!hfw->hf_options->draw)
162 return FALSE;
163 hfw->hf_options->draw->fault_pen->mode = FAULT_FINAL;
164 // printf("UNSET_PREVIEW_MODE\n");
165 hfw->gl_preview->refresh_on_mouse_down = TRUE;
166 // We need to recompute the fault once after releasing the mouse button
167 update_fault_callb (NULL,data);
168 return FALSE;
169 }
170
set_preview_mode(GtkWidget * widget,GdkEventButton * event,gpointer data)171 static gint set_preview_mode (GtkWidget *widget, GdkEventButton *event, gpointer data) {
172 gint *mode;
173 mode = (gint *) data;
174 if (!mode)
175 return FALSE;
176 *mode = FAULT_PREVIEW;
177 return FALSE;
178 // printf("SET_PREVIEW_MODE\n");
179 }
180
set_preview_mode_on_hfw(GtkWidget * widget,GdkEventButton * event,gpointer data)181 static gint set_preview_mode_on_hfw (GtkWidget *widget, GdkEventButton *event, gpointer data) {
182 hf_wrapper_struct *hfw;
183 hfw = (hf_wrapper_struct *) * (hf_wrapper_struct **) data;
184 if (!hfw)
185 return FALSE;
186 if (!hfw->hf_options->draw)
187 return FALSE;
188 hfw->hf_options->draw->fault_pen->mode = FAULT_PREVIEW;
189 hfw->gl_preview->refresh_on_mouse_down = FALSE;
190 // printf("SET_PREVIEW_MODE\n");
191 return FALSE;
192 }
193
fault_dialog_new(GtkWidget * window,GtkTooltips * tooltips,gpointer dts_ptr,gpointer data)194 GtkWidget *fault_dialog_new(GtkWidget *window, GtkTooltips *tooltips,
195 gpointer dts_ptr, gpointer data) {
196
197 // Note: data is a hf_wrapper_struct **
198 GtkWidget *frame, *vbox, *hbox, *hbox2, *wdg, *button, *scale;
199 GtkObject *adj;
200 fault_struct *pen;
201 draw_tools_struct *dts = (draw_tools_struct *) dts_ptr;
202
203 pen = dts->fault_pen;
204
205 vbox = gtk_vbox_new(FALSE, 0);
206 gtk_widget_show(vbox);
207
208 frame = frame_new("Pen - fault",0.5*DEF_PAD);
209 gtk_container_add(GTK_CONTAINER(frame),vbox);
210
211 dts->fault_line_dialog =
212 line_dialog_new (window, tooltips, "Fracture line", pen->fractal_line,
213 FAULT_PREVIEW_SIZE, FAULT_PREVIEW_SIZE,
214 data, update_fault_callb, set_preview_mode_on_hfw, unset_preview_mode);
215
216 gtk_box_pack_start(GTK_BOX(vbox), dts->fault_line_dialog->dialog,
217 FALSE, FALSE, DEF_PAD*0.5);
218
219 // Altitude difference
220
221 hbox = gtk_hbox_new(FALSE,0);
222 gtk_widget_show(hbox);
223 gtk_box_pack_start(GTK_BOX(vbox), hbox, TRUE, TRUE, DEF_PAD);
224
225 define_label_in_box("Difference in altitude",hbox,FALSE, FALSE,0);
226 adj = gtk_adjustment_new (pen->altitude_difference, -50, 50, 1, 1, 0.01);
227 scale = define_scale_in_box(adj,hbox,0, DEF_PAD*0.5);
228 gtk_signal_connect (GTK_OBJECT (scale), "button_press_event",
229 (GtkSignalFunc) set_preview_mode, (gpointer) &pen->mode);
230
231 gtk_signal_connect (GTK_OBJECT (scale), "button_press_event",
232 (GtkSignalFunc) gl_no_refresh_callb, data);
233
234 gtk_signal_connect (GTK_OBJECT (scale), "button_release_event",
235 (GtkSignalFunc) unset_preview_mode, data);
236 gtk_signal_connect (GTK_OBJECT (adj), "value_changed",
237 GTK_SIGNAL_FUNC (gint_adj_callb), (gpointer) &pen->altitude_difference);
238 gtk_signal_connect (GTK_OBJECT (adj), "value_changed",
239 GTK_SIGNAL_FUNC (gboolean_set_true), (gpointer) &pen->buffer_reset_required);
240 gtk_signal_connect (GTK_OBJECT (adj), "value_changed",
241 GTK_SIGNAL_FUNC (update_fault_callb), data);
242
243 button = gtk_button_new_with_label ("0");
244 gtk_widget_show(button);
245 gtk_box_pack_start(GTK_BOX(hbox), button, FALSE, FALSE, DEF_PAD);
246 gtk_signal_connect (GTK_OBJECT (button), "clicked", (GtkSignalFunc) zero_callb, adj);
247
248 // Smoothing
249
250 hbox = gtk_hbox_new(FALSE,0);
251 gtk_widget_show(hbox);
252 gtk_box_pack_start(GTK_BOX(vbox), hbox, TRUE, TRUE, DEF_PAD*0.5);
253
254 define_label_in_box("Smoothing",hbox,FALSE, FALSE,0);
255 adj = gtk_adjustment_new (pen->smoothing,0, 20, 1, 1, 0.01);
256 scale = define_scale_in_box(adj,hbox,0, DEF_PAD*0.5);
257 gtk_signal_connect (GTK_OBJECT (scale), "button_press_event",
258 (GtkSignalFunc) set_preview_mode, (gpointer) &pen->mode);
259
260 gtk_signal_connect (GTK_OBJECT (scale), "button_press_event",
261 (GtkSignalFunc) gl_no_refresh_callb, data);
262
263 gtk_signal_connect (GTK_OBJECT (scale), "button_release_event",
264 (GtkSignalFunc) unset_preview_mode, data);
265 gtk_signal_connect (GTK_OBJECT (adj), "value_changed",
266 GTK_SIGNAL_FUNC (gint_adj_callb), (gpointer) &pen->smoothing);
267 gtk_signal_connect (GTK_OBJECT (adj), "value_changed",
268 GTK_SIGNAL_FUNC (update_fault_callb), data);// Smoothing
269
270 // Separation
271
272 hbox = gtk_hbox_new(FALSE,0);
273 gtk_widget_show(hbox);
274 gtk_box_pack_start(GTK_BOX(vbox), hbox, TRUE, TRUE, DEF_PAD);
275
276 define_label_in_box("Separation",hbox,FALSE, FALSE,0);
277 adj = gtk_adjustment_new (pen->separation, 0, 100, 1, 1, 0.01);
278 scale = define_scale_in_box(adj,hbox,0, DEF_PAD*0.5);
279 gtk_signal_connect (GTK_OBJECT (scale), "button_press_event",
280 (GtkSignalFunc) set_preview_mode, (gpointer) &pen->mode);
281 gtk_signal_connect (GTK_OBJECT (scale), "button_release_event",
282 (GtkSignalFunc) unset_preview_mode, data);
283 gtk_signal_connect (GTK_OBJECT (scale), "button_press_event",
284 (GtkSignalFunc) gl_no_refresh_callb, (gpointer) data);
285 gtk_signal_connect (GTK_OBJECT (adj), "value_changed",
286 GTK_SIGNAL_FUNC (gint_adj_callb), (gpointer) &pen->separation);
287 gtk_signal_connect (GTK_OBJECT (adj), "value_changed",
288 GTK_SIGNAL_FUNC (gboolean_set_true), (gpointer) &pen->buffer_reset_required);
289 gtk_signal_connect (GTK_OBJECT (adj), "value_changed",
290 GTK_SIGNAL_FUNC (update_fault_callb), data);
291
292 percent_buttons_new (hbox, (gpointer *) adj);
293
294 // Check box for showing / hiding the accept buttons
295 button = define_check_button_in_box ("Auto Accept & Refresh", vbox, 0, 0, 0);
296 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (button),dts->fault_auto_accept_flag);
297 g_signal_connect (G_OBJECT (button), "toggled", GTK_SIGNAL_FUNC(toggle_check_button_callb), (gpointer) &dts->fault_auto_accept_flag);
298 // gtk_signal_connect (GTK_OBJECT(button), "toggled",
299 // GTK_SIGNAL_FUNC(toggle_check_button_callb), (gpointer) &dts->fault_auto_accept_flag);
300 // printf("Toggle pointer (dts->fault_auto_accept_flag): %p\n",&dts->fault_auto_accept_flag);
301 //
302 // Accept / reset
303 hbox = gtk_hbox_new(FALSE,DEF_PAD);
304 gtk_widget_show(hbox);
305
306 wdg = gtk_button_new_with_label (_("Reset"));
307 gtk_signal_connect (GTK_OBJECT (wdg), "clicked",
308 (GtkSignalFunc) reset_fault_callb, data);
309 gtk_widget_show(wdg);
310
311 gtk_box_pack_start(GTK_BOX(hbox), wdg, FALSE, FALSE, DEF_PAD);
312
313 // 2nd hbox for combining the Accept and Accept / Refresh button
314 hbox2 = gtk_hbox_new(FALSE,0);
315 gtk_widget_show(hbox2);
316
317 // Control check box, for showing / hiding the accept buttons
318 gtk_signal_connect (GTK_OBJECT(button), "toggled",
319 GTK_SIGNAL_FUNC(hide_if_true), hbox2);
320 if (dts->fault_auto_accept_flag)
321 gtk_widget_hide(hbox2);
322
323 button = gtk_button_new_with_label (_("Accept"));
324 gtk_signal_connect (GTK_OBJECT (button), "clicked",
325 (GtkSignalFunc) accept_fault_callb, data);
326
327 // Unactivate "Accept" button after a reset or accepting the change
328 // ("Apply_fault" reactivates the accept button)
329 gtk_signal_connect (GTK_OBJECT (wdg), "clicked",
330 (GtkSignalFunc) unset_sensitive_callb, (gpointer) hbox2);
331 gtk_signal_connect (GTK_OBJECT (button), "clicked",
332 (GtkSignalFunc) unset_sensitive_callb, (gpointer) hbox2);
333
334 gtk_widget_show(button);
335 gtk_box_pack_start(GTK_BOX(hbox2), button, FALSE, FALSE, DEF_PAD);
336
337 // Accept & Refresh button
338
339 button = gtk_button_new_with_label (_("Accept & Refresh"));
340 gtk_signal_connect (GTK_OBJECT (button), "clicked",
341 (GtkSignalFunc) accept_fault_callb, data);
342 gtk_signal_connect (GTK_OBJECT (button), "clicked",
343 (GtkSignalFunc) refresh_seed_from_seedbox, (gpointer) dts->fault_line_dialog->seed_dialog);
344 gtk_signal_connect (GTK_OBJECT (button), "clicked",
345 (GtkSignalFunc) update_line, (gpointer) dts->fault_line_dialog);
346
347 // Unactivate "Accept" button after a reset or accepting the change
348
349 // ("Apply_fault" reactivates the accept button)
350 gtk_signal_connect (GTK_OBJECT (wdg), "clicked",
351 (GtkSignalFunc) unset_sensitive_callb, (gpointer) hbox2);
352 gtk_signal_connect (GTK_OBJECT (button), "clicked",
353 (GtkSignalFunc) unset_sensitive_callb, (gpointer) hbox2);
354
355 gtk_widget_show(button);
356 gtk_box_pack_start(GTK_BOX(hbox2), button, FALSE, FALSE, DEF_PAD);
357 gtk_widget_set_sensitive(GTK_WIDGET(hbox2),FALSE);
358
359 gtk_box_pack_start(GTK_BOX(vbox), align_widget(hbox2,0.5,0.5), FALSE, FALSE, 0);
360
361 dts->fault_accept = hbox2;
362
363 gtk_box_pack_start (GTK_BOX (vbox), align_widget(hbox,0.5,0.5),
364 FALSE, FALSE, DEF_PAD);
365
366 return frame;
367 }
368
369