add typedef Py::TopoShape for convenience, move shape2pyshape to own file

This commit is contained in:
wmayer
2017-09-28 12:54:28 +02:00
parent 111dd2127c
commit 3c91e14fcd
4 changed files with 125 additions and 57 deletions

View File

@@ -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})

View File

@@ -0,0 +1,82 @@
/***************************************************************************
* Copyright (c) 2017 Werner Mayer <wmayer[at]users.sourceforge.net> *
* *
* 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 <CXX/Objects.hxx>
#include <Mod/Part/App/TopoShapeFacePy.h>
#include <Mod/Part/App/TopoShapeEdgePy.h>
#include <Mod/Part/App/TopoShapeWirePy.h>
#include <Mod/Part/App/TopoShapeVertexPy.h>
#include <Mod/Part/App/TopoShapeSolidPy.h>
#include <Mod/Part/App/TopoShapeShellPy.h>
#include <Mod/Part/App/TopoShapeCompSolidPy.h>
#include <Mod/Part/App/TopoShapeCompoundPy.h>
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

View File

@@ -0,0 +1,38 @@
/***************************************************************************
* Copyright (c) 2017 Werner Mayer <wmayer[at]users.sourceforge.net> *
* *
* 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 <CXX/Extensions.hxx>
#include <Mod/Part/App/TopoShapePy.h>
namespace Py {
typedef ExtensionObject<Part::TopoShapePy> TopoShape;
template<>
bool TopoShape::accepts (PyObject *pyob) const
{
return (pyob && PyObject_TypeCheck(pyob, &(Part::TopoShapePy::Type)));
}
}
#endif //PART_PYCXX_H

View File

@@ -72,6 +72,7 @@
#include <CXX/Extensions.hxx>
#include "TopoShape.h"
#include "PartPyCXX.h"
#include <Mod/Part/App/TopoShapePy.h>
#include <Mod/Part/App/TopoShapePy.cpp>
@@ -96,13 +97,8 @@ using namespace Part;
#define M_PI_2 1.57079632679489661923 /* pi/2 */
#endif
namespace Py {
typedef ExtensionObject<TopoShapePy> 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, ""))