Skip to content

Commit

Permalink
+ extend Gui.Selection.addSelection to pass object and tuple of sub-e…
Browse files Browse the repository at this point in the history
…lement names
  • Loading branch information
wwmayer committed May 19, 2016
1 parent 4d8f338 commit 716e256
Showing 1 changed file with 40 additions and 15 deletions.
55 changes: 40 additions & 15 deletions src/Gui/Selection.cpp
Expand Up @@ -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)
{
// already in ?
//if (isSelected(pDocName, pObjectName, pSubName))
// return true;

_SelObj temp;

temp.pDoc = getDocument(pDocName);
Expand Down Expand Up @@ -1071,21 +1067,50 @@ PyObject *SelectionSingleton::sAddSelection(PyObject * /*self*/, PyObject *args,
PyObject *object;
char* subname=0;
float x=0,y=0,z=0;
if (!PyArg_ParseTuple(args, "O!|sfff", &(App::DocumentObjectPy::Type),&object,&subname,&x,&y,&z))
return NULL; // NULL triggers exception
if (PyArg_ParseTuple(args, "O!|sfff", &(App::DocumentObjectPy::Type),&object,&subname,&x,&y,&z)) {
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;
}

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;
Selection().addSelection(docObj->getDocument()->getName(),
docObj->getNameInDocument(),
subname,x,y,z);
Py_Return;
}

Selection().addSelection(docObj->getDocument()->getName(),
docObj->getNameInDocument(),
subname,x,y,z);
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;
}

Py_Return;
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;
}
}
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*/)
Expand Down

0 comments on commit 716e256

Please sign in to comment.