Path.Area: added python abort() to abort lengthy operation

This commit is contained in:
Zheng, Lei 2017-02-01 02:45:13 +08:00
parent 6f862fe4a1
commit e66f4c5d6f
4 changed files with 42 additions and 5 deletions

View File

@ -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)

View File

@ -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)
};

View File

@ -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>

View File

@ -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;
}