[rkward-cvs] SF.net SVN: rkward-code:[4729] trunk/rkward/rkward/rbackend

tfry at users.sf.net tfry at users.sf.net
Sat Apr 27 13:30:23 UTC 2013


Revision: 4729
          http://sourceforge.net/p/rkward/code/4729
Author:   tfry
Date:     2013-04-27 13:30:23 +0000 (Sat, 27 Apr 2013)
Log Message:
-----------
Prepare for changing the default device to RK().

Modified Paths:
--------------
    trunk/rkward/rkward/rbackend/rkwarddevice/rkgraphicsdevice_stubs.cpp
    trunk/rkward/rkward/rbackend/rpackages/rkward/NAMESPACE
    trunk/rkward/rkward/rbackend/rpackages/rkward/R/internal_graphics.R
    trunk/rkward/rkward/rbackend/rpackages/rkward/R/public_graphics.R
    trunk/rkward/rkward/rbackend/rpackages/rkward/man/rk.capture.device.Rd

Modified: trunk/rkward/rkward/rbackend/rkwarddevice/rkgraphicsdevice_stubs.cpp
===================================================================
--- trunk/rkward/rkward/rbackend/rkwarddevice/rkgraphicsdevice_stubs.cpp	2013-04-27 06:21:35 UTC (rev 4728)
+++ trunk/rkward/rkward/rbackend/rkwarddevice/rkgraphicsdevice_stubs.cpp	2013-04-27 13:30:23 UTC (rev 4729)
@@ -123,6 +123,15 @@
 		if (rkd_waiting_for_reply) {
 			// For now, the backend does not support any nesting of graphics operations. It would make the protocol more complex.
 			// I believe the only use-case is resizing during interaction, and IMO, that's not a terribly important one to support.
+			//
+			// In case we do want to support nested operations, I think the plan would be basically:
+			// - For every request that awaits a reply (and only those), send a reply token
+			// - In RKGraphicsDataStreamReadGuard () wait for that specific token. If another token arrives, instead of the expected one,
+			//   put it on a stack, and continue waiting.
+			// - When waiting for a reply, also check the stack.
+			// What about the mutex?
+			// Well, essentially, during rkd_waiting_for_reply, nothing should attempt to obtain a lock. The transmitter thread can simply pause
+			// during that time.
 			rkd_suppress_on_exit++;
 			Rf_error ("Nested graphics operations are not supported by this device (did you try to resize the device during locator()?)");
 		}

Modified: trunk/rkward/rkward/rbackend/rpackages/rkward/NAMESPACE
===================================================================
--- trunk/rkward/rkward/rbackend/rpackages/rkward/NAMESPACE	2013-04-27 06:21:35 UTC (rev 4728)
+++ trunk/rkward/rkward/rbackend/rpackages/rkward/NAMESPACE	2013-04-27 13:30:23 UTC (rev 4729)
@@ -110,5 +110,7 @@
 export(rk.without.plot.history)
 export(setwd)
 export(Sys.setlocale)
+export(windows)
+export(win.graph)
 export(x11)
 export(X11)

Modified: trunk/rkward/rkward/rbackend/rpackages/rkward/R/internal_graphics.R
===================================================================
--- trunk/rkward/rkward/rbackend/rpackages/rkward/R/internal_graphics.R	2013-04-27 06:21:35 UTC (rev 4728)
+++ trunk/rkward/rkward/rbackend/rpackages/rkward/R/internal_graphics.R	2013-04-27 13:30:23 UTC (rev 4729)
@@ -31,17 +31,6 @@
 	.Call ("rk.graphics.device.resize", as.integer (devnum)-1, PACKAGE="(embedding)")
 }
 
-#' @export
-"x11" <- rk.screen.device
-
-#' @export
-"X11" <- x11
-
-if (base::.Platform$OS.type == "windows") {
-	  "windows" = rk.screen.device
-	  "win.graph" = rk.screen.device
-}
-
 # set from rkward the application:
 # options(device="rk.screen.device")
 #' @include internal.R

Modified: trunk/rkward/rkward/rbackend/rpackages/rkward/R/public_graphics.R
===================================================================
--- trunk/rkward/rkward/rbackend/rpackages/rkward/R/public_graphics.R	2013-04-27 06:21:35 UTC (rev 4728)
+++ trunk/rkward/rkward/rbackend/rpackages/rkward/R/public_graphics.R	2013-04-27 13:30:23 UTC (rev 4729)
@@ -43,7 +43,7 @@
 #' @export
 #' @aliases rk.graph.on rk.graph.off
 #' @rdname rk.graph.on
-rk.graph.on <- function (device.type=getOption ("rk.graphics.type"), width=getOption ("rk.graphics.width"), height=getOption ("rk.graphics.height"), quality, ...) 
+"rk.graph.on" <- function (device.type=getOption ("rk.graphics.type"), width=getOption ("rk.graphics.width"), height=getOption ("rk.graphics.height"), quality, ...) 
 {
 	if (!is.numeric (width)) width <- 480
 	if (!is.numeric (height)) height <- 480
@@ -85,6 +85,21 @@
 	invisible (ret)
 }
 
+#' \code{rk.graph.off()} closes the device that was opened by \code{rk.graph.on}. 
+#'
+#' @rdname rk.graph.on
+#' @export
+"rk.graph.off" <- function(){
+	.rk.cat.output ("\n")	# so the output will be auto-refreshed
+	ret <- dev.off()
+	
+	# dev.off () sets dev.next () as active, which may not have been active before rk.graph.on was called;
+	# so reset the correct device as active:
+	i <- get (".rk.active.device", .rk.variables)
+	if ((!is.null (i)) && (i %in% dev.list ())) ret <- dev.set (i)
+	ret
+}
+
 #' Plot graphics to RKWard native device
 #'
 #' \code{RK()} creates an R on-screen device that will be rendered in the RKWard frontend. 
@@ -119,13 +134,14 @@
 #'
 #' @param expr  Expression to evaluate. 
 #'
-#' @note Theoretically, \code{expr} can be any valid R expression. However typically this should be calls to X11(), Windows(), or, perhaps dev.copy().
+#' @details Theoretically, \code{expr} can be any valid R expression. However typically this should be calls to X11(), Windows(), or, perhaps dev.copy().
 #'       Importantly, the expression should create exactly one new window for \code{rk.capture.device()} to work. Keep in mind, that this is not
-#'       always the case for \code{plot(...)} and similar commands, which will re-use an existing plot window, if available. Further, note that
-#'       \code{rk.capture.device()} will not work on all platforms (most importantly, not in most MacOSX binaries). Finally, note that a captured
+#'       always the case for \code{plot(...)} and similar commands, which will re-use an existing plot window, if available.
+#'
+#' @note \code{rk.capture.device()} will not work on all platforms (most importantly, not in most MacOSX binaries). Further, note that a captured
 #'       \code{X11()} or \code{Windows} device may look similar to an \code{RK()} device, but is actually a very different thing.
 #'
-#' @seealso \link{RK()} 
+#' @seealso \link{RK}
 #'
 #' @export
 "rk.capture.device" <- function (expr) {
@@ -140,21 +156,68 @@
 	invisible (x)
 }
 
-#' \code{rk.graph.off()} closes the device that was opened by \code{rk.graph.on}. 
-#'
-#' @rdname rk.graph.on
-#' @export
-"rk.graph.off" <- function(){
-	.rk.cat.output ("\n")	# so the output will be auto-refreshed
-	ret <- dev.off()
-	
-	# dev.off () sets dev.next () as active, which may not have been active before rk.graph.on was called;
-	# so reset the correct device as active:
-	i <- get (".rk.active.device", .rk.variables)
-	if ((!is.null (i)) && (i %in% dev.list ())) ret <- dev.set (i)
+# Internal function to create wrapper around an R device function (used for X11(), Windows(), and - soon: Quartz()).
+".rk.make.device.wrapper" <- function (devicename) {
+	ret <- eval (substitute (
+		function (width=getOption("rk.screendevice.width"), height=getOption("rk.screendevice.height"), pointsize=12) {
+			rk.mode <- getOption ("rk.override.platform.devices")
+			if (identical (rk.mode, "replace") || !exists (devicename, envir=asNamespace ("grDevices"), inherits=FALSE)) {
+				if (!identical (rk.mode, "replace")) {
+					warning (paste (devicename, "()-device is not available. Falling back to RK()"))
+				}
+				args <- list ()
+				if (exists ("width", inherits=FALSE) && !missing (width)) args$width <- width
+				if (exists ("height", inherits=FALSE) && !missing (height)) args$height <- height
+				if (exists ("pointsize", inherits=FALSE) && !missing (pointsize)) args$pointsize <- pointsize
+				if (exists ("bg", inherits=FALSE) && !missing (bg)) args$bg <- bg
+				if (exists ("title", inherits=FALSE) && !missing (title)) args$title <- title
+				if (exists ("antialias", inherits=FALSE) && !missing (antialias)) args$antialias <- !identical (antialias, "none")
+				do.call (rkward::RK, args)
+			} else if (identical (rk.mode, "capture")) {
+				if (missing (width)) width <- getOption ("rk.screendevice.width")
+				if (!is.numeric (width)) width <- 7
+				if (missing (height)) height <- getOption ("rk.screendevice.height")
+				if (!is.numeric (height)) height <- 7
+				rk.capture.device (eval (body (grDevices::devicename)))
+			} else {
+				eval (body (grDevices::devicename))
+			}
+		}
+	))
+	if (exists (devicename, envir=asNamespace ("grDevices"), inherits=FALSE)) {
+		devfun <- get (devicename, asNamespace ("grDevices"))
+		formals (ret) <- formals (devfun)
+		environment (ret) <- environment (devfun)
+	}
 	ret
 }
 
+## NOTE: Adding an Rd-page for these makes "?X11" fail (R 3.0.0).
+# Overrides for platform specific R plotting devices
+#
+# These functions override the platform specific on-screen plotting devices by the same names.
+# The exact behavior depends on configuration settings, and can be one of: The original R device,
+# the original R device embedded using \code{rk.capture.device()}, or the call can be re-directed
+# to the \code{RK()} device. In the last case not all function arguments may be honored.
+#
+# @note If you want to use the \link{RK} device, you should call that, explicitly. These
+#       overrides are provided to make it easy to use scripts that refer to the platform specific
+#       plotting devices provided by R.
+#
+# @seealso \link{RK} \link{rk.capture.device} \link[grDevices]{X11} \link[grDevices]{Windows}
+#
+# @rdname DeviceOverrides
+#' @export
+"X11" <- rk.screen.device
+# NOTE: Not yet activated. Need to work on settings UI, first
+#"X11" <- .rk.make.device.wrapper ("X11")
+#' @export
+"x11" <- X11
+#' @export
+"windows" <- .rk.make.device.wrapper ("windows")
+#' @export
+"win.graph" <- .rk.make.device.wrapper ("win.graph")  # NOTE: Has different formals() than windows()
+
 #' Device for printing using the KDE print dialog
 #' 
 #' Creates a device operating on a temporary file (internally a

Modified: trunk/rkward/rkward/rbackend/rpackages/rkward/man/rk.capture.device.Rd
===================================================================
--- trunk/rkward/rkward/rbackend/rpackages/rkward/man/rk.capture.device.Rd	2013-04-27 06:21:35 UTC (rev 4728)
+++ trunk/rkward/rkward/rbackend/rpackages/rkward/man/rk.capture.device.Rd	2013-04-27 13:30:23 UTC (rev 4729)
@@ -12,7 +12,7 @@
   and if this has created a window on the screen, tries to
   embed it as an RKWard window.
 }
-\note{
+\details{
   Theoretically, \code{expr} can be any valid R expression.
   However typically this should be calls to X11(),
   Windows(), or, perhaps dev.copy().  Importantly, the
@@ -20,14 +20,16 @@
   \code{rk.capture.device()} to work. Keep in mind, that
   this is not always the case for \code{plot(...)} and
   similar commands, which will re-use an existing plot
-  window, if available. Further, note that
+  window, if available.
+}
+\note{
   \code{rk.capture.device()} will not work on all platforms
-  (most importantly, not in most MacOSX binaries). Finally,
+  (most importantly, not in most MacOSX binaries). Further,
   note that a captured \code{X11()} or \code{Windows}
   device may look similar to an \code{RK()} device, but is
   actually a very different thing.
 }
 \seealso{
-  \link{RK()}
+  \link{RK}
 }
 





More information about the rkward-tracker mailing list