[rkward-cvs] SF.net SVN: rkward:[2936] trunk/rkward/rkward/rbackend/rpackages/rkward/R/ public_graphics.R

kapatp at users.sourceforge.net kapatp at users.sourceforge.net
Mon Jul 5 08:49:36 UTC 2010


Revision: 2936
          http://rkward.svn.sourceforge.net/rkward/?rev=2936&view=rev
Author:   kapatp
Date:     2010-07-05 08:49:36 +0000 (Mon, 05 Jul 2010)

Log Message:
-----------
remove a plot form history: more structuring

Modified Paths:
--------------
    trunk/rkward/rkward/rbackend/rpackages/rkward/R/public_graphics.R

Modified: trunk/rkward/rkward/rbackend/rpackages/rkward/R/public_graphics.R
===================================================================
--- trunk/rkward/rkward/rbackend/rpackages/rkward/R/public_graphics.R	2010-07-04 18:59:13 UTC (rev 2935)
+++ trunk/rkward/rkward/rbackend/rpackages/rkward/R/public_graphics.R	2010-07-05 08:49:36 UTC (rev 2936)
@@ -164,7 +164,7 @@
 			record (deviceId, newplotflag = FALSE)
 		}
 	}
-	remove <- function (deviceId = dev.cur ())
+	remove <- function (deviceId = dev.cur (), pos = NULL) # pos can be of length > 1
 	{
 		history_length <- length (recorded)
 		if (history_length <= 1) {
@@ -172,34 +172,58 @@
 			return (invisible (NULL))
 		}
 		
-		deviceId <- as.character (deviceId)
-		n <- histPositions [[deviceId]] # history position of the calling device
-		
-		if (newPlotExists [[deviceId]]) {
-			# for unsaved plots, just set the flag to FALSE and replay the previous (== n) plot
+		pop.and.update <- function (n) {
+			recorded <<- recorded [-n]
+			len.r <- length (recorded)
 			
-			newPlotExists [[deviceId]] <<- FALSE
-			replay (n, deviceId)
-		} else {
-			# a saved plot: delete it:
-			recorded [[n]] <<- NULL
+			pos.aff <- unlist (histPositions) >= min (n) # all affected positions
+			pos.rem <- unlist (histPositions) %in% n # only removed positions
 			
-			# devices with position = n:
-			dEqn <- names (histPositions)[unlist (histPositions) == n]
-			# devices with position > n:
-			dGtn <- names (histPositions)[unlist (histPositions) > n]
+			dEqn <- names (histPositions)[pos.rem] # devices whose plots were removed
+			for (d in dEqn) {
+				m <- min (histPositions[[d]] - sum (n <= histPositions[[d]]) + 1, len.r)
+				if (newPlotExists[[d]]) {
+					histPositions [[d]] <<- m
+					.rk.graph.history.gui (d)
+				} else
+					replay (n = m, deviceId = d)
+			}
 			
-			if (n > length (recorded)) n <- n - 1
+			dGtn <- names (histPositions)[pos.aff & !pos.rem] # affected devices whose plots were _NOT_ removed
+			for (d in dGtn) {
+				histPositions[[d]] <<- histPositions[[d]] - sum (n <= histPositions[[d]])
+			}
+			.rk.graph.history.gui (dGtn)
 			
-			# for all devices in dEqn, replay the next (== n) plot, or, if this was the last plot then,
-			# replay the previous (== n) plot
-			lapply (X = dEqn, function (d,N) replay (n = N, deviceId = d), N = n)
-			
-			# for all devices in dGtn, decrese their position counter by 1 and update the gui
-			histPositions [dGtn] <<- lapply (histPositions [dGtn], FUN = function (d) d-1)
-			.rk.graph.history.gui (dGtn)
+			.rk.graph.history.gui (names (histPositions) [unlist (histPositions) == len.r])
 		}
 		
+		if (is.null (pos)) {
+			# call from: a managed device by clicking on 'Remove from history' icon
+			
+			if (is.null (deviceId)) stop ('Both deviceId and pos are NULL')
+			deviceId <- as.character (deviceId)
+			if (! (deviceId %in% names(histPositions))) stop (paste ('Device', deviceId, 'is not managed'))
+			
+			pos <- histPositions [[deviceId]]
+			
+			if (newPlotExists [[deviceId]]) {
+				# current plot, which is to be deleted, hasn't been saved to history yet, so just 
+				# set its flag to FALSE and replay the previous plot which is @ pos and not (pos-1)
+				
+				newPlotExists [[deviceId]] <<- FALSE
+				replay (n = pos, deviceId)
+			} else {
+				# current plot is a saved plot: so pop it and update the "affected" devices
+				
+				pop.and.update (n = pos)
+			}
+		} else if (all(pos > 0) && all (pos <= history_length)) {
+			# not called from any managed devices, so pop and update
+			pop.and.update (n = pos)
+		} else
+			stop (paste ('Invalid position(s)'))
+		
 		invisible (NULL)
 	}
 	replay <- function(n = histPositions [[as.character (deviceId)]] - 1L, deviceId = dev.cur ())
@@ -257,7 +281,7 @@
 	}
 	.rk.graph.history.gui <- function (deviceIds = names (histPositions))
 	{
-		# this function is called whenever the history length changes (ie, increases, for now)
+		# this function is called whenever the history length changes
 		# or the position changes in any device.
 		
 		deviceIds <- deviceIds [deviceIds != "1"] # ignore NULL device


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