%newobject ParaMEDMEM::MEDFileMeshes::New;
%newobject ParaMEDMEM::MEDFileMeshes::getMeshAtPos;
%newobject ParaMEDMEM::MEDFileMeshes::getMeshWithName;
+%newobject ParaMEDMEM::MEDFileMeshes::__getitem__;
%newobject ParaMEDMEM::MEDFileFields::New;
%newobject ParaMEDMEM::MEDFileFields::getFieldWithName;
%newobject ParaMEDMEM::MEDFileFields::getFieldAtPos;
+%newobject ParaMEDMEM::MEDFileFields::__getitem__;
%newobject ParaMEDMEM::MEDFileFieldMultiTS::New;
%newobject ParaMEDMEM::MEDFileFieldMultiTS::getFieldAtLevel;
%newobject ParaMEDMEM::MEDFileFieldMultiTS::getFieldAtTopLevel;
{
return self->simpleRepr();
}
+
+ MEDFileMesh *__getitem__(PyObject *obj) throw(INTERP_KERNEL::Exception)
+ {
+ if(PyInt_Check(obj))
+ {
+ MEDFileMesh *ret=self->getMeshAtPos((int)PyInt_AS_LONG(obj));
+ if(ret)
+ ret->incrRef();
+ return ret;
+ }
+ else if(PyString_Check(obj))
+ {
+ MEDFileMesh *ret=self->getMeshWithName(PyString_AsString(obj));
+ if(ret)
+ ret->incrRef();
+ return ret;
+ }
+ else
+ throw INTERP_KERNEL::Exception("MEDFileMeshes::__getitem__ : only integer or string with meshname supported !");
+ }
+
+ MEDFileMeshes *__setitem__(int obj, MEDFileMesh *mesh) throw(INTERP_KERNEL::Exception)
+ {
+ self->setMeshAtPos(obj,mesh);
+ return self;
+ }
MEDFileMesh *getMeshAtPos(int i) const throw(INTERP_KERNEL::Exception)
{
{
return self->simpleRepr();
}
+
+ MEDFileFieldMultiTS *__getitem__(PyObject *obj) throw(INTERP_KERNEL::Exception)
+ {
+ if(PyInt_Check(obj))
+ {
+ return self->getFieldAtPos((int)PyInt_AS_LONG(obj));
+ }
+ else if(PyString_Check(obj))
+ {
+ return self->getFieldWithName(PyString_AsString(obj));
+ }
+ else
+ throw INTERP_KERNEL::Exception("MEDFileFields::__getitem__ : only integer or string with fieldname supported !");
+ }
+
+ MEDFileFields *__setitem__(int obj, MEDFileFieldMultiTS *field) throw(INTERP_KERNEL::Exception)
+ {
+ self->setFieldAtPos(obj,field);
+ return self;
+ }
}
};
self.assertEqual(2,d2.getNumberOfMeshes())
self.assertEqual(3,d2.getNumberOfFields())
self.assertTrue(isinstance(d2.getMeshes().getMeshAtPos(0),MEDFileUMesh))
+ self.assertTrue(isinstance(d2.getMeshes()[0],MEDFileUMesh))
+ self.assertTrue(isinstance(d2.getMeshes()['2DCurveMesh_1'],MEDFileUMesh))
m1bis=d2.getMeshes().getMeshAtPos(0).getMeshAtLevel(0)
self.assertTrue(m1.isEqual(m1bis,1e-12))
self.assertEqual(('f1', 'f21', 'f22'),d2.getFields().getFieldsNames())
self.assertEqual([(-1, -1, 0.0)],d2.getFields().getFieldAtPos(2).getTimeSteps())
+ self.assertEqual([(-1, -1, 0.0)],d2.getFields()[2].getTimeSteps())
self.assertEqual([(-1, -1, 0.0)],d2.getFields().getFieldWithName("f21").getTimeSteps())
+ self.assertEqual([(-1, -1, 0.0)],d2.getFields()["f21"].getTimeSteps())
pass
def testMEDField9(self):
#include <vector>
-static PyObject* convertMEDFileMesh(ParaMEDMEM::MEDFileMesh* mesh, int owner)
+static PyObject* convertMEDFileMesh(ParaMEDMEM::MEDFileMesh* mesh, int owner) throw(INTERP_KERNEL::Exception)
{
PyObject *ret=0;
if(dynamic_cast<ParaMEDMEM::MEDFileUMesh *>(mesh))
if(dynamic_cast<ParaMEDMEM::MEDFileCMesh *>(mesh))
ret=SWIG_NewPointerObj((void*)mesh,SWIGTYPE_p_ParaMEDMEM__MEDFileCMesh,owner);
if(!ret)
- {
- PyErr_SetString(PyExc_TypeError,"Not recognized type of MEDFileMesh on downcast !");
- PyErr_Print();
- }
+ throw INTERP_KERNEL::Exception("Not recognized type of MEDFileMesh on downcast !");
return ret;
}
-static std::vector<std::pair<int,int> > convertTimePairIdsFromPy(PyObject *pyLi)
+static std::vector<std::pair<int,int> > convertTimePairIdsFromPy(PyObject *pyLi) throw(INTERP_KERNEL::Exception)
{
std::vector<std::pair<int,int> > ret;
if(PyList_Check(pyLi))
std::pair<int,int> p;
int size2=PyTuple_Size(o);
if(size2!=2)
- {
- const char msg[]="tuples in list must be of size 2 (dt,it) !";
- ret.clear();
- PyErr_SetString(PyExc_TypeError,msg);
- PyErr_Print();
- throw INTERP_KERNEL::Exception(msg);
- }
+ throw INTERP_KERNEL::Exception("tuples in list must be of size 2 (dt,it) !");
PyObject *o0=PyTuple_GetItem(o,0);
if(PyInt_Check(o0))
p.first=(int)PyInt_AS_LONG(o0);
else
- {
- const char msg[]="First elem of tuples in list must be integer : dt !";
- ret.clear();
- PyErr_SetString(PyExc_TypeError,msg);
- PyErr_Print();
- throw INTERP_KERNEL::Exception(msg);
- }
+ throw INTERP_KERNEL::Exception("First elem of tuples in list must be integer : dt !");
PyObject *o1=PyTuple_GetItem(o,1);
if(PyInt_Check(o1))
p.second=(int)PyInt_AS_LONG(o1);
else
- {
- const char msg[]="Second elem of tuples in list must be integer : dt !";
- ret.clear();
- PyErr_SetString(PyExc_TypeError,msg);
- PyErr_Print();
- throw INTERP_KERNEL::Exception(msg);
- }
+ throw INTERP_KERNEL::Exception("Second elem of tuples in list must be integer : dt !");
ret[i]=p;
}
else
- {
- const char msg[]="list must contain tuples only";
- ret.clear();
- PyErr_SetString(PyExc_TypeError,msg);
- PyErr_Print();
- throw INTERP_KERNEL::Exception(msg);
- return ret;
- }
+ throw INTERP_KERNEL::Exception("list must contain tuples only");
}
}
else
- {
- ret.clear();
- const char msg[]="convertTimePairIdsFromPy : not a list";
- PyErr_SetString(PyExc_TypeError,msg);
- PyErr_Print();
- throw INTERP_KERNEL::Exception(msg);
- }
+ throw INTERP_KERNEL::Exception("convertTimePairIdsFromPy : not a list");
return ret;
}
return ret;
}
-static std::vector<const ParaMEDMEM::MEDCouplingUMesh *> convertUMeshVecFromPy(PyObject *pyLi)
+static std::vector<const ParaMEDMEM::MEDCouplingUMesh *> convertUMeshVecFromPy(PyObject *pyLi) throw(INTERP_KERNEL::Exception)
{
std::vector<const ParaMEDMEM::MEDCouplingUMesh *> ret;
if(PyList_Check(pyLi))
void *argp;
int status=SWIG_ConvertPtr(obj,&argp,SWIGTYPE_p_ParaMEDMEM__MEDCouplingUMesh,0|0);
if(!SWIG_IsOK(status))
- {
- const char msg[]="list must contain only MEDCouplingUMesh";
- PyErr_SetString(PyExc_TypeError,msg);
- PyErr_Print();
- throw INTERP_KERNEL::Exception(msg);
- }
+ throw INTERP_KERNEL::Exception("list must contain only MEDCouplingUMesh");
ParaMEDMEM::MEDCouplingUMesh *arg=reinterpret_cast< ParaMEDMEM::MEDCouplingUMesh * >(argp);
ret[i]=arg;
}
}
- else
+ else if(PyTuple_Check(pyLi))
{
- ret.clear();
- const char msg[]="convertFieldDoubleVecFromPy : not a list";
- PyErr_SetString(PyExc_TypeError,msg);
- PyErr_Print();
- throw INTERP_KERNEL::Exception(msg);
+ int size=PyTuple_Size(pyLi);
+ ret.resize(size);
+ for(int i=0;i<size;i++)
+ {
+ PyObject *obj=PyTuple_GetItem(pyLi,i);
+ void *argp;
+ int status=SWIG_ConvertPtr(obj,&argp,SWIGTYPE_p_ParaMEDMEM__MEDCouplingUMesh,0|0);
+ if(!SWIG_IsOK(status))
+ throw INTERP_KERNEL::Exception("tuple must contain only MEDCouplingUMesh");
+ ParaMEDMEM::MEDCouplingUMesh *arg=reinterpret_cast< ParaMEDMEM::MEDCouplingUMesh * >(argp);
+ ret[i]=arg;
+ }
}
+ else
+ throw INTERP_KERNEL::Exception("convertFieldDoubleVecFromPy : not a list nor a tuple");
return ret;
}