[rkward-cvs] SF.net SVN: rkward:[3041] trunk/rkward

kapatp at users.sourceforge.net kapatp at users.sourceforge.net
Fri Sep 17 06:28:19 UTC 2010


Revision: 3041
          http://rkward.svn.sourceforge.net/rkward/?rev=3041&view=rev
Author:   kapatp
Date:     2010-09-17 06:28:18 +0000 (Fri, 17 Sep 2010)

Log Message:
-----------
wrapper around dev.set ()

Modified Paths:
--------------
    trunk/rkward/rkward/rbackend/rpackages/rkward/R/internal_graphics.R
    trunk/rkward/rkward/rbackend/rpackages/rkward/R/public_graphics.R
    trunk/rkward/rkward/windows/rkwindowcatcher.cpp
    trunk/rkward/tests/rkward_application_tests.R

Modified: trunk/rkward/rkward/rbackend/rpackages/rkward/R/internal_graphics.R
===================================================================
--- trunk/rkward/rkward/rbackend/rpackages/rkward/R/internal_graphics.R	2010-09-14 15:30:00 UTC (rev 3040)
+++ trunk/rkward/rkward/rbackend/rpackages/rkward/R/internal_graphics.R	2010-09-17 06:28:18 UTC (rev 3041)
@@ -99,11 +99,24 @@
 formals (dev.off) <- formals (grDevices::dev.off)
 .rk.dev.off.default <- grDevices::dev.off
 
+"dev.set" <- function ()
+{
+	ret <- eval (body (.rk.dev.set.default))
+	
+	if (getOption ("rk.enable.graphics.history") && rk.record.plot$.is.device.managed (which))
+		rk.record.plot$.set.trellis.last.object (which)
+	
+	ret
+}
+formals (dev.set) <- formals (grDevices::dev.set)
+.rk.dev.set.default <- grDevices::dev.set
+
 # see .rk.fix.assignmetns () in internal.R
 ".rk.fix.assignments.graphics" <- function ()
 {
 	assignInNamespace ("plot.new", plot.new, envir=as.environment ("package:graphics"))
 	assignInNamespace ("dev.off", dev.off, envir=as.environment ("package:grDevices"))
+	assignInNamespace ("dev.set", dev.set, envir=as.environment ("package:grDevices"))
 	
 	## set a hook defining "print.function" for lattice:
 	setHook (packageEvent ("lattice", "onLoad"),

Modified: trunk/rkward/rkward/rbackend/rpackages/rkward/R/public_graphics.R
===================================================================
--- trunk/rkward/rkward/rbackend/rpackages/rkward/R/public_graphics.R	2010-09-14 15:30:00 UTC (rev 3040)
+++ trunk/rkward/rkward/rbackend/rpackages/rkward/R/public_graphics.R	2010-09-17 06:28:18 UTC (rev 3041)
@@ -64,19 +64,6 @@
 	rk.record.plot$.my.message ("------- call end   -----------")
 }
 
-## TODO: need a wrapper around dev.set () and dev.copy!!
-## o/w a user call of dev.set () and dev.copy () will not be set/initiate the history properly
-"rk.activate.device" <- function (devId = dev.cur ())
-{
-	dev.set (devId)
-	if (getOption ("rk.enable.graphics.history")) {
-	rk.record.plot$.my.message ("------- call begin -----------")
-		rk.record.plot$.set.trellis.last.object ()
-		rk.record.plot$getDevSummary ()
-	rk.record.plot$.my.message ("------- call end   -----------")
-	}
-}
-
 # A global history of various graphics calls;
 "rk.record.plot" <- function ()
 {
@@ -111,7 +98,8 @@
 	.is.device.managed <- function (devId) as.character (devId) %in% .hP.names[-1]
 	.set.trellis.last.object <- function (devId = dev.cur ())
 	{
-		# called only from rk.activate.device ()
+		# called only from dev.set ()
+		if (!.is.device.managed (devId)) return (invisible ())
 		devId <- as.character (devId)
 		if (histPositions[[devId]]$pkg != "lattice") return (invisible ())
 		
@@ -185,14 +173,14 @@
 		d.cur <- dev.cur ()
 		histPositions <<- list ("1" = .hP.template)
 		for (d in as.character (.osd)) {
-			dev.set (as.numeric (d))
+			.rk.dev.set.default (as.numeric (d))
 			if (is.null (recordPlot ()[[1]])) # empty device
 				histPositions [[d]] <<- .hP.template
 			else
 				histPositions [[d]] <<- modifyList(.hP.template, 
 					list (is.this.plot.new = TRUE, is.this.dev.new = FALSE, pkg = "unknown"))
 		}
-		dev.set (d.cur)
+		.rk.dev.set.default (d.cur)
 		.set.hP.names ()
 		getDevSummary ()
 	}
@@ -353,9 +341,9 @@
 		unsplot <- NULL
 		unsplot.ls <- NULL
 		if (pkg %in% c("graphics", "unknown")) {
-			dev.set (as.numeric (devId))
+			.rk.dev.set.default (as.numeric (devId))
 			try (unsplot <- recordPlot(), silent=TRUE)
-			dev.set (devId.cur)
+			.rk.dev.set.default (devId.cur)
 		} else if  (pkg == "lattice") {
 			unsplot <- histPositions [[devId]]$plot
 			unsplot.ls <- histPositions [[devId]]$tlo.ls
@@ -566,7 +554,7 @@
 		
 		devId <- as.character (devId)
 		cur.devId <- dev.cur ()
-		dev.set (as.numeric(devId))
+		.rk.dev.set.default (as.numeric(devId))
 		
 		st <- .sP.index [[n]]
 		pkg <- savedPlots [[st]]$pkg
@@ -586,7 +574,7 @@
 			list (is.this.plot.new = FALSE, is.this.dev.new = FALSE, pos.prev = n, pos.cur = n, pkg = pkg, 
 				call = savedPlots [[st]]$call, plot = savedPlots [[st]]$plot, tlo.ls = savedPlots [[st]]$tlo.ls))
 		.my.hP.print (devId)
-		dev.set (cur.devId)
+		.rk.dev.set.default (cur.devId)
 		invisible()
 	}
 	

Modified: trunk/rkward/rkward/windows/rkwindowcatcher.cpp
===================================================================
--- trunk/rkward/rkward/windows/rkwindowcatcher.cpp	2010-09-14 15:30:00 UTC (rev 3040)
+++ trunk/rkward/rkward/windows/rkwindowcatcher.cpp	2010-09-17 06:28:18 UTC (rev 3041)
@@ -347,7 +347,7 @@
 void RKCaughtX11Window::activateDevice () {
 	RK_TRACE (MISC);
 
-	RKGlobals::rInterface ()->issueCommand ("rk.activate.device (" + QString::number (device_number) + ")", RCommand::App, i18n ("Activate graphics device number %1", device_number), error_dialog);
+	RKGlobals::rInterface ()->issueCommand ("dev.set (" + QString::number (device_number) + ")", RCommand::App, i18n ("Activate graphics device number %1", device_number), error_dialog);
 }
 
 void RKCaughtX11Window::copyDeviceToOutput () {
@@ -482,7 +482,7 @@
 	plot_list_action->setCurrentItem (history_position - 1);
 	plot_list_action->setEnabled (history_length > 0);
 
-	plot_force_append_action->setEnabled (RKSettingsModuleGraphics::plotHistoryEnabled ());
+	plot_force_append_action->setEnabled ((history_length > 0) && (RKSettingsModuleGraphics::plotHistoryEnabled ()));
 	plot_remove_action->setEnabled (history_length > 0);
 
 	plot_clear_history_action->setEnabled (history_length > 0);

Modified: trunk/rkward/tests/rkward_application_tests.R
===================================================================
--- trunk/rkward/tests/rkward_application_tests.R	2010-09-14 15:30:00 UTC (rev 3040)
+++ trunk/rkward/tests/rkward_application_tests.R	2010-09-17 06:28:18 UTC (rev 3041)
@@ -126,18 +126,18 @@
 			message ("mark 1")
 			rk.previous.plot (2)
 			stopifnot (dev.cur() == 3)
-			rk.activate.device (2)
+			dev.set (2)
 			compareCurrentPlotWith (plots[[2]])
 			rk.next.plot (2)
 			compareCurrentPlotWith (plots[[3]])
 
 			rk.previous.plot (3)
-			rk.activate.device (3)
+			dev.set (3)
 			compareCurrentPlotWith (plots[[4]])
 			rk.next.plot (3)
 			compareCurrentPlotWith (plots[[5]])
 
-			rk.activate.device (2)
+			dev.set (2)
 			rk.goto.plot (2, 1)
 			compareCurrentPlotWith (plots[[1]])
 
@@ -147,7 +147,7 @@
 			rk.removethis.plot (2)
 			compareCurrentPlotWith (plots[[2]])
 			message ("mark 3")
-			rk.activate.device (3)
+			dev.set (3)
 			rk.first.plot (3)
 			compareCurrentPlotWith (plots[[2]])
 
@@ -155,18 +155,18 @@
 			# this time, the plot was shown in both devices. It should not have be removed in the other!
 			rk.removethis.plot (3)
 			compareCurrentPlotWith (plots[[3]])
-			rk.activate.device (2)
+			dev.set (2)
 			compareCurrentPlotWith (plots[[2]])
 
 			## Reaching the history limit
 			message ("mark 5")
 			# three plots in history at this time, and one pending in device 2
-			rk.activate.device (3)
+			dev.set (3)
 			rk.first.plot ()
 			compareCurrentPlotWith (plots[[3]])
 			rk.last.plot ()
 			compareCurrentPlotWith (plots[[5]])
-			rk.activate.device (2)
+			dev.set (2)
 			plot (1, 1)
 			plot (1, 1)
 			# five plots in history at this time, and one pending in device 2
@@ -183,14 +183,14 @@
 			plots[[6]] <- recordPlot ()
 			rk.first.plot () 
 			# at this stage 6 plots are in history, duplicated plot is at pos = 6
-			rk.activate.device (2)
+			dev.set (2)
 			compareCurrentPlotWith (plots[[4]])
 			message ("mark 7")
 			title (main = "plot [[4]]: altered")
 			plots[[7]] <- recordPlot ()
 			rk.next.plot (); rk.previous.plot (); # overwrites at pos = 1
 			compareCurrentPlotWith (plots[[7]])
-			rk.activate.device (4)
+			dev.set (4)
 			rk.force.append.plot () # original plot 4, is now at position 7
 			compareCurrentPlotWith (plots[[4]])
 			rk.previous.plot (); # duplicated plot


This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.




More information about the rkward-tracker mailing list