diff --git a/isd.i b/isd.i index f2e88869406042f612af630e1acff5d54071cdcf..625bcd216d664c971b53b2239686affe5ee419fa 100644 --- a/isd.i +++ b/isd.i @@ -11,28 +11,29 @@ %include <std_string.i> -%include "Isd.h" %pythoncode %{ - import json - import numpy as np - @classmethod - def loads(cls, stream): - isd = cls() - if not isinstance(stream, dict): - stream = json.loads(stream) - for k, v in stream.items(): - if isinstance(v, np.ndarray): - v = v.tolist() - if isinstance(v, list): - for i in v: - isd.addParam(k, str(i)) - isd.addParam(k, str(v)) - return isd + import json +%} - @classmethod - def load(cls, fp): - return cls.loads(fp.read()) +%include "Isd.h" +%extend csm::Isd { + %pythoncode %{ + import json + import numpy as np + @classmethod + def loads(cls, stream): + isd = cls() + if not isinstance(stream, dict): + stream = json.loads(stream) + for k, v in stream.items(): + if isinstance(v, list): + for i in v: + isd.addParam(k, str(i)) + isd.addParam(k, str(v)) + return isd - Isd.load = load - Isd.loads = loads -%} \ No newline at end of file + @classmethod + def load(cls, fp): + return cls.loads(fp.read()) + %} +} \ No newline at end of file diff --git a/rastergm.i b/rastergm.i index 93ef9e2f082c95a13477a988de428833fced503f..60fc6c147401610f7af52fd9fa3803ed367a2d0f 100644 --- a/rastergm.i +++ b/rastergm.i @@ -4,8 +4,18 @@ %} %ignore CSM_RASTER_FAMILY; +%include exception.i +%exception { + try { + $action + } catch (const std::exception &e) { + SWIG_exception(SWIG_RuntimeError, e.what()); + } +} + %import model.i %import geometricmodel.i %import csm.i + %include RasterGM.h