diff --git a/src/Mod/Part/App/CMakeLists.txt b/src/Mod/Part/App/CMakeLists.txt index 8d45956f32..fc33a8f047 100644 --- a/src/Mod/Part/App/CMakeLists.txt +++ b/src/Mod/Part/App/CMakeLists.txt @@ -275,6 +275,8 @@ SET(Python_SRCS TopoShapeWirePyImp.cpp BRepOffsetAPI_MakePipeShellPy.xml BRepOffsetAPI_MakePipeShellPyImp.cpp + PartPyCXX.cpp + PartPyCXX.h ) SOURCE_GROUP("Python" FILES ${Python_SRCS}) diff --git a/src/Mod/Part/App/PartPyCXX.cpp b/src/Mod/Part/App/PartPyCXX.cpp new file mode 100644 index 0000000000..b9ffe79b30 --- /dev/null +++ b/src/Mod/Part/App/PartPyCXX.cpp @@ -0,0 +1,82 @@ +/*************************************************************************** + * Copyright (c) 2017 Werner Mayer * + * * + * 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" +#include "PartPyCXX.h" +#include +#include +#include +#include +#include +#include +#include +#include +#include + +namespace Part { +PartExport Py::Object shape2pyshape(const TopoDS_Shape &shape) +{ + PyObject* ret = 0; + if (!shape.IsNull()) { + TopAbs_ShapeEnum type = shape.ShapeType(); + switch (type) + { + case TopAbs_COMPOUND: + ret = new TopoShapeCompoundPy(new TopoShape(shape)); + break; + case TopAbs_COMPSOLID: + ret = new TopoShapeCompSolidPy(new TopoShape(shape)); + break; + case TopAbs_SOLID: + ret = new TopoShapeSolidPy(new TopoShape(shape)); + break; + case TopAbs_SHELL: + ret = new TopoShapeShellPy(new TopoShape(shape)); + break; + case TopAbs_FACE: + ret = new TopoShapeFacePy(new TopoShape(shape)); + break; + case TopAbs_WIRE: + ret = new TopoShapeWirePy(new TopoShape(shape)); + break; + case TopAbs_EDGE: + ret = new TopoShapeEdgePy(new TopoShape(shape)); + break; + case TopAbs_VERTEX: + ret = new TopoShapeVertexPy(new TopoShape(shape)); + break; + case TopAbs_SHAPE: + ret = new TopoShapePy(new TopoShape(shape)); + break; + default: + //shouldn't happen + ret = new TopoShapePy(new TopoShape(shape)); + break; + } + } else { + ret = new TopoShapePy(new TopoShape(shape)); + } + assert(ret); + + return Py::asObject(ret); +} +} //namespace Part diff --git a/src/Mod/Part/App/PartPyCXX.h b/src/Mod/Part/App/PartPyCXX.h new file mode 100644 index 0000000000..eaa4bff5bc --- /dev/null +++ b/src/Mod/Part/App/PartPyCXX.h @@ -0,0 +1,38 @@ +/*************************************************************************** + * Copyright (c) 2017 Werner Mayer * + * * + * 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 * + * * + ***************************************************************************/ + +#ifndef PART_PYCXX_H +#define PART_PYCXX_H + +#include +#include + +namespace Py { + typedef ExtensionObject TopoShape; + template<> + bool TopoShape::accepts (PyObject *pyob) const + { + return (pyob && PyObject_TypeCheck(pyob, &(Part::TopoShapePy::Type))); + } +} + +#endif //PART_PYCXX_H diff --git a/src/Mod/Part/App/TopoShapePyImp.cpp b/src/Mod/Part/App/TopoShapePyImp.cpp index 71816338d7..b040c1acaa 100644 --- a/src/Mod/Part/App/TopoShapePyImp.cpp +++ b/src/Mod/Part/App/TopoShapePyImp.cpp @@ -72,6 +72,7 @@ #include #include "TopoShape.h" +#include "PartPyCXX.h" #include #include @@ -96,13 +97,8 @@ using namespace Part; #define M_PI_2 1.57079632679489661923 /* pi/2 */ #endif -namespace Py { - typedef ExtensionObject TopoShape; - template<> - bool TopoShape::accepts (PyObject *pyob) const - { - return (pyob && PyObject_TypeCheck(pyob, &(Part::TopoShapePy::Type))); - } +namespace Part { +extern Py::Object shape2pyshape(const TopoDS_Shape &shape); } // returns a string which represents the object e.g. when printed in python @@ -157,56 +153,6 @@ int TopoShapePy::PyInit(PyObject* args, PyObject*) return 0; } -namespace Part { -//common code.. maybe put somewhere else? -PartExport Py::Object shape2pyshape(const TopoDS_Shape &shape) -{ - PyObject* ret = 0; - if (!shape.IsNull()) { - TopAbs_ShapeEnum type = shape.ShapeType(); - switch (type) - { - case TopAbs_COMPOUND: - ret = new TopoShapeCompoundPy(new TopoShape(shape)); - break; - case TopAbs_COMPSOLID: - ret = new TopoShapeCompSolidPy(new TopoShape(shape)); - break; - case TopAbs_SOLID: - ret = new TopoShapeSolidPy(new TopoShape(shape)); - break; - case TopAbs_SHELL: - ret = new TopoShapeShellPy(new TopoShape(shape)); - break; - case TopAbs_FACE: - ret = new TopoShapeFacePy(new TopoShape(shape)); - break; - case TopAbs_WIRE: - ret = new TopoShapeWirePy(new TopoShape(shape)); - break; - case TopAbs_EDGE: - ret = new TopoShapeEdgePy(new TopoShape(shape)); - break; - case TopAbs_VERTEX: - ret = new TopoShapeVertexPy(new TopoShape(shape)); - break; - case TopAbs_SHAPE: - ret = new TopoShapePy(new TopoShape(shape)); - break; - default: - //shouldn't happen - ret = new TopoShapePy(new TopoShape(shape)); - break; - } - } else { - ret = new TopoShapePy(new TopoShape(shape)); - } - assert(ret); - - return Py::asObject(ret); -} -} //namespace Part - PyObject* TopoShapePy::copy(PyObject *args) { if (!PyArg_ParseTuple(args, ""))