Add Python wrapper for pipeline object
This commit is contained in:
@@ -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
|
||||
)
|
||||
|
||||
@@ -35,6 +35,7 @@
|
||||
#include <App/Document.h>
|
||||
#include <SMESH_Mesh.hxx>
|
||||
#include <App/DocumentObjectPy.h>
|
||||
#include <Mod/Fem/App/FemPostPipelinePy.h>
|
||||
|
||||
#include <vtkDataSetReader.h>
|
||||
#include <vtkGeometryFilter.h>
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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";
|
||||
|
||||
37
src/Mod/Fem/App/FemPostPipelinePy.xml
Normal file
37
src/Mod/Fem/App/FemPostPipelinePy.xml
Normal file
@@ -0,0 +1,37 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<GenerateModel xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="generateMetaModel_Module.xsd">
|
||||
<PythonExport
|
||||
Father="GeoFeaturePy"
|
||||
Name="FemPostPipelinePy"
|
||||
Twin="FemPostPipeline"
|
||||
TwinPointer="FemPostPipeline"
|
||||
Include="Mod/Fem/App/FemPostPipeline.h"
|
||||
Namespace="Fem"
|
||||
FatherInclude="App/GeoFeaturePy.h"
|
||||
FatherNamespace="App">
|
||||
<Documentation>
|
||||
<Author Licence="LGPL" Name="Werner Mayer" EMail="wmayer@users.sourceforge.net" />
|
||||
<UserDocu>The FemPostPipeline class.</UserDocu>
|
||||
</Documentation>
|
||||
<Methode Name="read">
|
||||
<Documentation>
|
||||
<UserDocu>Read in vtk file</UserDocu>
|
||||
</Documentation>
|
||||
</Methode>
|
||||
<Methode Name="load">
|
||||
<Documentation>
|
||||
<UserDocu>Load a result object</UserDocu>
|
||||
</Documentation>
|
||||
</Methode>
|
||||
<Methode Name="getLastPostObject">
|
||||
<Documentation>
|
||||
<UserDocu>Get the last post-processing object</UserDocu>
|
||||
</Documentation>
|
||||
</Methode>
|
||||
<Methode Name="holdsPostObject">
|
||||
<Documentation>
|
||||
<UserDocu>Check if this pipeline holds a given post-processing object</UserDocu>
|
||||
</Documentation>
|
||||
</Methode>
|
||||
</PythonExport>
|
||||
</GenerateModel>
|
||||
102
src/Mod/Fem/App/FemPostPipelinePyImp.cpp
Normal file
102
src/Mod/Fem/App/FemPostPipelinePyImp.cpp
Normal file
@@ -0,0 +1,102 @@
|
||||
/***************************************************************************
|
||||
* 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 "FemPostPipeline.h"
|
||||
#include <Base/FileInfo.h>
|
||||
|
||||
#include <Mod/Fem/App/FemPostPipelinePy.h>
|
||||
#include <Mod/Fem/App/FemPostPipelinePy.cpp>
|
||||
|
||||
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("<FemPostPipeline object>");
|
||||
}
|
||||
|
||||
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<App::DocumentObjectPy*>(py)->getDocumentObjectPtr();
|
||||
if (!obj->getTypeId().isDerivedFrom(FemResultObject::getClassTypeId())) {
|
||||
PyErr_SetString(PyExc_TypeError, "object is not a result object");
|
||||
return 0;
|
||||
}
|
||||
|
||||
getFemPostPipelinePtr()->load(static_cast<FemResultObject*>(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<App::DocumentObjectPy*>(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<FemPostObject*>(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;
|
||||
}
|
||||
Reference in New Issue
Block a user