From 6c8c3dc71e7b48d2324787c0e9aa8338f48987d4 Mon Sep 17 00:00:00 2001 From: looooo Date: Thu, 23 Feb 2017 16:39:27 +0100 Subject: [PATCH] py3: gathering diff from Mod/Mesh 98a8275938388992ef1b7bb76dcd43438f61bf7e py3: make most of the unit test to succeed --- src/Mod/Mesh/App/MeshPyImp.cpp | 25 +++++++++++-------------- src/Mod/Mesh/App/MeshTestsApp.py | 7 ++++++- 2 files changed, 17 insertions(+), 15 deletions(-) diff --git a/src/Mod/Mesh/App/MeshPyImp.cpp b/src/Mod/Mesh/App/MeshPyImp.cpp index 4172e471c..a2dde83b3 100644 --- a/src/Mod/Mesh/App/MeshPyImp.cpp +++ b/src/Mod/Mesh/App/MeshPyImp.cpp @@ -1473,28 +1473,25 @@ PyObject* MeshPy::collapseFacets(PyObject *args) return 0; // NULL triggers exception // if no mesh is given - if (PyList_Check(pcObj)) { + try { + Py::Sequence list(pcObj); std::vector facets; - for (int i = 0; i < PyList_Size(pcObj); i++) { - PyObject *idx = PyList_GetItem(pcObj, i); + for (Py::Sequence::iterator it = list.begin(); it != list.end(); ++it) { #if PY_MAJOR_VERSION >= 3 - if (PyLong_Check(idx)){ - unsigned long iIdx = PyLong_AsLong(idx); + Py::Long idx(*it); + unsigned long iIdx = static_cast(idx); + facets.push_back(iIdx); #else - if (PyInt_Check(idx)){ - unsigned long iIdx = PyInt_AsLong(idx); + Py::Int idx(*it); + unsigned long iIdx = static_cast(idx); + facets.push_back(iIdx); #endif - facets.push_back(iIdx); - } - else { - Py_Error(Base::BaseExceptionFreeCADError, "list of integers needed"); - } } getMeshObjectPtr()->collapseFacets(facets); } - else { - Py_Error(Base::BaseExceptionFreeCADError, "List of Integers needed"); + catch (const Py::Exception&) { + return 0; } Py_Return; diff --git a/src/Mod/Mesh/App/MeshTestsApp.py b/src/Mod/Mesh/App/MeshTestsApp.py index d4834d27f..ee9a845fd 100644 --- a/src/Mod/Mesh/App/MeshTestsApp.py +++ b/src/Mod/Mesh/App/MeshTestsApp.py @@ -1,7 +1,12 @@ # (c) Juergen Riegel (juergen.riegel@web.de) 2007 LGPL import FreeCAD, os, sys, unittest, Mesh -import thread, time, tempfile, math +import time, tempfile, math +# http://python-kurs.eu/threads.php +try: + import _thread as thread +except: + import thread #---------------------------------------------------------------------------