Added command_stack option to all' default.
[hooke.git] / hooke / plugin / curve.py
index e6d5ce322d23eafcaeb24887c65783b1078f0b0c..931dca3e69ef6e033da4d034ea28467c32263ec2 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
@@ -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
@@ -282,8 +285,8 @@ class InfoCommand (CurveCommand):
             Argument(name='all', type='bool', default=False, count=1,
                      help='Get all curve information.'),
             ]
-        self.fields = ['name', 'path', 'experiment', 'driver', 'filetype', 'note',
-                       'blocks', 'block sizes']
+        self.fields = ['name', 'path', 'experiment', 'driver', 'filetype',
+                       'note', 'command stack', 'blocks', 'block sizes']
         for field in self.fields:
             args.append(Argument(
                     name=field, type='bool', default=False, count=1,
@@ -297,7 +300,7 @@ class InfoCommand (CurveCommand):
         fields = {}
         for key in self.fields:
             fields[key] = params[key]
-        if reduce(lambda x,y: x and y, fields.values()) == False:
+        if reduce(lambda x,y: x or y, fields.values()) == False:
             params['all'] = True # No specific fields set, default to 'all'
         if params['all'] == True:
             for key in self.fields:
@@ -327,6 +330,9 @@ class InfoCommand (CurveCommand):
     def _get_note(self, curve):
         return curve.info.get('note', None)
                               
+    def _get_command_stack(self, curve):
+        return curve.command_stack
+
     def _get_blocks(self, curve):
         return len(curve.data)
 
@@ -621,6 +627,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):