## FEM中从c++函数到python函数

Chinese forum
johnwang
Posts: 578
Joined: Sun Jan 27, 2019 12:41 am

### FEM中从c++函数到python函数

src/Mod/Fem目录下App和Gui子目录是c++函数，其他的子目录为python函数。如果用python编程，如何调用c++函数呢？

Code: Select all

``````void ViewProviderFemMesh::applyDisplacementToNodes(double factor)
{
if(DisplacementVector.size() == 0)
return;

float x,y,z;
// set the point coordinates
long sz = pcCoords->point.getNum();
SbVec3f* verts = pcCoords->point.startEditing();
for (long i=0;i < sz ;i++) {
verts[i].getValue(x,y,z);
// undo old factor#
Base::Vector3d oldDisp = DisplacementVector[i] * DisplacementFactor;
x -= oldDisp.x;
y -= oldDisp.y;
z -= oldDisp.z;
// apply new factor
Base::Vector3d newDisp = DisplacementVector[i] * factor;
x += newDisp.x;
y += newDisp.y;
z += newDisp.z;
// set the new value
verts[i].setValue(x,y,z);
}Gui/
pcCoords->point.finishEditing();

DisplacementFactor = factor;
}``````

Code: Select all

``````PyObject* ViewProviderFemMeshPy::applyDisplacement(PyObject * args)
{
double factor;
if (!PyArg_ParseTuple(args, "d", &factor))
return 0;

this->getViewProviderFemMeshPtr()->applyDisplacementToNodes(factor);

Py_Return;
}``````

python中对这个函数的调用可以看femguiobjects\_ViewProviderFemResultMechanical.py:

Code: Select all

``````    def update_displacement(self, factor=None):
if factor is None: