Commit b4e85dbe authored by Daniel Brown's avatar Daniel Brown
Browse files

Adding exception handling to add puts as extra lines if they can't be handled...

Adding exception handling to add puts as extra lines if they can't be handled for backward compatiability
parent aa3205bd
......@@ -319,7 +319,78 @@ class gauss(object):
kat.nodes[node].setGauss(kat.components[component], gp)
else:
kat.nodes[node].setGauss(kat.components[component], gpx, gpy)
# class tf(Command):
#
# class fQ(object):
# def __init__(self, f, Q, tf):
# assert(tf is not None)
# self._tf = tf
# self.__f = Param("f", self, None, canFsig=False, isPutable=True, isPutter=False, isTunable=True)
# self.__Q = Param("Q", self, None, canFsig=False, isPutable=True, isPutter=False, isTunable=True)
#
# def _register_param(self, param):
# self._tf._params.append(param)
#
# @property
# def f(self): return self.__f
# @f.setter
# def f(self,value): self.__f.value = SIfloat(value)
#
# @property
# def Q(self): return self.__Q
# @Q.setter
# def Q(self,value): self.__Q.value = SIfloat(value)
#
# def __init__(self, name):
# Command.__init__(self, name, False)
# self.zeros = []
# self.poles = []
# self.gain = 1
# self.phase = 0
# self._params = []
#
# def addPole(self,f, Q):
# self.poles.append(tf.fQ(SIfloat(f), SIfloat(Q), self))
#
# def addZero(self,f, Q):
# self.zeros.append(tf.fQ(SIfloat(f), SIfloat(Q), self))
#
# @staticmethod
# def parseFinesseText(text):
# values = text.split()
#
# if ((len(values)-4) % 3) != 0:
# raise pkex.BasePyKatException("Transfer function Finesse code format incorrect '{0}'".format(text))
#
# _tf = tf(values[1])
#
# _tf.gain = SIfloat(values[2])
# _tf.phase = SIfloat(values[3])
#
# N = int((len(values)-4) / 3)
#
# for i in range(1,N+1):
# if values[i*3+1] == 'p':
# _tf.addPole(SIfloat(values[i*3+2]), SIfloat(values[i*3+3]))
# elif values[i*3+1] == 'z':
# _tf.addZero(SIfloat(values[i*3+2]), SIfloat(values[i*3+3]))
# else:
# raise pkex.BasePyKatException("Transfer function pole/zero Finesse code format incorrect '{0}'".format(text))
#
# return _tf
#
# def getFinesseText(self):
# rtn = "tf {name} {gain} {phase} ".format(name=self.name,gain=self.gain,phase=self.phase)
#
# for p in self.poles:
# rtn += "p {f} {Q} ".format(f=p.f, Q=p.Q)
#
# for z in self.zeros:
# rtn += "p {f} {Q} ".format(f=z.f, Q=z.Q)
#
# return rtn
class tf(Command):
class fQ(object):
......@@ -339,7 +410,7 @@ class tf(Command):
def addZero(self,f, Q):
self.zeros.append(tf.fQ(SIfloat(f), SIfloat(Q)))
@staticmethod
def parseFinesseText(text):
values = text.split()
......
......@@ -1268,20 +1268,31 @@ class kat(object):
target = values[2]
variable = values[3]
if not hasattr(self, obj):
raise pkex.BasePyKatException("put command `{0}` refers to non-existing component".format(line))
try:
if not hasattr(self, obj):
raise pkex.BasePyKatException("put command `{0}` refers to non-existing component".format(line))
obj = getattr(self, obj)
obj = getattr(self, obj)
if not hasattr(obj, target):
raise pkex.BasePyKatException("put command component `{0}` does not have a parameter `{1}`".format(line, target))
target = getattr(obj, target)
if not hasattr(obj, target):
raise pkex.BasePyKatException("put command component `{0}` does not have a parameter `{1}`".format(line, target))
if not target.isPutable:
raise pkex.BasePyKatException("put command `{0}` parameter `{1}` cannot be put to".format(line, target))
target.put(self.getVariable(variable.replace('$', '')), alt)
target = getattr(obj, target)
except pkex.BasePyKatException as ex:
if self.verbose:
print("Warning: ", ex.msg)
print ("Parsing `{0}` into pykat object not implemented yet, added as extra line.".format(line))
if not target.isPutable:
raise pkex.BasePyKatException("put command `{0}` parameter `{1}` cannot be put to".format(line, target))
obj = line
# manually add the line to the block contents
self.__blocks[block].contents.append(line)
target.put(self.getVariable(variable.replace('$', '')), alt)
elif (first == "scale"):
v = line.split()
......@@ -1419,7 +1430,7 @@ class kat(object):
except pkex.BasePyKatException as ex:
pkex.PrintError("Error parsing line: '%s':"% line, ex)
pkex.PrintError("Pykat error parsing line: '%s':"% line, ex)
sys.exit(1)
def saveScript(self, filename=None):
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment