diff --git a/src/Mod/Fem/App/CMakeLists.txt b/src/Mod/Fem/App/CMakeLists.txt index ebf5f9e8c9..abf59e7ebf 100644 --- a/src/Mod/Fem/App/CMakeLists.txt +++ b/src/Mod/Fem/App/CMakeLists.txt @@ -41,10 +41,13 @@ if(BUILD_FEM_NETGEN) endif(BUILD_FEM_NETGEN) generate_from_xml(FemMeshPy) +generate_from_xml(FemPostPipelinePy) SET(Python_SRCS FemMeshPy.xml FemMeshPyImp.cpp + FemPostPipelinePy.xml + FemPostPipelinePyImp.cpp HypothesisPy.cpp HypothesisPy.h ) diff --git a/src/Mod/Fem/App/FemPostPipeline.cpp b/src/Mod/Fem/App/FemPostPipeline.cpp index 94cf5433c6..7544efd83c 100644 --- a/src/Mod/Fem/App/FemPostPipeline.cpp +++ b/src/Mod/Fem/App/FemPostPipeline.cpp @@ -35,6 +35,7 @@ #include #include #include +#include #include #include @@ -267,3 +268,12 @@ void FemPostPipeline::load(FemResultObject* res) { Data.setValue(grid); } + +PyObject* FemPostPipeline::getPyObject(void) +{ + if (PythonObject.is(Py::_None())) { + // ref counter is set to 1 + PythonObject = Py::Object(new FemPostPipelinePy(this),true); + } + return Py::new_reference_to(PythonObject); +} diff --git a/src/Mod/Fem/App/FemPostPipeline.h b/src/Mod/Fem/App/FemPostPipeline.h index 3d7a8106f3..1e77771781 100644 --- a/src/Mod/Fem/App/FemPostPipeline.h +++ b/src/Mod/Fem/App/FemPostPipeline.h @@ -50,7 +50,7 @@ public: short mustExecute(void) const; virtual App::DocumentObjectExecReturn* execute(void); - //PyObject* getPyObject(); + PyObject* getPyObject(); virtual const char* getViewProviderName(void) const { return "FemGui::ViewProviderFemPostPipeline"; diff --git a/src/Mod/Fem/App/FemPostPipelinePy.xml b/src/Mod/Fem/App/FemPostPipelinePy.xml new file mode 100644 index 0000000000..6bd3711093 --- /dev/null +++ b/src/Mod/Fem/App/FemPostPipelinePy.xml @@ -0,0 +1,37 @@ + + + + + + The FemPostPipeline class. + + + + Read in vtk file + + + + + Load a result object + + + + + Get the last post-processing object + + + + + Check if this pipeline holds a given post-processing object + + + + diff --git a/src/Mod/Fem/App/FemPostPipelinePyImp.cpp b/src/Mod/Fem/App/FemPostPipelinePyImp.cpp new file mode 100644 index 0000000000..f3196d62f7 --- /dev/null +++ b/src/Mod/Fem/App/FemPostPipelinePyImp.cpp @@ -0,0 +1,102 @@ +/*************************************************************************** + * 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 "FemPostPipeline.h" +#include + +#include +#include + +using namespace Fem; + +// returns a string which represents the object e.g. when printed in python +std::string FemPostPipelinePy::representation(void) const +{ + return std::string(""); +} + +PyObject* FemPostPipelinePy::read(PyObject *args) +{ + char* Name; + if (PyArg_ParseTuple(args, "et", "utf-8", &Name)) { + getFemPostPipelinePtr()->read(Base::FileInfo(Name)); + PyMem_Free(Name); + Py_Return; + } + return 0; +} + +PyObject* FemPostPipelinePy::load(PyObject *args) +{ + PyObject* py; + if (!PyArg_ParseTuple(args, "O!", &(App::DocumentObjectPy::Type), &py)) + return 0; + + App::DocumentObject* obj = static_cast(py)->getDocumentObjectPtr(); + if (!obj->getTypeId().isDerivedFrom(FemResultObject::getClassTypeId())) { + PyErr_SetString(PyExc_TypeError, "object is not a result object"); + return 0; + } + + getFemPostPipelinePtr()->load(static_cast(obj)); + Py_Return; +} + +PyObject* FemPostPipelinePy::getLastPostObject(PyObject *args) +{ + if (!PyArg_ParseTuple(args, "")) + return 0; + + App::DocumentObject* obj = getFemPostPipelinePtr()->getLastPostObject(); + if (obj) + return obj->getPyObject(); + Py_Return; +} + +PyObject* FemPostPipelinePy::holdsPostObject(PyObject *args) +{ + PyObject* py; + if (!PyArg_ParseTuple(args, "O!", &(App::DocumentObjectPy::Type), &py)) + return 0; + + App::DocumentObject* obj = static_cast(py)->getDocumentObjectPtr(); + if (!obj->getTypeId().isDerivedFrom(FemPostObject::getClassTypeId())) { + PyErr_SetString(PyExc_TypeError, "object is not a post-processing object"); + return 0; + } + + bool ok = getFemPostPipelinePtr()->holdsPostObject(static_cast(obj)); + return Py_BuildValue("O", (ok ? Py_True : Py_False)); +} + +PyObject *FemPostPipelinePy::getCustomAttributes(const char* /*attr*/) const +{ + return 0; +} + +int FemPostPipelinePy::setCustomAttributes(const char* /*attr*/, PyObject* /*obj*/) +{ + return 0; +}