+ extend Python API of selection gate

This commit is contained in:
wmayer
2014-04-03 13:57:57 +02:00
parent 0efd2597c7
commit 0c5087c6ea
4 changed files with 148 additions and 47 deletions

View File

@@ -907,7 +907,6 @@ SelectionSingleton::~SelectionSingleton()
{
}
SelectionSingleton* SelectionSingleton::_pcSingleton = NULL;
SelectionSingleton& SelectionSingleton::instance(void)
@@ -923,21 +922,6 @@ void SelectionSingleton::destruct (void)
delete _pcSingleton;
_pcSingleton = 0;
}
/*
void SelectionSingleton::addObject(App::DocumentObject *f)
{
_ObjectSet.insert(f);
}
void SelectionSingleton::removeObject(App::DocumentObject *f)
{
_ObjectSet.erase(f);
}
*/
//**************************************************************************
// Python stuff
@@ -977,13 +961,25 @@ PyMethodDef SelectionSingleton::Methods[] = {
{"removeObserver", (PyCFunction) SelectionSingleton::sRemSelObserver, 1,
"removeObserver(Object) -- Uninstall an observer\n"},
{"addSelectionGate", (PyCFunction) SelectionSingleton::sAddSelectionGate, 1,
"addSelectionGate(String) -- activate the selection gate.\n"
"The selection gate will prohibit all selections which do not match\n"
"the given selection filter string. Examples strings are:\n"
"'SELECT Part::Feature SUBELEMENT Edge',\n"
"'SELECT Robot::RobotObject'\n"},
"addSelectionGate(String|Filter|Gate) -- activate the selection gate.\n"
"The selection gate will prohibit all selections which do not match\n"
"the given selection filter string.\n"
" Examples strings are:\n"
"'SELECT Part::Feature SUBELEMENT Edge',\n"
"'SELECT Robot::RobotObject'\n"
"\n"
"You can also set an instance of SelectionFilter:\n"
"filter = Gui.Selection.Filter('SELECT Part::Feature SUBELEMENT Edge')\n"
"Gui.Selection.addSelectionGate(filter)\n"
"\n"
"And the most flexible approach is to write your own selection gate class\n"
"that implements the method 'allow'\n"
"class Gate:\n"
" def allow(self,doc,obj,sub):\n"
" return (sub[0:4] == 'Face')\n"
"Gui.Selection.addSelectionGate(Gate())"},
{"removeSelectionGate", (PyCFunction) SelectionSingleton::sRemoveSelectionGate, 1,
"removeSelectionGate() -- remove the active slection gate\n"},
"removeSelectionGate() -- remove the active selection gate\n"},
{NULL, NULL, 0, NULL} /* Sentinel */
};
@@ -1167,14 +1163,33 @@ PyObject *SelectionSingleton::sRemSelObserver(PyObject * /*self*/, PyObject *arg
PyObject *SelectionSingleton::sAddSelectionGate(PyObject * /*self*/, PyObject *args, PyObject * /*kwd*/)
{
char* filter;
if (!PyArg_ParseTuple(args, "s",&filter))
return NULL; // NULL triggers exception
if (PyArg_ParseTuple(args, "s",&filter)) {
PY_TRY {
Selection().addSelectionGate(new SelectionFilterGate(filter));
Py_Return;
} PY_CATCH;
}
PY_TRY {
Selection().addSelectionGate(new SelectionFilterGate(filter));
} PY_CATCH;
PyErr_Clear();
PyObject* filterPy;
if (PyArg_ParseTuple(args, "O!",SelectionFilterPy::type_object(),&filterPy)) {
PY_TRY {
Selection().addSelectionGate(new SelectionFilterGatePython(static_cast<SelectionFilterPy*>(filterPy)));
Py_Return;
} PY_CATCH;
}
Py_Return;
PyErr_Clear();
PyObject* gate;
if (PyArg_ParseTuple(args, "O",&gate)) {
PY_TRY {
Selection().addSelectionGate(new SelectionGatePython(Py::Object(gate, false)));
Py_Return;
} PY_CATCH;
}
PyErr_SetString(PyExc_ValueError, "Argument is neither string nor SelectionFiler nor SelectionGate");
return 0;
}
PyObject *SelectionSingleton::sRemoveSelectionGate(PyObject * /*self*/, PyObject *args, PyObject * /*kwd*/)