[genius] Mon May 05 17:00:38 2014 Jiri (George) Lebl <jirka 5z com>



commit 95da8e809c5250ddec9ccb281f73df440fff9e00
Author: Jiri (George) Lebl <jiri lebl gmail com>
Date:   Mon May 5 17:00:42 2014 -0500

    Mon May 05 17:00:38 2014  Jiri (George) Lebl <jirka 5z com>
    
        * src/gnome_genius.[ch], src/graphing.c: export the calc_running
          to graphing and use it.  Fix interrupting drawing of solutions
          from the gui.

 ChangeLog          |    6 +++++
 src/gnome-genius.c |   34 +++++++++++++++---------------
 src/gnome-genius.h |    1 +
 src/graphing.c     |   59 ++++++++++++++++++++++++++++++++++++++++++---------
 4 files changed, 72 insertions(+), 28 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index ea5b80c..ad93120 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+Mon May 05 17:00:38 2014  Jiri (George) Lebl <jirka 5z com>
+
+       * src/gnome_genius.[ch], src/graphing.c: export the calc_running
+         to graphing and use it.  Fix interrupting drawing of solutions
+         from the gui.
+
 Thu Apr 03 08:01:49 2014  Jiri (George) Lebl <jirka 5z com>
 
        * src/inter.c, src/genius-readline-helper.c: apply patch from Felipe
diff --git a/src/gnome-genius.c b/src/gnome-genius.c
index 19775c2..a025bf6 100644
--- a/src/gnome-genius.c
+++ b/src/gnome-genius.c
@@ -110,6 +110,8 @@ GtkWidget *genius_window = NULL;
 GtkWidget *genius_window_statusbar = NULL;
 GtkUIManager *genius_ui = NULL;
 
+int gel_calc_running = 0;
+
 static GtkWidget *setupdialog = NULL;
 static GtkWidget *term = NULL;
 static GtkWidget *notebook = NULL;
@@ -119,8 +121,6 @@ static GtkRecentManager *recent_manager;
 
 static char *clipboard_str = NULL;
 
-static int calc_running = 0;
-
 static int errors_printed = 0;
 
 static char *last_dir = NULL;
@@ -2163,7 +2163,7 @@ static void
 quitapp (GtkWidget * widget, gpointer data)
 {
        if (any_changed ()) {
-               if (calc_running) {
+               if (gel_calc_running) {
                        if ( ! genius_ask_question (NULL,
                                                    _("Genius is executing something, "
                                                      "and furthermore there are "
@@ -2178,7 +2178,7 @@ quitapp (GtkWidget * widget, gpointer data)
                                return;
                }
        } else {
-               if (calc_running) {
+               if (gel_calc_running) {
                        if ( ! genius_ask_question (NULL,
                                                    _("Genius is executing something, "
                                                      "are you sure you wish to "
@@ -2666,7 +2666,7 @@ void
 genius_interrupt_calc (void)
 {
        gel_interrupted = TRUE;
-       if (!calc_running) {
+       if ( ! gel_calc_running) {
                vte_terminal_feed_child (VTE_TERMINAL (term), "\n", 1);
        }
 }
@@ -2683,7 +2683,7 @@ executing_warning (void)
 static void
 warranty_call (GtkWidget *widget, gpointer data)
 {
-       if (calc_running) {
+       if (gel_calc_running) {
                executing_warning ();
                return;
        } else {
@@ -2751,10 +2751,10 @@ really_load_cb (GtkFileChooser *fs, int response, gpointer data)
                           "\e[0m (((\r\n", -1);
        gtk_notebook_set_current_page (GTK_NOTEBOOK (notebook), 0);
 
-       calc_running ++;
+       gel_calc_running ++;
        gel_load_guess_file (NULL, s, TRUE);
        gel_test_max_nodes_again ();
-       calc_running --;
+       gel_calc_running --;
 
        gel_printout_infos ();
 
@@ -3012,7 +3012,7 @@ copy_answer (void)
 static void
 copy_as_plain (GtkWidget *menu_item, gpointer data)
 {
-       if (calc_running) {
+       if (gel_calc_running) {
                executing_warning ();
                return;
        } else {
@@ -3031,7 +3031,7 @@ copy_as_plain (GtkWidget *menu_item, gpointer data)
 static void
 copy_as_latex (GtkWidget *menu_item, gpointer data)
 {
-       if (calc_running) {
+       if (gel_calc_running) {
                executing_warning ();
                return;
        } else {
@@ -3050,7 +3050,7 @@ copy_as_latex (GtkWidget *menu_item, gpointer data)
 static void
 copy_as_troff (GtkWidget *menu_item, gpointer data)
 {
-       if (calc_running) {
+       if (gel_calc_running) {
                executing_warning ();
                return;
        } else {
@@ -3069,7 +3069,7 @@ copy_as_troff (GtkWidget *menu_item, gpointer data)
 static void
 copy_as_mathml (GtkWidget *menu_item, gpointer data)
 {
-       if (calc_running) {
+       if (gel_calc_running) {
                executing_warning ();
                return;
        } else {
@@ -4130,7 +4130,7 @@ run_program (GtkWidget *menu_item, gpointer data)
        if (vname == NULL)
                vname = "???";
 
-       if (calc_running) {
+       if (gel_calc_running) {
                executing_warning ();
                return;
        } else {
@@ -4197,7 +4197,7 @@ run_program (GtkWidget *menu_item, gpointer data)
                fp = fdopen (p[0], "r");
                gel_lexer_open (fp);
 
-               calc_running ++;
+               gel_calc_running ++;
 
                g_free (prog);
 
@@ -4225,7 +4225,7 @@ run_program (GtkWidget *menu_item, gpointer data)
                fclose (fp);
 
                gel_test_max_nodes_again ();
-               calc_running --;
+               gel_calc_running --;
 
                gel_printout_infos ();
 
@@ -4619,11 +4619,11 @@ static void
 genius_got_etree (GelETree *e)
 {
        if (e != NULL) {
-               calc_running ++;
+               gel_calc_running ++;
                check_events();
                gel_evalexp_parsed (e, gel_main_out, "= \e[1;36m", TRUE);
                gel_test_max_nodes_again ();
-               calc_running --;
+               gel_calc_running --;
                gel_output_full_string (gel_main_out, "\e[0m");
                gel_output_flush (gel_main_out);
        }
diff --git a/src/gnome-genius.h b/src/gnome-genius.h
index 9fdfce5..e15ec39 100644
--- a/src/gnome-genius.h
+++ b/src/gnome-genius.h
@@ -35,6 +35,7 @@ typedef struct {
 
 extern GeniusSetup genius_setup;
 extern GtkWidget *genius_window;
+extern int gel_calc_running;
 
 void genius_interrupt_calc (void);
 
diff --git a/src/graphing.c b/src/graphing.c
index 175f7f5..5f920d3 100644
--- a/src/graphing.c
+++ b/src/graphing.c
@@ -321,8 +321,8 @@ static void plot_surface_functions (gboolean do_window_present, gboolean fit_fun
 /* replot the slope/vector fields after zoom or other axis changing event */
 static void replot_fields (void);
 
-static void slopefield_draw_solution (double x, double y, double dx);
-static void vectorfield_draw_solution (double x, double y, double dt, double tlen);
+static void slopefield_draw_solution (double x, double y, double dx, gboolean is_gui);
+static void vectorfield_draw_solution (double x, double y, double dt, double tlen, gboolean is_gui);
 
 static GtkWidget *
 create_range_spinboxes (const char *title, GtkWidget **titlew,
@@ -840,6 +840,7 @@ plot_print_cb (void)
        }
 
        plot_in_progress ++;
+       gel_calc_running ++;
        plot_window_setup ();
 
        /* Letter will fit on A4, so just currently do that */
@@ -859,6 +860,7 @@ plot_print_cb (void)
 
        if ( ! ret || gel_interrupted) {
                plot_in_progress --;
+               gel_calc_running --;
                plot_window_setup ();
 
                if ( ! gel_interrupted)
@@ -887,6 +889,7 @@ plot_print_cb (void)
        }
 
        plot_in_progress --;
+       gel_calc_running --;
        plot_window_setup ();
 
        close (fd);
@@ -978,6 +981,7 @@ really_export_cb (GtkFileChooser *fs, int response, gpointer data)
        }
 
        plot_in_progress ++;
+       gel_calc_running ++;
        plot_window_setup ();
 
        /* FIXME: There should be some options about size and stuff */
@@ -1042,6 +1046,7 @@ really_export_cb (GtkFileChooser *fs, int response, gpointer data)
        }
 
        plot_in_progress --;
+       gel_calc_running --;
        plot_window_setup ();
 
        if ( ! ret || gel_interrupted) {
@@ -1643,10 +1648,10 @@ plot_select_region (GtkPlotCanvas *canvas,
                                (GTK_SPIN_BUTTON (solver_y_sb), y);
 
                if (plot_mode == MODE_LINEPLOT_SLOPEFIELD)
-                       slopefield_draw_solution (x, y, solver_xinc);
+                       slopefield_draw_solution (x, y, solver_xinc, TRUE /*is_gui*/);
                else if (plot_mode == MODE_LINEPLOT_VECTORFIELD)
                        vectorfield_draw_solution (x, y, solver_tinc,
-                                                  solver_tlen);
+                                                  solver_tlen, TRUE /*is_gui*/);
 
                return;
        }
@@ -1841,9 +1846,9 @@ solver_dialog_response (GtkWidget *w, int response, gpointer data)
        if (response == RESPONSE_PLOT) {
                update_spinboxes (w);
                if (plot_mode == MODE_LINEPLOT_SLOPEFIELD)
-                       slopefield_draw_solution (solver_x, solver_y, solver_xinc);
+                       slopefield_draw_solution (solver_x, solver_y, solver_xinc, TRUE /*is_gui*/);
                else
-                       vectorfield_draw_solution (solver_x, solver_y, solver_tinc, solver_tlen);
+                       vectorfield_draw_solution (solver_x, solver_y, solver_tinc, solver_tlen, TRUE 
/*is_gui*/);
        } else if (response == RESPONSE_CLEAR) {
                clear_solutions ();
        } else  {
@@ -2568,6 +2573,7 @@ static void
 plot_axis (void)
 {
        plot_in_progress ++;
+       gel_calc_running ++;
        plot_window_setup ();
 
        if (plot_mode == MODE_LINEPLOT) {
@@ -2606,6 +2612,7 @@ plot_axis (void)
        }
 
        plot_in_progress --;
+       gel_calc_running --;
        plot_window_setup ();
 }
 
@@ -3783,7 +3790,7 @@ solution_destroyed (GtkWidget *plotdata, gpointer data)
 }
 
 static void
-slopefield_draw_solution (double x, double y, double dx)
+slopefield_draw_solution (double x, double y, double dx, gboolean is_gui)
 {
        double *xx, *yy;
        double cx, cy;
@@ -3800,6 +3807,10 @@ slopefield_draw_solution (double x, double y, double dx)
        if (slopefield_func == NULL)
                return;
 
+       plot_in_progress ++;
+       gel_calc_running ++;
+       plot_window_setup ();
+
        gdk_color_parse ("red", &color);
 
        fudgey = (ploty2-ploty1)/100;
@@ -3921,10 +3932,17 @@ slopefield_draw_solution (double x, double y, double dx)
                                          data);
        g_signal_connect (G_OBJECT (data), "destroy",
                          G_CALLBACK (solution_destroyed), NULL);
+
+       if (is_gui && gel_interrupted)
+               gel_interrupted = FALSE;
+
+       plot_in_progress --;
+       gel_calc_running --;
+       plot_window_setup ();
 }
 
 static void
-vectorfield_draw_solution (double x, double y, double dt, double tlen)
+vectorfield_draw_solution (double x, double y, double dt, double tlen, gboolean is_gui)
 {
        double *xx, *yy;
        double cx, cy, t;
@@ -3932,6 +3950,7 @@ vectorfield_draw_solution (double x, double y, double dt, double tlen)
        int i;
        GdkColor color;
        GtkPlotData *data;
+       gboolean ex;
 
        if (vectorfield_func_x == NULL ||
            vectorfield_func_y == NULL ||
@@ -3939,6 +3958,10 @@ vectorfield_draw_solution (double x, double y, double dt, double tlen)
            tlen <= 0.0)
                return;
 
+       plot_in_progress ++;
+       gel_calc_running ++;
+       plot_window_setup ();
+
        gdk_color_parse ("red", &color);
 
        len = (int)(tlen / dt) + 2;
@@ -3952,10 +3975,10 @@ vectorfield_draw_solution (double x, double y, double dt, double tlen)
        cy = y;
        t = 0.0;
        while (t < tlen && i < len) {
-               gboolean ex = FALSE;
                double xk1, xk2, xk3, xk4, xsl;
                double yk1, yk2, yk3, yk4, ysl;
 
+               ex = FALSE;
                /* standard Runge-Kutta */
                xk1 = call_xy_or_z_function (vectorfield_func_x,
                                             cx, cy, &ex);
@@ -4005,6 +4028,13 @@ vectorfield_draw_solution (double x, double y, double dt, double tlen)
                                          data);
        g_signal_connect (G_OBJECT (data), "destroy",
                          G_CALLBACK (solution_destroyed), NULL);
+
+       if (is_gui && gel_interrupted)
+               gel_interrupted = FALSE;
+
+       plot_in_progress --;
+       gel_calc_running--;
+       plot_window_setup ();
 }
 
 
@@ -4549,6 +4579,7 @@ plot_functions (gboolean do_window_present,
        add_line_plot ();
 
        plot_in_progress ++;
+       gel_calc_running ++;
        plot_window_setup ();
        gtk_plot_freeze (GTK_PLOT (line_plot));
 
@@ -4746,6 +4777,7 @@ plot_functions (gboolean do_window_present,
 
        gtk_plot_thaw (GTK_PLOT (line_plot));
        plot_in_progress --;
+       gel_calc_running --;
        plot_window_setup ();
 }
 
@@ -4764,6 +4796,7 @@ plot_surface_functions (gboolean do_window_present, gboolean fit_function)
        add_surface_plot ();
 
        plot_in_progress ++;
+       gel_calc_running ++;
        plot_window_setup ();
 
 
@@ -4910,6 +4943,7 @@ plot_surface_functions (gboolean do_window_present, gboolean fit_function)
        }
 
        plot_in_progress --;
+       gel_calc_running --;
        plot_window_setup ();
 }
 
@@ -7214,7 +7248,7 @@ SlopefieldDrawSolution_op (GelCtx *ctx, GelETree * * a, int *exception)
                return NULL;
        }
 
-       slopefield_draw_solution (x, y, dx);
+       slopefield_draw_solution (x, y, dx, FALSE /*is_gui*/);
 
        return gel_makenum_null ();
 }
@@ -7274,7 +7308,7 @@ VectorfieldDrawSolution_op (GelCtx *ctx, GelETree * * a, int *exception)
                return NULL;
        }
 
-       vectorfield_draw_solution (x, y, dt, tlen);
+       vectorfield_draw_solution (x, y, dt, tlen, FALSE /*is_gui*/);
 
        return gel_makenum_null ();
 }
@@ -9062,6 +9096,7 @@ ExportPlot_op (GelCtx *ctx, GelETree * * a, int *exception)
                gboolean eps = (strcasecmp (type, "eps") == 0);
 
                plot_in_progress ++;
+               gel_calc_running ++;
                plot_window_setup ();
 
                if ( ! gtk_plot_canvas_export_ps_with_size
@@ -9072,6 +9107,7 @@ ExportPlot_op (GelCtx *ctx, GelETree * * a, int *exception)
                         GTK_PLOT_PSPOINTS,
                         400, ASPECT * 400)) {
                        plot_in_progress --;
+                       gel_calc_running --;
                        plot_window_setup ();
                        gel_errorout (_("%s: export failed"), "ExportPlot");
                        return NULL;
@@ -9083,6 +9119,7 @@ ExportPlot_op (GelCtx *ctx, GelETree * * a, int *exception)
                }
 
                plot_in_progress --;
+               gel_calc_running --;
                plot_window_setup ();
        } else {
                gel_errorout (_("%s: unknown file type, can be \"png\", \"eps\", or \"ps\"."), "ExportPlot");


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]