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

kapatp at users.sourceforge.net kapatp at users.sourceforge.net
Sat Jul 3 21:38:35 UTC 2010


Revision: 2930
          http://rkward.svn.sourceforge.net/rkward/?rev=2930&view=rev
Author:   kapatp
Date:     2010-07-03 21:38:35 +0000 (Sat, 03 Jul 2010)

Log Message:
-----------
1. make rk.record.plot as the core of the graphics history code by keeping the wrapper functions in internal_graphics.R as simplistic as possible
2. is there a need to call updateHistoryActions in RKCaughtX11Window::xPlot () where x = first, previsous, next, ...? it is already being called by the chain: .rk.graph.history.gui > updateDeviceHistory > updateHistory > updateHistoryActions
3. add an enabled action to the 'Add to History' entry
4. restricting the history length/size has _NOT_ been added yet

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/rkward/windows/rkwindowcatcher.h

Modified: trunk/rkward/rkward/rbackend/rpackages/rkward/R/internal_graphics.R
===================================================================
--- trunk/rkward/rkward/rbackend/rpackages/rkward/R/internal_graphics.R	2010-07-02 08:44:28 UTC (rev 2929)
+++ trunk/rkward/rkward/rbackend/rpackages/rkward/R/internal_graphics.R	2010-07-03 21:38:35 UTC (rev 2930)
@@ -5,7 +5,7 @@
 "rk.screen.device" <- function (..., is.preview.device = FALSE) {
 	.rk.do.call ("startOpenX11", as.character (dev.cur ()));
 
-	if (!is.preview.device) dupFrom <- dev.cur ()
+	old_dev <- dev.cur ()
 
 	if (!exists (".rk.default.device")) {
 		if (base::.Platform$OS.type == "unix") {
@@ -23,10 +23,7 @@
 
 	.rk.do.call ("endOpenX11", as.character (dev.cur ()));
 
-	if (!is.preview.device) {
-		rk.record.plot$onAddDevice (old_dev = dupFrom, deviceId = dev.cur ())
-		rk.record.plot$.rk.graph.history.gui ()
-	}
+	rk.record.plot$onAddDevice (old_dev = old_dev, deviceId = dev.cur ())
 
 	invisible (x)
 }
@@ -46,16 +43,20 @@
 ".rk.preview.devices" <- list ();
 
 ".rk.startPreviewDevice" <- function (x) {
+	rk.record.plot$printPars()
 	a <- .rk.preview.devices[[x]]
 	if (is.null (a)) {
 		a <- dev.cur ()
-		x11 (is.preview.device = TRUE)
+		rk.record.plot$.set.isPreviewDevice (TRUE)
+		x11 ()
+		rk.record.plot$.set.isPreviewDevice (FALSE)
 		if (a != dev.cur ()) {
 			.rk.preview.devices[[x]] <<- dev.cur ()
 		}
 	} else {
 		dev.set (a)
 	}
+	rk.record.plot$printPars()
 }
 
 ".rk.killPreviewDevice" <- function (x) {
@@ -71,7 +72,7 @@
 "plot.new" <- function () 
 {
 	if (dev.cur() == 1) rk.screen.device ()
-	if (dev.interactive () && !(dev.cur() %in% .rk.preview.devices)) rk.record.plot$record ()
+	rk.record.plot$record ()
 	eval (body (.rk.plot.new.default))
 }
 formals (plot.new) <- formals (graphics::plot.new)
@@ -79,17 +80,12 @@
 
 "dev.off" <- function (which = dev.cur ())
 {
-	.is.inter <- dev.interactive ()
-	if (.is.inter) { 
-		# Why use 'which'? There is a which ()!!
-		if (!(which %in% .rk.preview.devices)) rk.record.plot$onDelDevice (deviceId = which)
-
-		# see http://thread.gmane.org/gmane.comp.statistics.rkward.devel/802
-		.rk.do.call ("killDevice", as.character (which))
-	}
-
+	rk.record.plot$onDelDevice (deviceId = which)
+	
+	# see http://thread.gmane.org/gmane.comp.statistics.rkward.devel/802
+	.rk.do.call ("killDevice", as.character (which))
+	
 	ret <- eval (body (.rk.dev.off.default))
-
 	return (ret)
 }
 formals (dev.off) <- formals (grDevices::dev.off)

Modified: trunk/rkward/rkward/rbackend/rpackages/rkward/R/public_graphics.R
===================================================================
--- trunk/rkward/rkward/rbackend/rpackages/rkward/R/public_graphics.R	2010-07-02 08:44:28 UTC (rev 2929)
+++ trunk/rkward/rkward/rbackend/rpackages/rkward/R/public_graphics.R	2010-07-03 21:38:35 UTC (rev 2930)
@@ -60,7 +60,9 @@
 {
 	# TODO: 
 	# - add a length and size limit to recorded () list
+	# - add option to delete a plot from history
 	# - add one or more tests to rkward_application_tests.R
+	# - .rk.graph.history.gui () add option to update only one deviceId
 	# - .... ?
 	
 	env <- environment()
@@ -68,48 +70,94 @@
 	histPositions <- list("1" = 0) # 1 is always null device
 	newPlotExists <- list("1" = FALSE)
 	isDuplicate <- FALSE
+	isPreviewDevice <- FALSE
 	
 	.set.isDuplicate <- function (x = FALSE) { isDuplicate <<- x }
+	.set.isPreviewDevice <- function (x = FALSE) { isPreviewDevice <<- x }
 	onAddDevice <- function (old_dev = 1, deviceId = dev.cur ())
 	{
 		old_dev <- as.character (old_dev)
 		deviceId <- as.character (deviceId)
 		
+		# onAddDevice is called only from rk.screen.device, so no need to check dev.interactive ()
+		if (isPreviewDevice) return (invisible (NULL))
 		if (old_dev %in% names (histPositions) && old_dev != "1") recordUnsaved (old_dev)
 		
 		if (isDuplicate) {
 			histPositions [[deviceId]] <<- histPositions [[old_dev]]
 		} else {
-			histPositions [[deviceId]] <<- length (recorded) + 1
+			n <- length (recorded)
+			histPositions [[deviceId]] <<- if (n > 0) n + 1 else 0
 		}
 		newPlotExists [[deviceId]] <<- FALSE
+		.rk.graph.history.gui ()
 	}
 	onDelDevice <- function (deviceId = dev.cur())
 	{
 		deviceId <- as.character (deviceId)
 		
-		recordUnsaved (deviceId)
-		histPositions [[deviceId]] <<- newPlotExists [[deviceId]] <<- NULL
+		if (deviceId %in% names (histPositions) && deviceId != "1") {
+			recordUnsaved (deviceId)
+			histPositions [[deviceId]] <<- newPlotExists [[deviceId]] <<- NULL
+		}
 	}
 	record <- function(deviceId = dev.cur (), newplotflag = TRUE, force = FALSE)
 	{
 		deviceId <- as.character (deviceId)
 		
+		isManaged <- deviceId %in% names (histPositions)
+		if (!isManaged && !force) return (invisible (NULL)) # --- (*)
+		
 		cur.deviceId <- dev.cur ()
 		dev.set (as.numeric(deviceId))
 		
-		if (newPlotExists [[deviceId]]) {
+		if (isManaged) {
+			# device is managed, that is, non-preview-interactive
+			
+			if (newPlotExists [[deviceId]]) {
+				# there is a new plot on this device, so save it,
+				# immaterial of whether force == TRUE or FALSE
+				
+				if (class (try (unsavedPlot <- recordPlot(), silent=TRUE)) != 'try-error') {
+					histPositions [[deviceId]] <<- n <- length(recorded) + 1
+					recorded [[n]] <<- unsavedPlot
+					.rk.graph.history.gui ()
+				}
+			} else if (force) {
+				# no new plot on this managed device but force == TRUE
+				# in other words, called from a non-preview interactive device by clicking "Add to history" icon
+				# so overwrite the existing plot in history by the current plot
+				# 
+				# use case:
+				# go back in history and update the plot using points () or lines () or ...
+				
+				n <- histPositions [[deviceId]]
+				if (n == 0) {
+					newPlotExists [[deviceId]] <<- TRUE
+					record (deviceId, newplotflag = FALSE, force = FALSE)
+				} else {
+					if (class (try (unsavedPlot <- recordPlot(), silent=TRUE)) != 'try-error') {
+						recorded [[n]] <<- unsavedPlot
+					}
+				}
+			}
+			newPlotExists [[deviceId]] <<- newplotflag
+		} else {
+			# device is not managed but due to (*) force == TRUE
+			# in other words, called from a preview device by clicking "Add to history" icon
+			# note: non-interactive devices such as pdf() png() etc. get returned at (*)
+			#
+			# use case:
+			# save a particular "preview" plot to history (useful since preview plots are _not_
+			# automatically added to history)
+			
+			n <- length (recorded) + 1
 			if (class (try (unsavedPlot <- recordPlot(), silent=TRUE)) != 'try-error') {
-				histPositions [[deviceId]] <<- length(recorded) + 1L
-				recorded [[histPositions [[deviceId]]]] <<- unsavedPlot
+				recorded [[n]] <<- unsavedPlot
 				.rk.graph.history.gui ()
 			}
-		} else if (force) {
-			if (class (try (unsavedPlot <- recordPlot(), silent=TRUE)) != 'try-error') {
-				recorded [[histPositions [[deviceId]]]] <<- unsavedPlot
-			}
 		}
-		newPlotExists [[deviceId]] <<- newplotflag
+		
 		dev.set (cur.deviceId)
 	}
 	recordUnsaved <- function (deviceId = dev.cur ())
@@ -133,7 +181,11 @@
 		else message("replay: 'n' not in valid range: ", n)
 		dev.set (cur.deviceId)
 	}
-	showFirst <- function(deviceId = dev.cur()) replay(n = 1, deviceId)
+	showFirst <- function(deviceId = dev.cur())
+	{
+		recordUnsaved (deviceId)
+		replay(n = 1, deviceId)
+	}
 	showPrevious <- function(deviceId)
 	{
 		recordUnsaved (deviceId)
@@ -144,11 +196,16 @@
 		recordUnsaved (deviceId)
 		replay(n = histPositions [[as.character (deviceId)]] + 1L, deviceId = deviceId)
 	}
-	showLast <- function(deviceId = dev.cur()) replay(n = length(recorded), deviceId)
+	showLast <- function(deviceId = dev.cur())
+	{
+		recordUnsaved (deviceId)
+		replay(n = length(recorded), deviceId)
+	}
 	resetHistory <- function ()
 	{
 		recorded <<- list()
 		isDuplicate <<- FALSE
+		isPreviewDevice <<- FALSE
 		for (dev_num in names (histPositions)) {
 			histPositions[[dev_num]] <<- 0
 			newPlotExists [[dev_num]] <<- FALSE
@@ -207,8 +264,14 @@
 	rk.record.plot$showLast (deviceId)
 	rk.record.plot$printPars ()
 }
+## TODO: .addthis.
 "rk.current.plot" <- function (deviceId = dev.cur ())
 {
-	if (!(deviceId %in% .rk.preview.devices)) rk.record.plot$record (deviceId, newplotflag=FALSE, force=TRUE)
+	# this call is not as simple as it looks; details are handled inside rk.record.plot$record ()
+	# 
+	# reason:
+	# flixibility to add a preview plot (preview device is _not_ managed) to the graphics history
+	
+	rk.record.plot$record (deviceId, newplotflag=FALSE, force=TRUE)
 	rk.record.plot$printPars ()
 }

Modified: trunk/rkward/rkward/windows/rkwindowcatcher.cpp
===================================================================
--- trunk/rkward/rkward/windows/rkwindowcatcher.cpp	2010-07-02 08:44:28 UTC (rev 2929)
+++ trunk/rkward/rkward/windows/rkwindowcatcher.cpp	2010-07-03 21:38:35 UTC (rev 2930)
@@ -382,7 +382,7 @@
 	RK_TRACE (MISC);
 
 	RCommand* c = new RCommand ("rk.next.plot (" + QString::number (device_number) + ')', RCommand::App, i18n ("Load next plot in device number %1", device_number), error_dialog);
-	updateHistoryActions (history_length, history_position+1);
+	//updateHistoryActions (history_length, history_position+1);
 	setStatusMessage (i18n ("Loading plot from history"), c);
 	RKGlobals::rInterface ()->issueCommand (c);
 }
@@ -391,7 +391,7 @@
 	RK_TRACE (MISC);
 
 	RCommand* c = new RCommand ("rk.previous.plot (" + QString::number (device_number) + ')', RCommand::App, i18n ("Load previous plot in device number %1", device_number), error_dialog);
-	updateHistoryActions (history_length, history_position-1);
+	//updateHistoryActions (history_length, history_position-1);
 	setStatusMessage (i18n ("Loading plot from history"), c);
 	RKGlobals::rInterface ()->issueCommand (c);
 }
@@ -400,7 +400,7 @@
 	RK_TRACE (MISC);
 
 	RCommand* c = new RCommand ("rk.first.plot (" + QString::number (device_number) + ')', RCommand::App, i18n ("Load first plot in device number %1", device_number), error_dialog);
-	updateHistoryActions (history_length, 1);
+	//updateHistoryActions (history_length, 1);
 	setStatusMessage (i18n ("Loading plot from history"), c);
 	RKGlobals::rInterface ()->issueCommand (c);
 }
@@ -409,7 +409,7 @@
 	RK_TRACE (MISC);
 
 	RCommand* c = new RCommand ("rk.last.plot (" + QString::number (device_number) + ')', RCommand::App, i18n ("Load last plot in device number %1", device_number), error_dialog);
-	updateHistoryActions (history_length, history_length);
+	//updateHistoryActions (history_length, history_length);
 	setStatusMessage (i18n ("Loading plot from history"), c);
 	RKGlobals::rInterface ()->issueCommand (c);
 }
@@ -418,7 +418,7 @@
 	RK_TRACE (MISC);
 
 	RKGlobals::rInterface ()->issueCommand ("rk.current.plot (" + QString::number (device_number) + ')', RCommand::App, i18n ("Add current plot to history (device number %1)", device_number), error_dialog);
-	updateHistoryActions (history_length+1, history_length+1);
+	//updateHistoryActions (history_length+1, history_length+1);
 }
 
 void RKCaughtX11Window::clearHistory () {
@@ -427,7 +427,7 @@
 	if (KMessageBox::warningContinueCancel (this, i18n ("This will clear the plot history for all devices windows, not only this one. If this is not your intent, press cancel, below.")) != KMessageBox::Continue) return;
 
 	RKGlobals::rInterface ()->issueCommand ("rk.record.plot$resetHistory ()", RCommand::App, i18n ("Clear plot history"), error_dialog);
-	updateHistoryActions (0, 0);
+	//updateHistoryActions (0, 0);
 }
 
 void RKCaughtX11Window::updateHistoryActions (int history_length, int position) {
@@ -440,6 +440,8 @@
 	plot_prev_action->setEnabled (position > 1);
 	plot_next_action->setEnabled ((history_length > 0) && (position < history_length));
 	plot_last_action->setEnabled ((history_length > 0) && (position < history_length));
+	
+	plot_clear_history_action->setEnabled (history_length > 0);
 }
 
 void RKCaughtX11Window::setStatusMessage (const QString& message, RCommand *command) {
@@ -516,6 +518,7 @@
  	action->setText (i18n ("Add to history"));
 	action->setIcon (RKStandardIcons::getIcon (RKStandardIcons::ActionSnapshot));
 	action = actionCollection ()->addAction ("plot_clear_history", window, SLOT (clearHistory()));
+	window->plot_clear_history_action = (KAction*) action;
  	action->setText (i18n ("Clear history"));
 	action->setIcon (RKStandardIcons::getIcon (RKStandardIcons::ActionClear));
 

Modified: trunk/rkward/rkward/windows/rkwindowcatcher.h
===================================================================
--- trunk/rkward/rkward/windows/rkwindowcatcher.h	2010-07-02 08:44:28 UTC (rev 2929)
+++ trunk/rkward/rkward/windows/rkwindowcatcher.h	2010-07-03 21:38:35 UTC (rev 2930)
@@ -184,6 +184,7 @@
 	KAction *plot_next_action;
 	KAction *plot_first_action;
 	KAction *plot_last_action;
+	KAction *plot_clear_history_action;
 
 	KPassivePopup* status_popup;
 	RCommand* status_change_command;


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