Ran update_copyright.py, which fixed some spellcheck errors in hooke/plugin/curve.py
[hooke.git] / hooke / plugin / curve.py
index 75f28eec110f63d69705fe235e61e7bce981cd32..d58d6605b4e94a623c7e8b29148e8d886edab81e 100644 (file)
@@ -1,5 +1,5 @@
-# Copyright (C) 2008-2010 Alberto Gomez-Kasai
-#                         Fabiano's Benedetti
+# Copyright (C) 2008-2010 Alberto Gomez-Casado
+#                         Fabrizio Benedetti
 #                         Massimo Sandal <devicerandom@gmail.com>
 #                         W. Trevor King <wking@drexel.edu>
 #
@@ -29,6 +29,7 @@ import copy
 import numpy
 
 from ..command import Command, Argument, Failure
+from ..command_stack import CommandStack
 from ..curve import Data
 from ..engine import CommandMessage
 from ..util.calculus import derivative
@@ -91,7 +92,7 @@ class CurveCommand (Command):
         Notes
         -----
         `hooke` is intended to attach the selected curve to the local
-        playlist, and the returned curve should not be effected by the
+        playlist; the returned curve should not be effected by the
         state of `hooke`.  This is important for reliable
         :class:`~hooke.command_stack.CommandStack`\s.
         """
@@ -123,14 +124,15 @@ class CurveCommand (Command):
         (e.g. :class:`GetCommand`) to avoid adding themselves to the
         stack entirely.
         """
-        curve = self._curve(hooke=None, params=params)
-        if (len(curve.command_stack) > 0
-            and curve.command_stack[-1].command == self.name
-            and curve.command_stack[-1].arguments == params):
-            pass  # no need to place duplicate calls on the stack.
-        else:
-            curve.command_stack.append(CommandMessage(
-                    self.name, params))
+        if params['stack'] == True:
+            curve = self._curve(hooke=None, params=params)
+            if (len(curve.command_stack) > 0
+                and curve.command_stack[-1].command == self.name
+                and curve.command_stack[-1].arguments == params):
+                pass  # no need to place duplicate calls on the stack.
+            else:
+                curve.command_stack.append(CommandMessage(
+                        self.name, params))
 
 
 class BlockCommand (CurveCommand):
@@ -258,7 +260,8 @@ class CurvePlugin (Builtin):
         self._commands = [
             GetCommand(self), InfoCommand(self), DeltaCommand(self),
             ExportCommand(self), DifferenceCommand(self),
-            DerivativeCommand(self), PowerSpectrumCommand(self)]
+            DerivativeCommand(self), PowerSpectrumCommand(self),
+            ClearStackCommand(self)]
 
 
 # Define commands
@@ -621,6 +624,19 @@ Otherwise, the chunks are end-to-end, and not overlapping.
         return params
 
 
+class ClearStackCommand (CurveCommand):
+    """Empty a curve's command stack.
+    """
+    def __init__(self, plugin):
+        super(ClearStackCommand, self).__init__(
+            name='clear curve command stack',
+            help=self.__doc__, plugin=plugin)
+
+    def _run(self, hooke, inqueue, outqueue, params):
+        curve = self._curve(hooke, params)
+        curve.command_stack = CommandStack()
+
+
 class OldCruft (object):
 
     def do_forcebase(self,args):