Skip to content

Commit

Permalink
Path.Area: added python abort() to abort lengthy operation
Browse files Browse the repository at this point in the history
  • Loading branch information
realthunder committed Jan 31, 2017
1 parent 6f862fe commit e66f4c5
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 5 deletions.
2 changes: 2 additions & 0 deletions src/Mod/Path/App/Area.cpp
Expand Up @@ -108,6 +108,8 @@ CAreaConfig::~CAreaConfig() {

TYPESYSTEM_SOURCE(Path::Area, Base::BaseClass);

bool Area::s_aborting;

Area::Area(const AreaParams *params)
:myHaveFace(false)
,myHaveSolid(false)
Expand Down
13 changes: 13 additions & 0 deletions src/Mod/Path/App/Area.h
Expand Up @@ -44,6 +44,10 @@
str << "Path.Area: " << _msg;\
Base::Console()._l("%s\n",str.str().c_str());\
qApp->sendPostedEvents();\
if(Area::aborted()) {\
Area::abort(false);\
throw Base::AbortException("operation aborted");\
}\
}while(0)

#define AREA_LOG(_msg) _AREA_LOG(Log,_msg)
Expand Down Expand Up @@ -195,6 +199,7 @@ class PathExport Area: public Base::BaseClass {
bool myHaveSolid;
bool myShapeDone;
int mySkippedShapes;
static bool s_aborting;

/** Called internally to combine children shapes for further processing */
void build();
Expand Down Expand Up @@ -432,6 +437,14 @@ class PathExport Area: public Base::BaseClass {
const AreaParams *params=NULL, const gp_Pnt *pstart=NULL, gp_Pnt *pend=NULL,
PARAM_ARGS_DEF(PARAM_FARG,AREA_PARAMS_PATH));

static void abort(bool aborting) {
s_aborting = aborting;
}

static bool aborted() {
return s_aborting;
}

PARAM_ENUM_DECLARE(AREA_PARAMS_PATH)
};

Expand Down
7 changes: 7 additions & 0 deletions src/Mod/Path/App/AreaPy.xml
Expand Up @@ -77,6 +77,13 @@ same algorithm</UserDocu>
<UserDocu>Get current algorithm parameters as a dictionary.</UserDocu>
</Documentation>
</Methode>
<Methode Name="abort" Keyword="true">
<Documentation>
<UserDocu>abort(aborting=True): Static method to abort any ongoing operation\n
To ensure no stray abortion is left in the previous operaion, it is advised to manually
clear the aborting flag by calling abort(False) before starting a new operation. </UserDocu>
</Documentation>
</Methode>
<Attribute Name="Sections" ReadOnly="true">
<Documentation>
<UserDocu>List of sections in this area.</UserDocu>
Expand Down
25 changes: 20 additions & 5 deletions src/Mod/Path/App/AreaPyImp.cpp
Expand Up @@ -100,10 +100,23 @@ static const AreaDoc myDocs[] = {
},
};

struct AreaPyDoc {
AreaPyDoc() {
static PyObject * abortArea(PyObject *, PyObject *args, PyObject *kwd) {
static char *kwlist[] = {"aborting", NULL};
PyObject *pObj = Py_True;
if (!PyArg_ParseTupleAndKeywords(args,kwd,"|O",kwlist,&pObj))
return 0;
Area::abort(PyObject_IsTrue(pObj));
return Py_None;
}

struct AreaPyModifier {
AreaPyModifier() {
for(PyMethodDef &method : Path::AreaPy::Methods) {
if(!method.ml_name) continue;
if(std::strcmp(method.ml_name,"abort")==0) {
method.ml_meth = (PyCFunction)abortArea;
method.ml_flags |= METH_STATIC;
}
for(const AreaDoc &doc : myDocs) {
if(std::strcmp(method.ml_name,doc.name)==0) {
method.ml_doc = doc.doc;
Expand All @@ -114,7 +127,7 @@ struct AreaPyDoc {
}
};

static AreaPyDoc doc;
static AreaPyModifier mod;

namespace Part {
extern PartExport Py::Object shape2pyshape(const TopoDS_Shape &shape);
Expand Down Expand Up @@ -376,6 +389,10 @@ PyObject* AreaPy::getParams(PyObject *args)
return dict;
}

PyObject* AreaPy::abort(PyObject *, PyObject *) {
return 0;
}

PyObject* AreaPy::getParamsDesc(PyObject *args, PyObject *keywds)
{
PyObject *pcObj = Py_True;
Expand Down Expand Up @@ -424,5 +441,3 @@ int AreaPy::setCustomAttributes(const char* /*attr*/, PyObject* /*obj*/)
{
return 0;
}


0 comments on commit e66f4c5

Please sign in to comment.