From a07b9cd0d447fe28610330622c9b5a2557538325 Mon Sep 17 00:00:00 2001 From: wmayer Date: Wed, 20 Jan 2016 22:48:26 +0100 Subject: [PATCH] + simplify porting of Inspection module to Python3 --- src/Mod/Inspection/App/AppInspection.cpp | 35 ++++++++++++----- src/Mod/Inspection/App/AppInspectionPy.cpp | 38 ------------------- src/Mod/Inspection/App/CMakeLists.txt | 1 - src/Mod/Inspection/Gui/AppInspectionGui.cpp | 35 ++++++++++++----- src/Mod/Inspection/Gui/AppInspectionGuiPy.cpp | 35 ----------------- src/Mod/Inspection/Gui/CMakeLists.txt | 1 - 6 files changed, 50 insertions(+), 95 deletions(-) delete mode 100644 src/Mod/Inspection/App/AppInspectionPy.cpp delete mode 100644 src/Mod/Inspection/Gui/AppInspectionGuiPy.cpp diff --git a/src/Mod/Inspection/App/AppInspection.cpp b/src/Mod/Inspection/App/AppInspection.cpp index b8d5819cd6ea..4bb9112ca1ea 100644 --- a/src/Mod/Inspection/App/AppInspection.cpp +++ b/src/Mod/Inspection/App/AppInspection.cpp @@ -1,5 +1,5 @@ /*************************************************************************** - * Copyright (c) YEAR YOUR NAME * + * Copyright (c) 2004 Werner Mayer * * * * This file is part of the FreeCAD CAx development system. * * * @@ -26,30 +26,45 @@ # include #endif +#include +#include + #include #include "InspectionFeature.h" -/* registration table */ -extern struct PyMethodDef Inspection_methods[]; +namespace Inspection { +class Module : public Py::ExtensionModule +{ +public: + Module() : Py::ExtensionModule("Inspection") + { + initialize("This module is the Inspection module."); // register with Python + } + + virtual ~Module() {} + +private: +}; -PyDoc_STRVAR(module_Inspection_doc, -"This module is the Inspection module."); +PyObject* initModule() +{ + return (new Module)->module().ptr(); +} + +} // namespace Inspection /* Python entry */ -extern "C" { -void InspectionExport initInspection() { +PyMODINIT_FUNC initInspection() { // ADD YOUR CODE HERE // // - (void) Py_InitModule3("Inspection", Inspection_methods, module_Inspection_doc); /* mod name, table ptr */ + (void)Inspection::initModule(); Base::Console().Log("Loading Inspection module... done\n"); Inspection::PropertyDistanceList ::init(); Inspection::Feature ::init(); Inspection::Group ::init(); } - -} // extern "C" diff --git a/src/Mod/Inspection/App/AppInspectionPy.cpp b/src/Mod/Inspection/App/AppInspectionPy.cpp deleted file mode 100644 index 88f94e67d02f..000000000000 --- a/src/Mod/Inspection/App/AppInspectionPy.cpp +++ /dev/null @@ -1,38 +0,0 @@ -/*************************************************************************** - * Copyright (c) YEAR YOUR NAME * - * * - * This file is part of the FreeCAD CAx development system. * - * * - * This library is free software; you can redistribute it and/or * - * modify it under the terms of the GNU Library General Public * - * License as published by the Free Software Foundation; either * - * version 2 of the License, or (at your option) any later version. * - * * - * This library is distributed in the hope that it will be useful, * - * but WITHOUT ANY WARRANTY; without even the implied warranty of * - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * - * GNU Library General Public License for more details. * - * * - * You should have received a copy of the GNU Library General Public * - * License along with this library; see the file COPYING.LIB. If not, * - * write to the Free Software Foundation, Inc., 59 Temple Place, * - * Suite 330, Boston, MA 02111-1307, USA * - * * - ***************************************************************************/ - - -#include "PreCompiled.h" -#ifndef _PreComp_ -#endif - -#include - -#include -#include -#include - - -/* registration table */ -struct PyMethodDef Inspection_methods[] = { - {NULL, NULL} /* end of table marker */ -}; diff --git a/src/Mod/Inspection/App/CMakeLists.txt b/src/Mod/Inspection/App/CMakeLists.txt index f0e7477700d6..7437050998fd 100644 --- a/src/Mod/Inspection/App/CMakeLists.txt +++ b/src/Mod/Inspection/App/CMakeLists.txt @@ -27,7 +27,6 @@ set(Inspection_LIBS SET(Inspection_SRCS AppInspection.cpp - AppInspectionPy.cpp InspectionFeature.cpp InspectionFeature.h PreCompiled.cpp diff --git a/src/Mod/Inspection/Gui/AppInspectionGui.cpp b/src/Mod/Inspection/Gui/AppInspectionGui.cpp index a47e74cbbb2d..e403b7c96963 100644 --- a/src/Mod/Inspection/Gui/AppInspectionGui.cpp +++ b/src/Mod/Inspection/Gui/AppInspectionGui.cpp @@ -1,5 +1,5 @@ /*************************************************************************** - * Copyright (c) YEAR YOUR NAME * + * Copyright (c) 2004 Werner Mayer * * * * This file is part of the FreeCAD CAx development system. * * * @@ -26,6 +26,9 @@ # include #endif +#include +#include + #include #include @@ -36,16 +39,30 @@ void CreateInspectionCommands(void); -/* registration table */ -extern struct PyMethodDef InspectionGui_methods[]; +namespace InspectionGui { +class Module : public Py::ExtensionModule +{ +public: + Module() : Py::ExtensionModule("InspectionGui") + { + initialize("This module is the InspectionGui module."); // register with Python + } -PyDoc_STRVAR(module_InspectionGui_doc, -"This module is the InspectionGui module."); + virtual ~Module() {} + +private: +}; + +PyObject* initModule() +{ + return (new Module)->module().ptr(); +} + +} // namespace InspectionGui /* Python entry */ -extern "C" { -void InspectionGuiExport initInspectionGui() +PyMODINIT_FUNC initInspectionGui() { if (!Gui::Application::Instance) { PyErr_SetString(PyExc_ImportError, "Cannot load Gui module in console application."); @@ -62,8 +79,6 @@ void InspectionGuiExport initInspectionGui() // // - (void) Py_InitModule3("InspectionGui", InspectionGui_methods, module_InspectionGui_doc); /* mod name, table ptr */ + (void)InspectionGui::initModule(); Base::Console().Log("Loading GUI of Inspection module... done\n"); } - -} // extern "C" diff --git a/src/Mod/Inspection/Gui/AppInspectionGuiPy.cpp b/src/Mod/Inspection/Gui/AppInspectionGuiPy.cpp deleted file mode 100644 index b7913e9c4742..000000000000 --- a/src/Mod/Inspection/Gui/AppInspectionGuiPy.cpp +++ /dev/null @@ -1,35 +0,0 @@ -/*************************************************************************** - * Copyright (c) YEAR YOUR NAME * - * * - * This file is part of the FreeCAD CAx development system. * - * * - * This library is free software; you can redistribute it and/or * - * modify it under the terms of the GNU Library General Public * - * License as published by the Free Software Foundation; either * - * version 2 of the License, or (at your option) any later version. * - * * - * This library is distributed in the hope that it will be useful, * - * but WITHOUT ANY WARRANTY; without even the implied warranty of * - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * - * GNU Library General Public License for more details. * - * * - * You should have received a copy of the GNU Library General Public * - * License along with this library; see the file COPYING.LIB. If not, * - * write to the Free Software Foundation, Inc., 59 Temple Place, * - * Suite 330, Boston, MA 02111-1307, USA * - * * - ***************************************************************************/ - - -#include "PreCompiled.h" -#ifndef _PreComp_ -#endif - - -#include -#include - -/* registration table */ -struct PyMethodDef InspectionGui_methods[] = { - {NULL, NULL} /* end of table marker */ -}; diff --git a/src/Mod/Inspection/Gui/CMakeLists.txt b/src/Mod/Inspection/Gui/CMakeLists.txt index 86df33cbfb7c..d2b41a1069f6 100644 --- a/src/Mod/Inspection/Gui/CMakeLists.txt +++ b/src/Mod/Inspection/Gui/CMakeLists.txt @@ -39,7 +39,6 @@ SET(InspectionGui_SRCS ${Inspection_QRC_SRCS} ${Dialogs_SRCS} AppInspectionGui.cpp - AppInspectionGuiPy.cpp Command.cpp PreCompiled.cpp PreCompiled.h