[genius] Fri Dec 07 17:21:26 2012 Jiri (George) Lebl <jirka 5z com>
- From: George Lebl <jirka src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [genius] Fri Dec 07 17:21:26 2012 Jiri (George) Lebl <jirka 5z com>
- Date: Fri, 7 Dec 2012 23:21:54 +0000 (UTC)
commit abfdece45bcf10d0b16b6be44a8b4e18d82d8cde
Author: Jiri (George) Lebl <jirka 5z com>
Date: Fri Dec 7 17:21:33 2012 -0600
Fri Dec 07 17:21:26 2012 Jiri (George) Lebl <jirka 5z com>
* src/graphing.c, help/C/gel-function-list.xml: add ExportPlot
function
ChangeLog | 5 ++
NEWS | 2 +
help/C/gel-function-list.xml | 28 ++++++++++
help/genius.txt | 23 +++++++++
src/graphing.c | 113 ++++++++++++++++++++++++++++++++++++++++++
5 files changed, 171 insertions(+), 0 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index 8fff6ad..4325f1f 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+Fri Dec 07 17:21:26 2012 Jiri (George) Lebl <jirka 5z com>
+
+ * src/graphing.c, help/C/gel-function-list.xml: add ExportPlot
+ function
+
Fri Dec 07 00:27:33 2012 Jiri (George) Lebl <jirka 5z com>
* help/C/genius.xml, help/C/gel-function-list.xml: add
diff --git a/NEWS b/NEWS
index 8af9178..8e1c0bc 100644
--- a/NEWS
+++ b/NEWS
@@ -4,6 +4,8 @@ Changes to 1.0.16
surface data, to allow more complicated 3d plots and 3d plots from data.
* Add LinePlotDrawAxisLabels and SurfacePlotDrawLegends parameters and
add corresponding UI checkboxes
+* Add ExportPlot function to export the current contents of the plot window
+ to a file from GEL
* Add sinc, BesselJ0, BesselJ1, BesselJn, BesselY0, BesselY1, BesselYn functions
* Simpler output when typing "help foo" when foo is neither defined nor
documented.
diff --git a/help/C/gel-function-list.xml b/help/C/gel-function-list.xml
index f55ea50..844a5ed 100644
--- a/help/C/gel-function-list.xml
+++ b/help/C/gel-function-list.xml
@@ -5372,6 +5372,34 @@ and has period <userinput>b-a</userinput>.</para>
<sect1 id="genius-gel-function-list-plotting">
<title>Plotting</title>
<variablelist>
+ <varlistentry id="gel-function-ExportPlot">
+ <term>ExportPlot</term>
+ <listitem>
+ <synopsis>ExportPlot (file,type)</synopsis>
+ <synopsis>ExportPlot (file)</synopsis>
+ <para>
+ Export the contents of the plotting window to a file.
+ the type is a string that specifies the file type to
+ use, "png", "eps", or "ps". If the type is not
+ specified, then it is taken to be the extension, in
+ which case the extension must be ".png", ".eps", or ".ps".
+ </para>
+ <para>
+ Note that files are overwritten without asking.
+ </para>
+ <para>
+ On successful export, true is returned. Otherwise
+ error is printed and exception is raised.
+ </para>
+ <para>
+ Examples:
+ <screen><prompt>genius></prompt> <userinput>ExportPlot("file.png")</userinput>
+<prompt>genius></prompt> <userinput>ExportPlot("/directory/file","eps")</userinput>
+</screen>
+ </para>
+ </listitem>
+ </varlistentry>
+
<varlistentry id="gel-function-LinePlot">
<term>LinePlot</term>
<listitem>
diff --git a/help/genius.txt b/help/genius.txt
index bc1cc8e..c262a2d 100644
--- a/help/genius.txt
+++ b/help/genius.txt
@@ -6139,6 +6139,29 @@ SymbolicTaylorApproximationFunction (f,x0,n)
Plotting
+ ExportPlot
+
+ExportPlot (file,type)
+
+ExportPlot (file)
+
+ Export the contents of the plotting window to a file.
+ the type is a string that specifies the file type to
+ use, "png", "eps", or "ps". If the type is not
+ specified, then it is taken to be the extension, in
+ which case the extension must be ".png", ".eps", or
+ ".ps".
+
+ Note that files are overwritten without asking.
+
+ On successful export, true is returned. Otherwise error
+ is printed and exception is raised.
+
+ Examples:
+
+genius> ExportPlot("file.png")
+genius> ExportPlot("/directory/file","eps")
+
LinePlot
LinePlot (func1,func2,func3,...)
diff --git a/src/graphing.c b/src/graphing.c
index d4eb73f..557f396 100644
--- a/src/graphing.c
+++ b/src/graphing.c
@@ -7961,6 +7961,117 @@ SurfacePlotDataGrid_op (GelCtx *ctx, GelETree * * a, int *exception)
}
static GelETree *
+ExportPlot_op (GelCtx *ctx, GelETree * * a, int *exception)
+{
+ char *file;
+ char *type;
+
+ if G_UNLIKELY (plot_in_progress != 0) {
+ gel_errorout (_("%s: Plotting in progress, cannot call %s"),
+ "ExportPlot", "ExportPlot");
+ return NULL;
+ }
+
+ if (a[0]->type != GEL_STRING_NODE ||
+ ve_string_empty(a[0]->str.str)) {
+ gel_errorout (_("%s: first argument not a nonempty string"), "ExportPlot");
+ return NULL;
+ }
+ file = a[0]->str.str;
+
+ if (a[1] == NULL) {
+ char *dot = strrchr (file, '.');
+ if (dot == NULL) {
+ gel_errorout (_("%s: type not specified and filename has no extension"), "ExportPlot");
+ return NULL;
+ }
+ type = dot+1;
+ }
+
+ if (a[1] != NULL) {
+ if (a[1]->type != GEL_STRING_NODE ||
+ ve_string_empty(a[1]->str.str)) {
+ gel_errorout (_("%s: second argument not a nonempty string"), "ExportPlot");
+ return NULL;
+ }
+ type = a[1]->str.str;
+ }
+
+ if (a[1] != NULL && a[2] != NULL) {
+ gel_errorout (_("%s: too many arguments"), "ExportPlot");
+ return NULL;
+ }
+
+ if (plot_canvas == NULL) {
+ gel_errorout (_("%s: plot canvas not active, cannot export"), "ExportPlot");
+ return NULL;
+ }
+
+ if (strcasecmp (type, "png") == 0) {
+ GdkPixbuf *pix;
+
+ /* sanity */
+ if (GTK_PLOT_CANVAS (plot_canvas)->pixmap == NULL) {
+ gel_errorout (_("%s: export failed"), "ExportPlot");
+ return NULL;
+ }
+
+ pix = gdk_pixbuf_get_from_drawable
+ (NULL /* dest */,
+ GTK_PLOT_CANVAS (plot_canvas)->pixmap,
+ NULL /* cmap */,
+ 0 /* src x */, 0 /* src y */,
+ 0 /* dest x */, 0 /* dest y */,
+ GTK_PLOT_CANVAS (plot_canvas)->pixmap_width,
+ GTK_PLOT_CANVAS (plot_canvas)->pixmap_height);
+
+ if (pix == NULL ||
+ ! gdk_pixbuf_save (pix, file, "png", NULL /* error */, NULL)) {
+ if (pix != NULL)
+ g_object_unref (G_OBJECT (pix));
+ gel_errorout (_("%s: export failed"), "ExportPlot");
+ return NULL;
+ }
+
+ g_object_unref (G_OBJECT (pix));
+ } else if (strcasecmp (type, "eps") == 0 ||
+ strcasecmp (type, "ps") == 0) {
+ gboolean eps = (strcasecmp (type, "eps") == 0);
+
+ plot_in_progress ++;
+ plot_window_setup ();
+
+ if ( ! gtk_plot_canvas_export_ps_with_size
+ (GTK_PLOT_CANVAS (plot_canvas),
+ file,
+ GTK_PLOT_PORTRAIT,
+ eps /* epsflag */,
+ GTK_PLOT_PSPOINTS,
+ 400, ASPECT * 400)) {
+ plot_in_progress --;
+ plot_window_setup ();
+ gel_errorout (_("%s: export failed"), "ExportPlot");
+ return NULL;
+ }
+
+ /* need this for some reason */
+ if (plot_canvas != NULL) {
+ gtk_widget_queue_draw (GTK_WIDGET (plot_canvas));
+ }
+
+ plot_in_progress --;
+ plot_window_setup ();
+ } else {
+ gel_errorout (_("%s: unknown file type, can be \"png\", \"eps\", or \"ps\"."), "ExportPlot");
+ return NULL;
+ }
+
+ return gel_makenum_bool (TRUE);
+}
+
+
+
+static GelETree *
set_LinePlotWindow (GelETree * a)
{
double x1, x2, y1, y2;
@@ -8444,6 +8555,8 @@ gel_add_graph_functions (void)
FUNC (LinePlotClear, 0, "", "plotting", N_("Show the line plot window and clear out functions"));
VFUNC (LinePlotDrawLine, 2, "x1,y1,x2,y2,args", "plotting", N_("Draw a line from x1,y1 to x2,y2. x1,y1,x2,y2 can be replaced by a n by 2 matrix for a longer line"));
+ VFUNC (ExportPlot, 2, "filename,type", "plotting", N_("Export the current contents of the plot canvas to a file. The file type is given by the string type, which can be \"png\", \"eps\", or \"ps\"."));
+
PARAMETER (SlopefieldTicks, N_("Number of slopefield ticks as a vector [vertical,horizontal]."));
PARAMETER (VectorfieldTicks, N_("Number of vectorfield ticks as a vector [vertical,horizontal]."));
PARAMETER (LinePlotVariableNames, N_("Default names used by all 2D plot functions. Should be a 4 vector of strings or identifiers [x,y,z,t]."));
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]