Salome HOME
Fix: getCellsContainingPoints() in case of polyhedron with a face containing colinear...
[tools/medcoupling.git] / src / MEDCoupling_Swig / MEDCouplingDataArrayTypemaps.i
index 31ff419eaae26ab3c46dee60c0a2fa9d76288b3d..9208a72f44867f5702f18c949343429555858eb3 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2007-2019  CEA/DEN, EDF R&D
+// Copyright (C) 2007-2024  CEA, EDF
 //
 // This library is free software; you can redistribute it and/or
 // modify it under the terms of the GNU Lesser General Public
@@ -681,6 +681,27 @@ static void convertPyToVectorPairInt(PyObject *pyLi, std::vector< std::pair<mcId
     throw INTERP_KERNEL::Exception(msg);
 }
 
+static void convertPyToVectorVectorPairInt(PyObject *pyLi, std::vector< std::vector< std::pair<mcIdType,mcIdType> > >& arr)
+{
+  const char msg[]="list must contain tuples of 2 integers only or tuple must contain tuples of 2 integers only !";
+  if(PyList_Check(pyLi))
+    {
+      std::size_t size=PyList_Size(pyLi);
+      arr.resize(size);
+      for(std::size_t i = 0 ; i < size ; ++i)
+        convertPyToVectorPairInt(PyList_GetItem(pyLi,i),arr[i]);
+    }
+  else if(PyTuple_Check(pyLi))
+    {
+      std::size_t size=PyTuple_Size(pyLi);
+      arr.resize(size);
+      for(std::size_t i = 0 ; i < size ; ++i)
+        convertPyToVectorPairInt(PyTuple_GetItem(pyLi,i),arr[i]);
+    }
+  else
+    throw INTERP_KERNEL::Exception(msg);
+}
+
 static void convertPyToVectorPairStringInt(PyObject *pyLi, std::vector< std::pair<std::string,int> >& arr)
 {
   const char msg[]="convertPyToVectorPairStringInt : list must contain tuples of 2 integers only or tuple must contain tuples of 1 string and 1 integer only !";
@@ -1389,6 +1410,17 @@ static void convertFromPyObjVectorOfObj(PyObject *pyLi, swig_type_info *ty, cons
     throw INTERP_KERNEL::Exception("convertFromPyObjVectorOfObj : not a list nor a tuple");
 }
 
+//convertFromVectorAutoObjToPyObj<MEDCoupling::MEDCouplingUMesh>(inpv,SWIGTYPE_p_MEDCoupling__MEDCouplingUMesh)
+template<class T>
+static PyObject *convertFromVectorAutoObjToPyObj(std::vector< MCAuto<T> >& inpVector, swig_type_info *ty)
+{
+  std::size_t sz(inpVector.size());
+  PyObject *ret = PyList_New(sz);
+  for(std::size_t i=0;i<sz;++i)
+    PyList_SetItem(ret,i,SWIG_NewPointerObj(SWIG_as_voidptr(inpVector[i].retn()),ty, SWIG_POINTER_OWN | 0 ));
+  return ret;
+}
+
 /*!
  * if python int -> cpp int sw=1
  * if python list[int] -> cpp vector<int> sw=2
@@ -2033,7 +2065,7 @@ static void convertObjToPossibleCpp6(PyObject *value, mcIdType& sw, char& cTyp,
             {
               vsType[i]=convertPyObjectToStr(o);
             }
-          catch(INTERP_KERNEL::Exception& e)
+          catch(INTERP_KERNEL::Exception& )
             {
               std::ostringstream oss; oss << "Tuple as been detected but element #" << i << " is not a string ! only tuples of strings accepted !";
               throw INTERP_KERNEL::Exception(oss.str().c_str());
@@ -2053,7 +2085,7 @@ static void convertObjToPossibleCpp6(PyObject *value, mcIdType& sw, char& cTyp,
             {
               vsType[i]=convertPyObjectToStr(o);
             }
-          catch(INTERP_KERNEL::Exception& e)
+          catch(INTERP_KERNEL::Exception& )
             {
               std::ostringstream oss; oss << "List as been detected but element #" << i << " is not a string ! only tuples of strings accepted !";
               throw INTERP_KERNEL::Exception(oss.str().c_str());
@@ -3115,8 +3147,11 @@ bool isCSRMatrix(PyObject *m)
   PyObject* pdict(PyDict_New());
   PyDict_SetItemString(pdict, "__builtins__", PyEval_GetBuiltins());
   PyObject *tmp(PyRun_String("from scipy.sparse import csr_matrix", Py_single_input, pdict, pdict));
-  if(!tmp)
-    throw INTERP_KERNEL::Exception("Problem during loading csr_matrix in scipy.sparse ! Is Scipy module available in present ?");
+  if (!tmp)
+  {
+    PyErr_Clear(); // Otherwise exception propagation will fail.
+    throw INTERP_KERNEL::Exception("Problem during loading csr_matrix in scipy.sparse! Is Scipy module available and present?");
+  }
   PyObject *csrMatrixCls=PyDict_GetItemString(pdict,"csr_matrix");
   if(!csrMatrixCls)
     throw INTERP_KERNEL::Exception("csr_matrix not found in scipy.sparse ! Is Scipy module available in present ?");