Skip to content

Commit

Permalink
rename python classes for shapes and
Browse files Browse the repository at this point in the history
implememnt __getstate__ and __setstate__ to enable pickling
issue #1948
  • Loading branch information
5263 committed Feb 4, 2015
1 parent 79173e3 commit 8ec87db
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/Mod/Part/App/AppPart.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,16 @@ void PartExport initPart()
PyModule_AddObject(partModule, "OCCDimensionError",
PartExceptionOCCDimensionError);

//rename the types properly to pickle and unpickle them
Part::TopoShapePy ::Type.tp_name = "Part.Shape";
Part::TopoShapeVertexPy ::Type.tp_name = "Part.Vertex";
Part::TopoShapeWirePy ::Type.tp_name = "Part.Wire";
Part::TopoShapeEdgePy ::Type.tp_name = "Part.Edge";
Part::TopoShapeSolidPy ::Type.tp_name = "Part.Solid";
Part::TopoShapeFacePy ::Type.tp_name = "Part.Face";
Part::TopoShapeCompoundPy ::Type.tp_name = "Part.Compound";
Part::TopoShapeCompSolidPy::Type.tp_name = "Part.CompSolid";
Part::TopoShapeShellPy ::Type.tp_name = "Part.Shell";
// Add Types to module
Base::Interpreter().addType(&Part::TopoShapePy ::Type,partModule,"Shape");
Base::Interpreter().addType(&Part::TopoShapeVertexPy ::Type,partModule,"Vertex");
Expand Down
10 changes: 10 additions & 0 deletions src/Mod/Part/App/TopoShapePy.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,16 @@ Sub-elements such as vertices, edges or faces are accessible as:
* Edge#, where # is in range(1, number of edges)
* Face#, where # is in range(1, number of faces)</UserDocu>
</Documentation>
<Methode Name="__getstate__" Const="true">
<Documentation>
<UserDocu>Serialize the content of this shape to a string in BREP format.</UserDocu>
</Documentation>
</Methode>
<Methode Name="__setstate__">
<Documentation>
<UserDocu>Deserialize the content of this shape from a string in BREP format.</UserDocu>
</Documentation>
</Methode>
<Methode Name="read">
<Documentation>
<UserDocu>Read in an IGES, STEP or BREP file.</UserDocu>
Expand Down
15 changes: 15 additions & 0 deletions src/Mod/Part/App/TopoShapePyImp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -455,6 +455,21 @@ PyObject* TopoShapePy::importBrepFromString(PyObject *args)
Py_Return;
}

PyObject* TopoShapePy::__getstate__(PyObject *args) {
return exportBrepToString(args);
}


PyObject* TopoShapePy::__setstate__(PyObject *args) {
if (! getTopoShapePtr()) {
PyErr_SetString(Base::BaseExceptionFreeCADError,"no c++ object");
return 0;
}
else {
return importBrepFromString(args);
}
}

PyObject* TopoShapePy::exportStl(PyObject *args)
{
double deflection = 0;
Expand Down

0 comments on commit 8ec87db

Please sign in to comment.