From 8f63d653145d133b6641931e3a704682ab1098bc Mon Sep 17 00:00:00 2001 From: hrocho Date: Tue, 1 Aug 2017 17:34:44 +0200 Subject: [PATCH] python update 2 --- catima.pyx | 85 ++++++++++++++++++++++++++++++++++------ tests/test.py | 106 +++++++++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 177 insertions(+), 14 deletions(-) diff --git a/catima.pyx b/catima.pyx index b9e40dd..b9311d8 100644 --- a/catima.pyx +++ b/catima.pyx @@ -12,16 +12,30 @@ import numpy cdef class Material: cdef catimac.Material cbase - def __cinit__(self, elements=None): + def __cinit__(self, elements=None, thickness=None, density=None): self.cbase = catimac.Material() if(elements and (isinstance(elements[0],float) or isinstance(elements[0],int))): self.cbase.add_element(elements[0],elements[1],elements[2]) if(elements and isinstance(elements[0],list)): for e in elements: self.cbase.add_element(e[0],e[1],e[2]) + if(not thickness is None): + self.thickness(thickness) + if(not density is None): + self.density(density) cdef from_c(self, catimac.Material &other): self.cbase = other + + cdef catimac.Material getc(self): + cdef catimac.Material res + res = self.cbase + return res + + def copy(self): + res = Material() + res.cbase = self.cbase + return res def add_element(self, a, z , s): self.cbase.add_element(a, z, s) @@ -89,29 +103,42 @@ cdef class Target: return self.cbase.Z cdef class Layers: - cdef catimac.Layers cbase cdef public: materials def __init__(self): self.materials=[] def add(self,Material m): - self.cbase.add(m.cbase) - self.materials.append(m) + self.materials.append(m.copy()) def num(self): - return self.cbase.num() + return len(self.materials) def get(self, key): - cdef catimac.Material cmat = self.cbase[key] - res = Material() - res.from_c(cmat) - return res + return self.materials[key] def __getitem__(self, key): if(isinstance(key,int) and key