[rkward-cvs] SF.net SVN: rkward:[2889] trunk/rkward/rkward
kapatp at users.sourceforge.net
kapatp at users.sourceforge.net
Mon Jun 21 04:17:49 UTC 2010
Revision: 2889
http://rkward.svn.sourceforge.net/rkward/?rev=2889&view=rev
Author: kapatp
Date: 2010-06-21 04:17:48 +0000 (Mon, 21 Jun 2010)
Log Message:
-----------
An initial implementation of graphics history by wrapping around plot.new. There are some obvious bugs which have to ironed out, but this implementation should not crash rkward.
Modified Paths:
--------------
trunk/rkward/rkward/rbackend/rpackages/rkward/R/internal.R
trunk/rkward/rkward/rbackend/rpackages/rkward/R/public.R
trunk/rkward/rkward/windows/rkcatchedx11windowpart.rc
trunk/rkward/rkward/windows/rkwindowcatcher.cpp
trunk/rkward/rkward/windows/rkwindowcatcher.h
Modified: trunk/rkward/rkward/rbackend/rpackages/rkward/R/internal.R
===================================================================
--- trunk/rkward/rkward/rbackend/rpackages/rkward/R/internal.R 2010-06-20 19:51:37 UTC (rev 2888)
+++ trunk/rkward/rkward/rbackend/rpackages/rkward/R/internal.R 2010-06-21 04:17:48 UTC (rev 2889)
@@ -473,9 +473,18 @@
formals (menu) <- formals (utils::menu)
.rk.menu.default <- utils::menu
+"plot.new" <- function ()
+{
+ rk.record.plot$record ()
+ eval (body (.rk.plot.new.default))
+}
+formals (plot.new) <- formals (graphics::plot.new)
+.rk.plot.new.default <- graphics::plot.new
+
# where masking is not enough, we need to assign in the namespace. This can only be done after package loading,
# so we have a separate function for that.
".rk.fix.assignments" <- function () {
assignInNamespace ("menu", menu, envir=as.environment ("package:utils"))
assignInNamespace ("select.list", select.list, envir=as.environment ("package:utils"))
+ assignInNamespace ("plot.new", plot.new, envir=as.environment ("package:graphics"))
}
Modified: trunk/rkward/rkward/rbackend/rpackages/rkward/R/public.R
===================================================================
--- trunk/rkward/rkward/rbackend/rpackages/rkward/R/public.R 2010-06-20 19:51:37 UTC (rev 2888)
+++ trunk/rkward/rkward/rbackend/rpackages/rkward/R/public.R 2010-06-21 04:17:48 UTC (rev 2889)
@@ -463,3 +463,111 @@
.rk.do.call ("select.list", params)
}
+# create a (global) history of various graphics calls - a rudimentary attempt
+# can do: record, showPrevious, showNext, replay
+"rk.record.plot" <- function ()
+{
+ # TODO:
+ # - record / show from which device? - Partially implemented
+ # - Create separate history for each device?
+ # - Destroy the history when a device is closed?
+ # - .... ?
+
+ env <- environment()
+ recorded <- list()
+ current <- numeric (length(dev.list()) + 2); # 1 is always null device
+ newPlotExists <- FALSE
+
+ onAddDevice <- function (deviceId)
+ {
+ recordUnsaved (deviceId)
+ current <<- c(current, current[deviceId])
+ }
+ onDelDevice <- function (deviceId = dev.cur())
+ {
+ recordUnsaved (deviceId)
+ current <<- current[-deviceId]
+ }
+ record <- function(newplotflag = TRUE, force = FALSE)
+ {
+ if (newPlotExists) {
+ if (class (try (unsavedPlot <- recordPlot(), silent=TRUE)) != 'try-error')
+ {
+ current[dev.cur()] <<- length(recorded) + 1L
+ recorded[[current[dev.cur()]]] <<- unsavedPlot
+ }
+ }
+ if (force) {
+ if (class (try (unsavedPlot <- recordPlot(), silent=TRUE)) != 'try-error')
+ {
+ recorded[[current[dev.cur()]]] <<- unsavedPlot
+ }
+ }
+ newPlotExists <<- newplotflag
+ }
+ recordUnsaved <- function (deviceId)
+ {
+ if ((current[deviceId] == length (recorded)) && newPlotExists) {
+ record (newplotflag = FALSE)
+ }
+ }
+ replay <- function(n = current[dev.cur()] - 1L, deviceId = dev.cur ())
+ {
+ if (n > 0 && n <= length(recorded)) {
+ current[deviceId] <<- n
+ replayPlot(recorded[[n]])
+ }
+ #else message("'n' not in valid range: ", n)
+ }
+ restore <- function() replay(n = length(recorded))
+ showPrevious <- function(deviceId)
+ {
+ recordUnsaved (deviceId)
+ replay(n = current[deviceId] - 1L, deviceId = deviceId)
+ }
+ showNext <- function(deviceId)
+ {
+ recordUnsaved (deviceId)
+ replay(n = current[deviceId] + 1L, deviceId = deviceId)
+ }
+ resetHistory <- function ()
+ {
+ recorded <<- list()
+ current <<- numeric (length(dev.list()) + 2)
+ newPlotExists <<- FALSE
+
+ }
+ env
+}
+rk.record.plot <- rk.record.plot ()
+
+# quick wrappers around rk.record.plot$show{Previous,Next} :
+# 1 is always the null device
+"rk.next.plot" <- function (deviceId = 2)
+{
+ # TODO - utilze the device number when rk.record.plot matures
+ cur.deviceId <- dev.cur ()
+ dev.set (which = deviceId)
+ rk.record.plot$showNext (deviceId)
+ dev.set (which = cur.deviceId)
+ invisible ()
+}
+"rk.current.plot" <- function (deviceId = 2)
+{
+ # TODO - utilze the device number when rk.record.plot matures
+ cur.deviceId <- dev.cur ()
+ dev.set (which = deviceId)
+ rk.record.plot$record (newplotflag=FALSE, force=TRUE)
+ dev.set (which = cur.deviceId)
+ invisible ()
+}
+"rk.previous.plot" <- function (deviceId = 2)
+{
+ # TODO - utilze the device number when rk.record.plot matures
+ cur.deviceId <- dev.cur ()
+ dev.set (which = deviceId)
+ rk.record.plot$showPrevious (deviceId)
+ dev.set (which = cur.deviceId)
+ invisible ()
+}
+
Modified: trunk/rkward/rkward/windows/rkcatchedx11windowpart.rc
===================================================================
--- trunk/rkward/rkward/windows/rkcatchedx11windowpart.rc 2010-06-20 19:51:37 UTC (rev 2888)
+++ trunk/rkward/rkward/windows/rkcatchedx11windowpart.rc 2010-06-21 04:17:48 UTC (rev 2889)
@@ -19,9 +19,10 @@
<Action name="set_fixed_size_manual"/>
<Merge/>
<Separator/>
+ </Menu>
<Action name="plot_prev"/>
+ <Action name="plot_curr"/>
<Action name="plot_next"/>
- </Menu>
<Merge/>
</MenuBar>
</kpartgui>
\ No newline at end of file
Modified: trunk/rkward/rkward/windows/rkwindowcatcher.cpp
===================================================================
--- trunk/rkward/rkward/windows/rkwindowcatcher.cpp 2010-06-20 19:51:37 UTC (rev 2888)
+++ trunk/rkward/rkward/windows/rkwindowcatcher.cpp 2010-06-21 04:17:48 UTC (rev 2889)
@@ -313,7 +313,8 @@
void RKCaughtX11Window::duplicateDevice () {
RK_TRACE (MISC);
- RKGlobals::rInterface ()->issueCommand ("dev.set (" + QString::number (device_number) + ")\ndev.copy (device=x11)", RCommand::App, i18n ("Duplicate graphics device number %1", device_number), error_dialog);
+// RKGlobals::rInterface ()->issueCommand ("dev.set (" + QString::number (device_number) + ")\ndev.copy (device=x11)", RCommand::App, i18n ("Duplicate graphics device number %1", device_number), error_dialog);
+ RKGlobals::rInterface ()->issueCommand ("dev.set (" + QString::number (device_number) + ")\nrk.record.plot$onAddDevice (" + QString::number (device_number) + ")\ndev.copy (device=x11)", RCommand::App, i18n ("Duplicate graphics device number %1", device_number), error_dialog);
}
void RKCaughtX11Window::nextPlot () {
@@ -322,6 +323,12 @@
RKGlobals::rInterface ()->issueCommand ("rk.next.plot (" + QString::number (device_number) + ')', RCommand::App, i18n ("Load next plot in device number %1", device_number), error_dialog);
}
+void RKCaughtX11Window::currentPlot () {
+ RK_TRACE (MISC);
+
+ RKGlobals::rInterface ()->issueCommand ("rk.current.plot (" + QString::number (device_number) + ')', RCommand::App, i18n ("Add current plot in device number %1", device_number), error_dialog);
+}
+
void RKCaughtX11Window::previousPlot () {
RK_TRACE (MISC);
@@ -358,9 +365,14 @@
action->setText (i18n ("Set specified fixed size..."));
action = actionCollection ()->addAction ("plot_prev", window, SLOT (previousPlot()));
- action->setText (i18n ("Restore previous plot"));
+// action->setText (i18n ("Restore previous plot"));
+ action->setText (i18n ("<"));
+ action = actionCollection ()->addAction ("plot_curr", window, SLOT (currentPlot()));
+// action->setText (i18n ("Add current plot"));
+ action->setText (i18n ("+"));
action = actionCollection ()->addAction ("plot_next", window, SLOT (nextPlot()));
- action->setText (i18n ("Advance to next plot"));
+// action->setText (i18n ("Advance to next plot"));
+ action->setText (i18n (">"));
action = actionCollection ()->addAction ("device_activate", window, SLOT (activateDevice()));
action->setText (i18n ("Make active"));
Modified: trunk/rkward/rkward/windows/rkwindowcatcher.h
===================================================================
--- trunk/rkward/rkward/windows/rkwindowcatcher.h 2010-06-20 19:51:37 UTC (rev 2888)
+++ trunk/rkward/rkward/windows/rkwindowcatcher.h 2010-06-21 04:17:48 UTC (rev 2889)
@@ -122,6 +122,7 @@
void duplicateDevice ();
void previousPlot ();
+ void currentPlot ();
void nextPlot ();
private slots:
void doEmbed ();
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