From 8fdb235d8fe6fad43a0247d39ff1992455d4fee6 Mon Sep 17 00:00:00 2001 From: "Zheng, Lei" Date: Sat, 21 Jan 2017 18:21:46 +0800 Subject: [PATCH] Path.Area: various fixes for Path.Area python object --- src/Mod/Path/App/Area.cpp | 2 +- src/Mod/Path/App/Area.h | 2 +- src/Mod/Path/App/AreaParams.h | 2 +- src/Mod/Path/App/AreaPy.xml | 5 ++++- src/Mod/Path/App/AreaPyImp.cpp | 24 ++++++++++++++++-------- 5 files changed, 23 insertions(+), 12 deletions(-) diff --git a/src/Mod/Path/App/Area.cpp b/src/Mod/Path/App/Area.cpp index 01cd1e7e964f..e90c5620da1d 100644 --- a/src/Mod/Path/App/Area.cpp +++ b/src/Mod/Path/App/Area.cpp @@ -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()); diff --git a/src/Mod/Path/App/Area.h b/src/Mod/Path/App/Area.h index 02b4664bd153..94470a1e2bb4 100644 --- a/src/Mod/Path/App/Area.h +++ b/src/Mod/Path/App/Area.h @@ -141,10 +141,10 @@ class PathExport Area: public Base::BaseClass { */ 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(); diff --git a/src/Mod/Path/App/AreaParams.h b/src/Mod/Path/App/AreaParams.h index c3493fa9a4dc..0da87d16e55b 100644 --- a/src/Mod/Path/App/AreaParams.h +++ b/src/Mod/Path/App/AreaParams.h @@ -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."))\ diff --git a/src/Mod/Path/App/AreaPy.xml b/src/Mod/Path/App/AreaPy.xml index 6bc8cd2ecc72..b4121fdb9d57 100644 --- a/src/Mod/Path/App/AreaPy.xml +++ b/src/Mod/Path/App/AreaPy.xml @@ -13,7 +13,10 @@ Delete="true"> - FreeCAD python wrapper of libarea + 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. diff --git a/src/Mod/Path/App/AreaPyImp.cpp b/src/Mod/Path/App/AreaPyImp.cpp index 7c8b058513e6..db4f0f397791 100644 --- a/src/Mod/Path/App/AreaPyImp.cpp +++ b/src/Mod/Path/App/AreaPyImp.cpp @@ -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,