diff --git a/src/Mod/Path/App/Area.cpp b/src/Mod/Path/App/Area.cpp index 1797f8473..794f51059 100644 --- a/src/Mod/Path/App/Area.cpp +++ b/src/Mod/Path/App/Area.cpp @@ -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) diff --git a/src/Mod/Path/App/Area.h b/src/Mod/Path/App/Area.h index 2955d7cb2..06a71a972 100644 --- a/src/Mod/Path/App/Area.h +++ b/src/Mod/Path/App/Area.h @@ -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) @@ -195,6 +199,7 @@ protected: bool myHaveSolid; bool myShapeDone; int mySkippedShapes; + static bool s_aborting; /** Called internally to combine children shapes for further processing */ void build(); @@ -432,6 +437,14 @@ public: 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) }; diff --git a/src/Mod/Path/App/AreaPy.xml b/src/Mod/Path/App/AreaPy.xml index 170288ed3..622dbb04a 100644 --- a/src/Mod/Path/App/AreaPy.xml +++ b/src/Mod/Path/App/AreaPy.xml @@ -77,6 +77,13 @@ same algorithm Get current algorithm parameters as a dictionary. + + + 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. + + List of sections in this area. diff --git a/src/Mod/Path/App/AreaPyImp.cpp b/src/Mod/Path/App/AreaPyImp.cpp index bec2817f0..29db5f485 100644 --- a/src/Mod/Path/App/AreaPyImp.cpp +++ b/src/Mod/Path/App/AreaPyImp.cpp @@ -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; @@ -114,7 +127,7 @@ struct AreaPyDoc { } }; -static AreaPyDoc doc; +static AreaPyModifier mod; namespace Part { extern PartExport Py::Object shape2pyshape(const TopoDS_Shape &shape); @@ -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; @@ -424,5 +441,3 @@ int AreaPy::setCustomAttributes(const char* /*attr*/, PyObject* /*obj*/) { return 0; } - -