From a7c7640173f09080f6dc8f883dc8882a7242308b Mon Sep 17 00:00:00 2001 From: ageay Date: Mon, 4 Feb 2013 09:34:06 +0000 Subject: [PATCH] swig of MEDCouplingUMesh.insertNextCell more general --- src/MEDCoupling_Swig/MEDCouplingBasicsTest.py | 33 +++++++++++++++++++ src/MEDCoupling_Swig/MEDCouplingCommon.i | 16 +++++---- 2 files changed, 42 insertions(+), 7 deletions(-) diff --git a/src/MEDCoupling_Swig/MEDCouplingBasicsTest.py b/src/MEDCoupling_Swig/MEDCouplingBasicsTest.py index 7f38d19bd..59642040e 100644 --- a/src/MEDCoupling_Swig/MEDCouplingBasicsTest.py +++ b/src/MEDCoupling_Swig/MEDCouplingBasicsTest.py @@ -10961,6 +10961,39 @@ class MEDCouplingBasicsTest(unittest.TestCase): self.assertEqual(12,b) ; self.assertEqual(125,len(a)) ; self.assertTrue(a.isIdentity()) pass + def testSwigUMeshInsertNextCell1(self): + m=MEDCouplingUMesh("toto",2) + # + coords=DataArrayDouble([0.,0.,1.,1.,1.,0.]) ; m.setCoords(coords) + da=DataArrayInt([0,1,2]) + m.allocateCells(0) + for i in xrange(5): + m.insertNextCell(NORM_TRI3,da) + pass + self.assertTrue(m.getNodalConnectivity().isEqual(DataArrayInt([3,0,1,2,3,0,1,2,3,0,1,2,3,0,1,2,3,0,1,2]))) + self.assertTrue(m.getNodalConnectivityIndex().isEqual(DataArrayInt([0,4,8,12,16,20]))) + # + da=DataArrayInt([0,1,2,3]) + m.allocateCells(0) + for i in xrange(5): + m.insertNextCell(NORM_TRI3,3,da) + pass + self.assertTrue(m.getNodalConnectivity().isEqual(DataArrayInt([3,0,1,2,3,0,1,2,3,0,1,2,3,0,1,2,3,0,1,2]))) + self.assertTrue(m.getNodalConnectivityIndex().isEqual(DataArrayInt([0,4,8,12,16,20]))) + # + da=DataArrayInt([0,1]) + m.allocateCells(0) + self.assertRaises(InterpKernelException,m.insertNextCell,NORM_TRI3,3,da) + # + da=DataArrayInt([0,1,2,0,1,3,0,1,4,0,1,5,0,1,6],5,3) + m.allocateCells(0) + for t in da: + m.insertNextCell(NORM_TRI3,t) + pass + self.assertTrue(m.getNodalConnectivity().isEqual(DataArrayInt([3,0,1,2,3,0,1,3,3,0,1,4,3,0,1,5,3,0,1,6]))) + self.assertTrue(m.getNodalConnectivityIndex().isEqual(DataArrayInt([0,4,8,12,16,20]))) + pass + def setUp(self): pass pass diff --git a/src/MEDCoupling_Swig/MEDCouplingCommon.i b/src/MEDCoupling_Swig/MEDCouplingCommon.i index b718ea8bb..fa9dac3ec 100644 --- a/src/MEDCoupling_Swig/MEDCouplingCommon.i +++ b/src/MEDCoupling_Swig/MEDCouplingCommon.i @@ -1605,11 +1605,12 @@ namespace ParaMEDMEM void insertNextCell(INTERP_KERNEL::NormalizedCellType type, int size, PyObject *li) throw(INTERP_KERNEL::Exception) { - int sz; - INTERP_KERNEL::AutoPtr tmp=convertPyToNewIntArr2(li,&sz); - if(size>sz) + int szArr,sw,iTypppArr; + std::vector stdvecTyyppArr; + const int *tmp=convertObjToPossibleCpp1_Safe(li,sw,szArr,iTypppArr,stdvecTyyppArr); + if(size>szArr) { - std::ostringstream oss; oss << "Wrap of MEDCouplingUMesh::insertNextCell : request of connectivity with length " << size << " whereas the length of input is " << sz << " !"; + std::ostringstream oss; oss << "Wrap of MEDCouplingUMesh::insertNextCell : request of connectivity with length " << size << " whereas the length of input is " << szArr << " !"; throw INTERP_KERNEL::Exception(oss.str().c_str()); } self->insertNextCell(type,size,tmp); @@ -1617,9 +1618,10 @@ namespace ParaMEDMEM void insertNextCell(INTERP_KERNEL::NormalizedCellType type, PyObject *li) throw(INTERP_KERNEL::Exception) { - int sz; - INTERP_KERNEL::AutoPtr tmp=convertPyToNewIntArr2(li,&sz); - self->insertNextCell(type,sz,tmp); + int szArr,sw,iTypppArr; + std::vector stdvecTyyppArr; + const int *tmp=convertObjToPossibleCpp1_Safe(li,sw,szArr,iTypppArr,stdvecTyyppArr); + self->insertNextCell(type,szArr,tmp); } DataArrayInt *getNodalConnectivity() throw(INTERP_KERNEL::Exception) -- 2.39.2