Skip to content

Commit

Permalink
Path.Area: various fixes for Path.Area python object
Browse files Browse the repository at this point in the history
  • Loading branch information
realthunder committed Jan 21, 2017
1 parent 797793b commit 8fdb235
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 12 deletions.
2 changes: 1 addition & 1 deletion src/Mod/Path/App/Area.cpp
Expand Up @@ -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());
Expand Down
2 changes: 1 addition & 1 deletion src/Mod/Path/App/Area.h
Expand Up @@ -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();

Expand Down
2 changes: 1 addition & 1 deletion src/Mod/Path/App/AreaParams.h
Expand Up @@ -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."))\
Expand Down
5 changes: 4 additions & 1 deletion src/Mod/Path/App/AreaPy.xml
Expand Up @@ -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>
Expand Down
24 changes: 16 additions & 8 deletions src/Mod/Path/App/AreaPyImp.cpp
Expand Up @@ -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),
Expand Down Expand Up @@ -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;
}

Expand All @@ -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;
Expand All @@ -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)))
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit 8fdb235

Please sign in to comment.