Path.Area: various fixes for Path.Area python object

This commit is contained in:
Zheng, Lei 2017-01-21 18:21:46 +08:00
parent 797793b4ac
commit 8fdb235d8f
5 changed files with 23 additions and 12 deletions

View File

@ -121,7 +121,7 @@ void Area::setPlane(const TopoDS_Shape &shape) {
}
BRepLib_FindSurface planeFinder(shape,-1,Standard_True);
if (!planeFinder.Found())
throw Base::ValueError("shape is not coplanar");
throw Base::ValueError("shape is not planar");
myWorkPlane = shape;
myTrsf.SetTransformation(GeomAdaptor_Surface(
planeFinder.Surface()).Plane().Position());

View File

@ -141,10 +141,10 @@ protected:
*/
TopoDS_Shape makePocket();
public:
/** Declare all parameters defined in #AREA_PARAMS_ALL as member variable */
PARAM_ENUM_DECLARE(AREA_PARAMS_ALL)
public:
Area(const AreaParams *params = NULL);
virtual ~Area();

View File

@ -79,7 +79,7 @@
* These parameters cooresponds to CAreaPocketParams in libarea
* */
#define AREA_PARAMS_POCKET \
((enum,mode,PocketMode,1,"Selects the pocket toolpath pattern",(None)(ZigZag)(Offset)(Spiral)(ZigZagOffset)))\
((enum,mode,PocketMode,0,"Selects the pocket toolpath pattern",(None)(ZigZag)(Offset)(Spiral)(ZigZagOffset)))\
((double,tool_radius,ToolRadius,1.0,"Tool radius for pocketing"))\
((double,extra_offset,PocketExtraOffset,0.0,"Extra offset for pocketing"))\
((double,stepover,PocketStepover,0.0,"Cutter diameter to step over on each pass. If =0, use ToolRadius."))\

View File

@ -13,7 +13,10 @@
Delete="true">
<Documentation>
<Author Licence="LGPL" Name="Zheng, Lei" EMail="realthunder.dev@gmail.com" />
<UserDocu>FreeCAD python wrapper of libarea</UserDocu>
<UserDocu>FreeCAD python wrapper of libarea\n
Path.Area(key=value ...)\n
The constuctor accepts the same parameters as setParams(...) to configure the object
All arguments are optional.</UserDocu>
</Documentation>
<Methode Name="add" Keyword='true'>
<Documentation>

View File

@ -64,15 +64,15 @@ static const AreaDoc myDocs[] = {
{
"makeOffset",
"makeOffset(" PARAM_PY_ARGS_DOC(ARG,AREA_PARAMS_OFFSET) "):\n"
"\n* index (-1): the index of the section. -1 means all sections. No effect on planar shape.\n"
"makeOffset(index=-1, " PARAM_PY_ARGS_DOC(ARG,AREA_PARAMS_OFFSET) "):\n"
"Make an 2D offset of the shape.\n"
"\n* index (-1): the index of the section. -1 means all sections. No effect on planar shape.\n"
PARAM_PY_DOC(ARG,AREA_PARAMS_OFFSET),
},
{
"makePocket",
"makePocket(" PARAM_PY_ARGS_DOC(ARG,AREA_PARAMS_POCKET) "):\n"
"makePocket(index=-1, " PARAM_PY_ARGS_DOC(ARG,AREA_PARAMS_POCKET) "):\n"
"Generate pocket toolpath of the shape.\n"
"\n* index (-1): the index of the section. -1 means all sections. No effect on planar shape.\n"
PARAM_PY_DOC(ARG,AREA_PARAMS_POCKET),
@ -115,8 +115,9 @@ PyObject *AreaPy::PyMake(struct _typeobject *, PyObject *, PyObject *) // Pytho
}
// constructor method
int AreaPy::PyInit(PyObject* /*args*/, PyObject* /*kwd*/)
int AreaPy::PyInit(PyObject* args, PyObject* kwd)
{
setParams(args,kwd);
return 0;
}
@ -132,15 +133,15 @@ PyObject* AreaPy::setPlane(PyObject *args) {
PyObject* AreaPy::getShape(PyObject *args, PyObject *keywds)
{
PyObject *pcObj = Py_True;
PyObject *pcObj = Py_False;
short index=-1;
static char *kwlist[] = {"index","rebuild", NULL};
if (!PyArg_ParseTupleAndKeywords(args, keywds,"|hO",kwlist,&pcObj))
Py_Error(Base::BaseExceptionFreeCADError, "This method accepts no argument");
Py_Error(Base::BaseExceptionFreeCADError, "Wrong parameters");
try {
if(PyObject_IsTrue(pcObj))
getAreaPtr()->clean(true);
getAreaPtr()->clean();
return Py::new_reference_to(Part::shape2pyshape(getAreaPtr()->getShape(index)));
}
PY_CATCH_OCC;
@ -150,7 +151,12 @@ PyObject* AreaPy::add(PyObject *args, PyObject *keywds)
{
PARAM_PY_DECLARE_INIT(PARAM_FARG,AREA_PARAMS_OPCODE)
PyObject *pcObj;
static char *kwlist[] = {PARAM_FIELD_STRINGS(ARG,AREA_PARAMS_OPCODE), NULL};
//Strangely, PyArg_ParseTupleAndKeywords requires all arguments to be keyword based,
//even non-optional ones? That doesn't make sense in python. Seems only in python 3
//they added '$' to address that issue.
static char *kwlist[] = {"shape",PARAM_FIELD_STRINGS(ARG,AREA_PARAMS_OPCODE), NULL};
if (!PyArg_ParseTupleAndKeywords(args, keywds,
"O|" PARAM_PY_KWDS(AREA_PARAMS_OPCODE),
kwlist,&pcObj,PARAM_REF(PARAM_FARG,AREA_PARAMS_OPCODE)))
@ -207,6 +213,8 @@ PyObject* AreaPy::makePocket(PyObject *args, PyObject *keywds)
short index = -1;
PARAM_PY_DECLARE_INIT(PARAM_FARG,AREA_PARAMS_POCKET)
//Override pocket mode default
mode = Area::PocketModeZigZagOffset;
if (!PyArg_ParseTupleAndKeywords(args, keywds,
"|h" PARAM_PY_KWDS(AREA_PARAMS_POCKET), kwlist,