changeset 24687:8b935067a257

Allow printing without updating qt visible or invisible figures (bug #52940). * graphics.in.h (figure::properties::__gl_window__, __printing__): Add hidden properties. * Figure.cc (Figure::update): Return if __printing__ is "on". Set __gl_window__ "on" if the figure has been shown at least once. * Backend.cc (Backend::print_figure): Allow invisible figures to be printed. * print.m: Set and restore "__printing__" property to prevent figure window updates. * __opengl_print__.m: Allow qt invisible figures to be printed without osmesa if they have been visible at least once.
author Pantxo Diribarne <pantxo.diribarne@gmail.com>
date Wed, 31 Jan 2018 23:22:51 +0100
parents 21e97b50989d
children dd68506c0926
files libgui/graphics/Backend.cc libgui/graphics/Figure.cc libinterp/corefcn/graphics.in.h scripts/plot/util/print.m scripts/plot/util/private/__opengl_print__.m
diffstat 5 files changed, 28 insertions(+), 13 deletions(-) [+]
line wrap: on
line diff
--- a/libgui/graphics/Backend.cc	Sun Feb 04 23:58:29 2018 +0100
+++ b/libgui/graphics/Backend.cc	Wed Jan 31 23:22:51 2018 +0100
@@ -185,14 +185,11 @@
                          const std::string& file_cmd,
                          const std::string& /*debug_file*/) const
   {
-    if (go.get_properties ().is_visible ())
-      {
-        ObjectProxy *proxy = toolkitObjectProxy (go);
+    ObjectProxy *proxy = toolkitObjectProxy (go);
 
-        if (proxy)
-          proxy->print (QString::fromStdString (file_cmd),
-                        QString::fromStdString (term));
-      }
+    if (proxy)
+      proxy->print (QString::fromStdString (file_cmd),
+                    QString::fromStdString (term));
   }
 
   uint8NDArray
--- a/libgui/graphics/Figure.cc	Sun Feb 04 23:58:29 2018 +0100
+++ b/libgui/graphics/Figure.cc	Wed Jan 31 23:22:51 2018 +0100
@@ -432,10 +432,14 @@
       return;
 
     figure::properties& fp = properties<figure> ();
+
+    if (fp.is___printing__ ())
+      return;
+    
     QMainWindow *win = qWidget<QMainWindow> ();
 
     m_blockUpdates = true;
-
+    
     switch (pId)
       {
       case figure::properties::ID_POSITION:
@@ -465,7 +469,14 @@
 
       case figure::properties::ID_VISIBLE:
         if (fp.is_visible ())
-          QTimer::singleShot (0, win, SLOT (show ()));
+          {
+            QTimer::singleShot (0, win, SLOT (show ()));
+            if (! fp.is___gl_window__ ())
+              {
+                gh_manager::auto_lock lock;
+                fp.set ("__gl_window__", "on");
+              }
+          }                
         else
           win->hide ();
         break;
--- a/libinterp/corefcn/graphics.in.h	Sun Feb 04 23:58:29 2018 +0100
+++ b/libinterp/corefcn/graphics.in.h	Wed Jan 31 23:22:51 2018 +0100
@@ -1589,7 +1589,7 @@
 
   bool_property (const std::string& nm, const graphics_handle& h,
                  const char *val)
-    : radio_property (nm, h, radio_values (std::string (val) == "on" ? 
+    : radio_property (nm, h, radio_values (std::string (val) == "on" ?
                                            "{on}|off" : "on|{off}"), val)
   { }
 
@@ -3159,7 +3159,7 @@
       callback_property windowscrollwheelfcn , Matrix ()
       radio_property windowstyle , "{normal}|modal|docked"
 
-      // Overridden base property  
+      // Overridden base property
       // Property is not implemented for figures.
       // Hide it and set it to a default value that works.
       radio_property pickableparts h , "{visible}"
@@ -3169,9 +3169,11 @@
       mutable string_property __gl_renderer__ hr , ""
       mutable string_property __gl_vendor__ hr , ""
       mutable string_property __gl_version__ hr , ""
+      bool_property __gl_window__ h , "off"
       string_property __graphics_toolkit__ hs , default_graphics_toolkit ()
       any_property __guidata__ h , Matrix ()
       radio_property __mouse_mode__ hS , "{none}|pan|rotate|select|text|zoom"
+      bool_property __printing__ h , "off"
       any_property __pan_mode__ h , Matrix ()
       any_property __plot_stream__ h , Matrix ()
       any_property __rotate_mode__ h , Matrix ()
--- a/scripts/plot/util/print.m	Sun Feb 04 23:58:29 2018 +0100
+++ b/scripts/plot/util/print.m	Wed Jan 31 23:22:51 2018 +0100
@@ -427,10 +427,13 @@
     ## graphics toolkit translates figure position to eps bbox (points)
     fpos = get (opts.figure, "position");
     props(end+1).h = opts.figure;
+    props(end).name = "__printing__";
+    props(end).value = {"off"};
+    props(end+1).h = opts.figure;
     props(end).name = "position";
     props(end).value = {fpos};
     fpos(3:4) = opts.canvas_size;
-    set (opts.figure, "position", fpos);
+    set (opts.figure, "__printing__", "on", "position", fpos);
     nfig += 1;
 
     ## Implement InvertHardCopy option
--- a/scripts/plot/util/private/__opengl_print__.m	Sun Feb 04 23:58:29 2018 +0100
+++ b/scripts/plot/util/private/__opengl_print__.m	Wed Jan 31 23:22:51 2018 +0100
@@ -150,7 +150,9 @@
       fprintf ("opengl-pipeline: '%s'\n", pipeline{n});
     endif
 
-    if (strcmp (get (opts.figure, "visible"), "on"))
+    if (strcmp (get (opts.figure, "visible"), "on")
+        || (strcmp (get (opts.figure, "__graphics_toolkit__"), "qt")
+            && strcmp (get (opts.figure, "__gl_window__"), "on")))
       ## Use toolkits "print_figure" method
       drawnow (gl2ps_device{n}, ['|' pipeline{n}]);
     else