diff --git a/catima.pyx b/catima.pyx index f4369f0..b9311d8 100644 --- a/catima.pyx +++ b/catima.pyx @@ -1,16 +1,41 @@ +""" + catima python module + ~~~~~~~~~~~ + This module provides interface to the catima c++ library + :copyright: (c) 2017 by Andrej Prochazka + :licence: GNU Affero General Public License, see LICENCE for more details +""" + cimport catimac from enum import IntEnum import numpy cdef class Material: cdef catimac.Material cbase - def __cinit__(self, elements): + def __cinit__(self, elements=None, thickness=None, density=None): self.cbase = catimac.Material() - if(elements and isinstance(elements[0],int)): + 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) @@ -36,6 +61,35 @@ cdef class Material: else: return self.cbase.thickness(val) +class material(IntEnum): + PLASTIC = 201 + AIR = 202 + CH2 = 203 + LH2 = 204 + LD2 = 205 + WATER = 206 + DIAMOND = 207 + GLASS = 208 + ALMG3 = 209 + ARCO2_30 = 210 + CF4 = 211 + ISOBUTANE = 212 + KAPTON = 213 + MYLAR = 214 + NAF = 215 + P10 = 216 + POLYOLEFIN = 217 + CMO2 = 218 + SUPRASIL = 219 + HAVAR = 220 + +def get_material(int matid): + res = Material() + cdef catimac.Material cres = catimac.get_material(matid); + res.from_c(cres) + return res + + cdef class Target: cdef catimac.Target cbase @@ -49,34 +103,56 @@ cdef class Target: return self.cbase.Z cdef class Layers: - cdef catimac.Layers cbase - - def __cinit__(self): - self.cbase = catimac.Layers() - self.materials = [] + 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): + return self.materials[key] def __getitem__(self, key): - if(isinstance(key,int)): - return self.materials[key] + if(isinstance(key,int) and key