+ extend Gui.Selection.addSelection to pass object and tuple of sub-element names
This commit is contained in:
parent
4d8f338b8d
commit
716e2563b7
|
@ -730,10 +730,6 @@ bool SelectionSingleton::addSelection(const char* pDocName, const char* pObjectN
|
||||||
|
|
||||||
bool SelectionSingleton::addSelection(const char* pDocName, const char* pObjectName, const std::vector<std::string>& pSubNames)
|
bool SelectionSingleton::addSelection(const char* pDocName, const char* pObjectName, const std::vector<std::string>& pSubNames)
|
||||||
{
|
{
|
||||||
// already in ?
|
|
||||||
//if (isSelected(pDocName, pObjectName, pSubName))
|
|
||||||
// return true;
|
|
||||||
|
|
||||||
_SelObj temp;
|
_SelObj temp;
|
||||||
|
|
||||||
temp.pDoc = getDocument(pDocName);
|
temp.pDoc = getDocument(pDocName);
|
||||||
|
@ -1071,9 +1067,7 @@ PyObject *SelectionSingleton::sAddSelection(PyObject * /*self*/, PyObject *args,
|
||||||
PyObject *object;
|
PyObject *object;
|
||||||
char* subname=0;
|
char* subname=0;
|
||||||
float x=0,y=0,z=0;
|
float x=0,y=0,z=0;
|
||||||
if (!PyArg_ParseTuple(args, "O!|sfff", &(App::DocumentObjectPy::Type),&object,&subname,&x,&y,&z))
|
if (PyArg_ParseTuple(args, "O!|sfff", &(App::DocumentObjectPy::Type),&object,&subname,&x,&y,&z)) {
|
||||||
return NULL; // NULL triggers exception
|
|
||||||
|
|
||||||
App::DocumentObjectPy* docObjPy = static_cast<App::DocumentObjectPy*>(object);
|
App::DocumentObjectPy* docObjPy = static_cast<App::DocumentObjectPy*>(object);
|
||||||
App::DocumentObject* docObj = docObjPy->getDocumentObjectPtr();
|
App::DocumentObject* docObj = docObjPy->getDocumentObjectPtr();
|
||||||
if (!docObj || !docObj->getNameInDocument()) {
|
if (!docObj || !docObj->getNameInDocument()) {
|
||||||
|
@ -1084,9 +1078,40 @@ PyObject *SelectionSingleton::sAddSelection(PyObject * /*self*/, PyObject *args,
|
||||||
Selection().addSelection(docObj->getDocument()->getName(),
|
Selection().addSelection(docObj->getDocument()->getName(),
|
||||||
docObj->getNameInDocument(),
|
docObj->getNameInDocument(),
|
||||||
subname,x,y,z);
|
subname,x,y,z);
|
||||||
|
Py_Return;
|
||||||
|
}
|
||||||
|
|
||||||
|
PyErr_Clear();
|
||||||
|
PyObject *sequence;
|
||||||
|
if (PyArg_ParseTuple(args, "O!O", &(App::DocumentObjectPy::Type),&object,&sequence)) {
|
||||||
|
App::DocumentObjectPy* docObjPy = static_cast<App::DocumentObjectPy*>(object);
|
||||||
|
App::DocumentObject* docObj = docObjPy->getDocumentObjectPtr();
|
||||||
|
if (!docObj || !docObj->getNameInDocument()) {
|
||||||
|
PyErr_SetString(Base::BaseExceptionFreeCADError, "Cannot check invalid object");
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
if (PyTuple_Check(sequence) || PyList_Check(sequence)) {
|
||||||
|
Py::Sequence list(sequence);
|
||||||
|
for (Py::Sequence::iterator it = list.begin(); it != list.end(); ++it) {
|
||||||
|
std::string subname = static_cast<std::string>(Py::String(*it));
|
||||||
|
Selection().addSelection(docObj->getDocument()->getName(),
|
||||||
|
docObj->getNameInDocument(),
|
||||||
|
subname.c_str());
|
||||||
|
}
|
||||||
|
|
||||||
Py_Return;
|
Py_Return;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
catch (const Py::Exception&) {
|
||||||
|
// do nothing here
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
PyErr_SetString(PyExc_ValueError, "type must be 'DocumentObject[,subname[,x,y,z]]' or 'DocumentObject, list or tuple of subnames'");
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
PyObject *SelectionSingleton::sRemoveSelection(PyObject * /*self*/, PyObject *args, PyObject * /*kwd*/)
|
PyObject *SelectionSingleton::sRemoveSelection(PyObject * /*self*/, PyObject *args, PyObject * /*kwd*/)
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in New Issue
Block a user