Jeroen Demeyer on Mon, 09 Jan 2017 17:24:58 +0100


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

[PATCH] Move rectdraw0() to a method of PARI_plot



>From 164a23086079b7b2fad5ff40b69339fce444560d Mon Sep 17 00:00:00 2001
From: Jeroen Demeyer <jdemeyer@cage.ugent.be>
Date: Mon, 9 Jan 2017 15:55:05 +0100
Subject: [PATCH 1/2] Move rectdraw0 to a "method" PARI_plot.draw

---
 src/graph/plotQt.c    | 14 ++++----------
 src/graph/plotQt4.c   | 14 ++++----------
 src/graph/plotWin32.c |  6 +++++-
 src/graph/plotX.c     | 10 ++++++----
 src/graph/plotfltk.c  | 11 ++++-------
 src/graph/plotnull.c  |  9 ---------
 src/graph/plotport.c  | 11 +++++++++--
 src/graph/plotps.c    |  7 +++++--
 src/graph/rect.h      |  2 +-
 9 files changed, 38 insertions(+), 46 deletions(-)

diff --git a/src/graph/plotQt.c b/src/graph/plotQt.c
index 9aa3a81..b9eebe2 100644
--- a/src/graph/plotQt.c
+++ b/src/graph/plotQt.c
@@ -566,20 +566,13 @@ void PlotWindow::save( int id) {
 #endif // __FANCY_WIN__
 
 
-
-//
-// Implementation of the two architecture-dependent functions
-// (from rect.h) requested by pari's plotting routines
-//
-
-
-void
-rectdraw0(long *w, long *x, long *y, long lw)
+/* Interface to PARI's plotting functions */
+static void
+draw(long *w, long *x, long *y, long lw)
 {
     if (pari_daemon()) return;  // parent process returns
 
     pari_close();
-    PARI_get_plot();
 
     // launch Qt window
     int argc = 1; char *argv[] = { "gp", "-qws"}; // set argc = 2 for cross
@@ -621,5 +614,6 @@ PARI_get_plot(void)
     pari_plot.vunit   = 3;           //
     pari_plot.fwidth  = 6;           // font width
     pari_plot.fheight = 9;           //   and height
+    pari_plot.draw    = &draw;
     pari_plot.init    = 1;           // flag: pari_plot is set now!
 }
diff --git a/src/graph/plotQt4.c b/src/graph/plotQt4.c
index 1ef7c40..07bc570 100644
--- a/src/graph/plotQt4.c
+++ b/src/graph/plotQt4.c
@@ -553,20 +553,13 @@ void PlotWindow::save( int id)
 #endif // __FANCY_WIN__
 
 
-
-//
-// Implementation of the two architecture-dependent functions
-// (from rect.h) requested by pari's plotting routines
-//
-
-
-void
-rectdraw0(long *w, long *x, long *y, long lw)
+/* Interface to PARI's plotting functions */
+static void
+draw(long *w, long *x, long *y, long lw)
 {
     if (pari_daemon()) return;  // parent process returns
 
     pari_close();
-    PARI_get_plot();
 
     // launch Qt window
     int argc = 1;                         // set argc = 2 for cross
@@ -608,5 +601,6 @@ PARI_get_plot(void)
     pari_plot.vunit   = 3;           //
     pari_plot.fwidth  = 6;           // font width
     pari_plot.fheight = 9;           //   and height
+    pari_plot.draw    = &draw;
     pari_plot.init    = 1;           // flag: pari_plot is set now!
 }
diff --git a/src/graph/plotWin32.c b/src/graph/plotWin32.c
index 8af4d66..9084832 100644
--- a/src/graph/plotWin32.c
+++ b/src/graph/plotWin32.c
@@ -68,7 +68,10 @@ static void DrawString(void *data, long x, long y, char *text, long numtext)
   TextOut((HDC)data, x, y, text, numtext);
 }
 
-void rectdraw0(long *w, long *x, long *y, long lw)
+
+/* Interface to PARI's plotting functions */
+static void
+draw(long *w, long *x, long *y, long lw)
 {
   char tmppath[MAX_PATH], fname[MAX_PATH];
   struct plot_eng plotWin32;
@@ -121,4 +124,5 @@ PARI_get_plot(void)
 
   pari_plot.fwidth  = tm.tmAveCharWidth;
   pari_plot.fheight = tm.tmHeight;
+  pari_plot.draw    = &draw;
 }
diff --git a/src/graph/plotX.c b/src/graph/plotX.c
index 13bf839..9391e98 100644
--- a/src/graph/plotX.c
+++ b/src/graph/plotX.c
@@ -154,8 +154,10 @@ PARI_ColorSetUp(Display *display, GEN colors)
   }
 }
 
-void
-rectdraw0(long *w, long *x, long *y, long lw)
+
+/* Interface to PARI's plotting functions */
+static void
+draw(long *w, long *x, long *y, long lw)
 {
   long oldwidth,oldheight;
   struct plot_eng plotX;
@@ -173,7 +175,6 @@ rectdraw0(long *w, long *x, long *y, long lw)
 
   if (pari_daemon()) return;  /* parent process returns */
 
-  PARI_get_plot();
   pari_close();
 
   display = XOpenDisplay(NULL);
@@ -293,6 +294,7 @@ PARI_get_plot(void)
   pari_plot.fwidth  = 9;
   pari_plot.hunit   = 5;
   pari_plot.vunit   = 5;
-  pari_plot.init = 1;
+  pari_plot.draw    = &draw;
+  pari_plot.init    = 1;
   XCloseDisplay(display);
 }
diff --git a/src/graph/plotfltk.c b/src/graph/plotfltk.c
index 3879728..acd11bf 100644
--- a/src/graph/plotfltk.c
+++ b/src/graph/plotfltk.c
@@ -189,20 +189,16 @@ int Plotter::handle(int event)
   }
 }
 
-//
-// Implementation of the two architecture-dependent functions
-// (from rect.h) requested by pari's plotting routines
-//
 
-void
-rectdraw0(long *w, long *x, long *y, long lw)
+/* Interface to PARI's plotting functions */
+static void
+fltk_draw(long *w, long *x, long *y, long lw)
 {
     Plotter *win;
 
     if (pari_daemon()) return;  // parent process returns
 
     pari_close();
-    PARI_get_plot();
 
     Fl::visual(FL_DOUBLE|FL_INDEX);
     win = new Plotter( w, x, y, lw);
@@ -225,5 +221,6 @@ PARI_get_plot(void)
     pari_plot.vunit   = 3;           //
     pari_plot.fwidth  = 6;           // font width
     pari_plot.fheight = 9;           //   and height
+    pari_plot.draw    = &fltk_draw;
     pari_plot.init    = 1;           // flag: pari_plot is set now!
 }
diff --git a/src/graph/plotnull.c b/src/graph/plotnull.c
index fdf26e3..1eee925 100644
--- a/src/graph/plotnull.c
+++ b/src/graph/plotnull.c
@@ -15,14 +15,5 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */
 #include "rect.h"
 
 void
-rectdraw0(long *w, long *x, long *y, long lw)
-{
-  (void)w;
-  (void)x;
-  (void)y;
-  (void)lw;
-}
-
-void
 PARI_get_plot(void)
 { pari_err(e_MISC,"high resolution graphics disabled"); }
diff --git a/src/graph/plotport.c b/src/graph/plotport.c
index c6de38f..5f4fcc1 100644
--- a/src/graph/plotport.c
+++ b/src/graph/plotport.c
@@ -1565,7 +1565,7 @@ rectplothrawin(long grect, dblPointList *data, long flags)
   if (W)
   {
     if (W == &pari_plot)
-      rectdraw0(w,wx,wy,2);
+      W->draw(w,wx,wy,2);
     else
       postdraw0(w,wx,wy,2, 0);
     killrect(w[1]);
@@ -1704,6 +1704,7 @@ PARI_get_psplot(void)
   pari_psplot.fwidth = 6;
   pari_psplot.hunit = 5;
   pari_psplot.vunit = 5;
+  pari_psplot.draw = NULL;  /* Currently unused for ps plotting */
 }
 
 static void
@@ -1736,7 +1737,13 @@ gendraw(GEN list, long ps, long flag)
     ne = itos(win); check_rect(ne);
     w[i] = ne;
   }
-  if (ps) postdraw0(w,x,y,n,flag); else rectdraw0(w,x,y,n);
+  if (ps)
+    postdraw0(w,x,y,n,flag);
+  else
+  {
+    PARI_get_plot();
+    pari_plot.draw(w,x,y,n);
+  }
   pari_free(x); pari_free(y); pari_free(w);
 }
 
diff --git a/src/graph/plotps.c b/src/graph/plotps.c
index dcdecc1..cad9574 100644
--- a/src/graph/plotps.c
+++ b/src/graph/plotps.c
@@ -19,8 +19,10 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */
 #include "paripriv.h"
 #include "rect.h"
 
-void
-rectdraw0(long *w, long *x, long *y, long lw)
+
+/* Interface to PARI's plotting functions */
+static void
+draw(long *w, long *x, long *y, long lw)
 {
   struct plot_eng plot;
   FILE *file;
@@ -53,5 +55,6 @@ PARI_get_plot(void)
   pari_plot.fwidth  = 6;
   pari_plot.hunit   = 3;
   pari_plot.vunit   = 3;
+  pari_plot.draw    = &draw;
   pari_plot.init = 1;
 }
diff --git a/src/graph/rect.h b/src/graph/rect.h
index b8a3476..1c60cd5 100644
--- a/src/graph/rect.h
+++ b/src/graph/rect.h
@@ -23,6 +23,7 @@ typedef struct PARI_plot {
   long fheight;
   long init;
   char name[PLOT_NAME_LEN+1];
+  void (*draw)(long *w, long *x, long *y, long lw);
 } PARI_plot;
 
 extern PARI_plot pari_plot, pari_psplot;
@@ -281,6 +282,5 @@ void gen_rectdraw0(struct plot_eng *eng, long *w, long *x, long *y, long lw, dou
 
 /* architecture-dependent plot file (plotX.c ...) */
 void  PARI_get_plot(void);
-void  rectdraw0(long *w, long *x, long *y, long lw);
 
 ENDEXTERN
-- 
2.7.3