###
# Copyright 2008-2011 Diamond Light Source Ltd.
# This file is part of Diffcalc.
#
# Diffcalc is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# Diffcalc is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Diffcalc.  If not, see <http://www.gnu.org/licenses/>.
###
from diffcalc.util import allnum

def getNameFromScannableOrString(o):
        try:  # it may be a scannable
            return o.getName()
        except AttributeError:
            return str(o)
            raise TypeError()


class DummyParameterManager(object):

    def getParameterDict(self):
        return {}

    def _setParameter(self, name, value):
        raise KeyError(name)

    def _getParameter(self, name):
        raise KeyError(name)

    def update_tracked(self):
        pass


def sim(self, scn, hkl):
    """sim hkl scn -- simulates moving scannable (not all)
    """
    if not isinstance(hkl, (tuple, list)):
        raise TypeError

    if not allnum(hkl):
        raise TypeError()

    try:
        print scn.simulateMoveTo(hkl)
    except AttributeError:
        raise TypeError("The first argument does not support simulated moves")
